コード例 #1
0
ファイル: PasteForm.php プロジェクト: nicolask/Indechse-pste
 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
 public function getRecentItems()
 {
     $config = \Pste\Registry::getInstance()->config;
     $db = new \DB();
     // Get raw db info.
     $posts = $db->getRecentPostSummary($config->list);
     // Augment with some formatting
     foreach ($posts as $idx => $post) {
         $age = $post['age'];
         $days = floor($age / (3600 * 24));
         $hours = floor($age / 3600);
         $minutes = floor($age / 60);
         $seconds = $age;
         if ($days > 1) {
             $age = "{$days} days ago";
         } elseif ($hours > 0) {
             $age = "{$hours} hour" . ($hours > 1 ? "s" : "") . " ago";
         } elseif ($minutes > 0) {
             $age = "{$minutes} minute" . ($minutes > 1 ? "s" : "") . " ago";
         } else {
             $age = "< 1 min ago";
         }
         $posts[$idx]['agefmt'] = $age;
         $posts[$idx]['url'] = $config->url . $post['pid'];
     }
     $this->recent = $posts;
 }
コード例 #3
0
ファイル: bootstrap.php プロジェクト: nicolask/Indechse-pste
/**
 * wrapper for config instance creation so the instance does not live in global
 * scope 
 */
function bootstrap($configuration_array)
{
    $config = new \Pste\Config($configuration_array);
    \Pste\Registry::getInstance()->config = $config;
    $route = new \Pste\Route();
    $route->setTemplatePath($config->template);
    \Pste\Registry::getInstance()->route = $route;
}
コード例 #4
0
ファイル: UserLogin.php プロジェクト: nicolask/Indechse-pste
 protected function getUserdata()
 {
     $user = \Pste\Registry::getInstance()->user;
     $this->authenticated = false;
     if (\Pste\Registry::getInstance()->authenticated) {
         $this->authenticated = true;
         $this->user = $user;
     }
 }
コード例 #5
0
ファイル: Route.php プロジェクト: nicolask/Indechse-pste
 /**
  *
  * @return \Pste\Route 
  */
 public function route()
 {
     $route = \Pste\Registry::getInstance()->route;
     if (!$route instanceof \Pste\Route) {
         $route = new \Pste\Route();
         $route->setTemplatePath(\Pste\Registry::getInstance()->config->template);
         \Pste\Registry::getInstance()->route = $route;
     }
     return $route;
 }
コード例 #6
0
 protected function getPosts()
 {
     $db = new \DB();
     $config = \Pste\Registry::getInstance()->config;
     $pastes = $db->getAllPastes($this->request->getParam('page', 1), $config->itemsPerPage);
     $this->count = $db->getPasteCount();
     $this->page = $this->request->getParam('page', 1);
     $this->itemsPerPage = $config->itemsPerPage;
     $this->pastes = $pastes;
     $this->url = $config->url;
 }
コード例 #7
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;
 }
コード例 #8
0
ファイル: index.php プロジェクト: nicolask/Indechse-pste
        if ($id) {
            $pastebin->redirectToPost($id);
            exit;
        }
    }
    if ($request->hasParam('show') && ($config->restrict_show && \Pste\Registry::getInstance()->authenticated || !$config->restrict_show)) {
        $content = \Pste\Component::add(new \Pste\Component\SinglePaste(array('pid' => $request->getParam('show'), 'request' => $request)));
    } else {
        if ($request->hasParam('archive')) {
            require_once 'components/PasteArchive.php';
            $content = \Pste\Component::add(new \Pste\Component\PasteArchive(array('page' => $request->getParam('page'), 'request' => $request)));
        } else {
            if ($request->hasParam('submit', 'GET')) {
                $content = \Pste\Component::add(new \Pste\Component\PasteForm(array('request' => $request)));
            } else {
                if ($request->hasParam('info', 'GET') && \Pste\Registry::getInstance()->authenticated) {
                    phpinfo();
                    die;
                } else {
                    $content = \Pste\Component::add(new \Pste\Component\StaticPage(array('template' => 'components/frontpage.php', 'request' => $request)));
                }
            }
        }
    }
    $layout = new \Pste\Layout(array('request' => $request));
    $layout->setContent($content);
    $layout->setTemplate('theme.php');
    ob_start();
    echo $layout->render();
    ob_end_flush();
} catch (Exception $ex) {
コード例 #9
0
ファイル: theme.php プロジェクト: nicolask/Indechse-pste
        </div>
        <div id="menu">
            <?php 
echo \Pste\Component::add(new \Pste\Component\RecentItems());
?>
        </div>
        
        <div id="content"><br />
            <h1>Welcome! Here you can paste sources and general debugging text, 
                You can even set yourself a password if you want to keep it just for yourself.</h1>
                <?php 
echo $this->content;
?>
                <br />
                
                <h1>&copy; <?php 
echo date("Y");
?>
 - Powered by <a href="https://github.com/nicolask/indechse-pste">Indechse Pste</a> 0.1 
                    - rendered in <?php 
echo round(microtime(true) - \Pste\Registry::getInstance()->starttime, 4);
?>
</h1>
                <?php 
echo \Pste\Component::add(new \Pste\Component\StaticPage(array('template' => 'components/credits.php')));
?>
 
            
        </div>
    </body>
</html>
コード例 #10
0
ファイル: View.php プロジェクト: nicolask/Indechse-pste
 public function __construct($params = array())
 {
     $this->_initParams($params);
     $this->_config = \Pste\Registry::getInstance()->config;
     $this->_init();
 }
コード例 #11
0
ファイル: paste.php プロジェクト: nicolask/Indechse-pste
 function getPaste($pid)
 {
     $post = $this->db->getPaste($pid);
     if ($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']));
         $post['posttitle'] = "Posted by {$post['poster']} on {$post['postdate']} - {$expires}";
         if ($post['parent_pid'] > 0) {
             $parent_pid = $post['parent_pid'];
             $parent = $this->db->getPaste($parent_pid);
             if ($parent) {
                 $route = \Pste\Registry::getInstance()->route;
                 $post['parent_poster'] = $parent['poster'];
                 $post['parent_url'] = $this->getPasteUrl($parent_pid);
                 $post['parent_postdate'] = $parent['postdate'];
                 $post['parent_diffurl'] = $route->url($pid);
             }
         }
         // Amendments
         $post['followups'] = $this->db->getFollowupPosts($pid);
         foreach ($post['followups'] as $idx => $followup) {
             $post['followups'][$idx]['followup_url'] = $this->getPasteUrl($followup['pid']);
         }
         if ($post['password'] != 'EMPTY') {
             $post['downloadurl'] = $this->conf['url'] . "?dl={$pid}&pass="******"?dl={$pid}";
         }
         // Store the code for later editing
         $post['editcode'] = $post['code'];
         // Preprocess
         $highlight = array();
         $prefix_size = strlen($this->conf['highlight_prefix']);
         if ($prefix_size) {
             $lines = explode("\n", $post['editcode']);
             $post['editcode'] = "";
             foreach ($lines as $idx => $line) {
                 if (substr($line, 0, $prefix_size) == $this->conf['highlight_prefix']) {
                     $highlight[] = $idx + 1;
                     $line = substr($line, $prefix_size);
                 }
                 $post['editcode'] .= $line . "\n";
             }
             $post['editcode'] = rtrim($post['editcode']);
         }
         // Get formatted version of code
         if (strlen($post['codefmt']) == 0) {
             $geshi = new GeSHi($post['editcode'], $post['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);
             }
             $post['codefmt'] = $geshi->parse_code();
             $post['codecss'] = $geshi->get_stylesheet();
             // Save it!
             $this->db->saveFormatting($pid, $post['codefmt'], $post['codecss']);
         }
         $post['pid'] = $pid;
     } else {
         $post['codefmt'] = "<b>Unknown post ID, it probably expired.</b><br />";
     }
     return $post;
 }