Mixin_Dynamic_Stylesheet_Instance_Methods

Provides instance methods for the dynamic stylesheet utility.

Defined (1)

The class is defined in the following location(s).

/products/photocrati_nextgen/modules/dynamic_stylesheet/package.module.dynamic_stylesheet.php  
  1. class Mixin_Dynamic_Stylesheet_Instance_Methods extends Mixin 
  2. /** 
  3. * Registers a template with the dynamic stylesheet utility. A template 
  4. * must be registered before it can be loaded 
  5. * @param string $name 
  6. * @param string $template 
  7. */ 
  8. function register($name, $template) 
  9. $this->object->_known_templates[$name] = $template; 
  10. /** 
  11. * Finds a registered template by name 
  12. * @param string $name 
  13. * @return int 
  14. */ 
  15. function get_css_template_index($name) 
  16. return array_search($name, array_keys($this->object->_known_templates)); 
  17. function get_css_template($index) 
  18. $keys = array_keys($this->object->_known_templates); 
  19. return $this->object->_known_templates[$keys[$index]]; 
  20. /** 
  21. * Loads a template, along with the dynamic variables to be interpolated 
  22. * @param string $name 
  23. * @param array $vars 
  24. */ 
  25. function enqueue($name, $data = array()) 
  26. if (($index = $this->object->get_css_template_index($name)) !== FALSE) { 
  27. if (is_subclass_of($data, 'C_DataMapper_Model')) { 
  28. $data = $data->get_entity(); 
  29. if (defined('NGG_INLINE_DYNAMIC_CSS') && NGG_INLINE_DYNAMIC_CSS) { 
  30. $css = $this->render_view($this->object->get_css_template($index), $data, TRUE); 
  31. wp_enqueue_style('ngg_dyncss', $this->get_static_url('photocrati-dynamic_stylesheet#blank.css'), FALSE, NGG_SCRIPT_VERSION); 
  32. wp_add_inline_style('ngg_dyncss', $css); 
  33. } else { 
  34. $data = $this->object->encode($data); 
  35. wp_enqueue_style('dyncss-' . $index . $data . '@dynamic', $this->object->get_router()->get_url("/{$this->object->_app}", FALSE) . "?index={$index}&data={$data}", FALSE, NGG_SCRIPT_VERSION); 
  36. /** 
  37. * Encodes $data 
  38. * base64 encoding uses '==' to denote the end of the sequence, but keep it out of the url 
  39. * @param $data 
  40. * @return string 
  41. */ 
  42. function encode($data) 
  43. $data = json_encode($data); 
  44. $data = base64_encode($data); 
  45. $data = str_replace('/', '\\', $data); 
  46. $data = rtrim($data, '='); 
  47. return $data; 
  48. /** 
  49. * Decodes $data 
  50. * @param $data 
  51. * @return array|mixed 
  52. */ 
  53. function decode($data) 
  54. $data = str_replace('\\', '/', $data); 
  55. $data = base64_decode($data . '=='); 
  56. $data = json_decode($data); 
  57. return $data;