Permalink
Browse files

New Features: standard code blocks and Toolbar Buttons

Signed-off-by: Taggic <taggic@t-online.de>
  • Loading branch information...
Taggic committed Feb 10, 2012
1 parent 2d14fd6 commit 029e4fdaaed9b54c927c8a19bd33d783bb3d86f7
View
@@ -1 +1 @@
2012-01-18
2012-02-10
View
@@ -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>',
)
)
);
}
}
View
@@ -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>
View
BIN +658 Bytes images/code.png
Binary file not shown.
View
BIN +805 Bytes images/code_code.png
Binary file not shown.
View
BIN +1.07 KB images/code_css.png
Binary file not shown.
View
BIN +485 Bytes images/code_file.png
Binary file not shown.
View
BIN +969 Bytes images/code_html.png
Binary file not shown.
View
BIN +785 Bytes images/code_js.png
Binary file not shown.
View
BIN +1.15 KB images/code_php.png
Binary file not shown.
View
BIN +1.26 KB images/code_txt.png
Binary file not shown.
View
BIN +1.04 KB images/code_xml.png
Binary file not shown.
View
BIN +598 Bytes images/code_xssnip.png
Binary file not shown.
View
@@ -0,0 +1,2 @@
<?php
$lang['insertcode'] = '[PATH],[from line],[to line],[code language] [code block file]';
View
@@ -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
View
@@ -5,6 +5,9 @@
div.xssnipper {
border: 1px dashed #a0a0a0;
background: #f0f0f0;
border-radius: 5px;
box-shadow: 3px 3px #CECECE;
}
div.xssnipper ol {
@@ -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;
}
View
@@ -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();
@@ -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++;
}
}

0 comments on commit 029e4fd

Please sign in to comment.