Refactor file_listing functions to static methods
Signed-off-by: Maurício Meneghini Fauth <mauriciofauth@gmail.com>
This commit is contained in:
parent
360d0ad62e
commit
e555b77946
@ -1002,7 +1002,6 @@ class Export
|
||||
$GLOBALS['single_table'] = $_REQUEST['single_table'];
|
||||
}
|
||||
|
||||
include_once './libraries/file_listing.lib.php';
|
||||
include_once './libraries/plugin_interface.lib.php';
|
||||
|
||||
/* Scan for plugins */
|
||||
|
||||
@ -650,7 +650,6 @@ class Import
|
||||
public static function getImportDisplay($import_type, $db, $table, $max_upload_size)
|
||||
{
|
||||
global $SESSION_KEY;
|
||||
include_once './libraries/file_listing.lib.php';
|
||||
include_once './libraries/plugin_interface.lib.php';
|
||||
|
||||
list(
|
||||
|
||||
106
libraries/classes/FileListing.php
Normal file
106
libraries/classes/FileListing.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Functions for listing directories
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
/**
|
||||
* PhpMyAdmin\FileListing class
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
class FileListing
|
||||
{
|
||||
/**
|
||||
* Returns array of filtered file names
|
||||
*
|
||||
* @param string $dir directory to list
|
||||
* @param string $expression regular expression to match files
|
||||
*
|
||||
* @return array sorted file list on success, false on failure
|
||||
*/
|
||||
public static function getDirContent($dir, $expression = '')
|
||||
{
|
||||
if (!@file_exists($dir) || !($handle = @opendir($dir))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
if (substr($dir, -1) != '/') {
|
||||
$dir .= '/';
|
||||
}
|
||||
while ($file = @readdir($handle)) {
|
||||
if (@is_file($dir . $file)
|
||||
&& ! @is_link($dir . $file)
|
||||
&& ($expression == '' || preg_match($expression, $file))
|
||||
) {
|
||||
$result[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
asort($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns options of filtered file names
|
||||
*
|
||||
* @param string $dir directory to list
|
||||
* @param string $extensions regular expression to match files
|
||||
* @param string $active currently active choice
|
||||
*
|
||||
* @return array sorted file list on success, false on failure
|
||||
*/
|
||||
public static function getFileSelectOptions($dir, $extensions = '', $active = '')
|
||||
{
|
||||
$list = self::getDirContent($dir, $extensions);
|
||||
if ($list === false) {
|
||||
return false;
|
||||
}
|
||||
$result = '';
|
||||
foreach ($list as $val) {
|
||||
$result .= '<option value="' . htmlspecialchars($val) . '"';
|
||||
if ($val == $active) {
|
||||
$result .= ' selected="selected"';
|
||||
}
|
||||
$result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currently supported decompressions.
|
||||
*
|
||||
* @return string separated list of extensions usable in self::getDirContent
|
||||
*/
|
||||
public static function supportedDecompressions()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$compressions = '';
|
||||
|
||||
if ($cfg['GZipDump'] && @function_exists('gzopen')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'gz';
|
||||
}
|
||||
if ($cfg['BZipDump'] && @function_exists('bzopen')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'bz2';
|
||||
}
|
||||
if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'zip';
|
||||
}
|
||||
|
||||
return $compressions;
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,7 @@
|
||||
namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\FileListing;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Plugins\TransformationsPlugin;
|
||||
use PhpMyAdmin\Relation;
|
||||
@ -1237,7 +1238,7 @@ class InsertEdit
|
||||
*/
|
||||
public static function getSelectOptionForUpload($vkey, $column)
|
||||
{
|
||||
$files = PMA_getFileSelectOptions(
|
||||
$files = FileListing::getFileSelectOptions(
|
||||
Util::userDir($GLOBALS['cfg']['UploadDir'])
|
||||
);
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ namespace PhpMyAdmin;
|
||||
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\FileListing;
|
||||
use PhpMyAdmin\Message;
|
||||
use PhpMyAdmin\Plugins\ImportPlugin;
|
||||
use PhpMyAdmin\Response;
|
||||
@ -3385,14 +3386,14 @@ class Util
|
||||
}
|
||||
|
||||
$matcher = '@\.(' . $extensions . ')(\.('
|
||||
. PMA_supportedDecompressions() . '))?$@';
|
||||
. FileListing::supportedDecompressions() . '))?$@';
|
||||
|
||||
$active = (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed']
|
||||
&& isset($GLOBALS['local_import_file']))
|
||||
? $GLOBALS['local_import_file']
|
||||
: '';
|
||||
|
||||
$files = PMA_getFileSelectOptions(
|
||||
$files = FileListing::getFileSelectOptions(
|
||||
self::userDir($uploaddir),
|
||||
$matcher,
|
||||
$active
|
||||
|
||||
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
||||
/**
|
||||
* Functions for listing directories
|
||||
*
|
||||
* @package PhpMyAdmin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns array of filtered file names
|
||||
*
|
||||
* @param string $dir directory to list
|
||||
* @param string $expression regular expression to match files
|
||||
*
|
||||
* @return array sorted file list on success, false on failure
|
||||
*/
|
||||
function PMA_getDirContent($dir, $expression = '')
|
||||
{
|
||||
if (!@file_exists($dir) || !($handle = @opendir($dir))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
if (substr($dir, -1) != '/') {
|
||||
$dir .= '/';
|
||||
}
|
||||
while ($file = @readdir($handle)) {
|
||||
if (@is_file($dir . $file)
|
||||
&& ! @is_link($dir . $file)
|
||||
&& ($expression == '' || preg_match($expression, $file))
|
||||
) {
|
||||
$result[] = $file;
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
asort($result);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns options of filtered file names
|
||||
*
|
||||
* @param string $dir directory to list
|
||||
* @param string $extensions regular expression to match files
|
||||
* @param string $active currently active choice
|
||||
*
|
||||
* @return array sorted file list on success, false on failure
|
||||
*/
|
||||
function PMA_getFileSelectOptions($dir, $extensions = '', $active = '')
|
||||
{
|
||||
$list = PMA_getDirContent($dir, $extensions);
|
||||
if ($list === false) {
|
||||
return false;
|
||||
}
|
||||
$result = '';
|
||||
foreach ($list as $val) {
|
||||
$result .= '<option value="' . htmlspecialchars($val) . '"';
|
||||
if ($val == $active) {
|
||||
$result .= ' selected="selected"';
|
||||
}
|
||||
$result .= '>' . htmlspecialchars($val) . '</option>' . "\n";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currently supported decompressions.
|
||||
*
|
||||
* @return string separated list of extensions usable in PMA_getDirContent
|
||||
*/
|
||||
function PMA_supportedDecompressions()
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$compressions = '';
|
||||
|
||||
if ($cfg['GZipDump'] && @function_exists('gzopen')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'gz';
|
||||
}
|
||||
if ($cfg['BZipDump'] && @function_exists('bzopen')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'bz2';
|
||||
}
|
||||
if ($cfg['ZipDump'] && @function_exists('gzinflate')) {
|
||||
if (!empty($compressions)) {
|
||||
$compressions .= '|';
|
||||
}
|
||||
$compressions .= 'zip';
|
||||
}
|
||||
|
||||
return $compressions;
|
||||
}
|
||||
@ -18,11 +18,6 @@ if (! defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
require_once './libraries/file_listing.lib.php'; // used for file listing
|
||||
|
||||
/**
|
||||
* return HTML for the sql query boxes
|
||||
*
|
||||
|
||||
@ -37,10 +37,6 @@ list(
|
||||
if (!empty($unsaved_values) && count($rows) < count($unsaved_values)) {
|
||||
$rows = array_fill(0, count($unsaved_values), false);
|
||||
}
|
||||
/**
|
||||
* file listing
|
||||
*/
|
||||
require_once 'libraries/file_listing.lib.php';
|
||||
|
||||
/**
|
||||
* Defines the url to return to in case of error in a sql statement
|
||||
|
||||
@ -1214,7 +1214,7 @@ class InsertEditTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* This condition should be tested, however, it gives an undefined function
|
||||
* PMA_getFileSelectOptions error:
|
||||
* PhpMyAdmin\FileListing::getFileSelectOptions error:
|
||||
* $GLOBALS['cfg']['UploadDir'] = true;
|
||||
*
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user