private function _saveTweets($tweets) { $file = new Garp_File(); $prefix = 'twitter'; if (isset($tweets['search'])) { foreach ($tweets['search'] as $query => $result) { $filename = $prefix . '_' . $query . '_search.js'; $filename = Garp_File::formatFilename($filename); $file->store($filename, $this->_addCallback($result), TRUE); } } if (isset($tweets['userTimeline'])) { foreach ($tweets['userTimeline'] as $screen_name => $timeline) { $filename = $prefix . '_' . $screen_name . '_timeline.js'; $filename = Garp_File::formatFilename($filename); $file->store($filename, $this->_addCallback($timeline), TRUE); } } if (isset($tweets['userList'])) { foreach ($tweets['userList'] as $name => $list) { $filename = $prefix . '_' . $name . '_list.js'; $filename = Garp_File::formatFilename($filename); $file->store($filename, $this->_addCallback($list), TRUE); } } }
public function testReadOnlyCdnShouldProhibitRemoval() { $this->_helper->injectConfigValues(array('cdn' => array('readonly' => true))); $exception = null; try { $filename = 'wefoiejwoiejfeiowjfeowijfoewijf.txt'; $file = new Garp_File(Garp_File::TYPE_DOCUMENTS); $file->clearContext(); $file->remove($filename); } catch (Exception $e) { $exception = $e->getMessage(); } $this->assertEquals(Garp_File::EXCEPTION_CDN_READONLY, $exception); }
private function _viewSourceById($id) { $imageModel = new Model_Image(); $imageRow = $imageModel->fetchRow($imageModel->getAdapter()->quoteInto("id = ?", $id)); if (count($imageRow) && isset($imageRow->filename)) { $file = new Garp_File('image'); $url = $file->getUrl($imageRow->filename); header("Location: " . $url); // @codingStandardsIgnoreStart exit; // @codingStandardsIgnoreEnd } throw new Zend_Controller_Action_Exception("Sorry, I can't find the requested image.", 404); }
public function store($filename, $data, $overwrite = false, $formatFilename = true) { $returnedParams = $this->_beforeStore($filename, $data, $overwrite, $formatFilename); list($filename, $data, $overwrite, $formatFilename) = $returnedParams; $result = parent::store($filename, $data, $overwrite, $formatFilename); return $result; }
protected function _getIni() { if (!self::$_config) { self::$_config = Zend_Registry::get('config'); $this->_validateConfig(self::$_config); } return self::$_config; }
/** * @param String $filename * @param String $data Binary file data * @param Boolean $overwrite Whether to overwrite this file, or create a unique name * @param Boolean $formatFilename Whether to correct the filename, * f.i. ensuring lowercase characters. * @return String Destination filename. */ public function store($filename, $data, $overwrite = false, $formatFilename = true) { $this->_verifyDirectory($filename); if ($formatFilename) { $filename = Garp_File::formatFilename($filename); } if (!$overwrite) { while ($this->exists($filename)) { $filename = Garp_File::getCumulativeFilename($filename); } } if ($this->_gzip) { $data = gzencode($data); } if (file_put_contents($this->_getFilePath($filename), $data) !== false) { chmod($this->_getFilePath($filename), self::PERMISSIONS); return $filename; } else { return false; } }
/** * @param string $filename * @param string $data Binary file data * @param boolean $overwrite Whether to overwrite this file, or create a unique name * @param boolean $formatFilename Whether to correct the filename, * f.i. ensuring lowercase characters. * @return string Destination filename. */ public function store($filename, $data, $overwrite = false, $formatFilename = true) { $this->_initApi(); $this->_createBucketIfNecessary(); if ($formatFilename) { $filename = Garp_File::formatFilename($filename); } if (!$overwrite) { while ($this->exists($filename)) { $filename = Garp_File::getCumulativeFilename($filename); } } $path = $this->_config['bucket'] . $this->_getUri($filename); $meta = array(Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ); if (false !== strpos($filename, '.')) { $ext = substr($filename, strrpos($filename, '.') + 1); if (array_key_exists($ext, $this->_knownMimeTypes)) { $mime = $this->_knownMimeTypes[$ext]; } else { $finfo = new finfo(FILEINFO_MIME); $mime = $finfo->buffer($data); } } else { $finfo = new finfo(FILEINFO_MIME); $mime = $finfo->buffer($data); } $meta[Zend_Service_Amazon_S3::S3_CONTENT_TYPE_HEADER] = $mime; if ($this->_config['gzip'] && $this->_gzipIsAllowedForFilename($filename)) { $meta['Content-Encoding'] = 'gzip'; $data = gzencode($data); } if ($this->_api->putObject($path, $data, $meta)) { return $filename; } return false; }
/** * Class constructor * @param String $fileName The datafile * @return Void */ public function __construct($fileName) { $gf = new Garp_File(); $fileUrl = $gf->getUrl($fileName); $this->_importFile = $fileUrl; }
protected function _getJson() { $file = new Garp_File(Garp_File::TYPE_DOCUMENTS); $data = $file->fetch(basename($this->_importFile)); return Zend_Json::decode($data); }
/** * Import content from various formats. * This action has two states; * - first a datafile is uploaded. The user is presented with a mapping interface * where they have to map columns in the datafile to columns in the database. * - then this URL is called again with the selected mapping, and the columns are * mapped and inserted into the database. * * @return Void */ public function importAction() { $memLim = ini_get('memory_limit'); ini_set('memory_limit', '2G'); set_time_limit(0); // No time limit Zend_Registry::set('CMS', true); $params = new Garp_Util_Configuration($this->getRequest()->getParams()); $params->obligate('datafile')->obligate('model')->setDefault('firstRow', 0)->setDefault('ignoreErrors', false); $importer = Garp_Content_Import_Factory::getImporter($params['datafile']); $success = false; if (isset($params['mapping'])) { $mapping = Zend_Json::decode($params['mapping']); $className = Garp_Content_Api::modelAliasToClass($params['model']); $model = new $className(); $response = array(); try { $success = !!$importer->save($model, $mapping, array('firstRow' => $params['firstRow'], 'ignoreErrors' => $params['ignoreErrors'])); } catch (Exception $e) { $response['message'] = $e->getMessage(); } if ($success) { // cleanup input file $gf = new Garp_File(); $gf->remove($params['datafile']); } $response['success'] = $success; $this->view->response = $response; } else { $std = new stdClass(); $std->success = true; $std->data = $importer->getSampleData(); $this->view->response = $std; } ini_set('memory_limit', $memLim); $this->_helper->layout->setLayout('json'); $this->renderScript('content/call.phtml'); }