| 1 |
<?php |
<?php |
| 2 |
// $Id: technorati.module,v 1.6.2.3 2007/05/01 19:55:38 kbahey Exp $ |
// $Id: technorati.module,v 1.6.2.3 2007/05/01 19:55:38 kbahey Exp $ |
| 3 |
|
|
| 4 |
// Copyright 2006 http://2bits.com |
/* |
| 5 |
|
* @file |
| 6 |
|
* Technorati module for Drupal 6.x. |
| 7 |
|
* |
| 8 |
|
* This module enables Technorati (http://technorati.com) tags for Drupal |
| 9 |
|
* node. Tags can be stored in a separate database table or can be taken from |
| 10 |
|
* the taxonomy tags. |
| 11 |
|
* |
| 12 |
|
* Copyright (c) 2006 http://2bits.com |
| 13 |
|
* Copyright (c) 2008 Jan Dittberner <jan@dittberner.info> |
| 14 |
|
*/ |
| 15 |
|
|
| 16 |
define('TECHNORATI_NODE_TYPE', 'technorati_node_type_'); |
define('TECHNORATI_NODE_TYPE', 'technorati_node_type_'); |
| 17 |
|
|
| 27 |
define('TECHNORATI_DISPLAY_FULL', 2); |
define('TECHNORATI_DISPLAY_FULL', 2); |
| 28 |
define('TECHNORATI_DISPLAY_BOTH', 3); |
define('TECHNORATI_DISPLAY_BOTH', 3); |
| 29 |
|
|
| 30 |
function technorati_help($section) { |
/** |
| 31 |
switch ($section) { |
* Implementation of hook_help(). |
| 32 |
case 'admin/modules#description': |
*/ |
| 33 |
return t('Enables Technorati tags for selected content types, and pings Technorati when new content is created.'); |
function technorati_help($path, $arg) { |
| 34 |
|
switch ($path) { |
| 35 |
|
case 'admin/help#technorati' : |
| 36 |
|
return '<p>'. t('Enables Technorati tags for selected content types, and pings Technorati when new content is created.') .'</p>'; |
| 37 |
} |
} |
| 38 |
} |
} |
| 39 |
|
|
| 40 |
function technorati_menu($may_cache) { |
/** |
| 41 |
|
* Implementation of hook_menu(). |
| 42 |
|
*/ |
| 43 |
|
function technorati_menu() { |
| 44 |
$items = array(); |
$items = array(); |
| 45 |
|
|
| 46 |
$items[] = array( |
$items['admin/settings/technorati'] = array( |
| 47 |
'path' => 'admin/settings/technorati', |
'title' => 'Technorati', |
| 48 |
'title' => t('Technorati'), |
'description' => 'technorati settings', |
| 49 |
'description' => t('technorati settings.'), |
'page callback' => 'drupal_get_form', |
| 50 |
'callback' => 'drupal_get_form', |
'page arguments' => array('technorati_admin_settings'), |
| 51 |
'callback arguments' => array('technorati_admin_settings'), |
'access arguments' => array('administer site configuration'), |
| 52 |
'access' => user_access('administer site configuration'), |
'type' => MENU_NORMAL_ITEM |
| 53 |
'type' => MENU_NORMAL_ITEM, // optional |
); |
|
); |
|
| 54 |
return $items; |
return $items; |
| 55 |
} |
} |
| 56 |
|
|
| 57 |
|
/** |
| 58 |
|
* Form definition for technorati module settings. |
| 59 |
|
*/ |
| 60 |
function technorati_admin_settings() { |
function technorati_admin_settings() { |
| 61 |
if (!module_exists('ping')) { |
if (!module_exists('ping')) { |
| 62 |
drupal_set_message(t('This module requires that the %pingmodule be enabled', |
drupal_set_message(t('This module requires that the %pingmodule be enabled', |
| 93 |
'#description' => t('Select the type of tags to use for each content type.<ul><li>None: means do not do any Technorati tags for this content type.</li><li>Manual entry: means that the tags have to be entered manually for each node.</li><li>Drupal categories: means that the terms the node belong to will be used as Technorati tags.</li><li>Both: means a combination of manual entries and categories.</li></ul>'), |
'#description' => t('Select the type of tags to use for each content type.<ul><li>None: means do not do any Technorati tags for this content type.</li><li>Manual entry: means that the tags have to be entered manually for each node.</li><li>Drupal categories: means that the terms the node belong to will be used as Technorati tags.</li><li>Both: means a combination of manual entries and categories.</li></ul>'), |
| 94 |
); |
); |
| 95 |
|
|
| 96 |
foreach(node_get_types() as $node_type => $node_name) { |
foreach (node_get_types() as $node_type => $node_name) { |
| 97 |
$type = TECHNORATI_NODE_TYPE . $node_type; |
$type = TECHNORATI_NODE_TYPE . $node_type; |
| 98 |
$form['types'][$type] = array( |
$form['types'][$type] = array( |
| 99 |
'#type' => 'select', |
'#type' => 'select', |
| 103 |
); |
); |
| 104 |
} |
} |
| 105 |
|
|
| 106 |
return system_settings_form($form); |
return system_settings_form($form); |
| 107 |
} |
} |
| 108 |
|
|
| 109 |
function technorati_form_alter($form_id, &$form) { |
/** |
| 110 |
|
* Implementation of hook_form_alter(). |
| 111 |
|
*/ |
| 112 |
|
function technorati_form_alter(&$form, &$form_state, $form_id) { |
| 113 |
if (preg_match('/^(.*)_node_form$/', $form_id, $matches)) { |
if (preg_match('/^(.*)_node_form$/', $form_id, $matches)) { |
| 114 |
// Get the node type we are processing |
// Get the node type we are processing |
| 115 |
$node_type = $matches[1]; |
$node_type = $matches[1]; |
| 116 |
|
|
| 117 |
// Check what the technorati mode for that node type |
// Check what the technorati mode for that node type |
| 118 |
$mode = variable_get(TECHNORATI_NODE_TYPE . $node_type, TECHNORATI_MODE_NONE); |
$mode = variable_get(TECHNORATI_NODE_TYPE . $node_type, TECHNORATI_MODE_NONE); |
| 119 |
switch($mode) { |
switch ($mode) { |
| 120 |
case TECHNORATI_MODE_NONE: |
case TECHNORATI_MODE_NONE: |
| 121 |
case TECHNORATI_MODE_TAXONOMY: |
case TECHNORATI_MODE_TAXONOMY: |
| 122 |
// No need to do anything in the node form |
// No need to do anything in the node form |
| 153 |
} |
} |
| 154 |
} |
} |
| 155 |
|
|
| 156 |
function technorati_nodeapi(&$node, $op, $teaser, $page) { |
/** |
| 157 |
|
* Implementation of hook_theme(). |
| 158 |
|
*/ |
| 159 |
|
function technorati_theme() { |
| 160 |
|
return array( |
| 161 |
|
'technorati_tags' => array( |
| 162 |
|
'arguments' => array('tags' => NULL), |
| 163 |
|
), |
| 164 |
|
); |
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
/** |
| 168 |
|
* Implementation of hook_nodeapi(). |
| 169 |
|
*/ |
| 170 |
|
function technorati_nodeapi(&$node, $op, $a3, $a4) { |
| 171 |
$mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE); |
$mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE); |
| 172 |
switch($mode) { |
switch ($mode) { |
| 173 |
case TECHNORATI_MODE_NONE: |
case TECHNORATI_MODE_NONE: |
| 174 |
case TECHNORATI_MODE_TAXONOMY: |
case TECHNORATI_MODE_TAXONOMY: |
| 175 |
// No need to do anything in the node form |
// No need to do anything in the node form |
| 201 |
break; |
break; |
| 202 |
|
|
| 203 |
case 'view': |
case 'view': |
| 204 |
$technorati = array ( |
$technorati = array( |
| 205 |
'#value' => theme('technorati_tags', _technorati_process_tags($node)), |
'#value' => theme('technorati_tags', _technorati_process_tags($node)), |
| 206 |
'#weight' => 10, |
'#weight' => 10, |
| 207 |
); |
); |
| 208 |
$mode = variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL); |
$mode = variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL); |
| 209 |
switch($mode) { |
switch ($mode) { |
| 210 |
case TECHNORATI_DISPLAY_NONE: |
case TECHNORATI_DISPLAY_NONE: |
| 211 |
// No inline display. Theme will handle it all. |
// No inline display. Theme will handle it all. |
| 212 |
break; |
break; |
| 213 |
case TECHNORATI_DISPLAY_TEASER: |
case TECHNORATI_DISPLAY_TEASER: |
| 214 |
// Teaser view only |
// Teaser view only |
| 215 |
if ($teaser) { |
if ($a3) { |
| 216 |
$node->content['technorati'] = $technorati; |
$node->content['technorati'] = $technorati; |
| 217 |
} |
} |
| 218 |
break; |
break; |
| 219 |
case TECHNORATI_DISPLAY_FULL: |
case TECHNORATI_DISPLAY_FULL: |
| 220 |
// Full page view only |
// Full page view only |
| 221 |
if (!$teaser) { |
if (!$a3) { |
| 222 |
$node->content['technorati'] = $technorati; |
$node->content['technorati'] = $technorati; |
| 223 |
} |
} |
| 224 |
break; |
break; |
| 225 |
case TECHNORATI_DISPLAY_BOTH: |
case TECHNORATI_DISPLAY_BOTH: |
| 226 |
// Teaser and full page view |
// Teaser and full page view |
| 227 |
$node->content['technorati'] = $technorati; |
$node->content['technorati'] = $technorati; |
| 228 |
break; |
break; |
| 229 |
} |
} |
| 230 |
break; |
break; |
| 231 |
} |
} |
| 232 |
} |
} |
| 233 |
|
|
| 234 |
|
/** |
| 235 |
|
* Theme function for registered theme 'technorati_tags'. |
| 236 |
|
*/ |
| 237 |
function theme_technorati_tags($tags) { |
function theme_technorati_tags($tags) { |
| 238 |
$path = base_path() . drupal_get_path('module', 'technorati') . '/technobubble.gif'; |
$path = base_path() . drupal_get_path('module', 'technorati') .'/technobubble.gif'; |
| 239 |
$output = '<div class="technorati_tags">'; |
$output = '<div class="technorati_tags">'; |
| 240 |
$output .= '<img src="' . $path . '"/>'; |
$output .= '<img src="'. $path .'"/>'; |
| 241 |
$output .= '<strong>' . t('Technorati Tags: ') . '</strong>'; |
$output .= '<strong>'. t('Technorati Tags: ') .'</strong>'; |
| 242 |
$output .= implode(' ', $tags); |
$output .= implode(' ', $tags); |
| 243 |
$output .= '</div>'; |
$output .= '</div>'; |
| 244 |
//$output .= '<script type="text/javascript" src="http://technorati.com/embed/CODE.js"></script>'; |
//$output .= '<script type="text/javascript" src="http://technorati.com/embed/CODE.js"></script>'; |
| 245 |
return $output; |
return $output; |
| 246 |
} |
} |
| 247 |
|
|
| 248 |
|
/** |
| 249 |
|
* This function is called by technorati_nodeapi() with $op 'view' and |
| 250 |
|
* processes the tags in a node type and technorati mode specific way. |
| 251 |
|
*/ |
| 252 |
function _technorati_process_tags($node) { |
function _technorati_process_tags($node) { |
| 253 |
$mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE); |
$mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE); |
| 254 |
switch($mode) { |
switch ($mode) { |
| 255 |
case TECHNORATI_MODE_MANUAL: |
case TECHNORATI_MODE_MANUAL: |
| 256 |
return _technorati_manual($node); |
return _technorati_manual($node); |
| 257 |
|
|
| 263 |
} |
} |
| 264 |
} |
} |
| 265 |
|
|
| 266 |
|
/** |
| 267 |
|
* This function handles the manually assigned technorati tags of a node. It |
| 268 |
|
* is called by _technorati_process_tags() for the technorati modes 'manual' |
| 269 |
|
* and 'both'. |
| 270 |
|
*/ |
| 271 |
function _technorati_manual($node) { |
function _technorati_manual($node) { |
| 272 |
$links = array(); |
$links = array(); |
| 273 |
if (is_array($node->technorati_tags)) { |
if (is_array($node->technorati_tags)) { |
| 274 |
foreach($node->technorati_tags as $tag) { |
foreach ($node->technorati_tags as $tag) { |
| 275 |
$links[] = _technorati_link($tag); |
$links[] = _technorati_link($tag); |
| 276 |
} |
} |
| 277 |
} |
} |
| 278 |
return $links; |
return $links; |
| 279 |
} |
} |
| 280 |
|
|
| 281 |
|
/** |
| 282 |
|
* This function handles the taxonomy tags of a node and creates technorati |
| 283 |
|
* links from them. It is called by _technorati_process_tags() for the |
| 284 |
|
* technorati modes 'taxonomy' and 'both'. |
| 285 |
|
*/ |
| 286 |
function _technorati_taxonomy($node) { |
function _technorati_taxonomy($node) { |
| 287 |
$links = array(); |
$links = array(); |
| 288 |
$terms = taxonomy_node_get_terms($node->nid); |
$terms = taxonomy_node_get_terms($node); |
| 289 |
foreach ($terms as $term) { |
foreach ($terms as $term) { |
| 290 |
$links[] = _technorati_link($term->name); |
$links[] = _technorati_link($term->name); |
| 291 |
} |
} |
| 292 |
return $links; |
return $links; |
| 293 |
} |
} |
| 294 |
|
|
| 295 |
|
/** |
| 296 |
|
* Calls the Technorati ping service at http://rpc.technorati.com/rpc/ping and |
| 297 |
|
* notifies changes to the given URL. |
| 298 |
|
*/ |
| 299 |
function technorati_ping($name = '', $url = '') { |
function technorati_ping($name = '', $url = '') { |
| 300 |
$result = xmlrpc('http://rpc.technorati.com/rpc/ping', 'weblogUpdates.ping', $name, $url); |
$result = xmlrpc('http://rpc.technorati.com/rpc/ping', 'weblogUpdates.ping', $name, $url); |
| 301 |
if ($result) { |
if ($result) { |
| 302 |
watchdog("directory ping", t('Successfully notified technorati.com site.'), WATCHDOG_NOTICE); |
watchdog("directory ping", 'Successfully notified technorati.com site.', WATCHDOG_NOTICE); |
| 303 |
} |
} |
| 304 |
else { |
else { |
| 305 |
watchdog('directory ping', t('Failed to notify technorati.com site.'), WATCHDOG_WARNING); |
watchdog('directory ping', 'Failed to notify technorati.com site.', WATCHDOG_WARNING); |
| 306 |
} |
} |
| 307 |
} |
} |
| 308 |
|
|
| 323 |
|
|
| 324 |
/** |
/** |
| 325 |
* Strip whitespace from left and/or right of tags, and reduce multiples |
* Strip whitespace from left and/or right of tags, and reduce multiples |
| 326 |
* to just one |
* to just one. |
| 327 |
* |
* |
| 328 |
* Reference: daggillies's comment on http://www.php.net/trim |
* Reference: daggillies's comment on http://www.php.net/trim |
| 329 |
*/ |
*/ |