-
Notifications
You must be signed in to change notification settings - Fork 5
/
kebo-twitter-feed.php
452 lines (329 loc) · 13.3 KB
/
kebo-twitter-feed.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
<?php
/*
* Plugin Name: Kebo - Twitter Feed
* Plugin URI: http://wordpress.org/plugins/kebo-twitter-feed/
* Description: Connect your site to your Twitter account and display your Twitter Feed on your website effortlessly with a custom widget.
* Version: 1.5.12
* Author: Kebo
* Author URI: https://www.kebo.io/
* Text Domain: kebo_twitter
* Domain Path: /languages
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'KEBO_TWITTER_PLUGIN_VERSION', '1.5.12' );
define( 'KEBO_TWITTER_PLUGIN_URL', plugin_dir_url(__FILE__) );
define( 'KEBO_TWITTER_PLUGIN_PATH', plugin_dir_path(__FILE__) );
define( 'KEBO_TWITTER_API_DOMAIN', 'auth.kebo.io' );
define( 'KEBO_TWITTER_API_PATH', '/request/index.php' );
function kebo_twitter_plugin_setup() {
/**
* Include Plugin Options.
*/
require_once( KEBO_TWITTER_PLUGIN_PATH . 'inc/options.php' );
/**
* Include Menu Page.
*/
require_once( KEBO_TWITTER_PLUGIN_PATH . 'inc/menu.php' );
/**
* Include Custom Widget.
*/
require_once( KEBO_TWITTER_PLUGIN_PATH . 'inc/widget.php' );
/**
* Include Request for the Twitter Feed.
*/
require_once( KEBO_TWITTER_PLUGIN_PATH . 'inc/get_tweets.php' );
/**
* Include Shortcode.
*/
require_once( KEBO_TWITTER_PLUGIN_PATH . 'inc/shortcode.php' );
/**
* Include AJAX.
*/
require_once( KEBO_TWITTER_PLUGIN_PATH . 'inc/ajax.php' );
/**
* Load Text Domain for Translations.
*/
load_plugin_textdomain( 'kebo_twitter', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
add_action('plugins_loaded', 'kebo_twitter_plugin_setup', 15);
if ( ! function_exists('kebo_twitter_scripts') ):
/**
* Enqueue plugin scripts and styles.
*/
function kebo_twitter_scripts( $hook_suffix ) {
// Queues the main CSS file.
wp_register_style( 'kebo-twitter-plugin', KEBO_TWITTER_PLUGIN_URL . 'css/plugin.css', array(), KEBO_TWITTER_PLUGIN_VERSION, 'all' );
wp_register_script( 'responsive-slides', KEBO_TWITTER_PLUGIN_URL . 'js/responsiveslides.min.js', array( 'jquery' ), KEBO_TWITTER_PLUGIN_VERSION, false );
// Enqueue Stylesheet for Admin Pages
if ( is_admin() && 'settings_page_kebo-twitter' == $hook_suffix ) {
wp_enqueue_style( 'kebo-twitter-plugin' );
}
// WP 3.2 compatibility (cannot enqueue after the header).
global $wp_version;
if ( version_compare( $wp_version, '3.3', '<' ) ) {
wp_enqueue_style( 'kebo-twitter-plugin' );
}
}
add_action('wp_enqueue_scripts', 'kebo_twitter_scripts');
add_action('admin_enqueue_scripts', 'kebo_twitter_scripts');
endif;
/**
* Add a link to the plugin screen, to allow users to jump straight to the settings page.
*/
function kebo_twitter_plugin_meta( $links ) {
$links[] = '<a href="' . admin_url( 'options-general.php?page=kebo-twitter' ) . '">' . __( 'Settings', 'kebo_twitter' ) . '</a>';
return $links;
}
add_filter( 'plugin_action_links_kebo-twitter-feed/kebo-twitter-feed.php', 'kebo_twitter_plugin_meta' );
/**
* Check we are on WordPress version 3.3 at least,
* before trying to use the WP Pointer.
*/
global $wp_version;
if ( version_compare( $wp_version, '3.3', '>=' ) ) {
/**
* Adds a WordPress pointer to Kebo Twitter settings page.
*/
function kebo_twitter_pointer_script_style( $hook_suffix ) {
// Assume pointer shouldn't be shown
$enqueue_pointer_script_style = false;
// Get array list of dismissed pointers for current user and convert it to array
$dismissed_pointers = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
// Check if our pointer is not among dismissed ones
if ( ! in_array( 'kebo_twitter_settings_pointer', $dismissed_pointers ) ) {
$enqueue_pointer_script_style = true;
// Add footer scripts using callback function
add_action('admin_print_footer_scripts', 'kebo_twitter_pointer_print_scripts');
}
// Enqueue pointer CSS and JS files, if needed
if ( $enqueue_pointer_script_style ) {
wp_enqueue_style( 'wp-pointer' );
wp_enqueue_script( 'wp-pointer' );
}
}
add_action( 'admin_enqueue_scripts', 'kebo_twitter_pointer_script_style' );
function kebo_twitter_pointer_print_scripts() {
$pointer_content = '<h3>' . __('Connect to your Twitter Account', 'kebo_twitter') . '</h3>';
$pointer_content .= '<p>' . __('In just a few clicks we can connect your website to your Twitter account and display your latest Tweets.', 'kebo_twitter') . ' <a href="' . admin_url('options-general.php?page=kebo-twitter') . '">' . __('Get Started Now', 'kebo_twitter') . '</a></p>';
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function($) {
$('#menu-settings').pointer({
content: '<?php echo $pointer_content; ?>',
position: {
edge: 'left', // arrow direction
align: 'center' // vertical alignment
},
pointerWidth: 350,
close: function() {
$.post(ajaxurl, {
pointer: 'kebo_twitter_settings_pointer', // pointer ID
action: 'dismiss-wp-pointer'
});
}
}).pointer('open');
});
//]]>
</script>
<?php
}
}
/*
* Outputs Slider Javascript
* Shows a single tweet at a time, fading between them.
*/
function kebo_twitter_slider_script() {
// Collect the IDs of all Widgets using the Slider display.
$widget_ids = Kebo_Twitter_Feed_Widget::$slider_ids;
foreach ( $widget_ids as $widget_id ) {
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function() {
ktimeout = jQuery( ".<?php echo $widget_id; ?>" ).data( "timeout" );
kspeed = jQuery( ".<?php echo $widget_id; ?>" ).data( "speed" );
jQuery( function() {
jQuery( ".<?php echo $widget_id; ?>" ).responsiveSlides({
auto: true, // Boolean: Animate automatically, true or false
speed: kspeed, // Integer: Speed of the transition, in milliseconds
timeout: ktimeout, // Integer: Time between slide transitions, in milliseconds
pager: false, // Boolean: Show pager, true or false
nav: false, // Boolean: Show navigation, true or false
random: false, // Boolean: Randomize the order of the slides, true or false
pause: true // Boolean: Pause on hover, true or false
});
});
});
//]]>
</script>
<?php
}
}
/*
* Print the Tweet Intent js
*/
function kebo_twitter_intent_script() {
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function() {
jQuery( '.ktweet .kfooter a:not(.ktogglemedia)' ).click(function(e) {
// Prevent Click from Reloading page
e.preventDefault();
var khref = jQuery(this).attr('href');
window.open( khref, 'twitter', 'width=600, height=400, top=0, left=0');
});
});
//]]>
</script>
<?php
}
/*
* Print the Tweet Media js
*/
function kebo_twitter_media_script() {
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function() {
jQuery( '.ktweet .ktogglemedia' ).click(function(e) {
// Prevent Click from Reloading page
e.preventDefault();
var klink = jQuery(this);
var kid = klink.data( 'id' );
var kcontainer = jQuery( '#' + kid );
if ( klink.hasClass('kclosed') && kcontainer.hasClass('kclosed') ) {
klink.removeClass('kclosed');
kcontainer.removeClass('kclosed');
} else {
klink.addClass('kclosed');
kcontainer.addClass('kclosed');
};
});
});
//]]>
</script>
<?php
}
/*
* Detects touch devices - saved for potential use
*/
function kebo_twitter_touch_script() {
?>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function() {
var is_touch_device = 'ontouchstart' in document.documentElement;
if (is_touch_device) {
jQuery(".kebo-tweets").each(function(index, element) {
jQuery(this).addClass( "touch" );
});
} else {
jQuery(".kebo-tweets").each(function(index, element) {
jQuery(this).addClass( "notouch" );
});
}
});
//]]>
</script>
<?php
}
/*
* Check if the plugin has updated.
* If so process any changes and update current version.
*/
function kebo_twitter_update_check() {
$plugin_version = get_option( 'kebo_twitter_version' );
/*
* Runs if version check matches
*/
if ( false == $plugin_version || empty( $plugin_version ) || ( ! empty( $plugin_version ) && KEBO_TWITTER_PLUGIN_VERSION > $plugin_version ) ) {
//add_action( 'admin_notices', 'kebo_twitter_upgrade_notice' );
// Delete currently cached data in an attempt to properly purge corrupt data.
delete_transient( 'kebo_twitter_feed_' . get_current_blog_id() );
// Set silent cache to refresh after page load.
add_action( 'shutdown', 'kebo_twitter_refresh_cache' );
// Connection Migration Script
add_action( 'after_setup_theme', 'kebo_twitter_activation_script' );
// Update Plugin Version Option
update_option( 'kebo_twitter_version', KEBO_TWITTER_PLUGIN_VERSION );
}
}
add_action( 'admin_init', 'kebo_twitter_update_check' );
function kebo_twitter_activation_script() {
if ( is_multisite() ) {
global $wpdb;
// Store Network Site ID so we can get back later.
$current_blog = get_current_blog_id();
// Get a list of all Blog IDs, ignore network admin with ID of 1.
$blogs = $wpdb->get_results("
SELECT blog_id
FROM {$wpdb->blogs}
WHERE site_id = '{$wpdb->siteid}'
AND spam = '0'
AND deleted = '0'
AND archived = '0'
AND blog_id != '{$current_blog}'
");
foreach ( $blogs as $blog ) {
switch_to_blog( $blog->blog_id );
// Check if old format is used for storing connection info
if ( false !== ( $twitter_data = get_transient( 'kebo_twitter_connection_' . $blog->blog_id ) ) ) {
// Add connection data to new Option
update_option( 'kebo_twitter_connection', $twitter_data );
// Delete the now un-used Transient
delete_transient( 'kebo_twitter_connection_' . $blog->blog_id );
}
}
// Go back to Network Site
switch_to_blog( $current_blog );
} else {
// Check if old format is used for storing connection info
if ( false !== ( $twitter_data = get_transient( 'kebo_twitter_connection_1' ) ) ) {
// Add connection data to new Option
update_option( 'kebo_twitter_connection', $twitter_data );
// Delete the now un-used Transient
delete_transient( 'kebo_twitter_connection_1' );
}
}
}
/*
* Use if needed
*/
function kebo_twitter_upgrade_notice() {
?>
<div class="updated">
<p><?php echo sprintf( __( 'This update changed the way your connection to Twitter was stored by WordPress, please check the plugin is still connected to your Twitter account, <a href="%s">here</a>.', 'kebo_twitter' ), admin_url( 'options-general.php?page=kebo-twitter' ) ); ?></p>
</div>
<?php
}
/*
* Display an Admin Notice if plugin is active but no connection to Twitter is active.
*/
$twitter_data = get_option( 'kebo_twitter_connection' );
// Check if Connection data is being stored.
if ( empty ( $twitter_data ) ) {
add_action( 'admin_notices', 'kebo_twitter_no_connection_notice' );
}
// Display Notice
function kebo_twitter_no_connection_notice() {
global $current_screen;
if ( 'settings_page_kebo-twitter' !== $current_screen->id ) {
?>
<div class="updated">
<p><?php echo sprintf( __( '<strong>Kebo Twitter Feed:</strong> No connection to Twitter found, to get started connect to your Twitter account from <a href="%s">this page</a>.', 'kebo_twitter' ), admin_url( 'options-general.php?page=kebo-twitter' ) ); ?></p>
</div>
<?php
}
}
/**
* ToDo List
*
* 1. Include Re-Tweets in request to Twitter API and give users the option.
* 2.
*
*/