'admin/settings/technorati',
'title' => t('Technorati'),
'description' => t('technorati settings.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('technorati_admin_settings'),
'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM, // optional
);
return $items;
}
function technorati_admin_settings() {
if (!module_exists('ping')) {
drupal_set_message(t('This module requires that the %pingmodule be enabled',
array('%pingmodule' => l('ping module', 'admin/modules'))), 'error');
return;
}
$display_options = array(
TECHNORATI_DISPLAY_NONE => t('None'),
TECHNORATI_DISPLAY_TEASER => t('Teaser view'),
TECHNORATI_DISPLAY_FULL => t('Full page view'),
TECHNORATI_DISPLAY_BOTH => t('Both'),
);
$node_options = array(
TECHNORATI_MODE_NONE => t('None'),
TECHNORATI_MODE_MANUAL => t('Manual entry'),
TECHNORATI_MODE_TAXONOMY => t('Drupal categories'),
TECHNORATI_MODE_BOTH => t('Both'),
);
$form[TECHNORATI_DISPLAY_TYPE] = array(
'#type' => 'select',
'#title' => t('How to display the technorati tags'),
'#default_value' => variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL),
'#options' => $display_options,
'#description' => t('Select how to display the tags.
- None: means that the module will not display the tags. The theme can use the $node->technorati object to display the tags anywhere.
- Teaser: means that the tags will only be displayed when the node is in teaser view.
- Full page: means that the tags will only be displayed when the node is in full page view.
- Both: means the tags will be displayed in both teaser and full view.
'),
);
$form['types'] = array(
'#type' => 'fieldset',
'#title' => t('Content types'),
'#collapsible' => TRUE,
'#description' => t('Select the type of tags to use for each content type.- None: means do not do any Technorati tags for this content type.
- Manual entry: means that the tags have to be entered manually for each node.
- Drupal categories: means that the terms the node belong to will be used as Technorati tags.
- Both: means a combination of manual entries and categories.
'),
);
foreach(node_get_types() as $node_type => $node_name) {
$type = TECHNORATI_NODE_TYPE . $node_type;
$form['types'][$type] = array(
'#type' => 'select',
'#title' => $node_type,
'#default_value' => variable_get($type, TECHNORATI_MODE_NONE),
'#options' => $node_options,
);
}
return system_settings_form($form);
}
function technorati_form_alter($form_id, &$form) {
if (preg_match('/^(.*)_node_form$/', $form_id, $matches)) {
// Get the node type we are processing
$node_type = $matches[1];
// Check what the technorati mode for that node type
$mode = variable_get(TECHNORATI_NODE_TYPE . $node_type, TECHNORATI_MODE_NONE);
switch($mode) {
case TECHNORATI_MODE_NONE:
case TECHNORATI_MODE_TAXONOMY:
// No need to do anything in the node form
return;
case TECHNORATI_MODE_MANUAL:
case TECHNORATI_MODE_BOTH:
// We need to inject the texfield for technorati tags in the form
$tags = '';
// Load the node and get the technorati tags, if present
if ($nid = $form['nid']['#value']) {
$node = node_load($nid);
if (is_array($node->technorati_tags)) {
$tags = implode(',', $node->technorati_tags);
}
}
$form['technorati'] = array(
'#type' => 'fieldset',
'#title' => t('Technorati'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['technorati']['technorati_tags'] = array(
'#type' => 'textfield',
'#title' => t('Technorati tags'),
'#default_value' => $tags,
'#size' => 80,
'#maxlength' => 120,
'#description' => t('Enter your Technorati tags, separated by commas.'),
);
}
}
}
function technorati_nodeapi(&$node, $op, $teaser, $page) {
$mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);
switch($mode) {
case TECHNORATI_MODE_NONE:
case TECHNORATI_MODE_TAXONOMY:
// No need to do anything in the node form
return;
}
switch ($op) {
case 'insert':
db_query("INSERT INTO {technorati} (nid, tags) VALUES (%d, '%s')",
$node->nid, serialize(explode(',', $node->technorati_tags)));
break;
case 'update':
db_query('DELETE FROM {technorati} WHERE nid = %d', $node->nid);
db_query("INSERT INTO {technorati} (nid, tags) VALUES (%d, '%s')",
$node->nid, serialize(explode(',', $node->technorati_tags)));
break;
case 'delete':
db_query('DELETE FROM {technorati} WHERE nid = %d', $node->nid);
break;
case 'load':
$result = db_query('SELECT tags FROM {technorati} WHERE nid = %d', $node->nid);
$tags = unserialize(db_result($result));
if ($tags) {
return array('technorati_tags' => $tags);
}
break;
case 'view':
$technorati = array (
'#value' => theme('technorati_tags', _technorati_process_tags($node)),
'#weight' => 10,
);
$mode = variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL);
switch($mode) {
case TECHNORATI_DISPLAY_NONE:
// No inline display. Theme will handle it all.
break;
case TECHNORATI_DISPLAY_TEASER:
// Teaser view only
if ($teaser) {
$node->content['technorati'] = $technorati;
}
break;
case TECHNORATI_DISPLAY_FULL:
// Full page view only
if (!$teaser) {
$node->content['technorati'] = $technorati;
}
break;
case TECHNORATI_DISPLAY_BOTH:
// Teaser and full page view
$node->content['technorati'] = $technorati;
break;
}
break;
}
}
function theme_technorati_tags($tags) {
$path = base_path() . drupal_get_path('module', 'technorati') . '/technobubble.gif';
$output = '';
//$output .= '';
return $output;
}
function _technorati_process_tags($node) {
$mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);
switch($mode) {
case TECHNORATI_MODE_MANUAL:
return _technorati_manual($node);
case TECHNORATI_MODE_TAXONOMY:
return _technorati_taxonomy($node);
case TECHNORATI_MODE_BOTH:
return array_merge(_technorati_taxonomy($node), _technorati_manual($node));
}
}
function _technorati_manual($node) {
$links = array();
if (is_array($node->technorati_tags)) {
foreach($node->technorati_tags as $tag) {
$links[] = _technorati_link($tag);
}
}
return $links;
}
function _technorati_taxonomy($node) {
$links = array();
$terms = taxonomy_node_get_terms($node->nid);
foreach ($terms as $term) {
$links[] = _technorati_link($term->name);
}
return $links;
}
function _technorati_link($tag) {
$tag = RDF_wsstrip(check_plain($tag)); // part of Ron's patch
return '' . $tag . ''; // part of Ron's patch
// old line replaced by the two new lines above: return '' . check_plain($tag) . '';
}
function technorati_ping($name = '', $url = '') {
$result = xmlrpc('http://rpc.technorati.com/rpc/ping', 'weblogUpdates.ping', $name, $url);
if ($result) {
watchdog("directory ping", t('Successfully notified technorati.com site.'), WATCHDOG_NOTICE);
}
else {
watchdog('directory ping', t('Failed to notify technorati.com site.'), WATCHDOG_WARNING);
}
}
//////////////////////////////////////////////////////////////////////
// Proposed patch to fix formatting of technorati tags //
// by Ron D. Fredericks (RDF), April 22, 2007 //
// www.embeddedcomponents.com/blogs/category/web-components/drupal //
// //
// Patch tested against development snapshot: //
// http://drupal.org/project/technorati //
// 5.x-1.x-dev 2007-Apr-14 //
// //
// New function: //
// RDF_wsstrip(string) //
// //
// Updated function: //
// _technorati_link($tag) //
// //
// Patch: //
// 1) Replace any "+" symbols with whitespace. //
// 2) Delete all whitespace from left or right of elements. //
// 3) Reduce multiple whitespace in between elements //
// to a single whitespace. //
// 4) Replace any remaining single whitespace characters //
// in between elements with "+" characters. //
//////////////////////////////////////////////////////////////////////
function RDF_wsstrip($str)
// by Ron Fredericks, April 22, 2007
// references: see http://www.php.net/manual comments str_replace and trim functions
{
$str=str_replace("+", " ", $str);
$str=ereg_replace (' +', ' ', trim($str));
return ereg_replace("[\r\t\n]","",$str);
}