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

Diff of /contributions/modules/zeitgeist/zeitgeist.module

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

revision 1.9.6.2, Sun Oct 14 16:52:53 2007 UTC revision 1.9.6.3, Thu Aug 7 19:55:06 2008 UTC
# Line 15  Line 15 
15   * after installing a new module version.   * after installing a new module version.
16   *   *
17   * @copyright  2005-2007 Frédéric G. MARAND   * @copyright  2005-2007 Frédéric G. MARAND
  * @license    http://www.cecill.info/licences/Licence_CeCILL_V2-en.html  
  * @version    CVS: $Id: zeitgeist.module,v 1.9.6.1 2007/08/27 22:45:48 fgm Exp $  
18   * @link       http://drupal.org/project/zeitgeist   * @link       http://drupal.org/project/zeitgeist
19   * @since      Drupal 4.7   * @since      Drupal 4.7
20     *
21     * Coding style:
22     * @link http://wiki.audean.com/coding
23     *
24     * @license Licensed under the CeCILL, version 2
25     *
26     * License note: G2 is distributed by OSInet to its customers under the
27     * CeCILL 2.0 license. OSInet support services only apply to the module
28     * when distributed by OSInet, not by any third-party further down the
29     * distribution chain.
30     *
31     * If you obtained G2 from drupal.org, that site received it under the
32     * GPL v2 or later license and can therefore distribute it under the GPL v2 or
33     * later, and so can you and just anyone down the chain as long as the GPL v2 or
34     * later terms are abided by, the module distributor in that case being the
35     * drupal.org organization or the downstream distributor, not OSInet.
36   */   */
37    
38    // $Id: zeitgeist.module,v 1.9.6.2 2007/10/14 16:52:53 fgm Exp $
39    
40  /**  /**
41   * Miscellaneous data   * Miscellaneous data
42   */   */
43  define('ZGSEARCHFORM',     'search_form');           // The name of the form to trap when recording searches  define('ZGSEARCHFORM',     'search_form');           // The name of the form to trap when recording searches
44  define('ZGTABLE',          '{zeitgeist}');           // The name of the table holding our data  define('ZGTABLE',          '{zeitgeist}');           // The name of the table holding our data
45  define('ZGVERSION',        '$Id: zeitgeist.module,v 1.9.6.1 2007/08/27 22:45:48 fgm Exp $');  define('ZGVERSION',        '$Id: zeitgeist.module,v 1.9.6.2 2007/10/14 16:52:53 fgm Exp $');
46  define('ZGSCHEMAVERSION',  'zg_schema_version');     // read-only  define('ZGSCHEMAVERSION',  'zg_schema_version');     // read-only
47  define('ZGONEDAY',         86400);                   // 24 hours * 60 minutes * 60 seconds  define('ZGONEDAY',         86400);                   // 24 hours * 60 minutes * 60 seconds
48    
49  /**  // Module paths
50    define('ZGPATHSETTINGS',   'admin/settings/zeitgeist');
51    define('ZGPATHPAGE',       'admin/reports/zeitgeist');
52    
53    /*
54   * Enumerations   * Enumerations
55   */   */
56    
57  // Time spans for the results of _zeitgeist_stats().  /*
58  // @see function _zeitgeist_stats()   * Time spans for the results of _zeitgeist_stats().
59     *
60     * @see _zeitgeist_stats()
61     */
62  define('ZGSPANDAY',           1); // Return zeitgeist for a day, starting at 00:00  define('ZGSPANDAY',           1); // Return zeitgeist for a day, starting at 00:00
63  define('ZGSPANWEEKM',         2); // Return zeitgeist for a calendar week, starting on Monday  define('ZGSPANWEEKM',         2); // Return zeitgeist for a calendar week, starting on Monday
64  define('ZGSPANWEEKS',         3); // Return zeitgeist for a calendar week, starting on Sunday  define('ZGSPANWEEKS',         3); // Return zeitgeist for a calendar week, starting on Sunday
# Line 59  define('ZGVALIDATEDISPLAY', 2); // U Line 82  define('ZGVALIDATEDISPLAY', 2); // U
82   */   */
83  define('ZGVARLATESTCLEAR', 'zeitgeist_latest_clear'); // What is the data of the latest history clear ?  define('ZGVARLATESTCLEAR', 'zeitgeist_latest_clear'); // What is the data of the latest history clear ?
84  define('ZGVARLATESTCOUNT', 'zeitgeist_latest_count'); // How many recent searches are displayed in their block ?  define('ZGVARLATESTCOUNT', 'zeitgeist_latest_count'); // How many recent searches are displayed in their block ?
85    define('ZGVARLATESTCACHE', 'zeitgeist_latest_cache'); // Block minimum caching duration in minutes
86  define('ZGVARTOPCOUNT',    'zeitgeist_top_count');    // How many top queries are displayed in their block ?  define('ZGVARTOPCOUNT',    'zeitgeist_top_count');    // How many top queries are displayed in their block ?
87  define('ZGVARTOPSPAN',     'zeitgeist_top_span');     // ZG span for the top queries block  define('ZGVARTOPSPAN',     'zeitgeist_top_span');     // ZG span for the top queries block
88  define('ZGVARPAGEHEIGHT',  'zeitgeist_page_height');  // Number of rows on the zeitgeist pager  define('ZGVARTOPCACHE',    'zeitgeist_top_cache');    // Block minimum caching duration in minutes
89  define('ZGVARHISTORY',     'zeitgeist_history');      // How long does the module keep its historical data.  define('ZGVARHISTORY',     'zeitgeist_history');      // How long does the module keep its historical data.
90  define('ZGVARNOFOLLOW',    'zeitgeist_nofollow');     // Emit a rel=nofollow attribute in feature blocks  define('ZGVARNOFOLLOW',    'zeitgeist_nofollow');     // Emit a rel=nofollow attribute in feature blocks
91    define('ZGVARPAGEHEIGHT',  'zeitgeist_page_height');  // Number of rows on the zeitgeist pager
92  define('ZGVARRECORDEMPTY', 'zeitgeist_record_empty'); // Record empty searches  define('ZGVARRECORDEMPTY', 'zeitgeist_record_empty'); // Record empty searches
93  define('ZGVARTYPE',        'zeitgeist_type');         // Display search type in "recent searches" blocks  define('ZGVARTYPE',        'zeitgeist_type');         // Display search type in "recent searches" blocks
94  define('ZGVARVALIDATION',  'zeitgeist_validation');   // Configure handling of HTML search strings  define('ZGVARVALIDATION',  'zeitgeist_validation');   // Configure handling of HTML search strings
# Line 78  define('ZGDEFHISTORY', 0); Line 103  define('ZGDEFHISTORY', 0);
103  define('ZGDEFNOFOLLOW',    1);                        // Default is true  define('ZGDEFNOFOLLOW',    1);                        // Default is true
104  define('ZGDEFPAGEHEIGHT',  20);                       // Number of rows on the zeitgeist pager  define('ZGDEFPAGEHEIGHT',  20);                       // Number of rows on the zeitgeist pager
105  define('ZGDEFRECORDEMPTY', 1);                        // Defaut is true: record empty queries  define('ZGDEFRECORDEMPTY', 1);                        // Defaut is true: record empty queries
106  define('ZGDEFTYPE',        0);                        // Default is never  define('ZGDEFTYPE',        ZGDISPLAYTYPEADMIN);       // Default is admin only
107  define('ZGDEFVALIDATION',  ZGVALIDATEDISPLAY);        // Default is validate upon display  define('ZGDEFVALIDATION',  ZGVALIDATEDISPLAY);        // Default is validate upon display
108    
109  /**  /**
110   * Block deltas   * Block deltas
111   */   */
112  define('ZGBLOCKLATEST',    0);  define('ZGBLOCKLATEST',    'latest');
113  define('ZGBLOCKTOP',       1);  define('ZGBLOCKTOP',       'top');
   
 // Module paths  
 define('ZGPATHSETTINGS',   'admin/settings/zeitgeist');  
 define('ZGPATHPAGE',       'admin/logs/zeitgeist');  
114    
115  /**  /**
116   * implement hook_help   * implement hook_help
# Line 121  function zeitgeist_help($section) Line 142  function zeitgeist_help($section)
142    }    }
143    
144  /**  /**
145   * implement hook_menu   * Implement hook_menu().
146   *   *
147   * @return array   * @return array
148   */   */
149  function zeitgeist_menu()  function zeitgeist_menu()
150    {    {
151      $items = array();
152    
153    $items[ZGPATHSETTINGS] = array    $items[ZGPATHSETTINGS] = array
154      (      (
155      'title'            => 'Zeitgeist',      'title'            => 'Zeitgeist',
156      'description'      => 'Define the various parameters used by the Zeitgeist module',      'description'      => 'Configuration of zeitgeist search recording and display.',
157      'page callback'    => 'drupal_get_form',      'page callback'    => 'drupal_get_form',
158      'page arguments'   => array('zeitgeist_admin_settings'),      'page arguments'   => array('_zeitgeist_admin_settings'),
159      'access arguments' => array('administer search'),      'access arguments' => array('administer search'),
160      'type'             => MENU_NORMAL_ITEM,      'type'             => MENU_NORMAL_ITEM,
161      );      );
162    
163    $items[ZGPATHPAGE] = array    $items[ZGPATHPAGE] = array
164      (      (
165      'title'              => t('Zeitgeist'),      'title'              => t('Zeitgeist report'),
166      'description'        => t('Feel the Zeitgeist'),      'description'        => t('Feel the Zeitgeist'),
167      'page callback'      => 'zeitgeist_page',      'page callback'      => '_zeitgeist_page',
168      'type'               => MENU_NORMAL_ITEM,      'type'               => MENU_NORMAL_ITEM,
169      'access arguments'   => array('administer search'),      'access arguments'   => array('administer search'),
170      );      );
171    
172    return $items;    return $items;
173    }    }
174    
# Line 153  function zeitgeist_menu() Line 177  function zeitgeist_menu()
177   *   *
178   * @return array An array containing form items to place on the module settings page.   * @return array An array containing form items to place on the module settings page.
179   */   */
180  function zeitgeist_admin_settings()  function _zeitgeist_admin_settings()
181    {    {
182    $form[ZGVARLATESTCOUNT] = array    $form[ZGVARHISTORY]     = array
183      (      (
184      '#type'               => 'textfield',      '#type'               => 'textfield',
185      '#title'              => t('Recent searches displayed'),      '#title'              => t('Number of days of history'),
186      '#description'        => t('This is the number of recent searches displayed in the "Recent Searches" block provided by the zeitgeist module. Default: %def.',      '#description'        => t('Historical data are kept for that number of days. 0 means forever. Pruning is performed by cron on a daily basis'),
187                                 array('%def' => ZGDEFLATESTCOUNT)),      '#default_value'      => variable_get(ZGVARHISTORY, ZGDEFHISTORY),
188      '#default_value'      => variable_get(ZGVARLATESTCOUNT, ZGDEFLATESTCOUNT),      '#size'               => 4, // this is good until 2037, should be enough for all 6.x needs.
189      '#maxlength'          => 2,      '#maxlength'          => 4,
190      '#size'               => 2,      );
191    
192      $form['zeitgeist-display'] = array
193        (
194        '#type'               => 'fieldset',
195        '#title'              => t('Display settings'),
196        '#collapsible'        => TRUE,
197      );      );
198    $form[ZGVARTOPCOUNT] = array  
199      $form['zeitgeist-display']['zeitgeist-top'] = array
200        (
201        '#type'               => 'fieldset',
202        '#title'              => t('"Top searches" block'),
203        '#collapsible'        => TRUE,
204        '#collapsed'          => TRUE,
205        );
206      $form['zeitgeist-display']['zeitgeist-top'][ZGVARTOPCOUNT] = array
207      (      (
208      '#type'               => 'textfield',      '#type'               => 'textfield',
209      '#title'              => t('Top searches displayed'),      '#title'              => t('Top searches displayed'),
210      '#description'        => t('This is the number of top searches displayed in the "Top Searches" block provided by the zeitgeist module. Default: %def.',      '#description'        => t('This is the number of top searches displayed in the "Top Searches" block provided by the zeitgeist module. Default: %def.',
211                                 array('%def' => ZGDEFTOPCOUNT)),        array('%def' => ZGDEFTOPCOUNT)),
212      '#default_value'      => variable_get(ZGVARTOPCOUNT, ZGDEFTOPCOUNT),      '#default_value'      => variable_get(ZGVARTOPCOUNT, ZGDEFTOPCOUNT),
213      '#maxlength'          => 2,      '#maxlength'          => 2,
214      '#size'               => 2,      '#size'               => 2,
215      );      );
216    $form[ZGVARHISTORY]     = array    $form['zeitgeist-display']['zeitgeist-top'][ZGVARTOPCACHE] = array
217      (      (
218      '#type'               => 'textfield',      '#type'               => 'textfield',
219      '#title'              => t('Number of days of history'),      '#title'              => t('Cache expiration'),
220      '#description'        => t('Historical data are kept for that number of days. 0 means forever. Pruning is performed by cron on a daily basis'),      '#description'        => t('Block minimum caching duration in minutes (1 day = 1440 minutes). Note that blocks are cached as themed.'),
221      '#default_value'      => variable_get(ZGVARHISTORY, ZGDEFHISTORY),      '#default_value'      => variable_get(ZGVARTOPCACHE, 0),
222      '#size'               => 4, // this is good until 2037, should be enough for all 4.7 needs.      '#size'               => 5,
223      '#max_length'         => 4,      '#maxlength'          => 5,
224        );
225    
226      $form['zeitgeist-display']['zeitgeist-latest'] = array
227        (
228        '#type'               => 'fieldset',
229        '#title'              => t('"Latest searches" block'),
230        '#collapsible'        => TRUE,
231        '#collapsed'          => TRUE,
232        );
233      $form['zeitgeist-display']['zeitgeist-latest'][ZGVARLATESTCOUNT] = array
234        (
235        '#type'               => 'textfield',
236        '#title'              => t('Latest searches displayed'),
237        '#description'        => t('This is the number of recent searches displayed in the "Latest Searches" block provided by the zeitgeist module. Default: %def.',
238          array('%def' => ZGDEFLATESTCOUNT)),
239        '#default_value'      => variable_get(ZGVARLATESTCOUNT, ZGDEFLATESTCOUNT),
240        '#maxlength'          => 2,
241        '#size'               => 2,
242      );      );
243    $form[ZGVARTYPE]        = array    $form['zeitgeist-display']['zeitgeist-latest'][ZGVARTYPE]        = array
244      (      (
245      '#type'               => 'radios',      '#type'               => 'radios',
246      '#title'              => t('When should the search type be displayed in the "recent searches" blocks ?'),      '#title'              => t('When should the search type be displayed in the "Latest searches" block ?'),
247      '#default_value'      => variable_get(ZGVARTYPE, ZGDEFTYPE),      '#default_value'      => variable_get(ZGVARTYPE, ZGDEFTYPE),
248      '#options'            => array      '#options'            => array
249        (        (
# Line 198  function zeitgeist_admin_settings() Line 254  function zeitgeist_admin_settings()
254        ),        ),
255      '#description'        => t('<p>Recommended value is "Admin only"; "Always" is typically disturbing for visitors not already well-versed in Drupal.</p>'),      '#description'        => t('<p>Recommended value is "Admin only"; "Always" is typically disturbing for visitors not already well-versed in Drupal.</p>'),
256      );      );
257    $form[ZGVARVALIDATION]    = array    $form['zeitgeist-display']['zeitgeist-latest'][ZGVARLATESTCACHE] = array
258        (
259        '#type'               => 'textfield',
260        '#title'              => t('Cache expiration'),
261        '#description'        => t('Block minimum caching duration in minutes (1 day = 1440 minutes). Note that blocks are cached as themed.'),
262        '#default_value'      => variable_get(ZGVARLATESTCACHE, 0),
263        '#size'               => 5,
264        '#maxlength'          => 5,
265        );
266    
267      $form['zeitgeist-display']['zeitgeist-page'] = array
268        (
269        '#type'               => 'fieldset',
270        '#title'              => t('Default zeitgeist page'),
271        '#collapsible'        => TRUE,
272        '#collapsed'          => TRUE,
273        );
274      $form['zeitgeist-display']['zeitgeist-page'][ZGVARPAGEHEIGHT]  = array
275        (
276        '#type'               => 'textfield',
277        '#title'              => t('Height of the zeitgeist pager'),
278        '#default_value'      => variable_get(ZGVARPAGEHEIGHT, ZGDEFPAGEHEIGHT),
279        '#size'               => 3,
280        '#maxlength'          => 3,
281        );
282    
283      $form['zeigeist-filtering'] = array
284        (
285        '#type'               => 'fieldset',
286        '#title'              => t('Search filtering'),
287        '#collapsible'        => TRUE,
288        '#collapsed'          => TRUE,
289        );
290      $form['zeigeist-filtering'][ZGVARVALIDATION]    = array
291      (      (
292      '#type'               => 'radios',      '#type'               => 'radios',
293      '#title'              => t('How should search strings be validated to prevent spamming "recent searches" blocks ?'),      '#title'              => t('How should search strings be validated to prevent spamming ZG blocks ?'),
294      '#default_value'      => variable_get(ZGVARVALIDATION, ZGDEFVALIDATION),      '#default_value'      => variable_get(ZGVARVALIDATION, ZGDEFVALIDATION),
295      '#options'            => array      '#options'            => array
296        (        (
# Line 211  function zeitgeist_admin_settings() Line 300  function zeitgeist_admin_settings()
300        ),        ),
301      '#description'        => t('<p>Recommended value is "Do not record HTML": spammers may abuse ZG by submitting links via scripts.</p>'),      '#description'        => t('<p>Recommended value is "Do not record HTML": spammers may abuse ZG by submitting links via scripts.</p>'),
302      );      );
303    $form[ZGVARRECORDEMPTY] = array    $form['zeigeist-filtering'][ZGVARRECORDEMPTY] = array
304      (      (
305      '#type'               => 'checkbox',      '#type'               => 'checkbox',
306      '#title'              => t('Should Zeitgeist record empty searches ?'),      '#title'              => t('Should Zeitgeist record empty searches ?'),
# Line 235  function zeitgeist_admin_settings() Line 324  function zeitgeist_admin_settings()
324      '#default_value'      => variable_get(ZGVARNOFOLLOW, ZGDEFNOFOLLOW),      '#default_value'      => variable_get(ZGVARNOFOLLOW, ZGDEFNOFOLLOW),
325      '#return_value'       => 1,      '#return_value'       => 1,
326      '#description'        => t('An attribute for the "a" (X)HTML alement, !attr is non-standard, but is recognized by several search engines, notably Google, MSN and Yahoo!',      '#description'        => t('An attribute for the "a" (X)HTML alement, !attr is non-standard, but is recognized by several search engines, notably Google, MSN and Yahoo!',
327                                 array('!attr' => '<code>rel="nofollow"</code>')),        array('!attr' => '<code>rel="nofollow"</code>')),
328      );      );
329    $form['advanced'][ZGVERSION] = array    $form['advanced'][ZGVERSION] = array
330      (      (
# Line 343  function zeitgeist_block($op = 'list', $ Line 432  function zeitgeist_block($op = 'list', $
432            $form = array();            $form = array();
433            break;            break;
434          }          }
435          _zeitgeist_admin_settings_submit(NULL, NULL); // clear cache
436        return $form;        return $form;
437        break;        break;
438    
# Line 350  function zeitgeist_block($op = 'list', $ Line 440  function zeitgeist_block($op = 'list', $
440        switch ($delta)        switch ($delta)
441          {          {
442          case ZGBLOCKLATEST:          case ZGBLOCKLATEST:
443            _zeitgeist_block_settings_save($edit, 'latest');            _zeitgeist_block_settings_save($edit, ZGBLOCKLATEST);
444            break;            break;
445          case ZGBLOCKTOP:          case ZGBLOCKTOP:
446            _zeitgeist_block_settings_save($edit, 'top');            _zeitgeist_block_settings_save($edit, ZGBLOCKTOP);
447            break;            break;
448          }          }
449        break;        break;
# Line 364  function zeitgeist_block($op = 'list', $ Line 454  function zeitgeist_block($op = 'list', $
454            $count = variable_get(ZGVARLATESTCOUNT, ZGDEFLATESTCOUNT);            $count = variable_get(ZGVARLATESTCOUNT, ZGDEFLATESTCOUNT);
455            $subject = variable_get('zeitgeist_latest_title', t('Latest %count searches'));            $subject = variable_get('zeitgeist_latest_title', t('Latest %count searches'));
456            $subject = t($subject, array('%count' => $count));            $subject = t($subject, array('%count' => $count));
457            $block['subject'] = $subject;            $now = time();
458            $block['content'] = theme('zeitgeist_block_latest', $count);            $cache = cache_get(ZGCIDLATEST, 'cache');
459              if (empty($cache) || ($now >= $cache->expire))
460                {
461                $block = array
462                  (
463                  'subject' => $subject,
464                  'content' => theme('zeitgeist_block_latest', $count),
465                  );
466                cache_set(ZGCIDLATEST, 'cache', serialize($block), $expires = $now + 60 * variable_get(ZGVARLATESTCACHE, 0));
467                }
468              else
469                {
470                $block = unserialize($cache->data);
471                }
472            break;            break;
473          case ZGBLOCKTOP:          case ZGBLOCKTOP:
           $count = variable_get(ZGVARTOPCOUNT, ZGDEFTOPCOUNT);  
474            $subject = variable_get('zeitgeist_top_title', t('Top %count searches'));            $subject = variable_get('zeitgeist_top_title', t('Top %count searches'));
475            $subject = t($subject, array('%count' => $count));            $subject = t($subject, array('%count' => $count));
476            $block['subject'] = $subject;            $now = time();
477            $block['content'] = theme('zeitgeist_block_top', $count);            $cache = cache_get(ZGCIDTOP);
478              if (empty($cache) || ($now >= $cache->expire))
479                {
480                $block = array
481                  (
482                  'subject' => $subject,
483                  'content' => theme('zeitgeist_block_top', $count),
484                  );
485                cache_set(ZGCIDTOP, 'cache', serialize($block), $expires = $now + 60 * variable_get(ZGVARTOPCACHE, 0));
486                }
487              else
488                {
489                $block = unserialize($cache->data);
490                }
491          break;          break;
492          }          }
493        return $block;        return $block;
# Line 397  function _zeitgeist_store_search($search Line 512  function _zeitgeist_store_search($search
512    }    }
513    
514  /**  /**
515   * Provides the block-specific contents common to each ZG block: ability to rename the block and change its title   * Provides the block-specific contents common to each ZG block:
516     * ability to rename the block.
517   *   *
518   * @param array $form The current form for which this is built   * @param array $form The current form for which this is built
519   * @param string $infotitle Block information: the title   * @param string $infotitle Block information: the title
# Line 602  function _zeitgeist_clear_older($days) Line 718  function _zeitgeist_clear_older($days)
718    $today = _zeitgeist_date();    $today = _zeitgeist_date();
719    $limit = _zeitgeist_date($today - $days * 60 * 60 * 24);    $limit = _zeitgeist_date($today - $days * 60 * 60 * 24);
720    $sq = 'DELETE FROM {zeitgeist} WHERE ts < %d';    $sq = 'DELETE FROM {zeitgeist} WHERE ts < %d';
721    /* $q = */ db_query($sq, $limit);    db_query($sq, $limit);
722    }    }
723    
724  /**  /**
# Line 633  function zeitgeist_cron() Line 749  function zeitgeist_cron()
749   */   */
750  function theme_zeitgeist_block_top($count = NULL)  function theme_zeitgeist_block_top($count = NULL)
751    {    {
752      if (is_null($count))
753        {
754        $count = variable_get(ZGVARTOPCOUNT, ZGDEFTOPCOUNT);
755        }
756      $ts = null;
757    
758      /**
759       * Uncomment this fragment for last month's zeitgeist. Leave it commented for
760       * the current month
761       *
762    $arDate = getdate();    $arDate = getdate();
763    // Uncomment that line for last month's zeitgeist. Leave it commented for the current month    $ts = mktime(0, 0, 0, $arDate['mon'] - 1, 1, $arDate['year']); // mktime wraps months cleanly, no worry
764    // $ts = mktime(0, 0, 0, $arDate['mon'] - 1, 1, $arDate['year']); // mktime wraps months cleanly, no worry    unset($arDate);
765    unset ($arDate);     * -- end of fragment
766       */
767    
768    $arStats = _zeitgeist_stats(ZGSPANMONTH, $ts, 'node', $count);    $arStats = _zeitgeist_stats(ZGSPANMONTH, $ts, 'node', $count);
769    $arScores = array();    $arScores = array();
770    $attr = variable_get(ZGVARNOFOLLOW, ZGDEFNOFOLLOW) ? array ('rel' => 'nofollow') : NULL ;    $attr = variable_get(ZGVARNOFOLLOW, ZGDEFNOFOLLOW)
771    $attr = array_merge($attr, array('absolute' => true));      ? array('rel' => 'nofollow')
772        : NULL ;
773      $attr = array_merge($attr, array('absolute' => TRUE));
774    foreach ($arStats->scores as $score)    foreach ($arStats->scores as $score)
775      {      {
776      $arScores [] = l($score['search'] . " (${score['count']})",      $arScores[] = l($score['search'] . " (${score['count']})",
777        "search/node/$score[search]", $attr);        "search/node/$score[search]", $attr);
778      }      }
779    unset($arStats);    unset($arStats);
780    
781    $ret = theme('item_list', $arScores);    $ret = theme('item_list', $arScores);
782    unset ($arScores);    unset($arScores);
783    
784    return $ret;    return $ret;
785    }    }
786    
# Line 663  function theme_zeitgeist_block_latest($c Line 793  function theme_zeitgeist_block_latest($c
793    {    {
794    $ar = _zeitgeist_block_latest($count);    $ar = _zeitgeist_block_latest($count);
795    $arLinks = array();    $arLinks = array();
796    $attr = variable_get(ZGVARNOFOLLOW, ZGDEFNOFOLLOW) ? array ('rel' => 'nofollow') : NULL ;    $attr = variable_get(ZGVARNOFOLLOW, ZGDEFNOFOLLOW)
797      ? array('rel' => 'nofollow')
798      : NULL;
799    $attr = array_merge($attr, array('absolute' => true));    $attr = array_merge($attr, array('absolute' => true));
800    foreach ($ar as $key => $value)    foreach ($ar as $key => $value)
801      {      {
# Line 736  function _zeitgeist_validate($search, $t Line 868  function _zeitgeist_validate($search, $t
868    }    }
869    
870  /**  /**
871   * implement hook_theme   * Sample basic stats page. Note that you can obtain much more finely
872     * tuned results for human-sensible time spans using _zeitgeist_stats
873     * and you won't even need to query the DB yourself !
874     *
875     * @return string HTML
876     */
877    function zeitgeist_page_single_column()
878      {
879      $height = variable_get(ZGVARPAGEHEIGHT, ZGDEFPAGEHEIGHT); // pager height
880    
881      $sq = 'SELECT zg.search, count(zg.ts) cnt '
882        . 'FROM {zeitgeist} zg '
883        . 'WHERE '
884        . " (zg.category = 'node') "
885        . 'GROUP BY 1 '
886        . 'ORDER BY 2 DESC, 1 ASC ';
887    
888      $sq_count = 'SELECT count(DISTINCT zg.search) cnt '
889        . 'FROM {zeitgeist} zg '
890        . 'WHERE '
891        . " (zg.category = 'node') ";
892    
893      $q = pager_query($sq, $height, 0, $sq_count);
894      $ar = array();
895      $cnt = 0;
896      while ($o = db_fetch_object($q))
897        {
898        $ar[] = "$o->cnt - " . l($o->search, "search/node/$o->search");
899        $cnt += $o->cnt;
900        }
901      $ret .= theme('item_list', $ar);
902      $ret .= '<p>' . t('For a total of %cnt hits for these %height searches.',
903        array
904          (
905          '%cnt' => $cnt,
906          '%height' => $height,
907          )
908        ) . "</p>\n";
909      $ret .= theme('pager');
910      return $ret;
911      }
912    
913    /**
914     * Sample page showing ZG results. For smarter results, build your own page with
915     * _zeitgeist_stats and the ZGSPAN* human-oriented durations constants
916     *
917     * @param int $days
918     * @return string
919     * @see _zeitgeist_stats()
920     */
921    function _zeitgeist_page($days = 30)
922      {
923      if (!is_numeric($days))
924        {
925        $days = 30;
926        }
927      $height = variable_get(ZGVARPAGEHEIGHT, ZGDEFPAGEHEIGHT); // pager height
928    
929      drupal_set_title(t('Zeitgeist over the last !days days',
930        array('!days' => $days)));
931      $limit = time() - ZGONEDAY * $days ;
932    
933    
934      $arRecherches = array();
935      $sq = 'SELECT DISTINCT search, count(ts) AS nts '
936          . 'FROM {zeitgeist} z '
937       // . "WHERE z.category = 'node' "
938          . 'WHERE z.ts >= %d '
939          . 'GROUP BY search '
940          . 'ORDER BY nts DESC, search ASC ';
941      $q = db_query_range($sq, $limit, 0, $height * 3);
942      while ($o = db_fetch_array($q))
943        {
944        if ($o['search'] == '')
945          $o['search'] = '&lt;vide&gt;';
946        $arRecherches[$o['search']] = $o['nts'];
947        }
948    
949      $n = count($arRecherches);
950      $mod = $n % 3;
951    
952      $break = count($arRecherches) / 3;
953      $rows = array();
954      $i = 0;
955      foreach ($arRecherches as $search => $count)
956        {
957        if ($i < $break)
958          {
959          $rows[$i] = array
960            (
961            $search, $count,
962            null, null,
963            null, null,
964            );
965          }
966        elseif ($i < 2 * $break)
967          {
968          $rows[$i - $break][2] = $search;
969          $rows[$i - $break][3] = $count;
970          }
971        else
972          {
973          $rows[$i - 2 * $break][4] = $search;
974          $rows[$i - 2 * $break][5] = $count;
975          }
976        $i++;
977        }
978    
979      $header = array
980        (
981        t('Search'), t('#'),
982        t('Search'), t('#'),
983        t('Search'), t('#'),
984        );
985      $attributes = array
986        (
987        );
988    
989      $ret = theme_table($header, $rows, $attributes);
990    
991      $ret .= t('<p>Searches below the pager !limit are not included in this list.</p>',
992        array('!limit' => l(t('limit'), ZGPATHSETTINGS)));
993      return $ret;
994      }
995    
996    /**
997     * When changing ZG settings, clear the ZG block cache, since its content
998     * will often be affected by the changes.
999     *
1000     * @param string $form_id
1001     * @param array $form_values
1002     */
1003    function _zeitgeist_admin_settings_submit($form_id, $form_values)
1004      {
1005      cache_clear_all(ZGCIDLATEST, 'cache');
1006      cache_clear_all(ZGCIDTOP, 'cache');
1007      }
1008    
1009    /**
1010     * Implement the new Drupal 6 hook_theme()
1011   *   *
1012   * @return array   * @return array
1013   */   */

Legend:
Removed from v.1.9.6.2  
changed lines
  Added in v.1.9.6.3

  ViewVC Help
Powered by ViewVC 1.1.2