function transferCategories()
 {
     $sSql = "SELECT \r\n        \t\t\t`CategoryID` AS `id`, \r\n        \t\t\t`CategoryName` AS `name`\r\n        \t\tFROM `ArticlesCategory`";
     $rResult = mysql_query($sSql, $this->rOldDb);
     $iCount = mysql_num_rows($rResult);
     while ($aCategory = mysql_fetch_assoc($rResult)) {
         if (get_mb_len($aCategory['name']) > 32) {
             $aCategory['name'] = get_mb_substr($aCategory['name'], 0, 32);
         }
         if ($this->existsCategory($aCategory['name'], 0, $this->_sType)) {
             continue;
         }
         //escape all values
         $aCategory['name'] = $this->oMigrationModule->_oDb->escape($aCategory['name']);
         $sSql = "INSERT INTO `sys_categories`(`Category`, `ID`, `Type`, `Owner`, `Status`, `Date`)\r\n            \t\t VALUES('" . $aCategory['name'] . "', '0', '" . $this->_sType . "', '0', 'active', NOW())";
         $iResult = (int) $this->oDolModule->_oDb->query($sSql);
         if ($iResult <= 0) {
             $this->setResultStatus('Database error. Cannot insert category in the database.');
             return MIGRATION_FAILED;
         }
     }
     return MIGRATION_SUCCESSFUL;
 }
示例#2
0
function uriGenerate($s, $sTable, $sField, $iMaxLen = 255)
{
    $s = uriFilter($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);
}
示例#3
0
 function checkLength($s, $iLenMin, $iLenMax)
 {
     if (is_array($s)) {
         foreach ($s as $k => $v) {
             $iLen = get_mb_len($v);
             if ($iLen < $iLenMin || $iLen > $iLenMax) {
                 return false;
             }
         }
         return true;
     }
     $iLen = get_mb_len($s);
     return $iLen >= $iLenMin && $iLen <= $iLenMax ? true : false;
 }
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);
}
示例#5
0
function uriGenerate($s, $sTable, $sField, $sEmpty = '-')
{
    $s = uriFilter($s, $sEmpty);
    if (uriCheckUniq($s, $sTable, $sField)) {
        return $s;
    }
    // cut off redundant part
    if (get_mb_len($s) > 240) {
        $s = get_mb_substr($s, 0, 240);
    }
    // try to add date
    $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);
}
示例#6
0
 /**
  * Prepare SQL query before execution if some arguments are need to be passed to it.
  * All parameters marked with question (?) symbol in SQL query are replaced with parameters passed after SQL query parameter.
  * Parameters are properly excaped and surrounded by qutes if needed.
  * Example:
  * @code
  * $sSql = $oDb->prepare("SELECT `a`, `b` from `t` WHERE `c` = ? and `d` = ?", 12, 'aa');
  * echo $sSql;// outputs: SELECT `a`, `b` from `t` WHERE `c` = 12 and `d` = 'aa'
  * $a = $oDb->getAll($sSql);
  * @endcode
  *
  * @param  string $sQuery SQL query, parameters for replacing are marked with ? symbol
  * @param  mixed  $mixed  any number if parameters to replace, number of parameters whould match number of ? symbols in SQL query
  * @return string with SQL query ready for execution
  */
 function prepare($sQuery)
 {
     $aArgs = func_get_args();
     $sQuery = array_shift($aArgs);
     $iPos = 0;
     foreach ($aArgs as $mixedArg) {
         if (is_null($mixedArg)) {
             $s = 'NULL';
         } elseif (is_numeric($mixedArg)) {
             $s = $mixedArg;
         } else {
             $s = "'" . mysql_real_escape_string($mixedArg) . "'";
         }
         $i = bx_mb_strpos($sQuery, '?', $iPos);
         $sQuery = bx_mb_substr_replace($sQuery, $s, $i, 1);
         $iPos = $i + get_mb_len($s);
     }
     return $sQuery;
 }
示例#7
0
 function getCorrectUri($sCaption, $iOwnerId = 0, $bCheck = true)
 {
     $sUri = uriFilter($sCaption);
     if (!$sUri) {
         $sUri = '-';
     }
     if (!$bCheck) {
         return $sUri;
     }
     if ($this->checkUriUniq($sUri, $iOwnerId)) {
         return $sUri;
     }
     if (get_mb_len($sUri) > 240) {
         $sUri = get_mb_substr($sUri, 0, 240);
     }
     $sUri .= '-' . date('Y-m-d');
     if ($this->checkUriUniq($sUri, $iOwnerId)) {
         return $sUri;
     }
     for ($i = 0; $i < 999; ++$i) {
         if ($this->checkUriUniq($sUri . '-' . $i, $iOwnerId)) {
             return $sUri . '-' . $i;
         }
     }
     return time();
 }