wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
function.translate_url.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: function.translate_url.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/util/class.URIUtil.php");
20 
21 /*
22 * Smarty plugin
23 * -------------------------------------------------------------
24 * File: function.translate_url.php
25 * Type: function
26 * Name: translate_url
27 * Purpose: translate a relative url into an absolute one. The 'base' parameter
28 * defines the relative path from the executed script to the location
29 * from which the relative path given in the 'url' parameter is seen
30 * from. The result maybe printed directly or assigned to a smarty variable.
31 * If the parameter 'absolute' is set to true, the url will be given absolute
32 * (the default value is false which means the url is relative).
33 * Example: If an image is stored in the database under the location
34 * '../../media/image1.png' as seen from http://www.example.com/cms/application/main.php
35 * and the image should be displayed in a template that is displayed by the script
36 * http://www.example.com/index.php than the image url may be translated by using the
37 * following call:
38 * Usage: {translate_url url=$image->getFile() base="cms/application/"} or
39 * {translate_url url=$image->getFile() base="cms/application/" varname="imageFile" absolute=true}
40 * -------------------------------------------------------------
41 */
42 function smarty_function_translate_url($params, &$smarty)
43 {
44  $url = $params['url'];
45  $base = $params['base'];
46 
47  $urls = URIUtil::translate($url, $base);
48 
49  $result = $urls['relative'];
50  if (isset($params['absolute']) && $params['absolute'])
51  $result = $urls['absolute'];
52 
53  if (isset($params['varname']))
54  $smarty->assign($params['varname'], $result);
55  else
56  echo $result;
57 }
58 ?>
smarty_function_translate_url($params, &$smarty)
translate($rel_uri, $base)