2019-03-22 20:48:56 +01:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
2020-12-05 18:40:35 +01:00
|
|
|
|
* Plugin Name: WolKal3000 – Termin-Synchronisation
|
|
|
|
|
* Plugin URI: https://git.netzbegruenung.de/NB-Public/WolKal3000/
|
|
|
|
|
* Description: Synchronisation des Kal3000-Plugins mit Wolke-Kalendern und ICS-Dateien
|
2021-01-18 17:26:45 +01:00
|
|
|
|
* Version: 0.3.9
|
|
|
|
|
* Author: Harald Milz & Netzbegrünung e.V.
|
2019-03-22 20:48:56 +01:00
|
|
|
|
* License: GPLv3
|
|
|
|
|
* License URI: https://www.gnu.org/licenses/gpl-3.0
|
|
|
|
|
* Domain Path: /languages
|
|
|
|
|
*
|
|
|
|
|
* {Plugin Name} is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* {Plugin Name} is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with {Plugin Name}. If not, see {License URI}.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
|
|
|
|
|
|
2019-03-23 08:30:33 +01:00
|
|
|
|
// The real work goes here.
|
2021-01-18 17:26:45 +01:00
|
|
|
|
require_once dirname( __FILE__ ) . "/wolkal3000-worker.php";
|
|
|
|
|
require_once dirname( __FILE__ ) . "/wolkal3000-admin.php";
|
2019-03-23 17:28:30 +01:00
|
|
|
|
|
2019-03-27 18:13:25 +01:00
|
|
|
|
// create custom scheduler from custom option
|
2021-01-18 17:26:45 +01:00
|
|
|
|
add_filter( 'cron_schedules', 'wolkal3000_cron_interval' );
|
2019-04-11 16:37:07 +02:00
|
|
|
|
|
2021-01-18 17:26:45 +01:00
|
|
|
|
function wolkal3000_cron_interval( $schedules ) {
|
|
|
|
|
$options = get_option('wolkal3000_options');
|
|
|
|
|
$current = ( isset ($options['wolkal3000_timer']) ? $options['wolkal3000_timer'] : 60 ); // default 60 minutes
|
2021-02-19 12:29:11 +01:00
|
|
|
|
$interval = 60 * $current; // wir speichern Minuten
|
2021-01-18 17:26:45 +01:00
|
|
|
|
$schedules['wolkal3000_interval'] = array(
|
2019-03-27 18:13:25 +01:00
|
|
|
|
'interval' => $interval,
|
2021-01-18 17:26:45 +01:00
|
|
|
|
'display' => esc_html__( 'Calendar fetch interval' ),
|
2019-03-23 17:28:30 +01:00
|
|
|
|
);
|
|
|
|
|
return $schedules;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-03-27 13:49:46 +01:00
|
|
|
|
|
2019-03-22 20:48:56 +01:00
|
|
|
|
/**
|
|
|
|
|
* Initializes the plugin and creates a table
|
|
|
|
|
*
|
|
|
|
|
* @since 0.1.0
|
|
|
|
|
*
|
2021-01-18 17:26:45 +01:00
|
|
|
|
* - wolkal3000_category - name of the calendar, for later per-unit display
|
|
|
|
|
* - wolkal3000_link - the public or private .ics link
|
|
|
|
|
* - wolkal3000_veranstalter - ?
|
|
|
|
|
* - wolkal3000_active - flag if a calendar is active or not. Default active.
|
2019-03-24 18:33:00 +01:00
|
|
|
|
*
|
|
|
|
|
* Since there is no install hook in WP, we will use the activation hook for both.
|
2019-03-22 20:48:56 +01:00
|
|
|
|
*/
|
|
|
|
|
|
2021-01-18 17:26:45 +01:00
|
|
|
|
function wolkal3000_activate()
|
2019-03-22 20:48:56 +01:00
|
|
|
|
{
|
|
|
|
|
global $wpdb;
|
2019-04-09 21:02:56 +02:00
|
|
|
|
// CREATE geocoding caching table if it does not exist already.
|
2019-03-25 21:40:28 +01:00
|
|
|
|
// the location field will be used only during development and debugging, and will be omitted in production.
|
2021-01-18 17:26:45 +01:00
|
|
|
|
$table = $wpdb->prefix.WOLKAL3000_GEO_TABLE;
|
2019-03-25 14:48:06 +01:00
|
|
|
|
$query = "CREATE TABLE IF NOT EXISTS $table (
|
|
|
|
|
id INT(9) NOT NULL AUTO_INCREMENT,
|
2021-01-18 17:26:45 +01:00
|
|
|
|
wolkal3000_geo_location VARCHAR(128) NOT NULL,
|
|
|
|
|
wolkal3000_geo_hash VARCHAR(40) NOT NULL,
|
|
|
|
|
wolkal3000_geo_lat VARCHAR(20) NOT NULL,
|
|
|
|
|
wolkal3000_geo_lon VARCHAR(20) NOT NULL,
|
|
|
|
|
wolkal3000_geo_timestamp INT(16) NOT NULL,
|
2019-03-25 14:48:06 +01:00
|
|
|
|
UNIQUE KEY id (id)
|
|
|
|
|
);";
|
|
|
|
|
$wpdb->query($query);
|
2019-03-22 20:48:56 +01:00
|
|
|
|
|
2019-03-23 08:30:33 +01:00
|
|
|
|
// and start the scheduler;
|
2021-01-18 17:26:45 +01:00
|
|
|
|
if ( ! wp_next_scheduled( 'wolkal3000_worker_hook' ) ) {
|
|
|
|
|
wp_schedule_event( time(), 'wolkal3000_interval', 'wolkal3000_worker_hook' );
|
2019-03-22 20:48:56 +01:00
|
|
|
|
}
|
2019-04-08 13:53:45 +02:00
|
|
|
|
|
2021-01-18 17:26:45 +01:00
|
|
|
|
wolkal3000_error_log (INFO, "wolkal3000 activated");
|
2019-04-08 13:53:45 +02:00
|
|
|
|
|
|
|
|
|
// empty geocode cache if option is set.
|
2021-01-18 17:26:45 +01:00
|
|
|
|
$options = get_option('wolkal3000_options');
|
|
|
|
|
if ( isset ( $options['wolkal3000_reset_cache'] ) && '1' == $options['wolkal3000_reset_cache'] ) {
|
2019-04-08 13:53:45 +02:00
|
|
|
|
$wpdb->query("DELETE IGNORE FROM $table WHERE 1=1");
|
2021-01-18 17:26:45 +01:00
|
|
|
|
wolkal3000_error_log (INFO, "emptied geocoding cache");
|
2019-04-08 13:53:45 +02:00
|
|
|
|
}
|
2019-03-22 20:48:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 17:26:45 +01:00
|
|
|
|
register_activation_hook( __FILE__, 'wolkal3000_activate' );
|
2019-03-22 20:48:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2019-03-24 18:33:00 +01:00
|
|
|
|
* Deactivate unregisters the scheduling function.
|
2019-03-22 20:48:56 +01:00
|
|
|
|
*
|
|
|
|
|
* @since 0.1.0
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2021-01-18 17:26:45 +01:00
|
|
|
|
function wolkal3000_deactivate()
|
2019-03-22 20:48:56 +01:00
|
|
|
|
{
|
2019-04-01 15:56:56 +02:00
|
|
|
|
// clean up! Many plugins forget the housekeeping when deactivating.
|
2021-01-18 17:26:45 +01:00
|
|
|
|
wp_clear_scheduled_hook('wolkal3000_worker_hook');
|
|
|
|
|
wolkal3000_error_log (INFO, "wolkal3000 deactivated");
|
2019-03-22 20:48:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 17:26:45 +01:00
|
|
|
|
register_deactivation_hook( __FILE__, 'wolkal3000_deactivate' );
|
2019-03-22 20:48:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Uninstall drops our DB table
|
|
|
|
|
*
|
|
|
|
|
* @since 0.1.0
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2021-01-18 17:26:45 +01:00
|
|
|
|
function wolkal3000_uninstall()
|
2019-03-22 20:48:56 +01:00
|
|
|
|
{
|
2019-04-01 15:56:56 +02:00
|
|
|
|
// clean up! Many plugins forget the housekeeping when uninstalling.
|
2021-01-18 17:26:45 +01:00
|
|
|
|
wolkal3000_error_log (INFO, "uninstalling wolkal3000");
|
2019-03-22 20:48:56 +01:00
|
|
|
|
// can we uninstall without deactivating first?
|
2021-01-18 17:26:45 +01:00
|
|
|
|
// wolkal3000_deactivate;
|
2019-03-22 20:48:56 +01:00
|
|
|
|
global $wpdb;
|
2019-03-28 14:45:17 +01:00
|
|
|
|
// drop the geocache table
|
2021-01-18 17:26:45 +01:00
|
|
|
|
$table = $wpdb->prefix.WOLKAL3000_GEO_TABLE ;
|
2019-03-28 14:45:17 +01:00
|
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS $table" );
|
2019-03-27 13:49:46 +01:00
|
|
|
|
// and the options.
|
2021-01-18 17:26:45 +01:00
|
|
|
|
delete_option ( 'wolkal3000_options' );
|
2019-03-22 20:48:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-18 17:26:45 +01:00
|
|
|
|
register_uninstall_hook( __FILE__, 'wolkal3000_uninstall' );
|
2019-03-22 20:48:56 +01:00
|
|
|
|
|
2019-04-08 10:43:28 +02:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Debug logging if debugging is activated
|
|
|
|
|
*
|
|
|
|
|
* @since 0.3.0
|
|
|
|
|
*/
|
|
|
|
|
|
2021-01-18 17:26:45 +01:00
|
|
|
|
function wolkal3000_error_log($level, $args) {
|
2019-04-09 21:02:56 +02:00
|
|
|
|
$levels = array ( 'NONE', 'CRIT', 'WARN', 'INFO' );
|
2021-01-18 17:26:45 +01:00
|
|
|
|
$options = get_option('wolkal3000_options');
|
|
|
|
|
if ( isset ( $options['wolkal3000_debugging'] )) {
|
|
|
|
|
if ( $level <= (int) $options['wolkal3000_debugging'] ) {
|
|
|
|
|
error_log ( "WolKal3000 [" . $levels[$level] . "] " . $args );
|
2019-04-09 21:02:56 +02:00
|
|
|
|
}
|
2019-04-08 10:43:28 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|