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