| 1 |
<?php |
<?php |
| 2 |
// $Id: follow.module,v 1.1 2009/04/29 17:20:42 q0rban Exp $ |
// $Id: follow.module,v 1.1.2.14 2009/10/06 15:19:26 q0rban Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 17 |
switch ($path) { |
switch ($path) { |
| 18 |
case 'follow': |
case 'follow': |
| 19 |
case 'user/%/follow': |
case 'user/%/follow': |
| 20 |
return t('You are helpless.'); |
return t('Please copy and paste urls for each service you would like to display in the block.'); |
| 21 |
case 'admin/settings/follow': |
case 'admin/settings/follow': |
| 22 |
return t('Here you can set what the default titles are for the "follow" blocks. If you would like a custom title, edit the individual blocks <a href="!href">here</a>.', array('!href' => url('admin/build/block'))); |
return t('Here you can set what the default titles are for the "follow" blocks. If you would like a custom title, edit the individual blocks <a href="!href">here</a>.', array('!href' => url('admin/build/block'))); |
| 23 |
} |
} |
| 24 |
} |
} |
| 25 |
|
|
| 26 |
/** |
/** |
| 27 |
|
* Implementation of hook_init(). |
| 28 |
|
*/ |
| 29 |
|
function follow_init() { |
| 30 |
|
drupal_add_css(drupal_get_path('module', 'follow') .'/follow.css'); |
| 31 |
|
} |
| 32 |
|
|
| 33 |
|
/** |
| 34 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 35 |
*/ |
*/ |
| 36 |
function follow_menu() { |
function follow_menu() { |
| 37 |
$items = array(); |
$items = array(); |
| 38 |
|
|
| 39 |
$items['follow'] = array( |
$items['admin/build/follow'] = array( |
| 40 |
'title' => 'Add follow links', |
'title' => 'Site follow links', |
| 41 |
'description' => 'Add sitewide follow links', |
'description' => 'Add sitewide follow links', |
| 42 |
'page callback' => 'drupal_get_form', |
'page callback' => 'drupal_get_form', |
| 43 |
'page arguments' => array('follow_links_form'), |
'page arguments' => array('follow_links_form'), |
| 70 |
* Access callback for user follow links editing. |
* Access callback for user follow links editing. |
| 71 |
*/ |
*/ |
| 72 |
function follow_links_user_access($uid) { |
function follow_links_user_access($uid) { |
| 73 |
return ((($GLOBALS['user']->uid == $uid) && user_access('edit own follow links')) || user_access('edit any user follow links')) && $account->uid > 0; |
return ((($GLOBALS['user']->uid == $uid) && user_access('edit own follow links')) || user_access('edit any user follow links')) && $uid > 0; |
| 74 |
} |
} |
| 75 |
|
|
| 76 |
/** |
/** |
| 159 |
elseif ($op == 'view') { |
elseif ($op == 'view') { |
| 160 |
switch ($delta) { |
switch ($delta) { |
| 161 |
case 'site': |
case 'site': |
| 162 |
if ($content = _follow_block_content() |
if (($content = _follow_block_content()) |
| 163 |
&& (variable_get('follow_site_block_user', TRUE) || !(arg(0) == 'user' && is_numeric(arg(1))))) { |
&& (variable_get('follow_site_block_user', TRUE) || !(arg(0) == 'user' && is_numeric(arg(1))))) { |
| 164 |
return array( |
return array( |
| 165 |
'subject' => _follow_block_subject(), |
'subject' => _follow_block_subject(), |
| 169 |
break; |
break; |
| 170 |
case 'user': |
case 'user': |
| 171 |
$uid = arg(1); |
$uid = arg(1); |
| 172 |
if (arg(0) == 'user' && is_numeric($uid) && $content = _follow_block_content($uid)) { |
if (arg(0) == 'user' && is_numeric($uid) && ($content = _follow_block_content($uid))) { |
| 173 |
return array( |
return array( |
| 174 |
'subject' => _follow_block_subject($uid), |
'subject' => _follow_block_subject($uid), |
| 175 |
'content' => $content, |
'content' => $content, |
| 203 |
// Special handling for usernames. |
// Special handling for usernames. |
| 204 |
if ($setting == FOLLOW_NAME) { |
if ($setting == FOLLOW_NAME) { |
| 205 |
$account = user_load($uid); |
$account = user_load($uid); |
| 206 |
return t('Follow @name on', array('@name' => $account->name)); |
// Set plain to TRUE for realname module support. |
| 207 |
|
return t('Follow !name on', array('!name' => theme('username', $account, array('plain' => TRUE)))); |
| 208 |
} |
} |
| 209 |
return t('Follow me on'); |
return t('Follow me on'); |
| 210 |
} |
} |
| 228 |
* The uid of the user account. Defaults to the site form, $uid = 0. |
* The uid of the user account. Defaults to the site form, $uid = 0. |
| 229 |
*/ |
*/ |
| 230 |
function _follow_block_content($uid = 0) { |
function _follow_block_content($uid = 0) { |
| 231 |
|
$output = ''; |
| 232 |
|
|
| 233 |
if ($links = follow_links_load($uid)) { |
if ($links = follow_links_load($uid)) { |
| 234 |
drupal_add_css(drupal_get_path('module', 'follow') .'/follow.css'); |
$output = theme('follow_links', $links, follow_networks_load()); |
| 235 |
return theme('follow_links', $links, follow_networks_load()); |
$output .= _follow_block_config_links($uid); |
| 236 |
} |
} |
| 237 |
|
|
| 238 |
|
return $output; |
| 239 |
} |
} |
| 240 |
|
|
| 241 |
/** |
/** |
| 284 |
return "<a$attributes>$title</a>\n"; |
return "<a$attributes>$title</a>\n"; |
| 285 |
} |
} |
| 286 |
|
|
| 287 |
|
/** |
| 288 |
|
* Outputs a list of configuration links for users with appropriate permissions |
| 289 |
|
* |
| 290 |
|
* @param $uid |
| 291 |
|
* The uid of the user account. Defaults to the site form, $uid = 0. |
| 292 |
|
* @return |
| 293 |
|
* A string containing the links, output with theme_links(). |
| 294 |
|
*/ |
| 295 |
|
function _follow_block_config_links($uid) { |
| 296 |
|
$links = array(); |
| 297 |
|
|
| 298 |
|
if ($uid == 0 && user_access('edit site follow links')) { |
| 299 |
|
$links['follow_edit'] = array( |
| 300 |
|
'title' => t('Edit'), |
| 301 |
|
'href' => 'admin/build/follow', |
| 302 |
|
'query' => drupal_get_destination(), |
| 303 |
|
); |
| 304 |
|
} |
| 305 |
|
elseif (follow_links_user_access($uid)) { |
| 306 |
|
$links['follow_edit'] = array( |
| 307 |
|
'title' => t('Edit'), |
| 308 |
|
'href' => 'user/'. $uid .'/follow', |
| 309 |
|
'query' => drupal_get_destination(), |
| 310 |
|
); |
| 311 |
|
} |
| 312 |
|
|
| 313 |
|
if (user_access('administer blocks')) { |
| 314 |
|
$links['follow_configure'] = array( |
| 315 |
|
'title' => t('Configure'), |
| 316 |
|
'href' => $uid ? 'admin/build/block/configure/follow/user' : 'admin/build/block/configure/follow/site', |
| 317 |
|
'query' => drupal_get_destination(), |
| 318 |
|
); |
| 319 |
|
} |
| 320 |
|
|
| 321 |
|
return theme('links', $links, array('class' => 'links inline')); |
| 322 |
|
} |
| 323 |
|
|
| 324 |
|
|
| 325 |
/** |
/** |
| 326 |
* The form for editing follow links. |
* The form for editing follow links. |
| 394 |
* Validates the url field to verify it's actually a url. |
* Validates the url field to verify it's actually a url. |
| 395 |
*/ |
*/ |
| 396 |
function follow_url_validate($form) { |
function follow_url_validate($form) { |
| 397 |
if($form['#value'] && !preg_match("/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i", $form['#value'])) { |
$url = trim($form['#value']); |
| 398 |
|
if($url && !preg_match("/^[a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+$/i", $url)) { |
| 399 |
form_error($form, t('The specified url is invalid.')); |
form_error($form, t('The specified url is invalid.')); |
| 400 |
} |
} |
| 401 |
} |
} |
| 409 |
|
|
| 410 |
foreach($links as $name => $link) { |
foreach($links as $name => $link) { |
| 411 |
$link = (object) $link; |
$link = (object) $link; |
| 412 |
|
$link->url = trim($link->url); |
| 413 |
|
|
| 414 |
// Check to see if there's actually a link |
// Check to see if there's actually a link |
| 415 |
if (empty($link->url)) { |
if (empty($link->url)) { |
| 416 |
// If there's an lid, delete the link. |
// If there's an lid, delete the link. |
| 585 |
*/ |
*/ |
| 586 |
function follow_follow_networks() { |
function follow_follow_networks() { |
| 587 |
return array( |
return array( |
| 588 |
'facebook' => t('Facebook'), |
'facebook' => t('Facebook'), |
| 589 |
'virb' => t('Virb'), |
'virb' => t('Virb'), |
| 590 |
'myspace' => t('MySpace'), |
'myspace' => t('MySpace'), |
| 591 |
'twitter' => t('Twitter'), |
'twitter' => t('Twitter'), |
| 592 |
'picasa' => t('Picasa'), |
'picasa' => t('Picasa'), |
| 593 |
'flickr' => t('Flickr'), |
'flickr' => t('Flickr'), |
| 594 |
'youtube' => t('YouTube'), |
'youtube' => t('YouTube'), |
| 595 |
'vimeo' => t('Vimeo'), |
'vimeo' => t('Vimeo'), |
| 596 |
'bliptv' => t('blip.tv'), |
'bliptv' => t('blip.tv'), |
| 597 |
'lastfm' => t('last.fm'), |
'lastfm' => t('last.fm'), |
| 598 |
|
'linkedin' => t('LinkedIn'), |
| 599 |
|
'delicious' => t('Delicious'), |
| 600 |
|
'tumblr' => t('Tumblr'), |
| 601 |
); |
); |
| 602 |
} |
} |