コード例 #1
0
ファイル: Messages.php プロジェクト: rexmac/zyndax
 /**
  * Display messages
  *
  * @return void
  */
 public function render()
 {
     // Any flash messages?
     #if(!is_array($this->view->messages)) $this->view->messages = array();
     $messages = $this->_messages + HelperBroker::getStaticHelper('SessionMessenger')->getMessages();
     #\Rexmac\Zyndax\Log\Logger::debug(__METHOD__.'::THIS_MESSAGES::'.var_export($this->_messages, true));
     #\Rexmac\Zyndax\Log\Logger::debug(__METHOD__.'::SESS_MESSAGES::'.var_export(HelperBroker::getStaticHelper('SessionMessenger')->getMessages(), true));
     #\Rexmac\Zyndax\Log\Logger::debug(__METHOD__.'::MRGD_MESSAGES::'.var_export($messages, true));
     $request = FrontController::getInstance()->getRequest();
     #\Rexmac\Zyndax\Log\Logger::debug(__METHOD__.':: '.$request->getModuleName().'/'.$request->getControllerName().'/'.$request->getActionName());
     $route = $request->getModuleName() . '/' . $request->getControllerName() . '/' . $request->getActionName();
     if ($request->isXmlHttpRequest()) {
         if (!empty($messages)) {
             $this->view->messages = $messages;
         }
         return;
     }
     foreach ($messages as $type => $msgs) {
         $msgs = str_replace('\'', '\\\'', $msgs);
         #$msgs = array_map('htmlentities', $msgs, array_fill(0, count($msgs), ENT_QUOTES, 'UTF-8'
         #$msgs = array_map('myfunction', $msgs);
         // I'm sure there was a very good reason for the following, but I currently have no idea what that reason was.
         // Anyways, it is preventing us from including HTML formatting in messages.
         /*$msgs = array_map(
             function($str) {
               return htmlentities($str, ENT_QUOTES, 'UTF-8');
             },
             $msgs
           );*/
         $out = "['" . implode("','", $msgs) . "']";
         if ($request->isMobileRequest()) {
             $script = "  \$('div.ui-page-active > div.ui-content').showMessage({'thisMessage': {$out}, 'className': '{$type}'});";
         } else {
             if ($route === 'default/user/login') {
                 // Probably a better way to hanlde this special-case
                 $script = "  \$('#content').showMessage({'thisMessage': {$out}, 'className': '{$type}'});";
             } else {
                 $script = "  Notifier.{$type}({$out}.join(' '));";
             }
         }
         JqueryViewHelper::appendScript($script);
     }
     #\Rexmac\Zyndax\Log\Logger::debug(__METHOD__.'::DONE::');
 }
コード例 #2
0
ファイル: SiteController.php プロジェクト: rexmac/zyndax
 /**
  * Privacy action
  *
  * @return void
  */
 public function privacyAction()
 {
     $request = $this->getRequest();
     $form = new \Admin_Form_SitePrivacyPolicy();
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $data = $form->getValues();
             try {
                 #$data['privacyPolicy'];
                 Logger::debug(__METHOD__ . ':: privacyPolicy ::' . $data['privacyPolicy']);
                 SiteContentService::createOrUpdate(array('name' => 'privacyPolicy', 'content' => $data['privacyPolicy']), array('name' => 'privacyPolicy'));
                 $this->view->success = 1;
                 $message = 'Privacy policy has been updated.';
                 $this->_helper->sessionMessenger($message, 'success');
                 return $this->_helper->redirector('index');
             } catch (Exception $e) {
                 $this->getResponse()->setHttpResponseCode(500);
                 $this->view->success = 0;
                 $message = 'development' == APPLICATION_ENV ? $e->getMessage() : 'Application error: ASiPr001';
                 $this->view->messages()->addMessage($message, 'error');
                 Logger::err($e->getMessage());
             }
         } else {
             // Submitted form data is invalid
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->success = 0;
         }
     } else {
         // Not a POST request
     }
     $this->view->form = $form;
     $this->view->inlineScript()->appendFile('/js/libs/ckeditor/ckeditor.js');
     JqueryViewHelper::appendFile('/js/libs/ckeditor/adapters/jquery.js');
 }
コード例 #3
0
ファイル: UserController.php プロジェクト: rexmac/zyndax
 /**
  * User profile action
  *
  * @return void
  */
 public function profileAction()
 {
     $request = $this->getRequest();
     $user = $this->_user;
     $form = new \Application_Form_UserUpdate($user);
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $data = $form->getValues();
             try {
                 $changed = $this->_updateUser($user, $data);
                 $this->view->success = 1;
                 if ($changed) {
                     $message = 'Profile updated successfully.';
                     $msgPriority = 'success';
                     $form = new \Application_Form_UserUpdate($user);
                 } else {
                     $message = 'No changes were made.';
                     $msgPriority = 'notice';
                 }
                 $this->view->messages()->addMessage($message, $msgPriority);
             } catch (Exception $e) {
                 $this->getResponse()->setHttpResponseCode(500);
                 $this->view->success = 0;
                 #$message = ('development' == APPLICATION_ENV ? $e->getMessage() : 'Application error: UCPA001');
                 $message = 'Application error: UCPA001 - ' . $e->getMessage();
                 $this->view->messages()->addMessage($message, 'error');
                 Logger::err($e->getMessage());
             }
         } else {
             // Submitted form data is invalid
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->success = 0;
         }
     } else {
         // Not a POST request
     }
     $this->view->form = $form;
     JqueryViewHelper::assignData(array('userId' => $user->getId()));
 }
