/**
  * Find all defined callbacks in the app or other plugins
  *
  * @param undefined $cached
  * @return void
  * @access public
  */
 public function load()
 {
     $cached = Cache::read('_plugin_callbacks_', '_cake_models_');
     if ($cached !== false) {
         $this->settings = $cached;
         return $cached;
     }
     App::import('Folder');
     $Folder = new Folder($this->path . 'plugins');
     $folders = current($Folder->ls());
     $files = array();
     foreach ($folders as $folder) {
         if ($Folder->cd($this->path . 'models' . DS . 'callbacks')) {
             $files = $Folder->findRecursive('([a-z_]+)_' . $folder . '.php');
         }
         $files = array_flip($files);
         foreach ($folders as $_folder) {
             if ($Folder->cd($this->path . 'plugins' . DS . $_folder . DS . 'models' . DS . 'callbacks')) {
                 $files = array_merge($files, array_flip($Folder->findRecursive('([a-z_]+)_' . $folder . '.php')));
             }
         }
         foreach (array_keys($files) as $k => $file) {
             if (!preg_match_all('/models\\/callbacks\\/([a-z_]+)_' . $folder . '\\.php/i', $file, $matches)) {
                 continue;
             }
             $plugin = current($matches[1]);
             if (empty($plugin)) {
                 $plugin = 'app';
             }
             $callbackName = Inflector::camelize(sprintf('%s_%s', $plugin, $folder));
             $this->settings[$folder][$plugin] = $callbackName;
         }
     }
     Cache::write('_plugin_callbacks_', $this->settings, '_cake_models_');
 }
Example #2
0
 /**
  * The main method: where things happen
  * 
  * @access public
  */
 function main()
 {
     if (isset($this->params['quiet'])) {
         $this->quiet = true;
     }
     $tmp = new Folder(TMP);
     $folders = reset($tmp->read());
     // read only directories (array[0])
     foreach ($folders as $folder) {
         $tmp->cd(TMP);
         $tmp->cd($folder);
         $files = end($tmp->read());
         // read only files (array[1])
         if (in_array('last_interaction', $files)) {
             $file_interaction = (int) file_get_contents($tmp->pwd() . DS . 'last_interaction');
             // as each piece is 1Mb, this will give the user the chance of uploading at 13,7 kbps (1,7 kb/s)
             if (time() - $file_interaction > 600) {
                 $this->out("Removing {$folder}");
                 foreach ($files as $file) {
                     unlink($tmp->pwd() . DS . $file);
                 }
                 $tmp->delete();
             }
         }
     }
 }
 function getJobs()
 {
     App::import('Core', 'Folder');
     $Folder = new Folder();
     $jobs = array();
     if ($Folder->cd(APP . 'vendors' . DS . 'shells' . DS . 'jobs' . DS)) {
         $x = $Folder->read(true, true, true);
         $jobs = array_merge($jobs, $x[1]);
     }
     if ($Folder->cd(VENDORS . DS . 'shells' . DS . 'jobs' . DS)) {
         $x = $Folder->read(true, true, true);
         $jobs = array_merge($jobs, $x[1]);
     }
     return $jobs;
 }
Example #4
0
 /**
  * Loads all available event handler classes for enabled plugins
  *
  */
 private function __loadEventHandlers()
 {
     $this->__eventHandlerCache = Cache::read('event_handlers', 'core');
     if (empty($this->__eventHandlerCache)) {
         App::import('Core', 'Folder');
         $folder = new Folder();
         $pluginsPaths = App::path('plugins');
         foreach ($pluginsPaths as $pluginsPath) {
             $folder->cd($pluginsPath);
             $plugins = $folder->read();
             $plugins = $plugins[0];
             if (count($plugins)) {
                 foreach ($plugins as $pluginName) {
                     $filename = $pluginsPath . $pluginName . DS . $pluginName . '_events.php';
                     $className = Inflector::camelize($pluginName . '_events');
                     if (file_exists($filename)) {
                         if (EventCore::__loadEventClass($className, $filename)) {
                             EventCore::__getAvailableHandlers($this->__eventClasses[$className]);
                         }
                     }
                 }
             }
         }
         Cache::write('event_handlers', $this->__eventHandlerCache, 'core');
     }
 }
