includes/template.php
changeset 590 03a60844c7c5
parent 585 35e91d16ecf5
child 592 27377179fe58
equal deleted inserted replaced
589:88d4ed0a2898 590:03a60844c7c5
   360   {
   360   {
   361     global $db, $session, $paths, $template, $plugins; // Common objects
   361     global $db, $session, $paths, $template, $plugins; // Common objects
   362     global $email;
   362     global $email;
   363     global $lang;
   363     global $lang;
   364     
   364     
   365     profiler_log("template: starting var init");
       
   366     
       
   367     if(!$this->theme || !$this->style)
   365     if(!$this->theme || !$this->style)
   368     {
   366     {
   369       $this->load_theme();
   367       $this->load_theme();
   370     }
   368     }
   371     
   369     
   410     if ( $local_page_id === $this->initted_to_page_id && $local_namespace === $this->initted_to_namespace && $this->theme === $this->initted_to_theme['theme'] && $this->style === $this->initted_to_theme['style'] && !$force_init )
   408     if ( $local_page_id === $this->initted_to_page_id && $local_namespace === $this->initted_to_namespace && $this->theme === $this->initted_to_theme['theme'] && $this->style === $this->initted_to_theme['style'] && !$force_init )
   411     {
   409     {
   412       // we're already initted with this page.
   410       // we're already initted with this page.
   413       return true;
   411       return true;
   414     }
   412     }
       
   413     
       
   414     profiler_log("template: starting var init");
   415     
   415     
   416     $this->initted_to_page_id = $local_page_id;
   416     $this->initted_to_page_id = $local_page_id;
   417     $this->initted_to_namespace = $local_namespace;
   417     $this->initted_to_namespace = $local_namespace;
   418     $this->initted_to_theme = array(
   418     $this->initted_to_theme = array(
   419         'theme' => $this->theme,
   419         'theme' => $this->theme,
   560     {
   560     {
   561       eval($cmd);
   561       eval($cmd);
   562     }
   562     }
   563     $ns =& $this->namespace_string;
   563     $ns =& $this->namespace_string;
   564     
   564     
       
   565     //
       
   566     // PAGE TOOLBAR (on-page controls/actions)
       
   567     //
       
   568     
       
   569     profiler_log('template: var init: finished initial setup, starting toolbar');
       
   570     
   565     // Initialize the toolbar
   571     // Initialize the toolbar
   566     $tb = '';
   572     $tb = '';
   567     
   573     
   568     // Create "xx page" button
   574     // Create "xx page" button
   569     
   575     
   936         'TEXT'        => $lang->get('onpage_btn_moreoptions')
   942         'TEXT'        => $lang->get('onpage_btn_moreoptions')
   937         ));
   943         ));
   938       $tb .= $button->run();
   944       $tb .= $button->run();
   939     }
   945     }
   940     
   946     
       
   947     //
       
   948     // OTHER SWITCHES
       
   949     //
       
   950     
       
   951     profiler_log('template: var init: finshed toolbar, starting other switches');
       
   952     
   941     $is_opera = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) ? true : false;
   953     $is_opera = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) ? true : false;
   942     
   954     
   943     $this->tpl_bool = Array(
   955     $this->tpl_bool = Array(
   944       'auth_admin'=>$session->user_level >= USER_LEVEL_ADMIN ? true : false,
   956       'auth_admin' => $session->user_level >= USER_LEVEL_ADMIN ? true : false,
   945       'user_logged_in'=>$session->user_logged_in,
   957       'user_logged_in' => $session->user_logged_in,
   946       'opera'=>$is_opera,
   958       'opera' => $is_opera,
   947       );
   959       );
   948     
   960     
   949     if($session->sid_super) { $ash = '&auth='.$session->sid_super; $asq = "?auth=".$session->sid_super; $asa = "&auth=".$session->sid_super; $as2 = htmlspecialchars(urlSeparator).'auth='.$session->sid_super; }
   961     if ( $session->sid_super )
   950     else { $asq=''; $asa=''; $as2 = ''; $ash = ''; }
   962     {
       
   963       $ash = '&auth=' . $session->sid_super;
       
   964       $asq = "?auth=" . $session->sid_super;
       
   965       $asa = "&auth=" . $session->sid_super;
       
   966       $as2 = htmlspecialchars(urlSeparator) . 'auth='.$session->sid_super;
       
   967     }
       
   968     else
       
   969     {
       
   970       $asq = '';
       
   971       $asa = '';
       
   972       $as2 = '';
       
   973       $ash = '';
       
   974     }
   951     
   975     
   952     $code = $plugins->setHook('compile_template');
   976     $code = $plugins->setHook('compile_template');
   953     foreach ( $code as $cmd )
   977     foreach ( $code as $cmd )
   954     {
   978     {
   955       eval($cmd);
   979       eval($cmd);
   956     }
   980     }
   957     
   981     
   958     // Some additional sidebar processing
   982     // Some additional sidebar processing
   959     if($this->sidebar_extra != '') {
   983     if ( $this->sidebar_extra != '' )
       
   984     {
   960       $se = $this->sidebar_extra;
   985       $se = $this->sidebar_extra;
   961       $parser = $this->makeParserText($tplvars['sidebar_section_raw']);
   986       $parser = $this->makeParserText($tplvars['sidebar_section_raw']);
   962       $parser->assign_vars(Array('TITLE'=>'Links','CONTENT'=>$se));
   987       $parser->assign_vars(array(
       
   988           'TITLE' => 'Links', // FIXME: l10n
       
   989           'CONTENT' => $se
       
   990         ));
       
   991       
   963       $this->sidebar_extra = $parser->run();
   992       $this->sidebar_extra = $parser->run();
   964     }
   993     }
   965     
   994     
   966     $this->sidebar_extra = $this->sidebar_extra.$this->sidebar_widgets;
   995     $this->sidebar_extra = $this->sidebar_extra . $this->sidebar_widgets;
   967     
   996     
   968     $this->tpl_bool['fixed_menus'] = false;
   997     $this->tpl_bool['fixed_menus'] = false;
   969     /* if($this->sidebar_extra == '') $this->tpl_bool['right_sidebar'] = false;
   998     $this->tpl_bool['right_sidebar'] = true;
   970     else */ $this->tpl_bool['right_sidebar'] = true;
       
   971     
       
   972     $this->tpl_bool['auth_rename'] = ( $local_page_exists && $session->check_acl_scope('rename', $local_namespace) && ( $perms->get_permissions('rename') && ( $paths->page_protected && $perms->get_permissions('even_when_protected') || !$paths->page_protected ) ));
   999     $this->tpl_bool['auth_rename'] = ( $local_page_exists && $session->check_acl_scope('rename', $local_namespace) && ( $perms->get_permissions('rename') && ( $paths->page_protected && $perms->get_permissions('even_when_protected') || !$paths->page_protected ) ));
   973     
       
   974     $this->tpl_bool['enable_uploads'] = ( getConfig('enable_uploads') == '1' && $session->get_permissions('upload_files') ) ? true : false;
  1000     $this->tpl_bool['enable_uploads'] = ( getConfig('enable_uploads') == '1' && $session->get_permissions('upload_files') ) ? true : false;
   975     
       
   976     $this->tpl_bool['stupid_mode'] = false;
  1001     $this->tpl_bool['stupid_mode'] = false;
   977     
       
   978     $this->tpl_bool['in_admin'] = ( ( $local_page_id == 'Administration' && $local_namespace == 'Special' ) || $local_namespace == 'Admin' );
  1002     $this->tpl_bool['in_admin'] = ( ( $local_page_id == 'Administration' && $local_namespace == 'Special' ) || $local_namespace == 'Admin' );
   979     
  1003     
   980     $p = ( isset($_GET['printable']) ) ? '/printable' : '';
  1004     $p = ( isset($_GET['printable']) ) ? '/printable' : '';
   981     
  1005     
   982     // Add the e-mail address client code to the header
  1006     // Add the e-mail address client code to the header
  1016         'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { void(ajaxStartAdminLogin()); return false; }"',
  1040         'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { void(ajaxStartAdminLogin()); return false; }"',
  1017         'TEXT'=>$lang->get('sidebar_btn_administration'),
  1041         'TEXT'=>$lang->get('sidebar_btn_administration'),
  1018       ));
  1042       ));
  1019     
  1043     
  1020     $admin_link = $parser->run();
  1044     $admin_link = $parser->run();
       
  1045     
       
  1046     profiler_log('template: var init: finished sidebar/misc processing, starting dynamic vars and finalization');
  1021     
  1047     
  1022     $SID = ($session->sid_super) ? $session->sid_super : '';
  1048     $SID = ($session->sid_super) ? $session->sid_super : '';
  1023     
  1049     
  1024     $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($local_fullpage)));
  1050     $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($local_fullpage)));
  1025     $urlname_clean = strtr( $urlname_clean, array( '<' => '&lt;', '>' => '&gt;' ) );
  1051     $urlname_clean = strtr( $urlname_clean, array( '<' => '&lt;', '>' => '&gt;' ) );
  1082       foreach($paths->nslist as $k => $c)
  1108       foreach($paths->nslist as $k => $c)
  1083       {
  1109       {
  1084         $js_dynamic .= "namespace_list['{$k}'] = '$c';";
  1110         $js_dynamic .= "namespace_list['{$k}'] = '$c';";
  1085       }
  1111       }
  1086       $js_dynamic .= "\n    //]]>\n    </script>";
  1112       $js_dynamic .= "\n    //]]>\n    </script>";
       
  1113       
       
  1114     profiler_log('template: var init: finished JS dynamic vars and assigning final var set');
  1087     
  1115     
  1088     $tpl_strings = Array(
  1116     $tpl_strings = Array(
  1089       'PAGE_NAME'=>htmlspecialchars($local_cdata['name']),
  1117       'PAGE_NAME'=>htmlspecialchars($local_cdata['name']),
  1090       'PAGE_URLNAME'=> $urlname_clean,
  1118       'PAGE_URLNAME'=> $urlname_clean,
  1091       'SITE_NAME'=>htmlspecialchars(getConfig('site_name')),
  1119       'SITE_NAME'=>htmlspecialchars(getConfig('site_name')),
  1124       $tpl_strings[ 'NS_' . strtoupper($ns_id) ] = $ns_prefix;
  1152       $tpl_strings[ 'NS_' . strtoupper($ns_id) ] = $ns_prefix;
  1125     }
  1153     }
  1126     
  1154     
  1127     $this->assign_vars($tpl_strings, true);
  1155     $this->assign_vars($tpl_strings, true);
  1128     
  1156     
       
  1157     //
       
  1158     // COMPILE THE SIDEBAR
       
  1159     //
       
  1160     
       
  1161     // This is done after the big assign_vars() so that sidebar code has access to the newly assigned variables
       
  1162     
       
  1163     profiler_log('template: var init: finished final var set, executing and applying sidebar templates');
       
  1164     
  1129     list($this->tpl_strings['SIDEBAR_LEFT'], $this->tpl_strings['SIDEBAR_RIGHT'], $min) = $this->fetch_sidebar();
  1165     list($this->tpl_strings['SIDEBAR_LEFT'], $this->tpl_strings['SIDEBAR_RIGHT'], $min) = $this->fetch_sidebar();
  1130     $this->tpl_bool['sidebar_left']  = ( $this->tpl_strings['SIDEBAR_LEFT']  != $min) ? true : false;
  1166     $this->tpl_bool['sidebar_left']  = ( $this->tpl_strings['SIDEBAR_LEFT']  != $min) ? true : false;
  1131     $this->tpl_bool['sidebar_right'] = ( $this->tpl_strings['SIDEBAR_RIGHT'] != $min) ? true : false;
  1167     $this->tpl_bool['sidebar_right'] = ( $this->tpl_strings['SIDEBAR_RIGHT'] != $min) ? true : false;
  1132     $this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility
  1168     $this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility
  1133     
  1169     
  1134     // and finally one that needs to be symlinked...
  1170     // and finally one string value that needs to be symlinked...
  1135     if ( !isset($this->tpl_strings['ADDITIONAL_HEADERS']) )
  1171     if ( !isset($this->tpl_strings['ADDITIONAL_HEADERS']) )
  1136     {
  1172     {
  1137       $this->tpl_strings['ADDITIONAL_HEADERS'] =& $this->additional_headers;
  1173       $this->tpl_strings['ADDITIONAL_HEADERS'] =& $this->additional_headers;
  1138     }
  1174     }
  1139     
  1175     
       
  1176     // done!
  1140     $code = $plugins->setHook('template_var_init_end');
  1177     $code = $plugins->setHook('template_var_init_end');
  1141     foreach ( $code as $cmd )
  1178     foreach ( $code as $cmd )
  1142     {
  1179     {
  1143       eval($cmd);
  1180       eval($cmd);
  1144     }
  1181     }
  2131   The way this works is: match all blocks using the standard form with a different keyword in the block each time,
  2168   The way this works is: match all blocks using the standard form with a different keyword in the block each time,
  2132   and replace them with appropriate PHP logic. Plugin-extensible now. :-)
  2169   and replace them with appropriate PHP logic. Plugin-extensible now. :-)
  2133   */
  2170   */
  2134   
  2171   
  2135   // This is a workaround for what seems like a PCRE bug
  2172   // This is a workaround for what seems like a PCRE bug
  2136   while ( ( profiler_log("[template] compiler matchout start") || true ) && preg_match_all($regexp, $text, $matches) )
  2173   while ( preg_match_all($regexp, $text, $matches) )
  2137   {
  2174   {
  2138   
  2175   
  2139   profiler_log("[template] compiler core loop start");
       
  2140   for ( $i = 0; $i < count($matches[0]); $i++ )
  2176   for ( $i = 0; $i < count($matches[0]); $i++ )
  2141   {
  2177   {
  2142     $start_tag =& $matches[1][$i];
  2178     $start_tag =& $matches[1][$i];
  2143     $type =& $matches[2][$i];
  2179     $type =& $matches[2][$i];
  2144     $test =& $matches[3][$i];
  2180     $test =& $matches[3][$i];
  2195     
  2231     
  2196     $text = str_replace_once($matches[0][$i], $tag_complete, $text);
  2232     $text = str_replace_once($matches[0][$i], $tag_complete, $text);
  2197   }
  2233   }
  2198   }
  2234   }
  2199   
  2235   
  2200   profiler_log("[template] compiler core loop end");
       
  2201   
       
  2202   // For debugging ;-)
  2236   // For debugging ;-)
  2203   // die("<pre>&lt;?php\n" . htmlspecialchars($text."\n\n".print_r($matches,true)) . "\n\n?&gt;</pre>");
  2237   // die("<pre>&lt;?php\n" . htmlspecialchars($text."\n\n".print_r($matches,true)) . "\n\n?&gt;</pre>");
  2204   
  2238   
  2205   //
  2239   //
  2206   // Data substitution/variables
  2240   // Data substitution/variables
  2230     $tag = "{PHP:$i:$seed}";
  2264     $tag = "{PHP:$i:$seed}";
  2231     $text = str_replace_once($tag, "'; $match echo '", $text);
  2265     $text = str_replace_once($tag, "'; $match echo '", $text);
  2232   }
  2266   }
  2233   
  2267   
  2234   // echo('<pre>' . htmlspecialchars($text) . '</pre>');
  2268   // echo('<pre>' . htmlspecialchars($text) . '</pre>');
  2235   
       
  2236   profiler_log("[template] compiler subst end");
       
  2237   
  2269   
  2238   return $text;
  2270   return $text;
  2239 }
  2271 }
  2240 
  2272 
  2241 /**
  2273 /**