public static function logon($params)
 {
     $config = Lms_Application::getConfig('auth');
     $authProviderKey = $config['module'];
     $authClassName = 'Lms_Auth_Adapter_' . ucfirst($config['module']);
     $authAdapter = new $authClassName(Lms_Db::get($config['db']));
     $authAdapter->setIdentity($params['username'])->setCredential($params['password']);
     $auth = Lms_MultiAuth::getInstance();
     if (!$params['remember']) {
         $storage = $auth->getStorage();
         $storage->setCookieExpire(0);
     }
     $result = $auth->authenticate($authAdapter, $config['module']);
     if (!$result->isValid()) {
         $auth->clearIdentity();
         $errors = $result->getMessages();
         $translate = Lms_Application::getTranslate();
         foreach ($errors as &$error) {
             $error = $translate->translate($error);
         }
         return new Lms_Api_Response(401, 'Authorization failed', $errors);
     } else {
         return new Lms_Api_Response(200, 'OK');
     }
 }
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);
    }
}
 public static function postProcess(&$rows, $coverWidth = 100)
 {
     foreach ($rows as &$row) {
         if (isset($row["international_name"])) {
             $row["international_name"] = htmlentities($row["international_name"], ENT_NOQUOTES, 'cp1252');
         }
         if (isset($row["covers"])) {
             $covers = array_values(array_filter(preg_split("/(\r\n|\r|\n)/", $row["covers"])));
             $row["cover"] = array_shift($covers);
             if ($row["cover"]) {
                 $row["cover"] = Lms_Application::thumbnail($row["cover"], $width = $coverWidth, $height = 0, $defer = true);
             }
             unset($row["covers"]);
         }
     }
 }
 public static function getUser()
 {
     if (!self::$_userInstance) {
         self::$_userInstance = new Lms_Item_User();
         self::initUserInstance();
     }
     if (self::$_identified === null) {
         Lms_Application::getAuthData($login, $pass);
         if ($login && $pass) {
             self::$_userInstance->loadFromDb($login, $pass);
         }
         if (!self::$_userInstance->getId()) {
             self::$_userInstance->loadFromDb('guest');
         }
         self::$_identified = true;
     }
     return self::$_userInstance;
 }
<?php

/**
 * @copyright 2006-2011 LanMediaService, Ltd.
 * @license    http://www.lanmediaservice.com/license/1_0.txt
 * @author Ilya Spesivtsev <*****@*****.**>
 * @version $Id: api.php 700 2011-06-10 08:40:53Z macondos $
 */
