Example #1
0
 /**
  * Authenticate a user.
  * @param Zend_Controller_Request_Abstract $request The current request
  * @param Zend_Controller_Response_Abstract $response The current response
  * @return Array|Boolean User data, or FALSE
  */
 public function authenticate(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
 {
     $authVars = new Garp_Util_Configuration($this->_getAuthVars()->toArray());
     $authVars->obligate('model')->obligate('identityColumn')->obligate('credentialColumn')->setDefault('hashMethod', 'MD5')->setDefault('salt', '');
     if (!$request->getPost($authVars['identityColumn']) || !$request->getPost($authVars['credentialColumn'])) {
         $this->_addError('Insufficient data received');
         return false;
     }
     $identityValue = $request->getPost($authVars['identityColumn']);
     $credentialValue = $request->getPost($authVars['credentialColumn']);
     $ini = Zend_Registry::get('config');
     $sessionColumns = null;
     if (!empty($ini->auth->login->sessionColumns)) {
         $sessionColumns = $ini->auth->login->sessionColumns;
         $sessionColumns = explode(',', $sessionColumns);
     }
     $model = new Model_AuthLocal();
     try {
         $result = $model->tryLogin($identityValue, $credentialValue, $authVars, $sessionColumns);
         return $result->toArray();
     } catch (Garp_Auth_Adapter_Db_UserNotFoundException $e) {
         $this->_addError('The email address is not found');
     } catch (Garp_Auth_Adapter_Db_InvalidPasswordException $e) {
         $this->_addError('The password is invalid');
     }
     return false;
 }
Example #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;
 }
Example #3
0
 /**
  * Subscribe the provided email to a list.
  * @param Array|Garp_Util_Configuration $options
  * @return StdClass
  */
 public function listSubscribe($options)
 {
     if (!$options instanceof Garp_Util_Configuration) {
         $options = new Garp_Util_Configuration($options);
     }
     $options->obligate('email_address')->obligate('id')->setDefault('merge_vars', array('LNAME' => '', 'FNAME' => ''));
     $options['method'] = 'listSubscribe';
     return $this->_send((array) $options);
 }
Example #4
0
 /**
  * Class constructor
  * @param String $id
  * @param Array $params
  * @return Void
  */
 public function __construct($id, array $config = array())
 {
     // validate given config options
     $config = new Garp_Util_Configuration($config);
     $config->obligate('model')->setDefault('bindingOptions', array());
     if (empty($config['bindingOptions']['bindingModel'])) {
         throw new Garp_Browsebox_Exception('The related filter is only applicable to HABTM relationships and therefore a bindingModel must be configured.');
     }
     $config = (array) $config;
     parent::__construct($id, $config);
 }
Example #5
0
 /**
  * Required keys: to, subject, message OR htmlMessage
  *
  * @param array $params
  * @return void
  */
 protected function _validateParams(array $params)
 {
     $config = new Garp_Util_Configuration($params);
     $config->obligate('to');
     $config->obligate('subject');
     if (!isset($params['message']) && !isset($params['htmlMessage'])) {
         throw new Garp_Util_Configuration_Exception(sprintf(Garp_Util_Configuration::EXCEPTION_MISSINGKEY, 'message OR htmlMessage'));
     }
 }
Example #6
0
 /**
  * Set default options
  *
  * @param array $options
  * @return void
  */
 protected function _setDefaultOptions(&$options)
 {
     $options = new Garp_Util_Configuration($options);
     $options->setDefault('formatForRobots', '%Y-%m-%d')->setDefault('attributes', array());
     $options = (array) $options;
 }
 /**
  * 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();
 }
Example #8
0
 /**
  * Configure the behavior
  * @param Array $config
  * @return Void
  */
 protected function _setup($config)
 {
     $config = new Garp_Util_Configuration($config);
     $config->obligate('contentTypes');
     $this->_config = $config;
 }
Example #9
0
 /**
  * Generate a Facebook facepile.
  *
  * @param array $params Various Facebook URL parameters
  * @param bool $useFacebookPageAsUrl
  * @return string
  */
 public function facebookFacepile(array $params = array(), $useFacebookPageAsUrl = false)
 {
     $this->_needsFacebookInit = true;
     $params = new Garp_Util_Configuration($params);
     $params->setDefault('href', array_key_exists('href', $params) && $params['href'] ? $params['href'] : $this->_getCurrentUrl())->setDefault('max_rows', 1)->setDefault('width', 450)->setDefault('colorscheme', 'light');
     if ($useFacebookPageAsUrl) {
         $this->_setFacebookPageUrlAsHref($params);
     }
     $html = '<fb:facepile ' . $this->_renderHtmlAttribs($params) . '></fb:facepile>';
     return $html;
 }
Example #10
0
 /**
  * Set configuration options. This method makes sure there are usable defaults in place.
  * @param Garp_Util_Configuration $options
  * @return Garp_Browsebox $this
  */
 public function setConfig(Garp_Util_Configuration $options)
 {
     $options->obligate('id')->obligate('model')->setDefault('pageSize', 10)->setDefault('chunkSize', 1)->setDefault('order', null)->setDefault('conditions', null)->setDefault('viewPath', 'partials/browsebox/' . $options['id'] . '.phtml')->setDefault('bindings', array())->setDefault('filters', array())->setDefault('cycle', false)->setDefault('javascriptOptions', new Garp_Util_Configuration())->setDefault('select', null);
     if (!empty($options['filters'])) {
         $options['filters'] = $this->_parseFilters($options['filters']);
     }
     $this->_options = $options;
     return $this;
 }
Example #11
0
 /**
  * Class constructor
  * @param Array $config
  * @return Void
  */
 private function __construct(array $config)
 {
     $config = new Garp_Util_Configuration($config);
     $config->obligate('appId')->obligate('secret');
     $this->_client = $this->_getClient((array) $config);
 }