public function exec()
 {
     $responses = array();
     foreach ($this->_actions as $actionNum => $actionParams) {
         Lms_Debug::debug('Action: ' . str_replace("\n", "", print_r($actionParams, 1)));
         $actionName = $actionParams['action'];
         list($serverName, $method) = explode('.', $actionName);
         $serverClass = 'Lms_Api_Server_' . ucfirst($serverName);
         if (is_callable(array($serverClass, $method))) {
             $responses[$actionNum] = call_user_func(array($serverClass, $method), $actionParams);
         } else {
             if (class_exists($serverClass, true)) {
                 $responses[$actionNum] = new Lms_Api_Response(500, 'Unknown API Service method');
             } else {
                 $responses[$actionNum] = new Lms_Api_Response(500, 'Unknown API Service');
             }
         }
     }
     $formatterClass = 'Lms_Api_Formatter_' . ucfirst($this->_format);
     $formatter = new $formatterClass();
     $formatter->setUp();
     foreach ($responses as $actionNum => $response) {
         echo $formatter->format($actionNum, $response);
     }
 }
 public static function compileTo($outputFile)
 {
     if (!count(self::$loadedFiles)) {
         return;
     }
     $fp = fopen($outputFile, "a+");
     if (flock($fp, LOCK_EX)) {
         if ($filesize = filesize($outputFile)) {
             fseek($fp, 0);
             $currentFile = fread($fp, $filesize);
         } else {
             $currentFile = '';
         }
         if (!$currentFile) {
             $appendSource = "<?php\n";
             $existingClasses = array();
         } else {
             $appendSource = '';
             $existingClasses = self::getClassesFromSource($currentFile);
         }
         for ($i = 0; $i < count(self::$loadedFiles); $i++) {
             $filename = self::$loadedFiles[$i];
             if (self::$excludeRegexp && preg_match(self::$excludeRegexp, $filename)) {
                 continue;
             }
             $f = @fopen($filename, "r", true);
             $fstat = fstat($f);
             $file = fread($f, $fstat['size']);
             fclose($f);
             $classes = self::getClassesFromSource($file);
             if (!count(array_intersect($existingClasses, $classes))) {
                 if (strpos($file, '__FILE__') === false) {
                     Lms_Debug::debug("Complile autoload {$filename}");
                     $endFile = substr($file, -2) == '?>' ? -2 : null;
                     $appendSource .= $endFile === null ? substr($file, 5) : substr($file, 5, -2);
                 } else {
                     //Потенциально ненадежно, но работает
                     $filePath = self::realPath($filename);
                     if ($filePath) {
                         Lms_Debug::warn("Complile autoload with __FILE__ constant {$filename}");
                         $file = str_replace('__FILE__', "'{$filePath}'", $file);
                         $endFile = substr($file, -2) == '?>' ? -2 : null;
                         $appendSource .= $endFile === null ? substr($file, 5) : substr($file, 5, -2);
                     }
                 }
             } else {
                 Lms_Debug::debug("Conflict detect on file {$filename}. Complile autoload terminated.");
                 $appendSource = '';
                 break;
             }
         }
         if ($appendSource) {
             fseek($fp, 0, SEEK_END);
             fwrite($fp, $appendSource);
         }
         flock($fp, LOCK_UN);
     }
     fclose($fp);
 }
<?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();
 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;
 }
Exemplo n.º 5
0
 /**
  * Журналирует сообщения
  *
  * @param string $db
  * @param string $sql
  */
 public static function databaseLogger($db, $sql)
 {
     $caller = $db->findLibraryCaller();
     Lms_Debug::debug($sql . " -- {$caller['file']}, {$caller['line']} ");
 }
 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;
 }
 public static function close()
 {
     if (self::getConfig('optimize', 'classes_combine')) {
         Lms_NameScheme_Autoload::compileTo(APP_ROOT . '/includes/All.php');
     }
     foreach (self::$_config['databases'] as $dbAlias => $dbConfig) {
         if (Lms_Db::isInstanciated($dbAlias)) {
             $db = Lms_Db::get($dbAlias);
             $sqlStatistics = $db->getStatistics();
             $time = round(1000 * $sqlStatistics['time']);
             $count = $sqlStatistics['count'];
             Lms_Debug::debug("Database {$dbAlias} time: {$time} ms ({$count} queries)");
         }
     }
     foreach (Lms_Timers::getTimers() as $name => $timer) {
         $time = round(1000 * $timer->getSumTime());
         Lms_Debug::debug('Profiling "' . $name . '": ' . $time . ' ms (' . $timer->getCount() . ')');
     }
     Lms_Debug::debug('Used memory: ' . round(memory_get_usage() / 1024) . ' KB');
     self::$_mainTimer->stop();
     $time = round(1000 * self::$_mainTimer->getSumTime());
     Lms_Debug::debug("Execution time: {$time} ms");
 }