First
This commit is contained in:
119
syntax/div.php
Normal file
119
syntax/div.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
|
||||
* @author Francois Merciol <dokuplugin@merciol.fr>
|
||||
*
|
||||
* Plugin Glossary: manage forms for glossary
|
||||
*/
|
||||
|
||||
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');
|
||||
|
||||
require_once (dirname (__FILE__).'/../glossary.class.php');
|
||||
|
||||
// ============================================================
|
||||
class syntax_plugin_glossary_div extends DokuWiki_Syntax_Plugin {
|
||||
|
||||
// ============================================================
|
||||
function getType () { return 'substition'; }
|
||||
function getPType () { return 'block'; }
|
||||
function getAllowedTypes () { return array ('container', 'baseonly', 'formatting', 'substition', 'protected', 'disabled', 'paragraphs'); }
|
||||
function getSort () { return 309; }
|
||||
function connectTo ($mode) {
|
||||
$this->Lexer->addSpecialPattern ('\{\{glossary[^}]*\}\}', $mode, 'plugin_glossary_div');
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function handle ($match, $state, $pos, Doku_Handler $handler) {
|
||||
switch ($state) {
|
||||
case DOKU_LEXER_SPECIAL :
|
||||
return array ($state, trim (substr ($match, 10, -2))); // "{{glossary" => 10 "}}" => 2
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function render ($mode, Doku_Renderer $renderer, $indata) {
|
||||
if ($mode != 'xhtml')
|
||||
return false;
|
||||
list ($state, $data) = $indata;
|
||||
$data = " ".$data." ";
|
||||
$renderer->info ['cache'] = FALSE;
|
||||
$cmd = "";
|
||||
$arg = "";
|
||||
|
||||
if (preg_match_all ("#(\"[^\"]*\")* help (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0) {
|
||||
$this->help ($renderer);
|
||||
return true;
|
||||
}
|
||||
// namespace
|
||||
global $ID;
|
||||
$ns = getNS ($ID);
|
||||
if (preg_match_all ("#>([^ ]*) .*#", strtolower ($data), $dumy) > 0) {
|
||||
$ns = $dumy[1][0];
|
||||
if (($ns == '*') || ($ns == ':'))
|
||||
$ns = '';
|
||||
elseif ($ns == '.')
|
||||
$ns = getNS ($ID);
|
||||
else
|
||||
$ns = cleanID ($ns);
|
||||
}
|
||||
if (preg_match_all ("#(\"[^\"]*\")* sample (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0)
|
||||
$cmd = "printSample";
|
||||
elseif (preg_match_all ("#(\"[^\"]*\")* list (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0)
|
||||
$cmd = "printList";
|
||||
elseif (preg_match_all ("#(\"[^\"]*\")* poll=\"(?<word>[^\"]*)\" (\"[^\"]*\")*#", $data, $dumy) > 0) {
|
||||
$cmd = "printPoll";
|
||||
$arg = $dumy['word'][0];
|
||||
} elseif (preg_match_all ("#(\"[^\"]*\")* proposal (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0)
|
||||
$cmd = "printProposal";
|
||||
elseif (preg_match_all ("#(\"[^\"]*\")* admin-proposal (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0)
|
||||
$cmd = "adminProposal";
|
||||
elseif (preg_match_all ("#(\"[^\"]*\")* admin-definition (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0)
|
||||
$cmd = "adminDefinition";
|
||||
elseif (preg_match_all ("#(\"[^\"]*\")* admin-glossaries (\"[^\"]*\")*#", strtolower ($data), $dumy) > 0)
|
||||
$cmd = "adminGlossaries";
|
||||
else {
|
||||
$this->help ($renderer);
|
||||
return true;
|
||||
}
|
||||
|
||||
$glossary = new glossary ($this, $ns);
|
||||
ob_start ();
|
||||
$glossary->$cmd ($arg);
|
||||
$text = ob_get_contents();
|
||||
ob_end_clean ();
|
||||
foreach ($glossary->message as $type => $msg)
|
||||
$text = '<div class="'.$type.'">'.$msg.'</div>'.$text;
|
||||
$renderer->doc .= '<div class="glossary">'.$text.'</div>';
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function isAdmin () {
|
||||
global $INFO;
|
||||
return
|
||||
isset ($INFO ['userinfo']) &&
|
||||
isset ($INFO ['userinfo']['grps']) &&
|
||||
in_array (trim ($this->getConf ('adminGroup')), $INFO ['userinfo']['grps']);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function help (Doku_Renderer $renderer) {
|
||||
$url = "http://admin.parlenet.org/plugins/glossary/";
|
||||
$renderer->doc .=
|
||||
' <h1>Help Glossary</h1>'.NL.
|
||||
' <ul>'.NL.
|
||||
' <li><b>{{glossary></b>namespace [help] (sample|list|proposal|admin-proposal|admin-definition|admin-glossaries)<b>}}</b></li>'.NL.
|
||||
' <li><b><glossary</b> (help|clock|face-smile|face-sad|stop|one-way|search) <b>/></b></li>'.NL.
|
||||
' <li><b><glossary</b> (word|translate) <b>></b> ... <b></glossary></b></li>'.NL.
|
||||
' </ul>'.NL.
|
||||
' <p><a class="urlextern" rel="nofollow" title="'.$url.'" href="'.$url.'">'.$url.'</a></p>'.NL;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
} // syntax_plugin_GLOSSARY
|
||||
?>
|
131
syntax/span.php
Normal file
131
syntax/span.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
* @license http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.html
|
||||
* @author Francois Merciol <dokuplugin@merciol.fr>
|
||||
*
|
||||
* Plugin Glossary: manage forms for glossary
|
||||
*/
|
||||
|
||||
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');
|
||||
|
||||
require_once (dirname (__FILE__).'/../glossary.class.php');
|
||||
|
||||
// ============================================================
|
||||
class syntax_plugin_glossary_span extends DokuWiki_Syntax_Plugin {
|
||||
|
||||
// ============================================================
|
||||
function getType () { return 'formatting'; }
|
||||
function getPType () { return 'normal'; }
|
||||
function getAllowedTypes() { return array ('formatting', 'substition', 'disabled'); }
|
||||
function getSort () { return 195; }
|
||||
function accepts ($mode) {
|
||||
if ($mode == substr (get_class ($this), 7))
|
||||
return true;
|
||||
return parent::accepts ($mode);
|
||||
}
|
||||
|
||||
function connectTo ($mode) {
|
||||
$this->Lexer->addSpecialPattern ('<glossary[^/]*?/>', $mode, 'plugin_glossary_span');
|
||||
$this->Lexer->addEntryPattern ('<glossary[^/]*?>(?=.*?</glossary>)', $mode, 'plugin_glossary_span');
|
||||
}
|
||||
function postConnect() {
|
||||
$this->Lexer->addExitPattern ('</glossary>', 'plugin_glossary_span');
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function handle ($match, $state, $pos, Doku_Handler $handler) {
|
||||
switch ($state) {
|
||||
case DOKU_LEXER_SPECIAL :
|
||||
$data = strtolower (trim (substr ($match, 9, -2)));
|
||||
return array ($state, $data);
|
||||
case DOKU_LEXER_ENTER:
|
||||
$data = strtolower (trim (substr ($match, 9, -1)));
|
||||
return array ($state, $data);
|
||||
|
||||
case DOKU_LEXER_UNMATCHED :
|
||||
$handler->_addCall ('cdata', array ($match), $pos);
|
||||
return false;
|
||||
|
||||
case DOKU_LEXER_EXIT :
|
||||
return array ($state, '');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
function render ($mode, Doku_Renderer $renderer, $indata) {
|
||||
if (empty ($indata))
|
||||
return false;
|
||||
if ($mode != 'xhtml')
|
||||
false;
|
||||
list ($state, $data) = $indata;
|
||||
$data = trim ($data);
|
||||
switch ($state) {
|
||||
case DOKU_LEXER_SPECIAL :
|
||||
$imgDir = DOKU_REL.'lib/plugins/glossary/images/';
|
||||
if ($data == "help")
|
||||
$renderer->doc .= '<img src="'.$imgDir.'help.png" />';
|
||||
elseif ($data == "clock")
|
||||
$renderer->doc .= '<img src="'.$imgDir.'clock.png" />';
|
||||
elseif ($data == "face-smile")
|
||||
$renderer->doc .= '<img src="'.$imgDir.'face-smile.png" />';
|
||||
elseif ($data == "face-sad")
|
||||
$renderer->doc .= '<img src="'.$imgDir.'face-sad.png" />';
|
||||
elseif ($data == "stop")
|
||||
$renderer->doc .= '<img src="'.$imgDir.'stop.png" />';
|
||||
elseif ($data == "one-way")
|
||||
$renderer->doc .= '<img src="'.$imgDir.'one-way.png" />';
|
||||
elseif ($data == "eye")
|
||||
$renderer->doc .= '<img src="'.$imgDir.'eye.png" />';
|
||||
elseif ($data == "score")
|
||||
$renderer->doc .= '<img src="'.$imgDir.'score-all.png" width="32" />';
|
||||
elseif ($data == "search")
|
||||
$renderer->doc .= '<img src="'.$imgDir.'search.png" />';
|
||||
elseif (preg_match_all ("#(?<ns>.*)\s+(?<type>definition|proposal|poll)#", $data, $dumy) > 0) {
|
||||
global $ID;
|
||||
$ns = getNS ($ID);
|
||||
if (count ($dumy ['ns']) > 0) {
|
||||
$ns = $dumy['ns'][0];
|
||||
if (($ns == '*') || ($ns == ':'))
|
||||
$ns = '';
|
||||
elseif ($ns == '.')
|
||||
$ns = getNS ($ID);
|
||||
else
|
||||
$ns = cleanID ($ns);
|
||||
}
|
||||
$glossary = new glossary ($this, $ns);
|
||||
switch ($dumy['type'][0]) {
|
||||
case "definition":
|
||||
$renderer->doc .= $glossary->getDefinitionSize ();
|
||||
break;
|
||||
case "proposal":
|
||||
$renderer->doc .= $glossary->getProposalSize ();
|
||||
break;
|
||||
case "poll":
|
||||
$renderer->doc .= $glossary->getPollSize ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DOKU_LEXER_ENTER:
|
||||
if ($data == "word")
|
||||
$renderer->doc .= '<span class="glossaryWord">';
|
||||
elseif ($data == "translate")
|
||||
$renderer->doc .= '<span class="glossaryTranslate">';
|
||||
else
|
||||
$renderer->doc .= '<span>';
|
||||
break;
|
||||
case DOKU_LEXER_EXIT:
|
||||
$renderer->doc .= "</span>";
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
} // syntax_plugin_GLOSSARY
|
||||
?>
|
Reference in New Issue
Block a user