LinkWeaver!

About LinkWeaver

LinkWeaver is an Open Source package for managing trees of links. Right now the database structure is in flux and the code is preliminary and very very very rough (i.e. not very much works). You have been warned!

LinkWeaver was developed for use at The OpenScience Project and it may be of general use elsewhere. It is primarily a set of shell scripts, PHP, text, and html files, but the database structure is somewhat general and can be applied to other sites that want to implement their own trees of links.



Requirements

What you need:



Database Tables

Hierarchical trees of links are basically large databases, and LinkWeaver is built on a few interrelated database tables. The SQL code for creating the tables used by LinkWeaver is shown below the explanation of each table.

The urls table contains information that is specific to a particular link including a default names and description, the status of the link, how many times it has been visited via the LinkWeaver system, contact info, etc. The lines in this table that are italicized and in red are specific to our particular site. You may have other fields that are important to your specific application, and the italicized fields can be replaced however you would like.

          
create table urls (
        id                integer not null auto_increment primary key,

        url               varchar(255) not null,
        name              varchar(255),
        description       text,

        status            enum('ok','broken') not null,

        total_hits        integer default 0,
        recent_hits       float default 0.0,
        last_hit          date,

        avg_rating        float default 0.0,
        rating_count      integer default 0,

        date_created      date,
        date_modified     date,
        license_type      varchar(20)
);
                

The urls from these tables are then grouped together to form the entryGroups table. This is done so that entire groups of links can be easily moved around in the tree if the tree structure changes. The name and description are both optional:


create table entryGroups (
        id                integer not null auto_increment primary key,

        name              varchar(255),
        description       text,

        total_hits        integer default 0,
        recent_hits       float default 0.0,
        last_hit          date,

        date_created      date,
        date_modified     date
);
                  

The sections table contains navigational information for the hierarchical tree. Each section has a group_id that associates a entryGroup with the section. Since entryGroups can appear in the tree in multiple locations, the name and description fields override the default name and description fields for the associated entryGroup.


create table sections (
        id                integer not null auto_increment primary key,
        group_id          integer not null references entryGroups,
        parent_id         integer not null references sections,
                
        n_children        integer default 0,

        name              varchar(255),
        description       text,

        status            enum('live','pending','suspended','deleted') not null,

        total_hits        integer default 0,
        recent_hits       float default 0.0,
        last_hit          date,

        date_created      date,
        date_modified     date,
        contact_id        integer references users
);
                  

The entries table maps the entries in urls into the entryGroups table. A specific link may have entries in many entryGroups. Since each place in the hierarchy may want to describe the link differently, the linkname, description, and hitcount fields override the default name, description and hitcount when the data is displayed.


create table entries (
        id                integer not null auto_increment primary key,
        group_id          integer not null references entryGroups,
        url_id            integer not null references urls,

        name              varchar(255),
        description       text,

        status            enum('live','pending','suspended','deleted') not null,

        total_hits        integer default 0,
        recent_hits       float default 0.0,
        last_hit          date,

        avg_rating        float default 0.0,
        rating_count      integer default 0,

        date_created      date,
        date_modified     date,
        contact_id        integer references users
);
                  

The users table defines a list of users, passwords, and email addresses for the tree and link editors:


 create table users (
        id                integer not null auto_increment primary key,
        username          char(16) default '' not null,
        password          char(16) default '' not null,
        email             varchar(100)
);
                 

The editors table maps users onto their authority domains within the hierarchy. An editor of a section can change anything that sits below their section_id in the hierarchical tree. This is abstracted out from the users table so that a single user can have control over multiple disconnected branches of the tree.


 create table editors (
        id                integer not null auto_increment primary key,
        user_id           integer not null references users,
        section_id        integer not null references sections
);
                 

The administrators table maps users onto administrative functions (modifying the editor entries, changing the structure of the table, etc.):


create table administrators (
        id                integer not null auto_increment primary key,
        user_id           integer not null references users
);
                  


Queries

Once these database tables have been set up in MySQL, we need to worry a little bit about the database queries.

In order to render each page in the tree, we need to make 1 substantial database query to figure out which links we should display in this section. (Again, the parts that are specific for our site are in red italics.) The variable in blue is how we look up only those entries that are in our particular section.


SELECT e.id, e.group_id, e.url_id, e.name, e.description, 
       e.status, e.total_hits, e.recent_hits, e.last_hit, 
       e.avg_rating, e.rating_count, e.date_created, 
       e.date_modified, e.contact_id, 
       u.url, u.name as uName, u.description as uDescription,
       u.status as uStatus, u.total_hits as uTotalHits, 
       u.recent_hits as uRecentHits, u.last_hit as uLastHit, 
       u.avg_rating as uAvgRating, u.rating_count as uRatingCount, 
       u.date_created as uDateCreated, u.date_modified as uDateModified 
FROM   entries e, urls u, entryGroups g 
WHERE g.id = e.group_id 
AND e.group_id =  $groupid
AND e.url_id = u.id 
AND e.status = 'live' 
ORDER BY u.avg_rating, u.recent_hits, desc;
                  

The $groupid is determined by navigation through the tree.

The glue between the queries and the web is handled via PHP, which has a very powerful MySQL interface.



Code

LinkWeaver uses the following directory structure:

  • include/ - configuration, appearance, and database files

    • body.txt - body tag with background and text colors
    • bottom.txt - the bottom matter for each page
    • config.inc.php - directories, database location and username, table names, admin address
    • css.txt - cascading style sheet
    • dbClose.inc.php - close the database connection
    • dbConnect.inc.php - connect to database
    • entrybodyend.txt - how to end the display of a link entry body
    • entrybodystart.txt - how to start the display of a link entry body
    • entryheadend.txt - how to end the display of a link entry header
    • entryheadstart.txt - how to start the display of a link entry header
    • headerend.txt - how to end the display of a header
    • headerstart.txt - how to start the display of a header
    • opening.txt - Some frontmatter for each page
    • sectionend.txt - How to end display of a major section
    • sectionstart.txt - How to start display of a major section
    • title.txt - The portion of the title string that recurs on each page.

  • links/ - the directory tree that maps out the hierarchical structure of the linked lists

    • add2.php - Process an "add-a-link" form entry
    • addalink.php - Form for adding a link. A link to this file is contained in each section.
    • exportdirs - export sectionlist to the database
    • gendirs - use sectionlist to create directories and links
    • template.php - the meat. A link to this file is contained in each section.
    • Section1 - directories with subsections
    • Section2 - directories with subsections

  • admin/ - administration of the database tables

    • index.php - not-yet-functional check for editor permissions of the section