Commit 50b6955c authored by Pietro Saccardi's avatar Pietro Saccardi

Added basic skeleton for a DokuWiki plugin

parent 30949d59
This diff is collapsed.
ifauthex Plugin for DokuWiki
Toggles content depending on user and user groups.
All documentation for this plugin can be found at
https://git.mittelab.org/proj/ifauthex-dokuwiki-plugin
If you install this plugin manually, make sure it is installed in
lib/plugins/ifauthex/ - 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) Pietro Saccardi <lizardm4@gmail.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 LICENSING file for details
<?php
/**
* General tests for the ifauthex plugin
*
* @group plugin_ifauthex
* @group plugins
*/
class general_plugin_ifauthex_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('ifauthex', $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']));
}
/**
* Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
* conf/metadata.php.
*/
public function test_plugin_conf()
{
$conf_file = __DIR__ . '/../conf/default.php';
if (file_exists($conf_file)) {
include($conf_file);
}
$meta_file = __DIR__ . '/../conf/metadata.php';
if (file_exists($meta_file)) {
include($meta_file);
}
$this->assertEquals(
gettype($conf),
gettype($meta),
'Both ' . DOKU_PLUGIN . 'ifauthex/conf/default.php and ' . DOKU_PLUGIN . 'ifauthex/conf/metadata.php have to exist and contain the same keys.'
);
if (gettype($conf) != 'NULL' && gettype($meta) != 'NULL') {
foreach ($conf as $key => $value) {
$this->assertArrayHasKey(
$key,
$meta,
'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'ifauthex/conf/metadata.php'
);
}
foreach ($meta as $key => $value) {
$this->assertArrayHasKey(
$key,
$conf,
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'ifauthex/conf/default.php'
);
}
}
}
}
base ifauthex
author Pietro Saccardi
email lizardm4@gmail.com
date 2019-01-09
name ifauthex plugin
desc Toggles content depending on user and user groups.
url https://git.mittelab.org/proj/ifauthex-dokuwiki-plugin
<?php
/**
* DokuWiki Plugin ifauthex (Syntax Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Pietro Saccardi <lizardm4@gmail.com>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) {
die();
}
require_once('grammar.php');
class syntax_plugin_ifauthex extends DokuWiki_Syntax_Plugin
{
/**
* @return string Syntax mode type
*/
public function getType()
{
return 'substition';
}
/**
* @return string Paragraph type
*/
public function getPType()
{
return 'normal';
}
/**
* @return int Sort order - Low numbers go before high numbers
*/
public function getSort()
{
return 350;
}
/**
* Connect lookup pattern to lexer.
*
* @param string $mode Parser mode
*/
public function connectTo($mode)
{
$this->Lexer->addSpecialPattern('<FIXME>', $mode, 'plugin_ifauthex_ifauthex');
// $this->Lexer->addEntryPattern('<FIXME>', $mode, 'plugin_ifauthex_ifauthex');
}
// public function postConnect()
// {
// $this->Lexer->addExitPattern('</FIXME>', 'plugin_ifauthex_ifauthex');
// }
/**
* Handle matches of the ifauthex syntax
*
* @param string $match The match of the syntax
* @param int $state The state of the handler
* @param int $pos The position in the document
* @param Doku_Handler $handler The handler
*
* @return array Data for the renderer
*/
public function handle($match, $state, $pos, Doku_Handler $handler)
{
$data = array();
return $data;
}
/**
* Render xhtml output or metadata
*
* @param string $mode Renderer mode (supported modes: xhtml)
* @param Doku_Renderer $renderer The renderer
* @param array $data The data from the handler() function
*
* @return bool If rendering was successful.
*/
public function render($mode, Doku_Renderer $renderer, $data)
{
if ($mode !== 'xhtml') {
return false;
}
return true;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment