Example #1
0
 public function prepare(CM_Frontend_Environment $environment, CM_Frontend_ViewResponse $viewResponse)
 {
     $level = $this->_params->has('level') ? $this->_params->getInt('level') : null;
     if (null !== $level && !CM_Log_Logger::hasLevel($level)) {
         throw new CM_Exception_InvalidParam('Invalid `level` param');
     }
     $levelList = $level ? [$level] : null;
     $type = $this->_params->has('type') ? $this->_params->getInt('type') : null;
     if (null !== $type && !CM_Paging_Log::isValidType($type)) {
         throw new CM_Exception_InvalidParam('Invalid `type` param');
     }
     $aggregate = $this->_params->has('aggregate') ? $this->_params->getInt('aggregate') : null;
     $urlPage = $this->_params->has('urlPage') ? $this->_params->getString('urlPage') : null;
     $urlParams = $this->_params->has('urlParams') ? $this->_params->getArray('urlParams') : null;
     $aggregationPeriod = $aggregate;
     if (0 === $aggregationPeriod) {
         $deployStamp = CM_App::getInstance()->getDeployVersion();
         $aggregationPeriod = time() - $deployStamp;
     }
     $logList = new CM_Paging_Log($levelList, $type, (bool) $aggregationPeriod, $aggregationPeriod);
     $logList->setPage($this->_params->getPage(), $this->_params->getInt('count', 50));
     $viewResponse->setData(['level' => $level, 'type' => $type, 'logList' => $logList, 'aggregate' => $aggregate, 'aggregationPeriod' => $aggregationPeriod, 'aggregationPeriodList' => array(3600, 86400, 7 * 86400, 31 * 86400), 'urlPage' => $urlPage, 'urlParams' => $urlParams, 'levelMap' => array_flip(CM_Log_Logger::getLevels())]);
     $viewResponse->getJs()->setProperty('level', $level);
     $viewResponse->getJs()->setProperty('type', $type);
 }
Example #2
0
 public function testProcessReturnDeployVersion()
 {
     $response = $this->getResponseAjax(new CM_Page_View_Ajax_Test_Mock(), 'loadPage', ['path' => CM_Page_View_Ajax_Test_MockRedirect::getPath()]);
     $responseDecoded = CM_Params::jsonDecode($response->getContent());
     $this->assertArrayHasKey('deployVersion', $responseDecoded);
     $this->assertSame(CM_App::getInstance()->getDeployVersion(), $responseDecoded['deployVersion']);
 }
Example #3
0
 /**
  * @return CM_App
  */
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Example #4
0
 /**
  * @param string   $hostname
  * @param int      $port
  * @param string   $tag
  * @param int|null $minLevel
  * @return CM_Log_Handler_Fluentd
  * @throws CM_Exception_Invalid
  */
 public function createFluentdLogger($hostname, $port, $tag, $minLevel = null)
 {
     $fluentd = new \Fluent\Logger\FluentLogger($hostname, $port);
     $appName = CM_App::getInstance()->getName();
     $contextFormatter = new CM_Log_ContextFormatter_Cargomedia($appName);
     return new CM_Log_Handler_Fluentd($fluentd, $contextFormatter, $tag, $minLevel);
 }
Example #5
0
 /**
  * @param integer     $version
  * @param string|null $namespace
  */
 public function runUpdate($version, $namespace = null)
 {
     $versionBumps = CM_App::getInstance()->runUpdateScript($namespace, $version);
     if ($versionBumps > 0) {
         $db = CM_Db_Db::getClient()->getDatabaseName();
         CM_Db_Db::exec('DROP DATABASE IF EXISTS `' . $db . '_test`');
     }
 }
Example #6
0
 public function testProcessReturnDeployVersion()
 {
     $body = CM_Params::jsonEncode(['method' => 'CM_Http_Response_RPCTest.add', 'params' => [2, 3]]);
     $site = $this->getMockSite();
     $request = new CM_Http_Request_Post('/rpc', null, null, $body);
     $response = CM_Http_Response_RPC::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $responseDecoded = CM_Params::jsonDecode($response->getContent());
     $this->assertArrayHasKey('deployVersion', $responseDecoded);
     $this->assertSame(CM_App::getInstance()->getDeployVersion(), $responseDecoded['deployVersion']);
 }
