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

Diff of /contributions/modules/similar/similar.module

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

revision 1.8.2.2, Thu Mar 6 22:11:34 2008 UTC revision 1.8.2.3, Fri May 8 13:44:36 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: similar.module,v 1.7.2.7 2007/11/29 16:17:37 deekayen Exp $  // $Id: similar.module,v 1.8.2.2 2008/03/06 22:11:34 deekayen Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 12  Line 12 
12   * @author Arnab Nandi http://arnab.org/   * @author Arnab Nandi http://arnab.org/
13   */   */
14    
 define('SIMILAR_CACHE_LIFETIME', 0);  
 define('SIMILAR_CACHE_DISABLED', 0);  
 define('SIMILAR_CACHE_ENABLED', 1);  
   
15  /**  /**
16   * Implementation of hook_help().   * Implementation of hook_help().
17   *   *
# Line 29  function similar_help($path, $arg) { Line 25  function similar_help($path, $arg) {
25    }    }
26  }  }
27    
 function similar_menu() {  
   $items = array();  
   
   $items['admin/settings/similar'] = array(  
     'title' => 'Similar Entries',  
     'description' => 'A module that displays a block with the most similar nodes to the currently viewed one, based on the title and body fields.',  
     'page callback' => 'drupal_get_form',  
     'page arguments' => array('similar_admin_settings'),  
     'access callback' => 'user_access',  
     'access arguments' => array('administer site configuration')  
   );  
   
   return $items;  
 }  
   
 function similar_admin_settings() {  
   $form = array();  
   
   $form['similar_cache'] = array(  
     '#type' => 'fieldset',  
     '#title' => t('Cache settings'),  
     '#collapsible' => true,  
     '#collapsed' => false);  
   
   $form['similar_cache']['similar_cache']  = array(  
     '#type' => 'radios',  
     '#title' => t('Cache'),  
     '#default_value' => variable_get('similar_cache', SIMILAR_CACHE_DISABLED),  
     '#options' => array(SIMILAR_CACHE_DISABLED => t('Disabled'), SIMILAR_CACHE_ENABLED => t('Enabled'))  
   );  
   
   $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');  
   $period[0] = t('none');  
   $form['similar_cache']['similar_cache_lifetime'] = array(  
     '#type' => 'select',  
     '#title' => t('Minimum cache lifetime'),  
     '#default_value' => variable_get('similar_cache_lifetime', SIMILAR_CACHE_LIFETIME),  
     '#options' => $period,  
     '#description' => t('The cached block items will be forced to remain in cache at least this long before they are refreshed. Otherwise, cron jobs and node updates will clear the similar entries block cache at each occurrence. The retention policy below can be used to override this setting.')  
   );  
   
   $form['similar_cache']['retention']  = array(  
     '#type' => 'fieldset',  
     '#title' => 'Retention policy',  
     '#collapsible' => true,  
     '#collapsed' => true,  
     '#description' => t('Adjust whether or not to clear the similar entries cache when node content is updated. Remember, not setting delete to force clear cache may result in broken links for cached similar entries. This policy overrides the cache lifetime. Disabling every setting in this group will give full expiration control to the cache lifetime setting.')  
   );  
   $form['similar_cache']['retention']['similar_clear_on_insert']  = array(  
     '#type' => 'radios',  
     '#title' => t('Force clear on insert'),  
     '#default_value' => variable_get('similar_clear_on_insert', 0),  
     '#options' => array(0 => t('Disabled'), 1 => t('Enabled'))  
   );  
   
   $form['similar_cache']['retention']['update']  = array(  
     '#type' => 'fieldset',  
     '#collapsible' => false  
   );  
   $form['similar_cache']['retention']['update']['similar_clear_on_update']  = array(  
     '#type' => 'radios',  
     '#title' => t('Force clear on update'),  
     '#default_value' => variable_get('similar_clear_on_update', 0),  
     '#options' => array(0 => t('Disabled'), 1 => t('Enabled'))  
   );  
   $form['similar_cache']['retention']['update']['similar_clear_node_only']  = array(  
     '#type' => 'radios',  
     '#title' => t('Clear node only'),  
     '#default_value' => variable_get('similar_clear_node_only', 1),  
     '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),  
     '#description' => t('Disabled will clear all the cached similar blocks on the system. Enabled will only clear the similar entries block cache shown on the updated node.')  
   );  
   $form['similar_cache']['retention']['similar_clear_on_delete']  = array(  
     '#type' => 'radios',  
     '#title' => t('Force clear on deletion'),  
     '#default_value' => variable_get('similar_clear_on_delete', 1),  
     '#options' => array(0 => t('Disabled'), 1 => t('Enabled'))  
   );  
   return system_settings_form($form);  
 }  
   
 /**  
  * Perform forced cache clearing  
  */  
 function similar_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {  
   switch ($op) {  
     case 'insert':  
       if (variable_get('similar_clear_on_insert', 0)) {  
         cache_clear_all('similar_block_0:', 'cache', true);  
       }  
       break;  
     case 'update':  
       if (variable_get('similar_clear_on_update', 0)) {  
         if (variable_get('similar_clear_node_only', 1)) {  
           cache_clear_all("similar_block_0:$node->nid", 'cache');  
         }  
         else {  
           cache_clear_all('similar_block_0:', 'cache', true);  
         }  
       }  
       break;  
     case 'delete':  
       if (variable_get('similar_clear_on_delete', 1)) {  
         cache_clear_all('similar_block_0:', 'cache', true);  
       }  
       else {  
         cache_clear_all("similar_block_0:$node->nid", 'cache');  
       }  
       break;  
   }  
 }  
   
