/[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.5, Tue Jan 11 02:24:42 2005 UTC revision 1.6, Tue Jan 11 23:40:15 2005 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: blogroll.module,v 1.4 2005/01/11 01:29:36 grantbow Exp $  // $Id: blogroll.module,v 1.5 2005/01/11 02:24:42 grantbow Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 8  Line 8 
8    
9  /**  /**
10   * Implementation of hook_help().   * Implementation of hook_help().
11     *
12     * @param $section
13     *   provides help for /admin/modules and /admin/help.
14     *
15     * @return
16     *   A brief message for administrators to explain what this module does
17   */   */
18  function blogroll_help($section) {  function blogroll_help($section) {
19    switch ($section) {    switch ($section) {
   
     // Brief message for administrators to explain what this module does  
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':
# Line 22  function blogroll_help($section) { Line 26  function blogroll_help($section) {
26    
27  /**  /**
28   * Implementation of hook_menu().   * Implementation of hook_menu().
29     *
30     * @return
31     *   Arrays containing paths to be accessed.
32   */   */
33  function blogroll_menu($may_cache) {  function blogroll_menu($may_cache) {
34    global $user;    global $user;
35    $items = array();    $items = array();
36    
37    $items[] = array('path' => 'blogroll/edit', 'title' => t('edit blogroll'),    if ($may_cache) {
38      'callback' => 'blogroll_edit',      $items[] = array('path' => 'blogroll/edit', 'title' => t('edit blogroll'),
39      'access' => user_access('edit own blog'), // depends on blog.module        'callback' => 'blogroll_edit',
40      'type' => MENU_CALLBACK);        'access' => user_access('edit own blog'), // depends on blog.module
41    $items[] = array('path' => 'blogroll/script', 'title' => t('blogroll'),        'type' => MENU_CALLBACK);
42      'callback' => 'blogroll_script',      $items[] = array('path' => 'blogroll/script', 'title' => t('blogroll'),
43      'access' => TRUE,        'callback' => 'blogroll_script',
44      'type' => MENU_CALLBACK);        'access' => TRUE,
45          'type' => MENU_CALLBACK);
46      }
47    return $items;    return $items;
48  }  }
49    
50  /**  /**
51   * Menu callback; form for editing one's blogroll.   * Menu callback; prints the form form for editing one's blogroll.
52     *
53     * @param $uid
54     *   User ID number.  If omitted, uid 0 is used.
55   */   */
56  function blogroll_edit($uid = 0) {  function blogroll_edit($uid = 0) {
57    global $user;    global $user;
# Line 59  function blogroll_edit($uid = 0) { Line 71  function blogroll_edit($uid = 0) {
71    
72    // display blogroll table    // display blogroll table
73    $header = array(t('Rolled blogs'), t('Weight'), t('Actions'));    $header = array(t('Rolled blogs'), t('Weight'), t('Actions'));
74    $rolls = db_query("SELECT b.uid, b.name, b.url, b.weight FROM {blogroll} b WHERE b.uid = %d", $user->uid);    $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);
75    while ($roll = db_fetch_object($rolls)) {    while ($roll = db_fetch_object($rolls)) {
76      $form  = form_hidden('action', 'del');      $form  = form_hidden('action', 'del');
77      $form .= form_hidden('url', $roll->url);      $form .= form_hidden('url', $roll->url);
# Line 93  function blogroll_edit($uid = 0) { Line 105  function blogroll_edit($uid = 0) {
105  }  }
106    
107  /**  /**
108   * Implementation of hook_block(); generates a block containing the blogroll.   * Implementation of hook_block();
109     *
110     * @param $op
111     *   Operation 'list' or 'view'.  If omitted 'list' is used.
112     * @param $delta
113     *   If omitted, 0 is used.
114     *
115     * @return a block containing the blogroll
116   */   */
117  function blogroll_block($op = 'list', $delta = 0) {  function blogroll_block($op = 'list', $delta = 0) {
118    global $user;    global $user;
# Line 104  function blogroll_block($op = 'list', $d Line 123  function blogroll_block($op = 'list', $d
123      case('view'):      case('view'):
124        if (user_access('access content')) {        if (user_access('access content')) {
125          $output = '<ul>';          $output = '<ul>';
126          $request_uid = arg(1); // arg(1)          $request_uid = arg(1); // arg(1), won't work when URL is non-numeric.
127          $rolls = db_query("SELECT b.uid, b.name, b.url FROM {blogroll} b WHERE b.uid = %d", $request_uid);          $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);
128          while ($roll = db_fetch_object($rolls)) {          while ($roll = db_fetch_object($rolls)) {
129            $output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a></li>';            $output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a></li>';
130          }          }
# Line 131  function blogroll_script() { Line 150  function blogroll_script() {
150      $result = db_query('SELECT name, url, count(*) as cnt FROM {blogroll} GROUP BY name, url ORDER BY cnt desc, name');      $result = db_query('SELECT name, url, count(*) as cnt FROM {blogroll} GROUP BY name, url ORDER BY cnt desc, name');
151    }    }
152    else {    else {
153      $result = db_query('SELECT name, url FROM {blogroll} WHERE uid = %d ORDER BY name',arg(2));      $result = db_query('SELECT name, url, weight FROM {blogroll} WHERE uid = %d ORDER BY weight',arg(2));
154    }    }
155    while ($feed = db_fetch_object($result)) {    while ($feed = db_fetch_object($result)) {
156       print "'<a href=".$feed->url.">".$feed->name."</a><br>'+\n";       print "'<a href=".$feed->url.">".$feed->name."</a><br>'+\n";

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

  ViewVC Help
Powered by ViewVC 1.1.2