xref: /plugin/spatialhelper/admin/purge.php (revision 9fe665eafd0d05e64d58de3106d311e5f4af1841)
1<?php
2
3use dokuwiki\Extension\AdminPlugin;
4
5/*
6 * Copyright (c) 2014 Mark C. Prins <mprins@users.sf.net>
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 */
20/**
21 * DokuWiki Plugin spatialhelper (Admin Component).
22 * This component purges and recreates the spatial index and sitemaps.
23 *
24 * @author Mark Prins
25 */
26class admin_plugin_spatialhelper_purge extends AdminPlugin
27{
28    /**
29     *
30     * @see DokuWiki_Admin_Plugin::getMenuSort()
31     */
32    public function getMenuSort(): int
33    {
34        return 801;
35    }
36
37    public function getMenuIcon(): string
38    {
39        $plugin = $this->getPluginName();
40        return DOKU_PLUGIN . $plugin . '/admin/purge.svg';
41    }
42
43    /**
44     * purge and regenerate the index and sitemaps.
45     *
46     * @see DokuWiki_Admin_Plugin::handle()
47     */
48    public function handle(): void
49    {
50        if (isset($_REQUEST ['purgeindex'])) {
51            global $conf;
52            $path = $conf ['indexdir'] . '/spatial.idx';
53            if (file_exists($path) && unlink($path)) {
54                msg($this->getLang('admin_purged_tiles'), 0);
55            }
56        }
57
58        $indexer = plugin_load('helper', 'spatialhelper_index');
59        $indexer->generateSpatialIndex();
60
61        $sitemapper = plugin_load('helper', 'spatialhelper_sitemap');
62        $sitemapper->createKMLSitemap($this->getConf('media_kml'));
63        $sitemapper->createGeoRSSSitemap($this->getConf('media_georss'));
64    }
65
66    /**
67     * render the form for this plugin.
68     *
69     * @see DokuWiki_Admin_Plugin::html()
70     */
71    public function html(): void
72    {
73        echo $this->locale_xhtml('admin_purge_intro');
74
75        $form = new Doku_Form(
76            ['id'     => 'spatialhelper__purgeform', 'method' => 'post']
77        );
78        $form->addHidden('purgeindex', 'true');
79
80        $form->addElement(
81            form_makeButton(
82                'submit',
83                'admin',
84                $this->getLang('admin_submit'),
85                ['title' => $this->getLang('admin_submit')]
86            )
87        );
88        $form->printForm();
89    }
90}
91