--- modules/technorati/technorati.module 2007-04-28 21:48:10.000000000 +0000
+++ modules/technorati/technoratiNew.module 2007-04-28 22:21:56.000000000 +0000
@@ -1,256 +1,277 @@
- '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) {
- 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);
- }
-}
+ '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) {
+ // Patch by Ron D. Fredericks (RDF), April 22, 2007
+ // http://www.embeddedcomponents.com/blogs/
+ // a) remove whitespace between tags;
+ // b) format the n words making up multi-word tags
+ // with (n-1) "+" symbols.
+ $tag = check_plain($tag);
+ $tag = str_replace("+", " ", $tag);
+ $tag = _technorati_wsstrip($tag);
+ return '' . $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);
+ }
+}
+
+function _technorati_wsstrip($str) {
+// Whitespace strip algorithm:
+// a) Delete all whitespace from left and/or right of tags,
+// b) Reduce multiple whitespace in between elements of tags
+// to a single whitespace.
+// Reference:
+// daggillies's comment on http://www.php.net/trim
+ $str=ereg_replace (' +', ' ', trim($str));
+ return ereg_replace("[\r\t\n]","",$str);
+}