. * @author tjeerd * @version 1.0 * @updated 18-nov-2010 12:17:32 */ $compile_time = microtime(true); $lib_sorts = ''; class libs { private $load; private $lib_checksums; /** * * @param load */ public function __construct($load = TRUE) { $this->load = $load; } public function __destruct() {} public static function lib_sorts() { return 'interface|class|tool|navigation|module|doctype|sma|plugin'; } /** * * @param prefix * @param dir */ public function load_libs($prefix='', $dir = 'lib') { $prefix = libs::lib_sorts(); $this->load_license($dir); $struct = $this->lib_checksums['libs']; $struct = libs::license_libs($prefix, $dir."/custom", $struct); $struct = libs::license_libs($prefix, "custom", $struct); $libs = array_keys($struct); $return = array(); foreach ($struct as $item) { $file = basename($item['file'], ".php"); $pos = strpos($file, "."); $cur_prefix = substr($file, 0, $pos); $return[$cur_prefix][] = substr($file, $pos+1); } foreach ($libs as $lib) $this->load_file($struct, $lib); return $return; } /** * * @param struct * @param key */ private function load_file($struct, $key) { if (isset($struct[$key])) { if (!empty($struct[$key]['requires'])) { foreach ($struct[$key]['requires'] as $sub) { $this->load_file($struct, $sub); } } require_once($struct[$key]['file']); unset($struct[$key]); } } public static function license_libs($prefix='', $dir = 'lib', $classes = array()) { $prefix = libs::lib_sorts(); if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (preg_match('/^('.$prefix.')\..+\.php$/U', $file)) { $classes = array_merge($classes, libs::license_lib($dir."/".$file)); } else if (is_dir($dir."/".$file) && $file!="." && $file!="..") { $classes = array_merge($classes, libs::license_libs($prefix, $dir."/".$file, $classes)); } } } } return $classes; } public static function license_lib($filename) { $return = array(); $file = file_get_contents($filename); $pattern = "/(class|interface) (.+)\s/U"; preg_match_all($pattern, $file, $matches, PREG_SET_ORDER); if (isset($matches[0])) { $return[$matches[0][2]] = array(); $return[$matches[0][2]]['file'] = $filename; $return[$matches[0][2]]['requires'] = array(); $pattern = "/(implements|extends) (.+)\s/U"; preg_match_all($pattern, $file, $submatches, PREG_SET_ORDER); if (!empty($submatches)) { $subreturn = array(); foreach ($submatches as $submatch) { $subreturn = array_merge($subreturn, explode(",", $submatch[2])); } $return[$matches[0][2]]['requires'] = array_unique($subreturn); } } return $return; } /** * * @param dir */ private function load_license($dir) { $this->lib_checksums = file_get_contents($dir."/license/license.txt"); if (empty($this->lib_checksums)) { die('Fatal error: Contentbooster license file not found.'); exit(); } $this->lib_checksums = base64_decode($this->lib_checksums); $this->lib_checksums = unserialize($this->lib_checksums); foreach ($this->lib_checksums['libs'] as $key => $item) { $item['file'] = preg_replace("/^lib/U", $dir, $item['file']); $this->lib_checksums['libs'][$key] = $item; } foreach ($this->lib_checksums['plugins'] as $key => $item) { $this->lib_checksums['plugins'][$key] = preg_replace("/^lib/U", $dir, $item); } } public function get_plugins() { return $this->lib_checksums['plugins']; } public function get_version() { return $this->lib_checksums['LICENSE_FOR_VERSION']; } } ?>