Issues (93)

admin/purge.php (7 issues)

Labels
Severity
1
<?php
2
3
/*
4
 * Copyright (c) 2008-2023 Mark C. Prins <[email protected]>
5
 *
6
 * Permission to use, copy, modify, and distribute this software for any
7
 * purpose with or without fee is hereby granted, provided that the above
8
 * copyright notice and this permission notice appear in all copies.
9
 *
10
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
 *
18
 * @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
19
 */
20
use dokuwiki\Extension\AdminPlugin;
0 ignored issues
show
The type dokuwiki\Extension\AdminPlugin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use dokuwiki\Logger;
0 ignored issues
show
The type dokuwiki\Logger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
/**
24
 * DokuWiki Plugin openlayersmap (Admin Component).
25
 * This component purges the cached tiles and maps.
26
 *
27
 * @author Mark Prins
28
 */
29
class admin_plugin_openlayersmap_purge extends AdminPlugin
30
{
31
    /**
32
     * (non-PHPdoc)
33
     * @see DokuWiki_Admin_Plugin::getMenuSort()
34
     */
35
    public function getMenuSort(): int
36
    {
37
        return 800;
38
    }
39
40
    public function getMenuIcon(): string
41
    {
42
        $plugin = $this->getPluginName();
43
        return DOKU_PLUGIN . $plugin . '/admin/purge.svg';
0 ignored issues
show
The constant DOKU_PLUGIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
44
    }
45
46
    /**
47
     * (non-PHPdoc)
48
     * @see DokuWiki_Admin_Plugin::handle()
49
     */
50
    public function handle(): void
51
    {
52
        global $conf;
53
        if (!isset($_REQUEST['continue']) || !checkSecurityToken()) {
0 ignored issues
show
The function checkSecurityToken was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        if (!isset($_REQUEST['continue']) || !/** @scrutinizer ignore-call */ checkSecurityToken()) {
Loading history...
54
            return;
55
        }
56
        if (isset($_REQUEST['purgetiles'])) {
57
            $path = $conf['cachedir'] . '/olmaptiles';
58
            if ($this->rrmdir($path)) {
59
                msg($this->getLang('admin_purged_tiles'), 0);
0 ignored issues
show
The function msg was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
                /** @scrutinizer ignore-call */ 
60
                msg($this->getLang('admin_purged_tiles'), 0);
Loading history...
60
            }
61
        }
62
        if (isset($_REQUEST['purgemaps'])) {
63
            $path = $conf['mediadir'] . '/olmapmaps';
64
            if ($this->rrmdir($path)) {
65
                msg($this->getLang('admin_purged_maps'), 0);
66
            }
67
        }
68
    }
69
70
    /**
71
     * Recursively delete the directory.
72
     * @param string $sDir directory path
73
     * @return boolean true when succesful
74
     */
75
    private function rrmdir(string $sDir): bool
76
    {
77
        if (is_dir($sDir)) {
78
            Logger::debug('admin_plugin_openlayersmap_purge::rrmdir: recursively removing path: ', $sDir);
79
            $sDir = rtrim($sDir, '/');
80
            $oDir = dir($sDir);
81
            while (($sFile = $oDir->read()) !== false) {
82
                if ($sFile !== '.' && $sFile !== '..') {
83
                    (!is_link("$sDir/$sFile") && is_dir("$sDir/$sFile")) ?
84
                        $this->rrmdir("$sDir/$sFile") : unlink("$sDir/$sFile");
85
                }
86
            }
87
            $oDir->close();
88
            rmdir($sDir);
89
            return true;
90
        }
91
        return false;
92
    }
93
94
    /**
95
     * (non-PHPdoc)
96
     * @see DokuWiki_Admin_Plugin::html()
97
     */
98
    public function html(): void
99
    {
100
        echo $this->locale_xhtml('admin_intro');
101
        $form = new Doku_Form(['id' => 'olmap_purgeform', 'method' => 'post']);
0 ignored issues
show
The type Doku_Form was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
102
        $form->addHidden('continue', 'go');
103
104
        $form->startFieldset($this->getLang('admin_tiles'));
105
        $form->addElement('<p>');
106
        $form->addElement(
107
            '<input id="purgetiles" name="purgetiles" type="checkbox" value="1" class="checkbox" />'
108
        );
109
        $form->addElement(
110
            '<label for="purgetiles" class="label">' . $this->getLang('admin_purge_tiles')
111
            . '</label>'
112
        );
113
        $form->addElement('</p>');
114
        $form->endFieldset();
115
116
        $form->startFieldset($this->getLang('admin_maps'));
117
        $form->addElement('<p>');
118
        $form->addElement('<input id="purgemaps" name="purgemaps" type="checkbox" value="1" class="checkbox" />');
119
        $form->addElement(
120
            '<label for="purgemaps" class="label">' . $this->getLang('admin_purge_maps') . '</label>'
121
        );
122
        $form->addElement('</p>');
123
        $form->endFieldset();
124
125
        $form->addElement(
126
            form_makeButton(
0 ignored issues
show
The function form_makeButton was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

126
            /** @scrutinizer ignore-call */ 
127
            form_makeButton(
Loading history...
127
                'submit',
128
                'admin',
129
                $this->getLang('admin_submit'),
130
                ['accesskey' => 'p', 'title' => $this->getLang('admin_submit')]
131
            )
132
        );
133
        $form->printForm();
134
    }
135
}
136