Exemplo n.º 1
0
 /**
  * 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::');
 }
Exemplo n.º 2
0
 /**
  * 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;
 }