Index: blogroll/INSTALL.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/blogroll/INSTALL.txt,v
retrieving revision 1.4
diff -u -r1.4 INSTALL.txt
--- blogroll/INSTALL.txt	13 Feb 2005 05:59:29 -0000	1.4
+++ blogroll/INSTALL.txt	6 Jun 2007 11:58:53 -0000
@@ -4,12 +4,18 @@
 using these steps.
 
 1) The table is named "blogroll".  If you use a prefix for your tables edit
-   blogroll.mysql and change the name in the line: CREATE TABLE blogroll (
+   blogroll.mysql or blogroll.pgsql and change the name in the line:
+   CREATE TABLE blogroll (
+   If using blogroll.pgsql, also fix the line beginning with:
+   CREATE INDEX blogroll_uid_url_idx
 
 2) From the command line, type 'mysql -u username -p drupal < blogroll.mysql'
    where drupal is your drupal database and username is your mysql username.
+   For PostgreSQL users the command syntax is as
+   'psql -U username -d drupal < blogroll.pgsql'.
 
-3) Copy blogroll.module to your drupal installation's module directory
+3) Copy the entire blogroll directory to your drupal installation's
+   /sites/all/modules directory.
 
 4) Activate the module from administer >> modules
 
@@ -33,6 +39,3 @@
 6) Login as a user and navigate to your own blog to get a point and click
    interface.
 
-7) Another feature is the polling of a user's blogroll from an external
-   location.  This works for personal blogrolls and the community blogroll.
-
Index: blogroll/README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/blogroll/README.txt,v
retrieving revision 1.7
diff -u -r1.7 README.txt
--- blogroll/README.txt	13 Feb 2005 05:59:29 -0000	1.7
+++ blogroll/README.txt	6 Jun 2007 11:58:53 -0000
@@ -1,6 +1,8 @@
 /* $Id: README.txt,v 1.7 2005/02/13 05:59:29 grantbow Exp $ */
 
-NOTE: blogroll.pgsql is untested.
+NOTE: Module does NOT currently support module installation scheme used in
+Drupal 5. You'll have to create the database table manually. Please read
+INSTALL.txt! 
 
 This module provides a standard blogroll feature.  Each user's blog has it's
 own blogroll.  The owner of the blog can edit his own blogroll.  All users that
@@ -31,15 +33,12 @@
 I have created a project page http://drupal.org/project/blogroll.
 It has patches under discussion, bugs and release downloads.
 
-Aldon Hynes <ahynes1 at optonline.net> added functionality so that blogrolls
-can be retrieved externally using the following bit of javascript.  This will
-return the blog roll for user 1.  If the /1 is omitted, it will return the
-community blogroll.  This is a combination of all users' entries sorted by
-frequency.
-
-<script language="javascript" type="text/javascript"
-             src="http://example.com/index.php?q=blogroll/script/1"></script>
+Possibility to load blogrolls externally by javascript is removed from
+Drupal 5 compatible version. If you need this feature please re-implement
+it and submit a patch.
 
 Module Author:
 Grant Bowman <grantbow at grantbow.com>
 
