/** * This action list all admin controller in all active modules. * It can help to build navigation. */ public function listAdminAction() { $front = $this->getFrontController(); $modules = $front->getControllerDirectory(); $moduleEnabled = Centurion_Config_Manager::get('resources.modules'); $this->view->modules = array(); foreach ($modules as $moduleName => $module) { $this->view->modules[$moduleName] = array(); if (!in_array($moduleName, $moduleEnabled)) { continue; } $dbTableDir = realpath($module); if (!file_exists($dbTableDir)) { continue; } $dir = new Centurion_Iterator_DbTableFilter($dbTableDir); foreach ($dir as $fileInfo) { if (substr($fileInfo, 0, 5) == 'Admin') { if (substr($fileInfo, -14) == 'Controller.php') { $controllerName = Centurion_Inflector::tableize(substr($fileInfo, 0, -14), '-'); $this->view->modules[$moduleName][] = $controllerName; } } } } ksort($this->view->modules); }
/** * * @param string $apiKey Flickr api key. If not given, it will try to find it in config. */ public function __construct($apiKey = null) { if (null === $apiKey) { $apiKey = Centurion_Config_Manager::get('flickr.apikey'); } parent::__construct($apiKey); }
/** * Check if the current user has an identity. * * @param string $url Redirect to a specific url, by default it redirects to admin login form */ public function direct($url = null, $throwException = false) { if (!$this->getActionController()->getUser()->hasIdentity() || $this->getActionController()->getUser()->getIdentity()->username == 'anonymous') { if (null === $url) { if (null != Centurion_Config_Manager::get('auth.login.params')) { $params = Centurion_Config_Manager::get('auth.login.params'); } else { $params = array('controller' => 'login', 'action' => 'index', 'module' => 'admin'); } if (null !== Centurion_Config_Manager::get('auth.login.params')) { $route = Centurion_Config_Manager::get('auth.login.route'); } else { $route = 'default'; } $url = Zend_Controller_Action_HelperBroker::getStaticHelper('url')->url($params, $route); } if ($throwException) { throw new Zend_Auth_Exception('Authentification required'); } $url .= sprintf('?next=%s', $this->getRequest()->getRequestUri()); if (defined('PHPUNIT') && PHPUNIT == true) { $this->getActionController()->getHelper('viewRenderer')->setNoRender(); $this->getActionController()->getHelper('layout')->disableLayout(); Zend_Controller_Front::getInstance()->setParam('noErrorHandler', true); $this->getActionController()->getHelper('redirector')->setPrependBase(false)->gotoUrl($url); throw new Exception('die'); } else { return $this->getActionController()->getHelper('redirector')->setPrependBase(false)->gotoUrlAndExit($url); } } }
public function init() { $controller = $this->getActionController(); if (!($requestedLocale = $controller->getRequest()->getParam('language', false))) { $local = new Zend_Locale(); $requestedLocale = $local->getLanguage(); } if (is_array($requestedLocale)) { $requestedLocale = current($requestedLocale); } $requestedLocale = strtolower($requestedLocale); try { Centurion_Db::getSingleton('translation/language')->get(array('locale' => $requestedLocale)); } catch (Centurion_Db_Table_Row_Exception_DoesNotExist $e) { $requestedLocale = Translation_Traits_Common::getDefaultLanguage(); $requestedLocale = $requestedLocale->locale; } Zend_Registry::get('Zend_Translate')->setLocale($requestedLocale); Zend_Locale::setDefault($requestedLocale); Zend_Registry::set('Zend_Locale', $requestedLocale); $options = Centurion_Db_Table_Abstract::getDefaultFrontendOptions(); if (!isset($options['cache_id_prefix'])) { $options['cache_id_prefix'] = ''; } $options['cache_id_prefix'] = $requestedLocale . '_' . $options['cache_id_prefix']; Centurion_Db_Table_Abstract::setDefaultFrontendOptions($options); //TODO: fix this when in test unit environment if (!APPLICATION_ENV === 'testing') { $this->getActionController()->getFrontController()->getParam('bootstrap')->getResource('cachemanager')->addIdPrefix($requestedLocale . '_'); } if (Centurion_Config_Manager::get('translation.global_param')) { $this->getFrontController()->getRouter()->setGlobalParam('language', $requestedLocale); } }
public function isValidKey($row, $key, $effect) { $lifetime = Centurion_Config_Manager::get('media.key_lifetime'); list($lifetimeValue, $lifetimeUnit) = sscanf($lifetime, '%d%s'); $lifetimeUnit = strtolower($lifetimeUnit); $date = new Zend_Date(); switch ($lifetimeUnit) { case 'j': $date->setHour(0); case 'h': $date->setMinute(0); case 'm': default: $date->setSecond(0); } for ($i = 0; $i < $lifetimeValue; $i++) { if ($key === $row->getTemporaryKey($effect, $date)) { return true; } switch ($lifetimeUnit) { case 'j': $date->subDay(1); break; case 'h': $date->subHour(1); break; case 'm': default: $date->subMinute(1); break; } } return false; }
/** * This allow with a config file, to change the cookie_domain of the session. * Set "session.domain" directive in application.ini to change this. * * @param string $namespace * @param string $member */ public function __construct($namespace = self::NAMESPACE_DEFAULT, $member = self::MEMBER_DEFAULT) { $cookieDomain = Centurion_Config_Manager::get('session.domain', $_SERVER['SERVER_NAME']); if ($cookieDomain !== null) { Zend_Session::setOptions(array('cookie_domain' => $cookieDomain)); } parent::__construct($namespace, $member); }
public function setView(Zend_View_Interface $view) { static $first = true; parent::setView($view); if ($first && null !== ($defaultTitle = Centurion_Config_Manager::get('resources.layout.configs.headTitle.default'))) { $this->set($defaultTitle); } $first = false; }
/** * @param $filename * @return array with 2 keys: height and width */ protected function _getImageSize($filename) { if (!is_file($filename)) { $filename = Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $filename; } $adapter = Centurion_Image::factory(); $adapter->open($filename); return array('height' => $adapter->getSourceHeight(), 'width' => $adapter->getSourceWidth()); }
/** * Retrieve the current site. * * @return Sites_Model_DbTable_Row_Site * @throws Centurion_Exception When the current site was not found */ public function getCurrent() { $options = Centurion_Config_Manager::get('centurion'); if (!array_key_exists('site_id', $options)) { throw new Centurion_Exception("You're using the Centurion \"sites framework\" without having set the \"site_id\" setting in your application.ini. " . "Create a site in your database and set the \"centurion.site_id\" setting to fix this error."); } if (!isset(self::$_sites[$options['site_id']])) { self::$_sites[$options['site_id']] = $this->get(array($this->_primary => $options['site_id'])); } return self::$_sites[$options['site_id']]; }
public function init() { $options = Centurion_Config_Manager::get('media'); $this->_filename = new Centurion_Form_Element_FileTable(sprintf('filename_%s', $this->getName())); $this->_filename->getPluginLoader(Zend_Form_Element_File::TRANSFER_ADAPTER)->addPrefixPath('Centurion_File_Transfer_Adapter', 'Centurion/File/Transfer/Adapter/'); if (null !== $this->getAttrib('adapter')) { $this->_filename->setTransferAdapter($this->getAttrib('adapter')); } $this->_filename->setDestination($options['uploads_dir'])->addValidator('Count', false, 1)->addValidator('Size', false, 4194304)->addValidator('Extension', false, $this->_extension); $this->addElement($this->_filename); $this->removeElement('_XSRF'); }
/** * (non-PHPdoc) * @see Centurion/Contrib/core/traits/Version/Model/Core_Traits_Version_Model_DbTable::init() */ public function init() { parent::init(); $this->_localizedColsPrefix .= $this->_modelName . '_'; if (false === Centurion_Config_Manager::get('translation.default_language', false)) { throw new Centurion_Traits_Exception('no default language have been set in the configuration. Please add a \'translation.default_language\' entry'); } $this->_languageRefRule = $this->_addReferenceMapRule('language', 'language_id', 'Translation_Model_DbTable_Language'); $referenceMap = $this->_referenceMap; $referenceMap['original'] = array('columns' => 'original_id', 'refColumns' => 'id', 'refTableClass' => get_class($this->_model), 'onDelete' => Zend_Db_Table_Abstract::CASCADE, 'onUpdate' => Zend_Db_Table_Abstract::CASCADE); $referenceMap['language'] = array('columns' => 'language_id', 'refColumns' => 'id', 'refTableClass' => 'Translation_Model_DbTable_Language', 'onDelete' => Zend_Db_Table_Abstract::CASCADE, 'onUpdate' => Zend_Db_Table_Abstract::CASCADE); Centurion_Signal::factory('on_select_joinInner')->connect(array($this, 'onJoinInner'), $this->_model); }
protected function _initZFDebug() { if (Centurion_Config_Manager::get('zfdebug')) { $this->bootstrap('frontController'); $frontController = $this->getResource('frontController'); $options = array('plugins' => array('Variables', 'File' => array('base_path' => APPLICATION_PATH), 'Memory', 'Time', 'Registry', 'Exception', 'Cache' => array('backend' => array('core' => $this->_getCache('core')->getBackend(), 'view' => $this->_getCache('view')->getBackend(), '_page' => $this->_getCache('_page')->getBackend())))); if ($this->hasPluginResource('db')) { $this->bootstrap('db'); $db = $this->getPluginResource('db')->getDbAdapter(); $options['plugins']['Database']['adapter'] = $db; } $debug = new Centurion_ZFDebug_Controller_Plugin_Debug($options); $frontController->registerPlugin($debug); } }
public function editAction() { $row = $this->_helper->getObjectOr404($this->_model, array('id' => $this->_getParam('id'))); $types = Centurion_Config_Manager::get('admin.navigation.types'); if ($row->proxy !== null) { foreach ($types as $type) { if (isset($type['className']) && $row->proxy->getTable() instanceof $type['className']) { if (isset($type['urlEdit'])) { $type['urlEdit']['_next'] = urlencode($this->view->url(array('action' => 'index'))); $type['urlEdit']['id'] = $row->proxy->id; $this->_redirect($this->view->url($type['urlEdit'])); die; } } } } parent::editAction(); }
public function isValid($ticket = null, $actionUrl = null, $lifeTime = null) { if (null === $ticket) { $ticket = Zend_Controller_Front::getInstance()->getRequest()->getParam('ticket'); if (null === $ticket) { return false; } } $actionUrl = $this->_getActionUrl($actionUrl); if (null === $lifeTime) { $lifeTime = Centurion_Config_Manager::get('ticket.lifetime'); } list($lifetimeValue, $lifetimeUnit) = sscanf($lifeTime, '%d%s'); $lifetimeUnit = strtolower($lifetimeUnit); $date = new Zend_Date(); switch ($lifetimeUnit) { case 'j': case 'd': $date->setHour(0); case 'h': $date->setMinute(0); case 'm': default: $date->setSecond(0); } for ($i = 0; $i < $lifetimeValue; $i++) { if ($ticket === $this->getKey($actionUrl, $date)) { return true; } switch ($lifetimeUnit) { case 'j': $date->subDay(1); break; case 'h': $date->subHour(1); break; case 'm': default: $date->subMinute(1); break; } } return false; }
public static function generateTmx() { $languageRowSet = Centurion_Db::getSingleton('translation/language')->all(); $translationTable = Centurion_Db::getSingleton('translation/translation'); $uidTable = Centurion_Db::getSingleton('translation/uid'); foreach ($languageRowSet as $languageRow) { $implementation = new DOMImplementation(); $dtd = $implementation->createDocumentType('tmx', '', 'http://www.lisa.org/fileadmin/standards/tmx14.dtd.txt'); $dom = $implementation->createDocument('', '', $dtd); $dom->encoding = 'UTF-8'; $dom->version = '1.0'; $dom->formatOutput = true; $root = $dom->createElement('tmx'); $root->setAttribute('version', '1.4'); $header = $dom->createElement('header'); $header->setAttribute('creationtool', 'Centurion'); $header->setAttribute('creationtoolversion', '1.0.0'); $header->setAttribute('datatype', 'winres'); $header->setAttribute('segtype', 'sentence'); $header->setAttribute('adminlang', 'en-us'); $header->setAttribute('srclang', 'en-us'); $header->setAttribute('o-tmf', 'abc'); $root->appendChild($header); $body = $dom->createElement('body'); $select = $uidTable->select(false)->reset(Zend_Db_Select::COLUMNS)->from(array('a' => 'translation_uid', 'a.uid'))->setIntegrityCheck(false)->join(array('b' => 'translation_translation'), 'b.uid_id = a.id and b.language_id = ' . $languageRow->id, 'b.translation'); $translationRowset = $uidTable->fetchAll($select); foreach ($translationRowset as $translationRow) { $tu = $dom->createElement('tu'); $tu->setAttribute('tuid', $translationRow->uid); $tuv = $dom->createElement('tuv'); $tuv->setAttribute('xml:lang', $languageRow->locale); $seg = $dom->createElement('seg'); $seg->appendChild($dom->createCDATASection(null !== $translationRow->translation ? $translationRow->translation : $translationRow->uid)); $tuv->appendChild($seg); $tu->appendChild($tuv); $body->appendChild($tu); } $root->appendChild($body); $dom->appendChild($root); $dom->save(Centurion_Config_Manager::get('resources.translate.data') . DIRECTORY_SEPARATOR . sprintf("%s.xml", $languageRow->locale)); } }
public function preDispatch() { $bootstrap = $this->getActionController()->getInvokeArg('bootstrap'); $config = $bootstrap->getOptions(); $module = $this->getRequest()->getModuleName(); $controller = $this->getRequest()->getControllerName(); $layoutScript = null; if (isset($config['resources']['layout']['admin']['layout']) && isset($config['admin']['controllers']) && in_array($controller, $config['admin']['controllers'])) { $layoutScript = $config['resources']['layout']['admin']['layout']; } elseif (isset($config['resources']['layout']['layout'])) { $layoutScript = $config['resources']['layout']['layout']; } if (isset($config['resources']['layout']['configs'][$layoutScript])) { Centurion_Config_Manager::set('resources.layout.configs', $config['resources']['layout']['configs'][$layoutScript]); } if (null !== $layoutScript) { //$this->getRequest()->setParam('_layout', $layoutScript); $this->getActionController()->getHelper('layout')->setLayout($layoutScript); } }
public function _getRawData($col) { $spec = $this->getTable()->getTranslationSpec(); if ($this->_data[Translation_Traits_Model_DbTable::ORIGINAL_FIELD] && in_array($col, $spec[Translation_Traits_Model_DbTable::SET_NULL_FIELDS])) { Centurion_Db_Table_Abstract::setFiltersStatus(false); $originalRow = $this->getTable()->get(array('id' => $this->_data[Translation_Traits_Model_DbTable::ORIGINAL_FIELD])); Centurion_Db_Table_Abstract::setFiltersStatus(true); return $originalRow->{$col}; } if (!array_key_exists($this->_prefix . $col, $this->_data) || !in_array($col, $spec[Translation_Traits_Model_DbTable::TRANSLATED_FIELDS])) { return $this->_data[$col]; } if (Centurion_Config_Manager::get(Translation_Traits_Common::GET_DEFAULT_CONFIG_KEY, Translation_Traits_Common::NOT_EXISTS_GET_DEFAULT)) { if (null == $this->_data[$this->_prefix . $col]) { return $this->_data[$col]; } } if (isset($this->_data[$this->_prefix . $col])) { return $this->_data[$this->_prefix . $col]; } else { return $this->_data[$col]; } }
protected function getTestableModel() { global $application; $bootstrap = $application->getBootstrap(); $bootstrap->bootstrap('FrontController'); $bootstrap->bootstrap('modules'); $bootstrap->bootstrap('db'); $moduleRessource = $bootstrap->getResource('modules'); if (null == $this->_testableModel) { $this->_testableModel = array(); $front = Centurion_Controller_Front::getInstance(); $modules = $front->getControllerDirectory(); $moduleEnabled = Centurion_Config_Manager::get('resources.modules'); foreach ($modules as $moduleName => $module) { if (!in_array($moduleName, $moduleEnabled)) { continue; } $dbTableDir = realpath($module . '/../models/DbTable'); if (!file_exists($dbTableDir)) { continue; } $dir = new Centurion_Iterator_DbTableFilter($dbTableDir); foreach ($dir as $fileInfo) { $filename = $fileInfo->getFilenameWithoutExtension(); $className = sprintf('%s_Model_DbTable_%s', ucfirst($moduleName), $filename); $model = Centurion_Db::getSingletonByClassName($className); if (method_exists($model, 'getTestCondition')) { $testCondition = $model->getTestCondition(); if (null !== $testCondition) { $this->_testableModel[] = array($model, $model->getTestCondition()); } } } } } return $this->_testableModel; }
protected function setUp() { $this->setBrowser("*chrome"); $this->setBrowserUrl(Centurion_Config_Manager::get('test.serverurl')); }
protected function _loadIfNotLoaded($filename) { if ($this->_movie === null) { $this->_movie = Centurion_Movie::factory(Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $filename); } }
/** * Initialize DbTable for each loaded module. * * @return void */ protected function _initDbTable() { $cache = $this->_getCache('core'); if (!($references = $cache->load('references_apps'))) { $this->bootstrap('FrontController'); $this->bootstrap('db'); $this->bootstrap('modules'); $front = $this->getResource('FrontController'); $modules = $front->getControllerDirectory(); $references = array(); $moduleEnabled = Centurion_Config_Manager::get('resources.modules'); foreach ($modules as $moduleName => $module) { if (!in_array($moduleName, $moduleEnabled)) { continue; } $dbTableDir = realpath($module . '/../models/DbTable'); if (!file_exists($dbTableDir)) { continue; } $dir = new Centurion_Iterator_DbTableFilter($dbTableDir); foreach ($dir as $fileInfo) { $filename = $fileInfo->getFilenameWithoutExtension(); $className = sprintf('%s_Model_DbTable_%s', ucfirst($moduleName), $filename); $model = Centurion_Db::getSingletonByClassName($className); $meta = $model->getMeta(); $metaData = $model->info('metadata'); foreach ($model->getReferenceMap() as $key => $referenceMap) { $refTableClass = $referenceMap['refTableClass']; $referencedModel = Centurion_Db::getSingletonByClassName($refTableClass); $plural = true; if (isset($metaData[$referenceMap['columns']]['UNIQUE']) && $metaData[$referenceMap['columns']]['UNIQUE'] == true) { $plural = false; } if ($plural) { $dependentTableKey = $meta['verbosePlural']; } else { $dependentTableKey = $meta['verboseName']; } if (array_key_exists($dependentTableKey, $referencedModel->getDependentTables())) { continue; } if (!array_key_exists($refTableClass, $references)) { $references[$refTableClass] = array(); } $references[$refTableClass][$dependentTableKey] = $className; } } } $cache->save($references, 'references_apps'); } Centurion_Db::setReferences($references); }
public function dashboardAction() { $config = Centurion_Config_Manager::get('admin.dashboard'); $this->_helper->widgetRenderer($config); }
public function update(array $data, $where) { $currentFileRow = $this->fetchRow($where); if (null !== $currentFileRow->proxy_model) { $oldProxyTableClass = $currentFileRow->proxy_model; } foreach ($currentFileRow->duplicates as $duplicate) { $duplicate->delete(); } foreach ($this->_dependentProxies as $key => $dependentProxy) { $proxyTable = Centurion_Db::getSingletonByClassName($dependentProxy); $mimes = array_keys($proxyTable->getMimeTypes()); if (!in_array($data['mime'], $mimes)) { continue; } if (in_array($data['mime'], $mimes)) { $newProxyTableClass = $dependentProxy; break; } } if (!isset($data['sha1'])) { $data['sha1'] = sha1_file(Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $data['local_filename']); } if (isset($oldProxyTableClass) && $oldProxyTableClass != $newProxyTableClass) { $currentProxyRow = Centurion_Db::getRow($oldProxyTableClass, $currentFileRow->proxy_pk); if (null !== $currentProxyRow) { $data = array_merge($data, array('proxy_model' => null, 'proxy_pk' => null)); $currentProxyRow->delete(); } } if (null !== $newProxyTableClass) { $newProxyTable = Centurion_Db::getSingletonByClassName($newProxyTableClass); if (isset($oldProxyTableClass) && $oldProxyTableClass == $newProxyTableClass) { $pk = $newProxyTable->update($data, $newProxyTable->getAdapter()->quoteInto('id = ?', $currentFileRow->proxy_pk)); } else { $pk = $newProxyTable->insert($data); $data['proxy_model'] = $newProxyTableClass; } $data['proxy_pk'] = $pk; } if (array_key_exists(self::BELONG_TO, $data)) { list($model, $pk) = $this->_setupProxyBelong($data[self::BELONG_TO]); $data = array_merge($data, array('belong_model' => $model, 'belong_pk' => $pk)); unset($data[self::BELONG_TO]); } return parent::update($data, $where); }
public function getAction() { $fileId = $this->_getParam('file_id'); if (null === $fileId && $this->getRequest()->getServer('REDIRECT_QUERY_STRING')) { // Here, it's for an same apache server without urlrewriting list($id, $fileid, $key, $effect) = explode(':', $this->getRequest()->getServer('REDIRECT_QUERY_STRING')); $this->_request->setParam('id', $id); $this->_request->setParam('fileid', $fileId); $this->_request->setParam('key', $key); $this->_request->setParam('effect', $effect); // If the server don't have urlrewriting, he could (must?) use ErrorDocument 404 in .htaccess $this->getResponse()->setHttpResponseCode(200); } $fileId = bin2hex(Centurion_Inflector::urlDecode($this->_request->getParam('file_id'))); $key = bin2hex(Centurion_Inflector::urlDecode($this->_request->getParam('key'))); if (trim($this->_request->getParam('id')) == '') { $id = $fileId; } else { $id = bin2hex(Centurion_Inflector::urlDecode($this->_request->getParam('id'))); } if (!($effectPath = $this->_request->getParam('effect'))) { return $this->_forward('get', 'file'); } $media = Centurion_Config_Manager::get('media'); $fileRow = $this->_helper->getObjectOr404('media/file', array('id' => $id)); $mediaAdapter = Media_Model_Adapter::factory($media['adapter'], $media['params']); $this->forward404If(!$mediaAdapter->isValidKey($fileRow, $key, $effectPath), sprintf("key '%s' for file '%s' is not valid or expired", $key, $fileRow->pk)); // TODO : modifier le file exist sur le bon chemin (cf getFullpath) if (!file_exists($media['uploads_dir'] . DIRECTORY_SEPARATOR . $fileRow->local_filename)) { $this->_redirect('/layouts/backoffice/images/px.png', array('code' => 307)); } $effects = Media_Model_DbTable_Image::effectsString2Array($effectPath); $imageAdapter = Centurion_Image::factory(); $imagePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid(); $imageAdapter->open($media['uploads_dir'] . DIRECTORY_SEPARATOR . $fileRow->local_filename); foreach ($effects as $key => $effect) { switch ($key) { // case 'adaptiveresize': // $effect = array_merge(array('width' => null, 'height' => null), $effect); // $imageAdapter->adaptiveResize($effect['width'], $effect['height']); // break; case 'adaptiveresize': $effect = array_merge(array('width' => null, 'height' => null), $effect); $imageAdapter->adaptiveResize($effect[1]['width'], $effect[1]['height']); break; case 'cropcenter': $effect = array_merge(array('width' => null, 'height' => null), $effect); $imageAdapter->cropFromCenter($effect['width'], $effect['height']); break; case 'resize': $effect = array_merge(array('maxWidth' => null, 'maxHeight' => null, 'minWidth' => null, 'minHeight' => null), $effect); $imageAdapter->resize($effect['maxWidth'], $effect['maxHeight'], $effect['minWidth'], $effect['minHeight']); break; case 'crop': $effect = array_merge(array('x' => null, 'y' => null, 'width' => null, 'height' => null), $effect); $imageAdapter->crop($effect['x'], $effect['y'], $effect['width'], $effect['height']); break; case 'cropcenterresize': $effect = array_merge(array('width' => null, 'height' => null), $effect); $imageAdapter->cropAndResizeFromCenter($effect['width'], $effect['height']); break; case 'cropedgeresize': $effect = array_merge(array('width' => null, 'height' => null, 'edge' => null), $effect); $imageAdapter->cropAndResizeFromEdge($effect['width'], $effect['height'], $effect['edge']); break; case 'IMG_FILTER_NEGATE': $imageAdapter->effect('IMG_FILTER_NEGATE'); break; case 'IMG_FILTER_GRAYSCALE': $imageAdapter->effect('IMG_FILTER_GRAYSCALE'); break; case 'IMG_FILTER_BRIGHTNESS': $effect = array_merge(array('degree' => null), $effect); $imageAdapter->effect('IMG_FILTER_BRIGHTNESS', $effect['degree']); break; case 'IMG_FILTER_CONTRAST': $effect = array_merge(array('degree' => null), $effect); $imageAdapter->effect('IMG_FILTER_CONTRAST', $effect['degree']); break; case 'IMG_FILTER_COLORIZE': $effect = array_merge(array('red' => null, 'green' => null, 'blue' => null), $effect); $imageAdapter->effect('IMG_FILTER_COLORIZE', $effect['red'], $effect['green'], $effect['blue']); break; case 'IMG_FILTER_EDGEDETECT': $imageAdapter->effect('IMG_FILTER_EDGEDETECT'); break; case 'IMG_FILTER_EMBOSS': $imageAdapter->effect('IMG_FILTER_EMBOSS'); break; case 'IMG_FILTER_SELECTIVE_BLUR': $imageAdapter->effect('IMG_FILTER_SELECTIVE_BLUR'); break; case 'IMG_FILTER_GAUSSIAN_BLUR': $imageAdapter->effect('IMG_FILTER_GAUSSIAN_BLUR'); break; case 'IMG_FILTER_MEAN_REMOVAL': $imageAdapter->effect('IMG_FILTER_MEAN_REMOVAL'); break; case 'IMG_FILTER_SMOOTH': $imageAdapter->effect('IMG_FILTER_SMOOTH', $effect['degree']); break; case 'IMG_FILTER_PIXELATE': $imageAdapter->effect('IMG_FILTER_PIXELATE', $effect['size'], $effect['pixelate']); } } if (!is_dir(dirname($imagePath))) { mkdir(dirname($imagePath), 0777, true); } $imageAdapter->save($imagePath, $fileRow->mime); $isSaved = $mediaAdapter->save($imagePath, $fileRow->getRelativePath($effectPath, false, true)); if ($isSaved) { Centurion_Db::getSingleton('media/duplicate')->insert(array('file_id' => $fileRow->id, 'adapter' => $media['adapter'], 'params' => serialize($media['params']), 'dest' => $fileRow->getRelativePath($effectPath, false, true))); return $this->getHelper('redirector')->gotoUrlAndExit($fileRow->getStaticUrl($effectPath) . '&'); } $offset = 24 * 60 * 60 * 365; $this->getResponse()->setHeader('Content-type', $fileRow->mime)->setHeader('Content-Length', filesize($imagePath))->setHeader('Content-Disposition', sprintf('inline; filename="%s";', $fileRow->filename))->setHeader('Cache-Control', sprintf('max-age=%d, public', $offset))->setHeader('Expires', sprintf('%s GMT', gmdate('D, d M Y H:i:s', time() + $offset)))->sendHeaders(); while (@ob_end_flush()) { } $fp = fopen($imagePath, 'rb'); fpassthru($fp); fclose($fp); if (file_exists($imagePath)) { unlink($imagePath); } $this->getResponse()->clearHeaders(); }
/** * Set options for Centurion_Config_Manager * * @param array $options Options * @return $this */ public function setOptions(array $options) { parent::setOptions($options); Centurion_Config_Manager::add($options); return $this; }
/** * * @param string $path * @param array $options */ protected function _callApi($path, $options) { $restClient = $this->_getClient(); $restClient->getHttpClient()->resetParameters(); if (!isset($options['login'])) { $options['login'] = Centurion_Config_Manager::get('centurion.service.bitlty.login'); } if (!isset($options['apiKey'])) { $options['apiKey'] = Centurion_Config_Manager::get('centurion.service.bitlty.apiKey'); } $param['format'] = 'json'; $this->_response = $restClient->restGet($path, $options); switch ($param['format']) { case 'json': $this->_data = Zend_Json::decode($this->_response->getBody()); break; case 'xml': throw new Exception('Not yet implemented. Please use json format.'); break; } $this->_checkErrors(); return $this->_data['data']; }
/** * Test if a given ticket is valid for a given url and a given lifetime. * * @param null|string $ticket the ticket to test * @param string|array|null $actionUrl the url * @param null $lifeTime * @return bool if valid or not * @TODO test $ticket before. it's a sha1 so only hexa and 40 string lenght */ public function isValid($ticket = null, $actionUrl = null, $lifeTime = null) { if (null === $ticket) { $ticket = $this->getRequest()->getParam('ticket'); //If not ticket in request, it could only be false if (null === $ticket) { return false; } } $actionUrl = $this->_getActionUrl($actionUrl); if (null === $lifeTime) { $lifeTime = Centurion_Config_Manager::get('ticket.lifetime'); } list($lifetimeValue, $lifetimeUnit) = sscanf($lifeTime, '%d%s'); $lifetimeUnit = strtolower($lifetimeUnit); $date = $this->_getDate(); //In order to test if current ticket is valid, we will generate all ticket from now to maximum lifetime //and test if we find the current for ($i = 0; $i < $lifetimeValue; $i++) { $key = $this->getKey($actionUrl, $date); if ($ticket === $key) { return true; } //We decrement the date by 1 unit switch ($lifetimeUnit) { case 'j': $date->subDay(1); break; case 'h': $date->subHour(1); break; case 'm': default: $date->subMinute(1); break; } } return false; }
/** * Retrieve the profile attached to the user instance. * * @return Centurion_Db_Table_Row_Abstract */ public function getProfile() { if (null === $this->_profile) { $options = Centurion_Config_Manager::get('centurion'); if (!isset($options['auth_profile'])) { throw new Centurion_Exception('No site profile module available: you have to set a centurion.auth_profile in your application.ini'); } if (!class_exists($options['auth_profile'])) { throw new Centurion_Exception('The class in centurion.auth_profile option does not exists.'); } $this->_profile = Centurion_Db::getSingletonByClassName($options['auth_profile'])->findOneByUserId($this->pk); } return $this->_profile; }
/** * Clears all current config parameters. * @static * @return void */ public static function clear() { self::$_config = array(); }
public function delete() { if ($this->file_id !== null && $this->getTable()->select(true)->where('file_id=?', $this->file_id)->count() == 1) { unlink(Centurion_Config_Manager::get('media.uploads_dir') . DIRECTORY_SEPARATOR . $this->local_filename); } parent::delete(); }