YOP Poll - Version 5.7.6

Version Description

  • Fixed issues with cloning poll
  • Fixed conflicts with different plugins
  • Fixed issue with pagination on archive page
  • Fixed issue with logs page
  • Fixed issue with facebook voting
  • Added new shortcuts for email notifications
  • Added new column for username in view votes page
Download this release

Release Info

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

Code changes from version 5.7.4 to 5.7.6

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,34 @@ 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 +775,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 +1073,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 +1135,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 +1177,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 +1356,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 +1451,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 +1470,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
+ }if (version_compare($installed_version, '5.7.5', '<=')) {
757
+ global $wpdb;
758
+ update_option("yop_poll_version", '5.7.6');
759
}
760
}
761
+
762
+ private static function update_poll_template_in_database2($template)
763
+ {
764
global $wpdb;
765
+ $sql = $wpdb->query($wpdb->prepare("
766
UPDATE " . $wpdb->yop_poll_templates . "
767
SET name = %s,
768
before_vote_template = %s,
775
last_modified = %s
776
WHERE
777
id = %d
778
+ ", $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']));
779
return $sql;
780
}
781
+
782
+ public function yop_poll_get_polls_for_body_mail_update()
783
+ {
784
global $wpdb;
785
+ $result = $wpdb->get_results(("
786
SELECT ID
787
+ FROM " . $wpdb->yop_polls . " ORDER BY ID ASC
788
+ "), ARRAY_A);
789
return $result;
790
}
791
+
792
+ private function install_default_options()
793
+ {
794
+ $default_poll_options = get_option('yop_poll_options');
795
796
$default_poll_options['is_default_answer'] = 'no';
797
+ $default_poll_options['poll_start_date'] = current_time('mysql');
798
+ $default_poll_options['poll_end_date'] = '01-01-2038 23:59:59';
799
800
+ update_option('yop_poll_options', $default_poll_options);
801
}
802
803
+ private function uninstall_default_options()
804
+ {
805
// delete_option( "yop_poll_version" );
806
// delete_option( "yop_poll_options" );
807
}
808
809
+ public function activate($networkwide)
810
+ {
811
+ if (!current_user_can('activate_plugins')) {
812
+ $error = new WP_Error ('Wordpress_version_error', __yop_poll('You need permissions to activate this plugin'), __yop_poll('Error: Wordpress Activation Permissions Problem'));
813
}
814
815
+ if (!version_compare($GLOBALS['wp_version'], YOP_POLL_WP_VERSION, '>=')) {
816
+ $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'));
817
+ $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'));
818
}
819
820
+ if (isset ($error) && is_wp_error($error)) {
821
+ wp_die($error->get_error_message(), $error->get_error_data());
822
}
823
824
825
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
826
+ require_once(YOP_POLL_INC . 'db_schema.php');
827
$this->install_default_options();
828
$capObj = YOP_POLL_Capabilities::get_instance();
829
$capObj->install_capabilities();
830
Yop_Poll_DbSchema::install_database();
831
}
832
833
+ public function deactivatedelete($networkwide)
834
+ {
835
+ require_once(YOP_POLL_INC . 'db_schema.php');
836
Yop_Poll_DbSchema::delete_database_tables();
837
$capObj = YOP_POLL_Capabilities::get_instance();
838
$capObj->uninstall_capabilities();
839
$this->uninstall_default_options();
840
}
841
842
+ function new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta)
843
+ {
844
+ if (!function_exists('is_plugin_active_for_network')) {
845
+ require_once(ABSPATH . '/wp-admin/includes/plugin.php');
846
}
847
+ if (is_plugin_active_for_network(YOP_POLL_SHORT_PLUGIN_FILE)) {
848
$old_blog = $GLOBALS['wpdb']->blogid;
849
+ switch_to_blog($blog_id);
850
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
851
+ $this->activate(null);
852
+ switch_to_blog($old_blog);
853
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
854
}
855
}
856
857
+ function delete_blog($blog_id)
858
+ {
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
876
+ public function activation_hook($default)
877
+ {
878
ini_set('max_execution_time', 700);
879
+ $current_options = get_option('yop_poll_options');
880
+ $polls = self::yop_poll_get_polls_from_db();
881
+ $answers = self::yop_poll_get_answers_from_db();
882
+ $logs = self::yop_poll_get_logs_from_db();
883
+ $bans = self::yop_poll_get_bans_from_db();
884
$custom_fields = self::yop_poll_get_custom_fields_from_db();
885
+ $custom_votes = self::yop_poll_get_custom_fields_votes_from_db();
886
+ $metas = self::yop_poll_get_polls_meta_from_db();
887
+ $answers_meta = self::yop_poll_get_answers_meta_from_db();
888
+ $templates = self::yop_poll_get_templates_from_db();
889
+ foreach ($templates as $template) {
890
+ $template['before_vote_template'] = "[QUESTION_CONTAINER]" . $template['before_vote_template'];
891
+ $template['before_vote_template'] = str_replace('%POLL-ANSWER-LABEL%', '%POLL-ANSWER-LABEL% [ANSWER_RESULT_CONTAINER]', $template['before_vote_template']);
892
+ $template['before_vote_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['before_vote_template']);
893
+ $template['before_vote_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['before_vote_template']);
894
+ $template['after_vote_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['after_vote_template']);
895
+ $template['after_vote_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['after_vote_template']);
896
+ $template['after_end_date_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['after_end_date_template']);
897
+ $template['after_end_date_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['after_end_date_template']);
898
+ $template['before_vote_template'] = preg_replace('/%POLL-ANSWER-RESULT-BAR%/', '%POLL-ANSWER-RESULT-BAR% [/ANSWER_RESULT_CONTAINER]', $template['before_vote_template'], 1);
899
$find = '[/ANSWER_RESULT_CONTAINER]';
900
$replace = '';
901
// $template['before_vote_template']= preg_replace(strrev("/$find/"),strrev($replace),strrev( $template['before_vote_template']),1);
902
+ $template['after_vote_template'] = "[QUESTION_CONTAINER]" . $template['after_vote_template'];
903
+ $template['after_end_date_template'] = "[QUESTION_CONTAINER]" . $template['after_end_date_template'];
904
/* if(strpos($template['before_vote_template'],"[CAPTCHA_CONTAINER]"))
905
$template['before_vote_template']=str_replace('[CAPTCHA_CONTAINER]','[/QUESTION_CONTAINER][CAPTCHA_CONTAINER]',$template['before_vote_template']);
906
else{
907
$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']);
908
} */
909
+ $template['before_vote_template'] = $template['before_vote_template'] . '[/QUESTION_CONTAINER]';
910
+ if (strpos($template['before_vote_template'], "%POLL-QUESTION%") && strpos($template['before_vote_template'], '%POLL-NAME%')) {
911
+ $template['before_vote_template'] = str_replace('%POLL-QUESTION%', '', $template['before_vote_template']);
912
+ $template['before_vote_template'] = str_replace('%POLL-NAME%', '%POLL-QUESTION%', $template['before_vote_template']);
913
}
914
+ if (strpos($template['after_vote_template'], "%POLL-QUESTION%") && strpos($template['after_vote_template'], '%POLL-NAME%')) {
915
+ $template['after_vote_template'] = str_replace('%POLL-QUESTION%', '', $template['after_vote_template']);
916
+ $template['after_vote_template'] = str_replace('%POLL-NAME%', '%POLL-QUESTION%', $template['after_vote_template']);
917
}
918
+ $template['after_vote_template'] = $template['after_vote_template'] . '[/QUESTION_CONTAINER]';
919
+ $template['after_end_date_template'] = $template['after_end_date_template'] . '[/QUESTION_CONTAINER]';
920
+ $template['js'] = <<<NOWDOC
921
function stripBorder_%POLL-ID%(object) {
922
object.each(function() {
923
if( parseInt(jQuery(this).width() ) > 0) {
1073
};
1074
1075
NOWDOC;
1076
+ $template['js'] = addslashes($template['js']);
1077
+ $templates_ids[$template['id']] = self::insert_template_in_databease(($template));
1078
}
1079
1080
+ foreach ($polls as $poll) {
1081
1082
+ foreach ($answers as $answer) {
1083
+ if ($answer['poll_id'] == $poll['id']) {
1084
$answers_ordonate[$poll['id']][] = (array)$answer;
1085
}
1086
+ if ($answer['poll_id'] > $poll['id']) {
1087
break;
1088
}
1089
1090
+ foreach ($logs as $log) {
1091
+ if ($log['poll_id'] == $poll['id'] && $log['answer_id'] == $answer['id']) {
1092
+ $logs_ordonate[$poll['id']][] = (array)$log;
1093
$logs_ordonate_details[$log['id']][] = $answer['answer'];
1094
}
1095
}
1096
+ foreach ($answers_meta as $answer_meta) {
1097
+ if ($answer_meta['yop_poll_answer_id'] == $answer['id']) {
1098
$answer_meta_ordonate[$answer['id']][] = (array)$answer_meta;
1099
}
1100
}
1101
}
1102
1103
+ foreach ($bans as $ban) {
1104
+ if ($ban['poll_id'] == $poll['id']) {
1105
$bans_ordonate[$poll['id']][] = (array)$ban;
1106
}
1107
+ if ($ban['poll_id'] > $poll['id']) {
1108
break;
1109
}
1110
}
1111
1112
+ foreach ($metas as $meta) {
1113
+ if ($meta['yop_poll_id'] == $poll['id']) {
1114
$metas_ordonate[$poll['id']][] = (array)$meta;
1115
}
1116
+ if ($meta['yop_poll_id'] > $poll['id']) {
1117
break;
1118
}
1119
}
1120
1121
+ foreach ($custom_fields as $custom_field) {
1122
+ if ($custom_field['poll_id'] == $poll['id']) {
1123
$custom_fields_ordonate[$poll['id']][] = (array)$custom_field;
1124
+ if ($custom_field['poll_id'] > $poll['id']) {
1125
break;
1126
}
1127
1128
+ foreach ($custom_votes as $custom_vote) {
1129
+ if ($custom_field['id'] == $custom_vote['custom_field_id']) {
1130
$custom_votes_fields_ordonate[$custom_field['id']][] = (array)$custom_vote;
1131
}
1132
}
1135
}
1136
1137
1138
+ foreach ($polls as $poll) {
1139
+ $current_poll = new YOP_POLL_Poll_Model();
1140
+ $current_poll->poll_author = $poll['poll_author'];
1141
+ $current_poll->ID = $poll['id'];
1142
+ $current_poll->poll_title = $poll['name'];
1143
+ $current_poll->poll_name = $poll['name'];
1144
+ $current_poll->poll_date = $poll['date_added'];
1145
$current_poll->poll_modified = $poll['last_modified'];
1146
+ $current_poll->poll_status = $poll['status'];
1147
+ $current_poll->poll_type = "poll";
1148
+ $current_poll->poll_status = $poll['status'];
1149
+ $current_poll->email_notifications_body = '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
1150
1151
<p>Vote Details:</p>
1152
1177
[/QUESTION]
1178
1179
<p><b>Vote ID:</b> <br />%VOTE_ID%</p>';
1180
+ if ($poll['end_date'] <= "2038-01-18 23:59:59") {
1181
1182
+ $current_poll->poll_end_date = convert_date($poll['end_date'], 'd-m-Y H:i:s', 1);
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
+ } else {
1195
1196
$current_poll->poll_start_date = "01-01-2038 23:59:59";
1197
1198
}
1199
$current_poll->poll_total_votes = $poll['total_votes'];
1200
+ $question = new YOP_POLL_Question_Model();
1201
+ $question->type = "text";
1202
+ $question->question = $poll['question'];
1203
+ $question->question_date = $current_poll->poll_date;
1204
+ $question->question_author = $current_poll->poll_author;
1205
+ $question->question_modified = $current_poll->poll_modified;
1206
+ $question->question_status = $current_poll->poll_status;
1207
+ $question->poll_order = 1;
1208
+ $i = 0;
1209
+
1210
+
1211
+ foreach ($answers_ordonate[$poll['id']] as $answer_ordonate) {
1212
+
1213
+ if ($answer_ordonate['type'] == "other") {
1214
+ $current_poll->allow_other_answers = 'yes';
1215
+ $question->allow_other_answers = 'yes';
1216
}
1217
}
1218
+ $q[] = $question;
1219
// yop_poll_dump($current_poll);
1220
$current_poll->questions = $q;
1221
+ $current_poll->auto_generate_poll_page = "no";
1222
+ $current_poll_id = $current_poll->insert();
1223
+ $current_poll_id = $current_poll->ID;
1224
// yop_poll_dump($current_poll->save())
1225
+ $no_modif = 0;
1226
+ $no_modif2 = 0;
1227
+ $current_poll_meta = $current_options;
1228
+ if (isset($metas_ordonate[$poll['id']])) {
1229
+ $poll_option = maybe_unserialize($metas_ordonate[$poll['id']][0]['meta_value']);
1230
+ foreach ($current_options as $key => $value) {
1231
+ if (isset($poll_option[$key])) {
1232
1233
+ if ($key == 'view_results_permissions') {
1234
1235
+ list($g1, $d) = explode('-', $poll_option[$key]);
1236
+ if ($g1 == "quest") {
1237
+ $g1 = "guest";
1238
1239
}
1240
1241
+ $current_poll_meta[$key] = array($g1, $d);
1242
+ $no_modif = 1;
1243
1244
+ } else
1245
+ if ($key == 'vote_permisions') {
1246
+ list($g1, $d) = explode('-', $poll_option['vote_permisions']);
1247
+ if ($g1 == "quest") {
1248
+ $g1 = "guest";
1249
1250
}
1251
+ $no_modif2 = 1;
1252
+ $current_poll_meta[$key] = array($g1, $d);
1253
+ } else
1254
$current_poll_meta[$key] = $poll_option[$key];
1255
1256
1257
} else
1258
+ $current_poll_meta[$key] = $default[$key];
1259
}
1260
}
1261
+ $current_poll_meta['view_results'] = array($poll_option['view_results']);
1262
$current_poll_meta['sorting_results'] = $default['sorting_answers'];
1263
+ if (!isset($poll_option['view_results_link'])) {
1264
+ $current_poll_meta['view_results_link'] = "yes";
1265
+ } else
1266
+ $current_poll_meta['view_results_link'] = $poll_option['view_results_link'];
1267
+
1268
+ if ($poll_option['view_results'] == 'custom-date')
1269
+ $current_poll_meta['view_results_start_date'] = $poll_option['view_results_start_date'];
1270
+ if (empty($current_poll_meta['view_results'][0])) {
1271
$current_poll_meta['view_results'] = array('after');
1272
}
1273
+ if ($no_modif == 0 || empty($current_poll_meta['view_results'])) {
1274
+ $current_poll_meta['view_results_permissions'] = array('guest', 'registered');
1275
1276
}
1277
1278
+ if ($no_modif2 == 0 || empty($current_poll_meta['vote_permisions'])) {
1279
+ $current_poll_meta['vote_permisions'] = array('guest', 'registered');
1280
}
1281
1282
+ if ($poll_option['blocking_voters'] == 'cookie-ip')
1283
+ $current_poll_meta['blocking_voters'] = array("cookie", 'ip');
1284
else {
1285
+ if ($poll_option['blocking_voters'] == 'username')
1286
+ $current_poll_meta['blocking_voters'] = array("user_id");
1287
else
1288
+ $current_poll_meta['blocking_voters'] = array('dont-block');
1289
}
1290
+ $current_poll_meta['facebook_share_after_vote'] = "no";
1291
+ $current_poll_meta['show_google_share_button'] = "no";
1292
+ $current_poll_meta['facebook_show_comments_widget'] = "no";
1293
+ $current_poll_meta['facebook_share_description'] = __yop_poll('Just casted an YOP Poll vote on ') . get_bloginfo('name');
1294
+ if (isset($poll_option['show_in_archive']))
1295
+ $current_poll_meta['show_poll_in_archive'] = $poll_option['show_in_archive'];
1296
+ if (isset($poll_option['schedule_reset_poll_date']))
1297
+ $current_poll_meta['schedule_reset_poll_date'] = $poll_option['schedule_reset_poll_date'];
1298
+ if (isset($poll_option['template'])) {
1299
+ $current_poll_meta['template'] = $templates_ids[$poll_option['template']];
1300
+ } else $current_poll_meta['template'] = 1;
1301
+ if (isset($poll_option['widget_template'])) {
1302
+ $current_poll_meta['widget_template'] = $templates_ids[$poll_option['widget_template']];
1303
+ } else $current_poll_meta['widget_template'] = 1;
1304
+ if (isset($poll_option['widget_template']) && isset($poll_option['template']) && $poll_option['template'] != $poll_option['widget_template']) {
1305
+ $current_poll_meta['use_the_same_template_for_widget'] = "no";
1306
}
1307
+ if (isset($poll_option['view_total_answers_label'])) {
1308
+ $current_poll_meta['view_total_answers_label'] = $default['view_total_answers_label'];
1309
}
1310
+ if (isset($poll_option['answer_result_label'])) {
1311
+ $current_poll_meta['answer_result_label'] = $default['answer_result_label'];
1312
}
1313
+ if ($current_poll_meta['vote_permisions_anonymous'] == "no" && $current_poll_meta['vote_permisions_wordpress'] == "no") {
1314
+ $current_poll_meta['vote_permisions_anonymous'] = "yes";
1315
}
1316
+ update_yop_poll_question_meta($current_poll_id, 'options', $current_poll_meta);
1317
+ update_yop_poll_meta($current_poll_id, 'options', $current_poll_meta);
1318
+ if ($poll['show_in_archive'] == "yes") {
1319
+ self::save_poll_order($current_poll_id, $poll['archive_order']);
1320
}
1321
1322
+ if ($default['sorting_answers'] == "votes") {
1323
+ $answers_ordonate[$poll['id']] = self::get_answers_order_by_votes($poll['id'], $default['sorting_answers_direction']);
1324
+ }
1325
+ if ($default['sorting_answers'] == "alphabetical") {
1326
+ $answers_ordonate[$poll['id']] = self::get_answers_order_by_alph($poll['id'], $default['sorting_answers_direction']);
1327
}
1328
+ foreach ($answers_ordonate[$poll['id']] as $answer_ordonate) {
1329
+ $ans = new YOP_POLL_Answer_Model();
1330
+ $ans->answer = $answer_ordonate['answer'];
1331
+ $ans->answer_author = $current_poll->poll_author;
1332
+ $ans->answer_date = $current_poll->poll_date;
1333
$ans->answer_modified = $poll['last_modified'];
1334
+ if ($answer_ordonate['type'] != "other") {
1335
$ans->type = "text";
1336
+ } else {
1337
+ $current_poll->allow_other_answers = 'yes';
1338
+ $question->allow_other_answers = 'yes';
1339
$ans->type = "other";
1340
}
1341
+ $ans->answer_status = $answer['status'];
1342
+ $ans->votes = $answer_ordonate['votes'];
1343
+ $ans->question_order = $i++;
1344
1345
+ if ($answer_ordonate['type'] != "other") {
1346
$answersa[] = $ans;
1347
+ if (isset($answer_meta_ordonate[$answer_ordonate['id']])) {
1348
+ $answer_option = maybe_unserialize($answer_meta_ordonate[$answer_ordonate['id']][0]['meta_value']);
1349
$answer_options = $ans->options;
1350
+ foreach ($ans->options as $key => &$value) {
1351
+ if (isset($answer_option[$key])) {
1352
$ans->$key = $answer_option[$key];
1353
}
1354
1356
$ans->options = $answer_options;
1357
}
1358
1359
+ $question->addAnswer($ans);
1360
1361
$question->save_answers();
1362
$answersids[$answer_ordonate['id']] = $ans->ID;
1363
}
1364
1365
}
1366
+ if (!empty($custom_fields_ordonate[$poll['id']]))
1367
+ foreach ($custom_fields_ordonate[$poll['id']] as $custom_ordonate) {
1368
+ $oldid = $custom_ordonate['id'];
1369
+ // $question = $current_poll->questions;
1370
+ $custom_ordonate['question_id'] = $current_poll_id;
1371
+ $custom_ordonate['poll_id'] = $current_poll_id;
1372
+ $newid = insert_custom_field_in_db($custom_ordonate);
1373
+ foreach ($custom_votes_fields_ordonate[$oldid] as $votes) {
1374
+ $votes['custom_field_id'] = $newid;
1375
+ $votes['question_id'] = $current_poll_id;
1376
+ $votes['poll_id'] = $current_poll_id;
1377
+ $votes['id'] = insert_votes_custom_in_db($votes);
1378
+ $custom_field_vote[$poll['id']][] = $votes;
1379
+ }
1380
}
1381
1382
+ if (!empty($logs_ordonate[$poll['id']]))
1383
+ foreach ($logs_ordonate[$poll['id']] as $log_ordonate) {
1384
+ $log['poll_id'] = $current_poll_id;
1385
+ $log['vote_id'] = $log_ordonate['vote_id'];
1386
+ $log['ip'] = $log_ordonate['ip'];
1387
+ $log['user_id'] = $log_ordonate['user_id'];
1388
+ $log['user_type'] = $log_ordonate['user_type'];
1389
+ $log['vote_date'] = $log_ordonate['vote_date'];
1390
+ $log['tr_id'] = $log_ordonate['tr_id'];
1391
+ $vote_details[1]["q-" . $current_poll_id]['question'] = $poll['question'];
1392
+ $vote_details[1]["q-" . $current_poll_id]['id'] = $current_poll_id;
1393
+ $vote_details[1]["q-" . $current_poll_id]['a'][] = $answersids[$log_ordonate['answer_id']];
1394
+ if ($log_ordonate['other_answer_value'] != "" && isset($log_ordonate['other_answer_value'])) {
1395
+ $ans = new YOP_POLL_Answer_Model();
1396
+ $ans->answer = $answer_ordonate['answer'];
1397
+ $ans->answer_author = $current_poll->poll_author;
1398
+ $ans->answer_date = $current_poll->poll_date;
1399
+ $ans->answer_modified = $poll['last_modified'];
1400
+ $ans->answer = $log_ordonate['other_answer_value'];
1401
+ $ans->answer_status = 'active';
1402
+ $ans->votes = 1;
1403
+ $ans->type = 'other';
1404
+ $ans->question_order = $i++;
1405
+ $question->addAnswer($ans);
1406
+ $question->save_answers();
1407
}
1408
+ if (!empty($custom_field_vote[$poll['id']]))
1409
+ foreach ($custom_field_vote[$poll['id']] as $vote) {
1410
+ if ($vote['vote_id'] == $log_ordonate['vote_id']) {
1411
+ $vote_details[1]["q-" . $current_poll_id]['cf'][] = $vote['id'];
1412
+ }
1413
1414
+ }
1415
+ foreach ($logs_ordonate_details[$log_ordonate['id']] as $a) {
1416
+ $vote_details[1]["q-" . $current_poll_id]['answers'][] = $a;
1417
+ $log['vote_details'] = json_encode($vote_details[1]);
1418
+ $log['message'] = "Succes";
1419
+ insert_result_in_db($log);
1420
+ insert_log_in_db($log);
1421
+ unset($vote_details[1]["q-" . $current_poll_id]['answers']);
1422
+ }
1423
+ unset($vote_details);
1424
}
1425
+ if (!empty($bans_ordonate[$poll['id']]))
1426
+ foreach ($bans_ordonate[$poll['id']] as $ban_ordonate) {
1427
+ $ban = $ban_ordonate;
1428
+ $ban['poll_id'] = $current_poll_id;
1429
+ self::insert_ban_in_db($ban);
1430
}
1431
1432
1433
}
1434
1435
}
1436
1437
+ public function insert_template_in_databease($template)
1438
+ {
1439
global $wpdb;
1440
+ $sql = $wpdb->query($wpdb->prepare("
1441
INSERT INTO " . $wpdb->yop_poll_templates . "
1442
SET
1443
template_author = %d,
1451
date_added = %s,
1452
last_modified = %s,
1453
status = %s
1454
+ ", $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']));
1455
return $GLOBALS['wpdb']->insert_id;
1456
}
1457
+
1458
+ private static function update_poll_template_in_database($template)
1459
+ {
1460
global $wpdb;
1461
+ $sql = $wpdb->query($wpdb->prepare("
1462
UPDATE " . $wpdb->yop_poll_templates . "
1463
SET name = %s,
1464
before_vote_template = %s,
1470
last_modified = %s
1471
WHERE
1472
id = %d
1473
+ ", $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']));
1474
return $sql;
1475
}
1476
+
1477
+ public function yop_poll_get_polls_from_db()
1478
+ {
1479
global $wpdb;
1480
+ $result = $wpdb->get_results(("
1481
SELECT *
1482
FROM " . $wpdb->prefix . "yop_polls ORDER BY id ASC
1483
+ "), ARRAY_A);
1484
return $result;
1485
1486
}
1487
1488
+ public function yop_poll_get_polls_meta_from_db()
1489
+ {
1490
global $wpdb;
1491
+ $result = $wpdb->get_results(("
1492
SELECT *
1493
FROM " . $wpdb->prefix . "yop_pollmeta ORDER BY yop_poll_id ASC
1494
+ "), ARRAY_A);
1495
return $result;
1496
1497
}
1498
1499
+ public function yop_poll_get_answers_meta_from_db()
1500
+ {
1501
global $wpdb;
1502
1503
+ $result = $wpdb->get_results(("
1504
SELECT *
1505
FROM " . $wpdb->prefix . "yop_poll_answermeta
1506
+ "), ARRAY_A);
1507
return $result;
1508
1509
}
1510
1511
+ public function yop_poll_get_templates_from_db()
1512
+ {
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
+
1521
+ public function yop_poll_get_templates_new_version_from_db()
1522
+ {
1523
global $wpdb;
1524
+ $result = $wpdb->get_results(("
1525
SELECT *
1526
FROM " . $wpdb->yop_poll_templates
1527
+ ), ARRAY_A);
1528
return $result;
1529
}
1530
1531
+ public function yop_poll_get_custom_fields_from_db()
1532
+ {
1533
global $wpdb;
1534
+ $result = $wpdb->get_results(("
1535
SELECT *
1536
FROM " . $wpdb->prefix . "yop_poll_custom_fields ORDER BY poll_id ASC
1537
+ "), ARRAY_A);
1538
return $result;
1539
}
1540
1541
+ public function yop_poll_get_custom_fields_votes_from_db()
1542
+ {
1543
global $wpdb;
1544
+ $result = $wpdb->get_results(("
1545
SELECT *
1546
FROM " . $wpdb->prefix . "yop_poll_votes_custom_fields
1547
+ "), ARRAY_A);
1548
return $result;
1549
}
1550
1551
+ public function yop_poll_get_bans_from_db()
1552
+ {
1553
global $wpdb;
1554
+ $result = $wpdb->get_results(("
1555
SELECT *
1556
FROM " . $wpdb->prefix . "yop_poll_bans ORDER BY poll_id ASC
1557
+ "), ARRAY_A);
1558
return $result;
1559
}
1560
+
1561
+ public function yop_poll_get_answers_from_db()
1562
+ {
1563
global $wpdb;
1564
+ $result = $wpdb->get_results(("
1565
SELECT *
1566
FROM " . $wpdb->prefix . "yop_poll_answers ORDER BY poll_id ASC
1567
+ "), ARRAY_A);
1568
return $result;
1569
}
1570
+
1571
+ public function get_answers_order_by_votes($poll_id, $dir)
1572
+ {
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 votes $dir
1577
+ ", $poll_id), ARRAY_A);
1578
return $result;
1579
}
1580
1581
+ public function get_answers_order_by_alph($poll_id, $dir)
1582
+ {
1583
global $wpdb;
1584
+ $result = $wpdb->get_results($wpdb->prepare("
1585
SELECT *
1586
FROM " . $wpdb->prefix . "yop_poll_answers WHERE poll_id=%d ORDER BY answer $dir
1587
+ ", $poll_id), ARRAY_A);
1588
return $result;
1589
}
1590
1591
+ public function yop_poll_get_logs_from_db()
1592
+ {
1593
global $wpdb;
1594
+ $result = $wpdb->get_results(("
1595
SELECT *
1596
FROM " . $wpdb->prefix . "yop_poll_logs
1597
+ "), ARRAY_A);
1598
return $result;
1599
}
1600
1601
+ private static function insert_ban_in_db($ban)
1602
+ {
1603
global $wpdb;
1604
+ $sql = $wpdb->query($wpdb->prepare("
1605
INSERT INTO $wpdb->yop_poll_bans
1606
( poll_id,type,value,period ,unit)
1607
VALUES(%d,%s,%s,%d,%s)
1608
+ ", $ban['poll_id'], $ban['type'], $ban['value'], intval($ban['period']), $ban['unit']));
1609
+ return $wpdb->get_results($sql);
1610
}
1611
+
1612
+ private function save_poll_order($poll, $poll_order)
1613
+ {
1614
+ $poll_archive_order = get_option('yop_poll_archive_order', array());
1615
+ if ($poll_archive_order == "") {
1616
$poll_archive_order = array();
1617
}
1618
+ if (trim($poll_order) <= 0) {
1619
+ $poll_order = 1;
1620
}
1621
+ $key = array_search($poll, $poll_archive_order);
1622
+ if ($key !== false) {
1623
+ unset($poll_archive_order[$key]);
1624
}
1625
+ if ($poll_order > count($poll_archive_order)) {
1626
+ array_push($poll_archive_order, $poll);
1627
+ } else {
1628
+ array_splice($poll_archive_order, trim($poll_order) - 1, 0, array($poll));
1629
}
1630
+ update_option('yop_poll_archive_order', $poll_archive_order);
1631
}
1632
1633
}
inc/poll_admin.php CHANGED
@@ -1046,6 +1046,7 @@ class YOP_POLL_Poll_Admin extends YOP_POLL_Abstract_Admin {
1046
$question->ID = 0;
1047
foreach( $question->answers as $answer ) {
1048
$answer->ID = 0;
1049
}
1050
if(isset($question->custom_fields))
1051
foreach($question->custom_fields as $custom){
@@ -1054,8 +1055,8 @@ class YOP_POLL_Poll_Admin extends YOP_POLL_Abstract_Admin {
1054
$custom->question_id=0;
1055
}
1056
}
1057
-
1058
- $id_poll=$poll_clone->save();
1059
self::save_poll_order($poll_clone,$poll_clone->poll_archive_order);
1060
update_yop_poll_meta( $id_poll, 'options', $meta );
1061
1046
$question->ID = 0;
1047
foreach( $question->answers as $answer ) {
1048
$answer->ID = 0;
1049
+ $answer->votes = 0;
1050
}
1051
if(isset($question->custom_fields))
1052
foreach($question->custom_fields as $custom){
1055
$custom->question_id=0;
1056
}
1057
}
1058
+ $is_clone=true;
1059
+ $id_poll=$poll_clone->save($is_clone);
1060
self::save_poll_order($poll_clone,$poll_clone->poll_archive_order);
1061
update_yop_poll_meta( $id_poll, 'options', $meta );
1062
inc/public-admin.php CHANGED
@@ -159,15 +159,15 @@
159
160
$args = array(
161
'base' => remove_query_arg( 'yop_poll_page', $_SERVER['REQUEST_URI'] ) . '%_%',
162
- 'format' => '&&yop_poll_page=%#%',
163
'total' => $total_per_page,
164
'current' => max( 1, $yop_poll_page ),
165
'prev_next' => true,
166
'prev_text' => __( '&laquo; Previous', 'yop_poll' ),
167
'next_text' => __( 'Next &raquo;', 'yop_poll' )
168
);
169
- $temp = "";
170
171
if($ok==1){
172
for( $i = ( $args['current'] - 1 ) * $per_page; $i <= ( $args['current'] - 1 ) * $per_page + $per_page - 1; $i ++ ) {
173
if(isset($archives[$i]['ID']))
159
160
$args = array(
161
'base' => remove_query_arg( 'yop_poll_page', $_SERVER['REQUEST_URI'] ) . '%_%',
162
+ 'format' => '&yop_poll_page=%#%',
163
'total' => $total_per_page,
164
'current' => max( 1, $yop_poll_page ),
165
'prev_next' => true,
166
'prev_text' => __( '&laquo; Previous', 'yop_poll' ),
167
'next_text' => __( 'Next &raquo;', 'yop_poll' )
168
);
169
170
+ $temp = "<style> .yop-poll-container{display:block !important;}.yop-poll-footer{display: inline-block;margin: auto;text-align: center;width: 100%;}</style>";
171
if($ok==1){
172
for( $i = ( $args['current'] - 1 ) * $per_page; $i <= ( $args['current'] - 1 ) * $per_page + $per_page - 1; $i ++ ) {
173
if(isset($archives[$i]['ID']))
js/yop-poll-general-options.js CHANGED
@@ -314,7 +314,7 @@ jQuery( document ).ready( function() {
314
jQuery('#yop-poll-email-notifications-body').textcomplete([
315
316
{ // tech companies
317
- words: ['%VOTE_DATE%', '%POLL_NAME%', '[ QUESTION ] ','[/QUESTION]', '[ ANSWERS ]', ' %ANSWER_VALUE%', '[/ANSWERS]','[ CUSTOM_FIELDS ]','%CUSTOM_FIELD_NAME%','%CUSTOM_FIELD_VALUE%','[/CUSTOM_FIELDS]'],
318
match: /(\[|%)(\w*)#x2F;,
319
search: function (term, callback) {
320
callback(jQuery.map(this.words, function (word) {
314
jQuery('#yop-poll-email-notifications-body').textcomplete([
315
316
{ // tech companies
317
+ words: ['%VOTE_DATE%', '%POLL_NAME%','%POLL_TOTAL_VOTES%','%WP_USERNAME%','%WP_FIRST_NAME%','%WP_LAST_NAME%', '[ QUESTION ] ','[/QUESTION]', '[ ANSWERS ]', ' %ANSWER_VALUE%', '[/ANSWERS]','[ CUSTOM_FIELDS ]','%CUSTOM_FIELD_NAME%','%CUSTOM_FIELD_VALUE%','[/CUSTOM_FIELDS]'],
318
match: /(\[|%)(\w*)#x2F;,
319
search: function (term, callback) {
320
callback(jQuery.map(this.words, function (word) {
lib/Twig/AutoloaderYOP.php ADDED
@@ -0,0 +1,48 @@
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of Twig.
5
+ *
6
+ * (c) 2009 Fabien Potencier
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ /**
13
+ * Autoloads Twig classes.
14
+ *
15
+ * @author Fabien Potencier <fabien@symfony.com>
16
+ */
17
+ class Yop_Twig_Autoloader
18
+ {
19
+ /**
20
+ * Registers Twig_Autoloader as an SPL autoloader.
21
+ *
22
+ * @param Boolean $prepend Whether to prepend the autoloader or not.
23
+ */
24
+ public static function register($prepend = false)
25
+ {
26
+ if (version_compare(phpversion(), '5.3.0', '>=')) {
27
+ spl_autoload_register(array(new self, 'autoload'), true, $prepend);
28
+ } else {
29
+ spl_autoload_register(array(new self, 'autoload'));
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Handles autoloading of classes.
35
+ *
36
+ * @param string $class A class name.
37
+ */
38
+ public static function autoload($class)
39
+ {
40
+ if (0 !== strpos($class, 'Twig')) {
41
+ return;
42
+ }
43
+
44
+ if (is_file($file = dirname(__FILE__).'/../'.str_replace(array('_', "\0"), array('/', ''), $class).'.php')) {
45
+ require $file;
46
+ }
47
+ }
48
+ }
models/abstract_model.php CHANGED
@@ -1,44 +1,36 @@
1
<?php
2
- abstract class YOP_POLL_Abstract_Model {
3
4
5
6
protected $data = null;
7
8
9
-
10
protected $options = null;
11
12
13
-
14
protected $questions = null;
15
16
17
-
18
protected $ID = null;
19
20
21
-
22
protected $unique_id = null;
23
24
25
-
26
protected $vote = false;
27
28
29
-
30
protected $type = 'quiz';
31
32
33
-
34
protected $error = "";
35
36
37
-
38
protected $success = "";
39
40
41
-
42
private $default_fields = array(
43
44
'ID',
@@ -70,165 +62,156 @@ abstract class YOP_POLL_Abstract_Model {
70
);
71
72
73
74
- function __construct( $id = 0, $is_view_results = "no", $question_sort = "poll_order", $question_sort_rule = "ASC", $answer_sort = "question_order", $answer_sort_rule = "ASC" ) {
75
76
- if( $id instanceof YOP_POLL_Abstract_Model ) {
77
-
78
- $this->init( $id->data, $is_view_results, $question_sort, $question_sort_rule, $answer_sort, $answer_sort_rule );
79
80
return;
81
82
- }
83
-
84
- elseif( is_object( $id ) ) {
85
86
- $this->init( $id, $is_view_results, $question_sort, $question_sort_rule, $answer_sort, $answer_sort_rule );
87
88
return;
89
90
}
91
92
93
-
94
- if( ! empty( $id ) && ! is_numeric( $id ) ) {
95
96
$id = 0;
97
98
}
99
100
- if($id=="-3"){
101
102
103
- $filters = array();
104
$filters[] = array(
105
- 'field' => 'poll_type',
106
- 'value' => 'poll',
107
'operator' => '='
108
);
109
110
111
$filters[] = array(
112
- 'field' => 'poll_start_date',
113
- 'value' => current_time( 'mysql' ),
114
'operator' => '<='
115
);
116
$args = array(
117
'return_fields' => 'ID ',
118
- 'filters' => $filters,
119
- 'search' => array(
120
-
121
- ),
122
- 'orderby' => "poll_start_date",
123
- 'order' => 'DESC'
124
);
125
126
- $total_polls = Yop_Poll_Model::get_polls_filter_search( $args );
127
- $ok=0;
128
$current_date = yop_poll_get_mysql_curent_date();
129
130
- if( count($total_polls)>1) {
131
- while($ok==0){
132
- $id=rand ( 1 , count($total_polls));
133
- $poll=new YOP_POLL_Poll_Model($id);
134
- if( $current_date <= convert_date( $poll->poll_end_date, 'Y-m-d H:i:s' ) ) {
135
- $ok=1;
136
}
137
- }
138
- }
139
- else
140
- $id=rand ( 1 , count($total_polls));
141
}
142
- if($id=="-2"){
143
144
145
- $filters = array();
146
$filters[] = array(
147
- 'field' => 'poll_type',
148
- 'value' => 'poll',
149
'operator' => '='
150
);
151
152
$filters[] = array(
153
- 'field' => 'poll_start_date',
154
- 'value' => current_time( 'mysql' ),
155
'operator' => '<='
156
);
157
158
$args = array(
159
'return_fields' => 'ID ',
160
- 'filters' => $filters,
161
- 'search' => array(
162
-
163
- ),
164
- 'orderby' => "poll_date",
165
- 'order' => 'ASC'
166
);
167
168
- $total_polls = Yop_Poll_Model::get_polls_filter_search( $args );
169
- $id=$total_polls[count($total_polls)-1]['ID'] ;
170
}
171
- if($id=="-1"){
172
173
174
- $poll = self::get_current_active_poll( );
175
- $id=$poll['ID'];
176
}
177
178
179
- $data = self::get_data_by( 'id', $id );
180
181
- if( $data ) {
182
183
- $this->init( $data, $is_view_results, $question_sort, $question_sort_rule, $answer_sort, $answer_sort_rule );
184
185
- }
186
-
187
- else {
188
189
$this->default_init();
190
191
}
192
193
194
195
- $this->poll_start_date = convert_date( $this->poll_start_date, "Y-m-d H:i:s" );
196
-
197
- $this->poll_end_date = convert_date( $this->poll_end_date, "Y-m-d H:i:s" );
198
199
}
200
201
- public static function get_current_active_poll( $offset = 0 ) {
202
global $wpdb;
203
$current_date = self::get_mysql_curent_date();
204
- return $wpdb->get_row( $wpdb->prepare( "
205
SELECT * FROM " . $wpdb->yop_polls . "
206
WHERE
207
%s >= poll_start_date AND
208
%s <= poll_end_date
209
ORDER BY
210
poll_date ASC
211
- ", $current_date, $current_date ), ARRAY_A, $offset );
212
}
213
214
215
- function init( $data, $is_view_results, $question_sort, $question_sort_rule, $answer_sort, $answer_sort_rule ) {
216
217
$this->data = $data;
218
219
- $this->ID = (int)$data->ID;
220
221
$this->init_options();
222
223
- if( 'yes' == $is_view_results ) {
224
225
- switch( $this->sorting_results ) {
226
227
case "database":
228
229
{
230
231
- $answer_sort = 'ID';
232
233
$answer_sort_rule = $this->sorting_results_direction;
234
@@ -240,7 +223,7 @@ abstract class YOP_POLL_Abstract_Model {
240
241
{
242
243
- $answer_sort = 'answer';
244
245
$answer_sort_rule = $this->sorting_results_direction;
246
@@ -252,7 +235,7 @@ abstract class YOP_POLL_Abstract_Model {
252
253
{
254
255
- $answer_sort = 'votes';
256
257
$answer_sort_rule = $this->sorting_results_direction;
258
@@ -264,7 +247,7 @@ abstract class YOP_POLL_Abstract_Model {
264
265
{
266
267
- $answer_sort = "question_order";
268
269
$answer_sort_rule = "ASC";
270
@@ -278,15 +261,15 @@ abstract class YOP_POLL_Abstract_Model {
278
279
$this->questions = array();
280
281
- $questions_ids = $this->load_questions_ids( $question_sort, $question_sort_rule );
282
283
- if( $questions_ids && count( $questions_ids ) > 0 ) {
284
285
- foreach( $questions_ids as $question_id ) {
286
287
- $new_question = new YOP_POLL_Question_Model( $question_id, $answer_sort, $answer_sort_rule );
288
289
- if( $new_question ) {
290
291
$this->questions[] = $new_question;
292
@@ -299,50 +282,48 @@ abstract class YOP_POLL_Abstract_Model {
299
}
300
301
302
-
303
- function default_init() {
304
305
$this->data = new stdClass();
306
307
- $this->ID = null;
308
309
$this->init_options();
310
311
- $this->questions = array();
312
313
$this->data->poll_start_date = $this->options['poll_start_date'];
314
315
- $this->data->poll_end_date = $this->options['poll_end_date'];
316
317
}
318
319
320
321
- function init_options() {
322
-
323
- $this->options = array();
324
325
$poll_default_options = yop_poll_poll_default_options();
326
327
328
329
- $poll_archive_order = get_option( 'yop_poll_archive_order', array() );
330
331
- $key = array_search( $this->ID, $poll_archive_order );
332
-
333
- if( $key !== false ) {
334
335
$this->options['poll_archive_order'] = $key + 1;
336
337
}
338
339
340
341
- if( $poll_default_options && count( $poll_default_options ) > 0 ) {
342
-
343
- foreach( $poll_default_options as $option_name => $option_value ) {
344
345
- $this->options[$option_name] = $this->get_option( $option_name );
346
347
}
348
@@ -351,66 +332,61 @@ abstract class YOP_POLL_Abstract_Model {
351
}
352
353
354
355
- function _unset() {
356
-
357
- $this->data = null;
358
359
- $this->ID = null;
360
361
$this->questions = null;
362
363
- $this->options = null;
364
365
$this->unique_id = null;
366
367
- $this->error = null;
368
-
369
- $this->success = null;
370
371
372
373
}
374
375
376
377
- static function get_data_by( $field, $value ) {
378
-
379
- if( 'id' == $field ) {
380
381
- if( ! is_numeric( $value ) ) {
382
383
return false;
384
385
}
386
387
- $value = intval( $value );
388
389
- if( $value < 1 ) {
390
391
return false;
392
393
}
394
395
- }
396
-
397
- else {
398
399
- $value = trim( $value );
400
401
}
402
403
404
-
405
- if( ! $value ) {
406
407
return false;
408
409
}
410
411
412
-
413
- switch( $field ) {
414
415
case 'id':
416
@@ -435,10 +411,9 @@ abstract class YOP_POLL_Abstract_Model {
435
}
436
437
438
439
- if( false !== $model_id ) {
440
-
441
- if( $model = wp_cache_get( $model_id, 'yop_poll_model' ) ) {
442
443
return $model;
444
@@ -447,17 +422,14 @@ abstract class YOP_POLL_Abstract_Model {
447
}
448
449
450
-
451
- if( ! $model = $GLOBALS['wpdb']->get_row( $GLOBALS['wpdb']->prepare( "SELECT * FROM {$GLOBALS['wpdb']->yop_polls} WHERE $db_field = %s", $value ) ) ) {
452
453
return false;
454
455
}
456
457
458
-
459
- wp_cache_add( $model_id, $model, 'yop_poll_model' );
460
-
461
462
463
return $model;
@@ -465,28 +437,26 @@ abstract class YOP_POLL_Abstract_Model {
465
}
466
467
468
469
- static function get_other_model_data_by( $field, $value, $current_model_id ) {
470
-
471
- $value = trim( $value );
472
473
474
-
475
- if( ! $value ) {
476
477
return false;
478
479
}
480
481
- if( intval( $current_model_id ) <= 0 ) {
482
483
return false;
484
485
}
486
487
488
-
489
- switch( $field ) {
490
491
case 'name':
492
@@ -503,184 +473,168 @@ abstract class YOP_POLL_Abstract_Model {
503
}
504
505
506
-
507
- if( ! $model = $GLOBALS['wpdb']->get_row( $GLOBALS['wpdb']->prepare( "SELECT * FROM {$GLOBALS['wpdb']->yop_polls} WHERE $db_field = %s AND ID != %d", $value, $current_model_id ) ) ) {
508
509
return false;
510
511
}
512
513
514
-
515
return $model;
516
517
}
518
519
520
521
- function __isset( $key ) {
522
-
523
- if( 'id' == strtolower( $key ) ) {
524
525
$key = 'ID';
526
527
}
528
529
- if( 'type' == $key ) {
530
531
$key = 'type';
532
533
}
534
535
536
-
537
- if( isset( $this->$key ) ) {
538
539
return true;
540
541
}
542
543
- if( isset( $this->data->$key ) ) {
544
545
return true;
546
547
}
548
549
550
-
551
- return $this->isset_option( $key );
552
553
}
554
555
556
-
557
- function isset_option( $key ) {
558
559
560
-
561
- if( isset( $this->options[$key] ) ) {
562
563
return true;
564
565
}
566
567
568
569
- $poll_options = get_yop_poll_meta( $this->ID, 'options', true );
570
-
571
- if( isset( $poll_options[$key] ) ) {
572
573
return true;
574
575
}
576
577
578
-
579
return false;
580
581
}
582
583
584
-
585
- function __get( $key ) {
586
587
$value = null;
588
589
- if( 'id' == strtolower( $key ) ) {
590
591
return $this->ID;
592
593
}
594
595
- if( 'type' == $key ) {
596
597
return $this->type;
598
599
}
600
601
- if( 'questions' == $key ) {
602
603
return $this->questions;
604