includes/template.php
changeset 607 935f3799b654
parent 598 4e5985fffc4d
child 615 8eed90734867
equal deleted inserted replaced
605:d2d4e40ecd29 607:935f3799b654
  2012    */
  2012    */
  2013    
  2013    
  2014   function fetch_sidebar()
  2014   function fetch_sidebar()
  2015   {
  2015   {
  2016     global $db, $session, $paths, $template, $plugins; // Common objects
  2016     global $db, $session, $paths, $template, $plugins; // Common objects
       
  2017     global $cache;
  2017     
  2018     
  2018     $left = '';
  2019     $left = '';
  2019     $right = '';
  2020     $right = '';
  2020     
  2021     
  2021     // check the cache
  2022     // check the cache
  2022     $cache_enable = getConfig('cache_thumbs') == '1' && !$session->user_logged_in;
  2023     if ( !$session->user_logged_in && $data = $cache->fetch('anon_sidebar') )
  2023     $cache_file = ENANO_ROOT . "/cache/cache_anon_sidebar.php";
  2024     {
  2024     $cache_fresh = intval(getConfig('sidebar_anon_cache_time') + 600) >= time();
  2025       if ( @$data['_theme_'] === $this->theme )
  2025     if ( $cache_enable && $cache_fresh )
  2026       {
  2026     {
  2027         unset($data['_theme_']);
  2027       @include($cache_file);
  2028         return $data;
  2028       if ( isset($sidebar_cache) )
       
  2029       {
       
  2030         // we loaded the cache!
       
  2031         foreach ( $sidebar_cache as $i => $_ )
       
  2032         {
       
  2033           $block =& $sidebar_cache[$i];
       
  2034           $block = str_replace('$USERNAME$', $session->username, $block);
       
  2035         }
       
  2036         return $sidebar_cache;
       
  2037       }
  2029       }
  2038     }
  2030     }
  2039     
  2031     
  2040     if ( !$this->fetch_block('Links') )
  2032     if ( !$this->fetch_block('Links') )
  2041       $this->initLinksWidget();
  2033       $this->initLinksWidget();
  2077           $c = ob_get_contents();
  2069           $c = ob_get_contents();
  2078           ob_end_clean();
  2070           ob_end_clean();
  2079           break;
  2071           break;
  2080         case BLOCK_PLUGIN:
  2072         case BLOCK_PLUGIN:
  2081           $parser = $this->makeParserText('{CONTENT}');
  2073           $parser = $this->makeParserText('{CONTENT}');
  2082           $c = (gettype($this->fetch_block($row['block_content'])) == 'string') ? $this->fetch_block($row['block_content']) : /* This used to say "can't find plugin block" but I think it's more friendly to just silently hide it. */ '';
  2074           $c = '<!-- PLUGIN -->' . (gettype($this->fetch_block($row['block_content'])) == 'string') ? $this->fetch_block($row['block_content']) : /* This used to say "can't find plugin block" but I think it's more friendly to just silently hide it. */ '';
  2083           break;
  2075           break;
  2084       }
  2076       }
  2085       // is there a {restrict} or {hideif} block?
  2077       // is there a {restrict} or {hideif} block?
  2086       if ( preg_match('/\{(restrict|hideif) ([a-z0-9_\(\)\|&! ]+)\}/', $c, $match) )
  2078       if ( preg_match('/\{(restrict|hideif) ([a-z0-9_\(\)\|&! ]+)\}/', $c, $match) )
  2087       {
  2079       {
  2123     if(isset($vars['sidebar_bottom']))
  2115     if(isset($vars['sidebar_bottom']))
  2124     {
  2116     {
  2125       $min .= $bottom;
  2117       $min .= $bottom;
  2126     }
  2118     }
  2127     $return = Array($left, $right, $min);
  2119     $return = Array($left, $right, $min);
  2128     if ( $cache_enable )
  2120     if ( getConfig('cache_thumbs') == '1' && !$session->user_logged_in )
  2129     {
  2121     {
  2130       $cachestore = Language::var_export_string($return);
  2122       $cachestore = enano_json_encode($return);
  2131       $cachestore = str_replace($session->username, '$USERNAME$', $cachestore);
  2123       $cachestore = str_replace($session->username, '$USERNAME$', $cachestore);
  2132       $cachestore = <<<EOF
  2124       $cachestore = str_replace($paths->page, '$PAGEID$', $cachestore);
  2133 <?php
  2125       $cachestore = enano_json_decode($cachestore);
  2134 /**
  2126       $cachestore['_theme_'] = $this->theme;
  2135  * Automatically generated cache of the sidebar for guests.
  2127       $cache->store('anon_sidebar', $cachestore, 10);
  2136  * Do not modify this, it is refreshed every 15 minutes.
       
  2137  */
       
  2138 
       
  2139 \$sidebar_cache = $cachestore;
       
  2140 EOF;
       
  2141       $fh = @fopen($cache_file, 'w');
       
  2142       if ( $fh )
       
  2143       {
       
  2144         fwrite($fh, $cachestore);
       
  2145         fclose($fh);
       
  2146       }
       
  2147       setConfig('sidebar_anon_cache_time', time());
       
  2148     }
  2128     }
  2149     return $return;
  2129     return $return;
  2150   }
  2130   }
  2151   
  2131   
  2152   function initLinksWidget()
  2132   function initLinksWidget()