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/gcal-import-admin.php

202 lines
8.3 KiB
PHP
Raw Normal View History

2019-03-27 18:12:22 +01:00
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
2019-03-27 21:29:46 +01:00
2019-03-27 13:49:02 +01:00
/**
* Display the admin table
*
* @since 0.1.0
*
*/
2019-03-28 14:38:28 +01:00
/*
* Quellen:
* https://codex.wordpress.org/Creating_Options_Pages
* http://ottopress.com/2009/wordpress-settings-api-tutorial/
*/
2019-03-27 21:29:46 +01:00
add_action('admin_menu', 'gcal_admin_add_page');
function gcal_admin_add_page() {
2020-12-05 18:40:35 +01:00
add_options_page( 'WolKal3000 Synchronisation von Kal3000 mit Wolke-Kalendern', 'WolKal3000', 'manage_options', 'kal3000-gcal-import', 'gcal_options_page');
2019-03-27 21:29:46 +01:00
}
function gcal_options_page() {
2019-03-27 18:12:22 +01:00
if ( !current_user_can( 'manage_options' ) ) {
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
}
?>
2019-03-27 21:29:46 +01:00
<div class="wrap">
<h1><?= esc_html(get_admin_page_title()); ?></h1>
2020-12-05 18:40:35 +01:00
<p>Mit WolKal3000 kannst du dein Kal3000-Plugin automatisch mit Kalendern in der grünen Wolke synchronisieren. Darüber hinaus kannst du jede andere ICS-Datei verwenden.</p>
2019-03-27 21:29:46 +01:00
<form action="options.php" method="post">
<?php settings_fields('gcal_options'); ?>
<?php do_settings_sections('gcal'); ?>
2020-12-05 18:40:35 +01:00
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
</br></br></br><hr></br>
<?php do_settings_sections('gcal2'); ?>
2019-03-27 21:29:46 +01:00
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
</form></div>
<?php
}
add_action('admin_init', 'gcal_admin_init');
function gcal_admin_init(){
register_setting( 'gcal_options', 'gcal_options', 'gcal_options_validate' );
2020-12-05 18:40:35 +01:00
add_settings_section('gcal_feeds', 'Wolke-Kalender einer Terminkategorie zuordnen', 'gcal_feeds_section_text', 'gcal');
2019-03-28 14:38:28 +01:00
// 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 = 'gcal_feed_' . $term->name;
2019-04-06 07:43:00 +02:00
$feed_name = $term->name;
2020-12-05 18:40:35 +01:00
add_settings_field($unique_id, 'Terminkategorie "'.$feed_name.'"', 'gcal_feeds_setting_string', 'gcal', 'gcal_feeds', array($unique_id));
2019-03-28 14:38:28 +01:00
}
2020-12-05 18:40:35 +01:00
add_settings_section('gcal_timer', 'Synchronisationsintervall', 'gcal_timer_section_text', 'gcal');
add_settings_field('gcal_timer', 'Synchronisiere alle …', 'gcal_timer_setting_string', 'gcal', 'gcal_timer');
2019-03-28 14:38:28 +01:00
2020-12-05 18:40:35 +01:00
add_settings_section('gcal_geocoding', 'Geocoding (EXPERIMENTELL)', 'gcal_geocoding_section_text', 'gcal2');
add_settings_field('gcal_geocoding', 'Geocoding-Methode', 'gcal_geocoding_setting_string', 'gcal2', 'gcal_geocoding');
2019-04-08 10:43:28 +02:00
2020-12-05 18:40:35 +01:00
add_settings_section('gcal_debugging', 'Entwickler*innenoptionen', 'gcal_debugging_section_text', 'gcal2');
add_settings_field('gcal_debugging', 'Debugging', 'gcal_debugging_setting_string', 'gcal2', 'gcal_debugging');
2019-03-27 21:29:46 +01:00
}
2019-03-28 14:38:28 +01:00
function gcal_feeds_section_text() {
2019-03-27 21:29:46 +01:00
?>
2020-12-05 18:40:35 +01:00
<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="hilfeseite" target="_blank">Erfahre mehr darüber, wie du die Export-Adresse eines Wolke-Kalenders findest.</a></b>
</p>
2019-03-27 21:29:46 +01:00
<?php
}
2019-03-28 14:38:28 +01:00
function gcal_feeds_setting_string($args) {
$options = get_option('gcal_options');
2020-12-05 18:40:35 +01:00
$placeholder = "z.B. https://wolke.netzbegruenung.de/remote.php/dav/public-calendars/xxxxxxxxxxxxxxxx?export";
2019-03-28 14:38:28 +01:00
// 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 '<input type="text" id="' . $args[0] . '" name="gcal_options[' . $args[0] . ']" value="' . $options[$args[0]] . '" size="80" maxlength="256" placeholder="' . $placeholder . '" > </br>';
}
function gcal_timer_section_text() {
?>
2020-12-05 18:40:35 +01:00
<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>
2019-03-28 14:38:28 +01:00
<?php
}
function gcal_timer_setting_string() {
2019-03-27 21:29:46 +01:00
$options = get_option('gcal_options');
2019-03-28 14:38:28 +01:00
$placeholder = "default 60";
echo '<input type="text" id="gcal_timer" name="gcal_options[gcal_timer]" value="' . $options['gcal_timer'] . '" size="6" maxlength="6" placeholder="' . $placeholder . '" > Minuten </br>';
2019-03-27 21:29:46 +01:00
}
2019-03-28 14:38:28 +01:00
function gcal_geocoding_section_text() {
?>
2020-12-05 18:40:35 +01:00
<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>
2019-03-28 14:38:28 +01:00
<?php
}
function gcal_geocoding_setting_string() {
$options = get_option('gcal_options');
$current = ( isset ($options['gcal_geocoding']) ? $options['gcal_geocoding'] : 'off' ); // default off
2019-03-28 16:30:04 +01:00
$apikey = ( isset ($options['gcal_apikey']) ? $options['gcal_apikey'] : '' ); // default empty
2019-03-28 14:38:28 +01:00
$coders = array(
array(
'option' => 'off',
'name' => 'deaktiviert',
2020-12-05 18:40:35 +01:00
), /*
2019-03-28 14:38:28 +01:00
array(
'option' => 'official',
'name' => 'Google official - erfordert einen API Key --> ',
2019-03-28 14:38:28 +01:00
),
array(
'option' => 'inofficial',
'name' => 'Google inofficial',
2020-12-05 18:40:35 +01:00
), */
2019-03-28 14:38:28 +01:00
array(
'option' => 'osm',
2020-12-05 18:40:35 +01:00
'name' => 'OpenStreetMap (EXPERIMENTELL)',
2019-03-28 14:38:28 +01:00
),
);
foreach ( $coders as $coder ) {
$checked = ( $current == $coder['option'] ? 'checked' : '' );
2019-03-28 16:30:04 +01:00
echo '<input type="radio" id="gcal_geocoding" name="gcal_options[gcal_geocoding]" value ="' . $coder['option'] . '" ' . $checked . '> ' . $coder['name'];
if ( $coder['option'] == 'official' ) {
echo '<input type="text" size="48" id="gcal_geocoding" name="gcal_options[gcal_apikey]" value="' . $apikey . '">';
2019-03-28 16:30:04 +01:00
}
echo '</br>' ;
2019-04-01 15:59:09 +02:00
}
2019-03-28 14:38:28 +01:00
}
2019-04-08 10:43:28 +02:00
function gcal_debugging_section_text() {
?>
2020-12-05 18:40:35 +01:00
<p>Debugging aktivieren? Speicherort: ${APACHE_LOG_DIR}/error.log</br></br>
Um die Performance zu verbessern, werden gefundene Geocoding-Daten zwischengespeichert. </br>
2020-12-05 18:40:35 +01:00
Zu Debugging-Zwecken kann der Zwischenspeicher (Cache) des Plugins gelöscht </br>
werden, um ein neues Geocoding aller Termin-Orte zu erzwingen. </br>
</p>
2019-04-08 10:43:28 +02:00
<?php
}
function gcal_debugging_setting_string($args) {
$options = get_option('gcal_options');
// example from https://code.tutsplus.com/tutorials/the-wordpress-settings-api-part-8-validation-sanitisation-and-input-i--wp-25361
2019-04-09 21:03:35 +02:00
// echo '<input type="checkbox" id="gcal_debugging" name="gcal_options[gcal_debugging]" value="1"' . checked( 1, $options['gcal_debugging'], false ) . '> Debug-Logging aktivieren </br>';
// let's make a select box:
?>
<select id="gcal_debugging" name="gcal_options[gcal_debugging]">
<option value=0 <?php selected($options['gcal_debugging'], NONE); ?>>off</option>
<option value=1 <?php selected($options['gcal_debugging'], CRIT); ?>>critical</option>
<option value=2 <?php selected($options['gcal_debugging'], WARN); ?>>critical + warnings</option>
<option value=3 <?php selected($options['gcal_debugging'], INFO); ?>>critical + warnings + info</option>
</select> </br>
<?php
2019-04-08 10:43:28 +02:00
// actual logging is done by gcal_error_log()
// Cache reset on restart
2020-12-05 18:40:35 +01:00
echo '</br><input type="checkbox" id="gcal_reset_cache" name="gcal_options[gcal_reset_cache]" value="1"' . checked( 1, $options['gcal_reset_cache'], false ) . '> Geocoding-Cache nach Deaktivieren und Aktivieren des Plugins löschen </br>';}
2019-04-08 10:43:28 +02:00
2019-03-28 14:38:28 +01:00
2019-03-27 21:29:46 +01:00
function gcal_options_validate($input) {
2019-03-28 14:38:28 +01:00
return $input;
2019-04-01 15:59:09 +02:00
// TODO
2019-03-28 14:38:28 +01:00
/*
2019-03-27 21:29:46 +01:00
$newinput['text_string'] = trim($input['text_string']);
if(!preg_match('/^[a-z0-9]{32}$/i', $newinput['text_string'])) {
$newinput['text_string'] = '';
}
return $newinput;
2019-03-28 14:38:28 +01:00
*/
2019-03-27 21:29:46 +01:00
}
2019-03-27 18:12:22 +01:00