Ignore:
Timestamp:
Oct 28, 2010, 12:19:44 AM (13 years ago)
Author:
plg
Message:

bug fixed: ability to use a Google Analytics/Piwik javascript code including a
comma.

simpler code, easier to maintain I hope.

change file format from MacOs to Unix line endings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Statistics/main.inc.php

    r3438 r7445  
    22/*
    33Plugin Name: Statistics
    4 Version: 2.0.b
     4Version: 2.0.c
    55Description: Add source code like Google Analytics on each page.
    66Plugin URI: http://phpwebgallery.net/ext/extension_view.php?eid=174
     
    1010if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    1111define('STAT_DIR' , basename(dirname(__FILE__)));
    12 
    1312define('STAT_PATH' , PHPWG_PLUGINS_PATH . STAT_DIR . '/');
    1413
    1514function statistics_admin_menu($menu)
    16 
    1715{
    18 
    19     array_push($menu, array('NAME' => 'Statistics',
    20 
    21       'URL' => get_admin_plugin_menu_link(STAT_PATH . 'admin/stat_admin.php')));
    22 
    23     return $menu;
    24 
     16  array_push(
     17    $menu,
     18    array(
     19      'NAME' => 'Statistics',
     20      'URL' => get_admin_plugin_menu_link(STAT_PATH . 'admin/stat_admin.php')
     21      )
     22    );
     23  return $menu;
    2524}
    2625
     26function stat_candoit($type)
     27{
     28  global $conf, $user;
     29
     30  $conf_statistics = unserialize($conf['statistics']);
     31
     32  if (is_admin() and $conf_statistics['exclude_admin'])
     33  {
     34    return false;
     35  }
     36
     37  if (is_a_guest() and $conf_statistics['exclude_guest'])
     38  {
     39    return false;
     40  }
    2741
    2842
    29 function stat_candoit($type)
    30 
    31 {
    32 
    33   global $conf, $user;
    34 
    35 
    36 
    37   $conf_statistics = explode("," , $conf['statistics']);
    38 
    39 
    40 
    41   $is_guest = (function_exists('is_a_guest') ? is_a_guest() : $user['is_the_guest']);
    42 
    43 
    44 
    45   if
    46 
    47   (
    48 
    49     (
    50 
    51       (($conf_statistics[0] == 'on') and ($type == 'header')) or
    52 
    53       (($conf_statistics[1] == 'on') and ($type == 'tail'))
    54 
    55     ) and
    56 
    57     (($conf_statistics[3] == 'on' and !is_admin()) or (empty($conf_statistics[3]))) and
    58 
    59     (($conf_statistics[4] == 'on' and !$is_guest) or (empty($conf_statistics[4])))
    60 
    61   )
    62 
     43  $show_htmlcontent = false;
     44  if ($conf_statistics['header'] and $type == 'header')
    6345  {
    64 
    65     return '
    66 
    67 <!-- Plugin Statitics -->
    68 
    69 '.$conf_statistics[2].'
    70 
    71 <!-- Plugin Statitics -->';
    72 
     46    $show_htmlcontent = true;
     47  }
     48  if ($conf_statistics['tail'] and $type == 'tail')
     49  {
     50    $show_htmlcontent = true;
    7351  }
    7452
    75   else
    76 
     53  if (!$show_htmlcontent)
    7754  {
    78 
    7955    return false;
    80 
    8156  }
    8257
     58  return '
     59<!-- Plugin Statistics -->
     60'.$conf_statistics['content'].'
     61<!-- Plugin Statistics -->
     62';
    8363}
     64
    8465function stat_tail()
    8566{
     67  global $template;
    8668
    87   global $template;
    8869  if ($code_stat = stat_candoit('tail'))
    89 
    9070  {
    91 
    9271    $template->append('footer_elements', $code_stat);
    93 
    9472  }
    95 
    9673}
    9774
    98 
    99 
    10075function stat_header()
    101 
    10276{
    103 
    10477  global $template;
    10578
     79  if ($code_stat = stat_candoit('header'))
     80  {
     81    $template->append('head_elements', $code_stat);
     82  }
     83}
    10684
    107 
    108   if ($code_stat = stat_candoit('header'))
    109 
    110   {
    111 
    112     $template->append('head_elements', $code_stat);
    113 
    114   }
    115 
    116 }
    11785add_event_handler('get_admin_plugin_menu_links', 'statistics_admin_menu');
    11886add_event_handler('loc_end_page_tail', 'stat_tail');
    11987add_event_handler('loc_end_page_header', 'stat_header');
    120 
    12188?>
Note: See TracChangeset for help on using the changeset viewer.