Christian Tramnitz
3f03ea7cda
* redundante readme.txt entfernt * GCAL namespace auf wolkal3000 geändert (Dateinamen, WP options) (dadurch ggf. Co-Existenz mit dem ursprüinglichen GCal-Plugin möglich!) * Vorkonfiguration für die Wolke, man braucht nur die 16-stellige Kalender ID (dadurch Security Verbesserung: kein dynamisches Laden von potentiell nicht vertrauenswürdigen Inhalten) * Google Maps Funktionen entfernt **Bei Migration von <= 0.3.8 bitte das alte Plugin per "uninstall" deinstallieren, damit die Daten im alten Namespace gelöscht werden. Achtung: Die Konfiguration muss (im neuen Namespace) neu vorgenommen werden!** Co-authored-by: Christian Tramnitz <christian.tramnitz@gruene-hochtaunus.de> Reviewed-on: #13 Co-Authored-By: Christian Tramnitz <christian.tramnitz@git@verdigado.com> Co-Committed-By: Christian Tramnitz <christian.tramnitz@git@verdigado.com>
153 lines
4.8 KiB
PHP
153 lines
4.8 KiB
PHP
<?php
|
||
/**
|
||
* 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
|
||
* Version: 0.3.9
|
||
* Author: Harald Milz & Netzbegrünung e.V.
|
||
* 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!' );
|
||
|
||
// The real work goes here.
|
||
require_once dirname( __FILE__ ) . "/wolkal3000-worker.php";
|
||
require_once dirname( __FILE__ ) . "/wolkal3000-admin.php";
|
||
|
||
// create custom scheduler from custom option
|
||
add_filter( 'cron_schedules', 'wolkal3000_cron_interval' );
|
||
|
||
function wolkal3000_cron_interval( $schedules ) {
|
||
$options = get_option('wolkal3000_options');
|
||
$current = ( isset ($options['wolkal3000_timer']) ? $options['wolkal3000_timer'] : 60 ); // default 60 minutes
|
||
$interval = 60 * $current; // wir speichern Minuten
|
||
$schedules['wolkal3000_interval'] = array(
|
||
'interval' => $interval,
|
||
'display' => esc_html__( 'Calendar fetch interval' ),
|
||
);
|
||
return $schedules;
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* Initializes the plugin and creates a table
|
||
*
|
||
* @since 0.1.0
|
||
*
|
||
* - 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.
|
||
*
|
||
* Since there is no install hook in WP, we will use the activation hook for both.
|
||
*/
|
||
|
||
function wolkal3000_activate()
|
||
{
|
||
global $wpdb;
|
||
// CREATE geocoding caching table if it does not exist already.
|
||
// the location field will be used only during development and debugging, and will be omitted in production.
|
||
$table = $wpdb->prefix.WOLKAL3000_GEO_TABLE;
|
||
$query = "CREATE TABLE IF NOT EXISTS $table (
|
||
id INT(9) NOT NULL AUTO_INCREMENT,
|
||
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,
|
||
UNIQUE KEY id (id)
|
||
);";
|
||
$wpdb->query($query);
|
||
|
||
// and start the scheduler;
|
||
if ( ! wp_next_scheduled( 'wolkal3000_worker_hook' ) ) {
|
||
wp_schedule_event( time(), 'wolkal3000_interval', 'wolkal3000_worker_hook' );
|
||
}
|
||
|
||
wolkal3000_error_log (INFO, "wolkal3000 activated");
|
||
|
||
// empty geocode cache if option is set.
|
||
$options = get_option('wolkal3000_options');
|
||
if ( isset ( $options['wolkal3000_reset_cache'] ) && '1' == $options['wolkal3000_reset_cache'] ) {
|
||
$wpdb->query("DELETE IGNORE FROM $table WHERE 1=1");
|
||
wolkal3000_error_log (INFO, "emptied geocoding cache");
|
||
}
|
||
}
|
||
|
||
register_activation_hook( __FILE__, 'wolkal3000_activate' );
|
||
|
||
|
||
/**
|
||
* Deactivate unregisters the scheduling function.
|
||
*
|
||
* @since 0.1.0
|
||
*
|
||
*/
|
||
|
||
function wolkal3000_deactivate()
|
||
{
|
||
// clean up! Many plugins forget the housekeeping when deactivating.
|
||
wp_clear_scheduled_hook('wolkal3000_worker_hook');
|
||
wolkal3000_error_log (INFO, "wolkal3000 deactivated");
|
||
}
|
||
|
||
register_deactivation_hook( __FILE__, 'wolkal3000_deactivate' );
|
||
|
||
|
||
/**
|
||
* Uninstall drops our DB table
|
||
*
|
||
* @since 0.1.0
|
||
*
|
||
*/
|
||
|
||
function wolkal3000_uninstall()
|
||
{
|
||
// clean up! Many plugins forget the housekeeping when uninstalling.
|
||
wolkal3000_error_log (INFO, "uninstalling wolkal3000");
|
||
// can we uninstall without deactivating first?
|
||
// wolkal3000_deactivate;
|
||
global $wpdb;
|
||
// drop the geocache table
|
||
$table = $wpdb->prefix.WOLKAL3000_GEO_TABLE ;
|
||
$wpdb->query( "DROP TABLE IF EXISTS $table" );
|
||
// and the options.
|
||
delete_option ( 'wolkal3000_options' );
|
||
}
|
||
|
||
register_uninstall_hook( __FILE__, 'wolkal3000_uninstall' );
|
||
|
||
|
||
/*
|
||
* Debug logging if debugging is activated
|
||
*
|
||
* @since 0.3.0
|
||
*/
|
||
|
||
function wolkal3000_error_log($level, $args) {
|
||
$levels = array ( 'NONE', 'CRIT', 'WARN', 'INFO' );
|
||
$options = get_option('wolkal3000_options');
|
||
if ( isset ( $options['wolkal3000_debugging'] )) {
|
||
if ( $level <= (int) $options['wolkal3000_debugging'] ) {
|
||
error_log ( "WolKal3000 [" . $levels[$level] . "] " . $args );
|
||
}
|
||
}
|
||
}
|
||
|