=====A Robust Link Management Solution===== The system currently: ~A) Detects whenever a page mentions its name ~A) Detects whenever a page stops mentioning its name ~A) Allows admins to create "link groups" ~A) Allows managers to move links between "link groups" with ease ~A) Allows managers to assign weights to individual links ~A) Renders "link groups" in a variety of styles ~A) Allows content of linked pages to be embedded within the calling page ====The Data Model==== ''you may have to replace wikka_ with your used prefix'' --NilsLindenberg %%(mysql) CREATE TABLE `wikka_link_manager_groups` ( `id` int(11) NOT NULL auto_increment, `name` varchar(100) NOT NULL default '', `description` mediumtext, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) TYPE=MyISAM AUTO_INCREMENT=1 ; CREATE TABLE `wikka_link_manager_links` ( `link_id` int(11) NOT NULL auto_increment, `this_tag` varchar(75) NOT NULL default '', `page_tag` varchar(75) NOT NULL default '', `link_group_id` int(11) default NULL, `weight` int(11) default NULL, PRIMARY KEY (`link_id`) ) TYPE=MyISAM AUTO_INCREMENT=1 ; %% ====The PHP Code==== I've found that it's convenient to keep a "common settings" file in the actions directory to store variables shared between actions and handlers. In my setup, I call it "common.ini.php". Here is the code: %%(php) config['table_prefix'] . 'link_manager_groups'; $table_links = $this->config['table_prefix'] . 'link_manager_links'; $table_pages = $this->config['table_prefix'] . 'pages'; ?> %% Next up is the "linkmanager.php" file, which should also be saved in the actions directory... %%(php) IsAdmin(); $has_access = $this->HasAccess('write'); if ($has_access) { if (isset($_POST['update_links'])) { mysql_query("DELETE FROM $table_links WHERE this_tag = '$this->tag'"); $links_to_move = isset($_POST['selected_links']) ? $_POST['selected_links'] : array(); if (isset($_POST['link_weights'])) { foreach ($_POST['link_weights'] as $page_tag => $link_weight) { if (empty($link_weight)) $link_weight = 'NULL'; if (isset($links_to_move[$page_tag])) { $link_group_id = $_POST['group_select']; unset($links_to_move[$page_tag]); } else { $link_group_id = isset($_POST['link_group_ids']) ? $_POST['link_group_ids'][$page_tag] : ''; } mysql_query("INSERT INTO $table_links (this_tag, page_tag, link_group_id, weight) VALUES ('$this->tag', '$page_tag', $link_group_id, $link_weight)"); } } if (count($links_to_move) && $_POST['group_select'] != 'None') { foreach ($links_to_move as $page_tag => $junk) { mysql_query("INSERT INTO $table_links (this_tag, page_tag, link_group_id) VALUES ('$this->tag', '$page_tag', $_POST[group_select])"); } } } } if ($is_admin) { if (isset($_GET['delete_group'])) { mysql_query("DELETE FROM $table_link_groups WHERE id = $_GET[group_id]"); } if (isset($_POST['add_new_group'])) { $new_group_name = mysql_real_escape_string($_POST['group_name']); $new_group_description = mysql_real_escape_string($_POST['group_description']); mysql_query("INSERT INTO $table_link_groups (name, description) VALUES ('$new_group_name', '$new_group_description')"); } if (isset($_POST['update_groups'])) { $group_names = $_POST['group_names']; $group_descriptions = $_POST['group_descriptions']; foreach ($group_names as $group_id => $group_name) { $group_description = mysql_real_escape_string($group_descriptions[$group_id]); mysql_query("UPDATE $table_link_groups SET name = '$group_name', description = '$group_description' WHERE id = $group_id"); } } } if ($has_access) { echo "
'; } ?> %% Now, save the following code as "lmshow.php" in the same directory... %%(php) tag' $link_where ORDER BY weight DESC"; $result = mysql_query($sql); if ($result && mysql_num_rows($result)) { while ($row = mysql_fetch_array($result)) { $groups[$row['link_group_id']]['links'][$row['page_tag']] = $row['body']; ++$count[$row['link_group_id']]; } arsort($count); foreach ($count as $id => $n) { if (is_array($groups[$id]['links'])) { $name = $groups[$id]['name']; $css_id = str_replace(' ', '_', $name); if ($embed) { foreach ($groups[$id]['links'] as $page_tag => $body) { $body = preg_replace('/{{.*linkmanager.*}}/U', '', $body); $body = preg_replace('/{{.*lmshow.*}}/U', '', $body); $output .= ($embed == 'all') ? trim($body) : fetch_section($body, $embed); $output .= "\n\n"; } echo $this->Format($output); } else { echo "