Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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:  * This file contains the cHTMLLink class.
  4:  *
  5:  * @package Core
  6:  * @subpackage GUI_HTML
  7:  * @version SVN Revision $Rev:$
  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:     protected $_link;
 28: 
 29:     /* Stores the content */
 30:     protected $_content;
 31: 
 32:     /* Stores the anchor */
 33:     protected $_anchor;
 34: 
 35:     /* Stores the custom entries */
 36:     protected $_custom;
 37: 
 38:     protected $_image;
 39: 
 40:     /**
 41:      * Constructor.
 42:      * Creates an HTML link.
 43:      *
 44:      * @param string $href String with the location to link to
 45:      * @return void
 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:         // Check for backend
 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:      * Sets the link to a specific location
 73:      *
 74:      * @param string $href String with the location to link to
 75:      * @return cHTMLLink $this
 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:      * Sets the target frame
 90:      *
 91:      * @param string $target Target frame identifier
 92:      * @return cHTMLLink $this
 93:      */
 94:     public function setTargetFrame($target) {
 95:         return $this->updateAttribute('target', $target);
 96:     }
 97: 
 98:     /**
 99:      * Sets a CONTENIDO link (area, frame, action)
100:      *
101:      * @param string $targetarea Target backend area
102:      * @param string $targetframe Target frame (1-4)
103:      * @param string $targetaction Target action
104:      * @return cHTMLLink $this
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:      * Sets a multilink
117:      *
118:      * @param string $righttoparea Area (right top)
119:      * @param string $righttopaction Action (right top)
120:      * @param string $rightbottomarea Area (right bottom)
121:      * @param string $rightbottomaction Action (right bottom)
122:      * @return cHTMLLink $this
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:      * Sets a custom attribute to be appended to the link
138:      *
139:      * @param string $key Parameter name
140:      * @param string $value Parameter value
141:      * @return cHTMLLink $this
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:      * Unsets a previous set custom attribute
157:      *
158:      * @param string $key Parameter name
159:      * @return cHTMLLink $this
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:      * Sets an anchor
216:      * Only works for the link types Link and cLink.
217:      *
218:      * @param string $content Anchor name
219:      * @return cHTMLLink $this
220:      */
221:     public function setAnchor($anchor) {
222:         $this->_anchor = $anchor;
223: 
224:         return $this;
225:     }
226: 
227:     /**
228:      * Renders the link
229:      *
230:      * @return string Rendered HTML
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: 
CMS CONTENIDO 4.9.1 API documentation generated by ApiGen 2.8.0