Example #5
0
 /**
  * Recursive Read a path and return files and folders not in the excluded Folder list
  *
  * @param string $path The path you wish to read.
  * @return array
  **/
 public function fileList($path)
 {
     $this->_Folder->cd($path);
     $filePattern = $this->fileRegExp . '\\.' . implode('|', $this->allowedExtensions);
     $contents = $this->_Folder->findRecursive($filePattern);
     $this->_filterFolders($contents);
     $this->_filterFiles($contents);
     return $contents;
 }
 /**
  * createTemporaryFolder
  *
  * @param string $folderName temporary middle name
  * @return Folder
  */
 public function createTemporaryFolder($controller, $folderName = 'download')
 {
     $folder = new Folder();
     if (!$folder) {
         throw new Exception(__d('net_commons', 'can not create folder'));
     }
     $folderName = TMP . $controller->plugin . DS . $folderName . DS . microtime(true);
     $folder->create($folderName);
     if (!$folder->cd($folderName)) {
         throw new Exception(__d('net_commons', 'can not change folder'));
     }
     $this->_workingFolder = $folder;
     return $folder;
 }
Example #7
0
 function run()
 {
     $return = array();
     $paths = array(CACHE . 'models', CACHE . 'persistent', CACHE . 'views');
     $folder = new Folder();
     foreach ($paths as $path) {
         $folder->cd($path);
         $files = $folder->read();
         foreach ($files[1] as $file) {
             if ($file == 'empty') {
                 continue;
             }
             $return[] = $path . DS . $file;
             unlink($path . DS . $file);
         }
     }
     return $return;
 }
Example #8
0
 /**
  * Чистка хранилища по условию
  *
  * @param array $conditions условие
  *
  * @return bool
  */
 public function expire($conditions = [])
 {
     $dir = $this->_config['dir'] . DS;
     // обрабатываем директории для логов
     // переходив в нужную директорию
     chdir($dir);
     $entries = scandir($dir);
     \App::uses('Folder', 'Utility');
     $Dir = new \Folder();
     $Dir->cd($dir);
     foreach ($entries as $entry) {
         if (!is_dir($entry) || in_array($entry, ['.', '..']) || !is_writable($entry)) {
             continue;
         }
         if (strtotime($entry) < strtotime($conditions)) {
             $Dir->delete($entry);
         }
     }
     return true;
 }
