Пример #1
0
 /**
  * parse - Parses the code that has been loaded into the GeSHi instance
  * through loadDocument().
  *
  * @return string
  */
 public function parse()
 {
     // Codeblock header | Shows the language being used
     $return = "<div class='codeBlock codeBlockHeader'>Code Language: " . $this->_geshi->get_language_name() . '</div>';
     $return .= $this->_geshi->parse_code();
     // Parses code using the GeSHi instance
     return $return;
 }
Пример #2
0
 /**
  * Function to render syntax-highlighted lines of code
  * 
  * @param $code string the code to be rendered
  * @param $lang the language to use the syntax highlighting for
  * @param $options array header, start, end optional parameters
  */
 function parse($code, $lang, $options = array())
 {
     strtolower($lang);
     $geshi = new GeSHI(trim($code), $lang);
     //Set Geshi configuration settings
     if (file_exists(CONFIGS . 'geshi.php')) {
         include CONFIGS . 'geshi.php';
     }
     $geshi->language_data['LANG_NAME'] = $lang;
     if (isset($options['header'])) {
         $geshi->set_header_content($options['header']);
     }
     if (isset($options['start'])) {
         if (!isset($options['end'])) {
             $options['end'] = $options['start'];
         }
         $lines = array();
         for ($i = 0; $i <= $options['end'] - $options['start']; $i++) {
             $lines[$i] = (string) $options['start'] + $i;
         }
         $geshi->highlight_lines_extra($lines);
     }
     return $geshi->parse_code();
 }
Пример #3
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__);
 }
Пример #4
0
     }
     $b .= "<center>\n        <form action=index.php?lev=" . $_SESSION[$_CONF['sess_name'] . '_lev'] . "&cat=" . $_SESSION[$_CONF['sess_name'] . '_cat'] . " method=post name=teacher_page_form>\n        <input type=submit name=continue value=Continue />\n        </form><center>";
 } else {
     $t = "Custom Teacher Pages";
     $b = "\n        <script type=\"text/javascript\">\n        function confirmDelete(){\n            var msg = \"You are about to permanently delete a file.  Are You Sure?\\n\";\n            return confirm(msg);\n        }\n        </script>\n        This is where teachers can create custom pages for use within the confines of the site.  This gives all of the security and user info of the user using the page.<br />\n        You need to know something about Php to create pages here at the moment.<br />\n        <br />\n        You can use simple html but it must be embedded into php... for example...<br/>\n        <br />";
     /** Now for syntax highlighting the example **/
     include 'geshi.php';
     $lang = 'php';
     $path = 'geshi';
     $src = '
     <?php 
     $my_out = "<center> This text is centered </center>";
     $my_out .= "This is a second line of text.  Notice that after the first line, we need the .= with $my_out";
     ?>
     ';
     $geshi = new GeSHI($src, $lang, $path);
     $b .= $geshi->parse_code();
     $b .= "\n        <br /> \n        The \$my_out variable MUST be used.<br />\n";
     /** LIST ALL CUSTOM PAGES FOR THIS TEACHER **/
     $b .= "<center>\n                <table>\n                <tr>\n                    <th colspan=3>Teacher Custom pages</th>\n                    <th>\n                        <form action=index.php?lev=" . $_SESSION[$_CONF['sess_name'] . '_lev'] . "&cat=" . $_SESSION[$_CONF['sess_name'] . '_cat'] . " method=post name=teacher_page_form>\n                        <input type=submit name=newPage value=New />\n                        </form>\n                    </th>\n                </tr>";
     $sql = "SELECT * from teacher_pages where teacher_id=" . $UID;
     $result = $db->query($sql);
     while ($row = $result->fetch_assoc()) {
         $b .= "<tr>\n                    <td align=right>" . $row['link_name'] . "</td>\n                    <!--td>" . $row['description'] . "</td-->\n                    <td>\n                    <form action=index.php?lev=" . $_SESSION[$_CONF['sess_name'] . '_lev'] . "&cat=" . $_SESSION[$_CONF['sess_name'] . '_cat'] . " method=post id=edit_page_form name=edit_page_form>\n                        <input type=submit name=editPage value=Edit />\n                        <input type=submit name=previewPage value=Preview />\n                        <input type=submit name=deletePage value=Delete onClick=\"return confirmDelete();\" />\n                        <input type=hidden name=page_id value=" . $row['page_id'] . " />\n                    </form>\n                    </td>\n                   </tr>";
     }
     $b .= "</table>\n              </center>";
 }
 $main .= make_box($t, $b, $c);
 if (isset($_POST['previewPage'])) {
     include $SAVE_PATH . $_REQUEST['page_id'] . ".php";
     $b = $my_out;
Пример #5
0
 $stmt = $pdo->prepare('SELECT * FROM `' . $dbtbl . '` WHERE
                        `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']));
 }