/** * 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(); } } } }
/** * Check if all dummy files exist */ public function testTestSetup() { // check dummy files foreach (array($this->upload1, $this->upload2, $this->uploadNoExt, $this->uploadImage) as $upload) { $this->assertTrue(file_exists($upload['tmp_name'])); } // check upload dir $this->assertEqual($this->UploadFolder->pwd(), MEDIA_TESTAPP_UPLOADDIR); }
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)); } } }
function upload() { $directory = $this->getNextParam(null, 'path'); $container = $this->getNextParam(null, 'container'); if (empty($directory) || empty($container)) { $this->errorAndExit('Directory and Container required'); } $Folder = new Folder($directory); if ($this->params['recursive']) { $files = $Folder->findRecursive(); } else { $single_files = $Folder->find(); $files = array(); foreach ($single_files as $file) { $files[] = $Folder->pwd() . DS . $file; } } $this->ProgressBar->start(count($files)); foreach ($files as $file) { CloudFiles::upload($file, $container); $this->ProgressBar->next(); } $this->out(); $this->out("Finished."); }
function __cleanUp() { $Cleanup = new Folder(TMP . 'tests/git'); if ($Cleanup->pwd() == TMP . 'tests/git') { $Cleanup->delete(); } }
/** * Returns the full path of the File. * * @return string Full path to file * @access public */ function pwd() { if (is_null($this->path)) { $this->path = $this->Folder->slashTerm($this->Folder->pwd()) . $this->name; } return $this->path; }
/** * Returns the full path of the file. * * @return string Full path to the file * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::pwd */ public function pwd() { if ($this->path === null) { $this->path = $this->Folder->slashTerm($this->Folder->pwd()) . $this->name; } return $this->path; }
public function admin_reset($user_id) { if ($this->Auth->user('role') > 1) { $dir = new Folder('../webroot/img/avatars/'); if ($dir->path != null) { // On supprime le fichier $files = $dir->find($user_id . '.jpg'); foreach ($files as $file) { $file = new File($dir->pwd() . DS . $file); $file->delete(); $file->close(); } // On sauvegarde $user = $this->User->find('first', ['conditions' => ['User.id' => $user_id]]); $username = $user['User']['username']; $avatar = 'http://cravatar.eu/helmavatar/' . $username; $this->User->id = $user_id; $this->User->saveField('avatar', $avatar); // Redirection $this->Session->setFlash('L\'avatar de ' . $username . ' a été réinitialisé', 'toastr_success'); return $this->redirect(['controller' => 'users', 'action' => 'edit', $user_id]); } } else { throw new NotFoundException(); } }
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); }
function end() { parent::end(); $Cleanup = new Folder(TMP . 'tests/svn'); if ($Cleanup->pwd() == TMP . 'tests/svn') { $Cleanup->delete(); } }
function uploadConsultDocument($data) { $folderPath = WWW_ROOT . $this->consult_document_path . DS . $data['consult_id']; $consultantFolder = new Folder($folderPath, true, 0755); $extension = substr($data['name'], -3); $fileName = uniqid() . '.' . $extension; if (is_null($consultantFolder->pwd())) { if (!$this->createFolder($folderPath)) { throw new Exception(self::CREATE_FILE_ERROR); } } if (move_uploaded_file($data['tmp_name'], $consultantFolder->pwd() . DS . $fileName)) { return $consultantFolder->pwd() . DS . $fileName; } else { throw new Exception(self::CREATE_FILE_ERROR); } }
function endTest() { $Cleanup = new Folder(TMP . 'tests/git'); if ($Cleanup->pwd() == TMP . 'tests/git') { $Cleanup->delete(); } unset($this->Source); }
public function ingest($type = "meta") { if ($type == "meta") { $meta = new Folder('/Users/n00002621/Dropbox/Research - Cheminfo/OSDB/IS-DB/metadata'); $files = $meta->find('.*\\.xml'); foreach ($files as $file) { $file = new File($meta->pwd() . DS . $file); $text = $file->read(); $xml = simplexml_load_string($text); $data = json_decode(json_encode($xml), true); $set = $data['data_set']; $sam = $data['sample']; $set['id'] = $set['DataSetId']; unset($set['DataSetId']); $set['author_id'] = $set['ContactAuthor']; unset($set['ContactAuthor']); $set['publication_id'] = $set['PublicationId']; unset($set['PublicationId']); $set['sample_id'] = $set['SampleId']; unset($set['SampleId']); $set['datatype'] = $set['DataType']; unset($set['DataType']); $set['dataformat'] = $set['DataFormat']; unset($set['DataFormat']); $set['description'] = $set['Description']; unset($set['Description']); if (isset($set['Instrument'])) { $set['instrument'] = $set['Instrument']; unset($set['Instrument']); } else { $set['instrument'] = ""; } if (isset($set['MeasurementTechnique'])) { $set['measurement'] = $set['MeasurementTechnique']; unset($set['MeasurementTechnique']); } else { $set['measurement'] = ""; } $set['oldfilename'] = $set['OldFileName']; unset($set['OldFileName']); $set['newfilename'] = $set['NewFileName']; unset($set['NewFileName']); $set['mimetype'] = $set['MimeType']; unset($set['MimeType']); $set['filesize'] = $set['FileSize']; unset($set['FileSize']); $set['submitted'] = $set['SubmissionDate']; unset($set['SubmissionDate']); $set['flags'] = $set['DataSetFlags']; unset($set['DataSetFlags']); debug($set); debug($sam); exit; } debug($files); exit; } }
public function main() { $Folder = new Folder(dirname(dirname(dirname(__FILE__))) . DS . "features"); $this->out("copy " . $Folder->pwd() . " to Cake Root..."); $Folder->copy(array('to' => ROOT . DS . "features")); $File = new File(dirname(__FILE__) . DS . "behat.yml.default"); $this->out("copy " . $File->name() . " to App/Config..."); $File->copy(APP . DS . "Config" . DS . "behat.yml"); }
public function listar($idConvenio) { $dir = new Folder(WWW_ROOT . 'xml/' . $idConvenio); $path = $dir->pwd() . '\\'; $files = $dir->read(true); $this->set('idConvenio', $idConvenio); $this->set('path', $path); $this->set('files', $files); }
function __cleanUp() { $path = Configure::read('Content.base'); $Cleanup = new Folder(TMP . 'tests/git'); if ($Cleanup->pwd() == TMP . 'tests/git') { $Cleanup->delete(); } @unlink($path . 'chaw'); @unlink($path . 'permissions.ini'); }
/** * Returns the full path of the file. * * @return string Full path to the file */ public function pwd() { if ($this->path === null) { $dir = $this->Folder->pwd(); if (is_dir($dir)) { $this->path = $this->Folder->slashTerm($dir) . $this->name; } } return $this->path; }
/** * Creates the file. * * @return boolean Success * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::create */ public function create() { $dir = $this->Folder->pwd(); if (is_dir($dir) && is_writable($dir) && !$this->exists()) { if (touch($this->path)) { return true; } } return false; }
public function addCssFonts() { if (!is_object(IdmlAssembler::getInstance()->getProcessor())) { return; } $dir = new Folder(APP . "Data/Pxe/Fonts"); $files = $dir->find(); foreach ($files as $file) { IdmlAssembler::getInstance()->getProcessor()->addFontToBook($dir->pwd() . DS . $file); } }
/** * testAddTestDirectoryRecursiveWithNonPhp * * @return void */ public function testAddTestDirectoryRecursiveWithNonPhp() { $this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.'); $Folder = new Folder(TMP . 'MyTestFolder', true, 0777); touch($Folder->path . DS . 'BackupTest.php~'); touch($Folder->path . DS . 'SomeNotesTest.txt'); touch($Folder->path . DS . 'NotHiddenTest.php'); $suite = $this->getMock('CakeTestSuite', array('addTestFile')); $suite->expects($this->exactly(1))->method('addTestFile'); $suite->addTestDirectoryRecursive($Folder->pwd()); $Folder->delete(); }
/** * testAddTestDirectoryRecursiveWithHidden * * @return void */ public function testAddTestDirectoryRecursiveWithHidden() { $this->skipIf(!is_writeable(TMP), 'Cant addTestDirectoryRecursiveWithHidden unless the tmp folder is writable.'); $Folder = new Folder(TMP . 'MyTestFolder', true, 0777); mkdir($Folder->path . DS . '.svn', 0777, true); touch($Folder->path . DS . '.svn' . DS . 'InHiddenFolderTest.php'); touch($Folder->path . DS . 'NotHiddenTest.php'); touch($Folder->path . DS . '.HiddenTest.php'); $suite = $this->getMock('CakeTestSuite', array('addTestFile')); $suite->expects($this->exactly(1))->method('addTestFile'); $suite->addTestDirectoryRecursive($Folder->pwd()); $Folder->delete(); }
static function createFile($type, $params = array()) { $contentFile = null; $year = date('Y'); $title = Inflector::slug($params['title'], '-'); $filename = strtolower($title); $directory = new Folder(WWW_ROOT . 'files' . DS . 'arquivos' . DS . $filename . DS, true, 0777); if ($type == 'marketing') { $upload = explode('.', $params['file']['name']); $filename = $upload[0]; if (!empty($params)) { $destination = $directory->pwd() . $params['file']['name']; move_uploaded_file($params['file']['tmp_name'], $destination); } } else { $contentFile = $params['content']; } try { $file = new File($directory->path . DS . $filename . '.html', true, 0777); $file->write('<!doctype html>'); $file->append('<html lang="en">'); $file->append('<head>'); $file->append('<meta charset="UTF-8">'); $file->append('<title>Universidade Castelo Branco :: ' . $params['title'] . '</title>'); $file->append('</head>'); $file->append('<body>'); $file->append('<p align="center"> Caso não consiga visualizar este email, <a href="http://arquivos.castelobranco.br/data/publico/email/' . $year . '/' . $filename . '.html" title="' . $params['title'] . '"> acesse aqui.</a></p>'); $file->append('<div style="margin:auto; width:600px">'); switch ($type) { case 'marketing': $file->append('<img src="http://arquivos.castelobranco.br/data/publico/email/2014/' . $params['file']['name'] . '" alt="' . $params['title'] . '" width="600" />'); break; case 'text': $file->append('<img src="http://arquivos.castelobranco.br/data/publico/outros/2012/img/logo-castelo.jpg" alt="Logo" /><hr/>'); $file->append($contentFile); break; default: break; } $file->append('</div>'); $file->append('</body>'); $file->append('</html>'); $file->close(); return true; } catch (CakeException $e) { $e->getMessage("Não foi possivel Criar o arquivo!"); return false; } return false; }
function _downloadAvatar($user) { #Creamos el directorio del usuario $dir = new Folder(ROOT . DS . 'app/webroot/img/users/' . $user['username'], true); ###################################################################################### $file = new File($dir->pwd() . DS . 'avatar.jpg'); if ($file->exists()) { return true; } ################################################################## if ($this->Gravatar->accountExists($user['email'])) { $this->Gravatar->download($user['email'], '/webroot/img/users/' . $user['username'] . '/' . 'avatar.jpg', array('size' => 50)); } else { copy(ROOT . DS . 'app/webroot/img/users/default_avatar.jpg', $dir->pwd() . DS . 'avatar.jpg'); } }
public function flags($current) { $dir = new Folder(WWW_ROOT . 'img/flags'); $files = $dir->find('.*', true); if ($current != 'unknown') { $flag[$current] = $current; } $flag[''] = ''; foreach ($files as $file) { $file = new File($dir->pwd() . DS . $file); $flag[Inflector::humanize($file->name())] = Inflector::humanize($file->name()); $file->close(); // Be sure to close the file when you're done } return $flag; }
public function execute() { // Reset core i18n translations $this->_translations = array(); // todo: not only webroot $dir = new Folder(APP . 'webroot' . DS . 'js'); $files = $dir->find('.*\\.js'); foreach ($files as $file) { $this->_locale_parse_js_file($dir->pwd() . DS . $file); } // Create POT file $this->_buildFiles(); $this->_output = APP . 'Locale' . DS; $this->_writeFiles(); $this->out(); $this->out(__d('i18n_js', '<info>I18nJs POT files created in %s</info>', $this->_output)); }
/** * createWysIsWygZIP * * このメソッドはいずれはWYSISWYGエディタダウンロードコンポーネントへ移動します * @param Folder $folder * @param string $zipFileName * @param string $data wysiswyg editor content * @return string path to zip file about "data" */ public function createWysIsWygZIP($folder, $zipFileName, $data) { $fileName = $zipFileName . '.zip'; $zip = new ZipArchive(); $filePath = $folder->pwd() . DS . $fileName; $zipFp = $zip->open($filePath, ZipArchive::CREATE); if ($zipFp === true) { $zip->addFromString($zipFileName, $data); } else { return null; } // // 本当はここにWysISWygエディタの中に添付されている画像ファイルなどを // zipに突っ込む処理が入る // $zip->close(); return $filePath; }
/** * Removes record for given ID. If no ID is given, the current ID is used. Returns true on success. * * @param int|string $id ID of record to delete * @param bool $cascade Set to true to delete records that depend on this record * @return bool True on success * @triggers Model.beforeDelete $this, [$cascade] * @triggers Model.afterDelete $this * @link http://book.cakephp.org/2.0/en/models/deleting-data.html */ public function delete($id = null, $cascade = true) { /** * Constructor. * * @param string $path Path to folder * @param bool $create Create folder if not found * @param string|bool $mode Mode (CHMOD) to apply to created folder, false to ignore * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder */ $dir = new Folder(TMP . 'logs'); /** * Returns an array of all matching files in current directory. * * @param string $regexpPattern Preg_match pattern (Defaults to: .*) * @param bool $sort Whether results should be sorted. * @return array Files that match given pattern * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::find */ $files = $dir->find('.*', true); foreach ($files as $file) { /** * Constructor * * @param string $path Path to file * @param boolean $create Create file if it does not exist (if true) * @param integer $mode Mode to apply to the folder holding the file * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File */ $file = new File($dir->pwd() . DS . $file); /** * Deletes the File. * * @return boolean Success * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#File::delete */ if ($file->delete()) { continue; } else { return false; } } return true; }
/** * Read contents of currently selected directory * * @return FileExplorer */ public function readContents() { $exceptions = $this->excludes; if (!$this->_Folder || !$this->_Folder->pwd()) { return $this; } list($folders, $files) = $this->_Folder->read(true, $exceptions, true); $_folders = array(); foreach ($folders as $folder) { array_push($_folders, array('name' => basename($folder), 'size' => null, 'permissions' => null, 'writeable' => is_writeable($folder))); } $_files = array(); foreach ($files as $file) { $pathinfo = pathinfo($file); array_push($_files, array('name' => $pathinfo['filename'], 'basename' => $pathinfo['basename'], 'size' => filesize($file), 'ext' => @$pathinfo['extension'], 'permissions' => fileperms($file), 'writeable' => is_writeable($file))); } $this->_contents = array('Folder' => $_folders, 'File' => $_files); return $this; }
/** * compressFile * * @param string &$filePath input file path * @return string */ public function compressFile($password) { // 暗号化ZIPにするのはノーマルファイルの場合のみと考える $filePath = $this->_workingFolder->pwd() . DS . $this->_downloadFileName; $cmd = '/usr/bin/zip'; if (!file_exists($cmd)) { return $filePath; } $pathInfo = pathinfo($filePath); $this->_downloadFileName = $pathInfo['filename'] . '.zip'; $outputFilePath = $pathInfo['dirname'] . DS . $this->_downloadFileName; $execCmd = sprintf('%s -j -e -P %s %s %s', $cmd, $password, $outputFilePath, $filePath); // コマンドを実行する exec(escapeshellcmd($execCmd)); // 入力ファイルを削除する @unlink($filePath); $this->_downloadFileExt = 'zip'; return $outputFilePath; }
/** * Main execution method * * @access public * @return boolean */ function execute() { $this->_answer = isset($this->params['auto']) ? 'y' : 'n'; $this->model = array_shift($this->args); $this->directory = array_shift($this->args); $this->_quiet = isset($this->params['quiet']); if (!isset($this->model)) { $this->model = $this->in('Name of model:', null, 'Media.Attachment'); } if (!isset($this->directory)) { $this->directory = $this->in('Directory to search:', null, MEDIA_TRANSFER); } $this->_Model = ClassRegistry::init($this->model); if (!isset($this->_Model->Behaviors->Coupler)) { $this->err('CouplerBehavior is not attached to Model'); return false; } $this->_baseDirectory = $this->_Model->Behaviors->Coupler->settings[$this->_Model->alias]['baseDirectory']; $this->_Folder = new Folder($this->directory); $this->interactive = !isset($this->model, $this->directory); if ($this->interactive) { $input = $this->in('Interactive?', 'y/n', 'y'); if ($input == 'n') { $this->interactive = false; } } $this->out(); $this->out(sprintf('%-25s: %s', 'Model', $this->_Model->name)); $this->out(sprintf('%-25s: %s', 'Search directory', $this->_Folder->pwd())); $this->out(sprintf('%-25s: %s', 'Automatic repair', $this->_answer == 'y' ? 'yes' : 'no')); if ($this->in('Looks OK?', 'y,n', 'y') == 'n') { return false; } $this->_Model->Behaviors->disable('Coupler'); $this->_checkFilesWithRecords(); $this->_checkRecordsWithFiles(); $this->_Model->Behaviors->enable('Coupler'); $this->out(); return true; }