Example #7
0
 private function _setInitialVersion()
 {
     $app = CM_App::getInstance();
     foreach (CM_App::getInstance()->getUpdateScriptPaths() as $namespace => $path) {
         $updateFiles = CM_Util::rglob('*.php', $path);
         $version = array_reduce($updateFiles, function ($initial, $path) {
             $filename = basename($path);
             return max($initial, (int) $filename);
         }, 0);
         $app->setVersion($version, $namespace);
     }
 }
Example #8
0
 protected function _getEmoticonImg($emoticonCode, $height = null)
 {
     $emoticon = CM_Emoticon::findByCode($emoticonCode);
     if (!$emoticon) {
         throw new CM_Exception_Invalid('Cannot find emoticon for code `' . $emoticonCode . '`.');
     }
     $urlCdn = $this->_mockSite->getUrlCdn();
     $siteType = $this->_mockSite->getId();
     $deployVersion = CM_App::getInstance()->getDeployVersion();
     $heightAttribute = $height ? ' height="' . $height . '"' : '';
     return '<img src="' . $urlCdn . '/layout/' . $siteType . '/' . $deployVersion . '/img/emoticon/' . $emoticon->getFileName() . '" class="emoticon emoticon-' . $emoticon->getName() . '" title="' . $emoticon->getDefaultCode() . '"' . $heightAttribute . ' />';
 }
Example #9
0
/**
 * @param CM_Frontend_Render $render
 * @return string
 */
function smarty_helper_resourceJs_libraryDebug(CM_Frontend_Render $render)
{
    $paths = CM_Asset_Javascript_Library::getIncludedPaths($render->getSite());
    $content = '';
    foreach ($paths as $path) {
        $path = str_replace(DIR_ROOT, '/', $path);
        $path = str_replace(DIRECTORY_SEPARATOR, '/', $path);
        $path .= '?' . CM_App::getInstance()->getDeployVersion();
        $content .= '<script type="text/javascript" src="' . $path . '"></script>' . PHP_EOL;
    }
    $content .= smarty_helper_resourceJs('library', 'library.js?debug=true', $render);
    return $content;
}
Example #10
0
 public function prepare(CM_Frontend_Environment $environment, CM_Frontend_ViewResponse $viewResponse)
 {
     $type = $this->_params->getInt('type');
     $aggregate = $this->_params->has('aggregate') ? $this->_params->getInt('aggregate') : null;
     $urlPage = $this->_params->has('urlPage') ? $this->_params->getString('urlPage') : null;
     $urlParams = $this->_params->has('urlParams') ? $this->_params->getArray('urlParams') : null;
     $aggregationPeriod = $aggregate;
     if (0 === $aggregationPeriod) {
         $deployStamp = CM_App::getInstance()->getDeployVersion();
         $aggregationPeriod = time() - $deployStamp;
     }
     $logList = CM_Paging_Log_Abstract::factory($type, (bool) $aggregationPeriod, $aggregationPeriod);
     $logList->setPage($this->_params->getPage(), $this->_params->getInt('count', 50));
     $viewResponse->setData(['type' => $type, 'logList' => $logList, 'aggregate' => $aggregate, 'aggregationPeriod' => $aggregationPeriod, 'aggregationPeriodList' => array(3600, 86400, 7 * 86400, 31 * 86400), 'urlPage' => $urlPage, 'urlParams' => $urlParams]);
     $viewResponse->getJs()->setProperty('type', $type);
 }
