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: protected $_link;
28:
29:
30: protected $_content;
31:
32:
33: protected $_anchor;
34:
35:
36: protected $_custom;
37:
38: protected $_image;
39:
40: 41: 42: 43: 44: 45: 46:
47: public function __construct($href = '') {
48: global $sess;
49: parent::__construct();
50:
51: $this->setLink($href);
52: $this->_tag = 'a';
53: $this->_image = '';
54:
55:
56: if (is_object($sess)) {
57: if ($sess->classname == 'cSession') {
58: $this->enableAutomaticParameterAppend();
59: }
60: }
61: }
62:
63: public function enableAutomaticParameterAppend() {
64: return $this->setEvent('click', 'var doit = true; try { var i = get_registered_parameters() } catch (e) { doit = false; }; if (doit == true) { this.href += i; }');
65: }
66:
67: public function disableAutomaticParameterAppend() {
68: return $this->unsetEvent('click');
69: }
70:
71: 72: 73: 74: 75: 76:
77: public function setLink($href) {
78: $this->_link = $href;
79: $this->_type = 'link';
80:
81: if (strpos($href, 'javascript:') !== false) {
82: $this->disableAutomaticParameterAppend();
83: }
84:
85: return $this;
86: }
87:
88: 89: 90: 91: 92: 93:
94: public function setTargetFrame($target) {
95: return $this->updateAttribute('target', $target);
96: }
97:
98: 99: 100: 101: 102: 103: 104: 105:
106: public function setCLink($targetarea, $targetframe, $targetaction = '') {
107: $this->_targetarea = $targetarea;
108: $this->_targetframe = $targetframe;
109: $this->_targetaction = $targetaction;
110: $this->_type = 'clink';
111:
112: return $this;
113: }
114:
115: 116: 117: 118: 119: 120: 121: 122: 123:
124: public function setMultiLink($righttoparea, $righttopaction, $rightbottomarea, $rightbottomaction) {
125: $this->_targetarea = $righttoparea;
126: $this->_targetframe = 3;
127: $this->_targetaction = $righttopaction;
128: $this->_targetarea2 = $rightbottomarea;
129: $this->_targetframe2 = 4;
130: $this->_targetaction2 = $rightbottomaction;
131: $this->_type = 'multilink';
132:
133: return $this;
134: }
135:
136: 137: 138: 139: 140: 141: 142:
143: public function setCustom($key, $value) {
144: $this->_custom[$key] = $value;
145:
146: return $this;
147: }
148:
149: public function setImage($src) {
150: $this->_image = $src;
151:
152: return $this;
153: }
154:
155: 156: 157: 158: 159: 160:
161: public function unsetCustom($key) {
162: if (isset($this->_custom[$key])) {
163: unset($this->_custom[$key]);
164: }
165:
166: return $this;
167: }
168:
169: public function getHref() {
170: global $sess;
171:
172: if (is_array($this->_custom)) {
173: $custom = '';
174:
175: foreach ($this->_custom as $key => $value) {
176: $custom .= "&$key=$value";
177: }
178: }
179:
180: if ($this->_anchor) {
181: $anchor = '#' . $this->_anchor;
182: } else {
183: $anchor = '';
184: }
185:
186: switch ($this->_type) {
187: case 'link':
188: $custom = '';
189: if (is_array($this->_custom)) {
190: foreach ($this->_custom as $key => $value) {
191: if ($custom == '') {
192: $custom .= "?$key=$value";
193: } else {
194: $custom .= "&$key=$value";
195: }
196: }
197: }
198:
199: return $this->_link . $custom . $anchor;
200: break;
201: case 'clink':
202: $this->disableAutomaticParameterAppend();
203: return 'main.php?area=' . $this->_targetarea . '&frame=' . $this->_targetframe . '&action=' . $this->_targetaction . $custom . '&contenido=' . $sess->id . $anchor;
204: break;
205: case 'multilink':
206: $this->disableAutomaticParameterAppend();
207: $tmp_mstr = 'javascript:conMultiLink(\'%s\',\'%s\',\'%s\',\'%s\');';
208: $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));
209: return $mstr;
210: break;
211: }
212: }
213:
214: 215: 216: 217: 218: 219: 220:
221: public function setAnchor($anchor) {
222: $this->_anchor = $anchor;
223:
224: return $this;
225: }
226:
227: 228: 229: 230: 231:
232: public function toHTML() {
233: $this->updateAttribute('href', $this->getHref());
234:
235: if ($this->_image != '') {
236: $image = new cHTMLImage($this->_image);
237: $this->setContent($image);
238: }
239:
240: return parent::toHTML();
241: }
242:
243: }
244: