Source for file image-defs.php

Documentation is available at image-defs.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: image-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for managing and using IMAGES */
  24. /* */
  25. /* ******************************************************************** */
  26. /** @package image */
  27. include_once("renderable.php");
  28.  
  29. // ----------------------------------------------------------------------
  30. /**
  31. * Image class
  32. * A class for managing a standard image.
  33. * @package image
  34. */
  35. class image extends RenderableObject {
  36. /** Name of the image element */
  37.  
  38. var $name = "";
  39. /** Image ALT tag content */
  40.  
  41. var $alt = "";
  42. /** Image file source URL/path */
  43.  
  44. var $src = "";
  45. /** Width of image in pixels */
  46.  
  47. var $width = 0;
  48. /** Height of image in pixels */
  49.  
  50. var $height = 0;
  51. /** Padding at image sides in pixels */
  52.  
  53. var $hspace = 0;
  54. /** Padding at image top & bottom in pixels */
  55.  
  56. var $vspace = 0;
  57. /** Image alignment with respect to the page:
  58. * 'left' (default), 'right', 'top', 'bottom', 'middle',
  59. * 'absbottom', 'absmiddle', 'baseline', 'texttop'
  60. */
  61. var $align = "";
  62. /** Image border with in pixels */
  63.  
  64. var $border = 0;
  65. /** Script to execute on mouse-over */
  66.  
  67. var $onmouseover = "";
  68. /** Script to execute on mouse-out */
  69.  
  70. var $onmouseout = "";
  71. /** Text to display in status area when mouse over image */
  72.  
  73. var $linkover_text = "";
  74. /** Image map to use */
  75.  
  76. var $map = "";
  77. //.....................................................................
  78. /**
  79. * Constructor
  80. * Creates the basic image object.
  81. * @param string $name Name of this image element
  82. * @param string $src URL or path to the actual image file
  83. * @param string $alt Image ALT tag content
  84. * @param integer $width Width of the image in pixels
  85. * @param integer $height Height of the image in pixels
  86. * @param integer $border Size of border around the image in pixels
  87. * @param integer $hspace Padding to left & right of image in pixels
  88. * @param integer $vspace Padding top & bottom of image in pixels
  89. * @param string $align Alignment of image with respect to the page
  90. */
  91. function image($name, $src, $alt, $width=0, $height=0, $border=0, $hspace=0, $vspace=0, $align="") {
  92. $this->name = $name;
  93. $this->src = $src;
  94. $this->alt = $alt;
  95. $this->width = $width;
  96. $this->height = $height;
  97. $this->border = $border;
  98. $this->hspace = $hspace;
  99. $this->vspace = $vspace;
  100. $this->align = $align;
  101. } // image
  102. //.....................................................................
  103. /**
  104. * Set image details
  105. * Allow setting of src and metrics from outside.
  106. * @param string $src URL or path to the actual image file
  107. * @param integer $width Width of the image in pixels
  108. * @param integer $height Height of the image in pixels
  109. * @param integer $border Size of border around the image in pixels
  110. * @param integer $hspace Padding to left & right of image in pixels
  111. * @param integer $vspace Padding top & bottom of image in pixels
  112. * @param string $align Alignment of image with respect to the page
  113. */
  114. function set_src($src, $width, $height, $border=0, $hspace=0, $vspace=0, $align="") {
  115. $this->src = $src;
  116. $this->width=$width;
  117. $this->height = $height;
  118. $this->border = $border;
  119. $this->hspace = $hspace;
  120. $this->vspace = $vspace;
  121. $this->align = $align;
  122. return $this;
  123. } // set_src
  124. //.....................................................................
  125. /**
  126. * Set linkover text
  127. * Defines the text to show when the mouse moves over the image.
  128. * @param string $txt Text to show in status area when mouse-over.
  129. */
  130. function set_linkover_text($txt) {
  131. $this->linkover_text = $txt;
  132. } // set_linkover_text
  133. //.....................................................................
  134. /**
  135. * Set image map
  136. * Defines the image map to use with this image.
  137. * @param string $map The name of the image map to associate with this image.
  138. */
  139. function use_map($map) {
  140. $this->map = $map;
  141. } // use_map
  142. //.....................................................................
  143. /**
  144. * Render image as javascript object
  145. * @return string Javascript code rendering of this image
  146. */
  147. function javascript() {
  148. $js = "";
  149. if (($this->height > 0) && ($this->width > 0)) {
  150. $js .= "var " . $this->name . "=new Image(" . $this->width . "," . $this->height . ");\n";
  151. $js .= "var " . $this->name . ".src=\"" . $this->src . "\";\n";
  152. }
  153. return $js;
  154. } // javascript
  155. // ....................................................................
  156. /**
  157. * This renders the field as WML.
  158. * @return string The field as WML.
  159. */
  160. function wml() {
  161. return $this->html();
  162. } // wml
  163. // ....................................................................
  164. /**
  165. * This renders the field as HTML.
  166. * @return string The field as HTML.
  167. */
  168. function html() {
  169. global $RESPONSE;
  170. $html = "<img src=\"$this->src\"";
  171. $html .= " name=\"$this->name\"";
  172. $html .= " alt=\"$this->alt\"";
  173. // IE will show alt as tooltip, but others use title..
  174. if (isset($RESPONSE) && $RESPONSE->browser != "IE" && $this->alt != "") {
  175. $html .= " title=\"$this->alt\"";
  176. }
  177. if ($this->width > 0) $html .= " width=\"$this->width\"";
  178. if ($this->height > 0) $html .= " height=\"$this->height\"";
  179. if ($this->hspace > 0) $html .= " hspace=\"$this->hspace\"";
  180. if ($this->vspace > 0) $html .= " vspace=\"$this->vspace\"";
  181. if ($this->align != "") $html .= " align=\"$this->align\"";
  182. if ($this->map != "") $html .= " usemap=\"$this->map\"";
  183. $html .= " border=\"$this->border\"";
  184. if ($this->linkover_text != "" && $this->onmouseover == "") {
  185. $this->onmouseover = "status='$this->linkover_text';return true;";
  186. $this->onmouseout = "status='';return true;";
  187. }
  188. if ($this->onmouseover != "") $html .= " onmouseover=\"$this->onmouseover\"";
  189. if ($this->onmouseout != "") $html .= " onmouseout=\"$this->onmouseout\"";
  190. $html .= ">";
  191. return $html;
  192. } // html
  193.  
  194. } // image class
  195. // ----------------------------------------------------------------------
  196.  
  197. /**
  198. * Clickable Image class
  199. * A class for managing a clickable image. A clickable image is
  200. * one which redirects to a given URL when clicked on.
  201. * @package image
  202. */
  203. class clickable_image extends RenderableObject {
  204. // Public
  205. /** URL to go to when image is clicked on */
  206.  
  207. var $url = "";
  208.  
  209. // Private
  210. /** The image object
  211. @access private */
  212. var $img;
  213. //.....................................................................
  214. /**
  215. * Constructor
  216. * Creates the basic clickable image object.
  217. * @param string $name Name of this image element
  218. * @param string $url URL to go to when image is clicked
  219. * @param string $alt Image ALT tag content
  220. * @param string $src URL or path to the actual image file
  221. * @param integer $width Width of the image in pixels
  222. * @param integer $height Height of the image in pixels
  223. * @param integer $border Size of border around the image in pixels
  224. */
  225. function clickable_image($name, $url, $alt, $src, $width=0, $height=0, $border=0) {
  226. $this->img = new image($name, $src, $alt, $width, $height, $border);
  227. $this->url = $url;
  228. } // clickable_image
  229. //.....................................................................
  230. /**
  231. * Set linkover text
  232. * Defines the text to show when the mouse moves over the image.
  233. * @param string $txt Text to show in status area when mouse-over.
  234. */
  235. function set_linkover_text($txt) {
  236. if (isset($this->img)) {
  237. $this->img->set_linkover_text($txt);
  238. }
  239. } // set_linkover_text
  240. // ....................................................................
  241. /**
  242. * This renders the field as HTML.
  243. * @return string The field as HTML.
  244. */
  245. function html() {
  246. $html = "<a href=\"" . $this->url . "\">";
  247. $html .= $this->img->html();
  248. $html .= "</a>";
  249. return $html;
  250. } // html
  251.  
  252. } // clickable_image class
  253. // ----------------------------------------------------------------------
  254.  
  255. /**
  256. * Hover class
  257. * Provides and image which changes to a second image when the mouse
  258. * is over the top of it, using onmouseover and onmouseout events.
  259. * @package image
  260. */
  261. class hover extends RenderableObject {
  262. // Public
  263. /** Name of this element */
  264.  
  265. var $name = "";
  266. /** Name of the over version of this element */
  267.  
  268. var $name_over = "";
  269. /** URL to go to when image is clicked */
  270.  
  271. var $url = "";
  272.  
  273. // Private
  274. /** Image object
  275. @access private */
  276. var $img;
  277. /** Image over object
  278. @access private */
  279. var $img_over;
  280. /** Flag, true if images have been defined
  281. @access private */
  282. var $images_defined = false;
  283. //.....................................................................
  284. /**
  285. * Constructor
  286. * Creates the hover object.
  287. * This creates two image objects, one for the normal image and
  288. * one for the image displayed when the mouse goes over it. You
  289. * must define these images:
  290. * @see set_image()
  291. * @see set_image_over()
  292. * @param string $name Name of this hover image element
  293. * @param string $url URL to go to when image is clicked
  294. * @param string $alt Image ALT tag content
  295. */
  296. function hover( $name, $url, $alt ) {
  297. $this->name = $name;
  298. $this->name_over = $name . "_over";
  299. $this->url = $url;
  300. $this->img = new image($this->name, $url, $alt);
  301. $this->img_over = new image($this->name_over, $url, $alt);
  302. } // hover
  303. //.....................................................................
  304. /**
  305. * Define normal image
  306. * This is the image which is displayed when the mouse is 'out'.
  307. * @param string $src URL or path to the actual image file
  308. * @param integer $width Width of the image in pixels
  309. * @param integer $height Height of the image in pixels
  310. * @param integer $border Size of border around the image in pixels
  311. */
  312. function set_image($src, $width, $height, $border=0) {
  313. $this->img = $this->img->set_src($src, $width, $height, $border);
  314. return $this;
  315. } // set_image
  316. //.....................................................................
  317. /**
  318. * Define over image
  319. * This is the image which is displayed when the mouse is 'over'.
  320. * @param string $src URL or path to the actual image file
  321. * @param integer $width Width of the image in pixels
  322. * @param integer $height Height of the image in pixels
  323. * @param integer $border Size of border around the image in pixels
  324. */
  325. function set_image_over($src, $width, $height, $border=0) {
  326. $this->img_over = $this->img_over->set_src($src, $width, $height, $border);
  327. return $this;
  328. } // set_image_over
  329. // ....................................................................
  330. /**
  331. * This renders the field as HTML.
  332. * @return string The field as HTML.
  333. */
  334. function html() {
  335. $html = "";
  336. $html .= "<a href=\"" . $this->url . "\"";
  337. $html .= " onmouseover=\"$this->name.src='" . $this->img_over->src . "'; window.status='$this->name'; return true;\"\n";
  338. $html .= " onmouseout=\"$this->name.src='" . $this->img->src . "'; window.status=''; return true;\">\n";
  339. $html .= $this->img->html();
  340. $html .= "</a>\n";
  341. return $html;
  342. } // html
  343.  
  344. } // hover class
  345. // ----------------------------------------------------------------------
  346.  
  347. ?>

Documentation generated by phpDocumentor 1.3.0RC3