/** * undocumented function * * @return void */ function main() { $choice = ''; $Tasks = new Folder(dirname(__FILE__) . DS . 'tasks'); list($folders, $files) = $Tasks->read(); $i = 1; $choices = array(); foreach ($files as $file) { if (preg_match('/upgrade_/', $file)) { $choices[$i] = basename($file, '.php'); $this->out($i++ . '. ' . basename($file, '.php')); } } while ($choice == '') { $choice = $this->in("Enter a number from the list above, or 'q' to exit", null, 'q'); if ($choice === 'q') { $this->out("Exit"); $this->_stop(); } if ($choice == '' || intval($choice) > count($choices)) { $this->err("The number you selected was not an option. Please try again."); $choice = ''; } } if (intval($choice) > 0 && intval($choice) <= count($choices)) { $upgrade = Inflector::classify($choices[intval($choice)]); } $this->tasks = array($upgrade); $this->loadTasks(); return $this->{$upgrade}->execute(); }
/** * tearDown method * * @return void */ public function tearDown() { parent::tearDown(); $Folder = new Folder($this->Task->path . 'bake_test_app'); $Folder->delete(); unset($this->Task); }
/** * Performs the initial git-svn clone of plugins. * * This shell grabs plugins that require their initial clone in the order * they were requested, and clones them from the WordPress SVN repository. * * If unspecified, a maximum of 5 plugins will be cloned with one run. * * @return int Shell return code. */ function main() { $max = 5; if (isset($this->args[0]) && is_numeric($this->args[0]) && $this->args[0] > 0) { $max = (int) $this->args[0]; } $plugins = $this->Plugin->findByState('cloning', array('contain' => array('PluginsState' => array('State')), 'order' => array('InnerPluginsState.modified'), 'limit' => $max)); if (count($plugins) == 0) { $this->out(__('<info>No plugins need to be cloned.</info>')); $this->_unlock(); return 0; } $this->out(__('Cloning %d plugins...', count($plugins))); $dir = new Folder(TMP . 'git', true, 0755); $error = implode(', ', $dir->errors()); if (!empty($error)) { $this->_unlock(); $this->error(__('Filesystem Error'), __('Failed to create git clone directory: %s', $error)); } $dir = new Folder(TMP . 'logs' . DS . 'git', true, 0755); $error = implode(', ', $dir->errors()); if (!empty($error)) { $this->_unlock(); $this->error(__('Filesystem Error'), __('Failed to create git logs directory: %s', $error)); } foreach ($plugins as $plugin) { $this->out(__('Cloning: "%s" (%d)', $plugin['Plugin']['slug'], $plugin['Plugin']['id'])); $svn_url = sprintf(Configure::read('App.plugin_svn_url'), $plugin['Plugin']['slug']); $git_path = sprintf(Configure::read('App.plugin_repo_path'), $plugin['Plugin']['slug']); $log_path = TMP . 'logs' . DS . 'git' . DS . $plugin['Plugin']['slug'] . '.log'; // Clear out any existing git-svn clone attempt that failed before. $git_dir = new Folder($git_path); $git_dir->delete(); try { $this->_exec('git svn clone -qq --prefix=svn/ -s %s %s >> %s 2>&1', $svn_url, $git_path, $log_path); } catch (RuntimeException $e) { $this->out(__('<warning>Failed to clone "%s", please check the git log file.</warning>', $plugin['Plugin']['slug'])); $this->PluginsState->touch($plugin['InnerPluginsState']['id']); continue; } if (!$this->_createGithubRepo($plugin['Plugin']['slug'])) { $this->PluginsState->touch($plugin['InnerPluginsState']['id']); continue; } if (!$this->PluginsState->findOrCreate($plugin['Plugin']['id'], 'cloned') || !$this->PluginsState->findOrCreate($plugin['Plugin']['id'], 'updating')) { $this->out(__('<warning>Failed marking plugin as cloned.</warning>')); // Even though this plugin cloned successfully, if we can't // mark it as cloned, we don't want it to slip into limbo, so // we'll let it attempt to do the full clone all over again. $this->PluginsState->touch($plugin['InnerPluginsState']['id']); continue; } if (!$this->PluginsState->delete($plugin['InnerPluginsState']['id'])) { $this->out(__('<warning>Failed removing "cloning" state on cloned plugin.</warning>')); } } $this->out(__('<info>Finished cloning plugins.</info>')); $this->_unlock(); return 0; }
/** * Overwrite shell initialize to dynamically load all Queue Related Tasks. * * @return void */ public function initialize() { $paths = App::path('Console/Command/Task'); foreach ($paths as $path) { $Folder = new Folder($path); $res = array_merge($this->tasks, $Folder->find('Queue.*\\.php')); foreach ($res as &$r) { $r = basename($r, 'Task.php'); } $this->tasks = $res; } $plugins = CakePlugin::loaded(); foreach ($plugins as $plugin) { $pluginPaths = App::path('Console/Command/Task', $plugin); foreach ($pluginPaths as $pluginPath) { $Folder = new Folder($pluginPath); $res = $Folder->find('Queue.*Task\\.php'); foreach ($res as &$r) { $r = $plugin . '.' . basename($r, 'Task.php'); } $this->tasks = array_merge($this->tasks, $res); } } parent::initialize(); $this->QueuedTask->initConfig(); }
public function main() { $App = new Folder(APP); $r = $App->findRecursive('.*\\.php'); $this->out("Checking *.php in " . APP); $folders = array(); foreach ($r as $file) { $error = ''; $action = ''; $c = file_get_contents($file); if (preg_match('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', $c)) { $error = 'leading'; } if (preg_match('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', $c)) { $error = 'trailing'; } if (!empty($error)) { $this->report[$error][0]++; $this->out(''); $this->out('contains ' . $error . ' whitespaces: ' . $this->shortPath($file)); if (!$this->autoCorrectAll) { $dirname = dirname($file); if (in_array($dirname, $folders)) { $action = 'y'; } while (empty($action)) { //TODO: [r]! $action = $this->in(__('Remove? [y]/[n], [a] for all in this folder, [r] for all below, [*] for all files(!), [q] to quit'), array('y', 'n', 'r', 'a', 'q', '*'), 'q'); } } else { $action = 'y'; } if ($action == '*') { $action = 'y'; $this->autoCorrectAll = true; } elseif ($action == 'a') { $action = 'y'; $folders[] = $dirname; $this->out('All: ' . $dirname); } if ($action == 'q') { die('Abort... Done'); } elseif ($action == 'y') { if ($error == 'leading') { $res = preg_replace('/^[\\n\\r|\\n\\r|\\n|\\r|\\s]+\\<\\?php/', '<?php', $c); } else { //trailing $res = preg_replace('/\\?\\>[\\n\\r|\\n\\r|\\n|\\r|\\s]+$/', '?>', $c); } file_put_contents($file, $res); $this->report[$error][1]++; $this->out('fixed ' . $error . ' whitespaces: ' . $this->shortPath($file)); } } } # report $this->out('--------'); $this->out('found ' . $this->report['leading'][0] . ' leading, ' . $this->report['trailing'][0] . ' trailing ws'); $this->out('fixed ' . $this->report['leading'][1] . ' leading, ' . $this->report['trailing'][1] . ' trailing ws'); }
/** * tearDown method * * @return void */ public function tearDown() { unset($this->Package); $Folder = new Folder(TMP . DS . 'repos'); $Folder->delete(); parent::tearDown(); }
/** * tearDown method * * @return void */ public function tearDown() { parent::tearDown(); unset($this->Task); $Folder = new Folder($this->path); $Folder->delete(); }
public function InsertPageNumber($fileName, $alignment, $format, $isTop, $setPageNumberOnFirstPage) { try { //check whether files are set or not if ($fileName == "") { throw new Exception("File not specified"); } //Build JSON to post $fieldsArray = array('Format' => $format, 'Alignment' => $alignment, 'IsTop' => $isTop, 'SetPageNumberOnFirstPage' => $setPageNumberOnFirstPage); $json = json_encode($fieldsArray); //build URI to insert page number $strURI = Product::$BaseProductUri . "/words/" . $fileName . "/insertPageNumbers"; //sign URI $signedURI = Utils::Sign($strURI); $responseStream = Utils::processCommand($signedURI, "POST", "json", $json); $v_output = Utils::ValidateOutput($responseStream); if ($v_output === "") { //Save docs on server $folder = new Folder(); $outputStream = $folder->GetFile($fileName); $outputPath = SaasposeApp::$OutPutLocation . $fileName; Utils::saveFile($outputStream, $outputPath); return ""; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
public function render($view = null, $layout = null) { // set vars $name = $download = $extension = $id = $modified = $path = $cache = $mimeType = $compress = null; extract($this->viewVars, EXTR_OVERWRITE); $this->viewVars['thumbName'] = $thumbName = md5(json_encode($this->viewVars['params'])); $dir = new Folder(CACHE . 'thumbs', true, 0755); $files = $dir->find($this->viewVars['thumbName']); if (empty($files)) { $pos = strpos($this->viewVars['params']['image'], 'http://'); if ($pos !== FALSE) { $this->_loadExternalFile(); $this->_resizeFile(); unlink($this->viewVars['params']['image']); } else { $this->viewVars['params']['image'] = WWW_ROOT . $this->viewVars['params']['image']; $this->_resizeFile(); } } $modified = @filemtime(CACHE . 'thumbs/' . $thumbName); $pos1 = strrpos($params['image'], '.'); $id = substr($params['image'], $pos1 + 1, 8); $this->response->type($id); $this->viewVars['path'] = CACHE . 'thumbs' . DS . $thumbName; $this->viewVars['download'] = false; $this->viewVars['cache'] = '+1 day'; $this->viewVars['modified'] = '@' . $modified; // Must be a string to work. See MediaView->render() parent::render(); }
/** * Remove a pasta .git */ function _excludeGitFolder($pluginPath) { App::import('Folder'); $gitFolder = $pluginPath . DS . '.git' . DS; $folder = new Folder($gitFolder, false); $folder->delete($gitFolder); }
public function upload(Model $Model, $arquivo = array(), $altura = 800, $largura = 600, $pasta = null, $nome_arquivo) { // App::uses('Vendor', 'wideimage'); App::import('Vendor', 'WideImage', array('file' => 'WideImage' . DS . 'WideImage.php')); App::uses('Folder', 'Utility'); $ext = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/x-jps', 'image/png', 'image/gif'); if ($arquivo['error'] != 0 || $arquivo['size'] == 0) { return false; } $img = WideImage::load($arquivo['tmp_name']); $folder = new Folder(); $pathinfo = pathinfo($arquivo['name']); if ($folder->create(WWW_ROOT . 'img' . DS . $pasta . DS)) { //se conseguiu criar o diretório eu dou permissão $folder->chmod(WWW_ROOT . 'img' . DS . $pasta . DS, 0755, true); } else { return false; } $pathinfo['filename'] = strtolower(Inflector::slug($pathinfo['filename'], '-')); $arquivo['name'] = $nome_arquivo . '.' . $pathinfo['extension']; $img->saveToFile(WWW_ROOT . 'img' . DS . $pasta . DS . 'original_' . $arquivo['name']); $img = $img->resize($largura, $altura, 'fill'); $img->saveToFile(WWW_ROOT . 'img' . DS . $pasta . DS . $arquivo['name']); // debug(WWW_ROOT.'img'.DS.$pasta.DS.$arquivo['name']); die; return $arquivo['name']; }
public function DeleteChart($chartIndex) { try { //check whether file is set or not if ($this->FileName == "") { throw new Exception("No file name specified"); } //check whether workshett name is set or not if ($this->WorksheetName == "") { throw new Exception("Worksheet name not specified"); } $strURI = Product::$BaseProductUri . "/cells/" . $this->FileName . "/worksheets/" . $this->WorksheetName . "/charts/" . $chartIndex; $signedURI = Utils::Sign($strURI); $responseStream = Utils::processCommand($signedURI, "DELETE", "", ""); $v_output = Utils::ValidateOutput($responseStream); if ($v_output === "") { //Save doc on server $folder = new Folder(); $outputStream = $folder->GetFile($this->FileName); $outputPath = SaasposeApp::$OutPutLocation . $this->FileName; Utils::saveFile($outputStream, $outputPath); return ""; } else { return $v_output; } } catch (Exception $e) { throw new Exception($e->getMessage()); } }
/** * We need to test that the _versions folder isn't completed wiped by * {@link VersionedFileExtension::onBeforeDelete()} when there is more than the file currently being deleted. */ public function testOnBeforeDelete() { // Create the second file $file2 = $this->folder->getFullPath() . 'test-file2.txt'; file_put_contents($file2, 'first-version'); $file2Obj = new File(); $file2Obj->ParentID = $this->folder->ID; $file2Obj->Filename = $this->folder->getFilename() . 'test-file2.txt'; $file2Obj->write(); // Create a second version of the second file file_put_contents($file2Obj->getFullPath(), 'second-version'); $file2Obj->createVersion(); // Delete the second file $file2Obj->delete(); // Ensure the _versions folder still exists $this->assertTrue(is_dir($this->folder->getFullPath())); $this->assertTrue(is_dir($this->folder->getFullPath() . '/_versions')); // Now delete the first file, and ensure the _versions folder no longer exists $this->file->delete(); $this->assertTrue(is_dir($this->folder->getFullPath())); $this->assertFalse(is_dir($this->folder->getFullPath() . '/_versions')); // Now create another file to ensure that the _versions folder can be successfully re-created $file3 = $this->folder->getFullPath() . 'test-file3.txt'; file_put_contents($file3, 'first-version'); $file3Obj = new File(); $file3Obj->ParentID = $this->folder->ID; $file3Obj->Filename = $this->folder->getFilename() . 'test-file3.txt'; $file3Obj->write(); $this->assertTrue(is_file($file3Obj->getFullPath())); $this->assertTrue(is_dir($this->folder->getFullPath() . '/_versions')); }
public function addFolder() { $form = new Form('form-addfolder', Router::getInstance()->build('BrowserController', 'addFolder')); $fieldset = new Fieldset(System::getLanguage()->_('AddFolder')); $name = new Text('name', System::getLanguage()->_('FolderName'), true); $parent = new Select('parent', System::getLanguage()->_('ParentFolder'), Folder::getAll()); $parent->selected_value = Utils::getGET('parent', 0); $fieldset->addElements($name, $parent); $form->addElements($fieldset); if (Utils::getPOST('submit', false) !== false) { if ($form->validate()) { try { $folder = new Folder($parent->selected_value); $folder->addFolder($name->value); if ($folder->id == 0) { System::forwardToRoute(Router::getInstance()->build('BrowserController', 'index')); } else { System::forwardToRoute(Router::getInstance()->build('BrowserController', 'show', $folder->id)); } exit; } catch (InvalidFolderNameException $e) { $name->error = System::getLanguage()->_('ErrorInvalidFolderName'); } catch (FolderAlreadyExistsException $e) { $name->error = System::getLanguage()->_('ErrorFolderAlreadyExists'); } catch (Exception $e) { $name->error = System::getLanguage()->_('ErrorInvalidParameter'); } } } $form->setSubmit(new Button(System::getLanguage()->_('Create'), 'icon icon-new-folder')); $smarty = new Template(); $smarty->assign('title', System::getLanguage()->_('AddFolder')); $smarty->assign('form', $form->__toString()); $smarty->display('form.tpl'); }
/** * レイアウトテンプレートを取得 * コンボボックスのソースとして利用 * * @return array レイアウトの一覧データ */ public function getTemplates() { $templatesPathes = array(); if ($this->BcBaser->siteConfig['theme']) { $templatesPathes[] = WWW_ROOT . 'theme' . DS . $this->BcBaser->siteConfig['theme'] . DS . 'Feed' . DS; } $templatesPathes[] = BASER_PLUGINS . 'Feed' . DS . 'View' . DS . 'Feed' . DS; $_templates = array(); foreach ($templatesPathes as $templatesPath) { $folder = new Folder($templatesPath); $files = $folder->read(true, true); $foler = null; if ($files[1]) { if ($_templates) { $_templates = am($_templates, $files[1]); } else { $_templates = $files[1]; } } } $templates = array(); foreach ($_templates as $template) { $ext = Configure::read('BcApp.templateExt'); if ($template != 'ajax' . $ext && $template != 'error' . $ext) { $template = basename($template, $ext); $templates[$template] = $template; } } return $templates; }
/** * Get a unique filename within given target folder, remove uniqid() suffix from file (optional, add $strPrefix) and append file count by name to * file if file with same name already exists in target folder * * @param string $strTarget The target file path * @param string $strPrefix A uniqid prefix from the given target file, that was added to the file before and should be removed again * @param $i integer Internal counter for recursion usage or if you want to add the number to the file * * @return string | false The filename with the target folder and unique id or false if something went wrong (e.g. target does not exist) */ public static function getUniqueFileNameWithinTarget($strTarget, $strPrefix = null, $i = 0) { $objFile = new \File($strTarget, true); $strTarget = ltrim(str_replace(TL_ROOT, '', $strTarget), '/'); $strPath = str_replace('.' . $objFile->extension, '', $strTarget); if ($strPrefix && ($pos = strpos($strPath, $strPrefix)) !== false) { $strPath = str_replace(substr($strPath, $pos, strlen($strPath)), '', $strPath); $strTarget = $strPath . '.' . $objFile->extension; } // Create the parent folder if (!file_exists($objFile->dirname)) { $objFolder = new \Folder(ltrim(str_replace(TL_ROOT, '', $objFile->dirname), '/')); // something went wrong with folder creation if ($objFolder->getModel() === null) { return false; } } if (file_exists(TL_ROOT . '/' . $strTarget)) { // remove suffix if ($i > 0 && StringUtil::endsWith($strPath, '_' . $i)) { $strPath = rtrim($strPath, '_' . $i); } // increment counter & add extension again $i++; // for performance reasons, add new unique id to path to make recursion come to end after 100 iterations if ($i > 100) { return static::getUniqueFileNameWithinTarget(static::addUniqIdToFilename($strPath . '.' . $objFile->extension, null, false)); } return static::getUniqueFileNameWithinTarget($strPath . '_' . $i . '.' . $objFile->extension, $strPrefix, $i); } return $strTarget; }
function testWritingSubsiteID() { $this->objFromFixture('Member', 'admin')->logIn(); $subsite = $this->objFromFixture('Subsite', 'domaintest1'); FileSubsites::$default_root_folders_global = true; Subsite::changeSubsite(0); $file = new File(); $file->write(); $file->onAfterUpload(); $this->assertEquals((int) $file->SubsiteID, 0); Subsite::changeSubsite($subsite->ID); $this->assertTrue($file->canEdit()); $file = new File(); $file->write(); $this->assertEquals((int) $file->SubsiteID, 0); $this->assertTrue($file->canEdit()); FileSubsites::$default_root_folders_global = false; Subsite::changeSubsite($subsite->ID); $file = new File(); $file->write(); $this->assertEquals($file->SubsiteID, $subsite->ID); // Test inheriting from parent folder $folder = new Folder(); $folder->write(); $this->assertEquals($folder->SubsiteID, $subsite->ID); FileSubsites::$default_root_folders_global = true; $file = new File(); $file->ParentID = $folder->ID; $file->onAfterUpload(); $this->assertEquals($folder->SubsiteID, $file->SubsiteID); }
public function clear() { $this->out("Cleanup CACHE directories"); $dirs = array("models", "persistent", "views"); $i = $failed = 0; foreach ($dirs as $dir) { $this->hr(); $path = CACHE . $dir; if (!is_dir($path)) { $this->out("<error>{$path} is not a directory</error>"); continue; } $this->out("<info>Clear directory {$path}</info>"); $Folder = new Folder($path); list(, $files) = $Folder->read(true, array('.', 'empty'), true); foreach ($files as $file) { if (!unlink($file)) { $failed++; $this->out("<error>Failed to delete file {$file}</error>"); continue; } $this->out("<success>Deleted file {$file}</success>"); $i++; } } $this->out("<success>{$i} files deleted</success>"); $this->out("<error>{$failed} files failed</error>"); $this->hr(); }
public function category() { $col_name = "placement_category_id"; $category = null; if (isset($this->{$col_name}) && is_numeric($this->{$col_name})) { $category_id = $this->{$col_name}; $entry = $this->entry(); if (empty($entry)) { return null; } if ($entry->class === 'entry') { require_once 'class.mt_category.php'; $category = new Category(); $loaded = $category->Load("category_id = {$category_id}"); } else { require_once 'class.mt_folder.php'; $category = new Folder(); $loaded = $category->Load("category_id = {$category_id}"); } if (!$loaded) { $category = null; } } return $category; }
/** * Delete directory for upload test. * * @return void */ public function tearDownFiles() { //アップロードテストのためのディレクトリ削除 $folder = new Folder(); $folder->delete(TMP . 'tests' . DS . 'files'); unset($folder); }
/** * Find the given folder or create it both as {@link Folder} database records * and on the filesystem. If necessary, creates parent folders as well. * * @param $folderPath string Absolute or relative path to the file. * If path is relative, its interpreted relative to the "assets/" directory. * @return Folder */ public static function find_or_make($folderPath) { // Create assets directory, if it is missing if (!file_exists(ASSETS_PATH)) { Filesystem::makeFolder(ASSETS_PATH); } $folderPath = trim(Director::makeRelative($folderPath)); // replace leading and trailing slashes $folderPath = preg_replace('/^\\/?(.*)\\/?$/', '$1', $folderPath); $parts = explode("/", $folderPath); $parentID = 0; $item = null; foreach ($parts as $part) { if (!$part) { continue; } // happens for paths with a trailing slash $item = DataObject::get_one("Folder", sprintf("\"Name\" = '%s' AND \"ParentID\" = %d", Convert::raw2sql($part), (int) $parentID)); if (!$item) { $item = new Folder(); $item->ParentID = $parentID; $item->Name = $part; $item->Title = $part; $item->write(); } if (!file_exists($item->getFullPath())) { Filesystem::makeFolder($item->getFullPath()); } $parentID = $item->ID; } return $item; }
/** * add shop to folder * */ function addShopToFolder() { $name = @$this->request->data['name']; $shop_id = @$this->request->data['shop_id']; if (!$shop_id || !$name) { return $this->responseng('faild to add shop.'); } $dataFolder = array("user_id" => $this->user_id, "name" => $name, "type_folder" => intval(@$this->request->data['type_folder'])); $ret = $this->FolderUser->save($dataFolder); $folder_id_old = @$this->request->data["older_folder_id"]; $datashopFolder = array("folder_id" => $ret["FolderUser"]["id"], "shop_id" => $shop_id, "rank" => 1, "status" => NO_MY_FOLDER); $result = $this->FolderShop->save($datashopFolder); App::uses('Folder', 'Utility'); $folder = new Folder(); if (!empty($folder_id_old)) { $oldFolder = $this->FolderUser->findById($folder_id_old); $newFolder = $ret; $path = WWW_ROOT . 'shops' . DS . $oldFolder["FolderUser"]["user_id"] . DS . $oldFolder["FolderUser"]["id"] . DS . $shop_id; $newPath = WWW_ROOT . 'shops' . DS . $newFolder["FolderUser"]["user_id"] . DS . $newFolder["FolderUser"]["id"] . DS . $result["FolderShop"]["shop_id"]; if (is_dir($path)) { if (!is_dir($newPath)) { $folder->create($newPath); } $folder->copy(array('to' => $newPath, 'from' => $path, 'mode' => 0777)); } } if ($result) { return $this->responseOk(); } return $this->responseng('can not save data'); }
/** * testProcessVersion * * @return void */ public function testProcessVersion() { $this->Image->create(); $result = $this->Image->save(array('foreign_key' => 'test-1', 'model' => 'Test', 'file' => array('name' => 'titus.jpg', 'size' => 332643, 'tmp_name' => CakePlugin::path('FileStorage') . DS . 'Test' . DS . 'Fixture' . DS . 'File' . DS . 'titus.jpg', 'error' => 0))); $result = $this->Image->find('first', array('conditions' => array('id' => $this->Image->getLastInsertId()))); $this->assertTrue(!empty($result) && is_array($result)); $this->assertTrue(file_exists($this->testPath . $result['ImageStorage']['path'])); $path = $this->testPath . $result['ImageStorage']['path']; $Folder = new Folder($path); $folderResult = $Folder->read(); $this->assertEqual(count($folderResult[1]), 3); Configure::write('Media.imageSizes.Test', array('t200' => array('thumbnail' => array('mode' => 'outbound', 'width' => 200, 'height' => 200)))); ClassRegistry::init('FileStorage.ImageStorage')->generateHashes(); $Event = new CakeEvent('ImageVersion.createVersion', $this->Image, array('record' => $result, 'storage' => StorageManager::adapter('Local'), 'operations' => array('t200' => array('thumbnail' => array('mode' => 'outbound', 'width' => 200, 'height' => 200))))); CakeEventManager::instance()->dispatch($Event); $path = $this->testPath . $result['ImageStorage']['path']; $Folder = new Folder($path); $folderResult = $Folder->read(); $this->assertEqual(count($folderResult[1]), 4); $Event = new CakeEvent('ImageVersion.removeVersion', $this->Image, array('record' => $result, 'storage' => StorageManager::adapter('Local'), 'operations' => array('t200' => array('thumbnail' => array('mode' => 'outbound', 'width' => 200, 'height' => 200))))); CakeEventManager::instance()->dispatch($Event); $path = $this->testPath . $result['ImageStorage']['path']; $Folder = new Folder($path); $folderResult = $Folder->read(); $this->assertEqual(count($folderResult[1]), 3); }
function __cleanUp() { $Cleanup = new Folder(TMP . 'tests/git'); if ($Cleanup->pwd() == TMP . 'tests/git') { $Cleanup->delete(); } }
public function view($id = null) { $this->layout = 'index'; $this->Anotacion->id = $id; $user = $this->User->findByUsername('transparenciapasiva'); if (!$this->Anotacion->exists() || $this->Anotacion->field('user_id') != $user['User']['id']) { $this->Session->setFlash('<h2 class="alert alert-error">La Anotacion no Existe</h2>', 'default', array(), 'buscar'); $this->redirect(array('controller' => 'home', 'action' => 'index/tab:3')); } $this->set('anotacion', $this->Anotacion->read(null, $id)); $folder_anot = new Folder(WWW_ROOT . 'files' . DS . 'Anotaciones' . DS . 'anot_' . $this->Anotacion->id); $files_url = array(); foreach ($folder_anot->find('.*') as $file) { $files_url[] = basename($folder_anot->pwd()) . DS . $file; } $this->set('files', $files_url); //////////////////////////////////////////////////////////////////// $folder_anot = new Folder(WWW_ROOT . 'files' . DS . 'Anotaciones' . DS . 'anot_' . $this->Anotacion->id . DS . 'Respuestas'); $files_url = array(); $dir = $folder_anot->read(true, false, true); foreach ($dir[0] as $key => $value) { $folder = new Folder($value); foreach ($folder->find('.*') as $file) { $files_url[basename($folder->pwd())][] = $file; } } $this->set('files_res', $files_url); }
private function delete_files(Folder $folder, $regex = '') { $files_to_delete = $folder->get_files($regex, true); foreach ($files_to_delete as $file) { $file->delete(); } }
/** * レイアウトテンプレートを取得 * コンボボックスのソースとして利用 * * @return array * @access public */ function getTemplates() { $templatesPathes = array(); if ($this->Baser->siteConfig['theme']) { $templatesPathes[] = WWW_ROOT . 'themed' . DS . $this->Baser->siteConfig['theme'] . DS . 'feed' . DS; } $templatesPathes[] = BASER_PLUGINS . 'feed' . DS . 'views' . DS . 'feed' . DS; $_templates = array(); foreach ($templatesPathes as $templatesPath) { $folder = new Folder($templatesPath); $files = $folder->read(true, true); $foler = null; if ($files[1]) { if ($_templates) { $_templates = am($_templates, $files[1]); } else { $_templates = $files[1]; } } } $templates = array(); foreach ($_templates as $template) { if ($template != 'ajax.ctp' && $template != 'error.ctp') { $template = basename($template, '.ctp'); $templates[$template] = $template; } } return $templates; }
/** * Verifica se os menus do banco estão atualizados com os do arquivo * @param $aDados- array de menus do banco * @return boolean */ public function isUpToDate($aDados) { $aDados = Set::combine($aDados, "/Menu/id", "/Menu"); App::import("Xml"); App::import("Folder"); App::import("File"); $sCaminhosArquivos = Configure::read("Cms.CheckPoint.menus"); $oFolder = new Folder($sCaminhosArquivos); $aConteudo = $oFolder->read(); $aArquivos = Set::sort($aConteudo[1], "{n}", "desc"); if (empty($aArquivos)) { return false; } $oFile = new File($sCaminhosArquivos . $aArquivos[0]); $oXml = new Xml($oFile->read()); $aAntigo = $oXml->toArray(); foreach ($aDados as &$aMenu) { $aMenu['Menu']['content'] = str_replace("\r\n", " ", $aMenu['Menu']['content']); } if (isset($aAntigo["menus"])) { $aAntigo["Menus"] = $aAntigo["menus"]; unset($aAntigo["menus"]); } if (isset($aAntigo["Menus"])) { $aAntigo = Set::combine($aAntigo["Menus"], "/Menu/id", "/Menu"); $aRetorno = Set::diff($aDados, $aAntigo); } return empty($aRetorno); }
public function buildCss() { App::import('Vendor', 'AssetMinify.JSMinPlus'); // Ouverture des fichiers de config $dir = new Folder(Configure::read('App.www_root') . 'css' . DS . 'minified'); if ($dir->path !== null) { foreach ($dir->find('config_.*.ini') as $file) { preg_match('`^config_(.*)\\.ini$`', $file, $grep); $file = new File($dir->pwd() . DS . $file); $ini = parse_ini_file($file->path, true); $fileFull = new File($dir->path . DS . 'full_' . $grep[1] . '.css', true, 0644); $fileGz = new File($dir->path . DS . 'gz_' . $grep[1] . '.css', true, 0644); $contentFull = ''; foreach ($ini as $data) { // On a pas de version minifié if (!($fileMin = $dir->find('file_' . md5($data['url'] . $data['md5']) . '.css'))) { $fileMin = new File($dir->path . DS . 'file_' . md5($data['url'] . $data['md5']) . '.css', true, 0644); $this->out("Compression de " . $data['file'] . ' ... ', 0); $fileMin->write(MinifyUtils::compressCss(MinifyUtils::cssAbsoluteUrl($data['url'], file_get_contents($data['file'])))); $this->out('OK'); } else { $fileMin = new File($dir->path . DS . 'file_' . md5($data['url'] . $data['md5']) . '.css'); } $contentFull .= $fileMin->read() . PHP_EOL; } // version full $fileFull->write($contentFull); $fileFull->close(); // compression $fileGz->write(gzencode($contentFull, 6)); } } }
public function index() { $this->layout = '/xml/sitemap'; $publish_date = date('2016-02-28'); //sitemap公開日を最終更新日用に設定しておく $link_map = $this->Link->find('first', array('conditions' => array('Link.publish' => 1), 'order' => array('Link.modified' => 'desc'))); $erg_lists = $this->Game->find('all', array('conditions' => array('Game.publish' => 1), 'order' => array('Game.modified' => 'desc'), 'fields' => array('Game.id', 'Game.modified'))); $mh_last = $this->Information->find('first', array('conditions' => array('Information.publish' => 1, 'Information.title LIKE' => '%' . 'モンハンメモ' . '%'), 'order' => array('Information.id' => 'desc'))); /* モンハンメモのページ一覧を取得ここから */ $folder = new Folder('../View/mh'); $mh = $folder->read(); foreach ($mh[1] as $key => &$value) { $value = str_replace('.ctp', '', $value); if ($value == 'index') { $index_key = $key; //indexページを後で除くため } } unset($mh[1][$index_key]); $mh_lists = $mh[1]; /* モンハンメモのページ一覧を取得ここまで */ $tool_last = $this->Information->find('first', array('conditions' => array('Information.publish' => 1, 'Information.title LIKE' => '%' . '自作ツール' . '%'), 'order' => array('Information.id' => 'desc'))); /* 自作ツールのページ一覧を取得ここから */ $array_tools = $this->Tool->getArrayTools(); $tool_lists = $array_tools['list']; /* 自作ツールのページ一覧を取得ここまで */ $voice_lists = $this->Voice->find('list', array('conditions' => array('Voice.publish' => 1), 'fields' => 'system_name')); $diary_lists = $this->Diary->find('all', array('conditions' => array('Diary.publish' => 1), 'order' => array('Diary.modified' => 'desc'), 'fields' => array('Diary.id', 'Diary.modified'))); $this->set(compact('publish_date', 'link_map', 'erg_lists', 'mh_last', 'mh_lists', 'tool_last', 'tool_lists', 'voice_lists', 'diary_lists')); $this->RequestHandler->respondAs('xml'); //xmlファイルとして読み込む }