| 1 |
<?php |
<?php |
| 2 |
// $Id: follow.module,v 1.3 2009/10/30 21:09:28 pwolanin Exp $ |
// $Id: follow.module,v 1.4 2009/10/30 21:13:50 pwolanin Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 74 |
} |
} |
| 75 |
|
|
| 76 |
/** |
/** |
| 77 |
* Implementation of hook_perm(). |
* Implementation of hook_permission(). |
| 78 |
*/ |
*/ |
| 79 |
function follow_permission() { |
function follow_permission() { |
| 80 |
return array( |
return array( |
| 117 |
} |
} |
| 118 |
|
|
| 119 |
/** |
/** |
| 120 |
* Implementation of hook_block(). |
* Implementation of hook_block_info(). |
| 121 |
*/ |
*/ |
| 122 |
function follow_block($op = 'list', $delta = 'site', $edit = array()) { |
function follow_block_info() { |
| 123 |
if ($op == 'list') { |
$blocks['site'] = array( |
| 124 |
$blocks['site'] = array( |
'info' => t('Follow Site'), |
| 125 |
'info' => t('Follow Site'), |
'cache' => DRUPAL_CACHE_GLOBAL, |
| 126 |
'cache' => BLOCK_CACHE_GLOBAL, |
); |
|
); |
|
| 127 |
|
|
| 128 |
$blocks['user'] = array( |
$blocks['user'] = array( |
| 129 |
'info' => t('Follow User'), |
'info' => t('Follow User'), |
| 130 |
'cache' => BLOCK_CACHE_PER_PAGE, |
'cache' => DRUPAL_CACHE_PER_PAGE, |
| 131 |
); |
); |
| 132 |
|
|
| 133 |
return $blocks; |
return $blocks; |
| 134 |
} |
} |
|
elseif ($op == 'configure') { |
|
|
switch($delta) { |
|
|
case 'site': |
|
|
$form['follow_title'] = array( |
|
|
'#type' => 'radios', |
|
|
'#title' => t('Default block title'), |
|
|
'#default_value' => variable_get('follow_site_block_title', FOLLOW_NAME), |
|
|
'#options' => array( |
|
|
FOLLOW_NAME => t('Follow @name on', array('@name' => variable_get('site_name', 'Drupal'))), |
|
|
FOLLOW_ME => t('Follow me on'), |
|
|
FOLLOW_US => t('Follow us on'), |
|
|
), |
|
|
); |
|
|
$form['follow_user'] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#title' => t('User pages'), |
|
|
'#description' => t('Should this block display on user profile pages?'), |
|
|
'#default_value' => variable_get('follow_site_block_user', TRUE), |
|
|
); |
|
|
return $form; |
|
| 135 |
|
|
| 136 |
case 'user': |
|
| 137 |
$form['follow_title'] = array( |
/** |
| 138 |
'#type' => 'radios', |
* Implementation of hook_block_configure(). |
| 139 |
'#title' => t('Default block title'), |
*/ |
| 140 |
'#default_value' => variable_get('follow_user_block_title', FOLLOW_NAME), |
function follow_block_configure($delta = '') { |
| 141 |
'#options' => array( |
switch($delta) { |
| 142 |
FOLLOW_NAME => t('Follow [username] on'), |
case 'site': |
| 143 |
FOLLOW_ME => t('Follow me on'), |
$form['follow_title'] = array( |
| 144 |
), |
'#type' => 'radios', |
| 145 |
); |
'#title' => t('Default block title'), |
| 146 |
return $form; |
'#default_value' => variable_get('follow_site_block_title', FOLLOW_NAME), |
| 147 |
} |
'#options' => array( |
| 148 |
|
FOLLOW_NAME => t('Follow @name on', array('@name' => variable_get('site_name', 'Drupal'))), |
| 149 |
|
FOLLOW_ME => t('Follow me on'), |
| 150 |
|
FOLLOW_US => t('Follow us on'), |
| 151 |
|
), |
| 152 |
|
); |
| 153 |
|
$form['follow_user'] = array( |
| 154 |
|
'#type' => 'checkbox', |
| 155 |
|
'#title' => t('User pages'), |
| 156 |
|
'#description' => t('Should this block display on user profile pages?'), |
| 157 |
|
'#default_value' => variable_get('follow_site_block_user', TRUE), |
| 158 |
|
); |
| 159 |
|
return $form; |
| 160 |
|
|
| 161 |
|
case 'user': |
| 162 |
|
$form['follow_title'] = array( |
| 163 |
|
'#type' => 'radios', |
| 164 |
|
'#title' => t('Default block title'), |
| 165 |
|
'#default_value' => variable_get('follow_user_block_title', FOLLOW_NAME), |
| 166 |
|
'#options' => array( |
| 167 |
|
FOLLOW_NAME => t('Follow [username] on'), |
| 168 |
|
FOLLOW_ME => t('Follow me on'), |
| 169 |
|
), |
| 170 |
|
); |
| 171 |
|
return $form; |
| 172 |
} |
} |
| 173 |
elseif ($op == 'save') { |
} |
| 174 |
variable_set('follow_'. $delta .'_block_title', $edit['follow_title']); |
|
| 175 |
if ($delta == 'site') { |
/** |
| 176 |
variable_set('follow_site_block_user', $edit['follow_user']); |
* Implementation of hook_block_save(). |
| 177 |
} |
*/ |
| 178 |
|
function follow_block_save($delta = '', $edit = array()) { |
| 179 |
|
variable_set('follow_'. $delta .'_block_title', $edit['follow_title']); |
| 180 |
|
if ($delta == 'site') { |
| 181 |
|
variable_set('follow_site_block_user', $edit['follow_user']); |
| 182 |
} |
} |
| 183 |
elseif ($op == 'view') { |
} |
| 184 |
switch ($delta) { |
|
| 185 |
case 'site': |
/** |
| 186 |
if (($content = _follow_block_content()) |
* Implementation of hook_block_view(). |
| 187 |
&& (variable_get('follow_site_block_user', TRUE) || !(arg(0) == 'user' && is_numeric(arg(1))))) { |
*/ |
| 188 |
return array( |
function follow_block_view($delta = '') { |
| 189 |
'subject' => _follow_block_subject(), |
switch ($delta) { |
| 190 |
'content' => $content, |
case 'site': |
| 191 |
); |
if (($content = _follow_block_content()) |
| 192 |
} |
&& (variable_get('follow_site_block_user', TRUE) || !(arg(0) == 'user' && is_numeric(arg(1))))) { |
| 193 |
break; |
return array( |
| 194 |
case 'user': |
'subject' => _follow_block_subject(), |
| 195 |
$uid = arg(1); |
'content' => $content, |
| 196 |
if (arg(0) == 'user' && is_numeric($uid) && ($content = _follow_block_content($uid))) { |
); |
| 197 |
return array( |
} |
| 198 |
'subject' => _follow_block_subject($uid), |
break; |
| 199 |
'content' => $content, |
case 'user': |
| 200 |
); |
$uid = arg(1); |
| 201 |
} |
if (arg(0) == 'user' && is_numeric($uid) && ($content = _follow_block_content($uid))) { |
| 202 |
break; |
return array( |
| 203 |
} |
'subject' => _follow_block_subject($uid), |
| 204 |
|
'content' => $content, |
| 205 |
|
); |
| 206 |
|
} |
| 207 |
|
break; |
| 208 |
} |
} |
| 209 |
} |
} |
| 210 |
|
|
| 300 |
* |
* |
| 301 |
* @ingroup themable |
* @ingroup themable |
| 302 |
*/ |
*/ |
| 303 |
function theme_follow_link($link, $title) { |
function theme_follow_link($variables) { |
| 304 |
|
$link = $variables['link']; |
| 305 |
|
$title = $variables['title']; |
| 306 |
$classes = array(); |
$classes = array(); |
| 307 |
$classes[] = 'follow-link'; |
$classes[] = 'follow-link'; |
| 308 |
$classes[] = "follow-link-{$link->name}"; |
$classes[] = "follow-link-{$link->name}"; |
| 309 |
$classes[] = $link->uid ? 'follow-link-user' : 'follow-link-site'; |
$classes[] = $link->uid ? 'follow-link-user' : 'follow-link-site'; |
| 310 |
$attributes = drupal_attributes(array( |
$attributes = array( |
| 311 |
'class' => implode(' ', $classes), |
'class' => implode(' ', $classes), |
|
'href' => $link->url, |
|
| 312 |
'title' => follow_link_title($link->uid) .' '. $title, |
'title' => follow_link_title($link->uid) .' '. $title, |
| 313 |
)); |
); |
| 314 |
|
|
| 315 |
return "<a$attributes>$title</a>\n"; |
return l($title, $link->url, array('attributes' => $attributes)) . "\n"; |
| 316 |
} |
} |
| 317 |
|
|
| 318 |
/** |
/** |
| 329 |
if ($uid == 0 && user_access('edit site follow links')) { |
if ($uid == 0 && user_access('edit site follow links')) { |
| 330 |
$links['follow_edit'] = array( |
$links['follow_edit'] = array( |
| 331 |
'title' => t('Edit'), |
'title' => t('Edit'), |
| 332 |
'href' => 'admin/build/follow', |
'href' => 'admin/config/services/follow', |
| 333 |
'query' => drupal_get_destination(), |
'query' => drupal_get_destination(), |
| 334 |
); |
); |
| 335 |
} |
} |
| 344 |
if (user_access('administer blocks')) { |
if (user_access('administer blocks')) { |
| 345 |
$links['follow_configure'] = array( |
$links['follow_configure'] = array( |
| 346 |
'title' => t('Configure'), |
'title' => t('Configure'), |
| 347 |
'href' => $uid ? 'admin/build/block/configure/follow/user' : 'admin/build/block/configure/follow/site', |
'href' => $uid ? 'admin/structure/block/configure/follow/user' : 'admin/structure/block/configure/follow/site', |
| 348 |
'query' => drupal_get_destination(), |
'query' => drupal_get_destination(), |
| 349 |
); |
); |
| 350 |
} |
} |
| 480 |
if (isset($form['follow_links'][$key]['weight'])) { |
if (isset($form['follow_links'][$key]['weight'])) { |
| 481 |
$row[] = drupal_render($form['follow_links'][$key]['lid']) . drupal_render($form['follow_links'][$key]['name']); |
$row[] = drupal_render($form['follow_links'][$key]['lid']) . drupal_render($form['follow_links'][$key]['name']); |
| 482 |
$row[] = drupal_render($form['follow_links'][$key]['url']); |
$row[] = drupal_render($form['follow_links'][$key]['url']); |
| 483 |
|
|
| 484 |
// Now, render the weight row. |
// Now, render the weight row. |
| 485 |
$form['follow_links'][$key]['weight']['#attributes']['class'] = 'follow-links-weight'; |
$form['follow_links'][$key]['weight']['#attributes']['class'] = 'follow-links-weight'; |
| 486 |
$row[] = drupal_render($form['follow_links'][$key]['weight']); |
$row[] = drupal_render($form['follow_links'][$key]['weight']); |
| 487 |
|
|
| 488 |
// Add the new row to our collection of rows, and give it the 'draggable' class. |
// Add the new row to our collection of rows, and give it the 'draggable' class. |
| 489 |
$rows[] = array( |
$rows[] = array( |
| 490 |
'data' => $row, |
'data' => $row, |
| 570 |
* An int containing the ID of a link. |
* An int containing the ID of a link. |
| 571 |
*/ |
*/ |
| 572 |
function follow_link_delete($lid) { |
function follow_link_delete($lid) { |
| 573 |
$sql = 'DELETE FROM {follow_links} WHERE lid = %d'; |
db_delete('follow_links') |
| 574 |
db_query($sql, $lid); |
->condition('lid', $lid) |
| 575 |
|
->execute(); |
| 576 |
} |
} |
| 577 |
|
|
| 578 |
|
|