From: Michael J. Rubinsky Date: Thu, 30 Jul 2009 16:16:07 +0000 (-0400) Subject: Add ability to add external script files. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a31a7f97f99b80e86be3ebb6a43775b943112ddc;p=horde.git Add ability to add external script files. (Code ported from Ansel's Ansel_Script_Files) --- diff --git a/framework/Core/lib/Horde.php b/framework/Core/lib/Horde.php index 32056f96b..ba1cb72b8 100644 --- a/framework/Core/lib/Horde.php +++ b/framework/Core/lib/Horde.php @@ -295,15 +295,17 @@ HTML; return; } - $js_tocache = $js_force = array(); + $js_tocache = $js_force = $js_external = array(); $mtime = array(0); $s_list = $hsf->listFiles(); foreach ($s_list as $app => $files) { foreach ($files as $file) { - if ($file['d'] && ($file['f'][0] != '/')) { + if ($file['d'] && ($file['f'][0] != '/') && empty($file['e'])) { $js_tocache[$file['p'] . $file['f']] = false; $mtime[] = filemtime($file['p'] . $file['f']); + } elseif (!empty($file['e'])) { + $js_external[] = $file['u']; } else { $js_force[] = $file['u']; } @@ -358,12 +360,24 @@ HTML; } } - foreach (array_merge(array($js_url), $js_force) as $val) { + foreach (array_merge($js_external, array($js_url), $js_force) as $val) { echo '\n"; } } /** + * Inlude script files from external sources. + * + * @param string $url The url to the external script file. + * @param string $app The app scope + */ + static public function addExternalScriptFile($url, $app = null) + { + $hsf = Horde_Script_Files::singleton(); + $hsf->addExternal($url, $app); + } + + /** * Get a token for protecting a form. * * @param string $slug Slug name. diff --git a/framework/Core/lib/Horde/Script/Files.php b/framework/Core/lib/Horde/Script/Files.php index a1cc7afa4..115bfc7b2 100644 --- a/framework/Core/lib/Horde/Script/Files.php +++ b/framework/Core/lib/Horde/Script/Files.php @@ -86,6 +86,31 @@ class Horde_Script_Files } /** + * Adds an external script file + * + * @param string $url The url to the external script file. + * @param string $app The app scope + */ + public function addExternal($url, $app) + { + if (empty($app)) { + $app = $GLOBALS['registry']->getApp(); + } + + // Don't include scripts multiple times. + if (!empty($this->_included[$app][$url])) { + return false; + } + + $this->_included[$app][$url] = true; + + $this->_files[$app][] = array('f' => basename($url), + 'u' => $url, + 'd' => false, + 'e' => true); + } + + /** * Helper function to determine if given file needs to be output. */ public function _add($file, $app, $direct, $full = false)