Example #9
0
File: Mwb.php Project: asper/mwb
 public function listFiles()
 {
     $paths = array('app' => APP . 'Config' . DS . 'Schema' . DS);
     $plugins = App::objects('plugin');
     CakePlugin::loadAll();
     foreach ($plugins as $plugin) {
         $paths[$plugin] = App::pluginPath($plugin) . 'Config' . DS . 'Schema' . DS;
     }
     $fileList = array();
     $folder = new Folder();
     foreach ($paths as $plugin => $path) {
         if ($folder->cd($path)) {
             $files = $folder->find('.*\\.mwb');
             if (!empty($files)) {
                 foreach ($files as $file) {
                     $pathinfo = pathinfo($file);
                     $fileList[] = array('name' => $plugin . '/' . $pathinfo['filename']);
                 }
             }
         }
     }
     return $fileList;
 }
 /**
  * testNoTestCaseSupplied method
  *
  * @access public
  * @return void
  */
 function testNoTestCaseSupplied()
 {
     if (php_sapi_name() != 'cli') {
         unset($_GET['group']);
         CodeCoverageManager::start(substr(md5(microtime()), 0, 5), new CakeHtmlReporter());
         CodeCoverageManager::report(false);
         $this->assertError();
         CodeCoverageManager::start('libs/' . basename(__FILE__), new CakeHtmlReporter());
         CodeCoverageManager::report(false);
         $this->assertError();
         $path = LIBS;
         if (strpos(LIBS, ROOT) === false) {
             $path = ROOT . DS . LIBS;
         }
         App::import('Core', 'Folder');
         $folder = new Folder();
         $folder->cd($path);
         $contents = $folder->ls();
         /**
          * remove method
          *
          * @param mixed $var
          * @access public
          * @return void
          */
         function remove($var)
         {
             return $var != basename(__FILE__);
         }
         $contents[1] = array_filter($contents[1], "remove");
         foreach ($contents[1] as $file) {
             CodeCoverageManager::start('libs' . DS . $file, new CakeHtmlReporter());
             CodeCoverageManager::report(false);
             $this->assertNoErrors('libs' . DS . $file);
         }
     }
 }
 /**
  * Test that test cases don't cause errors
  *
  * @return void
  */
 function testNoTestCaseSuppliedNoErrors()
 {
     if ($this->skipIf(PHP_SAPI == 'cli', 'Is cli, cannot run this test %s')) {
         return;
     }
     $reporter =& new CakeHtmlReporter(null, array('group' => false, 'app' => false, 'plugin' => false));
     $path = LIBS;
     if (strpos(LIBS, ROOT) === false) {
         $path = ROOT . DS . LIBS;
     }
     App::import('Core', 'Folder');
     $folder = new Folder();
     $folder->cd($path);
     $contents = $folder->read();
     $contents[1] = array_filter($contents[1], array(&$this, '_basenameFilter'));
     foreach ($contents[1] as $file) {
         CodeCoverageManager::init('libs' . DS . $file, $reporter);
         CodeCoverageManager::report(false);
         $this->assertNoErrors('libs' . DS . $file);
     }
 }
 public function get_all_app_controllers()
 {
     $controllers = array();
     App::uses('Folder', 'Utility');
     $folder = new Folder();
     $didCD = $folder->cd(APP . 'Controller');
     if (!empty($didCD)) {
         $files = $folder->findRecursive('.*Controller\\.php');
         foreach ($files as $fileName) {
             $file = basename($fileName);
             // Get the controller name
             //$controller_class_name = Inflector::camelize(substr($file, 0, strlen($file) - strlen('Controller.php')));
             $controller_class_name = Inflector::camelize(substr($file, 0, strlen($file) - strlen('.php')));
             App::uses($controller_class_name, 'Controller');
             $controllers[] = array('file' => $fileName, 'name' => substr($controller_class_name, 0, strlen($controller_class_name) - strlen('Controller')));
         }
     }
     sort($controllers);
     return $controllers;
 }
 function __loadDbItems()
 {
     // variable used to determine the read dir time
     $acdate = strtotime("now");
     // check to see whether a valid directory was passed to the script
     if ($this->Session->read('User.dirname_get')) {
         // if it is valid, we'll set it as the directory to read data from
         $this->dirpath = $this->Session->read('User.dirname_get');
     } else {
         // if it is invalid, we'll use the default directory
         $this->dirpath = Configure::read('default_get_dir');
     }
     // use Folder class
     $dir = new Folder($this->dirpath);
     // try to change the current working directory to the one from wich i want to read contents from
     if (!$dir->cd($this->dirpath)) {
         // if the change failed, I'll use the default directory
         $this->dirpath = Configure::read('default_get_dir');
         $dir->cd(Configure::read('default_get_dir'));
     }
     // once the current working directory is set, it is opened and read from
     $dir_listing = $dir->read(true, false, true);
     if ($dir_listing) {
         // while there are still entries
         foreach ($dir_listing[1] as $entry) {
             // if the entry is to be shown (not part of the 'not_to_be_shown' array)
             if (!in_array($entry, Configure::read('not_to_be_shown'))) {
                 $file = new File($entry);
                 if ($file->readable()) {
                     // store the file extension
                     $fext = $file->ext();
                     // store the filename
                     $fname = $file->name;
                     // store the lowercased extension
                     $lfext = strtolower($fext);
                     // store size of file into KB
                     $fsize = round($file->size() / 1024, 2);
                     // store date of file
                     $fidate = $file->lastChange();
                     // store dirpath with file
                     $finfokey = $entry;
                     // store absfilename
                     $fnameabs = $file->name();
                     // define check for filestatus_status (if updated)
                     $update_status = Configure::read('msg_items_file_unselected');
                     // check table fileinfo for update or insert
                     $file_info = $this->FileInfo->find('first', array('conditions' => array('fileinfo_id' => $finfokey), 'fields' => array('fileinfo_id', 'fileinfo_filedate')));
                     if (!empty($file_info)) {
                         $this->FileInfo->read(null, $file_info['FileInfo']['fileinfo_id']);
                         $this->FileInfo->set(array('fileinfo_dirname' => $this->dirpath, 'fileinfo_filename' => $fname, 'fileinfo_absfilename' => $fnameabs, 'fileinfo_ext' => $lfext, 'fileinfo_size' => $fsize, 'fileinfo_filedate' => $fidate, 'fileinfo_timenow' => $acdate));
                         $this->FileInfo->save();
                         // check data modified file is changed
                         if ($fidate > $file_info['FileInfo']['fileinfo_filedate']) {
                             $update_status = Configure::read('msg_items_file_updated');
                         }
                     } else {
                         $this->FileInfo->create();
                         $this->FileInfo->set(array('fileinfo_id' => $finfokey, 'fileinfo_dirname' => $this->dirpath, 'fileinfo_filename' => $fname, 'fileinfo_absfilename' => $fnameabs, 'fileinfo_ext' => $lfext, 'fileinfo_size' => $fsize, 'fileinfo_filedate' => $fidate, 'fileinfo_timenow' => $acdate));
                         $this->FileInfo->save();
                     }
                     // check table filestatus for update or insert
                     $file_status = $this->FileStatus->find('first', array('conditions' => array('filestatus_fileinfo_key' => $finfokey, 'filestatus_users_id' => $this->Session->read('User.id')), 'fields' => array('filestatus_id', 'filestatus_status')));
                     if (!empty($file_status)) {
                         if ($file_status['FileStatus']['filestatus_status'] == Configure::read('msg_items_file_selected') && $update_status != Configure::read('msg_items_file_updated')) {
                             $update_status = Configure::read('msg_items_file_selected');
                         }
                         $this->FileStatus->read(null, $file_status['FileStatus']['filestatus_id']);
                         $this->FileStatus->set(array('filestatus_status' => $update_status, 'filestatus_users_id' => $this->Session->read('User.id'), 'filestatus_timenow' => $acdate));
                         $this->FileStatus->save();
                     } else {
                         $this->FileStatus->create();
                         $this->FileStatus->set(array('filestatus_fileinfo_key' => $finfokey, 'filestatus_status' => $update_status, 'filestatus_users_id' => $this->Session->read('User.id'), 'filestatus_timenow' => $acdate));
                         $this->FileStatus->save();
                     }
                 }
             }
         }
         // check consistency : delete from db files that's removed from directory
         $file_info_del = $this->FileInfo->deleteAll(array('fileinfo_timenow < ' => $acdate));
         if (!$file_info_del) {
             $this->log('DownloadsController:__loadDbItems - Unable delete FileInfo model record', Configure::read('log_file'));
         }
         // check consistency : delete from db files that's removed from directory
         $file_status_del = $this->FileStatus->deleteAll(array('filestatus_timenow < ' => $acdate, 'filestatus_users_id' => $this->Session->read('User.id')));
         if (!$file_status_del) {
             $this->log('DownloadsController:__loadDbItems - Unable delete FileStatus model record', Configure::read('log_file'));
         }
     }
 }
 /**
  * Checks to see if the temporary plugin folder exists
  * and creates it if it does not
  *
  * @return void
  * @author Jose Diaz-Gonzalez
  **/
 function __checkPluginFolder()
 {
     $tempHandler = new Folder();
     $tempPath = trim(TMP);
     $pluginPath = trim(TMP . 'plugins');
     $tempHandler->cd($tempPath);
     $temp = $tempHandler->ls();
     foreach ($temp[0] as $tempFolder) {
         if ($tempFolder !== 'plugins') {
             $tempHandler->create($pluginPath);
         }
     }
 }
