This repository has been archived on 2024-01-12. You can view files and clone it, but cannot push or open issues or pull requests.
WolKal3000/wolkal3000-admin.php

203 lines
8.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
require_once dirname( __FILE__ ) . "/wolkal3000-config.php";
/**
* Display the admin table
*
* @since 0.1.0
*
*/
/*
* Quellen:
* https://codex.wordpress.org/Creating_Options_Pages
* http://ottopress.com/2009/wordpress-settings-api-tutorial/
*/
add_action('admin_menu', 'wolkal3000_admin_add_page');
function wolkal3000_admin_add_page() {
add_options_page( 'WolKal3000 Synchronisation von Kal3000 mit Wolke-Kalendern', 'WolKal3000', 'manage_options', 'wolkal3000', 'wolkal3000_options_page');
}
function wolkal3000_options_page() {
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
if ( !defined('WOLKAL_PREFIX') ) {
wp_die( __( 'WOLKAL_PREFIX is not configured in wolkal3000-config.php, please check the installation steps!' ) );
}
if ( !file_exists(__DIR__ . '/icalparser/src/IcalParser.php')) {
wp_die( __( 'icalparser is not properly installed, please check the installation steps!' ) );
}
?>
<div class="wrap">
<h1><?= esc_html(get_admin_page_title()); ?></h1>
<p>Mit WolKal3000 kannst du dein Kal3000-Plugin automatisch mit Kalendern in der grünen Wolke synchronisieren.</p>
<form action="options.php" method="post">
<?php settings_fields('wolkal3000_options'); ?>
<?php do_settings_sections('wolkal3000'); ?>
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
</br></br></br><hr></br>
<?php do_settings_sections('wolkal3000_adv'); ?>
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
</form></div>
<?php
}
add_action('admin_init', 'wolkal3000_admin_init');
function wolkal3000_admin_init(){
register_setting( 'wolkal3000_options', 'wolkal3000_options', 'wolkal3000_options_validate' );
add_settings_section('wolkal3000_feeds', 'Wolke-Kalender einer Terminkategorie zuordnen', 'wolkal3000_feeds_section_text', 'wolkal3000');
// settings fields dynamisch pro Feed generieren, nur ein Callback mit Args nutzen.
$terms = get_terms( array(
'taxonomy' => 'termine_type',
'hide_empty' => false, )
);
foreach($terms as $term){
$unique_id = 'wolkal3000_feed_' . $term->name;
$feed_name = $term->name;
add_settings_field($unique_id, 'Terminkategorie "'.$feed_name.'"', 'wolkal3000_feeds_setting_string', 'wolkal3000', 'wolkal3000_feeds', array($unique_id));
}
add_settings_section('wolkal3000_timer', 'Synchronisationsintervall', 'wolkal3000_timer_section_text', 'wolkal3000');
add_settings_field('wolkal3000_timer', 'Synchronisiere alle …', 'wolkal3000_timer_setting_string', 'wolkal3000', 'wolkal3000_timer');
add_settings_section('wolkal3000_geocoding', 'Geocoding (EXPERIMENTELL)', 'wolkal3000_geocoding_section_text', 'wolkal3000_adv');
add_settings_field('wolkal3000_geocoding', 'Geocoding-Methode', 'wolkal3000_geocoding_setting_string', 'wolkal3000_adv', 'wolkal3000_geocoding');
add_settings_section('wolkal3000_debugging', 'Entwickler*innenoptionen', 'wolkal3000_debugging_section_text', 'wolkal3000_adv');
add_settings_field('wolkal3000_debugging', 'Debugging', 'wolkal3000_debugging_setting_string', 'wolkal3000_adv', 'wolkal3000_debugging');
}
function wolkal3000_feeds_section_text() {
?>
<p><b>Wolke-Kalender synchronisieren in eine ausgewählte Terminkategorie von Kal3000. Bitte trage hierfür die entsprechende Export-Adresse des gewünschten Wolke-Kalenders ein.</b></br><b>Falls zu einer Terminkategorie kein Wolke-Kalender synchronisiert werden soll, entsprechendes Feld bitte leer lassen.</b></p>
<p><b><a href="https://confluence.netzbegruenung.de/pages/viewpage.action?pageId=40730689" target="_blank">Erfahre mehr darüber, wie du die Export-Adresse eines Wolke-Kalenders findest.</a></b>
</p>
<?php
}
function wolkal3000_feeds_setting_string($args) {
$options = get_option('wolkal3000_options');
$placeholder = "ABCDEFGHIKLMNOPQ";
// die id entspricht dem unique_id in add_settings_field.
// der name wird options.php als Name der zu setzenden Option übergeben
// der Value ist der inhalt von der $option[unique_id].
echo WOLKAL_PREFIX . '<input type="text" id="' . $args[0] . '" name="wolkal3000_options[' . $args[0] . ']" value="' . $options[$args[0]] . '" size="16" maxlength="16" placeholder="' . $placeholder . '" >' . WOLKAL_SUFFIX . '</br>';
}
function wolkal3000_timer_section_text() {
?>
<p><b>In welcher Regelmäßigkeit sollen die Wolke-Kalender synchronisiert werden? Bitte Zeitintervall in Minuten angeben.</b></br>
<b>Achtung: Um Änderungen wirksam werden zu lassen, muss das Plugin deaktiviert und wieder aktiviert werden. (Menüpunkt "Plugins")</b></p>
<?php
}
function wolkal3000_timer_setting_string() {
$options = get_option('wolkal3000_options');
$placeholder = "default 60";
echo '<input type="text" id="wolkal3000_timer" name="wolkal3000_options[wolkal3000_timer]" value="' . $options['wolkal3000_timer'] . '" size="6" maxlength="4" placeholder="' . $placeholder . '" > Minuten </br>';
}
function wolkal3000_geocoding_section_text() {
?>
<p>Damit der Termin-Ort auf einer Karte eingezeichnet werden kann, müssen die Ortsinformationen von der Textform in geografische Länge und Breite umgerechnet werden.</br>Dies nennt sich Geocoding. Dabei handelt es sich um eine experimentelle Funktion von WolKal3000.</p>
<?php
}
function wolkal3000_geocoding_setting_string() {
$options = get_option('wolkal3000_options');
$current = ( isset ($options['wolkal3000_geocoding']) ? $options['wolkal3000_geocoding'] : 'off' ); // default off
$coders = array(
array(
'option' => 'off',
'name' => 'deaktiviert',
), /*
array(
'option' => 'official',
'name' => 'Google official - erfordert einen API Key --> ',
),
array(
'option' => 'inofficial',
'name' => 'Google inofficial',
), */
array(
'option' => 'osm',
'name' => 'OpenStreetMap (EXPERIMENTELL)',
),
);
foreach ( $coders as $coder ) {
$checked = ( $current == $coder['option'] ? 'checked' : '' );
echo '<input type="radio" id="wolkal3000_geocoding" name="wolkal3000_options[wolkal3000_geocoding]" value ="' . $coder['option'] . '" ' . $checked . '> ' . $coder['name'];
echo '</br>' ;
}
}
function wolkal3000_debugging_section_text() {
?>
<p>Debugging aktivieren? Speicherort: ${APACHE_LOG_DIR}/error.log</br></br>
Um die Performance zu verbessern, werden gefundene Geocoding-Daten zwischengespeichert. </br>
Zu Debugging-Zwecken kann der Zwischenspeicher (Cache) des Plugins gelöscht </br>
werden, um ein neues Geocoding aller Termin-Orte zu erzwingen. </br>
</p>
<?php
}
function wolkal3000_debugging_setting_string($args) {
$options = get_option('wolkal3000_options');
// example from https://code.tutsplus.com/tutorials/the-wordpress-settings-api-part-8-validation-sanitisation-and-input-i--wp-25361
// echo '<input type="checkbox" id="wolkal3000_debugging" name="wolkal3000_options[wolkal3000_debugging]" value="1"' . checked( 1, $options['wolkal3000_debugging'], false ) . '> Debug-Logging aktivieren </br>';
// let's make a select box:
?>
<select id="wolkal3000_debugging" name="wolkal3000_options[wolkal3000_debugging]">
<option value=0 <?php selected($options['wolkal3000_debugging'], NONE); ?>>off</option>
<option value=1 <?php selected($options['wolkal3000_debugging'], CRIT); ?>>critical</option>
<option value=2 <?php selected($options['wolkal3000_debugging'], WARN); ?>>critical + warnings</option>
<option value=3 <?php selected($options['wolkal3000_debugging'], INFO); ?>>critical + warnings + info</option>
</select> </br>
<?php
// actual logging is done by wolkal3000_error_log()
// Cache reset on restart
echo '</br><input type="checkbox" id="wolkal3000_reset_cache" name="wolkal3000_options[wolkal3000_reset_cache]" value="1"' . checked( 1, $options['wolkal3000_reset_cache'], false ) . '> Geocoding-Cache nach Deaktivieren und Aktivieren des Plugins löschen </br>';}
function wolkal3000_options_validate($input) {
return $input;
// TODO
/*
$newinput['text_string'] = trim($input['text_string']);
if(!preg_match('/^[a-z0-9]{32}$/i', $newinput['text_string'])) {
$newinput['text_string'] = '';
}
return $newinput;
*/
}