Page MenuHomePhabricator

No OneTemporary

diff --git a/action.php b/action.php
--- a/action.php
+++ b/action.php
@@ -1,108 +1,138 @@
<?php
/**
* DokuWiki Plugin metaeditor (Action Component)
*
* @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,98 +1,82 @@
<?php
/**
* DokuWiki Plugin metaeditor (Admin Component)
*
* @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;
-
- //p_save_metadata($id, $meta);
}
- /*
- function recurseTree($var){
- //$out = '<li>';
- foreach($var as $k => $v){
- if($k == 'id')
- $out .= '<li>'.$v;
- if(is_array($v)){
- $out .= '<ul>'.$this->recurseTree($v).'</ul>';
- }
- $out .= '</li>';
- }
- return $out; //.'</li>';
- }
- */
-
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')
{
- $out .= '<li>'.$item['id'];
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() {
- //$cache = false;
- //$id = 'start';
- //$meta = p_read_metadata($id, $cache);
-
- print_r($list);
echo '<table>';
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_result"></div></td>';
- //echo '<ul>'.$this->recurseTree($meta).'</ul>';
- //echo '</div>';
- //print_r($meta);
+ 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:
diff --git a/script.js b/script.js
--- a/script.js
+++ b/script.js
@@ -1,73 +1,99 @@
/* DOKUWIKI:include_once jstree.js */
jQuery(function()
{
var selectedPageId = null;
var selectedNode = null;
+ var selectedNodeValue = null;
+
+ jQuery('#event_save').click(function() {
+ var newVal = jQuery('#event_value').val()
+ jQuery.post(
+ DOKU_BASE + 'lib/exe/ajax.php',
+ {
+ call: 'plugin_metaeditor',
+ q: 'setMetaValue',
+ r: selectedPageId,
+ k: {
+ key : selectedNode,
+ oldval : selectedNodeValue,
+ newval : newVal
+ }
+ },
+ function(data) {
+ alert(data);
+ }
+ );
+
+ });
jQuery('#metaTree').on('changed.jstree', function (e, data) {
var i, j, r;
if(data.selected.length != 1)
return;
var node = data.instance.get_node(data.selected[0]);
if(!data.instance.is_leaf(node))
return;
r = data.instance.get_path(data.selected[0]);
selectedNode = r;
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_metaeditor',
q: 'getMetaValue',
r: selectedPageId,
k: r
},
function(data) {
- jQuery('#event_result').html(data);
+ jQuery('#event_path').html(selectedNode.join(':'));
+ jQuery('#event_value').val(data);
+ selectedNodeValue = data;
}
);
})
// create the instance
.jstree({
core : {
multiple: false
- }
+ },
+ plugins: ["wholerow"]
});
jQuery('#fileTree').on('changed.jstree', function (e, data) {
var i, j, r;
if(data.selected.length != 1)
return;
var node = data.instance.get_node(data.selected[0]);
if(!data.instance.is_leaf(node))
return;
r = node.text;
selectedPageId = r;
jQuery.post(
DOKU_BASE + 'lib/exe/ajax.php',
{
call: 'plugin_metaeditor',
q: 'getMeta',
r: r
},
function(data) {
jQuery('#metaTree').jstree(true).settings.core.data = data;
jQuery('#metaTree').jstree(true).refresh();
}
);
})
// create the instance
.jstree({
core : {
multiple: false
- }
+ },
+ plugins: ["wholerow"]
});
});

File Metadata

Mime Type
text/x-diff
Expires
Wed, Dec 4, 8:51 PM (6 h, 21 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
533857
Default Alt Text
(8 KB)

Event Timeline