Exemple #1
0
<br><br>
<h2 id="Live_Info">Get Live Info - The 'Hello World' of Samesub</h2>
&nbsp;<p>Let's go right away with an example using Html and Javascript. Just 
copy the following code, save it in a .html file and then open it from a Web 
Browser. The example prints the current title and the time remaining.</p>
<?php 
$source = "<html>\n\t<head>\n\t\t<script type=\"text/javascript\" src=\"http://code.jquery.com/jquery-latest.js\"></script>\n\t\t<script type=\"text/javascript\">\n\t\tfunction getLiveInfo(){\n\t\t\t\$.getJSON('http://samesub.com/api/v1/live/getall?callback=?',\n\t\t\t\t{},\n\t\t\t\tfunction(data) {\n\t\t\t\t\t//If everything is ok(response_code == 200), let's print some LIVE information\n\t\t\t\t\tif(data.response_code == 200){\n\t\t\t\t\t\t\$('#title').html(data.title);\n\t\t\t\t\t\t\$('#time_remaining').html(data.time_remaining + ' seconds.');\n\t\t\t\t\t}else{\n\t\t\t\t\t\t//Otherwise alert data.response_message\t\t\t\t\n\t\t\t\t\t\talert(data.response_message);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\t\t\n\t\t//When the page has loaded, we call our function\n\t\t\$(document).ready(function() {\n\t\t\tgetLiveInfo();\n\t\t});\n\t\t</script>\n\t</head>\n\t<body>\n\t\t<h1>My First Samesub API example</h1>\n\t\t<p>Current Title: <span id=\"title\"></span></p>\n\t\t<p>Time remaining: <span id=\"time_remaining\"></span></p>\n\t</body>\n</html>";
$language = 'Javascript';
$geshi = new GeSHi($source, $language);
$geshi->enable_classes();
$geshi->set_overall_class('myjs_lines');
$geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
$geshi->set_overall_style("padding:0 0 5px 0;border:1px solid #999999");
$geshi->set_tab_width(2);
$geshi->set_header_content("(<LANGUAGE>) Example - Getting current subject info in homepage(LIVE) using Jquery");
$geshi->set_header_content_style("background-color: #DFDFFF;font-size:14px;font-weight:bold;");
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_line_style('background: #fcfcfc;', true);
Yii::app()->clientScript->registerCss('highlightcode', $geshi->get_stylesheet());
echo $geshi->parse_code();
?>

<p>&nbsp;</p>
<p>Let's analyze the code step by step:</p>
<ol>
	<li>We include the <a href="http://jquery.com/">Jquery Javascript Framework</a> 
	to make our work more easy.</li>
<li>We use the 
<a href="api#live/getall">live/getall</a> API resource to get the information in live(homepage).</li>
	<li>For this example we have added a callback parameter to the url (notice
	<b>callback=?</b>) to prevent 'Same Origin' security policy error, since 
Exemple #2
0
    exit("File not found ({$path}).");
}
// Prepare GeSHi instance
$geshi = new GeSHi();
$geshi->set_language('text');
$geshi->load_from_file($path);
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->enable_classes();
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
$geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
$geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
$geshi->set_code_style('color: #000020;', 'color: #000020;');
$geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
$geshi->set_header_content('Source code viewer - ' . $path . ' - ' . $geshi->get_language_name());
$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
$geshi->set_footer_content('Parsed in <TIME> seconds,  using GeSHi <VERSION>');
$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Source code viewer - <?php 
echo $path;
?>
 - <?php 
$geshi->get_language_name();
?>
</title>
    <style type="text/css">
    public function View($ID, $lang)
    {
        $this->id = intval($ID);
        if (empty($this->id)) {
            die("ID not valid!");
        }
        //Elimino tutti i sorgenti che hanno una durata inferiore a time();
        $this->sql->sendQuery("DELETE FROM " . __PREFIX__ . "pastes WHERE expire_date > 0 AND expire_date < " . time());
        $this->my_is_numeric($this->id);
        $this->check_id_exists($this->id);
        require_once "lib/geshi/geshi.php";
        $this->info = mysql_fetch_array($this->sql->sendQuery("SELECT * FROM `" . __PREFIX__ . "pastes` WHERE id = '" . $this->id . "' LIMIT 1;"));
        $geshi = new GeSHi($this->info['text'], $lang);
        $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
        if (!empty($lang)) {
            $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
        }
        $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
        $geshi->set_line_style('background: #fcfcfc;', 'background: #f0f0f0;', true);
        $geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif;  
										 font-size: 90%; 
										 border-bottom: 2px dotted black;
										 padding: 5px;');
        $this->PrintHeader();
        print "<br />\n" . $geshi->parse_code();
    }
Exemple #4
0
$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 {
    if ($drop['editable'] == 0) {
        $editable = '';
    } else {
        die("WOAH! WE HAVE AN ERROR IN THE HOUSE!!! CONTACT THE AUTHORITIES!");
    }
}
$geshi->set_header_content('You are viewing Drop #' . $drop['id'] . ' and it is being highlighted with the ' . $drop['lang'] . ' syntax.' . $editable);
$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #414141; background-color: #d2d2c8; border-bottom: 1px solid #d0d0d0; padding: 2px;');
if (!isset($drops[1])) {
    $geshi->set_footer_content('Parsed in <TIME> seconds');
}
$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #414141; background-color: #d2d2c8; border-top: 1px solid #d0d0d0; padding: 2px;');
//geshi results
echo $geshi->parse_code();
//echo $drop['text'];
Exemple #5
0
    public function View($ID, $line, $lang)
    {
        $this->id = intval($ID);
        if (empty($this->id)) {
            die("<div id=\"error\">ID not valid!</div>");
        }
        //Elimino tutti i sorgenti che hanno una durata inferiore a time();
        $this->sql->sendQuery("DELETE FROM " . __PREFIX__ . "pastes WHERE expire_date > 0 AND expire_date < " . time());
        $this->my_is_numeric($this->id);
        $this->check_id_exists($this->id);
        //Thanks sPaste and Stoner
        $this->url = "http://" . $_SERVER["HTTP_HOST"] . substr($_SERVER["PHP_SELF"], 0, strpos($_SERVER["PHP_SELF"], "/", strlen($_SERVER["PHP_SELF"]) - strlen(basename($_SERVER["PHP_SELF"])) - 1));
        if ($line == 'no') {
            $this->line = "<input type=\"button\" value=\"Visual Lines\" onClick=\"location.href='" . $this->url . "/view.php?id=" . $this->id . "&line=yes'\">\n";
        } else {
            if ($line == NULL || $line == 'yes') {
                $this->line = "<input type=\"button\" value=\"No Visual Lines\" onClick=\"location.href='" . $this->url . "/view.php?id=" . $this->id . "&line=no'\">\n";
            } else {
                if ($line != 'yes' && $line != 'no' && $line != NULL) {
                    die("Hacking Attemp!");
                }
            }
        }
        require_once "lib/geshi/geshi.php";
        $this->info = mysql_fetch_array($this->sql->sendQuery("SELECT * FROM `" . __PREFIX__ . "pastes` WHERE id = '" . $this->id . "' LIMIT 1;"));
        if (!empty($lang)) {
            $geshi = new GeSHi($this->info['text'], $lang);
        } else {
            $geshi = new GeSHi($this->info['text'], $this->info['language']);
        }
        $geshi->set_header_type(GESHI_HEADER_PRE_VALID);
        if ($line == 'yes' || $line == NULL) {
            $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
        }
        $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
        $geshi->set_line_style('background: #fcfcfc;', 'background: #f0f0f0;', true);
        $geshi->set_header_content("<font size=\"3\" >\n\n\t\t\t\t\t\t\t\t\tTitle: <b>" . $this->info['title'] . "</b><br />\n\n\t\t\t\t\t\t\t\t\tAuthor: <b>" . $this->info['author'] . "</b><br />\n\n\t\t\t\t\t\t\t\t\tDate: <b>" . $this->info['data'] . "</b> <br />\n\n\t\t\t\t\t\t\t\t\tLanguage: <b>" . $this->info['language'] . "</b>\n\n\t\t\t\t\t\t\t\t\t<br />\n\n\t\t\t\t\t\t\t\t\t<p style=\"float: left;\">Line: <b>" . $this->line . "</b>\n\n\t\t\t\t\t\t\t\t\t<p style=\"float: right;\"><b><a href=\"view.php?mode=raw&id=" . $this->id . "\" target=\"_blank\" >RAW</a> | <a href=\"view.php?mode=embed&id=" . $this->id . "\">EMBED</a></p></b><br /><br />\n\n\t\t\t\t\t\t\t\t\t</font>\n");
        $geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif;  
										 font-size: 90%; 
										 border-bottom: 2px dotted black;
										 padding: 5px;');
        $this->PrintHeader();
        print "<br />\n" . $geshi->parse_code();
        $this->PrintFooter();
    }
Exemple #6
0
    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>');