Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/web-directory-free/addons/w2dc_ratings/classes/comments_manager.php
+++ b/web-directory-free/addons/w2dc_ratings/classes/comments_manager.php
@@ -1,148 +0,0 @@
-<?php
-
-// @codingStandardsIgnoreFile
-
-class w2dc_comments_manager {
-
- public function __construct() {
- add_action('wp_ajax_w2dc_comments_add_comment', array($this, 'comments_add_comment'));
- add_action('wp_ajax_nopriv_w2dc_comments_add_comment', array($this, 'comments_add_comment'));
- add_action('wp_ajax_w2dc_comments_load_template', array($this, 'comments_load_template'));
- add_action('wp_ajax_nopriv_w2dc_comments_load_template', array($this, 'comments_load_template'));
- }
-
- public function comments_load_template() {
- check_ajax_referer('w2dc_comments_nonce', 'security');
-
- $this->display_comments_node($_POST['post_id']);
-
- die();
- }
-
- public function display_comments_node($post_id, $parent = '') {
- $comments = get_comments(array(
- 'post_id' => (int)$post_id,
- 'number' => 100,
- 'status' => 'approve',
- 'order' => 'ASC',
- 'parent' => (int)$parent
- ));
-
- if ($comments):
- ?>
- <div class="w2dc-comments-container">
- <?php foreach ($comments as $comment) : ?>
- <?php $this->display_comment($comment); ?>
- <?php $this->display_comments_node($post_id, $comment->comment_ID); ?>
- <?php endforeach; ?>
- </div>
- <?php
- endif;
- }
-
- public function display_comment($comment) {
- $user = new WP_User($comment->user_id);
- $class = null;
- if (!empty($user->roles) && is_array($user->roles)) {
- foreach ($user->roles as $role) {
- $class = $role;
- }
- } else {
- $class = 'annon';
- }
- ?>
- <div class="w2dc-comments-content w2dc-comments-<?php w2dc_esc_e($class); ?>" id="comment-<?php w2dc_esc_e($comment->comment_ID); ?>">
- <div class="w2dc-comments-p">
- <?php w2dc_comments_profile_pic($comment->comment_author_email); ?>
- <?php print $comment->comment_content; ?><br />
- <time class="meta">
- <strong><?php $user = get_user_by('login', $comment->comment_author); if (!empty($user->user_url)) : ?><a href="<?php print $user->user_url; ?>" target="_blank"><?php print $comment->comment_author; ?></a><?php else : ?><?php print $comment->comment_author; ?><?php endif; ?></strong>
- <?php print human_time_diff(strtotime($comment->comment_date), current_time('timestamp')); ?> ago. <a class="w2dc-comment-reply" data-comment-id="<?php w2dc_esc_e($comment->comment_ID); ?>" data-comment-author="<?php echo esc_attr($comment->comment_author); ?>" href="javascript: void(0);"><?php esc_html_e('Reply ↓', 'w2dc'); ?></a>
- </time>
- </div>
- </div>
- <?php
- }
-
- /**
- * Inserts a comment for the current post if the user is logged in.
- *
- * @since 0.1-alpha
- * @uses check_ajax_referer()
- * @uses is_user_logged_in()
- * @uses wp_insert_comment()
- * @uses wp_get_current_user()
- * @uses current_time()
- * @uses wp_kses()
- * @uses get_option()
- */
- public function comments_add_comment() {
- check_ajax_referer('w2dc_comments_nonce', 'security');
-
- $comment = trim(
- wp_kses( $_POST['comment'],
- array(
- 'a' => array(
- 'href' => array(),
- 'title' => array()
- ),
- 'br' => array(),
- 'em' => array(),
- 'strong' => array(),
- 'blockquote' => array(),
- 'code' => array()
- )
- )
- );
-
- if (empty($comment)) die();
-
- if (get_option('comment_registration') == 1 && ! is_user_logged_in()) die();
-
- $data = array(
- 'comment_post_ID' => (int)$_POST['post_id'],
- 'comment_content' => $comment,
- 'comment_type' => '',
- 'comment_parent' => (int)$_POST['comment_parent'],
- 'comment_author_IP' => $_SERVER['REMOTE_ADDR'],
- 'comment_agent' => $_SERVER['HTTP_USER_AGENT'],
- 'comment_date' => current_time('mysql'),
- 'comment_approved' => 1
- );
-
- if (is_user_logged_in()) {
- $current_user = wp_get_current_user();
-
- $author_email = $current_user->user_email;
- $author_url = $current_user->user_url;
- $author_name = $current_user->user_nicename;
-
- $data['user_id'] = $current_user->ID;
- } else {
- $author_email = empty( $_POST['user_email'] ) ? null : esc_attr( $_POST['user_email'] );
- $author_url = empty( $_POST['user_url'] ) ? null : esc_url( $_POST['user_url'], array('http','https') );
- $author_name = empty( $_POST['user_name'] ) ? null : esc_attr( $_POST['user_name'] );
- }
-
- $data['comment_author'] = $author_name;
- $data['comment_author_email'] = $author_email;
- $data['comment_author_url'] = $author_url;
-
- wp_insert_comment($data);
-
- die();
- }
-}
-
-function w2dc_comments_profile_pic($id_or_email = null, $email = null) {
- if (is_null($id_or_email)) {
- $current_user = wp_get_current_user();
- $id_or_email = $current_user->ID;
- }
-
- $html = get_avatar($id_or_email, 32);
-
- echo '<span class="w2dc-comments-profile-pic-container">' . $html . '</span>';
-}
-
-?>
No newline at end of file
--- a/web-directory-free/addons/w2dc_ratings/classes/ratings.php
+++ b/web-directory-free/addons/w2dc_ratings/classes/ratings.php
@@ -1,113 +0,0 @@
-<?php
-
-// @codingStandardsIgnoreFile
-
-class w2dc_avg_rating {
- public $ratings = array();
- public $ratings_count = 0;
- public $avg_value = 0;
-
- private $post_id;
-
- public function __construct($post_id) {
- global $wpdb;
-
- $this->post_id = $post_id;
-
- $like = $wpdb->esc_like(W2DC_RATING_PREFIX);
-
- $results = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->postmeta} WHERE post_id=%d AND meta_key LIKE %s", $post_id, $like.'%'), ARRAY_A);
- foreach ($results AS $row) {
- $rating = new w2dc_rating($row);
- $this->ratings[] = $rating;
- $this->avg_value += $rating->value;
- $this->ratings_count++;
- }
- if ($this->ratings_count) {
- $this->avg_value = $this->avg_value/$this->ratings_count;
- }
- $this->avg_value = number_format(round($this->avg_value, 1), 1);
- }
-
- public function update_avg_rating() {
- update_post_meta($this->post_id, W2DC_AVG_RATING_KEY, $this->avg_value);
- }
-
- public function render_star($star_num) {
- $sub = $this->avg_value - $star_num;
- if ($sub >= 0 || abs($sub) <= 0.25) {
- return 'w2dc-fa-star';
- } elseif (abs($sub) >= 0.25 && abs($sub) <= 0.75) {
- return 'w2dc-fa-star-half-o';
- } else {
- return 'w2dc-fa-star-o';
- }
- }
-
- public function get_percents_counts($counts) {
- if ($this->ratings) {
- return round($counts/$this->ratings_count*100);
- } else {
- return 0;
- }
- }
-
- public function calculateTotals() {
- $total_counts = array('1' => 0, '2' => 0, '3' => 0, '4' => 0, '5' => 0);
- foreach ($this->ratings AS $rating) {
- $total_counts[round($rating->value)]++;
- }
- krsort($total_counts);
-
- return $total_counts;
- }
-}
-
-class w2dc_rating {
- public $user_id;
- public $ip;
- public $value;
-
- private static $validation;
-
- public function __construct($row) {
- $this->value = $row['meta_value'];
-
- $part = str_replace(W2DC_RATING_PREFIX, '', $row['meta_key']);
-
- if (!self::$validation) {
- self::$validation = new w2dc_form_validation();
- }
-
- if (self::$validation->valid_ip($part)) {
- $this->ip = $part;
- } else {
- $this->user_id = $part;
- }
- }
-
- public function render_star($star_num) {
- if ($this->value >= $star_num) {
- return 'w2dc-fa-star';
- } else {
- return 'w2dc-fa-star-o';
- }
- }
-}
-
-function w2dc_build_single_rating($post_id, $user_id) {
- global $wpdb;
-
- if ($row = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->postmeta} WHERE post_id=%d AND meta_key=%s", $post_id, W2DC_RATING_PREFIX.$user_id), ARRAY_A)) {
- $rating = new w2dc_rating($row);
- return $rating;
- }
-}
-
-function w2dc_reset_ratings($post_id) {
- global $wpdb;
-
- return ($wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id=%d AND (meta_key=%s OR meta_key LIKE %s)", $post_id, W2DC_AVG_RATING_KEY, W2DC_RATING_PREFIX.'%')) !== false) ? true : false;
-}
-
-?>
No newline at end of file
--- a/web-directory-free/addons/w2dc_ratings/templates/avg_rating.tpl.php
+++ b/web-directory-free/addons/w2dc_ratings/templates/avg_rating.tpl.php
@@ -1,27 +0,0 @@
-<?php
-
-// @codingStandardsIgnoreFile
-
-?>
-<div class="w2dc-rating" <?php if ($meta_tags && $avg_rating->ratings_count): ?>itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating"<?php endif; ?>>
- <?php if ($meta_tags && $avg_rating->ratings_count): ?>
- <?php if ($review_count = get_comments_number()): ?><meta itemprop="reviewCount" content="<?php w2dc_esc_e($review_count); ?>" /><?php endif; ?>
- <meta itemprop="ratingValue" content="<?php w2dc_esc_e($avg_rating->avg_value); ?>" />
- <meta itemprop="ratingCount" content="<?php w2dc_esc_e($avg_rating->ratings_count); ?>" />
- <?php endif; ?>
- <?php if ($show_avg): ?>
- <span class="w2dc-rating-avgvalue">
- <span><?php w2dc_esc_e($avg_rating->avg_value); ?></span>
- </span>
- <?php endif; ?>
- <div class="w2dc-rating-stars <?php if ($active): ?>w2dc-rating-active<?php endif; ?> <?php if (!empty($noajax)): ?>w2dc-rating-active-noajax<?php endif; ?>" <?php if (!empty($post_id)): ?>data-listing="<?php w2dc_esc_e($post_id); ?>"<?php endif; ?> data-nonce="<?php echo wp_create_nonce('save_rating')?>">
- <label class="w2dc-rating-icon w2dc-fa <?php echo $avg_rating->render_star(5); ?>" <?php if (!empty($post_id)): ?>for="star-rating-5-<?php echo $post_id; ?>"<?php endif; ?> data-rating="5"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo $avg_rating->render_star(4); ?>" <?php if (!empty($post_id)): ?>for="star-rating-4-<?php echo $post_id; ?>"<?php endif; ?> data-rating="4"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo $avg_rating->render_star(3); ?>" <?php if (!empty($post_id)): ?>for="star-rating-3-<?php echo $post_id; ?>"<?php endif; ?> data-rating="3"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo $avg_rating->render_star(2); ?>" <?php if (!empty($post_id)): ?>for="star-rating-2-<?php echo $post_id; ?>"<?php endif; ?> data-rating="2"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo $avg_rating->render_star(1); ?>" <?php if (!empty($post_id)): ?>for="star-rating-1-<?php echo $post_id; ?>"<?php endif; ?> data-rating="1"></label>
- <?php if (!empty($noajax)): ?>
- <input type="hidden" name="w2dc-rating-noajax-<?php w2dc_esc_e($post_id); ?>" class="w2dc-rating-noajax-value" value="<?php w2dc_esc_e($avg_rating->avg_value); ?>">
- <?php endif; ?>
- </div>
-</div>
No newline at end of file
--- a/web-directory-free/addons/w2dc_ratings/templates/comments.tpl.php
+++ b/web-directory-free/addons/w2dc_ratings/templates/comments.tpl.php
@@ -1,61 +0,0 @@
-<?php
-
-// @codingStandardsIgnoreFile
-
-/**
- * Our comments form template, the comments loop is loaded via AJAX from w2dc_comments_load_template()
- */
-if ( !defined( 'ABSPATH' ) ) die( 'You cannot access this template file directly' );
-
-// Get current listing
-$listing = w2dc_isListing();
-
-?>
-<?php
- $name = esc_html__('Name...', 'w2dc');
- $email = esc_html__('Email...', 'w2dc');
- $website = esc_html__('Website...', 'w2dc');
- $user_email = null;
- $user_website = null;
- $user_name = null;
-
- if ( is_user_logged_in() ){
- $current_user = wp_get_current_user();
- $user_name = $current_user->user_nicename;
- $user_email = $current_user->user_email;
- $user_website = $current_user->user_url;
- }
-?>
-<div class="w2dc-comments-container" name="comments">
- <div id="w2dc_comments_ajax_handle" class="last-child" data-post_id="<?php w2dc_esc_e($listing->post->ID); ?>">
- <div id="w2dc_comments_ajax_target" class="w2dc-display-none"></div>
- <input type="hidden" name="comment_parent" value="0" id="comment_parent" />
- <input type="hidden" name="w2dc_comments_nonce" value="<?php print wp_create_nonce('w2dc_comments_nonce'); ?>" id="w2dc_comments_nonce" />
- <?php if ( get_option('comment_registration') != 1 || is_user_logged_in() ) : ?>
- <div class="w2dc-comments-content-form w2dc-comments-content-comment-fields">
- <div class="w2dc-comments-p">
- <h4 id="w2dc-comments-leave-comment-label"><?php esc_html_e('Leave a comment', 'w2dc'); ?></h4>
- <form action="javascript://" method="POST" id="w2dc_default_add_comment_form">
- <input type="hidden" name="w2dc_comments_nonce" value="<?php print wp_create_nonce('w2dc_comments_nonce'); ?>" id="w2dc_comments_nonce" />
- <?php w2dc_comments_profile_pic(); ?>
- <textarea placeholder="<?php esc_attr_e('Press enter to submit comment...', 'w2dc'); ?>" tabindex="4" id="comment" name="comment" id="w2dc-comments-textarea" class="w2dc-comments-auto-expand submit-on-enter"></textarea>
- <span class="w2dc-comments-more-handle"><a href="#"><?php esc_html_e('more', 'w2dc'); ?></a></span>
- <div class="w2dc-comments-more-container" <?php if ($user_email != null) : ?>style="display: none;"<?php endif; ?>>
- <div class="w2dc-comments-allowed-tags-container">
- <?php printf(esc_html__('Allowed %s tags and attributes:', 'w2dc'), '<abbr title="HyperText Markup Language">HTML</abbr>'); ?>
- <code><a href="" title=""> <blockquote> <code> <em> <strong></code>
- </div>
- <div class="w2dc-comments-field"><input type="text" tabindex="5" name="user_name" id="w2dc_comments_user_name" placeholder="<?php print $name; ?>" value="<?php print $user_name; ?>" /></div>
- <div class="w2dc-comments-field"><input type="email" required tabindex="5" name="user_email" id="w2dc_comments_user_email" placeholder="<?php print $email; ?>" value="<?php print $user_email; ?>" /></div>
- <div class="w2dc-comments-field"><input type="url" required tabindex="6" name="user_url" id="w2dc_comments_user_url" placeholder="<?php print $website; ?>" value="<?php print $user_website; ?>" /></div>
- </div>
- </form>
- </div>
- </div>
- <?php else : ?>
- <div class="callout-container">
- <p><?php printf(esc_html__('Please %s or %s to leave Comments', 'w2dc'), wp_register('','', false), '<a href="' . wp_login_url() . '" class="w2dc-comments-login-handle">' . esc_html__('Login', 'w2dc') . '</a>'); ?></p>
- </div>
- <?php endif; ?>
- </div>
-</div>
No newline at end of file
--- a/web-directory-free/addons/w2dc_ratings/templates/ratings_metabox.tpl.php
+++ b/web-directory-free/addons/w2dc_ratings/templates/ratings_metabox.tpl.php
@@ -1,33 +0,0 @@
-<?php if (get_option('w2dc_manage_ratings') || current_user_can('edit_others_posts')): ?>
-<script>
- jQuery(document).ready(function($) {
- "use strict";
-
- $("#w2dc-reset-all-ratings").on('click', function() {
- if (confirm('<?php echo esc_html__('Are you sure you want to reset all ratings of this listing?', 'w2dc'); ?>')) {
- w2dc_ajax_loader_show();
- $.ajax({
- type: "POST",
- url: w2dc_js_objects.ajaxurl,
- data: {'action': 'w2dc_reset_ratings', 'post_id': <?php w2dc_esc_e($listing->post->ID); ?>},
- success: function(){
- $(".w2dc-ratings-counts").html('0');
- $(".w2dc-admin-avgvalue").remove();
- },
- complete: function() {
- w2dc_ajax_loader_hide();
- }
- });
-
- }
- });
- });
-</script>
-<?php endif; ?>
-<div class="w2dc-content w2dc-ratings-metabox">
- <?php w2dc_renderTemplate(array(W2DC_RATINGS_TEMPLATES_PATH, 'ratings_overall.tpl.php'), array('listing' => $listing, 'total_counts' => $total_counts)); ?>
-
- <?php if (get_option('w2dc_manage_ratings') || current_user_can('edit_others_posts')): ?>
- <input id="w2dc-reset-all-ratings" type="button" class="w2dc-btn w2dc-btn-primary" onClick="" value="<?php esc_attr_e('Reset all ratings', 'w2dc'); ?>" />
- <?php endif; ?>
-</div>
No newline at end of file
--- a/web-directory-free/addons/w2dc_ratings/templates/ratings_options_in_level.tpl.php
+++ b/web-directory-free/addons/w2dc_ratings/templates/ratings_options_in_level.tpl.php
@@ -1,12 +0,0 @@
- <tr>
- <th scope="row">
- <label><?php esc_html_e('Ratings', 'w2dc'); ?></label>
- </th>
- <td>
- <input
- name="ratings_enabled"
- type="checkbox"
- value="1"
- <?php if (isset($level->ratings_enabled)) checked($level->ratings_enabled, 1, true); ?> />
- </td>
- </tr>
No newline at end of file
--- a/web-directory-free/addons/w2dc_ratings/templates/ratings_overall.tpl.php
+++ b/web-directory-free/addons/w2dc_ratings/templates/ratings_overall.tpl.php
@@ -1,31 +0,0 @@
-<?php
-
-// @codingStandardsIgnoreFile
-
-?>
-<!-- ratings_metabox.tpl.php -->
-<div class="w2dc-ratings-overall-wrapper">
- <div class="w2dc-ratings-overall-avgvalue">
- <span class="w2dc-ratings-overall-stars">
- <?php echo esc_html_e('Average', 'w2dc'); ?>
- </span>
- <?php w2dc_renderTemplate(array(W2DC_RATINGS_TEMPLATES_PATH, 'avg_rating.tpl.php'), array('avg_rating' => $listing->avg_rating, 'post_id' => $listing->post->ID, 'meta_tags' => false, 'active' => false, 'show_avg' => true)); ?>
- </div>
- <?php foreach ($total_counts AS $rating=>$counts): ?>
- <div class="w2dc-ratings-overall">
- <span class="w2dc-ratings-overall-stars">
- <?php w2dc_esc_e($rating); ?> <?php echo _n('Star ', 'Stars', $rating, 'w2dc'); ?>
- </span>
- <div class="w2dc-rating">
- <div class="w2dc-rating-stars">
- <label class="w2dc-rating-icon w2dc-fa <?php echo ($rating >= 5) ? 'w2dc-fa-star' : 'w2dc-fa-star-o' ?>"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo ($rating >= 4) ? 'w2dc-fa-star' : 'w2dc-fa-star-o' ?>"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo ($rating >= 3) ? 'w2dc-fa-star' : 'w2dc-fa-star-o' ?>"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo ($rating >= 2) ? 'w2dc-fa-star' : 'w2dc-fa-star-o' ?>"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo ($rating >= 1) ? 'w2dc-fa-star' : 'w2dc-fa-star-o' ?>"></label>
- </div>
- </div>
- - <span class="w2dc-ratings-counts"><?php echo $counts; ?> (<?php echo $listing->avg_rating->get_percents_counts($counts); ?>%)</span>
- </div>
- <?php endforeach; ?>
-</div>
No newline at end of file
--- a/web-directory-free/addons/w2dc_ratings/templates/single_rating.tpl.php
+++ b/web-directory-free/addons/w2dc_ratings/templates/single_rating.tpl.php
@@ -1,14 +0,0 @@
-<?php
-
-// @codingStandardsIgnoreFile
-
-?>
-<div class="w2dc-rating">
- <div class="w2dc-rating-stars">
- <label class="w2dc-rating-icon w2dc-fa <?php echo $rating->render_star(5); ?>"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo $rating->render_star(4); ?>"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo $rating->render_star(3); ?>"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo $rating->render_star(2); ?>"></label>
- <label class="w2dc-rating-icon w2dc-fa <?php echo $rating->render_star(1); ?>"></label>
- </div>
-</div>
No newline at end of file
--- a/web-directory-free/addons/w2dc_ratings/w2dc_ratings.php
+++ b/web-directory-free/addons/w2dc_ratings/w2dc_ratings.php
@@ -1,510 +0,0 @@
-<?php
-
-// @codingStandardsIgnoreFile
-
-define('W2DC_RATINGS_PATH', plugin_dir_path(__FILE__));
-
-function w2dc_ratings_loadPaths() {
- define('W2DC_RATINGS_TEMPLATES_PATH', W2DC_RATINGS_PATH . 'templates/');
- define('W2DC_RATINGS_RESOURCES_URL', plugins_url('/', __FILE__) . 'resources/');
-}
-add_action('init', 'w2dc_ratings_loadPaths', 0);
-
-define('W2DC_RATING_PREFIX', '_w2dc_rating_');
-define('W2DC_AVG_RATING_KEY', '_w2dc_avg_rating');
-
-include_once W2DC_RATINGS_PATH . 'classes/ratings.php';
-include_once W2DC_RATINGS_PATH . 'classes/comments_manager.php';
-
-class w2dc_ratings_plugin {
-
- public function init() {
- global $w2dc_instance, $w2dc_shortcodes, $w2dc_shortcodes_init;
-
- if (!get_option('w2dc_installed_ratings')) {
- add_action('init', 'w2dc_install_ratings', 0);
- }
- add_action('w2dc_version_upgrade', 'w2dc_upgrade_ratings');
-
- add_filter('w2dc_build_settings', array($this, 'plugin_settings'));
-
- add_action('wp_ajax_w2dc_save_rating', array($this, 'ajax_save_rating'));
- add_action('wp_ajax_nopriv_w2dc_save_rating', array($this, 'ajax_save_rating'));
-
- add_action('wp_ajax_w2dc_reset_ratings', array($this, 'reset_ratings'));
- add_action('wp_ajax_nopriv_w2dc_reset_ratings', array($this, 'reset_ratings'));
-
- add_filter('w2dc_listing_loading', array($this, 'load_listing'));
- add_filter('w2dc_listing_map_loading', array($this, 'load_listing'));
-
- add_filter('comment_text', array($this, 'rating_in_comment'), 10000);
-
- add_action('w2dc_listing_title_html', array($this, 'render_rating'), 10, 2);
- add_action('w2dc_listing_title_location_html', array($this, 'render_rating'), 10, 2);
- add_filter('w2dc_listing_title_search_html', array($this, 'get_rating_stars'), 10, 2);
- add_action('w2dc_dashboard_listing_title', array($this, 'render_rating_dashboard'));
-
- add_filter('w2dc_map_info_window_fields', array($this, 'add_rating_field_to_map_window'));
- add_filter('w2dc_map_info_window_fields_values', array($this, 'render_rating_in_map_window'), 10, 3);
-
- add_filter('w2dc_default_orderby_options', array($this, 'order_by_rating_option'));
- add_filter('w2dc_ordering_options', array($this, 'order_by_rating_html'), 10, 3);
- add_filter('w2dc_order_args', array($this, 'order_by_rating_args'), 101, 2);
-
- $this->loadRatingsByLevels();
- add_filter('w2dc_levels_loading', array($this, 'loadRatingsByLevels'), 10, 2);
- add_filter('w2dc_level_html', array($this, 'ratings_options_in_level_html'));
- add_filter('w2dc_level_validation', array($this, 'ratings_options_in_level_validation'));
- add_filter('w2dc_level_create_edit_args', array($this, 'ratings_options_in_level_create_add'), 1, 2);
-
- add_action('add_meta_boxes', array($this, 'addRatingsMetabox'), 301);
-
- add_action('w2dc_edit_listing_metaboxes_post', array($this, 'frontendRatingsMetabox'));
-
- add_filter('manage_'.W2DC_POST_TYPE.'_posts_columns', array($this, 'add_listings_table_columns'));
- add_filter('manage_'.W2DC_POST_TYPE.'_posts_custom_column', array($this, 'manage_listings_table_rows'), 10, 2);
-
- // we can not call w2dc_isListing() here, lets call it later in the filter
- if (get_option('w2dc_reviews_comments_mode') == 'comments') {
- $w2dc_instance->comments_manager = new w2dc_comments_manager;
-
- add_filter('comments_template', array($this, 'comments_template'));
- }
-
- add_action('w2dc_render_template', array($this, 'check_custom_template'), 10, 2);
- }
-
- /**
- * check is there template in one of these paths:
- * - themes/theme/w2dc-plugin/templates/w2dc_payments/
- * - plugins/w2dc/templates/w2dc_payments/
- *
- */
- public function check_custom_template($template, $args) {
- if (is_array($template)) {
- $template_path = $template[0];
- $template_file = $template[1];
-
- if ($template_path == W2DC_RATINGS_TEMPLATES_PATH && ($fsubmit_template = w2dc_isTemplate('w2dc_ratings/' . $template_file))) {
- return $fsubmit_template;
- }
- }
- return $template;
- }
-
- public function plugin_settings($options) {
- $options['template']['menus']['ratings'] = array(
- 'name' => 'ratings',
- 'title' => esc_html__('Ratings & Comments', 'w2dc'),
- 'icon' => 'font-awesome:w2dc-fa-star',
- 'controls' => array(
- 'ratings' => array(
- 'type' => 'section',
- 'title' => esc_html__('Ratings settings', 'w2dc'),
- 'fields' => array(
- array(
- 'type' => 'toggle',
- 'name' => 'w2dc_only_registered_users',
- 'label' => esc_html__('Only registered users may place ratings', 'w2dc'),
- 'default' => get_option('w2dc_only_registered_users'),
- ),
- array(
- 'type' => 'toggle',
- 'name' => 'w2dc_manage_ratings',
- 'label' => esc_html__('Allow users to reset ratings of own listings', 'w2dc'),
- 'default' => get_option('w2dc_manage_ratings'),
- ),
- array(
- 'type' => 'toggle',
- 'name' => 'w2dc_orderby_rating',
- 'label' => esc_html__('Allow sorting by ratings', 'w2dc'),
- 'default' => get_option('w2dc_orderby_rating'),
- ),
- ),
- ),
- 'comments' => array(
- 'type' => 'section',
- 'title' => esc_html__('Comments mode', 'w2dc'),
- 'fields' => array(
- array(
- 'type' => 'radiobutton',
- 'name' => 'w2dc_reviews_comments_mode',
- 'label' => esc_html__('Comments mode', 'w2dc'),
- 'default' => get_option('w2dc_reviews_comments_mode'),
- 'items' => array(
- array(
- 'value' => 'disabled',
- 'label' => esc_html__('disabled', 'w2dc'),
- ),
- array(
- 'value' => 'native',
- 'label' => esc_html__('comments system of installed theme or another plugin', 'w2dc'),
- ),
- array(
- // include comments_template filter in the init()
- 'value' => 'comments',
- 'label' => esc_html__('use simple directory comments', 'w2dc'),
- ),
- ),
- ),
- ),
- ),
- ),
- );
-
- return $options;
- }
-
- public function loadRatingsByLevels($level = null, $array = array()) {
- global $w2dc_instance, $wpdb;
-
- if (!$array && isset($w2dc_instance->levels->levels_array)) {
- $array = $wpdb->get_results("SELECT * FROM {$wpdb->w2dc_levels} ORDER BY order_num", ARRAY_A);
-
- foreach ($array AS $row) {
- $w2dc_instance->levels->levels_array[$row['id']]->ratings_enabled = $row['ratings_enabled'];
-
- if (is_object($level) && $level->id == $row['id'])
- $level->ratings_enabled = $row['ratings_enabled'];
- }
- } elseif ($level && isset($array['ratings_enabled'])) {
- $level->ratings_enabled = $array['ratings_enabled'];
- }
-
- return $level;
- }
-
- public function ratings_options_in_level_html($level) {
- w2dc_renderTemplate(array(W2DC_RATINGS_TEMPLATES_PATH, 'ratings_options_in_level.tpl.php'), array('level' => $level));
- }
-
- public function ratings_options_in_level_validation($validation) {
- $validation->set_rules('ratings_enabled', esc_html__('Ratings', 'w2dc'), 'is_checked');
-
- return $validation;
- }
-
- public function ratings_options_in_level_create_add($insert_update_args, $array) {
- $insert_update_args['ratings_enabled'] = w2dc_getValue($array, 'ratings_enabled', 1);
- return $insert_update_args;
- }
-
- public function load_listing($listing) {
- global $w2dc_instance;
-
- if ($listing->level->ratings_enabled) {
- $listing->avg_rating = new w2dc_avg_rating($listing->post->ID);
- }
-
- return $listing;
- }
-
- public function addRatingsMetabox($post_type) {
- if ($post_type == W2DC_POST_TYPE && ($level = w2dc_getCurrentListingInAdmin()->level) && $level->ratings_enabled) {
- add_meta_box('w2dc_ratings',
- esc_html__('Listing ratings', 'w2dc'),
- array($this, 'listingRatingsMetabox'),
- W2DC_POST_TYPE,
- 'normal',
- 'high');
- }
- }
-
- public function listingRatingsMetabox($post) {
- $listing = new w2dc_listing();
- $listing->loadListingFromPost($post);
-
- $total_counts = $listing->avg_rating->calculateTotals();
-
- w2dc_renderTemplate(array(W2DC_RATINGS_TEMPLATES_PATH, 'ratings_metabox.tpl.php'), array('listing' => $listing, 'total_counts' => $total_counts));
- }
-
- public function frontendRatingsMetabox($listing) {
- if ($listing->level->ratings_enabled) {
- if (get_option('w2dc_manage_ratings') || current_user_can('edit_others_posts')) {
- echo '<div class="w2dc-submit-section w2dc-submit-section-ratings">';
- echo '<h3 class="w2dc-submit-section-label">' . esc_html__('Listing ratings', 'w2dc') . '</h3>';
- echo '<div class="w2dc-submit-section-inside">';
- $this->listingRatingsMetabox($listing->post);
- echo '</div>';
- echo '</div>';
- }
- }
- }
-
- public function reset_ratings() {
- $post_id = w2dc_getValue($_POST, 'post_id');
-
- if (($post = get_post($post_id)) && ((get_option('w2dc_manage_ratings') && w2dc_current_user_can_edit_listing($post_id)) || current_user_can('edit_others_posts'))) {
- w2dc_reset_ratings($post_id);
-
- // Update ratings according to existing listing's reviews
- do_action('w2dc_reset_ratings', $post_id);
- }
- die();
- }
-
- public function add_listings_table_columns($columns) {
- $w2dc_columns['w2dc_rating'] = esc_html__('Rating', 'w2dc');
-
- $comments_index = array_search("comments", array_keys($columns));
-
- return array_slice($columns, 0, $comments_index, true) + $w2dc_columns + array_slice($columns, $comments_index, count($columns)-$comments_index, true);
- }
-
- public function manage_listings_table_rows($column, $post_id) {
- if ($column == "w2dc_rating") {
- $listing = new w2dc_listing();
- $listing->loadListingFromPost($post_id);
- $this->render_rating($listing, false, false);
- }
- }
-
- public function ajax_save_rating() {
- $post_id = w2dc_getValue($_POST, 'post_id');
- $rating = w2dc_getValue($_POST, 'rating');
- $_wpnonce = wp_verify_nonce(w2dc_getValue($_POST, '_wpnonce'), 'save_rating');
-
- if ($_wpnonce) {
- if ($this->save_rating($post_id, $rating)) {
- $listing = w2dc_getListing($post_id);
- $out = w2dc_renderTemplate(array(W2DC_RATINGS_TEMPLATES_PATH, 'avg_rating.tpl.php'), array('avg_rating' => $listing->avg_rating, 'post_id' => $listing->post->ID, 'meta_tags' => false, 'active' => true, 'show_avg' => true), true);
- echo json_encode(array('html' => $out));
- }
- }
-
- die();
- }
-
- public function save_rating($post_id, $rating) {
-
- if (($post = get_post($post_id)) && $rating && ($rating >= 1 && $rating <= 5)) {
- $user_id = get_current_user_id();
- $ip = w2dc_ip_address();
- if (get_option('w2dc_only_registered_users') && !$user_id) {
- return false;
- }
-
- if (!$this->is_listing_rated($post->ID)) {
- if ($user_id) {
- add_post_meta($post->ID, W2DC_RATING_PREFIX . $user_id, $rating);
- } elseif ($ip) {
- add_post_meta($post->ID, W2DC_RATING_PREFIX . $ip, $rating);
- }
-
- setcookie(W2DC_RATING_PREFIX . $post->ID, $rating, time() + 31536000, '/');
-
- $avg_rating = new w2dc_avg_rating($post->ID);
- $avg_rating->update_avg_rating();
- } else {
- // possible to change user rating
- if ($user_id) {
- update_post_meta($post->ID, W2DC_RATING_PREFIX . $user_id, $rating);
- } elseif ($ip) {
- update_post_meta($post->ID, W2DC_RATING_PREFIX . $ip, $rating);
- }
-
- setcookie(W2DC_RATING_PREFIX . $post->ID, $rating, time() + 31536000, '/');
-
- $avg_rating = new w2dc_avg_rating($post->ID);
- $avg_rating->update_avg_rating();
- }
-
- return true;
- }
- }
-
- public function is_listing_rated($id) {
- if (!isset($_COOKIE[W2DC_RATING_PREFIX . $id])) {
- if ($user_id = get_current_user_id()) {
- if (get_post_meta($id, W2DC_RATING_PREFIX . $user_id, true)) {
- return true;
- }
- }
- if ($ip = w2dc_ip_address()) {
- if (get_post_meta($id, W2DC_RATING_PREFIX . $ip, true)) {
- return true;
- }
- }
- } else {
- return true;
- }
- }
-
- public function render_rating($listing, $meta_tags = false, $active = true, $show_avg = true) {
- global $w2dc_instance;
-
- if ($listing->level->ratings_enabled) {
- if (get_option('w2dc_only_registered_users') && !get_current_user_id()) {
- $active = false;
- }
- if ($listing->post->post_author && (get_current_user_id() == $listing->post->post_author) && !current_user_can('manage_options')) {
- $active = false;
- }
- if ($w2dc_instance->action == 'printlisting' || $w2dc_instance->action == 'pdflisting') {
- $active = false;
- }
-
- $active = apply_filters('w2dc_is_active_rating', $active, $listing);
-
- w2dc_renderTemplate(array(W2DC_RATINGS_TEMPLATES_PATH, 'avg_rating.tpl.php'), array('avg_rating' => $listing->avg_rating, 'post_id' => $listing->post->ID, 'meta_tags' => $meta_tags, 'active' => $active, 'show_avg' => $show_avg));
- }
-
- return $listing;
- }
-
- public function get_rating_stars($title, $listing) {
- if ($listing->level->ratings_enabled) {
- return $title . ' ' . w2dc_renderTemplate(
- array(W2DC_RATINGS_TEMPLATES_PATH, 'avg_rating.tpl.php'),
- array(
- 'avg_rating' => $listing->avg_rating,
- 'post_id' => $listing->post->ID,
- 'meta_tags' => false,
- 'active' => false,
- 'show_avg' => false
- ), true);
- }
- return $title;
- }
-
- public function render_rating_dashboard($listing) {
- global $w2dc_instance;
-
- if ($listing->level->ratings_enabled)
- w2dc_renderTemplate(array(W2DC_RATINGS_TEMPLATES_PATH, 'avg_rating.tpl.php'), array('avg_rating' => $listing->avg_rating, 'post_id' => $listing->post->ID, 'meta_tags' => false, 'active' => false, 'show_avg' => true));
-
- return $listing;
- }
-
- public function add_rating_field_to_map_window($fields) {
- $fields = array('rating' => '') + $fields;
-
- return $fields;
- }
-
- public function render_rating_in_map_window($content_field, $field_slug, $listing) {
- if ($field_slug == 'rating' && $listing->level->ratings_enabled && isset($listing->avg_rating)) {
- return w2dc_renderTemplate(array(W2DC_RATINGS_TEMPLATES_PATH, 'avg_rating.tpl.php'), array('avg_rating' => $listing->avg_rating, 'post_id' => $listing->post->ID, 'meta_tags' => false, 'active' => false, 'show_avg' => true), true);
- }
- }
-
- public function order_by_rating_args($args, $defaults = array()) {
- if (get_option('w2dc_orderby_rating')) {
- if (isset($_REQUEST['order_by']) && $_REQUEST['order_by']) {
- $order_by = $_REQUEST['order_by'];
- $order = w2dc_getValue($_REQUEST, 'order', 'DESC');
- } else {
- if (isset($defaults['order_by']) && $defaults['order_by']) {
- $order_by = $defaults['order_by'];
- $order = w2dc_getValue($defaults, 'order', 'DESC');
- }
- }
-
- if (isset($order_by) && $order_by == 'rating_order') {
- $args['orderby'] = 'meta_value_num';
- $args['meta_key'] = W2DC_AVG_RATING_KEY;
- $args['order'] = $order;
- if (get_option('w2dc_orderby_sticky_featured')) {
- add_filter('get_meta_sql', array($this, 'add_null_values'));
- add_filter('w2dc_frontend_controller_construct', array($this, 'remove_query_filters'));
- }
- if (get_option('w2dc_orderby_exclude_null')) {
- add_filter('posts_join', 'w2dc_join_levels');
- add_filter('posts_where', array($this, 'where_ratings_levels'));
- add_filter('w2dc_frontend_controller_construct', array($this, 'remove_query_filters'));
- }
- }
- }
-
- return $args;
- }
- public function where_ratings_levels($where = '') {
-
- if (strpos($where, ".post_type = '". W2DC_POST_TYPE ."'") !== false) {
- $where .= " AND w2dc_levels.ratings_enabled=1";
- }
-
- return $where;
- }
- /**
- * Listings with empty values must be sorted as well
- *
- */
- public function add_null_values($clauses) {
- $clauses['where'] = str_replace("wp_postmeta.meta_key = '".W2DC_AVG_RATING_KEY."'", "(wp_postmeta.meta_key = '".W2DC_AVG_RATING_KEY."' OR wp_postmeta.meta_value IS NULL)", $clauses['where']);
- return $clauses;
- }
- public function remove_query_filters() {
- remove_filter('posts_join', 'w2dc_join_levels');
- remove_filter('posts_where', array($this, 'where_ratings_levels'));
- remove_filter('get_meta_sql', array($this, 'add_null_values'));
- }
-
- public function order_by_rating_option($ordering) {
- if (get_option('w2dc_orderby_rating'))
- $ordering['rating_order'] = esc_html__('Rating', 'w2dc');
-
- return $ordering;
- }
-
- public function order_by_rating_html($ordering, $base_url, $defaults = array()) {
- if (get_option('w2dc_orderby_rating')) {
- $ordering->addLinks(array('rating_order' => array('DESC' => esc_html__('Best rating', 'w2dc'))));
- }
-
- return $ordering;
- }
-
- public function rating_in_comment($output) {
- $comment = 0;
- if (($comment = get_comment($comment)) && ($post = get_post()) && $post->post_type == W2DC_POST_TYPE) {
- if ($rating = w2dc_build_single_rating($comment->comment_post_ID, $comment->user_id))
- $output = w2dc_renderTemplate(array(W2DC_RATINGS_TEMPLATES_PATH, 'single_rating.tpl.php'), array('rating' => $rating), true) . $output;
- }
-
- return $output;
- }
-
- public function comments_template($file){
- if (w2dc_isListing()) {
- return W2DC_RATINGS_TEMPLATES_PATH . 'comments.tpl.php';
- }
-
- return $file;
- }
-}
-
-function w2dc_install_ratings() {
- global $wpdb;
-
- // there may be possible bug in WP, on some servers it doesn't allow to execute more than one SQL query in one request
- $wpdb->query("ALTER TABLE {$wpdb->w2dc_levels} ADD `ratings_enabled` tinyint(1) NOT NULL DEFAULT '1' AFTER `map_markers`");
- if (array_search('ratings_enabled', $wpdb->get_col("DESC {$wpdb->w2dc_levels}"))) {
- update_option('w2dc_only_registered_users', 0);
- update_option('w2dc_manage_ratings', 1);
-
- w2dc_upgrade_ratings('1.5.8');
- w2dc_upgrade_ratings('2.5.9');
-
- update_option('w2dc_installed_ratings', 1);
- }
-}
-
-function w2dc_upgrade_ratings($new_version) {
- if ($new_version == '1.5.8') {
- update_option('w2dc_orderby_rating', 1);
- }
- if ($new_version == '2.5.9') {
- if (get_option('w2dc_reviews_comments_mode') == 'reviews') {
- update_option('w2dc_reviews_comments_mode', 'comments');
- }
- }
-}
-
-global $w2dc_ratings_instance;
-
-$w2dc_ratings_instance = new w2dc_ratings_plugin();
-$w2dc_ratings_instance->init();
-
-?>
--- a/web-directory-free/classes/admin.php
+++ b/web-directory-free/classes/admin.php
@@ -1,487 +0,0 @@
-<?php
-
-// @codingStandardsIgnoreFile
-
-class w2dc_admin {
-
- public function __construct() {
- global $w2dc_instance;
-
- add_action('admin_menu', array($this, 'menu'));
-
- $w2dc_instance->settings_manager = new w2dc_settings_manager;
-
- $w2dc_instance->levels_manager = new w2dc_levels_manager;
-
- $w2dc_instance->listings_manager = new w2dc_listings_manager;
-
- $w2dc_instance->locations_manager = new w2dc_locations_manager;
-
- $w2dc_instance->locations_levels_manager = new w2dc_locations_levels_manager;
-
- $w2dc_instance->categories_manager = new w2dc_categories_manager;
-
- $w2dc_instance->content_fields_manager = new w2dc_content_fields_manager;
-
- $w2dc_instance->media_manager = new w2dc_media_manager;
-
- $w2dc_instance->csv_manager = new w2dc_csv_manager;
-
- $w2dc_instance->demo_data_manager = new w2dc_demo_data_manager;
-
- add_filter('w2dc_build_settings', array($this, 'addAddonsSettings'));
-
- add_action('admin_menu', array($this, 'addChooseLevelPage'));
- add_action('load-post-new.php', array($this, 'handleLevel'));
-
- // hide some meta-blocks when create/edit posts
- add_action('admin_init', array($this, 'hideMetaBoxes'));
- add_filter('default_hidden_meta_boxes', array($this, 'showAuthorMetaBox'), 10, 2);
-
- add_action('admin_head-post-new.php', array($this, 'hidePreviewButton'));
- add_action('admin_head-post.php', array($this, 'hidePreviewButton'));
-
- add_filter('post_row_actions', array($this, 'removeQuickEdit'), 10, 2);
- add_filter('quick_edit_show_taxonomy', array($this, 'removeQuickEditTax'), 10, 2);
-
- add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts_styles'), 0);
- add_action('admin_print_scripts', array($w2dc_instance, 'dequeue_maps_googleapis'), 1000);
-
- add_filter('admin_body_class', array($this, 'addBodyClasses'));
-
- add_action('wp_ajax_w2dc_generate_color_palette', array($this, 'generate_color_palette'));
- add_action('wp_ajax_nopriv_w2dc_generate_color_palette', array($this, 'generate_color_palette'));
- add_action('wp_ajax_w2dc_get_jqueryui_theme', array($this, 'get_jqueryui_theme'));
- add_action('wp_ajax_nopriv_w2dc_get_jqueryui_theme', array($this, 'get_jqueryui_theme'));
- add_action('vp_w2dc_option_before_ajax_save', array($this, 'remove_colorpicker_cookie'));
- add_action('wp_footer', array($this, 'render_palette_picker'));
-
- add_action('admin_notices', array($this, 'renderAdminMessages'));
- }
-
- public function renderAdminMessages() {
- global $pagenow;
-
- if (!empty($_GET['page']) && $_GET['page'] == 'w2dc_settings') {
- echo '<div class="notice notice-info is-dismissible">
- <p>Love Web 2.0 Directory plugin? Consider buying full version at <a href="https://www.salephpscripts.com">salephpscripts.com</a></p>
- </div>';
- }
-
- if ((($pagenow == 'edit.php' || $pagenow == 'post-new.php') && ($post_type = w2dc_getValue($_GET, 'post_type')) &&
- (in_array($post_type, array(W2DC_POST_TYPE, 'w2dc_invoice')))
- ) ||
- ($pagenow == 'post.php' && ($post_id = w2dc_getValue($_GET, 'post')) && ($post = get_post($post_id)) && w2dc_getValue($_GET, 'action') == 'edit' &&
- (in_array($post->post_type, array(W2DC_POST_TYPE, 'w2dc_invoice', 'shop_order', 'shop_subscription')))
- ) ||
- (($pagenow == 'edit-tags.php' || $pagenow == 'term.php') && ($taxonomy = w2dc_getValue($_GET, 'taxonomy')) &&
- (in_array($taxonomy, array(W2DC_LOCATIONS_TAX, W2DC_CATEGORIES_TAX, W2DC_TAGS_TAX)))
- )) {
- w2dc_renderMessages();
- }
- }
-
- public function addChooseLevelPage() {
- add_submenu_page('options.php',
- __('Choose level of new listing', 'w2dc'),
- __('Choose level of new listing', 'w2dc'),
- 'publish_posts',
- 'w2dc_choose_level',
- array($this, 'chooseLevelsPage')
- );
- }
-
- // Special page to choose the level for new listing
- public function chooseLevelsPage() {
- global $w2dc_instance;
-
- $w2dc_instance->levels_manager->displayChooseLevelTable();
- }
-
- public function handleLevel() {
- global $w2dc_instance;
-
- if (isset($_GET['post_type']) && $_GET['post_type'] == W2DC_POST_TYPE) {
- if (!isset($_GET['level_id'])) {
- // adapted for WPML
- global $sitepress;
- if (function_exists('wpml_object_id_filter') && $sitepress && isset($_GET['trid']) && isset($_GET['lang']) && isset($_GET['source_lang'])) {
- global $sitepress;
- $listing_id = $sitepress->get_original_element_id_by_trid($_GET['trid']);
-
- $listing = new w2dc_listing();
- $listing->loadListingFromPost($listing_id);
- wp_redirect(add_query_arg(array('post_type' => 'w2dc_listing', 'level_id' => $listing->level->id, 'trid' => $_GET['trid'], 'lang' => $_GET['lang'], 'source_lang' => $_GET['source_lang']), admin_url('post-new.php')));
- } else {
- if (count($w2dc_instance->levels->levels_array) != 1) {
- wp_redirect(add_query_arg('page', 'w2dc_choose_level', admin_url('options.php')));
- } else {
- $single_level = array_shift($w2dc_instance->levels->levels_array);
- wp_redirect(add_query_arg(array('post_type' => 'w2dc_listing', 'level_id' => $single_level->id), admin_url('post-new.php')));
- }
- }
- die();
- }
- }
- }
-
- public function menu() {
- if (defined('W2DC_DEMO') && W2DC_DEMO) {
- $capability = 'publish_posts';
- } else {
- $capability = 'manage_options';
- }
-
- add_menu_page(__("Directory settings", "w2dc"),
- __('Directory Admin', 'w2dc'),
- $capability,
- 'w2dc_settings',
- '',
- W2DC_RESOURCES_URL . 'images/menuicon.png'
- );
- add_submenu_page(
- 'w2dc_settings',
- __("Directory settings", "w2dc"),
- __("Directory settings", "w2dc"),
- $capability,
- 'w2dc_settings'
- );
-
- add_submenu_page(
- 'w2dc_debug',
- __("Directory Debug", "w2dc"),
- __("Directory Debug", "w2dc"),
- $capability,
- 'w2dc_debug',
- array($this, 'debug')
- );
- add_submenu_page(
- 'w2dc_reset',
- __("Directory Reset", "w2dc"),
- __("Directory Reset", "w2dc"),
- 'manage_options',
- 'w2dc_reset',
- array($this, 'reset')
- );
- }
-
- public function debug() {
- global $w2dc_instance, $wpdb;
-
- $w2dc_locationGeoname = new w2dc_locationGeoname();
- $geolocation_response = $w2dc_locationGeoname->geocodeRequest('1600 Amphitheatre Parkway Mountain View, CA 94043', 'test');
-
- $settings = $wpdb->get_results($wpdb->prepare("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE %s", $wpdb->esc_like('w2dc_') . '%'), ARRAY_A);
-
- w2dc_renderTemplate('debug.tpl.php', array(
- 'rewrite_rules' => get_option('rewrite_rules'),
- 'geolocation_response' => $geolocation_response,
- 'settings' => $settings,
- 'levels' => $w2dc_instance->levels,
- 'content_fields' => $w2dc_instance->content_fields,
- ));
- }
-
- public function reset() {
- global $w2dc_instance, $wpdb;
-
- if (isset($_GET['reset']) && $_GET['reset'] == 'installation') {
- if (delete_option('w2dc_installed_directory')) {
- w2dc_save_dynamic_css();
- w2dc_addMessage('Directory installation will be repeated!');
- }
- }
- if (isset($_GET['reset']) && ($_GET['reset'] == 'settings' || $_GET['reset'] == 'settings_tables')) {
- if ($wpdb->query($wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE %s", $wpdb->esc_like('w2dc_') . '%')) !== false) {
- delete_option('vpt_option');
- w2dc_save_dynamic_css();
- w2dc_addMessage('All directory settings were deleted!');
- }
- }
- if (isset($_GET['reset']) && $_GET['reset'] == 'settings_tables') {
- $wpdb->query("DROP TABLE IF EXISTS $wpdb->w2dc_content_fields_groups");
- $wpdb->query("DROP TABLE IF EXISTS $wpdb->w2dc_content_fields");
- $wpdb->query("DROP TABLE IF EXISTS $wpdb->w2dc_directories");
- $wpdb->query("DROP TABLE IF EXISTS $wpdb->w2dc_levels");
- $wpdb->query("DROP TABLE IF EXISTS $wpdb->w2dc_levels_relationships");
- $wpdb->query("DROP TABLE IF EXISTS $wpdb->w2dc_locations_levels");
- $wpdb->query("DROP TABLE IF EXISTS $wpdb->w2dc_locations_relationships");
- w2dc_addMessage('W2DC database tables were dropped!');
- }
- w2dc_renderTemplate('reset.tpl.php');
- }
-
- public function hideMetaBoxes() {
- global $post, $pagenow;
-
- if (($pagenow == 'post-new.php' && isset($_GET['post_type']) && $_GET['post_type'] == W2DC_POST_TYPE) || ($pagenow == 'post.php' && $post && $post->post_type == W2DC_POST_TYPE)) {
- $user_id = get_current_user_id();
- update_user_meta($user_id, 'metaboxhidden_' . W2DC_POST_TYPE, array('trackbacksdiv', 'commentstatusdiv', 'postcustom'));
- }
- }
-
- public function showAuthorMetaBox($hidden, $screen) {
- if ($screen->post_type == W2DC_POST_TYPE) {
- if ($key = array_search('authordiv', $hidden)) {
- unset($hidden[$key]);
- }
- }
-
- return $hidden;
- }
-
- public function hidePreviewButton() {
- global $post_type;
-
- if ($post_type == W2DC_POST_TYPE) {
- echo '<style type="text/css">#preview-action {display: none;}</style>';
- }
- }
-
- public function removeQuickEdit($actions, $post) {
- if ($post->post_type == W2DC_POST_TYPE) {
- unset($actions['inline hide-if-no-js']);
- unset($actions['view']);
- }
- return $actions;
- }
-
- public function removeQuickEditTax($show_in_quick_edit, $taxonomy_name) {
- if ($taxonomy_name == W2DC_CATEGORIES_TAX || $taxonomy_name == W2DC_LOCATIONS_TAX)
- $show_in_quick_edit = false;
-
- return $show_in_quick_edit;
- }
-
- public function addBodyClasses($classes) {
- return "$classes w2dc-body";
- }
-
- public function addAddonsSettings($options) {
- $options['template']['menus']['general']['controls'] = array_merge(
- array('addons' => array(
- 'type' => 'section',
- 'title' => __('Addons', 'w2dc'),
- 'description' => __('Refresh this page after switch on/off any addon.', 'w2dc'),
- 'fields' => array(
- array(
- 'type' => 'toggle',
- 'name' => 'w2dc_ratings_addon',
- 'label' => __('Ratings & Comments addon', 'w2dc'),
- 'description' => __('Ability to place ratings and comments for listings.', 'w2dc'),
- 'default' => get_option('w2dc_ratings_addon'),
- ),
- ),
- )),
- $options['template']['menus']['general']['controls']
- );
-
- return $options;
- }
-
-public function admin_enqueue_scripts_styles($hook) {
- global $w2dc_instance;
-
- // include admin.css, rtl.css, bootstrap, custom.css and datepicker files in admin,
- // also in customizer and required for VC plugin, SiteOrigin plugin and widgets
- if (
- w2dc_isDirectoryPageInAdmin() ||
- is_customize_preview() ||
- $hook == "widgets.php" ||
- get_post_meta(get_the_ID(), '_wpb_vc_js_status', true)
- ) {
- wp_enqueue_script('jquery-ui-datepicker');
- wp_register_style('w2dc-jquery-ui-style', W2DC_RESOURCES_URL . 'css/jquery-ui/themes/smoothness/jquery-ui.css');
- wp_enqueue_style('w2dc-jquery-ui-style');
- if ($i18n_file = w2dc_getDatePickerLangFile(get_locale())) {
- wp_register_script('datepicker-i18n', $i18n_file, array('jquery-ui-datepicker'));
- wp_enqueue_script('datepicker-i18n');
- }
-
- if (is_customize_preview())
- $this->enqueue_global_vars();
- else
- add_action('admin_head', array($this, 'enqueue_global_vars'));
-
- wp_register_style('w2dc-bootstrap', W2DC_RESOURCES_URL . 'css/bootstrap.css', array(), W2DC_VERSION_TAG);
- wp_register_style('w2dc-admin', W2DC_RESOURCES_URL . 'css/admin.css', array(), W2DC_VERSION_TAG);
- if (function_exists('is_rtl') && is_rtl()) {
- wp_register_style('w2dc-admin-rtl', W2DC_RESOURCES_URL . 'css/admin-rtl.css', array(), W2DC_VERSION_TAG);
- }
-
- if ($admin_custom = w2dc_isResource('css/admin-custom.css')) {
- wp_register_style('w2dc-admin-custom', $admin_custom, array(), W2DC_VERSION_TAG);
- }
- }
-
- if (w2dc_isDirectoryPageInAdmin()) {
-
- add_action('wp_print_scripts', array($w2dc_instance, 'dequeue_maps_googleapis'), 1000);
-
- wp_register_style('w2dc-font-awesome', W2DC_RESOURCES_URL . 'css/font-awesome.css', array(), W2DC_VERSION_TAG);
- wp_register_script('w2dc-js-functions', W2DC_RESOURCES_URL . 'js/js_functions.js', array('jquery'), false, true);
-
- wp_register_script('w2dc-categories-edit-scripts', W2DC_RESOURCES_URL . 'js/categories_icons.js', array('jquery'));
- wp_register_script('w2dc-categories-scripts', W2DC_RESOURCES_URL . 'js/manage_categories.js', array('jquery'));
-
- wp_register_script('w2dc-locations-edit-scripts', W2DC_RESOURCES_URL . 'js/locations_icons.js', array('jquery'));
-
- wp_register_style('w2dc-media-styles', W2DC_RESOURCES_URL . 'lightbox/css/lightbox.min.css', array(), W2DC_VERSION_TAG);
- wp_register_script('w2dc-media-scripts-lightbox', W2DC_RESOURCES_URL . 'lightbox/js/lightbox.js', array('jquery'));
-
- wp_localize_script(
- 'w2dc-js-functions',
- 'w2dc_maps_callback',
- array(
- 'callback' => 'w2dc_load_maps_api_backend'
- )
- );
-
- wp_enqueue_script('jquery-ui-selectmenu');
- wp_enqueue_script('jquery-ui-autocomplete');
- }
-
- wp_enqueue_style('w2dc-bootstrap');
- wp_enqueue_style('w2dc-font-awesome');
- wp_enqueue_style('w2dc-admin');
- wp_enqueue_style('w2dc-admin-rtl');
- wp_enqueue_script('jquery-ui-dialog');
- wp_enqueue_script('w2dc-js-functions');
- wp_enqueue_style('w2dc-admin-custom');
-
- if (w2dc_isDirectoryPageInAdmin() && w2dc_is_maps_used()) {
- if (w2dc_getMapEngine() == 'mapbox') {
- wp_register_script('mapbox-gl', 'https://api.tiles.mapbox.com/mapbox-gl-js/' . W2DC_MAPBOX_VERSION . '/mapbox-gl.js');
- wp_enqueue_script('mapbox-gl');
- wp_register_style('mapbox-gl', 'https://api.tiles.mapbox.com/mapbox-gl-js/' . W2DC_MAPBOX_VERSION . '/mapbox-gl.css');
- wp_enqueue_style('mapbox-gl');
- wp_register_script('w2dc-mapbox', W2DC_RESOURCES_URL . 'js/mapboxgl.js', array('jquery'), W2DC_VERSION_TAG, true);
- wp_enqueue_script('w2dc-mapbox');
-
- wp_register_script('mapbox-draw', 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.4.3/mapbox-gl-draw.js');
- wp_enqueue_script('mapbox-draw');
- wp_register_style('mapbox-draw', 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-draw/v1.4.3/mapbox-gl-draw.css');
- wp_enqueue_style('mapbox-draw');
-
- wp_register_script('mapbox-directions', 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v4.1.1/mapbox-gl-directions.js');
- wp_enqueue_script('mapbox-directions');
- wp_register_style('mapbox-directions', 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v4.1.1/mapbox-gl-directions.css');
- wp_enqueue_style('mapbox-directions');
-
- if (in_array(get_option('w2dc_mapbox_map_style'), array(
- 'mapbox://styles/mapbox/streets-v11',
- 'mapbox://styles/mapbox/outdoors-v11',
- 'mapbox://styles/mapbox/light-v10',
- 'mapbox://styles/mapbox/dark-v10',
- ))) {
- wp_register_script('mapbox-language', 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-language/v1.0.0/mapbox-gl-language.js');
- wp_enqueue_script('mapbox-language');
- }
- } else {
- wp_register_script('w2dc-google-maps', W2DC_RESOURCES_URL . 'js/google_maps.js', array('jquery'), W2DC_VERSION_TAG, true);
- wp_enqueue_script('w2dc-google-maps');
- }
- }
- }
-
- public function enqueue_global_vars() {
- // adapted for WPML
- global $sitepress;
- if (function_exists('wpml_object_id_filter') && $sitepress) {
- $ajaxurl = admin_url('admin-ajax.php?lang=' . $sitepress->get_current_language());
- } else {
- $ajaxurl = admin_url('admin-ajax.php');
- }
-
- echo '
-<script>
-';
- echo 'var w2dc_js_objects = ' . json_encode(
- array(
- 'ajaxurl' => $ajaxurl,
- 'is_rtl' => (int)is_rtl(),
- 'is_maps_used' => (int)w2dc_is_maps_used(),
- 'lang' => (($sitepress && get_option('w2dc_map_language_from_wpml')) ? ICL_LANGUAGE_CODE : apply_filters('w2dc_map_language', '')),
- 'fields_in_categories' => array(),
- 'is_admin' => (int)is_admin(),
- 'cancel_button' => esc_html__('Cancel', 'w2dc'),
- )
- ) . ';
-';
-
- echo 'var w2dc_maps_objects = ' . json_encode(
- array(
- 'notinclude_maps_api' => ((defined('W2DC_NOTINCLUDE_MAPS_API') && W2DC_NOTINCLUDE_MAPS_API) ? 1 : 0),
- 'google_api_key' => get_option('w2dc_google_api_key'),
- 'mapbox_api_key' => get_option('w2dc_mapbox_api_key'),
- 'map_markers_type' => get_option('w2dc_map_markers_type'),
- 'default_marker_color' => get_option('w2dc_default_marker_color'),
- 'default_marker_icon' => get_option('w2dc_default_marker_icon'),
- 'global_map_icons_path' => W2DC_MAP_ICONS_URL,
- 'marker_image_width' => (int)get_option('w2dc_map_marker_width'),
- 'marker_image_height' => (int)get_option('w2dc_map_marker_height'),
- 'marker_image_anchor_x' => (int)get_option('w2dc_map_marker_anchor_x'),
- 'marker_image_anchor_y' => (int)get_option('w2dc_map_marker_anchor_y'),
- 'default_geocoding_location' => get_option('w2dc_default_geocoding_location'),
- 'map_style' => w2dc_getSelectedMapStyle(),
- 'address_autocomplete' => (int)get_option('w2dc_address_autocomplete'),
- 'address_autocomplete_code' => get_option('w2dc_address_autocomplete_code'),
- 'enable_my_location_button' => (int)get_option('w2dc_address_geocode'),
- 'my_location_button' => esc_html__('My Location', 'w2dc'),
- 'my_location_button_error' => esc_html__('GeoLocation service does not work on your device!', 'w2dc'),
- 'default_latitude' => apply_filters('w2dc_default_latitude', 34),
- 'default_longitude' => apply_filters('w2dc_default_longitude', 0),
- )
- ) . ';
-';
- echo '</script>
-';
- }
-
- public function generate_color_palette() {
- ob_start();
- include W2DC_PATH . '/classes/customization/dynamic_css.php';
- $dynamic_css = ob_get_contents();
- ob_get_clean();
-
- echo $dynamic_css;
- die();
- }
-
- public function get_jqueryui_theme() {
- global $w2dc_color_schemes;
-
- if (isset($_COOKIE['w2dc_compare_palettes']) && get_option('w2dc_compare_palettes')) {
- $scheme = $_COOKIE['w2dc_compare_palettes'];
- if ($scheme && isset($w2dc_color_schemes[$scheme]['w2dc_jquery_ui_schemas']))
- echo '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/' . $w2dc_color_schemes[$scheme]['w2dc_jquery_ui_schemas'] . '/jquery-ui.css';
- }
- die();
- }
-
- public function remove_colorpicker_cookie($opt) {
- if (isset($_COOKIE['w2dc_compare_palettes'])) {
- unset($_COOKIE['w2dc_compare_palettes']);
- setcookie('w2dc_compare_palettes', '', -1, '/');
- }
- }
-
- public function render_palette_picker() {
- global $w2dc_instance;
-
- if (!empty($w2dc_instance->frontend_controllers) &&
- $w2dc_instance->action != 'printlisting' &&
- $w2dc_instance->action != 'pdflisting' &&
- $w2dc_instance->action != 'printinvoice'
- ) {
- if (
- (get_option('w2dc_compare_palettes') && current_user_can('manage_options')) ||
- (defined('W2DC_DEMO') && W2DC_DEMO) ||
- apply_filters("w2dc_show_compare_palettes", false)
- ) {
- w2dc_renderTemplate('color_picker/color_picker_panel.tpl.php');
- }
- }
- }
-}
-?>
No newline at end of file
--- a/web-directory-free/classes/ajax_controller.php
+++ b/web-directory-free/classes/ajax_controller.php
@@ -1,543 +0,0 @@
-<?php
-
-// @codingStandardsIgnoreFile
-
-class w2dc_ajax_controller {
-
- public function __construct() {
- add_action('wp_ajax_w2dc_get_map_marker_info', array($this, 'get_map_marker_info'));
- add_action('wp_ajax_nopriv_w2dc_get_map_marker_info', array($this, 'get_map_marker_info'));
-
- add_action('wp_ajax_w2dc_get_sharing_buttons', array($this, 'get_sharing_buttons'));
- add_action('wp_ajax_nopriv_w2dc_get_sharing_buttons', array($this, 'get_sharing_buttons'));
-
- add_action('wp_ajax_w2dc_controller_request', array($this, 'controller_request'));
- add_action('wp_ajax_nopriv_w2dc_controller_request', array($this, 'controller_request'));
-
- add_action('wp_ajax_w2dc_select_fa_icon', array($this, 'select_field_icon'));
- add_action('wp_ajax_nopriv_w2dc_select_fa_icon', array($this, 'select_field_icon'));
-
- add_action('wp_ajax_w2dc_contact_form', array($this, 'contact_form'));
- add_action('wp_ajax_nopriv_w2dc_contact_form', array($this, 'contact_form'));
-
- // is used in wcsearch 'wcsearch_keywords_search_action' filter
- add_action('wp_ajax_w2dc_keywords_search', array($this, 'keywords_search'));
- add_action('wp_ajax_nopriv_w2dc_keywords_search', array($this, 'keywords_search'));
-
- add_action('wp_ajax_w2dc_add_term', array($this, 'add_term'));
- add_action('wp_ajax_nopriv_w2dc_add_term', array($this, 'add_term'));
- add_action('wp_ajax_w2dc_update_tax_wrapper', array($this, 'update_tax_wrapper'));
- add_action('wp_ajax_nopriv_w2dc_update_tax_wrapper', array($this, 'update_tax_wrapper'));
- }
-
- public function controller_request() {
- global $w2dc_instance, $w2dc_global_base_url;
-
- $w2dc_instance->setCurrentDirectory();
-
- $post_args = $_POST;
-
- $shortcode_atts = array_merge(array(
- 'custom_home' => 0,
- 'onepage' => 0,
- 'map_markers_is_limit' => get_option('w2dc_map_markers_is_limit'),
- 'sticky_featured' => 0,
- 'order_by' => get_option('w2dc_default_orderby'),
- 'order' => get_option('w2dc_default_order'),
- 'hide_order' => (int)(!(get_option('w2dc_show_orderby_links'))),
- 'hide_count' => (int)(!(get_option('w2dc_show_listings_count'))),
- 'hide_paginator' => 0,
- 'show_views_switcher' => (int)get_option('w2dc_views_switcher'),
- 'listings_view_type' => get_option('w2dc_views_switcher_default'),
- 'listings_view_grid_columns' => (int)get_option('w2dc_views_switcher_grid_columns'),
- 'listing_thumb_width' => (int)get_option('w2dc_listing_thumb_width'),
- 'wrap_logo_list_view' => (int)get_option('w2dc_wrap_logo_list_view'),
- 'logo_animation_effect' => get_option('w2dc_logo_animation_effect'),
- 'hide_content' => 0,
- 'rating_stars' => 1,
- 'summary_on_logo_hover' => 0,
- 'paged' => 1,
- 'include_categories_children' => 1,
- 'template' => 'frontend/listings_block.tpl.php',
- 'ajax_map_loading' => 0,
- 'geo_poly' => 0,
- 'show_summary_button' => 1,
- 'show_readmore_button' => 1,
- 'ajax_action' => '', // 'search', 'geo_poly', 'order', 'paginator', 'show_more', 'ajax_initial_load', 'ajax_markers'
- ), $post_args);
-
- // set 'perpage' on custom home when no exact parameter was entered
- if (!empty($post_args['is_home']) && empty($shortcode_atts['per