1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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');
|