Page MenuHomePhabricator

No OneTemporary

diff --git a/action.php b/action.php
--- a/action.php
+++ b/action.php
@@ -1,138 +1,140 @@
<?php
/**
* DokuWiki Plugin metaeditor (Action Component)
*
+ * Simple Meta Data Editor, heavily AJAX/jQuery based.
+ *
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Böhler <dev@aboehler.at>
*/
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
class action_plugin_metaeditor extends DokuWiki_Action_Plugin {
// Load the helper plugin
public function action_plugin_metaeditor() {
}
// Register our hooks
function register(&$controller) {
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'handle_ajax_call_unknown');
}
function handle_ajax_call_unknown($event, $param) {
if($event->data != 'plugin_metaeditor') return;
$event->preventDefault();
$event->stopPropagation();
global $INPUT;
//global $auth; // FIXME: Add auth check for admin user here
$action = trim($INPUT->post->str('q'));
$pageid = trim($INPUT->post->str('r'));
$key = $INPUT->post->arr('k');
$data = array();
$json = false;
switch($action)
{
case 'getMeta':
$data = $this->getMetaForPage($pageid);
$json = true;
break;
case 'getMetaValue':
$data = $this->getMetaValueForPage($pageid, $key);
break;
case 'setMetaValue':
$oldval = $key['oldval'];
$newval = $key['newval'];
$key = $key['key'];
$data = $this->setMetaValueForPage($pageid, $key, $oldval, $newval);
breka;
}
//$data = $_SERVER['REMOTE_USER'];
if($json)
{
//json library of DokuWiki
require_once DOKU_INC . 'inc/JSON.php';
$json = new JSON();
//set content type
header('Content-Type: application/json');
echo $json->encode($data);
}
else
{
echo $data;
}
}
function setMetaValueForPage($pageid, $key, $oldval, $newval)
{
$cache = false;
$meta = p_read_metadata($pageid, $cache);
$m = &$meta;
foreach($key as $k)
$m = &$m[$k];
if($m == $oldval)
{
$m = $newval;
if(p_save_metadata($pageid, $meta))
return "Successfully saved: $newval";
else
return "Error saving value: $newval";
}
else
{
return "Key has changed in the meantime, expected $oldval but got $m. Nothing was saved!";
}
}
function parseMetaTree($meta)
{
$out = array();
foreach($meta as $k => $v)
{
$a = array();
$a['text'] = $k;
if(is_array($v))
{
$a['children'] = $this->parseMetaTree($v);
}
else
$a['icon'] = DOKU_URL."/lib/images/page.png";
$out[] = $a;
}
return $out;
}
function getMetaForPage($pageid)
{
$cache = false;
$meta = p_read_metadata($pageid, $cache);
$out = $this->parseMetaTree($meta);
return $out;
}
function getMetaValueForPage($pageid, $key)
{
$cache = false;
$meta = p_read_metadata($pageid, $cache);
foreach($key as $k)
{
$meta = $meta[$k];
}
return $meta;
}
}
diff --git a/admin/editor.php b/admin/editor.php
--- a/admin/editor.php
+++ b/admin/editor.php
@@ -1,82 +1,85 @@
<?php
/**
* DokuWiki Plugin metaeditor (Admin Component)
*
+ * Simple Meta Data Editor, heavily AJAX/jQuery based.
+ *
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Andreas Gohr <gohr@cosmocode.de>
*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
require_once(DOKU_PLUGIN.'admin.php');
class admin_plugin_metaeditor_editor extends DokuWiki_Admin_Plugin {
/**
* Constructor. Load helper plugin
*/
function admin_plugin_metaeditor_editor(){
}
function getMenuSort() { return 501; }
function forAdminOnly() { return true; }
function getMenuText($language) {
return "Simple Persistent Meta Data Editor";
}
function handle() {
if(!is_array($_REQUEST['d']) || !checkSecurityToken()) return;
}
function recurseTree($ns) {
global $conf;
$out = '';
$list = array();
$opts = array(
'depth' => 1,
'listfiles' => true,
'listdirs' => true,
'pagesonly' => true,
'firsthead' => true,
'sneakyacl' => $conf['sneaky_index'],
);
search($list,$conf['datadir'],'search_universal',$opts,$ns);
foreach($list as $item)
{
if($item['type'] == 'f' || $item['type'] == 'd')
{
if($item['type'] == 'd')
{
$out .= '<li>'.$item['id'];
$out .= '<ul>'.$this->recurseTree(str_replace(':', '/', $item['id'])).'</ul>';
}
else
{
$out .= '<li data-jstree=\'{"icon":"'.DOKU_URL.'/lib/images/page.png"}\'>'.$item['id'];
}
$out .= '</li>';
}
}
return $out;
}
function html() {
-
+ echo '<h1>Meta Data Editor</h1>';
echo '<table>';
+ echo '<tr><th width="30\%">Page</th><th width="30\%">Meta Data</th><th width="30\%">Value</th></tr>';
echo '<tr>';
echo '<td><div id="fileTree">';
echo '<ul>'.$this->recurseTree('/').'</ul>';
echo '</div></td>';
echo '<td><div id="metaTree"></div></td>';
echo '<td><div id="event_path"></div><br><div id="event_result">';
echo '<input type="text" id="event_value" value="..."><br>';
echo '<input type="submit" id="event_save" value="Save">';
echo '</div></td>';
}
}
// vim:ts=4:sw=4:et:enc=utf-8:

File Metadata

Mime Type
text/x-diff
Expires
Wed, Dec 25, 12:47 PM (1 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
533945
Default Alt Text
(5 KB)

Event Timeline