Advertisement
Guest User

EM_Em0074settings_Model_Config_Font

a guest
Jan 26th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. <?php
  2. class EM_Em0074settings_Model_Config_Font
  3. {
  4. const CACHE_KEY = 'EM0074SETTINGS_GOOGLE_FONTS';
  5. const CACHE_LIFETIME = 86400;
  6.  
  7. protected $googlefonts_url = 'https://www.googleapis.com/webfonts/v1/webfonts?sort=popularity&key=AIzaSyAp8j2F_JhufO21IIbykS2uZaIY5NCTr1k';
  8.  
  9.  
  10. public function toOptionArray()
  11. {
  12. /** @var Mage_Core_Model_Cache */
  13. $cache = Mage::app()->getCacheInstance();
  14. if (!($fonts = $cache->load(self::CACHE_KEY))) {
  15. $ch = curl_init($this->googlefonts_url);
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  17. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  18. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  19. $fonts = curl_exec($ch);
  20. curl_close($ch);
  21.  
  22. $fonts = Zend_Json::decode($fonts);
  23.  
  24. $options = array();
  25. if (!isset($fonts['items'])) return $options; // can't connect to google font
  26.  
  27. foreach ($fonts['items'] as $item) {
  28. $options[$item['family']] = array(
  29. 'value' => $item['family'],
  30. 'label' => $item['family'],
  31. );
  32. }
  33.  
  34. ksort($options);
  35. $options = array_values($options);
  36.  
  37. $cache->save(serialize($options), self::CACHE_KEY, array(), self::CACHE_LIFETIME);
  38. return $options;
  39. }
  40. else {
  41. return unserialize($fonts);
  42. }
  43.  
  44. }
  45.  
  46. }
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement