Пример #1
0
 /**
  * Resets the filters
  * @param string $root Root directory
  * @return array
  */
 public function resetFilters($root)
 {
     // Get a reference to the global Filters object
     $filters = Factory::getFilters();
     $filter = Factory::getFilterObject('directories');
     $filter->reset($root);
     $filter = Factory::getFilterObject('files');
     $filter->reset($root);
     $filter = Factory::getFilterObject('skipdirs');
     $filter->reset($root);
     $filter = Factory::getFilterObject('skipfiles');
     $filter->reset($root);
     $filters->save();
     return $this->make_listing($root);
 }
Пример #2
0
 /**
  * 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);
             }
         }
     }
 }
Пример #3
0
 /**
  * Resets the filters
  *
  * @param   string  $root  Root directory
  *
  * @return  array
  */
 protected function resetAllFilters($root)
 {
     // Get a reference to the global Filters object
     $filters = Factory::getFilters();
     foreach ($this->knownFilterTypes as $filterName) {
         $filter = Factory::getFilterObject($filterName);
         $filter->reset($root);
     }
     $filters->save();
 }