function indexText($text, $type, $id, &$trigramValues, &$suggestionValues)
{
    if (!trim($text)) {
        return;
    }
    static $stopWords, $db;
    if (!$stopWords) {
        $stopWords = Lms_Application::getConfig('indexing', 'stop_words');
    }
    if (!$db) {
        $db = Lms_Db::get('main');
    }
    $trigrams = array();
    $textLength = Lms_Text::length($text);
    if ($textLength >= 3) {
        for ($i = 0; $i <= $textLength - 3; $i++) {
            $trigram = substr($text, $i, 3);
            $trigramValues[] = sprintf("('%s','%s',%d)", mysql_real_escape_string(strtolower($trigram)), $type, $id);
        }
    }
    preg_match_all('{\\w{2,}}', strtolower($text), $words, PREG_PATTERN_ORDER);
    $wordsFiltered = array();
    foreach (array_diff($words[0], $stopWords) as $word) {
        if (!preg_match('{^\\d+$}', $word)) {
            $wordsFiltered[] = $word;
        }
    }
    array_unshift($wordsFiltered, strtolower($text));
    //print_r($wordsFiltered);
    foreach ($wordsFiltered as $word) {
        $suggestionValues[] = sprintf("('%s','%s',%d)", mysql_real_escape_string(trim($word, ' .\'"')), $type, $id);
    }
}
Ejemplo n.º 2
0
 public static function findModule($uri)
 {
     foreach (self::$shemaList as $partUri => $uriConfig) {
         if (Lms_Text::pos($uri, $partUri) === $uriConfig['pos']) {
             return $uriConfig['name'];
         }
     }
     return self::$defaultModule;
 }
Ejemplo n.º 3
0
 /**
  * Set strings encoding
  *
  * @param string $encoding
  */
 public static function setEncoding($encoding)
 {
     self::$encoding = $encoding;
 }
Ejemplo n.º 4
0
 private function _getPlugin($file)
 {
     static $pluginsCache = array();
     foreach ($this->plugins as $str => $plugin) {
         if (Lms_Text::pos($file, $str) === $plugin['pos']) {
             $module = $plugin['name'];
             if (!isset($pluginsCache[$module])) {
                 if ($class_name = $this->loadModule($module)) {
                     $pluginsCache[$module] = new $class_name();
                 }
             }
             return $pluginsCache[$module];
         }
     }
     throw new Lms_Exception('Plugin for "' . $file . '" not found!');
     return false;
 }
 private static function matchStrings($str1, $str2)
 {
     return self::compareStrings($str1, $str2) <= self::maxLevensteinDistance(Lms_Text::length($str1));
 }
 /**
  * Check whether a file is remote
  *
  * @param unknown_type $url
  * @return unknown
  */
 private static function _isRemote($url)
 {
     return (bool) (Lms_Text::pos($url, "http://") !== false || Lms_Text::pos($url, "ftp://") !== false);
 }
 public static function initVariables()
 {
     if (self::$_request) {
         self::$_rootUrl = self::$_request->getBaseUrl();
     }
     if (preg_match('{\\.php$}i', self::$_rootUrl)) {
         self::$_rootUrl = dirname(self::$_rootUrl);
     }
     Lms_Text::setEncoding('CP1251');
     Lms_Text::enableMultiByte();
     Lms_Api_Formatter_Ajax::setEncoding('CP1251');
     Lms_Api_Formatter_Json::setEncoding('CP1251');
     Lms_Thumbnail::setHttpClient(self::getHttpClient());
     Lms_Thumbnail::setThumbnailScript(self::getConfig('thumbnail', 'script'), self::getConfig('thumbnail', 'key'));
     Lms_Thumbnail::setImageDir(rtrim($_SERVER['DOCUMENT_ROOT'] . self::$_rootUrl, '/\\') . '/media/images');
     Lms_Thumbnail::setThumbnailDir(rtrim($_SERVER['DOCUMENT_ROOT'] . self::$_rootUrl, '/\\') . '/media/thumbnails');
     Lms_Thumbnail::setCache(self::getConfig('thumbnail', 'cache'));
 }
