Exemple #1
0
 /**
  * analyzes jQuery components to load; fills static array $jquery
  *
  * @access private
  * @param  array    $arr
  * @param  string   $for
  * @param  string   $section
  * @return void
  **/
 private static function _analyze_jquery_components(&$arr, $for = 'frontend', $section = NULL)
 {
     global $page_id;
     $static =& CAT_Helper_Page::$jquery;
     $val = CAT_Helper_Validate::getInstance();
     $set = self::getInstance()->db()->query('SELECT `use_core`, `use_ui` FROM `:prefix:pages_headers` WHERE `page_id`=:id OR `page_id`=0', array('id' => $page_id));
     if ($set->rowCount()) {
         while (false !== ($row = $set->fetch())) {
             if ($row['use_ui'] == 'Y') {
                 $arr['ui'] = true;
             }
             if ($row['use_core'] == 'Y') {
                 $arr['core'] = true;
             }
         }
     }
     // make sure that we load the core if needed, even if the
     // author forgot to set the flags
     if (isset($arr['ui']) && $arr['ui'] === true) {
         $arr['core'] = true;
     }
     // load the components
     if (isset($arr['ui-theme']) && file_exists(CAT_PATH . '/modules/lib_jquery/jquery-ui/themes/' . $arr['ui-theme'])) {
         $static[] = CAT_Helper_Page::$space . '<link rel="stylesheet" type="text/css" href="' . $val->sanitize_url(CAT_URL . '/modules/lib_jquery/jquery-ui/themes/' . $arr['ui-theme'] . '/jquery-ui.css') . '" media="all" />' . "\n";
     }
     // core is always added to header
     if (!CAT_Helper_Page::$jquery_core && isset($arr['core']) && $arr['core'] === true) {
         CAT_Helper_Page::$jquery[] = CAT_Helper_Page::$space . '<script type="text/javascript" src="' . $val->sanitize_url(CAT_URL . '/modules/lib_jquery/jquery-core/jquery-core.min.js') . '"></script>' . "\n";
         CAT_Helper_Page::$jquery_core = true;
     }
     // ui is always added to header
     if (!CAT_Helper_Page::$jquery_ui_core && isset($arr['ui']) && $arr['ui'] === true) {
         CAT_Helper_Page::$jquery[] = CAT_Helper_Page::$space . '<script type="text/javascript" src="' . $val->sanitize_url(CAT_URL . '/modules/lib_jquery/jquery-ui/ui/jquery-ui.min.js') . '"></script>' . "\n";
         CAT_Helper_Page::$jquery[] = CAT_Helper_Page::$space . '<script type="text/javascript" src="' . $val->sanitize_url(CAT_URL . '/modules/lib_jquery/jquery-ui/ui/i18n/jquery-ui-i18n.min.js') . '"></script>' . "\n";
         CAT_Helper_Page::$jquery_ui_core = true;
     }
     // components to load on all pages (backend only)
     if (isset($arr['all']) && is_array($arr['all'])) {
         foreach ($arr['all'] as $item) {
             $resolved = self::_find_item($item);
             if ($resolved) {
                 $static[] = CAT_Helper_Page::$space . '<script type="text/javascript" src="' . $val->sanitize_url(CAT_URL . '/modules/lib_jquery/plugins/' . $resolved) . '"></script>' . "\n";
             }
         }
     }
     // components to load on individual pages only (backend only)
     if (isset($arr['individual']) && is_array($arr['individual']) && isset($section) && $section != '') {
         foreach ($arr['individual'] as $section_name => $item) {
             if ($section_name == strtolower($section)) {
                 $resolved = self::_find_item($item);
                 $static[] = CAT_Helper_Page::$space . '<script type="text/javascript" src="' . $val->sanitize_url(CAT_URL . '/modules/lib_jquery/plugins/' . $item) . '"></script>' . "\n";
             }
         }
     }
     self::$instance->log()->logDebug('jQuery', $static);
 }