1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8//this script may only be included - so its better to die if called directly. 9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) { 10 header("location: index.php"); 11 exit; 12} 13 14/** 15 * Smarty modifier plugin to convert a string suitable for a URL using the current SEFURL slug settings wiki_url_scheme 16 * 17 * - type: modifier 18 * - name: slug 19 * - purpose: to return a usable SEFURL URL component string 20 * - note: also removes non-parse wiki tags generated by the list plugin 21 * 22 * Example: href="Page-Name-{$row.object_id}-{$row.title|slug}" 23 * 24 * @param string to be slugified 25 * @param int $length defaults to 70 26 * @param bool $mixedCase set true to preserve capitalisation 27 * @param bool $breakWords set true to break words 28 * 29 * @return string 30 * 31 * @throws SmartyException 32 */ 33 34function smarty_modifier_slug($string, $length = 70, $mixedCase = false, $breakWords = false) 35{ 36 global $prefs; 37 TikiLib::lib('smarty')->loadPlugin('smarty_modifier_nonp'); 38 39 if (! $breakWords) { 40 $offset = strrpos($string, ' ', $length - strlen($string)); 41 if ($offset) { 42 $length = $offset; 43 } 44 } 45 $string = substr(smarty_modifier_nonp($string), 0, $length); 46 if (! $mixedCase) { 47 $string = mb_strtolower($string); 48 } 49 50 $asciiOnly = $prefs['url_only_ascii'] === 'y'; 51 52 $str = TikiLib::lib('slugmanager')->generate($prefs['wiki_url_scheme'], $string, $asciiOnly); 53 54 if (!$asciiOnly) { 55 $str = urlencode($str); 56 } 57 return $str; 58} 59