forked from kcpt-steven-kohlmeyer/rating-system
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrating-system.php
211 lines (176 loc) · 6.64 KB
/
rating-system.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/**
* Plugin Name: Rating System
* Plugin URI: http://github.com/AlexAlexandru/rating-system
* Description: The simple way to add like or dislike buttons.
* Version: 2.7.6.1
* Author: AlexAlexandru
* Author URI: https://github.com/AlexAlexandru
* License: GPL2
* Text Domain: vortex_system_ld
* Domain Path: /languages
*/
if ( ! defined( 'ABSPATH' ) ) exit;//exit if accessed directly
$sse = plugin_dir_path( __FILE__).'admin/framework/autoload.php';
if ( file_exists($sse) ) {
include($sse);
};
function vortex_ra_read_cookie($name,$postid){
if(isset($_COOKIE[$name])){
$decode = json_decode($_COOKIE[$name]);
$found = array_search($postid, $decode);
if ($found !== false) {
return 'found';
} else {
return 'notfound';
}
}else{
return 'notfound';
}
}
function vortex_ra_cookie($name,$postid,$name2){
if(!isset($_COOKIE[$name])){
$array = json_encode(array($postid));
setcookie($name,$array,time()+ 2419200,'/',COOKIE_DOMAIN,is_ssl(),true);
}else{
$decode = json_decode($_COOKIE[$name]);
if(!in_array($postid,$decode)){
array_push($decode,$postid);
$encode = json_encode($decode);
setcookie($name,$encode,time()+ 2419200,'/',COOKIE_DOMAIN,is_ssl(),true);
}
}
}
//require all usefull stuffs
function vortex_systen_main_function(){
if(class_exists('myCRED_Hook')){
include(plugin_dir_path( __FILE__ ).'mycredcomments.php');
include(plugin_dir_path( __FILE__ ).'mycredposts.php');
function vortex_mycred_references_filter($references){
$references['vortex_like_posts_mycred_author_content'] = __( 'Receive like for posts(content author)', 'vortex_system_ld' );
$references['vortex_like_posts_mycred_author'] = __( 'Receive like for posts(like author)', 'vortex_system_ld' );
$references['vortex_like_coms_mycred_author_content'] = __( 'Receive like for comments(content author)', 'vortex_system_ld' );
$references['vortex_like_coms_mycred_author'] = __( 'Receive like for comments(like author)', 'vortex_system_ld' );
return $references;
}
add_filter('mycred_all_references','vortex_mycred_references_filter');
}
$vortex_like_dislike = get_option('vortex_like_dislike');
load_plugin_textdomain( 'vortex_system_ld', FALSE, basename(plugin_dir_path( __FILE__ )). '/languages' );
$options = plugin_dir_path( __FILE__).'admin/vortexlikedislike.php';
if ( file_exists($options) ) {
include($options);
};
//donation button
function vortex_system_donation_button(){
echo '<form style="width:260px;margin:0 auto;" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="VVGFFVJSFVZ7S">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
';
}
add_action('sse_footer_vortex_like_dislike','vortex_system_donation_button');
$vortex_like_dislike = get_option("vortex_like_dislike");
if($vortex_like_dislike['v-switch-posts'] && isset($vortex_like_dislike['v-switch-posts'])){
include(plugin_dir_path( __FILE__ ).'posts-pages.php');
//load metabox
include(plugin_dir_path( __FILE__).'metabox.php');
}
if($vortex_like_dislike['v-switch-comments'] && isset($vortex_like_dislike['v-switch-comments'])){
include(plugin_dir_path( __FILE__ ).'comments.php');
}
}
add_action('plugins_loaded','vortex_systen_main_function');
function rating_system_load_widgets(){
$widget = plugin_dir_path( __FILE__ ).'widget/widget.php';
if(file_exists($widget)){
include( $widget );
}
}
add_action('plugins_loaded','rating_system_load_widgets');
//add shortcode
function vortex_rating_system_register_shortcodes(){
function vortex_shortcode_render_posts($atts){
extract( shortcode_atts( array(
'counter' => "yes",
), $atts ) );
if($counter == "yes"){
return vortex_render_for_posts(true,true);
}else{
return vortex_render_for_posts(true,false);
}
}
function vortex_shortcode_render_posts_disable_dislike($atts){
extract( shortcode_atts( array(
'counter' => true,
), $atts ) );
if($counter == "yes"){
return vortex_render_for_posts(false,true);
}else{
return vortex_render_for_posts(false,false);
}
}
function vortex_shortcode_render_comments(){
return vortex_render_for_comments();
}
function vortex_shortcode_render_comments_disable_dislike(){
return vortex_render_for_comments(false);
}
function vortex_shortcode_render_top_posts($atts){
extract( shortcode_atts( array(
'number' => '5',
'display_counter' => 'yes',
'display_content' => 'no',
'link_to_post' => 'yes',
'category_slugs' => '',
), $atts ) );
$args = array(
'orderby' => 'meta_value_num',
'meta_key' => 'vortex_system_likes',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => $number,
'category_name' => $category_slugs
);
// The Query
$query = new WP_Query( $args );
// The Loop
if ( $query->have_posts() ) {
echo '<ul>';
while ( $query->have_posts() ) {
$query->the_post();
$current_likes = get_post_meta(get_the_ID(),'vortex_system_likes',true);
echo '<li class="top-posts '.get_the_ID().' ">';
echo '<div class="top-posts-title '.get_the_ID().'">';
if($link_to_post == "yes"){
echo '<a class="top-posts-link '.get_the_ID().'" href="'.get_the_permalink().'">'.get_the_title().'</a>';
} else {
the_title();
}
if($display_counter == 'yes'){
echo ' '.$current_likes.' likes';
}
echo '</div>';
if($display_content == 'yes'){
echo '<div class="top-posts-content '.get_the_ID().'">';
echo get_the_content();
echo '</div>';
}
echo '</li>';
}
echo '</ul>';
} else {
echo 'No posts found.';
}
// Restore original Post Data
wp_reset_postdata();
}
add_shortcode('rating-system-top-posts', 'vortex_shortcode_render_top_posts');
add_shortcode('rating-system-posts', 'vortex_shortcode_render_posts');
add_shortcode('rating-system-posts-disable-dislike', 'vortex_shortcode_render_posts_disable_dislike');
add_shortcode('rating-system-comments', 'vortex_shortcode_render_comments');
add_shortcode('rating-system-comments-disable-dislike', 'vortex_shortcode_render_comments_disable_dislike');
}
add_action( 'init', 'vortex_rating_system_register_shortcodes');