Example #1
0
 private static function _getFileInfo($base, $action, $format = 'html')
 {
     // go see what templates are available
     $dirPrefixPatterns = [APP_DIR, CORE_DIR];
     $fileNamePatterns = [$action . '.' . $format, $action];
     $fileTypes = ['phtml' => 'Phtml', 'xhtml' => 'Xhtml'];
     foreach ($dirPrefixPatterns as $dirPrefixPattern) {
         $prefixedBase = $dirPrefixPattern . $base;
         foreach ($fileNamePatterns as $fileNamePattern) {
             foreach ($fileTypes as $fileType => $parserType) {
                 $filePattern = $fileNamePattern . '.' . $fileType;
                 if (!substr_count($prefixedBase, DIRECTORY_SEPARATOR . 'layout' . DIRECTORY_SEPARATOR)) {
                     $layoutDir = 'layout.' . Ajde::app()->getDocument()->getLayout()->getName() . DIRECTORY_SEPARATOR;
                     if ($fileMatch = Ajde_Fs_Find::findFile($prefixedBase . TEMPLATE_DIR . $layoutDir, $filePattern)) {
                         return ['filename' => $fileMatch, 'parser' => $parserType];
                     }
                 }
                 if ($fileMatch = Ajde_Fs_Find::findFile($prefixedBase . TEMPLATE_DIR, $filePattern)) {
                     return ['filename' => $fileMatch, 'parser' => $parserType];
                 }
             }
         }
     }
     return false;
 }
Example #2
0
 /**
  * TODO.
  *
  * @param string $directory
  *
  * @throws Exception
  */
 public function readConfigDir($directory)
 {
     $environment = Ajde_Environment::current();
     $searchDirs = [CORE_DIR . $directory, CORE_DIR . $directory . $environment . DS, APP_DIR . $directory, APP_DIR . $directory . $environment . DS];
     foreach ($searchDirs as $searchDir) {
         foreach (Ajde_Fs_Find::findFiles($searchDir, '*.json') as $configFile) {
             if (!($configData = json_decode(file_get_contents($configFile), true))) {
                 throw new Exception('Config file ' . $configFile . ' contains invalid JSON');
             }
             $this->merge(pathinfo($configFile, PATHINFO_FILENAME), $configData);
         }
     }
 }
Example #3
0
File: Meta.php Project: nabble/ajde
 /**
  * @return Ajde_Crud_Cms_Meta_Type[]
  */
 public function getTypes()
 {
     if (!$this->_types) {
         $ds = DIRECTORY_SEPARATOR;
         $files = Ajde_Fs_Find::findFiles(LIB_DIR . 'Ajde' . $ds . 'Crud' . $ds . 'Cms' . $ds . 'Meta' . $ds . 'Type' . $ds, '*.php');
         foreach ($files as $file) {
             $filename = pathinfo($file, PATHINFO_FILENAME);
             $className = 'Ajde_Crud_Cms_Meta_Type_' . ucfirst($filename);
             $this->_types[strtolower($filename)] = new $className();
         }
         ksort($this->_types);
     }
     return $this->_types;
 }
Example #4
0
 public function afterDelete()
 {
     // Delete main file
     $clean = Ajde_Fs_Find::findFiles($this->uploadDirectory, $this->pointer);
     // Delete thumbnail file
     $clean = array_merge($clean, Ajde_Fs_Find::findFiles($this->uploadDirectory, $this->thumbnail));
     // Delete thumbs of main file
     $clean = array_merge($clean, Ajde_Fs_Find::findFiles($this->uploadDirectory . Ajde_Resource_Image::$_thumbDir . DS, pathinfo($this->pointer, PATHINFO_FILENAME) . '_*x*.' . pathinfo($this->pointer, PATHINFO_EXTENSION)));
     // Delete thumbs of thumbnail file
     $clean = array_merge($clean, Ajde_Fs_Find::findFiles($this->uploadDirectory . Ajde_Resource_Image::$_thumbDir . DS, pathinfo($this->thumbnail, PATHINFO_FILENAME) . '_*x*.' . pathinfo($this->thumbnail, PATHINFO_EXTENSION)));
     foreach (array_unique($clean) as $path) {
         unlink($path);
     }
 }
Example #5
0
 public function getCacheStatus()
 {
     $hash = $this->getHash();
     $fileTimePattern = $hash['fileName'] . '.' . $hash['fileTime'] . '.' . $this->getType();
     if ($fileName = Ajde_Fs_Find::findFile($this->getBase(), $fileTimePattern)) {
         return ['status' => self::CACHE_STATUS_EXIST, 'fileName' => $fileName];
     }
     $fileNamePattern = $hash['fileName'] . '.*.' . $this->getType();
     if ($fileName = Ajde_Fs_Find::findFile($this->getBase(), $fileNamePattern)) {
         return ['status' => self::CACHE_STATUS_UPDATE, 'fileName' => $fileName];
     }
     return ['status' => self::CACHE_STATUS_NOT_EXIST, 'fileName' => ''];
 }
Example #6
0
File: Db.php Project: nabble/ajde
 private function installFromVersion($version = 'v0')
 {
     $sqlFiles = Ajde_Fs_Find::findFiles(DEV_DIR . 'db' . DIRECTORY_SEPARATOR, 'v*.sql');
     usort($sqlFiles, [$this, 'versionSort']);
     foreach ($sqlFiles as $sqlFile) {
         $sqlFileVersion = pathinfo($sqlFile, PATHINFO_FILENAME);
         if (version_compare($sqlFileVersion, $version) > 0) {
             $this->executeFile($sqlFile);
         }
     }
 }
Example #7
0
File: Lang.php Project: nabble/ajde
 public function getAvailableNiceNames()
 {
     $langs = Ajde_Fs_Find::findFiles(LANG_DIR, '*');
     $return = [];
     foreach ($langs as $lang) {
         $lang = basename($lang);
         $return[$lang] = $this->getNiceName($lang);
     }
     return $return;
 }
Example #8
0
 public function doCleanthumbs()
 {
     $toBeCleaned = Ajde_Fs_Find::findFilenames(UPLOAD_DIR . Ajde_Resource_Image::$_thumbDir . DIRECTORY_SEPARATOR, '*.*');
     foreach ($toBeCleaned as $file) {
         unlink(LOCAL_ROOT . UPLOAD_DIR . Ajde_Resource_Image::$_thumbDir . DIRECTORY_SEPARATOR . $file);
     }
     Ajde_Session_Flash::alert('Thumbnails will be refreshed next time they are loaded');
     return $this->redirect(Ajde_Http_Response::REDIRECT_REFFERER);
 }