Skip to content

Commit

Permalink
New Features: standard code blocks and Toolbar Buttons
Browse files Browse the repository at this point in the history
Signed-off-by: Taggic <taggic@t-online.de>
  • Loading branch information
Taggic committed Feb 10, 2012
1 parent 2d14fd6 commit 029e4fd
Show file tree
Hide file tree
Showing 17 changed files with 203 additions and 54 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2012-01-18
2012-02-10
110 changes: 110 additions & 0 deletions action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* Action Plugin: Inserts a button into the toolbar to add file tags
*
* @author Heiko Barth
*/

if (!defined('DOKU_INC')) die();
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
require_once (DOKU_PLUGIN . 'action.php');

class action_plugin_xssnipper extends DokuWiki_Action_Plugin {

/**
* Return some info
*/
function getInfo() {
return array (
'author' => 'Heiko Barth',
'date' => '2010-03-02',
'name' => 'Toolbar Code Button',
'desc' => 'Inserts a code button into the toolbar',
'url' => 'http://www.heiko-barth.de/download.php?id=dw_codebutton',
);
}

/**
* Register the eventhandlers
*/
function register(&$controller) {
$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'insert_button', array ());
}

/**
* Inserts the toolbar button
*/
function insert_button(&$event, $param) {
$event->data[] = array (
'type' => 'picker',
'title' => 'Code select',
'icon' => '../../plugins/xssnipper/images/code.png',
'list' => array(
array(
'type' => 'format',
'title' => 'xssnip',
'icon' => '../../plugins/xssnipper/images/code_xssnip.png',
'open' => '{(xssnipper>',
'close' => ')}',
),
array(
'type' => 'format',
'title' => 'code',
'icon' => '../../plugins/xssnipper/images/code_code.png',
'open' => '<code>\n',
'close' => '\n</code>',
),
array(
'type' => 'format',
'title' => 'php',
'icon' => '../../plugins/xssnipper/images/code_php.png',
'open' => '<code php>\n',
'close' => '\n</code>',
),
array(
'type' => 'format',
'title' => 'html',
'icon' => '../../plugins/xssnipper/images/code_html.png',
'open' => '<code html>\n',
'close' => '\n</code>',
),
array(
'type' => 'format',
'title' => 'js',
'icon' => '../../plugins/xssnipper/images/code_js.png',
'open' => '<code php>\n',
'close' => '\n</code>',
),
array(
'type' => 'format',
'title' => 'code',
'icon' => '../../plugins/xssnipper/images/code_css.png',
'open' => '<code css>\n',
'close' => '\n</code>',
),
array(
'type' => 'format',
'title' => 'txt',
'icon' => '../../plugins/xssnipper/images/code_txt.png',
'open' => '<code txt>\n',
'close' => '\n</code>',
),
array(
'type' => 'format',
'title' => 'xml',
'icon' => '../../plugins/xssnipper/images/code_xml.png',
'open' => '<code xml>\n',
'close' => '\n</code>',
),
array(
'type' => 'format',
'title' => 'file',
'icon' => '../../plugins/xssnipper/images/code_file.png',
'open' => '<file>\n',
'close' => '\n</file>',
)
)
);
}

}
9 changes: 9 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
code=<code [type] [filename]> insert_code_here </code>
xssnip={(xssnipper>[path],[from line],[to line],[type] [filename])}
php=<code php [filename]> insert_code_here </code>
css=<code css [filename]> insert_code_here </code>
html=<code html [filename]> insert_code_here </code>
js=<code js [filename]> insert_code_here </code>
txt=<code txt [filename]> insert_code_here </code>
xml=<code xml [filename]> insert_code_here </code>
file=<file></file>
Binary file added images/code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/code_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/code_css.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/code_file.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/code_html.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/code_js.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/code_php.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/code_txt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/code_xml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/code_xssnip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$lang['insertcode'] = '[PATH],[from line],[to line],[code language] [code block file]';
4 changes: 2 additions & 2 deletions plugin.info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
base xssnipper
author Taggic
email taggic@t-online.de
date 2012-01-18
date 2012-02-10
name xssnipper
desc provides syntax plugin to retrieve code snippeds from files
url http://www.dokuwiki.org/plugin:mysnipper
url http://www.dokuwiki.org/plugin:xssnipper

12 changes: 12 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
div.xssnipper {
border: 1px dashed #a0a0a0;
background: #f0f0f0;
border-radius: 5px;
box-shadow: 3px 3px #CECECE;

}

div.xssnipper ol {
Expand All @@ -26,4 +29,13 @@
color: #000000;
padding:5px 0;
margin:0px;
}

