Guest User

Untitled

a guest
May 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <?php
  2. class GoogleAppHelper extends AppHelper{
  3. public function __construct($options = array()){
  4. $default = array(
  5. 'cachePath' => dirname(dirname(dirname(__FILE__))).DS.'webroot'.DS.'img'.DS.get_class($this).DS,
  6. 'cacheImagePath' => '/google/img/'.get_class($this).'/'
  7. );
  8.  
  9. $options = array_merge($default, $options);
  10.  
  11. $this->cachePath = $options['cachePath'];
  12. $this->cacheImagePath = $options['cacheImagePath'];
  13. }
  14.  
  15. protected function _checkCache($data){
  16. $file = sha1(serialize($data)).'.png';
  17. if (is_file($this->cachePath.$file)){
  18. return $this->Html->image($this->cacheImagePath.$file );
  19. }
  20. return false;
  21. }
  22.  
  23. protected function _writeCache($data, $url){
  24. $file = sha1(serialize($data)).'.png';
  25.  
  26. if(is_writable($this->cachePath)){
  27. $contents = file_get_contents($url);
  28.  
  29. $fp = fopen($this->cachePath.$file, 'w');
  30. fwrite($fp, $contents);
  31. fclose($fp);
  32.  
  33. if (!is_file($this->cachePath.$file)){
  34. $this->__errors[] = __('Could not create the cache file', true);
  35. }
  36. }
  37. }
  38. }
Add Comment
Please, Sign In to add comment