/** * Create an URI starting with /, regarding the current request * By default, the controller will stay the same * * @param string|array $prm URL Parameters: * - bool absolute If the url should be absolute * - string sep Seperator if needed (default: cfg config empty) * - strong controller * - string lang (if not valid it will be ignored) * - string module * - string action * - array paramA * - string param (using only if paramA doesn't exist) * - string text * - string out (if not valid it will be ignored) * @return string the URL */ public static function uri($prm = array()) { if (!is_array($prm)) $prm = self::uriString($prm); if (self::isAbsolutizeAllUris() && !isset($prm['absolute'])) $prm['absolute'] = true; $sep = array_key_exists('sep', $prm)? $prm['sep'] : self::$cfg->sep; $tmp = array_fill(0, 4, self::$cfg->empty); if (array_key_exists('moduleScaffold', $prm) && !empty($prm['moduleScaffold'])) $tmp[0] = utils::urlify($prm['moduleScaffold']); else if (array_key_exists('module', $prm) && !empty($prm['module'])) $tmp[0] = utils::urlify($prm['module']); if (array_key_exists('action', $prm) && !empty($prm['action'])) $tmp[1] = $prm['action']; if (array_key_exists('paramA', $prm) && is_array($prm['paramA'])) $tmp[2] = self::createParam($prm['paramA'], false); else if (array_key_exists('param', $prm) && !empty($prm['param'])) $tmp[2] = $prm['param']; if (array_key_exists('text', $prm) && !empty($prm['text'])) $tmp[3] = utils::urlify($prm['text']); while(count($tmp) > 0 && (empty($tmp[count($tmp) - 1]) || $tmp[count($tmp) - 1] == self::$cfg->empty)) array_pop($tmp); $out = (array_key_exists('out', $prm) ? (self::isOut($prm['out'])? $prm['out'] : null) : self::getRequested('out')); if (is_null($out) && (!isset($prm['out']) || is_null($prm['out']))) $out = self::$cfg->defaultOut; if ($out) { if (false && empty($tmp)) $tmp[] = self::$cfg->empty.'.'.$out; else if (!empty($tmp) && $out != self::$cfg->noOut) $tmp[count($tmp) - 1] .= '.'.$out; } $forceLang = self::$cfg->forceLang ? (self::$cfg->forceLang === true ? self::$cfg->lang : self::$cfg->forceLang) : null; if (array_key_exists('lang', $prm)) { if (self::isLang($prm['lang'])) array_unshift($tmp, $prm['lang']); else if ($forceLang) array_unshift($tmp, $forceLang); } else if (self::getRequested('lang')) array_unshift($tmp, self::getRequested('lang')); else if (self::$cfg->lang != self::get('lang')) array_unshift($tmp, self::get('lang')); else if ($forceLang && count($tmp)) array_unshift($tmp, $forceLang); if ($forceLang && count($tmp) == 1 && $tmp[0] == $forceLang) $tmp = array(); $prefix = array_key_exists('absolute', $prm) && $prm['absolute']? request::get('domain') : null; $prefix.= self::get('path'); if (array_key_exists('controller', $prm)) { if ($prm['controller']) array_unshift($tmp, $prm['controller']); } else if (self::get('pathWithController')) $prefix.= request::get('controller').'/'; foreach($tmp as &$t) $t = str_replace(array(' ', '/'), self::$cfg->empty, $t); return $prefix.implode($sep, $tmp); }
/** * Create a filename to not erease existing files * * @param string $name Filename * @return string Filename useable */ protected function safeFileName($name) { $name = strtolower(utils::urlify($name, '.')); $ext = file::getExt($name); if ($ext) { $ext = '.' . $ext; } $initName = substr($name, 0, -strlen($ext)); $i = 2; while (file::exists($this->dir . DS . $name)) { $name = $initName . '-' . $i . $ext; $i++; } return $name; }
function clean_filename($filename){ return utils::urlify($filename, '.'); $filename = preg_replace('/^\W+|\W+$/', '', $filename); // remove all non-alphanumeric chars at begin & end of string $filename = preg_replace('/\s+/', '_', $filename); // compress internal whitespace and replace with _ return strtolower(preg_replace('/\W-/', '', $filename)); // remove all non-alphanumeric chars except _ and - }