table.xssnipper {
background:#f0f0f0 !important;
border: 1px dashed #a0a0a0;
max-width: 100% !important;
}
table.xssnipper pre {
border: 0 !important;
}
118 changes: 67 additions & 51 deletions syntax.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ function handle($match, $state, $pos, &$handler) {
if (!$params) {
msg('Syntax of xssnipper detected but an unknown parameter was attached.', -1);
}
elseif($params[0] == ''){
// 0 1 2 3
// {(xssnipper>,[start line],[type] [file],<c>[content]</c>)}
$params = explode(",",$match,4);
$xssnipper = array();
$xssnipper['filepath'] = '';
$xssnipper['from'] = $params[1];
$alpha = explode(' ',$params[2]);
$xssnipper['type'] = $alpha[0];
$xssnipper['file'] = $alpha[1];
$xssnipper['code'] = $params[3];
}
else {
// Values
$xssnipper = array();
Expand All @@ -75,67 +87,71 @@ function handle($match, $state, $pos, &$handler) {
$alpha = explode(' ',$params[3]);
$xssnipper['type'] = $alpha[0];
$xssnipper['file'] = $alpha[1];
return $xssnipper;
}
return $xssnipper;
}
/******************************************************************************/
/* render output
* @author Taggic <taggic@t-online.de>
*/
function render($mode, &$renderer, $xssnipper) {
global $ID;
if(!$xssnipper['type']) $xssnipper['type']='txt';
if($this->_codeblock<1) $this->_codeblock=1;

if(!$xssnipper['type']) $xssnipper['type']='txt';
if(!$xssnipper['file']) $xssnipper['file']= basename($xssnipper['filepath']);
if(!$xssnipper['file']) $xssnipper['file']='snippet.'.$xssnipper['type'];
if(!$simplesnipper['until']) $simplesnipper['until'] = count($records);
if($this->_codeblock<1) $this->_codeblock=1;

// 1. check if $xssnipper['filepath'] exist, else error message
if(!file_exists($xssnipper['filepath'])) {
msg('file '.$xssnipper['filepath'].' not found',-1);
return false;
}

// 2. open the file in read mode
$records = file($xssnipper['filepath']);

// 3. load the file content from line = $xssnipper['from'] , to line = $xssnipper['until'] into $code_lines
if(!$xssnipper['until']) $xssnipper['until']=count($records);
foreach ($records as $line_num => $line) {
if(($line_num>=$xssnipper['from']-1) && ($line_num<=$xssnipper['until']-2))
$code_lines .= $line;
if ($line_num>$xssnipper['until']) break;
}

$geshi = new GeSHi($code_lines, $xssnipper['type']);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_overall_class('xssnipper');
$geshi->set_header_type(GESHI_HEADER_DIV);
$geshi->start_line_numbers_at($xssnipper['from']);

$xs_path = '?do=export_code&id='.$ID;
$text = $geshi->parse_code();

$code_block .= NL.NL.'
<dl class="code">
<dt>
<a href="'.$xs_path.'&codeblock='.$this->_codeblock.'" title="Download Snippet" class="mediafile mf_'.$xssnipper['type'].'">'.$xssnipper['file'].'</a>
</dt>
<dd>'.$text.'</dd>
</dl>'.NL.NL;

$renderer->doc .= $code_block;

if($this->_codeblock == $_REQUEST['codeblock']){
header("Content-Type: text/plain; charset=utf-8");
header("Content-Disposition: attachment; filename=".trim($xssnipper['file']));
header("X-Robots-Tag: noindex");
header("Pragma: public");
echo trim($code_lines,"\r\n");
exit;
if($xssnipper['filepath']=='') {
$code_lines = $xssnipper['code'];
}
$this->_codeblock++;
else {
if(!$xssnipper['file']) $xssnipper['file']= basename($xssnipper['filepath']);
if(!$xssnipper['file']) $xssnipper['file']='snippet.'.$xssnipper['type'];

// 1. check if $xssnipper['filepath'] exist, else error message
if(!file_exists($xssnipper['filepath'])) {
msg('file '.$xssnipper['filepath'].' not found',-1);
return false;
}

// 2. open the file in read mode
$records = file($xssnipper['filepath']);

// 3. load the file content from line = $xssnipper['from'] , to line = $xssnipper['until'] into $code_lines
if(!$xssnipper['until']) $xssnipper['until']=count($records);
foreach ($records as $line_num => $line) {
if(($line_num>=$xssnipper['from']-1) && ($line_num<=$xssnipper['until']-2))
$code_lines .= $line;
if ($line_num>$xssnipper['until']) break;
}
}
$geshi = new GeSHi($code_lines, $xssnipper['type']);
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
$geshi->set_overall_class('xssnipper');
$geshi->set_header_type(GESHI_HEADER_DIV);
// $geshi->set_header_type(GESHI_HEADER_PRE_TABLE);
$geshi->start_line_numbers_at($xssnipper['from']);

$xs_path = '?do=export_code&id='.$ID;
$text = $geshi->parse_code();

$code_block .= NL.NL.'
<dl class="code">
<dt>
<a href="'.$xs_path.'&codeblock='.$this->_codeblock.'" title="Download Snippet" class="mediafile mf_'.$xssnipper['type'].'">'.$xssnipper['file'].'</a>
</dt>
<dd style="display : none;">'.$code_lines.'</dd>'.$text.'
</dl>'.NL;

$renderer->doc .= $code_block;

if($this->_codeblock == $_REQUEST['codeblock']){
header("Content-Type: text/plain; charset=utf-8");
header("Content-Disposition: attachment; filename=".trim($xssnipper['file']));
header("X-Robots-Tag: noindex");
header("Pragma: public");
echo trim($code_lines,"\r\n");
exit;
}
$this->_codeblock++;

}
}
Expand Down

0 comments on commit 029e4fd

Please sign in to comment.