/** * 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; }
/** * Get formatted post, ready for inserting into a page * Returns an array of useful information */ function getPost($pid) { $post = $this->db->getPost($pid, $this->conf['subdomain']); if ($post) { //show a quick reference url, poster and parents $post['posttitle'] = "Posted by {$post['poster']} on {$post['postdate']}"; if ($post['parent_pid'] != '0') { $parent_pid = $post['parent_pid']; $parent = $this->db->getPost($parent_pid, $this->conf['subdomain']); if ($parent) { $post['parent_poster'] = trim($parent['poster']); if (strlen($post['parent_poster']) == 0) { $post['parent_poster'] = 'Anonymous'; } $post['parent_url'] = $this->getPostUrl($parent_pid); $post['parent_postdate'] = $parent['postdate']; $post['parent_diffurl'] = $this->conf['this_script'] . "?diff={$pid}"; } } //any amendments - note that a db class might have already //filled this if efficient, othewise we grab it on demand if (!isset($post['followups'])) { $post['followups'] = $this->db->getFollowupPosts($pid); } foreach ($post['followups'] as $idx => $followup) { $post['followups'][$idx]['followup_url'] = $this->getPostUrl($followup['pid']); } $post['downloadurl'] = $this->conf['this_script'] . "?dl={$pid}"; $post['deleteurl'] = $this->conf['this_script'] . "?erase={$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->set_encoding($this->conf['htmlentity_encoding']); $geshi->enable_classes(); $geshi->set_header_type(GESHI_HEADER_DIV); $geshi->set_line_style('background: #ffffff;', 'background: #f8f8f8;'); //$geshi->set_comments_style(1, 'color: #008800;',true); //$geshi->set_comments_style('multi', 'color: #008800;',true); //$geshi->set_strings_style('color:#008888',true); //$geshi->set_keyword_group_style(1, 'color:#000088',true); //$geshi->set_keyword_group_style(2, 'color:#000088;font-weight: normal;',true); //$geshi->set_keyword_group_style(3, 'color:black;font-weight: normal;',true); //$geshi->set_keyword_group_style(4, 'color:#000088',true); //$geshi->set_symbols_style('color:#ff0000'); 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 may have been deleted</b><br />"; } return $post; }
array('name' => 'style', 'type' => 'text', 'description' => 'CSS style'), array('name' => 'lang', 'type' => 'select', 'options' => array('php', 'sql', 'html'), 'description' => 'language type'), array('name' => 'lines', 'type' => 'text', 'description' => 'lines to be highlighted') ); **/ if (isset($p['style'])) { $p['style'] = ' style="' . $p['style'] . '"'; } else { $p['style'] = ''; } if (!$p['lang']) { $p['lang'] = 'php-brief'; } else { $p['lang'] = $p['lang']; } @(list($type, $body) = explode(':', $body, 2)); if ($type == 'file') { $geshi = new GeSHi(trim(file_get_contents("{$g['base_path']}/codes/{$body}")), $p['lang']); $geshi->set_header_content('Filename: ' . $body); } elseif ($type == 'code') { $geshi = new GeSHi(trim($body), $p['lang']); } if (@count($p['lines'])) { $geshi->highlight_lines_extra(explode(',', $p['lines'])); $geshi->set_highlight_lines_extra_style('background: #330'); } $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_line_style('margin: 3px 0;'); $geshi->set_header_content_style('font-size: 0.8em; color: #333'); $geshi->set_header_type(GESHI_HEADER_DIV); @($g['slide'] .= '<div class="code">' . $geshi->parse_code() . '</div>');
} $drop['text'] = array_merge($drop['text'], array($line)); if (isset($drops[1])) { if ($ilines == 9) { $drop['text'] = array_merge($drop['text'], array("... This Drop is longer than 10 lines. Click the name above to see it all ...")); break; } } } $drop['text'] = implode("\n", $drop['text']); } //geshi object $geshi = new GeSHi(stripslashes($drop['text']), $drop['lang']); $geshi->highlight_lines_extra($highlight); $geshi->set_tab_width(4); $geshi->set_highlight_lines_extra_style('background:#FFFF88;'); $geshi->enable_keyword_links(false); //geshi line numbers $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); $geshi->set_header_type(GESHI_HEADER_DIV); //geshi styling for syntax box $geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #fdfdf6; line-height:1.3em;', true); $geshi->set_line_style('font: normal normal \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060; padding-right: 5px;', true); $geshi->set_code_style('color: #000020;', 'color: #000020;'); if ($drop['editable'] == 1) { if (!isset($_GET['passkey'])) { $editable = ' You may <a href="' . $DROP_CONF_siteURL . '/' . $drop['id'] . '/edit">edit this</a> drop.'; } else { $editable = ' You may <a href="' . substr($_SERVER['REQUEST_URI'], 0, -30) . '/edit?pkey=' . $_GET['passkey'] . '">edit this</a> drop.'; } } else {
function getPaste($pid) { $post = $this->db->getPaste($pid); if ($post) { // Show a quick reference url, title and parents. $expires = is_null($post['expires']) ? " (Never Expires) " : " - Expires on " . date("D, F jS @ g:ia", strtotime($post['expires'])); $post['posttitle'] = "<b>{$post['title']}</b> - Posted on {$post['postdate']} {$expires}"; if ($post['parent_pid'] > 0) { $parent_pid = $post['parent_pid']; $parent = $this->db->getPaste($parent_pid); if ($parent) { $post['parent_title'] = $parent['title']; $post['parent_url'] = $this->getPasteUrl($parent_pid); $post['parent_postdate'] = $parent['postdate']; $post['parent_diffurl'] = $this->conf['diff_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; }