[go: nahoru, domu]

Skip to content

Commit

Permalink
removed global functions, reformatting
Browse files Browse the repository at this point in the history
brobably broken in current state
  • Loading branch information
splitbrain committed Feb 10, 2011
1 parent fc66a0a commit f576111
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 206 deletions.
49 changes: 30 additions & 19 deletions action.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<?php
/**
* DokuWiki Plugin publish (Action Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Jarrod Lowe <dokuwiki@rrod.net>
* @author Andreas Gohr <gohr@cosmocode.de>
*/

// TODO:
// Old Revisions Display X
Expand All @@ -16,15 +23,12 @@
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
require_once(DOKU_PLUGIN.'publish/shared.php');



class action_plugin_publish extends DokuWiki_Action_Plugin {
private $hlp;

function getInfo() { return publish_getInfo(); }
function action_plugin_publish(){
$this->hlp = plugin_load('helper','publish'); // load helper plugin
}

function register(&$controller) {
$controller->register_hook('HTML_EDITFORM_OUTPUT', 'BEFORE', $this, handle_html_editform_output, array());
Expand All @@ -38,12 +42,17 @@ function register(&$controller) {

function handle_html_editform_output(&$event, $param) {
global $ID;
if(!in_namespace($this->getConf('apr_namespaces'), $ID)) { return; }
global $INFO;
if($INFO['perm'] < AUTH_DELETE) { return; }
#$html = '<input type=checkbox name=approve> Approve</input>';

if(!$this->hlp->in_namespace($this->getConf('apr_namespaces'), $ID)) {
return;
}
if($INFO['perm'] < AUTH_DELETE) {
return;
}

$html = '<label class="nowrap" for="approved"><input type="checkbox" id="approved" name="approved" value="1" tabindex=3 return approval_checkbox(\'' . $this->getConf('apr_approved_text') . '\'); }"/> <span>' . $this->getLang('apr_do_approve') . '</span></label>';
$event->data->insertElement(12,$html);
$event->data->insertElement(12,$html); //FIXME hardcoded element position
}

function debug(&$event, $param) {
Expand All @@ -63,7 +72,7 @@ function handle_io_write(&$event, $param) {
global $ACT;
global $USERINFO;
global $INFO;
if(!in_namespace($this->getConf('apr_namespaces'), $ID)) { return; }
if(!$this->hlp->in_namespace($this->getConf('apr_namespaces'), $ID)) { return; }
if($INFO['perm'] < AUTH_DELETE) { return true; }
if($ACT != 'save') { return true; }
if(!$event->data[3]) { return true; } # don't approve the doc being moved to archive
Expand All @@ -78,11 +87,13 @@ function handle_io_write(&$event, $param) {
}

function handle_display_banner(&$event, $param) {
$strings = array();
global $ID;
if(!in_namespace($this->getConf('apr_namespaces'), $ID)) { return; }
global $REV;

if(!$this->hlp->in_namespace($this->getConf('apr_namespaces'), $ID)) { return; }
if($event->data != 'show') { return true; }

$strings = array();
$meta = p_get_metadata($ID);
$rev = $REV;
if(!$rev) { $rev = $meta['last_change']['date']; }
Expand All @@ -94,7 +105,6 @@ function handle_display_banner(&$event, $param) {

$longdate = date('d/m/y H:i', $rev);


# Is this document approved?
$approver = null;
$date = null;
Expand All @@ -104,7 +114,8 @@ function handle_display_banner(&$event, $param) {
$approver = $meta['approval'][$rev][1];
if(!$approver) { $approver = $meta['approval'][$rev][2]; }
if(!$approver) { $approver = $meta['approval'][$rev][0]; }
$approver = '<a href="mailto:' .
//FIXME use correct user function here
$approver = '<a href="mailto:' .
$meta['approval'][$rev][2] .
'">' .
$approver .
Expand All @@ -124,7 +135,7 @@ function handle_display_banner(&$event, $param) {
$most_recent_approved = $allapproved[$id];
}
}

# Latest, if draft
$most_recent_draft = null;
#$strings[] = '<!-- lr='.$latest_rev.', r='.$rev.', mra='.$most_recently_approved.', d='.($latest_rev != $rev).','.($latest_rev != $most_recently_approved).' -->';
Expand Down Expand Up @@ -161,7 +172,7 @@ function handle_display_banner(&$event, $param) {
if(!$approver) {
# Draft
$strings[] = '<span class="approval_draft">';
$strings[] = sprintf($this->getLang('apr_draft'),
$strings[] = sprintf($this->getLang('apr_draft'),
'<span class="approval_date">' . $longdate . '</span>');
$strings[] = '</span>';
}
Expand Down Expand Up @@ -191,8 +202,8 @@ function handle_display_banner(&$event, $param) {

function handle_revisions(&$event, $param) {
global $ID;
if(!in_namespace($this->getConf('apr_namespaces'), $ID)) { return; }
global $REV;
if(!$this->hlp->in_namespace($this->getConf('apr_namespaces'), $ID)) { return; }
$meta = p_get_metadata($ID);
$latest_rev = $meta['last_change']['date'];

Expand Down
78 changes: 78 additions & 0 deletions helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* DokuWiki Plugin publish (Helper Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Jarrod Lowe <dokuwiki@rrod.net>
* @author Andreas Gohr <gohr@cosmocode.de>
*/

// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();

class helper_plugin_publish extends DokuWiki_Plugin {

// FIXME find out what this is supposed to do and how it can be done better
function in_namespace($valid, $check) {
// PHP apparantly does not have closures -
// so we will parse $valid ourselves. Wasteful.
$valid = preg_split('/\s+/', $valid);
//if(count($valid) == 0) { return true; }//whole wiki matches
if((count($valid)==1) and ($valid[0]=="")) { return true; }//whole wiki matches
$check = trim($check, ':');
$check = explode(':', $check);

// Check against all possible namespaces
foreach($valid as $v) {
$v = explode(':', $v);
$n = 0;
$c = count($v);
$matching = 1;

// Check each element, untill all elements of $v satisfied
while($n < $c) {
if($v[$n] != $check[$n]) {
// not a match
$matching = 0;
break;
}
$n += 1;
}
if($matching == 1) { return true; } // a match
}
return false;
}

// FIXME find out what this is supposed to do and how it can be done better
function in_sub_namespace($valid, $check) {
// is check a dir which contains any valid?
// PHP apparantly does not have closures -
// so we will parse $valid ourselves. Wasteful.
$valid = preg_split('/\s+/', $valid);
//if(count($valid) == 0) { return true; }//whole wiki matches
if((count($valid)==1) and ($valid[0]=="")) { return true; }//whole wiki matches
$check = trim($check, ':');
$check = explode(':', $check);

// Check against all possible namespaces
foreach($valid as $v) {
$v = explode(':', $v);
$n = 0;
$c = count($check); //this is what is different from above!
$matching = 1;

// Check each element, untill all elements of $v satisfied
while($n < $c) {
if($v[$n] != $check[$n]) {
// not a match
$matching = 0;
break;
}
$n += 1;
}
if($matching == 1) { return true; } // a match
}
return false;
}

}
69 changes: 0 additions & 69 deletions shared.php

This file was deleted.

Loading

0 comments on commit f576111

Please sign in to comment.