includes/template.php
changeset 741 a216e412c439
parent 732 c3752aa881c2
child 760 60c132a5bc8e
equal deleted inserted replaced
740:098e744df928 741:a216e412c439
    12  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    12  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    13  */
    13  */
    14  
    14  
    15 class template
    15 class template
    16 {
    16 {
    17   var $tpl_strings, $tpl_bool, $vars_assign_history, $theme, $style, $no_headers, $additional_headers, $sidebar_extra, $sidebar_widgets, $toolbar_menu, $theme_list, $named_theme_list, $default_theme, $default_style, $plugin_blocks, $namespace_string, $style_list, $theme_loaded, $initted_to_page_id, $initted_to_namespace;
    17   var $tpl_strings, $tpl_bool, $vars_assign_history, $theme, $style, $no_headers, $additional_headers, $sidebar_extra, $sidebar_widgets, $toolbar_menu, $theme_list, $named_theme_list, $default_theme, $default_style, $plugin_blocks, $plugin_blocks_content, $namespace_string, $style_list, $theme_loaded, $initted_to_page_id, $initted_to_namespace;
    18   
    18   
    19   var $initted_to_theme = array(
    19   var $initted_to_theme = array(
    20       'theme' => false,
    20       'theme' => false,
    21       'style' => false
    21       'style' => false
    22     );
    22     );
    52     $this->tpl_strings = Array();
    52     $this->tpl_strings = Array();
    53     $this->sidebar_extra = '';
    53     $this->sidebar_extra = '';
    54     $this->toolbar_menu = '';
    54     $this->toolbar_menu = '';
    55     $this->additional_headers = '';
    55     $this->additional_headers = '';
    56     $this->plugin_blocks = Array();
    56     $this->plugin_blocks = Array();
       
    57     $this->plugin_blocks_content = array();
    57     $this->theme_loaded = false;
    58     $this->theme_loaded = false;
    58     
    59     
    59     $this->theme_list = Array();
    60     $this->theme_list = Array();
    60     $this->named_theme_list = Array();
    61     $this->named_theme_list = Array();
    61     
    62     
   183     $df_data =& $this->named_theme_list[ $this->default_theme ];
   184     $df_data =& $this->named_theme_list[ $this->default_theme ];
   184     $this->default_style = ( in_array($df_data['default_style'], $df_data['css']) ) ? $df_data['default_style'] : $df_data['css'][0];
   185     $this->default_style = ( in_array($df_data['default_style'], $df_data['css']) ) ? $df_data['default_style'] : $df_data['css'][0];
   185   }
   186   }
   186   
   187   
   187   /**
   188   /**
   188    * Systematically deletes themes if they're blocked by theme security settings. Called when session->start() finishes.
   189    * Systematically deletes themes from available list if they're blocked by theme security settings. Called when session->start() finishes.
   189    */
   190    */
   190   
   191   
   191   function process_theme_acls()
   192   function process_theme_acls()
   192   {
   193   {
   193     global $db, $session, $paths, $template, $plugins; // Common objects
   194     global $db, $session, $paths, $template, $plugins; // Common objects
   303       $parser = $this->makeParserText($tplvars['sidebar_section_raw']);
   304       $parser = $this->makeParserText($tplvars['sidebar_section_raw']);
   304     }
   305     }
   305     
   306     
   306     $parser->assign_vars(Array('TITLE' => '{TITLE}','CONTENT' => $h));
   307     $parser->assign_vars(Array('TITLE' => '{TITLE}','CONTENT' => $h));
   307     $this->plugin_blocks[$t] = $parser->run();
   308     $this->plugin_blocks[$t] = $parser->run();
       
   309     $this->plugin_blocks_content[$t] = $h;
   308     $this->sidebar_widgets .= $parser->run();
   310     $this->sidebar_widgets .= $parser->run();
   309   }
   311   }
   310   function add_header($html)
   312   function add_header($html)
   311   {
   313   {
   312     /* debug only **
   314     /* debug only **
   342     // Make sure we're allowed to use this theme.
   344     // Make sure we're allowed to use this theme.
   343     if ( (
   345     if ( (
   344         // If it was removed, it's probably blocked by an ACL, or it was uninstalled
   346         // If it was removed, it's probably blocked by an ACL, or it was uninstalled
   345         !isset($this->named_theme_list[$this->theme]) ||
   347         !isset($this->named_theme_list[$this->theme]) ||
   346         // Check if the theme is disabled
   348         // Check if the theme is disabled
   347         ( isset($this->named_theme_list[$this->theme]) && $this->named_theme_list[$this->theme]['enabled'] == 0 ) )
   349         ( isset($this->named_theme_list[$this->theme]) && isset($this->named_theme_list[$this->theme]['enabled']) && $this->named_theme_list[$this->theme]['enabled'] == 0 ) )
   348         // Above all, if it's a system theme, don't inhibit the loading process.
   350         // Above all, if it's a system theme, don't inhibit the loading process.
   349         && !in_array($this->theme, $this->system_themes)
   351         && !in_array($this->theme, $this->system_themes)
   350       )
   352       )
   351     {
   353     {
   352       // No, something is preventing it - fall back to site default
   354       // No, something is preventing it - fall back to site default
  1103         'TEXT'=>$lang->get('sidebar_btn_administration'),
  1105         'TEXT'=>$lang->get('sidebar_btn_administration'),
  1104       ));
  1106       ));
  1105     
  1107     
  1106     $admin_link = $parser->run();
  1108     $admin_link = $parser->run();
  1107     
  1109     
       
  1110     $parser->assign_vars(Array(
       
  1111         'HREF'=>makeUrlNS('Special', 'EditSidebar'),
       
  1112         'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { void(ajaxLoginNavTo(\'Special\', \'EditSidebar\', ' . USER_LEVEL_ADMIN . ')); return false; }"',
       
  1113         'TEXT'=>$lang->get('sidebar_btn_editsidebar'),
       
  1114       ));
       
  1115     
       
  1116     $sidebar_link = $parser->run();
       
  1117     
  1108     $SID = ($session->sid_super) ? $session->sid_super : '';
  1118     $SID = ($session->sid_super) ? $session->sid_super : '';
  1109     
  1119     
  1110     $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($local_fullpage)));
  1120     $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($local_fullpage)));
  1111     $urlname_clean = strtr( $urlname_clean, array( '<' => '&lt;', '>' => '&gt;' ) );
  1121     $urlname_clean = strtr( $urlname_clean, array( '<' => '&lt;', '>' => '&gt;' ) );
  1112     
  1122     
  1126     $js_dynamic = '    <script type="text/javascript">// <![CDATA[
  1136     $js_dynamic = '    <script type="text/javascript">// <![CDATA[
  1127       // This section defines some basic and very important variables that are used later in the static Javascript library.
  1137       // This section defines some basic and very important variables that are used later in the static Javascript library.
  1128       // SKIN DEVELOPERS: The template variable for this code block is {JS_DYNAMIC_VARS}. This MUST be inserted BEFORE the tag that links to the main Javascript lib.
  1138       // SKIN DEVELOPERS: The template variable for this code block is {JS_DYNAMIC_VARS}. This MUST be inserted BEFORE the tag that links to the main Javascript lib.
  1129       var title = \''. $urlname_jssafe .'\';
  1139       var title = \''. $urlname_jssafe .'\';
  1130       var physical_title = \'' . $physical_urlname_jssafe . '\';
  1140       var physical_title = \'' . $physical_urlname_jssafe . '\';
       
  1141       var on_main_page = ' . ( $local_page == get_main_page() ? 'true' : 'false' ) . ';
       
  1142       var main_page_members = \'' . addslashes(get_main_page(true)) . '\';
  1131       var page_exists = '. ( ( $local_page_exists) ? 'true' : 'false' ) .';
  1143       var page_exists = '. ( ( $local_page_exists) ? 'true' : 'false' ) .';
  1132       var scriptPath = \'' . addslashes(scriptPath) . '\';
  1144       var scriptPath = \'' . addslashes(scriptPath) . '\';
  1133       var contentPath = \'' . addslashes(contentPath) . '\';
  1145       var contentPath = \'' . addslashes(contentPath) . '\';
  1134       var cdnPath = \'' . addslashes(cdnPath) . '\';
  1146       var cdnPath = \'' . addslashes(cdnPath) . '\';
  1135       var ENANO_SID = \'' . $SID . '\';
  1147       var ENANO_SID = \'' . $SID . '\';
  1171         $js_dynamic .= "namespace_list['{$k}'] = '$c';";
  1183         $js_dynamic .= "namespace_list['{$k}'] = '$c';";
  1172       }
  1184       }
  1173       $js_dynamic .= "\n    //]]>\n    </script>";
  1185       $js_dynamic .= "\n    //]]>\n    </script>";
  1174       
  1186       
  1175     $tpl_strings = Array(
  1187     $tpl_strings = Array(
  1176       'PAGE_NAME'=>htmlspecialchars($local_cdata['name']),
  1188       'PAGE_NAME' => htmlspecialchars($local_cdata['name']),
  1177       'PAGE_URLNAME'=> $urlname_clean,
  1189       'PAGE_URLNAME' =>  $urlname_clean,
  1178       'SITE_NAME'=>htmlspecialchars(getConfig('site_name')),
  1190       'SITE_NAME' => htmlspecialchars(getConfig('site_name')),
  1179       'USERNAME'=>$session->username,
  1191       'USERNAME' => $session->username,
  1180       'SITE_DESC'=>htmlspecialchars(getConfig('site_desc')),
  1192       'SITE_DESC' => htmlspecialchars(getConfig('site_desc')),
  1181       'TOOLBAR'=>$tb,
  1193       'TOOLBAR' => $tb,
  1182       'SCRIPTPATH'=>scriptPath,
  1194       'SCRIPTPATH' => scriptPath,
  1183       'CONTENTPATH'=>contentPath,
  1195       'CONTENTPATH' => contentPath,
  1184       'CDNPATH' => cdnPath,
  1196       'CDNPATH' => cdnPath,
  1185       'ADMIN_SID_QUES'=>$asq,
  1197       'ADMIN_SID_QUES' => $asq,
  1186       'ADMIN_SID_AMP'=>$asa,
  1198       'ADMIN_SID_AMP' => $asa,
  1187       'ADMIN_SID_AMP_HTML'=>$ash,
  1199       'ADMIN_SID_AMP_HTML' => $ash,
  1188       'ADMIN_SID_AUTO'=>$as2,
  1200       'ADMIN_SID_AUTO' => $as2,
  1189       'ADMIN_SID_RAW'=> ( is_string($session->sid_super) ? $session->sid_super : '' ),
  1201       'ADMIN_SID_RAW' =>  ( is_string($session->sid_super) ? $session->sid_super : '' ),
  1190       'COPYRIGHT'=>RenderMan::parse_internal_links(getConfig('copyright_notice')),
  1202       'COPYRIGHT' => RenderMan::parse_internal_links(getConfig('copyright_notice')),
  1191       'TOOLBAR_EXTRAS'=>$this->toolbar_menu,
  1203       'TOOLBAR_EXTRAS' => $this->toolbar_menu,
  1192       'REQUEST_URI'=>( defined('ENANO_CLI') ? '' : $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ),
  1204       'REQUEST_URI' => ( defined('ENANO_CLI') ? '' : $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ),
  1193       'STYLE_LINK'=>makeUrlNS('Special', 'CSS'.$p, null, true), //contentPath.$paths->nslist['Special'].'CSS' . $p,
  1205       'STYLE_LINK' => makeUrlNS('Special', 'CSS'.$p, null, true), //contentPath.$paths->nslist['Special'].'CSS' . $p,
  1194       'LOGIN_LINK'=>$login_link,
  1206       'LOGIN_LINK' => $login_link,
  1195       'LOGOUT_LINK'=>$logout_link,
  1207       'LOGOUT_LINK' => $logout_link,
  1196       'ADMIN_LINK'=>$admin_link,
  1208       'ADMIN_LINK' => $admin_link,
  1197       'THEME_LINK'=>$theme_link,
  1209       'THEME_LINK' => $theme_link,
  1198       'SEARCH_ACTION'=>makeUrlNS('Special', 'Search'),
  1210       'SIDEBAR_LINK' => $sidebar_link,
  1199       'INPUT_TITLE'=>( urlSeparator == '&' ? '<input type="hidden" name="title" value="' . htmlspecialchars( $paths->nslist[$local_namespace] . $local_page_id ) . '" />' : ''),
  1211       'SEARCH_ACTION' => makeUrlNS('Special', 'Search'),
  1200       'INPUT_AUTH'=>( $session->sid_super ? '<input type="hidden" name="auth"  value="' . $session->sid_super . '" />' : ''),
  1212       'INPUT_TITLE' => ( urlSeparator == '&' ? '<input type="hidden" name="title" value="' . htmlspecialchars( $paths->nslist[$local_namespace] . $local_page_id ) . '" />' : ''),
  1201       'TEMPLATE_DIR'=>scriptPath.'/themes/'.$this->theme,
  1213       'INPUT_AUTH' => ( $session->sid_super ? '<input type="hidden" name="auth"  value="' . $session->sid_super . '" />' : ''),
  1202       'THEME_ID'=>$this->theme,
  1214       'TEMPLATE_DIR' => scriptPath.'/themes/'.$this->theme,
  1203       'STYLE_ID'=>$this->style,
  1215       'THEME_ID' => $this->theme,
  1204       'MAIN_PAGE' => getConfig('main_page'),
  1216       'STYLE_ID' => $this->style,
       
  1217       'MAIN_PAGE' => get_main_page(),
  1205       'JS_HEADER' => $js_head,
  1218       'JS_HEADER' => $js_head,
  1206       'JS_FOOTER' => $js_foot,
  1219       'JS_FOOTER' => $js_foot,
  1207       'JS_DYNAMIC_VARS'=>$js_dynamic,
  1220       'JS_DYNAMIC_VARS' => $js_dynamic,
  1208       'UNREAD_PMS'=>$session->unread_pms,
  1221       'UNREAD_PMS' => $session->unread_pms,
  1209       'URL_ABOUT_ENANO' => makeUrlNS('Special', 'About_Enano', '', true),
  1222       'URL_ABOUT_ENANO' => makeUrlNS('Special', 'About_Enano', '', true),
  1210       'REPORT_URI' => makeUrl($local_fullpage, 'do=sql_report', true)
  1223       'REPORT_URI' => makeUrl($local_fullpage, 'do=sql_report', true)
  1211       );
  1224       );
  1212     
  1225     
  1213     foreach ( $paths->nslist as $ns_id => $ns_prefix )
  1226     foreach ( $paths->nslist as $ns_id => $ns_prefix )
  2040    * Fetch the HTML for a plugin-added sidebar block
  2053    * Fetch the HTML for a plugin-added sidebar block
  2041    * @param $name the plugin name
  2054    * @param $name the plugin name
  2042    * @return string
  2055    * @return string
  2043    */
  2056    */
  2044    
  2057    
  2045   function fetch_block($id)
  2058   function fetch_block($id, $just_the_innards_maam = false)
  2046   {
  2059   {
  2047     if(isset($this->plugin_blocks[$id])) return $this->plugin_blocks[$id];
  2060     if ( $just_the_innards_maam )
  2048     else return false;
  2061     {
       
  2062       $source =& $this->plugin_blocks_content;
       
  2063     }
       
  2064     else
       
  2065     {
       
  2066       $source =& $this->plugin_blocks;
       
  2067     }
       
  2068     return isset($source[$id]) ? $source[$id] : false;
  2049   }
  2069   }
  2050   
  2070   
  2051   /**
  2071   /**
  2052    * Fetches the contents of both sidebars.
  2072    * Fetches the contents of both sidebars.
  2053    * @return array - key 0 is left, key 1 is right, key 2 is the HTML that makes up an empty sidebar
  2073    * @return array - key 0 is left, key 1 is right, key 2 is the HTML that makes up an empty sidebar