Esempio n. 1
0
 /**
  * Traverses the folder and adds the folder recursively.
  *
  * @param string $strFolder
  *
  * @return bool
  */
 public function addFolder($strFolder)
 {
     $bitReturn = true;
     if (is_dir(_realpath_ . $strFolder)) {
         $objFilesystem = new class_filesystem();
         $arrFiles = $objFilesystem->getCompleteList($strFolder, array(), array(), array(".", ".."));
         foreach ($arrFiles["files"] as $arrOneFile) {
             $bitReturn = $bitReturn && $this->addFile($arrOneFile["filepath"]);
         }
         foreach ($arrFiles["folders"] as $strOneFolder) {
             $bitReturn = $bitReturn && $this->addFolder($strFolder . "/" . $strOneFolder);
         }
         return $bitReturn;
     }
     return false;
 }
 /**
  * Returns a list of installed packages, so a single metadata-entry
  * for each package.
  *
  * @return class_module_packagemanager_metadata[]
  */
 public function getInstalledPackages()
 {
     $arrReturn = array();
     //loop all packages found
     $objFilesystem = new class_filesystem();
     $arrFolders = $objFilesystem->getCompleteList("/templates");
     foreach ($arrFolders["folders"] as $strOneFolder) {
         try {
             $objMetadata = new class_module_packagemanager_metadata();
             $objMetadata->autoInit("/templates/" . $strOneFolder);
             $arrReturn[] = $objMetadata;
         } catch (class_exception $objEx) {
         }
     }
     return $arrReturn;
 }
 /**
  * @param $strPath
  * @return void
  */
 private function recursiveImageProcessing($strPath)
 {
     $objFilesystem = new class_filesystem();
     $arrFilesFolders = $objFilesystem->getCompleteList($strPath, array(".jpg", ".jpeg", ".png", ".gif"), array(), array(".", "..", ".svn"));
     $this->intFilesTotal += $arrFilesFolders["nrFiles"];
     foreach ($arrFilesFolders["folders"] as $strOneFolder) {
         $this->recursiveImageProcessing($strPath . "/" . $strOneFolder);
     }
     foreach ($arrFilesFolders["files"] as $arrOneFile) {
         $strImagePath = $strPath . "/" . $arrOneFile["filename"];
         $objImage = new class_image2();
         $objImage->setUseCache(false);
         $objImage->load($strImagePath);
         $objImage->addOperation(new class_image_scale($this->intMaxWidth, $this->intMaxHeight));
         if ($objImage->save($strImagePath)) {
             $this->intFilesProcessed++;
         }
     }
 }
