modifier.translate_path.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
13 
14 /**
15  * Translate the given path into a path relative to the executed script.
16  *
17  * Example:
18  * @code
19  * <a href="{$pdf|translate_path:$cmsBase}" target="_blank">Link</a>
20  * @endcode
21  *
22  * @param $path The path
23  * @param $base Relative path from the executed script to the location
24  * that the given path is relative to.
25  * @param $strict Boolean whether the function should return null, if the url does not exist or not (optiona, default: false)
26  * @return String
27  */
28 function smarty_modifier_translate_path($path, $base, $strict=false) {
29  if (strlen($path) > 0) {
30  $urls = URIUtil::translate($path, $base);
31  return FileUtil::fileExists($urls['relative']) || !$strict ? $urls['relative'] : null;
32  }
33  return null;
34 }
35 ?>
URIUtil provides support for uri manipulation.
Definition: URIUtil.php:18
FileUtil provides basic support for file functionality like HTTP file upload.
Definition: FileUtil.php:22