Example #1
0
 /**
  * loadDocument - Loads the current document into a new GeSHi instance
  * used for syntax highlighting using the [code][/code] block.
  *
  * @param $code - The code to be parsed through GeSHi
  * @param $lang - The language the code falls under
  *
  * @return void
  */
 public function loadDocument($code, $lang)
 {
     $this->_language = $lang;
     // Set language of CodeDocument
     $this->_geshi = new GeSHi($code, strtolower($lang));
     // Create new GeSHi instance using code and lang provided
     $this->_geshi->set_header_type(GESHI_HEADER_PRE);
     // Set header type | For display type
     $this->_geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
     // Enable line numbers
     $this->_geshi->enable_keyword_links(false);
     // Disable keyword links in code
     $this->_geshi->set_tab_width(4);
     // Set the tab width of code
     $this->_geshi->set_overall_class('codeBlock');
     // Class for custom styling
     $this->_geshi->set_code_style('font-family: dejavu, monospace; font-size: 11px;', true);
 }
Example #2
0
 public function add($d)
 {
     global $LANGUAGES_FILES;
     if (!$this->check($d)) {
         return false;
     }
     require_once b1n_PATH_GESHI . '/geshi.php';
     $geshi = new GeSHI($d['source'], $LANGUAGES_FILES[$d['language']], b1n_PATH_GESHI . '/geshi');
     $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
     $geshi->set_header_type(GESHI_HEADER_DIV);
     $highlight = $geshi->parse_code();
     $this->sql->query("BEGIN TRANSACTION");
     $query = "\n      INSERT INTO paste (\n        lan_id,\n        pas_author,\n        pas_title,\n        pas_source,\n        pas_source_text,\n        pas_length,\n        pas_md5,\n        pas_usr_ip\n      )\n      VALUES (\n        " . Data::inBd($d['language']) . ",\n        " . Data::inBd($d['author']) . ",\n        " . Data::inBd($d['title']) . ",\n        " . Data::inBd($highlight) . ",\n        " . Data::inBd($d['source']) . ",\n        " . Data::inBd(strlen(trim($d['source']))) . ",\n        md5(" . Data::inBd($d['source']) . "),\n        " . Data::inBd($_SERVER['REMOTE_ADDR']) . "\n      )";
     if ($this->sql->query($query)) {
         $id = $this->sql->singleQuery("\n        SELECT CURRVAL('paste_pas_id_seq') AS id");
         $id['id'] = base_convert($id['id'], 10, b1n_CODE_BASE);
         $this->sql->query("COMMIT TRANSACTION");
         return $id;
     }
     Error::msg("Erro inesperado", __METHOD__);
 }
Example #3
0
                        `pasteid` = ?');
 //fields: pasteid, code, language, timestamp, dsc, rmable, rmid
 $stmt->execute(array($_GET['id']));
 $obj = $stmt->fetch(PDO::FETCH_OBJ);
 $dsc = $obj->dsc;
 if ($dsc == '') {
     $dsc .= 'no user notes';
 }
 echo '<a href="./plain.php?id=' . $_GET['id'] . '">plaintext</a> &mdash; <a
 href="./dl.php?id=' . $_GET['id'] . '">download</a> &mdash; added ' . date('F
 jS, Y \\a\\t h:i:s A T', $obj->timestamp) . ' &mdash; <em>' . $dsc . '</em>
 &mdash; <a href="./lnumbers.php?id=' . $_GET['id'] . '">Toggle line
 numbers</a> &mdash; hilighted by <a
 href="http://qbnz.com/highlighter/">GeSHi</a><br>';
 $geshi = new GeSHI($obj->code, $obj->language);
 $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
 $geshi->set_line_style('background: #fff;', 'background: #f0f0f0;');
 //this determines the line styles.  odd (white)          even (grey)
 if ($_COOKIE['kwpstln'] == 0) {
     $geshi->enable_line_numbers(GESHI_NO_LINE_NUMBERS);
 }
 echo $geshi->parse_code();
 if ($obj->rmable == '1') {
     echo "Removal ID: " . $obj->rmid . '<br>';
     echo "You can use the id at the deletion page.  Don't share it.  \n            The ID willn't show up anymore.";
     $stmt->closeCursor();
     $stmt = $pdo->prepare('UPDATE `' . $dbtbl . '` SET `rmable` = 0
     WHERE `pasteid` = ?');
     $stmt->execute(array($_GET['id']));
 }
 $stmt->closeCursor();