a first very basic implementation of the preview mechanism
This commit is contained in:
parent
4d6524b891
commit
6ea007c9f8
|
@ -47,6 +47,7 @@
|
|||
!/lib/plugins/popularity
|
||||
!/lib/plugins/revert
|
||||
!/lib/plugins/safefnrecode
|
||||
!/lib/plugins/styler
|
||||
!/lib/plugins/testing
|
||||
!/lib/plugins/usermanager
|
||||
!/lib/plugins/action.php
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
# Config file for travis-ci.org
|
||||
|
||||
language: php
|
||||
php:
|
||||
- "5.5"
|
||||
- "5.4"
|
||||
- "5.3"
|
||||
env:
|
||||
- DOKUWIKI=master
|
||||
- DOKUWIKI=stable
|
||||
before_install: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh
|
||||
install: sh travis.sh
|
||||
script: cd _test && phpunit --stderr --group plugin_styler
|
|
@ -0,0 +1,27 @@
|
|||
styler Plugin for DokuWiki
|
||||
|
||||
Allows to edit style.ini replacements
|
||||
|
||||
All documentation for this plugin can be found at
|
||||
https://www.dokuwiki.org/plugin:styler
|
||||
|
||||
If you install this plugin manually, make sure it is installed in
|
||||
lib/plugins/styler/ - 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) Andreas Gohr <andi@splitbrain.org>
|
||||
|
||||
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
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* General tests for the styler plugin
|
||||
*
|
||||
* @group plugin_styler
|
||||
* @group plugins
|
||||
*/
|
||||
class general_plugin_styler_test extends DokuWikiTest {
|
||||
|
||||
/**
|
||||
* Simple test to make sure the plugin.info.txt is in correct format
|
||||
*/
|
||||
public function test_plugininfo() {
|
||||
$file = __DIR__.'/../plugin.info.txt';
|
||||
$this->assertFileExists($file);
|
||||
|
||||
$info = confToHash($file);
|
||||
|
||||
$this->assertArrayHasKey('base', $info);
|
||||
$this->assertArrayHasKey('author', $info);
|
||||
$this->assertArrayHasKey('email', $info);
|
||||
$this->assertArrayHasKey('date', $info);
|
||||
$this->assertArrayHasKey('name', $info);
|
||||
$this->assertArrayHasKey('desc', $info);
|
||||
$this->assertArrayHasKey('url', $info);
|
||||
|
||||
$this->assertEquals('styler', $info['base']);
|
||||
$this->assertRegExp('/^https?:\/\//', $info['url']);
|
||||
$this->assertTrue(mail_isvalid($info['email']));
|
||||
$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
|
||||
$this->assertTrue(false !== strtotime($info['date']));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* DokuWiki Plugin styler (Action Component)
|
||||
*
|
||||
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if(!defined('DOKU_INC')) die();
|
||||
|
||||
class action_plugin_styler extends DokuWiki_Action_Plugin {
|
||||
|
||||
/**
|
||||
* Registers a callback function for a given event
|
||||
*
|
||||
* @param Doku_Event_Handler $controller DokuWiki's event controller object
|
||||
* @return void
|
||||
*/
|
||||
public function register(Doku_Event_Handler $controller) {
|
||||
|
||||
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax');
|
||||
$controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handle_action');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* [Custom event handler which performs action]
|
||||
*
|
||||
* @param Doku_Event $event event object by reference
|
||||
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
|
||||
* handler was registered]
|
||||
* @return void
|
||||
*/
|
||||
public function handle_action(Doku_Event &$event, $param) {
|
||||
$event->data = act_clean($event->data);
|
||||
if($event->data === 'styler_plugin_preview') {
|
||||
msg('handle') ;
|
||||
$event->data = 'show';
|
||||
$this->preview();
|
||||
} elseif ($event->data === 'styler_plugin_save') {
|
||||
$event->data = 'show';
|
||||
}
|
||||
}
|
||||
|
||||
protected function preview(){
|
||||
global $conf;
|
||||
$ini = $conf['cachedir'].'/preview.ini';
|
||||
io_saveFile($ini, $this->makeini());
|
||||
}
|
||||
|
||||
protected function makeini() {
|
||||
global $INPUT;
|
||||
|
||||
$ini = "[replacements]\n";
|
||||
foreach($INPUT->arr('tpl') as $key => $val) {
|
||||
$ini .= $key .' = "'.addslashes($val).'"'."\n";
|
||||
}
|
||||
|
||||
return $ini;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Custom event handler which performs action]
|
||||
*
|
||||
* @param Doku_Event $event event object by reference
|
||||
* @param mixed $param [the parameters passed as fifth argument to register_hook() when this
|
||||
* handler was registered]
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function handle_ajax(Doku_Event &$event, $param) {
|
||||
if($event->data != 'plugin_styler') return;
|
||||
$event->preventDefault();
|
||||
$event->stopPropagation();
|
||||
|
||||
/** @var admin_plugin_styler $hlp */
|
||||
$hlp = plugin_load('admin', 'styler');
|
||||
$hlp->html();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// vim:ts=4:sw=4:et:
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
/**
|
||||
* DokuWiki Plugin styler (Admin Component)
|
||||
*
|
||||
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
|
||||
// must be run within Dokuwiki
|
||||
if(!defined('DOKU_INC')) die();
|
||||
|
||||
class admin_plugin_styler extends DokuWiki_Admin_Plugin {
|
||||
|
||||
/**
|
||||
* @return int sort number in admin menu
|
||||
*/
|
||||
public function getMenuSort() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool true if only access for superuser, false is for superusers and moderators
|
||||
*/
|
||||
public function forAdminOnly() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should carry out any processing required by the plugin.
|
||||
*/
|
||||
public function handle() {
|
||||
set_doku_pref('styler_plugin', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render HTML output, e.g. helpful text and a form
|
||||
*/
|
||||
public function html() {
|
||||
global $conf;
|
||||
$tpl = $conf['template'];
|
||||
define('SIMPLE_TEST',1); // hack, ideally certain functions should be moved out of css.php
|
||||
require_once(DOKU_INC.'lib/exe/css.php');
|
||||
$styleini = css_styleini($conf['template'], true);
|
||||
$replacements = $styleini['replacements'];
|
||||
|
||||
ptln('<h1>'.$this->getLang('menu').'</h1>');
|
||||
|
||||
if (empty($replacements)) {
|
||||
echo '<p class="error">Sorry, this template does not support this functionality.</p>';
|
||||
} else {
|
||||
echo '<p>Intro blah... for the currently active template ("'.$tpl.'")... not all variables preview...</p>';
|
||||
|
||||
echo '<form class="styler" id="plugin__styler" method="post">';
|
||||
echo '<h2>Template variables</h2>';
|
||||
echo '<table>';
|
||||
foreach($replacements as $key => $value){
|
||||
echo '<tr>';
|
||||
echo '<td>'.$key.'</td>';
|
||||
echo '<td><input name="tpl['.hsc($key).']" value="'.hsc($value).'" />';
|
||||
echo '</tr>';
|
||||
}
|
||||
echo '</table>';
|
||||
echo '<input type="submit" name="do[styler_plugin_preview]" value="preview">';
|
||||
echo '</form>';
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// vim:ts=4:sw=4:et:
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
/**
|
||||
* English language file for styler plugin
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
|
||||
// menu entry for admin plugins
|
||||
// $lang['menu'] = 'Your menu entry';
|
||||
|
||||
// custom language strings for the plugin
|
||||
// $lang['fixme'] = 'FIXME';
|
||||
|
||||
|
||||
|
||||
//Setup VIM: ex: et ts=4 :
|
|
@ -0,0 +1,7 @@
|
|||
base styler
|
||||
author Andreas Gohr
|
||||
email andi@splitbrain.org
|
||||
date 2015-05-16
|
||||
name styler plugin
|
||||
desc Allows to edit style.ini replacements
|
||||
url https://www.dokuwiki.org/plugin:styler
|
|
@ -0,0 +1,40 @@
|
|||
jQuery(function () {
|
||||
|
||||
|
||||
if (DokuCookie.getValue('styler_plugin') == 1) {
|
||||
|
||||
|
||||
|
||||
// load dialog
|
||||
var $dialog = jQuery(document.createElement('div'));
|
||||
jQuery('body').append($dialog);
|
||||
$dialog.load(
|
||||
DOKU_BASE + '/lib/exe/ajax.php',
|
||||
{
|
||||
'call': 'plugin_styler'
|
||||
},
|
||||
function () {
|
||||
// load the preview template
|
||||
var now = new Date().getTime();
|
||||
var $style = jQuery('link[rel=stylesheet][href*="lib/exe/css.php"]');
|
||||
$style.attr('href', DOKU_BASE + 'lib/exe/css.php?preview=1&tseed=' + now);
|
||||
|
||||
// open the dialog
|
||||
$dialog.dialog({
|
||||
'title': 'Template Variables',
|
||||
'width': 500,
|
||||
'top': 50,
|
||||
'position': { 'my': 'left top', 'at': 'left top', 'of': window },
|
||||
// bring everything back to normal
|
||||
'close': function (event, ui) {
|
||||
// disable the styler plugin again
|
||||
DokuCookie.setValue('styler_plugin', 0);
|
||||
// reload
|
||||
document.location.reload()
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue