public function getFiles() { $ret = array(); $directory = $this->getState('directory', ''); $directory = AEUtilFilesystem::translateStockDirs($directory); // Get all archive files $allFiles = AEUtilScanner::getFiles($directory, true); $files = array(); if (!empty($allFiles)) { foreach ($allFiles as $file) { $ext = strtoupper(substr($file, -3)); if (in_array($ext, array('JPA', 'JPS', 'ZIP'))) { $files[] = $file; } } } // If nothing found, bail out if (empty($files)) { return $ret; } // Make sure these files do not already exist in another backup record $db = $this->getDBO(); $sql = $db->getQuery(true)->select($db->qn('absolute_path'))->from($db->qn('#__ak_stats'))->where($db->qn('absolute_path') . ' LIKE ' . $db->q($directory . '%'))->where($db->qn('filesexist') . ' = ' . $db->q('1')); $db->setQuery($sql); $existingfiles = $db->loadColumn(); foreach ($files as $file) { if (!in_array($file, $existingfiles)) { $ret[] = $file; } } return $ret; }
function getLogFiles() { $configuration = AEFactory::getConfiguration(); $outdir = $configuration->get('akeeba.basic.output_directory'); $files = AEUtilScanner::getFiles($outdir); $ret = array(); if (!empty($files) && is_array($files)) { foreach ($files as $filename) { $basename = basename($filename); if (substr($basename, 0, 7) == 'akeeba.' && substr($basename, -4) == '.log' && $basename != 'akeeba.log') { $tag = str_replace('akeeba.', '', str_replace('.log', '', $basename)); if (!empty($tag)) { $ret[] = $tag; } } } } return $ret; }
/** * Returns a listing of contained directories and files, as well as their * exclusion status * @param string $root The root directory * @param string $node The subdirectory to scan * @return array */ private function &get_listing($root, $node) { // Initialize the absolute directory root $directory = substr($root, 0); // Replace stock directory tags, like [SITEROOT] $stock_dirs = AEPlatform::getInstance()->get_stock_directories(); if (!empty($stock_dirs)) { foreach ($stock_dirs as $key => $replacement) { $directory = str_replace($key, $replacement, $directory); } } $directory = AEUtilFilesystem::TranslateWinPath($directory); // Clean and add the node $node = AEUtilFilesystem::TranslateWinPath($node); if ($node == '/') { $node = ''; } // Just a dir. sep. is treated as no dir at all // Trim leading and trailing slashes $node = trim($node, '/'); // Add node to directory if (!empty($node)) { $directory .= '/' . $node; } // Add any required trailing slash to the node to be used below if (!empty($node)) { $node .= '/'; } // Get a filters instance $filters = AEFactory::getFilters(); // Detect PHP 5.2.5or earlier, with broken json_decode implementation $phpversion = PHP_VERSION; $vparts = explode('.', $phpversion); if ($vparts[0] == 5 && $vparts[1] == 2 && $vparts[2] <= 5 || $vparts[0] == 5 && $vparts[1] == 1) { define('AKEEBA_SAFE_JSON', false); require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/jsonlib.php'; } else { $test = '-test-'; $tj = json_encode($test); $test = json_decode($test); if ($test == '-test-') { define('AKEEBA_SAFE_JSON', true); } else { define('AKEEBA_SAFE_JSON', false); require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/jsonlib.php'; } } // Get a listing of folders and process it $folders = AEUtilScanner::getFolders($directory); asort($folders); $folders_out = array(); if (!empty($folders)) { foreach ($folders as $folder) { $folder = AEUtilFilesystem::TranslateWinPath($folder); // Filter out files whose names result to an empty JSON representation if (AKEEBA_SAFE_JSON) { $json_folder = json_encode($folder); $folder = json_decode($json_folder); } else { $jsonobj = new Akeeba_Services_JSON(0); $json_folder = $jsonobj->encode($folder); $folder = $jsonobj->decode($json_folder); } if (empty($folder)) { continue; } $test = $node . $folder; $status = array(); // Check dir/all filter (exclude) $result = $filters->isFilteredExtended($test, $root, 'dir', 'all', $byFilter); $status['directories'] = !$result ? 0 : ($byFilter == 'directories' ? 1 : 2); // Check dir/content filter (skip_files) $result = $filters->isFilteredExtended($test, $root, 'dir', 'content', $byFilter); $status['skipfiles'] = !$result ? 0 : ($byFilter == 'skipfiles' ? 1 : 2); // Check dir/children filter (skip_dirs) $result = $filters->isFilteredExtended($test, $root, 'dir', 'children', $byFilter); $status['skipdirs'] = !$result ? 0 : ($byFilter == 'skipdirs' ? 1 : 2); // Add to output array $folders_out[$folder] = $status; } } unset($folders); $folders = $folders_out; // Get a listing of files and process it $files = AEUtilScanner::getFiles($directory); asort($files); $files_out = array(); if (!empty($files)) { foreach ($files as $file) { // Filter out files whose names result to an empty JSON representation if (AKEEBA_SAFE_JSON) { $json_file = json_encode($file); $file = json_decode($json_file); } else { $jsonobj = new Akeeba_Services_JSON(0); $json_file = $jsonobj->encode($file); $file = $jsonobj->decode($json_file); } if (empty($file)) { continue; } $test = $node . $file; $status = array(); // Check file/all filter (exclude) $result = $filters->isFilteredExtended($test, $root, 'file', 'all', $byFilter); $status['files'] = !$result ? 0 : ($byFilter == 'files' ? 1 : 2); $status['size'] = @filesize($directory . '/' . $file); // Add to output array $files_out[$file] = $status; } } unset($files); $files = $files_out; // Return a compiled array $retarray = array('folders' => $folders, 'files' => $files); return $retarray; /* Return array format * [array] : * 'folders' [array] : * (folder_name) => [array]: * 'directories' => 0|1|2 * 'skipfiles' => 0|1|2 * 'skipdirs' => 0|1|2 * 'files' [array] : * (file_name) => [array]: * 'files' => 0|1|2 * * Legend: * 0 -> Not excluded * 1 -> Excluded by the direct filter * 2 -> Excluded by another filter (regex, api, an unknown plugin filter...) */ }
/** * Public constructor, loads filter data and filter classes */ public final function __construct() { static $initializing = false; parent::__construct(); // Call parent's constructor // Load filter data from platform's database AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Fetching filter data from database'); $this->filter_registry =& AEPlatform::getInstance()->load_filters(); // Load platform, plugin and core filters $this->filters = array(); $locations = array(AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'platform' . DIRECTORY_SEPARATOR . AKEEBAPLATFORM . DIRECTORY_SEPARATOR . 'filters', AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'filters', AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'filters'); AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Loading filters'); foreach ($locations as $folder) { $is_platform = $folder == AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'platform' . DIRECTORY_SEPARATOR . AKEEBAPLATFORM . DIRECTORY_SEPARATOR . 'filters'; $files = AEUtilScanner::getFiles($folder); if ($files === false) { continue; } // Skip inexistent folders if (empty($files)) { continue; } // Skip no-match folders // Loop all files foreach ($files as $file) { if (substr($file, -4) != '.php') { continue; } // Skip non-PHP files if (in_array(substr($file, 0, 1), array('.', '_'))) { continue; } // Skip filter files starting with dot or dash $filter_name = ($is_platform ? 'Platform' : '') . ucfirst(basename($file, '.php')); // Extract filter base name if (array_key_exists($filter_name, $this->filters)) { continue; } // Skip already loaded filters AEUtilLogger::WriteLog(_AE_LOG_DEBUG, '-- Loading filter ' . $filter_name); $this->filters[$filter_name] =& AEFactory::getFilterObject($filter_name); // Add the filter } } // Load platform, plugin and core stacked filters $locations = array(AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'platform' . DIRECTORY_SEPARATOR . AKEEBAPLATFORM . DIRECTORY_SEPARATOR . 'filters' . DIRECTORY_SEPARATOR . 'stack', AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'filters' . DIRECTORY_SEPARATOR . 'stack', AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'filters' . DIRECTORY_SEPARATOR . 'stack'); $config =& AEFactory::getConfiguration(); AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Loading optional filters'); foreach ($locations as $folder) { $is_platform = $folder == AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'platform' . DIRECTORY_SEPARATOR . AKEEBAPLATFORM . DIRECTORY_SEPARATOR . 'filters' . DIRECTORY_SEPARATOR . 'stack'; $files = AEUtilScanner::getFiles($folder); if ($files === false) { continue; } // Skip inexistent folders if (empty($files)) { continue; } // Skip no-match folders // Loop all files foreach ($files as $file) { if (substr($file, -4) != '.php') { continue; } // Skip non-PHP files $bare_name = strtolower(basename($file, '.php')); $filter_name = 'Stack' . ($is_platform ? 'Platform' : '') . ucfirst(basename($file, '.php')); // Extract filter base name if (array_key_exists($filter_name, $this->filters)) { continue; } // Skip already loaded filters if (!file_exists(substr($file, 0, -4) . '.ini')) { continue; } // Make sure the INI file also exists $key = "core.filters.{$bare_name}.enabled"; if ($config->get($key, 0)) { AEUtilLogger::WriteLog(_AE_LOG_DEBUG, '-- Loading optional filter ' . $filter_name); $this->filters[$filter_name] =& AEFactory::getFilterObject($filter_name); // Add the filter } } } }
/** * Public constructor, loads filter data and filter classes */ public final function __construct() { static $initializing = false; parent::__construct(); // Call parent's constructor // Load filter data from platform's database AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Fetching filter data from database'); $this->filter_registry = AEPlatform::getInstance()->load_filters(); // Load platform, plugin and core filters $this->filters = array(); $locations = array(AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'filters', AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'filters'); $platform_paths = AEPlatform::getInstance()->getPlatformDirectories(); foreach ($platform_paths as $p) { $locations[] = $p . '/filters'; } AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Loading filters'); foreach ($locations as $folder) { $is_platform = $this->isPlatformDirectory($folder); $files = AEUtilScanner::getFiles($folder); if ($files === false) { continue; } // Skip inexistent folders if (empty($files)) { continue; } // Skip no-match folders // Loop all files foreach ($files as $file) { if (substr($file, -4) != '.php') { continue; // Skip non-PHP files } if (in_array(substr($file, 0, 1), array('.', '_'))) { continue; // Skip filter files starting with dot or dash } // 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(basename($file, '.php')); if (preg_match('/[^a-z0-9]/', $bare_name)) { continue; } $filter_name = ($is_platform ? 'Platform' : '') . ucfirst(basename($file, '.php')); // Extract filter base name if (array_key_exists($filter_name, $this->filters)) { continue; // Skip already loaded filters } AEUtilLogger::WriteLog(_AE_LOG_DEBUG, '-- Loading filter ' . $filter_name); $this->filters[$filter_name] = AEFactory::getFilterObject($filter_name); // Add the filter } } // Load platform, plugin and core stacked filters $locations = array(AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'filters' . DIRECTORY_SEPARATOR . 'stack', AEFactory::getAkeebaRoot() . DIRECTORY_SEPARATOR . 'filters' . DIRECTORY_SEPARATOR . 'stack'); $platform_paths = AEPlatform::getInstance()->getPlatformDirectories(); $platform_stack_paths = array(); foreach ($platform_paths as $p) { $locations[] = $p . '/filters'; $locations[] = $p . '/filters/stack'; $platform_stack_paths[] = $p . '/filters/stack'; } $config = AEFactory::getConfiguration(); AEUtilLogger::WriteLog(_AE_LOG_DEBUG, 'Loading optional filters'); foreach ($locations as $folder) { $is_platform = $this->isPlatformDirectory($folder); $files = AEUtilScanner::getFiles($folder); if ($files === false) { continue; } // Skip inexistent folders if (empty($files)) { continue; } // Skip no-match folders // Loop all files foreach ($files as $file) { if (substr($file, -4) != '.php') { continue; } // Skip non-PHP files // 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(basename($file, '.php')); if (preg_match('/[^a-z0-9]/', $bare_name)) { continue; } $filter_name = 'Stack' . ($is_platform ? 'Platform' : '') . ucfirst(basename($file, '.php')); // Extract filter base name if (array_key_exists($filter_name, $this->filters)) { continue; } // Skip already loaded filters if (!file_exists($folder . '/' . substr($file, 0, -4) . '.ini')) { continue; } // Make sure the INI file also exists $key = "core.filters.{$bare_name}.enabled"; if ($config->get($key, 0)) { AEUtilLogger::WriteLog(_AE_LOG_DEBUG, '-- Loading optional filter ' . $filter_name); $this->filters[$filter_name] = AEFactory::getFilterObject($filter_name); // Add the filter } } } }