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.php

153 lines
4.8 KiB
PHP
Raw Permalink Normal View History

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
* 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.
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
add_filter( 'cron_schedules', 'wolkal3000_cron_interval' );
2019-04-11 16:37:07 +02:00
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(
2019-03-27 18:13:25 +01:00
'interval' => $interval,
'display' => esc_html__( 'Calendar fetch interval' ),
2019-03-23 17:28:30 +01:00
);
return $schedules;
}
2019-03-22 20:48:56 +01:00
/**
* 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.
2019-03-22 20:48:56 +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.
// the location field will be used only during development and debugging, and will be omitted in production.
$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,
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;
if ( ! wp_next_scheduled( 'wolkal3000_worker_hook' ) ) {
wp_schedule_event( time(), 'wolkal3000_interval', 'wolkal3000_worker_hook' );
2019-03-22 20:48:56 +01:00
}
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");
}
2019-03-22 20:48:56 +01:00
}
register_activation_hook( __FILE__, 'wolkal3000_activate' );
2019-03-22 20:48:56 +01:00
/**
* Deactivate unregisters the scheduling function.
2019-03-22 20:48:56 +01:00
*
* @since 0.1.0
*
*/
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.
wp_clear_scheduled_hook('wolkal3000_worker_hook');
wolkal3000_error_log (INFO, "wolkal3000 deactivated");
2019-03-22 20:48:56 +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
*
*/
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.
wolkal3000_error_log (INFO, "uninstalling wolkal3000");
2019-03-22 20:48:56 +01:00
// can we uninstall without deactivating first?
// wolkal3000_deactivate;
2019-03-22 20:48:56 +01:00
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' );
2019-03-22 20:48:56 +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
*/
function wolkal3000_error_log($level, $args) {
2019-04-09 21:02:56 +02:00
$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 );
2019-04-09 21:02:56 +02:00
}
2019-04-08 10:43:28 +02:00
}
}