Esempio n. 1
0
function uriFilter($s)
{
    if ($GLOBALS['oTemplConfig']->bAllowUnicodeInPreg) {
        $s = get_mb_replace('/[^\\pL^\\pN]+/u', '-', $s);
    } else {
        $s = get_mb_replace('/([^\\d^\\w]+)/u', '-', $s);
    }
    // latin characters only
    $s = get_mb_replace('/([-^]+)/', '-', $s);
    $s = get_mb_replace('/([-]+)$/', '', $s);
    // remove trailing dash
    if (!$s) {
        $s = '-';
    }
    return $s;
}
Esempio n. 2
0
function uriFilter($s, $sEmpty = '-')
{
    bx_import('BxTemplConfig');
    if (BxTemplConfig::getInstance()->bAllowUnicodeInPreg) {
        $s = get_mb_replace('/[^\\pL^\\pN]+/u', '-', $s);
    } else {
        $s = get_mb_replace('/([^\\d^\\w]+)/u', '-', $s);
    }
    // latin characters only
    $s = get_mb_replace('/([-^]+)/', '-', $s);
    $s = get_mb_replace('/([-]+)$/', '', $s);
    // remove trailing dash
    if (!$s) {
        $s = $sEmpty;
    }
    return $s;
}
function uriGenerate($s, $sTable, $sField, $iMaxLen = 255)
{
    //$s = get_mb_replace ('/[^\pL^\pN]+/u', '-', $s); // unicode characters
    $s = get_mb_replace('/([^\\d^\\w]+)/', '-', $s);
    // latin characters
    $s = get_mb_replace('/([-^]+)/', '-', $s);
    if (uriCheckUniq($s, $sTable, $sField)) {
        return $s;
    }
    // try to add date
    if (get_mb_len($s) > 240) {
        $s = get_mb_substr($s, 0, 240);
    }
    $s .= '-' . date('Y-m-d');
    if (uriCheckUniq($s, $sTable, $sField)) {
        return $s;
    }
    // try to add number
    for ($i = 0; $i < 999; ++$i) {
        if (uriCheckUniq($s . '-' . $i, $sTable, $sField)) {
            return $s . '-' . $i;
        }
    }
    return rand(0, 999999999);
}
 protected function getFieldName($sObject, $mixedCaption)
 {
     if ($mixedCaption === false) {
         return $this->genFieldName($sObject);
     }
     $sName = get_mb_replace('/([^\\d^\\w]+)/u', '', $mixedCaption);
     if (empty($sName)) {
         return $this->genFieldName($sObject);
     }
     $sName = get_mb_replace('/([^\\d^\\w^\\s]+)/u', '', $mixedCaption);
     $sName = $this->getSystemName(trim($sName));
     if ($this->oDb->isInput($sObject, $sName)) {
         $sName = $this->genFieldName($sObject, $sName);
     }
     return $sName;
 }