function aft_plgn_jquery_init() { global $post; wp_enqueue_script('jquery-raty-min', RTP_PLUGIN_DIR_JS . 'jquery.raty.min.js', array('jquery')); wp_enqueue_script('jquery-progressbar', RTP_PLUGIN_DIR_JS . 'external/jquery.ui.progressbar.min.js', array('jquery', 'jquery-ui-widget', 'jquery-ui-core')); wp_enqueue_script('rtp-jscript', RTP_PLUGIN_DIR_JS . 'rtp.min.js', array('jquery'), '1.1', false); wp_enqueue_script('rtp-ajax-request', RTP_PLUGIN_DIR_JS . 'rtp-ajax.min.js', array('jquery'), '1.1', false); $option = get_option('aft_options_array'); if (!rtp_is_rated($post->ID)) { $is_rated = false; } else { $is_rated = true; } $adata = aft_plgn_fetch_rate_summary($post->ID, is_page() ? 'true' : 'false'); $rdata = aft_plgn_fetch_ratings($post->ID, $_COOKIE[RTP_COOKIE_NAME], is_page() ? 'true' : 'false'); wp_localize_script('rtp-jscript', 'rtpL10n', array('img_path' => RTP_PLUGIN_DIR_IMG, 'custom_hints' => $option['rtp_custom_hints'], 'hints' => json_encode(array('chint_1' => array(__('Poor'), __('Poor'), __('Average'), __('Average'), __('Excellent')), 'chint_2' => array(__('Low'), __('Low'), __('Medium'), __('Medium'), __('High')), 'trustworthy' => array(__('Lacks reputable sources'), __('Few reputable sources'), __('Adequate reputable sources'), __('Good reputable sources'), __('Great reputable sources')), 'objective' => array(__('Heavily biased'), __('Moderate bias'), __('Minimal bias'), __('No obvious bias'), __('Completely unbiased')), 'complete' => array(__('Missing most information'), __('Contains some information'), __('Contains key information, but with gaps'), __('Contains most key information'), __('Comprehensive coverage')), 'wellwritten' => array(__('Incomprehensive'), __('Difficult to understand'), __('Adequate clarity'), __('Good clarity'), __('Exceptional clarity')))), 'cancel_hint' => __('Remove this rating', RTP_PLUGIN_SNAME), 'is_rated' => $is_rated)); wp_localize_script('rtp-ajax-request', 'rtpL10nAjax', array('ajaxurl' => admin_url('admin-ajax.php'), 'success_msg' => __('Feedback submitted successfuly!', RTP_PLUGIN_SNAME), 'adata_arr' => json_encode(array('trustworthy' => $adata->total_trustworthy, 'objective' => $adata->total_objective, 'complete' => $adata->total_complete, 'wellwritten' => $adata->total_wellwritten, 'c_trustworthy' => $adata->count_trustworthy, 'c_objective' => $adata->count_objective, 'c_complete' => $adata->count_complete, 'c_wellwritten' => $adata->count_wellwritten)), 'is_rated' => $is_rated, 'is_custom_labels' => $option['rtp_is_custom_label'], 'rdata_arr' => json_encode(array('is_highly_knowledgable' => $rdata->is_highly_knowledgable, 'is_relevant' => $rdata->is_relevant, 'is_my_profession' => $rdata->is_my_profession, 'is_personal_passion' => $rdata->is_personal_passion)), 'thanks_msg' => __('Thank you for rating!', RTP_PLUGIN_SNAME))); }
function rtp_display_template($post_id = 0) { global $id; $rtp_options = get_option('aft_options_array'); $session_key = $_COOKIE[RTP_COOKIE_NAME]; if (intval($post_id) > 0) { $postid = $post_id; } else { $postid = $id; } $is_rated = rtp_is_rated($postid); $is_page = 'post' === get_post_type() ? 'false' : 'true'; // Show the current rating data if logged by IP or by IP and Cookie if ($rtp_options['rtp_logged_by'] == 1 || $rtp_options['rtp_logged_by'] == 3) { $data = rtp_fetch_ratings_byip($postid, get_ipaddress(), $is_page); } else { $data = aft_plgn_fetch_ratings($postid, $session_key, $is_page); } $ave_data = aft_plgn_fetch_rate_summary($postid, $is_page); $display = '<!--Main Content--> <div class="rtp-feedback"> <div class="rtp-feedback-panel"> <div class="rtp-feedback-buffer"> <div id="rtp-report" class="rtp-switch rtp-switch-form">View ratings</div> <div id="rtp-form" class="rtp-switch rtp-switch-report">Rate this article</div> <div class="feedback-title rtp-switch-form">%TITLE_LABEL%</div> <div class="feedback-title rtp-switch-report" id="rtp-report-title">%TITLE_LABEL_REPORT%<br /><span>Current average ratings.</span></div> <div style="clear:both;"></div> <!--Primary Feedback--> <div class="feedback-rating"> <div class="feedback-ratings"> <div class="feedback-label">%LABEL_TRUSTWORTHY%</div> <span class="rtp-average-report rtp-switch-report">%AVE_TRUSTWORTHY%</span> <div id="rtp-trustworthy-bar" class="rtp-switch-report"></div> <div class="rtp-switch-form" id="feedback-trustworthy"> <input type="hidden" id="rtp-trustworthy-val" name="trustworthy-score" value="%VAL_TRUSTWORTHY%" /> </div> <div class="rtp-rating-count rtp-switch-report">%COUNT_TRUSTWORTHY%</div> <div class="rtp-trustworthy-hint"></div> </div> <div class="feedback-ratings"> <div class="feedback-label">%LABEL_OBJECTIVE%</div> <span class="rtp-average-report rtp-switch-report">%AVE_OBJECTIVE%</span> <div id="rtp-objective-bar" class="rtp-switch-report"></div> <div class="rtp-switch-form" id="feedback-objective"> <input type="hidden" id="rtp-objective-val" name="objective-score" value="%VAL_OBJECTIVE%" /> </div> <div class="rtp-rating-count rtp-switch-report">%COUNT_OBJECTIVE%</div> <div class="rtp-objective-hint"></div> </div> <div class="feedback-ratings"> <div class="feedback-label">%LABEL_COMPLETE%</div> <span class="rtp-average-report rtp-switch-report">%AVE_COMPLETE%</span> <div id="rtp-complete-bar" class="rtp-switch-report"></div> <div class="rtp-switch-form" id="feedback-complete"> <input type="hidden" id="rtp-complete-val" name="complete-score" value="%VAL_COMPLETE%" /> </div> <div class="rtp-rating-count rtp-switch-report">%COUNT_COMPLETE%</div> <div class="rtp-complete-hint"></div> </div> <div class="feedback-ratings"> <div class="feedback-label">%LABEL_WELLWRITTEN%</div> <span class="rtp-average-report rtp-switch-report">%AVE_WELLWRITTEN%</span> <div id="rtp-wellwritten-bar" class="rtp-switch-report"></div> <div class="rtp-switch-form" id="feedback-wellwritten"> <input type="hidden" id="rtp-wellwritten-val" name="wellwritten-score" value="%VAL_WELLWRITTEN%" /> </div> <div class="rtp-rating-count rtp-switch-report">%COUNT_WELLWRITTEN%</div> <div class="rtp-wellwritten-hint"></div> </div> </div> <div style="clear:both;"></div> <!--For Feedback Options--> <div class="feedback-options rtp-switch-form"> <div class="feedback-options-selection"> <input id="feedback-options-general" type="checkbox" name="feedback-general" value="" /> <label class="feedback-label" for="feedback-options-general">' . __('I am highly knowledgeable about this topic (optional)') . '</label> </div> <div class="feeback-helpimprove-hidden" style="display:none;"> <ul id="feedback-helpimprove"> <li><input id="feedbackStudies" type="checkbox" name="feedback-studies" value="" /><label class="feedback-label" for="feedbackStudies">' . __('I have a relevant college/university degree') . '</label></li> <li><input id="feedbackProfession" type="checkbox" name="feedback-profession" value="" /><label class="feedback-label" for="feedbackProfession">' . __('It is part of my profession') . '</label></li> <li><input id="feedbackPassion" type="checkbox" name="feedback-passion" value="" /><label class="feedback-label" for="feedbackPassion">' . __('It is a deep personal passion') . '</label></li> </ul> </div> </div> <button class="rtp-button rtp-switch-form" id="submit-feedback" type="submit" name="aft-submit-feedback" value="aft-submit-feedback"><span id="rtp-button-label">' . __('Submit Ratings') . '</span></button> <div id="formstatus" class="rtp-switch-form"></div> </div> </div> <input type="hidden" id="feedback-postid" name="feedback-postid" value="%POST_ID%" /> <input type="hidden" id="feedback-datetime" name="feedback-datetime" value="%RATE_DATE%" /> <input type="hidden" id="feedback-ispage" name="feedback-ispage" value="%IS_PAGE%" /> </div>'; return rtp_extend_template($display, $postid, $data, $ave_data); }
function rtp_delete_logs($filter, $keyword) { global $wpdb; $ret = false; switch ($filter) { case 1: $data = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "feedbacks WHERE ip = '{$keyword}'"); foreach ($data as $newdata) { $old_data = aft_plgn_fetch_ratings($newdata->post_id, $newdata->session_key, $newdata->is_page); $summary_data = aft_plgn_fetch_rate_summary($newdata->post_id, $newdata->is_page); $sql = "DELETE FROM %sfeedbacks WHERE id = %d AND ip = '%s'"; $result = $wpdb->query(sprintf($sql, $wpdb->prefix, $newdata->id, $newdata->ip)); $rtp_data = array('post_id' => $newdata->post_id, 'user_type' => $newdata->user_type, 'session_key' => $newdata->session_key, 'trustworthy_rate' => $newdata->trustworthy_rate, 'objective_rate' => $newdata->objective_rate, 'complete_rate' => $newdata->complete_rate, 'wellwritten_rate' => $newdata->wellwritten_rate, 'is_page' => $newdata->is_page); aft_plgn_calculate_summary($rtp_data, $summary_data, false, $old_data, true); } break; //case 2: $sql .= " WHERE cookie = '%s'"; break; //case 2: $sql .= " WHERE cookie = '%s'"; break; case 3: $data = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "feedbacks WHERE post_id = '{$keyword}'"); foreach ($data as $newdata) { $old_data = aft_plgn_fetch_ratings($newdata->post_id, $newdata->session_key, $newdata->is_page); $summary_data = aft_plgn_fetch_rate_summary($newdata->post_id, $newdata->is_page); $sql = "DELETE FROM %sfeedbacks WHERE id = %d AND post_id = '%s'"; $result = $wpdb->query(sprintf($sql, $wpdb->prefix, $newdata->id, $keyword)); $rtp_data = array('post_id' => $newdata->post_id, 'user_type' => $newdata->user_type, 'session_key' => $newdata->session_key, 'trustworthy_rate' => $newdata->trustworthy_rate, 'objective_rate' => $newdata->objective_rate, 'complete_rate' => $newdata->complete_rate, 'wellwritten_rate' => $newdata->wellwritten_rate, 'is_page' => $newdata->is_page); aft_plgn_calculate_summary($rtp_data, $summary_data, false, $old_data, true); } break; default: $data = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "feedbacks WHERE id = '{$keyword}'"); foreach ($data as $newdata) { $old_data = aft_plgn_fetch_ratings($newdata->post_id, $newdata->session_key, $newdata->is_page); $summary_data = aft_plgn_fetch_rate_summary($newdata->post_id, $newdata->is_page); $sql = "DELETE FROM %sfeedbacks WHERE id = %d"; $result = $wpdb->query(sprintf($sql, $wpdb->prefix, $keyword)); $rtp_data = array('post_id' => $newdata->post_id, 'user_type' => $newdata->user_type, 'session_key' => $newdata->session_key, 'trustworthy_rate' => $newdata->trustworthy_rate, 'objective_rate' => $newdata->objective_rate, 'complete_rate' => $newdata->complete_rate, 'wellwritten_rate' => $newdata->wellwritten_rate, 'is_page' => $newdata->is_page); aft_plgn_calculate_summary($rtp_data, $summary_data, false, $old_data, true); } break; } if ($result) { $ret = true; } else { $ret = false; } return $ret; }