Example #11
0
 /**
  * @param array $servers
  * @return CM_Janus_Service
  * @throws CM_Exception_Invalid
  */
 public function createService(array $servers)
 {
     $serverList = new CM_Janus_ServerList();
     foreach ($servers as $serverId => $serverConfig) {
         $iceServerList = isset($serverConfig['iceServerList']) ? $serverConfig['iceServerList'] : null;
         if (empty($serverConfig['pluginList'])) {
             throw new CM_Exception_Invalid('Server pluginList is empty');
         }
         $serverList->addServer(new CM_Janus_Server($serverId, $serverConfig['key'], $serverConfig['httpAddress'], $serverConfig['webSocketAddress'], $serverConfig['pluginList'], new CM_Geo_Point($serverConfig['coordinates']['latitude'], $serverConfig['coordinates']['longitude']), $iceServerList));
     }
     $httpClient = new GuzzleHttp\Client();
     $appName = CM_App::getInstance()->getName();
     $contextFormatter = new CM_Log_ContextFormatter_Cargomedia($appName);
     $httpApiClient = new CM_Janus_HttpApiClient($httpClient, $contextFormatter);
     $janus = new CM_Janus_Service($serverList, $httpApiClient);
     return $janus;
 }
Example #12
0
 /**
  * @return string
  */
 public function fetch()
 {
     $page = $this->_getPage();
     $layout = $this->_getLayout();
     $page->checkAccessible($this->getRender()->getEnvironment());
     $frontend = $this->getRender()->getGlobalResponse();
     $viewResponse = new CM_Frontend_ViewResponse($layout);
     $viewResponse->setTemplateName('default');
     $layout->prepare($this->getRender()->getEnvironment(), $viewResponse);
     $viewResponse->set('viewResponse', $viewResponse);
     $viewResponse->set('page', $page);
     $viewResponse->set('pageTitle', $this->fetchTitle());
     $viewResponse->set('pageDescription', $this->fetchDescription());
     $viewResponse->set('pageKeywords', $this->fetchKeywords());
     $viewResponse->set('renderAdapter', $this);
     $environmentDefault = new CM_Frontend_Environment($this->getRender()->getEnvironment()->getSite());
     $renderDefault = new CM_Frontend_Render($environmentDefault);
     $viewResponse->set('renderDefault', $renderDefault);
     $viewResponse->set('languageList', new CM_Paging_Language_Enabled());
     $serviceManager = CM_Service_Manager::getInstance();
     $options = array();
     $options['deployVersion'] = CM_App::getInstance()->getDeployVersion();
     $options['renderStamp'] = floor(microtime(true) * 1000);
     $options['site'] = CM_Params::encode($this->getRender()->getSite());
     $options['url'] = $this->getRender()->getSite()->getUrl();
     $options['urlCdn'] = $this->getRender()->getSite()->getUrlCdn();
     $options['urlUserContentList'] = $serviceManager->getUserContent()->getUrlList();
     $options['language'] = $this->getRender()->getLanguage();
     $options['debug'] = CM_Bootloader::getInstance()->isDebug();
     $options['stream'] = $serviceManager->getStreamMessage()->getClientOptions();
     if ($viewer = $this->getRender()->getViewer()) {
         $options['stream']['channel']['key'] = CM_Model_StreamChannel_Message_User::getKeyByUser($viewer);
         $options['stream']['channel']['type'] = CM_Model_StreamChannel_Message_User::getTypeStatic();
     }
     $frontend->getOnloadHeaderJs()->append('cm.options = ' . CM_Params::encode($options, true));
     if ($viewer = $this->getRender()->getViewer()) {
         $frontend->getOnloadHeaderJs()->append('cm.viewer = ' . CM_Params::encode($viewer, true));
     }
     $frontend->treeExpand($viewResponse);
     $frontend->getOnloadReadyJs()->append('cm.getLayout()._ready();');
     $frontend->getOnloadHeaderJs()->append('cm.ready();');
     $html = $this->getRender()->fetchViewResponse($viewResponse);
     $frontend->treeCollapse();
     return $html;
 }
Example #13
0
 public function testProcessEmoticon()
 {
     $deployVersion = CM_App::getInstance()->getDeployVersion();
     $siteType = CM_Site_Abstract::factory()->getType();
     $usertext = new CM_Usertext_Usertext(new CM_Frontend_Render());
     $expectedValuePlain = "<img src=\"http://cdn.default.dev/layout/" . $siteType . "/" . $deployVersion . "/img/emoticon/cold_sweat.png\" class=\"emoticon emoticon-cold_sweat\" title=\":cold_sweat:\" />";
     $expectedValueMarkdown = "<p><img src=\"http://cdn.default.dev/layout/" . $siteType . "/" . $deployVersion . "/img/emoticon/cold_sweat.png\" class=\"emoticon emoticon-cold_sweat\" title=\":cold_sweat:\" /></p>";
     $usertext->setMode('escape');
     $this->assertSame('&lt;3', $usertext->transform('<3'));
     $usertext->setMode('oneline');
     $this->assertSame($expectedValuePlain, $usertext->transform(':-\\\\'));
     $usertext->setMode('simple');
     $this->assertSame($expectedValuePlain, $usertext->transform(':-\\\\'));
     $usertext->setMode('markdown');
     $this->assertSame($expectedValueMarkdown, $usertext->transform(':-\\\\'));
     $usertext->setMode('markdownPlain');
     $this->assertContains($expectedValuePlain, $usertext->transform(':-\\\\'));
 }
Example #14
0
 protected function _process()
 {
     $output = array();
     $this->_runWithCatching(function () use(&$output) {
         $query = CM_Params::factory($this->_request->getQuery());
         $method = $query->getString('method');
         if (!preg_match('/^(?<class>[\\w_]+)\\.(?<function>[\\w_]+)$/', $method, $matches)) {
             throw new CM_Exception_InvalidParam('Illegal method.', null, ['method' => $method]);
         }
         $class = $matches['class'];
         $function = $matches['function'];
         $params = $query->getArray('params');
         $output['success'] = array('result' => call_user_func_array(array($class, 'rpc_' . $function), $params));
     }, function (CM_Exception $e) use(&$output) {
         $output['error'] = array('type' => get_class($e), 'msg' => $e->getMessagePublic($this->getRender()), 'isPublic' => $e->isPublic());
     });
     $output['deployVersion'] = CM_App::getInstance()->getDeployVersion();
     $this->setHeader('Content-Type', 'application/json');
     $this->_setContent(json_encode($output));
 }
Example #15
0
 /**
  * @return array
  */
 private function _getOptions()
 {
     $serviceManager = CM_Service_Manager::getInstance();
     $options = array();
     $options['name'] = CM_App::getInstance()->getName();
     $options['deployVersion'] = CM_App::getInstance()->getDeployVersion();
     $options['renderStamp'] = floor(microtime(true) * 1000);
     $options['site'] = CM_Params::encode($this->getRender()->getSite());
     $options['url'] = $this->getRender()->getSite()->getUrl();
     $options['urlBase'] = $this->getRender()->getSite()->getUrlBase();
     $options['urlCdn'] = $this->getRender()->getSite()->getUrlCdn();
     $options['urlUserContentList'] = $serviceManager->getUserContent()->getUrlList();
     $options['urlServiceWorker'] = $this->getRender()->getUrlServiceWorker();
     if ($this->getRender()->getLanguageRewrite()) {
         $options['urlLanguage'] = $this->getRender()->getLanguage();
     }
     $options['debug'] = CM_Bootloader::getInstance()->isDebug();
     $options['stream'] = $serviceManager->getStreamMessage()->getClientOptions();
     if ($viewer = $this->getRender()->getViewer()) {
         $options['stream']['channel']['key'] = CM_Model_StreamChannel_Message_User::getKeyByUser($viewer);
         $options['stream']['channel']['type'] = CM_Model_StreamChannel_Message_User::getTypeStatic();
     }
     return $options;
 }
Example #16
0
 /**
  * @return int
  */
 protected function _getDeployVersion()
 {
     return CM_App::getInstance()->getDeployVersion();
 }
Example #17
0
 /**
  * @param string|null           $path
  * @param CM_Site_Abstract|null $site
  * @return string
  */
 public function getUrlStatic($path = null, CM_Site_Abstract $site = null)
 {
     if (null === $site) {
         $site = $this->getSite();
     }
     if ($this->getSite()->getUrlCdn()) {
         $url = $site->getUrlCdn();
     } else {
         $url = $site->getUrlBase();
     }
     $url .= '/static';
     if (null !== $path) {
         $url .= $path . '?' . CM_App::getInstance()->getDeployVersion();
     }
     return $url;
 }
Example #18
0
 public function testGetUrlStaticWithoutCdn()
 {
     $site = $this->getMockBuilder('CM_Site_Abstract')->setMethods(array('getUrlCdn'))->getMockForAbstractClass();
     $site->expects($this->any())->method('getUrlCdn')->will($this->returnValue(null));
     /** @var CM_Site_Abstract $site */
     $render = new CM_Frontend_Render(new CM_Frontend_Environment($site));
     $deployVersion = CM_App::getInstance()->getDeployVersion();
     $this->assertSame('http://www.default.dev/static/foo.jpg?' . $deployVersion, $render->getUrlStatic('/foo.jpg'));
 }
 public function testIsMail()
 {
     $emoticon = CM_Emoticon::findByCode(':-)');
     $siteDefault = CM_Site_Abstract::factory();
     $this->_assertSame('<span class="usertext oneline">foo <img src="http://cdn.default.dev/layout/' . $siteDefault->getId() . '/' . CM_App::getInstance()->getDeployVersion() . '/img/emoticon/smiley.png" class="emoticon emoticon-' . $emoticon->getName() . '" title=":smiley:" height="16" /></span>', array('text' => 'foo :-)', 'mode' => 'oneline', 'isMail' => true));
 }
Example #20
0
 public function testGetUrlStaticDifferentSite()
 {
     $render = new CM_Frontend_Render();
     $site = $this->getMockSite('CM_Site_Abstract', null, ['urlCdn' => 'http://cdn.other.com']);
     $deployVersion = CM_App::getInstance()->getDeployVersion();
     $this->assertSame('http://cdn.other.com/static/foo.jpg?' . $deployVersion, $render->getUrlStatic('/foo.jpg', $site));
 }
Example #21
0
 protected function _process()
 {
     $output = array();
     $this->_runWithCatching(function () use(&$output) {
         $output = $this->_processView($output);
     }, function (CM_Exception $e, array $errorOptions) use(&$output) {
         $output['error'] = array('type' => get_class($e), 'msg' => $e->getMessagePublic($this->getRender()), 'isPublic' => $e->isPublic());
     });
     $output['deployVersion'] = CM_App::getInstance()->getDeployVersion();
     $this->setHeader('Content-Type', 'application/json');
     $this->_setContent(json_encode($output));
 }
Example #22
0
File: TH.php Project: aladin1394/CM
 private static function clearDb()
 {
     self::clearCache();
     CM_App::getInstance()->getProvisionLoader()->reload(new CM_OutputStream_Null());
 }
Example #23
0
 public function testProcessReturnDeployVersion()
 {
     $site = CM_Site_Abstract::factory();
     $page = new CM_Page_View_Ajax_Test_Mock();
     $env = new CM_Frontend_Environment($site, CMTest_TH::createUser());
     $params = ['path' => CM_Page_View_Ajax_Test_MockRedirect::getPath(), 'currentLayout' => $page->getLayout($env)];
     $response = $this->getResponseAjax($page, 'loadPage', $params);
     $responseDecoded = CM_Params::jsonDecode($response->getContent());
     $this->assertArrayHasKey('deployVersion', $responseDecoded);
     $this->assertSame(CM_App::getInstance()->getDeployVersion(), $responseDecoded['deployVersion']);
 }
Example #24
0
 /**
  * @param string|null $path
  * @return string
  */
 public function getUrlStatic($path = null)
 {
     if ($this->getSite()->getUrlCdn()) {
         $url = $this->getSite()->getUrlCdn();
     } else {
         $url = $this->getSite()->getUrl();
     }
     $url .= '/static';
     if (null !== $path) {
         $url .= $path . '?' . CM_App::getInstance()->getDeployVersion();
     }
     return $url;
 }
Example #25
0
 public function fillCaches()
 {
     $this->_getStreamOutput()->writeln('Warming up caches…');
     CM_App::getInstance()->fillCaches();
 }