Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cHTML
  • cHTMLAlignmentTable
  • cHTMLArticle
  • cHTMLAside
  • cHTMLAudio
  • cHTMLButton
  • cHTMLCanvas
  • cHTMLCheckbox
  • cHTMLContentElement
  • cHTMLDiv
  • cHTMLFieldset
  • cHTMLFooter
  • cHTMLForm
  • cHTMLFormElement
  • cHTMLHeader
  • cHTMLHgroup
  • cHTMLHiddenField
  • cHTMLIFrame
  • cHTMLImage
  • cHTMLLabel
  • cHTMLLegend
  • cHTMLLink
  • cHTMLList
  • cHTMLListItem
  • cHTMLNav
  • cHTMLOptgroup
  • cHTMLOptionElement
  • cHTMLParagraph
  • cHTMLPasswordbox
  • cHTMLRadiobutton
  • cHTMLScript
  • cHTMLSection
  • cHTMLSelectElement
  • cHTMLSpan
  • cHTMLTable
  • cHTMLTableBody
  • cHTMLTableData
  • cHTMLTableHead
  • cHTMLTableHeader
  • cHTMLTableRow
  • cHTMLTextarea
  • cHTMLTextbox
  • cHTMLTime
  • cHTMLUpload
  • cHTMLVideo
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the cHTMLLink class.
  5:  *
  6:  * @package Core
  7:  * @subpackage GUI_HTML
  8:  *
  9:  * @author Simon Sprankel
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * cHTMLLink class represents a link.
 20:  *
 21:  * @package Core
 22:  * @subpackage GUI_HTML
 23:  */
 24: class cHTMLLink extends cHTMLContentElement {
 25:     /**
 26:      * Stores the link location
 27:      * @var string
 28:      */
 29:     protected $_link;
 30: 
 31:     /**
 32:      * Stores the content
 33:      *
 34:      * @todo this property overloads cHTML::$_content
 35:      *          and should be removed if unittests are available
 36:      * @var unknown_type
 37:      */
 38:     protected $_content;
 39: 
 40:     /**
 41:      * Stores the anchor
 42:      * @var string
 43:      */
 44:     protected $_anchor;
 45: 
 46:     /**
 47:      * Stores the custom entries
 48:      * @var array
 49:      */
 50:     protected $_custom;
 51: 
 52:     /**
 53:      * @var string
 54:      */
 55:     protected $_image;
 56: 
 57:     /**
 58:      * @var string
 59:      */
 60:     protected $_targetarea;
 61: 
 62:     /**
 63:      * @var string
 64:      */
 65:     protected $_targetframe;
 66: 
 67:     /**
 68:      * @var string
 69:      */
 70:     protected $_targetaction;
 71: 
 72:     /**
 73:      * @var string
 74:      */
 75:     protected $_type;
 76: 
 77:     /**
 78:      * @var string
 79:      */
 80:     protected $_targetarea2;
 81: 
 82:     /**
 83:      * @var string
 84:      */
 85:     protected $_targetaction2;
 86: 
 87:     /**
 88:      * @var string
 89:      */
 90:     protected $_targetframe2;
 91: 
 92:     /**
 93:      * Constructor to create an instance of this class.
 94:      *
 95:      * Creates an HTML link.
 96:      *
 97:      * @param string $href [optional]
 98:      *         String with the location to link to
 99:      */
100:     public function __construct($href = '') {
101:         parent::__construct();
102: 
103:         $this->setLink($href);
104:         $this->_tag = 'a';
105:         $this->_image = '';
106: 
107:         // Check for backend
108:         $sess = cRegistry::getSession();
109:         if (is_object($sess) && get_class($sess) == 'cSession') {
110:             $this->enableAutomaticParameterAppend();
111:         }
112:     }
113: 
114:     /**
115:      *
116:      * @return cHTML
117:      *         $this for chaining
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:      * @return cHTML
126:      *         $this for chaining
127:      */
128:     public function disableAutomaticParameterAppend() {
129:         return $this->unsetEvent('click');
130:     }
131: 
132:     /**
133:      * Sets the link to a specific location
134:      *
135:      * @param string $href
136:      *         String with the location to link to
137:      * @return cHTMLLink
138:      *         $this for chaining
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:      * Sets the target frame
153:      *
154:      * @param string $target
155:      *         Target frame identifier
156:      * @return cHTMLLink
157:      *         $this for chaining
158:      */
159:     public function setTargetFrame($target) {
160:         return $this->updateAttribute('target', $target);
161:     }
162: 
163:     /**
164:      * Sets a CONTENIDO link (area, frame, action)
165:      *
166:      * @param string $targetarea
167:      *         Target backend area
168:      * @param string $targetframe
169:      *         Target frame (1-4)
170:      * @param string $targetaction [optional]
171:      *         Target action
172:      * @return cHTMLLink
173:      *         $this for chaining
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:      * Sets a multilink
186:      *
187:      * @param string $righttoparea
188:      *         Area (right top)
189:      * @param string $righttopaction
190:      *         Action (right top)
191:      * @param string $rightbottomarea
192:      *         Area (right bottom)
193:      * @param string $rightbottomaction
194:      *         Action (right bottom)
195:      * @return cHTMLLink
196:      *         $this for chaining
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:      * Sets a custom attribute to be appended to the link
212:      *
213:      * @param string $key
214:      *         Parameter name
215:      * @param string $value
216:      *         Parameter value
217:      * @return cHTMLLink
218:      *         $this for chaining
219:      */
220:     public function setCustom($key, $value) {
221:         $this->_custom[$key] = $value;
222: 
223:         return $this;
224:     }
225: 
226:     /**
227:      *
228:      * @param string $src
229:      * @return cHTMLLink
230:      *         $this for chaining
231:      */
232:     public function setImage($src) {
233:         $this->_image = $src;
234: 
235:         return $this;
236:     }
237: 
238:     /**
239:      * Unsets a previous set custom attribute
240:      *
241:      * @param string $key
242:      *         Parameter name
243:      * @return cHTMLLink
244:      *         $this for chaining
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:      * @return string
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:      * Sets an anchor
305:      * Only works for the link types Link and cLink.
306:      *
307:      * @param string $content
308:      *         Anchor name
309:      * @return cHTMLLink
310:      *         $this for chaining
311:      */
312:     public function setAnchor($anchor) {
313:         $this->_anchor = $anchor;
314: 
315:         return $this;
316:     }
317: 
318:     /**
319:      * Renders the link
320:      *
321:      * @return string
322:      *         Rendered HTML
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: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0