first
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
defined( 'ABSPATH' ) or die( 'No script kiddies please!!' );
|
||||
if ( !class_exists( 'PLD_Activation' ) ) {
|
||||
|
||||
class PLD_Activation extends PLD_Library {
|
||||
|
||||
/**
|
||||
* Includes all the activation tasks
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function __construct() {
|
||||
register_activation_hook( PLD_PATH . 'posts-like-dislike.php', array( $this, 'activation_tasks' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Store default settings in database on activation
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function activation_tasks() {
|
||||
$default_settings = $this->get_default_settings();
|
||||
if(!get_option('pld_settings')){
|
||||
update_option('pld_settings',$default_settings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
new PLD_Activation();
|
||||
}
|
156
wp-content/plugins/posts-like-dislike/inc/classes/pld-admin.php
Normal file
156
wp-content/plugins/posts-like-dislike/inc/classes/pld-admin.php
Normal file
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
defined('ABSPATH') or die('No script kiddies please!!');
|
||||
|
||||
if (!class_exists('PLD_Admin')) {
|
||||
|
||||
class PLD_Admin extends PLD_Library {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
add_action('admin_menu', array($this, 'pld_admin_menu'));
|
||||
|
||||
/**
|
||||
* Plugin Settings link in plugins screen
|
||||
*
|
||||
*/
|
||||
add_filter('plugin_action_links_' . PLD_BASENAME, array($this, 'add_setting_link'));
|
||||
|
||||
/**
|
||||
* Settings save action
|
||||
*/
|
||||
add_action('wp_ajax_pld_settings_save_action', array($this, 'save_settings'));
|
||||
add_action('wp_ajax_nopriv_pld_settings_save_action', array($this, 'no_permission'));
|
||||
|
||||
/**
|
||||
* Settings restore action
|
||||
*/
|
||||
add_action('wp_ajax_pld_settings_restore_action', array($this, 'restore_settings'));
|
||||
add_action('wp_ajax_nopriv_pld_settings_restore_action', array($this, 'no_permission'));
|
||||
|
||||
/**
|
||||
* Count Info Meta Box
|
||||
*/
|
||||
add_action('add_meta_boxes', array($this, 'render_count_info_metabox'));
|
||||
|
||||
/**
|
||||
* Save posts like dislike meta box
|
||||
*/
|
||||
add_action('save_post', array($this, 'save_pld_metabox'));
|
||||
}
|
||||
|
||||
function pld_admin_menu() {
|
||||
add_options_page(__('Posts Like Dislike', 'posts-like-dislike'), __('Posts Like Dislike', 'posts-like-dislike'), 'manage_options', 'posts-like-dislike', array($this, 'pld_settings'));
|
||||
}
|
||||
|
||||
function pld_settings() {
|
||||
include(PLD_PATH . 'inc/views/backend/settings.php');
|
||||
}
|
||||
|
||||
function save_settings() {
|
||||
if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pld-backend-ajax-nonce') && current_user_can('manage_options')) {
|
||||
$_POST = stripslashes_deep($_POST);
|
||||
parse_str($_POST['settings_data'], $settings_data);
|
||||
$settings_data = $this->sanitize_array($settings_data);
|
||||
$pld_settings = $settings_data['pld_settings'];
|
||||
/**
|
||||
* Fires before storing the settings array into database
|
||||
*
|
||||
* @param type array $settings_data - before sanitization
|
||||
* @param type array $pld_settings - after sanitization
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
do_action('pld_before_save_settings', $settings_data, $pld_settings);
|
||||
|
||||
/**
|
||||
* Filters the settings stored in the database
|
||||
*
|
||||
* @param type array $pld_settings
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
update_option('pld_settings', apply_filters('pld_settings', $pld_settings));
|
||||
die(__('Settings saved successfully', PLD_TD));
|
||||
} else {
|
||||
die('No script kiddies please!!');
|
||||
}
|
||||
}
|
||||
|
||||
function no_permission() {
|
||||
die('No script kiddies please!!');
|
||||
}
|
||||
|
||||
function restore_settings() {
|
||||
if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pld-backend-ajax-nonce') && current_user_can('manage_options')) {
|
||||
$default_settings = $this->get_default_settings();
|
||||
update_option('pld_settings', $default_settings);
|
||||
die(__('Settings restored successfully.Redirecting...', PLD_TD));
|
||||
} else {
|
||||
die('No script kiddies please!!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds settings link
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function add_setting_link($links) {
|
||||
$settings_link = array(
|
||||
'<a href="' . admin_url('options-general.php?page=posts-like-dislike') . '">' . __('Settings', PLD_TD) . '</a>',
|
||||
);
|
||||
return array_merge($links, $settings_link);
|
||||
}
|
||||
|
||||
function render_count_info_metabox() {
|
||||
$pld_settings = $this->pld_settings;
|
||||
$post_types = (!empty($pld_settings['basic_settings']['post_types'])) ? $pld_settings['basic_settings']['post_types'] : array();
|
||||
if (empty($pld_settings['basic_settings']['hide_counter_info_metabox']) && !empty($post_types)) {
|
||||
add_meta_box('pld-count-info', esc_html__('Posts Like Dislike', 'posts-like-dislike'), array($this, 'render_count_info_html'), $post_types, 'normal');
|
||||
}
|
||||
}
|
||||
|
||||
function render_count_info_html($post) {
|
||||
$post_id = $post->ID;
|
||||
$like_count = get_post_meta($post_id, 'pld_like_count', true);
|
||||
$dislike_count = get_post_meta($post_id, 'pld_dislike_count', true);
|
||||
include(PLD_PATH . '/inc/views/backend/pld-metabox.php');
|
||||
}
|
||||
|
||||
function save_pld_metabox($post_id) {
|
||||
$nonce_name = isset($_POST['pld_metabox_nonce_field']) ? $_POST['pld_metabox_nonce_field'] : '';
|
||||
$nonce_action = 'pld_metabox_nonce';
|
||||
|
||||
// Check if nonce is valid.
|
||||
if (!wp_verify_nonce($nonce_name, $nonce_action)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if user has permissions to save data.
|
||||
if (!current_user_can('edit_post', $post_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if not an autosave.
|
||||
if (wp_is_post_autosave($post_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if not a revision.
|
||||
if (wp_is_post_revision($post_id)) {
|
||||
return;
|
||||
}
|
||||
if (isset($_POST['pld_like_count'], $_POST['pld_dislike_count'])) {
|
||||
$pld_like_count = sanitize_text_field($_POST['pld_like_count']);
|
||||
$pld_dislike_count = sanitize_text_field($_POST['pld_dislike_count']);
|
||||
update_post_meta($post_id, 'pld_like_count', $pld_like_count);
|
||||
update_post_meta($post_id, 'pld_dislike_count', $pld_dislike_count);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new PLD_Admin();
|
||||
}
|
315
wp-content/plugins/posts-like-dislike/inc/classes/pld-ajax.php
Normal file
315
wp-content/plugins/posts-like-dislike/inc/classes/pld-ajax.php
Normal file
@@ -0,0 +1,315 @@
|
||||
<?php
|
||||
|
||||
if (!class_exists('PLD_Ajax')) {
|
||||
|
||||
class PLD_Ajax extends PLD_Library {
|
||||
|
||||
function __construct() {
|
||||
add_action('wp_ajax_pld_post_ajax_action', array($this, 'like_dislike_action'));
|
||||
add_action('wp_ajax_nopriv_pld_post_ajax_action', array($this, 'like_dislike_action'));
|
||||
|
||||
add_action('wp_ajax_pld_post_undo_ajax_action', array($this, 'like_dislike_undo_action'));
|
||||
add_action('wp_ajax_nopriv_pld_post_undo_ajax_action', array($this, 'like_dislike_undo_action'));
|
||||
}
|
||||
|
||||
function like_dislike_action() {
|
||||
if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pld-ajax-nonce')) {
|
||||
$post_id = sanitize_text_field($_POST['post_id']);
|
||||
/**
|
||||
* Action pld_before_ajax_process
|
||||
*
|
||||
* @param type int $post_id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
do_action('pld_before_ajax_process', $post_id);
|
||||
$pld_settings = get_option('pld_settings');
|
||||
|
||||
/**
|
||||
* Cookie Restriction Validation
|
||||
*
|
||||
*/
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'cookie' && isset($_COOKIE['pld_' . $post_id])) {
|
||||
$response_array = array('success' => true, 'message' => 'Invalid action');
|
||||
echo json_encode($response_array);
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* IP Restriction Validation
|
||||
*/
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'ip') {
|
||||
$liked_ips = get_post_meta($post_id, 'pld_ips', true);
|
||||
$user_ip = $this->get_user_IP();
|
||||
if (empty($liked_ips)) {
|
||||
$liked_ips = array();
|
||||
}
|
||||
if (in_array($user_ip, $liked_ips)) {
|
||||
$response_array = array('success' => true, 'message' => 'Invalid action');
|
||||
echo json_encode($response_array);
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User Logged In validation
|
||||
*/
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'user') {
|
||||
if (is_user_logged_in()) {
|
||||
$liked_users = get_post_meta($post_id, 'pld_users', true);
|
||||
$liked_users = (empty($liked_users)) ? array() : $liked_users;
|
||||
$current_user_id = get_current_user_id();
|
||||
if (in_array($current_user_id, $liked_users)) {
|
||||
$response_array = array('success' => true, 'message' => 'Invalid action');
|
||||
echo json_encode($response_array);
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
$response_array = array('success' => true, 'message' => 'Invalid action');
|
||||
echo json_encode($response_array);
|
||||
die();
|
||||
}
|
||||
}
|
||||
$type = sanitize_text_field($_POST['type']);
|
||||
|
||||
if ($type == 'like') {
|
||||
$like_count = get_post_meta($post_id, 'pld_like_count', true);
|
||||
if (empty($like_count)) {
|
||||
$like_count = 0;
|
||||
}
|
||||
$like_count = $like_count + 1;
|
||||
$check = update_post_meta($post_id, 'pld_like_count', $like_count);
|
||||
|
||||
if ($check) {
|
||||
|
||||
$response_array = array('success' => true, 'latest_count' => $like_count);
|
||||
} else {
|
||||
$response_array = array('success' => false, 'latest_count' => $like_count);
|
||||
}
|
||||
} else {
|
||||
$dislike_count = get_post_meta($post_id, 'pld_dislike_count', true);
|
||||
if (empty($dislike_count)) {
|
||||
$dislike_count = 0;
|
||||
}
|
||||
$dislike_count = $dislike_count + 1;
|
||||
$check = update_post_meta($post_id, 'pld_dislike_count', $dislike_count);
|
||||
if ($check) {
|
||||
$response_array = array('success' => true, 'latest_count' => $dislike_count);
|
||||
} else {
|
||||
$response_array = array('success' => false, 'latest_count' => $dislike_count);
|
||||
}
|
||||
}
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'cookie') {
|
||||
setcookie('pld_' . $post_id, $type, time() + 365 * 24 * 60 * 60, '/');
|
||||
}
|
||||
/**
|
||||
* Check the liked ips and insert the user ips for future checking
|
||||
*
|
||||
*/
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'ip') {
|
||||
$liked_ips = get_post_meta($post_id, 'pld_ips', true);
|
||||
$liked_ips = (empty($liked_ips)) ? array() : $liked_ips;
|
||||
|
||||
$liked_ips_info = get_comment_meta($post_id, 'pld_ips_info', true);
|
||||
$liked_ips_info = (empty($liked_ips_info)) ? array() : $liked_ips_info;
|
||||
if (!in_array($user_ip, $liked_ips)) {
|
||||
$liked_ips[] = $user_ip;
|
||||
$liked_ips_info[md5($user_ip)] = $type;
|
||||
}
|
||||
update_post_meta($post_id, 'pld_ips', $liked_ips);
|
||||
update_post_meta($post_id, 'pld_ips_info', $liked_ips_info);
|
||||
}
|
||||
/**
|
||||
* Check if user is logged in to check user login for like dislike action
|
||||
*/
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'user') {
|
||||
if (is_user_logged_in()) {
|
||||
|
||||
$liked_users = get_post_meta($post_id, 'pld_users', true);
|
||||
$liked_users = (empty($liked_users)) ? array() : $liked_users;
|
||||
|
||||
$liked_users_info = get_post_meta($post_id, 'pld_users_info', true);
|
||||
$liked_users_info = (empty($liked_users_info)) ? array() : $liked_users_info;
|
||||
$current_user_id = get_current_user_id();
|
||||
if (!in_array($current_user_id, $liked_users)) {
|
||||
$liked_users[] = $current_user_id;
|
||||
}
|
||||
$liked_users_info[$current_user_id] = $type;
|
||||
update_post_meta($post_id, 'pld_users', $liked_users);
|
||||
update_comment_meta($post_id, 'pld_users_info', $liked_users_info);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action pld_after_ajax_process
|
||||
*
|
||||
* @param type int $post_id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
do_action('pld_after_ajax_process', $post_id);
|
||||
echo json_encode($response_array);
|
||||
|
||||
//$this->print_array( $response_array );
|
||||
die();
|
||||
} else {
|
||||
die('No script kiddies please!');
|
||||
}
|
||||
}
|
||||
|
||||
function like_dislike_undo_action() {
|
||||
if (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pld-ajax-nonce')) {
|
||||
$post_id = sanitize_text_field($_POST['post_id']);
|
||||
/**
|
||||
* Action pld_before_undo_ajax_process
|
||||
* Fires just before the undo ajax process
|
||||
*
|
||||
* @param type int $post_id
|
||||
*
|
||||
* @since 1.1.9
|
||||
*/
|
||||
do_action('pld_before_undo_ajax_process', $post_id);
|
||||
|
||||
|
||||
|
||||
$type = sanitize_text_field($_POST['type']);
|
||||
|
||||
$pld_settings = get_option('pld_settings');
|
||||
|
||||
/**
|
||||
* Cookie Validation
|
||||
*/
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'cookie' && !isset($_COOKIE['pld_' . $post_id])) {
|
||||
$response_array = array('success' => false, 'message' => 'Invalid action');
|
||||
echo json_encode($response_array);
|
||||
die();
|
||||
}
|
||||
/**
|
||||
* IP Validation
|
||||
*/
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'ip') {
|
||||
$user_ip = $this->get_user_IP();
|
||||
|
||||
$liked_ips = get_post_meta($post_id, 'pld_ips', true);
|
||||
|
||||
if (empty($liked_ips)) {
|
||||
$liked_ips = array();
|
||||
}
|
||||
if ((!in_array($user_ip, $liked_ips))) {
|
||||
$response_array = array('success' => false, 'message' => 'Invalid action');
|
||||
echo json_encode($response_array);
|
||||
die();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* User Logged in validation
|
||||
*/
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'user') {
|
||||
if (is_user_logged_in()) {
|
||||
$liked_users = get_post_meta($post_id, 'pld_users', true);
|
||||
$liked_users = (empty($liked_users)) ? array() : $liked_users;
|
||||
$current_user_id = get_current_user_id();
|
||||
if (!in_array($current_user_id, $liked_users)) {
|
||||
$response_array = array('success' => false, 'message' => 'Invalid action');
|
||||
echo json_encode($response_array);
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
$response_array = array('success' => false, 'message' => 'Invalid action');
|
||||
echo json_encode($response_array);
|
||||
die();
|
||||
}
|
||||
}
|
||||
if ($type == 'like') {
|
||||
$like_count = get_post_meta($post_id, 'pld_like_count', true);
|
||||
if (empty($like_count)) {
|
||||
$like_count = 0;
|
||||
}
|
||||
$like_count = $like_count - 1;
|
||||
$check = update_post_meta($post_id, 'pld_like_count', $like_count);
|
||||
|
||||
if ($check) {
|
||||
|
||||
$response_array = array('success' => true, 'latest_count' => $like_count);
|
||||
} else {
|
||||
$response_array = array('success' => false, 'latest_count' => $like_count);
|
||||
}
|
||||
} else {
|
||||
$dislike_count = get_post_meta($post_id, 'pld_dislike_count', true);
|
||||
if (empty($dislike_count)) {
|
||||
$dislike_count = 0;
|
||||
}
|
||||
$dislike_count = $dislike_count - 1;
|
||||
$check = update_post_meta($post_id, 'pld_dislike_count', $dislike_count);
|
||||
if ($check) {
|
||||
$response_array = array('success' => true, 'latest_count' => $dislike_count);
|
||||
} else {
|
||||
$response_array = array('success' => false, 'latest_count' => $dislike_count);
|
||||
}
|
||||
}
|
||||
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'cookie') {
|
||||
$cookie_name = 'pld_' . $post_id;
|
||||
setcookie($cookie_name, $type, time() - 3600 * 24 * 365, '/');
|
||||
}
|
||||
/**
|
||||
* Check the liked ips and insert the user ips for future checking
|
||||
*
|
||||
*/
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'ip') {
|
||||
$liked_ips = get_post_meta($post_id, 'pld_ips', true);
|
||||
$liked_ips = (empty($liked_ips)) ? array() : $liked_ips;
|
||||
|
||||
$liked_ips_info = get_post_meta($post_id, 'pld_ips_info', true);
|
||||
$liked_ips_info = (empty($liked_ips_info)) ? array() : $liked_ips_info;
|
||||
if (in_array($user_ip, $liked_ips)) {
|
||||
$liked_ips = array_diff($liked_ips, [$user_ip]);
|
||||
unset($liked_ips_info[md5($user_ip)]);
|
||||
}
|
||||
|
||||
update_post_meta($post_id, 'pld_ips', $liked_ips);
|
||||
update_post_meta($post_id, 'pld_ips_info', $liked_ips_info);
|
||||
}
|
||||
/**
|
||||
* Check if user is logged in to check user login for like dislike action
|
||||
*/
|
||||
if ($pld_settings['basic_settings']['like_dislike_resistriction'] == 'user') {
|
||||
if (is_user_logged_in()) {
|
||||
|
||||
$liked_users = get_post_meta($post_id, 'pld_users', true);
|
||||
$liked_users = (empty($liked_users)) ? array() : $liked_users;
|
||||
|
||||
$liked_users_info = get_post_meta($post_id, 'pld_users_info', true);
|
||||
$liked_users_info = (empty($liked_users_info)) ? array() : $liked_users_info;
|
||||
|
||||
$current_user_id = get_current_user_id();
|
||||
if (in_array($current_user_id, $liked_users)) {
|
||||
$liked_users = array_diff($liked_users, [$current_user_id]);
|
||||
unset($liked_users_info[$current_user_id]);
|
||||
}
|
||||
|
||||
update_post_meta($post_id, 'pld_users', $liked_users);
|
||||
update_post_meta($post_id, 'pld_users_info', $liked_users_info);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Action pld_after_undo_ajax_process
|
||||
* Fires just after the undo ajax process
|
||||
*
|
||||
* @param type int $post_id
|
||||
*
|
||||
* @since 1.1.9
|
||||
*/
|
||||
do_action('pld_after_undo_ajax_process', $post_id);
|
||||
echo json_encode($response_array);
|
||||
|
||||
//$this->print_array( $response_array );
|
||||
die();
|
||||
} else {
|
||||
die('No script kiddies please!');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new PLD_Ajax();
|
||||
}
|
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
if (!class_exists('PLD_Enqueue')) {
|
||||
|
||||
class PLD_Enqueue {
|
||||
|
||||
/**
|
||||
* Includes all the frontend and backend JS and CSS enqueues
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function __construct() {
|
||||
add_action('wp_enqueue_scripts', array($this, 'register_frontend_assets'));
|
||||
add_action('admin_enqueue_scripts', array($this, 'register_backend_assets'));
|
||||
}
|
||||
|
||||
function register_frontend_assets() {
|
||||
$pld_settings = get_option('pld_settings');
|
||||
if (empty($pld_settings['design_settings']['disable_fontawesome'])) {
|
||||
/**
|
||||
* Fontawesome 5 support
|
||||
*
|
||||
* @version 1.0.6
|
||||
*/
|
||||
wp_enqueue_style('pld-font-awesome', PLD_CSS_DIR . '/fontawesome/css/all.min.css', array(), PLD_VERSION);
|
||||
}
|
||||
wp_enqueue_style('pld-frontend', PLD_CSS_DIR . '/pld-frontend.css', array(), PLD_VERSION);
|
||||
wp_enqueue_script('pld-frontend', PLD_JS_DIR . '/pld-frontend.js', array('jquery'), PLD_VERSION);
|
||||
$ajax_nonce = wp_create_nonce('pld-ajax-nonce');
|
||||
|
||||
$js_object = array('admin_ajax_url' => admin_url('admin-ajax.php'), 'admin_ajax_nonce' => $ajax_nonce);
|
||||
wp_localize_script('pld-frontend', 'pld_js_object', $js_object);
|
||||
}
|
||||
|
||||
function register_backend_assets($hook) {
|
||||
wp_enqueue_style('wp-color-picker');
|
||||
wp_enqueue_media();
|
||||
wp_enqueue_style('pld-admin-css', PLD_CSS_DIR . '/pld-backend.css', array(), PLD_VERSION);
|
||||
wp_enqueue_script('pld-admin-js', PLD_JS_DIR . '/pld-backend.js', array('jquery', 'wp-color-picker'), PLD_VERSION);
|
||||
$ajax_nonce = wp_create_nonce('pld-backend-ajax-nonce');
|
||||
$messages = array('wait' => __('Please wait', PLD_TD), 'restore_confirm' => __('Are you sure you want to restore default settings?', PLD_TD));
|
||||
$js_object = array('admin_ajax_url' => admin_url('admin-ajax.php'), 'admin_ajax_nonce' => $ajax_nonce, 'messages' => $messages);
|
||||
wp_localize_script('pld-admin-js', 'pld_admin_js_object', $js_object);
|
||||
}
|
||||
}
|
||||
|
||||
new PLD_Enqueue();
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
if (!class_exists('PLD_Hooks')) {
|
||||
class PLD_Hooks extends PLD_Library
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
add_filter('the_content', array($this, 'posts_like_dislike'), 200); // hook to add html for like dislike
|
||||
add_action('pld_like_dislike_output', array($this, 'generate_like_dislike_html'), 10, 3);
|
||||
add_action('wp_head', array($this, 'custom_styles'));
|
||||
add_shortcode('posts_like_dislike', array($this, 'render_pld_shortcode'));
|
||||
}
|
||||
|
||||
public function posts_like_dislike($content)
|
||||
{
|
||||
include(PLD_PATH . '/inc/cores/like-dislike-render.php');
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function render_pld_shortcode($atts)
|
||||
{
|
||||
$content = '';
|
||||
$shortcode = true;
|
||||
include(PLD_PATH . '/inc/cores/like-dislike-render.php');
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function generate_like_dislike_html($content, $shortcode, $atts)
|
||||
{
|
||||
include(PLD_PATH . '/inc/views/frontend/like-dislike-html.php');
|
||||
}
|
||||
|
||||
public function custom_styles()
|
||||
{
|
||||
$pld_settings = $this->pld_settings;
|
||||
echo "<style>";
|
||||
if ($pld_settings['design_settings']['icon_color'] != '') {
|
||||
echo 'a.pld-like-dislike-trigger {color: ' . esc_attr($pld_settings['design_settings']['icon_color']) . ';}';
|
||||
}
|
||||
if ($pld_settings['design_settings']['count_color'] != '') {
|
||||
echo 'span.pld-count-wrap {color: ' . esc_attr($pld_settings['design_settings']['count_color']) . ';}';
|
||||
}
|
||||
if (!empty($pld_settings['design_settings']['already_liked_disliked_color'])) {
|
||||
echo 'a.pld-prevent.pld-undo-trigger {color: ' . esc_html($pld_settings['design_settings']['already_liked_disliked_color']) . ';}';
|
||||
}
|
||||
echo "</style>";
|
||||
}
|
||||
}
|
||||
|
||||
new PLD_Hooks();
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
if(!class_exists('PLD_Init')){
|
||||
class PLD_Init{
|
||||
function __construct(){
|
||||
add_action('init',array($this,'pld_init'));
|
||||
}
|
||||
|
||||
function pld_init(){
|
||||
load_plugin_textdomain( 'posts-like-dislike', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
|
||||
/**
|
||||
* Fires when Init hook is fired through plugin
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
do_action('pld_init');
|
||||
}
|
||||
}
|
||||
|
||||
new PLD_Init();
|
||||
}
|
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
if (!class_exists('PLD_Library')) {
|
||||
|
||||
class PLD_Library {
|
||||
|
||||
var $pld_settings;
|
||||
|
||||
function __construct() {
|
||||
$this->pld_settings = get_option('pld_settings');
|
||||
}
|
||||
|
||||
function print_array($array) {
|
||||
echo "<pre>";
|
||||
print_r($array);
|
||||
echo "</pre>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default settings array
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function get_default_settings() {
|
||||
$default_settings = array();
|
||||
$default_settings['basic_settings']['status'] = 0;
|
||||
$default_settings['basic_settings']['like_dislike_position'] = 'after';
|
||||
$default_settings['basic_settings']['like_dislike_display'] = 'both';
|
||||
$default_settings['basic_settings']['like_dislike_resistriction'] = 'cookie';
|
||||
$default_settings['basic_settings']['display_order'] = 'like-dislike';
|
||||
$default_settings['basic_settings']['like_hover_text'] = '';
|
||||
$default_settings['basic_settings']['dislike_hover_text'] = '';
|
||||
$default_settings['design_settings']['template'] = 'template-1';
|
||||
$default_settings['design_settings']['like_icon'] = '';
|
||||
$default_settings['design_settings']['dislike_icon'] = '';
|
||||
$default_settings['design_settings']['icon_color'] = '';
|
||||
$default_settings['design_settings']['count_color'] = '';
|
||||
/**
|
||||
* Filters deault settings
|
||||
*
|
||||
* @param type array $default_settings
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
return apply_filters('pld_default_settings', $default_settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns visitors IP address
|
||||
*
|
||||
* @return string $ip
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function get_user_IP() {
|
||||
$client = (!empty($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : '';
|
||||
$forward = (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : '';
|
||||
$remote = (!empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : '';
|
||||
|
||||
if (filter_var($client, FILTER_VALIDATE_IP)) {
|
||||
$ip = $client;
|
||||
} elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
|
||||
$ip = $forward;
|
||||
} else {
|
||||
$ip = $remote;
|
||||
}
|
||||
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes Multi Dimensional Array
|
||||
* @param array $array
|
||||
* @param array $sanitize_rule
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function sanitize_array($array = array(), $sanitize_rule = array()) {
|
||||
if (!is_array($array) || count($array) == 0) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($array as $k => $v) {
|
||||
if (!is_array($v)) {
|
||||
|
||||
$default_sanitize_rule = (is_numeric($k)) ? 'html' : 'text';
|
||||
$sanitize_type = isset($sanitize_rule[$k]) ? $sanitize_rule[$k] : $default_sanitize_rule;
|
||||
$array[$k] = $this->sanitize_value($v, $sanitize_type);
|
||||
}
|
||||
if (is_array($v)) {
|
||||
$array[$k] = $this->sanitize_array($v, $sanitize_rule);
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes Value
|
||||
*
|
||||
* @param type $value
|
||||
* @param type $sanitize_type
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function sanitize_value($value = '', $sanitize_type = 'text') {
|
||||
switch ($sanitize_type) {
|
||||
case 'html':
|
||||
return $this->sanitize_html($value);
|
||||
break;
|
||||
case 'none':
|
||||
return $value;
|
||||
break;
|
||||
default:
|
||||
return sanitize_text_field($value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitizes the content by bypassing allowed html
|
||||
*
|
||||
* @param string $text
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
function sanitize_html($text) {
|
||||
$allowed_html = wp_kses_allowed_html('post');
|
||||
return wp_kses($text, $allowed_html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints display none
|
||||
*
|
||||
* @param string $param1
|
||||
* @param string $param2
|
||||
*
|
||||
* @since 1.0.5
|
||||
*/
|
||||
function display_none($param1, $param2) {
|
||||
if ($param1 != $param2) {
|
||||
echo 'style="display:none"';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current page URL
|
||||
*
|
||||
* @since 1.0.5
|
||||
*/
|
||||
function get_current_page_url() {
|
||||
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
|
||||
$url = "https://";
|
||||
else
|
||||
$url = "http://";
|
||||
// Append the host(domain name, ip) to the URL.
|
||||
$url .= $_SERVER['HTTP_HOST'];
|
||||
|
||||
// Append the requested resource location to the URL
|
||||
$url .= $_SERVER['REQUEST_URI'];
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user