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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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: /**
  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:         global $sess;
102:         parent::__construct();
103: 
104:         $this->setLink($href);
105:         $this->_tag = 'a';
106:         $this->_image = '';
107: 
108:         // Check for backend
109:         if (is_object($sess)) {
110:             if ($sess->classname == 'cSession') {
111:                 $this->enableAutomaticParameterAppend();
112:             }
113:         }
114:     }
115: 
116:     /**
117:      *
118:      * @return cHTML
119:      *         $this for chaining
120:      */
121:     public function enableAutomaticParameterAppend() {
122:         return $this->setEvent('click', 'var doit = true; try { var i = get_registered_parameters() } catch (e) { doit = false; }; if (doit == true) { this.href += i; }');
123:     }
124: 
125:     /**
126:      *
127:      * @return cHTML
128:      *         $this for chaining
129:      */
130:     public function disableAutomaticParameterAppend() {
131:         return $this->unsetEvent('click');
132:     }
133: 
134:     /**
135:      * Sets the link to a specific location
136:      *
137:      * @param string $href
138:      *         String with the location to link to
139:      * @return cHTMLLink
140:      *         $this for chaining
141:      */
142:     public function setLink($href) {
143:         $this->_link = $href;
144:         $this->_type = 'link';
145: 
146:         if (strpos($href, 'javascript:') !== false) {
147:             $this->disableAutomaticParameterAppend();
148:         }
149: 
150:         return $this;
151:     }
152: 
153:     /**
154:      * Sets the target frame
155:      *
156:      * @param string $target
157:      *         Target frame identifier
158:      * @return cHTMLLink
159:      *         $this for chaining
160:      */
161:     public function setTargetFrame($target) {
162:         return $this->updateAttribute('target', $target);
163:     }
164: 
165:     /**
166:      * Sets a CONTENIDO link (area, frame, action)
167:      *
168:      * @param string $targetarea
169:      *         Target backend area
170:      * @param string $targetframe
171:      *         Target frame (1-4)
172:      * @param string $targetaction [optional]
173:      *         Target action
174:      * @return cHTMLLink
175:      *         $this for chaining
176:      */
177:     public function setCLink($targetarea, $targetframe, $targetaction = '') {
178:         $this->_targetarea = $targetarea;
179:         $this->_targetframe = $targetframe;
180:         $this->_targetaction = $targetaction;
181:         $this->_type = 'clink';
182: 
183:         return $this;
184:     }
185: 
186:     /**
187:      * Sets a multilink
188:      *
189:      * @param string $righttoparea
190:      *         Area (right top)
191:      * @param string $righttopaction
192:      *         Action (right top)
193:      * @param string $rightbottomarea
194:      *         Area (right bottom)
195:      * @param string $rightbottomaction
196:      *         Action (right bottom)
197:      * @return cHTMLLink
198:      *         $this for chaining
199:      */
200:     public function setMultiLink($righttoparea, $righttopaction, $rightbottomarea, $rightbottomaction) {
201:         $this->_targetarea = $righttoparea;
202:         $this->_targetframe = 3;
203:         $this->_targetaction = $righttopaction;
204:         $this->_targetarea2 = $rightbottomarea;
205:         $this->_targetframe2 = 4;
206:         $this->_targetaction2 = $rightbottomaction;
207:         $this->_type = 'multilink';
208: 
209:         return $this;
210:     }
211: 
212:     /**
213:      * Sets a custom attribute to be appended to the link
214:      *
215:      * @param string $key
216:      *         Parameter name
217:      * @param string $value
218:      *         Parameter value
219:      * @return cHTMLLink
220:      *         $this for chaining
221:      */
222:     public function setCustom($key, $value) {
223:         $this->_custom[$key] = $value;
224: 
225:         return $this;
226:     }
227: 
228:     /**
229:      *
230:      * @param string $src
231:      * @return cHTMLLink
232:      *         $this for chaining
233:      */
234:     public function setImage($src) {
235:         $this->_image = $src;
236: 
237:         return $this;
238:     }
239: 
240:     /**
241:      * Unsets a previous set custom attribute
242:      *
243:      * @param string $key
244:      *         Parameter name
245:      * @return cHTMLLink
246:      *         $this for chaining
247:      */
248:     public function unsetCustom($key) {
249:         if (isset($this->_custom[$key])) {
250:             unset($this->_custom[$key]);
251:         }
252: 
253:         return $this;
254:     }
255: 
256:     /**
257:      *
258:      * @return string
259:      */
260:     public function getHref() {
261:         global $sess;
262: 
263:         if (is_array($this->_custom)) {
264:             $custom = '';
265: 
266:             foreach ($this->_custom as $key => $value) {
267:                 $custom .= "&$key=$value";
268:             }
269:         }
270: 
271:         if ($this->_anchor) {
272:             $anchor = '#' . $this->_anchor;
273:         } else {
274:             $anchor = '';
275:         }
276: 
277:         switch ($this->_type) {
278:             case 'link':
279:                 $custom = '';
280:                 if (is_array($this->_custom)) {
281:                     foreach ($this->_custom as $key => $value) {
282:                         if ($custom == '') {
283:                             $custom .= "?$key=$value";
284:                         } else {
285:                             $custom .= "&$key=$value";
286:                         }
287:                     }
288:                 }
289: 
290:                 return $this->_link . $custom . $anchor;
291:                 break;
292:             case 'clink':
293:                 $this->disableAutomaticParameterAppend();
294:                 return 'main.php?area=' . $this->_targetarea . '&frame=' . $this->_targetframe . '&action=' . $this->_targetaction . $custom . '&contenido=' . $sess->id . $anchor;
295:                 break;
296:             case 'multilink':
297:                 $this->disableAutomaticParameterAppend();
298:                 $tmp_mstr = 'javascript:Con.multiLink(\'%s\',\'%s\',\'%s\',\'%s\');';
299:                 $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));
300:                 return $mstr;
301:                 break;
302:         }
303:     }
304: 
305:     /**
306:      * Sets an anchor
307:      * Only works for the link types Link and cLink.
308:      *
309:      * @param string $content
310:      *         Anchor name
311:      * @return cHTMLLink
312:      *         $this for chaining
313:      */
314:     public function setAnchor($anchor) {
315:         $this->_anchor = $anchor;
316: 
317:         return $this;
318:     }
319: 
320:     /**
321:      * Renders the link
322:      *
323:      * @return string
324:      *         Rendered HTML
325:      */
326:     public function toHtml() {
327:         $this->updateAttribute('href', $this->getHref());
328: 
329:         if ($this->_image != '') {
330:             $image = new cHTMLImage($this->_image);
331:             $this->setContent($image);
332:         }
333: 
334:         return parent::toHtml();
335:     }
336: 
337: }
338: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0