if (!isset($_GET['p']) || !isset($_GET['v'])) {
    exit;
}
define('SKIP_DEBUG_CONSOLE', true);
require_once dirname(__FILE__) . "/app/config.php";
Lms_Application::setRequest();
Lms_Application::prepareApi();
Lms_Debug::debug('Request URI: ' . $_SERVER['REQUEST_URI']);
$url = Lms_Thumbnail::processDeferUrl($_GET);
if ($url) {
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: ' . $url);
    header("Pragma: public");
    header("Cache-Control: public");
    header("Expires: " . date("r", time() + 600));
}
Lms_Application::close();
 public static function hitFilm($params)
 {
     try {
         $db = Lms_Db::get('main');
         $filmId = (int) $params['film_id'];
         Lms_Application::hitFilm($filmId);
         return new Lms_Api_Response(200);
     } catch (Exception $e) {
         return new Lms_Api_Response(500, $e->getMessage());
     }
 }
 private function getCompiledItem()
 {
     $compress = Lms_Application::getConfig('optimize', 'js_compress');
     $filename = md5(serialize($this->_cache));
     $path = self::$cacheDir . $filename . ($compress ? '_compressed' : '') . '.js';
     if (!file_exists($path)) {
         Lms_Debug::debug("Combine javascripts to {$path}...");
         Lms_FileSystem::createFolder(dirname($path), 0777, true);
         $jsContent = '';
         foreach ($this->_cache as $js) {
             if (is_array($js)) {
                 $jsContent .= file_get_contents($js['filepath']) . "\n\n";
                 Lms_Debug::debug($js['filepath'] . ' ... OK');
             } else {
                 $jsContent .= $js . "\n\n";
                 Lms_Debug::debug('Inline JavaScript ... OK');
             }
         }
         if ($compress) {
             $jsContent = JSMin::minify($jsContent);
         }
         file_put_contents($path, $jsContent);
     }
     $url = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path);
     $item = $this->createData('text/javascript', array('src' => $url));
     return $item;
 }
 private function getCompiledItem()
 {
     $compress = Lms_Application::getConfig('optimize', 'css_compress');
     $filename = md5(serialize($this->_cache));
     $path = self::$cacheDir . $filename . ($compress ? '_compressed' : '') . '.css';
     if (!file_exists($path)) {
         Lms_Debug::debug("Combine css to {$path}...");
         Lms_FileSystem::createFolder(dirname($path), 0777, true);
         $cssContent = '';
         foreach ($this->_cache as $css) {
             $content = file_get_contents($css['filepath']);
             if ($compress) {
                 $cssContent .= Minify_CSS::minify($content, array('prependRelativePath' => dirname($path), 'currentDir' => dirname($css['filepath']), 'symlinks' => Lms_Application::getConfig('symlinks')));
             } else {
                 $cssContent .= Minify_CSS_UriRewriter::rewrite($content, dirname($css['filepath']), $_SERVER['DOCUMENT_ROOT'], Lms_Application::getConfig('symlinks'));
             }
             $cssContent .= "\n\n";
             Lms_Debug::debug($css['filepath'] . ' ... OK');
         }
         file_put_contents($path, $cssContent);
     }
     $url = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path);
     $item = $this->createDataStylesheet(array('href' => $url));
     return $item;
 }
<?php

/**
 * @copyright 2006-2011 LanMediaService, Ltd.
 * @license    http://www.lanmediaservice.com/license/1_0.txt
 * @author Ilya Spesivtsev <*****@*****.**>
 * @version $Id: api.php 700 2011-06-10 08:40:53Z macondos $
 */
if (!isset($_GET['q'])) {
    exit;
}
require_once dirname(__FILE__) . "/app/config.php";
$query = Lms_Translate::translate('UTF-8', 'CP1251', $_GET['q']);
$_POST['action'][0] = 'Video.getSuggestion';
$_POST['query'][0] = $query;
$_GET['format'] = 'json';
Lms_Application::runApi();
header("Pragma: private");
header("Cache-Control: private");
header("Expires: " . date("r", time() + 600));
#!/usr/local/bin/php -q
<?php 
require_once dirname(__FILE__) . '/include/init.php';
$db = Lms_Db::get('main');
$db->query('TRUNCATE `suggestion_cache`');
echo "\nIndexing...";
$n = 1;
$limit = 100;
while (true) {
    $rows = $db->select('SELECT (LEFT(`word`,?d)) as `query`, COUNT(*) as c FROM `suggestion` WHERE LENGTH(`word`)>=?d GROUP BY (LEFT(`word`, ?d)) HAVING c>?d', $n, $n, $n, $limit);
    if (!count($rows)) {
        break;
    }
    echo "\n{$n}: " . count($rows) . " ({$rows[0]['query']}) ";
    foreach ($rows as $num => $row) {
        if (!($num % 10)) {
            echo '.';
        }
        $suggestion = Lms_Application::getSuggestion($row['query']);
        $db->query('INSERT IGNORE INTO `suggestion_cache` SET `query`=? ,`result`=?', $row['query'], Zend_Json::encode($suggestion));
    }
    echo ' OK';
    $n += 1;
}
echo "\nDone\n";
require_once dirname(__FILE__) . '/include/end.php';
 public static function getHttpClient()
 {
     if (!self::$_httpClient) {
         $httpOptions = Lms_Application::getConfig('http_client');
         self::$_httpClient = new Zend_Http_Client(null, $httpOptions);
     }
     return self::$_httpClient;
 }
<?php

@ini_set('max_execution_time', 0);
@set_time_limit();
if (!defined('LOGS_SUBDIR')) {
    define('LOGS_SUBDIR', 'tasks');
}
require_once dirname(dirname(dirname(__FILE__))) . "/config.php";
Lms_Application::prepareApi();