Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Commit

Permalink
Merge branch 'TJG/BT-43' into 'release/1.0.0'
Browse files Browse the repository at this point in the history
TJG/BT-43

See merge request open-source/dokuwiki/backup!40
  • Loading branch information
tatewake committed Sep 14, 2020
2 parents 1914d9d + f5f21da commit cbf246a
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 186 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.php_cs.cache
129 changes: 68 additions & 61 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,25 @@ class admin_plugin_backup extends DokuWiki_Admin_Plugin
protected $prefFile = DOKU_CONF . 'backup.json';
protected $filters = null;

protected function isRunningWindows()
{
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false;
}

function btRemoveFiles($dir, $startString) {
if (is_dir($dir))
{
$objects = scandir($dir);

foreach ($objects as $object)
{
if ($object != "." && $object != ".." && substr($object, 0, strlen($startString)) === $startString)
{
if (!is_dir($dir. DIRECTORY_SEPARATOR .$object) || is_link($dir."/".$object))
{
unlink($dir. DIRECTORY_SEPARATOR .$object);
}
}
}
}
}
protected function isRunningWindows()
{
return (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? true : false;
}

public function btRemoveFiles($dir, $startString)
{
if (is_dir($dir)) {
$objects = scandir($dir);

foreach ($objects as $object) {
if ($object != "." && $object != ".." && substr($object, 0, strlen($startString)) === $startString) {
if (!is_dir($dir. DIRECTORY_SEPARATOR .$object) || is_link($dir."/".$object)) {
unlink($dir. DIRECTORY_SEPARATOR .$object);
}
}
}
}
}

/** @inheritdoc */
public function handle()
Expand All @@ -57,39 +54,35 @@ public function html()
echo '<div class="plugin_backup">';

if ($INPUT->post->bool('backup')) {
$this->removeMediaAtticBackups();
$this->removeMediaAtticBackups();
$this->runBackup();
} else {
echo '<h1>' . $this->getLang('menu') . '</h1>';

if ($this->isRunningWindows())
{
msg($this->getLang('windows-msg'), 2);
}

if ($this->isRunningWindows())
{
echo '<div class="bt-warning" style="display: block;">';
echo $this->locale_xhtml('windows');
echo '<button type="button" class="collapsible">I understand</button>';
echo '</div>';

echo '<div class="bt-content" style="display: none;">';
}
else
{
echo '<div>';
}
if ($this->isRunningWindows()) {
msg($this->getLang('windows-msg'), 2);
}

if ($this->isRunningWindows()) {
echo '<div class="bt-warning" style="display: block;">';
echo $this->locale_xhtml('windows');
echo '<button type="button" class="collapsible">I understand</button>';
echo '</div>';

echo '<div class="bt-content" style="display: none;">';
} else {
echo '<div>';
}

echo $this->locale_xhtml('intro');

echo $this->getForm();

$this->listBackups();

echo $this->locale_xhtml('donate');
echo '</div>';
}
echo $this->locale_xhtml('donate');
echo '</div>';
}

echo '</div>';
}
Expand Down Expand Up @@ -130,16 +123,15 @@ protected function listBackups()

protected function removeMediaAtticBackups()
{
try
{
global $conf;
try {
global $conf;

$self = fullpath(dirname(mediaFN($this->getConf('backupnamespace') . ':foo')));
$targetdir = $conf['mediaolddir'] . '/' . $this->stripPrefix($self, fullpath(dirname(mediaFN($conf['savedir']))));
$self = fullpath(dirname(mediaFN($this->getConf('backupnamespace') . ':foo')));
$targetdir = $conf['mediaolddir'] . '/' . $this->stripPrefix($self, fullpath(dirname(mediaFN($conf['savedir']))));

$this->btRemoveFiles($targetdir, 'dw-backup-');
}
catch (Exception $e) { }
$this->btRemoveFiles($targetdir, 'dw-backup-');
} catch (Exception $e) {
}
}

