*/
define('TECHNORATI_NODE_TYPE', 'technorati_node_type_');
define('TECHNORATI_MODE_NONE', 0);
define('TECHNORATI_MODE_MANUAL', 1);
define('TECHNORATI_MODE_TAXONOMY', 2);
define('TECHNORATI_MODE_BOTH', 3);
define('TECHNORATI_DISPLAY_TYPE', 'technorati_display_type');
define('TECHNORATI_DISPLAY_NONE', 0);
define('TECHNORATI_DISPLAY_TEASER', 1);
define('TECHNORATI_DISPLAY_FULL', 2);
define('TECHNORATI_DISPLAY_BOTH', 3);
/**
* Implementation of hook_help().
*/
function technorati_help($path, $arg) {
switch ($path) {
case 'admin/help#technorati' :
return '
'. t('Enables Technorati tags for selected content types, and pings Technorati when new content is created.') .'
';
}
}
/**
* Implementation of hook_menu().
*/
function technorati_menu() {
$items = array();
$items['admin/settings/technorati'] = array(
'title' => 'Technorati',
'description' => 'technorati settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('technorati_admin_settings'),
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM
);
return $items;
}
/**
* Form definition for technorati module settings.
*/
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);
}
/**
* Implementation of hook_form_alter().
*/
function technorati_form_alter(&$form, &$form_state, $form_id) {
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.'),
);
}
}
}
/**
* Implementation of hook_theme().
*/
function technorati_theme() {
return array(
'technorati_tags' => array(
'arguments' => array('tags' => NULL),
),
);
}
/**
* Implementation of hook_nodeapi().
*/
function technorati_nodeapi(&$node, $op, $a3, $a4) {
$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 ($a3) {
$node->content['technorati'] = $technorati;
}
break;
case TECHNORATI_DISPLAY_FULL:
// Full page view only
if (!$a3) {
$node->content['technorati'] = $technorati;
}
break;
case TECHNORATI_DISPLAY_BOTH:
// Teaser and full page view
$node->content['technorati'] = $technorati;
break;
}
break;
}
}
/**
* Theme function for registered theme 'technorati_tags'.
*/
function theme_technorati_tags($tags) {
$path = base_path() . drupal_get_path('module', 'technorati') .'/technobubble.gif';
$output = '';
//$output .= '';
return $output;
}
/**
* This function is called by technorati_nodeapi() with $op 'view' and
* processes the tags in a node type and technorati mode specific way.
*/
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));
}
}
/**
* This function handles the manually assigned technorati tags of a node. It
* is called by _technorati_process_tags() for the technorati modes 'manual'
* and 'both'.
*/
function _technorati_manual($node) {
$links = array();
if (is_array($node->technorati_tags)) {
foreach ($node->technorati_tags as $tag) {
$links[] = _technorati_link($tag);
}
}
return $links;
}
/**
* This function handles the taxonomy tags of a node and creates technorati
* links from them. It is called by _technorati_process_tags() for the
* technorati modes 'taxonomy' and 'both'.
*/
function _technorati_taxonomy($node) {
$links = array();
$terms = taxonomy_node_get_terms($node);
foreach ($terms as $term) {
$links[] = _technorati_link($term->name);
}
return $links;
}
/**
* Calls the Technorati ping service at http://rpc.technorati.com/rpc/ping and
* notifies changes to the given URL.
*/
function technorati_ping($name = '', $url = '') {
$result = xmlrpc('http://rpc.technorati.com/rpc/ping', 'weblogUpdates.ping', $name, $url);
if ($result) {
watchdog("directory ping", 'Successfully notified technorati.com site.', WATCHDOG_NOTICE);
}
else {
watchdog('directory ping', 'Failed to notify technorati.com site.', WATCHDOG_WARNING);
}
}
/**
* Remove whitespace between tags, and format the n words making up
* multi-word tags with (n-1) "+" symbols.
*/
function _technorati_link($tag) {
$tag = _technorati_wsstrip(str_replace('+', ' ', check_plain($tag)));
$output = '