Beispiel #1
0
 /**
  * Renders a scaled version of the image referenced by the provided filename, taken any (optional) manipulators into consideration.
  * @param   String  $sourceData     The binary data of the original source image.
  * @param   Array   $scaleParams
  * @param   Int     $imageType      One of the PHP image type constants, such as IMAGETYPE_JPEG
  * @return  Array
  *                  ['resource']    The image file data string
  *                  ['mime']        Mime type of the generated cache file
  *                  ['timestamp']   Timestamp of the generated cache file
  **/
 public function scale($sourceData, $scaleParams, $imageType)
 {
     $this->_setInputParams($scaleParams);
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
     if (strlen($sourceData) == 0) {
         throw new Exception("This is an empty file!");
     }
     if (!($source = imagecreatefromstring($sourceData))) {
         $finfo = new finfo(FILEINFO_MIME);
         $mime = $finfo->buffer($sourceData);
         throw new Exception("This source image could not be scaled. It's probably not a valid file type. Instead, this file is of the following type: " . $mime);
     }
     $this->_analyzeSourceImage($source, $imageType);
     $this->_addOmittedCanvasDimension();
     if ($this->_isFilterDefined($scaleParams)) {
         Garp_Image_Filter::filter($source, $scaleParams['filter']);
     }
     if ($this->_isSourceEqualToTarget($scaleParams)) {
         $outputImage = $sourceData;
     } else {
         $canvas = $this->_createCanvasImage($imageType);
         $this->_projectSourceOnCanvas($source, $canvas);
         // Enable progressive jpegs
         imageinterlace($canvas, true);
         $outputImage = $this->_renderToImageData($canvas);
         imagedestroy($canvas);
     }
     $output = array('resource' => $outputImage, 'mime' => $this->params['mime'], 'timestamp' => time());
     imagedestroy($source);
     return $output;
 }
Beispiel #2
0
 /**
  * Return the bytes representing the export format (for instance, binary code
  * describing a PDF or Excel file). These will be offered to download.
  *
  * @param Garp_Util_Configuration $params Various parameters describing which content to export
  * @return string
  */
 public function getOutput(Garp_Util_Configuration $params)
 {
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
     $params->setDefault('rule', null)->setDefault('rule2', null);
     $filter = array();
     if (array_key_exists('filter', $params) && $params['filter']) {
         $filter = urldecode($params['filter']);
         $filter = Zend_Json::decode($params['filter']);
     }
     $fetchOptions = array('query' => $filter, 'rule' => $params['rule'], 'rule2' => $params['rule2']);
     if (!empty($params['fields'])) {
         $fields = is_array($params['fields']) ? $params['fields'] : explode(',', $params['fields']);
         $fetchOptions['fields'] = array_combine($fields, $fields);
     }
     if (isset($params['sortField']) && isset($params['sortDir'])) {
         $fetchOptions['sort'] = array($params['sortField'] . ' ' . $params['sortDir']);
     }
     switch ($params['selection']) {
         case 'id':
             // specific record
             $params->obligate('id');
             $fetchOptions['query']['id'] = Zend_Json::decode($params['id']);
             break;
         case 'page':
             $params->obligate('pageSize');
             // specific page
             if (isset($params['page'])) {
                 $fetchOptions['start'] = ($params['page'] - 1) * $params['pageSize'];
                 $fetchOptions['limit'] = $params['pageSize'];
                 // specific selection of pages
             } elseif (isset($params['from']) && isset($params['to'])) {
                 $pages = $params['to'] - $params['from'] + 1;
                 $fetchOptions['start'] = ($params['from'] - 1) * $params['pageSize'];
                 $fetchOptions['limit'] = $pages * $params['pageSize'];
             } else {
                 throw new Garp_Content_Exception(self::EXCEPTION_INVALID_CONFIG);
             }
             break;
     }
     $fetchOptions['filterForeignKeys'] = true;
     $className = Garp_Content_Api::modelAliasToClass($params['model']);
     $model = new $className();
     $this->_bindModels($model);
     // Allow the model or its observers to modify the fetchOptions
     $model->notifyObservers('beforeExport', array(&$fetchOptions));
     $manager = new Garp_Content_Manager($model);
     $data = $manager->fetch($fetchOptions);
     $data = (array) $data;
     // Allow the model or its observers to modify the data
     $model->notifyObservers('afterExport', array(&$data, &$fetchOptions));
     if (empty($data)) {
         $data = array(array('message' => __('no results found')));
     }
     $humanizedData = $this->_humanizeData($data, $model);
     $formattedData = $this->format($model, $humanizedData);
     return $formattedData;
 }