/**
Expand Down Expand Up @@ -209,11 +201,15 @@ protected function getForm()
$prefs = $this->loadPreferences();
foreach ($prefs as $pref => $val) {
$label = $this->getLang('bt_' . $pref);
if (!$label) continue; // unknown pref, skip it
if (!$label) {
continue;
} // unknown pref, skip it

$form->setHiddenField("pref[$pref]", '0');
$cb = $form->addCheckbox("pref[$pref]", $label)->useInput(false)->addClass('block');
if ($val) $cb->attr('checked', 'checked');
if ($val) {
$cb->attr('checked', 'checked');
}
}

$form->addButton('backup', $this->getLang('bt_create_backup'));
Expand Down Expand Up @@ -290,7 +286,9 @@ protected function createBackup($fn, $prefs, $logger)
$tar->create($fn);

foreach ($prefs as $pref => $val) {
if (!$val) continue;
if (!$val) {
continue;
}

$cmd = [$this, 'backup' . ucfirst($pref)];
if (is_callable($cmd)) {
Expand Down Expand Up @@ -325,10 +323,16 @@ protected function addDirectoryToTar(Tar $tar, $dir, $as, $logger = null, $filte
$file = $as . '/' . $file;

// custom filter:
if ($filter !== null && !$filter($file)) continue;
if (!$this->defaultFilter($file)) continue;
if ($filter !== null && !$filter($file)) {
continue;
}
if (!$this->defaultFilter($file)) {
continue;
}

if ($logger !== null) $logger($file);
if ($logger !== null) {
$logger($file);
}
$tar->addFile($path, $file);
}
}
Expand All @@ -349,10 +353,14 @@ protected function defaultFilter($path)
$this->filters = array_filter($this->filters);
}

if (strpos($path, '/.git') !== false) return false;
if (strpos($path, '/.git') !== false) {
return false;
}

foreach ($this->filters as $filter) {
if (strpos($path, $filter) === 0) return false;
if (strpos($path, $filter) === 0) {
return false;
}
}

return true;
Expand Down Expand Up @@ -534,5 +542,4 @@ protected function backupPlugins(Tar $tar, $logger)
}

// endregion

}
1 change: 0 additions & 1 deletion lang/de/donate.txt

This file was deleted.

16 changes: 0 additions & 16 deletions lang/de/intro.txt

This file was deleted.

20 changes: 0 additions & 20 deletions lang/de/lang.php

This file was deleted.

4 changes: 0 additions & 4 deletions lang/de/settings.php

This file was deleted.

1 change: 0 additions & 1 deletion lang/fr/donate.txt

This file was deleted.

12 changes: 0 additions & 12 deletions lang/fr/intro.txt

This file was deleted.

21 changes: 0 additions & 21 deletions lang/fr/lang.php

This file was deleted.

4 changes: 0 additions & 4 deletions lang/fr/settings.php

This file was deleted.

17 changes: 0 additions & 17 deletions lang/ja/intro.txt

This file was deleted.

16 changes: 0 additions & 16 deletions lang/ja/lang.php

This file was deleted.

3 changes: 0 additions & 3 deletions lang/ja/settings.php

This file was deleted.

18 changes: 8 additions & 10 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ var plugin_backup = {
timer: null,
$log: null,

start: function () {
start: function() {
plugin_backup.$log = jQuery('.plugin_backup .log');
plugin_backup.timer = window.setInterval(function () {
plugin_backup.timer = window.setInterval(function() {
plugin_backup.$log.scrollTop(plugin_backup.$log[0].scrollHeight);
}, 100);
},

stop: function () {
stop: function() {
if (plugin_backup.timer) {
window.clearInterval(plugin_backup.timer);
plugin_backup.timer = null;
Expand All @@ -20,11 +20,9 @@ var plugin_backup = {
};

var btColl = document.getElementsByClassName("collapsible");
for (var btIter = 0; btIter < btColl.length; i++)
{
btColl[btIter].addEventListener("click", function()
{
document.getElementsByClassName('bt-content')[0].style.display='block';
document.getElementsByClassName('bt-warning')[0].style.display='none';
});
for (var btIter = 0; btIter < btColl.length; i++) {
btColl[btIter].addEventListener("click", function() {
document.getElementsByClassName('bt-content')[0].style.display = 'block';
document.getElementsByClassName('bt-warning')[0].style.display = 'none';
});
}

0 comments on commit cbf246a

Please sign in to comment.