/** * @param string $title Page title * @param string $body_class Optional value for the class attribute of the <body> element */ function __initialize($title = "", $body_class = false) { // this makes HtmlPage.tpl.php the 'one and only' template // for all derivered classes, unless they override it after // parent::__initialize with $this->file = X $file = str_replace(".class.php", ".tpl.php", __FILE__); parent::__initialize($file); $this->set("title", $title); $this->set("meta", $this->meta); $this->set("js", $this->js); $this->set("css", $this->css); $this->set("content", array()); $this->set("docready", $this->docready); $this->set("plaindocready", $this->plaindocready); $this->set("inlineheaderpre", $this->inlineheaderpre); $this->set("inlineheader", $this->inlineheader); if ($body_class) { $this->set("bodyClass", "{$body_class}"); } if (resourceExists("favicon.ico")) { $this->set("favicon", resFile("favicon.ico")); } // set up correct display on mobile devices: http://stackoverflow.com/questions/8220267/jquery-detect-scroll-at-bottom $this->addMeta("viewport", "width=device-width, height=device-height, initial-scale=1.0"); }
/** * @internal Collects dependencies from a file */ function minify_collect_from_file($kind, $f, $debug_path = '') { global $dependency_info, $res_file_storage, $ext_resources; if (!$f) { return; } $classname = fq_class_name(array_shift(explode('.', basename($f)))); if (isset($res_file_storage[$classname]) || minify_forbidden($classname)) { return; } $order = array('static', 'inherited', 'instanciated', 'self'); //:array('self','incontent','instanciated','inherited'); $res_file_storage[$classname] = array(); $content = file_get_contents($f); // remove block-comments $content = preg_replace("|/\\*.*\\*/|sU", "", $content); do { $c2 = preg_replace("|(.*)//.*\$|m", "\$1", $content); if ($content == $c2) { break; } $content = $c2; } while (true); foreach ($order as $o) { switch ($o) { case 'inherited': if (preg_match_all('/class\\s+[^\\s]+\\s+extends\\s+([^\\s]+)/', $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $m) { $file_for_class = __search_file_for_class($m[1]); if (!$file_for_class) { continue; } $dependency_info[$classname][] = strtolower($m[1]); minify_collect_from_file($kind, $file_for_class, $debug_path . '/' . $classname); } } break; case 'instanciated': $matches = array(); if (preg_match_all('/new\\s+([^\\(]+)\\(/', $content, $by_new, PREG_SET_ORDER)) { $matches = array_merge($matches, $by_new); } if (preg_match_all('/\\s+([^:\\s\\(\\)]+)::Make\\(/Ui', $content, $by_make, PREG_SET_ORDER)) { $matches = array_merge($matches, $by_make); } if (count($matches) > 0) { foreach ($matches as $m) { $file_for_class = __search_file_for_class($m[1]); if (!$file_for_class) { continue; } $dependency_info[$classname][] = strtolower($m[1]); minify_collect_from_file($kind, $file_for_class, $debug_path . '/' . $classname); } } break; case 'self': $simplecls = array_pop(explode("\\", $classname)); if (resourceExists(strtolower("{$simplecls}.{$kind}"))) { $tmp = resFile(strtolower("{$simplecls}.{$kind}")); if (!in_array($tmp, $res_file_storage[$classname])) { $res_file_storage[$classname][] = $tmp; } } break; case 'static': try { foreach (ResourceAttribute::Collect($classname) as $resource) { $b = $resource->Resolve(); if ($resource instanceof \ScavixWDF\Reflection\ExternalResourceAttribute) { $ext_resources[] = $b; continue; } if (!ends_with($b, $kind)) { continue; } $b = strtolower($b); if (!in_array($b, $res_file_storage[$classname])) { $res_file_storage[$classname][] = $b; } } } catch (Exception $ex) { } break; } } }
/** * @internal Collects dependencies from a file */ function minify_collect_from_file($kind, $f, $debug_path = '') { global $dependency_info, $res_file_storage; if (!$f) { return; } $classname = strtolower(basename($f, ".class.php")); if (isset($res_file_storage[$classname]) || minify_forbidden($classname)) { return; } $order = array('static', 'inherited', 'instanciated', 'self'); //:array('self','incontent','instanciated','inherited'); $res_file_storage[$classname] = array(); $content = file_get_contents($f); // remove block-comments $content = preg_replace("|/\\*.*\\*/|sU", "", $content); do { $c2 = preg_replace("|(.*)//.*\$|m", "\$1", $content); if ($content == $c2) { break; } $content = $c2; } while (true); foreach ($order as $o) { switch ($o) { case 'inherited': if (preg_match_all('/class\\s+[^\\s]+\\s+extends\\s+([^\\s]+)/', $content, $matches, PREG_SET_ORDER)) { // log_debug("minify_collect_from_file [$debug_path/$classname]: INHERITED",$matches); foreach ($matches as $m) { $file_for_class = __search_file_for_class($m[1]); if (!$file_for_class) { continue; } $dependency_info[$classname][] = strtolower($m[1]); minify_collect_from_file($kind, $file_for_class, $debug_path . '/' . $classname); } } break; case 'instanciated': if (preg_match_all('/new\\s+([^\\(]+)\\(/', $content, $matches, PREG_SET_ORDER)) { // log_debug("minify_collect_from_file [$debug_path/$classname]: INSTANCIATED",$matches); foreach ($matches as $m) { $file_for_class = __search_file_for_class($m[1]); if (!$file_for_class) { continue; } $dependency_info[$classname][] = strtolower($m[1]); minify_collect_from_file($kind, $file_for_class, $debug_path . '/' . $classname); } } break; case 'self': if (resourceExists(strtolower("{$classname}.{$kind}"))) { $tmp = resFile(strtolower("{$classname}.{$kind}")); if (!in_array($tmp, $res_file_storage[$classname])) { $res_file_storage[$classname][] = $tmp; } } break; case 'static': try { $buf = ResourceAttribute::ResolveAll(ResourceAttribute::Collect($classname)); foreach ($buf as $b) { if (!ends_with($b, $kind)) { continue; } $b = strtolower($b); if (!in_array($b, $res_file_storage[$classname])) { $res_file_storage[$classname][] = $b; } } } catch (Exception $ex) { } break; } } }
private function __collectResourcesInternal($template) { $res = array(); if (is_object($template)) { $classname = get_class($template); // first collect statics from the class definitions $static = ResourceAttribute::ResolveAll(ResourceAttribute::Collect($classname)); $res = array_merge($res, $static); if ($template instanceof Renderable) { // then check all contents and collect theis includes foreach ($template->__getContentVars() as $varname) { $sub = array(); foreach ($template->{$varname} as $var) { if (is_object($var) || is_array($var)) { $sub = array_merge($sub, $this->__collectResourcesInternal($var)); } } $res = array_merge($res, $sub); } // for Template class check the template file too if ($template instanceof Template) { $fnl = strtolower(array_shift(explode(".", basename($template->file)))); if (get_class_simple($template, true) != $fnl) { if (resourceExists("{$fnl}.css")) { $res[] = resFile("{$fnl}.css"); } elseif (resourceExists("{$fnl}.less")) { $res[] = resFile("{$fnl}.less"); } if (resourceExists("{$fnl}.js")) { $res[] = resFile("{$fnl}.js"); } } } // finally include the 'self' stuff (<classname>.js,...) // Note: these can be forced to be loaded in static if they require to be loaded before the contents resources $classname = get_class_simple($template); $parents = array(); $cnl = strtolower($classname); do { if (resourceExists("{$cnl}.css")) { $parents[] = resFile("{$cnl}.css"); } elseif (resourceExists("{$cnl}.less")) { $parents[] = resFile("{$cnl}.less"); } if (resourceExists("{$cnl}.js")) { $parents[] = resFile("{$cnl}.js"); } $classname = array_pop(explode('\\', get_parent_class(fq_class_name($classname)))); $cnl = strtolower($classname); } while ($classname != ""); $res = array_merge($res, array_reverse($parents)); } } elseif (is_array($template)) { foreach ($template as $var) { if (is_object($var) || is_array($var)) { $res = array_merge($res, $this->__collectResourcesInternal($var)); } } } return array_unique($res); }
/** * Returns aresource file, as local path or as URI. * * @param string $filename The resource filename (relative or name only) * @param bool $as_local_path If true returns no URL, but a local path * @return string An URL to the resource or the local file path. FALSE on error. */ function resFile($filename, $as_local_path = false) { if ($conf = resourceExists($filename, true, $as_local_path)) { return $conf; } return ""; }