+Module upgraded to Drupal 5 by:
+Pekka L J Jalkanen <plj@iki.fi>
Index: blogroll/blogroll.info
===================================================================
RCS file: blogroll/blogroll.info
diff -N blogroll/blogroll.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ blogroll/blogroll.info	6 Jun 2007 11:58:53 -0000
@@ -0,0 +1,3 @@
+; $Id$
+name = Blogroll
+description = Provides personal bloggers with a blogroll block and a community blogroll.
\ No newline at end of file
Index: blogroll/blogroll.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/blogroll/blogroll.module,v
retrieving revision 1.10
diff -u -r1.10 blogroll.module
--- blogroll/blogroll.module	31 Jan 2005 02:37:41 -0000	1.10
+++ blogroll/blogroll.module	6 Jun 2007 11:58:54 -0000
@@ -2,171 +2,252 @@
 // $Id: blogroll.module,v 1.10 2005/01/31 02:37:41 grantbow Exp $
 
 /**
- * @file
- * Enables users to provide a blogroll with their blogs.
- */
-
-/**
- * Implementation of hook_help().
- *
- * @param $section
- *   provides help for /admin/modules and /admin/help and admin/settings/blogroll.
- *
- * @return
- *   A brief message for administrators to explain what this module does
+ * Implementation of hook_help
  */
 function blogroll_help($section) {
   switch ($section) {
-    case 'admin/modules#description':
-      return t('Provides personal bloggers with a blogroll block and a community blogroll.');
     case 'admin/help#blogroll':
-      return '<p>'. t('The blogroll block must be enabled and should contain a path.') .'</p><p>'. t('If you are vewing a blog and are the owner you may click \"Edit.\"') .'</p>';
+      $output = '<p>'. t('The blogroll block must be enabled and should contain a path.') .'</p><p>'. t('If you are vewing a blog and are the owner you may click \"Edit.\"') .'</p>';
     case 'admin/settings/blogroll':
-      return t('A blogroll block provides personal bloggers with an editable list of other interesting blogs. Blogrolls only make sense from a blog perspective so a path must be used when enabling the block.  A community blogroll provides a listing of all blogrolled blogs sorted by frequency and name.');
+      $output .= t('A blogroll block enables personal bloggers to maintain an editable list of links to other blogs they find interesting. Blogrolls only make sense from a blog perspective so a path must be used when enabling the block. A community blogroll provides a listing of all blogrolled blogs sorted by frequency and name.');
+    return $output;
   }
 }
 
 /**
- * Implementation of hook_menu().
- *
- * @return
- *   Arrays containing paths to be accessed.
+ * Implementation of hook_menu
  */
 function blogroll_menu($may_cache) {
-  global $user;
   $items = array();
-
+  
   if ($may_cache) {
-    $items[] = array('path' => 'blogroll/edit', 'title' => t('edit blogroll'),
-      'callback' => 'blogroll_edit',
-      'access' => user_access('edit own blog'), // depends on blog.module
-      'type' => MENU_CALLBACK);
-    $items[] = array('path' => 'blogroll', 'title' => t('community blogroll'),
+    $items[] = array('path' => 'blogroll', 'title' => variable_get('blogroll_title', t('Blogroll')),
       'callback' => 'blogroll_page',
-      'access' => TRUE,
+      'access' => user_access('access content'), 
       'type' => MENU_CALLBACK);
-    $items[] = array('path' => 'blogroll/script', 'title' => t('blogroll'),
-      'callback' => 'blogroll_script',
-      'access' => TRUE,
+    $items[] = array('path' => 'blogroll/edit', 'title' => t('Edit blogroll'),
+      'callback' => 'blogroll_edit_page',
+      'access' => user_access('edit own blog'), //Depends on blog.module
       'type' => MENU_CALLBACK);
+    $items[] = array('path' => 'admin/settings/blogroll',
+      'title' => variable_get('blogroll_title', t('Blogroll')),
+      'description' => t('Define basic settings for per-user and community blogrolls.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('blogroll_admin_settings'),
+      'access' => user_access('administer site configuration'),
+      'type' => MENU_NORMAL_ITEM);
   }
   return $items;
 }
 
 /**
- * Implementation of hook_settings()
- *
- * @return
- *   The settings controls
+ * Admin settings callback.
  */
-function blogroll_settings() {
+function blogroll_admin_settings() {
   // add a checkbox for showing/hiding cnt for each url?
-  $group = form_select(t('Number of blogs listed in the community blogroll block'), 'blogroll_block_num', variable_get('blogroll_block_num', '5'), drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)), t('Number of blogs to show for the ?q=blog community blogroll block.') );
-  return form_group(t('Community blogroll block settings'), $group);
+  $form = array();
+  $form['blogroll']['blogroll_title'] = array(
+    '#type' => 'textfield',
+    '#title' => t('The title used for the blogroll'),
+    '#default_value' => variable_get('blogroll_title', 'Blogroll'),
+  );
+  $form['blogroll']['blogroll_description'] = array(
+    '#type' => 'textarea',
+    '#title' => t('The description of the blogroll, for use on the blogroll page'),
+    '#default_value' => variable_get('blogroll_description', t('A community blogroll is a list of all the blogs linked by personal bloggers of this site. It is sorted by frequency, then by name. The most frequent blogs may be provided by a block.')),
+  );
+  $form['blogroll']['blogroll_block_num'] = array(
+    '#type' => 'select',
+    '#title' => t('Number of blogs listed sidebar'),
+    '#default_value' => variable_get('blogroll_block_num', '10'),
+    '#options' => drupal_map_assoc(array(5, 10, 15, 20, 25, 30)),
+  );
+  $form['blogroll']['blogroll_show_popularity'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Show popularity'),
+    '#default_value' => variable_get('blogroll_show_popularity', 1),
+    '#return_value' => 1,
+  );
+  return system_settings_form($form);
+}
+
+/**
+ * Menu callback; displays the blogroll editing page
+ */
+function blogroll_edit_page() {
+  global $user;
+  $output = '';
+
+  if ($user->uid) {
+    $output = drupal_get_form('blogroll_edit_form', $user->uid);
+    $output .= drupal_get_form('blogroll_edit_add_form');
+  }
+
+  return $output;
 }
 
 /**
  * Prepare the blogroll display portion of the page
  */
-function blogroll_edit_display($edit, $uid) {
-  $output = '<p>'. t('After making changes click \'Update blogs.\'.') .'</p>';
+function blogroll_edit_form($uid) {
 
-  // display roll_form with it's table
-  $roll_form = '';
-  $header = array(t('Delete'), t('URL'), t('Name'), t('Weight'));
+  //Display roll_form with it's table
   $rolls = db_query("SELECT b.uid, b.name, b.url, b.weight FROM {blogroll} b WHERE b.uid = %d ORDER BY b.weight", $uid);
   while ($roll = db_fetch_object($rolls)) {
-    $rows[] = array(
-      array('data' => form_checkbox(NULL, $roll->url .'][delete', 1, 0), 'align' => 'center', 'class' => 'delete'),
-      array('data' => $roll->url, 'class' => 'url'),
-      array('data' => form_textfield(NULL, $roll->url .'][name', $roll->name, 30, 128), 'class' => 'name'),
-      array('data' => form_weight(NULL, $roll->url .'][weight', $roll->weight), 'class' => 'weight')
-    );
-  }
-  if (!$rows) {
-    $rows[] = array(
-      array('data' => t('No blogs available in your blogroll.'), 'class' => 'no_blogrolls', 'colspan' => '3')
-    );
-    $roll_form .= theme('table', $header, $rows);
-  } else {
-    $roll_form .= theme('table', $header, $rows);
-    $roll_form .= form_submit(t('Update blogs'));
+    $form['old'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Edit your present blogroll items'),
+      '#collapsible' => TRUE,
+      '#tree' => TRUE,
+    );
+    $form['old'][check_plain($roll->url)]['delete'] = array(
+      '#type' => 'checkbox',
+      '#default_value' => 0,
+      '#return_value' => 1,
+    );
+
+    $form['old'][check_plain($roll->url)]['url'] = array(
+      '#type' => 'textfield',
+      '#maxlength' => 128,
+      '#size' => 25,
+      '#default_value' => check_plain($roll->url),
+    );
+
+    $form['old'][check_plain($roll->url)]['name'] = array(
+      '#type' => 'textfield',
+      '#maxlength' => 128,
+      '#size' => 25,
+      '#default_value' => check_plain($roll->name),
+    );
+
+    $form['old'][check_plain($roll->url)]['weight'] = array(
+      '#type' => 'weight',
+      '#default_value' => check_plain($roll->weight),
+    );
+  
+    $form['old']['submit'] = array(
+      '#type' => 'submit',
+      '#value' => t('Update blogs'),
+    );
   }
-  $output .= form($roll_form, 'post', url('blogroll/edit'));
-  return form_group(t('Current blogs'), $output);
+  return $form;
 }
 
 /**
  * Prepare the blogroll adding portion of the page
  */
-function blogroll_edit_add_form($edit) {
-  $edit['url'] = 'http://';
-  $output = '<br /><p>'. t('After adding click \'Add blog.\'') .'</p>';
-  // user inputs for url and name
-  $header = array(t('URL'), t('Name'), t('Weight'));
-  $row[] = array(
-    array('data' => form_textfield(NULL, 'url', $edit['url'], 50, 128), 'class' => 'url'),
-    array('data' => form_textfield(NULL, 'name', $edit['name'], 30, 128), 'class' => 'name'),
-    array('data' => form_weight(NULL, 'weight', $edit['weight']), 'class' => 'weight')
-  );
-  $form  = theme('table', $header, $row);
-  $form .= form_submit(t('Add blog'));
-  $output .= form($form, 'post', url('blogroll/edit'));
-  return form_group(t('New blog'), $output);
+function blogroll_edit_add_form() {
+  $form = array();
+  
+  $form['new'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Add a new blogroll item'),
+    '#collapsible' => TRUE,
+    '#tree' => TRUE,
+  );
+
+  $form['new']['url'] = array(
+    '#type' => 'textfield',
+    '#maxlength' => 128,
+    '#size' => 25,
+  );
+
+  $form['new']['name'] = array(
+    '#type' => 'textfield',
+    '#maxlength' => 128,
+    '#size' => 25,
+  );
+
+  $form['new']['weight'] = array(
+    '#type' => 'weight',
+  );
+
+  $form['new']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Add blog'),
+  );
+
+  return $form;
 }
 
-/**
- * Menu callback; displays the blogroll editing page
- */
-function blogroll_edit() {
+function blogroll_edit_add_form_submit($form_id, $edit) {
   global $user;
+  $uid = $user->uid;  
+  // process post data
+  if ($edit['new']['url'] and $edit['new']['name']) {
+    db_query("INSERT INTO {blogroll} VALUES ('%d', '%s', '%s', '%d')", $uid, $edit['new']['url'], $edit['new']['name'], $edit['new']['weight']);
+    drupal_set_message( t('The blog was added.'));
+    cache_clear_all();
+    drupal_goto('blogroll/edit');
+    drupal_set_message( t('Your blogrolls have been updated.'));
+    cache_clear_all();
+    drupal_goto('blogroll/edit');
+  }
+}
 
-  $output = '';
+function blogroll_edit_form_submit($form_id, $edit) {
+  global $user;
   $uid = $user->uid;
-  $edit = $_POST['edit'];
-  $op = $_POST['op'];
-
-  if ($uid) {
-    // process post data
-    switch($op) {
-      case 'Add blog':
-        if ($edit['url'] and $edit['name']) {
-          // if ! 404 $edit[url] {};
-          db_query("INSERT into {blogroll} values ('%d', '%s', '%s', '%d')", $uid, $edit['url'], $edit['name'], $edit['weight']);
-          drupal_set_message( t('The blog was added.'));
-          cache_clear_all();
-          drupal_goto('blogroll/edit');
-        }
-      case 'Update blogs':
-        foreach ($edit as $url => $roll) {
-          if ($roll['delete']) {
-            db_query("DELETE FROM {blogroll} WHERE uid = '%d' AND url= '%s'", $uid, $url);
-          } else {
-            db_query("UPDATE {blogroll} b SET b.name = '%s', b.weight = %d WHERE b.uid = '%d' AND b.url = '%s'", $roll['name'], $roll['weight'], $uid, $url);
-          }
-        };
-        drupal_set_message( t('Your blogrolls have been updated.'));
-        cache_clear_all();
-        drupal_goto('blogroll/edit');
+  // process post data
+  //print_r($edit);
+  foreach ($edit['old'] as $url => $roll) {
+    if ($roll['delete'] == 1) {
+      db_query("DELETE FROM {blogroll} WHERE uid = '%d' AND url= '%s'", $uid, $url);
+    } else {
+      //Note that since this is an update, roll['url'] and $url may differ.
+      db_query("UPDATE {blogroll} SET url = '%s', name = '%s', weight = %d WHERE uid = '%d' AND url = '%s'", $roll['url'], $roll['name'], $roll['weight'], $uid, $url);
     }
+  };
+  drupal_set_message( t('Your blogrolls have been updated.'));
+  cache_clear_all();
+  drupal_goto('blogroll/edit');
+}
 
-    $output  = '<p>'. t('Your blogroll is shown on your personal blog\'s page.') .'</p>';
-    $output .= blogroll_edit_display($edit, $uid);
-    $output .= blogroll_edit_add_form($edit);
+function theme_blogroll_edit_add_form($form) {
+  //$output = '<br /><p>'. t('Add a new blog to your blogroll:') .'</p>';  
+  $header = array(t('URL'), t('Name'), t('Weight'));
+  
+  $row = array();
+  $row[] = drupal_render($form['new']['url']);
+  $row[] = drupal_render($form['new']['name']);
+  $row[] = drupal_render($form['new']['weight']);
+  
+  $rows = array($row);
+  
+  $form['new']['#children'] = theme('table', $header, $rows);
+  $form['new']['#children'] .= drupal_render($form['new']['submit']);
+  $output .= drupal_render($form);
+  return $output;
+}
+
+function theme_blogroll_edit_form($form) {
+  $output  = '<p>'. t('Your blogroll is shown on your personal blog\'s page.');
+  $header = array(t('Delete'), t('URL'), t('Name'), t('Weight'));  
+  foreach (element_children($form['old']) as $key) {
+    if(!($key == 'submit')) { //This test avoids an empty table line in output.
+      $row = array();
+      $row[] = drupal_render($form['old'][$key]['delete']);
+      $row[] = drupal_render($form['old'][$key]['url']);
+      $row[] = drupal_render($form['old'][$key]['name']);
+      $row[] = drupal_render($form['old'][$key]['weight']);
+      $rows[] = $row;
+    }
+  }
+  if(!$rows) {
+    $output .= ' ' . t('It is currently empty. You may add some links using form below.') . '</p>';
+    return $output;
   }
 
-  print theme('page', $output);
+  $form['old']['#children'] = theme('table', $header, $rows);
+  $form['old']['#children'] .= drupal_render($form['old']['submit']); 
+  $output .= '</p>';
+  $output .= drupal_render($form);
+  return $output;
 }
 
+
 /**
- * Implementation of hook_block();
- *
- * @param $op 
- *   Operation 'list' or 'view'.  If omitted 'list' is used.
- * @param $delta
- *   If omitted, 0 is used.
- *
- * @return a block containing the blogroll
+ * Implementation of hook_block.
  */
 function blogroll_block($op = 'list', $delta = 0) {
   global $user;
@@ -177,33 +258,52 @@
     case('view'):
       if (user_access('access content')) {
         $output = '<ul>';
+        $nodetype == arg(0);
         $request_uid = arg(1); // arg(1), won't work when URL is non-numeric or viewing a blog node
-        if ((arg(0) == 'blogroll') and (arg(1) == 'edit')) { // for /blogroll/edit
-            $request_uid = $user->uid;
+        //The following tries to find out, if non-numeric URL is a path alias
+      	if (!($nodetype === 'blog' && is_numeric($request_uid))) {
+      	  $real_args = explode('/', (drupal_get_normal_path($_GET['q'])));
+      	  $nodetype = $real_args[0];
+      	  $request_uid = $real_args[1];
+        }
+      	if (!($nodetype == 'blog')) {      		  
+          if ((arg(0) == 'blogroll') and (arg(1) == 'edit')) { // for /blogroll/edit
+              $request_uid = $user->uid;
+          }
+          else return NULL;
         }
         if ($request_uid) {
-          $block['subject'] = t('Blogroll');
+          $block['subject'] = variable_get('blogroll_title', t('Blogroll'));
           $rolls = db_query("SELECT b.uid, b.name, b.url, b.weight FROM {blogroll} b WHERE b.uid = %d ORDER BY b.weight", $request_uid);
           while ($roll = db_fetch_object($rolls) and ($count < variable_get('blogroll_block_num', '5'))) {
-            $output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a></li>';
-          }
-          $output .= t('</ul>');
-          if ($user->uid == $request_uid) {  // owner viewing own blog
-            $output .= '<div class="more-link">'. l('edit', 'blogroll/edit', array('title' => t('Edit'))) .'</div>';
+            $notempty = TRUE;
+            $output .= '<li><a href="'. check_url($roll->url) .'">'. check_plain($roll->name) .'</a></li>';
           }
+          $output .= '</ul>';
         } else { // for community /blog collection and /blogroll
-          $block['subject'] = t('Community blogroll');
+          $block['subject'] = variable_get('blogroll_title', t('Blogroll'));
           // should handle identical URLs with different names.
           $rolls = db_query_range('SELECT b.name, b.url, count(*) as cnt FROM {blogroll} b GROUP BY b.name, b.url ORDER BY cnt, b.name', 0, variable_get('blogroll_block_num', 5));
           while ($roll = db_fetch_object($rolls)) {
-            $output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a> ('. $roll->cnt .')</li>';
+            $notempty = TRUE;
+            $output .= '<li><a href="'. check_url($roll->url) .'">'. check_plain($roll->name) . '</a>';
+            if (variable_get('blogroll_show_popularity', 1)) {
+            	$output .= ' ('. check_plain($roll->cnt) .')';
+            }
+            $output .= '</li>';
           }
-          $output .= t('</ul>');
-          $output .= '<div class="more-link">'. l('more', 'blogroll', array('title' => t('more'))) .'</div>';
+          $output .= '</ul>';
         }
+        $output .= '<div class="more-link">';
+        if (/*user_access('create blog posts') ||*/ $user->uid == $request_uid) {
+          $output .= l('edit', 'blogroll/edit', array('title' => t('Edit'))) . ' | ';
+        }
+        $output .=  l('more', 'blogroll', array('title' => t('more')));
+        $output .= '</div>';
+
         $block['content'] = $output;
       }
-      return $block;
+      if($user->uid == $request_uid || $notempty) return $block;
   }
 }
 
@@ -211,39 +311,17 @@
  * Menu callback; displays a Drupal page containing all blogrolled blogs
  */
 function blogroll_page($uid = 0) {
-  $output = '<p>'. t('A community blogroll is a list of all the blogs blogrolled by personal bloggers of this site. It is sorted by frequency, then by name. The most frequent blogs may be provided by a block.') .'</p>';
+  $output = '<p>'. variable_get('blogroll_description', t('A community blogroll is a list of all the blogs blogrolled by personal bloggers of this site. It is sorted by frequency, then by name. The most frequent blogs may be provided by a block.')) . '</p>';
   $output .= '<ul>';
   // should handle identical URLs with different names.
   $rolls = db_query('SELECT b.name, b.url, count(*) as cnt FROM {blogroll} b GROUP BY b.name, b.url ORDER BY cnt, b.name');
   while ($roll = db_fetch_object($rolls)) {
-    $output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a> ('. $roll->cnt .')</li>';
+    $output .= '<li><a href="'. $roll->url .'">'. $roll->name . '</a>';
+    if (variable_get('blogroll_show_popularity', 1)) {
+      $output .= '('. $roll->cnt .')';
+    }
+    $output .= '</li>';
   }
   $output .= '</ul>';
-  print theme('page', $output);
-}
-
-
-/**
- * Output a javascript function
- * Called by hook_menu() to "draw" a blogroll
- * If no uid is provided output all user's blogrolls grouped by frequency
- */
-function blogroll_script() {
-  print "<!-- \ndrawroll( \n";
-  if ( arg(2) == "") {	// no userID provided
-    $result = db_query('SELECT name, url, sum(10-weight) as cnt FROM {blogroll} GROUP BY name, url ORDER BY cnt desc, name');
-  }
-  else {
-    $result = db_query('SELECT name, url, weight FROM {blogroll} WHERE uid = %d ORDER BY weight',arg(2));
-  }
-  while ($feed = db_fetch_object($result)) {
-     print "'<a href=\"".$feed->url."\">".$feed->name."</a><br>'+\n";
-  }
-  print "'');\n\n";
-
-  print "function drawroll(s){\n        document.write(s);\n}\n";
-  print "// -->\n";
-
+  return $output;
 }
-
-?>
