| 1 |
<?php |
<?php |
| 2 |
// $Id: blogroll.module,v 1.7 2005/01/29 10:37:15 grantbow Exp $ |
// $Id: blogroll.module,v 1.8 2005/01/30 17:29:16 ahynes1 Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* Enables users to provide and edit a blogroll with their blogs. |
* Enables users to provide a blogroll with their blogs. |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
/** |
/** |
| 10 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 11 |
* |
* |
| 12 |
* @param $section |
* @param $section |
| 13 |
* provides help for /admin/modules and /admin/help. |
* provides help for /admin/modules and /admin/help and admin/settings/blogroll. |
| 14 |
* |
* |
| 15 |
* @return |
* @return |
| 16 |
* A brief message for administrators to explain what this module does |
* A brief message for administrators to explain what this module does |
| 18 |
function blogroll_help($section) { |
function blogroll_help($section) { |
| 19 |
switch ($section) { |
switch ($section) { |
| 20 |
case 'admin/modules#description': |
case 'admin/modules#description': |
| 21 |
return t('Provides users with a blogroll on their blogs.'); |
return t('Provides personal bloggers with a blogroll block and a community blogroll.'); |
| 22 |
case 'admin/help#blogroll': |
case 'admin/help#blogroll': |
| 23 |
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>'; |
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 |
|
case 'admin/settings/blogroll': |
| 25 |
|
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.'); |
| 26 |
} |
} |
| 27 |
} |
} |
| 28 |
|
|
| 41 |
'callback' => 'blogroll_edit', |
'callback' => 'blogroll_edit', |
| 42 |
'access' => user_access('edit own blog'), // depends on blog.module |
'access' => user_access('edit own blog'), // depends on blog.module |
| 43 |
'type' => MENU_CALLBACK); |
'type' => MENU_CALLBACK); |
| 44 |
|
$items[] = array('path' => 'blogroll', 'title' => t('community blogroll'), |
| 45 |
|
'callback' => 'blogroll_page', |
| 46 |
|
'access' => TRUE, |
| 47 |
|
'type' => MENU_CALLBACK); |
| 48 |
$items[] = array('path' => 'blogroll/script', 'title' => t('blogroll'), |
$items[] = array('path' => 'blogroll/script', 'title' => t('blogroll'), |
| 49 |
'callback' => 'blogroll_script', |
'callback' => 'blogroll_script', |
| 50 |
'access' => TRUE, |
'access' => TRUE, |
| 51 |
'type' => MENU_CALLBACK); |
'type' => MENU_CALLBACK); |
| 52 |
} |
} |
| 54 |
} |
} |
| 55 |
|
|
| 56 |
/** |
/** |
| 57 |
|
* Implementation of hook_settings() |
| 58 |
|
* |
| 59 |
|
* @return |
| 60 |
|
* The settings controls |
| 61 |
|
*/ |
| 62 |
|
function blogroll_settings() { |
| 63 |
|
// add a checkbox for showing/hiding cnt for each url? |
| 64 |
|
$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.') ); |
| 65 |
|
return form_group(t('Community blogroll block settings'), $group); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
|
/** |
| 69 |
* Prepare the blogroll display portion of the page |
* Prepare the blogroll display portion of the page |
| 70 |
*/ |
*/ |
| 71 |
function blogroll_edit_display($edit, $uid) { |
function blogroll_edit_display($edit, $uid) { |
| 72 |
$output = '<p>'. t('Your blogroll is shown on your blog\'s page. After making changes click \'Update blogs.\'.') .'</p>'; |
$output = '<p>'. t('After making changes click \'Update blogs.\'.') .'</p>'; |
| 73 |
|
|
| 74 |
// display roll_form with it's table |
// display roll_form with it's table |
| 75 |
$roll_form = ''; |
$roll_form = ''; |
| 88 |
$rows[] = array( |
$rows[] = array( |
| 89 |
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') |
| 90 |
); |
); |
| 91 |
|
$roll_form .= theme('table', $header, $rows); |
| 92 |
|
} else { |
| 93 |
|
$roll_form .= theme('table', $header, $rows); |
| 94 |
|
$roll_form .= form_submit(t('Update blogs')); |
| 95 |
} |
} |
|
$roll_form .= theme('table', $header, $rows); |
|
|
$roll_form .= form_submit(t('Update blogs')); |
|
| 96 |
$output .= form($roll_form, 'post', url('blogroll/edit')); |
$output .= form($roll_form, 'post', url('blogroll/edit')); |
| 97 |
return form_group(t('Current blogs'), $output); |
return form_group(t('Current blogs'), $output); |
| 98 |
} |
} |
| 141 |
case 'Update blogs': |
case 'Update blogs': |
| 142 |
foreach ($edit as $url => $roll) { |
foreach ($edit as $url => $roll) { |
| 143 |
if ($roll['delete']) { |
if ($roll['delete']) { |
| 144 |
db_query("DELETE from {blogroll} where uid = '%d' and url= '%s'", $uid, $url); |
db_query("DELETE from {blogroll} b WHERE b.uid = '%d' and b.url= '%s'", $uid, $url); |
| 145 |
} else { |
} else { |
| 146 |
db_query("UPDATE {blogroll} SET name = '%s', weight = %d WHERE uid = '%d' AND url = '%s'", $roll['name'], $roll['weight'], $uid, $url); |
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); |
| 147 |
} |
} |
| 148 |
}; |
}; |
| 149 |
drupal_set_message( t('Your blogrolls have been updated.')); |
drupal_set_message( t('Your blogrolls have been updated.')); |
| 177 |
return $block; |
return $block; |
| 178 |
case('view'): |
case('view'): |
| 179 |
if (user_access('access content')) { |
if (user_access('access content')) { |
|
$block['subject'] = t('Blogroll'); |
|
| 180 |
|
|
| 181 |
$output = '<ul>'; |
$output = '<ul>'; |
| 182 |
$request_uid = arg(1); // arg(1), won't work when URL is non-numeric or viewing a blog node |
$request_uid = arg(1); // arg(1), won't work when URL is non-numeric or viewing a blog node |
| 183 |
if ($request_uid) { |
if ($request_uid) { |
| 184 |
$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); |
$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); |
| 185 |
while ($roll = db_fetch_object($rolls)) { |
while ($roll = db_fetch_object($rolls) and ($count < variable_get('blogroll_block_num', '5'))) { |
| 186 |
$output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a></li>'; |
$output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a></li>'; |
| 187 |
} |
} |
| 188 |
|
$output .= t('</ul>'); |
| 189 |
|
if ($user->uid == $request_uid) { // owner viewing own blog |
| 190 |
|
$output .= '<div class="more-link">'. l('edit', 'blogroll/edit', array('title' => t('Edit'))) .'</div>'; |
| 191 |
|
} |
| 192 |
} else { // for community /blog collection |
} else { // for community /blog collection |
| 193 |
$rolls = db_query('SELECT name, url, sum(10-weight) as wgt, count(*) as cnt FROM {blogroll} GROUP BY name, url ORDER BY wgt desc, name'); |
// should handle identical URLs with different names. |
| 194 |
|
$rolls = db_query_range('SELECT name, url, count(*) as cnt FROM {blogroll} GROUP BY name, url ORDER BY cnt, name', 0, variable_get('blogroll_block_num', 5)); |
| 195 |
while ($roll = db_fetch_object($rolls)) { |
while ($roll = db_fetch_object($rolls)) { |
| 196 |
$output .= '<li><a href="' . $roll->url .'">'. $roll->name .'</a> ('. $roll->cnt .')</li>'; |
$output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a> ('. $roll->cnt .')</li>'; |
| 197 |
} |
} |
| 198 |
|
$output .= t('</ul>'); |
| 199 |
|
$output .= '<div class="more-link">'. l('more', 'blogroll', array('title' => t('more'))) .'</div>'; |
| 200 |
} |
} |
| 201 |
$output .= t('</ul>'); |
$block['subject'] = t('Blogroll'); |
|
if ($user->uid == $request_uid) { // owner viewing own blog |
|
|
$output .= '<div class="more-link">'. l('edit', 'blogroll/edit', array('title' => t('Edit blogroll'))) .'</div>'; |
|
|
} |
|
| 202 |
$block['content'] = $output; |
$block['content'] = $output; |
| 203 |
} |
} |
| 204 |
return $block; |
return $block; |
| 206 |
} |
} |
| 207 |
|
|
| 208 |
/** |
/** |
| 209 |
|
* Menu callback; displays a Drupal page containing all blogrolled blogs |
| 210 |
|
*/ |
| 211 |
|
function blogroll_page($uid = 0) { |
| 212 |
|
$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>'; |
| 213 |
|
$output .= '<ul>'; |
| 214 |
|
// should handle identical URLs with different names. |
| 215 |
|
$rolls = db_query('SELECT name, url, count(*) as cnt FROM {blogroll} GROUP BY name, url ORDER BY cnt, name'); |
| 216 |
|
while ($roll = db_fetch_object($rolls)) { |
| 217 |
|
$output .= '<li><a href="'. $roll->url .'">'. $roll->name .'</a> ('. $roll->cnt .')</li>'; |
| 218 |
|
} |
| 219 |
|
$output .= '</ul>'; |
| 220 |
|
print theme('page', $output); |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
|
| 224 |
|
/** |
| 225 |
* Output a javascript function |
* Output a javascript function |
| 226 |
* Called by hook_menu() to "draw" a blogroll |
* Called by hook_menu() to "draw" a blogroll |
| 227 |
* If no uid is provided output all user's blogrolls grouped by frequency |
* If no uid is provided output all user's blogrolls grouped by frequency |