Example #15
0
 /**
  * Creates thumbnail folders if they do not already exist
  *
  * @param string $dir Path to uploads
  * @param array $thumbsizes List of names of thumbnail type
  * @return void
  * @access protected
  */
 function _createFolders($dir, $thumbsizes)
 {
     if ($dir[0] !== '/') {
         $dir = WWW_ROOT . $dir;
     }
     $folder = new Folder();
     if (!$folder->cd($dir)) {
         $folder->create($dir);
     }
     if (!$folder->cd($dir . DS . 'thumb')) {
         $folder->create($dir . DS . 'thumb');
     }
     foreach ($thumbsizes as $thumbName) {
         if (!$folder->cd($dir . DS . 'thumb' . DS . $thumbName)) {
             $folder->create($dir . DS . 'thumb' . DS . $thumbName);
         }
     }
 }
 /**
  * Move temporary upload to destination
  *
  * @param array $tmpUpload
  * @param string $dest Filepath to destination
  * @throws AttachableUploadException
  */
 protected function _store(Model &$model, $tmpUpload, $config)
 {
     //create subfolders if needed
     $path = $this->_getBasePath($model, $config);
     $Folder = new Folder($path, true);
     if (!$Folder->cd($path)) {
         throw new AttachableUploadException(self::UPLOAD_ERR_STORE_UPLOAD);
     }
     unset($Folder);
     //build filename
     list($filename, $ext, $dotExt) = self::splitBasename($tmpUpload['name']);
     if (isset($model->data[$model->alias][$config['uploadNameField']]) && !empty($model->data[$model->alias][$config['uploadNameField']])) {
         //TODO validate filename
         $filename = trim($model->data[$model->alias][$config['uploadNameField']]);
     }
     if ($config['hashFilename']) {
         $filename = sha1($filename);
     } elseif ($config['slug']) {
         $filename = Inflector::slug($filename, $config['slug']);
     }
     $basename = $filename . $dotExt;
     //build targetname
     $targetPath = $path . $basename;
     if (file_exists($targetPath) && $config['allowOverwrite'] == false) {
         $i = 0;
         $_filename = $filename;
         do {
             $filename = $_filename . '_' . ++$i;
             $basename = $filename . $dotExt;
             $targetPath = $path . $basename;
         } while (file_exists($targetPath) == true);
     }
     //move temporary file
     $TmpFile = new File($tmpUpload['tmp_name'], false);
     $File = new File($targetPath, true);
     if (!$File->write($TmpFile->read())) {
         throw new AttachableUploadException(self::UPLOAD_ERR_STORE_UPLOAD);
     }
     $File->close();
     if (!$TmpFile->delete()) {
         $this->log(__('Failed to delete temporary upload file %s', basename($tmpUpload['tmp_name'])));
     }
     //attachment data
     $attachment = array('path' => $targetPath, 'basename' => $basename, 'filename' => $filename, 'ext' => $ext);
     //TODO trigger event 'afterStore'. Use for creating preview
     $attachment = $this->_attachPreview($attachment, $config);
     return $attachment;
 }
 /**
  * Creates thumbnail folders if they do not already exist
  *
  * @param string $dir Path to uploads
  * @param string $thumbDir Path to thumbnails
  * @param array $thumbsizes
  * @param integer $folderPermission octal value of created folder permission
  * @return void
  * @access protected
  */
 function _createFolders($dir, $thumbDir, $thumbsizes, $folderPermission)
 {
     if ($dir[0] !== '/') {
         $dir = WWW_ROOT . $dir;
     }
     $folder = new Folder();
     if (!$folder->cd($dir)) {
         $folder->create($dir, $folderPermission);
     }
     if (!$folder->cd($dir . DS . $thumbDir)) {
         $folder->create($dir . DS . $thumbDir, $folderPermission);
     }
     foreach ($thumbsizes as $thumbsize) {
         if ($thumbsize != 'normal' && !$folder->cd($dir . DS . $thumbDir . DS . $thumbsize)) {
             $folder->create($dir . DS . $thumbDir . DS . $thumbsize, $folderPermission);
         }
     }
 }