Beispiel #3
0
 /**
  * Central start method
  *
  * @param array $args
  * @return Void
  */
 public function main(array $args = array())
 {
     if (!$args) {
         $this->_displayHelp();
         return;
     }
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
     $this->_args = $args;
     $command = $args[0];
     $this->{'_' . $command}();
 }
Beispiel #4
0
 /**
  * This updates your database to be compliant with the refactored Translatable behavior.
  * I18n views no longer use fallbacks to the default language records.
  * Therefore an update to existing databases is necessary. This command populates records in
  * non-default languages to provide the data that used to be fallen back on.
  *
  * @param array $args
  * @return bool
  */
 public function populateLocalizedRecords(array $args = array())
 {
     Zend_Registry::get('CacheFrontend')->setOption('caching', false);
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
     $models = !empty($args) ? array($args[0]) : $this->_getInternationalizedModels();
     array_walk($models, array($this, '_populateRecordsForModel'));
     Zend_Registry::get('CacheFrontend')->setOption('caching', true);
     Garp_Cache_Manager::purge();
     Garp_Cli::lineOut('Done.');
     return true;
 }
Beispiel #5
0
 public function restore($args = array())
 {
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
     $version = new Garp_Semver();
     Garp_Cli::lineOut('Restoring gumball ' . $version, Garp_Cli::PURPLE);
     $gumball = new Garp_Gumball($version);
     try {
         $gumball->restore();
         $this->_broadcastGumballInstallation($version);
         Garp_Cli::lineOut('Done!', Garp_Cli::GREEN);
     } catch (Garp_Gumball_Exception_SourceEnvNotConfigured $e) {
         Garp_Cli::errorOut(self::ERROR_SOURCE_ENV_NOT_CONFIGURED);
         return false;
     } catch (Exception $e) {
         Garp_Cli::errorOut('Error: ' . $e->getMessage());
         return false;
     }
     return true;
 }
Beispiel #6
0
 protected function _enableHighMemory()
 {
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
 }
 /**
  * Export content in various formats
  *
  * @return Void
  */
 public function exportAction()
 {
     Zend_Registry::set('CMS', true);
     $mem = new Garp_Util_Memory();
     $mem->useHighMemory();
     $params = new Garp_Util_Configuration($this->getRequest()->getParams());
     // make sure some required parameters are in place
     $params->obligate('exporttype')->obligate('model')->obligate('selection')->setDefault('fields', Zend_Db_Select::SQL_WILDCARD);
     // fetch exporter
     $exporter = Garp_Content_Export_Factory::getExporter($params['exporttype']);
     $bytes = $exporter->getOutput($params);
     $filename = $exporter->getFilename($params);
     $download = Zend_Controller_Action_HelperBroker::getStaticHelper('download');
     $download->force($bytes, $filename, $this->_response);
     $this->_helper->viewRenderer->setNoRender();
 }
Beispiel #8
0
<?php

date_default_timezone_set('Europe/Amsterdam');
define('APPLICATION_ENV', 'testing');
define('MEMCACHE_HOST', null);
define('MEMCACHE_PORT', null);
$garpRoot = dirname(__FILE__) . '/..';
error_reporting(-1);
ini_set('log_errors', 0);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 'stderr');
require_once $garpRoot . '/application/init.php';
// Grab either the configuration of a host project, where garp3 is installed as dependency,
// or take predefined config.ini used in Garp's own test suite.
$assumedApplicationIniPath = APPLICATION_PATH . '/configs/application.ini';
$application = new Garp_Application(APPLICATION_ENV, file_exists($assumedApplicationIniPath) ? $assumedApplicationIniPath : GARP_APPLICATION_PATH . '/../tests/config.ini');
$application->bootstrap();
Zend_Registry::set('application', $application);
$mem = new Garp_Util_Memory();
$mem->useHighMemory();