· 5 years ago · Feb 16, 2020, 05:02 PM
1<?php
2/**
3 * All wp-ulike functionalities starting from here...
4 *
5 *
6 * @package wp-ulike
7 * @author TechnoWich 2020
8 * @link https://wpulike.com
9 *
10 * Plugin Name: WP ULike
11 * Plugin URI: https://wpulike.com/?utm_source=wp-plugins&utm_campaign=plugin-uri&utm_medium=wp-dash
12 * Description: WP ULike plugin allows to integrate a beautiful Ajax Like Button into your wordPress website to allow your visitors to like and unlike pages, posts, comments AND buddypress activities. Its very simple to use and supports many options.
13 * Version: 4.1.5
14 * Author: Ali Mirzaei
15 * Author URI: https://wpulike.com/?utm_source=wp-plugins&utm_campaign=author-uri&utm_medium=wp-dash
16 * Text Domain: wp-ulike
17 * License: GPL2
18 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
19 * Domain Path: /lang
20 * Tested up to: 5.3.1
21
22 /------------------------------------------\
23 _ __ _ _____ _ _ _ _
24 | | / \ | | ___ \ | |(_)| | / /
25 | | / /\ \ | | |_/ / _| || || |/ / ___
26 | | / / \ \ | | __/ | | | || || | / _ \
27 | |/ / \ \| | | | |_| | || || |\ \ __/
28 \___/ \__/\_| \__,_|_||_||_| \_\___|
29
30 \--> Alimir, 2019 <--/
31
32 Thanks for using WP ULike plugin!
33
34 \------------------------------------------/
35*/
36
37// If this file is called directly, abort.
38if ( ! defined( 'WPINC' ) ) {
39 die('No Naughty Business Please !');
40}
41
42// Abort loading if WordPress is upgrading
43if ( defined( 'WP_INSTALLING' ) && WP_INSTALLING ) {
44 return;
45}
46
47// Do not change these values
48define( 'WP_ULIKE_PLUGIN_URI' , 'https://wpulike.com/' );
49define( 'WP_ULIKE_VERSION' , '4.1.5' );
50define( 'WP_ULIKE_SLUG' , 'wp-ulike' );
51define( 'WP_ULIKE_NAME' , __( 'WP ULike', WP_ULIKE_SLUG ));
52
53define( 'WP_ULIKE_DIR' , plugin_dir_path( __FILE__ ) );
54define( 'WP_ULIKE_URL' , plugins_url( '', __FILE__ ) );
55define( 'WP_ULIKE_BASENAME' , plugin_basename( __FILE__ ) );
56
57define( 'WP_ULIKE_ADMIN_DIR' , WP_ULIKE_DIR . '/admin' );
58define( 'WP_ULIKE_ADMIN_URL' , WP_ULIKE_URL . '/admin' );
59
60define( 'WP_ULIKE_INC_DIR' , WP_ULIKE_DIR . '/inc' );
61define( 'WP_ULIKE_INC_URL' , WP_ULIKE_URL . '/inc' );
62
63define( 'WP_ULIKE_ASSETS_DIR' , WP_ULIKE_DIR . '/assets' );
64define( 'WP_ULIKE_ASSETS_URL' , WP_ULIKE_URL . '/assets' );
65
66/**
67 * Initialize the plugin
68 * ===========================================================================*/
69
70if ( ! class_exists( 'WpUlikeInit' ) ) :
71
72 class WpUlikeInit {
73
74 /**
75 * Instance of this class.
76 *
77 * @since 3.1
78 *
79 * @var object
80 */
81 protected static $instance = null;
82
83
84 /**
85 * Initialize the plugin
86 *
87 * @since 3.1
88 */
89 private function __construct() {
90 // init plugin
91 add_action( 'plugins_loaded', array( $this, 'init' ) );
92
93 add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
94 add_action( 'wp_enqueue_scripts', array( $this, 'frontend_assets' ) );
95
96 // Activate plugin when new blog is added
97 add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
98 add_action( 'activated_plugin', array( $this, 'after_activation' ) );
99
100 $prefix = is_network_admin() ? 'network_admin_' : '';
101 add_filter( "{$prefix}plugin_action_links", array( $this, 'add_links' ), 10, 5 );
102 }
103
104 /**
105 * Init the plugin when WordPress Initialises.
106 *
107 * @return void
108 */
109 public function admin_assets( $hook ){
110 new wp_ulike_admin_assets( $hook );
111 }
112
113 /**
114 * Init the plugin when WordPress Initialises.
115 *
116 * @return void
117 */
118 public function frontend_assets(){
119 new wp_ulike_frontend_assets();
120 }
121
122 /**
123 * Init the plugin when WordPress Initialises.
124 *
125 * @return void
126 */
127 public function init(){
128 // Include Files
129 $this->includes();
130
131 // @deprecate version 5.0
132 global $wp_version;
133 if ( version_compare( $wp_version, '4.6', '<' ) ) {
134 // Load plugin text domain
135 $this->load_plugin_textdomain();
136 }
137
138 // Loaded action
139 do_action( 'wp_ulike_loaded' );
140 }
141
142 /**
143 * Add custom links too plugin info
144 *
145 * @since 3.1
146 *
147 * @return Array
148 */
149 public function add_links( $actions, $plugin_file ) {
150
151 if ( $plugin_file === WP_ULIKE_BASENAME ) {
152 $settings = array('settings' => '<a href="admin.php?page=wp-ulike-settings">' . __('Settings', WP_ULIKE_SLUG) . '</a>');
153 $stats = array('stats' => '<a href="admin.php?page=wp-ulike-statistics">' . __('Statistics', WP_ULIKE_SLUG) . '</a>');
154 $about = array('about' => '<a href="admin.php?page=wp-ulike-about">' . __('About', WP_ULIKE_SLUG) . '</a>');
155 // Merge on actions array
156 $actions = array_merge( $about, $actions );
157 $actions = array_merge( $stats, $actions );
158 $actions = array_merge( $settings, $actions );
159 }
160
161 return $actions;
162 }
163
164
165 /**
166 * Auto-load classes on demand to reduce memory consumption
167 *
168 * @param mixed $class
169 * @return void
170 */
171 public function autoload( $class ) {
172
173 $path = null;
174 $class = strtolower( $class );
175 $file = 'class-' . str_replace( '_', '-', $class ) . '.php';
176
177 // the possible pathes containing classes
178 $possible_pathes = array(
179 WP_ULIKE_INC_DIR . '/classes/',
180 WP_ULIKE_ADMIN_DIR . '/classes/'
181 );
182
183 foreach ( $possible_pathes as $path ) {
184 if( is_readable( $path . $file ) ){
185 include_once( $path . $file );
186 return;
187 }
188
189 }
190
191 }
192
193
194 /**
195 * Include Files
196 *
197 * @return void
198 */
199 private function includes() {
200
201 // Global Variables
202 global $wp_user_IP, $wp_ulike_class;
203
204 // Auto-load classes on demand
205 if ( function_exists( "__autoload" ) ) {
206 spl_autoload_register( "__autoload" );
207 }
208 spl_autoload_register( array( $this, 'autoload' ) );
209
210 // load common functionalities
211 include_once( WP_ULIKE_INC_DIR . '/index.php' );
212
213 // global variable of user IP
214 $wp_user_IP = $this->get_ip();
215
216 // global wp_ulike_class
217 $wp_ulike_class = wp_ulike::get_instance();
218
219 // Dashboard and Administrative Functionality
220 if ( is_admin() ) {
221 // Load AJAX specific codes on demand
222 if ( defined('DOING_AJAX') && DOING_AJAX ){
223 include( WP_ULIKE_INC_DIR . '/frontend-ajax.php' );
224 include( WP_ULIKE_ADMIN_DIR . '/admin-ajax.php' );
225 }
226
227 // Load admin specific codes
228 include( WP_ULIKE_ADMIN_DIR . '/index.php' );
229 }
230
231 }
232
233 /**
234 * Get Client IP address
235 *
236 * @since 3.1
237 *
238 * @return String
239 */
240 public function get_ip() {
241 // Get user IP
242 $user_ip = wp_ulike_get_user_ip();
243 // Check GDPR anonymise
244 if ( wp_ulike_is_true( wp_ulike_get_option( 'enable_anonymise_ip', false ) ) ) {
245 return $this->anonymise_ip( $user_ip );
246 } else {
247 return $user_ip;
248 }
249 }
250
251 /**
252 * Anonymise IP address
253 *
254 * @since 3.3
255 *
256 * @return String
257 */
258 public function anonymise_ip( $ip_address ) {
259 if ( strpos( $ip_address, "." ) == true ) {
260 return preg_replace('~[0-9]+$~', '0', $ip_address);
261 } else {
262 return preg_replace('~[0-9]*:[0-9]+$~', '0000:0000', $ip_address);
263 }
264 }
265
266 /**
267 * Return an instance of this class.
268 *
269 * @since 3.1
270 *
271 * @return object A single instance of this class.
272 */
273 public static function get_instance() {
274
275 // If the single instance hasn't been set, set it now.
276 if ( null == self::$instance ) {
277 self::$instance = new self;
278 }
279
280 return self::$instance;
281 }
282
283
284 /**
285 * Fired when the plugin is activated.
286 *
287 * @since 3.1
288 *
289 * @param boolean $network_wide True if WPMU superadmin uses
290 * "Network Activate" action, false if
291 * WPMU is disabled or plugin is
292 * activated on an individual blog.
293 */
294 public static function activate( $network_wide ) {
295
296 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
297
298 if ( $network_wide ) {
299
300 // Get all blog ids
301 $blog_ids = self::get_blog_ids();
302
303 foreach ( $blog_ids as $blog_id ) {
304
305 switch_to_blog( $blog_id );
306 self::single_activate();
307 }
308
309 restore_current_blog();
310
311 } else {
312 self::single_activate();
313 }
314
315 } else {
316 self::single_activate();
317 }
318 }
319
320 public function after_activation( $plugin ) {
321 if( $plugin == WP_ULIKE_BASENAME ) {
322 // Redirect to the about page
323 if( wp_safe_redirect( admin_url( 'admin.php?page=wp-ulike-about' ) ) ) {
324 exit;
325 }
326 }
327 }
328
329
330 /**
331 * Fired when the plugin is deactivated.
332 *
333 * @since 3.1
334 *
335 * @param boolean $network_wide True if WPMU superadmin uses
336 * "Network Deactivate" action, false if
337 * WPMU is disabled or plugin is
338 * deactivated on an individual blog.
339 */
340 public static function deactivate( $network_wide ) {
341
342 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
343
344 if ( $network_wide ) {
345
346 // Get all blog ids
347 $blog_ids = self::get_blog_ids();
348
349 foreach ( $blog_ids as $blog_id ) {
350 switch_to_blog( $blog_id );
351 self::single_deactivate();
352 }
353
354 restore_current_blog();
355
356 } else {
357 self::single_deactivate();
358 }
359
360 } else {
361 self::single_deactivate();
362 }
363
364 }
365
366
367 /**
368 * Fired for each blog when the plugin is activated.
369 *
370 * @since 3.1
371 */
372 private static function single_activate() {
373
374 global $wpdb;
375
376 if ( ! empty( $wpdb->charset ) ) {
377 $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
378 }
379 if ( ! empty( $wpdb->collate ) ) {
380 $charset_collate .= " COLLATE $wpdb->collate";
381 }
382
383 if( ! function_exists('maybe_create_table') ){
384 // Add one library admin function for next function
385 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
386 }
387
388 // Posts table
389 $posts_table = $wpdb->prefix . "ulike";
390 maybe_create_table( $posts_table, "CREATE TABLE IF NOT EXISTS `{$posts_table}` (
391 `id` bigint(20) NOT NULL AUTO_INCREMENT,
392 `post_id` bigint(20) NOT NULL,
393 `date_time` datetime NOT NULL,
394 `ip` varchar(100) NOT NULL,
395 `user_id` varchar(100) NOT NULL,
396 `status` varchar(30) NOT NULL,
397 PRIMARY KEY (`id`)
398 ) $charset_collate AUTO_INCREMENT=1;" );
399
400 // Comments table
401 $comments_table = $wpdb->prefix . "ulike_comments";
402 maybe_create_table( $comments_table, "CREATE TABLE IF NOT EXISTS `{$comments_table}` (
403 `id` bigint(20) NOT NULL AUTO_INCREMENT,
404 `comment_id` bigint(20) NOT NULL,
405 `date_time` datetime NOT NULL,
406 `ip` varchar(100) NOT NULL,
407 `user_id` varchar(100) NOT NULL,
408 `status` varchar(30) NOT NULL,
409 PRIMARY KEY (`id`)
410 ) $charset_collate AUTO_INCREMENT=1;" );
411
412 // Activities table
413 $activities_table = $wpdb->prefix . "ulike_activities";
414 maybe_create_table( $activities_table, "CREATE TABLE IF NOT EXISTS `{$activities_table}` (
415 `id` bigint(20) NOT NULL AUTO_INCREMENT,
416 `activity_id` bigint(20) NOT NULL,
417 `date_time` datetime NOT NULL,
418 `ip` varchar(100) NOT NULL,
419 `user_id` varchar(100) NOT NULL,
420 `status` varchar(30) NOT NULL,
421 PRIMARY KEY (`id`)
422 ) $charset_collate AUTO_INCREMENT=1;" );
423
424 // Forums table
425 $forums_table = $wpdb->prefix . "ulike_forums";
426 maybe_create_table( $forums_table, "CREATE TABLE IF NOT EXISTS `{$forums_table}` (
427 `id` bigint(20) NOT NULL AUTO_INCREMENT,
428 `topic_id` bigint(20) NOT NULL,
429 `date_time` datetime NOT NULL,
430 `ip` varchar(100) NOT NULL,
431 `user_id` varchar(100) NOT NULL,
432 `status` varchar(30) NOT NULL,
433 PRIMARY KEY (`id`)
434 ) $charset_collate AUTO_INCREMENT=1;" );
435
436 do_action( 'wp_ulike_activated', get_current_blog_id() );
437 }
438
439
440 /**
441 * Fired for each blog when the plugin is deactivated.
442 *
443 * @since 3.1
444 */
445 private static function single_deactivate() {
446 do_action( 'wp_ulike_deactivated' );
447 }
448
449
450 /**
451 * Fired when a new site is activated with a WPMU environment.
452 *
453 * @since 3.1
454 *
455 * @param int $blog_id ID of the new blog.
456 */
457 public function activate_new_site( $blog_id ) {
458 if ( 1 !== did_action( 'wpmu_new_blog' ) ) {
459 return;
460 }
461
462 switch_to_blog( $blog_id );
463 self::single_activate();
464 restore_current_blog();
465 }
466
467 /**
468 * Get all blog ids of blogs in the current network that are:
469 * - not archived
470 * - not spam
471 * - not deleted
472 *
473 * @since 3.1
474 *
475 * @return array|false The blog ids, false if no matches.
476 */
477 private static function get_blog_ids() {
478 global $wpdb;
479
480 // get an array of blog ids
481 $sql = "SELECT blog_id FROM $wpdb->blogs
482 WHERE archived = '0' AND spam = '0'
483 AND deleted = '0'";
484
485 return $wpdb->get_col( $sql );
486 }
487
488 /**
489 * Load the plugin text domain for translation.
490 *
491 * @since 3.1
492 */
493 public function load_plugin_textdomain() {
494 $locale = apply_filters( 'plugin_locale', get_locale(), WP_ULIKE_SLUG );
495 load_textdomain( WP_ULIKE_SLUG, trailingslashit( WP_LANG_DIR ) . WP_ULIKE_SLUG . '/' . WP_ULIKE_SLUG . '-' . $locale . '.mo' );
496 load_plugin_textdomain( WP_ULIKE_SLUG, FALSE, dirname( WP_ULIKE_BASENAME ) . '/lang/' );
497 }
498
499 }
500
501 // Register hooks that are fired when the plugin is activated or deactivated.
502 register_activation_hook ( __FILE__, array( 'WpUlikeInit', 'activate' ) );
503 register_deactivation_hook( __FILE__, array( 'WpUlikeInit', 'deactivate' ) );
504
505 /**
506 * Open WP Ulike World :)
507 *
508 * @since 3.1
509 */
510 function RUN_WPULIKE(){
511 return WpUlikeInit::get_instance();
512 }
513 RUN_WPULIKE();
514
515else :
516
517 function wp_ulike_two_instances_error() {
518 $class = 'notice notice-error';
519 $message = __( 'You are using two instances of WP ULike plugin at same time, please deactive one of them.', WP_ULIKE_SLUG );
520 printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
521 }
522 add_action( 'admin_notices', 'wp_ulike_two_instances_error' );
523
524endif;
525
526/*============================================================================*/