/[drupal]/contributions/modules/blogroll/blogroll.module
ViewVC logotype

Diff of /contributions/modules/blogroll/blogroll.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.6, Tue Jan 11 23:40:15 2005 UTC revision 1.7, Sat Jan 29 10:37:15 2005 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: blogroll.module,v 1.5 2005/01/11 02:24:42 grantbow Exp $  // $Id: blogroll.module,v 1.6 2005/01/11 23:40:15 grantbow Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 20  function blogroll_help($section) { Line 20  function blogroll_help($section) {
20      case 'admin/modules#description':      case 'admin/modules#description':
21        return t('Provides users with a blogroll on their blogs.');        return t('Provides users with a blogroll on their blogs.');
22      case 'admin/help#blogroll':      case 'admin/help#blogroll':
23        return t('<p>The blogroll block must be enabled.</p><p>Only blog owners may edit their blogroll. Click \"add\" in the block or click \"remove\" next to any blog to perform those actions.</p>');        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>';
24    }    }
25  }  }
26    
# Line 48  function blogroll_menu($may_cache) { Line 48  function blogroll_menu($may_cache) {
48  }  }
49    
50  /**  /**
51   * Menu callback; prints the form form for editing one's blogroll.   * Prepare the blogroll display portion of the page
  *  
  * @param $uid  
  *   User ID number.  If omitted, uid 0 is used.  
52   */   */
53  function blogroll_edit($uid = 0) {  function blogroll_edit_display($edit, $uid) {
54    global $user;    $output = '<p>'. t('Your blogroll is shown on your blog\'s page. After making changes click \'Update blogs.\'.') .'</p>';
   
   $edit = $_POST['edit'];  
   
   // process post data  
   if ($edit['action'] == 'add' and $edit['url'] and $edit['name']) {  
     // if ! 404 $edit[url] {}  
     db_query("INSERT into {blogroll} values('%d', '%s', '%s', '0')", $user->uid, $edit['url'], $edit['name']);  
   }  
   if ($edit['action'] == 'del' and $edit['url'] ) {  
     db_query("DELETE from {blogroll} where uid = '%d' and url= '%s'", $user->uid, $edit['url']);  
   }  
   
   $output = t('<p>This page allows you to view and edit the blogs in your blogroll. By default your blogroll is only shown on your blog\'s html page. </p>');  
55    
56    // display blogroll table    // display roll_form with it's table
57    $header = array(t('Rolled blogs'), t('Weight'), t('Actions'));    $roll_form = '';
58    $rolls = db_query("SELECT b.uid, b.name, b.url, b.weight FROM {blogroll} b WHERE b.uid = %d ORDER BY b.weight", $user->uid);    $header = array(t('Delete'), t('URL'), t('Name'), t('Weight'));
59      $rolls = db_query("SELECT b.uid, b.name, b.url, b.weight FROM {blogroll} b WHERE b.uid = %d ORDER BY b.weight", $uid);
60    while ($roll = db_fetch_object($rolls)) {    while ($roll = db_fetch_object($rolls)) {
61      $form  = form_hidden('action', 'del');      // little $delete_form for delete buttons
     $form .= form_hidden('url', $roll->url);  
     $form .= form_hidden('name', $roll->name);  
     $form .= form_submit(t('Delete'));  
62      $rows[] = array(      $rows[] = array(
63        array('data' => '<a href="'. $roll->url .'">'. $roll->name .'</a>', 'class' => 'rolled_blogs'),        array('data' => form_checkbox(NULL, $roll->url .'][delete', 1, 0), 'align' => 'center', 'class' => 'delete'),
64        array('data' => $roll->weight, 'class' => 'weight'),        array('data' => $roll->url, 'class' => 'url'),
65        // weight: +-10 , see modules/block.module for how to do it well.        array('data' => form_textfield(NULL, $roll->url .'][name', $roll->name, 30, 128), 'class' => 'name'),
66        array('data' => form($form, 'post', url('blogroll/edit')), 'class' => 'actions')        array('data' => form_weight(NULL, $roll->url .'][weight', $roll->weight), 'class' => 'weight')
67      );      );
68    }    }
69    if (!$rows) {    if (!$rows) {
# Line 89  function blogroll_edit($uid = 0) { Line 71  function blogroll_edit($uid = 0) {
71        array('data' => t('No blogs available in your blogroll.'), 'class' => 'no_blogrolls', 'colspan' => '3')        array('data' => t('No blogs available in your blogroll.'), 'class' => 'no_blogrolls', 'colspan' => '3')
72      );      );
73    }    }
74    $output .= theme('table', $header, $rows);    $roll_form .= theme('table', $header, $rows);
75      $roll_form .= form_submit(t('Update blogs'));
76      $output .= form($roll_form, 'post', url('blogroll/edit'));
77      return form_group(t('Current blogs'), $output);
78    }
79    
80    $output .= t('<br /><p>To add a blog to your blogroll enter the information and click \'Add blog.\'</p>');  /**
81    // add url and name   * Prepare the blogroll adding portion of the page
82    $form  = "<div class=\"blogroll-edit-form\">\n";   */
83    $form .= form_hidden('action', 'add');  function blogroll_edit_add_form($edit) {
84    $form .= form_textfield(t('Blog url'), 'url', $edit['url'], 64, 64);    $edit['url'] = 'http://';
85    $form .= form_textfield(t('Blog name'), 'name', $edit['name'], 64, 64);    $output = '<br /><p>'. t('After adding click \'Add blog.\'') .'</p>';
86      // user inputs for url and name
87      $header = array(t('URL'), t('Name'), t('Weight'));
88      $row[] = array(
89        array('data' => form_textfield(NULL, 'url', $edit['url'], 50, 128), 'class' => 'url'),
90        array('data' => form_textfield(NULL, 'name', $edit['name'], 30, 128), 'class' => 'name'),
91        array('data' => form_weight(NULL, 'weight', $edit['weight']), 'class' => 'weight')
92      );
93      $form  = theme('table', $header, $row);
94    $form .= form_submit(t('Add blog'));    $form .= form_submit(t('Add blog'));
   $form .= "</div>\n";  
95    $output .= form($form, 'post', url('blogroll/edit'));    $output .= form($form, 'post', url('blogroll/edit'));
96      return form_group(t('New blog'), $output);
97    }
98    
99    /**
100     * Menu callback; displays the blogroll editing page
101     */
102    function blogroll_edit() {
103      global $user;
104    
105      $output = '';
106      $uid = $user->uid;
107      $edit = $_POST['edit'];
108      $op = $_POST['op'];
109    
110      if ($uid) {
111        // process post data
112        switch($op) {
113          case 'Add blog':
114            if ($edit['url'] and $edit['name']) {
115              // if ! 404 $edit[url] {};
116              db_query("INSERT into {blogroll} values ('%d', '%s', '%s', '%d')", $uid, $edit['url'], $edit['name'], $edit['weight']);
117              drupal_set_message( t('The blog was added.'));
118              cache_clear_all();
119              drupal_goto('blogroll/edit');
120            }
121          case 'Update blogs':
122            foreach ($edit as $url => $roll) {
123              if ($roll['delete']) {
124                db_query("DELETE from {blogroll} where uid = '%d' and url= '%s'", $uid, $url);
125              } else {
126                db_query("UPDATE {blogroll} SET name = '%s', weight = %d WHERE uid = '%d' AND url = '%s'", $roll['name'], $roll['weight'], $uid, $url);
127              }
128            };
129            drupal_set_message( t('Your blogrolls have been updated.'));
130            cache_clear_all();
131            drupal_goto('blogroll/edit');
132        }
133    
134        $output  = '<p>'. t('Your blogroll is shown on your personal blog\'s page.') .'</p>';
135        $output .= blogroll_edit_display($edit, $uid);
136        $output .= blogroll_edit_add_form($edit);
137      }
138    
139    print theme('page', $output);    print theme('page', $output);
140  }  }
# Line 122  function blogroll_block($op = 'list', $d Line 157  function blogroll_block($op = 'list', $d
157        return $block;        return $block;
158      case('view'):      case('view'):
159        if (user_access('access content')) {        if (user_access('access content')) {
160            $block['subject'] = t('Blogroll');
161    
162          $output = '<ul>';          $output = '<ul>';
163          $request_uid = arg(1); // arg(1), won't work when URL is non-numeric.          $request_uid = arg(1); // arg(1), won't work when URL is non-numeric or viewing a blog node
164          $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);          if ($request_uid) {
165          while ($roll = db_fetch_object($rolls)) {            $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);
166            $output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a></li>';            while ($roll = db_fetch_object($rolls)) {
167                $output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a></li>';
168              }
169            } else { // for community /blog collection
170              $rolls = db_query('SELECT name, url, count(*) as cnt FROM {blogroll} GROUP BY name, url ORDER BY cnt desc, name');
171              while ($roll = db_fetch_object($rolls)) {
172                $output .= '<li><a href="' . $roll->url .'">'. $roll->name .'</a> ('. $roll->cnt .')</li>';
173              }
174          }          }
175          $output .= t('</ul>');          $output .= t('</ul>');
176          if ($user->uid == $request_uid) {  // owner viewing own blog          if ($user->uid == $request_uid) {  // owner viewing own blog
177            $output .= '<div class="more-link">'. l('edit', 'blogroll/edit', array('title' => t('Edit blogroll'))) .'</div>';            $output .= '<div class="more-link">'. l('edit', 'blogroll/edit', array('title' => t('Edit blogroll'))) .'</div>';
178          }          }
         $block['subject'] = t('Blogroll');  
179          $block['content'] = $output;          $block['content'] = $output;
180        }        }
181        return $block;        return $block;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

  ViewVC Help
Powered by ViewVC 1.1.2