? linksdb-drupal-5-notes.txt
? linksdb.info
Index: linksdb.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/linksdb/linksdb.module,v
retrieving revision 1.12
diff -u -r1.12 linksdb.module
--- linksdb.module	7 Aug 2006 08:24:35 -0000	1.12
+++ linksdb.module	3 Apr 2007 15:26:32 -0000
@@ -2,20 +2,22 @@
 // $Id: linksdb.module,v 1.12 2006/08/07 08:24:35 flibs Exp $
 
 /**
+ * Update from 4.7.x to 5.x Notes:
+ * Update By: 	Phil Menni (UK Digital Graphics Ltd - www.ukdg.net)
+ * Update Date: 02/04/2007
+ * See the attached 'linksdb-drupal-5-notes.txt' for info on the changes made 
+ */
+ 
+/**
  * Implementation of hook_help().
  */
 function linksdb_help($section) {
   switch ($section) {
     case 'admin/help#linksdb':
       return "<h3>" . t('Links Module') . "</h3><p>" . t('This module allows you to maintain a database of links') . "</p>";
-    case 'admin/modules#description':
-      return t('Maintains a database of links.');
-    case 'admin/settings/linksdb':
-      return t('<p>Manages the database of links.</p>');
   }
 }
-function linksdb_perm()
-{
+function linksdb_perm() {
 	return array('manage links', 'suggest links', 'moderate links');
 }
 
@@ -23,6 +25,16 @@
 	$items = array();
 
 	$items[] = array(
+    'path' => 'admin/settings/linkdb',
+    'title' => t('LinksDB'),
+    'description' => t('Manages the database of links.'),
+		'callback' => 'drupal_get_form',
+    'callback arguments' => array('linksdb_settings'),
+    'access' => user_access('administer site configuration'),
+    'type' => MENU_NORMAL_ITEM, // optional
+   );
+   
+	$items[] = array(
 		'path' => 'links',
 		'title' => t('links'),
 		'callback' => 'linksdb_display',
@@ -97,8 +109,11 @@
 	return $items;
 }
 
-function linksdb_report($id=NULL)
-{
+function linksdb_report($id=NULL) {
+	return drupal_get_form('linksdb_report_form', $id, 'linksdb_report');
+}
+
+function linksdb_report_form($id=NULL) {
 	$form = array();
 	$form['id'] = array('#type' => 'hidden', '#value' => $id);
 	$form['reason'] = array(
@@ -111,46 +126,44 @@
 		'#type' => 'submit',
 		'#value' => t('Submit report'),
 	);
-	return drupal_get_form('reportform', $form, 'linksdb_report');
+	return $form;
 }
 
-function linksdb_report_submit($fid, $v)
-{
+function linksdb_report_submit($fid, $v) {
 	global $user;
 	db_query("UPDATE {links_links} SET dead=1, deadcomment='%s', deadby=%d WHERE id=%d;", $v['reason'], $user->uid, $v['id']);
 	drupal_set_message(t('Thank you for your feedback.  The site administrators will check this link soon and take the appropriate action.'));
 	return "links";
 }
 
-function linksdb_refer($id=NULL)
-{
+function linksdb_refer($id=NULL) {
 	db_query("UPDATE {links_links} SET clicks=clicks+1 WHERE id=%d;", $id);
 	$link = db_fetch_object(db_query("SELECT url FROM {links_links} WHERE id=%d;", $id));
 	header("Location: $link->url");
 }
 
-function linksdb_deadlinks()
-{
+function linksdb_deadlinks() {
+	return drupal_get_form('linksdb_deadlinks_form', 'linksdb_moderate');
+}
+
+function linksdb_deadlinks_form() {
 	$form = array();
 	$c = array();
 
 	$cl = db_query("SELECT name, id FROM {links_categories};");
-	while($cat = db_fetch_object($cl))
-	{
+	while($cat = db_fetch_object($cl)) {
 		$c[$cat->id] = $cat->name;
 	}
 
 	$c[0] = "<" . t('Root') . ">";
 
 	$ll = db_query("SELECT * FROM {links_links} WHERE dead=1 ORDER BY name;");
-	while($link = db_fetch_object($ll))
-	{
-		if(variable_get('linksdb_show_report', 1)==1)
-		{
-			if($link->dead==1)
-			{
+	while($link = db_fetch_object($ll)) {
+		if(variable_get('linksdb_show_report', 1)==1) {
+			if($link->dead==1) {
 				$link->description .= "<br/><b>This link is marked as dead: $link->deadcomment</b>";
-			} else {
+			}
+			else {
 				$link->description .= "<br/>" . l(t("Report this link as dead"), "links/report/$link->id");
 			}
 		}
@@ -166,62 +179,69 @@
 			'#newwindow' => $link->newwindow,
 		);
 	}
-	return drupal_get_form('moderateform', $form, 'linksdb_moderate');
+	return $form;
+}
+
+function linksdb_moderate() {
+	return drupal_get_form('linksdb_moderate_form', 'linksdb_moderate');
 }
-function linksdb_moderate()
-{
+
+function linksdb_moderate_form() {
 	$form = array();
 	$cl = db_query("SELECT name, id FROM {links_categories};");
 	$c = array();
-	while($cat = db_fetch_object($cl))
-	{
+	while($cat = db_fetch_object($cl)) {
 		$c[$cat->id] = $cat->name;
 	}
 	$c[0] = '<'.t('Root').'>';
 	$ll = db_query("SELECT name, url, description, id, category, clicks FROM {links_links} WHERE active=0 ORDER BY name;");
 	$form['head'] = array('#type' => 'markup', '#value' => '<table><tr><th>Link</th><th>Category</th><th>Activate</th></tr>');
-	while($link = db_fetch_object($ll))
-	{
-		$form["left$link->id"] = array(
-			'#type' => 'markup',
-			'#value' => '<tr><td>',
-		);
-		$form["link$link->id"] = array(
-			'#type' => 'link',
-			'#title' => $link->name,
-			'#description' => $link->description,
-			'#url' => $link->url,
-			'#click' => "links/refer/$link->id",
-			'#edit' => "links/edit/$link->id",
-			'#newwindow' => $link->newwindow,
-			'#clicks' => $link->clicks,
-		);
-		$form["mid$link->id"] = array(
-			'#type' => 'markup',
-			'#value' => '</td><td>' . $c[$link->category] . "</td><td>",
-		);
-		$form["activate$link->id"] = array(
-			'#type' => 'checkbox',
-			'#default_value' => 0,
-		);
-		$form["right$link->id"] = array(
-			'#type' => 'markup',
-			'#value' => '</td></tr>',
-		);
+	if (db_num_rows($ll) > 0) {
+		while($link = db_fetch_object($ll)) {
+			$form["left$link->id"] = array(
+				'#type' => 'markup',
+				'#value' => '<tr><td>',
+			);
+			$form["link$link->id"] = array(
+				'#type' => 'link',
+				'#title' => $link->name,
+				'#description' => $link->description,
+				'#url' => $link->url,
+				'#click' => "links/refer/$link->id",
+				'#edit' => "links/edit/$link->id",
+				'#newwindow' => $link->newwindow,
+				'#clicks' => $link->clicks,
+			);
+			$form["mid$link->id"] = array(
+				'#type' => 'markup',
+				'#value' => '</td><td>' . $c[$link->category] . "</td><td>",
+			);
+			$form["activate$link->id"] = array(
+				'#type' => 'checkbox',
+				'#default_value' => 0,
+			);
+			$form["right$link->id"] = array(
+				'#type' => 'markup',
+				'#value' => '</td></tr>',
+			);
+		}
+	}
+	// no links to moderate
+	else {
+	  $form["no-moderate-links"] = array(
+				'#type' => 'markup',
+				'#value' => '<tr><td colspan="3">No links to moderate.</td></tr>',
+			);
 	}
 	$form['foot'] = array('#type' => 'markup', '#value' => '</table>');
 	$form['save'] = array('#type' => 'submit', '#value' => t('Save changes'));
-	return drupal_get_form('moderateform', $form, 'linksdb_moderate');
+	return $form;
 }
 
-function linksdb_moderate_submit($formid, $v)
-{
-	while(list($key, $val) = each($v))
-	{
-		if(preg_match('/activate(\d+)/', $key, $m))
-		{
-			if($val==1)
-			{
+function linksdb_moderate_form_submit($formid, $v) {
+	while(list($key, $val) = each($v)) {
+		if(preg_match('/activate(\d+)/', $key, $m)) {
+			if($val==1) {
 				db_query("UPDATE {links_links} SET active=1 WHERE id=%d;", $m[1]);
 				drupal_set_message("Link " . $m[1] . " activated");
 			}
@@ -229,16 +249,17 @@
 	}
 }
 
-function linksdb_suggest()
-{
+function linksdb_suggest() {
+	return drupal_get_form('linksdb_suggest_form');
+}
+
+function linksdb_suggest_form() {
 	$copt = array();
 	$copt[0] = '<'.t('Root').'>';
 	$tree = array();
 	linksdb_childnodes(0, 1, $tree);
-	foreach($tree as $cat)
-	{
-		if($cat['id'] != $id)
-		{
+	foreach($tree as $cat) {
+		if($cat['id'] != $id) {
 			$copt[$cat['id']]=$cat['title'];
 		}
 	}
@@ -272,26 +293,23 @@
 		'#value' => t('Suggest this site'),
 	);
 
-	return drupal_get_form('submitform', $form, 'linksdb_suggest');
+	return $form;
 }
 
-function linksdb_suggest_submit($fid, $v)
-{
+function linksdb_suggest_form_submit($fid, $v) {
 	db_query("INSERT INTO {links_links} (name, url, description, active, category) VALUES ('%s', '%s', '%s', 0, %d);", $v['title'], $v['url'], $v['description'], $v['category']);
 	drupal_set_message(t("Thank you for your suggestion.  The site staff will review it shortly and if approved will be on the site soon."));
 	return "links";
 }
 
 
-function linksdb_elements()
-{
+function linksdb_elements() {
 	$type = array();
 	$type['link'] = array('#input' => 0);
 	return $type;
 }
 
-function theme_link($element)
-{
+function theme_link($element) {
 	$target = $element['#newwindow']==1?array("target"=>"_new"):array();
 	$url = $element['#url'];
 	if(preg_match('/^([^?]+)?.*/', $url, $m)==1)
@@ -312,21 +330,23 @@
 	{
 		$title .= " - " . l("Edit Link", $element['#edit']);
 	}
-	return theme('form_element', $element['#title'], "$title", $element['#description'], $element['#id'], $element['#required'], form_get_error($element));
+	return theme('form_element', $element, $title);
 }
 
-function linksdb_show_all($cat=NULL)
-{
+function linksdb_show_all($cat = NULL) {
+	return drupal_get_form('linksdb_show_all_form', $cat);
+}
+
+function linksdb_show_all_form($cat=NULL) {
 	$form = array();
-	$ll = db_query("SELECT * FROM {links_links} WHERE category=%d AND active=1 ORDER BY name;", $cat);
-	while($link = db_fetch_object($ll))
-        { 
-		if(variable_get('linksdb_show_report', 1)==1)
-		{
-			if($link->dead==1)
-			{
+	$ll = db_query("SELECT * FROM {links_links} WHERE category = %d AND active = 1 ORDER BY name;", $cat);
+	while($link = db_fetch_object($ll)) {
+drupal_set_message(" -> " . print_r($cat, true), 'debug'); 
+		if(variable_get('linksdb_show_report', 1)==1) {
+			if($link->dead==1) {
 				$link->description .= "<br/><b>This link is marked as dead: $link->deadcomment</b>";
-			} else {
+			}
+			else {
 				$link->description .= "<br/>" . l(t("Report this link as dead"), "links/report/$link->id");
 			}
 		}
@@ -340,32 +360,26 @@
 			'#newwindow' => $link->newwindow,
 			'#clicks' => $link->clicks,
 		);
-        }
-	return drupal_get_form('myform', form_builder('myform', $form), 'linksdb_display');
+  }
+	return $form;
 }
 
-function linksdb_display_rec($me, &$form)
-{
-	$cat = db_fetch_object(db_query("SELECT shown FROM {links_categories} WHERE id=%d;", $me));
-	if(!$cat)
-	{
-		$cat->shown=99999999;
+function linksdb_display_rec($me, &$form) {
+  $cat = db_fetch_object(db_query("SELECT shown FROM {links_categories} WHERE id=%d;", $me));
+	if(!$cat) {
+		$cat->shown = 99999999;
 	}
-	$cl = db_query("SELECT * FROM {links_links} WHERE category=%d AND active=1 ORDER BY name;", $me);
+	$cl = db_query("SELECT * FROM {links_links} WHERE category = %d AND active=1 ORDER BY name;", $me);
 	$cc = 0;
-	while($link = db_fetch_object($cl))
-	{
-		if($cc<$cat->shown)
-		{
-			if(variable_get('linksdb_show_report', 1)==1)
-			{
-				if($link->dead==1)
-				{
+	while($link = db_fetch_object($cl)) {
+		if($cc < $cat->shown) {
+		  if(variable_get('linksdb_show_report', 1)==1) {
+				if($link->dead==1) {
 					$link->description .= "<br/><b>This link is marked as dead: $link->deadcomment</b>";
-				} else {
+				}
+				else {
 					$link->description .= "<br/>" . l(t("Report this link as dead"), "links/report/$link->id");
 				}
-
 			}
 			$form["link$link->id"] = array(
 				'#type' => 'link',
@@ -380,16 +394,14 @@
 		}
 		$cc++;
 	}
-	if($cc>$cat->shown)
-	{
+	if($cc>$cat->shown) {
 		$form['showmore'] = array(
 			'#type' => 'markup',
 			'#value' => l('Show more', "links/view/all/$me"),
 		);
 	}
 	$cl = db_query("SELECT name, id, collapsed FROM {links_categories} WHERE parent=%d ORDER BY name;", $me);
-	while($cat = db_fetch_object($cl))
-	{
+	while($cat = db_fetch_object($cl)) {
 		$form['cat' . $cat->id] = array(
 			'#type' => 'fieldset',
 			'#title' => $cat->name,
@@ -400,17 +412,23 @@
 	}
 }
 
-function linksdb_display()
-{
+function linksdb_display() {
+	return drupal_get_form('linksdb_display_form', 'linksdb_display');
+}
+
+function linksdb_display_form() {
 	$form = array();
 	linksdb_display_rec(0, $form['root']);
-	return drupal_get_form('myform', form_builder('myform', $form), 'linksdb_display');
+	$form = form_builder('linksdb_display_form', $form);
+	return $form;
 }
-
 	
 
-function linksdb_edit($id = NULL)
-{
+function linksdb_edit($id = NULL) {
+	return drupal_get_form('linksdb_edit_form', $id, 'linksdb_edit');
+}
+
+function linksdb_edit_form($id = NULL) {
 	$form = array();
 	$copt = array();
 	$copt[0] = '<'.t('Root').'>';
@@ -494,12 +512,11 @@
 			'#value' => t('Delete Link'),
 		);
 	}
-	return drupal_get_form('myform', form_builder('myform', $form), 'linksdb_edit');
+	return $form;
 }
 
-function linksdb_edit_submit($form_id, $values)
-{
-        $op = isset($_POST['op']) ? $_POST['op'] : '';
+function linksdb_edit_form_submit($form_id, $values) {
+  $op = isset($_POST['op']) ? $_POST['op'] : '';
 	if($op == t('Add Link'))
 	{
 		$id = $values['id'];
@@ -521,8 +538,7 @@
 	return "links";
 }
 
-function linksdb_childnodes($me, $depth, &$tree)
-{
+function linksdb_childnodes($me, $depth, &$tree) {
 	$out = "";
 	$space = "";
 	for($x=0; $x<$depth; $x++)
@@ -538,8 +554,7 @@
 }
 	
 
-function linksdb_categories()
-{
+function linksdb_categories() {
 	$tree = array();
 	$categories="";
 	linksdb_childnodes(0, 1, $tree);
@@ -551,8 +566,11 @@
 	return "<br/><br/>$categories<br/>$addnew";
 }
 
-function linksdb_categories_edit($id=NULL)
-{
+function linksdb_categories_edit($id=NULL) {
+	return drupal_get_form('linksdb_categories_edit_form', $id); 
+}
+
+function linksdb_categories_edit_form($id=NULL) {
 	$form = array();
 	$copt = array();
 	$copt[0] = '<'.t('Root').'>';
@@ -595,7 +613,7 @@
 		'#size' => 4,
 		'#title' => t('Number to show'),
 		'#description' => t('Number of links to show before a "show all" link is added'),
-		'#default_value' => $cat?$cat->shown:10,
+		'#default_value' => $cat->shown ? $cat->shown : 10,
 	);
 	if($id)
 	{
@@ -613,11 +631,10 @@
 			'#value' => t('Add Category'),
 		);
 	}
-	return drupal_get_form('myform', form_builder('myform', $form), 'linksdb_categories_edit');
+	return $form;
 }
 
-function linksdb_categories_edit_submit($form_id, $values)
-{
+function linksdb_categories_edit_form_submit($form_id, $values) {
 	$id = $values['id'];
 	$op = isset($_POST['op']) ? $_POST['op'] : '';
 	if($id)
@@ -641,8 +658,7 @@
 	return "links/category";
 }	
 
-function linksdb_settings()
-{
+function linksdb_settings() {
 	$form = array();
 	$form['linksdb_show_clicks'] = array(
 		'#type' => 'checkbox',
@@ -656,5 +672,5 @@
 		'#default_value' => variable_get('linksdb_show_report', 1),
 		'#description' => t('Show or hide the link to report a link as dead'),
 	);
-	return $form;
+	return system_settings_form($form);
 }
