public function prepare(CM_Frontend_Environment $environment, CM_Frontend_ViewResponse $viewResponse) { if (CM_Http_Request_Abstract::hasInstance()) { $ip = CM_Http_Request_Abstract::getInstance()->getIp(); if ($locationGuess = CM_Model_Location::findByIp($ip)) { $this->getField('location')->setValue($locationGuess); } } }
protected function _getSuggestions($term, array $options, CM_Frontend_Render $render) { $ip = CM_Http_Request_Abstract::getInstance()->getIp(); $locations = new CM_Paging_Location_Suggestions($term, $options['levelMin'], $options['levelMax'], CM_Model_Location::findByIp($ip), $options['scopeLocation']); $locations->setPage(1, 15); $out = array(); foreach ($locations as $location) { $out[] = $this->getSuggestion($location, $render); } return $out; }
/** * @return array */ protected function _getDefaultMetaInfo() { $metaInfo = array(); if ($fqdn = CM_Util::getFqdn()) { $metaInfo['fqdn'] = $fqdn; } if (CM_Http_Request_Abstract::hasInstance()) { $request = CM_Http_Request_Abstract::getInstance(); $metaInfo['uri'] = $request->getUri(); if ($viewer = $request->getViewer()) { $metaInfo['userId'] = $viewer->getId(); } if ($ip = $request->getIp()) { $metaInfo['ip'] = $ip; } if ($request->hasHeader('Referer')) { $metaInfo['referer'] = $request->getHeader('Referer'); } if ($request->hasHeader('User-Agent')) { $metaInfo['useragent'] = $request->getHeader('User-Agent'); } } return $metaInfo; }
/** * @param string $streamName * @param string $clientKey * @return boolean */ public static function rpc_unsubscribe($streamName, $clientKey) { $adapter = self::getInstance()->getAdapter(); $adapter->getServerId(CM_Http_Request_Abstract::getInstance()); $adapter->unsubscribe($streamName, $clientKey); return true; }
public function trackPageView(CM_Frontend_Environment $environment, $path) { if ($viewer = $environment->getViewer()) { $this->setUserId($viewer->getId()); } if (CM_Http_Request_Abstract::hasInstance()) { $this->setRequestClientId(CM_Http_Request_Abstract::getInstance()->getClientId()); } }
public function testProcessTrackingViewer() { $viewer = $this->getMock('CM_Model_User', array('getIdRaw', 'getVisible', 'getLanguage')); $viewer->expects($this->any())->method('getIdRaw')->will($this->returnValue(array('id' => '1'))); $viewer->expects($this->any())->method('getVisible')->will($this->returnValue(false)); $viewer->expects($this->any())->method('getLanguage')->will($this->returnValue(null)); /** @var CM_Model_User $viewer */ $response = CMTest_TH::createResponsePage('/mock5', null, $viewer); $response->setServiceManager($this->_getServiceManager('ga123', 'km123')); $response->process(); $html = $response->getContent(); $this->assertContains('ga("create", "ga123"', $html); $this->assertContains('ga("send", "pageview", "\\/mock5")', $html); $this->assertContains('var _kmq = _kmq || [];', $html); $this->assertContains("var _kmk = _kmk || 'km123';", $html); $clientId = CM_Http_Request_Abstract::getInstance()->getClientId(); $this->assertContains("_kmq.push(['identify', 'Guest {$clientId}']);", $html); $this->assertContains("_kmq.push(['identify', '1']);", $html); $this->assertContains("_kmq.push(['alias', 'Guest {$clientId}', '1']);", $html); }