Пример #1
0
 public function testSetNull()
 {
     $environment = new CM_Frontend_Environment();
     $this->assertEquals(CM_Site_Abstract::factory(), $environment->getSite());
     $this->assertNull($environment->getViewer());
     $this->assertNull($environment->getLanguage());
     $this->assertSame('en', $environment->getLocale());
     $this->assertEquals(CM_Bootloader::getInstance()->getTimeZone(), $environment->getTimeZone());
     $this->assertSame(CM_Bootloader::getInstance()->isDebug(), $environment->isDebug());
     $this->assertNull($environment->getLocation());
 }
Пример #2
0
 public function testSetNull()
 {
     $defaultCurrency = CM_Model_Currency::create('840', 'USD');
     $environment = new CM_Frontend_Environment();
     $this->assertEquals(CM_Site_Abstract::factory(), $environment->getSite());
     $this->assertNull($environment->getViewer());
     $this->assertNull($environment->getLanguage());
     $this->assertSame('en', $environment->getLocale());
     $this->assertEquals(CM_Bootloader::getInstance()->getTimeZone(), $environment->getTimeZone());
     $this->assertSame(CM_Bootloader::getInstance()->isDebug(), $environment->isDebug());
     $this->assertNull($environment->getLocation());
     $this->assertEquals($defaultCurrency, $environment->getCurrency());
     $this->assertNull($environment->getClientDevice());
 }
Пример #3
0
 /**
  * @param CM_Frontend_Environment $environment
  * @param string|null             $layoutName
  * @throws CM_Exception_Invalid
  * @return CM_Layout_Abstract
  */
 public function getLayout(CM_Frontend_Environment $environment, $layoutName = null)
 {
     if (null === $layoutName) {
         $layoutName = 'Default';
     }
     $layoutName = (string) $layoutName;
     foreach ($environment->getSite()->getModules() as $moduleNamespace) {
         $classname = $moduleNamespace . '_Layout_' . $layoutName;
         if (class_exists($classname)) {
             return new $classname();
         }
     }
     throw new CM_Exception_Invalid('layout `' . $layoutName . '` is not defined in any namespace');
 }
Пример #4
0
    public function getHtml(CM_Frontend_Environment $environment)
    {
        $scriptName = 'analytics.js';
        if ($environment->isDebug()) {
            $scriptName = 'analytics_debug.js';
        }
        $html = '<script type="text/javascript">';
        $html .= <<<EOF
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/{$scriptName}','ga');
EOF;
        $fieldList = ['cookieDomain' => $environment->getSite()->getHost()];
        if ($user = $environment->getViewer()) {
            $fieldList['userId'] = (string) $user->getId();
        }
        $html .= 'ga("create", ' . CM_Params::jsonEncode($this->_getCode()) . ', ' . CM_Params::jsonEncode(array_filter($fieldList)) . ');';
        $html .= $this->getJs();
        $html .= '</script>';
        return $html;
    }
Пример #5
0
 /**
  * @param CM_Frontend_Environment $environment
  * @param string                  $layoutName
  * @return string
  * @throws CM_Exception_Invalid
  */
 protected function _getLayoutClassByName(CM_Frontend_Environment $environment, $layoutName)
 {
     $layoutName = (string) $layoutName;
     foreach ($environment->getSite()->getModules() as $moduleNamespace) {
         $classname = $moduleNamespace . '_Layout_' . $layoutName;
         if (class_exists($classname)) {
             return $classname;
         }
     }
     throw new CM_Exception_Invalid('Layout is not defined in any namespace', null, ['layoutName' => $layoutName]);
 }
Пример #6
0
 /**
  * @param CM_Frontend_Environment $environment
  */
 public function trackSignUp(CM_Frontend_Environment $environment)
 {
     if ($viewer = $environment->getViewer()) {
         $this->_pushEvent($viewer, 'signup', ['site' => $environment->getSite()->getHost()]);
     }
 }