Example #18
0
 function process($type, $data)
 {
     switch ($type) {
         case 'js':
             $path = JS;
             break;
         case 'css':
             $path = CSS;
             break;
     }
     $folder = new Folder();
     //make sure the cache folder exists
     if ($folder->create($path . $this->cachePath, "777")) {
         /* trigger_error('Could not create ' . $path . $this->cachePath
            . '. Please create it manually with 777 permissions', E_USER_WARNING);*/
     }
     //check if the cached file exists
     $names = Set::extract($data, '{n}.name');
     $folder->cd($path . $this->cachePath);
     $fileName = $folder->find($this->__generateFileName($names) . '_([0-9]{10}).' . $type);
     if ($fileName) {
         //take the first file...really should only be one.
         $fileName = $fileName[0];
     }
     //make sure all the pieces that went into the packed script
     //are OLDER then the packed version
     if ($this->checkTS && $fileName) {
         $packed_ts = filemtime($path . $this->cachePath . $fileName);
         $latest_ts = 0;
         $scripts = Set::extract($data, '{n}.script');
         foreach ($scripts as $script) {
             $latest_ts = max($latest_ts, filemtime($path . $script . '.' . $type));
         }
         //an original file is newer.  need to rebuild
         if ($latest_ts > $packed_ts) {
             unlink($path . $this->cachePath . $fileName);
             $fileName = null;
         }
     }
     //file doesn't exist.  create it.
     if (!$fileName) {
         $ts = time();
         //merge the script
         $scriptBuffer = '';
         $scripts = Set::extract($data, '{n}.script');
         foreach ($scripts as $script) {
             $buffer = file_get_contents($path . $script . '.' . $type);
             switch ($type) {
                 case 'js':
                     //jsmin only works with PHP5
                     if (PHP5) {
                         App::import('Vendor', 'jsmin/jsmin');
                         $buffer = trim(JSMin::minify($buffer));
                     }
                     break;
                 case 'css':
                     vendor('csstidy/class.csstidy');
                     $tidy = new csstidy();
                     $tidy->load_template($this->cssCompression);
                     $tidy->parse($buffer);
                     $buffer = $tidy->print->plain();
                     break;
             }
             $scriptBuffer .= "\n/* {$script}.{$type} */\n" . $buffer;
         }
         //write the file
         $fileName = $this->__generateFileName($names) . '_' . $ts . '.' . $type;
         $file = new File($path . $this->cachePath . $fileName);
         $file->write(trim($scriptBuffer));
     }
     if ($type == 'css') {
         //$html->css doesn't check if the file already has
         //the .css extension and adds it automatically, so we need to remove it.
         $fileName = str_replace('.css', '', $fileName);
     }
     return $fileName;
 }
 /**
  * Returns the name of the test object file based on a given test case file name
  *
  * @param string $file
  * @param string $isApp
  * @return string name of the test object file
  * @access private
  */
 function __testObjectFileFromCaseFile($file, $isApp = true)
 {
     $manager = CodeCoverageManager::getInstance();
     $path = $manager->__getTestFilesPath($isApp);
     $folderPrefixMap = array('behaviors' => 'models', 'components' => 'controllers', 'helpers' => 'views');
     foreach ($folderPrefixMap as $dir => $prefix) {
         if (strpos($file, $dir) === 0) {
             $path .= $prefix . DS;
             break;
         }
     }
     $testManager = new TestManager();
     $testFile = str_replace(array('/', $testManager->_testExtension), array(DS, '.php'), $file);
     $folder = new Folder();
     $folder->cd(ROOT . DS . CAKE_TESTS_LIB);
     $contents = $folder->read();
     if (in_array(basename($testFile), $contents[1])) {
         $testFile = basename($testFile);
         $path = ROOT . DS . CAKE_TESTS_LIB;
     }
     $path .= $testFile;
     $realpath = realpath($path);
     if ($realpath) {
         return $realpath;
     }
     return $path;
 }
