Ejemplo n.º 1
0
 /**
  * Минификация яваскриптов
  * 
  * @return void
  */
 public function jsAction()
 {
     $this->_response->setHeader('Content-Type', 'text/javascript', true);
     if (isset($this->_params['files'])) {
         $files = explode(',', $this->_params['files']);
         foreach ($files as $key => $file) {
             $file = $this->_jsdir . trim($file) . '.js';
             if (file_exists($file)) {
                 $files[$key] = $file;
             }
         }
         if (!empty($files)) {
             $cacheid = 'minify_js_' . md5(implode(',', $files));
             $this->_cache->setMasterFiles($files);
             if ($this->_cache->test($cacheid)) {
                 $this->_response->setBody($this->_cache->load($cacheid));
             } else {
                 require_once 'Phorm/Plugin/jsmin.php';
                 $str = '';
                 foreach ($files as $file) {
                     $str .= file_get_contents($file) . PHP_EOL;
                 }
                 $js = JSMin::minify($str);
                 $this->_cache->save($js, $cacheid);
                 $this->_response->setBody($js);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /** Perform a curl request based on url provided
  * @access public
  * @param string $method
  * @param array $params
  * @return type
  */
 public function get($method, $params)
 {
     $url = $this->createUrl($method, $params);
     if (!$this->_cache->test(md5($url))) {
         $config = array('adapter' => 'Zend_Http_Client_Adapter_Curl', 'curloptions' => array(CURLOPT_POST => true, CURLOPT_USERAGENT => $_SERVER["HTTP_USER_AGENT"], CURLOPT_FOLLOWLOCATION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_LOW_SPEED_TIME => 1));
         $client = new Zend_Http_Client($url, $config);
         $response = $client->request();
         $data = $response->getBody();
         $this->_cache->save($data);
     } else {
         $data = $this->_cache->load(md5($url));
     }
     return Zend_Json_Decoder::decode($data, Zend_Json::TYPE_OBJECT);
 }
Ejemplo n.º 3
0
 /** Get data from the endpoint
  * @access protected
  * @return string
  */
 protected function getData()
 {
     $key = md5($this->_uri);
     if (!$this->_cache->test($key)) {
         $graph = new EasyRdf_Graph(self::URI . $this->_uri . self::SUFFIX);
         $graph->load();
         $data = $graph->resource(self::URI . $this->_uri);
         $this->_cache->save($data);
     } else {
         $data = $this->_cache->load($key);
     }
     EasyRdf_Namespace::set('dcterms', 'http://purl.org/dc/terms/');
     EasyRdf_Namespace::set('pleiades', 'http://pleiades.stoa.org/places/vocab#');
     return $data;
 }
Ejemplo n.º 4
0
 /** Get the data for a postcode
  * @access public
  * @param string $postcode
  * @return array
  * @throws Pas_Geo_Exception
  */
 public function getData($postcode)
 {
     if ($this->_validator->isValid($postcode)) {
         $postcode = str_replace(' ', '', $postcode);
     } else {
         throw new Pas_Geo_Exception('Invalid postcode sent');
     }
     $key = md5($postcode);
     if (!$this->_cache->test($key)) {
         $response = $this->_get($postcode);
         $this->_cache->save($response);
     } else {
         $response = $this->_cache->load($key);
     }
     $geo = json_decode($response);
     return array('lat' => $geo->wgs84_lat, 'lon' => $geo->wgs84_lon);
 }
Ejemplo n.º 5
0
 /** Fetch one result
  * @access public
  * @param array $where
  * @param string $order
  * @return Object
  */
 public function fetchRow($where = null, $order = null)
 {
     $id = md5($where->__toString());
     if (!$this->_cache->test($id) || !$this->cache_result) {
         $result = parent::fetchRow($where, $order);
         $this->_cache->save($result);
         return $result;
     } else {
         return $this->_cache->load($id);
     }
 }
Ejemplo n.º 6
0
 /** Fetch pairs from the model
  * @access public
  * @param string $sql
  * @param array $bind
  * @return array
  */
 public function fetchPairs($sql, $bind = array())
 {
     $id = md5($sql);
     if (!$this->_cache->test($id) || !$this->cache_result) {
         $result = parent::fetchPairs($sql, $bind);
         $this->_cache->save($result);
         return $result;
     } else {
         return $this->_cache->load($id);
     }
 }
Ejemplo n.º 7
0
 /**
  * Test if a cache is available for the given id
  *
  * @param string $id Cache ID
  * @return boolean
  * @throws coding_exception
  */
 public function test($id)
 {
     if ($this->cache === false) {
         return false;
     }
     try {
         return $this->cache->test($id);
     } catch (Zend_Cache_Exception $e) {
         throw new coding_exception('Zend Cache Error: ' . $e->getMessage());
     }
 }
Ejemplo n.º 8
0
 /** Get a place from the WOEID
  * @access public
  * @param integer $woeid
  * @return boolean|array
  */
 public function getPlace($woeid)
 {
     if (!is_null($woeid)) {
         $key = 'geoplaceID' . $woeid;
         if (!$this->_cache->test($key)) {
             $yql = 'select * from geo.places where woeid = ' . $woeid;
             $place = $this->_oauth->execute($yql, $this->_accessToken, $this->_accessSecret, $this->_accessExpiry, $this->_handle);
             $this->_cache->save($place);
         } else {
             $place = $this->_cache->load($key);
         }
         return $this->_parser->parsePlace($place);
     } else {
         return false;
     }
 }