Source for file renderable.php

Documentation is available at renderable.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: renderable.php */
  22. /* Author: Paul Waite */
  23. /* Description: Renderable object definition. */
  24. /* */
  25. /* ******************************************************************** */
  26. /** @package core *//** Undefined/unknown browser type */
  27. ("BROWSER_TYPE_UNKNOWN", "");
  28. /** Standard HTML web browser */
  29. ("BROWSER_TYPE_HTML", "html");
  30. /** XHTML (HTML 5.0) capable web browser, phone, or PDA */
  31. ("BROWSER_TYPE_XHTML", "xhtml");
  32. /** Standard WAP phone */
  33. ("BROWSER_TYPE_WML", "wml");
  34. /** WAP phone with Phone.com extensions */
  35. ("BROWSER_TYPE_WMLUP", "wmlup");
  36. /** XML-only-capable browser, an unlikely beast */
  37. ("BROWSER_TYPE_XML", "xml");
  38. /** Not really a browser, a command-line script.. */
  39. ("BROWSER_TYPE_CLI", "cli");
  40. /** Default browser type, in absence of true knowledge.. */
  41. ("BROWSER_TYPE_DEFAULT", "html");
  42.  
  43. // -----------------------------------------------------------------------
  44. /**
  45. * RenderableObject class
  46. * This object should be inherited by all classes which are
  47. * intended to output content for the client browser.
  48. * @package core
  49. */
  50. class RenderableObject {
  51. /**
  52. * Constructor
  53. * Create a renderable object. Any object which you want to
  54. * be able to deliver content to a device such as a web
  55. * browser or wap phone etc. should inherit this class.
  56. */
  57. function RenderableObject() {
  58. return true;
  59. }
  60. /**
  61. * Return output suitable for normal wap-capable device. This
  62. * method must be over-ridden by a method of the same name in
  63. * the descendant class which renders output to wap devices.
  64. * @param mixed $parm Optional parameter to pass to method
  65. */
  66. function wml($parm="") {
  67. return "";
  68. }
  69. /**
  70. * Return output suitable for normal wap-capable device which
  71. * has Phone.com extensions. This method must be over-ridden
  72. * by a method of the same name in the descendant class which
  73. * renders output to wap devices.
  74. * @param mixed $parm Optional parameter to pass to method
  75. */
  76. function wmlup($parm="") {
  77. return $this->wml($parm);
  78. }
  79. /**
  80. * Return output suitable for normal HTML-capable device. This
  81. * method must be over-ridden by a method of the same name in
  82. * the descendant class which renders output to web browsers.
  83. * @param mixed $parm Optional parameter to pass to method
  84. */
  85. function html($parm="") {
  86. return "";
  87. }
  88. /**
  89. * Return output suitable for XML-capable devices or agents.
  90. * This method must be over-ridden by a method of the same name
  91. * in the descendant class which renders XML output.
  92. * @param mixed $parm Optional parameter to pass to method
  93. */
  94. function xml($parm="") {
  95. return "";
  96. }
  97. /**
  98. * Render output
  99. * Render in the appropriate way for the browser type. In
  100. * this instance we define the 'type' of the browser based
  101. * on the kind of content it is expecting back. Note that
  102. * this does not determine the actual "make" of the browser
  103. * (Internet Explorer, Netscape etc.) since a given "make"
  104. * of browser can deal with all sorts of content types..
  105. * @param mixed $parm Optional parameter to pass to method
  106. */
  107. function render($parm="") {
  108. global $RESPONSE;
  109. switch ($RESPONSE->browser_type) {
  110. case BROWSER_TYPE_XHTMLMP:
  111. case BROWSER_TYPE_WML:
  112. if ($parm == "") return $this->wml();
  113. else return $this->wml($parm);
  114. break;
  115.  
  116. case BROWSER_TYPE_WMLUP:
  117. if ($parm == "") return $this->wmlup();
  118. else return $this->wmlup($parm);
  119. break;
  120.  
  121. case BROWSER_TYPE_XHTML:
  122. case BROWSER_TYPE_HTML:
  123. if ($parm == "") return $this->html();
  124. else return $this->html($parm);
  125. break;
  126.  
  127. case BROWSER_TYPE_XML:
  128. if ($parm == "") return $this->xml();
  129. else return $this->xml($parm);
  130. break;
  131.  
  132. default:
  133. if ($parm == "") return $this->html();
  134. else return $this->html($parm);
  135. } // switch
  136. } // render
  137.  
  138.  
  139.  
  140. } // RenderableObject
  141. // ......................................................................
  142.  
  143. /**
  144. * A renderable tag of some kind. Basically a tag is a language construct
  145. * designed to render at least an identifying name and a value. More
  146. * specific variants might add other properties, and control the way
  147. * the tag is actually rendered.
  148. * @package core
  149. */
  150. class tag extends RenderableObject {
  151. var $tag_name = "";
  152. var $tag_value = "";
  153. var $attributes = array();
  154. /** Constructor
  155. * @param string $name The name of this tag
  156. * @param string $value The value of this tag
  157. */
  158. function tag($name, $value="") {
  159. $this->tag_name = $name;
  160. $this->tag_value = $value;
  161. }
  162. /** Adds an attribute to this tag.
  163. * @param string $attrname The name of the attribute
  164. * @param string $attrvalue The value of the attribute
  165. */
  166. function add_attribute($attrname, $attrvalue="") {
  167. $this->attributes[$attrname] = $attrvalue;
  168. }
  169. } // tag class
  170. // ----------------------------------------------------------------------
  171.  
  172. ?>

Documentation generated by phpDocumentor 1.3.0RC3