forked from madgicweb/buddystream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buddystream.php
executable file
·240 lines (188 loc) · 7.93 KB
/
buddystream.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php
/*
Plugin Name: BuddyStream
Plugin URI: https://github.com/madgicweb/buddystream
Description: Synchronizes your favorite Social Networks to the BuddyPress activity stream
Version: 3.3.0
Author: Madgicweb | blackphantom
Author URI: https://github.com/madgicweb
*/
// Copyright (c) 2010/2011/2012/2013/2014 Buddystream.net All rights reserved.
//
// Released under the GPL license
// http://www.opensource.org/licenses/gpl-license.php
//
// This is an add-on for Buddypress
// http://buddypress.org/
//
// **********************************************************************
// 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.
// **********************************************************************
/*
* Only load code that needs BuddyPress
* to run once BP is loaded and initialized.
*/
function buddystream_init()
{
global $bp;
//define plugin version and installed value
define('BP_BUDDYSTREAM_VERSION', '3.3.0');
define('BP_BUDDYSTREAM_IS_INSTALLED', 1);
define('BP_BUDDYSTREAM_DIR', dirname(__FILE__));
define('BP_BUDDYSTREAM_URL', plugin_dir_url(__FILE__));
define('BP_BUDDYSTREAM_IS_PREMIUM', 1);
//first load translations
buddyStreamLoadTranslations();
//initialize the database if needed
buddyStreamInitDatabase();
//initialize settings if needed
buddyStreamInitSettings();
//now initialize the core
include_once('lib/BuddyStreamCurl.php');
include_once('lib/BuddyStreamOAuth.php');
include_once('lib/BuddyStreamLog.php');
include_once('lib/BuddyStreamExtensions.php');
include_once('lib/BuddyStreamFilters.php');
include_once('lib/BuddyStreamSupport.php');
include_once('lib/BuddyStreamPageLoader.php');
include_once('lib/BuddyStreamCore.php');
//turn all syncing on
buddyStreamInitSync();
}
/**
* Initialise sync settings for the first time (3.0)
*/
function buddyStreamInitSync(){
if( ! get_site_option("buddystream_321")){
if(get_site_option('buddystream_license_key')){
global $bp;
require_once (ABSPATH . WPINC . '/class-feed.php');
$url = "http://buddystream.net/cronservice/check.php?licensekey="
. get_site_option('buddystream_license_key')
. "&domain=" . str_replace("http://", "", $bp->root_domain)
. "&contenturl=" . WP_CONTENT_URL
. "&output=rss"
. "&validate=" . md5(date('Ymd'));
@fetch_feed($url);
}
update_site_option("buddystream_321", "true");
}
if( ! get_site_option("buddystream_30")){
$buddyStreamExtensions = new BuddyStreamExtensions();
foreach ($buddyStreamExtensions->getExtensionsConfigs() as $extension) {
if (is_array($extension) && !$extension['parent'] && $extension['synctypes']) {
$arrSyncTypes = explode(",", str_replace(" ","",$extension['synctypes']));
foreach($arrSyncTypes as $syncType){
update_site_option('buddystream_' . $extension['name'] . '_'.$syncType, 'on');
}
}
//get parent subextensions
$subExtensions = $buddyStreamExtensions->getExtensionsWithParent($extension['name']);
foreach ($subExtensions as $subExtension) {
if($subExtension['synctypes']){
$arrSyncTypes = explode(",", str_replace(" ","",$subExtension['synctypes']));
foreach($arrSyncTypes as $syncType){
update_site_option('buddystream_' . $subExtension['name'] . '_'.$syncType, 'on');
}
}
}
}
update_site_option("buddystream_30", "true");
}
}
/**
* Initialise default settings
*/
function buddyStreamInitSettings(){
if( ! get_site_option('buddystream_init_settings') != 'BP_BUDDYSTREAM_VERSION'){
if(!get_site_option('buddystream_social_albums')){
update_site_option('buddystream_social_albums', 'on');
}
if(!get_site_option('buddystream_group_sharing')){
update_site_option('buddystream_group_sharing', 'on');
}
update_site_option('buddystream_init_settings', BP_BUDDYSTREAM_VERSION);
}
if( ! get_site_option('buddystream_2512')) {
update_site_option('buddystream_facebook_privacy_setting', 'on');
update_site_option('buddystream_2512', '1');
}
}
/**
* Initialise database tables needed for plugin.
*/
function buddyStreamInitDatabase(){
if( ! get_site_option("buddystream_installed_version")){
global $wpdb;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
$buddystreamSql = "CREATE TABLE IF NOT EXISTS " . $wpdb->base_prefix . "buddystream_log (
`id` int(11) NOT NULL auto_increment,
`date` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`type` text NOT NULL,
`message` text NOT NULL,
PRIMARY KEY (`id`)
);";
@dbDelta($buddystreamSql);
unset($buddystreamSql);
$buddystreamSql = "CREATE TABLE IF NOT EXISTS " . $wpdb->base_prefix . "buddystream_imports (
`id` int(11) NOT NULL auto_increment,
`item_id` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);";
@dbDelta($buddystreamSql);
unset($buddystreamSql);
update_site_option("buddystream_installed_version", "1");
}
if( ! get_site_option('buddystream_26')) {
global $wpdb,$bp;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
$buddystreamSql = "CREATE TABLE IF NOT EXISTS " . $wpdb->base_prefix . "buddystream_imports (
`id` int(11) NOT NULL auto_increment,
`item_id` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
);";
@dbDelta($buddystreamSql);
unset($buddystreamSql);
//now get all activity items with a secondary id adn add it to them buddystream imports table
$items = $wpdb->get_results("SELECT * FROM ".$bp->activity->table_name." WHERE secondary_item_id != ''");
foreach($items as $item){
$item_id = str_replace($item->user_id."_", "", $item->secondary_item_id);
$item_id = $item->user_id."-".$item_id."-".$item->component;
$wpdb->query("INSERT INTO ".$wpdb->base_prefix."buddystream_imports set item_id='".$item_id."'");
}
update_site_option('buddystream_26', '1');
}
}
/*
* Load the translation files for the plugin and extensions
*/
function buddyStreamLoadTranslations() {
if (file_exists( BP_BUDDYSTREAM_DIR."/languages/buddystream-" . get_locale() . ".mo")) {
load_textdomain('buddystream_lang', BP_BUDDYSTREAM_DIR."/languages/buddystream-" . get_locale().".mo");
}else{
load_textdomain('buddystream_lang', BP_BUDDYSTREAM_DIR."/languages/buddystream-en_US.mo");
}
$handle = opendir(dirname(__FILE__)."/extensions");
if ($handle) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != ".DS_Store") {
if (file_exists(BP_BUDDYSTREAM_DIR."/extensions/".$file."/languages/buddystream_".$file."-".get_locale().".mo")) {
load_textdomain('buddystream_' . $file, BP_BUDDYSTREAM_DIR."/extensions/".$file."/languages/buddystream_".$file."-".get_locale().".mo");
}else{
load_textdomain('buddystream_' . $file, BP_BUDDYSTREAM_DIR."/extensions/".$file."/languages/buddystream_".$file."-en_US.mo");
}
}
}
}
}
add_action('bp_init', 'buddystream_init', 4);
/**
* Add the BuddyStream Connect Widget
*/
add_action('widgets_init', 'buddystream_connect_widget');
function buddystream_connect_widget() {
include_once('lib/BuddyStreamWidgets.php');
register_widget('BuddyStream_Connect_Widget');
}