includes/template.php
changeset 971 bc8f3ab74e5e
parent 957 6b7644fec887
child 978 ed84b24b8e07
equal deleted inserted replaced
970:d894086f38cc 971:bc8f3ab74e5e
    60   var $fading_button = '';
    60   var $fading_button = '';
    61   
    61   
    62   function __construct()
    62   function __construct()
    63   {
    63   {
    64     global $db, $session, $paths, $template, $plugins; // Common objects
    64     global $db, $session, $paths, $template, $plugins; // Common objects
       
    65     global $cache;
    65     
    66     
    66     $this->tpl_bool    = Array();
    67     $this->tpl_bool    = Array();
    67     $this->tpl_strings = Array();
    68     $this->tpl_strings = Array();
    68     $this->sidebar_extra = '';
    69     $this->sidebar_extra = '';
    69     $this->toolbar_menu = '';
    70     $this->toolbar_menu = '';
    83     if ( defined('IN_ENANO_UPGRADE') )
    84     if ( defined('IN_ENANO_UPGRADE') )
    84     {
    85     {
    85       return $this->construct_compat();
    86       return $this->construct_compat();
    86     }
    87     }
    87     
    88     
    88     $q = $db->sql_query('SELECT theme_id, theme_name, enabled, default_style, group_policy, group_list FROM ' . table_prefix . 'themes;');
    89     if ( !$this->theme_list = $cache->fetch('themes') )
    89     if ( !$q )
    90     {
    90       $db->_die('template.php selecting theme list');
    91       $q = $db->sql_query('SELECT theme_id, theme_name, enabled, default_style, group_policy, group_list FROM ' . table_prefix . 'themes;');
    91     
    92       if ( !$q )
    92     $i = 0;
    93         $db->_die('template.php selecting theme list');
    93     while ( $row = $db->fetchrow() )
    94       
    94     {
    95       $i = 0;
    95       $this->theme_list[$i] = $row;
    96       while ( $row = $db->fetchrow() )
    96       $i++;
    97       {
    97     }
    98         $this->theme_list[$i] = $row;
    98     unset($theme);
    99         $i++;
    99     $this->theme_list = array_values($this->theme_list);
   100       }
       
   101       unset($theme);
       
   102       $this->theme_list = array_values($this->theme_list);
       
   103       $cache->store('themes', $this->theme_list, -1);
       
   104     }
       
   105     
   100     // Create associative array of themes
   106     // Create associative array of themes
   101     foreach ( $this->theme_list as $i => &$theme )
   107     foreach ( $this->theme_list as $i => &$theme )
   102       $this->named_theme_list[ $theme['theme_id'] ] =& $this->theme_list[$i];
   108       $this->named_theme_list[ $theme['theme_id'] ] =& $this->theme_list[$i];
       
   109     
       
   110     unset($theme);
   103     
   111     
   104     $this->default_theme = ( $_ = getConfig('theme_default') ) ? $_ : $this->theme_list[0]['theme_id'];
   112     $this->default_theme = ( $_ = getConfig('theme_default') ) ? $_ : $this->theme_list[0]['theme_id'];
   105     $this->named_theme_list[ $this->default_theme ]['css'] = $this->get_theme_css_files($this->default_theme);
   113     $this->named_theme_list[ $this->default_theme ]['css'] = $this->get_theme_css_files($this->default_theme);
   106     // Come up with the default style. If the CSS file specified in default_style exists, we're good, just
   114     // Come up with the default style. If the CSS file specified in default_style exists, we're good, just
   107     // use that. Otherwise, use the first stylesheet that comes to mind.
   115     // use that. Otherwise, use the first stylesheet that comes to mind.
   750     
   758     
   751     // Page toolbar
   759     // Page toolbar
   752     // Comments button
   760     // Comments button
   753     if ( $conds['comments'] )
   761     if ( $conds['comments'] )
   754     {
   762     {
   755       $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$this->page_id.'\' AND namespace=\''.$this->namespace.'\';');
   763       $cdata = $this->page->ns->get_cdata();
   756       if ( !$e )
   764       if ( isset($cdata['comments_approved']) )
   757       {
   765       {
   758         $db->_die();
   766         $approval_counts = array(
   759       }
   767             COMMENT_APPROVED => $cdata['comments_approved'],
   760       $num_comments = $db->numrows();
   768             COMMENT_UNAPPROVED => $cdata['comments_unapproved'],
   761       $approval_counts = array(COMMENT_UNAPPROVED => 0, COMMENT_APPROVED => 0, COMMENT_SPAM => 0);
   769             COMMENT_SPAM => $cdata['comments_spam']
   762       
   770           );
   763       while ( $r = $db->fetchrow() )
   771         $num_comments = array_sum($approval_counts);
   764       {  
   772       }
   765         $approval_counts[$r['approved']]++;
   773       else
       
   774       {
       
   775         $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$this->page_id.'\' AND namespace=\''.$this->namespace.'\';');
       
   776         if ( !$e )
       
   777         {
       
   778           $db->_die();
       
   779         }
       
   780         $num_comments = $db->numrows();
       
   781         $approval_counts = array(COMMENT_UNAPPROVED => 0, COMMENT_APPROVED => 0, COMMENT_SPAM => 0);
       
   782         
       
   783         while ( $r = $db->fetchrow() )
       
   784         {  
       
   785           $approval_counts[$r['approved']]++;
       
   786         }
   766       }
   787       }
   767       
   788       
   768       $db->free_result();
   789       $db->free_result();
   769       // $n = ( $session->check_acl_scope('mod_comments', $this->namespace) && $perms->get_permissions('mod_comments') ) ? (string)$num_comments : (string)$na;
   790       // $n = ( $session->check_acl_scope('mod_comments', $this->namespace) && $perms->get_permissions('mod_comments') ) ? (string)$num_comments : (string)$na;
   770       if ( $session->check_acl_scope('mod_comments', $this->namespace) && $this->page->perms->get_permissions('mod_comments') && ( $approval_counts[COMMENT_UNAPPROVED] + $approval_counts[COMMENT_SPAM] ) > 0 )
   791       if ( $session->check_acl_scope('mod_comments', $this->namespace) && $this->page->perms->get_permissions('mod_comments') && ( $approval_counts[COMMENT_UNAPPROVED] + $approval_counts[COMMENT_SPAM] ) > 0 )
  1362       $t_loc = $lang->get('page_msg_stats_gentime_short', array('time' => $f));
  1383       $t_loc = $lang->get('page_msg_stats_gentime_short', array('time' => $f));
  1363       $t_loc_long = $lang->get('page_msg_stats_gentime_long', array('time' => $f));
  1384       $t_loc_long = $lang->get('page_msg_stats_gentime_long', array('time' => $f));
  1364       $q_loc = '<a href="' . $this->tpl_strings['REPORT_URI'] . '">' . $lang->get('page_msg_stats_sql', array('nq' => $db->num_queries)) . '</a>';
  1385       $q_loc = '<a href="' . $this->tpl_strings['REPORT_URI'] . '">' . $lang->get('page_msg_stats_sql', array('nq' => $db->num_queries)) . '</a>';
  1365       $dbg = $t_loc;
  1386       $dbg = $t_loc;
  1366       $dbg_long = $t_loc_long;
  1387       $dbg_long = $t_loc_long;
  1367       if ( $session->user_level >= USER_LEVEL_ADMIN )
  1388       if ( $session->user_level >= USER_LEVEL_ADMIN || defined('ENANO_DEBUG') )
  1368       {
  1389       {
  1369         $dbg .= "&nbsp;&nbsp;|&nbsp;&nbsp;$q_loc";
  1390         $dbg .= "&nbsp;&nbsp;|&nbsp;&nbsp;$q_loc";
  1370         $dbg_long .= "&nbsp;&nbsp;|&nbsp;&nbsp;$q_loc";
  1391         $dbg_long .= "&nbsp;&nbsp;|&nbsp;&nbsp;$q_loc";
  1371       }
  1392       }
  1372       
  1393       
  1803     // Images
  1824     // Images
  1804     $message = RenderMan::process_image_tags($message, $taglist);
  1825     $message = RenderMan::process_image_tags($message, $taglist);
  1805     $message = RenderMan::process_imgtags_stage2($message, $taglist);
  1826     $message = RenderMan::process_imgtags_stage2($message, $taglist);
  1806     
  1827     
  1807     // Internal links
  1828     // Internal links
  1808     $message = RenderMan::parse_internal_links($message, $tplvars['sidebar_button']);
  1829     $message = RenderMan::parse_internal_links($message, $tplvars['sidebar_button'], false);
  1809     
  1830     
  1810     // External links
  1831     // External links
  1811     
  1832     
  1812     $url_regexp = <<<EOF
  1833     $url_regexp = <<<EOF
  1813 (
  1834 (