public static function get_instance() { if (!self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
public function add_script_load_url($urls) { $hub = Upfront_PublicScripts_Registry::get_instance(); $scripts = $hub->get_all(); if (empty($scripts)) { return $urls; } $ckey = $this->_cache->key(self::TYPE_SCRIPT, $scripts); $raw_cache_key = $ckey->get_hash(); $cache = $this->_debugger->is_active() ? false : $this->_cache->get($ckey); if (empty($cache)) { foreach ($scripts as $key => $frags) { $path = upfront_element_dir($frags[0], $frags[1]); if (file_exists($path)) { $cache .= "/* {$key} */\n" . file_get_contents($path) . "\n"; } } $this->_cache->set($ckey, $cache); } $url = Upfront_VirtualPage::get_url(join('/', array('upfront-dependencies', 'scripts', $raw_cache_key))); $urls[] = $url; return $urls; }
/** * Adds element script resource. * @param string $slug Script ID to be keyed under (hopefully unique) * @param array $path_info Two-member array, describing resource location. The members are like arguments for upfront_element_dir/upfront_element_url * @return bool False on failure/invalid arguments, true on success */ function upfront_add_element_script($slug, $path_info) { if (empty($slug) || empty($path_info)) { return false; } if (!is_array($path_info)) { return false; } if (count($path_info) != 2) { return false; } if (current_theme_supports("upfront-element_scripts") && current_theme_supports("{$slug}-script")) { return true; } // Current theme supports element scripts, and this script in particular if (empty($_GET['dev']) && empty($_GET['debug'])) { // Yeah, so re-intorduce the hacks $hub = Upfront_PublicScripts_Registry::get_instance(); return $hub->set($slug, $path_info); } else { wp_enqueue_script($slug, upfront_element_url($path_info[0], $path_info[1]), array('jquery')); } }