202 lines
8.3 KiB
PHP
202 lines
8.3 KiB
PHP
<?php
|
||
|
||
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
||
|
||
|
||
/**
|
||
* 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', 'gcal_admin_add_page');
|
||
|
||
function gcal_admin_add_page() {
|
||
add_options_page( 'WolKal3000 – Synchronisation von Kal3000 mit Wolke-Kalendern', 'WolKal3000', 'manage_options', 'kal3000-gcal-import', 'gcal_options_page');
|
||
}
|
||
|
||
function gcal_options_page() {
|
||
|
||
if ( !current_user_can( 'manage_options' ) ) {
|
||
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
|
||
}
|
||
|
||
?>
|
||
|
||
<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. Darüber hinaus kannst du jede andere ICS-Datei verwenden.</p>
|
||
|
||
<form action="options.php" method="post">
|
||
<?php settings_fields('gcal_options'); ?>
|
||
<?php do_settings_sections('gcal'); ?>
|
||
<input name="Submit" type="submit" value="<?php esc_attr_e('Save Changes'); ?>" />
|
||
</br></br></br><hr></br>
|
||
<?php do_settings_sections('gcal2'); ?>
|
||
<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' );
|
||
add_settings_section('gcal_feeds', 'Wolke-Kalender einer Terminkategorie zuordnen', 'gcal_feeds_section_text', 'gcal');
|
||
|
||
// 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;
|
||
$feed_name = $term->name;
|
||
add_settings_field($unique_id, 'Terminkategorie "'.$feed_name.'"', 'gcal_feeds_setting_string', 'gcal', 'gcal_feeds', array($unique_id));
|
||
}
|
||
|
||
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');
|
||
|
||
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');
|
||
|
||
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');
|
||
}
|
||
|
||
|
||
function gcal_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="hilfeseite" target="_blank">Erfahre mehr darüber, wie du die Export-Adresse eines Wolke-Kalenders findest.</a></b>
|
||
</p>
|
||
<?php
|
||
}
|
||
|
||
|
||
|
||
function gcal_feeds_setting_string($args) {
|
||
$options = get_option('gcal_options');
|
||
$placeholder = "z.B. https://wolke.netzbegruenung.de/remote.php/dav/public-calendars/xxxxxxxxxxxxxxxx?export";
|
||
// 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() {
|
||
?>
|
||
<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 gcal_timer_setting_string() {
|
||
$options = get_option('gcal_options');
|
||
$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>';
|
||
}
|
||
|
||
|
||
|
||
function gcal_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 gcal_geocoding_setting_string() {
|
||
$options = get_option('gcal_options');
|
||
$current = ( isset ($options['gcal_geocoding']) ? $options['gcal_geocoding'] : 'off' ); // default off
|
||
$apikey = ( isset ($options['gcal_apikey']) ? $options['gcal_apikey'] : '' ); // default empty
|
||
|
||
$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="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 . '">';
|
||
}
|
||
|
||
echo '</br>' ;
|
||
}
|
||
}
|
||
|
||
|
||
function gcal_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 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
|
||
// 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
|
||
// actual logging is done by gcal_error_log()
|
||
// Cache reset on restart
|
||
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>';}
|
||
|
||
|
||
|
||
function gcal_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;
|
||
*/
|
||
}
|
||
|
||
|