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