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: parent::__construct();
102:
103: $this->setLink($href);
104: $this->_tag = 'a';
105: $this->_image = '';
106:
107:
108: $sess = cRegistry::getSession();
109: if (is_object($sess) && get_class($sess) == 'cSession') {
110: $this->enableAutomaticParameterAppend();
111: }
112: }
113:
114: 115: 116: 117: 118:
119: public function enableAutomaticParameterAppend() {
120: return $this->setEvent('click', 'var doit = true; try { var i = get_registered_parameters() } catch (e) { doit = false; }; if (doit == true) { this.href += i; }');
121: }
122:
123: 124: 125: 126: 127:
128: public function disableAutomaticParameterAppend() {
129: return $this->unsetEvent('click');
130: }
131:
132: 133: 134: 135: 136: 137: 138: 139:
140: public function setLink($href) {
141: $this->_link = $href;
142: $this->_type = 'link';
143:
144: if (cString::findFirstPos($href, 'javascript:') !== false) {
145: $this->disableAutomaticParameterAppend();
146: }
147:
148: return $this;
149: }
150:
151: 152: 153: 154: 155: 156: 157: 158:
159: public function setTargetFrame($target) {
160: return $this->updateAttribute('target', $target);
161: }
162:
163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174:
175: public function setCLink($targetarea, $targetframe, $targetaction = '') {
176: $this->_targetarea = $targetarea;
177: $this->_targetframe = $targetframe;
178: $this->_targetaction = $targetaction;
179: $this->_type = 'clink';
180:
181: return $this;
182: }
183:
184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197:
198: public function setMultiLink($righttoparea, $righttopaction, $rightbottomarea, $rightbottomaction) {
199: $this->_targetarea = $righttoparea;
200: $this->_targetframe = 3;
201: $this->_targetaction = $righttopaction;
202: $this->_targetarea2 = $rightbottomarea;
203: $this->_targetframe2 = 4;
204: $this->_targetaction2 = $rightbottomaction;
205: $this->_type = 'multilink';
206:
207: return $this;
208: }
209:
210: 211: 212: 213: 214: 215: 216: 217: 218: 219:
220: public function setCustom($key, $value) {
221: $this->_custom[$key] = $value;
222:
223: return $this;
224: }
225:
226: 227: 228: 229: 230: 231:
232: public function setImage($src) {
233: $this->_image = $src;
234:
235: return $this;
236: }
237:
238: 239: 240: 241: 242: 243: 244: 245:
246: public function unsetCustom($key) {
247: if (isset($this->_custom[$key])) {
248: unset($this->_custom[$key]);
249: }
250:
251: return $this;
252: }
253:
254: 255: 256: 257:
258: public function getHref() {
259: global $sess;
260:
261: if (is_array($this->_custom)) {
262: $custom = '';
263:
264: foreach ($this->_custom as $key => $value) {
265: $custom .= "&$key=$value";
266: }
267: }
268:
269: if ($this->_anchor) {
270: $anchor = '#' . $this->_anchor;
271: } else {
272: $anchor = '';
273: }
274:
275: switch ($this->_type) {
276: case 'link':
277: $custom = '';
278: if (is_array($this->_custom)) {
279: foreach ($this->_custom as $key => $value) {
280: if ($custom == '') {
281: $custom .= "?$key=$value";
282: } else {
283: $custom .= "&$key=$value";
284: }
285: }
286: }
287:
288: return $this->_link . $custom . $anchor;
289: break;
290: case 'clink':
291: $this->disableAutomaticParameterAppend();
292: return 'main.php?area=' . $this->_targetarea . '&frame=' . $this->_targetframe . '&action=' . $this->_targetaction . $custom . '&contenido=' . $sess->id . $anchor;
293: break;
294: case 'multilink':
295: $this->disableAutomaticParameterAppend();
296: $tmp_mstr = 'javascript:Con.multiLink(\'%s\',\'%s\',\'%s\',\'%s\');';
297: $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));
298: return $mstr;
299: break;
300: }
301: }
302:
303: 304: 305: 306: 307: 308: 309: 310: 311:
312: public function setAnchor($anchor) {
313: $this->_anchor = $anchor;
314:
315: return $this;
316: }
317:
318: 319: 320: 321: 322: 323:
324: public function toHtml() {
325: $this->updateAttribute('href', $this->getHref());
326:
327: if ($this->_image != '') {
328: $image = new cHTMLImage($this->_image);
329: $this->setContent($image);
330: }
331:
332: return parent::toHtml();
333: }
334:
335: }
336: