Index: modules/blogroll/blogroll.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/blogroll/blogroll.module,v
retrieving revision 1.10
diff -u -r1.10 blogroll.module
--- modules/blogroll/blogroll.module	31 Jan 2005 02:37:41 -0000	1.10
+++ modules/blogroll/blogroll.module	25 Nov 2005 20:54:52 -0000
@@ -38,14 +38,14 @@
 
   if ($may_cache) {
     $items[] = array('path' => 'blogroll/edit', 'title' => t('edit blogroll'),
-      'callback' => 'blogroll_edit',
+      'callback' => 'blogroll_edit_page',
       '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,
       'type' => MENU_CALLBACK);
-    $items[] = array('path' => 'blogroll/script', 'title' => t('blogroll'),
+    $items[] = array('path' => 'blogroll/script', 'title' => variable_get('blogroll_title', t('Blogroll')),
       'callback' => 'blogroll_script',
       'access' => TRUE,
       'type' => MENU_CALLBACK);
@@ -61,103 +61,194 @@
  */
 function blogroll_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 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.')),
+  );
+  $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 $form;
+}
+
+/**
+ * Menu callback; displays the blogroll editing page
+ */
+function blogroll_edit_page() {
+  global $user;
+  $output = '';
+
+  if ($user->uid) {
+    $output  = '<p>'. t('Your blogroll is shown on your personal blog\'s page.') .'</p>';
+    $output .= blogroll_edit_form($user->uid);
+    $output .= blogroll_edit_add_form();
+  }
+
+  print theme('page', $output);
 }
 
 /**
  * Prepare the blogroll display portion of the page
  */
-function blogroll_edit_display($edit, $uid) {
+function blogroll_edit_form($uid) {
   $output = '<p>'. t('After making changes click \'Update blogs.\'.') .'</p>';
 
   // display roll_form with it's table
-  $roll_form = '';
-  $header = array(t('Delete'), t('URL'), t('Name'), t('Weight'));
+  //$header = array(t('Delete'), t('URL'), t('Name'), t('Weight'));
   $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')
+    $form['old'][$roll->url]['delete'] = array(
+      '#type' => 'checkbox',
+      '#default_value' => 0,
+      '#return_value' => 1,
     );
-  }
-  if (!$rows) {
-    $rows[] = array(
-      array('data' => t('No blogs available in your blogroll.'), 'class' => 'no_blogrolls', 'colspan' => '3')
+
+    $form['old'][$roll->url]['url'] = array(
+      '#type' => 'markup',
+      '#value' => $roll->url,
+    );
+
+    $form['old'][$roll->url]['name'] = array(
+      '#type' => 'textfield',
+      '#maxlength' => 128,
+      '#size' => 25,
+      '#default_value' => $roll->name,
+    );
+
+    $form['old'][$roll->url]['weight'] = array(
+      '#type' => 'weight',
+      '#default_value' => $roll->weight,
     );
-    $roll_form .= theme('table', $header, $rows);
-  } else {
-    $roll_form .= theme('table', $header, $rows);
-    $roll_form .= form_submit(t('Update blogs'));
   }
-  $output .= form($roll_form, 'post', url('blogroll/edit'));
-  return form_group(t('Current blogs'), $output);
+  
+  $form['#tree'] = true;
+  
+  $form['buttons']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Update blogs'),
+  );
+  
+  return drupal_get_form('blogroll_edit', $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']['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['buttons']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Add blog'),
+  );
+
+  return drupal_get_form('blogroll_edit_add', $form);
 }
 
-/**
- * Menu callback; displays the blogroll editing page
- */
-function blogroll_edit() {
+function blogroll_edit_add_execute($form_id, $edit) {
   global $user;
+  $uid = $user->uid;  
+  // process post data
+  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');
+    drupal_set_message( t('Your blogrolls have been updated.'));
+    cache_clear_all();
+    drupal_goto('blogroll/edit');
+  }
+}
 
-  $output = '';
+function blogroll_edit_execute($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
+  foreach ($edit['old'] as $url => $roll) {
+    if ($roll['delete'] == 1) {
+      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');
+}
 
-    $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) {
+  $output = '<br /><p>'. t('Add a new blog to your blogroll:') .'</p>';
+  
+  $header = array(t('URL'), t('Name'), t('Weight'));
+  
+  $row = array();
+  $row[] = form_render($form['new']['url']);
+  $row[] = form_render($form['new']['name']);
+  $row[] = form_render($form['new']['weight']);
+  
+  $rows = array($row);
+  
+  $output .= theme('table', $header, $rows);
+  $output .= form_render($form);
+  return $output;
+}
 
-  print theme('page', $output);
+function theme_blogroll_edit($form) {
+  $header = array(t('Delete'), t('URL'), t('Name'), t('Weight'));  
+  foreach (element_children($form['old']) as $key) {
+    $row = array();
+    $row[] = form_render($form['old'][$key]['delete']);
+    $row[] = form_render($form['old'][$key]['url']);
+    $row[] = form_render($form['old'][$key]['name']);
+    $row[] = form_render($form['old'][$key]['weight']);
+    $rows[] = $row;
+  }
+  
+  if (!$rows) {
+    $rows[] = array(
+      array('data' => t('No blogs available in your blogroll.'), 'class' => 'no_blogrolls', 'colspan' => '3')
+    );
+  }
+  
+  $output .= theme('table', $header, $rows);
+  $output .= form_render($form);
+  return $output;
 }
 
+
 /**
  * Implementation of hook_block();
  *
@@ -182,25 +273,32 @@
             $request_uid = $user->uid;
         }
         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>';
-          }
+          $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>';
+            $output .= '<li><a href="'. $roll->url .'">'. $roll->name . '</a>';
+            if (variable_get('blogroll_show_popularity', 1)) {
+            	$output .= '('. $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('edit own blog') || $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;
@@ -211,12 +309,16 @@
  * 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);
@@ -246,4 +348,3 @@
 
 }
 
-?>
