/** * usage in template * {outputJavascriptDir(#Hydra#,#Hydra.js",#.......#)} * * call_user * */ function outputJavascriptDir($path) { $relpath = $this->rootURL . '/' . $path . '/'; $ff = HTML_FlexyFramework::get(); $dir = $this->rootDir . '/' . $path; $args = func_get_args(); $ar = array(); if (count($args) < 2) { $ar = glob($dir . '/*.js'); } else { array_shift($args); foreach ($args as $f) { if (strpos($f, '*') > -1) { $ar = array_merge($ar, glob($dir . '/' . $f)); continue; } $ar[] = $dir . '/' . $f; } } // cached version?? - how do we decide if it's expired? // while scanning the directory is slow... - it's faster than serving every file... if (empty($ar)) { echo "<!-- skipping {$path} - no files found -->\n"; return; } //$path = $this->rootURL ."/Pman/$mod/"; $files = array(); $arfiles = array(); $maxtime = 0; $mtime = 0; foreach ($ar as $fn) { $f = basename($fn); // got the 'module file..' $mtime = filemtime($dir . '/' . $f); $maxtime = max($mtime, $maxtime); $arfiles[$fn] = $mtime; $files[] = $relpath . $f . '?ts=' . $mtime; } ksort($arfiles); // just sort by name so it's consistant for serialize.. $ui = posix_getpwuid(posix_geteuid()); $compiledir = session_save_path() . '/' . $ui['name'] . '-' . $ff->project . '-' . $ff->version . '-jscompile'; if (!file_exists($compiledir)) { mkdir($compiledir, 0700, true); } $lsort = create_function('$a,$b', 'return strlen($a) > strlen($b) ? 1 : -1;'); usort($files, $lsort); $ff = HTML_FlexyFramework::get(); if (!empty($ff->Pman['isDev']) && !empty($_REQUEST['isDev'])) { echo "<!-- Javascript compile turned off (isDev on) -->\n"; $this->assetArrayToHtml($files, 'js'); return; } $smod = str_replace('/', '.', $path); $output = date('Y-m-d-H-i-s-', $maxtime) . $smod . '-' . md5(serialize($arfiles)) . '.js'; // where are we going to write all of this.. // This has to be done via a if (!file_exists($compiledir . '/' . $output) || !filesize($compiledir . '/' . $output)) { require_once 'Pman/Core/JsCompile.php'; $x = new Pman_Core_JsCompile(); $x->pack($arfiles, $compiledir . '/' . $output, false); clearstatcache(); if (!file_exists($compiledir . '/' . $output) || !filesize($compiledir . '/' . $output)) { echo "<!-- compile did not generate files : " . basename($compiledir) . "/{$output} -->\n"; $this->assetArrayToHtml($files, 'js'); return; } } else { // echo "<!-- file already exists: {$basedir}/{$output} -->\n"; } $asset = $ff->project == 'Pman' ? '/Core/Asset/js/' : '/Asset/js/'; //$this->arrayToJsInclude( $files); $this->assetArrayToHtml(array($this->baseURL . $asset . $output), 'js'); }
/** * moduleJavascriptList: list the javascript files in a module * * The original version of this.. still needs more thought... * * Compiled is in Pman/_compiled_/{$mod}/{LATEST...}.js * Translations are in Pman/_translations_/{$mod}.js * * if that stuff does not exist just list files in Pman/{$mod}/*.js * * Compiled could be done on the fly.. * * * * @param {String} $mod the module to look at - eg. Pman/{$mod}/*.js * @return {Array} list of include paths (either compiled or raw) * */ function moduleJavascriptList($mod) { $dir = $this->rootDir . '/Pman/' . $mod; if (!file_exists($dir)) { echo '<!-- missing directory ' . htmlspecialchars($dir) . ' -->'; return array(); } $info = $this->moduleJavascriptFilesInfo($mod); if (empty($info->files)) { return array(); } // finally sort the files, so they are in the right order.. // only compile this stuff if public_cache is set.. // suggestions... // public_cache_dir = /var/www/myproject_cache // public_cache_url = /myproject_cache (with Alias apache /myproject_cache/ /var/www/myproject_cache/) // bit of debugging if (!$info->compile) { echo "<!-- Javascript compile turned off (isDev on, or public_cache_dir not set) -->\n"; return $info->files; } // where are we going to write all of this.. // This has to be done via a if (!file_exists($info->basedir . '/' . $info->output) || !filesize($info->basedir . '/' . $info->output)) { require_once 'Pman/Core/JsCompile.php'; $x = new Pman_Core_JsCompile(); $x->pack($info->filesmtime, $info->basedir . '/' . $info->output, $info->translation_base); } else { echo "<!-- file exists not exist: {$info->basedir}/{$info->output} -->\n"; } if (file_exists($info->basedir . '/' . $info->output) && filesize($info->basedir . '/' . $info->output)) { $ret = array($info->baseurl . '/' . $info->output); // output all the ava // fixme - this needs the max datetime for the translation file.. $ret[] = $this->baseURL . "/Admin/InterfaceTranslations/" . $mod . ".js"; //?ts=".$info->translation_mtime; //if ($info->translation_mtime) { // $ret[] = $this->rootURL."/_translations_/". $info->smod.".js?ts=".$info->translation_mtime; //} return $ret; } // give up and output original files... return $info->files; }