예제 #1
0
 protected function _execute(CM_Params $params)
 {
     $id = $params->getInt('id');
     $values = $params->getArray('values');
     $svm = new CM_SVM_Model($id);
     return $svm->predict($values);
 }
예제 #2
0
 protected function _execute(CM_Params $params)
 {
     $propertyId = $params->getString('propertyId');
     $parameterList = $params->getArray('parameterList');
     $client = new CMService_GoogleAnalytics_MeasurementProtocol_Client($propertyId);
     $client->_submitHit($parameterList);
 }
예제 #3
0
 protected function _execute(CM_Params $params)
 {
     $user = $params->getUser('user');
     if (null === CM_Model_StreamChannel_Message_User::findByUser($user)) {
         $user->setOnline(false);
     }
 }
예제 #4
0
파일: File.php 프로젝트: NicolasSchmutz/cm
 public function prepare(CM_Params $renderParams, CM_Frontend_Environment $environment, CM_Frontend_ViewResponse $viewResponse)
 {
     $text = $this->getParams()->has('text') ? $renderParams->getString('text') : null;
     $skipDropZone = $renderParams->getBoolean('skipDropZone', false);
     $viewResponse->set('text', $text);
     $viewResponse->set('skipDropZone', $skipDropZone);
 }
예제 #5
0
 protected function _execute(CM_Params $params)
 {
     $id = $params->getInt('id');
     $class = $params->getInt('class');
     $values = $params->getArray('values');
     $svm = new CM_SVM_Model($id);
     $svm->addTraining($class, $values);
 }
예제 #6
0
파일: Abstract.php 프로젝트: cargomedia/cm
 public function ajax_loadComponent(CM_Params $params, CM_Frontend_JavascriptContainer_View $handler, CM_Http_Response_View_Ajax $response)
 {
     $className = $params->getString('className');
     $params->remove('className');
     if (!class_exists($className)) {
         throw new CM_Exception_Invalid('Class not found', CM_Exception::WARN, ['className' => $className]);
     }
     return $response->loadComponent($className, $params);
 }
예제 #7
0
 protected function _execute(CM_Params $params)
 {
     $indexClassName = $params->getString('indexClassName');
     $id = $params->getString('id');
     /** @var CM_Elasticsearch_Type_Abstract $index */
     $index = new $indexClassName();
     $index->update(array($id));
     $index->getIndex()->refresh();
 }
예제 #8
0
 public function ajax_flushLog(CM_Params $params, CM_Frontend_JavascriptContainer $handler, CM_Http_Response_View_Ajax $response)
 {
     if (!$this->_getAllowedFlush($response->getRender()->getEnvironment())) {
         throw new CM_Exception_NotAllowed();
     }
     $type = $params->getInt('type');
     $logList = CM_Paging_Log_Abstract::factory($type);
     $logList->flush();
     $response->reloadComponent();
 }
예제 #9
0
 protected function _execute(CM_Params $params)
 {
     $code = $params->getString('code');
     $identityList = $params->getArray('identityList');
     $eventName = $params->getString('eventName');
     $propertyList = $params->getArray('propertyList');
     $kissMetrics = new CMService_KissMetrics_Client($code);
     $kissMetrics->setIdentityList($identityList);
     $kissMetrics->trackEvent($eventName, $propertyList);
 }
예제 #10
0
 protected function _execute(CM_Params $params)
 {
     $indexClassName = $params->getString('indexClassName');
     $id = $params->getString('id');
     $client = CM_Service_Manager::getInstance()->getElasticsearch()->getClient();
     /** @var CM_Elasticsearch_Type_Abstract $index */
     $index = new $indexClassName($client);
     $index->updateDocuments(array($id));
     $index->refreshIndex();
 }
예제 #11
0
 public function ajax_getSuggestionByCoordinates(CM_Params $params, CM_Frontend_JavascriptContainer_View $handler, CM_Http_Response_View_Ajax $response)
 {
     $lat = $params->getFloat('lat');
     $lon = $params->getFloat('lon');
     $location = CM_Model_Location::findByCoordinates($lat, $lon);
     $location = $this->_squashLocationInConstraints($location);
     if (!$location) {
         throw new CM_Exception('Cannot find a location by coordinates `' . $lat . '` / `' . $lon . '`.');
     }
     return $this->getSuggestion($location, $response->getRender());
 }
예제 #12
0
파일: File.php 프로젝트: cargomedia/cm
 public function prepare(CM_Params $renderParams, CM_Frontend_Environment $environment, CM_Frontend_ViewResponse $viewResponse)
 {
     $text = $renderParams->has('text') ? $renderParams->getString('text') : null;
     $buttonTheme = $this->_params->getString('buttonTheme', 'default');
     $skipPreviews = $this->_params->getBoolean('skipPreviews', false);
     $viewResponse->set('text', $text);
     $viewResponse->set('buttonTheme', $buttonTheme);
     if ($skipPreviews) {
         $viewResponse->setDataAttributes(['skip-previews' => '']);
     }
 }
예제 #13
0
파일: LogList.php 프로젝트: cargomedia/cm
 public function ajax_flushLog(CM_Params $params, CM_Frontend_JavascriptContainer $handler, CM_Http_Response_View_Ajax $response)
 {
     if (!$this->_getAllowedFlush($response->getRender()->getEnvironment())) {
         throw new CM_Exception_NotAllowed();
     }
     $level = $params->has('level') ? $params->getInt('level') : null;
     $levelList = $level ? [$level] : null;
     $type = $params->has('type') ? $params->getInt('type') : null;
     $logList = new CM_Paging_Log($levelList, $type);
     $logList->flush();
     $response->reloadComponent();
 }
예제 #14
0
 public function testProcessInvalidCharsRequired()
 {
     $invalidChars = array(chr(192), chr(214), chr(255), chr(140));
     foreach ($invalidChars as $inputChar) {
         $form = new CM_Form_MockForm();
         $formAction = new CM_FormAction_MockForm_TestExampleAction($form);
         $data = array('must_check' => 'checked', 'text' => $inputChar);
         $response = $this->getResponseFormAction($formAction, $data);
         try {
             $this->assertFormResponseError($response, null, 'text');
         } catch (PHPUnit_Framework_AssertionFailedError $e) {
             $this->assertNotSame($inputChar, self::$formActionData->getString('text'));
         }
     }
 }
예제 #15
0
파일: Form.php 프로젝트: NicolasSchmutz/cm
 protected function _processView(array $output)
 {
     $success = array();
     $form = $this->_getView();
     $className = get_class($form);
     if (!$form instanceof CM_Form_Abstract) {
         throw new CM_Exception_Invalid('`' . $className . '`is not `CM_Form_Abstract` instance');
     }
     $query = $this->_request->getQuery();
     $actionName = (string) $query['actionName'];
     $data = (array) $query['data'];
     $this->_setStringRepresentation($className . '::' . $actionName);
     $success['data'] = CM_Params::encode($form->process($data, $actionName, $this));
     if (!empty($this->errors)) {
         $success['errors'] = $this->errors;
     }
     $jsCode = $this->getRender()->getGlobalResponse()->getJs();
     if (!empty($jsCode)) {
         $success['exec'] = $jsCode;
     }
     if (!empty($this->messages)) {
         $success['messages'] = $this->messages;
     }
     $output['success'] = $success;
     return $output;
 }
