Esempio n. 1
0
 private function processRequest()
 {
     if ($this->httpRequest->isPost() && $this->httpRequest->isAjax() && $this->httpRequest->getHeader(self::XHR_HEADER)) {
         $data = json_decode(file_get_contents('php://input'), true);
         if ($data && isset($data[self::AJAX_ACTION_KEY])) {
             switch ($data[self::AJAX_ACTION_KEY]) {
                 case self::AJAX_ACTION_LOAD:
                     $message = $data[self::AJAX_MESSAGE_KEY];
                     if (!$this->translator->hasTranslation($message)) {
                         throw new \Exception();
                     }
                     $data = array('translation' => $this->translator->findTranslation($message));
                     $this->httpResponse->setContentType('application/json');
                     echo json_encode($data);
                     break;
                 case self::AJAX_ACTION_EDIT:
                     $message = $data[self::AJAX_MESSAGE_KEY];
                     $translation = $data[self::AJAX_TRANSLATION_KEY];
                     if (!$this->translator->hasTranslation($message)) {
                         throw new \Exception();
                     }
                     $info = $this->translator->getMessageInfo($message);
                     $data = $this->translator->_loadCategory($info['path'], $info['category']);
                     $data[$info['name']] = $translation;
                     $this->translator->getLoader()->save($info['path'], $info['category'], $this->translator->getLanguage(), $data);
                     $this->httpResponse->setContentType('application/json');
                     break;
                 default:
                     throw new \Exception();
                     break;
             }
         }
         exit;
     }
 }
Esempio n. 2
0
 /**
  * Handles an incomuing request and saves the data if necessary.
  */
 private function processRequest()
 {
     if ($this->httpRequest->isPost() && $this->httpRequest->isAjax() && $this->httpRequest->getHeader($this->xhrHeader)) {
         $data = json_decode(file_get_contents('php://input'));
         if ($data) {
             if ($this->debugMode === true && $this->sessionStorage) {
                 $stack = isset($this->sessionStorage['stack']) ? $this->sessionStorage['stack'] : array();
             }
             $this->translator->lang = $data->{$this->languageKey};
             $file = $data->{$this->fileKey};
             unset($data->{$this->languageKey}, $data->{$this->fileKey});
             foreach ($data as $string => $value) {
                 $this->translator->setTranslation($string, $value, $file);
                 if ($this->debugMode === true && $this->sessionStorage && isset($stack[$string])) {
                     unset($stack[$string]);
                 }
             }
             $this->translator->save($file);
             if ($this->debugMode === true && $this->sessionStorage) {
                 $this->sessionStorage['stack'] = $stack;
             }
         }
         exit;
     }
 }
Esempio n. 3
0
 /**
  * 
  * @param Scripter $scripter
  * @param Response $response
  * @param Request $request
  */
 public static function register_shutdown(Scripter $scripter, Response $response, Request $request)
 {
     register_shutdown_function(function () use($scripter, $response, $request) {
         $page = ob_get_contents();
         ob_end_clean();
         $header_type = $response->getHeader("Content-Type");
         if ($header_type && strpos($header_type, "text/html") === 0 && !$request->isAjax()) {
             $scripter->cache->removeNotUseFile();
             preg_match('/(?:<head[^>]*>)(.*?)<\\/head>/s', $page, $matches);
             if (isset($matches[1])) {
                 $replace = $matches[1];
                 $matches[1] .= '<script type="text/javascript" src="' . '/' . $scripter->config->url_path_name . '/' . $scripter->getPageName() . '/js' . '"></script>';
                 $matches[1] .= '<link rel="stylesheet" href="' . '/' . $scripter->config->url_path_name . '/' . $scripter->getPageName() . '/css' . '">';
                 $page = str_replace($replace, $matches[1], $page);
             }
         }
         echo $page;
     });
 }
Esempio n. 4
0
 public function isAjax()
 {
     return $this->request->isAjax();
 }