示例#1
0
 protected function _initData()
 {
     $conf = \Pste\Registry::getInstance()->config;
     $emptyPost = array('pid' => null, 'poster' => null, 'posted' => null, 'code' => '', 'parent_pid' => null, 'format' => $conf->default_highlighter, 'codefmt' => '', 'expiry_flag' => 'f', 'codecss' => null, 'expires' => null, 'password' => null);
     if (!$this->request->hasParam('show')) {
         $post = $emptyPost;
     } else {
         $pid = $this->request->getParam('show');
         $paste = new \Pste\Model\Paste($pid);
         $post = $paste->getContent();
         if (!$post) {
             return $this->forward(new StaticPage(array('template' => 'components/paste_invalid.php')));
         }
         $postPass = $this->request->hasParam('thePassword') ? $this->request->getParam('thePassword') : null;
         $pass = $post['password'];
         $restrictedPost = null !== $pass && $pass !== sha1("EMPTY") ? true : false;
         $accessAllowed = !$restrictedPost || sha1($postPass) == $pass ? true : false;
         $passwordFail = $restrictedPost && null !== $postPass && $postPass !== $pass ? true : false;
         if (!$accessAllowed) {
             require_once 'components/StaticPage.php';
             return $this->forward(new StaticPage(array('template' => 'components/paste_password.php', 'fail' => $passwordFail)));
         }
         $post['password'] = $this->request->getParam('thePassword', '');
     }
     $this->post = $post;
     $this->geshiformats = $conf->get('geshiformats');
     $this->popular_syntax = $conf->get('popular_syntax');
     $this->highlight_prefix = $conf->get('highlight_prefix');
 }
示例#2
0
 /**
  * get the data for the paste-poste
  * 
  * @return type 
  */
 public function getPaste()
 {
     $conf = \Pste\Registry::getInstance()->config;
     $pid = $this->pid;
     $paste = new \Pste\Model\Paste($pid);
     $post = $paste->getContent();
     if (!$post) {
         return $this->forward(new StaticPage(array('template' => 'components/paste_invalid.php')));
     }
     $this->followUp(new PasteForm(array('request' => $this->request)));
     $postPass = $this->request->hasParam('thePassword') ? $this->request->getParam('thePassword') : null;
     $pass = $post['password'];
     $restrictedPost = null !== $pass && $pass !== sha1("EMPTY") ? true : false;
     $accessAllowed = !$restrictedPost || sha1($postPass) == $pass ? true : false;
     $passwordFail = $restrictedPost && null !== $postPass && $postPass !== $pass ? true : false;
     if (!$accessAllowed) {
         require_once 'components/StaticPage.php';
         return $this->forward(new StaticPage(array('template' => 'components/paste_password.php', 'fail' => $passwordFail)));
     }
     $paste = $post;
     // Show a quick reference url, poster and parents .
     $expires = is_null($post['expires']) ? "Never Expires" : "Expires on " . date("F D jS g:i A", strtotime($post['expires']));
     $paste['posttitle'] = "Posted as {$post['poster']} on {$post['postdate']} - {$expires}";
     $paste['editcode'] = $paste['code'];
     // Preprocess
     $highlight = array();
     $prefix_size = strlen($this->conf['highlight_prefix']);
     if ($prefix_size) {
         $lines = explode("\n", $post['code']);
         $paste['editcode'] = "";
         foreach ($lines as $idx => $line) {
             if (substr($line, 0, $prefix_size) == $conf['highlight_prefix']) {
                 $highlight[] = $idx + 1;
                 $line = substr($line, $prefix_size);
             }
             $paste['editcode'] .= $line . "\n";
         }
         $paste['editcode'] = rtrim($post['editcode']);
     }
     $requestedFormat = $this->request->getParam('udf');
     $format = $requestedFormat ? $requestedFormat : $post['format'];
     // Get formatted version of code
     if (0 && strlen($post['codefmt']) > 0 && $format == $post['format']) {
         $paste['codefmt'] = $post['codefmt'];
     } else {
         $geshi = new \GeSHi($paste['editcode'], $format);
         $geshi->enable_classes();
         $geshi->set_header_type(GESHI_HEADER_DIV);
         $geshi->set_line_style('background: #ffffff;', 'background: #f4f4f4;');
         if (count($highlight)) {
             $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
             $geshi->highlight_lines_extra($highlight);
             $geshi->set_highlight_lines_extra_style('color:black;background:#FFFF88;');
         } else {
             $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
         }
         $paste['codefmt'] = $geshi->parse_code();
         $paste['codecss'] = $geshi->get_stylesheet();
     }
     $paste['pid'] = $pid;
     $paste['downloadurl'] = $conf->url . $post['pid'];
     $this->url = $conf->url;
     $this->post = $paste;
     $this->geshiformats = $conf->get('geshiformats');
     $this->popular_syntax = $conf->get('popular_syntax');
     $this->format = $format;
 }