YOP Poll - Version 5.7.5

Version Description

  • Fixed issue with vote button not showing up
  • Other minor fixes
Download this release

Release Info

Developer yourownprogrammer
Plugin Icon 128x128 YOP Poll
Version 5.7.5
Comparing to
See all releases

Code changes from version 5.7.4 to 5.7.5

css/yop-poll-slider.css CHANGED
@@ -198,7 +198,7 @@
198
199
.yop-poll-pro-slider .yop-poll-pro-template-li p, .yop-poll-widget-slider .yop-poll-widget-template-li p, .yop-poll-buy-slider .yop-poll-buy-template-li p {
200
201
- margin: 0;
202
203
padding: 3px;
204
@@ -532,6 +532,25 @@
532
transition: all 0.3s linear;
533
534
}
535
li:before, li:after {
536
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
537
}
198
199
.yop-poll-pro-slider .yop-poll-pro-template-li p, .yop-poll-widget-slider .yop-poll-widget-template-li p, .yop-poll-buy-slider .yop-poll-buy-template-li p {
200
201
+ margin: 0 auto;
202
203
padding: 3px;
204
532
transition: all 0.3s linear;
533
534
}
535
+
536
+ .yop-poll-page-template-buy p, .yop-poll-widget-template-buy p, .yop-poll-buy-template-buy p {
537
+
538
+ background: #00A8FF;
539
+
540
+ color: #FFF;
541
+
542
+ -webkit-transition: all 0.3s linear;
543
+
544
+ -moz-transition: all 0.3s linear;
545
+
546
+ -ms-transition: all 0.3s linear;
547
+
548
+ -o-transition: all 0.3s linear;
549
+
550
+ transition: all 0.3s linear;
551
+
552
+ }
553
+
554
li:before, li:after {
555
-moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
556
}
inc/maintenance.php CHANGED
@@ -1,23 +1,25 @@
1
<?php
2
3
- class YOP_POLL_Maintenance {
4
5
- private function network_propagate( $pfunction, $networkwide ) {
6
- error_reporting( 0 );
7
- if( function_exists( 'is_multisite' ) && is_multisite() ) {
8
9
- if( $networkwide ) {
10
11
$old_blog = $GLOBALS['wpdb']->blogid;
12
13
- $blogids = $GLOBALS['wpdb']->get_col( "SELECT blog_id FROM {$GLOBALS['wpdb']->blogs}" );
14
15
- foreach( $blogids as $blog_id ) {
16
17
- switch_to_blog( $blog_id );
18
19
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
20
- $version = get_option( "yop_poll_version" );
21
22
/* if ( version_compare( $version, '4.9.2', '<=' ) &&isset($version)) {
23
yop_poll_dump(12);
@@ -28,79 +30,66 @@ class YOP_POLL_Maintenance {
28
} */
29
30
31
32
- $poll_archive_page = get_page_by_path( 'yop-poll-archive', ARRAY_A );
33
34
- if( ! $poll_archive_page ) {
35
36
- $_p = array();
37
38
- $_p['post_title'] = 'Yop Poll Archive';
39
40
- $_p['post_content'] = "[yop_poll_archive]";
41
42
- $_p['post_status'] = 'publish';
43
-
44
- $_p['post_type'] = 'page';
45
46
$_p['comment_status'] = 'open';
47
48
- $_p['ping_status'] = 'open';
49
-
50
- $_p['post_category'] = array( 1 ); // the default 'Uncategorised'
51
-
52
53
54
- $poll_archive_page_id = wp_insert_post( $_p );
55
56
57
58
- }
59
-
60
- else {
61
62
$poll_archive_page_id = $poll_archive_page['ID'];
63
64
}
65
66
67
68
69
70
- call_user_func( array( $this, $pfunction ), $networkwide );
71
-
72
- $version = get_option( "yop_poll_version" );
73
-
74
-
75
-
76
77
-
78
- $default_options = get_option( 'yop_poll_options' );
79
-
80
- $default_options['archive_url'] = get_permalink( $poll_archive_page_id );
81
82
$default_options['yop_poll_archive_page_id'] = $poll_archive_page_id;
83
84
85
-
86
//addind default options
87
88
- update_option( 'yop_poll_options', $default_options );
89
-
90
91
92
}
93
94
- switch_to_blog( $old_blog );
95
96
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
97
98
return;
99
100
}
101
}
102
103
- $version = get_option( "yop_poll_version" );
104
105
/* if ( version_compare( $version, '4.9.2', '<=' ) &&isset($version)) {
106
yop_poll_dump(12);
@@ -112,180 +101,173 @@ class YOP_POLL_Maintenance {
112
} */
113
114
115
116
117
118
- $poll_archive_page = get_page_by_path( 'yop-poll-archive', ARRAY_A );
119
120
- if( ! $poll_archive_page ) {
121
122
- $_p = array();
123
124
- $_p['post_title'] = 'Yop Poll Archive';
125
-
126
- $_p['post_content'] = "[yop_poll_archive]";
127
-
128
- $_p['post_status'] = 'publish';
129
-
130
- $_p['post_type'] = 'page';
131
132
$_p['comment_status'] = 'open';
133
134
- $_p['ping_status'] = 'open';
135
-
136
- $_p['post_category'] = array( 1 ); // the default 'Uncategorised'
137
138
139
140
- $poll_archive_page_id = wp_insert_post( $_p );
141
142
143
-
144
- }
145
-
146
- else {
147
148
$poll_archive_page_id = $poll_archive_page['ID'];
149
150
}
151
152
153
-
154
//addind default options
155
156
- call_user_func( array( $this, $pfunction ), $networkwide );
157
158
159
160
- $default_options = get_option( 'yop_poll_options' );
161
-
162
- $default_options['archive_url'] = get_permalink( $poll_archive_page_id );
163
164
$default_options['yop_poll_archive_page_id'] = $poll_archive_page_id;
165
166
167
-
168
//addind default options
169
170
- update_option( 'yop_poll_options', $default_options );
171
-
172
173
174
}
175
176
- function propagate_activation( $networkwide ) {
177
if (version_compare(phpversion(), '5.3', '<')) {
178
wp_die("Php version isn't high enough!");
179
}
180
181
- $this->network_propagate( 'activate', $networkwide );
182
183
}
184
185
- function propagate_deactivation( $networkwide ) {
186
global $wpdb;
187
// $wpdb->query( "DROP TABLE `" . $wpdb->prefix . "yop_pollmeta`, `" . $wpdb->prefix . "yop_polls`, `" . $wpdb->prefix . "yop_poll_answermeta`, `" . $wpdb->prefix . "yop_poll_answers`, `" . $wpdb->prefix . "yop_poll_custom_fields`, `" . $wpdb->prefix . "yop_poll_logs`, `" . $wpdb->prefix . "yop_poll_voters`, `" . $wpdb->prefix . "yop_poll_bans`, `" . $wpdb->prefix . "yop_poll_templates`, `" . $wpdb->prefix . "yop_poll_votes_custom_fields`, `" . $wpdb->prefix . "yop_poll_facebook_users`" );
188
- $this->network_propagate( 'deactivate', $networkwide );
189
}
190
- public function some_function($x=0,$current_options=array()){
191
- $installed_version = get_option( "yop_poll_version" );
192
global $wpdb;
193
194
- if ( version_compare( $installed_version, '4.9.3', '<=' )||$x==1 ){
195
if (!(version_compare(phpversion(), '5.3', '<'))) {
196
- ini_set("memory_limit","1024M");
197
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
198
- require_once( YOP_POLL_INC . 'db_schema.php' );
199
- if(empty($current_options)){
200
- $current_options=get_option( 'yop_poll_options' );
201
202
- $default=get_option( 'yop_poll_options' );
203
}
204
$capObj = YOP_POLL_Capabilities::get_instance();
205
$capObj->install_capabilities();
206
Yop_Poll_DbSchema::create_poll_database_tables();
207
- $wpdb->query( 'ALTER TABLE `' . $wpdb->yop_polls . '` CHANGE `ID` `ID` INT( 11 ) NOT NULL ' );
208
- $this->install_default_options();
209
-
210
- $new_options=array(
211
-
212
- 'user_interface_type' => 'beginner',
213
- 'is_default_answer' => $current_options['is_default_answer'],
214
- 'poll_start_date' =>current_time( 'mysql' ),
215
- 'poll_end_date' => '01-01-2038 23:59:59',
216
- 'view_results' => array( $current_options['view_results']),
217
- 'view_results_start_date' => convert_date($current_options['view_results_start_date'],'d-m-Y H:i:s',1),
218
- 'view_results_permissions' => array( 'guest', 'registered' ),
219
- 'view_results_type' => $current_options['view_results_type'],
220
- 'answer_result_label' => $current_options['answer_result_label'],
221
- 'vote_button_label' => $current_options['vote_button_label'],
222
- 'template_width' => $current_options['template_width'],
223
- 'widget_template_width' => $current_options['widget_template_width'],
224
- 'view_results_link' => $current_options['view_results_link'],
225
- 'view_results_link_label' => $current_options['view_results_link_label'],
226
- 'view_back_to_vote_link' => $current_options['view_back_to_vote_link'],
227
- 'view_back_to_vote_link_label' => $current_options['view_back_to_vote_link_label'],
228
- 'view_total_votes' => $current_options['view_total_votes'],
229
- 'view_total_votes_label' => $current_options['view_total_votes_label'],
230
- 'view_total_answers' =>$current_options['view_total_answers'],
231
- 'view_total_answers_label' => $current_options['view_total_answers_label'],
232
- 'message_after_vote' => $current_options['message_after_vote'],
233
- 'vote_permisions' => array( 'guest', 'registered' ),
234
- 'vote_permisions_wordpress' => $current_options['vote_permisions_wordpress'],
235
- 'vote_permisions_wordpress_label' => $current_options['vote_permisions_wordpress_label'],
236
- 'vote_permisions_anonymous' => $current_options['vote_permisions_anonymous'],
237
- 'vote_permisions_anonymous_label' =>$current_options['vote_permisions_anonymous_label'],
238
- 'blocking_voters' => array( $current_options['blocking_voters'] ),
239
- 'blocking_voters_interval_value' => $current_options['blocking_voters_interval_value'],
240
- 'blocking_voters_interval_unit' => $current_options['blocking_voters_interval_unit'],
241
- 'limit_number_of_votes_per_user' => $current_options['limit_number_of_votes_per_user'],
242
- 'number_of_votes_per_user' => $current_options['number_of_votes_per_user'],
243
- 'percentages_decimals' => $current_options['percentages_decimals'],
244
- 'use_default_loading_image' => $current_options['use_default_loading_image'],
245
- 'loading_image_url' => $current_options['loading_image_url'],
246
- 'redirect_after_vote' => $current_options['redirect_after_vote'],
247
- 'redirect_after_vote_url' =>$current_options['redirect_after_vote_url'],
248
- 'date_format' => 'UE',
249
- 'view_poll_archive_link' => $current_options['view_poll_archive_link'],
250
- 'auto_generate_poll_page' => $current_options['auto_generate_poll_page'],
251
- 'has_auto_generate_poll_page' => $current_options['has_auto_generate_poll_page'],
252
- 'use_captcha' => $current_options['use_captcha'],
253
- 'send_email_notifications' => $current_options['send_email_notifications'],
254
- 'allow_other_answers' => $current_options['allow_other_answers'],
255
- 'other_answers_label' => $current_options['other_answers_label'],
256
- 'is_default_other_answer' => $current_options['is_default_other_answer'],
257
- 'add_other_answers_to_default_answers' =>$current_options['add_other_answers_to_default_answers'],
258
- 'display_other_answers_values' => $current_options['display_other_answers_values'],
259
- 'allow_multiple_answers' => $current_options['allow_multiple_answers'],
260
- 'allow_multiple_answers_number' => $current_options['allow_multiple_answers_number'],
261
- 'allow_multiple_answers_min_number' => $current_options['allow_multiple_answers_min_number'],
262
- 'display_answers' =>$current_options['display_answers'],
263
- 'display_answers_tabulated_cols' => $current_options['display_answers_tabulated_cols'],
264
- 'sorting_results' => 'as_defined',
265
- 'sorting_answers' => 'as_defined',
266
- 'sorting_results_direction' => $current_options['sorting_results_direction'],
267
- 'sorting_answers_direction' => $current_options['sorting_answers_direction'],
268
- 'singular_answer_result_votes_number_label' => $current_options['singular_answer_result_votes_number_label'],
269
- 'plural_answer_result_votes_number_label' => $current_options['plural_answer_result_votes_number_label'],
270
- 'display_results' => $current_options['display_results'],
271
- 'display_results_tabulated_cols' => $current_options['display_results_tabulated_cols'],
272
- 'bar_background' => $current_options['bar_background'],
273
- 'bar_height' => $current_options['bar_height'],
274
- 'bar_border_color' => $current_options['bar_border_color'],
275
- 'bar_border_width' =>$current_options['bar_border_width'],
276
- 'bar_border_style' => $current_options['bar_border_style'],
277
- 'sorting_archive_polls' => 'votes',
278
- 'sorting_archive_polls_rule' => 'asc',
279
- 'archive_url' => $current_options['archive_url'],
280
- 'archive_link_label' => $current_options['view_poll_archive_link_label'],
281
- 'show_poll_in_archive' => $current_options['show_in_archive'],
282
- 'poll_archive_order' => $current_options['archive_order'],
283
- 'archive_polls_per_page' => $current_options['archive_polls_per_page'],
284
- 'email_notifications_from_name' => $current_options['email_notifications_from_name'],
285
- 'email_notifications_from_email' => $current_options['email_notifications_from_email'],
286
- 'email_notifications_recipients' => $current_options['email_notifications_recipients'],
287
- 'email_notifications_subject' =>$current_options['email_notifications_subject'],
288
- 'email_notifications_body' => '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
289
290
<p>Vote Details:</p>
291
@@ -316,57 +298,57 @@ class YOP_POLL_Maintenance {
316
[/QUESTION]
317
318
<p><b>Vote ID:</b> <br />%VOTE_ID%</p>',
319
- 'schedule_reset_poll_stats' => $current_options['schedule_reset_poll_stats'],
320
- 'schedule_reset_poll_date' => current_time( 'mysql' ),
321
- 'schedule_reset_poll_recurring_value' => $current_options['schedule_reset_poll_recurring_value'],
322
- 'schedule_reset_poll_recurring_unit' => $current_options['schedule_reset_poll_recurring_unit'],
323
- 'singular_answer_result_votes_number_label' => __yop_poll( "vote" ),
324
- 'plural_answer_result_votes_number_label' => __yop_poll( "votes" ),
325
- 'start_scheduler' => $current_options['start_scheduler'],
326
- 'use_the_same_template_for_widget' => 'yes' ,
327
- 'vote_permisions_facebook' => 'no',
328
329
- 'vote_permisions_facebook_label' => __yop_poll( 'Vote as Facebook User' ),
330
331
- 'facebook_share_after_vote' => 'no',
332
333
- 'facebook_share_description' => __yop_poll( 'Just casted an YOP Poll vote on ' ) . get_bloginfo( 'name' ),
334
335
- 'vote_permisions_google' => 'no',
336
337
- 'vote_permisions_google_label' => __yop_poll( 'Vote as G+ User' ),
338
339
- 'show_google_share_button' => 'no',
340
- 'google_integration' =>'no',
341
- 'facebook_integration' =>'no',
342
- 'facebook_show_comments_widget' => "no"
343
// 'view_total_answers_label' => __yop_poll( 'Poll total answers: %POLL-TOTAL-ANSWERS%' ),
344
345
);
346
- if( $current_options['blocking_voters']=='cookie-ip')
347
- $new_options['blocking_voters' ]=array("cookie",'ip');
348
- else{
349
- if( $current_options['blocking_voters']=='username')
350
- $new_options['blocking_voters' ]=array('user_id');
351
}
352
- list($g1,$d)=explode('-',$current_options['view_results_permissions']);
353
- $new_options['view_results_permissions' ]=array($g1,$d);
354
- list($g1,$d)=explode('-',$current_options['view_results_link']);
355
- $new_options['view_results_link' ]=array($g1,$d);
356
- update_option( 'yop_poll_options', $new_options );
357
- update_option( "yop_poll_version", YOP_POLL_VERSION );
358
YOP_POLL_Maintenance::activation_hook($default);
359
- $wpdb->query( 'ALTER TABLE `' . $wpdb->yop_polls . '` CHANGE `ID` `ID` INT( 11 ) NOT NULL AUTO_INCREMENT ' );
360
361
}
362
}
363
- $installed_version = get_option( "yop_poll_version" );
364
365
- if ( version_compare( $installed_version, '5.2', '<=' ) ){
366
ini_set('max_execution_time', 700);
367
- ini_set("memory_limit","512M");
368
- $default_poll_options = get_option( 'yop_poll_options' );
369
- $default_poll_options['email_notifications_body'] = '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
370
371
<p>Vote Details:</p>
372
@@ -397,10 +379,10 @@ class YOP_POLL_Maintenance {
397
[/QUESTION]
398
399
<p><b>Vote ID:</b> <br />%VOTE_ID%</p>';
400
- update_option( 'yop_poll_options', $default_poll_options );
401
- $templates = self::yop_poll_get_templates_new_version_from_db();
402
- foreach($templates as $template){
403
- $template['js']= <<<NOWDOC
404
function stripBorder_%POLL-ID%(object) {
405
object.each(function() {
406
if( parseInt(jQuery(this).width() ) > 0) {
@@ -509,10 +491,10 @@ function runOnPollStateChange_%POLL-ID%() {
509
NOWDOC;
510
self::update_poll_template_in_database(($template));
511
}
512
- $polls=self::yop_poll_get_polls_for_body_mail_update();
513
- foreach($polls as $poll){
514
- $current=new YOP_POLL_Poll_Model($poll['ID']);
515
- $current->email_notifications_body='<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
516
517
<p>Vote Details:</p>
518
@@ -546,36 +528,36 @@ NOWDOC;
546
$current->save();
547
548
}
549
- update_option( "yop_poll_version", YOP_POLL_VERSION );
550
}
551
- $installed_version = get_option( "yop_poll_version" );
552
- if ( version_compare( $installed_version, '5.3', '<=' ) ){
553
- update_option( "yop_poll_version", YOP_POLL_VERSION );
554
}
555
- $installed_version = get_option( "yop_poll_version" );
556
- if ( version_compare( $installed_version, '5.5', '<=' ) ){
557
- update_option( "yop_poll_version", YOP_POLL_VERSION );
558
}
559
- $installed_version = get_option( "yop_poll_version" );
560
561
- if ( version_compare( $installed_version, '5.6', '<=' ) ){
562
global $wpdb;
563
- update_option( "yop_poll_version", YOP_POLL_VERSION );
564
- $default_poll_options = get_option( 'yop_poll_options' );
565
- $default_poll_options['show_results_in']="bar";
566
- update_option( 'yop_poll_options', $default_poll_options );
567
568
- $wpdb->query( 'ALTER TABLE `' . $wpdb->yop_poll_templates . '` ADD `after_vote_template_chart` text' );
569
- update_option( "yop_poll_version", '5.7' );
570
571
}
572
- if ( version_compare( $installed_version, '5.7', '<=' ) ){
573
global $wpdb;
574
- update_option( "yop_poll_version", YOP_POLL_VERSION );
575
576
- $templates = self::yop_poll_get_templates_new_version_from_db();
577
- foreach($templates as $template){
578
- $template['js']= <<<NOWDOC
579
function stripBorder_%POLL-ID%(object) {
580
object.each(function() {
581
if( parseInt(jQuery(this).width() ) > 0) {
@@ -730,7 +712,7 @@ function runOnPollStateChange_%POLL-ID%() {
730
731
};
732
NOWDOC;
733
- $template['after_vote_template_chart']= <<<NOWDOC
734
[QUESTION_CONTAINER]
735
<div id = "yop-poll-question-container-%POLL-ID%-%QUESTION-ID%" class = "yop-poll-question-container-%POLL-ID%">
736
<div id = "yop-poll-question-%POLL-ID%-%QUESTION-ID%"
@@ -753,25 +735,31 @@ NOWDOC;
753
NOWDOC;
754
self::update_poll_template_in_database2($template);
755
}
756
- update_option( "yop_poll_version", '5.7.1' );
757
758
}
759
- if ( version_compare( $installed_version, '5.7.1', '<=' ) ){
760
global $wpdb;
761
- update_option( "yop_poll_version", '5.7.2' );
762
}
763
- if ( version_compare( $installed_version, '5.7.2', '<=' ) ){
764
global $wpdb;
765
- update_option( "yop_poll_version", '5.7.3' );
766
}
767
- if ( version_compare( $installed_version, '5.7.3', '<=' ) ){
768
global $wpdb;
769
- update_option( "yop_poll_version", '5.7.4' );
770
}
771
}
772
- private static function update_poll_template_in_database2( $template ) {
773
global $wpdb;
774
- $sql = $wpdb->query( $wpdb->prepare( "
775
UPDATE " . $wpdb->yop_poll_templates . "
776
SET name = %s,
777
before_vote_template = %s,
@@ -784,138 +772,149 @@ NOWDOC;
784
last_modified = %s
785
WHERE
786
id = %d
787
- ", $template['name'], $template['before_vote_template'], $template['after_vote_template'],$template['after_vote_template_chart'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time( 'mysql' ), $template['id'] ) );
788
return $sql;
789
}
790
- public function yop_poll_get_polls_for_body_mail_update(){
791
global $wpdb;
792
- $result = $wpdb->get_results(( "
793
SELECT ID
794
- FROM " . $wpdb->yop_polls." ORDER BY ID ASC
795
- " ), ARRAY_A );
796
return $result;
797
}
798
- private function install_default_options() {
799
- $default_poll_options = get_option( 'yop_poll_options' );
800
801
$default_poll_options['is_default_answer'] = 'no';
802
- $default_poll_options['poll_start_date' ] = current_time( 'mysql' );
803
- $default_poll_options['poll_end_date'] = '01-01-2038 23:59:59';
804
805
- update_option( 'yop_poll_options', $default_poll_options );
806
}
807
808
- private function uninstall_default_options() {
809
// delete_option( "yop_poll_version" );
810
// delete_option( "yop_poll_options" );
811
}
812
813
- public function activate( $networkwide ) {
814
- if( ! current_user_can( 'activate_plugins' ) ) {
815
- $error = new WP_Error ( 'Wordpress_version_error', __yop_poll( 'You need permissions to activate this plugin' ), __yop_poll( 'Error: Wordpress Activation Permissions Problem' ) );
816
}
817
818
- if( ! version_compare( $GLOBALS['wp_version'], YOP_POLL_WP_VERSION, '>=' ) ) {
819
- $error = new WP_Error ( 'Wordpress_version_error', sprintf( __yop_poll( 'You need at least Wordpress version %s to use this plugin' ), YOP_POLL_WP_VERSION ), __yop_poll( 'Error: Wordpress Version Problem' ) );
820
- $error = new WP_Error ( 'Wordpress_version_error', sprintf( __yop_poll( 'You need at least Wordpress version %s to use this plugin' ), YOP_POLL_WP_VERSION ), __yop_poll( 'Error: Wordpress Version Problem' ) );
821
}
822
823
- if( isset ( $error ) && is_wp_error( $error ) ) {
824
- wp_die( $error->get_error_message(), $error->get_error_data() );
825
}
826
827
828
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
829
- require_once( YOP_POLL_INC . 'db_schema.php' );
830
$this->install_default_options();
831
$capObj = YOP_POLL_Capabilities::get_instance();
832
$capObj->install_capabilities();
833
Yop_Poll_DbSchema::install_database();
834
}
835
836
- public function deactivatedelete( $networkwide ) {
837
- require_once( YOP_POLL_INC . 'db_schema.php' );
838
Yop_Poll_DbSchema::delete_database_tables();
839
$capObj = YOP_POLL_Capabilities::get_instance();
840
$capObj->uninstall_capabilities();
841
$this->uninstall_default_options();
842
}
843
844
- function new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
845
- if( ! function_exists( 'is_plugin_active_for_network' ) ) {
846
- require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
847
}
848
- if( is_plugin_active_for_network( YOP_POLL_SHORT_PLUGIN_FILE ) ) {
849
$old_blog = $GLOBALS['wpdb']->blogid;
850
- switch_to_blog( $blog_id );
851
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
852
- $this->activate( null );
853
- switch_to_blog( $old_blog );
854
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
855
}
856
}
857
858
- function delete_blog( $blog_id ) {
859
$old_blog = $GLOBALS['wpdb']->blogid;
860
- switch_to_blog( $blog_id );
861
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
862
- $this->deactivatedelete( null );
863
- require_once( YOP_POLL_INC . 'db_schema.php' );
864
// Yop_Poll_DbSchema::delete_database_tables();
865
$capObj = YOP_POLL_Capabilities::get_instance();
866
$capObj->uninstall_capabilities();
867
$this->uninstall_default_options();
868
- switch_to_blog( $old_blog );
869
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
870
}
871
872
- function update() {
873
}
874
875
- public function activation_hook($default) {
876
ini_set('max_execution_time', 700);
877
- $current_options=get_option( 'yop_poll_options' );
878
- $polls = self::yop_poll_get_polls_from_db();
879
- $answers = self::yop_poll_get_answers_from_db();
880
- $logs = self::yop_poll_get_logs_from_db();
881
- $bans = self::yop_poll_get_bans_from_db();
882
$custom_fields = self::yop_poll_get_custom_fields_from_db();
883
- $custom_votes = self::yop_poll_get_custom_fields_votes_from_db();
884
- $metas = self::yop_poll_get_polls_meta_from_db();
885
- $answers_meta = self::yop_poll_get_answers_meta_from_db();
886
- $templates = self::yop_poll_get_templates_from_db();
887
- foreach($templates as $template){
888
- $template['before_vote_template'] ="[QUESTION_CONTAINER]". $template['before_vote_template'];
889
- $template['before_vote_template']=str_replace('%POLL-ANSWER-LABEL%','%POLL-ANSWER-LABEL% [ANSWER_RESULT_CONTAINER]',$template['before_vote_template']);
890
- $template['before_vote_template']=str_replace('%POLL-TOTAL-ANSWERS%','%POLL-TOTAL-ANSWERS-LABEL%',$template['before_vote_template']);
891
- $template['before_vote_template']=str_replace('%POLL-TOTAL-VOTES%','%POLL-TOTAL-VOTES-LABEL%',$template['before_vote_template']);
892
- $template['after_vote_template']=str_replace('%POLL-TOTAL-VOTES%','%POLL-TOTAL-VOTES-LABEL%',$template['after_vote_template']);
893
- $template['after_vote_template']=str_replace('%POLL-TOTAL-ANSWERS%','%POLL-TOTAL-ANSWERS-LABEL%',$template['after_vote_template']);
894
- $template['after_end_date_template']=str_replace('%POLL-TOTAL-ANSWERS%','%POLL-TOTAL-ANSWERS-LABEL%',$template['after_end_date_template']);
895
- $template['after_end_date_template']=str_replace('%POLL-TOTAL-VOTES%','%POLL-TOTAL-VOTES-LABEL%',$template['after_end_date_template']);
896
- $template['before_vote_template']=preg_replace('/%POLL-ANSWER-RESULT-BAR%/','%POLL-ANSWER-RESULT-BAR% [/ANSWER_RESULT_CONTAINER]',$template['before_vote_template'],1);
897
$find = '[/ANSWER_RESULT_CONTAINER]';
898
$replace = '';
899
// $template['before_vote_template']= preg_replace(strrev("/$find/"),strrev($replace),strrev( $template['before_vote_template']),1);
900
- $template['after_vote_template'] ="[QUESTION_CONTAINER]". $template['after_vote_template'];
901
- $template['after_end_date_template'] ="[QUESTION_CONTAINER]". $template['after_end_date_template'];
902
/* if(strpos($template['before_vote_template'],"[CAPTCHA_CONTAINER]"))
903
$template['before_vote_template']=str_replace('[CAPTCHA_CONTAINER]','[/QUESTION_CONTAINER][CAPTCHA_CONTAINER]',$template['before_vote_template']);
904
else{
905
$template['before_vote_template']=str_replace('<div id="yop-poll-vote-%POLL-ID%" class="yop-poll-footer">','[/QUESTION_CONTAINER]<div id="yop-poll-vote-%POLL-ID%" class="yop-poll-footer">',$template['before_vote_template']);
906
} */
907
- $template['before_vote_template']= $template['before_vote_template'].'[/QUESTION_CONTAINER]' ;
908
- if(strpos($template['before_vote_template'],"%POLL-QUESTION%")&&strpos($template['before_vote_template'],'%POLL-NAME%')){
909
- $template['before_vote_template']=str_replace('%POLL-QUESTION%','',$template['before_vote_template']);
910
- $template['before_vote_template']=str_replace('%POLL-NAME%','%POLL-QUESTION%',$template['before_vote_template']);
911
}
912
- if(strpos($template['after_vote_template'],"%POLL-QUESTION%")&&strpos($template['after_vote_template'],'%POLL-NAME%')){
913
- $template['after_vote_template']=str_replace('%POLL-QUESTION%','',$template['after_vote_template']);
914
- $template['after_vote_template']=str_replace('%POLL-NAME%','%POLL-QUESTION%',$template['after_vote_template']);
915
}
916
- $template['after_vote_template']= $template['after_vote_template'].'[/QUESTION_CONTAINER]';
917
- $template['after_end_date_template']=$template['after_end_date_template'].'[/QUESTION_CONTAINER]';
918
- $template['js']=<<<NOWDOC
919
function stripBorder_%POLL-ID%(object) {
920
object.each(function() {
921
if( parseInt(jQuery(this).width() ) > 0) {
@@ -1071,60 +1070,60 @@ function runOnPollStateChange_%POLL-ID%() {
1071
};
1072
1073
NOWDOC;
1074
- $template['js'] = addslashes( $template['js'] );
1075
- $templates_ids[$template['id']]=self::insert_template_in_databease(($template));
1076
}
1077
1078
- foreach( $polls as $poll ) {
1079
1080
- foreach( $answers as $answer ) {
1081
- if( $answer['poll_id'] == $poll['id'] ) {
1082
$answers_ordonate[$poll['id']][] = (array)$answer;
1083
}
1084
- if( $answer['poll_id'] > $poll['id'] ) {
1085
break;
1086
}
1087
1088
- foreach( $logs as $log ) {
1089
- if( $log['poll_id'] == $poll['id'] && $log['answer_id'] == $answer['id'] ) {
1090
- $logs_ordonate[$poll['id']][] = (array)$log;
1091
$logs_ordonate_details[$log['id']][] = $answer['answer'];
1092
}
1093
}
1094
- foreach( $answers_meta as $answer_meta ) {
1095
- if( $answer_meta['yop_poll_answer_id'] == $answer['id'] ) {
1096
$answer_meta_ordonate[$answer['id']][] = (array)$answer_meta;
1097
}
1098
}
1099
}
1100
1101
- foreach( $bans as $ban ) {
1102
- if( $ban['poll_id'] == $poll['id'] ) {
1103
$bans_ordonate[$poll['id']][] = (array)$ban;
1104
}
1105
- if( $ban['poll_id'] > $poll['id'] ) {
1106
break;
1107
}
1108
}
1109
1110
- foreach( $metas as $meta ) {
1111
- if( $meta['yop_poll_id'] == $poll['id'] ) {
1112
$metas_ordonate[$poll['id']][] = (array)$meta;
1113
}
1114
- if( $meta['yop_poll_id'] > $poll['id'] ) {
1115
break;
1116
}
1117
}
1118
1119
- foreach( $custom_fields as $custom_field ) {
1120
- if( $custom_field['poll_id'] == $poll['id'] ) {
1121
$custom_fields_ordonate[$poll['id']][] = (array)$custom_field;
1122
- if( $custom_field['poll_id'] > $poll['id'] ) {
1123
break;
1124
}
1125
1126
- foreach( $custom_votes as $custom_vote ) {
1127
- if( $custom_field['id'] == $custom_vote['custom_field_id'] ) {
1128
$custom_votes_fields_ordonate[$custom_field['id']][] = (array)$custom_vote;
1129
}
1130
}
@@ -1133,18 +1132,18 @@ NOWDOC;
1133
}
1134
1135
1136
- foreach( $polls as $poll ) {
1137
- $current_poll = new YOP_POLL_Poll_Model();
1138
- $current_poll->poll_author = $poll['poll_author'];
1139
- $current_poll->ID = $poll['id'];
1140
- $current_poll->poll_title = $poll['name'];
1141
- $current_poll->poll_name = $poll['name'];
1142
- $current_poll->poll_date = $poll['date_added'];
1143
$current_poll->poll_modified = $poll['last_modified'];
1144
- $current_poll->poll_status = $poll['status'];
1145
- $current_poll->poll_type = "poll";
1146
- $current_poll->poll_status = $poll['status'];
1147
- $current_poll->email_notifications_body='<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
1148
1149
<p>Vote Details:</p>
1150
@@ -1175,188 +1174,178 @@ NOWDOC;
1175
[/QUESTION]
1176
1177
<p><b>Vote ID:</b> <br />%VOTE_ID%</p>';
1178
- if( $poll['end_date'] <= "2038-01-18 23:59:59" ) {
1179
-
1180
- $current_poll->poll_end_date =convert_date ($poll['end_date'],'d-m-Y H:i:s',1 );
1181
1182
- }
1183
1184
- else {
1185
1186
$current_poll->poll_end_date = "01-01-2038 23:59:59";
1187
1188
}
1189
1190
- if( $poll['start_date'] <= "2038-01-18 23:59:59" ) {
1191
1192
- $current_poll->poll_start_date = convert_date($poll['start_date'],'d-m-Y H:i:s',1 );
1193
1194
- }
1195
-
1196
- else {
1197
1198
$current_poll->poll_start_date = "01-01-2038 23:59:59";
1199
1200
}
1201
$current_poll->poll_total_votes = $poll['total_votes'];
1202
- $question = new YOP_POLL_Question_Model();
1203
- $question->type = "text";
1204
- $question->question = $poll['question'];
1205
- $question->question_date = $current_poll->poll_date;
1206
- $question->question_author = $current_poll->poll_author;
1207
- $question->question_modified = $current_poll->poll_modified;
1208
- $question->question_status = $current_poll->poll_status;
1209
- $question->poll_order = 1;
1210
- $i = 0;
1211
-
1212
-
1213
-
1214
- foreach( $answers_ordonate[$poll['id']] as $answer_ordonate ) {
1215
-
1216
- if( $answer_ordonate['type'] == "other" ) {
1217
- $current_poll->allow_other_answers='yes';
1218
- $question->allow_other_answers= 'yes';
1219
}
1220
}
1221
- $q[] = $question;
1222
// yop_poll_dump($current_poll);
1223
$current_poll->questions = $q;
1224
- $current_poll->auto_generate_poll_page="no";
1225
- $current_poll_id = $current_poll->insert();
1226
- $current_poll_id =$current_poll->ID;
1227
// yop_poll_dump($current_poll->save())
1228
- $no_modif=0;
1229
- $no_modif2=0;
1230
- $current_poll_meta=$current_options;
1231
- if( isset( $metas_ordonate[$poll['id']] ) ) {
1232
- $poll_option = maybe_unserialize( $metas_ordonate[$poll['id']][0]['meta_value'] );
1233
- foreach( $current_options as $key => $value ) {
1234
- if( isset( $poll_option[$key] ) ) {
1235
1236
- if($key=='view_results_permissions'){
1237
1238
- list($g1,$d)=explode('-',$poll_option[$key]);
1239
- if($g1=="quest"){
1240
- $g1="guest";
1241
1242
}
1243
1244
- $current_poll_meta[$key] = array($g1,$d);
1245
- $no_modif=1;
1246
1247
- }
1248
- else
1249
- if($key=='vote_permisions'){
1250
- list($g1,$d)=explode('-',$poll_option['vote_permisions']);
1251
- if($g1=="quest"){
1252
- $g1="guest";
1253
1254
}
1255
- $no_modif2=1;
1256
- $current_poll_meta[$key] = array($g1,$d);
1257
- }
1258
- else
1259
$current_poll_meta[$key] = $poll_option[$key];
1260
1261
1262
} else
1263
- $current_poll_meta[$key]=$default[$key];
1264
}
1265
}
1266
- $current_poll_meta['view_results'] = array($poll_option['view_results'] );
1267
$current_poll_meta['sorting_results'] = $default['sorting_answers'];
1268
- if(!isset($poll_option['view_results_link'])){
1269
- $current_poll_meta['view_results_link']="yes";
1270
- }
1271
- else
1272
- $current_poll_meta['view_results_link'] = $poll_option['view_results_link'] ;
1273
-
1274
- if( $poll_option['view_results']=='custom-date')
1275
- $current_poll_meta['view_results_start_date'] =$poll_option['view_results_start_date'] ;
1276
- if(empty( $current_poll_meta['view_results'][0])) {
1277
$current_poll_meta['view_results'] = array('after');
1278
}
1279
- if($no_modif==0 ||empty($current_poll_meta['view_results'])){
1280
- $current_poll_meta['view_results_permissions'] = array( 'guest', 'registered' );
1281
1282
}
1283
1284
- if($no_modif2==0||empty($current_poll_meta['vote_permisions'])){
1285
- $current_poll_meta['vote_permisions'] = array( 'guest', 'registered' );
1286
}
1287
1288
- if( $poll_option['blocking_voters']=='cookie-ip')
1289
- $current_poll_meta['blocking_voters' ]=array("cookie",'ip');
1290
else {
1291
- if( $poll_option['blocking_voters']=='username')
1292
- $current_poll_meta['blocking_voters' ]=array("user_id");
1293
else
1294
- $current_poll_meta['blocking_voters' ]=array( 'dont-block' );
1295
- }
1296
- $current_poll_meta['facebook_share_after_vote']="no";
1297
- $current_poll_meta['show_google_share_button']="no";
1298
- $current_poll_meta['facebook_show_comments_widget'] ="no";
1299
- $current_poll_meta['facebook_share_description'] = __yop_poll( 'Just casted an YOP Poll vote on ' ) . get_bloginfo( 'name' );
1300
- if(isset($poll_option['show_in_archive']))
1301
- $current_poll_meta['show_poll_in_archive']=$poll_option['show_in_archive'] ;
1302
- if(isset($poll_option['schedule_reset_poll_date']))
1303
- $current_poll_meta['schedule_reset_poll_date']=$poll_option['schedule_reset_poll_date'] ;
1304
- if(isset($poll_option['template'])){
1305
- $current_poll_meta['template']=$templates_ids[ $poll_option['template']];
1306
- } else $current_poll_meta['template']=1;
1307
- if(isset($poll_option['widget_template'])){
1308
- $current_poll_meta['widget_template']=$templates_ids[ $poll_option['widget_template']];
1309
}
1310
- else $current_poll_meta['widget_template']=1;
1311
- if(isset($poll_option['widget_template']) && isset($poll_option['template'])&& $poll_option['template']!=$poll_option['widget_template']){
1312
- $current_poll_meta['use_the_same_template_for_widget'] ="no";
1313
}
1314
- if(isset($poll_option['view_total_answers_label'])){
1315
- $current_poll_meta['view_total_answers_label']=$default['view_total_answers_label'];
1316
}
1317
- if(isset($poll_option['answer_result_label'])){
1318
- $current_poll_meta['answer_result_label']=$default['answer_result_label'];
1319
}
1320
- if( $current_poll_meta['vote_permisions_anonymous']=="no"&& $current_poll_meta['vote_permisions_wordpress']=="no"){
1321
- $current_poll_meta['vote_permisions_anonymous']="yes";
1322
}
1323
- update_yop_poll_question_meta( $current_poll_id, 'options', $current_poll_meta);
1324
- update_yop_poll_meta( $current_poll_id, 'options', $current_poll_meta );
1325
- if($poll['show_in_archive'] =="yes"){
1326
- self::save_poll_order($current_poll_id,$poll['archive_order']);
1327
}
1328
1329
- if($default['sorting_answers']=="votes"){
1330
- $answers_ordonate[$poll['id']]=self::get_answers_order_by_votes($poll['id'],$default['sorting_answers_direction']);
1331
- }
1332
- if($default['sorting_answers']=="alphabetical"){
1333
- $answers_ordonate[$poll['id']]=self::get_answers_order_by_alph($poll['id'],$default['sorting_answers_direction']);
1334
}
1335
- foreach( $answers_ordonate[$poll['id']] as $answer_ordonate ) {
1336
- $ans = new YOP_POLL_Answer_Model();
1337
- $ans->answer = $answer_ordonate['answer'];
1338
- $ans->answer_author = $current_poll->poll_author;
1339
- $ans->answer_date = $current_poll->poll_date;
1340
$ans->answer_modified = $poll['last_modified'];
1341
- if( $answer_ordonate['type'] != "other" ) {
1342
$ans->type = "text";
1343
- }
1344
- else{
1345
- $current_poll->allow_other_answers = 'yes';
1346
- $question->allow_other_answers = 'yes';
1347
$ans->type = "other";
1348
}
1349
- $ans->answer_status = $answer['status'];
1350
- $ans->votes = $answer_ordonate['votes'];
1351
- $ans->question_order = $i ++;
1352
1353
- if( $answer_ordonate['type'] != "other" ) {
1354
$answersa[] = $ans;
1355
- if( isset( $answer_meta_ordonate[$answer_ordonate['id']] ) ) {
1356
- $answer_option = maybe_unserialize( $answer_meta_ordonate[$answer_ordonate['id']][0]['meta_value'] );
1357
$answer_options = $ans->options;
1358
- foreach( $ans->options as $key => &$value ) {
1359
- if( isset( $answer_option[$key] ) ) {
1360
$ans->$key = $answer_option[$key];
1361
}
1362
@@ -1364,87 +1353,88 @@ NOWDOC;
1364
$ans->options = $answer_options;
1365
}
1366
1367
- $question->addAnswer( $ans );
1368
1369
$question->save_answers();
1370
$answersids[$answer_ordonate['id']] = $ans->ID;
1371
}
1372
1373
}
1374
- if(!empty($custom_fields_ordonate[$poll['id']]))
1375
- foreach( $custom_fields_ordonate[$poll['id']] as $custom_ordonate ) {
1376
- $oldid = $custom_ordonate['id'];
1377
- // $question = $current_poll->questions;
1378
- $custom_ordonate['question_id'] = $current_poll_id;
1379
- $custom_ordonate['poll_id'] = $current_poll_id;
1380
- $newid = insert_custom_field_in_db( $custom_ordonate );
1381
- foreach( $custom_votes_fields_ordonate[$oldid] as $votes ) {
1382
- $votes['custom_field_id'] = $newid;
1383
- $votes['question_id'] = $current_poll_id;
1384
- $votes['poll_id'] = $current_poll_id;
1385
- $votes['id'] = insert_votes_custom_in_db( $votes );
1386
- $custom_field_vote[$poll['id']][] = $votes;
1387
}
1388
- }
1389
1390
- if(!empty($logs_ordonate[$poll['id']]))
1391
- foreach( $logs_ordonate[$poll['id']] as $log_ordonate ) {
1392
- $log['poll_id'] = $current_poll_id;
1393
- $log['vote_id'] = $log_ordonate['vote_id'];
1394
- $log['ip'] = $log_ordonate['ip'];
1395
- $log['user_id'] = $log_ordonate['user_id'];
1396
- $log['user_type'] = $log_ordonate['user_type'];
1397
- $log['vote_date'] = $log_ordonate['vote_date'];
1398
- $log['tr_id'] = $log_ordonate['tr_id'];
1399
- $vote_details[1]["q-" . $current_poll_id]['question'] = $poll['question'];
1400
- $vote_details[1]["q-" . $current_poll_id]['id'] = $current_poll_id;
1401
- $vote_details[1]["q-" . $current_poll_id]['a'][] = $answersids[$log_ordonate['answer_id']];
1402
- if($log_ordonate['other_answer_value']!=""&&isset($log_ordonate['other_answer_value'])){
1403
- $ans = new YOP_POLL_Answer_Model();
1404
- $ans->answer = $answer_ordonate['answer'];
1405
- $ans->answer_author = $current_poll->poll_author;
1406
- $ans->answer_date = $current_poll->poll_date;
1407
- $ans->answer_modified = $poll['last_modified'];
1408
- $ans->answer = $log_ordonate['other_answer_value'];
1409
- $ans->answer_status ='active';
1410
- $ans->votes = 1;
1411
- $ans->type = 'other';
1412
- $ans->question_order = $i ++;
1413
- $question->addAnswer( $ans );
1414
- $question->save_answers();
1415
- }
1416
- if(!empty($custom_field_vote[$poll['id']]))
1417
- foreach( $custom_field_vote[$poll['id']] as $vote ) {
1418
- if( $vote['vote_id'] == $log_ordonate['vote_id'] ) {
1419
- $vote_details[1]["q-" . $current_poll_id]['cf'][] = $vote['id'];
1420
}
1421
1422
}
1423
- foreach( $logs_ordonate_details[$log_ordonate['id']] as $a ) {
1424
- $vote_details[1]["q-" . $current_poll_id]['answers'][] = $a;
1425
- $log['vote_details'] = json_encode( $vote_details[1] );
1426
- $log['message'] = "Succes";
1427
- insert_result_in_db( $log );
1428
- insert_log_in_db( $log );
1429
- unset( $vote_details[1]["q-" . $current_poll_id]['answers'] );
1430
}
1431
- unset( $vote_details );
1432
- }
1433
- if(!empty($bans_ordonate[$poll['id']]))
1434
- foreach( $bans_ordonate[$poll['id']] as $ban_ordonate ) {
1435
- $ban = $ban_ordonate;
1436
- $ban['poll_id'] = $current_poll_id;
1437
- self::insert_ban_in_db( $ban );
1438
- }
1439
1440
1441
}
1442
1443
}
1444
1445
- public function insert_template_in_databease($template){
1446
global $wpdb;
1447
- $sql= $wpdb->query( $wpdb->prepare( "
1448
INSERT INTO " . $wpdb->yop_poll_templates . "
1449
SET
1450
template_author = %d,
@@ -1458,12 +1448,14 @@ NOWDOC;
1458
date_added = %s,
1459
last_modified = %s,
1460
status = %s
1461
- ", $template['template_author'], $template['name'], $template['before_vote_template'], $template['after_vote_template'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time( 'mysql' ), current_time( 'mysql' ), $template['status'] ) );
1462
return $GLOBALS['wpdb']->insert_id;
1463
}
1464
- private static function update_poll_template_in_database( $template ) {
1465
global $wpdb;
1466
- $sql = $wpdb->query( $wpdb->prepare( "
1467
UPDATE " . $wpdb->yop_poll_templates . "
1468
SET name = %s,
1469
before_vote_template = %s,
@@ -1475,145 +1467,164 @@ NOWDOC;
1475
last_modified = %s
1476
WHERE
1477
id = %d
1478
- ", $template['name'], $template['before_vote_template'], $template['after_vote_template'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time( 'mysql' ), $template['id'] ) );
1479
return $sql;
1480
}
1481
- public function yop_poll_get_polls_from_db() {
1482
global $wpdb;
1483
- $result = $wpdb->get_results(( "
1484
SELECT *
1485
FROM " . $wpdb->prefix . "yop_polls ORDER BY id ASC
1486
- " ), ARRAY_A );
1487
return $result;
1488
1489
}
1490
1491
- public function yop_poll_get_polls_meta_from_db() {
1492
global $wpdb;
1493
- $result = $wpdb->get_results( ( "
1494
SELECT *
1495
FROM " . $wpdb->prefix . "yop_pollmeta ORDER BY yop_poll_id ASC
1496
- " ), ARRAY_A );
1497
return $result;
1498
1499
}
1500
1501
- public function yop_poll_get_answers_meta_from_db() {
1502
global $wpdb;
1503
1504
- $result = $wpdb->get_results( ("
1505
SELECT *
1506
FROM " . $wpdb->prefix . "yop_poll_answermeta
1507
- " ), ARRAY_A );
1508
return $result;
1509
1510
}
1511
1512
- public function yop_poll_get_templates_from_db() {
1513
global $wpdb;
1514
- $result = $wpdb->get_results( ( "
1515
SELECT *
1516
FROM " . $wpdb->prefix . "yop_poll_templates
1517
- " ), ARRAY_A );
1518
return $result;
1519
}
1520
- public function yop_poll_get_templates_new_version_from_db() {
1521
global $wpdb;
1522
- $result = $wpdb->get_results( ( "
1523
SELECT *
1524
FROM " . $wpdb->yop_poll_templates
1525
- ), ARRAY_A );
1526
return $result;
1527
}
1528
1529
- public function yop_poll_get_custom_fields_from_db() {
1530
global $wpdb;
1531
- $result = $wpdb->get_results( ( "
1532
SELECT *
1533
FROM " . $wpdb->prefix . "yop_poll_custom_fields ORDER BY poll_id ASC
1534
- " ), ARRAY_A );
1535
return $result;
1536
}
1537
1538
- public function yop_poll_get_custom_fields_votes_from_db() {
1539
global $wpdb;
1540
- $result = $wpdb->get_results( ( "
1541
SELECT *
1542
FROM " . $wpdb->prefix . "yop_poll_votes_custom_fields
1543
- " ), ARRAY_A );
1544
return $result;
1545
}
1546
1547
- public function yop_poll_get_bans_from_db() {
1548
global $wpdb;
1549
- $result = $wpdb->get_results( ( "
1550
SELECT *
1551
FROM " . $wpdb->prefix . "yop_poll_bans ORDER BY poll_id ASC
1552
- " ), ARRAY_A );
1553
return $result;
1554
}
1555
- public function yop_poll_get_answers_from_db() {
1556
global $wpdb;
1557
- $result = $wpdb->get_results( ( "
1558
SELECT *
1559
FROM " . $wpdb->prefix . "yop_poll_answers ORDER BY poll_id ASC
1560
- " ), ARRAY_A );
1561
return $result;
1562
}
1563
- public function get_answers_order_by_votes($poll_id,$dir) {
1564
global $wpdb;
1565
- $result = $wpdb->get_results( $wpdb->prepare( "
1566
SELECT *
1567
FROM " . $wpdb->prefix . "yop_poll_answers WHERE poll_id=%d ORDER BY votes $dir
1568
- ",$poll_id ), ARRAY_A );
1569
return $result;
1570
}
1571
1572
- public function get_answers_order_by_alph($poll_id,$dir) {
1573
global $wpdb;
1574
- $result = $wpdb->get_results( $wpdb->prepare( "
1575
SELECT *
1576
FROM " . $wpdb->prefix . "yop_poll_answers WHERE poll_id=%d ORDER BY answer $dir
1577
- ",$poll_id ), ARRAY_A );
1578
return $result;
1579
}
1580
1581
- public function yop_poll_get_logs_from_db() {
1582
global $wpdb;
1583
- $result = $wpdb->get_results( ( "
1584
SELECT *
1585
FROM " . $wpdb->prefix . "yop_poll_logs
1586
- " ), ARRAY_A );
1587
return $result;
1588
}
1589
1590
- private static function insert_ban_in_db( $ban ) {
1591
global $wpdb;
1592
- $sql = $wpdb->query( $wpdb->prepare( "
1593
INSERT INTO $wpdb->yop_poll_bans
1594
( poll_id,type,value,period ,unit)
1595
VALUES(%d,%s,%s,%d,%s)
1596
- ", $ban['poll_id'], $ban['type'], $ban['value'], intval( $ban['period'] ), $ban['unit'] ) );
1597
- return $wpdb->get_results( $sql );
1598
}
1599
- private function save_poll_order( $poll, $poll_order ) {
1600
- $poll_archive_order = get_option( 'yop_poll_archive_order', array() );
1601
- if( $poll_archive_order == "" ) {
1602
$poll_archive_order = array();
1603
- }if( trim( $poll_order ) <= 0 ) {
1604
- $poll_order = 1;
1605
}
1606
- $key = array_search( $poll, $poll_archive_order );
1607
- if( $key !== false ) {
1608
- unset( $poll_archive_order[$key] );
1609
}
1610
- if( $poll_order > count( $poll_archive_order ) ) {
1611
- array_push( $poll_archive_order, $poll );
1612
}
1613
- else {
1614
- array_splice( $poll_archive_order, trim( $poll_order ) - 1, 0, array( $poll ) );
1615
}
1616
- update_option( 'yop_poll_archive_order', $poll_archive_order );
1617
}
1618
1619
}
1
<?php
2
3
+ class YOP_POLL_Maintenance
4
+ {
5
6
+ private function network_propagate($pfunction, $networkwide)
7
+ {
8
+ error_reporting(0);
9
+ if (function_exists('is_multisite') && is_multisite()) {
10
11
+ if ($networkwide) {
12
13
$old_blog = $GLOBALS['wpdb']->blogid;
14
15
+ $blogids = $GLOBALS['wpdb']->get_col("SELECT blog_id FROM {$GLOBALS['wpdb']->blogs}");
16
17
+ foreach ($blogids as $blog_id) {
18
19
+ switch_to_blog($blog_id);
20
21
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
22
+ $version = get_option("yop_poll_version");
23
24
/* if ( version_compare( $version, '4.9.2', '<=' ) &&isset($version)) {
25
yop_poll_dump(12);
30
} */
31
32
33
+ $poll_archive_page = get_page_by_path('yop-poll-archive', ARRAY_A);
34
35
+ if (!$poll_archive_page) {
36
37
+ $_p = array();
38
39
+ $_p['post_title'] = 'Yop Poll Archive';
40
41
+ $_p['post_content'] = "[yop_poll_archive]";
42
43
+ $_p['post_status'] = 'publish';
44
45
+ $_p['post_type'] = 'page';
46
47
$_p['comment_status'] = 'open';
48
49
+ $_p['ping_status'] = 'open';
50
51
+ $_p['post_category'] = array(1); // the default 'Uncategorised'
52
53
54
+ $poll_archive_page_id = wp_insert_post($_p);
55
56
57
+ } else {
58
59
$poll_archive_page_id = $poll_archive_page['ID'];
60
61
}
62
63
64
+ call_user_func(array($this, $pfunction), $networkwide);
65
66
+ $version = get_option("yop_poll_version");
67
68
69
+ $default_options = get_option('yop_poll_options');
70
71
+ $default_options['archive_url'] = get_permalink($poll_archive_page_id);
72
73
$default_options['yop_poll_archive_page_id'] = $poll_archive_page_id;
74
75
76
//addind default options
77
78
+ update_option('yop_poll_options', $default_options);
79
80
81
}
82
83
+ switch_to_blog($old_blog);
84
85
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
86
87
return;
88
89
}
90
}
91
92
+ $version = get_option("yop_poll_version");
93
94
/* if ( version_compare( $version, '4.9.2', '<=' ) &&isset($version)) {
95
yop_poll_dump(12);
101
} */
102
103
104
+ $poll_archive_page = get_page_by_path('yop-poll-archive', ARRAY_A);
105
106
+ if (!$poll_archive_page) {
107
108
+ $_p = array();
109
110
+ $_p['post_title'] = 'Yop Poll Archive';
111
112
+ $_p['post_content'] = "[yop_poll_archive]";
113
114
+ $_p['post_status'] = 'publish';
115
116
+ $_p['post_type'] = 'page';
117
118
$_p['comment_status'] = 'open';
119
120
+ $_p['ping_status'] = 'open';
121
122
+ $_p['post_category'] = array(1); // the default 'Uncategorised'
123
124
125
+ $poll_archive_page_id = wp_insert_post($_p);
126
127
128
+ } else {
129
130
$poll_archive_page_id = $poll_archive_page['ID'];
131
132
}
133
134
135
//addind default options
136
137
+ call_user_func(array($this, $pfunction), $networkwide);
138
139
140
+ $default_options = get_option('yop_poll_options');
141
142
+ $default_options['archive_url'] = get_permalink($poll_archive_page_id);
143
144
$default_options['yop_poll_archive_page_id'] = $poll_archive_page_id;
145
146
147
//addind default options
148
149
+ update_option('yop_poll_options', $default_options);
150
151
152
}
153
154
+ function propagate_activation($networkwide)
155
+ {
156
if (version_compare(phpversion(), '5.3', '<')) {
157
wp_die("Php version isn't high enough!");
158
}
159
160
+ $this->network_propagate('activate', $networkwide);
161
162
}
163
164
+ function propagate_deactivation($networkwide)
165
+ {
166
global $wpdb;
167
// $wpdb->query( "DROP TABLE `" . $wpdb->prefix . "yop_pollmeta`, `" . $wpdb->prefix . "yop_polls`, `" . $wpdb->prefix . "yop_poll_answermeta`, `" . $wpdb->prefix . "yop_poll_answers`, `" . $wpdb->prefix . "yop_poll_custom_fields`, `" . $wpdb->prefix . "yop_poll_logs`, `" . $wpdb->prefix . "yop_poll_voters`, `" . $wpdb->prefix . "yop_poll_bans`, `" . $wpdb->prefix . "yop_poll_templates`, `" . $wpdb->prefix . "yop_poll_votes_custom_fields`, `" . $wpdb->prefix . "yop_poll_facebook_users`" );
168
+ $this->network_propagate('deactivate', $networkwide);
169
}
170
+
171
+ public function some_function($x = 0, $current_options = array())
172
+ {
173
+ $installed_version = get_option("yop_poll_version");
174
global $wpdb;
175
176
+ if (version_compare($installed_version, '4.9.3', '<=') || $x == 1) {
177
if (!(version_compare(phpversion(), '5.3', '<'))) {
178
+ ini_set("memory_limit", "1024M");
179
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
180
+ require_once(YOP_POLL_INC . 'db_schema.php');
181
+ if (empty($current_options)) {
182
+ $current_options = get_option('yop_poll_options');
183
184
+ $default = get_option('yop_poll_options');
185
}
186
$capObj = YOP_POLL_Capabilities::get_instance();
187
$capObj->install_capabilities();
188
Yop_Poll_DbSchema::create_poll_database_tables();
189
+ $wpdb->query('ALTER TABLE `' . $wpdb->yop_polls . '` CHANGE `ID` `ID` INT( 11 ) NOT NULL ');
190
+ $this->install_default_options();
191
+
192
+ $new_options = array(
193
+
194
+ 'user_interface_type' => 'beginner',
195
+ 'is_default_answer' => $current_options['is_default_answer'],
196
+ 'poll_start_date' => current_time('mysql'),
197
+ 'poll_end_date' => '01-01-2038 23:59:59',
198
+ 'view_results' => array($current_options['view_results']),
199
+ 'view_results_start_date' => convert_date($current_options['view_results_start_date'], 'd-m-Y H:i:s', 1),
200
+ 'view_results_permissions' => array('guest', 'registered'),
201
+ 'view_results_type' => $current_options['view_results_type'],
202
+ 'answer_result_label' => $current_options['answer_result_label'],
203
+ 'vote_button_label' => $current_options['vote_button_label'],
204
+ 'template_width' => $current_options['template_width'],
205
+ 'widget_template_width' => $current_options['widget_template_width'],
206
+ 'view_results_link' => $current_options['view_results_link'],
207
+ 'view_results_link_label' => $current_options['view_results_link_label'],
208
+ 'view_back_to_vote_link' => $current_options['view_back_to_vote_link'],
209
+ 'view_back_to_vote_link_label' => $current_options['view_back_to_vote_link_label'],
210
+ 'view_total_votes' => $current_options['view_total_votes'],
211
+ 'view_total_votes_label' => $current_options['view_total_votes_label'],
212
+ 'view_total_answers' => $current_options['view_total_answers'],
213
+ 'view_total_answers_label' => $current_options['view_total_answers_label'],
214
+ 'message_after_vote' => $current_options['message_after_vote'],
215
+ 'vote_permisions' => array('guest', 'registered'),
216
+ 'vote_permisions_wordpress' => $current_options['vote_permisions_wordpress'],
217
+ 'vote_permisions_wordpress_label' => $current_options['vote_permisions_wordpress_label'],
218
+ 'vote_permisions_anonymous' => $current_options['vote_permisions_anonymous'],
219
+ 'vote_permisions_anonymous_label' => $current_options['vote_permisions_anonymous_label'],
220
+ 'blocking_voters' => array($current_options['blocking_voters']),
221
+ 'blocking_voters_interval_value' => $current_options['blocking_voters_interval_value'],
222
+ 'blocking_voters_interval_unit' => $current_options['blocking_voters_interval_unit'],
223
+ 'limit_number_of_votes_per_user' => $current_options['limit_number_of_votes_per_user'],
224
+ 'number_of_votes_per_user' => $current_options['number_of_votes_per_user'],
225
+ 'percentages_decimals' => $current_options['percentages_decimals'],
226
+ 'use_default_loading_image' => $current_options['use_default_loading_image'],
227
+ 'loading_image_url' => $current_options['loading_image_url'],
228
+ 'redirect_after_vote' => $current_options['redirect_after_vote'],
229
+ 'redirect_after_vote_url' => $current_options['redirect_after_vote_url'],
230
+ 'date_format' => 'UE',
231
+ 'view_poll_archive_link' => $current_options['view_poll_archive_link'],
232
+ 'auto_generate_poll_page' => $current_options['auto_generate_poll_page'],
233
+ 'has_auto_generate_poll_page' => $current_options['has_auto_generate_poll_page'],
234
+ 'use_captcha' => $current_options['use_captcha'],
235
+ 'send_email_notifications' => $current_options['send_email_notifications'],
236
+ 'allow_other_answers' => $current_options['allow_other_answers'],
237
+ 'other_answers_label' => $current_options['other_answers_label'],
238
+ 'is_default_other_answer' => $current_options['is_default_other_answer'],
239
+ 'add_other_answers_to_default_answers' => $current_options['add_other_answers_to_default_answers'],
240
+ 'display_other_answers_values' => $current_options['display_other_answers_values'],
241
+ 'allow_multiple_answers' => $current_options['allow_multiple_answers'],
242
+ 'allow_multiple_answers_number' => $current_options['allow_multiple_answers_number'],
243
+ 'allow_multiple_answers_min_number' => $current_options['allow_multiple_answers_min_number'],
244
+ 'display_answers' => $current_options['display_answers'],
245
+ 'display_answers_tabulated_cols' => $current_options['display_answers_tabulated_cols'],
246
+ 'sorting_results' => 'as_defined',
247
+ 'sorting_answers' => 'as_defined',
248
+ 'sorting_results_direction' => $current_options['sorting_results_direction'],
249
+ 'sorting_answers_direction' => $current_options['sorting_answers_direction'],
250
+ 'singular_answer_result_votes_number_label' => $current_options['singular_answer_result_votes_number_label'],
251
+ 'plural_answer_result_votes_number_label' => $current_options['plural_answer_result_votes_number_label'],
252
+ 'display_results' => $current_options['display_results'],
253
+ 'display_results_tabulated_cols' => $current_options['display_results_tabulated_cols'],
254
+ 'bar_background' => $current_options['bar_background'],
255
+ 'bar_height' => $current_options['bar_height'],
256
+ 'bar_border_color' => $current_options['bar_border_color'],
257
+ 'bar_border_width' => $current_options['bar_border_width'],
258
+ 'bar_border_style' => $current_options['bar_border_style'],
259
+ 'sorting_archive_polls' => 'votes',
260
+ 'sorting_archive_polls_rule' => 'asc',
261
+ 'archive_url' => $current_options['archive_url'],
262
+ 'archive_link_label' => $current_options['view_poll_archive_link_label'],
263
+ 'show_poll_in_archive' => $current_options['show_in_archive'],
264
+ 'poll_archive_order' => $current_options['archive_order'],
265
+ 'archive_polls_per_page' => $current_options['archive_polls_per_page'],
266
+ 'email_notifications_from_name' => $current_options['email_notifications_from_name'],
267
+ 'email_notifications_from_email' => $current_options['email_notifications_from_email'],
268
+ 'email_notifications_recipients' => $current_options['email_notifications_recipients'],
269
+ 'email_notifications_subject' => $current_options['email_notifications_subject'],
270
+ 'email_notifications_body' => '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
271
272
<p>Vote Details:</p>
273
298
[/QUESTION]
299
300
<p><b>Vote ID:</b> <br />%VOTE_ID%</p>',
301
+ 'schedule_reset_poll_stats' => $current_options['schedule_reset_poll_stats'],
302
+ 'schedule_reset_poll_date' => current_time('mysql'),
303
+ 'schedule_reset_poll_recurring_value' => $current_options['schedule_reset_poll_recurring_value'],
304
+ 'schedule_reset_poll_recurring_unit' => $current_options['schedule_reset_poll_recurring_unit'],
305
+ 'singular_answer_result_votes_number_label' => __yop_poll("vote"),
306
+ 'plural_answer_result_votes_number_label' => __yop_poll("votes"),
307
+ 'start_scheduler' => $current_options['start_scheduler'],
308
+ 'use_the_same_template_for_widget' => 'yes',
309
+ 'vote_permisions_facebook' => 'no',
310
311
+ 'vote_permisions_facebook_label' => __yop_poll('Vote as Facebook User'),
312
313
+ 'facebook_share_after_vote' => 'no',
314
315
+ 'facebook_share_description' => __yop_poll('Just casted an YOP Poll vote on ') . get_bloginfo('name'),
316
317
+ 'vote_permisions_google' => 'no',
318
319
+ 'vote_permisions_google_label' => __yop_poll('Vote as G+ User'),
320
321
+ 'show_google_share_button' => 'no',
322
+ 'google_integration' => 'no',
323
+ 'facebook_integration' => 'no',
324
+ 'facebook_show_comments_widget' => "no"
325
// 'view_total_answers_label' => __yop_poll( 'Poll total answers: %POLL-TOTAL-ANSWERS%' ),
326
327
);
328
+ if ($current_options['blocking_voters'] == 'cookie-ip')
329
+ $new_options['blocking_voters'] = array("cookie", 'ip');
330
+ else {
331
+ if ($current_options['blocking_voters'] == 'username')
332
+ $new_options['blocking_voters'] = array('user_id');
333
}
334
+ list($g1, $d) = explode('-', $current_options['view_results_permissions']);
335
+ $new_options['view_results_permissions'] = array($g1, $d);
336
+ list($g1, $d) = explode('-', $current_options['view_results_link']);
337
+ $new_options['view_results_link'] = array($g1, $d);
338
+ update_option('yop_poll_options', $new_options);
339
+ update_option("yop_poll_version", YOP_POLL_VERSION);
340
YOP_POLL_Maintenance::activation_hook($default);
341
+ $wpdb->query('ALTER TABLE `' . $wpdb->yop_polls . '` CHANGE `ID` `ID` INT( 11 ) NOT NULL AUTO_INCREMENT ');
342
343
}
344
}
345
+ $installed_version = get_option("yop_poll_version");
346
347
+ if (version_compare($installed_version, '5.2', '<=')) {
348
ini_set('max_execution_time', 700);
349
+ ini_set("memory_limit", "512M");
350
+ $default_poll_options = get_option('yop_poll_options');
351
+ $default_poll_options['email_notifications_body'] = '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
352
353
<p>Vote Details:</p>
354
379
[/QUESTION]
380
381
<p><b>Vote ID:</b> <br />%VOTE_ID%</p>';
382
+ update_option('yop_poll_options', $default_poll_options);
383
+ $templates = self::yop_poll_get_templates_new_version_from_db();
384
+ foreach ($templates as $template) {
385
+ $template['js'] = <<<NOWDOC
386
function stripBorder_%POLL-ID%(object) {
387
object.each(function() {
388
if( parseInt(jQuery(this).width() ) > 0) {
491
NOWDOC;
492
self::update_poll_template_in_database(($template));
493
}
494
+ $polls = self::yop_poll_get_polls_for_body_mail_update();
495
+ foreach ($polls as $poll) {
496
+ $current = new YOP_POLL_Poll_Model($poll['ID']);
497
+ $current->email_notifications_body = '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
498
499
<p>Vote Details:</p>
500
528
$current->save();
529
530
}
531
+ update_option("yop_poll_version", YOP_POLL_VERSION);
532
}
533
+ $installed_version = get_option("yop_poll_version");
534
+ if (version_compare($installed_version, '5.3', '<=')) {
535
+ update_option("yop_poll_version", YOP_POLL_VERSION);
536
}
537
+ $installed_version = get_option("yop_poll_version");
538
+ if (version_compare($installed_version, '5.5', '<=')) {
539
+ update_option("yop_poll_version", YOP_POLL_VERSION);
540
}
541
+ $installed_version = get_option("yop_poll_version");
542
543
+ if (version_compare($installed_version, '5.6', '<=')) {
544
global $wpdb;
545
+ update_option("yop_poll_version", YOP_POLL_VERSION);
546
+ $default_poll_options = get_option('yop_poll_options');
547
+ $default_poll_options['show_results_in'] = "bar";
548
+ update_option('yop_poll_options', $default_poll_options);
549
550
+ $wpdb->query('ALTER TABLE `' . $wpdb->yop_poll_templates . '` ADD `after_vote_template_chart` text');
551
+ update_option("yop_poll_version", '5.7');
552
553
}
554
+ if (version_compare($installed_version, '5.7', '<=')) {
555
global $wpdb;
556
+ update_option("yop_poll_version", YOP_POLL_VERSION);
557
558
+ $templates = self::yop_poll_get_templates_new_version_from_db();
559
+ foreach ($templates as $template) {
560
+ $template['js'] = <<<NOWDOC
561
function stripBorder_%POLL-ID%(object) {
562
object.each(function() {
563
if( parseInt(jQuery(this).width() ) > 0) {
712
713
};
714
NOWDOC;
715
+ $template['after_vote_template_chart'] = <<<NOWDOC
716
[QUESTION_CONTAINER]
717
<div id = "yop-poll-question-container-%POLL-ID%-%QUESTION-ID%" class = "yop-poll-question-container-%POLL-ID%">
718
<div id = "yop-poll-question-%POLL-ID%-%QUESTION-ID%"
735
NOWDOC;
736
self::update_poll_template_in_database2($template);
737
}
738
+ update_option("yop_poll_version", '5.7.1');
739
740
}
741
+ if (version_compare($installed_version, '5.7.1', '<=')) {
742
global $wpdb;
743
+ update_option("yop_poll_version", '5.7.2');
744
}
745
+ if (version_compare($installed_version, '5.7.2', '<=')) {
746
global $wpdb;
747
+ update_option("yop_poll_version", '5.7.3');
748
}
749
+ if (version_compare($installed_version, '5.7.3', '<=')) {
750
global $wpdb;
751
+ update_option("yop_poll_version", '5.7.4');
752
+ }
753
+ if (version_compare($installed_version, '5.7.4', '<=')) {
754
+ global $wpdb;
755
+ update_option("yop_poll_version", '5.7.5');
756
}
757
}
758
+
759
+ private static function update_poll_template_in_database2($template)
760
+ {
761
global $wpdb;
762
+ $sql = $wpdb->query($wpdb->prepare("
763
UPDATE " . $wpdb->yop_poll_templates . "
764
SET name = %s,
765
before_vote_template = %s,
772
last_modified = %s
773
WHERE
774
id = %d
775
+ ", $template['name'], $template['before_vote_template'], $template['after_vote_template'], $template['after_vote_template_chart'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time('mysql'), $template['id']));
776
return $sql;
777
}
778
+
779
+ public function yop_poll_get_polls_for_body_mail_update()
780
+ {
781
global $wpdb;
782
+ $result = $wpdb->get_results(("
783
SELECT ID
784
+ FROM " . $wpdb->yop_polls . " ORDER BY ID ASC
785
+ "), ARRAY_A);
786
return $result;
787
}
788
+
789
+ private function install_default_options()
790
+ {
791
+ $default_poll_options = get_option('yop_poll_options');
792
793
$default_poll_options['is_default_answer'] = 'no';
794
+ $default_poll_options['poll_start_date'] = current_time('mysql');
795
+ $default_poll_options['poll_end_date'] = '01-01-2038 23:59:59';
796
797
+ update_option('yop_poll_options', $default_poll_options);
798
}
799
800
+ private function uninstall_default_options()
801
+ {
802
// delete_option( "yop_poll_version" );
803
// delete_option( "yop_poll_options" );
804
}
805
806
+ public function activate($networkwide)
807
+ {
808
+ if (!current_user_can('activate_plugins')) {
809
+ $error = new WP_Error ('Wordpress_version_error', __yop_poll('You need permissions to activate this plugin'), __yop_poll('Error: Wordpress Activation Permissions Problem'));
810
}
811
812
+ if (!version_compare($GLOBALS['wp_version'], YOP_POLL_WP_VERSION, '>=')) {
813
+ $error = new WP_Error ('Wordpress_version_error', sprintf(__yop_poll('You need at least Wordpress version %s to use this plugin'), YOP_POLL_WP_VERSION), __yop_poll('Error: Wordpress Version Problem'));
814
+ $error = new WP_Error ('Wordpress_version_error', sprintf(__yop_poll('You need at least Wordpress version %s to use this plugin'), YOP_POLL_WP_VERSION), __yop_poll('Error: Wordpress Version Problem'));
815
}
816
817
+ if (isset ($error) && is_wp_error($error)) {
818
+ wp_die($error->get_error_message(), $error->get_error_data());
819
}
820
821
822
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
823
+ require_once(YOP_POLL_INC . 'db_schema.php');
824
$this->install_default_options();
825
$capObj = YOP_POLL_Capabilities::get_instance();
826
$capObj->install_capabilities();
827
Yop_Poll_DbSchema::install_database();
828
}
829
830
+ public function deactivatedelete($networkwide)
831
+ {
832
+ require_once(YOP_POLL_INC . 'db_schema.php');
833
Yop_Poll_DbSchema::delete_database_tables();
834
$capObj = YOP_POLL_Capabilities::get_instance();
835
$capObj->uninstall_capabilities();
836
$this->uninstall_default_options();
837
}
838
839
+ function new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta)
840
+ {
841
+ if (!function_exists('is_plugin_active_for_network')) {
842
+ require_once(ABSPATH . '/wp-admin/includes/plugin.php');
843
}
844
+ if (is_plugin_active_for_network(YOP_POLL_SHORT_PLUGIN_FILE)) {
845
$old_blog = $GLOBALS['wpdb']->blogid;
846
+ switch_to_blog($blog_id);
847
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
848
+ $this->activate(null);
849
+ switch_to_blog($old_blog);
850
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
851
}
852
}
853
854
+ function delete_blog($blog_id)
855
+ {
856
$old_blog = $GLOBALS['wpdb']->blogid;
857
+ switch_to_blog($blog_id);
858
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
859
+ $this->deactivatedelete(null);
860
+ require_once(YOP_POLL_INC . 'db_schema.php');
861
// Yop_Poll_DbSchema::delete_database_tables();
862
$capObj = YOP_POLL_Capabilities::get_instance();
863
$capObj->uninstall_capabilities();
864
$this->uninstall_default_options();
865
+ switch_to_blog($old_blog);
866
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
867
}
868
869
+ function update()
870
+ {
871
}
872
873
+ public function activation_hook($default)
874
+ {
875
ini_set('max_execution_time', 700);
876
+ $current_options = get_option('yop_poll_options');
877
+ $polls = self::yop_poll_get_polls_from_db();
878
+ $answers = self::yop_poll_get_answers_from_db();
879
+ $logs = self::yop_poll_get_logs_from_db();
880
+ $bans = self::yop_poll_get_bans_from_db();
881
$custom_fields = self::yop_poll_get_custom_fields_from_db();
882
+ $custom_votes = self::yop_poll_get_custom_fields_votes_from_db();
883
+ $metas = self::yop_poll_get_polls_meta_from_db();
884
+ $answers_meta = self::yop_poll_get_answers_meta_from_db();
885
+ $templates = self::yop_poll_get_templates_from_db();
886
+ foreach ($templates as $template) {
887
+ $template['before_vote_template'] = "[QUESTION_CONTAINER]" . $template['before_vote_template'];
888
+ $template['before_vote_template'] = str_replace('%POLL-ANSWER-LABEL%', '%POLL-ANSWER-LABEL% [ANSWER_RESULT_CONTAINER]', $template['before_vote_template']);
889
+ $template['before_vote_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['before_vote_template']);
890
+ $template['before_vote_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['before_vote_template']);
891
+ $template['after_vote_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['after_vote_template']);
892
+ $template['after_vote_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['after_vote_template']);
893
+ $template['after_end_date_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['after_end_date_template']);
894
+ $template['after_end_date_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['after_end_date_template']);
895
+ $template['before_vote_template'] = preg_replace('/%POLL-ANSWER-RESULT-BAR%/', '%POLL-ANSWER-RESULT-BAR% [/ANSWER_RESULT_CONTAINER]', $template['before_vote_template'], 1);
896
$find = '[/ANSWER_RESULT_CONTAINER]';
897
$replace = '';
898
// $template['before_vote_template']= preg_replace(strrev("/$find/"),strrev($replace),strrev( $template['before_vote_template']),1);
899
+ $template['after_vote_template'] = "[QUESTION_CONTAINER]" . $template['after_vote_template'];
900
+ $template['after_end_date_template'] = "[QUESTION_CONTAINER]" . $template['after_end_date_template'];
901
/* if(strpos($template['before_vote_template'],"[CAPTCHA_CONTAINER]"))
902
$template['before_vote_template']=str_replace('[CAPTCHA_CONTAINER]','[/QUESTION_CONTAINER][CAPTCHA_CONTAINER]',$template['before_vote_template']);
903
else{
904
$template['before_vote_template']=str_replace('<div id="yop-poll-vote-%POLL-ID%" class="yop-poll-footer">','[/QUESTION_CONTAINER]<div id="yop-poll-vote-%POLL-ID%" class="yop-poll-footer">',$template['before_vote_template']);
905
} */
906
+ $template['before_vote_template'] = $template['before_vote_template'] . '[/QUESTION_CONTAINER]';
907
+ if (strpos($template['before_vote_template'], "%POLL-QUESTION%") && strpos($template['before_vote_template'], '%POLL-NAME%')) {
908
+ $template['before_vote_template'] = str_replace('%POLL-QUESTION%', '', $template['before_vote_template']);
909
+ $template['before_vote_template'] = str_replace('%POLL-NAME%', '%POLL-QUESTION%', $template['before_vote_template']);
910
}
911
+ if (strpos($template['after_vote_template'], "%POLL-QUESTION%") && strpos($template['after_vote_template'], '%POLL-NAME%')) {
912
+ $template['after_vote_template'] = str_replace('%POLL-QUESTION%', '', $template['after_vote_template']);
913
+ $template['after_vote_template'] = str_replace('%POLL-NAME%', '%POLL-QUESTION%', $template['after_vote_template']);
914
}
915
+ $template['after_vote_template'] = $template['after_vote_template'] . '[/QUESTION_CONTAINER]';
916
+ $template['after_end_date_template'] = $template['after_end_date_template'] . '[/QUESTION_CONTAINER]';
917
+ $template['js'] = <<<NOWDOC
918
function stripBorder_%POLL-ID%(object) {
919
object.each(function() {
920
if( parseInt(jQuery(this).width() ) > 0) {
1070
};
1071
1072
NOWDOC;
1073
+ $template['js'] = addslashes($template['js']);
1074
+ $templates_ids[$template['id']] = self::insert_template_in_databease(($template));
1075
}
1076
1077
+ foreach ($polls as $poll) {
1078
1079
+ foreach ($answers as $answer) {
1080
+ if ($answer['poll_id'] == $poll['id']) {
1081
$answers_ordonate[$poll['id']][] = (array)$answer;
1082
}
1083
+ if ($answer['poll_id'] > $poll['id']) {
1084
break;
1085
}
1086
1087
+ foreach ($logs as $log) {
1088
+ if ($log['poll_id'] == $poll['id'] && $log['answer_id'] == $answer['id']) {
1089
+ $logs_ordonate[$poll['id']][] = (array)$log;
1090
$logs_ordonate_details[$log['id']][] = $answer['answer'];
1091
}
1092
}
1093
+ foreach ($answers_meta as $answer_meta) {
1094
+ if ($answer_meta['yop_poll_answer_id'] == $answer['id']) {
1095
$answer_meta_ordonate[$answer['id']][] = (array)$answer_meta;
1096
}
1097
}
1098
}
1099
1100
+ foreach ($bans as $ban) {
1101
+ if ($ban['poll_id'] == $poll['id']) {
1102
$bans_ordonate[$poll['id']][] = (array)$ban;
1103
}
1104
+ if ($ban['poll_id'] > $poll['id']) {
1105
break;
1106
}
1107
}
1108
1109
+ foreach ($metas as $meta) {
1110
+ if ($meta['yop_poll_id'] == $poll['id']) {
1111
$metas_ordonate[$poll['id']][] = (array)$meta;
1112
}
1113
+ if ($meta['yop_poll_id'] > $poll['id']) {
1114
break;
1115
}
1116
}
1117
1118
+ foreach ($custom_fields as $custom_field) {
1119
+ if ($custom_field['poll_id'] == $poll['id']) {
1120
$custom_fields_ordonate[$poll['id']][] = (array)$custom_field;
1121
+ if ($custom_field['poll_id'] > $poll['id']) {
1122
break;
1123
}
1124
1125
+ foreach ($custom_votes as $custom_vote) {
1126
+ if ($custom_field['id'] == $custom_vote['custom_field_id']) {
1127
$custom_votes_fields_ordonate[$custom_field['id']][] = (array)$custom_vote;
1128
}
1129
}
1132
}
1133
1134
1135
+ foreach ($polls as $poll) {
1136
+ $current_poll = new YOP_POLL_Poll_Model();
1137
+ $current_poll->poll_author = $poll['poll_author'];
1138
+ $current_poll->ID = $poll['id'];
1139
+ $current_poll->poll_title = $poll['name'];
1140
+ $current_poll->poll_name = $poll['name'];
1141
+ $current_poll->poll_date = $poll['date_added'];
1142
$current_poll->poll_modified = $poll['last_modified'];
1143
+ $current_poll->poll_status = $poll['status'];
1144
+ $current_poll->poll_type = "poll";
1145
+ $current_poll->poll_status = $poll['status'];
1146
+ $current_poll->email_notifications_body = '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
1147
1148
<p>Vote Details:</p>
1149
1174
[/QUESTION]
1175
1176
<p><b>Vote ID:</b> <br />%VOTE_ID%</p>';
1177
+ if ($poll['end_date'] <= "2038-01-18 23:59:59") {
1178
1179
+ $current_poll->poll_end_date = convert_date($poll['end_date'], 'd-m-Y H:i:s', 1);
1180
1181
+ } else {
1182
1183
$current_poll->poll_end_date = "01-01-2038 23:59:59";
1184
1185
}
1186
1187
+ if ($poll['start_date'] <= "2038-01-18 23:59:59") {
1188
1189
+ $current_poll->poll_start_date = convert_date($poll['start_date'], 'd-m-Y H:i:s', 1);
1190
1191
+ } else {
1192
1193
$current_poll->poll_start_date = "01-01-2038 23:59:59";
1194
1195
}
1196
$current_poll->poll_total_votes = $poll['total_votes'];
1197
+ $question = new YOP_POLL_Question_Model();
1198
+ $question->type = "text";
1199
+ $question->question = $poll['question'];
1200
+ $question->question_date = $current_poll->poll_date;
1201
+ $question->question_author = $current_poll->poll_author;
1202
+ $question->question_modified = $current_poll->poll_modified;
1203
+ $question->question_status = $current_poll->poll_status;
1204
+ $question->poll_order = 1;
1205
+ $i = 0;
1206
+
1207
+
1208
+ foreach ($answers_ordonate[$poll['id']] as $answer_ordonate) {
1209
+
1210
+ if ($answer_ordonate['type'] == "other") {
1211
+ $current_poll->allow_other_answers = 'yes';
1212
+ $question->allow_other_answers = 'yes';
1213
}
1214
}
1215
+ $q[] = $question;
1216
// yop_poll_dump($current_poll);
1217
$current_poll->questions = $q;
1218
+ $current_poll->auto_generate_poll_page = "no";
1219
+ $current_poll_id = $current_poll->insert();
1220
+ $current_poll_id = $current_poll->ID;
1221
// yop_poll_dump($current_poll->save())
1222
+ $no_modif = 0;
1223
+ $no_modif2 = 0;
1224
+ $current_poll_meta = $current_options;
1225
+ if (isset($metas_ordonate[$poll['id']])) {
1226
+ $poll_option = maybe_unserialize($metas_ordonate[$poll['id']][0]['meta_value']);
1227
+ foreach ($current_options as $key => $value) {
1228
+ if (isset($poll_option[$key])) {
1229
1230
+ if ($key == 'view_results_permissions') {
1231
1232
+ list($g1, $d) = explode('-', $poll_option[$key]);
1233
+ if ($g1 == "quest") {
1234
+ $g1 = "guest";
1235
1236
}
1237
1238
+ $current_poll_meta[$key] = array($g1, $d);
1239
+ $no_modif = 1;
1240
1241
+ } else
1242
+ if ($key == 'vote_permisions') {
1243
+ list($g1, $d) = explode('-', $poll_option['vote_permisions']);
1244
+ if ($g1 == "quest") {
1245
+ $g1 = "guest";
1246
1247
}
1248
+ $no_modif2 = 1;
1249
+ $current_poll_meta[$key] = array($g1, $d);
1250
+ } else
1251
$current_poll_meta[$key] = $poll_option[$key];
1252
1253
1254
} else
1255
+ $current_poll_meta[$key] = $default[$key];
1256
}
1257
}
1258
+ $current_poll_meta['view_results'] = array($poll_option['view_results']);
1259
$current_poll_meta['sorting_results'] = $default['sorting_answers'];
1260
+ if (!isset($poll_option['view_results_link'])) {
1261
+ $current_poll_meta['view_results_link'] = "yes";
1262
+ } else
1263
+ $current_poll_meta['view_results_link'] = $poll_option['view_results_link'];
1264
+
1265
+ if ($poll_option['view_results'] == 'custom-date')
1266
+ $current_poll_meta['view_results_start_date'] = $poll_option['view_results_start_date'];
1267
+ if (empty($current_poll_meta['view_results'][0])) {
1268
$current_poll_meta['view_results'] = array('after');
1269
}
1270
+ if ($no_modif == 0 || empty($current_poll_meta['view_results'])) {
1271
+ $current_poll_meta['view_results_permissions'] = array('guest', 'registered');
1272
1273
}
1274
1275
+ if ($no_modif2 == 0 || empty($current_poll_meta['vote_permisions'])) {
1276
+ $current_poll_meta['vote_permisions'] = array('guest', 'registered');
1277
}
1278
1279
+ if ($poll_option['blocking_voters'] == 'cookie-ip')
1280
+ $current_poll_meta['blocking_voters'] = array("cookie", 'ip');
1281
else {
1282
+ if ($poll_option['blocking_voters'] == 'username')
1283
+ $current_poll_meta['blocking_voters'] = array("user_id");
1284
else
1285
+ $current_poll_meta['blocking_voters'] = array('dont-block');
1286
}
1287
+ $current_poll_meta['facebook_share_after_vote'] = "no";
1288
+ $current_poll_meta['show_google_share_button'] = "no";
1289
+ $current_poll_meta['facebook_show_comments_widget'] = "no";
1290
+ $current_poll_meta['facebook_share_description'] = __yop_poll('Just casted an YOP Poll vote on ') . get_bloginfo('name');
1291
+ if (isset($poll_option['show_in_archive']))
1292
+ $current_poll_meta['show_poll_in_archive'] = $poll_option['show_in_archive'];
1293
+ if (isset($poll_option['schedule_reset_poll_date']))
1294
+ $current_poll_meta['schedule_reset_poll_date'] = $poll_option['schedule_reset_poll_date'];
1295
+ if (isset($poll_option['template'])) {
1296
+ $current_poll_meta['template'] = $templates_ids[$poll_option['template']];
1297
+ } else $current_poll_meta['template'] = 1;
1298
+ if (isset($poll_option['widget_template'])) {
1299
+ $current_poll_meta['widget_template'] = $templates_ids[$poll_option['widget_template']];
1300
+ } else $current_poll_meta['widget_template'] = 1;
1301
+ if (isset($poll_option['widget_template']) && isset($poll_option['template']) && $poll_option['template'] != $poll_option['widget_template']) {
1302
+ $current_poll_meta['use_the_same_template_for_widget'] = "no";
1303
}
1304
+ if (isset($poll_option['view_total_answers_label'])) {
1305
+ $current_poll_meta['view_total_answers_label'] = $default['view_total_answers_label'];
1306
}
1307
+ if (isset($poll_option['answer_result_label'])) {
1308
+ $current_poll_meta['answer_result_label'] = $default['answer_result_label'];
1309
}
1310
+ if ($current_poll_meta['vote_permisions_anonymous'] == "no" && $current_poll_meta['vote_permisions_wordpress'] == "no") {
1311
+ $current_poll_meta['vote_permisions_anonymous'] = "yes";
1312
}
1313
+ update_yop_poll_question_meta($current_poll_id, 'options', $current_poll_meta);
1314
+ update_yop_poll_meta($current_poll_id, 'options', $current_poll_meta);
1315
+ if ($poll['show_in_archive'] == "yes") {
1316
+ self::save_poll_order($current_poll_id, $poll['archive_order']);
1317
}
1318
1319
+ if ($default['sorting_answers'] == "votes") {
1320
+ $answers_ordonate[$poll['id']] = self::get_answers_order_by_votes($poll['id'], $default['sorting_answers_direction']);
1321
+ }
1322
+ if ($default['sorting_answers'] == "alphabetical") {
1323
+ $answers_ordonate[$poll['id']] = self::get_answers_order_by_alph($poll['id'], $default['sorting_answers_direction']);
1324
}
1325
+ foreach ($answers_ordonate[$poll['id']] as $answer_ordonate) {
1326
+ $ans = new YOP_POLL_Answer_Model();
1327
+ $ans->answer = $answer_ordonate['answer'];
1328
+ $ans->answer_author = $current_poll->poll_author;
1329
+ $ans->answer_date = $current_poll->poll_date;
1330
$ans->answer_modified = $poll['last_modified'];
1331
+ if ($answer_ordonate['type'] != "other") {
1332
$ans->type = "text";
1333
+ } else {
1334
+ $current_poll->allow_other_answers = 'yes';
1335
+ $question->allow_other_answers = 'yes';
1336
$ans->type = "other";
1337
}
1338
+ $ans->answer_status = $answer['status'];
1339
+ $ans->votes = $answer_ordonate['votes'];
1340
+ $ans->question_order = $i++;
1341
1342
+ if ($answer_ordonate['type'] != "other") {
1343
$answersa[] = $ans;
1344
+ if (isset($answer_meta_ordonate[$answer_ordonate['id']])) {
1345
+ $answer_option = maybe_unserialize($answer_meta_ordonate[$answer_ordonate['id']][0]['meta_value']);
1346
$answer_options = $ans->options;
1347
+ foreach ($ans->options as $key => &$value) {
1348
+ if (isset($answer_option[$key])) {
1349
$ans->$key = $answer_option[$key];
1350
}
1351
1353
$ans->options = $answer_options;
1354
}
1355
1356
+ $question->addAnswer($ans);
1357
1358
$question->save_answers();
1359
$answersids[$answer_ordonate['id']] = $ans->ID;
1360
}
1361
1362
}
1363
+ if (!empty($custom_fields_ordonate[$poll['id']]))
1364
+ foreach ($custom_fields_ordonate[$poll['id']] as $custom_ordonate) {
1365
+ $oldid = $custom_ordonate['id'];
1366
+ // $question = $current_poll->questions;
1367
+ $custom_ordonate['question_id'] = $current_poll_id;
1368
+ $custom_ordonate['poll_id'] = $current_poll_id;
1369
+ $newid = insert_custom_field_in_db($custom_ordonate);
1370
+ foreach ($custom_votes_fields_ordonate[$oldid] as $votes) {
1371
+ $votes['custom_field_id'] = $newid;
1372
+ $votes['question_id'] = $current_poll_id;
1373
+ $votes['poll_id'] = $current_poll_id;
1374
+ $votes['id'] = insert_votes_custom_in_db($votes);
1375
+ $custom_field_vote[$poll['id']][] = $votes;
1376
+ }
1377
}
1378
1379
+ if (!empty($logs_ordonate[$poll['id']]))
1380
+ foreach ($logs_ordonate[$poll['id']] as $log_ordonate) {
1381
+ $log['poll_id'] = $current_poll_id;
1382
+ $log['vote_id'] = $log_ordonate['vote_id'];
1383
+ $log['ip'] = $log_ordonate['ip'];
1384
+ $log['user_id'] = $log_ordonate['user_id'];
1385
+ $log['user_type'] = $log_ordonate['user_type'];
1386
+ $log['vote_date'] = $log_ordonate['vote_date'];
1387
+ $log['tr_id'] = $log_ordonate['tr_id'];
1388
+ $vote_details[1]["q-" . $current_poll_id]['question'] = $poll['question'];
1389
+ $vote_details[1]["q-" . $current_poll_id]['id'] = $current_poll_id;
1390
+ $vote_details[1]["q-" . $current_poll_id]['a'][] = $answersids[$log_ordonate['answer_id']];
1391
+ if ($log_ordonate['other_answer_value'] != "" && isset($log_ordonate['other_answer_value'])) {
1392
+ $ans = new YOP_POLL_Answer_Model();
1393
+ $ans->answer = $answer_ordonate['answer'];
1394
+ $ans->answer_author = $current_poll->poll_author;
1395
+ $ans->answer_date = $current_poll->poll_date;
1396
+ $ans->answer_modified = $poll['last_modified'];
1397
+ $ans->answer = $log_ordonate['other_answer_value'];
1398
+ $ans->answer_status = 'active';
1399
+ $ans->votes = 1;
1400
+ $ans->type = 'other';
1401
+ $ans->question_order = $i++;
1402
+ $question->addAnswer($ans);
1403
+ $question->save_answers();
1404
}
1405
+ if (!empty($custom_field_vote[$poll['id']]))
1406
+ foreach ($custom_field_vote[$poll['id']] as $vote) {
1407
+ if ($vote['vote_id'] == $log_ordonate['vote_id']) {
1408
+ $vote_details[1]["q-" . $current_poll_id]['cf'][] = $vote['id'];
1409
+ }
1410
1411
+ }
1412
+ foreach ($logs_ordonate_details[$log_ordonate['id']] as $a) {
1413
+ $vote_details[1]["q-" . $current_poll_id]['answers'][] = $a;
1414
+ $log['vote_details'] = json_encode($vote_details[1]);
1415
+ $log['message'] = "Succes";
1416
+ insert_result_in_db($log);
1417
+ insert_log_in_db($log);
1418
+ unset($vote_details[1]["q-" . $current_poll_id]['answers']);
1419
+ }
1420
+ unset($vote_details);
1421
}
1422
+ if (!empty($bans_ordonate[$poll['id']]))
1423
+ foreach ($bans_ordonate[$poll['id']] as $ban_ordonate) {
1424
+ $ban = $ban_ordonate;
1425
+ $ban['poll_id'] = $current_poll_id;
1426
+ self::insert_ban_in_db($ban);
1427
}
1428
1429
1430
}
1431
1432
}
1433
1434
+ public function insert_template_in_databease($template)
1435
+ {
1436
global $wpdb;
1437
+ $sql = $wpdb->query($wpdb->prepare("
1438
INSERT INTO " . $wpdb->yop_poll_templates . "
1439
SET
1440
template_author = %d,
1448
date_added = %s,
1449
last_modified = %s,
1450
status = %s
1451
+ ", $template['template_author'], $template['name'], $template['before_vote_template'], $template['after_vote_template'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time('mysql'), current_time('mysql'), $template['status']));
1452
return $GLOBALS['wpdb']->insert_id;
1453
}
1454
+
1455
+ private static function update_poll_template_in_database($template)
1456
+ {
1457
global $wpdb;
1458
+ $sql = $wpdb->query($wpdb->prepare("
1459
UPDATE " . $wpdb->yop_poll_templates . "
1460
SET name = %s,
1461
before_vote_template = %s,
1467
last_modified = %s
1468
WHERE
1469
id = %d
1470
+ ", $template['name'], $template['before_vote_template'], $template['after_vote_template'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time('mysql'), $template['id']));
1471
return $sql;
1472
}
1473
+
1474
+ public function yop_poll_get_polls_from_db()
1475
+ {
1476
global $wpdb;
1477
+ $result = $wpdb->get_results(("
1478
SELECT *
1479
FROM " . $wpdb->prefix . "yop_polls ORDER BY id ASC
1480
+ "), ARRAY_A);
1481
return $result;
1482
1483
}
1484
1485
+ public function yop_poll_get_polls_meta_from_db()
1486
+ {
1487
global $wpdb;
1488
+ $result = $wpdb->get_results(("
1489
SELECT *
1490
FROM " . $wpdb->prefix . "yop_pollmeta ORDER BY yop_poll_id ASC
1491
+ "), ARRAY_A);
1492
return $result;
1493
1494
}
1495
1496
+ public function yop_poll_get_answers_meta_from_db()
1497
+ {
1498
global $wpdb;
1499
1500
+ $result = $wpdb->get_results(("
1501
SELECT *
1502
FROM " . $wpdb->prefix . "yop_poll_answermeta
1503
+ "), ARRAY_A);
1504
return $result;
1505
1506
}
1507
1508
+ public function yop_poll_get_templates_from_db()
1509
+ {
1510
global $wpdb;
1511
+ $result = $wpdb->get_results(("
1512
SELECT *
1513
FROM " . $wpdb->prefix . "yop_poll_templates
1514
+ "), ARRAY_A);
1515
return $result;
1516
}
1517
+
1518
+ public function yop_poll_get_templates_new_version_from_db()
1519
+ {
1520
global $wpdb;
1521
+ $result = $wpdb->get_results(("
1522
SELECT *
1523
FROM " . $wpdb->yop_poll_templates
1524
+ ), ARRAY_A);
1525
return $result;
1526
}
1527
1528
+ public function yop_poll_get_custom_fields_from_db()
1529
+ {
1530
global $wpdb;
1531
+ $result = $wpdb->get_results(("
1532
SELECT *
1533
FROM " . $wpdb->prefix . "yop_poll_custom_fields ORDER BY poll_id ASC
1534
+ "), ARRAY_A);
1535
return $result;
1536
}
1537
1538
+ public function yop_poll_get_custom_fields_votes_from_db()
1539
+ {
1540
global $wpdb;
1541
+ $result = $wpdb->get_results(("
1542
SELECT *
1543
FROM " . $wpdb->prefix . "yop_poll_votes_custom_fields
1544
+ "), ARRAY_A);
1545
return $result;
1546
}
1547
1548
+ public function yop_poll_get_bans_from_db()
1549
+ {
1550
global $wpdb;
1551
+ $result = $wpdb->get_results(("
1552
SELECT *
1553
FROM " . $wpdb->prefix . "yop_poll_bans ORDER BY poll_id ASC
1554
+ "), ARRAY_A);
1555
return $result;
1556
}
1557
+
1558
+ public function yop_poll_get_answers_from_db()
1559
+ {
1560
global $wpdb;
1561
+ $result = $wpdb->get_results(("
1562
SELECT *
1563
FROM " . $wpdb->prefix . "yop_poll_answers ORDER BY poll_id ASC
1564
+ "), ARRAY_A);
1565
return $result;
1566
}
1567
+
1568
+ public function get_answers_order_by_votes($poll_id, $dir)
1569
+ {
1570
global $wpdb;
1571
+ $result = $wpdb->get_results($wpdb->prepare("
1572
SELECT *
1573
FROM " . $wpdb->prefix . "yop_poll_answers WHERE poll_id=%d ORDER BY votes $dir
1574
+ ", $poll_id), ARRAY_A);
1575
return $result;
1576
}
1577
1578
+ public function get_answers_order_by_alph($poll_id, $dir)
1579
+ {
1580
global $wpdb;
1581
+ $result = $wpdb->get_results($wpdb->prepare("
1582
SELECT *
1583
FROM " . $wpdb->prefix . "yop_poll_answers WHERE poll_id=%d ORDER BY answer $dir
1584
+ ", $poll_id), ARRAY_A);
1585
return $result;
1586
}
1587
1588
+ public function yop_poll_get_logs_from_db()
1589
+ {
1590
global $wpdb;
1591
+ $result = $wpdb->get_results(("
1592
SELECT *
1593
FROM " . $wpdb->prefix . "yop_poll_logs
1594
+ "), ARRAY_A);
1595
return $result;
1596
}
1597
1598
+ private static function insert_ban_in_db($ban)
1599
+ {
1600
global $wpdb;
1601
+ $sql = $wpdb->query($wpdb->prepare("
1602
INSERT INTO $wpdb->yop_poll_bans
1603
( poll_id,type,value,period ,unit)
1604
VALUES(%d,%s,%s,%d,%s)
1605
+ ", $ban['poll_id'], $ban['type'], $ban['value'], intval($ban['period']), $ban['unit']));
1606
+ return $wpdb->get_results($sql);
1607
}
1608
+
1609
+ private function save_poll_order($poll, $poll_order)
1610
+ {
1611
+ $poll_archive_order = get_option('yop_poll_archive_order', array());
1612
+ if ($poll_archive_order == "") {
1613
$poll_archive_order = array();
1614
}
1615
+ if (trim($poll_order) <= 0) {
1616
+ $poll_order = 1;
1617
}
1618
+ $key = array_search($poll, $poll_archive_order);
1619
+ if ($key !== false) {
1620
+ unset($poll_archive_order[$key]);
1621
}
1622
+ if ($poll_order > count($poll_archive_order)) {
1623
+ array_push($poll_archive_order, $poll);
1624
+ } else {
1625
+ array_splice($poll_archive_order, trim($poll_order) - 1, 0, array($poll));
1626
}
1627
+ update_option('yop_poll_archive_order', $poll_archive_order);
1628
}
1629
1630
}
models/poll_model.php CHANGED
@@ -1,108 +1,111 @@
1
<?php
2
3
- Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
4
5
protected $type = 'poll';
6
7
- function __construct( $id = 0, $is_view_results = 'no', $question_sort = "poll_order", $question_sort_rule = "ASC", $answer_sort = "question_order", $answer_sort_rule = "ASC" ) {
8
9
- parent::__construct( $id, $is_view_results, $question_sort, $question_sort_rule, $answer_sort, $answer_sort_rule );
10
11
}
12
13
- public static function return_template_preview_html( $template_id = '', $loc = 1 ) {
14
15
- if( '' == $template_id ) {
16
return "";
17
- }
18
- else {
19
- $uID = uniqid( 't' );
20
- $poll =new YOP_POLL_Poll_Model();
21
- $template_details = self::get_poll_template_from_database( intval( $template_id ) );
22
- $template = $template_details['before_vote_template'];
23
- $template = stripslashes_deep( $template );
24
25
- $template = str_ireplace( '%POLL-NAME%', "Poll Name", $template );
26
- $template = str_ireplace( '%POLL-VOTE-BUTTON%', '<button class="yop_poll_vote_button" onclick="return false;">Vote</button>', $template );
27
28
- $question = new YOP_POLL_Question_Model();
29
30
- $question->question = "Poll Question";
31
$question->allow_multiple_answers = "no";
32
- $question->allow_other_answers = "no";
33
34
- for( $i = 0; $i < 5; $i ++ ) {
35
- $a = new YOP_POLL_Answer_Model();
36
- $j = $i + 1;
37
- $a->ID = $i + 1;
38
$a->answer = "Answer {$j}";
39
40
- $question->addAnswer( $a );
41
- unset( $a );
42
}
43
- $poll->questions=$question;
44
- $t = $template;
45
$pattern = '\[(\[?)(QUESTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
46
- preg_match( "/$pattern/s", $t, $m );
47
$m = $m[5];
48
49
- $m = str_ireplace( "%POLL-QUESTION%", $question->question, $m );
50
51
$pattern = '/\[(\[?)(ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/';
52
- preg_match( $pattern, $m, $m1 );
53
$m1 = $m1[5];
54
55
$ts = "";
56
57
/** Start Answer Description replace */
58
$pattern = '\[(\[?)(ANSWER_DESCRIPTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
59
- $m1 = preg_replace( "/$pattern/s", "", $m1 );
60
/** End Answer Description replace */
61
62
/** Start Answer Result replace */
63
$pattern = '\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
64
- $m1 = preg_replace( "/$pattern/s", "", $m1 );
65
/** End Answer Result replace */
66
67
- foreach( $question->answers as $answer ) {
68
- $temps = str_ireplace( '%POLL-ANSWER-CHECK-INPUT%', '<input type="radio" value="' . $answer->ID . '" name="yop_poll_answer-' . $uID . '" id="yop-poll-answer-' . $uID . '-' . $answer->ID . '" />', $m1 );
69
- $temps = str_ireplace( '%POLL-ANSWER-LABEL%', '<label>' . $answer->answer . '</label>', $temps );
70
$ts .= $temps;
71
}
72
73
$pattern = '/\[(\[?)(ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/';
74
- $m = preg_replace( $pattern, $ts, $m );
75
76
- $pattern = '\[(\[?)(QUESTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
77
- $template = preg_replace( "/$pattern/s", $m, $template );
78
79
- $pattern = array(
80
'/\[(\[?)(OTHER_ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/',
81
'/\[(\[?)(CUSTOM_FIELD_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/',
82
'/\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/',
83
'/\[(\[?)(CAPTCHA_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/'
84
);
85
- $template = preg_replace( $pattern, "", $template );
86
- $template = preg_replace( '/\[\/?QUESTION_CONTAINER\]/', "", $template );
87
- $template = str_ireplace( "%POLL-ID%", "preview-" . $uID, $template );
88
- $template = self::strip_all_tags( $template );
89
-
90
- $t = '<style type="text/css">' . $poll->return_poll_css( $template_details['css'], array(
91
- "location" => 'page',
92
- 'preview' => true,
93
'template_id' => $uID,
94
- 'loc' => $loc
95
- ) ) . '</style>';
96
$t .= '<div id="yop-poll-container-preview-' . $uID . '" class="yop-poll-container" style="position: relative; z-index: 1;">';
97
$t .= '' . $template . '</div>';
98
99
- $qID = uniqid( 'q' );
100
- $t = str_ireplace( "%QUESTION-ID%", $qID, $t );
101
return $t;
102
}
103
}
104
105
- private static function strip_all_tags( $template ) {
106
107
$tags = array(
108
'%CAPTCHA-PLAY%',
@@ -148,31 +151,31 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
148
'%SHARE-BUTTON%'
149
);
150
151
- foreach( $tags as $tag ) {
152
- $template = str_ireplace( $tag, '', $template );
153
}
154
return $template;
155
}
156
157
public function return_poll_css(
158
$css = "", $attr = array(
159
- 'location' => 'page',
160
- 'preview' => false,
161
'template_id' => '',
162
- 'loc' => 1
163
)
164
- ) {
165
- $preview = isset( $attr['preview'] ) ? $attr['preview'] : false;
166
- $location = isset( $attr['location'] ) ? $attr['location'] : 'page';
167
- if( $preview ) {
168
$template = $css;
169
- $template.="li.yop-poll-li-answer-%POLL-ID% {width:100%}";
170
- $template.="div.yop-poll-answers-%POLL-ID% ul{width:100%}";
171
- $template = str_ireplace( "%POLL-ID%", 'preview-' . $attr['template_id'] . '', $template );
172
- $template = str_ireplace( "%POLL-WIDTH%", '200px', $template );
173
- return stripslashes( $template );
174
- }
175
- else {
176
$unique_id = $this->ID . $this->unique_id;
177
178
/*if ( !$poll_id ){
@@ -192,175 +195,175 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
192
$template_details = self::get_poll_template_from_database( $template_id );
193
$template = $template_details['css'];*/
194
195
- $template = str_ireplace( '%POLL-ID%', $unique_id, $css );
196
- if( 'widget' == $location ) {
197
- $template = str_ireplace( '%POLL-WIDTH%', $this->widget_template_width, $template );
198
}
199
- else {
200
- $template = str_ireplace( '%POLL-WIDTH%', $this->template_width, $template );
201
- }
202
- return stripslashes( $template );
203
}
204
}
205
206
- private static function count_other_answers( $question ) {
207
- $n = count( $question->answers );
208
$nr = 0;
209
- for( $i = 0; $i < $n; $i ++ ) {
210
- if( $question->answers[$i]->type == "other" ) {
211
- $nr ++;
212
}
213
}
214
return $nr;
215
}
216
217
- public function return_poll_js( $attr = array( 'location' => 'page' ) ) {
218
- $poll_id = $this->ID;
219
- $location = isset( $attr['location'] ) ? $attr['location'] : 'page';
220
$unique_id = $this->unique_id;
221
222
- if( ! $poll_id ) {
223
return '';
224
}
225
226
- if( 'widget' == $location ) {
227
$template_id = $this->widget_template;
228
- }
229
- else {
230
$template_id = $this->template;
231
}
232
233
- if( '' == $template_id ) {
234
//get default template
235
$template_details = self::get_poll_template_from_database();
236
- }
237
- else {
238
- $template_details = self::get_poll_template_from_database( $template_id );
239
}
240
241
$tabulate = array();
242
243
- foreach( $this->questions as $question ) {
244
$answers_tabulated_cols = 1; //vertical display
245
$results_tabulated_cols = 1;
246
247
- $include_others = false;
248
- $display_answers = array( 'text', 'image', 'video' );
249
250
- if( isset( $question->allow_other_answers ) && 'yes' == $question->allow_other_answers ) {
251
252
- if( isset( $question->display_other_answers_values ) && 'yes' == $question->display_other_answers_values ) {
253
- $include_others = true;
254
- $display_answers = array( 'text', 'image', 'video', 'other' );
255
}
256
}
257
258
259
- if( 'orizontal' == $question->display_answers ) {
260
- $ans_no = $question->countanswers( $display_answers, $include_others );
261
- if( $ans_no > 0 ) {
262
$answers_tabulated_cols = $ans_no;
263
}
264
- if( isset( $question->allow_other_answers ) && 'yes' == $question->allow_other_answers ) {
265
- $answers_tabulated_cols ++;
266
}
267
- }
268
- else
269
- if( 'tabulated' == $question->display_answers ) {
270
$answers_tabulated_cols = $question->display_answers_tabulated_cols;
271
//yop_poll_dump($answers_tabulated_cols);
272
273
}
274
275
- if( 'orizontal' == $question->display_results ) {
276
- $ans_no = $question->countanswers( $display_answers, $include_others );
277
- if( $ans_no > 0 ) {
278
$results_tabulated_cols = $ans_no;
279
}
280
- }
281
- else if( 'tabulated' == $question->display_results ) {
282
$results_tabulated_cols = $question->display_results_tabulated_cols;
283
}
284
285
- array_push($tabulate, array( $answers_tabulated_cols, $results_tabulated_cols,$ans_per_question,$question->ID) );
286
}
287
288
$template = $template_details['js'];
289
- if( 'vertical' == $question->display_answers ) {
290
- $template.="jQuery(document).ready(function(){ jQuery('.yop-poll-li-answer-%POLL-ID%').css('float','none');});" ;
291
292
}
293
- $template = str_ireplace( '%POLL-ID%', $poll_id . $unique_id, $template );
294
- $template = str_ireplace( '%ANSWERS-TABULATED-COLS%', json_encode( $tabulate ), $template );
295
- $template = str_ireplace( '%POLL-WIDTH%',str_replace( "px","",$this->template_width), $template );
296
- $template = str_ireplace( '%RESULTS-TABULATED-COLS%', json_encode( $tabulate ), $template );
297
- return stripslashes( $template );
298
}
299
300
- public function question_replace_callback( $m ) {
301
- $is_voted = $this->is_voted();
302
$return_string = "";
303
- $that=$this;
304
- foreach( $this->questions as $question ) {
305
306
$qunique_id = $question->ID;
307
- $temp = str_ireplace( '%QUESTION-ID%', $qunique_id, $m[5] );
308
- $temp = str_ireplace( '%POLL-QUESTION%', $question->question, $temp );
309
310
- $temp = str_ireplace('class = '.'"'. 'yop-poll-li-answer-' . $this->ID . $this->unique_id ,'class='.'"'. 'yop-poll-li-answer-' . $this->ID . $this->unique_id . ' yop-poll-li-answer-' . $this->ID . $this->unique_id."-".$question->ID, $temp);
311
312
- if( ! $is_voted ) {
313
/** Start Anwer replace */
314
- if( $this->count_answers( $question ) > 0 ) {
315
$pattern = '\[(\[?)(ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
316
- $temp = preg_replace_callback( "/$pattern/s", function ( $m ) use ($that, $question ) {
317
- return $that->answer_replace_callback( $m[5], $question );
318
- }, $temp );
319
}
320
/** End Anwer replace */
321
322
/** Start Other Answer replace */
323
$pattern = '\[(\[?)(OTHER_ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
324
- $temp = str_ireplace('class = '.'"'. 'yop-poll-li-answer-' . $this->ID . $this->unique_id ,'class='.'"'. 'yop-poll-li-answer-' . $this->ID . $this->unique_id . ' yop-poll-li-answer-' . $this->ID . $this->unique_id."-".$question->ID, $temp);
325
326
- $temp = preg_replace_callback( "/$pattern/s", function ( $m ) use ( $that, $question ) {
327
- return $that->other_answer_replace_callback( $m[5], $question );
328
- }, $temp );
329
/** End Other Answer replace */
330
331
/** Start Custom Fields replace*/
332
$pattern = '\[(\[?)(CUSTOM_FIELD_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
333
- $temp = preg_replace_callback( "/$pattern/s", function ( $m ) use ( $that ,$question ) {
334
- return $that->custom_field_replace_callback( $m[5], $question );
335
- }, $temp );
336
/** End Custom Fields replace*/
337
}
338
$pattern = '\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
339
- $temp = preg_replace_callback( "/$pattern/s", function ( $m ) use ( $that, $question ) {
340
- return $that->answer_result_replace_callback( $m[5], $question );
341
- }, $temp );
342
343
$return_string .= $temp;
344
}
345
return $return_string;
346
}
347
348
- private static function count_answers( $question ) {
349
- $n = count( $question->answers );
350
$nr = 0;
351
- for( $i = 0; $i < $n; $i ++ ) {
352
- if( in_array( $question->answers[$i]->type, array( 'text' ) ) ) {
353
- $nr ++;
354
}
355
}
356
return $nr;
357
}
358
359
- public function answer_replace_callback( $m, $question ) {
360
$unique_id = $this->unique_id;
361
362
$multiple_answers = false;
363
- if( $question->allow_multiple_answers == 'yes' ) {
364
$multiple_answers = true;
365
}
366
@@ -368,77 +371,77 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
368
369
/** Get question total votes( default + other ) */
370
371
/**Is allowed to display other answers?*/
372
$display_other_answers = false;
373
374
- if( isset( $question->allow_other_answers ) && 'yes' == $question->allow_other_answers ) {
375
- if( isset( $question->display_other_answers_values ) && 'yes' == $question->display_other_answers_values ) {
376
$display_other_answers = true;
377
}
378
}
379
380
$percentages_decimals = 0;
381
- if( isset( $this->percentages_decimals ) ) {
382
$percentages_decimals = $this->percentages_decimals;
383
}
384
385
- $id = $this->ID;
386
387
$view_results = $this->is_view_poll_results();
388
- //yop_poll_dump($view_results);
389
- $that=$this;
390
- foreach( $question->answers as $answer ) {
391
/**Check if is allowed to display current answers*/
392
- if( ( $answer->type == "other" ) && ! $display_other_answers ) {
393
continue;
394
}
395
- if($view_results){
396
- if( $answer->votes > 0 ) {
397
- $percentages = floatval( $answer->votes * 100 / $total_votes );
398
- }
399
- else {
400
- $percentages = 0;
401
- }
402
- }
403
- if( function_exists( 'icl_translate' ) ) {
404
- $answer->answer = icl_translate( 'yop_poll', $answer->ID . '_answer', $answer->answer );
405
- }
406
- if( $multiple_answers ) {
407
- if( isset( $answer->is_default_answer ) && $answer->is_default_answer == "yes" ) {
408
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-CHECK-INPUT%', '<input type="checkbox" checked="checked" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . '][]" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m );
409
- }
410
- else {
411
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-CHECK-INPUT%', '<input type="checkbox" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . '][]" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m );
412
}
413
}
414
- else {
415
- if( isset( $answer->is_default_answer ) && $answer->is_default_answer == "yes" ) {
416
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-CHECK-INPUT%', '<input type="radio" checked="checked" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . ']" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m );
417
}
418
- else {
419
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-CHECK-INPUT%', '<input type="radio" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . ']" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m );
420
}
421
}
422
423
/** Start Answer Description replace */
424
- $pattern = '\[(\[?)(ANSWER_DESCRIPTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
425
- $temp_answer_model = preg_replace_callback( "/$pattern/s", function ( $m ) use ( $that,$answer, $id, $unique_id ) {
426
- return $that->answer_description_replace_callback( $m[5], $answer, $id, $unique_id );
427
- }, $temp_answer_model );
428
/** End Answer Description replace */
429
- if($view_results){
430
- /** Start Answer Result replace */
431
- $pattern = '\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
432
- $temp_answer_model = preg_replace_callback( "/$pattern/s", function ( $m ) use ( $that,$answer, $view_results, $id, $unique_id, $percentages, $percentages_decimals ) {
433
- return $that->answer_result_bar_callback( $m[5], $answer, $view_results, $id, $unique_id, $percentages, $percentages_decimals );
434
- }, $temp_answer_model );
435
- /** End Answer Result replace */
436
}
437
- if( $answer->type == "text" ) {
438
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-LABEL%', '<label for="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '">' . yop_poll_kses( stripslashes( $answer->answer ) ) . '</label>', $temp_answer_model );
439
}
440
- if( $answer->type == "other" ) {
441
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-LABEL%', '<label style=" cursor: pointer;" for="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '">' . yop_poll_kses( stripslashes( $answer->answer ) ) . '</label>', $temp_answer_model );
442
}
443
444
$model .= $temp_answer_model;
@@ -447,47 +450,52 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
447
return $model;
448
}
449
450
- private static function get_question_votes( $question ) {
451
$total_votes = 0;
452
- foreach( $question->answers as $answer ) {
453
- $total_votes += intval( $answer->votes );
454
}
455
return $total_votes;
456
}
457
458
- private function is_view_poll_results() {
459
$is_voted = $this->is_voted();
460
- if( ( ( in_array( 'before', $this->view_results ) ) || ( in_array( 'after', $this->view_results ) && $is_voted ) || ( in_array( 'custom-date', $this->view_results ) && self::get_mysql_curent_date() >= convert_date( $this->view_results_start_date, 'Y-m-d H:i:s',1) ) || ( in_array( 'after-poll-end-date', $this->view_results ) && self::get_mysql_curent_date() >= convert_date( $this->poll_end_date, 'Y-m-d H:i:s' ) ) ) && ! in_array( 'never', $this->view_results ) && ( ( in_array( 'guest', $this->view_results_permissions ) && ! is_user_logged_in() ) || ( in_array( 'registered', $this->view_results_permissions ) && is_user_logged_in() ) )
461
) {
462
return true;
463
}
464
return false;
465
}
466
- public function answer_description_replace_callback( $m, $answer, $id, $unique_id ) {
467
- if( "" == $answer->description ) {
468
return "";
469
}
470
- return str_ireplace( "%ANSWER-DESCRIPTION%", '<label for="yop-poll-answer-' . $id . $unique_id . '-' . $answer->ID . '">' . yop_poll_kses( stripslashes( $answer->description ) ) . '</label>', $m );
471
}
472
473
- public function answer_result_bar_callback( $m, $answer, $view_results, $id, $unique_id, $percentages, $percentages_decimals ) {
474
- if( $view_results ) {
475
- $tmp = str_ireplace( '%POLL-ANSWER-RESULT-BAR%', self::display_poll_result_bar( $answer->ID, $percentages, $this->options, $id . $unique_id ), $m );
476
- $tmp = str_ireplace( '%POLL-ANSWER-RESULT-VOTES%', self::display_poll_result_votes( $answer->votes, $this->options ), $tmp );
477
- $tmp = str_ireplace( '- ( )', self::display_poll_result_votes( $answer->votes, $this->options ), $tmp );
478
- $tmp = str_ireplace( '%POLL-ANSWER-RESULT-PERCENTAGES%', self::display_poll_result_percentages( round( $percentages, $percentages_decimals ), $this->options ), $tmp );
479
return $tmp;
480
- }
481
- else {
482
return "";
483
}
484
}
485
486
- private static function display_poll_result_bar( $answer_id = 0, $procent = 0, $options = array(), $unique_id = '' ) {
487
$result_bar = ' <div class="yop-poll-results-bar-' . $unique_id . '" ';
488
$result_bar .= ' ';
489
$result_bar .= '><div>';
490
- if( floatval( $procent ) > 0 ) {
491
492
$result_bar .= '<div style="' . 'width:' . $procent . '%; ';
493
$result_bar .= 'height:' . $options['bar_height'] . 'px; ' . 'background-color:#' . $options['bar_background'] . '; ' . 'border-style:' . $options['bar_border_style'] . '; ' . 'border-width:' . $options['bar_border_width'] . 'px; ' . 'border-color:#' . $options['bar_border_color'] . '; ';
@@ -497,93 +505,91 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
497
return $result_bar;
498
}
499
500
- private static function display_poll_result_votes( $votes = 0, $options = array() ) {
501
502
- if( 'votes-number' == $options['view_results_type'] || 'votes-number-and-percentages' == $options['view_results_type'] ) {
503
- if( '1' == $votes ) {
504
- $options = get_option('yop_poll_options' );
505
return $votes . ' ' . $options['singular_answer_result_votes_number_label'];
506
- }
507
- else {
508
- $options = get_option('yop_poll_options' );
509
return $votes . ' ' . $options['plural_answer_result_votes_number_label'];
510
}
511
}
512
}
513
514
- private static function display_poll_result_percentages( $votes, $options = array() ) {
515
- if( 'percentages' == $options['view_results_type'] || 'votes-number-and-percentages' == $options['view_results_type'] ) {
516
return $votes . '%';
517
- }
518
- else {
519
return '';
520
}
521
}
522
523
- public function other_answer_replace_callback( $m, $question ) {
524
$unique_id = $this->unique_id;
525
526
$multiple_answers = false;
527
- if( $question->allow_multiple_answers == 'yes' ) {
528
$multiple_answers = true;
529
}
530
531
$model = "";
532
533
- $allow_other_answers = false;
534
$display_other_answers = false;
535
- if( isset( $question->allow_other_answers ) && $question->allow_other_answers == 'yes' ) {
536
$allow_other_answers = true;
537
- if( isset( $question->add_other_answers_to_default_answers ) && ( 'yes' == $question->add_other_answers_to_default_answers ) ) {
538
$display_other_answers = true;
539
}
540
}
541
542
- if( $allow_other_answers ) {
543
/**Display other answer input */
544
- if( function_exists( 'icl_translate' ) ) {
545
- $other_answer_label = icl_translate( 'yop_poll', $this->ID . '_other_answer_label', yop_poll_kses( $question->other_answers_label ) );
546
- }
547
- else {
548
- $other_answer_label = yop_poll_kses( $question->other_answers_label );
549
}
550
551
- if( $multiple_answers ) {
552
- $temp_answer_model = str_ireplace( '%POLL-OTHER-ANSWER-CHECK-INPUT%', '<input type="checkbox" value="other" name="yop_poll_answer[' . $question->ID . '][]" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other" />', $m );
553
- }
554
- else {
555
- $temp_answer_model = str_ireplace( '%POLL-OTHER-ANSWER-CHECK-INPUT%', '<input type="radio" value="other" name="yop_poll_answer[' . $question->ID . ']" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other" />', $m );
556
}
557
- $temp_answer_model = str_ireplace( '%POLL-OTHER-ANSWER-LABEL%', '<label for="yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other">' . $other_answer_label . '</label>', $temp_answer_model );
558
- $temp_answer_model = str_ireplace( '%POLL-OTHER-ANSWER-TEXT-INPUT%', '<label style="width:100%;"><input onclick="document.getElementById(\'yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other' . '\').checked=true;" type="text" value="" name="yop_poll_other_answer[' . $question->ID . ']" id="yop-poll-other-answer-' . $this->ID . $unique_id . '-other" /></label>', $temp_answer_model );
559
560
- if( $this->is_view_poll_results() ) {
561
/**Display only if other answers were not displayed */
562
- if( ! $display_other_answers ) {
563
/** Count question total votes( default + other ) */
564
- $total_votes = $this->get_question_votes( $question );
565
566
/** Count other answers votes*/
567
- $other_votes = $this->get_question_other_votes( $question );
568
569
570
$percentages_decimals = 0;
571
- if( isset( $this->percentages_decimals ) ) {
572
$percentages_decimals = $this->percentages_decimals;
573
}
574
575
- if( $other_votes > 0 ) {
576
- $percentages = floatval( $other_votes * 100 / $total_votes );
577
- }
578
- else {
579
$percentages = 0;
580
}
581
- if( $this->is_view_poll_results() ) {
582
- $temp_answer_model = str_ireplace( '%POLL-OTHER-ANSWER-RESULT-BAR%', self::display_poll_result_bar( 'other', $percentages, $this->options, $this->ID . $unique_id ), $temp_answer_model );
583
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-RESULT-VOTES%', self::display_poll_result_votes( $other_votes, $this->options ), $temp_answer_model );
584
- $temp_answer_model = str_ireplace( '- ( )', self::display_poll_result_votes( $other_votes, $this->options ), $temp_answer_model );
585
586
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-RESULT-PERCENTAGES%', self::display_poll_result_percentages( round( $percentages, $percentages_decimals ), $this->options ), $temp_answer_model );
587
}
588
}
589
}
@@ -592,29 +598,31 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
592
return $model;
593
}
594
595
- private static function get_question_other_votes( $question ) {
596
$total_votes = 0;
597
- foreach( $question->answers as $answer ) {
598
- if( $answer->type == 'other' ) {
599
- $total_votes += intval( $answer->votes );
600
}
601
}
602
return $total_votes;
603
}
604
605
- public function custom_field_replace_callback( $m, $question ) {
606
$unique_id = $this->unique_id;
607
- $is_voted = $this->is_voted();
608
- $model = "";
609
- if( ! $is_voted ) {
610
- if( count( $question->custom_fields ) > 0 ) {
611
- foreach( $question->custom_fields as $custom_field ) {
612
- if( function_exists( 'icl_translate' ) ) {
613
- $custom_field['custom_field'] = icl_translate( 'yop_poll', $custom_field->ID . '_custom_field', $custom_field->custom_field );
614
}
615
- $temp_string = str_ireplace( '%POLL-CUSTOM-FIELD-LABEL%', '<label for="yop-poll-customfield-' . $this->ID . $unique_id . '-' . $custom_field->ID . '">' . yop_poll_kses( $custom_field->custom_field ) . '</label>', $m );
616
617
- $temp_string = str_ireplace( '%POLL-CUSTOM-FIELD-TEXT-INPUT%', '<input type="text" value="" name="yop_poll_customfield[' . $question->ID . '][' . $custom_field->ID . ']" id="yop-poll-customfield-' . $this->ID . $unique_id .'-'.$custom_field->ID.'" class='.'"yop-poll-customfield-' . $this->ID . $unique_id .'"/>', $temp_string );
618
$model .= $temp_string;
619
}
620
}
@@ -622,99 +630,94 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
622
return $model;
623
}
624
625
- public function answer_result_replace_callback( $m, $question ) {
626
- $unique_id = $this->unique_id;
627
$return_string = '';
628
- $is_voted = $this->is_voted();
629
- $id = $this->ID;
630
631
- if( $this->is_view_poll_results() ) {
632
$display_other_answers = false;
633
- if( 'yes' == $question->allow_other_answers ) {
634
- if( 'yes' == $question->display_other_answers_values ) {
635
$display_other_answers = true;
636
}
637
}
638
639
$percentages_decimals = 0;
640
- if( isset( $this->percentages_decimals ) ) {
641
$percentages_decimals = $this->percentages_decimals;
642
}
643
644
- if( isset( $this->sorting_results ) ) {
645
- if( 'as_defined' == $this->sorting_results ) {
646
- $question->sortAnswers( 'question_order', 'asc' );
647
- }
648
- elseif( 'database' == $this->sorting_results ) {
649
$order_dir = 'asc';
650
- if( isset( $this->sorting_results_direction ) ) {
651
- $order_dir = ( 'asc' == $this->sorting_results_direction ) ? 'asc' : 'desc';
652
}
653
- $question->sortAnswers( 'ID', $order_dir );
654
- }
655
- elseif( 'alphabetical' == $this->sorting_results ) {
656
$order_dir = 'asc';
657
- if( isset( $this->sorting_results_direction ) ) {
658
- $order_dir = ( 'asc' == $this->sorting_results_direction ) ? 'asc' : 'desc';
659
}
660
- $question->sortAnswers( 'alphabetical', $order_dir );
661
- }
662
- elseif( 'votes' == $this->sorting_results ) {
663
$order_dir = 'asc';
664
- if( isset( $this->sorting_results_direction ) ) {
665