From 7791ce27ee69a1d64772d3c1717fb49c1b745d80 Mon Sep 17 00:00:00 2001 From: "o.pinke" Date: Mon, 28 Jun 2021 15:54:32 +0200 Subject: [PATCH] init classfile and add to autoloader --- conlite/classes/gui/class.file_list.php | 115 ++++++++++++++++++ .../includes/include.js_files_overview.php | 108 +--------------- data/config/production/config.autoloader.php | 3 +- 3 files changed, 118 insertions(+), 108 deletions(-) create mode 100644 conlite/classes/gui/class.file_list.php diff --git a/conlite/classes/gui/class.file_list.php b/conlite/classes/gui/class.file_list.php new file mode 100644 index 0000000..da33a5a --- /dev/null +++ b/conlite/classes/gui/class.file_list.php @@ -0,0 +1,115 @@ +_sPath = $sPath; + $this->_mFileExt = $mFileExt; + $this->_iScanDepth = 3; + $this->_oTpl = new Template(); + } + + public function scanDir() { + if (empty($this->_sPath) || !is_readable($this->_sPath)) { + return false; + } + $this->_bWritable = (!is_writable($this->_sPath)) ? true : false; + + $this->_aDirItems = $this->_assetsMap($this->_sPath, $this->_iScanDepth); + asort($this->_aDirItems, SORT_STRING | SORT_FLAG_CASE | SORT_NATURAL); + } + + public function renderList($sTpl = null, $bReturn = false) { + global $sess, $area; + $sList = '' . "\n"; + $this->_oTpl->set('s', 'item_list', $sList); + + $this->_oTpl->set('s', 'multilink1', $sess->url("main.php?area=$area&frame=3&file=\${file}")); + $this->_oTpl->set('s', 'multilink2', $sess->url("main.php?area=$area&frame=4&action=js_edit&file=\${file}&tmp_file=\${file}")); + + $this->_oTpl->generate(cRegistry::getConfigValue('path', 'contenido') . cRegistry::getConfigValue('path', 'templates') . "html5/file_list.html", $bReturn); + } + + protected function _getSubItems($sName, $aItems, $sPathToItem) { + $sPathToItem = $sPathToItem . $sName . DIRECTORY_SEPARATOR; + $sItemListEntry = '
  • ' . $sName . "\n\t"; + if (is_array($aItems) && count($aItems) > 0) { + $sItemListEntry .= '' . "\n"; + } + $sItemListEntry .= '
  • ' . "\n"; + return $sItemListEntry; + } + + protected function _assetsMap($source_dir, $directory_depth = 0, $hidden = false) { + if ($fp = @opendir($source_dir)) { + $filedata = array(); + $new_depth = $directory_depth - 1; + $source_dir = rtrim($source_dir, '/') . '/'; + + while (FALSE !== ($file = readdir($fp))) { + // Remove '.', '..', and hidden files [optional] + if (!trim($file, '.') OR ($hidden == false && $file[0] == '.')) { + continue; + } + + + if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir . $file)) { + $aTmp = $this->_assetsMap($source_dir . $file . '/', $new_depth, $hidden); + if (!empty($aTmp)) { + asort($aTmp, SORT_STRING | SORT_FLAG_CASE | SORT_NATURAL); + $filedata[$file] = $aTmp; + } + unset($aTmp); + } else { + $sFileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION)); + if (!empty($this->_mFileExt) && in_array($sFileExt, $this->_mFileExt)) { + $filedata[] = $file; + } + } + } + + closedir($fp); + return $filedata; + } + echo 'can not open dir'; + return FALSE; + } + +} diff --git a/conlite/includes/include.js_files_overview.php b/conlite/includes/include.js_files_overview.php index e13505c..611f761 100644 --- a/conlite/includes/include.js_files_overview.php +++ b/conlite/includes/include.js_files_overview.php @@ -7,114 +7,8 @@ if (!defined('CON_FRAMEWORK')) { die('Illegal call'); } -class clFileList { - protected $_sPath; - protected $_mFileExt; - protected $_iScanDepth; - protected $_aDirItems; - protected $_bWritable; - protected $_oTpl; - - public function __construct($sPath, $mFileExt = null) { - - if(!empty($mFileExt) && is_string($mFileExt)) { - $mFileExt = [strtolower($mFileExt)]; - } - $this->_sPath = $sPath; - $this->_mFileExt = $mFileExt; - $this->_iScanDepth = 3; - $this->_oTpl = new Template(); - } - - public function scanDir() { - if (empty($this->_sPath) || !is_readable($this->_sPath)) { - return false; - } - $this->_bWritable = (!is_writable($this->_sPath)) ? true : false; - - $this->_aDirItems = $this->_assetsMap($this->_sPath, $this->_iScanDepth); - asort($this->_aDirItems, SORT_STRING | SORT_FLAG_CASE | SORT_NATURAL); - } - - public function renderList($sTpl = null, $bReturn = false) { - global $sess, $area; - $sList = ''."\n"; - $this->_oTpl->set('s', 'item_list', $sList); - - $this->_oTpl->set('s', 'multilink1', $sess->url("main.php?area=$area&frame=3&file=\${file}")); - $this->_oTpl->set('s', 'multilink2', $sess->url("main.php?area=$area&frame=4&action=js_edit&file=\${file}&tmp_file=\${file}")); - - $this->_oTpl->generate(cRegistry::getConfigValue('path', 'contenido') . cRegistry::getConfigValue('path', 'templates') . "html5/file_list.html", $bReturn); - } - - protected function _getSubItems($sName, $aItems, $sPathToItem) { - $sPathToItem = $sPathToItem.$sName.DIRECTORY_SEPARATOR; - $sItemListEntry = '
  • '.$sName."\n\t"; - if(is_array($aItems) && count($aItems) >0) { - $sItemListEntry .= ''."\n"; - } - $sItemListEntry .= '
  • '."\n"; - return $sItemListEntry; - } - - protected function _assetsMap($source_dir, $directory_depth = 0, $hidden = false) { - if ($fp = @opendir($source_dir)) { - $filedata = array(); - $new_depth = $directory_depth - 1; - $source_dir = rtrim($source_dir, '/') . '/'; - - while (FALSE !== ($file = readdir($fp))) { - // Remove '.', '..', and hidden files [optional] - if (!trim($file, '.') OR ($hidden == false && $file[0] == '.')) { - continue; - } - - - if (($directory_depth < 1 OR $new_depth > 0) && is_dir($source_dir . $file)) { - $aTmp = $this->_assetsMap($source_dir . $file . '/', $new_depth, $hidden); - if(!empty($aTmp)) { - asort($aTmp, SORT_STRING | SORT_FLAG_CASE | SORT_NATURAL); - $filedata[$file] = $aTmp; - } - unset($aTmp); - } else { - $sFileExt = strtolower(pathinfo($file, PATHINFO_EXTENSION)); - if(!empty($this->_mFileExt) && in_array($sFileExt, $this->_mFileExt)) { - $filedata[] = $file; - } - } - } - - closedir($fp); - return $filedata; - } - echo 'can not open dir'; - return FALSE; - } - -} - -$oDirList = new clFileList($cfgClient[$client]["js"]["path"], 'js'); +$oDirList = new cGuiFileList($cfgClient[$client]["js"]["path"], 'js'); $oDirList->scanDir(); $oDirList->renderList(); \ No newline at end of file diff --git a/data/config/production/config.autoloader.php b/data/config/production/config.autoloader.php index 2432532..8a8efda 100644 --- a/data/config/production/config.autoloader.php +++ b/data/config/production/config.autoloader.php @@ -345,5 +345,6 @@ return array( 'PHPMailerOAuthGoogle' => 'conlite/external/PHPMailer/class.phpmaileroauthgoogle.php', 'cStringMultiByteWrapper' => 'conlite/classes/class.string.multi.byte.wrapper.php', 'cString' => 'conlite/classes/class.string.php', - 'cGuiPage' => 'conlite/classes/gui/class.page.php' + 'cGuiPage' => 'conlite/classes/gui/class.page.php', + 'cGuiFileList' => 'conlite/classes/gui/class.file_list.php' );