예제 #16
0
 public function testProcessTranslationsEnableKey()
 {
     $language = CMTest_TH::createLanguage('test');
     $languageKey = CM_Model_LanguageKey::create('Hello World');
     $this->assertSame(false, $languageKey->getJavascript());
     $site = CM_Site_Abstract::factory();
     $render = new CM_Frontend_Render(new CM_Frontend_Environment(null, null, $language));
     // Check that key is *not* included in the JS translations list
     $versionJavascript = CM_Model_Language::getVersionJavascript();
     $request = new CM_Http_Request_Get($render->getUrlResource('library-js', "translations/{$versionJavascript}.js"));
     $response = CM_Http_Response_Resource_Javascript_Library::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $this->assertNotContains('Hello World', $response->getContent());
     // Request JS-enabling of language key via RPC call
     $body = CM_Params::jsonEncode(['method' => 'CM_Model_Language.requestTranslationJs', 'params' => ['Hello World']]);
     $request = new CM_Http_Request_Post('/rpc', null, null, $body);
     $response = CM_Http_Response_RPC::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     CMTest_TH::reinstantiateModel($languageKey);
     $this->assertSame(true, $languageKey->getJavascript());
     // Check that key *is* included in the JS translations list
     $versionJavascript = CM_Model_Language::getVersionJavascript();
     $request = new CM_Http_Request_Get($render->getUrlResource('library-js', "translations/{$versionJavascript}.js"));
     $response = CM_Http_Response_Resource_Javascript_Library::createFromRequest($request, $site, $this->getServiceManager());
     $response->process();
     $this->assertContains('Hello World', $response->getContent());
 }
예제 #17
0
 /**
  * @param CM_Params|array|null $params
  */
 public function __construct($params = null)
 {
     if (!$params instanceof CM_Params) {
         $params = CM_Params::factory($params, false);
     }
     $this->_params = $params;
 }
예제 #18
0
파일: Service.php 프로젝트: cargomedia/cm
 /**
  * @param string     $channel
  * @param string     $event
  * @param mixed|null $data
  */
 public function publish($channel, $event, $data = null)
 {
     if (!$this->getEnabled()) {
         return;
     }
     $this->getAdapter()->publish($channel, $event, CM_Params::encode($data));
 }
예제 #19
0
파일: View.php 프로젝트: NicolasSchmutz/cm
 /**
  * @param mixed $varList
  */
 public function debug($varList)
 {
     foreach ($varList as &$var) {
         $var = CM_Params::encode($var, true);
     }
     $this->_operations[] = 'this.message(' . implode(', ', $varList) . ');';
 }
예제 #20
0
파일: Ajax.php 프로젝트: cargomedia/cm
 protected function _processView(array $output)
 {
     $success = array();
     $query = $this->_request->getQuery();
     if (!isset($query['method'])) {
         throw new CM_Exception_Invalid('No method specified', CM_Exception::WARN);
     }
     if (!preg_match('/^[\\w_]+$/i', $query['method'])) {
         throw new CM_Exception_Invalid('Illegal method', CM_Exception::WARN, ['method' => $query['method']]);
     }
     if (!isset($query['params']) || !is_array($query['params'])) {
         throw new CM_Exception_Invalid('Illegal params', CM_Exception::WARN);
     }
     $view = $this->_getView();
     if ($view instanceof CM_View_CheckAccessibleInterface) {
         $view->checkAccessible($this->getRender()->getEnvironment());
     }
     $ajaxMethodName = 'ajax_' . $query['method'];
     $params = CM_Params::factory($query['params'], true);
     $componentHandler = new CM_Frontend_JavascriptContainer_View();
     $this->_setStringRepresentation(get_class($view) . '::' . $ajaxMethodName);
     if (!method_exists($view, $ajaxMethodName)) {
         throw new CM_Exception_Invalid('Method not found', CM_Exception::WARN, ['method' => $ajaxMethodName]);
     }
     $data = $view->{$ajaxMethodName}($params, $componentHandler, $this);
     $success['data'] = CM_Params::encode($data);
     $frontend = $this->getRender()->getGlobalResponse();
     $frontend->getOnloadReadyJs()->append($componentHandler->compile('this'));
     $jsCode = $frontend->getJs();
     if (strlen($jsCode)) {
         $success['exec'] = $jsCode;
     }
     $output['success'] = $success;
     return $output;
 }
예제 #21
0
 /**
  * @param CM_Model_Language $language
  */
 public function __construct(CM_Model_Language $language)
 {
     $translations = array();
     foreach (new CM_Paging_Translation_Language($language, null, null, null, true) as $translation) {
         $translations[$translation['key']] = $language->getTranslation($translation['key']);
     }
     $this->_content = 'cm.language.setAll(' . CM_Params::encode($translations, true) . ');';
 }
예제 #22
0
파일: Set.php 프로젝트: NicolasSchmutz/cm
 public function prepare(CM_Params $renderParams, CM_Frontend_Environment $environment, CM_Frontend_ViewResponse $viewResponse)
 {
     $viewResponse->set('class', $renderParams->has('class') ? $renderParams->getString('class') : null);
     $viewResponse->set('optionList', $this->_getOptionList());
     $viewResponse->set('translate', $renderParams->getBoolean('translate', $this->_translate) || $renderParams->has('translatePrefix'));
     $viewResponse->set('translatePrefix', $renderParams->has('translatePrefix') ? $renderParams->getString('translatePrefix') : null);
 }
예제 #23
0
 /**
  * @param CM_Site_Abstract  $site
  * @param bool|null         $debug
  * @param CM_Model_Language $language
  */
 public function __construct(CM_Site_Abstract $site, $debug = null, CM_Model_Language $language)
 {
     parent::__construct($site, $debug);
     $translations = array();
     foreach ($language->getTranslations(true) as $translation) {
         $translations[$translation['key']] = $language->getTranslation($translation['key']);
     }
     $this->_js->append('cm.language.setAll(' . CM_Params::encode($translations, true) . ');');
 }
예제 #24
0
파일: RPCTest.php 프로젝트: aladin1394/CM
 public function testProcessingInvalidMethod()
 {
     $body = CM_Params::jsonEncode(['method' => 'foo']);
     $request = new CM_Http_Request_Post('/rpc/' . CM_Site_Abstract::factory()->getType(), null, null, $body);
     $response = new CM_Http_Response_RPC($request, $this->getServiceManager());
     $response->process();
     $responseData = CM_Params::jsonDecode($response->getContent());
     $this->assertSame(['error' => ['type' => 'CM_Exception_InvalidParam', 'msg' => 'Internal server error', 'isPublic' => false]], $responseData);
 }
예제 #25
0
파일: Boolean.php 프로젝트: cargomedia/cm
 public function prepare(CM_Params $renderParams, CM_Frontend_Environment $environment, CM_Frontend_ViewResponse $viewResponse)
 {
     $display = $renderParams->get('display', self::DISPLAY_CHECKBOX);
     if (!in_array($display, array(self::DISPLAY_CHECKBOX, self::DISPLAY_SWITCH))) {
         throw new CM_Exception_InvalidParam('Display needs to be either `checkbox` or `switch`');
     }
     $viewResponse->set('display', $display);
     $viewResponse->set('tabindex', $renderParams->has('tabindex') ? $renderParams->getInt('tabindex') : null);
     $viewResponse->set('class', $renderParams->has('class') ? $renderParams->getString('class') : null);
     $viewResponse->set('checked', $this->getValue() ? 'checked' : null);
     $viewResponse->set('text', $renderParams->has('text') ? $renderParams->getString('text') : null);
 }
예제 #26
0
파일: Example.php 프로젝트: cargomedia/cm
 public function ajax_validate(CM_Params $params, CM_Frontend_JavascriptContainer_View $handler, CM_Http_Response_View_Ajax $response)
 {
     $data = $params->getArray('data');
     $result = [];
     foreach ($data as $name => $userInput) {
         $field = $this->getField($name);
         $empty = $field->isEmpty($userInput);
         $value = null;
         $validationError = null;
         if (!$empty) {
             try {
                 $value = $field->validate($response->getEnvironment(), $userInput);
             } catch (CM_Exception_FormFieldValidation $e) {
                 $validationError = $e->getMessagePublic($response->getRender());
             }
         }
         $result[$name] = ['value' => $value, 'empty' => $empty, 'validationError' => $validationError];
     }
     return $result;
 }
예제 #27
0
파일: RPCTest.php 프로젝트: cargomedia/cm
 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']);
 }
예제 #28
0
function smarty_function_formField(array $params, Smarty_Internal_Template $template)
{
    /** @var CM_Frontend_Render $render */
    $render = $template->smarty->getTemplateVars('render');
    $cssClasses = array();
    if (isset($params['class'])) {
        $cssClasses[] = (string) $params['class'];
        unset($params['class']);
    }
    $label = null;
    if (isset($params['label'])) {
        $label = (string) $params['label'];
    }
    $input = null;
    $fieldName = null;
    if (isset($params['prepend'])) {
        $input .= (string) $params['prepend'];
    }
    /** @var CM_Frontend_ViewResponse|null $viewResponse */
    $viewResponse = null;
    if (isset($params['name'])) {
        $fieldName = (string) $params['name'];
        $cssClasses[] = $fieldName;
        /** @var CM_Form_Abstract $form */
        $form = $render->getGlobalResponse()->getClosestViewResponse('CM_Form_Abstract')->getView();
        if (null === $form) {
            throw new CM_Exception_Invalid('Cannot find parent `CM_Form_Abstract` view response. Named {formField} can be only rendered within form view.');
        }
        $formField = $form->getField($fieldName);
        $renderAdapter = new CM_RenderAdapter_FormField($render, $formField);
        $input .= $renderAdapter->fetch(CM_Params::factory($params, false), $viewResponse);
        if (null !== $formField->getValue()) {
            $cssClasses[] = 'prefilled';
        }
    }
    if (isset($params['append'])) {
        $input .= (string) $params['append'];
    }
    $html = '<div class="formField clearfix ' . join(' ', $cssClasses) . '">';
    if ($label) {
        $html .= '<label';
        if ($viewResponse) {
            $html .= ' for="' . $viewResponse->getAutoIdTagged('input') . '"';
        }
        $html .= '>' . $label . '</label>';
    }
    if ($input) {
        $html .= '<div class="input">';
        $html .= $input;
        $html .= '</div>';
    }
    $html .= '</div>';
    return $html;
}
예제 #29
0
 public function testProcessHostRedirect_parameter()
 {
     $site = CM_Site_Abstract::factory();
     $location = CMTest_TH::createLocation();
     $locationEncoded = CM_Params::encode($location, true);
     $query = http_build_query(['location' => $locationEncoded]);
     $response = CMTest_TH::createResponsePage('/mock5?' . $query, array('host' => 'incorrect-host.org'));
     $response->process();
     $siteUrl = 'http://' . $site->getHost();
     $this->assertContains('Location: ' . $siteUrl . '/mock5?' . $query, $response->getHeaders());
 }
예제 #30
0
파일: Debug.php 프로젝트: cargomedia/cm
 public function ajax_clearCache(CM_Params $params, CM_Frontend_JavascriptContainer_View $handler, CM_Http_Response_View_Ajax $response)
 {
     $cachesCleared = array();
     if ($params->getBoolean('CM_Cache_Storage_Memcache', false)) {
         $cache = new CM_Cache_Storage_Memcache();
         $cache->flush();
         $cachesCleared[] = 'CM_Cache_Storage_Memcache';
     }
     if ($params->getBoolean('CM_Cache_Storage_Apc', false)) {
         $cache = new CM_Cache_Storage_Apc();
         $cache->flush();
         $cachesCleared[] = 'CM_Cache_Storage_Apc';
     }
     if ($params->getBoolean('CM_Cache_Storage_File', false)) {
         $cache = new CM_Cache_Storage_File();
         $cache->flush();
         $cachesCleared[] = 'CM_Cache_Storage_File';
     }
     $handler->message('Cleared: ' . implode(', ', $cachesCleared));
 }