1: <?php
2:
3: /**
4: * This file contains the cHTMLImage class.
5: *
6: * @package Core
7: * @subpackage GUI_HTML
8: * @version SVN Revision $Rev:$
9: *
10: * @author Simon Sprankel
11: * @copyright four for business AG <www.4fb.de>
12: * @license http://www.contenido.org/license/LIZENZ.txt
13: * @link http://www.4fb.de
14: * @link http://www.contenido.org
15: */
16:
17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
18:
19: /**
20: * cHTMLImage class represents an image.
21: *
22: * @package Core
23: * @subpackage GUI_HTML
24: */
25: class cHTMLImage extends cHTML {
26:
27: /**
28: * Constructor.
29: * Creates an HTML IMG element.
30: *
31: * @param mixed $src [optional]
32: * image source
33: * @param string $class [optional]
34: * the class of this element
35: */
36: public function __construct($src = NULL, $class = '') {
37: parent::__construct();
38:
39: $this->_tag = 'img';
40: $this->_contentlessTag = true;
41:
42: $this->setSrc($src);
43: $this->setClass($class);
44: }
45:
46: /**
47: * Sets the image's source file
48: *
49: * @param string $src
50: * source location
51: * @return cHTMLImage
52: * $this for chaining
53: */
54: public function setSrc($src) {
55: if ($src === NULL) {
56: $src = 'images/spacer.gif';
57: }
58:
59: return $this->updateAttribute('src', $src);
60: }
61:
62: /**
63: * Sets the image's width
64: *
65: * @param int $width
66: * Image width
67: * @return cHTMLImage
68: * $this for chaining
69: */
70: public function setWidth($width) {
71: return $this->updateAttribute('width', $width);
72: }
73:
74: /**
75: * Sets the image's height
76: *
77: * @param int $height
78: * Image height
79: * @return cHTMLImage
80: * $this for chaining
81: */
82: public function setHeight($height) {
83: return $this->updateAttribute('height', $height);
84: }
85:
86: /**
87: * Sets the border size
88: *
89: * @param int $border
90: * Border size
91: * @return cHTMLImage
92: * $this for chaining
93: */
94: public function setBorder($border) {
95: return $this->updateAttribute('border', $border);
96: }
97:
98: /**
99: * Apply dimensions from the source image
100: */
101: public function applyDimensions() {
102: // Try to open the image
103: list($width, $height) = @getimagesize(cRegistry::getBackendPath() . $this->getAttribute('src'));
104:
105: if (!empty($width) && !empty($height)) {
106: $this->setWidth($width);
107: $this->setHeight($height);
108: }
109: }
110:
111: }
112: