/system/expressionengine/libraries/channel_entries_parser/Components.php

https://bitbucket.org/mbaily/tremain · PHP · 222 lines · 75 code · 37 blank · 110 comment · 4 complexity · 5476d173c67c3f30303318db16326796 MD5 · raw file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2013, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. require_once APPPATH.'libraries/channel_entries_parser/components/Category.php';
  15. require_once APPPATH.'libraries/channel_entries_parser/components/Custom_date.php';
  16. require_once APPPATH.'libraries/channel_entries_parser/components/Custom_field.php';
  17. require_once APPPATH.'libraries/channel_entries_parser/components/Custom_field_pair.php';
  18. require_once APPPATH.'libraries/channel_entries_parser/components/Custom_member_field.php';
  19. require_once APPPATH.'libraries/channel_entries_parser/components/Date.php';
  20. require_once APPPATH.'libraries/channel_entries_parser/components/Header_and_footer.php';
  21. require_once APPPATH.'libraries/channel_entries_parser/components/Relationship.php';
  22. require_once APPPATH.'libraries/channel_entries_parser/components/Simple_conditional.php';
  23. require_once APPPATH.'libraries/channel_entries_parser/components/Simple_variable.php';
  24. require_once APPPATH.'libraries/channel_entries_parser/components/Switch.php';
  25. // ------------------------------------------------------------------------
  26. /**
  27. * ExpressionEngine Channel Parser Components
  28. *
  29. * @package ExpressionEngine
  30. * @subpackage Core
  31. * @category Core
  32. * @author EllisLab Dev Team
  33. * @link http://ellislab.com
  34. */
  35. class EE_Channel_parser_components {
  36. /**
  37. * The difference between these is in what variable array is passed
  38. * to them from the template->var_* arrays.
  39. * They also order differently. Pairs are done before all else to
  40. * discourage edge-case bugs where a pair's opening tag is accidentally
  41. * replace.
  42. * You may encounter edge-case bugs if you try to parse single tags
  43. * before the tag pairs are out of the way, so you're encouraged
  44. * to use the correct type for your component.
  45. */
  46. protected $pair = array();
  47. protected $single = array();
  48. protected $once = array();
  49. public function __construct()
  50. {
  51. // Dear third party devs, use the register_component method on
  52. // EE->channel_entries_parser for your own additions. Gracias.
  53. // Prep built-in parsers. Don't mess with the order, it matters!
  54. $this->register_pair('EE_Channel_header_and_footer_parser');
  55. $this->register_once('EE_Channel_category_parser');
  56. $this->register_once('EE_Channel_custom_field_pair_parser');
  57. $this->register_once('EE_Channel_relationship_parser');
  58. $this->register_single('EE_Channel_simple_conditional_parser');
  59. $this->register_single('EE_Channel_switch_parser');
  60. $this->register_single('EE_Channel_date_parser');
  61. $this->register_single('EE_Channel_simple_variable_parser');
  62. $this->register_single('EE_Channel_custom_date_parser');
  63. $this->register_single('EE_Channel_custom_field_parser');
  64. $this->register_single('EE_Channel_custom_member_field_parser');
  65. }
  66. // ------------------------------------------------------------------------
  67. /**
  68. * Register a component that parses a pair tag.
  69. *
  70. * @param String Class name of new component
  71. */
  72. public function register_pair($class)
  73. {
  74. $obj = new $class;
  75. if ( ! $obj instanceOf EE_Channel_parser_component)
  76. {
  77. throw new InvalidArgumentException($class.' must implement the EE_Channel_parser_component interface.');
  78. }
  79. $this->pair[] = $obj;
  80. }
  81. // ------------------------------------------------------------------------
  82. /**
  83. * Register a component that parses a single tag.
  84. *
  85. * @param String Class name of new component
  86. */
  87. public function register_single($class)
  88. {
  89. $obj = new $class;
  90. if ( ! $obj instanceOf EE_Channel_parser_component)
  91. {
  92. throw new InvalidArgumentException($class.' must implement the EE_Channel_parser_component interface.');
  93. }
  94. $this->single[] = $obj;
  95. }
  96. // ------------------------------------------------------------------------
  97. /**
  98. * Register a component that only runs once regardless of tag names.
  99. *
  100. * @param String Class name of new component
  101. */
  102. public function register_once($class)
  103. {
  104. $obj = new $class;
  105. if ( ! $obj instanceOf EE_Channel_parser_component)
  106. {
  107. throw new InvalidArgumentException($class.' must implement the EE_Channel_parser_component interface.');
  108. }
  109. $this->once[] = $obj;
  110. }
  111. // ------------------------------------------------------------------------
  112. /**
  113. * Pair tag parsing components
  114. *
  115. * @return Array List of pair tag parsing components
  116. */
  117. public function pair()
  118. {
  119. return $this->pair;
  120. }
  121. // ------------------------------------------------------------------------
  122. /**
  123. * Single tag parsing components
  124. *
  125. * @return Array List of single tag parsing components
  126. */
  127. public function single()
  128. {
  129. return $this->single;
  130. }
  131. // ------------------------------------------------------------------------
  132. /**
  133. * Single tag parsing components
  134. *
  135. * @return Array List of single tag parsing components
  136. */
  137. public function once()
  138. {
  139. return $this->once;
  140. }
  141. }
  142. // ------------------------------------------------------------------------
  143. /**
  144. * ExpressionEngine Channel Parser Component Interface
  145. *
  146. * @package ExpressionEngine
  147. * @subpackage Core
  148. * @category Core
  149. * @author EllisLab Dev Team
  150. * @link http://ellislab.com
  151. */
  152. interface EE_Channel_parser_component {
  153. /**
  154. * Check if your component or something something parsed by it
  155. * is in the disable= parameter.
  156. *
  157. * @param array A list of "disabled" features
  158. * @return Boolean Is disabled?
  159. */
  160. public function disabled(array $disabled, EE_Channel_preparser $pre);
  161. // ------------------------------------------------------------------------
  162. /**
  163. * Do any pre-processing on the tagdata or other data available
  164. * through the pre-parser.
  165. *
  166. * The return value of this method will be passed to the replace
  167. * method as a third parameter.
  168. *
  169. * @param String The tagdata to be parsed
  170. * @param Object The preparser object.
  171. * @return mixed [optional]
  172. */
  173. public function pre_process($tagdata, EE_Channel_preparser $pre);
  174. // ------------------------------------------------------------------------
  175. /**
  176. * Replace all tags that this component can deal with.
  177. *
  178. * @param String The tagdata to be parsed
  179. * @param Object The channel parser object
  180. * @param Mixed The results from the preparse method
  181. *
  182. * @return String The processed tagdata
  183. */
  184. public function replace($tagdata, EE_Channel_data_parser $obj, $pre_process_result);
  185. }