/** * Public constructor, loads filter data and filter classes */ public function __construct() { // Load filter data from platform's database Factory::getLog()->log(LogLevel::DEBUG, 'Fetching filter data from database'); $this->filter_registry = Platform::getInstance()->load_filters(); // Load platform, plugin and core filters $this->filters = array(); $locations = array(Factory::getAkeebaRoot() . '/Filter'); $platform_paths = Platform::getInstance()->getPlatformDirectories(); foreach ($platform_paths as $p) { $locations[] = $p . '/Filter'; } Factory::getLog()->log(LogLevel::DEBUG, 'Loading filters'); foreach ($locations as $folder) { if (!@is_dir($folder)) { continue; } if (!@is_readable($folder)) { continue; } $di = new \DirectoryIterator($folder); foreach ($di as $file) { if (!$file->isFile()) { continue; } // PHP 5.3.5 and earlier do not support getExtension //if ($file->getExtension() != 'php') if (substr($file->getBasename(), -4) != '.php') { continue; } $filename = $file->getFilename(); // Skip filter files starting with dot or dash if (in_array(substr($filename, 0, 1), array('.', '_'))) { continue; } // Some hosts copy .ini and .php files, renaming them (ie foobar.1.php) // We need to exclude them, otherwise we'll get a fatal error for declaring the same class twice $bare_name = $file->getBasename('.php'); if (preg_match('/[^a-zA-Z0-9]/', $bare_name)) { continue; } // Extract filter base name $filter_name = ucfirst($bare_name); // This is an abstract class; do not try to create instance if ($filter_name == 'Base') { continue; } // Skip already loaded filters if (array_key_exists($filter_name, $this->filters)) { continue; } Factory::getLog()->log(LogLevel::DEBUG, '-- Loading filter ' . $filter_name); // Add the filter $this->filters[$filter_name] = Factory::getFilterObject($filter_name); } } // Load platform, plugin and core stacked filters $locations = array(Factory::getAkeebaRoot() . '/Filter/Stack'); $platform_paths = Platform::getInstance()->getPlatformDirectories(); $platform_stack_paths = array(); foreach ($platform_paths as $p) { $locations[] = $p . '/Filter'; $locations[] = $p . '/Filter/Stack'; $platform_stack_paths[] = $p . '/Filter/Stack'; } $config = Factory::getConfiguration(); Factory::getLog()->log(LogLevel::DEBUG, 'Loading optional filters'); foreach ($locations as $folder) { if (!@is_dir($folder)) { continue; } if (!@is_readable($folder)) { continue; } $di = new \DirectoryIterator($folder); /** @var \DirectoryIterator $file */ foreach ($di as $file) { if (!$file->isFile()) { continue; } // PHP 5.3.5 and earlier do not support getExtension // if ($file->getExtension() != 'php') if (substr($file->getBasename(), -4) != '.php') { continue; } // Some hosts copy .ini and .php files, renaming them (ie foobar.1.php) // We need to exclude them, otherwise we'll get a fatal error for declaring the same class twice $bare_name = strtolower($file->getBasename('.php')); if (preg_match('/[^A-Za-z0-9]/', $bare_name)) { continue; } // Extract filter base name if (substr($bare_name, 0, 5) == 'stack') { $bare_name = substr($bare_name, 5); } $filter_name = 'Stack\\Stack' . ucfirst($bare_name); // Skip already loaded filters if (array_key_exists($filter_name, $this->filters)) { continue; } // Make sure the INI file also exists if (!file_exists($folder . '/' . $bare_name . '.ini')) { continue; } $key = "core.filters.{$bare_name}.enabled"; if ($config->get($key, 0)) { Factory::getLog()->log(LogLevel::DEBUG, '-- Loading optional filter ' . $filter_name); // Add the filter $this->filters[$filter_name] = Factory::getFilterObject($filter_name); } } } }
/** * Get the paths for a specific section * * @param string $section The section to get the path list for (engine, installer, gui, filter) * * @return array */ public function getEnginePartPaths($section = 'gui') { // Create the key if it's not already present if (!array_key_exists($section, $this->enginePartPaths)) { $this->enginePartPaths[$section] = array(); } // Add the defaults if the list is empty if (empty($this->enginePartPaths[$section])) { switch ($section) { case 'engine': $this->enginePartPaths[$section] = array(Factory::getFilesystemTools()->TranslateWinPath(Factory::getAkeebaRoot())); break; case 'installer': $this->enginePartPaths[$section] = array(Factory::getFilesystemTools()->TranslateWinPath(Platform::getInstance()->get_installer_images_path())); break; case 'gui': // Add core GUI definitions $this->enginePartPaths[$section] = array(Factory::getFilesystemTools()->TranslateWinPath(Factory::getAkeebaRoot() . '/Core')); // Add platform GUI definition files $platform_paths = Platform::getInstance()->getPlatformDirectories(); foreach ($platform_paths as $p) { $this->enginePartPaths[$section][] = Factory::getFilesystemTools()->TranslateWinPath($p . '/Config'); if (defined('AKEEBA_PRO') && AKEEBA_PRO) { $this->enginePartPaths[$section][] = Factory::getFilesystemTools()->TranslateWinPath($p . '/Config/Pro'); } } break; case 'filter': $this->enginePartPaths[$section] = array(Factory::getFilesystemTools()->TranslateWinPath(Factory::getAkeebaRoot() . '/Platform/Filter/Stack'), Factory::getFilesystemTools()->TranslateWinPath(Factory::getAkeebaRoot() . '/Filter/Stack')); $platform_paths = Platform::getInstance()->getPlatformDirectories(); foreach ($platform_paths as $p) { $this->enginePartPaths[$section][] = Factory::getFilesystemTools()->TranslateWinPath($p . '/Filter/Stack'); } break; } } return $this->enginePartPaths[$section]; }