Esempio n. 4
0
function walkFolderRecursive($strStartFolder)
{
    $objFilesystem = new class_filesystem();
    $arrFilesAndFolders = $objFilesystem->getCompleteList($strStartFolder, array(".php"), array(), array(".", "..", ".svn"));
    foreach ($arrFilesAndFolders["files"] as $arrOneFile) {
        $strFilename = $arrOneFile["filename"];
        //include the filecontent
        $strContent = file_get_contents($strStartFolder . "/" . $strFilename);
        if (uniSubstr($strContent, 0, 5) != "<?php") {
            echo "Whitespace at the beginning of file >> " . $strStartFolder . "/" . $strFilename . " is:>" . uniSubstr($strContent, 0, 1) . "< << \n";
        }
        if (uniSubstr($strContent, -2) != "?>") {
            echo "Whitespace at the end of file >> " . $strStartFolder . "/" . $strFilename . " << \n";
        }
    }
    foreach ($arrFilesAndFolders["folders"] as $strOneFolder) {
        walkFolderRecursive($strStartFolder . "/" . $strOneFolder);
    }
}
 /**
  * Checks if all content of the passed folder is writable
  * @param string $strFolder
  * @param string[] $arrErrors
  */
 private function checkWritableRecursive($strFolder, &$arrErrors)
 {
     if (!is_writable(_realpath_ . $strFolder)) {
         $arrErrors[] = $strFolder;
     }
     $objFilesystem = new class_filesystem();
     $arrContent = $objFilesystem->getCompleteList($strFolder);
     foreach ($arrContent["files"] as $arrOneFile) {
         if (!is_writable(_realpath_ . $strFolder . "/" . $arrOneFile["filename"])) {
             $arrErrors[] = $strFolder . "/" . $arrOneFile["filename"];
         }
     }
     foreach ($arrContent["folders"] as $strOneFolder) {
         $this->checkWritableRecursive($strFolder . "/" . $strOneFolder, $arrErrors);
     }
 }
 /**
  * Synchronized the list of template-packs available in the filesystem
  * with the list of packs stored at the database.
  *
  * @return void
  * @static
  */
 public static function syncTemplatepacks()
 {
     //scan the list of packs available in the filesystem
     $objFilesystem = new class_filesystem();
     $arrFolders = $objFilesystem->getCompleteList("/templates");
     //scan packs installed
     /** @var class_module_packagemanager_template[] $arrPacksInstalled */
     $arrPacksInstalled = self::getObjectList();
     foreach ($arrFolders["folders"] as $strOneFolder) {
         $bitFolderFound = false;
         //search the pack in the list of available ones
         foreach ($arrPacksInstalled as $objOnePack) {
             if ($objOnePack->getStrName() == $strOneFolder) {
                 $bitFolderFound = true;
                 break;
             }
         }
         if (!$bitFolderFound) {
             $objPack = new class_module_packagemanager_template();
             $objPack->setStrName($strOneFolder);
             $objPack->setIntRecordStatus(0);
             $objPack->updateObjectToDb();
         }
     }
     //scan folders not existing any more
     foreach ($arrPacksInstalled as $objOnePack) {
         if (!in_array($objOnePack->getStrName(), $arrFolders["folders"])) {
             $objOnePack->deleteObjectFromDatabase();
         }
     }
 }
 /**
  * Syncs the files in the db with the files in the filesystem
  *
  * @param string $strPrevID
  * @param string $strPath
  * @param bool $bitRecursive
  * @param \class_module_mediamanager_repo|null $objRepo
  *
  * @return array [insert, delete]
  */
 public static function syncRecursive($strPrevID, $strPath, $bitRecursive = true, class_module_mediamanager_repo $objRepo = null)
 {
     $arrReturn = array();
     $arrReturn["insert"] = 0;
     $arrReturn["delete"] = 0;
     if ($objRepo == null) {
         $objRepo = class_objectfactory::getInstance()->getObject($strPrevID);
         while ($objRepo != null && !$objRepo instanceof class_module_mediamanager_repo) {
             $objRepo = class_objectfactory::getInstance()->getObject($objRepo->getPrevId());
         }
     }
     //Load the files in the DB
     $arrObjDB = class_module_mediamanager_file::loadFilesDB($strPrevID);
     //Load files and folder from filesystem
     $objFilesystem = new class_filesystem();
     //if the repo defines a view-filter, take that one into account
     $arrViewFilter = array();
     if ($objRepo->getStrViewFilter() != "") {
         $arrViewFilter = explode(",", $objRepo->getStrViewFilter());
     }
     $arrFilesystem = $objFilesystem->getCompleteList($strPath, $arrViewFilter, array(), array(".", "..", ".svn"));
     //So, lets sync those two arrays
     //At first the files
     foreach ($arrFilesystem["files"] as $intKeyFS => $arrOneFileFilesystem) {
         //search the db-array for this file
         foreach ($arrObjDB as $intKeyDB => $objOneFileDB) {
             //File or folder
             if ($objOneFileDB->getintType() == self::$INT_TYPE_FILE) {
                 //compare
                 if ($objOneFileDB->getStrFilename() == str_replace(_realpath_, "", $arrOneFileFilesystem["filepath"])) {
                     //And unset from both arrays
                     unset($arrFilesystem["files"][$intKeyFS]);
                     unset($arrObjDB[$intKeyDB]);
                 }
             }
         }
     }
     //And loop the folders
     foreach ($arrFilesystem["folders"] as $intKeyFolder => $strFolder) {
         //search the array for folders
         foreach ($arrObjDB as $intKeyDB => $objOneFolderDB) {
             //file or folder?
             if ($objOneFolderDB->getIntType() == self::$INT_TYPE_FOLDER) {
                 //compare
                 if ($objOneFolderDB->getStrFilename() == $strPath . "/" . $strFolder) {
                     //Unset from both
                     unset($arrFilesystem["folders"][$intKeyFolder]);
                     unset($arrObjDB[$intKeyDB]);
                 }
             }
         }
     }
     //the remaining records from the database have to be deleted!
     if (count($arrObjDB) > 0) {
         foreach ($arrObjDB as $objOneFileDB) {
             $objOneFileDB->deleteObjectFromDatabase();
             $arrReturn["delete"]++;
         }
     }
     //the remaining records from the filesystem have to be added
     foreach ($arrFilesystem["files"] as $arrOneFileFilesystem) {
         $strFileName = $arrOneFileFilesystem["filename"];
         $strFileFilename = str_replace(_realpath_, "", $arrOneFileFilesystem["filepath"]);
         $objFile = new class_module_mediamanager_file();
         $objFile->setStrFilename($strFileFilename);
         $objFile->setStrName($strFileName);
         $objFile->setIntType(self::$INT_TYPE_FILE);
         $objFile->updateObjectToDb($strPrevID);
         $arrReturn["insert"]++;
     }
     foreach ($arrFilesystem["folders"] as $strFolder) {
         $strFileName = $strFolder;
         $strFileFilename = $strPath . "/" . $strFolder;
         $objFile = new class_module_mediamanager_file();
         $objFile->setStrFilename($strFileFilename);
         $objFile->setStrName($strFileName);
         $objFile->setIntType(self::$INT_TYPE_FOLDER);
         $objFile->updateObjectToDb($strPrevID);
         $arrReturn["insert"]++;
     }
     //Load subfolders
     class_carrier::getInstance()->getObjDB()->flushQueryCache();
     if ($bitRecursive) {
         $objFolders = class_module_mediamanager_file::loadFilesDB($strPrevID, self::$INT_TYPE_FOLDER);
         foreach ($objFolders as $objOneFolderDB) {
             $arrTemp = class_module_mediamanager_file::syncRecursive($objOneFolderDB->getSystemid(), $objOneFolderDB->getStrFilename(), $bitRecursive, $objRepo);
             $arrReturn["insert"] += $arrTemp["insert"];
             $arrReturn["delete"] += $arrTemp["delete"];
         }
     }
     return $arrReturn;
 }
 /**
  * Generates a view to browse the filesystem directly.
  * By default, the methods takes two params into account: folder and form_element
  *
  * @return string
  * @autoTestable
  */
 protected function actionFolderListFolderview()
 {
     $this->setArrModuleEntry("template", "/folderview.tpl");
     $strReturn = "";
     //param inits
     $strFolder = "/files";
     if ($this->getParam("folder") != "") {
         $strFolder = $this->getParam("folder");
     }
     $arrExcludeFolder = array(0 => ".", 1 => "..");
     $strFormElement = $this->getParam("form_element");
     $objFilesystem = new class_filesystem();
     $arrContent = $objFilesystem->getCompleteList($strFolder, array(), array(), $arrExcludeFolder, true, false);
     $strReturn .= $this->objToolkit->listHeader();
     $strReturn .= $this->objToolkit->genericAdminList(generateSystemid(), $this->getLang("commons_path"), "", $strFolder, 1);
     $strReturn .= $this->objToolkit->listFooter();
     $strReturn .= $this->objToolkit->divider();
     $intCounter = 0;
     //Show Folders
     //Folder to jump one back up
     $arrFolderStart = array("/files");
     $strReturn .= $this->objToolkit->listHeader();
     $bitHit = false;
     if (!in_array($strFolder, $arrFolderStart) && $bitHit == false) {
         $strAction = $this->objToolkit->listButton(class_link::getLinkAdmin($this->getArrModule("modul"), "folderListFolderview", "&folder=" . uniSubstr($strFolder, 0, uniStrrpos($strFolder, "/")) . "&form_element=" . $strFormElement, $this->getLang("commons_one_level_up"), $this->getLang("commons_one_level_up"), "icon_folderActionLevelup"));
         $strReturn .= $this->objToolkit->genericAdminList(generateSystemid(), "..", class_adminskin_helper::getAdminImage("icon_folderOpen"), $strAction, $intCounter++);
     }
     if ($arrContent["nrFolders"] != 0) {
         foreach ($arrContent["folders"] as $strFolderCur) {
             $strAction = $this->objToolkit->listButton(class_link::getLinkAdmin($this->getArrModule("modul"), "folderListFolderview", "&folder=" . $strFolder . "/" . $strFolderCur . "&form_element=" . $strFormElement, $this->getLang("action_open_folder"), $this->getLang("action_open_folder"), "icon_folderActionOpen"));
             $strAction .= $this->objToolkit->listButton("<a href=\"#\" title=\"" . $this->getLang("commons_accept") . "\" rel=\"tooltip\" onclick=\"KAJONA.admin.folderview.selectCallback([['" . $strFormElement . "', '" . $strFolder . "/" . $strFolderCur . "']]);\">" . class_adminskin_helper::getAdminImage("icon_accept"));
             $strReturn .= $this->objToolkit->genericAdminList(generateSystemid(), $strFolderCur, class_adminskin_helper::getAdminImage("icon_folderOpen"), $strAction, $intCounter++);
         }
     }
     if ($bitHit) {
         $strReturn .= $this->objToolkit->listFooter();
     }
     return $strReturn;
 }