Ejemplo n.º 8
0
 private function _SplitToChunks($str, $chunksLimit)
 {
     $chunks = array();
     while ($chunksLimit-- > 0 && ($pos = Lms_Text::pos($str, " ")) !== false) {
         $chunks[] = Lms_Text::substring($str, 0, $pos);
         $str = ltrim(Lms_Text::substring($str, $pos));
     }
     $chunks[] = $str;
     return $chunks;
 }
Ejemplo n.º 9
0
 private static function timeDiff($dateFirst, $dateLast, $limitReturnChunks = 1, Zend_Translate $translator = null, $lang = 'en', $units = self::DEFAULT_UNITS, $precision = 0.25)
 {
     $timeFirst = strtotime($dateFirst);
     $timeLast = strtotime($dateLast);
     $diff = abs($timeLast - $timeFirst);
     $rest = $diff;
     $restChunks = $limitReturnChunks;
     if (strpos($units, 'y') !== false) {
         $years = floor($rest / self::YEAR);
         if ($restChunks <= 1 && ($rest - $years * self::YEAR) / $diff > $precision) {
             $years = 0;
         } else {
             $restChunks--;
         }
         $rest = $rest - $years * self::YEAR;
     } else {
         $years = 0;
     }
     if (strpos($units, 'm') !== false) {
         $months = floor($rest / self::MONTH);
         if ($restChunks <= 1 && ($rest - $months * self::MONTH) / $diff > $precision) {
             $months = 0;
         } else {
             $restChunks--;
         }
         $rest = $rest - $months * self::MONTH;
     } else {
         $months = 0;
     }
     if (strpos($units, 'w') !== false) {
         $weeks = floor($rest / self::WEEK);
         if ($restChunks <= 1 && ($rest - $weeks * self::WEEK) / $diff > $precision) {
             $weeks = 0;
         } else {
             $restChunks--;
         }
         $rest = $rest - $weeks * self::WEEK;
     } else {
         $weeks = 0;
     }
     if (strpos($units, 'd') !== false) {
         $days = floor($rest / self::DAY);
         if ($restChunks <= 1 && ($rest - $days * self::DAY) / $diff > $precision) {
             $days = 0;
         } else {
             $restChunks--;
         }
         $rest = $rest - $days * self::DAY;
     } else {
         $days = 0;
     }
     if (strpos($units, 'h') !== false) {
         $hours = floor($rest / self::HOUR);
         if ($restChunks <= 1 && ($rest - $hours * self::HOUR) / $diff > $precision) {
             $hours = 0;
         } else {
             $restChunks--;
         }
         $rest = $rest - $hours * self::HOUR;
     } else {
         $hours = 0;
     }
     if (strpos($units, 'i') !== false) {
         $mins = floor($rest / self::MIN);
         if ($restChunks <= 1 && ($rest - $mins * self::MIN) / $diff > $precision) {
             $mins = 0;
         } else {
             $restChunks--;
         }
         $rest = $rest - $mins * self::MIN;
     } else {
         $mins = 0;
     }
     if (strpos($units, 's') !== false) {
         $seconds = $rest;
     } else {
         $seconds = 0;
     }
     $chunks = array('year(s)' => $years, 'month(s)' => $months, 'week(s)' => $weeks, 'day(s)' => $days, 'hour(s)' => $hours, 'min(s)' => $mins, 'second(s)' => $seconds);
     $outputStr = '';
     $i = 0;
     foreach ($chunks as $chunkName => $value) {
         if ($value) {
             if ($translator) {
                 $chunkName = $translator->translate($chunkName);
             }
             $translatedChunkNames = explode(" ", $chunkName);
             $translatedChunkName = Lms_Text::declension($value, $translatedChunkNames, $lang);
             $outputStr .= " {$value} {$translatedChunkName}";
             $i++;
             if ($i >= $limitReturnChunks) {
                 break;
             }
         }
     }
     $outputStr = trim($outputStr);
     return $outputStr;
 }