コード例 #4
0
ファイル: UsersController.php プロジェクト: rexmac/zyndax
 /**
  * Edit action
  *
  * @return void
  */
 public function editAction()
 {
     $request = $this->getRequest();
     $timeZone = new DateTimeZone($this->_user->getProfile()->getTimeZone()->getName());
     $params = $request->getParams();
     // Get the user that is being updated
     $userId = $request->getParam('userId', null);
     if (null === ($user = UserService::findOneById($userId))) {
         throw new \Admin_UsersControllerException('No user found.');
     }
     $form = new \Admin_Form_UserEdit();
     $form->setDefaultsFromUser($user);
     // Pre-validate form; set conditional requirements
     $form->preValidate($request->getParams());
     if ($request->isPost()) {
         // AJAX request with partial form submission? (probably an AJAX request to update a single property)
         if ($request->isXmlHttpRequest() && $form->isValidPartial($params)) {
             #Logger::debug(__METHOD__.':: params-pre = '.var_export($params, true));
             $params = array_merge($params, $this->_prepFormData($form->getValues(), $user));
             #Logger::debug(__METHOD__.':: params-post = '.var_export($params, true));
         }
         if ($form->isValid($params)) {
             $data = $form->getValues();
             #Logger::debug(__METHOD__.':: data = '.var_export($data, true));
             try {
                 $changed = $this->_updateUser($user, $data);
                 $this->view->success = 1;
                 $this->view->userId = $userId;
                 if ($changed) {
                     $message = 'User modified successfully.';
                     $msgPriority = 'success';
                 } else {
                     $message = 'No changes were made.';
                     $msgPriority = 'notice';
                 }
                 if (!$request->isXmlHttpRequest()) {
                     $this->_helper->sessionMessenger($message, $msgPriority);
                     return $this->_helper->getHelper('Redirector')->gotoRoute(array(), 'adminUsers');
                 }
                 $this->view->messages()->addMessage($message, $msgPriority);
             } catch (Exception $e) {
                 $this->getResponse()->setHttpResponseCode(500);
                 $this->view->success = 0;
                 $message = 'development' == APPLICATION_ENV ? $e->getMessage() : 'Application error: AUCEA001';
                 $this->view->messages()->addMessage($message, 'error');
                 Logger::err(__METHOD__ . '::' . $e->getMessage());
             }
         } else {
             // Submitted form data is invalid
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->success = 0;
             Logger::debug(__METHOD__ . ':: formErrors = ' . var_export($form->getMessages(), true));
             if ($request->isXmlHttpRequest()) {
                 $this->view->messages()->addMessage('Application error: AUCEA000', 'error');
                 #$this->view->messages()->addMessage($form->getMessages(), 'error');
             }
         }
     } else {
         // Not a POST request
         $form->setDefaultsFromUser($user);
     }
     $this->view->assign(array('editHistory' => UserEditEventService::findByUser($user->getId()), 'timeZone' => $timeZone, 'form' => $form, 'userId' => $userId));
     JqueryViewHelper::assignData(array('userId' => $userId));
 }
コード例 #5
0
ファイル: Monitor.php プロジェクト: rexmac/zyndax
 /**
  * Toggle logging of JavaScript errors
  *
  * @todo Toggle implies ability to undo, but there is currently no way of unappending script to Jquery view helper
  * @param bool $toggle Should JavaScript errors be logged? Default is TRUE.
  * @return Monitor
  */
 public function logJavaScriptErrors($toggle = true)
 {
     $this->_logJavaScriptErrors = $toggle;
     if ($toggle) {
         $viewRenderer = HelperBroker::getStaticHelper('viewRenderer');
         if (null === $viewRenderer->view) {
             try {
                 $viewRenderer->init();
             } catch (Zend_Exception $e) {
                 throw new MonitorException('Could not init() viewRenderer.');
             }
         }
         $view = $viewRenderer->view;
         if (false === $view->getPluginLoader('helper')->getPaths('Rexmac\\Zyndax\\View\\Helper')) {
             try {
                 $view->addHelperPath('Rexmac/Zyndax/View/Helper', 'Rexmac\\Zyndax\\View\\Helper');
             } catch (Zend_Exception $e) {
                 throw new MonitorException('Failed to add Rexmac\\Zyndax\\View\\Helper path to view', null, $e);
             }
         }
         JqueryViewHelper::appendScript('window.onerror=function(message,errorUrl,errorLine){' . '$.ajax({type:\'post\',url:\'?monitor=x\',dataType:\'html\',' . 'data:{\'message\':message,\'errorUrl\':errorUrl,\'errorLine\':errorLine}})}');
         /*JqueryViewHelper::appendScript('$("<a/>").appendTo($("body")).text("CLICK ME").click(function(e){
             e.preventDefault();
             alert("HELLO!" + window.parseNog());
           });');*/
     }
     $this->_registerControllerPlugin('\\Rexmac\\Zyndax\\Monitor\\Controller\\Plugin\\JavaScriptErrors', $toggle);
     return $this;
 }
コード例 #6
0
ファイル: ControllerTestCase.php プロジェクト: rexmac/zyndax
 /**
  * Tear down
  *
  * @return void
  */
 public function tearDown()
 {
     $this->reset();
     \Zend_Auth::getInstance()->clearIdentity();
     \Zend_Registry::_unsetInstance();
     #\Zend_Controller_Action_HelperBroker::resetHelpers();
     \Rexmac\Zyndax\View\Helper\Jquery::clearScript();
     set_include_path(APPLICATION_PATH . ':' . APPLICATION_PATH . '/../library:.:/usr/local/lib/php');
 }