diff options
Diffstat (limited to 'communi-events.php')
| -rw-r--r-- | communi-events.php | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/communi-events.php b/communi-events.php new file mode 100644 index 0000000..36aac54 --- /dev/null +++ b/communi-events.php @@ -0,0 +1,95 @@ +<?php +/** + * Plugin Name: CommuniApp Event Importer + * Plugin URI: + * Description: + * Version: 2022.09.1 + * Author: Genosse Einhorn + * Author URI: mailto:jonas@kuemmerlin.eu + */ + +define('COMMUNIEVENTS_PLUGIN_PATH', plugin_dir_path(__FILE__)); +define('COMMUNIEVENTS_PLUGIN_URL', trailingslashit(plugins_url('', __FILE__))); + +require_once COMMUNIEVENTS_PLUGIN_PATH . "api.php"; +require_once COMMUNIEVENTS_PLUGIN_PATH . "event-list.php"; +require_once COMMUNIEVENTS_PLUGIN_PATH . "event-calendar.php"; +require_once COMMUNIEVENTS_PLUGIN_PATH . "healthcheck.php"; +require_once COMMUNIEVENTS_PLUGIN_PATH . "ical-feed.php"; +require_once COMMUNIEVENTS_PLUGIN_PATH . "scraper.php"; +require_once COMMUNIEVENTS_PLUGIN_PATH . "admin.php"; + +/* PLUGIN SETUP + * + * Installs storage table and stuff + */ +function communievents_install() { + global $wpdb; + + $table_name = $wpdb->prefix . "communievents_events"; + + $charset_collate = $wpdb->get_charset_collate(); + + $sql = "CREATE TABLE $table_name ( + id INT(1) NOT NULL, + `group` INT(1) NOT NULL, + title TEXT NOT NULL, + location TEXT NOT NULL, + description TEXT NOT NULL, + start CHAR(19) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + end CHAR(19) CHARACTER SET ascii COLLATE ascii_bin NOT NULL, + allday BOOLEAN NOT NULL, + official BOOLEAN NOT NULL, + url TEXT NOT NULL, + lastsync BIGINT(1) NOT NULL, + PRIMARY KEY (id), + KEY start_idx (start), + KEY end_idx (end) + ) $charset_collate;"; + + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); + dbDelta($sql); + + communievents_setup_ical_feed(); // need to call it here for the rewrite flush + flush_rewrite_rules(); + + if (!wp_next_scheduled('communievents_cron_hook')) { + wp_schedule_event(time(), 'hourly', 'communievents_cron_hook'); + } +} + +register_activation_hook(__FILE__, 'communievents_install'); + +function communievents_uninstall() { + global $wpdb; + + $table_name = $wpdb->prefix . "communievents_events"; + + $wpdb->query("DROP TABLE IF EXISTS $table_name"); + + flush_rewrite_rules(); + + $timestamp = wp_next_scheduled('communievents_cron_hook'); + if ($timestamp) { + wp_unschedule_event($timestamp, 'communievents_cron_hook'); + } +} + +register_deactivation_hook(__FILE__, 'communievents_uninstall'); + + +/* INIT - register stuff + * + */ +function communievents_init() { + communievents_setup_ical_feed(); + communievents_setup_event_list(); + communievents_setup_event_calendar(); + communievents_setup_cron_hook(); + communievents_setup_healthcheck(); + communievents_setup_admin_page(); +} + +add_action('init', 'communievents_init'); + + |