Example #20
0
 /**
  * testDirSize method
  *
  * @return void
  */
 public function testDirSize()
 {
     $Folder = new Folder(TMP . 'config_non_existent', true);
     $this->assertEquals(0, $Folder->dirSize());
     $File = new File($Folder->pwd() . DS . 'my.php', true, 0777);
     $File->create();
     $File->write('something here');
     $File->close();
     $this->assertEquals(14, $Folder->dirSize());
     $Folder->cd(TMP);
     $Folder->delete($Folder->pwd() . 'config_non_existent');
 }
 /**
  * Callback
  *
  * Deletes file corresponding to record as well as generated versions of that file.
  *
  * If the file couldn't be deleted the callback won't stop the
  * delete operation to continue to delete the record.
  *
  * @param Model $Model
  * @param boolean $cascade
  * @return boolean
  */
 function beforeDelete(&$Model, $cascade = true)
 {
     extract($this->settings[$Model->alias]);
     $query = array('conditions' => array('id' => $Model->id), 'fields' => array('dirname', 'basename'), 'recursive' => -1);
     $result = $Model->find('first', $query);
     if (empty($result)) {
         return false;
         /* Record did not pass verification? */
     }
     $file = $baseDirectory;
     $file .= $result[$Model->alias]['dirname'];
     $file .= DS . $result[$Model->alias]['basename'];
     $File = new File($file);
     $Folder = new Folder($filterDirectory);
     list($versions, ) = $Folder->ls();
     foreach ($versions as $version) {
         $Folder->cd($filterDirectory . $version . DS . $result[$Model->alias]['dirname'] . DS);
         $basenames = $Folder->find($File->name() . '\\..*');
         if (count($basenames) > 1) {
             $message = "MediaBehavior::beforeDelete - Ambiguous filename ";
             $message .= "`" . $File->name() . "` in `" . $Folder->pwd() . "`.";
             trigger_error($message, E_USER_NOTICE);
             continue;
         } elseif (!isset($basenames[0])) {
             continue;
         }
         $FilterFile = new File($Folder->pwd() . $basenames[0]);
         $FilterFile->delete();
     }
     $File->delete();
     return true;
 }
Example #22
0
 function testCreateFolders()
 {
     if ($this->skipIf(is_dir(WWW_ROOT . 'test'), 'Directory "test" in webroot exists.')) {
         return;
     }
     $this->MeioUpload->_createFolders('test', array('a', 'b', 'c'));
     $this->assertTrue(is_dir(WWW_ROOT . 'test'));
     $this->assertTrue(is_dir(WWW_ROOT . 'test' . DS . 'thumb' . DS . 'a'));
     $this->assertTrue(is_dir(WWW_ROOT . 'test' . DS . 'thumb' . DS . 'b'));
     $this->assertTrue(is_dir(WWW_ROOT . 'test' . DS . 'thumb' . DS . 'c'));
     $this->assertFalse(is_dir(WWW_ROOT . 'test' . DS . 'thumb' . DS . 'd'));
     $folder = new Folder();
     $folder->cd(WWW_ROOT . 'test');
     $folder->delete();
 }
Example #23
0
 /**
  * Get the names of the plugin controllers ...
  *
  * This function will get an array of the plugin controller names, and
  * also makes sure the controllers are available for us to get the
  * method names by doing an App::import for each plugin controller.
  *
  * @return array of plugin names.
  */
 function _getPluginControllerNames()
 {
     App::import('Core', 'File', 'Folder');
     $paths = Configure::getInstance();
     $folder = new Folder();
     $folder->cd(APP . 'plugins');
     // Get the list of plugins
     $Plugins = $folder->read();
     $Plugins = $Plugins[0];
     $arr = array();
     // Loop through the plugins
     foreach ($Plugins as $pluginName) {
         // Change directory to the plugin
         $didCD = $folder->cd(APP . 'plugins' . DS . $pluginName . DS . 'controllers');
         if (!$didCD) {
             continue;
         }
         // Get a list of the files that have a file name that ends
         // with controller.php
         $files = $folder->findRecursive('.*_controller\\.php');
         // Loop through the controllers we found in the plugins directory
         foreach ($files as $fileName) {
             // Get the base file name
             $file = basename($fileName);
             // Get the controller name
             $file = Inflector::camelize(substr($file, 0, strlen($file) - strlen('_controller.php')));
             if (!preg_match('/^' . Inflector::humanize($pluginName) . 'App/', $file)) {
                 if (!App::import('Controller', $pluginName . '.' . $file)) {
                     trigger_error(__('Error importing ', true) . $file . __(' for plugin ', true) . $pluginName);
                 } else {
                     /// Now prepend the Plugin name ...
                     // This is required to allow us to fetch the method names.
                     $arr[] = Inflector::humanize($pluginName) . "/" . $file;
                 }
             }
         }
     }
     return $arr;
 }