-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimestreams-loader.php
167 lines (134 loc) · 5.39 KB
/
timestreams-loader.php
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/*
Plugin Name: Timestreams
Plugin URI: https://github.com/pszjmb1/Timestreams/
Description: Sensor data I/O for WordPress. Connect information from your community or school with your blog and the rest of the world.
Version: 2.0.0-Alpha-0.2
Author: Horizon Digital Economy Research Institute Jesse Blum (JMB) & Martin Flintham (MDF)
Author URI: http://www.horizon.ac.uk
License: AGPLv3
*/
/* Copyright (C) 2012 Horizon Digital Economy Research Institute, Jesse Blum (JMB) & Martin Flintham (MDF)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// from http://fuelyourcoding.com/simple-debugging-with-wordpress/
if(!function_exists('_log')){
function _log( $message ) {
if( WP_DEBUG === true ){
if( is_array( $message ) || is_object( $message ) ){
error_log( print_r( $message, true ) );
} else {
error_log( $message );
}
}
}
}
/**
* Sets up common variables and required files
*/
function hn_ts_setup(){
// Define the Timestreams version
if ( !defined( 'HN_TS_VERSION' ) )
define( 'HN_TS_VERSION', '0.8' );
// Define the database version
if ( !defined( 'HN_TS_DB_VERSION' ) )
define( 'HN_TS_DB_VERSION', 0.1 );
// Define the plugin name
if ( !defined( 'HN_TS_NAME' ) )
define( 'HN_TS_NAME', 'Timestreams' );
// Define the Timestreams blog id -- idea courtesy of Buddypress
if ( !defined( 'HN_TS_ROOT_BLOG' ) ) {
if( !is_multisite() ) {
$_id = 1;
}else if ( !defined( 'HN_TS_ENABLE_MULTIBLOG' ) ) {
$current_site = get_current_site();
$_id = $current_site->blog_id;
} else {
$_id = get_current_blog_id();
}
define( 'HN_TS_ROOT_BLOG', $_id );
}
// Path and URL
if ( !defined( 'HN_TS_PLUGIN_DIR' ) )
define( 'HN_TS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
if ( !defined( 'HN_TS_PLUGIN_URL' ) )
define( 'HN_TS_PLUGIN_URL', plugins_url( 'timestreams' ) );
hn_ts_timestreams_checkVersion(3);
//load_plugin_textdomain('timestreams',false,'timestreams/languages');
require_once( HN_TS_PLUGIN_DIR . '/utilities/utilitiesloader.php' );
require_once( HN_TS_PLUGIN_DIR . '/controllers/controllers-loader.php' );
require_once( HN_TS_PLUGIN_DIR . '/views/views-loader.php' );
require_once( HN_TS_PLUGIN_DIR . '/admin/admin-loader.php' );
require_once( HN_TS_PLUGIN_DIR . '/admin/visualisation.php' );
if(!wp_next_scheduled('hn_ts_cron_replication')){
wp_schedule_event(
time(), 'minutely', 'minutely_replication');
}
// Hook into the dashboard action
register_activation_hook(__FILE__, 'hn_ts_timestreams_activate');
register_deactivation_hook(__FILE__, 'hn_ts_timestreams_deactivate');
}
add_action('minutely_replication', 'hn_ts_continuousReplication');
function hn_ts_stylesheet(){
wp_enqueue_style('ts-css', plugins_url('/css/documentation.css', __FILE__));
}
add_action( 'wp_enqueue_scripts', 'hn_ts_stylesheet' );
function timestreams_init() {
$plugin_path = dirname( plugin_basename( __FILE__ ) ) ;
load_plugin_textdomain(HN_TS_NAME, false, $plugin_path);
}
add_action('init', 'timestreams_init');
add_filter('cron_schedules', 'add_scheduled_interval');
// add once a minute to wp schedules
function add_scheduled_interval($schedules) {
$schedules['minutely'] = array('interval'=>60, 'display'=>'Once a minute');
return $schedules;
}
/**
* Plugin activation. This creates the initial multisite tables.
*/
function hn_ts_timestreams_activate() {
// Ensure that ABSPATH was defined
if ( !defined( 'ABSPATH' ) ) exit;
$hn_ts_db = new Hn_TS_Database();
$hn_ts_db->hn_ts_createMultisiteTables();
}
/**
* Plugin deactivation. Currently this does nothing,
* but in the future should clean up the plugin database tables and files.
*/
function hn_ts_timestreams_deactivate() {
//To do: remove database tables
wp_clear_scheduled_hook('my_hourly_event');
}
/**
* Exits the plugin if the WP version is lower than $minver
* @param $minver is the minimum version of Wordpress supported
*/
function hn_ts_timestreams_checkVersion($minver){
global $wp_version;
$exit_msg="HN_TS_NAME requires Wordpress version ".$wp_version.' or newer.';
if(version_compare($wp_version, $minver,"<")){
exit($exit_msg);
}
}
/**
* Allow unity file uploads. This would be better placed in its own plugin.
* Ideally the functionality of the plugin would allow admins to add additional mimetypes.
*/
add_filter('upload_mimes', 'custom_upload_mimes');
function custom_upload_mimes ( $existing_mimes=array() ){
$existing_mimes['unity3d'] = 'application/vnd.unity';
return $existing_mimes;
}
hn_ts_setup();
?>