[ Index ]

PHP Cross Reference of phpwcms V1.5.0 _r431 (28.01.12)

title

Body

[close]

/include/inc_front/ -> js.inc.php (source)

   1  <?php
   2  /*************************************************************************************
   3     Copyright notice
   4     
   5     (c) 2002-2012 Oliver Georgi <oliver@phpwcms.de> // All rights reserved.
   6   
   7     This script is part of PHPWCMS. The PHPWCMS web content management system is
   8     free software; you can redistribute it and/or modify it under the terms of
   9     the GNU General Public License as published by the Free Software Foundation;
  10     either version 2 of the License, or (at your option) any later version.
  11    
  12     The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html
  13     A copy is found in the textfile GPL.txt and important notices to the license 
  14     from the author is found in LICENSE.txt distributed with these scripts.
  15    
  16     This script is distributed in the hope that it will be useful, but WITHOUT ANY 
  17     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  18     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
  19   
  20     This copyright notice MUST APPEAR in all copies of the script!
  21  *************************************************************************************/
  22  
  23  // ----------------------------------------------------------------
  24  // obligate check for phpwcms constants
  25  if (!defined('PHPWCMS_ROOT')) {
  26     die("You Cannot Access This Script Directly, Have a Nice Day.");
  27  }
  28  // ----------------------------------------------------------------
  29  
  30  // Frontend JavaScript Wrapper
  31  
  32  // set array for possible custom html head additions
  33  $block['custom_htmlhead']    = array();
  34  
  35  // set array to hold global onLoad and onDomReady events
  36  $block['js_onunload']        = array();
  37  $block['js_ondomready']        = array();
  38  $block['js_inline']            = array();
  39  
  40  // set default JS library
  41  if(empty($block['jslib'])) {
  42      $block['jslib'] = key($phpwcms['js_lib']);
  43  }
  44  
  45  // set if Google Ajax Library should be used and if it should from which base URI
  46  define('USE_GOOGLE_AJAX_LIB', !empty($block['googleapi']) || !isset($block['googleapi']) ? 'http://ajax.googleapis.com/ajax/libs/' : FALSE);
  47  
  48  // include the related JavaScript Library wrapper
  49  @include PHPWCMS_ROOT.'/include/inc_front/lib/js.'.$block['jslib'].'.inc.php';
  50  
  51  // check if selected JavaScript should be loaded permanently
  52  if(!empty($block['jslibload'])) {
  53      initJSLib();
  54  }
  55  
  56  // check if frontend.js should be loaded always - it is  more for historic reasons
  57  if(!empty($block['frontendjs'])) {
  58      initFrontendJS();
  59  }
  60  
  61  /**
  62   * Deprecated function to initialize the Slimbox
  63   */
  64  function initializeLightbox() {
  65      initSlimbox();
  66  }
  67  
  68  /**
  69   * Init SwfObject JavaScript Library
  70   */
  71  function initSwfObject() {
  72      if(empty($GLOBALS['block']['custom_htmlhead']['swfobject.js'])) {
  73          if(!USE_GOOGLE_AJAX_LIB) {
  74              $GLOBALS['block']['custom_htmlhead']['swfobject.js'] = getJavaScriptSourceLink(TEMPLATE_PATH.'lib/swfobject/swfobject.js');
  75          } else {
  76              $GLOBALS['block']['custom_htmlhead']['swfobject.js'] = getJavaScriptSourceLink(USE_GOOGLE_AJAX_LIB.'swfobject/2/swfobject.js');
  77          }
  78      }
  79      return TRUE;
  80  }
  81  
  82  function initFrontendJS() {
  83      $GLOBALS['block']['custom_htmlhead']['frontend.js'] = '  <script src="'.TEMPLATE_PATH.'inc_js/frontend.js" type="text/javascript"></script>';
  84  }
  85  
  86  function inlineJS($js='', $prefix='    ') {
  87      if($js) {
  88          $GLOBALS['block']['js_inline'][] = $prefix.$js;
  89      }
  90  }
  91  
  92  /**
  93   * render <!-- JS: PluginName|my.js //Whatever text -->
  94   */
  95  function renderHeadJS($js) {
  96  
  97      if(is_array($js) && isset($js[1])) {
  98          $js = $js[1];
  99      }
 100  
 101      $js = trim($js);
 102      
 103      if(empty($js)) {
 104          return '';
 105      }
 106  
 107      if(strpos($js, ';') !== false || strpos($js, '//') !== false || strpos($js, '/*') !== false) {
 108          
 109          $key = md5($js);
 110          
 111          // add the same section only once
 112          if(empty($GLOBALS['block']['custom_htmlhead'][$key])) {
 113                      
 114              $GLOBALS['block']['custom_htmlhead'][$key]  = '  <script type="text/javascript">' . LF . SCRIPT_CDATA_START . LF . '    ';
 115              $GLOBALS['block']['custom_htmlhead'][$key] .= $js;
 116              $GLOBALS['block']['custom_htmlhead'][$key] .= LF . SCRIPT_CDATA_END . LF . '  </script>';
 117              
 118          }
 119      
 120      } elseif($js == 'initJSLib') {
 121          
 122          initJSLib();
 123          
 124      } else {
 125      
 126          // test for .js
 127          $ext = which_ext($js);
 128          
 129          // decide it is a  plugin or qualified .js
 130          if($ext == 'js') {
 131              
 132              // replace {TEMPLATE}
 133              $js        = str_replace('{TEMPLATE}', TEMPLATE_PATH, $js);
 134              $GLOBALS['block']['custom_htmlhead'][md5($js)] = getJavaScriptSourceLink(html_specialchars($js));
 135              
 136          } else {
 137              
 138              initJSLib();
 139              
 140              if(strtolower($js) != 'initlib') {
 141      
 142                  initJSPlugin($js);
 143                  
 144              }
 145              
 146          }
 147      
 148      }
 149      
 150      return '';
 151      
 152  }
 153  
 154  
 155  ?>


Generated: Sun Jan 29 16:31:14 2012 Cross-referenced by PHPXref 0.7.1