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