1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23:
24: class cHTMLLink extends cHTMLContentElement {
25: 26: 27: 28:
29: protected $_link;
30:
31: 32: 33: 34: 35: 36: 37:
38: protected $_content;
39:
40: 41: 42: 43:
44: protected $_anchor;
45:
46: 47: 48: 49:
50: protected $_custom;
51:
52: 53: 54:
55: protected $_image;
56:
57: 58: 59:
60: protected $_targetarea;
61:
62: 63: 64:
65: protected $_targetframe;
66:
67: 68: 69:
70: protected $_targetaction;
71:
72: 73: 74:
75: protected $_type;
76:
77: 78: 79:
80: protected $_targetarea2;
81:
82: 83: 84:
85: protected $_targetaction2;
86:
87: 88: 89:
90: protected $_targetframe2;
91:
92: 93: 94: 95: 96: 97: 98: 99:
100: public function __construct($href = '') {
101: global $sess;
102: parent::__construct();
103:
104: $this->setLink($href);
105: $this->_tag = 'a';
106: $this->_image = '';
107:
108:
109: if (is_object($sess)) {
110: if ($sess->classname == 'cSession') {
111: $this->enableAutomaticParameterAppend();
112: }
113: }
114: }
115:
116: 117: 118: 119: 120:
121: public function enableAutomaticParameterAppend() {
122: return $this->setEvent('click', 'var doit = true; try { var i = get_registered_parameters() } catch (e) { doit = false; }; if (doit == true) { this.href += i; }');
123: }
124:
125: 126: 127: 128: 129:
130: public function disableAutomaticParameterAppend() {
131: return $this->unsetEvent('click');
132: }
133:
134: 135: 136: 137: 138: 139: 140: 141:
142: public function setLink($href) {
143: $this->_link = $href;
144: $this->_type = 'link';
145:
146: if (strpos($href, 'javascript:') !== false) {
147: $this->disableAutomaticParameterAppend();
148: }
149:
150: return $this;
151: }
152:
153: 154: 155: 156: 157: 158: 159: 160:
161: public function setTargetFrame($target) {
162: return $this->updateAttribute('target', $target);
163: }
164:
165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176:
177: public function setCLink($targetarea, $targetframe, $targetaction = '') {
178: $this->_targetarea = $targetarea;
179: $this->_targetframe = $targetframe;
180: $this->_targetaction = $targetaction;
181: $this->_type = 'clink';
182:
183: return $this;
184: }
185:
186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199:
200: public function setMultiLink($righttoparea, $righttopaction, $rightbottomarea, $rightbottomaction) {
201: $this->_targetarea = $righttoparea;
202: $this->_targetframe = 3;
203: $this->_targetaction = $righttopaction;
204: $this->_targetarea2 = $rightbottomarea;
205: $this->_targetframe2 = 4;
206: $this->_targetaction2 = $rightbottomaction;
207: $this->_type = 'multilink';
208:
209: return $this;
210: }
211:
212: 213: 214: 215: 216: 217: 218: 219: 220: 221:
222: public function setCustom($key, $value) {
223: $this->_custom[$key] = $value;
224:
225: return $this;
226: }
227:
228: 229: 230: 231: 232: 233:
234: public function setImage($src) {
235: $this->_image = $src;
236:
237: return $this;
238: }
239:
240: 241: 242: 243: 244: 245: 246: 247:
248: public function unsetCustom($key) {
249: if (isset($this->_custom[$key])) {
250: unset($this->_custom[$key]);
251: }
252:
253: return $this;
254: }
255:
256: 257: 258: 259:
260: public function getHref() {
261: global $sess;
262:
263: if (is_array($this->_custom)) {
264: $custom = '';
265:
266: foreach ($this->_custom as $key => $value) {
267: $custom .= "&$key=$value";
268: }
269: }
270:
271: if ($this->_anchor) {
272: $anchor = '#' . $this->_anchor;
273: } else {
274: $anchor = '';
275: }
276:
277: switch ($this->_type) {
278: case 'link':
279: $custom = '';
280: if (is_array($this->_custom)) {
281: foreach ($this->_custom as $key => $value) {
282: if ($custom == '') {
283: $custom .= "?$key=$value";
284: } else {
285: $custom .= "&$key=$value";
286: }
287: }
288: }
289:
290: return $this->_link . $custom . $anchor;
291: break;
292: case 'clink':
293: $this->disableAutomaticParameterAppend();
294: return 'main.php?area=' . $this->_targetarea . '&frame=' . $this->_targetframe . '&action=' . $this->_targetaction . $custom . '&contenido=' . $sess->id . $anchor;
295: break;
296: case 'multilink':
297: $this->disableAutomaticParameterAppend();
298: $tmp_mstr = 'javascript:Con.multiLink(\'%s\',\'%s\',\'%s\',\'%s\');';
299: $mstr = sprintf($tmp_mstr, 'right_top', $sess->url('main.php?area=' . $this->_targetarea . '&frame=' . $this->_targetframe . '&action=' . $this->_targetaction . $custom), 'right_bottom', $sess->url('main.php?area=' . $this->_targetarea2 . '&frame=' . $this->_targetframe2 . '&action=' . $this->_targetaction2 . $custom));
300: return $mstr;
301: break;
302: }
303: }
304:
305: 306: 307: 308: 309: 310: 311: 312: 313:
314: public function setAnchor($anchor) {
315: $this->_anchor = $anchor;
316:
317: return $this;
318: }
319:
320: 321: 322: 323: 324: 325:
326: public function toHtml() {
327: $this->updateAttribute('href', $this->getHref());
328:
329: if ($this->_image != '') {
330: $image = new cHTMLImage($this->_image);
331: $this->setContent($image);
332: }
333:
334: return parent::toHtml();
335: }
336:
337: }
338: