1: <?php
2:
3: /**
4: * Document for class GeoImg
5: *
6: * PHP Version 5.6
7: *
8: * @category Class
9: * @package Geolib
10: * @author Peter Pitchford <peter@geotonics.com>
11: * @license GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
12: * @link http://geotonics.com/#geolib
13: */
14:
15: /**
16: * Geo - Class to create HTML image tags, or an image in a link
17: *
18: * @category Html_Tag
19: * @package Geolib
20: * @author Peter Pitchford <peter@geotonics.com>
21: * @license GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
22: * @version Release: .1
23: * @link http://geotonics.com/#geolib
24: * @since Class available since Release .1
25: */
26: class GeoImg extends GeoTag
27: {
28: private $href;
29: private $title;
30: private $target;
31: private $rel;
32: private $absolutePath;
33:
34: /**
35: * Constructor for GeoImg object
36: *
37: * @param string $src Image src
38: * @param string $alt Image alt
39: * @param string $href Link href
40: * @param string $title Link title
41: * @param string $target Link target
42: * @param string $host Image host
43: * @param string $id Image id
44: * @param string $class Image class
45: * @param string $style Image style
46: * @param array $atts Any other Image attributes
47: * @param string $rel Link rel
48: */
49: public function __construct(
50: $src = null,
51: $alt = null,
52: $href = null,
53: $title = null,
54: $target = null,
55: $host = null,
56: $id = null,
57: $class = null,
58: $style = null,
59: $atts = null,
60: $rel = null
61: ) {
62: if ($src && !$host) {
63: $src=GEO_BASE.$src;
64: }
65: //geoDb($src,'src');
66: $this->setAtt("src", $src);
67: $this->setAtt("alt", $alt);
68: $this->setHost($host);
69: $this->init('img', null, $class, $id, $style, $atts);
70: $this->setLink($href, $title, $target, $rel);
71: }
72:
73: /**
74: * Set Absolute Path (which is then used by PHP's getimagesize()
75: *
76: * @return void
77: */
78: private function setAbsolutePath()
79: {
80: if ($this->atts["src"]) {
81: if (function_exists("apache_lookup_uri")) {
82: $info=apache_lookup_uri($this->atts["src"]);
83: $this->absolutePath=$info->filename;
84: } else {
85: $this->absolutePath=$_SERVER["DOCUMENT_ROOT"].geoIf($this->atts["src"][0]!="/", "/").$this->atts["src"];
86: }
87: }
88: }
89:
90: /**
91: * Set width and height attributes
92: *
93: * @return void
94: */
95: private function setImageSize()
96: {
97: if ($this->atts['src'] &&!$this->host) {
98: $this->setAbsolutePath();
99: $imageSize=getimagesize($this->absolutePath);
100:
101: if ($imageSize) {
102: $this->setAtt("width", $imageSize[0]);
103: $this->setAtt("height", $imageSize[1]);
104: }
105: }
106: }
107:
108: /**
109: * Set host for image src
110: *
111: * @param string $host host of image src (host is optional)
112: *
113: * @return void
114: */
115: public function setHost($host = null)
116: {
117: if ($host === true) {
118: $host = "http://" . $_SERVER["HTTP_HOST"];
119: } elseif ($host == null && defined("GEO_IMAGE_PATH")) {
120: $host = GEO_IMAGE_PATH;
121: }
122:
123: $this->host = $host;
124: }
125:
126: /**
127: * Add a link to the image.
128: *
129: * @param string $href href attribute of the link
130: * @param string $title title of the link
131: * @param string $target target of the link
132: * @param string $rel rel of the link
133: *
134: * @return void
135: */
136: public function setLink($href, $title = null, $target = null, $rel = null)
137: {
138: if ($href && !$title) {
139: $title = true;
140: }
141:
142: $this->href = $href;
143: $this->title = $title;
144: $this->target = $target;
145: $this->rel = $rel;
146: }
147:
148: /**
149: * Returns html image tag
150: *
151: * @param string $src Path to image
152: * @param string $alt Alternative text
153: *
154: * @return string HTML image tag
155: */
156: public function tag($src = null, $alt = null)
157: {
158: if ($alt) {
159: $this->setAtt("att", $alt);
160: }
161:
162: if ($src) {
163: $this->setAtt("src", $src);
164: }
165:
166: if ($this->host) {
167: $this->setAtt("src", $this->host.$this->atts['src']);
168: }
169:
170: $this->setImageSize();
171: $tag = parent::baseTag();
172:
173: if ($this->href) {
174: return geoLink(
175: $this->href,
176: $tag,
177: null,
178: $this->title,
179: null,
180: array("rel" => $this->rel),
181: $this->target
182: );
183: }
184:
185: return $tag;
186: }
187: }
188: