AgmMarkerReplacer

Handles quicktags replacement in text.

Defined (1)

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

/lib/class_agm_marker_replacer.php  
  1. class AgmMarkerReplacer { 
  2.  
  3. /** 
  4. * PHP4 compatibility constructor. 
  5. */ 
  6. function AgmMarkerReplacer () { 
  7. $this->__construct(); 
  8.  
  9. function __construct() { 
  10. $this->model = new AgmMapModel(); 
  11.  
  12. /** 
  13. * Creates a replacer and registers shortcodes. 
  14. * @access public 
  15. * @static 
  16. */ 
  17. static function register () { 
  18. $me = new AgmMarkerReplacer(); 
  19. $me->register_shortcodes(); 
  20.  
  21. /** 
  22. * Registers shortcodes for processing. 
  23. * @access private 
  24. */ 
  25. function register_shortcodes () { 
  26. add_shortcode('map', array($this, 'process_tags')); 
  27.  
  28. /** 
  29. * Creates markup to insert a single map. 
  30. * @access private 
  31. */ 
  32. function create_tag ($map, $overrides=array()) { 
  33. if (!$map['id']) return ''; 
  34.  
  35. $map = array_merge($map, $overrides); 
  36.  
  37. $elid = 'map-' . md5(microtime() . rand()); 
  38. $rpl = '<div class="agm_google_maps" id="' . $elid . '"></div>'; 
  39. $rpl .= '<script type="text/javascript">_agmMaps[_agmMaps.length] = {selector: "#' . $elid . '", data: ' . json_encode($map) . '};</script>'; 
  40. return $rpl; 
  41.  
  42. /** 
  43. * Creates markup to insert multiple maps. 
  44. * @access private 
  45. */ 
  46. function create_tags ($maps, $overrides=array()) { 
  47. if (!is_array($maps)) return ''; 
  48. $ret = ''; 
  49. foreach ($maps as $map) { 
  50. $ret .= $this->create_tag($map, $overrides); 
  51. return $ret; 
  52.  
  53. /** 
  54. * Creates a map overlay. 
  55. * Takes all resulting maps from a query and merges all 
  56. * markers into one map with default settings. 
  57. * @access private 
  58. */ 
  59. function create_overlay_tag ($maps, $overrides=array()) { 
  60. if (!is_array($maps)) return ''; 
  61. return $this->create_tag($this->model->merge_markers($maps), $overrides); 
  62.  
  63. /** 
  64. * Inserts a map for tags with ID attribute set. 
  65. * @access private 
  66. */ 
  67. function process_map_id_tag ($map_id, $overrides=array()) { 
  68. return $this->create_tag($this->model->get_map($map_id), $overrides); 
  69.  
  70. /** 
  71. * Inserts a map for tags with query attribute set. 
  72. * @access private 
  73. */ 
  74. function process_map_query_tag ($query, $overrides=array(), $overlay=false, $network=false) { 
  75. $method = $overlay ? 'create_overlay_tag' : 'create_tags'; 
  76. if ('random' == $query) return $this->$method($this->model->get_random_map(), $overrides); 
  77. if ('all' == $query) return $this->$method($this->model->get_all_maps(), $overrides); 
  78. return $network ? 
  79. $this->$method($this->model->get_custom_network_maps($query), $overrides) 
  80. $this->$method($this->model->get_custom_maps($query), $overrides) 
  81.  
  82. /** 
  83. * Processes text and replaces recognized tags. 
  84. * @access public 
  85. */ 
  86. function process_tags ($atts, $content=null) { 
  87. $body = false; 
  88. $atts = shortcode_atts(array( 
  89. 'id' => false,  
  90. 'query' => false,  
  91. 'overlay' => false,  
  92. 'network' => false,  
  93. // Appearance overrides 
  94. 'height' => false,  
  95. 'width' => false,  
  96. 'zoom' => false,  
  97. 'show_map' => false,  
  98. 'show_markers' => false,  
  99. 'show_images' => false,  
  100. 'show_posts' => false,  
  101. 'map_type' => false,  
  102. // Command switches 
  103. 'plot_routes' => false,  
  104. ), $atts); 
  105.  
  106. $overrides = array(); 
  107. $map_types = array( 
  108. 'ROADMAP',  
  109. 'SATELLITE',  
  110. 'HYBRID',  
  111. 'TERRAIN' 
  112. ); 
  113.  
  114. // Stacked queries fix 
  115. $atts['query'] = preg_replace( 
  116. '/' . preg_quote('&') . '/', '&',  
  117. preg_replace('/' . preg_quote('&') . '/', '&', $atts['query']) 
  118. ); 
  119.  
  120. if ($atts['height']) $overrides['height'] = $atts['height']; 
  121. if ($atts['width']) $overrides['width'] = $atts['width']; 
  122. if ($atts['zoom']) $overrides['zoom'] = $atts['zoom']; 
  123. if ($atts['show_map']) $overrides['show_map'] = ('true' == $atts['show_map']) ? 1 : 0; 
  124. if ($atts['show_markers']) $overrides['show_markers'] = ('true' == $atts['show_markers']) ? 1 : 0; 
  125. if ($atts['show_images']) $overrides['show_images'] = ('true' == $atts['show_images']) ? 1 : 0; 
  126. if ($atts['show_posts']) $overrides['show_posts'] = ('true' == $atts['show_posts']) ? 1 : 0; 
  127. if ($atts['plot_routes']) $overrides['plot_routes'] = ('true' == $atts['plot_routes']) ? 1 : 0; 
  128. if ($atts['map_type'] && in_array(strtoupper($atts['map_type']), $map_types)) $overrides['map_type'] = strtoupper($atts['map_type']); 
  129.  
  130. if (!AGM_USE_POST_INDEXER) $atts['network'] = false; // Can't do this without Post Indexer 
  131. if ($atts['id']) $body = $this->process_map_id_tag($atts['id'], $overrides); // Single map, no overlay 
  132. else if ($atts['query']) $body = $this->process_map_query_tag($atts['query'], $overrides, $atts['overlay'], $atts['network']); 
  133. return $body ? $body : $content;