/** * Find a file (or directory) of a certain category * @param string $category the category of the file * @param string $file_name the file name of the file we wish to find * @param boolean $find_all Defatults to false * @returns mixed. Returns either a string which is the path and file name of the file * we found, or null if we did not find the file. */ public function search($category, $file_name, $find_all = false) { if (!array_key_exists($category, $this->ordered_paths)) { $factory = I2CE_ModuleFactory::instance(); $factory->loadPaths(null, $category, false, $this); } if ($find_all || $this->stale_time < 0) { return parent::search($category, $file_name, $find_all); } if (array_key_exists($category, $this->preferred_locales) && is_array($this->preferred_locales[$category])) { $locales = $this->preferred_locales[$category]; } else { $locales = I2CE_Locales::getPreferredLocales(); } if (array_key_exists('I2CE_FileSearch_Caching', $_SESSION) && is_array($_SESSION['I2CE_FileSearch_Caching']) && array_key_exists($category, $_SESSION['I2CE_FileSearch_Caching']) && is_array($_SESSION['I2CE_FileSearch_Caching'][$category]) && array_key_exists($file_name, $_SESSION['I2CE_FileSearch_Caching'][$category]) && is_array($_SESSION['I2CE_FileSearch_Caching'][$category][$file_name])) { $data = $_SESSION['I2CE_FileSearch_Caching'][$category][$file_name]; if (array_key_exists('time', $data) && array_key_exists('location', $data) && array_key_exists('locale', $data)) { if (is_readable($data['location']) && time() - $data['time'] < $this->stale_time) { $this->found_locales = $data['locale']; return $data['location']; } else { unset($_SESSION['I2CE_FileSearch_Caching'][$category][$file_name]); } } } //did not find the file $location = parent::search($category, $file_name, false); if (!is_string($location) || strlen($location) == 0) { return null; } $_SESSION['I2CE_FileSearch_Caching'][$category][$file_name] = array('time' => time(), 'location' => $location, 'locale' => $this->found_locales); return $location; }
/** * Update the storage object with the classfile and default classpath. * * @param $storage I2CE_MagicDataNode * @param $module string containing the short module name. * * @returns boolean TRUE for success */ protected function updateMetaDataPaths() { $paths = $this->query('/I2CEConfiguration/metadata/path'); for ($i = 0; $i < $paths->length; $i++) { $pathNode = $paths->item($i); $pathCategory = strtoupper(trim($pathNode->getAttribute('name'))); $pathValues = $pathNode->getElementsByTagName('value'); $vals = array(); $this->meta_config->setIfIsSet($vals, "paths/{$pathCategory}", true); for ($j = 0; $j < $pathValues->length; $j++) { $vals[] = trim($pathValues->item($j)->textContent); } $this->meta_config->paths->{$pathCategory} = $vals; } if (isset($this->meta_config->class)) { unset($this->meta_config->class->file); } if (!isset($this->meta_config->paths->CLASSES)) { $this->meta_config->paths->CLASSES = array('./'); } if (isset($this->meta_config->class) && isset($this->meta_config->class->name)) { $temp_search = new I2CE_FileSearch(); $file = NULL; $this->meta_config->setIfIsSet($file, "file"); $prefix = dirname($file); if ($this->meta_config->is_parent("paths/CLASSES")) { foreach ($this->meta_config->paths->CLASSES as $path) { if (!$temp_search->addPath('CLASSES', $path, 'EVEN_LOWER', TRUE, $prefix)) { $this->raiseError("{$prefix}" . DIRECTORY_SEPARATOR . "{$path} doesn't exist!"); } } } $classfile = $temp_search->search('CLASSES', $this->meta_config->class->name . '.php'); if (!$classfile) { $path = print_r($temp_search->getSearchPath('CLASSES'), true); $this->raiseError("Class {$this->meta_config->class->name}" . " cannot be found in the given class" . " search path: {$path}", E_ERROR); return FALSE; } $this->meta_config->class->file = realpath($classfile); } return TRUE; }