/[drupal]/contributions/modules/technorati/technorati.module
ViewVC logotype

Diff of /contributions/modules/technorati/technorati.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.6.2.3, Tue May 1 19:55:38 2007 UTC revision 1.6.2.4, Sun Nov 30 22:33:46 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: technorati.module,v 1.6.2.2 2007/04/13 19:35:35 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 5.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    
# Line 17  define('TECHNORATI_DISPLAY_TEASER', 1); Line 27  define('TECHNORATI_DISPLAY_TEASER', 1);
27  define('TECHNORATI_DISPLAY_FULL',    2);  define('TECHNORATI_DISPLAY_FULL',    2);
28  define('TECHNORATI_DISPLAY_BOTH',    3);  define('TECHNORATI_DISPLAY_BOTH',    3);
29    
30    define('TECHNORATI_UNIFY_TAGS',      'technorati_unify_tags');
31    define('TECHNORATI_SORT_TAGS',       'technorati_sort_tags');
32    define('TECHNORATI_HIDE_NOTAGS',     'technorati_hide_notags');
33    
34    /**
35     * Implementation of hook_help().
36     */
37  function technorati_help($section) {  function technorati_help($section) {
38    switch ($section) {    switch ($section) {
39      case 'admin/modules#description':      case 'admin/modules#description':
# Line 24  function technorati_help($section) { Line 41  function technorati_help($section) {
41    }    }
42  }  }
43    
44    /**
45     * Implementation of hook_menu().
46     */
47  function technorati_menu($may_cache) {  function technorati_menu($may_cache) {
48    $items = array();    $items = array();
49    
50      $items[] = array(    $items[] = array(
51        'path' => 'admin/settings/technorati',      'path' => 'admin/settings/technorati',
52        'title' => t('Technorati'),      'title' => t('Technorati'),
53        'description' => t('technorati settings.'),      'description' => t('technorati settings.'),
54        'callback' => 'drupal_get_form',      'callback' => 'drupal_get_form',
55        'callback arguments' => array('technorati_admin_settings'),      'callback arguments' => array('technorati_admin_settings'),
56        'access' => user_access('administer site configuration'),      'access' => user_access('administer site configuration'),
57        'type' => MENU_NORMAL_ITEM, // optional      'type' => MENU_NORMAL_ITEM, // optional
58      );    );
59    return $items;    return $items;
60  }  }
61    
62    /**
63     * Form definition for technorati module settings.
64     */
65  function technorati_admin_settings() {  function technorati_admin_settings() {
66    if (!module_exists('ping')) {    if (!module_exists('ping')) {
67      drupal_set_message(t('This module requires that the %pingmodule be enabled',      drupal_set_message(t('This module requires that the %pingmodule be enabled',
# Line 61  function technorati_admin_settings() { Line 83  function technorati_admin_settings() {
83      TECHNORATI_MODE_BOTH     => t('Both'),      TECHNORATI_MODE_BOTH     => t('Both'),
84    );    );
85    
86    $form[TECHNORATI_DISPLAY_TYPE] = array(    $form['display'] = array(
87        '#type'          => 'fieldset',
88        '#title'         => t('Technorati tag display settings'),
89      );
90    
91      $form['display'][TECHNORATI_DISPLAY_TYPE] = array(
92      '#type'          => 'select',      '#type'          => 'select',
93      '#title'         => t('How to display the technorati tags'),      '#title'         => t('How to display the technorati tags'),
94      '#default_value' => variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL),      '#default_value' => variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL),
# Line 69  function technorati_admin_settings() { Line 96  function technorati_admin_settings() {
96      '#description' => t('Select how to display the tags.<ul><li>None: means that the module will not display the tags. The theme can use the $node->technorati object to display the tags anywhere.</li><li>Teaser: means that the tags will only be displayed when the node is in teaser view.</li><li>Full page: means that the tags will only be displayed when the node is in full page view.</li><li>Both: means the tags will be displayed in both teaser and full view.</li></ul>'),      '#description' => t('Select how to display the tags.<ul><li>None: means that the module will not display the tags. The theme can use the $node->technorati object to display the tags anywhere.</li><li>Teaser: means that the tags will only be displayed when the node is in teaser view.</li><li>Full page: means that the tags will only be displayed when the node is in full page view.</li><li>Both: means the tags will be displayed in both teaser and full view.</li></ul>'),
97    );    );
98    
99      $form['display'][TECHNORATI_UNIFY_TAGS] = array(
100        '#type'          => 'checkbox',
101        '#title'         => t('Unify technorati tags'),
102        '#default_value' => variable_get(TECHNORATI_UNIFY_TAGS, 0),
103        '#description'   => t('Use this option if you want to have only one occurrence of each choosen tag.'),
104      );
105    
106      $form['display'][TECHNORATI_SORT_TAGS] = array(
107        '#type'          => 'checkbox',
108        '#title'         => t('Sort technorati tags'),
109        '#default_value' => variable_get(TECHNORATI_SORT_TAGS, 0),
110        '#description'   => t('Sort the tags when displaying Technorati links.'),
111      );
112    
113      $form['display'][TECHNORATI_HIDE_NOTAGS] = array(
114        '#type'          => 'checkbox',
115        '#title'         => t('Hide technorati display if empty'),
116        '#default_value' => variable_get(TECHNORATI_HIDE_NOTAGS, 0),
117        '#description'   => t('Hide the display of the Technorati icon and the Technorati Tags label, if there are no tags assigned to a node.'),
118      );
119    
120    $form['types'] = array(    $form['types'] = array(
121      '#type' => 'fieldset',      '#type' => 'fieldset',
122      '#title' => t('Content types'),      '#title' => t('Content types'),
# Line 76  function technorati_admin_settings() { Line 124  function technorati_admin_settings() {
124      '#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>'),
125    );    );
126    
127    foreach(node_get_types() as $node_type => $node_name) {    foreach (node_get_types() as $node_type => $node_name) {
128      $type = TECHNORATI_NODE_TYPE . $node_type;      $type = TECHNORATI_NODE_TYPE . $node_type;
129      $form['types'][$type] = array(      $form['types'][$type] = array(
130        '#type'          => 'select',        '#type'          => 'select',
# Line 86  function technorati_admin_settings() { Line 134  function technorati_admin_settings() {
134      );      );
135    }    }
136    
137   return system_settings_form($form);    return system_settings_form($form);
138  }  }
139    
140    /**
141     * Implementation of hook_form_alter().
142     */
143  function technorati_form_alter($form_id, &$form) {  function technorati_form_alter($form_id, &$form) {
144    if (preg_match('/^(.*)_node_form$/', $form_id, $matches)) {    if (preg_match('/^(.*)_node_form$/', $form_id, $matches)) {
145      // Get the node type we are processing      // Get the node type we are processing
# Line 96  function technorati_form_alter($form_id, Line 147  function technorati_form_alter($form_id,
147    
148      // Check what the technorati mode for that node type      // Check what the technorati mode for that node type
149      $mode = variable_get(TECHNORATI_NODE_TYPE . $node_type, TECHNORATI_MODE_NONE);      $mode = variable_get(TECHNORATI_NODE_TYPE . $node_type, TECHNORATI_MODE_NONE);
150      switch($mode) {      switch ($mode) {
151        case TECHNORATI_MODE_NONE:        case TECHNORATI_MODE_NONE:
152        case TECHNORATI_MODE_TAXONOMY:        case TECHNORATI_MODE_TAXONOMY:
153          // No need to do anything in the node form          // No need to do anything in the node form
# Line 133  function technorati_form_alter($form_id, Line 184  function technorati_form_alter($form_id,
184    }    }
185  }  }
186    
187  function technorati_nodeapi(&$node, $op, $teaser, $page) {  /**
188     * Implementation of hook_nodeapi().
189     */
190    function technorati_nodeapi(&$node, $op, $a3, $a4) {
191    $mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);    $mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);
192    switch($mode) {    switch ($mode) {
193      case TECHNORATI_MODE_NONE:      case TECHNORATI_MODE_NONE:
194      case TECHNORATI_MODE_TAXONOMY:      case TECHNORATI_MODE_TAXONOMY:
195        // No need to do anything in the node form        // No need to do anything in the node form
# Line 167  function technorati_nodeapi(&$node, $op, Line 221  function technorati_nodeapi(&$node, $op,
221        break;        break;
222    
223      case 'view':      case 'view':
224        $technorati = array (        $technorati = array(
225          '#value' => theme('technorati_tags', _technorati_process_tags($node)),          '#value' => theme('technorati_tags', _technorati_process_tags($node)),
226          '#weight' => 10,          '#weight' => 10,
227          );        );
228        $mode = variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL);        $mode = variable_get(TECHNORATI_DISPLAY_TYPE, TECHNORATI_DISPLAY_FULL);
229        switch($mode) {        switch ($mode) {
230          case TECHNORATI_DISPLAY_NONE:          case TECHNORATI_DISPLAY_NONE:
231            // No inline display. Theme will handle it all.            // No inline display. Theme will handle it all.
232            break;            break;
233          case TECHNORATI_DISPLAY_TEASER:          case TECHNORATI_DISPLAY_TEASER:
234            // Teaser view only            // Teaser view only
235            if ($teaser) {            if ($a3) {
236              $node->content['technorati'] = $technorati;              $node->content['technorati'] = $technorati;
237            }            }
238            break;            break;
239          case TECHNORATI_DISPLAY_FULL:          case TECHNORATI_DISPLAY_FULL:
240            // Full page view only            // Full page view only
241            if (!$teaser) {            if (!$a3) {
242              $node->content['technorati'] = $technorati;              $node->content['technorati'] = $technorati;
243            }            }
244            break;            break;
245          case TECHNORATI_DISPLAY_BOTH:          case TECHNORATI_DISPLAY_BOTH:
246            // Teaser and full page view            // Teaser and full page view
247            $node->content['technorati'] = $technorati;            $node->content['technorati'] = $technorati;
248            break;            break;
249        }        }
250        break;        break;
251    }    }
252  }  }
253    
254    /**
255     * Theme function for registered theme 'technorati_tags'.
256     */
257  function theme_technorati_tags($tags) {  function theme_technorati_tags($tags) {
258    $path = base_path() . drupal_get_path('module', 'technorati') . '/technobubble.gif';    if (empty($tags) && variable_get(TECHNORATI_HIDE_NOTAGS, 0)) {
259    $output = '<div class="technorati_tags">';      return '';
260    $output .= '<img src="' . $path . '"/>';    }
261    $output .= '<strong>' . t('Technorati Tags: ') . '</strong>';    $path = base_path() . drupal_get_path('module', 'technorati') .'/technobubble.gif';
262    
263      $output  = '<div class="technorati_tags">';
264      $output .= '<img alt="'. t('Technorati Tags:') .'" src="'. $path .'"/>';
265      $output .= '<strong>'. t('Technorati Tags: ') .'</strong>';
266    $output .= implode(' ', $tags);    $output .= implode(' ', $tags);
267    $output .= '</div>';    $output .= '</div>';
268    //$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>';
269    return $output;    return $output;
270  }  }
271    
272    /**
273     * This function is called by technorati_nodeapi() with $op 'view' and
274     * processes the tags in a node type and technorati mode specific way.
275     */
276  function _technorati_process_tags($node) {  function _technorati_process_tags($node) {
277    $mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);    $mode = variable_get(TECHNORATI_NODE_TYPE . $node->type, TECHNORATI_MODE_NONE);
278    switch($mode) {    switch ($mode) {
279      case TECHNORATI_MODE_MANUAL:      case TECHNORATI_MODE_MANUAL:
280        return _technorati_manual($node);        $tags = _technorati_manual($node);
281          break;
282      case TECHNORATI_MODE_TAXONOMY:      case TECHNORATI_MODE_TAXONOMY:
283        return _technorati_taxonomy($node);        $tags = _technorati_taxonomy($node);
284          break;
285      case TECHNORATI_MODE_BOTH:      case TECHNORATI_MODE_BOTH:
286        return array_merge(_technorati_taxonomy($node),  _technorati_manual($node));        $tags = array_merge(_technorati_taxonomy($node),  _technorati_manual($node));
287          break;
288        default:
289          return;
290    }    }
291      if (variable_get(TECHNORATI_UNIFY_TAGS, 0)) {
292        $tags = array_unique($tags);
293      }
294      if (variable_get(TECHNORATI_SORT_TAGS, 0)) {
295        natcasesort($tags);
296      }
297      return $tags;
298  }  }
299    
300    /**
301     * This function handles the manually assigned technorati tags of a node. It
302     * is called by _technorati_process_tags() for the technorati modes 'manual'
303     * and 'both'.
304     */
305  function _technorati_manual($node) {  function _technorati_manual($node) {
306    $links = array();    $links = array();
307    if (is_array($node->technorati_tags)) {    if (is_array($node->technorati_tags)) {
308      foreach($node->technorati_tags as $tag) {      foreach ($node->technorati_tags as $tag) {
309        $links[] = _technorati_link($tag);        if (!empty($tag)) {
310            $links[] = _technorati_link($tag);
311          }
312      }      }
313    }    }
314    return $links;    return $links;
315  }  }
316    
317    /**
318     * This function handles the taxonomy tags of a node and creates technorati
319     * links from them. It is called by _technorati_process_tags() for the
320     * technorati modes 'taxonomy' and 'both'.
321     */
322  function _technorati_taxonomy($node) {  function _technorati_taxonomy($node) {
323    $links = array();    $links = array();
324    $terms = taxonomy_node_get_terms($node->nid);    $terms = taxonomy_node_get_terms($node->nid);
# Line 241  function _technorati_taxonomy($node) { Line 328  function _technorati_taxonomy($node) {
328    return $links;    return $links;
329  }  }
330    
331    /**
332     * Calls the Technorati ping service at http://rpc.technorati.com/rpc/ping and
333     * notifies changes to the given URL.
334     */
335  function technorati_ping($name = '', $url = '') {  function technorati_ping($name = '', $url = '') {
336    $result = xmlrpc('http://rpc.technorati.com/rpc/ping', 'weblogUpdates.ping', $name, $url);    $result = xmlrpc('http://rpc.technorati.com/rpc/ping', 'weblogUpdates.ping', $name, $url);
337    if ($result) {    if ($result) {
# Line 268  function _technorati_link($tag) { Line 359  function _technorati_link($tag) {
359    
360  /**  /**
361   * Strip whitespace from left and/or right of tags, and reduce multiples   * Strip whitespace from left and/or right of tags, and reduce multiples
362   * to just one   * to just one.
363   *   *
364   * Reference: daggillies's comment on http://www.php.net/trim   * Reference: daggillies's comment on http://www.php.net/trim
365   */   */

Legend:
Removed from v.1.6.2.3  
changed lines
  Added in v.1.6.2.4

  ViewVC Help
Powered by ViewVC 1.1.2