/** * This method will instantiate the object, configure it and return it * * @return Zend_Cache_Manager */ public static function getInstance() { $config = App_DI_Container::get('ConfigObject'); $cloudFrontConfig = array('accessKey' => $config->amazon->aws_access_key, 'privateKey' => $config->amazon->aws_private_key, 'distributionId' => $config->amazon->cloudfront->distribution_id); $cloudFront = new App_Amazon_CloudFront($cloudFrontConfig); return $cloudFront; }
/** * This method will instantiate the object, configure it and return it * * @return Zend_Cache_Manager */ public static function getInstance() { $config = App_DI_Container::get('ConfigObject'); $snsConfig = array('accessKey' => $config->amazon->aws_access_key, 'privateKey' => $config->amazon->aws_private_key, 'host' => $config->amazon->sns->host); $snsConfig['topicArn'] = $config->amazon->sns->topics->frontend_errors->arn; $sns = new App_Amazon_SNS_Topic($snsConfig); return $sns; }
/** * Return the url of the file in the CDN * * @param string $file * @param int $version * @access public * @return string **/ public function getUrl($file, $width = 0, $height = 0) { if (!empty($width) || !empty($height)) { $file = sprintf('%s_%d_%d.png', substr($file, 0, strrpos($file, '.')), $width, $height); } $cdnUrls = App_DI_Container::get('ConfigObject')->amazon->cloudfront->url->toArray(); shuffle($cdnUrls); return sprintf('http://%s/%s', array_pop($cdnUrls), $file); }
/** * Overrides init() in App_Form * * @access public * @return void */ public function init() { parent::init(); $config = App_DI_Container::get('ConfigObject'); // add an anti-CSRF token to all forms $csrfHash = new Zend_Form_Element_Hash('csrfhash'); $csrfHash->setOptions(array('required' => TRUE, 'filters' => array('StringTrim', 'StripTags'), 'validators' => array('NotEmpty'), 'salt' => $config->security->csrfsalt . get_class($this))); $this->addElement($csrfHash); }
/** * Remove a file from the CDN and S3 * * @return void */ public function removeFromCDN() { //Remove from S3 App_DI_Container::get('S3StorageEngine')->deleteItem($this->filename, array(Zend_Cloud_StorageService_Adapter_S3::BUCKET_NAME => App_DI_Container::get('ConfigObject')->amazon->s3->assets_bucket)); //Invalidate the image in the CDN if (!App_DI_Container::get('CloudFront')->invalidate($this->filename)) { App_Logger::log(sprintf('Error removing %s from CDN', $this->filename), Zend_Log::ERR); } }
/** * This method will instantiate the object, configure it and return it * * @return Zend_Cache_Manager */ public static function getInstance() { $manager = new Zend_Cache_Manager(); //Add the templates to the manager foreach (App_DI_Container::get('ConfigObject')->cache->toArray() as $k => $v) { $manager->setCacheTemplate($k, $v); } return $manager; }
/** * This method will instantiate the object, configure it and return it * * @return Zend_Cache_Manager */ public static function getInstance() { $config = App_DI_Container::get('ConfigObject'); $gearmanClient = new GearmanClient(); if (!empty($config->gearman->servers)) { $gearmanClient->addServers($config->gearman->servers->toArray()); } else { $gearmanClient->addServer(); } return $gearmanClient; }
/** * Convenience method to run the command * * @param string $name * @param mixed $args * @return boolean */ public function onCommand($name, $args) { if (strcasecmp($name, $this->_commandName) !== 0) { return FALSE; } //Do the command if (!empty($args['text'])) { $token = new Zend_Oauth_Token_Access(); $token->setToken(App_DI_Container::get('ConfigObject')->twitter->access_token); $token->setTokenSecret(App_DI_Container::get('ConfigObject')->twitter->access_token_secret); $twitter = new Zend_Service_Twitter(array('username' => App_DI_Container::get('ConfigObject')->twitter->username, 'accessToken' => $token)); $response = $twitter->status->update($args['text']); return $response->isSuccess(); } return FALSE; }
/** * undocumented function * * @param string $url * @access private * @return array **/ private static function _performRequest($url) { $cache = App_DI_Container::get('CacheManager')->getCache('memcache'); if (($result = $cache->load(sha1($url))) === FALSE) { $client = new Zend_Http_Client($url); $client->setMethod(Zend_Http_Client::GET); $response = $client->request(); if ($response->getStatus() == 200) { $result = $response->getBody(); $cache->save($result, sha1($url), array(), 86400); } else { $result = FALSE; } } return $result; }
/** * Convenience method to run the command * * @param string $name * @param mixed $args * @return boolean */ public function onCommand($name, $args) { if (strcasecmp($name, $this->_commandName) !== 0) { return FALSE; } //Do the command if (count($args) && (Zend_Registry::get('IS_PRODUCTION') || App_DI_Container::get('ConfigObject')->facebook->testing)) { $args['access_token'] = App_DI_Container::get('ConfigObject')->facebook->access_token; $url = 'https://graph.facebook.com/YOUR_PAGE/feed'; $client = new Zend_Http_Client($url); $client->setMethod(Zend_Http_Client::POST); $client->resetParameters(); $client->setParameterPost($args); $response = $client->request(); return $response->isSuccessful(); } return FALSE; }
/** * Write messages to the log and send notifications to email if configured * * @param string $msg * @param int * @return void */ public static function log($msg, $level = Zend_Log::INFO) { App_DI_Container::get('GeneralLog')->log($msg, $level); $config = App_DI_Container::get('ConfigObject'); if ($config->system->notifications->notify_on_errors) { if ($config->system->notifications->use_sns) { if ($level == Zend_Log::ERR) { App_DI_Container::get('SNSFrontendErrors')->publish('Critical Error', $msg); } if ($level == Zend_Log::INFO) { App_DI_Container::get('SNSFrontendInfo')->publish('Info event', $msg); } } else { $command = new App_Command_SendEmail(); $command->onCommand('sendEmail', array('type' => 'Notification', 'recipients' => $config->system->notifications->recipients->toArray(), 'message' => $msg, 'level' => $level)); } } }
/** * Convenience method to get the paginator * * @param mixed $array * @return void */ protected function _getPaginator($array) { $paginator = Zend_Paginator::factory($array); $paginator->setCurrentPageNumber($this->_getPage()); $paginator->setItemCountPerPage(App_DI_Container::get('ConfigObject')->paginator->items_per_page); return $paginator; }
/** * Returns a paginator or an array, depending on the value * provided for the $paginate field * * @param Zend_Db_Select $select * @param int $page * @param bool $paginate * @access protected * @return mixed */ protected function _paginate($select, $page, $paginate) { if (NULL === $paginate) { $paginate = $this->_returnPaginators; } if (!$paginate) { return $this->fetchAll($select); } $paginator = Zend_Paginator::factory($select); $paginator->setCurrentPageNumber($page); $paginator->setItemCountPerPage(App_DI_Container::get('ConfigObject')->paginator->items_per_page); return $paginator; }
/** * Overrides getAll() in App_Model * * @param int $page * @access public * @return Zend_Paginator */ public function findAll($page = 1) { $paginator = $this->fetchAll(); $privileges = array(); foreach ($paginator as $privilege) { $privilege->flag = $privilege->findParentRow('Flag'); $privilege->flagName = $privilege->flag->name; $privileges[] = $privilege; } $paginator = Zend_Paginator::factory($privileges); $paginator->setCurrentPageNumber($page); $paginator->setItemCountPerPage(App_DI_Container::get('ConfigObject')->paginator->items_per_page); return $paginator; }
/** * Hashes a password using the salt in the app.ini * * @param string $password * @static * @access public * @return string */ public static function hashPassword($password) { $config = App_DI_Container::get('ConfigObject'); $module = strtolower(CURRENT_MODULE); return sha1($config->{$module}->security->passwordsalt . $password); }
/** * Initialize the translation system * * @return void */ protected function _initTranslator() { $this->bootstrap('Locale'); //Extract some info from the request $lang = Zend_Registry::get('Zend_Locale')->getLanguage(); $translationFile = ROOT_PATH . '/library/App/Translations/' . $lang . '.mo'; //Check if the translations file is available, if not fallback default to english if (!file_exists($translationFile)) { $translationFile = APPLICATION_PATH . '/modules/' . CURRENT_MODULE . '/translations/en.mo'; } $options = array('adapter' => 'gettext', 'content' => $translationFile, 'locale' => $lang, 'disableNotices' => App_DI_Container::get('ConfigObject')->translations->disable_notices, 'logMessage' => "Missing translation: %message%", 'logUntranslated' => App_DI_Container::get('ConfigObject')->translations->log_missing_translations); //Create a zend_log for missing translations if (App_DI_Container::get('ConfigObject')->translations->log_missing_translations) { $pathLog = ROOT_PATH . '/logs/' . CURRENT_MODULE . '/missing_translations/' . date('Ymd') . '_' . $lang . '.log'; $writer = new Zend_Log_Writer_Stream($pathLog); $logger = new Zend_Log($writer); $options['log'] = $logger; } $translate = new Zend_Translate($options); Zend_Registry::set('Zend_Translate', $translate); Zend_Validate_Abstract::setDefaultTranslator($translate); Zend_Form::setDefaultTranslator($translate); }
/** * Store the Acl in the cache * * @return void */ private static function _storeInCache($acl = NULL) { if (is_null($acl) && App_FlagFlippers_Manager::_checkIfExist()) { $acl = App_FlagFlippers_Manager::_getFromRegistry(); } if (empty($acl)) { throw new Exception('You must provide a valid Acl in order to store it'); } $cacheHandler = App_DI_Container::get('CacheManager')->getCache('default'); $cacheHandler->save($acl, App_FlagFlippers_Manager::$indexKey); }
/** * This method will instantiate the object, configure it and return it * * @return Zend_Cache_Manager */ public static function getInstance() { $bitlyService = new App_Service_ShortUrl_BitLy(App_DI_Container::get('ConfigObject')->bitly->username, App_DI_Container::get('ConfigObject')->bitly->api_key); return $bitlyService; }
/** * Called automatically after creating the object * * @return void */ public function init() { //Retrieve the main logger from the registry $this->logger = App_DI_Container::get('GeneralLog'); }
/** * Store the email in the log * * @param string $msg * @param string $level * @return void */ private function _log($msg, $level = Zend_Log::INFO) { App_DI_Container::get('MailerLog')->log($msg, $level); }
/** * This method will instantiate the object, configure it and return it * * @return Zend_Cache_Manager */ public static function getInstance() { $config = App_DI_Container::get('ConfigObject'); $storage = Zend_Cloud_StorageService_Factory::getAdapter(array(Zend_Cloud_StorageService_Factory::STORAGE_ADAPTER_KEY => 'Zend_Cloud_StorageService_Adapter_S3', Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY => $config->amazon->aws_access_key, Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY => $config->amazon->aws_private_key)); return $storage; }
/** * Inits the Zend Paginator component * * @access protected * @return void */ protected function _initPaginator() { Zend_Paginator::setDefaultScrollingStyle(App_DI_Container::get('ConfigObject')->paginator->scrolling_style); Zend_View_Helper_PaginationControl::setDefaultViewPartial('default.phtml'); }