PSR-2 for extension plugin
This commit is contained in:
parent
d0a7b199d1
commit
18b1e90a59
|
@ -6,8 +6,8 @@
|
|||
* makes protected methods accessible
|
||||
*/
|
||||
class mock_helper_plugin_extension_extension extends helper_plugin_extension_extension {
|
||||
public function find_folders(&$result, $base, $default_type = 'plugin', $dir = '') {
|
||||
return parent::find_folders($result, $base, $default_type, $dir);
|
||||
public function findFolders(&$result, $base, $default_type = 'plugin', $dir = '') {
|
||||
return parent::findFolders($result, $base, $default_type, $dir);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$tdir = dirname(__FILE__).'/testdata';
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/plugin1", 'plugin');
|
||||
$ok = $extension->findFolders($result, "$tdir/plugin1", 'plugin');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -86,7 +86,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('plugin1', $this->extdir($result['old'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/plugin2", 'plugin');
|
||||
$ok = $extension->findFolders($result, "$tdir/plugin2", 'plugin');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('plugin', $result['new'][0]['type']);
|
||||
|
@ -94,7 +94,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('plugin2', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/plgsub3", 'plugin');
|
||||
$ok = $extension->findFolders($result, "$tdir/plgsub3", 'plugin');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -102,7 +102,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('plgsub3/plugin3', $this->extdir($result['old'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/plgsub4", 'plugin');
|
||||
$ok = $extension->findFolders($result, "$tdir/plgsub4", 'plugin');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('plugin', $result['new'][0]['type']);
|
||||
|
@ -110,7 +110,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('plgsub4/plugin4', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/plgfoo5", 'plugin');
|
||||
$ok = $extension->findFolders($result, "$tdir/plgfoo5", 'plugin');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('plugin', $result['new'][0]['type']);
|
||||
|
@ -118,7 +118,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('plgfoo5', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/plgsub6/plgfoo6", 'plugin');
|
||||
$ok = $extension->findFolders($result, "$tdir/plgsub6/plgfoo6", 'plugin');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('plugin', $result['new'][0]['type']);
|
||||
|
@ -126,7 +126,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('plgsub6/plgfoo6', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/either1", 'plugin');
|
||||
$ok = $extension->findFolders($result, "$tdir/either1", 'plugin');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -134,7 +134,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('either1', $this->extdir($result['old'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/eithersub2/either2", 'plugin');
|
||||
$ok = $extension->findFolders($result, "$tdir/eithersub2/either2", 'plugin');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -147,7 +147,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$tdir = dirname(__FILE__).'/testdata';
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/template1", 'template');
|
||||
$ok = $extension->findFolders($result, "$tdir/template1", 'template');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -155,7 +155,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('template1', $this->extdir($result['old'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/template2", 'template');
|
||||
$ok = $extension->findFolders($result, "$tdir/template2", 'template');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('template', $result['new'][0]['type']);
|
||||
|
@ -163,7 +163,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('template2', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/tplsub3", 'template');
|
||||
$ok = $extension->findFolders($result, "$tdir/tplsub3", 'template');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -171,7 +171,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('tplsub3/template3', $this->extdir($result['old'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/tplsub4", 'template');
|
||||
$ok = $extension->findFolders($result, "$tdir/tplsub4", 'template');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('template', $result['new'][0]['type']);
|
||||
|
@ -179,7 +179,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('tplsub4/template4', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/tplfoo5", 'template');
|
||||
$ok = $extension->findFolders($result, "$tdir/tplfoo5", 'template');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('template', $result['new'][0]['type']);
|
||||
|
@ -187,7 +187,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('tplfoo5', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/tplsub6/tplfoo6", 'template');
|
||||
$ok = $extension->findFolders($result, "$tdir/tplsub6/tplfoo6", 'template');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('template', $result['new'][0]['type']);
|
||||
|
@ -195,7 +195,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('tplsub6/tplfoo6', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/either1", 'template');
|
||||
$ok = $extension->findFolders($result, "$tdir/either1", 'template');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -203,7 +203,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('either1', $this->extdir($result['old'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/eithersub2/either2", 'template');
|
||||
$ok = $extension->findFolders($result, "$tdir/eithersub2/either2", 'template');
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -216,7 +216,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$tdir = dirname(__FILE__).'/testdata';
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/template1");
|
||||
$ok = $extension->findFolders($result, "$tdir/template1");
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -224,7 +224,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('template1', $this->extdir($result['old'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/template2");
|
||||
$ok = $extension->findFolders($result, "$tdir/template2");
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('template', $result['new'][0]['type']);
|
||||
|
@ -232,7 +232,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('template2', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/tplsub3");
|
||||
$ok = $extension->findFolders($result, "$tdir/tplsub3");
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -240,7 +240,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('tplsub3/template3', $this->extdir($result['old'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/tplsub4");
|
||||
$ok = $extension->findFolders($result, "$tdir/tplsub4");
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('template', $result['new'][0]['type']);
|
||||
|
@ -248,7 +248,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('tplsub4/template4', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/tplfoo5");
|
||||
$ok = $extension->findFolders($result, "$tdir/tplfoo5");
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('template', $result['new'][0]['type']);
|
||||
|
@ -256,7 +256,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('tplfoo5', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/tplsub6/tplfoo6");
|
||||
$ok = $extension->findFolders($result, "$tdir/tplsub6/tplfoo6");
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(1, count($result['new']));
|
||||
$this->assertEquals('template', $result['new'][0]['type']);
|
||||
|
@ -264,7 +264,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('tplsub6/tplfoo6', $this->extdir($result['new'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/either1");
|
||||
$ok = $extension->findFolders($result, "$tdir/either1");
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -272,7 +272,7 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$this->assertEquals('either1', $this->extdir($result['old'][0]['tmp']));
|
||||
|
||||
$result = array('old' => array(), 'new' => array());
|
||||
$ok = $extension->find_folders($result, "$tdir/eithersub2/either2");
|
||||
$ok = $extension->findFolders($result, "$tdir/eithersub2/either2");
|
||||
$this->assertTrue($ok);
|
||||
$this->assertEquals(0, count($result['new']));
|
||||
$this->assertEquals(1, count($result['old']));
|
||||
|
@ -292,4 +292,4 @@ class helper_plugin_extension_extension_test extends DokuWikiTest {
|
|||
$dir = trim(substr($dir, $len), '/');
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
|
||||
class action_plugin_extension extends DokuWiki_Action_Plugin {
|
||||
class action_plugin_extension extends DokuWiki_Action_Plugin
|
||||
{
|
||||
|
||||
/**
|
||||
* Registers a callback function for a given event
|
||||
|
@ -13,10 +14,10 @@ class action_plugin_extension extends DokuWiki_Action_Plugin {
|
|||
* @param Doku_Event_Handler $controller DokuWiki's event controller object
|
||||
* @return void
|
||||
*/
|
||||
public function register(Doku_Event_Handler $controller) {
|
||||
public function register(Doku_Event_Handler $controller)
|
||||
{
|
||||
|
||||
$controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'info');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,22 +26,23 @@ class action_plugin_extension extends DokuWiki_Action_Plugin {
|
|||
* @param Doku_Event $event
|
||||
* @param $param
|
||||
*/
|
||||
public function info(Doku_Event &$event, $param) {
|
||||
public function info(Doku_Event &$event, $param)
|
||||
{
|
||||
global $USERINFO;
|
||||
global $INPUT;
|
||||
|
||||
if($event->data != 'plugin_extension') return;
|
||||
if ($event->data != 'plugin_extension') return;
|
||||
$event->preventDefault();
|
||||
$event->stopPropagation();
|
||||
|
||||
if(empty($_SERVER['REMOTE_USER']) || !auth_isadmin($_SERVER['REMOTE_USER'], $USERINFO['grps'])) {
|
||||
if (empty($_SERVER['REMOTE_USER']) || !auth_isadmin($_SERVER['REMOTE_USER'], $USERINFO['grps'])) {
|
||||
http_status(403);
|
||||
echo 'Forbidden';
|
||||
exit;
|
||||
}
|
||||
|
||||
$ext = $INPUT->str('ext');
|
||||
if(!$ext) {
|
||||
if (!$ext) {
|
||||
http_status(400);
|
||||
echo 'no extension given';
|
||||
return;
|
||||
|
@ -51,7 +53,7 @@ class action_plugin_extension extends DokuWiki_Action_Plugin {
|
|||
$extension->setExtension($ext);
|
||||
|
||||
$act = $INPUT->str('act');
|
||||
switch($act) {
|
||||
switch ($act) {
|
||||
case 'enable':
|
||||
case 'disable':
|
||||
$json = new JSON();
|
||||
|
@ -74,9 +76,7 @@ class action_plugin_extension extends DokuWiki_Action_Plugin {
|
|||
/** @var helper_plugin_extension_list $list */
|
||||
$list = plugin_load('helper', 'extension_list');
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
echo $list->make_info($extension);
|
||||
echo $list->makeInfo($extension);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
/**
|
||||
* Admin part of the extension manager
|
||||
*/
|
||||
class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
||||
class admin_plugin_extension extends DokuWiki_Admin_Plugin
|
||||
{
|
||||
protected $infoFor = null;
|
||||
/** @var helper_plugin_extension_gui */
|
||||
protected $gui;
|
||||
|
@ -19,39 +20,43 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
*
|
||||
* loads additional helpers
|
||||
*/
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$this->gui = plugin_load('helper', 'extension_gui');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int sort number in admin menu
|
||||
*/
|
||||
public function getMenuSort() {
|
||||
public function getMenuSort()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool true if only access for superuser, false is for superusers and moderators
|
||||
*/
|
||||
public function forAdminOnly() {
|
||||
public function forAdminOnly()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the requested action(s) and initialize the plugin repository
|
||||
*/
|
||||
public function handle() {
|
||||
public function handle()
|
||||
{
|
||||
global $INPUT;
|
||||
// initialize the remote repository
|
||||
/* @var helper_plugin_extension_repository $repository */
|
||||
$repository = $this->loadHelper('extension_repository');
|
||||
|
||||
if(!$repository->hasAccess()) {
|
||||
if (!$repository->hasAccess()) {
|
||||
$url = $this->gui->tabURL('', array('purge' => 1));
|
||||
msg($this->getLang('repo_error').' [<a href="'.$url.'">'.$this->getLang('repo_retry').'</a>]', -1);
|
||||
}
|
||||
|
||||
if(!in_array('ssl', stream_get_transports())) {
|
||||
if (!in_array('ssl', stream_get_transports())) {
|
||||
msg($this->getLang('nossl'), -1);
|
||||
}
|
||||
|
||||
|
@ -59,17 +64,17 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
$extension = $this->loadHelper('extension_extension');
|
||||
|
||||
try {
|
||||
if($INPUT->post->has('fn') && checkSecurityToken()) {
|
||||
if ($INPUT->post->has('fn') && checkSecurityToken()) {
|
||||
$actions = $INPUT->post->arr('fn');
|
||||
foreach($actions as $action => $extensions) {
|
||||
foreach($extensions as $extname => $label) {
|
||||
switch($action) {
|
||||
foreach ($actions as $action => $extensions) {
|
||||
foreach ($extensions as $extname => $label) {
|
||||
switch ($action) {
|
||||
case 'install':
|
||||
case 'reinstall':
|
||||
case 'update':
|
||||
$extension->setExtension($extname);
|
||||
$installed = $extension->installOrUpdate();
|
||||
foreach($installed as $ext => $info) {
|
||||
foreach ($installed as $ext => $info) {
|
||||
msg(
|
||||
sprintf(
|
||||
$this->getLang('msg_' . $info['type'] . '_' . $info['action'] . '_success'),
|
||||
|
@ -82,7 +87,7 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
case 'uninstall':
|
||||
$extension->setExtension($extname);
|
||||
$status = $extension->uninstall();
|
||||
if($status) {
|
||||
if ($status) {
|
||||
msg(
|
||||
sprintf(
|
||||
$this->getLang('msg_delete_success'),
|
||||
|
@ -100,19 +105,19 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
);
|
||||
}
|
||||
break;
|
||||
case 'enable';
|
||||
case 'enable':
|
||||
$extension->setExtension($extname);
|
||||
$status = $extension->enable();
|
||||
if($status !== true) {
|
||||
if ($status !== true) {
|
||||
msg($status, -1);
|
||||
} else {
|
||||
msg(sprintf($this->getLang('msg_enabled'), hsc($extension->getDisplayName())), 1);
|
||||
}
|
||||
break;
|
||||
case 'disable';
|
||||
case 'disable':
|
||||
$extension->setExtension($extname);
|
||||
$status = $extension->disable();
|
||||
if($status !== true) {
|
||||
if ($status !== true) {
|
||||
msg($status, -1);
|
||||
} else {
|
||||
msg(sprintf($this->getLang('msg_disabled'), hsc($extension->getDisplayName())), 1);
|
||||
|
@ -122,37 +127,36 @@ class admin_plugin_extension extends DokuWiki_Admin_Plugin {
|
|||
}
|
||||
}
|
||||
send_redirect($this->gui->tabURL('', array(), '&', true));
|
||||
} elseif($INPUT->post->str('installurl') && checkSecurityToken()) {
|
||||
} elseif ($INPUT->post->str('installurl') && checkSecurityToken()) {
|
||||
$installed = $extension->installFromURL($INPUT->post->str('installurl'));
|
||||
foreach($installed as $ext => $info) {
|
||||
foreach ($installed as $ext => $info) {
|
||||
msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1);
|
||||
}
|
||||
send_redirect($this->gui->tabURL('', array(), '&', true));
|
||||
} elseif(isset($_FILES['installfile']) && checkSecurityToken()) {
|
||||
} elseif (isset($_FILES['installfile']) && checkSecurityToken()) {
|
||||
$installed = $extension->installFromUpload('installfile');
|
||||
foreach($installed as $ext => $info) {
|
||||
foreach ($installed as $ext => $info) {
|
||||
msg(sprintf($this->getLang('msg_'.$info['type'].'_'.$info['action'].'_success'), $info['base']), 1);
|
||||
}
|
||||
send_redirect($this->gui->tabURL('', array(), '&', true));
|
||||
}
|
||||
|
||||
} catch(Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
msg($e->getMessage(), -1);
|
||||
send_redirect($this->gui->tabURL('', array(), '&', true));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Render HTML output
|
||||
*/
|
||||
public function html() {
|
||||
public function html()
|
||||
{
|
||||
ptln('<h1>'.$this->getLang('menu').'</h1>');
|
||||
ptln('<div id="extension__manager">');
|
||||
|
||||
$this->gui->tabNavigation();
|
||||
|
||||
switch($this->gui->currentTab()) {
|
||||
switch ($this->gui->currentTab()) {
|
||||
case 'search':
|
||||
$this->gui->tabSearch();
|
||||
break;
|
||||
|
|
|
@ -6,12 +6,11 @@
|
|||
* @author Michael Hamann <michael@content-space.de>
|
||||
*/
|
||||
|
||||
if(!defined('DOKU_TPLLIB')) define('DOKU_TPLLIB', DOKU_INC.'lib/tpl/');
|
||||
|
||||
/**
|
||||
* Class helper_plugin_extension_extension represents a single extension (plugin or template)
|
||||
*/
|
||||
class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
||||
class helper_plugin_extension_extension extends DokuWiki_Plugin
|
||||
{
|
||||
private $id;
|
||||
private $base;
|
||||
private $is_template = false;
|
||||
|
@ -24,13 +23,25 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
/** @var array list of temporary directories */
|
||||
private $temporary = array();
|
||||
|
||||
/** @var string where templates are installed to */
|
||||
private $tpllib = '';
|
||||
|
||||
/**
|
||||
* helper_plugin_extension_extension constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->tpllib = dirname(tpl_incdir()).'/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* deletes any dangling temporary directories
|
||||
*/
|
||||
public function __destruct() {
|
||||
foreach($this->temporary as $dir){
|
||||
public function __destruct()
|
||||
{
|
||||
foreach ($this->temporary as $dir) {
|
||||
io_rmdir($dir, true);
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +49,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
/**
|
||||
* @return bool false, this component is not a singleton
|
||||
*/
|
||||
public function isSingleton() {
|
||||
public function isSingleton()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -48,12 +60,13 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @param string $id The id of the extension (prefixed with template: for templates)
|
||||
* @return bool If some (local or remote) data was found
|
||||
*/
|
||||
public function setExtension($id) {
|
||||
public function setExtension($id)
|
||||
{
|
||||
$id = cleanID($id);
|
||||
$this->id = $id;
|
||||
$this->base = $id;
|
||||
|
||||
if(substr($id, 0 , 9) == 'template:'){
|
||||
if (substr($id, 0, 9) == 'template:') {
|
||||
$this->base = substr($id, 9);
|
||||
$this->is_template = true;
|
||||
} else {
|
||||
|
@ -83,7 +96,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool If the extension is installed locally
|
||||
*/
|
||||
public function isInstalled() {
|
||||
public function isInstalled()
|
||||
{
|
||||
return is_dir($this->getInstallDir());
|
||||
}
|
||||
|
||||
|
@ -92,8 +106,9 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isGitControlled() {
|
||||
if(!$this->isInstalled()) return false;
|
||||
public function isGitControlled()
|
||||
{
|
||||
if (!$this->isInstalled()) return false;
|
||||
return is_dir($this->getInstallDir().'/.git');
|
||||
}
|
||||
|
||||
|
@ -102,10 +117,12 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool If the extension is bundled
|
||||
*/
|
||||
public function isBundled() {
|
||||
public function isBundled()
|
||||
{
|
||||
if (!empty($this->remoteInfo['bundled'])) return $this->remoteInfo['bundled'];
|
||||
return in_array($this->id,
|
||||
array(
|
||||
return in_array(
|
||||
$this->id,
|
||||
array(
|
||||
'authad', 'authldap', 'authmysql', 'authpdo',
|
||||
'authpgsql', 'authplain', 'acl', 'info', 'extension',
|
||||
'revert', 'popularity', 'config', 'safefnrecode', 'styling',
|
||||
|
@ -119,7 +136,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool if the extension is protected
|
||||
*/
|
||||
public function isProtected() {
|
||||
public function isProtected()
|
||||
{
|
||||
// never allow deinstalling the current auth plugin:
|
||||
global $conf;
|
||||
if ($this->id == $conf['authtype']) return true;
|
||||
|
@ -135,7 +153,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool If the extension is installed in the correct directory
|
||||
*/
|
||||
public function isInWrongFolder() {
|
||||
public function isInWrongFolder()
|
||||
{
|
||||
return $this->base != $this->getBase();
|
||||
}
|
||||
|
||||
|
@ -144,9 +163,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool If the extension is enabled
|
||||
*/
|
||||
public function isEnabled() {
|
||||
public function isEnabled()
|
||||
{
|
||||
global $conf;
|
||||
if($this->isTemplate()){
|
||||
if ($this->isTemplate()) {
|
||||
return ($conf['template'] == $this->getBase());
|
||||
}
|
||||
|
||||
|
@ -160,9 +180,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool If an update is available
|
||||
*/
|
||||
public function updateAvailable() {
|
||||
if(!$this->isInstalled()) return false;
|
||||
if($this->isBundled()) return false;
|
||||
public function updateAvailable()
|
||||
{
|
||||
if (!$this->isInstalled()) return false;
|
||||
if ($this->isBundled()) return false;
|
||||
$lastupdate = $this->getLastUpdate();
|
||||
if ($lastupdate === false) return false;
|
||||
$installed = $this->getInstalledVersion();
|
||||
|
@ -175,7 +196,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool If this extension is a template
|
||||
*/
|
||||
public function isTemplate() {
|
||||
public function isTemplate()
|
||||
{
|
||||
return $this->is_template;
|
||||
}
|
||||
|
||||
|
@ -186,7 +208,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getID() {
|
||||
public function getID()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
@ -195,7 +218,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string The name of the installation directory
|
||||
*/
|
||||
public function getInstallName() {
|
||||
public function getInstallName()
|
||||
{
|
||||
return $this->base;
|
||||
}
|
||||
|
||||
|
@ -205,7 +229,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string The basename
|
||||
*/
|
||||
public function getBase() {
|
||||
public function getBase()
|
||||
{
|
||||
if (!empty($this->localInfo['base'])) return $this->localInfo['base'];
|
||||
return $this->base;
|
||||
}
|
||||
|
@ -215,7 +240,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string The display name
|
||||
*/
|
||||
public function getDisplayName() {
|
||||
public function getDisplayName()
|
||||
{
|
||||
if (!empty($this->localInfo['name'])) return $this->localInfo['name'];
|
||||
if (!empty($this->remoteInfo['name'])) return $this->remoteInfo['name'];
|
||||
return $this->base;
|
||||
|
@ -226,7 +252,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The name of the author or false if there is none
|
||||
*/
|
||||
public function getAuthor() {
|
||||
public function getAuthor()
|
||||
{
|
||||
if (!empty($this->localInfo['author'])) return $this->localInfo['author'];
|
||||
if (!empty($this->remoteInfo['author'])) return $this->remoteInfo['author'];
|
||||
return false;
|
||||
|
@ -237,7 +264,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The email address or false if there is none
|
||||
*/
|
||||
public function getEmail() {
|
||||
public function getEmail()
|
||||
{
|
||||
// email is only in the local data
|
||||
if (!empty($this->localInfo['email'])) return $this->localInfo['email'];
|
||||
return false;
|
||||
|
@ -248,7 +276,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The md5sum of the email if there is any, false otherwise
|
||||
*/
|
||||
public function getEmailID() {
|
||||
public function getEmailID()
|
||||
{
|
||||
if (!empty($this->remoteInfo['emailid'])) return $this->remoteInfo['emailid'];
|
||||
if (!empty($this->localInfo['email'])) return md5($this->localInfo['email']);
|
||||
return false;
|
||||
|
@ -259,7 +288,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string The description
|
||||
*/
|
||||
public function getDescription() {
|
||||
public function getDescription()
|
||||
{
|
||||
if (!empty($this->localInfo['desc'])) return $this->localInfo['desc'];
|
||||
if (!empty($this->remoteInfo['description'])) return $this->remoteInfo['description'];
|
||||
return '';
|
||||
|
@ -270,7 +300,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string The URL
|
||||
*/
|
||||
public function getURL() {
|
||||
public function getURL()
|
||||
{
|
||||
if (!empty($this->localInfo['url'])) return $this->localInfo['url'];
|
||||
return 'https://www.dokuwiki.org/'.($this->isTemplate() ? 'template' : 'plugin').':'.$this->getBase();
|
||||
}
|
||||
|
@ -280,7 +311,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The version, usually in the form yyyy-mm-dd if there is any
|
||||
*/
|
||||
public function getInstalledVersion() {
|
||||
public function getInstalledVersion()
|
||||
{
|
||||
if (!empty($this->localInfo['date'])) return $this->localInfo['date'];
|
||||
if ($this->isInstalled()) return $this->getLang('unknownversion');
|
||||
return false;
|
||||
|
@ -291,7 +323,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The date of the last update or false if not available
|
||||
*/
|
||||
public function getUpdateDate() {
|
||||
public function getUpdateDate()
|
||||
{
|
||||
if (!empty($this->managerData['updated'])) return $this->managerData['updated'];
|
||||
return $this->getInstallDate();
|
||||
}
|
||||
|
@ -301,7 +334,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The date of the installation or false if not available
|
||||
*/
|
||||
public function getInstallDate() {
|
||||
public function getInstallDate()
|
||||
{
|
||||
if (!empty($this->managerData['installed'])) return $this->managerData['installed'];
|
||||
return false;
|
||||
}
|
||||
|
@ -311,7 +345,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return array The base names of the dependencies
|
||||
*/
|
||||
public function getDependencies() {
|
||||
public function getDependencies()
|
||||
{
|
||||
if (!empty($this->remoteInfo['dependencies'])) return $this->remoteInfo['dependencies'];
|
||||
return array();
|
||||
}
|
||||
|
@ -321,7 +356,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return array The base names of the missing dependencies
|
||||
*/
|
||||
public function getMissingDependencies() {
|
||||
public function getMissingDependencies()
|
||||
{
|
||||
/* @var Doku_Plugin_Controller $plugin_controller */
|
||||
global $plugin_controller;
|
||||
$dependencies = $this->getDependencies();
|
||||
|
@ -339,7 +375,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return array The names of the conflicting extensions
|
||||
*/
|
||||
public function getConflicts() {
|
||||
public function getConflicts()
|
||||
{
|
||||
if (!empty($this->remoteInfo['conflicts'])) return $this->remoteInfo['conflicts'];
|
||||
return array();
|
||||
}
|
||||
|
@ -349,7 +386,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return array The names of similar extensions
|
||||
*/
|
||||
public function getSimilarExtensions() {
|
||||
public function getSimilarExtensions()
|
||||
{
|
||||
if (!empty($this->remoteInfo['similar'])) return $this->remoteInfo['similar'];
|
||||
return array();
|
||||
}
|
||||
|
@ -359,7 +397,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return array The names of the tags of the extension
|
||||
*/
|
||||
public function getTags() {
|
||||
public function getTags()
|
||||
{
|
||||
if (!empty($this->remoteInfo['tags'])) return $this->remoteInfo['tags'];
|
||||
return array();
|
||||
}
|
||||
|
@ -369,7 +408,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return float|bool The popularity information or false if it isn't available
|
||||
*/
|
||||
public function getPopularity() {
|
||||
public function getPopularity()
|
||||
{
|
||||
if (!empty($this->remoteInfo['popularity'])) return $this->remoteInfo['popularity'];
|
||||
return false;
|
||||
}
|
||||
|
@ -380,7 +420,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The security warning if there is any, false otherwise
|
||||
*/
|
||||
public function getSecurityWarning() {
|
||||
public function getSecurityWarning()
|
||||
{
|
||||
if (!empty($this->remoteInfo['securitywarning'])) return $this->remoteInfo['securitywarning'];
|
||||
return false;
|
||||
}
|
||||
|
@ -390,7 +431,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The security issue if there is any, false otherwise
|
||||
*/
|
||||
public function getSecurityIssue() {
|
||||
public function getSecurityIssue()
|
||||
{
|
||||
if (!empty($this->remoteInfo['securityissue'])) return $this->remoteInfo['securityissue'];
|
||||
return false;
|
||||
}
|
||||
|
@ -400,7 +442,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The screenshot URL if there is any, false otherwise
|
||||
*/
|
||||
public function getScreenshotURL() {
|
||||
public function getScreenshotURL()
|
||||
{
|
||||
if (!empty($this->remoteInfo['screenshoturl'])) return $this->remoteInfo['screenshoturl'];
|
||||
return false;
|
||||
}
|
||||
|
@ -410,7 +453,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The thumbnail URL if there is any, false otherwise
|
||||
*/
|
||||
public function getThumbnailURL() {
|
||||
public function getThumbnailURL()
|
||||
{
|
||||
if (!empty($this->remoteInfo['thumbnailurl'])) return $this->remoteInfo['thumbnailurl'];
|
||||
return false;
|
||||
}
|
||||
|
@ -419,7 +463,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The previously used download URL, false if the extension has been installed manually
|
||||
*/
|
||||
public function getLastDownloadURL() {
|
||||
public function getLastDownloadURL()
|
||||
{
|
||||
if (!empty($this->managerData['downloadurl'])) return $this->managerData['downloadurl'];
|
||||
return false;
|
||||
}
|
||||
|
@ -429,7 +474,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The download URL if there is any, false otherwise
|
||||
*/
|
||||
public function getDownloadURL() {
|
||||
public function getDownloadURL()
|
||||
{
|
||||
if (!empty($this->remoteInfo['downloadurl'])) return $this->remoteInfo['downloadurl'];
|
||||
return false;
|
||||
}
|
||||
|
@ -439,7 +485,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool If the download URL has changed
|
||||
*/
|
||||
public function hasDownloadURLChanged() {
|
||||
public function hasDownloadURLChanged()
|
||||
{
|
||||
$lasturl = $this->getLastDownloadURL();
|
||||
$currenturl = $this->getDownloadURL();
|
||||
return ($lasturl && $currenturl && $lasturl != $currenturl);
|
||||
|
@ -450,7 +497,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The bug tracker URL if there is any, false otherwise
|
||||
*/
|
||||
public function getBugtrackerURL() {
|
||||
public function getBugtrackerURL()
|
||||
{
|
||||
if (!empty($this->remoteInfo['bugtracker'])) return $this->remoteInfo['bugtracker'];
|
||||
return false;
|
||||
}
|
||||
|
@ -460,7 +508,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The URL of the source repository if there is any, false otherwise
|
||||
*/
|
||||
public function getSourcerepoURL() {
|
||||
public function getSourcerepoURL()
|
||||
{
|
||||
if (!empty($this->remoteInfo['sourcerepo'])) return $this->remoteInfo['sourcerepo'];
|
||||
return false;
|
||||
}
|
||||
|
@ -470,7 +519,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The donation URL if there is any, false otherwise
|
||||
*/
|
||||
public function getDonationURL() {
|
||||
public function getDonationURL()
|
||||
{
|
||||
if (!empty($this->remoteInfo['donationurl'])) return $this->remoteInfo['donationurl'];
|
||||
return false;
|
||||
}
|
||||
|
@ -480,7 +530,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return array The type(s) as array of strings
|
||||
*/
|
||||
public function getTypes() {
|
||||
public function getTypes()
|
||||
{
|
||||
if (!empty($this->remoteInfo['types'])) return $this->remoteInfo['types'];
|
||||
if ($this->isTemplate()) return array(32 => 'template');
|
||||
return array();
|
||||
|
@ -491,7 +542,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return array The versions in the form yyyy-mm-dd => ('label' => label, 'implicit' => implicit)
|
||||
*/
|
||||
public function getCompatibleVersions() {
|
||||
public function getCompatibleVersions()
|
||||
{
|
||||
if (!empty($this->remoteInfo['compatible'])) return $this->remoteInfo['compatible'];
|
||||
return array();
|
||||
}
|
||||
|
@ -501,7 +553,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string|bool The last available update in the form yyyy-mm-dd if there is any, false otherwise
|
||||
*/
|
||||
public function getLastUpdate() {
|
||||
public function getLastUpdate()
|
||||
{
|
||||
if (!empty($this->remoteInfo['lastupdate'])) return $this->remoteInfo['lastupdate'];
|
||||
return false;
|
||||
}
|
||||
|
@ -511,9 +564,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string The base path of the extension
|
||||
*/
|
||||
public function getInstallDir() {
|
||||
public function getInstallDir()
|
||||
{
|
||||
if ($this->isTemplate()) {
|
||||
return DOKU_TPLLIB.$this->base;
|
||||
return $this->tpllib.$this->base;
|
||||
} else {
|
||||
return DOKU_PLUGIN.$this->base;
|
||||
}
|
||||
|
@ -524,7 +578,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string One of "none", "manual", "git" or "automatic"
|
||||
*/
|
||||
public function getInstallType() {
|
||||
public function getInstallType()
|
||||
{
|
||||
if (!$this->isInstalled()) return 'none';
|
||||
if (!empty($this->managerData)) return 'automatic';
|
||||
if (is_dir($this->getInstallDir().'/.git')) return 'git';
|
||||
|
@ -536,17 +591,17 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool|string True or error string
|
||||
*/
|
||||
public function canModify() {
|
||||
if($this->isInstalled()) {
|
||||
if(!is_writable($this->getInstallDir())) {
|
||||
public function canModify()
|
||||
{
|
||||
if ($this->isInstalled()) {
|
||||
if (!is_writable($this->getInstallDir())) {
|
||||
return 'noperms';
|
||||
}
|
||||
}
|
||||
|
||||
if($this->isTemplate() && !is_writable(DOKU_TPLLIB)) {
|
||||
if ($this->isTemplate() && !is_writable($this->tpllib)) {
|
||||
return 'notplperms';
|
||||
|
||||
} elseif(!is_writable(DOKU_PLUGIN)) {
|
||||
} elseif (!is_writable(DOKU_PLUGIN)) {
|
||||
return 'nopluginperms';
|
||||
}
|
||||
return true;
|
||||
|
@ -559,20 +614,21 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @throws Exception when something goes wrong
|
||||
* @return array The list of installed extensions
|
||||
*/
|
||||
public function installFromUpload($field){
|
||||
if($_FILES[$field]['error']){
|
||||
public function installFromUpload($field)
|
||||
{
|
||||
if ($_FILES[$field]['error']) {
|
||||
throw new Exception($this->getLang('msg_upload_failed').' ('.$_FILES[$field]['error'].')');
|
||||
}
|
||||
|
||||
$tmp = $this->mkTmpDir();
|
||||
if(!$tmp) throw new Exception($this->getLang('error_dircreate'));
|
||||
if (!$tmp) throw new Exception($this->getLang('error_dircreate'));
|
||||
|
||||
// filename may contain the plugin name for old style plugins...
|
||||
$basename = basename($_FILES[$field]['name']);
|
||||
$basename = preg_replace('/\.(tar\.gz|tar\.bz|tar\.bz2|tar|tgz|tbz|zip)$/', '', $basename);
|
||||
$basename = preg_replace('/[\W]+/', '', $basename);
|
||||
|
||||
if(!move_uploaded_file($_FILES[$field]['tmp_name'], "$tmp/upload.archive")){
|
||||
if (!move_uploaded_file($_FILES[$field]['tmp_name'], "$tmp/upload.archive")) {
|
||||
throw new Exception($this->getLang('msg_upload_failed'));
|
||||
}
|
||||
|
||||
|
@ -582,7 +638,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
$this->removeDeletedfiles($installed);
|
||||
// purge cache
|
||||
$this->purgeCache();
|
||||
}catch (Exception $e){
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
return $installed;
|
||||
|
@ -595,7 +651,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @throws Exception when something goes wrong
|
||||
* @return array The list of installed extensions
|
||||
*/
|
||||
public function installFromURL($url){
|
||||
public function installFromURL($url)
|
||||
{
|
||||
try {
|
||||
$path = $this->download($url);
|
||||
$installed = $this->installArchive($path, true);
|
||||
|
@ -604,7 +661,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
|
||||
// purge cache
|
||||
$this->purgeCache();
|
||||
}catch (Exception $e){
|
||||
} catch (Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
return $installed;
|
||||
|
@ -616,7 +673,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @throws \Exception when something goes wrong
|
||||
* @return array The list of installed extensions
|
||||
*/
|
||||
public function installOrUpdate() {
|
||||
public function installOrUpdate()
|
||||
{
|
||||
$url = $this->getDownloadURL();
|
||||
$path = $this->download($url);
|
||||
$installed = $this->installArchive($path, $this->isInstalled(), $this->getBase());
|
||||
|
@ -637,7 +695,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool If the plugin was sucessfully uninstalled
|
||||
*/
|
||||
public function uninstall() {
|
||||
public function uninstall()
|
||||
{
|
||||
$this->purgeCache();
|
||||
return io_rmdir($this->getInstallDir(), true);
|
||||
}
|
||||
|
@ -647,7 +706,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool|string True or an error message
|
||||
*/
|
||||
public function enable() {
|
||||
public function enable()
|
||||
{
|
||||
if ($this->isTemplate()) return $this->getLang('notimplemented');
|
||||
if (!$this->isInstalled()) return $this->getLang('notinstalled');
|
||||
if ($this->isEnabled()) return $this->getLang('alreadyenabled');
|
||||
|
@ -667,7 +727,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool|string True or an error message
|
||||
*/
|
||||
public function disable() {
|
||||
public function disable()
|
||||
{
|
||||
if ($this->isTemplate()) return $this->getLang('notimplemented');
|
||||
|
||||
/* @var Doku_Plugin_Controller $plugin_controller */
|
||||
|
@ -685,7 +746,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
/**
|
||||
* Purge the cache by touching the main configuration file
|
||||
*/
|
||||
protected function purgeCache() {
|
||||
protected function purgeCache()
|
||||
{
|
||||
global $config_cascade;
|
||||
|
||||
// expire dokuwiki caches
|
||||
|
@ -696,7 +758,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
/**
|
||||
* Read local extension data either from info.txt or getInfo()
|
||||
*/
|
||||
protected function readLocalData() {
|
||||
protected function readLocalData()
|
||||
{
|
||||
if ($this->isTemplate()) {
|
||||
$infopath = $this->getInstallDir().'/template.info.txt';
|
||||
} else {
|
||||
|
@ -710,15 +773,15 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
$path = $this->getInstallDir().'/';
|
||||
$plugin = null;
|
||||
|
||||
foreach($plugin_types as $type) {
|
||||
if(file_exists($path.$type.'.php')) {
|
||||
foreach ($plugin_types as $type) {
|
||||
if (file_exists($path.$type.'.php')) {
|
||||
$plugin = plugin_load($type, $this->base);
|
||||
if ($plugin) break;
|
||||
}
|
||||
|
||||
if($dh = @opendir($path.$type.'/')) {
|
||||
while(false !== ($cp = readdir($dh))) {
|
||||
if($cp == '.' || $cp == '..' || strtolower(substr($cp, -4)) != '.php') continue;
|
||||
if ($dh = @opendir($path.$type.'/')) {
|
||||
while (false !== ($cp = readdir($dh))) {
|
||||
if ($cp == '.' || $cp == '..' || strtolower(substr($cp, -4)) != '.php') continue;
|
||||
|
||||
$plugin = plugin_load($type, $this->base.'_'.substr($cp, 0, -4));
|
||||
if ($plugin) break;
|
||||
|
@ -741,21 +804,22 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @param string $url Where the extension was downloaded from. (empty for manual installs via upload)
|
||||
* @param array $installed Optional list of installed plugins
|
||||
*/
|
||||
protected function updateManagerData($url = '', $installed = null) {
|
||||
protected function updateManagerData($url = '', $installed = null)
|
||||
{
|
||||
$origID = $this->getID();
|
||||
|
||||
if(is_null($installed)) {
|
||||
if (is_null($installed)) {
|
||||
$installed = array($origID);
|
||||
}
|
||||
|
||||
foreach($installed as $ext => $info) {
|
||||
if($this->getID() != $ext) $this->setExtension($ext);
|
||||
if($url) {
|
||||
foreach ($installed as $ext => $info) {
|
||||
if ($this->getID() != $ext) $this->setExtension($ext);
|
||||
if ($url) {
|
||||
$this->managerData['downloadurl'] = $url;
|
||||
} elseif(isset($this->managerData['downloadurl'])) {
|
||||
} elseif (isset($this->managerData['downloadurl'])) {
|
||||
unset($this->managerData['downloadurl']);
|
||||
}
|
||||
if(isset($this->managerData['installed'])) {
|
||||
if (isset($this->managerData['installed'])) {
|
||||
$this->managerData['updated'] = date('r');
|
||||
} else {
|
||||
$this->managerData['installed'] = date('r');
|
||||
|
@ -763,23 +827,24 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
$this->writeManagerData();
|
||||
}
|
||||
|
||||
if($this->getID() != $origID) $this->setExtension($origID);
|
||||
if ($this->getID() != $origID) $this->setExtension($origID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the manager.dat file
|
||||
*/
|
||||
protected function readManagerData() {
|
||||
protected function readManagerData()
|
||||
{
|
||||
$managerpath = $this->getInstallDir().'/manager.dat';
|
||||
if (is_readable($managerpath)) {
|
||||
$file = @file($managerpath);
|
||||
if(!empty($file)) {
|
||||
foreach($file as $line) {
|
||||
if (!empty($file)) {
|
||||
foreach ($file as $line) {
|
||||
list($key, $value) = explode('=', trim($line, DOKU_LF), 2);
|
||||
$key = trim($key);
|
||||
$value = trim($value);
|
||||
// backwards compatible with old plugin manager
|
||||
if($key == 'url') $key = 'downloadurl';
|
||||
if ($key == 'url') $key = 'downloadurl';
|
||||
$this->managerData[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
@ -789,7 +854,8 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
/**
|
||||
* Write the manager.data file
|
||||
*/
|
||||
protected function writeManagerData() {
|
||||
protected function writeManagerData()
|
||||
{
|
||||
$managerpath = $this->getInstallDir().'/manager.dat';
|
||||
$data = '';
|
||||
foreach ($this->managerData as $k => $v) {
|
||||
|
@ -805,9 +871,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return false|string
|
||||
*/
|
||||
protected function mkTmpDir(){
|
||||
protected function mkTmpDir()
|
||||
{
|
||||
$dir = io_mktmpdir();
|
||||
if(!$dir) return false;
|
||||
if (!$dir) return false;
|
||||
$this->temporary[] = $dir;
|
||||
return $dir;
|
||||
}
|
||||
|
@ -819,27 +886,28 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @throws Exception when something goes wrong
|
||||
* @return string The path where the archive was saved
|
||||
*/
|
||||
public function download($url) {
|
||||
public function download($url)
|
||||
{
|
||||
// check the url
|
||||
if(!preg_match('/https?:\/\//i', $url)){
|
||||
if (!preg_match('/https?:\/\//i', $url)) {
|
||||
throw new Exception($this->getLang('error_badurl'));
|
||||
}
|
||||
|
||||
// try to get the file from the path (used as plugin name fallback)
|
||||
$file = parse_url($url, PHP_URL_PATH);
|
||||
if(is_null($file)){
|
||||
if (is_null($file)) {
|
||||
$file = md5($url);
|
||||
}else{
|
||||
} else {
|
||||
$file = utf8_basename($file);
|
||||
}
|
||||
|
||||
// create tmp directory for download
|
||||
if(!($tmp = $this->mkTmpDir())) {
|
||||
if (!($tmp = $this->mkTmpDir())) {
|
||||
throw new Exception($this->getLang('error_dircreate'));
|
||||
}
|
||||
|
||||
// download
|
||||
if(!$file = io_download($url, $tmp.'/', true, $file, 0)) {
|
||||
if (!$file = io_download($url, $tmp.'/', true, $file, 0)) {
|
||||
io_rmdir($tmp, true);
|
||||
throw new Exception(sprintf($this->getLang('error_download'), '<bdi>'.hsc($url).'</bdi>'));
|
||||
}
|
||||
|
@ -854,16 +922,17 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @throws Exception when something went wrong
|
||||
* @return array list of installed extensions
|
||||
*/
|
||||
public function installArchive($file, $overwrite=false, $base = '') {
|
||||
public function installArchive($file, $overwrite = false, $base = '')
|
||||
{
|
||||
$installed_extensions = array();
|
||||
|
||||
// create tmp directory for decompression
|
||||
if(!($tmp = $this->mkTmpDir())) {
|
||||
if (!($tmp = $this->mkTmpDir())) {
|
||||
throw new Exception($this->getLang('error_dircreate'));
|
||||
}
|
||||
|
||||
// add default base folder if specified to handle case where zip doesn't contain this
|
||||
if($base && !@mkdir($tmp.'/'.$base)) {
|
||||
if ($base && !@mkdir($tmp.'/'.$base)) {
|
||||
throw new Exception($this->getLang('error_dircreate'));
|
||||
}
|
||||
|
||||
|
@ -874,33 +943,33 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
// move the folder(s) to lib/..
|
||||
$result = array('old'=>array(), 'new'=>array());
|
||||
$default = ($this->isTemplate() ? 'template' : 'plugin');
|
||||
if(!$this->find_folders($result, $tmp.'/'.$base, $default)) {
|
||||
if (!$this->findFolders($result, $tmp.'/'.$base, $default)) {
|
||||
throw new Exception($this->getLang('error_findfolder'));
|
||||
}
|
||||
|
||||
// choose correct result array
|
||||
if(count($result['new'])) {
|
||||
if (count($result['new'])) {
|
||||
$install = $result['new'];
|
||||
}else{
|
||||
} else {
|
||||
$install = $result['old'];
|
||||
}
|
||||
|
||||
if(!count($install)){
|
||||
if (!count($install)) {
|
||||
throw new Exception($this->getLang('error_findfolder'));
|
||||
}
|
||||
|
||||
// now install all found items
|
||||
foreach($install as $item) {
|
||||
foreach ($install as $item) {
|
||||
// where to install?
|
||||
if($item['type'] == 'template') {
|
||||
$target_base_dir = DOKU_TPLLIB;
|
||||
}else{
|
||||
if ($item['type'] == 'template') {
|
||||
$target_base_dir = $this->tpllib;
|
||||
} else {
|
||||
$target_base_dir = DOKU_PLUGIN;
|
||||
}
|
||||
|
||||
if(!empty($item['base'])) {
|
||||
if (!empty($item['base'])) {
|
||||
// use base set in info.txt
|
||||
} elseif($base && count($install) == 1) {
|
||||
} elseif ($base && count($install) == 1) {
|
||||
$item['base'] = $base;
|
||||
} else {
|
||||
// default - use directory as found in zip
|
||||
|
@ -911,7 +980,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
|
||||
// check to make sure we aren't overwriting anything
|
||||
$target = $target_base_dir.$item['base'];
|
||||
if(!$overwrite && file_exists($target)) {
|
||||
if (!$overwrite && file_exists($target)) {
|
||||
// TODO remember our settings, ask the user to confirm overwrite
|
||||
continue;
|
||||
}
|
||||
|
@ -919,10 +988,10 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
$action = file_exists($target) ? 'update' : 'install';
|
||||
|
||||
// copy action
|
||||
if($this->dircopy($item['tmp'], $target)) {
|
||||
if ($this->dircopy($item['tmp'], $target)) {
|
||||
// return info
|
||||
$id = $item['base'];
|
||||
if($item['type'] == 'template') {
|
||||
if ($item['type'] == 'template') {
|
||||
$id = 'template:'.$id;
|
||||
}
|
||||
$installed_extensions[$id] = array(
|
||||
|
@ -936,7 +1005,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
}
|
||||
|
||||
// cleanup
|
||||
if($tmp) io_rmdir($tmp, true);
|
||||
if ($tmp) io_rmdir($tmp, true);
|
||||
|
||||
return $installed_extensions;
|
||||
}
|
||||
|
@ -962,20 +1031,20 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @param string $subdir - a subdirectory. do not set. used by recursion
|
||||
* @return bool - false on error
|
||||
*/
|
||||
protected function find_folders(&$result, $directory, $default_type='plugin', $subdir='') {
|
||||
protected function findFolders(&$result, $directory, $default_type = 'plugin', $subdir = '')
|
||||
{
|
||||
$this_dir = "$directory$subdir";
|
||||
$dh = @opendir($this_dir);
|
||||
if(!$dh) return false;
|
||||
if (!$dh) return false;
|
||||
|
||||
$found_dirs = array();
|
||||
$found_files = 0;
|
||||
$found_template_parts = 0;
|
||||
while (false !== ($f = readdir($dh))) {
|
||||
if($f == '.' || $f == '..') continue;
|
||||
if ($f == '.' || $f == '..') continue;
|
||||
|
||||
if(is_dir("$this_dir/$f")) {
|
||||
if (is_dir("$this_dir/$f")) {
|
||||
$found_dirs[] = "$subdir/$f";
|
||||
|
||||
} else {
|
||||
// it's a file -> check for config
|
||||
$found_files++;
|
||||
|
@ -1004,11 +1073,11 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
closedir($dh);
|
||||
|
||||
// files where found but no info.txt - use old method
|
||||
if($found_files){
|
||||
if ($found_files) {
|
||||
$info = array();
|
||||
$info['tmp'] = $this_dir;
|
||||
// does this look like a template or should we use the default type?
|
||||
if($found_template_parts >= 2) {
|
||||
if ($found_template_parts >= 2) {
|
||||
$info['type'] = 'template';
|
||||
} else {
|
||||
$info['type'] = $default_type;
|
||||
|
@ -1020,7 +1089,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
|
||||
// we have no files yet -> recurse
|
||||
foreach ($found_dirs as $found_dir) {
|
||||
$this->find_folders($result, $directory, $default_type, "$found_dir");
|
||||
$this->findFolders($result, $directory, $default_type, "$found_dir");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1035,13 +1104,13 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @throws Exception
|
||||
* @return bool
|
||||
*/
|
||||
private function decompress($file, $target) {
|
||||
private function decompress($file, $target)
|
||||
{
|
||||
// decompression library doesn't like target folders ending in "/"
|
||||
if(substr($target, -1) == "/") $target = substr($target, 0, -1);
|
||||
|
||||
$ext = $this->guess_archive($file);
|
||||
if(in_array($ext, array('tar', 'bz', 'gz'))) {
|
||||
if (substr($target, -1) == "/") $target = substr($target, 0, -1);
|
||||
|
||||
$ext = $this->guessArchiveType($file);
|
||||
if (in_array($ext, array('tar', 'bz', 'gz'))) {
|
||||
try {
|
||||
$tar = new \splitbrain\PHPArchive\Tar();
|
||||
$tar->open($file);
|
||||
|
@ -1051,8 +1120,7 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
}
|
||||
|
||||
return true;
|
||||
} elseif($ext == 'zip') {
|
||||
|
||||
} elseif ($ext == 'zip') {
|
||||
try {
|
||||
$zip = new \splitbrain\PHPArchive\Zip();
|
||||
$zip->open($file);
|
||||
|
@ -1078,15 +1146,16 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @param string $file The file to analyze
|
||||
* @return string|false false if the file can't be read, otherwise an "extension"
|
||||
*/
|
||||
private function guess_archive($file) {
|
||||
private function guessArchiveType($file)
|
||||
{
|
||||
$fh = fopen($file, 'rb');
|
||||
if(!$fh) return false;
|
||||
if (!$fh) return false;
|
||||
$magic = fread($fh, 5);
|
||||
fclose($fh);
|
||||
|
||||
if(strpos($magic, "\x42\x5a") === 0) return 'bz';
|
||||
if(strpos($magic, "\x1f\x8b") === 0) return 'gz';
|
||||
if(strpos($magic, "\x50\x4b\x03\x04") === 0) return 'zip';
|
||||
if (strpos($magic, "\x42\x5a") === 0) return 'bz';
|
||||
if (strpos($magic, "\x1f\x8b") === 0) return 'gz';
|
||||
if (strpos($magic, "\x50\x4b\x03\x04") === 0) return 'zip';
|
||||
return 'tar';
|
||||
}
|
||||
|
||||
|
@ -1097,27 +1166,27 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
* @param string $dst filename path to file
|
||||
* @return bool|int|string
|
||||
*/
|
||||
private function dircopy($src, $dst) {
|
||||
private function dircopy($src, $dst)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if(is_dir($src)) {
|
||||
if(!$dh = @opendir($src)) return false;
|
||||
if (is_dir($src)) {
|
||||
if (!$dh = @opendir($src)) return false;
|
||||
|
||||
if($ok = io_mkdir_p($dst)) {
|
||||
if ($ok = io_mkdir_p($dst)) {
|
||||
while ($ok && (false !== ($f = readdir($dh)))) {
|
||||
if($f == '..' || $f == '.') continue;
|
||||
if ($f == '..' || $f == '.') continue;
|
||||
$ok = $this->dircopy("$src/$f", "$dst/$f");
|
||||
}
|
||||
}
|
||||
|
||||
closedir($dh);
|
||||
return $ok;
|
||||
|
||||
} else {
|
||||
$exists = file_exists($dst);
|
||||
|
||||
if(!@copy($src, $dst)) return false;
|
||||
if(!$exists && !empty($conf['fperm'])) chmod($dst, $conf['fperm']);
|
||||
if (!@copy($src, $dst)) return false;
|
||||
if (!$exists && !empty($conf['fperm'])) chmod($dst, $conf['fperm']);
|
||||
@touch($dst, filemtime($src));
|
||||
}
|
||||
|
||||
|
@ -1129,29 +1198,30 @@ class helper_plugin_extension_extension extends DokuWiki_Plugin {
|
|||
*
|
||||
* @param array $installed
|
||||
*/
|
||||
private function removeDeletedfiles($installed) {
|
||||
foreach($installed as $id => $extension) {
|
||||
private function removeDeletedfiles($installed)
|
||||
{
|
||||
foreach ($installed as $id => $extension) {
|
||||
// only on update
|
||||
if($extension['action'] == 'install') continue;
|
||||
if ($extension['action'] == 'install') continue;
|
||||
|
||||
// get definition file
|
||||
if($extension['type'] == 'template') {
|
||||
$extensiondir = DOKU_TPLLIB;
|
||||
}else{
|
||||
if ($extension['type'] == 'template') {
|
||||
$extensiondir = $this->tpllib;
|
||||
} else {
|
||||
$extensiondir = DOKU_PLUGIN;
|
||||
}
|
||||
$extensiondir = $extensiondir . $extension['base'] .'/';
|
||||
$definitionfile = $extensiondir . 'deleted.files';
|
||||
if(!file_exists($definitionfile)) continue;
|
||||
if (!file_exists($definitionfile)) continue;
|
||||
|
||||
// delete the old files
|
||||
$list = file($definitionfile);
|
||||
|
||||
foreach($list as $line) {
|
||||
foreach ($list as $line) {
|
||||
$line = trim(preg_replace('/#.*$/', '', $line));
|
||||
if(!$line) continue;
|
||||
if (!$line) continue;
|
||||
$file = $extensiondir . $line;
|
||||
if(!file_exists($file)) continue;
|
||||
if (!file_exists($file)) continue;
|
||||
|
||||
io_rmdir($file, true);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
/**
|
||||
* Class helper_plugin_extension_list takes care of the overall GUI
|
||||
*/
|
||||
class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
||||
class helper_plugin_extension_gui extends DokuWiki_Plugin
|
||||
{
|
||||
|
||||
protected $tabs = array('plugins', 'templates', 'search', 'install');
|
||||
|
||||
|
@ -21,7 +22,8 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
*
|
||||
* initializes requested info window
|
||||
*/
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
global $INPUT;
|
||||
$this->infoFor = $INPUT->str('info');
|
||||
}
|
||||
|
@ -29,7 +31,8 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
/**
|
||||
* display the plugin tab
|
||||
*/
|
||||
public function tabPlugins() {
|
||||
public function tabPlugins()
|
||||
{
|
||||
/* @var Doku_Plugin_Controller $plugin_controller */
|
||||
global $plugin_controller;
|
||||
|
||||
|
@ -43,19 +46,20 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
$extension = $this->loadHelper('extension_extension');
|
||||
/* @var helper_plugin_extension_list $list */
|
||||
$list = $this->loadHelper('extension_list');
|
||||
$list->start_form();
|
||||
foreach($pluginlist as $name) {
|
||||
$list->startForm();
|
||||
foreach ($pluginlist as $name) {
|
||||
$extension->setExtension($name);
|
||||
$list->add_row($extension, $extension->getID() == $this->infoFor);
|
||||
$list->addRow($extension, $extension->getID() == $this->infoFor);
|
||||
}
|
||||
$list->end_form();
|
||||
$list->endForm();
|
||||
$list->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the template tab
|
||||
*/
|
||||
public function tabTemplates() {
|
||||
public function tabTemplates()
|
||||
{
|
||||
echo '<div class="panelHeader">';
|
||||
echo $this->locale_xhtml('intro_templates');
|
||||
echo '</div>';
|
||||
|
@ -69,19 +73,20 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
$extension = $this->loadHelper('extension_extension');
|
||||
/* @var helper_plugin_extension_list $list */
|
||||
$list = $this->loadHelper('extension_list');
|
||||
$list->start_form();
|
||||
foreach($tpllist as $name) {
|
||||
$list->startForm();
|
||||
foreach ($tpllist as $name) {
|
||||
$extension->setExtension("template:$name");
|
||||
$list->add_row($extension, $extension->getID() == $this->infoFor);
|
||||
$list->addRow($extension, $extension->getID() == $this->infoFor);
|
||||
}
|
||||
$list->end_form();
|
||||
$list->endForm();
|
||||
$list->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the search tab
|
||||
*/
|
||||
public function tabSearch() {
|
||||
public function tabSearch()
|
||||
{
|
||||
global $INPUT;
|
||||
echo '<div class="panelHeader">';
|
||||
echo $this->locale_xhtml('intro_search');
|
||||
|
@ -92,7 +97,7 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
$form->addElement(form_makeButton('submit', '', $this->getLang('search')));
|
||||
$form->printForm();
|
||||
|
||||
if(!$INPUT->bool('q')) return;
|
||||
if (!$INPUT->bool('q')) return;
|
||||
|
||||
/* @var helper_plugin_extension_repository $repository FIXME should we use some gloabl instance? */
|
||||
$repository = $this->loadHelper('extension_repository');
|
||||
|
@ -102,24 +107,24 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
$extension = $this->loadHelper('extension_extension');
|
||||
/* @var helper_plugin_extension_list $list */
|
||||
$list = $this->loadHelper('extension_list');
|
||||
$list->start_form();
|
||||
if($result){
|
||||
foreach($result as $name) {
|
||||
$list->startForm();
|
||||
if ($result) {
|
||||
foreach ($result as $name) {
|
||||
$extension->setExtension($name);
|
||||
$list->add_row($extension, $extension->getID() == $this->infoFor);
|
||||
$list->addRow($extension, $extension->getID() == $this->infoFor);
|
||||
}
|
||||
} else {
|
||||
$list->nothing_found();
|
||||
$list->nothingFound();
|
||||
}
|
||||
$list->end_form();
|
||||
$list->endForm();
|
||||
$list->render();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the template tab
|
||||
*/
|
||||
public function tabInstall() {
|
||||
public function tabInstall()
|
||||
{
|
||||
echo '<div class="panelHeader">';
|
||||
echo $this->locale_xhtml('intro_install');
|
||||
echo '</div>';
|
||||
|
@ -142,11 +147,12 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
*
|
||||
* @fixme style active one
|
||||
*/
|
||||
public function tabNavigation() {
|
||||
public function tabNavigation()
|
||||
{
|
||||
echo '<ul class="tabs">';
|
||||
foreach($this->tabs as $tab) {
|
||||
foreach ($this->tabs as $tab) {
|
||||
$url = $this->tabURL($tab);
|
||||
if($this->currentTab() == $tab) {
|
||||
if ($this->currentTab() == $tab) {
|
||||
$class = ' active';
|
||||
} else {
|
||||
$class = '';
|
||||
|
@ -161,11 +167,12 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function currentTab() {
|
||||
public function currentTab()
|
||||
{
|
||||
global $INPUT;
|
||||
|
||||
$tab = $INPUT->str('tab', 'plugins', true);
|
||||
if(!in_array($tab, $this->tabs)) $tab = 'plugins';
|
||||
if (!in_array($tab, $this->tabs)) $tab = 'plugins';
|
||||
return $tab;
|
||||
}
|
||||
|
||||
|
@ -178,19 +185,19 @@ class helper_plugin_extension_gui extends DokuWiki_Plugin {
|
|||
* @param bool $absolute create absolute URLs?
|
||||
* @return string
|
||||
*/
|
||||
public function tabURL($tab = '', $params = array(), $sep = '&', $absolute = false) {
|
||||
public function tabURL($tab = '', $params = array(), $sep = '&', $absolute = false)
|
||||
{
|
||||
global $ID;
|
||||
global $INPUT;
|
||||
|
||||
if(!$tab) $tab = $this->currentTab();
|
||||
if (!$tab) $tab = $this->currentTab();
|
||||
$defaults = array(
|
||||
'do' => 'admin',
|
||||
'page' => 'extension',
|
||||
'tab' => $tab,
|
||||
);
|
||||
if($tab == 'search') $defaults['q'] = $INPUT->str('q');
|
||||
if ($tab == 'search') $defaults['q'] = $INPUT->str('q');
|
||||
|
||||
return wl($ID, array_merge($defaults, $params), $absolute, $sep);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
/**
|
||||
* Class helper_plugin_extension_list takes care of creating a HTML list of extensions
|
||||
*/
|
||||
class helper_plugin_extension_list extends DokuWiki_Plugin {
|
||||
class helper_plugin_extension_list extends DokuWiki_Plugin
|
||||
{
|
||||
protected $form = '';
|
||||
/** @var helper_plugin_extension_gui */
|
||||
protected $gui;
|
||||
|
@ -19,30 +20,38 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
*
|
||||
* loads additional helpers
|
||||
*/
|
||||
public function __construct(){
|
||||
public function __construct()
|
||||
{
|
||||
$this->gui = plugin_load('helper', 'extension_gui');
|
||||
}
|
||||
|
||||
public function start_form() {
|
||||
/**
|
||||
* Initialize the extension table form
|
||||
*/
|
||||
public function startForm()
|
||||
{
|
||||
$this->form .= '<form id="extension__list" accept-charset="utf-8" method="post" action="">';
|
||||
$hidden = array(
|
||||
'do'=>'admin',
|
||||
'page'=>'extension',
|
||||
'sectok'=>getSecurityToken()
|
||||
);
|
||||
$this->add_hidden($hidden);
|
||||
$this->addHidden($hidden);
|
||||
$this->form .= '<ul class="extensionList">';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build single row of extension table
|
||||
*
|
||||
* @param helper_plugin_extension_extension $extension The extension that shall be added
|
||||
* @param bool $showinfo Show the info area
|
||||
*/
|
||||
public function add_row(helper_plugin_extension_extension $extension, $showinfo = false) {
|
||||
$this->start_row($extension);
|
||||
$this->populate_column('legend', $this->make_legend($extension, $showinfo));
|
||||
$this->populate_column('actions', $this->make_actions($extension));
|
||||
$this->end_row();
|
||||
public function addRow(helper_plugin_extension_extension $extension, $showinfo = false)
|
||||
{
|
||||
$this->startRow($extension);
|
||||
$this->populateColumn('legend', $this->makeLegend($extension, $showinfo));
|
||||
$this->populateColumn('actions', $this->makeActions($extension));
|
||||
$this->endRow();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +61,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param string $header The content of the header
|
||||
* @param int $level The level of the header
|
||||
*/
|
||||
public function add_header($id, $header, $level = 2) {
|
||||
public function addHeader($id, $header, $level = 2)
|
||||
{
|
||||
$this->form .='<h'.$level.' id="'.$id.'">'.hsc($header).'</h'.$level.'>'.DOKU_LF;
|
||||
}
|
||||
|
||||
|
@ -61,17 +71,20 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
*
|
||||
* @param string $data The content
|
||||
*/
|
||||
public function add_p($data) {
|
||||
public function addParagraph($data)
|
||||
{
|
||||
$this->form .= '<p>'.hsc($data).'</p>'.DOKU_LF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add hidden fields to the form with the given data
|
||||
* @param array $array
|
||||
*
|
||||
* @param array $data key-value list of fields and their values to add
|
||||
*/
|
||||
public function add_hidden(array $array) {
|
||||
public function addHidden(array $data)
|
||||
{
|
||||
$this->form .= '<div class="no">';
|
||||
foreach ($array as $key => $value) {
|
||||
foreach ($data as $key => $value) {
|
||||
$this->form .= '<input type="hidden" name="'.hsc($key).'" value="'.hsc($value).'" />';
|
||||
}
|
||||
$this->form .= '</div>'.DOKU_LF;
|
||||
|
@ -80,7 +93,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
/**
|
||||
* Add closing tags
|
||||
*/
|
||||
public function end_form() {
|
||||
public function endForm()
|
||||
{
|
||||
$this->form .= '</ul>';
|
||||
$this->form .= '</form>'.DOKU_LF;
|
||||
}
|
||||
|
@ -88,7 +102,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
/**
|
||||
* Show message when no results are found
|
||||
*/
|
||||
public function nothing_found() {
|
||||
public function nothingFound()
|
||||
{
|
||||
global $lang;
|
||||
$this->form .= '<li class="notfound">'.$lang['nothingfound'].'</li>';
|
||||
}
|
||||
|
@ -96,7 +111,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
/**
|
||||
* Print the form
|
||||
*/
|
||||
public function render() {
|
||||
public function render()
|
||||
{
|
||||
echo $this->form;
|
||||
}
|
||||
|
||||
|
@ -105,9 +121,10 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
*
|
||||
* @param helper_plugin_extension_extension $extension The extension
|
||||
*/
|
||||
private function start_row(helper_plugin_extension_extension $extension) {
|
||||
private function startRow(helper_plugin_extension_extension $extension)
|
||||
{
|
||||
$this->form .= '<li id="extensionplugin__'.hsc($extension->getID()).
|
||||
'" class="'.$this->make_class($extension).'">';
|
||||
'" class="'.$this->makeClass($extension).'">';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,14 +132,16 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param string $class The class name
|
||||
* @param string $html The content
|
||||
*/
|
||||
private function populate_column($class, $html) {
|
||||
private function populateColumn($class, $html)
|
||||
{
|
||||
$this->form .= '<div class="'.$class.' col">'.$html.'</div>'.DOKU_LF;
|
||||
}
|
||||
|
||||
/**
|
||||
* End the row
|
||||
*/
|
||||
private function end_row() {
|
||||
private function endRow()
|
||||
{
|
||||
$this->form .= '</li>'.DOKU_LF;
|
||||
}
|
||||
|
||||
|
@ -132,7 +151,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param helper_plugin_extension_extension $extension The extension
|
||||
* @return string The HTML code
|
||||
*/
|
||||
public function make_homepagelink(helper_plugin_extension_extension $extension) {
|
||||
public function makeHomepageLink(helper_plugin_extension_extension $extension)
|
||||
{
|
||||
$text = $this->getLang('homepage_link');
|
||||
$url = hsc($extension->getURL());
|
||||
return '<a href="'.$url.'" title="'.$url.'" class ="urlextern">'.$text.'</a> ';
|
||||
|
@ -144,15 +164,16 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param helper_plugin_extension_extension $extension The extension object
|
||||
* @return string The class name
|
||||
*/
|
||||
public function make_class(helper_plugin_extension_extension $extension) {
|
||||
public function makeClass(helper_plugin_extension_extension $extension)
|
||||
{
|
||||
$class = ($extension->isTemplate()) ? 'template' : 'plugin';
|
||||
if($extension->isInstalled()) {
|
||||
if ($extension->isInstalled()) {
|
||||
$class.=' installed';
|
||||
$class.= ($extension->isEnabled()) ? ' enabled':' disabled';
|
||||
if($extension->updateAvailable()) $class .= ' updatable';
|
||||
if ($extension->updateAvailable()) $class .= ' updatable';
|
||||
}
|
||||
if(!$extension->canModify()) $class.= ' notselect';
|
||||
if($extension->isProtected()) $class.= ' protected';
|
||||
if (!$extension->canModify()) $class.= ' notselect';
|
||||
if ($extension->isProtected()) $class.= ' protected';
|
||||
//if($this->showinfo) $class.= ' showinfo';
|
||||
return $class;
|
||||
}
|
||||
|
@ -163,19 +184,16 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param helper_plugin_extension_extension $extension The extension object
|
||||
* @return string The HTML code of the link
|
||||
*/
|
||||
public function make_author(helper_plugin_extension_extension $extension) {
|
||||
global $ID;
|
||||
|
||||
if($extension->getAuthor()) {
|
||||
|
||||
public function makeAuthor(helper_plugin_extension_extension $extension)
|
||||
{
|
||||
if ($extension->getAuthor()) {
|
||||
$mailid = $extension->getEmailID();
|
||||
if($mailid){
|
||||
if ($mailid) {
|
||||
$url = $this->gui->tabURL('search', array('q' => 'authorid:'.$mailid));
|
||||
return '<bdi><a href="'.$url.'" class="author" title="'.$this->getLang('author_hint').'" >'.
|
||||
'<img src="//www.gravatar.com/avatar/'.$mailid.'?s=20&d=mm" width="20" height="20" alt="" /> '.
|
||||
hsc($extension->getAuthor()).'</a></bdi>';
|
||||
|
||||
}else{
|
||||
} else {
|
||||
return '<bdi><span class="author">'.hsc($extension->getAuthor()).'</span></bdi>';
|
||||
}
|
||||
}
|
||||
|
@ -188,11 +206,12 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param helper_plugin_extension_extension $extension The extension object
|
||||
* @return string The HTML code
|
||||
*/
|
||||
public function make_screenshot(helper_plugin_extension_extension $extension) {
|
||||
public function makeScreenshot(helper_plugin_extension_extension $extension)
|
||||
{
|
||||
$screen = $extension->getScreenshotURL();
|
||||
$thumb = $extension->getThumbnailURL();
|
||||
|
||||
if($screen) {
|
||||
if ($screen) {
|
||||
// use protocol independent URLs for images coming from us #595
|
||||
$screen = str_replace('http://www.dokuwiki.org', '//www.dokuwiki.org', $screen);
|
||||
$thumb = str_replace('http://www.dokuwiki.org', '//www.dokuwiki.org', $thumb);
|
||||
|
@ -201,10 +220,9 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
$img = '<a href="'.hsc($screen).'" target="_blank" class="extension_screenshot">'.
|
||||
'<img alt="'.$title.'" width="120" height="70" src="'.hsc($thumb).'" />'.
|
||||
'</a>';
|
||||
} elseif($extension->isTemplate()) {
|
||||
} elseif ($extension->isTemplate()) {
|
||||
$img = '<img alt="" width="120" height="70" src="'.DOKU_BASE.
|
||||
'lib/plugins/extension/images/template.png" />';
|
||||
|
||||
} else {
|
||||
$img = '<img alt="" width="120" height="70" src="'.DOKU_BASE.
|
||||
'lib/plugins/extension/images/plugin.png" />';
|
||||
|
@ -219,17 +237,18 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param bool $showinfo Show the info section
|
||||
* @return string The HTML code
|
||||
*/
|
||||
public function make_legend(helper_plugin_extension_extension $extension, $showinfo = false) {
|
||||
public function makeLegend(helper_plugin_extension_extension $extension, $showinfo = false)
|
||||
{
|
||||
$return = '<div>';
|
||||
$return .= '<h2>';
|
||||
$return .= sprintf(
|
||||
$this->getLang('extensionby'),
|
||||
'<bdi>'.hsc($extension->getDisplayName()).'</bdi>',
|
||||
$this->make_author($extension)
|
||||
$this->makeAuthor($extension)
|
||||
);
|
||||
$return .= '</h2>'.DOKU_LF;
|
||||
|
||||
$return .= $this->make_screenshot($extension);
|
||||
$return .= $this->makeScreenshot($extension);
|
||||
|
||||
$popularity = $extension->getPopularity();
|
||||
if ($popularity !== false && !$extension->isBundled()) {
|
||||
|
@ -240,18 +259,18 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
'</div></div>'.DOKU_LF;
|
||||
}
|
||||
|
||||
if($extension->getDescription()) {
|
||||
if ($extension->getDescription()) {
|
||||
$return .= '<p><bdi>';
|
||||
$return .= hsc($extension->getDescription()).' ';
|
||||
$return .= '</bdi></p>'.DOKU_LF;
|
||||
}
|
||||
|
||||
$return .= $this->make_linkbar($extension);
|
||||
$return .= $this->makeLinkbar($extension);
|
||||
|
||||
if($showinfo){
|
||||
if ($showinfo) {
|
||||
$url = $this->gui->tabURL('');
|
||||
$class = 'close';
|
||||
}else{
|
||||
} else {
|
||||
$url = $this->gui->tabURL('', array('info' => $extension->getID()));
|
||||
$class = '';
|
||||
}
|
||||
|
@ -260,9 +279,9 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
'" data-extid="'.$extension->getID().'">'.$this->getLang('btn_info').'</a>';
|
||||
|
||||
if ($showinfo) {
|
||||
$return .= $this->make_info($extension);
|
||||
$return .= $this->makeInfo($extension);
|
||||
}
|
||||
$return .= $this->make_noticearea($extension);
|
||||
$return .= $this->makeNoticeArea($extension);
|
||||
$return .= '</div>'.DOKU_LF;
|
||||
return $return;
|
||||
}
|
||||
|
@ -273,19 +292,20 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param helper_plugin_extension_extension $extension The extension instance
|
||||
* @return string The HTML code
|
||||
*/
|
||||
public function make_linkbar(helper_plugin_extension_extension $extension) {
|
||||
public function makeLinkbar(helper_plugin_extension_extension $extension)
|
||||
{
|
||||
$return = '<div class="linkbar">';
|
||||
$return .= $this->make_homepagelink($extension);
|
||||
$return .= $this->makeHomepageLink($extension);
|
||||
if ($extension->getBugtrackerURL()) {
|
||||
$return .= ' <a href="'.hsc($extension->getBugtrackerURL()).
|
||||
'" title="'.hsc($extension->getBugtrackerURL()).'" class ="bugs">'.
|
||||
$this->getLang('bugs_features').'</a> ';
|
||||
}
|
||||
if ($extension->getTags()){
|
||||
if ($extension->getTags()) {
|
||||
$first = true;
|
||||
$return .= '<span class="tags">'.$this->getLang('tags').' ';
|
||||
foreach ($extension->getTags() as $tag) {
|
||||
if (!$first){
|
||||
if (!$first) {
|
||||
$return .= ', ';
|
||||
} else {
|
||||
$first = false;
|
||||
|
@ -305,10 +325,11 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param helper_plugin_extension_extension $extension The extension
|
||||
* @return string The HTML code
|
||||
*/
|
||||
public function make_noticearea(helper_plugin_extension_extension $extension) {
|
||||
public function makeNoticeArea(helper_plugin_extension_extension $extension)
|
||||
{
|
||||
$return = '';
|
||||
$missing_dependencies = $extension->getMissingDependencies();
|
||||
if(!empty($missing_dependencies)) {
|
||||
if (!empty($missing_dependencies)) {
|
||||
$return .= '<div class="msg error">' .
|
||||
sprintf(
|
||||
$this->getLang('missing_dependency'),
|
||||
|
@ -316,7 +337,7 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
) .
|
||||
'</div>';
|
||||
}
|
||||
if($extension->isInWrongFolder()) {
|
||||
if ($extension->isInWrongFolder()) {
|
||||
$return .= '<div class="msg error">' .
|
||||
sprintf(
|
||||
$this->getLang('wrong_folder'),
|
||||
|
@ -325,22 +346,22 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
) .
|
||||
'</div>';
|
||||
}
|
||||
if(($securityissue = $extension->getSecurityIssue()) !== false) {
|
||||
if (($securityissue = $extension->getSecurityIssue()) !== false) {
|
||||
$return .= '<div class="msg error">'.
|
||||
sprintf($this->getLang('security_issue'), '<bdi>'.hsc($securityissue).'</bdi>').
|
||||
'</div>';
|
||||
}
|
||||
if(($securitywarning = $extension->getSecurityWarning()) !== false) {
|
||||
if (($securitywarning = $extension->getSecurityWarning()) !== false) {
|
||||
$return .= '<div class="msg notify">'.
|
||||
sprintf($this->getLang('security_warning'), '<bdi>'.hsc($securitywarning).'</bdi>').
|
||||
'</div>';
|
||||
}
|
||||
if($extension->updateAvailable()) {
|
||||
if ($extension->updateAvailable()) {
|
||||
$return .= '<div class="msg notify">'.
|
||||
sprintf($this->getLang('update_available'), hsc($extension->getLastUpdate())).
|
||||
'</div>';
|
||||
}
|
||||
if($extension->hasDownloadURLChanged()) {
|
||||
if ($extension->hasDownloadURLChanged()) {
|
||||
$return .= '<div class="msg notify">' .
|
||||
sprintf(
|
||||
$this->getLang('url_change'),
|
||||
|
@ -360,13 +381,14 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param string $url
|
||||
* @return string HTML link
|
||||
*/
|
||||
public function shortlink($url){
|
||||
public function shortlink($url)
|
||||
{
|
||||
$link = parse_url($url);
|
||||
|
||||
$base = $link['host'];
|
||||
if(!empty($link['port'])) $base .= $base.':'.$link['port'];
|
||||
if (!empty($link['port'])) $base .= $base.':'.$link['port'];
|
||||
$long = $link['path'];
|
||||
if(!empty($link['query'])) $long .= $link['query'];
|
||||
if (!empty($link['query'])) $long .= $link['query'];
|
||||
|
||||
$name = shorten($base, $long, 55);
|
||||
|
||||
|
@ -379,12 +401,13 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param helper_plugin_extension_extension $extension The extension
|
||||
* @return string The HTML code
|
||||
*/
|
||||
public function make_info(helper_plugin_extension_extension $extension) {
|
||||
public function makeInfo(helper_plugin_extension_extension $extension)
|
||||
{
|
||||
$default = $this->getLang('unknown');
|
||||
$return = '<dl class="details">';
|
||||
|
||||
$return .= '<dt>'.$this->getLang('status').'</dt>';
|
||||
$return .= '<dd>'.$this->make_status($extension).'</dd>';
|
||||
$return .= '<dd>'.$this->makeStatus($extension).'</dd>';
|
||||
|
||||
if ($extension->getDonationURL()) {
|
||||
$return .= '<dt>'.$this->getLang('donate').'</dt>';
|
||||
|
@ -432,7 +455,7 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
$return .= ($extension->getTypes() ? hsc(implode(', ', $extension->getTypes())) : $default);
|
||||
$return .= '</bdi></dd>';
|
||||
|
||||
if(!$extension->isBundled() && $extension->getCompatibleVersions()) {
|
||||
if (!$extension->isBundled() && $extension->getCompatibleVersions()) {
|
||||
$return .= '<dt>'.$this->getLang('compatible').'</dt>';
|
||||
$return .= '<dd>';
|
||||
foreach ($extension->getCompatibleVersions() as $date => $version) {
|
||||
|
@ -441,24 +464,24 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
$return = rtrim($return, ', ');
|
||||
$return .= '</dd>';
|
||||
}
|
||||
if($extension->getDependencies()) {
|
||||
if ($extension->getDependencies()) {
|
||||
$return .= '<dt>'.$this->getLang('depends').'</dt>';
|
||||
$return .= '<dd>';
|
||||
$return .= $this->make_linklist($extension->getDependencies());
|
||||
$return .= $this->makeLinkList($extension->getDependencies());
|
||||
$return .= '</dd>';
|
||||
}
|
||||
|
||||
if($extension->getSimilarExtensions()) {
|
||||
if ($extension->getSimilarExtensions()) {
|
||||
$return .= '<dt>'.$this->getLang('similar').'</dt>';
|
||||
$return .= '<dd>';
|
||||
$return .= $this->make_linklist($extension->getSimilarExtensions());
|
||||
$return .= $this->makeLinkList($extension->getSimilarExtensions());
|
||||
$return .= '</dd>';
|
||||
}
|
||||
|
||||
if($extension->getConflicts()) {
|
||||
if ($extension->getConflicts()) {
|
||||
$return .= '<dt>'.$this->getLang('conflicts').'</dt>';
|
||||
$return .= '<dd>';
|
||||
$return .= $this->make_linklist($extension->getConflicts());
|
||||
$return .= $this->makeLinkList($extension->getConflicts());
|
||||
$return .= '</dd>';
|
||||
}
|
||||
$return .= '</dl>'.DOKU_LF;
|
||||
|
@ -471,7 +494,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param array $ext The extensions
|
||||
* @return string The HTML code
|
||||
*/
|
||||
public function make_linklist($ext) {
|
||||
public function makeLinkList($ext)
|
||||
{
|
||||
$return = '';
|
||||
foreach ($ext as $link) {
|
||||
$return .= '<bdi><a href="'.
|
||||
|
@ -486,7 +510,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param helper_plugin_extension_extension $extension The extension
|
||||
* @return string The HTML code
|
||||
*/
|
||||
public function make_actions(helper_plugin_extension_extension $extension) {
|
||||
public function makeActions(helper_plugin_extension_extension $extension)
|
||||
{
|
||||
global $conf;
|
||||
$return = '';
|
||||
$errors = '';
|
||||
|
@ -494,45 +519,43 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
if ($extension->isInstalled()) {
|
||||
if (($canmod = $extension->canModify()) === true) {
|
||||
if (!$extension->isProtected()) {
|
||||
$return .= $this->make_action('uninstall', $extension);
|
||||
$return .= $this->makeAction('uninstall', $extension);
|
||||
}
|
||||
if ($extension->getDownloadURL()) {
|
||||
if ($extension->updateAvailable()) {
|
||||
$return .= $this->make_action('update', $extension);
|
||||
$return .= $this->makeAction('update', $extension);
|
||||
} else {
|
||||
$return .= $this->make_action('reinstall', $extension);
|
||||
$return .= $this->makeAction('reinstall', $extension);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$errors .= '<p class="permerror">'.$this->getLang($canmod).'</p>';
|
||||
}
|
||||
|
||||
if (!$extension->isProtected() && !$extension->isTemplate()) { // no enable/disable for templates
|
||||
if ($extension->isEnabled()) {
|
||||
$return .= $this->make_action('disable', $extension);
|
||||
$return .= $this->makeAction('disable', $extension);
|
||||
} else {
|
||||
$return .= $this->make_action('enable', $extension);
|
||||
$return .= $this->makeAction('enable', $extension);
|
||||
}
|
||||
}
|
||||
|
||||
if ($extension->isGitControlled()){
|
||||
if ($extension->isGitControlled()) {
|
||||
$errors .= '<p class="permerror">'.$this->getLang('git').'</p>';
|
||||
}
|
||||
|
||||
if (
|
||||
$extension->isEnabled() &&
|
||||
if ($extension->isEnabled() &&
|
||||
in_array('Auth', $extension->getTypes()) &&
|
||||
$conf['authtype'] != $extension->getID()
|
||||
) {
|
||||
$errors .= '<p class="permerror">'.$this->getLang('auth').'</p>';
|
||||
}
|
||||
|
||||
}else{
|
||||
} else {
|
||||
if (($canmod = $extension->canModify()) === true) {
|
||||
if ($extension->getDownloadURL()) {
|
||||
$return .= $this->make_action('install', $extension);
|
||||
$return .= $this->makeAction('install', $extension);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$errors .= '<div class="permerror">'.$this->getLang($canmod).'</div>';
|
||||
}
|
||||
}
|
||||
|
@ -554,7 +577,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param helper_plugin_extension_extension $extension The extension
|
||||
* @return string The HTML code
|
||||
*/
|
||||
public function make_action($action, $extension) {
|
||||
public function makeAction($action, $extension)
|
||||
{
|
||||
$title = '';
|
||||
|
||||
switch ($action) {
|
||||
|
@ -577,7 +601,8 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
* @param helper_plugin_extension_extension $extension The extension
|
||||
* @return string The description of all relevant statusses
|
||||
*/
|
||||
public function make_status(helper_plugin_extension_extension $extension) {
|
||||
public function makeStatus(helper_plugin_extension_extension $extension)
|
||||
{
|
||||
$status = array();
|
||||
|
||||
|
||||
|
@ -593,10 +618,9 @@ class helper_plugin_extension_list extends DokuWiki_Plugin {
|
|||
} else {
|
||||
$status[] = $this->getLang('status_not_installed');
|
||||
}
|
||||
if(!$extension->canModify()) $status[] = $this->getLang('status_unmodifiable');
|
||||
if($extension->isBundled()) $status[] = $this->getLang('status_bundled');
|
||||
if (!$extension->canModify()) $status[] = $this->getLang('status_unmodifiable');
|
||||
if ($extension->isBundled()) $status[] = $this->getLang('status_bundled');
|
||||
$status[] = $extension->isTemplate() ? $this->getLang('status_template') : $this->getLang('status_plugin');
|
||||
return join(', ', $status);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,21 +6,22 @@
|
|||
* @author Michael Hamann <michael@content-space.de>
|
||||
*/
|
||||
|
||||
#define('EXTENSION_REPOSITORY_API', 'http://localhost/dokuwiki/lib/plugins/pluginrepo/api.php');
|
||||
|
||||
if (!defined('EXTENSION_REPOSITORY_API_ENDPOINT'))
|
||||
define('EXTENSION_REPOSITORY_API', 'http://www.dokuwiki.org/lib/plugins/pluginrepo/api.php');
|
||||
|
||||
/**
|
||||
* Class helper_plugin_extension_repository provides access to the extension repository on dokuwiki.org
|
||||
*/
|
||||
class helper_plugin_extension_repository extends DokuWiki_Plugin {
|
||||
class helper_plugin_extension_repository extends DokuWiki_Plugin
|
||||
{
|
||||
|
||||
const EXTENSION_REPOSITORY_API = 'http://www.dokuwiki.org/lib/plugins/pluginrepo/api.php';
|
||||
|
||||
private $loaded_extensions = array();
|
||||
private $has_access = null;
|
||||
|
||||
/**
|
||||
* Initialize the repository (cache), fetches data for all installed plugins
|
||||
*/
|
||||
public function init() {
|
||||
public function init()
|
||||
{
|
||||
/* @var Doku_Plugin_Controller $plugin_controller */
|
||||
global $plugin_controller;
|
||||
if ($this->hasAccess()) {
|
||||
|
@ -30,8 +31,7 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin {
|
|||
foreach ($list as $name) {
|
||||
$cache = new cache('##extension_manager##'.$name, '.repo');
|
||||
|
||||
if(
|
||||
!isset($this->loaded_extensions[$name]) &&
|
||||
if (!isset($this->loaded_extensions[$name]) &&
|
||||
$this->hasAccess() &&
|
||||
!$cache->useCache(array('age' => 3600 * 24))
|
||||
) {
|
||||
|
@ -43,7 +43,7 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin {
|
|||
|
||||
if ($request_needed) {
|
||||
$httpclient = new DokuHTTPClient();
|
||||
$data = $httpclient->post(EXTENSION_REPOSITORY_API, $request_data);
|
||||
$data = $httpclient->post(self::EXTENSION_REPOSITORY_API, $request_data);
|
||||
if ($data !== false) {
|
||||
$extensions = unserialize($data);
|
||||
foreach ($extensions as $extension) {
|
||||
|
@ -62,14 +62,15 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin {
|
|||
*
|
||||
* @return bool If repository access is available
|
||||
*/
|
||||
public function hasAccess() {
|
||||
public function hasAccess()
|
||||
{
|
||||
if ($this->has_access === null) {
|
||||
$cache = new cache('##extension_manager###hasAccess', '.repo');
|
||||
|
||||
if (!$cache->useCache(array('age' => 3600 * 24, 'purge'=>1))) {
|
||||
$httpclient = new DokuHTTPClient();
|
||||
$httpclient->timeout = 5;
|
||||
$data = $httpclient->get(EXTENSION_REPOSITORY_API.'?cmd=ping');
|
||||
$data = $httpclient->get(self::EXTENSION_REPOSITORY_API.'?cmd=ping');
|
||||
if ($data !== false) {
|
||||
$this->has_access = true;
|
||||
$cache->storeCache(1);
|
||||
|
@ -90,17 +91,17 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin {
|
|||
* @param string $name The plugin name to get the data for, template names need to be prefix by 'template:'
|
||||
* @return array The data or null if nothing was found (possibly no repository access)
|
||||
*/
|
||||
public function getData($name) {
|
||||
public function getData($name)
|
||||
{
|
||||
$cache = new cache('##extension_manager##'.$name, '.repo');
|
||||
|
||||
if(
|
||||
!isset($this->loaded_extensions[$name]) &&
|
||||
if (!isset($this->loaded_extensions[$name]) &&
|
||||
$this->hasAccess() &&
|
||||
!$cache->useCache(array('age' => 3600 * 24))
|
||||
) {
|
||||
$this->loaded_extensions[$name] = true;
|
||||
$httpclient = new DokuHTTPClient();
|
||||
$data = $httpclient->get(EXTENSION_REPOSITORY_API.'?fmt=php&ext[]='.urlencode($name));
|
||||
$data = $httpclient->get(self::EXTENSION_REPOSITORY_API.'?fmt=php&ext[]='.urlencode($name));
|
||||
if ($data !== false) {
|
||||
$result = unserialize($data);
|
||||
$cache->storeCache(serialize($result[0]));
|
||||
|
@ -121,19 +122,20 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin {
|
|||
* @param string $q the query string
|
||||
* @return array a list of matching extensions
|
||||
*/
|
||||
public function search($q){
|
||||
$query = $this->parse_query($q);
|
||||
public function search($q)
|
||||
{
|
||||
$query = $this->parseQuery($q);
|
||||
$query['fmt'] = 'php';
|
||||
|
||||
$httpclient = new DokuHTTPClient();
|
||||
$data = $httpclient->post(EXTENSION_REPOSITORY_API, $query);
|
||||
$data = $httpclient->post(self::EXTENSION_REPOSITORY_API, $query);
|
||||
if ($data === false) return array();
|
||||
$result = unserialize($data);
|
||||
|
||||
$ids = array();
|
||||
|
||||
// store cache info for each extension
|
||||
foreach($result as $ext){
|
||||
foreach ($result as $ext) {
|
||||
$name = $ext['plugin'];
|
||||
$cache = new cache('##extension_manager##'.$name, '.repo');
|
||||
$cache->storeCache(serialize($ext));
|
||||
|
@ -149,7 +151,8 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin {
|
|||
* @param string $q
|
||||
* @return array
|
||||
*/
|
||||
protected function parse_query($q){
|
||||
protected function parseQuery($q)
|
||||
{
|
||||
$parameters = array(
|
||||
'tag' => array(),
|
||||
'mail' => array(),
|
||||
|
@ -158,29 +161,29 @@ class helper_plugin_extension_repository extends DokuWiki_Plugin {
|
|||
);
|
||||
|
||||
// extract tags
|
||||
if(preg_match_all('/(^|\s)(tag:([\S]+))/', $q, $matches, PREG_SET_ORDER)){
|
||||
foreach($matches as $m){
|
||||
if (preg_match_all('/(^|\s)(tag:([\S]+))/', $q, $matches, PREG_SET_ORDER)) {
|
||||
foreach ($matches as $m) {
|
||||
$q = str_replace($m[2], '', $q);
|
||||
$parameters['tag'][] = $m[3];
|
||||
}
|
||||
}
|
||||
// extract author ids
|
||||
if(preg_match_all('/(^|\s)(authorid:([\S]+))/', $q, $matches, PREG_SET_ORDER)){
|
||||
foreach($matches as $m){
|
||||
if (preg_match_all('/(^|\s)(authorid:([\S]+))/', $q, $matches, PREG_SET_ORDER)) {
|
||||
foreach ($matches as $m) {
|
||||
$q = str_replace($m[2], '', $q);
|
||||
$parameters['mail'][] = $m[3];
|
||||
}
|
||||
}
|
||||
// extract extensions
|
||||
if(preg_match_all('/(^|\s)(ext:([\S]+))/', $q, $matches, PREG_SET_ORDER)){
|
||||
foreach($matches as $m){
|
||||
if (preg_match_all('/(^|\s)(ext:([\S]+))/', $q, $matches, PREG_SET_ORDER)) {
|
||||
foreach ($matches as $m) {
|
||||
$q = str_replace($m[2], '', $q);
|
||||
$parameters['ext'][] = $m[3];
|
||||
}
|
||||
}
|
||||
// extract types
|
||||
if(preg_match_all('/(^|\s)(type:([\S]+))/', $q, $matches, PREG_SET_ORDER)){
|
||||
foreach($matches as $m){
|
||||
if (preg_match_all('/(^|\s)(type:([\S]+))/', $q, $matches, PREG_SET_ORDER)) {
|
||||
foreach ($matches as $m) {
|
||||
$q = str_replace($m[2], '', $q);
|
||||
$parameters['type'][] = $m[3];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue