openrat-cms

OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs | README

Html.class.php (2432B)


      1 <?php
      2 // OpenRat Content Management System
      3 // Copyright (C) 2002-2012 Jan Dankert, cms@jandankert.de
      4 //
      5 // This program is free software; you can redistribute it and/or
      6 // modify it under the terms of the GNU General Public License
      7 // as published by the Free Software Foundation; either version 2
      8 // of the License, or (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU General Public License
     16 // along with this program; if not, write to the Free Software
     17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     18 
     19 
     20 namespace util;
     21 use cms\action\RequestParams;
     22 use cms\base\Configuration;
     23 
     24 /**
     25  * Bereitstellen von Methoden fuer die Darstellung von HTML-Elementen
     26  *
     27  * @author $Author$
     28  * @version $Revision$
     29  * @package openrat.services
     30  */
     31 class Html
     32 {
     33 
     34 
     35 	/**
     36 	 * creates a relative url to an action.
     37 	 *
     38 	 * @param string Aktion, die aufgerufen werden soll
     39 	 * @param string Unteraktion, die innerhalb der Aktion aufgerufen werden soll
     40 	 * @param int Id fuer diesen Aufruf
     41 	 * @param array Weitere beliebige Parameter
     42 	 * @deprecated UI logic, should not be used on the server.
     43 	 */
     44 	public static function url($action, $subaction = '', $id = '', $params = array())
     45 	{
     46 		if (intval($id) == 0)
     47 			$id = '';
     48 
     49 		$conf = Configuration::Conf();
     50 
     51 		// Session-Id ergaenzen
     52 		if ($conf->subset('interface')->subset('url')->is('add_sessionid',false))
     53 			$params[session_name()] = session_id();
     54 
     55 		if ($conf->subset('security')->is('use_post_token'.true))
     56 			$params['token'] = Session::token();
     57 
     58 		if (isset($params['objectid']) && !isset($params['id']))
     59 			$params['id'] = $params['objectid'];
     60 
     61 		$params[RequestParams::PARAM_ACTION   ] = $action;
     62 
     63 		if	( $subaction )
     64 			$params[RequestParams::PARAM_SUBACTION] = $subaction;
     65 
     66 		if	( $id )
     67 			$params[RequestParams::PARAM_ID] = $id;
     68 
     69 		$urlParameterList = array_map( function($name,$value) {
     70 			return urlencode($name) . '=' . urlencode($value);
     71 		},array_keys($params),$params);
     72 
     73 		// We do not escape '&' as '&amp;' here, as it would brake things like Ajax-Urls.
     74 		// Maybe the escaping should be controlled by a parameter.
     75 		return './?'.implode('&', $urlParameterList);
     76 	}
     77 }