28  /**  /**
29   * Implementation of hook_block().   * Implementation of hook_block().
30   *   *
# Line 155  function similar_block($op = 'list', $de Line 39  function similar_block($op = 'list', $de
39    switch ($op) {    switch ($op) {
40      case 'list':      case 'list':
41        $blocks[0]['info'] = t('Similar entries');        $blocks[0]['info'] = t('Similar entries');
42          $blocks[0]['cache'] = BLOCK_CACHE_PER_PAGE | BLOCK_CACHE_PER_ROLE;
43        return $blocks;        return $blocks;
44    
45      case 'configure':      case 'configure':
# Line 250  function similar_block($op = 'list', $de Line 135  function similar_block($op = 'list', $de
135              // The subject is displayed at the top of the block. Note that it should              // The subject is displayed at the top of the block. Note that it should
136              // be passed through t() for translation.              // be passed through t() for translation.
137              $block['subject'] = t('Similar entries');              $block['subject'] = t('Similar entries');
138                $block['content'] = theme('similar_content', $node);
             $cache_blocks = variable_get('similar_cache', SIMILAR_CACHE_DISABLED);  
   
             if ($cache_blocks) {  
               $cached_content = cache_get("similar_block_0:$node->nid", 'cache');  
   
               if ($cached_content === 0) { // cache_get() only returns 0 when data is not returned for the key  
                 $block['content'] = theme('similar_content', $node);  
   
                 $lifetime = variable_get('similar_cache_lifetime', SIMILAR_CACHE_LIFETIME);  
   
                 cache_set("similar_block_0:$node->nid", $block['content'], 'cache', $lifetime ? time() + $lifetime : CACHE_TEMPORARY);  
               }  
               else {  
                 $block['content'] = $cached_content->data;  
               }  
             }  
             else {  
               $block['content'] = theme('similar_content', $node);  
             }  
139          }          }
140        }        }
141        return empty($block['content']) ? '' : $block;        return empty($block['content']) ? '' : $block;

Legend:
Removed from v.1.8.2.2  
changed lines
  Added in v.1.8.2.3

  ViewVC Help
Powered by ViewVC 1.1.2