/** * Delete all values from the cache * * @param boolean $check Optional - only delete expired cache items * @return boolean True if the cache was succesfully cleared, false otherwise * @access public */ function clear($check) { if (!$this->__init) { return false; } $dir = dir($this->settings['path']); if ($check) { $now = time(); $threshold = $now - $this->settings['duration']; } while (($entry = $dir->read()) !== false) { if ($this->__setKey($entry) === false) { continue; } if ($check) { $mtime = $this->__File->lastChange(); if ($mtime === false || $mtime > $threshold) { continue; } $expires = $this->__File->read(11); $this->__File->close(); if ($expires > $now) { continue; } } $this->__File->delete(); } $dir->close(); return true; }
public function admin_index() { $logDir = LOGS; $Folder = new Folder($logDir, false); $logfiles = $Folder->find('.*.log(\\.[0-9])?', true); $files = array(); foreach ($logfiles as $logfile) { $F = new File($logDir . $logfile); $file = array('name' => $logfile, 'dir' => $logDir, 'size' => $F->size(), 'last_modified' => $F->lastChange(), 'last_access' => $F->lastAccess()); array_push($files, $file); } $this->set(compact('files')); }
function readFolder($folderName = null) { $folder = new Folder($folderName); $images = $folder->read(true, array('.', '..', 'Thumbs.db'), false); //pr($folder->tree($folderName)); $images = $images[1]; // We are only interested in files // Get more infos about the images $retVal = array(); foreach ($images as $the_image) { $the_image = new File($the_image); $retVal[] = array_merge($the_image->info(), array('size' => $the_image->size(), 'last_changed' => $the_image->lastChange())); } return $retVal; }
/** * Custom function for migrating from old file browser (kcfinder) to new one * * 1. upload all files inside of the webroot/upload folder (including the upload folder) to s3 * 2. run this migrate function * 3. check the /file_storage/file_storage/browser page (thumbnails should be showing up correctly now) * 4. delete the files from the server */ public function migrate() { $replacement = $directory = ROOT . DS . SITE_DIR . DS . 'Locale' . DS . 'View' . DS . 'webroot'; $directory = $replacement . DS . 'upload'; App::uses('Folder', 'Utility'); App::uses('File', 'Utility'); $dir = new Folder($directory); $files = $dir->findRecursive(); foreach ($files as $file) { $file = new File($file); $info = $file->info(); $model = $this->_detectModelByFileType($info['mime']); if (!empty($model)) { $data['FileStorage']['model'] = $model; $data['FileStorage']['filename'] = $info['basename']; $data['FileStorage']['filesize'] = $info['filesize']; $data['FileStorage']['mime_type'] = $info['mime']; $data['FileStorage']['extension'] = $info['extension']; $data['FileStorage']['path'] = '/' . str_replace('sites/', '', SITE_DIR) . str_replace($replacement, '', $info['dirname']) . '/'; $data['FileStorage']['adapter'] = 'S3Storage'; $data['FileStorage']['creator_id'] = $int = intval(filter_var($data['FileStorage']['path'], FILTER_SANITIZE_NUMBER_INT)); $data['FileStorage']['modifier_id'] = $int; $data['FileStorage']['created'] = date('Y-m-d H:i:s', $file->lastChange()); $data['FileStorage']['modified'] = date('Y-m-d H:i:s'); if ($duplicate = $this->FileStorage->find('first', array('conditions' => array('FileStorage.filename' => $data['FileStorage']['filename'])))) { debug('Duplicate : ' . $data['FileStorage']['filename']); unset($data); continue; } $this->FileStorage->create(); if ($this->FileStorage->save($data, array('callbacks' => false))) { debug('Saved: ' . $data['FileStorage']['filename']); unset($data); continue; } else { debug($data); exit; } } $file->close(); } $this->render(false); }
public function open($dir, $filename, $write = false) { $this->_currentFile = null; $this->_currentFileLastModified = null; $ds = $this->getDataSource(); $file = new File($filepath = $ds->config['path'] . DS . $dir . DS . $filename, false); if (!$file) { return false; } if (!$file->readable()) { return false; } if ($write && !$file->writable()) { return false; } $this->_currentFile = $file; $this->_currentFileLastChange = $file->lastChange(); return $file; }
/** * beforeRender callback function * * @param Controller $controller * @return array contents for panel */ public function beforeRender(Controller $controller) { $data = array(); $dir = new Folder(LOGS); $files = $dir->find(); foreach ($files as $log) { $file = new File(LOGS . $log); $name = $file->name(); $data[$name] = array(); if (!$file->readable()) { $data[$name]['content'] = __('This log file is unreadable.'); continue; } $data[$name]['lastChange'] = date('Y-m-d H:i:s', $file->lastChange()); if ($file->size() > $this->readBytes) { $file->offset(-$this->readBytes, SEEK_END); } $data[$name]['content'] = $file->read($this->readBytes); } return $data; }
/** * testLastChange method * * @return void */ public function testLastChange() { $someFile = new File(TMP . 'some_file.txt', false); $this->assertFalse($someFile->lastChange()); $this->assertTrue($someFile->open('r+')); $this->assertWithinMargin($someFile->lastChange(), time(), 2); $someFile->write('something'); $this->assertWithinMargin($someFile->lastChange(), time(), 2); $someFile->close(); $someFile->delete(); }
public function export() { // Check if the background jobs are enabled - if not, fall back to old export page. if (Configure::read('MISP.background_jobs')) { $now = time(); // as a site admin we'll use the ADMIN identifier, not to overwrite the cached files of our own org with a file that includes too much data. if ($this->_isSiteAdmin()) { $useOrg = 'ADMIN'; $conditions = null; } else { $useOrg = $this->Auth->User('org'); $conditions['OR'][] = array('orgc' => $this->Auth->user('org')); $conditions['OR'][] = array('distribution >' => 0); } $this->Event->recursive = -1; $newestEvent = $this->Event->find('first', array('conditions' => $conditions, 'fields' => 'timestamp', 'order' => 'Event.timestamp DESC')); $this->loadModel('Job'); foreach ($this->Event->export_types as $k => $type) { $job = $this->Job->find('first', array('fields' => array('id', 'progress'), 'conditions' => array('job_type' => 'cache_' . $k, 'org' => $useOrg), 'order' => array('Job.id' => 'desc'))); $dir = new Folder(APP . 'tmp/cached_exports/' . $k); if ($k === 'text') { // Since all of the text export files are generated together, we might as well just check for a single one md5. $file = new File($dir->pwd() . DS . 'misp.text_md5.' . $useOrg . $type['extension']); } else { $file = new File($dir->pwd() . DS . 'misp.' . $k . '.' . $useOrg . $type['extension']); } if (!$file->exists()) { $lastModified = 'N/A'; $this->Event->export_types[$k]['recommendation'] = 1; } else { $fileChange = $file->lastChange(); $lastModified = $this->__timeDifference($now, $fileChange); if ($fileChange > $newestEvent['Event']['timestamp']) { $this->Event->export_types[$k]['recommendation'] = 0; } else { $this->Event->export_types[$k]['recommendation'] = 1; } } $this->Event->export_types[$k]['lastModified'] = $lastModified; if (!empty($job)) { $this->Event->export_types[$k]['job_id'] = $job['Job']['id']; $this->Event->export_types[$k]['progress'] = $job['Job']['progress']; } else { $this->Event->export_types[$k]['job_id'] = -1; $this->Event->export_types[$k]['progress'] = 0; } //$this->Event->export_types[$k]['recommendation'] } $this->set('useOrg', $useOrg); $this->set('export_types', $this->Event->export_types); // generate the list of Attribute types $this->loadModel('Attribute'); //$lastModified = strftime("%d, %m, %Y, %T", $lastModified); $this->set('sigTypes', array_keys($this->Attribute->typeDefinitions)); } else { // generate the list of Attribute types $this->loadModel('Attribute'); //$lastModified = strftime("%d, %m, %Y, %T", $lastModified); $this->set('sigTypes', array_keys($this->Attribute->typeDefinitions)); $this->render('/Events/export_alternate'); } }
/** * Returns a path to the generated thumbnail. * It will only generate a thumbnail for an image if the source is newer than the thumbnail, * or if the thumbnail doesn't exist yet. * * Note: Changing the quality later on after a thumbnail is already generated would have * no effect. Original source images would have to be updated (re-uploaded or modified via * "touch" command or some other means). Or the existing thumbnail would have to be destroyed * manually or with the flushVersions() method below. * * @modified 2009-11-10 by Kevin DeCapite (www.decapite.net) * - Changed 2 return lines to use ImageVersionComponent::formatPath() method * - See that method's comment block for details * * @modified 2010-05-03 by Tom Maiaroto * - Added "letterbox" support so resized images don't need to stretch (when not cropping), changed up some resizing math * - Changed version() method so it takes an array which makes it easier to add more options in the future, consolidated code a lot * - Added sharpening support * * @param $options Array[required] Options that change the size and cropping method of the image * - image String[required] Location of the source image. * - size Array[optional] Size of the thumbnail. Default: 75x75 * - quality Int[optional] Quality of the thumbnail. Default: 85% * - crop Boolean[optional] Whether to crop the image (when one dimension is larger than specified $size) * - letterbox Mixed[optional] If defined, it needs to be an array that defines the RGB background color to use. So when crop is set to false, this will fill in the rest of the image with a background color. Note: Transparent images will have a transparent letterbox unless forced. * - force_letterbox_color Boolean[optional] Whether or not to force the letterbox color on images with transparency (gif and png images). Default: false (false meaning their letterboxes will be transparent, true meaning they get a colored letterbox which also floods behind any transparent/translucent areas of the image) * - sharpen Boolean[optional] Whether to sharpen the image version or not. Default: true (note: png and gif images are not sharpened because of possible problems with transparency) * * @return String path to thumbnail image. */ function version($options = array('image' => null, 'size' => array(75, 75), 'quality' => 85, 'crop' => false, 'letterbox' => null, 'force_letterbox_color' => false, 'sharpen' => true)) { if (isset($options['image'])) { $source = $options['image']; } else { $source = null; } if (isset($options['size'])) { $thumbSize = $options['size']; } else { $thumbSize == array(75, 75); } if (isset($options['quality'])) { $thumbQuality = $options['quality']; } else { $thumbQuality = 85; } if (isset($options['crop'])) { $crop = $options['crop']; } else { $crop = false; } if (isset($options['letterbox'])) { $letterbox = $options['letterbox']; } else { $letterbox = null; } if (is_string($letterbox)) { $letterbox = $this->_html2rgb($options['letterbox']); } if (isset($options['sharpen'])) { $sharpen = $options['sharpen']; } else { $sharpen = true; } if (isset($options['force_letterbox_color'])) { $force_letterbox_color = $options['force_letterbox_color']; } else { $force_letterbox_color = false; } // if no source provided, don't do anything if (empty($source)) { return false; } // set defaults if null passed for any values if ($thumbSize == null) { $thumbSize = array(75, 75); } if ($thumbQuality == null) { $thumbQuality = 85; } if ($crop == null) { $crop = false; } $webroot = new Folder(WWW_ROOT); $this->webRoot = $webroot->path; // set the size $thumb_size_x = $original_thumb_size_x = $thumbSize[0]; $thumb_size_y = $original_thumb_size_y = $thumbSize[1]; // round the thumbnail quality in case someone provided a decimal $thumbQuality = ceil($thumbQuality); // or if a value was entered beyond the extremes if ($thumbQuality > 100) { $thumbQuality = 100; } if ($thumbQuality < 0) { $thumbQuality = 0; } // get full path of source file (note: a beginning slash doesn't matter, the File class handles that I believe) $originalFile = new File($this->webRoot . $source); $source = $originalFile->Folder->path . DS . $originalFile->name() . '.' . $originalFile->ext(); // if the source file doesn't exist, don't do anything if (!file_exists($source)) { return false; } // get the destination where the new file will be saved (including file name) $pathToSave = $this->createPath($originalFile->Folder->path . DS . $thumbSize[0] . 'x' . $thumbSize[1]); $dest = $originalFile->Folder->path . DS . $thumb_size_x . 'x' . $thumb_size_y . DS . $originalFile->name() . '.' . $originalFile->ext(); // First make sure it's an image that we can use (bmp support isn't added, but could be) switch (strtolower($originalFile->ext())) { case 'jpg': case 'jpeg': case 'gif': case 'png': break; default: return false; break; } // Then see if the size version already exists and if so, is it older than our source image? if (file_exists($originalFile->Folder->path . DS . $thumb_size_x . 'x' . $thumb_size_y . DS . $originalFile->name() . '.' . $originalFile->ext())) { $existingFile = new File($dest); if (date('YmdHis', $existingFile->lastChange()) > date('YmdHis', $originalFile->lastChange())) { // if it's newer than the source, return the path. the source hasn't updated, so we don't need a new thumbnail. return $this->formatPath(substr(strstr($existingFile->Folder->path . DS . $existingFile->name() . '.' . $existingFile->ext(), 'webroot'), 7)); } } // Get source image dimensions $size = getimagesize($source); $width = $size[0]; $height = $size[1]; // $x and $y here are the image source offsets $x = NULL; $y = NULL; $dx = $dy = 0; if ($thumb_size_x > $width && $thumb_size_y > $height) { $crop = false; // don't need to crop now do we? } // don't allow new width or height to be greater than the original if ($thumb_size_x > $width) { $thumb_size_x = $width; } if ($thumb_size_y > $height) { $thumb_size_y = $height; } // generate new w/h if not provided (cool, idiot proofing) if ($thumb_size_x && !$thumb_size_y) { $thumb_size_y = $height * ($thumb_size_x / $width); } elseif ($thumb_size_y && !$thumb_size_x) { $thumb_size_x = $width * ($thumb_size_y / $height); } elseif (!$thumb_size_x && !$thumb_size_y) { $thumb_size_x = $width; $thumb_size_y = $height; } // set some default values for other variables we set differently based on options like letterboxing, etc. // TODO: clean this up and consolidate variables so the image creation process is shorter and nicer $new_width = $thumb_size_x; $new_height = $thumb_size_y; $x_mid = ceil($new_width / 2); //horizontal middle // TODO: possibly add options to change where the crop is from $y_mid = ceil($new_height / 2); //vertical middle // If the thumbnail is square if ($thumbSize[0] == $thumbSize[1]) { if ($width > $height) { $x = ceil(($width - $height) / 2); $width = $height; } elseif ($height > $width) { $y = ceil(($height - $width) / 2); $height = $width; } // else if the thumbnail is rectangular, don't stretch it } else { // if we aren't cropping then keep aspect ratio and contain image within the specified size if ($crop === false) { $ratio_orig = $width / $height; if ($thumb_size_x / $thumb_size_y > $ratio_orig) { $thumb_size_x = ceil($thumb_size_y * $ratio_orig); } else { $thumb_size_y = ceil($thumb_size_x / $ratio_orig); } } // if we are cropping... if ($crop === true) { $ratio_orig = $width / $height; if ($thumb_size_x / $thumb_size_y > $ratio_orig) { $new_height = ceil($thumb_size_x / $ratio_orig); $new_width = $thumb_size_x; } else { $new_width = ceil($thumb_size_y * $ratio_orig); $new_height = $thumb_size_y; } $x_mid = ceil($new_width / 2); //horizontal middle // TODO: possibly add options to change where the crop is from $y_mid = ceil($new_height / 2); //vertical middle } } switch (strtolower($originalFile->ext())) { case 'png': if ($thumbQuality != 0) { $thumbQuality = ($thumbQuality - 100) / 11.111111; $thumbQuality = round(abs($thumbQuality)); } $new_im = $this->_generateImage('png', $source, $dx, $dy, $x, $y, $x_mid, $y_mid, $new_width, $new_height, $original_thumb_size_x, $original_thumb_size_y, $thumb_size_x, $thumb_size_y, $height, $width, $letterbox, $crop, $sharpen, $force_letterbox_color); imagepng($new_im, $dest, $thumbQuality); imagedestroy($new_im); break; case 'gif': $new_im = $this->_generateImage('gif', $source, $dx, $dy, $x, $y, $x_mid, $y_mid, $new_width, $new_height, $original_thumb_size_x, $original_thumb_size_y, $thumb_size_x, $thumb_size_y, $height, $width, $letterbox, $crop, $sharpen, $force_letterbox_color); imagegif($new_im, $dest); // no quality setting imagedestroy($new_im); break; case 'jpg': case 'jpeg': $new_im = $this->_generateImage('jpg', $source, $dx, $dy, $x, $y, $x_mid, $y_mid, $new_width, $new_height, $original_thumb_size_x, $original_thumb_size_y, $thumb_size_x, $thumb_size_y, $height, $width, $letterbox, $crop, $sharpen, $force_letterbox_color); imagejpeg($new_im, $dest, $thumbQuality); imagedestroy($new_im); break; default: return false; break; } $outputPath = new File($dest); $finalPath = substr(strstr($outputPath->Folder->path . DS . $outputPath->name() . '.' . $outputPath->ext(), 'webroot'), 7); // PHP 5.3.0 would allow for a true flag as the third argument in strstr()... which would take out "webroot" so substr() wasn't required, but for older PHP... return $this->formatPath($finalPath); }
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')); } } }
public function get_file() { $path = null; $paths = $this->request->params['pass']; foreach ($paths as $p) { $path = $path . DS . $p; $this->set('mId', $p); } $path = str_replace('<>', ' ', $path); $file = new File(WWW_ROOT . 'files' . DS . $this->Session->read('User.company_id') . DS . 'SavedReports' . $path); $fileDetails = $file->info(); $fileChange = $file->lastChange(); $this->set('fileDetails', $fileDetails); $this->set('fileChange', $fileChange); $c_file = WWW_ROOT . 'files' . DS . $this->Session->read('User.company_id') . DS . 'SavedReports' . $path; $this->set('path', $path); }
/** * Sync Files * Check for templates, css, and js files and sync the database content fields * * @param string * @return bool * @todo This should only happen when there has been a change to the template */ public function syncFiles($type = 'template') { App::uses('Folder', 'Utility'); App::uses('File', 'Utility'); if ($type == 'template') { foreach ($this->templateDirectories as $directory) { $dir = new Folder($directory); $files = $dir->find('.*\\.ctp'); // This function must be responsible for making new template files show up at /webpages/index/template ^JB 6/3/2013 if (!empty($files)) { $dbTemplates = $this->_getDbFileRecords($files, 'template'); break; // stops us from searching in more directories } } if (!empty($files)) { foreach ($files as $file) { $file = new File($dir->pwd() . DS . $file); $templates[] = array('name' => $file->name, 'content' => $file->read(), 'type' => 'template', 'modified' => date('Y-m-d h:i:s', $file->lastChange())); // $file->write('I am overwriting the contents of this file'); // $file->append('I am adding to the bottom of this file.'); // $file->delete(); // I am deleting this file $file->close(); // Be sure to close the file when you're done } } foreach ($templates as $template) { $id = $this->find('first', array('conditions' => array('name' => $template['name']), 'fields' => array('id', 'modified'), 'callbacks' => false)); if (!empty($id)) { if ($id['Webpage']['modified'] < $template['modified']) { $this->id = $id['Webpage']['id']; try { $this->save($template); } catch (Exception $e) { throw new Exception($e->getMessage()); } } } else { try { $this->create(); $this->save($template); } catch (Exception $e) { throw new Exception($e->getMessage()); } } } } if ($type == 'css') { $dir = new Folder($this->cssDirectory); $files = $dir->find('.*\\.css'); if (!empty($files)) { foreach ($files as $file) { $file = new File($dir->pwd() . DS . $file); $csses[] = array('name' => str_replace($this->cssDirectory, '', $file->path), 'content' => $file->read(), 'modified' => date('Y-m-d h:i:s', $file->lastChange())); $file->close(); // Be sure to close the file when you're done } } if (!empty($csses)) { foreach ($csses as $css) { $id = $this->field('id', array('WebpageCss.name' => $css['name'])); if (!empty($id)) { try { $this->id = $id; $this->saveField('content', $css['content'], array('callbacks' => false)); } catch (Exception $e) { debug($e->getMessage()); break; } } else { try { $css['is_requested'] = 1; $this->create(); $this->save($css); } catch (Exception $e) { debug($e->getMessage()); break; } } } } } if ($type == 'js') { $dir = new Folder($this->jsDirectory); $files = $dir->find('.*\\.js'); if (!empty($files)) { foreach ($files as $file) { $file = new File($dir->pwd() . DS . $file); $jses[] = array('name' => str_replace($this->jsDirectory, '', $file->path), 'content' => $file->read(), 'modified' => date('Y-m-d h:i:s', $file->lastChange())); $file->close(); // Be sure to close the file when you're done } } if (!empty($jses)) { foreach ($jses as $js) { $id = $this->field('id', array('WebpageJs.name' => $js['name'])); if (!empty($id)) { try { $this->id = $id; $this->saveField('content', $js['content'], array('callbacks' => false)); } catch (Exception $e) { debug($e->getMessage()); break; } } else { try { $js['is_requested'] = 1; $this->create(); $this->save($js); } catch (Exception $e) { debug($e->getMessage()); break; } } } } } if ($type == 'element') { // not recursive into sub folders of the elements directory $dir = new Folder($this->elementsDirectory); $files = $dir->find('.*\\.ctp'); if (!empty($files)) { foreach ($files as $file) { $file = new File($dir->pwd() . DS . $file); $elements[] = array('name' => str_replace(array($this->elementsDirectory, '.ctp'), '', $file->path), 'content' => $file->read(), 'modified' => date('Y-m-d h:i:s', $file->lastChange())); $file->close(); // Be sure to close the file when you're done } } if (!empty($elements)) { foreach ($elements as $element) { $id = $this->field('id', array('Webpage.name' => $element['name'])); if (!empty($id)) { try { $this->id = $id; $this->saveField('content', $element['content'], array('callbacks' => false)); } catch (Exception $e) { debug($e->getMessage()); break; } } else { try { $element['type'] = 'element'; $this->create(); $this->save($element); } catch (Exception $e) { debug($e->getMessage()); break; } } } } } }
private function __advancedFileFind($conditions) { if (empty($this->fileList[1])) { $this->return = array(); return true; } $i = 0; foreach ($this->fileList[1] as $file) { if (in_array($file, $this->ignore)) { continue; } if ($this->recursive > -2) { $Folder = new Folder($this->path); $this->return[$i]['File']['path'] = $Folder->path . DS . $file; $this->return[$i]['File']['relative'] = $this->__relativePath($this->return[$i]['File']['path']); $stat = stat($this->return[$i]['File']['path']); $this->__fileStatus($i, $stat); if ($this->recursive > -1) { $this->return[$i]['File']['accessed'] = date('Y-m-d H:i:s', $stat['atime']); $this->return[$i]['File']['modified'] = date('Y-m-d H:i:s', $stat['mtime']); $this->return[$i]['File']['created'] = date('Y-m-d H:i:s', $stat['ctime']); $File = new File($this->return[$i]['File']['path']); $info = $File->info(); $this->return[$i]['File']['dirname'] = $info['dirname']; $this->return[$i]['File']['name'] = $info['basename']; $this->return[$i]['File']['extension'] = isset($info['extension']) ? $info['extension'] : null; $this->return[$i]['File']['filename'] = $info['filename']; $this->return[$i]['File']['writable'] = $File->writable(); if ($this->recursive > 0) { $this->return[$i]['File']['size'] = $File->size(); $this->return[$i]['File']['owner'] = $File->owner(); $this->return[$i]['File']['group'] = $File->group(); $this->return[$i]['File']['accessed'] = $File->lastAccess(); $this->return[$i]['File']['modidfied'] = $File->lastChange(); $this->return[$i]['File']['charmod'] = $File->perms(); if ($this->recursive > 1) { $this->return[$i]['File']['type'] = filetype($this->return[$i]['File']['path']); $this->return[$i]['File']['md5'] = $File->md5(); $this->return[$i]['File']['Extended'] = stat($this->return[$i]['File']['path']); $i++; continue; } $i++; } $i++; } $i++; } $i++; } return true; }
/** * Read Data * * @param Model $model * @param array $queryData * @param integer $recursive Number of levels of association * @return mixed */ public function read(&$model, $queryData = array(), $recursive = null) { if (isset($queryData["conditions"][$model->alias . ".extension"])) { $extension = preg_quote($queryData["conditions"][$model->alias . ".extension"]); } else { $extension = $this->config['extension']; } if (isset($queryData["conditions"][$model->alias . ".filename"])) { $filename = $queryData["conditions"][$model->alias . ".filename"]; $searchPattern = preg_quote($queryData["conditions"][$model->alias . ".filename"], '/'); } else { // $searchPattern = '.*' . '\.' . preg_quote($extension); $searchPattern = '.*' . '\\.' . $extension; } if (isset($queryData["conditions"][$model->alias . ".dir"])) { // $dir = $this->connection->realpath($this->config['path']) . DS . $queryData["conditions"][$model->alias . ".dir"]; $dir = is_array($dir = $queryData["conditions"][$model->alias . ".dir"]) ? $dir : array($dir); } /* var_dump($queryData);*/ // var_dump($searchPattern); if ($this->config['recursive']) { $list = $this->connection->findRecursive($searchPattern, true); /* $this->log($list); echo "list#\n"; var_dump($list);*/ foreach ($list as &$item) { $temp = $item; $item = array(); $item["full"] = $temp; $item["short"] = mb_substr($temp, mb_strlen($this->connection->realpath($this->config['path']) . DS)); } unset($item); } else { $list = $this->connection->find($searchPattern, true); foreach ($list as &$item) { $temp = $item; $item = array(); $item["full"] = $this->config['path'] . DS . $temp; $item["short"] = $temp; } unset($item); } $resultSet = array(); foreach ($list as $item) { /* if (isset($dir) && isset($filename)) { echo "dirconcat#\n"; var_dump($dir . DS . $filename); echo "itemfull#\n"; var_dump($item["full"]); if ($dir . DS . $filename === $item["full"]) continue; }*/ if (isset($dir)) { if (!$this->fileInDir($item["full"], $dir)) { continue; } } $file = new File($path = $this->config['path'] . DS . $item["short"], false); // var_dump($item); // $item = preg_replace('/' . $extPattern . '$/i', '', $item); $resultSet[] = array($model->alias => array('filename' => $item["short"], 'size' => $file->size(), 'modified' => $file->lastChange())); } if ($model->findQueryType === 'count') { return array(array(array('count' => count($resultSet)))); } return $resultSet; }
public function get_file() { $paths = $this->request->params['pass']; foreach ($paths as $p) { $path = $path . '/' . $p; $this->set('mId', $p); } $path = str_replace('<>', ' ', $path); $file = new File(WWW_ROOT . 'files/' . $path); $fileDetails = $file->info(); $fileChange = $file->lastChange(); $this->set('fileDetails', $fileDetails); $this->set('fileChange', $fileChange); //$c_file = WWW_ROOT . 'files/' . $path; $this->set('path', $path); }