Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TomCafferty committed Nov 9, 2012
0 parents commit e71880b
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README
@@ -0,0 +1,17 @@
F U N C T I O N

function Plugin for DokuWiki

All documentation for this plugin can be found at http://www.dokuwiki.org/plugin:function

If you install this plugin manually, make sure it is installed in lib/plugins/function/ - if the folder is called different it will not work!

Please refer to http://www.dokuwiki.org/plugins for additional info on how to install plugins in DokuWiki.

Copyright (C) Tom Cafferty tcafferty@glocalfocal.com

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

See the COPYING file in your DokuWiki folder for details.
8 changes: 8 additions & 0 deletions conf/default.php
@@ -0,0 +1,8 @@
<?php
/**
* Default settings for the function plugin
*
* @author Tom Cafferty <tcafferty@glocalfocal.com>
*/

$conf['file1'] = 'helloWorld.php';
9 changes: 9 additions & 0 deletions conf/metadata.php
@@ -0,0 +1,9 @@
<?php
/**
* Options for the function plugin
*
* @author Tom Cafferty <tcafferty@glocalfocal.com>
*/

$meta['file1'] = array('string');

7 changes: 7 additions & 0 deletions functions/helloWorld.php
@@ -0,0 +1,7 @@
<?php
function run () {
// Create output data
$dataout='<p class="cellGreen">Hello World!</p>';
// echo $dataout;
return $dataout;
}
3 changes: 3 additions & 0 deletions lang/en/settings.php
@@ -0,0 +1,3 @@
<?php

$lang['file1'] = 'A green Hello World function';
36 changes: 36 additions & 0 deletions style.css
@@ -0,0 +1,36 @@
html {
height: 100%;
}
body {
color: #000;
font-family: Arial, Helvetica, sans-serif;
height: 100%;
}
div#outerContainer {
min-height: 100%;
}
/**************************************/
/* cell colors */
/**************************************/
.cellGreen {
background-color: green;
font-weight: bold;
color: white;
}
.cellLightGreen {
background-color: #90EE90;
font-weight: bold;
}
.cellLightSalmon {
background-color: #FFA07A;
font-weight: bold;
}
.cellDarkOrange {
background-color: #FF8C00;
font-weight: bold;
}
.cellRed {
background-color: red;
font-weight: bold;
color: white;
}
84 changes: 84 additions & 0 deletions syntax.php
@@ -0,0 +1,84 @@
<?php
/**
* PHP Includes via Syntax
*
* Put your php files in /functions folder and add the path and function
* identifier to the /conf/default.php filr
*
* <function=functionId>
*
* The syntax includes the PHP file per include an puts the result into
* the wiki page.
*
* @license GNU_GPL_v2
* @author Markus Frosch <markus [at] lazyfrosch [dot] de>
* @author Tom Cafferty <tcafferty [at] glocalfocal [dot] com>
*/

if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');


class syntax_plugin_function extends DokuWiki_Syntax_Plugin {

function getInfo(){
return array(
'author' => 'Tom Cafferty',
'email' => 'tcafferty@glocalfocal.com',
'date' => '2012-10-05',
'name' => 'Function',
'desc' => 'Allows you to run a PHP function on Server',
'url' => 'http://www.dokuwiki.org/plugin:function',
);
}

function getType(){ return 'substition'; }
function getPType(){ return 'normal'; }
function getAllowedTypes() {
return array('substition','protected','disabled');
}
function getSort(){ return 195; }

function connectTo($mode) {
$this->Lexer->addSpecialPattern('<function=.*?>',$mode,'plugin_function');
}

function handle($match, $state, $pos, &$handler){
switch ($state) {
case DOKU_LEXER_SPECIAL :
return array($state, $match);
default:
return array($state);
}
}

function render($mode, &$renderer, $indata) {
global $conf;
if($mode == 'xhtml'){
list($state, $data) = $indata;

switch ($state) {
case DOKU_LEXER_SPECIAL :
preg_match("#^<function=(.+)>$#", $data, $matches);
$func = $matches[1];
if(preg_match("#^[a-z0-9\-_ \./]+$#i", $func)) {
$renderer->info['cache'] = FALSE;
$filename = DOKU_PLUGIN . 'function/functions/' . $this->getConf($func);
include ($filename);
$renderer->doc .= run();
}
else
$renderer->doc .= $renderer->_xmlEntities($data);
break;

}
return true;
}

// unsupported $mode
return false;
}
}

?>

0 comments on commit e71880b

Please sign in to comment.