363 $this->style_list =& $this->named_theme_list[ $this->theme ]['css']; |
378 $this->style_list =& $this->named_theme_list[ $this->theme ]['css']; |
364 $this->theme_loaded = true; |
379 $this->theme_loaded = true; |
365 } |
380 } |
366 |
381 |
367 /** |
382 /** |
368 * Initializes all variables related to on-page content. This includes sidebars and what have you. |
383 * Change the theme we're supposed to display. |
369 * @param object Optional PageProcessor object to use for passing metadata and permissions on. If omitted, uses information from $paths and $session. |
384 * @param string Theme name |
370 * @param bool If true, re-inits even if already initted with this page_id and namespace |
385 * @param string Style name; optional |
371 */ |
386 */ |
372 |
387 |
373 function init_vars($page = false, $force_init = false) |
388 function set_theme($theme = false, $style = false) |
374 { |
389 { |
375 global $db, $session, $paths, $template, $plugins; // Common objects |
390 $this->theme_initted = false; |
|
391 $this->load_theme($theme, $style); |
|
392 } |
|
393 |
|
394 /** |
|
395 * Change the page we're supposed to generate for |
|
396 * @param mixed Page ID *or* PageProcessor. If a PageProcessor, pulls permission info and such from that; if not, starts a PageProcessor. YOU SHOULD USE A PageProcessor WHENEVER POSSIBLE! It improves efficiency. |
|
397 * @param string Namespace; not required if including a PageProcessor. |
|
398 */ |
|
399 |
|
400 function set_page($page_id_or_pp, $namespace = false) |
|
401 { |
|
402 if ( is_object($page_id_or_pp) && get_class($page_id_or_pp) === 'PageProcessor' ) |
|
403 { |
|
404 $this->page_initted = false; |
|
405 $page =& $page_id_or_pp; |
|
406 $this->page = $page; |
|
407 $this->page_id = $page->page_id; |
|
408 $this->namespace = $page->namespace; |
|
409 } |
|
410 else if ( is_string($page_id_or_pp) ) |
|
411 { |
|
412 if ( !is_string($namespace) ) |
|
413 return false; |
|
414 |
|
415 if ( $page_id_or_pp === $this->page_id && $namespace === $this->namespace ) |
|
416 return true; |
|
417 |
|
418 $this->page_initted = false; |
|
419 $this->page = false; |
|
420 $this->page_id = sanitize_page_id($page_id_or_pp); |
|
421 $this->namespace = $namespace; |
|
422 } |
|
423 else |
|
424 { |
|
425 return false; |
|
426 } |
|
427 return true; |
|
428 } |
|
429 |
|
430 /** |
|
431 * Global, only-called-once init. Goes to all themes. |
|
432 */ |
|
433 |
|
434 function init_global_vars() |
|
435 { |
|
436 global $db, $session, $paths, $template, $plugins; // Common objects |
|
437 global $lang; |
376 global $email; |
438 global $email; |
377 global $lang; |
439 |
378 |
440 // IE PNG fixing code |
379 if(!$this->theme || !$this->style) |
441 if ( isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) |
380 { |
|
381 $this->load_theme(); |
|
382 } |
|
383 |
|
384 if ( defined('ENANO_TEMPLATE_LOADED') ) |
|
385 { |
|
386 // trigger_error("\$template->init_vars() called more than once", E_USER_WARNING); |
|
387 // die_semicritical('Illegal call', '<p>$template->init_vars() was called multiple times, this is not supposed to happen. Exiting with fatal error.</p>'); |
|
388 } |
|
389 else |
|
390 { |
|
391 @define('ENANO_TEMPLATE_LOADED', ''); |
|
392 } |
|
393 |
|
394 if ( is_object($page) && ( @get_class($page) == 'PageProcessor' || preg_match('/^Namespace_/', @get_class($page)) ) ) |
|
395 { |
|
396 $page_append = substr($paths->fullpage, strlen($paths->page)); |
|
397 if ( isset($paths->nslist[$page->namespace]) ) |
|
398 { |
|
399 $local_page = $paths->nslist[$page->namespace] . $page->page_id; |
|
400 } |
|
401 else |
|
402 { |
|
403 $local_page = $page->namespace . substr($paths->nslist['Special'], -1) . $page->page_id . $page_append; |
|
404 } |
|
405 $local_fullpage = $local_page . $page_append; |
|
406 $local_page_id =& $page->page_id; |
|
407 $local_namespace =& $page->namespace; |
|
408 $local_page_exists = $page->exists(); |
|
409 $perms =& $page->perms; |
|
410 if ( !is_object($perms) ) |
|
411 { |
|
412 unset($perms); |
|
413 $perms = $session->fetch_page_acl($local_page_id, $local_namespace); |
|
414 } |
|
415 } |
|
416 else |
|
417 { |
|
418 $local_page =& $paths->page; |
|
419 $local_page_id =& $paths->page_id; |
|
420 $local_fullpage =& $paths->fullpage; |
|
421 $local_namespace =& $paths->namespace; |
|
422 $local_page_exists =& $paths->page_exists; |
|
423 $local_page_protected =& $paths->page_protected; |
|
424 $perms =& $session; |
|
425 } |
|
426 |
|
427 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 ) |
|
428 { |
|
429 // we're already initted with this page. |
|
430 return true; |
|
431 } |
|
432 |
|
433 profiler_log("template: starting var init"); |
|
434 |
|
435 $this->initted_to_page_id = $local_page_id; |
|
436 $this->initted_to_namespace = $local_namespace; |
|
437 $this->initted_to_theme = array( |
|
438 'theme' => $this->theme, |
|
439 'style' => $this->style |
|
440 ); |
|
441 |
|
442 require(ENANO_ROOT . "/themes/{$this->theme}/theme.cfg"); |
|
443 |
|
444 if ( $local_page_exists && isPage($local_page) ) |
|
445 { |
|
446 $local_cdata =& $paths->pages[$local_page]; |
|
447 } |
|
448 else |
|
449 { |
|
450 // if the page doesn't exist but we're trying to load it, it was requested manually and $paths->cpage should match it. |
|
451 if ( $paths->page_id == $local_page_id ) |
|
452 { |
|
453 // load metadata from cpage |
|
454 $local_cdata =& $paths->cpage; |
|
455 } |
|
456 else |
|
457 { |
|
458 // generate our own failsafe metadata |
|
459 $local_cdata = array( |
|
460 'urlname' => $local_page, |
|
461 'urlname_nons' => $local_page_id, |
|
462 'namespace' => $local_namespace, |
|
463 'name' => get_page_title_ns($local_page_id, $local_namespace), |
|
464 'comments_on' => 0, |
|
465 'protected' => 0, |
|
466 'wiki_mode' => 2, |
|
467 'delvotes' => 0, |
|
468 'delvote_ips' => serialize(array()) |
|
469 ); |
|
470 } |
|
471 } |
|
472 |
|
473 // calculate protection |
|
474 if ( !isset($local_page_protected) ) |
|
475 { |
|
476 if ( $local_cdata['protected'] == 0 ) |
|
477 { |
|
478 $local_page_protected = false; |
|
479 } |
|
480 else if ( $local_cdata['protected'] == 1 ) |
|
481 { |
|
482 $local_page_protected = true; |
|
483 } |
|
484 else if ( $local_cdata['protected'] == 2 ) |
|
485 { |
|
486 if ( |
|
487 ( !$session->user_logged_in || // Is the user logged in? |
|
488 ( $session->user_logged_in && $session->reg_time + ( 4 * 86400 ) >= time() ) ) // If so, have they been registered for 4 days? |
|
489 && !$perms->get_permissions('even_when_protected') ) // And of course, is there an ACL that overrides semi-protection? |
|
490 { |
|
491 $local_page_protected = true; |
|
492 } |
|
493 else |
|
494 { |
|
495 $local_page_protected = false; |
|
496 } |
|
497 } |
|
498 } |
|
499 |
|
500 $tplvars = $this->extract_vars('elements.tpl'); |
|
501 |
|
502 if(isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) |
|
503 { |
442 { |
504 $this->add_header(' |
443 $this->add_header(' |
505 <!--[if lt IE 7]> |
444 <!--[if lt IE 7]> |
506 <script language="JavaScript"> |
445 <script language="JavaScript"> |
507 function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. |
446 function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. |
535 </script> |
474 </script> |
536 <![endif]--> |
475 <![endif]--> |
537 '); |
476 '); |
538 } |
477 } |
539 |
478 |
|
479 $is_opera = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) ? true : false; |
|
480 $is_msie = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? true : false; |
|
481 |
|
482 $this->assign_bool(array( |
|
483 'auth_admin' => $session->user_level >= USER_LEVEL_ADMIN ? true : false, |
|
484 'user_logged_in' => $session->user_logged_in, |
|
485 'opera' => $is_opera, |
|
486 'msie' => $is_msie |
|
487 )); |
|
488 |
|
489 if ( $session->sid_super ) |
|
490 { |
|
491 $ash = '&auth=' . $session->sid_super; |
|
492 $asq = "?auth=" . $session->sid_super; |
|
493 $asa = "&auth=" . $session->sid_super; |
|
494 $as2 = htmlspecialchars(urlSeparator) . 'auth='.$session->sid_super; |
|
495 } |
|
496 else |
|
497 { |
|
498 $asq = ''; |
|
499 $asa = ''; |
|
500 $as2 = ''; |
|
501 $ash = ''; |
|
502 } |
|
503 |
|
504 // Set up javascript includes |
|
505 // these depend heavily on whether we have a CDN to work with or not |
|
506 if ( getConfig('cdn_path') ) |
|
507 { |
|
508 // we're on a CDN, point to static includes |
|
509 // probably should have a way to compress stuff like this before uploading to CDN |
|
510 $js_head = '<script type="text/javascript" src="' . cdnPath . '/includes/clientside/static/enano-lib-basic.js"></script>'; |
|
511 $js_foot = <<<JSEOF |
|
512 <script type="text/javascript"> |
|
513 // This initializes the Javascript runtime when the DOM is ready - not when the page is |
|
514 // done loading, because enano-lib-basic still has to load some 15 other script files |
|
515 // check for the init function - this is a KHTML fix |
|
516 // This doesn't seem to work properly in IE in 1.1.x - there are some problems with |
|
517 // tinyMCE and l10n. |
|
518 if ( typeof ( enano_init ) == 'function' && !IE ) |
|
519 { |
|
520 enano_init(); |
|
521 window.onload = function(e) { }; |
|
522 } |
|
523 </script> |
|
524 JSEOF; |
|
525 } |
|
526 else |
|
527 { |
|
528 $cdnpath = cdnPath; |
|
529 // point to jsres compressor |
|
530 $js_head = <<<JSEOF |
|
531 <!-- Only load a basic set of functions for now. Let the rest of the API load when the page is finished. --> |
|
532 <script type="text/javascript" src="$cdnpath/includes/clientside/jsres.php?early"></script> |
|
533 JSEOF; |
|
534 $js_foot = <<<JSEOF |
|
535 <!-- jsres.php is a wrapper script that compresses and caches single JS files to minimize requests --> |
|
536 <script type="text/javascript" src="$cdnpath/includes/clientside/jsres.php"></script> |
|
537 <script type="text/javascript">//<![CDATA[ |
|
538 // This initializes the Javascript runtime when the DOM is ready - not when the page is |
|
539 // done loading, because enano-lib-basic still has to load some 15 other script files |
|
540 // check for the init function - this is a KHTML fix |
|
541 // This doesn't seem to work properly in IE in 1.1.x - there are some problems with |
|
542 // tinyMCE and l10n. |
|
543 if ( typeof ( enano_init ) == 'function' && !IE ) |
|
544 { |
|
545 enano_init(); |
|
546 window.onload = function(e) { }; |
|
547 } |
|
548 //]]></script> |
|
549 JSEOF; |
|
550 } |
|
551 |
|
552 $this->assign_bool(array( |
|
553 'fixed_menus' => false, |
|
554 'export' => false, |
|
555 'right_sidebar' => true, |
|
556 'enable_uploads' => ( getConfig('enable_uploads') == '1' && $session->get_permissions('upload_files') ) ? true : false, |
|
557 'stupid_mode' => false, |
|
558 )); |
|
559 |
|
560 // Add the e-mail address client code to the header |
|
561 $this->add_header($email->jscode()); |
|
562 |
|
563 // Assign our main variables |
|
564 $this->assign_vars(array( |
|
565 'SITE_NAME' => htmlspecialchars(getConfig('site_name')), |
|
566 'USERNAME' => $session->username, |
|
567 'SITE_DESC' => htmlspecialchars(getConfig('site_desc')), |
|
568 'SCRIPTPATH' => scriptPath, |
|
569 'CONTENTPATH' => contentPath, |
|
570 'CDNPATH' => cdnPath, |
|
571 'ADMIN_SID_QUES' => $asq, |
|
572 'ADMIN_SID_AMP' => $asa, |
|
573 'ADMIN_SID_AMP_HTML' => $ash, |
|
574 'ADMIN_SID_AUTO' => $as2, |
|
575 'ADMIN_SID_RAW' => ( is_string($session->sid_super) ? $session->sid_super : '' ), |
|
576 'CSRF_TOKEN' => $session->csrf_token, |
|
577 'COPYRIGHT' => RenderMan::parse_internal_links(getConfig('copyright_notice')), |
|
578 'REQUEST_URI' => ( defined('ENANO_CLI') ? '' : $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ), |
|
579 'SEARCH_ACTION' => makeUrlNS('Special', 'Search'), |
|
580 'INPUT_TITLE' => ( urlSeparator == '&' ? '<input type="hidden" name="title" value="' . htmlspecialchars( $paths->get_pathskey($this->page_id, $this->namespace) ) . '" />' : ''), |
|
581 'INPUT_AUTH' => ( $session->sid_super ? '<input type="hidden" name="auth" value="' . $session->sid_super . '" />' : ''), |
|
582 'MAIN_PAGE' => get_main_page(), |
|
583 'UNREAD_PMS' => $session->unread_pms, |
|
584 'JS_HEADER' => $js_head, |
|
585 'JS_FOOTER' => $js_foot, |
|
586 'URL_ABOUT_ENANO' => makeUrlNS('Special', 'About_Enano', '', true), |
|
587 ), true); |
|
588 |
|
589 $tpl_strings = array(); |
|
590 foreach ( $paths->nslist as $ns_id => $ns_prefix ) |
|
591 { |
|
592 $tpl_strings[ 'NS_' . strtoupper($ns_id) ] = $ns_prefix; |
|
593 } |
|
594 |
|
595 $this->assign_vars($tpl_strings, true); |
|
596 } |
|
597 |
|
598 /** |
|
599 * Init theme vars, like sidebar, global JS, that kind of stuff. |
|
600 */ |
|
601 |
|
602 function init_theme_vars() |
|
603 { |
|
604 global $db, $session, $paths, $template, $plugins; // Common objects |
|
605 global $lang; |
|
606 |
|
607 // allows conditional testing of the theme ID (a bit crude, came from my NSIS days) |
|
608 $this->assign_bool(array( |
|
609 "theme_is_{$this->theme}" => true |
|
610 )); |
|
611 |
|
612 $this->elements = $this->extract_vars('elements.tpl'); |
|
613 |
|
614 // Generate the code for the Administration and Edit Sidebar buttons |
|
615 // Once again, the new template parsing system can be used here |
|
616 |
|
617 $parser = $this->makeParserText($this->elements['sidebar_button']); |
|
618 |
|
619 $parser->assign_vars(Array( |
|
620 'HREF'=>makeUrlNS('Special', 'Administration'), |
|
621 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { void(ajaxStartAdminLogin()); return false; }"', |
|
622 'TEXT'=>$lang->get('sidebar_btn_administration'), |
|
623 )); |
|
624 |
|
625 $admin_link = $parser->run(); |
|
626 |
|
627 $parser->assign_vars(Array( |
|
628 'HREF'=>makeUrlNS('Special', 'EditSidebar'), |
|
629 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { void(ajaxLoginNavTo(\'Special\', \'EditSidebar\', ' . USER_LEVEL_ADMIN . ')); return false; }"', |
|
630 'TEXT'=>$lang->get('sidebar_btn_editsidebar'), |
|
631 )); |
|
632 |
|
633 $sidebar_link = $parser->run(); |
|
634 |
|
635 $this->assign_vars(array( |
|
636 'ADMIN_LINK' => $admin_link, |
|
637 'SIDEBAR_LINK' => $sidebar_link, |
|
638 'THEME_ID' => $this->theme, |
|
639 'STYLE_ID' => $this->style |
|
640 )); |
|
641 |
|
642 $this->theme_initted = true; |
|
643 } |
|
644 |
|
645 /** |
|
646 * Init page vars, like the toolbar, local JS, etc. |
|
647 */ |
|
648 |
|
649 function init_page_vars() |
|
650 { |
|
651 global $db, $session, $paths, $template, $plugins; // Common objects |
|
652 global $lang; |
|
653 |
|
654 if ( !$this->page ) |
|
655 { |
|
656 $this->page = new PageProcessor($this->page_id, $this->namespace); |
|
657 } |
|
658 |
|
659 $conds = $this->page->ns->get_conds(); |
|
660 |
|
661 $this->assign_bool(array( |
|
662 'in_admin' => ( ( $this->page_id == 'Administration' && $this->namespace == 'Special' ) || $this->namespace == 'Admin' ), |
|
663 'auth_rename' => ( $conds['rename'] ) |
|
664 )); |
|
665 |
540 // Get the "article" button text (depends on namespace) |
666 // Get the "article" button text (depends on namespace) |
541 switch($local_namespace) { |
667 switch ( $this->namespace ) |
|
668 { |
542 case "Article": |
669 case "Article": |
543 default: |
670 default: |
544 $ns = $lang->get('onpage_lbl_page_article'); |
671 $ns = $lang->get('onpage_lbl_page_article'); |
545 break; |
672 break; |
546 case "Admin": |
673 case "Admin": |
585 |
715 |
586 // |
716 // |
587 // PAGE TOOLBAR (on-page controls/actions) |
717 // PAGE TOOLBAR (on-page controls/actions) |
588 // |
718 // |
589 |
719 |
|
720 $local_page = $paths->get_pathskey($this->page_id, $this->namespace); |
|
721 $local_cdata = $this->page->ns->get_cdata(); |
|
722 |
590 // Initialize the toolbar |
723 // Initialize the toolbar |
591 $tb = ''; |
724 $tb = ''; |
592 $this->toolbar_menu = ''; |
725 $this->toolbar_menu = ''; |
593 |
726 |
594 // Create "xx page" button |
727 // Create "xx page" button |
595 |
728 |
596 $btn_selected = ( isset($tplvars['toolbar_button_selected'])) ? $tplvars['toolbar_button_selected'] : $tplvars['toolbar_button']; |
729 $btn_selected = ( isset($this->elements['toolbar_button_selected'])) ? $this->elements['toolbar_button_selected'] : $this->elements['toolbar_button']; |
597 $parser = $this->makeParserText($btn_selected); |
730 $parser = $this->makeParserText($btn_selected); |
598 |
731 |
599 $parser->assign_vars(array( |
732 if ( $conds['article'] ) |
600 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxReset()); return false; }" title="' . $lang->get('onpage_tip_article') . '" accesskey="a"', |
733 { |
601 'PARENTFLAGS' => 'id="mdgToolbar_article"', |
734 $parser->assign_vars(array( |
602 'HREF' => makeUrl($local_page, null, true), |
735 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxReset()); return false; }" title="' . $lang->get('onpage_tip_article') . '" accesskey="a"', |
603 'TEXT' => $this->namespace_string |
736 'PARENTFLAGS' => 'id="mdgToolbar_article"', |
604 )); |
737 'HREF' => makeUrl($local_page, null, true), |
605 |
738 'TEXT' => $this->namespace_string |
606 $tb .= $parser->run(); |
739 )); |
607 |
740 |
608 $button = $this->makeParserText($tplvars['toolbar_button']); |
741 $tb .= $parser->run(); |
|
742 } |
|
743 |
|
744 $button = $this->makeParserText($this->elements['toolbar_button']); |
609 |
745 |
610 // Page toolbar |
746 // Page toolbar |
611 // Comments button |
747 // Comments button |
612 if ( $perms->get_permissions('read') && getConfig('enable_comments', '1')=='1' && $local_cdata['comments_on'] == 1 ) |
748 if ( $conds['comments'] ) |
613 { |
749 { |
614 $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$local_page_id.'\' AND namespace=\''.$local_namespace.'\';'); |
750 $e = $db->sql_query('SELECT approved FROM '.table_prefix.'comments WHERE page_id=\''.$this->page_id.'\' AND namespace=\''.$this->namespace.'\';'); |
615 if ( !$e ) |
751 if ( !$e ) |
616 { |
752 { |
617 $db->_die(); |
753 $db->_die(); |
618 } |
754 } |
619 $num_comments = $db->numrows(); |
755 $num_comments = $db->numrows(); |
652 )); |
788 )); |
653 |
789 |
654 $tb .= $button->run(); |
790 $tb .= $button->run(); |
655 } |
791 } |
656 // Edit button |
792 // Edit button |
657 if($perms->get_permissions('read') && $session->check_acl_scope('edit_page', $local_namespace) && ( $perms->get_permissions('edit_page') && ( ( $paths->page_protected && $perms->get_permissions('even_when_protected') ) || !$paths->page_protected ) ) ) |
793 if( $conds['edit'] ) |
658 { |
794 { |
659 $button->assign_vars(array( |
795 $button->assign_vars(array( |
660 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_edit') . '" accesskey="e"', |
796 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_edit') . '" accesskey="e"', |
661 'PARENTFLAGS' => 'id="mdgToolbar_edit"', |
797 'PARENTFLAGS' => 'id="mdgToolbar_edit"', |
662 'HREF' => makeUrl($local_page, 'do=edit', true), |
798 'HREF' => makeUrl($local_page, 'do=edit', true), |
663 'TEXT' => $lang->get('onpage_btn_edit') |
799 'TEXT' => $lang->get('onpage_btn_edit') |
664 )); |
800 )); |
665 $tb .= $button->run(); |
801 $tb .= $button->run(); |
666 // View source button |
802 // View source button |
667 } |
803 } |
668 else if ( $session->check_acl_scope('view_source', $local_namespace) && $perms->get_permissions('view_source') && ( !$perms->get_permissions('edit_page') || !$perms->get_permissions('even_when_protected') && $paths->page_protected ) && $local_namespace != 'API') |
804 else if ( $conds['viewsource'] ) |
669 { |
805 { |
670 $button->assign_vars(array( |
806 $button->assign_vars(array( |
671 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_viewsource') . '" accesskey="e"', |
807 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxEditor()); return false; }" title="' . $lang->get('onpage_tip_viewsource') . '" accesskey="e"', |
672 'PARENTFLAGS' => 'id="mdgToolbar_edit"', |
808 'PARENTFLAGS' => 'id="mdgToolbar_edit"', |
673 'HREF' => makeUrl($local_page, 'do=viewsource', true), |
809 'HREF' => makeUrl($local_page, 'do=viewsource', true), |
674 'TEXT' => $lang->get('onpage_btn_viewsource') |
810 'TEXT' => $lang->get('onpage_btn_viewsource') |
675 )); |
811 )); |
676 $tb .= $button->run(); |
812 $tb .= $button->run(); |
677 } |
813 } |
678 // History button |
814 // History button |
679 if ( $perms->get_permissions('read') && $session->check_acl_scope('history_view', $local_namespace) && $local_page_exists && $perms->get_permissions('history_view') ) |
815 if ( $conds['history'] ) |
680 { |
816 { |
681 $button->assign_vars(array( |
817 $button->assign_vars(array( |
682 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxHistory()); return false; }" title="' . $lang->get('onpage_tip_history') . '" accesskey="h"', |
818 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxHistory()); return false; }" title="' . $lang->get('onpage_tip_history') . '" accesskey="h"', |
683 'PARENTFLAGS' => 'id="mdgToolbar_history"', |
819 'PARENTFLAGS' => 'id="mdgToolbar_history"', |
684 'HREF' => makeUrl($local_page, 'do=history', true), |
820 'HREF' => makeUrl($local_page, 'do=history', true), |
685 'TEXT' => $lang->get('onpage_btn_history') |
821 'TEXT' => $lang->get('onpage_btn_history') |
686 )); |
822 )); |
687 $tb .= $button->run(); |
823 $tb .= $button->run(); |
688 } |
824 } |
689 |
825 |
690 $menubtn = $this->makeParserText($tplvars['toolbar_menu_button']); |
826 $menubtn = $this->makeParserText($this->elements['toolbar_menu_button']); |
691 |
827 |
692 // Additional actions menu |
828 // Additional actions menu |
693 // Rename button |
829 // Rename button |
694 if ( $perms->get_permissions('read') && $session->check_acl_scope('rename', $local_namespace) && $local_page_exists && ( $perms->get_permissions('rename') && ( $paths->page_protected && $perms->get_permissions('even_when_protected') || !$paths->page_protected ) ) ) |
830 if ( $conds['rename'] ) |
695 { |
831 { |
696 $menubtn->assign_vars(array( |
832 $menubtn->assign_vars(array( |
697 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxRename()); return false; }" title="' . $lang->get('onpage_tip_rename') . '" accesskey="r"', |
833 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxRename()); return false; }" title="' . $lang->get('onpage_tip_rename') . '" accesskey="r"', |
698 'HREF' => makeUrl($local_page, 'do=rename', true), |
834 'HREF' => makeUrl($local_page, 'do=rename', true), |
699 'TEXT' => $lang->get('onpage_btn_rename'), |
835 'TEXT' => $lang->get('onpage_btn_rename'), |
700 )); |
836 )); |
701 $this->toolbar_menu .= $menubtn->run(); |
837 $this->toolbar_menu .= $menubtn->run(); |
702 } |
838 } |
703 |
839 |
704 // Vote-to-delete button |
840 // Vote-to-delete button |
705 if ( $paths->wiki_mode && $session->check_acl_scope('vote_delete', $local_namespace) && $perms->get_permissions('vote_delete') && $local_page_exists) |
841 if ( $conds['delvote'] ) |
706 { |
842 { |
707 $menubtn->assign_vars(array( |
843 $menubtn->assign_vars(array( |
708 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDelVote()); return false; }" title="' . $lang->get('onpage_tip_delvote') . '" accesskey="d"', |
844 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxDelVote()); return false; }" title="' . $lang->get('onpage_tip_delvote') . '" accesskey="d"', |
709 'HREF' => makeUrl($local_page, 'do=delvote', true), |
845 'HREF' => makeUrl($local_page, 'do=delvote', true), |
710 'TEXT' => $lang->get('onpage_btn_votedelete'), |
846 'TEXT' => $lang->get('onpage_btn_votedelete'), |
711 )); |
847 )); |
712 $this->toolbar_menu .= $menubtn->run(); |
848 $this->toolbar_menu .= $menubtn->run(); |
713 } |
849 } |
714 |
850 |
715 // Clear-votes button |
851 // Clear-votes button |
716 if ( $perms->get_permissions('read') && $session->check_acl_scope('vote_reset', $local_namespace) && $paths->wiki_mode && $local_page_exists && $perms->get_permissions('vote_reset') && $local_cdata['delvotes'] > 0) |
852 if ( $conds['resetvotes'] ) |
717 { |
853 { |
718 $menubtn->assign_vars(array( |
854 $menubtn->assign_vars(array( |
719 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxResetDelVotes()); return false; }" title="' . $lang->get('onpage_tip_resetvotes') . '" accesskey="y"', |
855 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxResetDelVotes()); return false; }" title="' . $lang->get('onpage_tip_resetvotes') . '" accesskey="y"', |
720 'HREF' => makeUrl($local_page, 'do=resetvotes', true), |
856 'HREF' => makeUrl($local_page, 'do=resetvotes', true), |
721 'TEXT' => $lang->get('onpage_btn_votedelete_reset'), |
857 'TEXT' => $lang->get('onpage_btn_votedelete_reset'), |
722 )); |
858 )); |
723 $this->toolbar_menu .= $menubtn->run(); |
859 $this->toolbar_menu .= $menubtn->run(); |
724 } |
860 } |
725 |
861 |
726 // Printable page button |
862 // Printable page button |
727 if ( $local_page_exists ) |
863 if ( $conds['printable'] ) |
728 { |
864 { |
729 $menubtn->assign_vars(array( |
865 $menubtn->assign_vars(array( |
730 'FLAGS' => 'title="' . $lang->get('onpage_tip_printable') . '"', |
866 'FLAGS' => 'title="' . $lang->get('onpage_tip_printable') . '"', |
731 'HREF' => makeUrl($local_page, 'printable=yes', true), |
867 'HREF' => makeUrl($local_page, 'printable=yes', true), |
732 'TEXT' => $lang->get('onpage_btn_printable'), |
868 'TEXT' => $lang->get('onpage_btn_printable'), |
733 )); |
869 )); |
734 $this->toolbar_menu .= $menubtn->run(); |
870 $this->toolbar_menu .= $menubtn->run(); |
735 } |
871 } |
736 |
872 |
737 // Protect button |
873 // Protect button |
738 if($perms->get_permissions('read') && $session->check_acl_scope('protect', $local_namespace) && $paths->wiki_mode && $local_page_exists && $perms->get_permissions('protect')) |
874 if ( $conds['protect'] ) |
739 { |
875 { |
740 switch($local_cdata['protected']) |
876 switch($this->page->ns->page_protected) |
741 { |
877 { |
742 case PROTECT_FULL: $protect_status = $lang->get('onpage_btn_protect_on'); break; |
878 case PROTECT_FULL: $protect_status = $lang->get('onpage_btn_protect_on'); break; |
743 case PROTECT_SEMI: $protect_status = $lang->get('onpage_btn_protect_semi'); break; |
879 case PROTECT_SEMI: $protect_status = $lang->get('onpage_btn_protect_semi'); break; |
744 case PROTECT_NONE: $protect_status = $lang->get('onpage_btn_protect_off'); break; |
880 case PROTECT_NONE: $protect_status = $lang->get('onpage_btn_protect_off'); break; |
745 } |
881 } |
746 |
882 |
747 $label = $this->makeParserText($tplvars['toolbar_label']); |
883 $label = $this->makeParserText($this->elements['toolbar_label']); |
748 $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_protect') . ' ' . "<b><span id=\"tb_ajax_protect_status\">$protect_status</span></b>")); |
884 $label->assign_vars(array('TEXT' => $lang->get('onpage_lbl_protect') . ' ' . "<b><span id=\"tb_ajax_protect_status\">$protect_status</span></b>")); |
749 $t0 = $label->run(); |
885 $t0 = $label->run(); |
750 |
886 |
751 $menubtn->assign_vars(array( |
887 $menubtn->assign_vars(array( |
752 'FLAGS' => 'accesskey="p" onclick="ajaxProtect(' . $local_cdata['protected'] . '); return false;" id="tb_ajax_protect_btn" title="' . $lang->get('onpage_tip_protect') . '"', |
888 'FLAGS' => 'accesskey="p" onclick="ajaxProtect(' . $this->page->ns->page_protected . '); return false;" id="tb_ajax_protect_btn" title="' . $lang->get('onpage_tip_protect') . '"', |
753 'HREF' => makeUrl($local_page, 'do=protect', true), |
889 'HREF' => makeUrl($local_page, 'do=protect', true), |
754 'TEXT' => $lang->get('onpage_btn_protect_change') |
890 'TEXT' => $lang->get('onpage_btn_protect_change') |
755 )); |
891 )); |
756 $t1 = $menubtn->run(); |
892 $t1 = $menubtn->run(); |
757 |
893 |
820 </tr> |
956 </tr> |
821 </table>'; |
957 </table>'; |
822 } |
958 } |
823 |
959 |
824 // Clear logs button |
960 // Clear logs button |
825 if ( $perms->get_permissions('read') && $session->check_acl_scope('clear_logs', $local_namespace) && $perms->get_permissions('clear_logs') ) |
961 if ( $conds['clearlogs'] ) |
826 { |
962 { |
827 $menubtn->assign_vars(array( |
963 $menubtn->assign_vars(array( |
828 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxClearLogs()); return false; }" title="' . $lang->get('onpage_tip_flushlogs') . '" accesskey="l"', |
964 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxClearLogs()); return false; }" title="' . $lang->get('onpage_tip_flushlogs') . '" accesskey="l"', |
829 'HREF' => makeUrl($local_page, 'do=flushlogs', true), |
965 'HREF' => makeUrl($local_page, 'do=flushlogs', true), |
830 'TEXT' => $lang->get('onpage_btn_clearlogs'), |
966 'TEXT' => $lang->get('onpage_btn_clearlogs'), |
831 )); |
967 )); |
832 $this->toolbar_menu .= $menubtn->run(); |
968 $this->toolbar_menu .= $menubtn->run(); |
833 } |
969 } |
834 |
970 |
835 // Delete page button |
971 // Delete page button |
836 if ( $perms->get_permissions('read') && $session->check_acl_scope('delete_page', $local_namespace) && $perms->get_permissions('delete_page') && $local_page_exists ) |
972 if ( $conds['delete'] ) |
837 { |
973 { |
838 $s = $lang->get('onpage_btn_deletepage'); |
974 $s = $lang->get('onpage_btn_deletepage'); |
839 if ( $local_cdata['delvotes'] == 1 ) |
975 if ( $this->page->ns->cdata['delvotes'] == 1 ) |
840 { |
976 { |
841 $subst = array( |
977 $subst = array( |
842 'num_votes' => $local_cdata['delvotes'], |
978 'num_votes' => $this->page->ns->cdata['delvotes'], |
843 'plural' => '' |
979 'plural' => '' |
844 ); |
980 ); |
845 $s .= $lang->get('onpage_btn_deletepage_votes', $subst); |
981 $s .= $lang->get('onpage_btn_deletepage_votes', $subst); |
846 } |
982 } |
847 else if ( $local_cdata['delvotes'] > 1 ) |
983 else if ( $this->page->ns->cdata['delvotes'] > 1 ) |
848 { |
984 { |
849 $subst = array( |
985 $subst = array( |
850 'num_votes' => $local_cdata['delvotes'], |
986 'num_votes' => $this->page->ns->cdata['delvotes'], |
851 'plural' => $lang->get('meta_plural') |
987 'plural' => $lang->get('meta_plural') |
852 ); |
988 ); |
853 $s .= $lang->get('onpage_btn_deletepage_votes', $subst); |
989 $s .= $lang->get('onpage_btn_deletepage_votes', $subst); |
854 } |
990 } |
855 |
991 |
898 |
1015 |
899 $this->toolbar_menu .= '<table border="0" cellspacing="0" cellpadding="0"><tr><td>'.$t0.'</td><td><input type="password" id="mdgPassSetField" size="10" /></td><td>'.$t.'</td></tr></table>'; |
1016 $this->toolbar_menu .= '<table border="0" cellspacing="0" cellpadding="0"><tr><td>'.$t0.'</td><td><input type="password" id="mdgPassSetField" size="10" /></td><td>'.$t.'</td></tr></table>'; |
900 } |
1017 } |
901 |
1018 |
902 // Manage ACLs button |
1019 // Manage ACLs button |
903 if ( !$paths->external_api_page && $session->check_acl_scope('edit_acl', $local_namespace) && ( $perms->get_permissions('edit_acl') || ( defined('ACL_ALWAYS_ALLOW_ADMIN_EDIT_ACL') && $session->user_level >= USER_LEVEL_ADMIN ) ) ) |
1020 if ( $conds['acledit'] ) |
904 { |
1021 { |
905 $menubtn->assign_vars(array( |
1022 $menubtn->assign_vars(array( |
906 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { var s = ajaxOpenACLManager(); console.debug(s); return false; }" title="' . $lang->get('onpage_tip_aclmanager') . '" accesskey="m"', |
1023 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { var s = ajaxOpenACLManager(); console.debug(s); return false; }" title="' . $lang->get('onpage_tip_aclmanager') . '" accesskey="m"', |
907 'HREF' => makeUrl($local_page, 'do=aclmanager', true), |
1024 'HREF' => makeUrl($local_page, 'do=aclmanager', true), |
908 'TEXT' => $lang->get('onpage_btn_acl'), |
1025 'TEXT' => $lang->get('onpage_btn_acl'), |
909 )); |
1026 )); |
910 $this->toolbar_menu .= $menubtn->run(); |
1027 $this->toolbar_menu .= $menubtn->run(); |
911 } |
1028 } |
912 |
1029 |
913 // Administer page button |
1030 // Administer page button |
914 if ( $session->user_level >= USER_LEVEL_ADMIN && $local_page_exists ) |
1031 if ( $conds['adminpage'] ) |
915 { |
1032 { |
916 $menubtn->assign_vars(array( |
1033 $menubtn->assign_vars(array( |
917 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxAdminPage()); return false; }" title="' . $lang->get('onpage_tip_adminoptions') . '" accesskey="g"', |
1034 'FLAGS' => 'onclick="if ( !KILL_SWITCH ) { void(ajaxAdminPage()); return false; }" title="' . $lang->get('onpage_tip_adminoptions') . '" accesskey="g"', |
918 'HREF' => makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'PageManager', true), |
1035 'HREF' => makeUrlNS('Special', 'Administration', 'module='.$paths->nslist['Admin'].'PageManager', true), |
919 'TEXT' => $lang->get('onpage_btn_admin'), |
1036 'TEXT' => $lang->get('onpage_btn_admin'), |
930 'TEXT' => $lang->get('onpage_btn_moreoptions') |
1047 'TEXT' => $lang->get('onpage_btn_moreoptions') |
931 )); |
1048 )); |
932 $tb .= $button->run(); |
1049 $tb .= $button->run(); |
933 } |
1050 } |
934 |
1051 |
935 // |
1052 // Generate the code for the Log in, Log out, Change theme, Administration, and Edit Sidebar buttons |
936 // OTHER SWITCHES |
|
937 // |
|
938 |
|
939 $is_opera = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'Opera')) ? true : false; |
|
940 $is_msie = (isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) ? true : false; |
|
941 |
|
942 $this->tpl_bool = Array( |
|
943 'auth_admin' => $session->user_level >= USER_LEVEL_ADMIN ? true : false, |
|
944 'user_logged_in' => $session->user_logged_in, |
|
945 'opera' => $is_opera, |
|
946 'msie' => $is_msie |
|
947 ); |
|
948 |
|
949 if ( $session->sid_super ) |
|
950 { |
|
951 $ash = '&auth=' . $session->sid_super; |
|
952 $asq = "?auth=" . $session->sid_super; |
|
953 $asa = "&auth=" . $session->sid_super; |
|
954 $as2 = htmlspecialchars(urlSeparator) . 'auth='.$session->sid_super; |
|
955 } |
|
956 else |
|
957 { |
|
958 $asq = ''; |
|
959 $asa = ''; |
|
960 $as2 = ''; |
|
961 $ash = ''; |
|
962 } |
|
963 |
|
964 // Set up javascript includes |
|
965 // these depend heavily on whether we have a CDN to work with or not |
|
966 if ( getConfig('cdn_path') ) |
|
967 { |
|
968 // we're on a CDN, point to static includes |
|
969 // probably should have a way to compress stuff like this before uploading to CDN |
|
970 $js_head = '<script type="text/javascript" src="' . cdnPath . '/includes/clientside/static/enano-lib-basic.js"></script>'; |
|
971 $js_foot = <<<JSEOF |
|
972 <script type="text/javascript"> |
|
973 // This initializes the Javascript runtime when the DOM is ready - not when the page is |
|
974 // done loading, because enano-lib-basic still has to load some 15 other script files |
|
975 // check for the init function - this is a KHTML fix |
|
976 // This doesn't seem to work properly in IE in 1.1.x - there are some problems with |
|
977 // tinyMCE and l10n. |
|
978 if ( typeof ( enano_init ) == 'function' && !IE ) |
|
979 { |
|
980 enano_init(); |
|
981 window.onload = function(e) { }; |
|
982 } |
|
983 </script> |
|
984 JSEOF; |
|
985 } |
|
986 else |
|
987 { |
|
988 $cdnpath = cdnPath; |
|
989 // point to jsres compressor |
|
990 $js_head = <<<JSEOF |
|
991 <!-- Only load a basic set of functions for now. Let the rest of the API load when the page is finished. --> |
|
992 <script type="text/javascript" src="$cdnpath/includes/clientside/jsres.php?early"></script> |
|
993 JSEOF; |
|
994 $js_foot = <<<JSEOF |
|
995 <!-- jsres.php is a wrapper script that compresses and caches single JS files to minimize requests --> |
|
996 <script type="text/javascript" src="$cdnpath/includes/clientside/jsres.php"></script> |
|
997 <script type="text/javascript">//<![CDATA[ |
|
998 // This initializes the Javascript runtime when the DOM is ready - not when the page is |
|
999 // done loading, because enano-lib-basic still has to load some 15 other script files |
|
1000 // check for the init function - this is a KHTML fix |
|
1001 // This doesn't seem to work properly in IE in 1.1.x - there are some problems with |
|
1002 // tinyMCE and l10n. |
|
1003 if ( typeof ( enano_init ) == 'function' && !IE ) |
|
1004 { |
|
1005 enano_init(); |
|
1006 window.onload = function(e) { }; |
|
1007 } |
|
1008 //]]></script> |
|
1009 JSEOF; |
|
1010 } |
|
1011 |
|
1012 $code = $plugins->setHook('compile_template'); |
|
1013 foreach ( $code as $cmd ) |
|
1014 { |
|
1015 eval($cmd); |
|
1016 } |
|
1017 |
|
1018 // Some additional sidebar processing |
|
1019 if ( $this->sidebar_extra != '' ) |
|
1020 { |
|
1021 $se = $this->sidebar_extra; |
|
1022 $parser = $this->makeParserText($tplvars['sidebar_section_raw']); |
|
1023 $parser->assign_vars(array( |
|
1024 'TITLE' => 'Links', // FIXME: l10n |
|
1025 'CONTENT' => $se |
|
1026 )); |
|
1027 |
|
1028 $this->sidebar_extra = $parser->run(); |
|
1029 } |
|
1030 |
|
1031 $this->sidebar_extra = $this->sidebar_extra . $this->sidebar_widgets; |
|
1032 |
|
1033 $this->tpl_bool['fixed_menus'] = false; |
|
1034 $this->tpl_bool['export'] = false; |
|
1035 $this->tpl_bool['right_sidebar'] = true; |
|
1036 $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 ) )); |
|
1037 $this->tpl_bool['enable_uploads'] = ( getConfig('enable_uploads') == '1' && $session->get_permissions('upload_files') ) ? true : false; |
|
1038 $this->tpl_bool['stupid_mode'] = false; |
|
1039 $this->tpl_bool['in_admin'] = ( ( $local_page_id == 'Administration' && $local_namespace == 'Special' ) || $local_namespace == 'Admin' ); |
|
1040 |
|
1041 // allows conditional testing of the theme ID (a bit crude, came from my NSIS days) |
|
1042 $this->tpl_bool["theme_is_{$this->theme}"] = true; |
|
1043 |
|
1044 $p = ( isset($_GET['printable']) ) ? '/printable' : ''; |
|
1045 |
|
1046 // Add the e-mail address client code to the header |
|
1047 $this->add_header($email->jscode()); |
|
1048 |
|
1049 // Generate the code for the Log out and Change theme sidebar buttons |
|
1050 // Once again, the new template parsing system can be used here |
1053 // Once again, the new template parsing system can be used here |
1051 |
1054 |
1052 $parser = $this->makeParserText($tplvars['sidebar_button']); |
1055 $parser = $this->makeParserText($this->elements['sidebar_button']); |
1053 |
1056 |
1054 $parser->assign_vars(Array( |
1057 $parser->assign_vars(Array( |
1055 'HREF'=>makeUrlNS('Special', "Logout/{$session->csrf_token}/{$local_page}"), |
1058 'HREF'=>makeUrlNS('Special', "Logout/{$session->csrf_token}/{$local_page}"), |
1056 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { mb_logout(); return false; }"', |
1059 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { mb_logout(); return false; }"', |
1057 'TEXT'=>$lang->get('sidebar_btn_logout'), |
1060 'TEXT'=>$lang->get('sidebar_btn_logout'), |
1073 'TEXT'=>$lang->get('sidebar_btn_changestyle'), |
1076 'TEXT'=>$lang->get('sidebar_btn_changestyle'), |
1074 )); |
1077 )); |
1075 |
1078 |
1076 $theme_link = $parser->run(); |
1079 $theme_link = $parser->run(); |
1077 |
1080 |
1078 $parser->assign_vars(Array( |
1081 // Run hooks |
1079 'HREF'=>makeUrlNS('Special', 'Administration'), |
1082 $code = $plugins->setHook('tpl_compile_toolbar'); |
1080 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { void(ajaxStartAdminLogin()); return false; }"', |
1083 foreach ( $code as $cmd ) |
1081 'TEXT'=>$lang->get('sidebar_btn_administration'), |
1084 { |
1082 )); |
1085 eval($cmd); |
1083 |
1086 } |
1084 $admin_link = $parser->run(); |
1087 |
1085 |
1088 // |
1086 $parser->assign_vars(Array( |
1089 // ASSIGN VARIABLES |
1087 'HREF'=>makeUrlNS('Special', 'EditSidebar'), |
1090 // |
1088 'FLAGS'=>'onclick="if ( !KILL_SWITCH ) { void(ajaxLoginNavTo(\'Special\', \'EditSidebar\', ' . USER_LEVEL_ADMIN . ')); return false; }"', |
1091 |
1089 'TEXT'=>$lang->get('sidebar_btn_editsidebar'), |
1092 $this->assign_vars(array( |
1090 )); |
1093 'PAGE_NAME' => htmlspecialchars($this->page->ns->cdata['name']), |
1091 |
1094 'PAGE_URLNAME' => sanitize_page_id($this->page_id), |
1092 $sidebar_link = $parser->run(); |
1095 'TOOLBAR' => $tb, |
|
1096 'TOOLBAR_EXTRAS' => $this->toolbar_menu, |
|
1097 'STYLE_LINK' => makeUrlNS('Special', 'CSS', null, true), //contentPath.$paths->nslist['Special'].'CSS' . $p, |
|
1098 'LOGIN_LINK' => $login_link, |
|
1099 'LOGOUT_LINK' => $logout_link, |
|
1100 'THEME_LINK' => $theme_link |
|
1101 ), true); |
|
1102 $this->page_initted = true; |
|
1103 } |
|
1104 |
|
1105 /** |
|
1106 * Generates and assigns the Javascript system variables |
|
1107 */ |
|
1108 |
|
1109 function generate_js_header() |
|
1110 { |
|
1111 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1112 global $lang; |
1093 |
1113 |
1094 $SID = ($session->sid_super) ? $session->sid_super : ''; |
1114 $SID = ($session->sid_super) ? $session->sid_super : ''; |
|
1115 |
|
1116 $local_page = $paths->get_pathskey($this->page_id, $this->namespace); |
|
1117 $local_fullpage = $paths->get_pathskey($this->page_id, $this->namespace) . substr($paths->fullpage, strlen($paths->page)); |
1095 |
1118 |
1096 $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($local_fullpage))); |
1119 $urlname_clean = str_replace('\'', '\\\'', str_replace('\\', '\\\\', dirtify_page_id($local_fullpage))); |
1097 $urlname_clean = strtr( $urlname_clean, array( '<' => '<', '>' => '>' ) ); |
1120 $urlname_clean = strtr( $urlname_clean, array( '<' => '<', '>' => '>' ) ); |
1098 |
1121 |
1099 $urlname_jssafe = sanitize_page_id($local_fullpage); |
1122 $urlname_jssafe = sanitize_page_id($local_fullpage); |
1100 $physical_urlname_jssafe = sanitize_page_id($paths->fullpage); |
1123 $physical_urlname_jssafe = sanitize_page_id($paths->fullpage); |
1101 |
1124 |
1102 if ( $session->check_acl_scope('even_when_protected', $local_namespace) ) |
1125 $protected = is_object($this->page) ? $this->page->ns->cdata['really_protected'] : false; |
1103 { |
|
1104 $protected = $paths->page_protected && !$perms->get_permissions('even_when_protected'); |
|
1105 } |
|
1106 else |
|
1107 { |
|
1108 $protected = false; |
|
1109 } |
|
1110 |
1126 |
1111 // Generate the dynamic javascript vars |
1127 // Generate the dynamic javascript vars |
1112 $js_dynamic = ' <script type="text/javascript">// <![CDATA[ |
1128 $js_dynamic = ' <script type="text/javascript">// <![CDATA[ |
1113 // This section defines some basic and very important variables that are used later in the static Javascript library. |
1129 // This section defines some basic and very important variables that are used later in the static Javascript library. |
1114 // 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. |
1130 // 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. |
1115 var title = \''. $urlname_jssafe .'\'; |
1131 var title = \''. $urlname_jssafe .'\'; |
1116 var physical_title = \'' . $physical_urlname_jssafe . '\'; |
1132 var physical_title = \'' . $physical_urlname_jssafe . '\'; |
1117 var on_main_page = ' . ( $local_page == get_main_page() ? 'true' : 'false' ) . '; |
1133 var on_main_page = ' . ( $local_page == get_main_page() ? 'true' : 'false' ) . '; |
1118 var main_page_members = \'' . addslashes(get_main_page(true)) . '\'; |
1134 var main_page_members = \'' . addslashes(get_main_page(true)) . '\'; |
1119 var page_exists = '. ( ( $local_page_exists) ? 'true' : 'false' ) .'; |
1135 var page_exists = '. ( ( is_object($this->page) ? $this->page->ns->exists() : true ) ? 'true' : 'false' ) .'; |
1120 var scriptPath = \'' . addslashes(scriptPath) . '\'; |
1136 var scriptPath = \'' . addslashes(scriptPath) . '\'; |
1121 var contentPath = \'' . addslashes(contentPath) . '\'; |
1137 var contentPath = \'' . addslashes(contentPath) . '\'; |
1122 var cdnPath = \'' . addslashes(cdnPath) . '\'; |
1138 var cdnPath = \'' . addslashes(cdnPath) . '\'; |
1123 var ENANO_SID = \'' . $SID . '\'; |
1139 var ENANO_SID = \'' . $SID . '\'; |
1124 var user_level = ' . $session->user_level . '; |
1140 var user_level = ' . $session->user_level . '; |
1129 var USER_LEVEL_MOD = ' . USER_LEVEL_MOD . '; |
1145 var USER_LEVEL_MOD = ' . USER_LEVEL_MOD . '; |
1130 var USER_LEVEL_ADMIN = ' . USER_LEVEL_ADMIN . '; |
1146 var USER_LEVEL_ADMIN = ' . USER_LEVEL_ADMIN . '; |
1131 var disable_redirect = ' . ( isset($_GET['redirect']) && $_GET['redirect'] == 'no' ? 'true' : 'false' ) . '; |
1147 var disable_redirect = ' . ( isset($_GET['redirect']) && $_GET['redirect'] == 'no' ? 'true' : 'false' ) . '; |
1132 var pref_disable_js_fx = ' . ( @$session->user_extra['disable_js_fx'] == 1 ? 'true' : 'false' ) . '; |
1148 var pref_disable_js_fx = ' . ( @$session->user_extra['disable_js_fx'] == 1 ? 'true' : 'false' ) . '; |
1133 var csrf_token = "' . $session->csrf_token . '"; |
1149 var csrf_token = "' . $session->csrf_token . '"; |
1134 var editNotice = \'' . ( (getConfig('wiki_edit_notice', '0')=='1') ? str_replace("\n", "\\\n", addslashes(RenderMan::render(getConfig('wiki_edit_notice_text')))) : '' ) . '\'; |
1150 var editNotice = \'' . $this->get_wiki_edit_notice() . '\'; |
1135 var prot = ' . ( ($protected) ? 'true' : 'false' ) .'; // No, hacking this var won\'t work, it\'s re-checked on the server |
1151 var prot = ' . ( ($protected) ? 'true' : 'false' ) .'; // No, hacking this var won\'t work, it\'s re-checked on the server |
1136 var ENANO_SPECIAL_CREATEPAGE = \''. makeUrl($paths->nslist['Special'].'CreatePage') .'\'; |
1152 var ENANO_SPECIAL_CREATEPAGE = \''. makeUrl($paths->nslist['Special'].'CreatePage') .'\'; |
1137 var ENANO_CREATEPAGE_PARAMS = \'_do=&pagename='. $urlname_clean .'&namespace=' . $local_namespace . '\'; |
1153 var ENANO_CREATEPAGE_PARAMS = \'_do=&pagename='. $this->page_id .'&namespace=' . $this->namespace . '\'; |
1138 var ENANO_SPECIAL_CHANGESTYLE = \''. makeUrlNS('Special', 'ChangeStyle') .'\'; |
1154 var ENANO_SPECIAL_CHANGESTYLE = \''. makeUrlNS('Special', 'ChangeStyle') .'\'; |
1139 var namespace_list = new Array(); |
1155 var namespace_list = new Array(); |
1140 var msg_loading_component = \'' . addslashes($lang->get('ajax_msg_loading_component')) . '\'; |
1156 var msg_loading_component = \'' . addslashes($lang->get('ajax_msg_loading_component')) . '\'; |
1141 var AES_BITS = '.AES_BITS.'; |
1157 var AES_BITS = '.AES_BITS.'; |
1142 var AES_BLOCKSIZE = '.AES_BLOCKSIZE.'; |
1158 var AES_BLOCKSIZE = '.AES_BLOCKSIZE.'; |
1143 var pagepass = \''. ( ( isset($_REQUEST['pagepass']) ) ? sha1($_REQUEST['pagepass']) : '' ) .'\'; |
1159 var pagepass = \''. ( ( isset($_REQUEST['pagepass']) ) ? sha1($_REQUEST['pagepass']) : '' ) .'\'; |
1144 var ENANO_THEME_LIST = \''; |
|
1145 foreach($this->theme_list as $t) { |
|
1146 if($t['enabled']) |
|
1147 { |
|
1148 $js_dynamic .= '<option value="'.$t['theme_id'].'"'; |
|
1149 // if($t['theme_id'] == $session->theme) $js_dynamic .= ' selected="selected"'; |
|
1150 $js_dynamic .= '>'.$t['theme_name'].'</option>'; |
|
1151 } |
|
1152 } |
|
1153 $js_dynamic .= '\'; |
|
1154 var ENANO_CURRENT_THEME = \''. $session->theme .'\'; |
|
1155 var ENANO_LANG_ID = ' . $lang->lang_id . '; |
1160 var ENANO_LANG_ID = ' . $lang->lang_id . '; |
1156 var ENANO_PAGE_TYPE = "' . addslashes($this->namespace_string) . '";'; |
1161 var ENANO_PAGE_TYPE = "' . addslashes($this->namespace_string) . '";'; |
1157 foreach($paths->nslist as $k => $c) |
1162 |
1158 { |
1163 foreach($paths->nslist as $k => $c) |
1159 $js_dynamic .= "namespace_list['{$k}'] = '$c';"; |
1164 { |
1160 } |
1165 $js_dynamic .= "namespace_list['{$k}'] = '$c';"; |
1161 $js_dynamic .= "\n //]]>\n </script>"; |
1166 } |
1162 |
1167 $js_dynamic .= "\n //]]>\n </script>"; |
1163 $tpl_strings = Array( |
1168 |
1164 'PAGE_NAME' => htmlspecialchars($local_cdata['name']), |
1169 $this->assign_vars(array( |
1165 'PAGE_URLNAME' => $urlname_clean, |
1170 'JS_DYNAMIC_VARS' => $js_dynamic, |
1166 'SITE_NAME' => htmlspecialchars(getConfig('site_name')), |
1171 'REPORT_URI' => makeUrl($local_fullpage, 'do=sql_report', true) |
1167 'USERNAME' => $session->username, |
1172 ), true); |
1168 'SITE_DESC' => htmlspecialchars(getConfig('site_desc')), |
1173 } |
1169 'TOOLBAR' => $tb, |
1174 |
1170 'SCRIPTPATH' => scriptPath, |
1175 /** |
1171 'CONTENTPATH' => contentPath, |
1176 * Fetches, parses, and assigns the sidebar. |
1172 'CDNPATH' => cdnPath, |
1177 */ |
1173 'ADMIN_SID_QUES' => $asq, |
1178 |
1174 'ADMIN_SID_AMP' => $asa, |
1179 function assign_sidebar() |
1175 'ADMIN_SID_AMP_HTML' => $ash, |
1180 { |
1176 'ADMIN_SID_AUTO' => $as2, |
|
1177 'ADMIN_SID_RAW' => ( is_string($session->sid_super) ? $session->sid_super : '' ), |
|
1178 'CSRF_TOKEN' => $session->csrf_token, |
|
1179 'COPYRIGHT' => RenderMan::parse_internal_links(getConfig('copyright_notice')), |
|
1180 'TOOLBAR_EXTRAS' => $this->toolbar_menu, |
|
1181 'REQUEST_URI' => ( defined('ENANO_CLI') ? '' : $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'] ), |
|
1182 'STYLE_LINK' => makeUrlNS('Special', 'CSS'.$p, null, true), //contentPath.$paths->nslist['Special'].'CSS' . $p, |
|
1183 'LOGIN_LINK' => $login_link, |
|
1184 'LOGOUT_LINK' => $logout_link, |
|
1185 'ADMIN_LINK' => $admin_link, |
|
1186 'THEME_LINK' => $theme_link, |
|
1187 'SIDEBAR_LINK' => $sidebar_link, |
|
1188 'SEARCH_ACTION' => makeUrlNS('Special', 'Search'), |
|
1189 'INPUT_TITLE' => ( urlSeparator == '&' ? '<input type="hidden" name="title" value="' . htmlspecialchars( $paths->nslist[$local_namespace] . $local_page_id ) . '" />' : ''), |
|
1190 'INPUT_AUTH' => ( $session->sid_super ? '<input type="hidden" name="auth" value="' . $session->sid_super . '" />' : ''), |
|
1191 'TEMPLATE_DIR' => scriptPath.'/themes/'.$this->theme, |
|
1192 'THEME_ID' => $this->theme, |
|
1193 'STYLE_ID' => $this->style, |
|
1194 'MAIN_PAGE' => get_main_page(), |
|
1195 'JS_HEADER' => $js_head, |
|
1196 'JS_FOOTER' => $js_foot, |
|
1197 'JS_DYNAMIC_VARS' => $js_dynamic, |
|
1198 'UNREAD_PMS' => $session->unread_pms, |
|
1199 'URL_ABOUT_ENANO' => makeUrlNS('Special', 'About_Enano', '', true), |
|
1200 'REPORT_URI' => makeUrl($local_fullpage, 'do=sql_report', true) |
|
1201 ); |
|
1202 |
|
1203 foreach ( $paths->nslist as $ns_id => $ns_prefix ) |
|
1204 { |
|
1205 $tpl_strings[ 'NS_' . strtoupper($ns_id) ] = $ns_prefix; |
|
1206 } |
|
1207 |
|
1208 $this->assign_vars($tpl_strings, true); |
|
1209 |
|
1210 profiler_log('template: var init: finished toolbar building and initial assign()'); |
|
1211 |
|
1212 // |
1181 // |
1213 // COMPILE THE SIDEBAR |
1182 // COMPILE THE SIDEBAR |
1214 // |
1183 // |
1215 |
1184 |
1216 // This is done after the big assign_vars() so that sidebar code has access to the newly assigned variables |
1185 // This is done after the big assign_vars() so that sidebar code has access to the newly assigned variables |
1217 |
1186 |
1218 list($this->tpl_strings['SIDEBAR_LEFT'], $this->tpl_strings['SIDEBAR_RIGHT'], $min) = $this->fetch_sidebar(); |
1187 list($this->tpl_strings['SIDEBAR_LEFT'], $this->tpl_strings['SIDEBAR_RIGHT'], $min) = $this->fetch_sidebar(); |
1219 $this->tpl_bool['sidebar_left'] = ( $this->tpl_strings['SIDEBAR_LEFT'] != $min) ? true : false; |
1188 $this->tpl_bool['sidebar_left'] = ( $this->tpl_strings['SIDEBAR_LEFT'] != $min) ? true : false; |
1220 $this->tpl_bool['sidebar_right'] = ( $this->tpl_strings['SIDEBAR_RIGHT'] != $min) ? true : false; |
1189 $this->tpl_bool['sidebar_right'] = ( $this->tpl_strings['SIDEBAR_RIGHT'] != $min) ? true : false; |
1221 $this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility |
1190 $this->tpl_bool['right_sidebar'] = $this->tpl_bool['sidebar_right']; // backward compatibility |
|
1191 } |
|
1192 |
|
1193 /** |
|
1194 * Initializes all variables related to on-page content. This includes sidebars and what have you. |
|
1195 * @param object Optional PageProcessor object to use for passing metadata and permissions on. If omitted, uses information from $paths and $session. |
|
1196 * @param bool If true, re-inits even if already initted with this page_id and namespace |
|
1197 */ |
|
1198 |
|
1199 function init_vars($page = false, $force_init = false) |
|
1200 { |
|
1201 global $db, $session, $paths, $template, $plugins; // Common objects |
|
1202 global $lang; |
|
1203 |
|
1204 $need_shared_init = ( !$this->theme_initted || !$this->page_initted ); |
|
1205 |
|
1206 if ( $need_shared_init ) |
|
1207 { |
|
1208 if ( !$this->theme || !$this->style ) |
|
1209 { |
|
1210 $this->load_theme(); |
|
1211 } |
|
1212 $code = $plugins->setHook('compile_template', true); |
|
1213 foreach ( $code as $cmd ) |
|
1214 { |
|
1215 eval($cmd); |
|
1216 } |
|
1217 } |
|
1218 |
|
1219 if ( !$this->theme_loaded ) |
|
1220 $this->load_theme(); |
|
1221 |
|
1222 require(ENANO_ROOT . "/themes/{$this->theme}/theme.cfg"); |
|
1223 |
|
1224 if ( !$this->page_id || !$this->namespace ) |
|
1225 { |
|
1226 $this->page_id = $paths->page_id; |
|
1227 $this->namespace = $paths->namespace; |
|
1228 } |
|
1229 |
|
1230 profiler_log('template: prepped for var set (loaded theme, ran compile_template hook)'); |
|
1231 |
|
1232 $this->init_global_vars(); |
|
1233 profiler_log('template: global vars set'); |
|
1234 |
|
1235 if ( !$this->theme_initted ) |
|
1236 $this->init_theme_vars(); |
|
1237 |
|
1238 profiler_log('template: theme vars set'); |
|
1239 |
|
1240 if ( !$this->page_initted && !empty($this->namespace) ) |
|
1241 { |
|
1242 profiler_log('template: page vars set'); |
|
1243 $this->init_page_vars(); |
|
1244 } |
|
1245 else |
|
1246 { |
|
1247 profiler_message('template: skipped setting page vars'); |
|
1248 } |
|
1249 |
|
1250 // Perform shared init (combine javascript, etc.) |
|
1251 if ( $need_shared_init ) |
|
1252 { |
|
1253 $this->generate_js_header(); |
|
1254 $this->assign_sidebar(); |
|
1255 profiler_log('template: assigned sidebar and JS'); |
|
1256 } |
1222 |
1257 |
1223 // and finally one string value that needs to be symlinked... |
1258 // and finally one string value that needs to be symlinked... |
1224 if ( !isset($this->tpl_strings['ADDITIONAL_HEADERS']) ) |
1259 if ( !isset($this->tpl_strings['ADDITIONAL_HEADERS']) ) |
1225 { |
1260 { |
1226 $this->tpl_strings['ADDITIONAL_HEADERS'] =& $this->additional_headers; |
1261 $this->tpl_strings['ADDITIONAL_HEADERS'] =& $this->additional_headers; |