YOP Poll - Version 5.7.5

Version Description

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

Release Info

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

Code changes from version 5.7.4 to 5.7.5

css/yop-poll-slider.css CHANGED
@@ -198,7 +198,7 @@
198
 
199
  .yop-poll-pro-slider .yop-poll-pro-template-li p, .yop-poll-widget-slider .yop-poll-widget-template-li p, .yop-poll-buy-slider .yop-poll-buy-template-li p {
200
 
201
- margin: 0;
202
 
203
  padding: 3px;
204
 
@@ -532,6 +532,25 @@
532
  transition: all 0.3s linear;
533
 
534
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535
  li:before, li:after {
536
  -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
537
  }
198
 
199
  .yop-poll-pro-slider .yop-poll-pro-template-li p, .yop-poll-widget-slider .yop-poll-widget-template-li p, .yop-poll-buy-slider .yop-poll-buy-template-li p {
200
 
201
+ margin: 0 auto;
202
 
203
  padding: 3px;
204
 
532
  transition: all 0.3s linear;
533
 
534
  }
535
+
536
+ .yop-poll-page-template-buy p, .yop-poll-widget-template-buy p, .yop-poll-buy-template-buy p {
537
+
538
+ background: #00A8FF;
539
+
540
+ color: #FFF;
541
+
542
+ -webkit-transition: all 0.3s linear;
543
+
544
+ -moz-transition: all 0.3s linear;
545
+
546
+ -ms-transition: all 0.3s linear;
547
+
548
+ -o-transition: all 0.3s linear;
549
+
550
+ transition: all 0.3s linear;
551
+
552
+ }
553
+
554
  li:before, li:after {
555
  -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box;
556
  }
inc/maintenance.php CHANGED
@@ -1,23 +1,25 @@
1
  <?php
2
 
3
- class YOP_POLL_Maintenance {
 
4
 
5
- private function network_propagate( $pfunction, $networkwide ) {
6
- error_reporting( 0 );
7
- if( function_exists( 'is_multisite' ) && is_multisite() ) {
 
8
 
9
- if( $networkwide ) {
10
 
11
  $old_blog = $GLOBALS['wpdb']->blogid;
12
 
13
- $blogids = $GLOBALS['wpdb']->get_col( "SELECT blog_id FROM {$GLOBALS['wpdb']->blogs}" );
14
 
15
- foreach( $blogids as $blog_id ) {
16
 
17
- switch_to_blog( $blog_id );
18
 
19
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
20
- $version = get_option( "yop_poll_version" );
21
 
22
  /* if ( version_compare( $version, '4.9.2', '<=' ) &&isset($version)) {
23
  yop_poll_dump(12);
@@ -28,79 +30,66 @@ class YOP_POLL_Maintenance {
28
  } */
29
 
30
 
 
31
 
32
- $poll_archive_page = get_page_by_path( 'yop-poll-archive', ARRAY_A );
33
 
34
- if( ! $poll_archive_page ) {
35
 
36
- $_p = array();
37
 
38
- $_p['post_title'] = 'Yop Poll Archive';
39
 
40
- $_p['post_content'] = "[yop_poll_archive]";
41
 
42
- $_p['post_status'] = 'publish';
43
-
44
- $_p['post_type'] = 'page';
45
 
46
  $_p['comment_status'] = 'open';
47
 
48
- $_p['ping_status'] = 'open';
49
-
50
- $_p['post_category'] = array( 1 ); // the default 'Uncategorised'
51
-
52
 
 
53
 
54
- $poll_archive_page_id = wp_insert_post( $_p );
55
 
 
56
 
57
 
58
- }
59
-
60
- else {
61
 
62
  $poll_archive_page_id = $poll_archive_page['ID'];
63
 
64
  }
65
 
66
 
 
67
 
 
68
 
69
 
70
- call_user_func( array( $this, $pfunction ), $networkwide );
71
-
72
- $version = get_option( "yop_poll_version" );
73
-
74
-
75
-
76
 
77
-
78
- $default_options = get_option( 'yop_poll_options' );
79
-
80
- $default_options['archive_url'] = get_permalink( $poll_archive_page_id );
81
 
82
  $default_options['yop_poll_archive_page_id'] = $poll_archive_page_id;
83
 
84
 
85
-
86
  //addind default options
87
 
88
- update_option( 'yop_poll_options', $default_options );
89
-
90
 
91
 
92
  }
93
 
94
- switch_to_blog( $old_blog );
95
 
96
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
97
 
98
  return;
99
 
100
  }
101
  }
102
 
103
- $version = get_option( "yop_poll_version" );
104
 
105
  /* if ( version_compare( $version, '4.9.2', '<=' ) &&isset($version)) {
106
  yop_poll_dump(12);
@@ -112,180 +101,173 @@ class YOP_POLL_Maintenance {
112
  } */
113
 
114
 
 
115
 
 
116
 
 
117
 
118
- $poll_archive_page = get_page_by_path( 'yop-poll-archive', ARRAY_A );
119
 
120
- if( ! $poll_archive_page ) {
121
 
122
- $_p = array();
123
 
124
- $_p['post_title'] = 'Yop Poll Archive';
125
-
126
- $_p['post_content'] = "[yop_poll_archive]";
127
-
128
- $_p['post_status'] = 'publish';
129
-
130
- $_p['post_type'] = 'page';
131
 
132
  $_p['comment_status'] = 'open';
133
 
134
- $_p['ping_status'] = 'open';
135
-
136
- $_p['post_category'] = array( 1 ); // the default 'Uncategorised'
137
 
 
138
 
139
 
140
- $poll_archive_page_id = wp_insert_post( $_p );
141
 
142
 
143
-
144
- }
145
-
146
- else {
147
 
148
  $poll_archive_page_id = $poll_archive_page['ID'];
149
 
150
  }
151
 
152
 
153
-
154
  //addind default options
155
 
156
- call_user_func( array( $this, $pfunction ), $networkwide );
157
 
158
 
 
159
 
160
- $default_options = get_option( 'yop_poll_options' );
161
-
162
- $default_options['archive_url'] = get_permalink( $poll_archive_page_id );
163
 
164
  $default_options['yop_poll_archive_page_id'] = $poll_archive_page_id;
165
 
166
 
167
-
168
  //addind default options
169
 
170
- update_option( 'yop_poll_options', $default_options );
171
-
172
 
173
 
174
  }
175
 
176
- function propagate_activation( $networkwide ) {
 
177
  if (version_compare(phpversion(), '5.3', '<')) {
178
  wp_die("Php version isn't high enough!");
179
  }
180
 
181
- $this->network_propagate( 'activate', $networkwide );
182
 
183
  }
184
 
185
- function propagate_deactivation( $networkwide ) {
 
186
  global $wpdb;
187
  // $wpdb->query( "DROP TABLE `" . $wpdb->prefix . "yop_pollmeta`, `" . $wpdb->prefix . "yop_polls`, `" . $wpdb->prefix . "yop_poll_answermeta`, `" . $wpdb->prefix . "yop_poll_answers`, `" . $wpdb->prefix . "yop_poll_custom_fields`, `" . $wpdb->prefix . "yop_poll_logs`, `" . $wpdb->prefix . "yop_poll_voters`, `" . $wpdb->prefix . "yop_poll_bans`, `" . $wpdb->prefix . "yop_poll_templates`, `" . $wpdb->prefix . "yop_poll_votes_custom_fields`, `" . $wpdb->prefix . "yop_poll_facebook_users`" );
188
- $this->network_propagate( 'deactivate', $networkwide );
189
  }
190
- public function some_function($x=0,$current_options=array()){
191
- $installed_version = get_option( "yop_poll_version" );
 
 
192
  global $wpdb;
193
 
194
- if ( version_compare( $installed_version, '4.9.3', '<=' )||$x==1 ){
195
  if (!(version_compare(phpversion(), '5.3', '<'))) {
196
- ini_set("memory_limit","1024M");
197
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
198
- require_once( YOP_POLL_INC . 'db_schema.php' );
199
- if(empty($current_options)){
200
- $current_options=get_option( 'yop_poll_options' );
201
 
202
- $default=get_option( 'yop_poll_options' );
203
  }
204
  $capObj = YOP_POLL_Capabilities::get_instance();
205
  $capObj->install_capabilities();
206
  Yop_Poll_DbSchema::create_poll_database_tables();
207
- $wpdb->query( 'ALTER TABLE `' . $wpdb->yop_polls . '` CHANGE `ID` `ID` INT( 11 ) NOT NULL ' );
208
- $this->install_default_options();
209
-
210
- $new_options=array(
211
-
212
- 'user_interface_type' => 'beginner',
213
- 'is_default_answer' => $current_options['is_default_answer'],
214
- 'poll_start_date' =>current_time( 'mysql' ),
215
- 'poll_end_date' => '01-01-2038 23:59:59',
216
- 'view_results' => array( $current_options['view_results']),
217
- 'view_results_start_date' => convert_date($current_options['view_results_start_date'],'d-m-Y H:i:s',1),
218
- 'view_results_permissions' => array( 'guest', 'registered' ),
219
- 'view_results_type' => $current_options['view_results_type'],
220
- 'answer_result_label' => $current_options['answer_result_label'],
221
- 'vote_button_label' => $current_options['vote_button_label'],
222
- 'template_width' => $current_options['template_width'],
223
- 'widget_template_width' => $current_options['widget_template_width'],
224
- 'view_results_link' => $current_options['view_results_link'],
225
- 'view_results_link_label' => $current_options['view_results_link_label'],
226
- 'view_back_to_vote_link' => $current_options['view_back_to_vote_link'],
227
- 'view_back_to_vote_link_label' => $current_options['view_back_to_vote_link_label'],
228
- 'view_total_votes' => $current_options['view_total_votes'],
229
- 'view_total_votes_label' => $current_options['view_total_votes_label'],
230
- 'view_total_answers' =>$current_options['view_total_answers'],
231
- 'view_total_answers_label' => $current_options['view_total_answers_label'],
232
- 'message_after_vote' => $current_options['message_after_vote'],
233
- 'vote_permisions' => array( 'guest', 'registered' ),
234
- 'vote_permisions_wordpress' => $current_options['vote_permisions_wordpress'],
235
- 'vote_permisions_wordpress_label' => $current_options['vote_permisions_wordpress_label'],
236
- 'vote_permisions_anonymous' => $current_options['vote_permisions_anonymous'],
237
- 'vote_permisions_anonymous_label' =>$current_options['vote_permisions_anonymous_label'],
238
- 'blocking_voters' => array( $current_options['blocking_voters'] ),
239
- 'blocking_voters_interval_value' => $current_options['blocking_voters_interval_value'],
240
- 'blocking_voters_interval_unit' => $current_options['blocking_voters_interval_unit'],
241
- 'limit_number_of_votes_per_user' => $current_options['limit_number_of_votes_per_user'],
242
- 'number_of_votes_per_user' => $current_options['number_of_votes_per_user'],
243
- 'percentages_decimals' => $current_options['percentages_decimals'],
244
- 'use_default_loading_image' => $current_options['use_default_loading_image'],
245
- 'loading_image_url' => $current_options['loading_image_url'],
246
- 'redirect_after_vote' => $current_options['redirect_after_vote'],
247
- 'redirect_after_vote_url' =>$current_options['redirect_after_vote_url'],
248
- 'date_format' => 'UE',
249
- 'view_poll_archive_link' => $current_options['view_poll_archive_link'],
250
- 'auto_generate_poll_page' => $current_options['auto_generate_poll_page'],
251
- 'has_auto_generate_poll_page' => $current_options['has_auto_generate_poll_page'],
252
- 'use_captcha' => $current_options['use_captcha'],
253
- 'send_email_notifications' => $current_options['send_email_notifications'],
254
- 'allow_other_answers' => $current_options['allow_other_answers'],
255
- 'other_answers_label' => $current_options['other_answers_label'],
256
- 'is_default_other_answer' => $current_options['is_default_other_answer'],
257
- 'add_other_answers_to_default_answers' =>$current_options['add_other_answers_to_default_answers'],
258
- 'display_other_answers_values' => $current_options['display_other_answers_values'],
259
- 'allow_multiple_answers' => $current_options['allow_multiple_answers'],
260
- 'allow_multiple_answers_number' => $current_options['allow_multiple_answers_number'],
261
- 'allow_multiple_answers_min_number' => $current_options['allow_multiple_answers_min_number'],
262
- 'display_answers' =>$current_options['display_answers'],
263
- 'display_answers_tabulated_cols' => $current_options['display_answers_tabulated_cols'],
264
- 'sorting_results' => 'as_defined',
265
- 'sorting_answers' => 'as_defined',
266
- 'sorting_results_direction' => $current_options['sorting_results_direction'],
267
- 'sorting_answers_direction' => $current_options['sorting_answers_direction'],
268
- 'singular_answer_result_votes_number_label' => $current_options['singular_answer_result_votes_number_label'],
269
- 'plural_answer_result_votes_number_label' => $current_options['plural_answer_result_votes_number_label'],
270
- 'display_results' => $current_options['display_results'],
271
- 'display_results_tabulated_cols' => $current_options['display_results_tabulated_cols'],
272
- 'bar_background' => $current_options['bar_background'],
273
- 'bar_height' => $current_options['bar_height'],
274
- 'bar_border_color' => $current_options['bar_border_color'],
275
- 'bar_border_width' =>$current_options['bar_border_width'],
276
- 'bar_border_style' => $current_options['bar_border_style'],
277
- 'sorting_archive_polls' => 'votes',
278
- 'sorting_archive_polls_rule' => 'asc',
279
- 'archive_url' => $current_options['archive_url'],
280
- 'archive_link_label' => $current_options['view_poll_archive_link_label'],
281
- 'show_poll_in_archive' => $current_options['show_in_archive'],
282
- 'poll_archive_order' => $current_options['archive_order'],
283
- 'archive_polls_per_page' => $current_options['archive_polls_per_page'],
284
- 'email_notifications_from_name' => $current_options['email_notifications_from_name'],
285
- 'email_notifications_from_email' => $current_options['email_notifications_from_email'],
286
- 'email_notifications_recipients' => $current_options['email_notifications_recipients'],
287
- 'email_notifications_subject' =>$current_options['email_notifications_subject'],
288
- 'email_notifications_body' => '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
289
 
290
  <p>Vote Details:</p>
291
 
@@ -316,57 +298,57 @@ class YOP_POLL_Maintenance {
316
  [/QUESTION]
317
 
318
  <p><b>Vote ID:</b> <br />%VOTE_ID%</p>',
319
- 'schedule_reset_poll_stats' => $current_options['schedule_reset_poll_stats'],
320
- 'schedule_reset_poll_date' => current_time( 'mysql' ),
321
- 'schedule_reset_poll_recurring_value' => $current_options['schedule_reset_poll_recurring_value'],
322
- 'schedule_reset_poll_recurring_unit' => $current_options['schedule_reset_poll_recurring_unit'],
323
- 'singular_answer_result_votes_number_label' => __yop_poll( "vote" ),
324
- 'plural_answer_result_votes_number_label' => __yop_poll( "votes" ),
325
- 'start_scheduler' => $current_options['start_scheduler'],
326
- 'use_the_same_template_for_widget' => 'yes' ,
327
- 'vote_permisions_facebook' => 'no',
328
 
329
- 'vote_permisions_facebook_label' => __yop_poll( 'Vote as Facebook User' ),
330
 
331
- 'facebook_share_after_vote' => 'no',
332
 
333
- 'facebook_share_description' => __yop_poll( 'Just casted an YOP Poll vote on ' ) . get_bloginfo( 'name' ),
334
 
335
- 'vote_permisions_google' => 'no',
336
 
337
- 'vote_permisions_google_label' => __yop_poll( 'Vote as G+ User' ),
338
 
339
- 'show_google_share_button' => 'no',
340
- 'google_integration' =>'no',
341
- 'facebook_integration' =>'no',
342
- 'facebook_show_comments_widget' => "no"
343
  // 'view_total_answers_label' => __yop_poll( 'Poll total answers: %POLL-TOTAL-ANSWERS%' ),
344
 
345
  );
346
- if( $current_options['blocking_voters']=='cookie-ip')
347
- $new_options['blocking_voters' ]=array("cookie",'ip');
348
- else{
349
- if( $current_options['blocking_voters']=='username')
350
- $new_options['blocking_voters' ]=array('user_id');
351
  }
352
- list($g1,$d)=explode('-',$current_options['view_results_permissions']);
353
- $new_options['view_results_permissions' ]=array($g1,$d);
354
- list($g1,$d)=explode('-',$current_options['view_results_link']);
355
- $new_options['view_results_link' ]=array($g1,$d);
356
- update_option( 'yop_poll_options', $new_options );
357
- update_option( "yop_poll_version", YOP_POLL_VERSION );
358
  YOP_POLL_Maintenance::activation_hook($default);
359
- $wpdb->query( 'ALTER TABLE `' . $wpdb->yop_polls . '` CHANGE `ID` `ID` INT( 11 ) NOT NULL AUTO_INCREMENT ' );
360
 
361
  }
362
  }
363
- $installed_version = get_option( "yop_poll_version" );
364
 
365
- if ( version_compare( $installed_version, '5.2', '<=' ) ){
366
  ini_set('max_execution_time', 700);
367
- ini_set("memory_limit","512M");
368
- $default_poll_options = get_option( 'yop_poll_options' );
369
- $default_poll_options['email_notifications_body'] = '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
370
 
371
  <p>Vote Details:</p>
372
 
@@ -397,10 +379,10 @@ class YOP_POLL_Maintenance {
397
  [/QUESTION]
398
 
399
  <p><b>Vote ID:</b> <br />%VOTE_ID%</p>';
400
- update_option( 'yop_poll_options', $default_poll_options );
401
- $templates = self::yop_poll_get_templates_new_version_from_db();
402
- foreach($templates as $template){
403
- $template['js']= <<<NOWDOC
404
  function stripBorder_%POLL-ID%(object) {
405
  object.each(function() {
406
  if( parseInt(jQuery(this).width() ) > 0) {
@@ -509,10 +491,10 @@ function runOnPollStateChange_%POLL-ID%() {
509
  NOWDOC;
510
  self::update_poll_template_in_database(($template));
511
  }
512
- $polls=self::yop_poll_get_polls_for_body_mail_update();
513
- foreach($polls as $poll){
514
- $current=new YOP_POLL_Poll_Model($poll['ID']);
515
- $current->email_notifications_body='<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
516
 
517
  <p>Vote Details:</p>
518
 
@@ -546,36 +528,36 @@ NOWDOC;
546
  $current->save();
547
 
548
  }
549
- update_option( "yop_poll_version", YOP_POLL_VERSION );
550
  }
551
- $installed_version = get_option( "yop_poll_version" );
552
- if ( version_compare( $installed_version, '5.3', '<=' ) ){
553
- update_option( "yop_poll_version", YOP_POLL_VERSION );
554
  }
555
- $installed_version = get_option( "yop_poll_version" );
556
- if ( version_compare( $installed_version, '5.5', '<=' ) ){
557
- update_option( "yop_poll_version", YOP_POLL_VERSION );
558
  }
559
- $installed_version = get_option( "yop_poll_version" );
560
 
561
- if ( version_compare( $installed_version, '5.6', '<=' ) ){
562
  global $wpdb;
563
- update_option( "yop_poll_version", YOP_POLL_VERSION );
564
- $default_poll_options = get_option( 'yop_poll_options' );
565
- $default_poll_options['show_results_in']="bar";
566
- update_option( 'yop_poll_options', $default_poll_options );
567
 
568
- $wpdb->query( 'ALTER TABLE `' . $wpdb->yop_poll_templates . '` ADD `after_vote_template_chart` text' );
569
- update_option( "yop_poll_version", '5.7' );
570
 
571
  }
572
- if ( version_compare( $installed_version, '5.7', '<=' ) ){
573
  global $wpdb;
574
- update_option( "yop_poll_version", YOP_POLL_VERSION );
575
 
576
- $templates = self::yop_poll_get_templates_new_version_from_db();
577
- foreach($templates as $template){
578
- $template['js']= <<<NOWDOC
579
  function stripBorder_%POLL-ID%(object) {
580
  object.each(function() {
581
  if( parseInt(jQuery(this).width() ) > 0) {
@@ -730,7 +712,7 @@ function runOnPollStateChange_%POLL-ID%() {
730
 
731
  };
732
  NOWDOC;
733
- $template['after_vote_template_chart']= <<<NOWDOC
734
  [QUESTION_CONTAINER]
735
  <div id = "yop-poll-question-container-%POLL-ID%-%QUESTION-ID%" class = "yop-poll-question-container-%POLL-ID%">
736
  <div id = "yop-poll-question-%POLL-ID%-%QUESTION-ID%"
@@ -753,25 +735,31 @@ NOWDOC;
753
  NOWDOC;
754
  self::update_poll_template_in_database2($template);
755
  }
756
- update_option( "yop_poll_version", '5.7.1' );
757
 
758
  }
759
- if ( version_compare( $installed_version, '5.7.1', '<=' ) ){
760
  global $wpdb;
761
- update_option( "yop_poll_version", '5.7.2' );
762
  }
763
- if ( version_compare( $installed_version, '5.7.2', '<=' ) ){
764
  global $wpdb;
765
- update_option( "yop_poll_version", '5.7.3' );
766
  }
767
- if ( version_compare( $installed_version, '5.7.3', '<=' ) ){
768
  global $wpdb;
769
- update_option( "yop_poll_version", '5.7.4' );
 
 
 
 
770
  }
771
  }
772
- private static function update_poll_template_in_database2( $template ) {
 
 
773
  global $wpdb;
774
- $sql = $wpdb->query( $wpdb->prepare( "
775
  UPDATE " . $wpdb->yop_poll_templates . "
776
  SET name = %s,
777
  before_vote_template = %s,
@@ -784,138 +772,149 @@ NOWDOC;
784
  last_modified = %s
785
  WHERE
786
  id = %d
787
- ", $template['name'], $template['before_vote_template'], $template['after_vote_template'],$template['after_vote_template_chart'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time( 'mysql' ), $template['id'] ) );
788
  return $sql;
789
  }
790
- public function yop_poll_get_polls_for_body_mail_update(){
 
 
791
  global $wpdb;
792
- $result = $wpdb->get_results(( "
793
  SELECT ID
794
- FROM " . $wpdb->yop_polls." ORDER BY ID ASC
795
- " ), ARRAY_A );
796
  return $result;
797
  }
798
- private function install_default_options() {
799
- $default_poll_options = get_option( 'yop_poll_options' );
 
 
800
 
801
  $default_poll_options['is_default_answer'] = 'no';
802
- $default_poll_options['poll_start_date' ] = current_time( 'mysql' );
803
- $default_poll_options['poll_end_date'] = '01-01-2038 23:59:59';
804
 
805
- update_option( 'yop_poll_options', $default_poll_options );
806
  }
807
 
808
- private function uninstall_default_options() {
 
809
  // delete_option( "yop_poll_version" );
810
  // delete_option( "yop_poll_options" );
811
  }
812
 
813
- public function activate( $networkwide ) {
814
- if( ! current_user_can( 'activate_plugins' ) ) {
815
- $error = new WP_Error ( 'Wordpress_version_error', __yop_poll( 'You need permissions to activate this plugin' ), __yop_poll( 'Error: Wordpress Activation Permissions Problem' ) );
 
816
  }
817
 
818
- if( ! version_compare( $GLOBALS['wp_version'], YOP_POLL_WP_VERSION, '>=' ) ) {
819
- $error = new WP_Error ( 'Wordpress_version_error', sprintf( __yop_poll( 'You need at least Wordpress version %s to use this plugin' ), YOP_POLL_WP_VERSION ), __yop_poll( 'Error: Wordpress Version Problem' ) );
820
- $error = new WP_Error ( 'Wordpress_version_error', sprintf( __yop_poll( 'You need at least Wordpress version %s to use this plugin' ), YOP_POLL_WP_VERSION ), __yop_poll( 'Error: Wordpress Version Problem' ) );
821
  }
822
 
823
- if( isset ( $error ) && is_wp_error( $error ) ) {
824
- wp_die( $error->get_error_message(), $error->get_error_data() );
825
  }
826
 
827
 
828
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
829
- require_once( YOP_POLL_INC . 'db_schema.php' );
830
  $this->install_default_options();
831
  $capObj = YOP_POLL_Capabilities::get_instance();
832
  $capObj->install_capabilities();
833
  Yop_Poll_DbSchema::install_database();
834
  }
835
 
836
- public function deactivatedelete( $networkwide ) {
837
- require_once( YOP_POLL_INC . 'db_schema.php' );
 
838
  Yop_Poll_DbSchema::delete_database_tables();
839
  $capObj = YOP_POLL_Capabilities::get_instance();
840
  $capObj->uninstall_capabilities();
841
  $this->uninstall_default_options();
842
  }
843
 
844
- function new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
845
- if( ! function_exists( 'is_plugin_active_for_network' ) ) {
846
- require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
 
847
  }
848
- if( is_plugin_active_for_network( YOP_POLL_SHORT_PLUGIN_FILE ) ) {
849
  $old_blog = $GLOBALS['wpdb']->blogid;
850
- switch_to_blog( $blog_id );
851
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
852
- $this->activate( null );
853
- switch_to_blog( $old_blog );
854
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
855
  }
856
  }
857
 
858
- function delete_blog( $blog_id ) {
 
859
  $old_blog = $GLOBALS['wpdb']->blogid;
860
- switch_to_blog( $blog_id );
861
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
862
- $this->deactivatedelete( null );
863
- require_once( YOP_POLL_INC . 'db_schema.php' );
864
  // Yop_Poll_DbSchema::delete_database_tables();
865
  $capObj = YOP_POLL_Capabilities::get_instance();
866
  $capObj->uninstall_capabilities();
867
  $this->uninstall_default_options();
868
- switch_to_blog( $old_blog );
869
- yop_poll_create_table_names( $GLOBALS['wpdb']->prefix );
870
  }
871
 
872
- function update() {
 
873
  }
874
 
875
- public function activation_hook($default) {
 
876
  ini_set('max_execution_time', 700);
877
- $current_options=get_option( 'yop_poll_options' );
878
- $polls = self::yop_poll_get_polls_from_db();
879
- $answers = self::yop_poll_get_answers_from_db();
880
- $logs = self::yop_poll_get_logs_from_db();
881
- $bans = self::yop_poll_get_bans_from_db();
882
  $custom_fields = self::yop_poll_get_custom_fields_from_db();
883
- $custom_votes = self::yop_poll_get_custom_fields_votes_from_db();
884
- $metas = self::yop_poll_get_polls_meta_from_db();
885
- $answers_meta = self::yop_poll_get_answers_meta_from_db();
886
- $templates = self::yop_poll_get_templates_from_db();
887
- foreach($templates as $template){
888
- $template['before_vote_template'] ="[QUESTION_CONTAINER]". $template['before_vote_template'];
889
- $template['before_vote_template']=str_replace('%POLL-ANSWER-LABEL%','%POLL-ANSWER-LABEL% [ANSWER_RESULT_CONTAINER]',$template['before_vote_template']);
890
- $template['before_vote_template']=str_replace('%POLL-TOTAL-ANSWERS%','%POLL-TOTAL-ANSWERS-LABEL%',$template['before_vote_template']);
891
- $template['before_vote_template']=str_replace('%POLL-TOTAL-VOTES%','%POLL-TOTAL-VOTES-LABEL%',$template['before_vote_template']);
892
- $template['after_vote_template']=str_replace('%POLL-TOTAL-VOTES%','%POLL-TOTAL-VOTES-LABEL%',$template['after_vote_template']);
893
- $template['after_vote_template']=str_replace('%POLL-TOTAL-ANSWERS%','%POLL-TOTAL-ANSWERS-LABEL%',$template['after_vote_template']);
894
- $template['after_end_date_template']=str_replace('%POLL-TOTAL-ANSWERS%','%POLL-TOTAL-ANSWERS-LABEL%',$template['after_end_date_template']);
895
- $template['after_end_date_template']=str_replace('%POLL-TOTAL-VOTES%','%POLL-TOTAL-VOTES-LABEL%',$template['after_end_date_template']);
896
- $template['before_vote_template']=preg_replace('/%POLL-ANSWER-RESULT-BAR%/','%POLL-ANSWER-RESULT-BAR% [/ANSWER_RESULT_CONTAINER]',$template['before_vote_template'],1);
897
  $find = '[/ANSWER_RESULT_CONTAINER]';
898
  $replace = '';
899
  // $template['before_vote_template']= preg_replace(strrev("/$find/"),strrev($replace),strrev( $template['before_vote_template']),1);
900
- $template['after_vote_template'] ="[QUESTION_CONTAINER]". $template['after_vote_template'];
901
- $template['after_end_date_template'] ="[QUESTION_CONTAINER]". $template['after_end_date_template'];
902
  /* if(strpos($template['before_vote_template'],"[CAPTCHA_CONTAINER]"))
903
  $template['before_vote_template']=str_replace('[CAPTCHA_CONTAINER]','[/QUESTION_CONTAINER][CAPTCHA_CONTAINER]',$template['before_vote_template']);
904
  else{
905
  $template['before_vote_template']=str_replace('<div id="yop-poll-vote-%POLL-ID%" class="yop-poll-footer">','[/QUESTION_CONTAINER]<div id="yop-poll-vote-%POLL-ID%" class="yop-poll-footer">',$template['before_vote_template']);
906
  } */
907
- $template['before_vote_template']= $template['before_vote_template'].'[/QUESTION_CONTAINER]' ;
908
- if(strpos($template['before_vote_template'],"%POLL-QUESTION%")&&strpos($template['before_vote_template'],'%POLL-NAME%')){
909
- $template['before_vote_template']=str_replace('%POLL-QUESTION%','',$template['before_vote_template']);
910
- $template['before_vote_template']=str_replace('%POLL-NAME%','%POLL-QUESTION%',$template['before_vote_template']);
911
  }
912
- if(strpos($template['after_vote_template'],"%POLL-QUESTION%")&&strpos($template['after_vote_template'],'%POLL-NAME%')){
913
- $template['after_vote_template']=str_replace('%POLL-QUESTION%','',$template['after_vote_template']);
914
- $template['after_vote_template']=str_replace('%POLL-NAME%','%POLL-QUESTION%',$template['after_vote_template']);
915
  }
916
- $template['after_vote_template']= $template['after_vote_template'].'[/QUESTION_CONTAINER]';
917
- $template['after_end_date_template']=$template['after_end_date_template'].'[/QUESTION_CONTAINER]';
918
- $template['js']=<<<NOWDOC
919
  function stripBorder_%POLL-ID%(object) {
920
  object.each(function() {
921
  if( parseInt(jQuery(this).width() ) > 0) {
@@ -1071,60 +1070,60 @@ function runOnPollStateChange_%POLL-ID%() {
1071
  };
1072
 
1073
  NOWDOC;
1074
- $template['js'] = addslashes( $template['js'] );
1075
- $templates_ids[$template['id']]=self::insert_template_in_databease(($template));
1076
  }
1077
 
1078
- foreach( $polls as $poll ) {
1079
 
1080
- foreach( $answers as $answer ) {
1081
- if( $answer['poll_id'] == $poll['id'] ) {
1082
  $answers_ordonate[$poll['id']][] = (array)$answer;
1083
  }
1084
- if( $answer['poll_id'] > $poll['id'] ) {
1085
  break;
1086
  }
1087
 
1088
- foreach( $logs as $log ) {
1089
- if( $log['poll_id'] == $poll['id'] && $log['answer_id'] == $answer['id'] ) {
1090
- $logs_ordonate[$poll['id']][] = (array)$log;
1091
  $logs_ordonate_details[$log['id']][] = $answer['answer'];
1092
  }
1093
  }
1094
- foreach( $answers_meta as $answer_meta ) {
1095
- if( $answer_meta['yop_poll_answer_id'] == $answer['id'] ) {
1096
  $answer_meta_ordonate[$answer['id']][] = (array)$answer_meta;
1097
  }
1098
  }
1099
  }
1100
 
1101
- foreach( $bans as $ban ) {
1102
- if( $ban['poll_id'] == $poll['id'] ) {
1103
  $bans_ordonate[$poll['id']][] = (array)$ban;
1104
  }
1105
- if( $ban['poll_id'] > $poll['id'] ) {
1106
  break;
1107
  }
1108
  }
1109
 
1110
- foreach( $metas as $meta ) {
1111
- if( $meta['yop_poll_id'] == $poll['id'] ) {
1112
  $metas_ordonate[$poll['id']][] = (array)$meta;
1113
  }
1114
- if( $meta['yop_poll_id'] > $poll['id'] ) {
1115
  break;
1116
  }
1117
  }
1118
 
1119
- foreach( $custom_fields as $custom_field ) {
1120
- if( $custom_field['poll_id'] == $poll['id'] ) {
1121
  $custom_fields_ordonate[$poll['id']][] = (array)$custom_field;
1122
- if( $custom_field['poll_id'] > $poll['id'] ) {
1123
  break;
1124
  }
1125
 
1126
- foreach( $custom_votes as $custom_vote ) {
1127
- if( $custom_field['id'] == $custom_vote['custom_field_id'] ) {
1128
  $custom_votes_fields_ordonate[$custom_field['id']][] = (array)$custom_vote;
1129
  }
1130
  }
@@ -1133,18 +1132,18 @@ NOWDOC;
1133
  }
1134
 
1135
 
1136
- foreach( $polls as $poll ) {
1137
- $current_poll = new YOP_POLL_Poll_Model();
1138
- $current_poll->poll_author = $poll['poll_author'];
1139
- $current_poll->ID = $poll['id'];
1140
- $current_poll->poll_title = $poll['name'];
1141
- $current_poll->poll_name = $poll['name'];
1142
- $current_poll->poll_date = $poll['date_added'];
1143
  $current_poll->poll_modified = $poll['last_modified'];
1144
- $current_poll->poll_status = $poll['status'];
1145
- $current_poll->poll_type = "poll";
1146
- $current_poll->poll_status = $poll['status'];
1147
- $current_poll->email_notifications_body='<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
1148
 
1149
  <p>Vote Details:</p>
1150
 
@@ -1175,188 +1174,178 @@ NOWDOC;
1175
  [/QUESTION]
1176
 
1177
  <p><b>Vote ID:</b> <br />%VOTE_ID%</p>';
1178
- if( $poll['end_date'] <= "2038-01-18 23:59:59" ) {
1179
-
1180
- $current_poll->poll_end_date =convert_date ($poll['end_date'],'d-m-Y H:i:s',1 );
1181
 
1182
- }
1183
 
1184
- else {
1185
 
1186
  $current_poll->poll_end_date = "01-01-2038 23:59:59";
1187
 
1188
  }
1189
 
1190
- if( $poll['start_date'] <= "2038-01-18 23:59:59" ) {
1191
 
1192
- $current_poll->poll_start_date = convert_date($poll['start_date'],'d-m-Y H:i:s',1 );
1193
 
1194
- }
1195
-
1196
- else {
1197
 
1198
  $current_poll->poll_start_date = "01-01-2038 23:59:59";
1199
 
1200
  }
1201
  $current_poll->poll_total_votes = $poll['total_votes'];
1202
- $question = new YOP_POLL_Question_Model();
1203
- $question->type = "text";
1204
- $question->question = $poll['question'];
1205
- $question->question_date = $current_poll->poll_date;
1206
- $question->question_author = $current_poll->poll_author;
1207
- $question->question_modified = $current_poll->poll_modified;
1208
- $question->question_status = $current_poll->poll_status;
1209
- $question->poll_order = 1;
1210
- $i = 0;
1211
-
1212
-
1213
-
1214
- foreach( $answers_ordonate[$poll['id']] as $answer_ordonate ) {
1215
-
1216
- if( $answer_ordonate['type'] == "other" ) {
1217
- $current_poll->allow_other_answers='yes';
1218
- $question->allow_other_answers= 'yes';
1219
  }
1220
  }
1221
- $q[] = $question;
1222
  // yop_poll_dump($current_poll);
1223
  $current_poll->questions = $q;
1224
- $current_poll->auto_generate_poll_page="no";
1225
- $current_poll_id = $current_poll->insert();
1226
- $current_poll_id =$current_poll->ID;
1227
  // yop_poll_dump($current_poll->save())
1228
- $no_modif=0;
1229
- $no_modif2=0;
1230
- $current_poll_meta=$current_options;
1231
- if( isset( $metas_ordonate[$poll['id']] ) ) {
1232
- $poll_option = maybe_unserialize( $metas_ordonate[$poll['id']][0]['meta_value'] );
1233
- foreach( $current_options as $key => $value ) {
1234
- if( isset( $poll_option[$key] ) ) {
1235
 
1236
- if($key=='view_results_permissions'){
1237
 
1238
- list($g1,$d)=explode('-',$poll_option[$key]);
1239
- if($g1=="quest"){
1240
- $g1="guest";
1241
 
1242
  }
1243
 
1244
- $current_poll_meta[$key] = array($g1,$d);
1245
- $no_modif=1;
1246
 
1247
- }
1248
- else
1249
- if($key=='vote_permisions'){
1250
- list($g1,$d)=explode('-',$poll_option['vote_permisions']);
1251
- if($g1=="quest"){
1252
- $g1="guest";
1253
 
1254
  }
1255
- $no_modif2=1;
1256
- $current_poll_meta[$key] = array($g1,$d);
1257
- }
1258
- else
1259
  $current_poll_meta[$key] = $poll_option[$key];
1260
 
1261
 
1262
  } else
1263
- $current_poll_meta[$key]=$default[$key];
1264
  }
1265
  }
1266
- $current_poll_meta['view_results'] = array($poll_option['view_results'] );
1267
  $current_poll_meta['sorting_results'] = $default['sorting_answers'];
1268
- if(!isset($poll_option['view_results_link'])){
1269
- $current_poll_meta['view_results_link']="yes";
1270
- }
1271
- else
1272
- $current_poll_meta['view_results_link'] = $poll_option['view_results_link'] ;
1273
-
1274
- if( $poll_option['view_results']=='custom-date')
1275
- $current_poll_meta['view_results_start_date'] =$poll_option['view_results_start_date'] ;
1276
- if(empty( $current_poll_meta['view_results'][0])) {
1277
  $current_poll_meta['view_results'] = array('after');
1278
  }
1279
- if($no_modif==0 ||empty($current_poll_meta['view_results'])){
1280
- $current_poll_meta['view_results_permissions'] = array( 'guest', 'registered' );
1281
 
1282
  }
1283
 
1284
- if($no_modif2==0||empty($current_poll_meta['vote_permisions'])){
1285
- $current_poll_meta['vote_permisions'] = array( 'guest', 'registered' );
1286
  }
1287
 
1288
- if( $poll_option['blocking_voters']=='cookie-ip')
1289
- $current_poll_meta['blocking_voters' ]=array("cookie",'ip');
1290
  else {
1291
- if( $poll_option['blocking_voters']=='username')
1292
- $current_poll_meta['blocking_voters' ]=array("user_id");
1293
  else
1294
- $current_poll_meta['blocking_voters' ]=array( 'dont-block' );
1295
- }
1296
- $current_poll_meta['facebook_share_after_vote']="no";
1297
- $current_poll_meta['show_google_share_button']="no";
1298
- $current_poll_meta['facebook_show_comments_widget'] ="no";
1299
- $current_poll_meta['facebook_share_description'] = __yop_poll( 'Just casted an YOP Poll vote on ' ) . get_bloginfo( 'name' );
1300
- if(isset($poll_option['show_in_archive']))
1301
- $current_poll_meta['show_poll_in_archive']=$poll_option['show_in_archive'] ;
1302
- if(isset($poll_option['schedule_reset_poll_date']))
1303
- $current_poll_meta['schedule_reset_poll_date']=$poll_option['schedule_reset_poll_date'] ;
1304
- if(isset($poll_option['template'])){
1305
- $current_poll_meta['template']=$templates_ids[ $poll_option['template']];
1306
- } else $current_poll_meta['template']=1;
1307
- if(isset($poll_option['widget_template'])){
1308
- $current_poll_meta['widget_template']=$templates_ids[ $poll_option['widget_template']];
1309
  }
1310
- else $current_poll_meta['widget_template']=1;
1311
- if(isset($poll_option['widget_template']) && isset($poll_option['template'])&& $poll_option['template']!=$poll_option['widget_template']){
1312
- $current_poll_meta['use_the_same_template_for_widget'] ="no";
 
 
 
 
 
 
 
 
 
 
 
 
 
1313
  }
1314
- if(isset($poll_option['view_total_answers_label'])){
1315
- $current_poll_meta['view_total_answers_label']=$default['view_total_answers_label'];
1316
  }
1317
- if(isset($poll_option['answer_result_label'])){
1318
- $current_poll_meta['answer_result_label']=$default['answer_result_label'];
1319
  }
1320
- if( $current_poll_meta['vote_permisions_anonymous']=="no"&& $current_poll_meta['vote_permisions_wordpress']=="no"){
1321
- $current_poll_meta['vote_permisions_anonymous']="yes";
1322
  }
1323
- update_yop_poll_question_meta( $current_poll_id, 'options', $current_poll_meta);
1324
- update_yop_poll_meta( $current_poll_id, 'options', $current_poll_meta );
1325
- if($poll['show_in_archive'] =="yes"){
1326
- self::save_poll_order($current_poll_id,$poll['archive_order']);
1327
  }
1328
 
1329
- if($default['sorting_answers']=="votes"){
1330
- $answers_ordonate[$poll['id']]=self::get_answers_order_by_votes($poll['id'],$default['sorting_answers_direction']);
1331
- }
1332
- if($default['sorting_answers']=="alphabetical"){
1333
- $answers_ordonate[$poll['id']]=self::get_answers_order_by_alph($poll['id'],$default['sorting_answers_direction']);
1334
  }
1335
- foreach( $answers_ordonate[$poll['id']] as $answer_ordonate ) {
1336
- $ans = new YOP_POLL_Answer_Model();
1337
- $ans->answer = $answer_ordonate['answer'];
1338
- $ans->answer_author = $current_poll->poll_author;
1339
- $ans->answer_date = $current_poll->poll_date;
1340
  $ans->answer_modified = $poll['last_modified'];
1341
- if( $answer_ordonate['type'] != "other" ) {
1342
  $ans->type = "text";
1343
- }
1344
- else{
1345
- $current_poll->allow_other_answers = 'yes';
1346
- $question->allow_other_answers = 'yes';
1347
  $ans->type = "other";
1348
  }
1349
- $ans->answer_status = $answer['status'];
1350
- $ans->votes = $answer_ordonate['votes'];
1351
- $ans->question_order = $i ++;
1352
 
1353
- if( $answer_ordonate['type'] != "other" ) {
1354
  $answersa[] = $ans;
1355
- if( isset( $answer_meta_ordonate[$answer_ordonate['id']] ) ) {
1356
- $answer_option = maybe_unserialize( $answer_meta_ordonate[$answer_ordonate['id']][0]['meta_value'] );
1357
  $answer_options = $ans->options;
1358
- foreach( $ans->options as $key => &$value ) {
1359
- if( isset( $answer_option[$key] ) ) {
1360
  $ans->$key = $answer_option[$key];
1361
  }
1362
 
@@ -1364,87 +1353,88 @@ NOWDOC;
1364
  $ans->options = $answer_options;
1365
  }
1366
 
1367
- $question->addAnswer( $ans );
1368
 
1369
  $question->save_answers();
1370
  $answersids[$answer_ordonate['id']] = $ans->ID;
1371
  }
1372
 
1373
  }
1374
- if(!empty($custom_fields_ordonate[$poll['id']]))
1375
- foreach( $custom_fields_ordonate[$poll['id']] as $custom_ordonate ) {
1376
- $oldid = $custom_ordonate['id'];
1377
- // $question = $current_poll->questions;
1378
- $custom_ordonate['question_id'] = $current_poll_id;
1379
- $custom_ordonate['poll_id'] = $current_poll_id;
1380
- $newid = insert_custom_field_in_db( $custom_ordonate );
1381
- foreach( $custom_votes_fields_ordonate[$oldid] as $votes ) {
1382
- $votes['custom_field_id'] = $newid;
1383
- $votes['question_id'] = $current_poll_id;
1384
- $votes['poll_id'] = $current_poll_id;
1385
- $votes['id'] = insert_votes_custom_in_db( $votes );
1386
- $custom_field_vote[$poll['id']][] = $votes;
 
1387
  }
1388
- }
1389
 
1390
- if(!empty($logs_ordonate[$poll['id']]))
1391
- foreach( $logs_ordonate[$poll['id']] as $log_ordonate ) {
1392
- $log['poll_id'] = $current_poll_id;
1393
- $log['vote_id'] = $log_ordonate['vote_id'];
1394
- $log['ip'] = $log_ordonate['ip'];
1395
- $log['user_id'] = $log_ordonate['user_id'];
1396
- $log['user_type'] = $log_ordonate['user_type'];
1397
- $log['vote_date'] = $log_ordonate['vote_date'];
1398
- $log['tr_id'] = $log_ordonate['tr_id'];
1399
- $vote_details[1]["q-" . $current_poll_id]['question'] = $poll['question'];
1400
- $vote_details[1]["q-" . $current_poll_id]['id'] = $current_poll_id;
1401
- $vote_details[1]["q-" . $current_poll_id]['a'][] = $answersids[$log_ordonate['answer_id']];
1402
- if($log_ordonate['other_answer_value']!=""&&isset($log_ordonate['other_answer_value'])){
1403
- $ans = new YOP_POLL_Answer_Model();
1404
- $ans->answer = $answer_ordonate['answer'];
1405
- $ans->answer_author = $current_poll->poll_author;
1406
- $ans->answer_date = $current_poll->poll_date;
1407
- $ans->answer_modified = $poll['last_modified'];
1408
- $ans->answer = $log_ordonate['other_answer_value'];
1409
- $ans->answer_status ='active';
1410
- $ans->votes = 1;
1411
- $ans->type = 'other';
1412
- $ans->question_order = $i ++;
1413
- $question->addAnswer( $ans );
1414
- $question->save_answers();
1415
- }
1416
- if(!empty($custom_field_vote[$poll['id']]))
1417
- foreach( $custom_field_vote[$poll['id']] as $vote ) {
1418
- if( $vote['vote_id'] == $log_ordonate['vote_id'] ) {
1419
- $vote_details[1]["q-" . $current_poll_id]['cf'][] = $vote['id'];
1420
  }
 
 
 
 
 
1421
 
 
 
 
 
 
 
 
 
 
 
1422
  }
1423
- foreach( $logs_ordonate_details[$log_ordonate['id']] as $a ) {
1424
- $vote_details[1]["q-" . $current_poll_id]['answers'][] = $a;
1425
- $log['vote_details'] = json_encode( $vote_details[1] );
1426
- $log['message'] = "Succes";
1427
- insert_result_in_db( $log );
1428
- insert_log_in_db( $log );
1429
- unset( $vote_details[1]["q-" . $current_poll_id]['answers'] );
1430
  }
1431
- unset( $vote_details );
1432
- }
1433
- if(!empty($bans_ordonate[$poll['id']]))
1434
- foreach( $bans_ordonate[$poll['id']] as $ban_ordonate ) {
1435
- $ban = $ban_ordonate;
1436
- $ban['poll_id'] = $current_poll_id;
1437
- self::insert_ban_in_db( $ban );
1438
- }
1439
 
1440
 
1441
  }
1442
 
1443
  }
1444
 
1445
- public function insert_template_in_databease($template){
 
1446
  global $wpdb;
1447
- $sql= $wpdb->query( $wpdb->prepare( "
1448
  INSERT INTO " . $wpdb->yop_poll_templates . "
1449
  SET
1450
  template_author = %d,
@@ -1458,12 +1448,14 @@ NOWDOC;
1458
  date_added = %s,
1459
  last_modified = %s,
1460
  status = %s
1461
- ", $template['template_author'], $template['name'], $template['before_vote_template'], $template['after_vote_template'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time( 'mysql' ), current_time( 'mysql' ), $template['status'] ) );
1462
  return $GLOBALS['wpdb']->insert_id;
1463
  }
1464
- private static function update_poll_template_in_database( $template ) {
 
 
1465
  global $wpdb;
1466
- $sql = $wpdb->query( $wpdb->prepare( "
1467
  UPDATE " . $wpdb->yop_poll_templates . "
1468
  SET name = %s,
1469
  before_vote_template = %s,
@@ -1475,145 +1467,164 @@ NOWDOC;
1475
  last_modified = %s
1476
  WHERE
1477
  id = %d
1478
- ", $template['name'], $template['before_vote_template'], $template['after_vote_template'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time( 'mysql' ), $template['id'] ) );
1479
  return $sql;
1480
  }
1481
- public function yop_poll_get_polls_from_db() {
 
 
1482
  global $wpdb;
1483
- $result = $wpdb->get_results(( "
1484
  SELECT *
1485
  FROM " . $wpdb->prefix . "yop_polls ORDER BY id ASC
1486
- " ), ARRAY_A );
1487
  return $result;
1488
 
1489
  }
1490
 
1491
- public function yop_poll_get_polls_meta_from_db() {
 
1492
  global $wpdb;
1493
- $result = $wpdb->get_results( ( "
1494
  SELECT *
1495
  FROM " . $wpdb->prefix . "yop_pollmeta ORDER BY yop_poll_id ASC
1496
- " ), ARRAY_A );
1497
  return $result;
1498
 
1499
  }
1500
 
1501
- public function yop_poll_get_answers_meta_from_db() {
 
1502
  global $wpdb;
1503
 
1504
- $result = $wpdb->get_results( ("
1505
  SELECT *
1506
  FROM " . $wpdb->prefix . "yop_poll_answermeta
1507
- " ), ARRAY_A );
1508
  return $result;
1509
 
1510
  }
1511
 
1512
- public function yop_poll_get_templates_from_db() {
 
1513
  global $wpdb;
1514
- $result = $wpdb->get_results( ( "
1515
  SELECT *
1516
  FROM " . $wpdb->prefix . "yop_poll_templates
1517
- " ), ARRAY_A );
1518
  return $result;
1519
  }
1520
- public function yop_poll_get_templates_new_version_from_db() {
 
 
1521
  global $wpdb;
1522
- $result = $wpdb->get_results( ( "
1523
  SELECT *
1524
  FROM " . $wpdb->yop_poll_templates
1525
- ), ARRAY_A );
1526
  return $result;
1527
  }
1528
 
1529
- public function yop_poll_get_custom_fields_from_db() {
 
1530
  global $wpdb;
1531
- $result = $wpdb->get_results( ( "
1532
  SELECT *
1533
  FROM " . $wpdb->prefix . "yop_poll_custom_fields ORDER BY poll_id ASC
1534
- " ), ARRAY_A );
1535
  return $result;
1536
  }
1537
 
1538
- public function yop_poll_get_custom_fields_votes_from_db() {
 
1539
  global $wpdb;
1540
- $result = $wpdb->get_results( ( "
1541
  SELECT *
1542
  FROM " . $wpdb->prefix . "yop_poll_votes_custom_fields
1543
- " ), ARRAY_A );
1544
  return $result;
1545
  }
1546
 
1547
- public function yop_poll_get_bans_from_db() {
 
1548
  global $wpdb;
1549
- $result = $wpdb->get_results( ( "
1550
  SELECT *
1551
  FROM " . $wpdb->prefix . "yop_poll_bans ORDER BY poll_id ASC
1552
- " ), ARRAY_A );
1553
  return $result;
1554
  }
1555
- public function yop_poll_get_answers_from_db() {
 
 
1556
  global $wpdb;
1557
- $result = $wpdb->get_results( ( "
1558
  SELECT *
1559
  FROM " . $wpdb->prefix . "yop_poll_answers ORDER BY poll_id ASC
1560
- " ), ARRAY_A );
1561
  return $result;
1562
  }
1563
- public function get_answers_order_by_votes($poll_id,$dir) {
 
 
1564
  global $wpdb;
1565
- $result = $wpdb->get_results( $wpdb->prepare( "
1566
  SELECT *
1567
  FROM " . $wpdb->prefix . "yop_poll_answers WHERE poll_id=%d ORDER BY votes $dir
1568
- ",$poll_id ), ARRAY_A );
1569
  return $result;
1570
  }
1571
 
1572
- public function get_answers_order_by_alph($poll_id,$dir) {
 
1573
  global $wpdb;
1574
- $result = $wpdb->get_results( $wpdb->prepare( "
1575
  SELECT *
1576
  FROM " . $wpdb->prefix . "yop_poll_answers WHERE poll_id=%d ORDER BY answer $dir
1577
- ",$poll_id ), ARRAY_A );
1578
  return $result;
1579
  }
1580
 
1581
- public function yop_poll_get_logs_from_db() {
 
1582
  global $wpdb;
1583
- $result = $wpdb->get_results( ( "
1584
  SELECT *
1585
  FROM " . $wpdb->prefix . "yop_poll_logs
1586
- " ), ARRAY_A );
1587
  return $result;
1588
  }
1589
 
1590
- private static function insert_ban_in_db( $ban ) {
 
1591
  global $wpdb;
1592
- $sql = $wpdb->query( $wpdb->prepare( "
1593
  INSERT INTO $wpdb->yop_poll_bans
1594
  ( poll_id,type,value,period ,unit)
1595
  VALUES(%d,%s,%s,%d,%s)
1596
- ", $ban['poll_id'], $ban['type'], $ban['value'], intval( $ban['period'] ), $ban['unit'] ) );
1597
- return $wpdb->get_results( $sql );
1598
  }
1599
- private function save_poll_order( $poll, $poll_order ) {
1600
- $poll_archive_order = get_option( 'yop_poll_archive_order', array() );
1601
- if( $poll_archive_order == "" ) {
 
 
1602
  $poll_archive_order = array();
1603
- }if( trim( $poll_order ) <= 0 ) {
1604
- $poll_order = 1;
1605
  }
1606
- $key = array_search( $poll, $poll_archive_order );
1607
- if( $key !== false ) {
1608
- unset( $poll_archive_order[$key] );
1609
  }
1610
- if( $poll_order > count( $poll_archive_order ) ) {
1611
- array_push( $poll_archive_order, $poll );
 
1612
  }
1613
- else {
1614
- array_splice( $poll_archive_order, trim( $poll_order ) - 1, 0, array( $poll ) );
 
 
1615
  }
1616
- update_option( 'yop_poll_archive_order', $poll_archive_order );
1617
  }
1618
 
1619
  }
1
  <?php
2
 
3
+ class YOP_POLL_Maintenance
4
+ {
5
 
6
+ private function network_propagate($pfunction, $networkwide)
7
+ {
8
+ error_reporting(0);
9
+ if (function_exists('is_multisite') && is_multisite()) {
10
 
11
+ if ($networkwide) {
12
 
13
  $old_blog = $GLOBALS['wpdb']->blogid;
14
 
15
+ $blogids = $GLOBALS['wpdb']->get_col("SELECT blog_id FROM {$GLOBALS['wpdb']->blogs}");
16
 
17
+ foreach ($blogids as $blog_id) {
18
 
19
+ switch_to_blog($blog_id);
20
 
21
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
22
+ $version = get_option("yop_poll_version");
23
 
24
  /* if ( version_compare( $version, '4.9.2', '<=' ) &&isset($version)) {
25
  yop_poll_dump(12);
30
  } */
31
 
32
 
33
+ $poll_archive_page = get_page_by_path('yop-poll-archive', ARRAY_A);
34
 
35
+ if (!$poll_archive_page) {
36
 
37
+ $_p = array();
38
 
39
+ $_p['post_title'] = 'Yop Poll Archive';
40
 
41
+ $_p['post_content'] = "[yop_poll_archive]";
42
 
43
+ $_p['post_status'] = 'publish';
44
 
45
+ $_p['post_type'] = 'page';
 
 
46
 
47
  $_p['comment_status'] = 'open';
48
 
49
+ $_p['ping_status'] = 'open';
 
 
 
50
 
51
+ $_p['post_category'] = array(1); // the default 'Uncategorised'
52
 
 
53
 
54
+ $poll_archive_page_id = wp_insert_post($_p);
55
 
56
 
57
+ } else {
 
 
58
 
59
  $poll_archive_page_id = $poll_archive_page['ID'];
60
 
61
  }
62
 
63
 
64
+ call_user_func(array($this, $pfunction), $networkwide);
65
 
66
+ $version = get_option("yop_poll_version");
67
 
68
 
69
+ $default_options = get_option('yop_poll_options');
 
 
 
 
 
70
 
71
+ $default_options['archive_url'] = get_permalink($poll_archive_page_id);
 
 
 
72
 
73
  $default_options['yop_poll_archive_page_id'] = $poll_archive_page_id;
74
 
75
 
 
76
  //addind default options
77
 
78
+ update_option('yop_poll_options', $default_options);
 
79
 
80
 
81
  }
82
 
83
+ switch_to_blog($old_blog);
84
 
85
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
86
 
87
  return;
88
 
89
  }
90
  }
91
 
92
+ $version = get_option("yop_poll_version");
93
 
94
  /* if ( version_compare( $version, '4.9.2', '<=' ) &&isset($version)) {
95
  yop_poll_dump(12);
101
  } */
102
 
103
 
104
+ $poll_archive_page = get_page_by_path('yop-poll-archive', ARRAY_A);
105
 
106
+ if (!$poll_archive_page) {
107
 
108
+ $_p = array();
109
 
110
+ $_p['post_title'] = 'Yop Poll Archive';
111
 
112
+ $_p['post_content'] = "[yop_poll_archive]";
113
 
114
+ $_p['post_status'] = 'publish';
115
 
116
+ $_p['post_type'] = 'page';
 
 
 
 
 
 
117
 
118
  $_p['comment_status'] = 'open';
119
 
120
+ $_p['ping_status'] = 'open';
 
 
121
 
122
+ $_p['post_category'] = array(1); // the default 'Uncategorised'
123
 
124
 
125
+ $poll_archive_page_id = wp_insert_post($_p);
126
 
127
 
128
+ } else {
 
 
 
129
 
130
  $poll_archive_page_id = $poll_archive_page['ID'];
131
 
132
  }
133
 
134
 
 
135
  //addind default options
136
 
137
+ call_user_func(array($this, $pfunction), $networkwide);
138
 
139
 
140
+ $default_options = get_option('yop_poll_options');
141
 
142
+ $default_options['archive_url'] = get_permalink($poll_archive_page_id);
 
 
143
 
144
  $default_options['yop_poll_archive_page_id'] = $poll_archive_page_id;
145
 
146
 
 
147
  //addind default options
148
 
149
+ update_option('yop_poll_options', $default_options);
 
150
 
151
 
152
  }
153
 
154
+ function propagate_activation($networkwide)
155
+ {
156
  if (version_compare(phpversion(), '5.3', '<')) {
157
  wp_die("Php version isn't high enough!");
158
  }
159
 
160
+ $this->network_propagate('activate', $networkwide);
161
 
162
  }
163
 
164
+ function propagate_deactivation($networkwide)
165
+ {
166
  global $wpdb;
167
  // $wpdb->query( "DROP TABLE `" . $wpdb->prefix . "yop_pollmeta`, `" . $wpdb->prefix . "yop_polls`, `" . $wpdb->prefix . "yop_poll_answermeta`, `" . $wpdb->prefix . "yop_poll_answers`, `" . $wpdb->prefix . "yop_poll_custom_fields`, `" . $wpdb->prefix . "yop_poll_logs`, `" . $wpdb->prefix . "yop_poll_voters`, `" . $wpdb->prefix . "yop_poll_bans`, `" . $wpdb->prefix . "yop_poll_templates`, `" . $wpdb->prefix . "yop_poll_votes_custom_fields`, `" . $wpdb->prefix . "yop_poll_facebook_users`" );
168
+ $this->network_propagate('deactivate', $networkwide);
169
  }
170
+
171
+ public function some_function($x = 0, $current_options = array())
172
+ {
173
+ $installed_version = get_option("yop_poll_version");
174
  global $wpdb;
175
 
176
+ if (version_compare($installed_version, '4.9.3', '<=') || $x == 1) {
177
  if (!(version_compare(phpversion(), '5.3', '<'))) {
178
+ ini_set("memory_limit", "1024M");
179
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
180
+ require_once(YOP_POLL_INC . 'db_schema.php');
181
+ if (empty($current_options)) {
182
+ $current_options = get_option('yop_poll_options');
183
 
184
+ $default = get_option('yop_poll_options');
185
  }
186
  $capObj = YOP_POLL_Capabilities::get_instance();
187
  $capObj->install_capabilities();
188
  Yop_Poll_DbSchema::create_poll_database_tables();
189
+ $wpdb->query('ALTER TABLE `' . $wpdb->yop_polls . '` CHANGE `ID` `ID` INT( 11 ) NOT NULL ');
190
+ $this->install_default_options();
191
+
192
+ $new_options = array(
193
+
194
+ 'user_interface_type' => 'beginner',
195
+ 'is_default_answer' => $current_options['is_default_answer'],
196
+ 'poll_start_date' => current_time('mysql'),
197
+ 'poll_end_date' => '01-01-2038 23:59:59',
198
+ 'view_results' => array($current_options['view_results']),
199
+ 'view_results_start_date' => convert_date($current_options['view_results_start_date'], 'd-m-Y H:i:s', 1),
200
+ 'view_results_permissions' => array('guest', 'registered'),
201
+ 'view_results_type' => $current_options['view_results_type'],
202
+ 'answer_result_label' => $current_options['answer_result_label'],
203
+ 'vote_button_label' => $current_options['vote_button_label'],
204
+ 'template_width' => $current_options['template_width'],
205
+ 'widget_template_width' => $current_options['widget_template_width'],
206
+ 'view_results_link' => $current_options['view_results_link'],
207
+ 'view_results_link_label' => $current_options['view_results_link_label'],
208
+ 'view_back_to_vote_link' => $current_options['view_back_to_vote_link'],
209
+ 'view_back_to_vote_link_label' => $current_options['view_back_to_vote_link_label'],
210
+ 'view_total_votes' => $current_options['view_total_votes'],
211
+ 'view_total_votes_label' => $current_options['view_total_votes_label'],
212
+ 'view_total_answers' => $current_options['view_total_answers'],
213
+ 'view_total_answers_label' => $current_options['view_total_answers_label'],
214
+ 'message_after_vote' => $current_options['message_after_vote'],
215
+ 'vote_permisions' => array('guest', 'registered'),
216
+ 'vote_permisions_wordpress' => $current_options['vote_permisions_wordpress'],
217
+ 'vote_permisions_wordpress_label' => $current_options['vote_permisions_wordpress_label'],
218
+ 'vote_permisions_anonymous' => $current_options['vote_permisions_anonymous'],
219
+ 'vote_permisions_anonymous_label' => $current_options['vote_permisions_anonymous_label'],
220
+ 'blocking_voters' => array($current_options['blocking_voters']),
221
+ 'blocking_voters_interval_value' => $current_options['blocking_voters_interval_value'],
222
+ 'blocking_voters_interval_unit' => $current_options['blocking_voters_interval_unit'],
223
+ 'limit_number_of_votes_per_user' => $current_options['limit_number_of_votes_per_user'],
224
+ 'number_of_votes_per_user' => $current_options['number_of_votes_per_user'],
225
+ 'percentages_decimals' => $current_options['percentages_decimals'],
226
+ 'use_default_loading_image' => $current_options['use_default_loading_image'],
227
+ 'loading_image_url' => $current_options['loading_image_url'],
228
+ 'redirect_after_vote' => $current_options['redirect_after_vote'],
229
+ 'redirect_after_vote_url' => $current_options['redirect_after_vote_url'],
230
+ 'date_format' => 'UE',
231
+ 'view_poll_archive_link' => $current_options['view_poll_archive_link'],
232
+ 'auto_generate_poll_page' => $current_options['auto_generate_poll_page'],
233
+ 'has_auto_generate_poll_page' => $current_options['has_auto_generate_poll_page'],
234
+ 'use_captcha' => $current_options['use_captcha'],
235
+ 'send_email_notifications' => $current_options['send_email_notifications'],
236
+ 'allow_other_answers' => $current_options['allow_other_answers'],
237
+ 'other_answers_label' => $current_options['other_answers_label'],
238
+ 'is_default_other_answer' => $current_options['is_default_other_answer'],
239
+ 'add_other_answers_to_default_answers' => $current_options['add_other_answers_to_default_answers'],
240
+ 'display_other_answers_values' => $current_options['display_other_answers_values'],
241
+ 'allow_multiple_answers' => $current_options['allow_multiple_answers'],
242
+ 'allow_multiple_answers_number' => $current_options['allow_multiple_answers_number'],
243
+ 'allow_multiple_answers_min_number' => $current_options['allow_multiple_answers_min_number'],
244
+ 'display_answers' => $current_options['display_answers'],
245
+ 'display_answers_tabulated_cols' => $current_options['display_answers_tabulated_cols'],
246
+ 'sorting_results' => 'as_defined',
247
+ 'sorting_answers' => 'as_defined',
248
+ 'sorting_results_direction' => $current_options['sorting_results_direction'],
249
+ 'sorting_answers_direction' => $current_options['sorting_answers_direction'],
250
+ 'singular_answer_result_votes_number_label' => $current_options['singular_answer_result_votes_number_label'],
251
+ 'plural_answer_result_votes_number_label' => $current_options['plural_answer_result_votes_number_label'],
252
+ 'display_results' => $current_options['display_results'],
253
+ 'display_results_tabulated_cols' => $current_options['display_results_tabulated_cols'],
254
+ 'bar_background' => $current_options['bar_background'],
255
+ 'bar_height' => $current_options['bar_height'],
256
+ 'bar_border_color' => $current_options['bar_border_color'],
257
+ 'bar_border_width' => $current_options['bar_border_width'],
258
+ 'bar_border_style' => $current_options['bar_border_style'],
259
+ 'sorting_archive_polls' => 'votes',
260
+ 'sorting_archive_polls_rule' => 'asc',
261
+ 'archive_url' => $current_options['archive_url'],
262
+ 'archive_link_label' => $current_options['view_poll_archive_link_label'],
263
+ 'show_poll_in_archive' => $current_options['show_in_archive'],
264
+ 'poll_archive_order' => $current_options['archive_order'],
265
+ 'archive_polls_per_page' => $current_options['archive_polls_per_page'],
266
+ 'email_notifications_from_name' => $current_options['email_notifications_from_name'],
267
+ 'email_notifications_from_email' => $current_options['email_notifications_from_email'],
268
+ 'email_notifications_recipients' => $current_options['email_notifications_recipients'],
269
+ 'email_notifications_subject' => $current_options['email_notifications_subject'],
270
+ 'email_notifications_body' => '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
271
 
272
  <p>Vote Details:</p>
273
 
298
  [/QUESTION]
299
 
300
  <p><b>Vote ID:</b> <br />%VOTE_ID%</p>',
301
+ 'schedule_reset_poll_stats' => $current_options['schedule_reset_poll_stats'],
302
+ 'schedule_reset_poll_date' => current_time('mysql'),
303
+ 'schedule_reset_poll_recurring_value' => $current_options['schedule_reset_poll_recurring_value'],
304
+ 'schedule_reset_poll_recurring_unit' => $current_options['schedule_reset_poll_recurring_unit'],
305
+ 'singular_answer_result_votes_number_label' => __yop_poll("vote"),
306
+ 'plural_answer_result_votes_number_label' => __yop_poll("votes"),
307
+ 'start_scheduler' => $current_options['start_scheduler'],
308
+ 'use_the_same_template_for_widget' => 'yes',
309
+ 'vote_permisions_facebook' => 'no',
310
 
311
+ 'vote_permisions_facebook_label' => __yop_poll('Vote as Facebook User'),
312
 
313
+ 'facebook_share_after_vote' => 'no',
314
 
315
+ 'facebook_share_description' => __yop_poll('Just casted an YOP Poll vote on ') . get_bloginfo('name'),
316
 
317
+ 'vote_permisions_google' => 'no',
318
 
319
+ 'vote_permisions_google_label' => __yop_poll('Vote as G+ User'),
320
 
321
+ 'show_google_share_button' => 'no',
322
+ 'google_integration' => 'no',
323
+ 'facebook_integration' => 'no',
324
+ 'facebook_show_comments_widget' => "no"
325
  // 'view_total_answers_label' => __yop_poll( 'Poll total answers: %POLL-TOTAL-ANSWERS%' ),
326
 
327
  );
328
+ if ($current_options['blocking_voters'] == 'cookie-ip')
329
+ $new_options['blocking_voters'] = array("cookie", 'ip');
330
+ else {
331
+ if ($current_options['blocking_voters'] == 'username')
332
+ $new_options['blocking_voters'] = array('user_id');
333
  }
334
+ list($g1, $d) = explode('-', $current_options['view_results_permissions']);
335
+ $new_options['view_results_permissions'] = array($g1, $d);
336
+ list($g1, $d) = explode('-', $current_options['view_results_link']);
337
+ $new_options['view_results_link'] = array($g1, $d);
338
+ update_option('yop_poll_options', $new_options);
339
+ update_option("yop_poll_version", YOP_POLL_VERSION);
340
  YOP_POLL_Maintenance::activation_hook($default);
341
+ $wpdb->query('ALTER TABLE `' . $wpdb->yop_polls . '` CHANGE `ID` `ID` INT( 11 ) NOT NULL AUTO_INCREMENT ');
342
 
343
  }
344
  }
345
+ $installed_version = get_option("yop_poll_version");
346
 
347
+ if (version_compare($installed_version, '5.2', '<=')) {
348
  ini_set('max_execution_time', 700);
349
+ ini_set("memory_limit", "512M");
350
+ $default_poll_options = get_option('yop_poll_options');
351
+ $default_poll_options['email_notifications_body'] = '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
352
 
353
  <p>Vote Details:</p>
354
 
379
  [/QUESTION]
380
 
381
  <p><b>Vote ID:</b> <br />%VOTE_ID%</p>';
382
+ update_option('yop_poll_options', $default_poll_options);
383
+ $templates = self::yop_poll_get_templates_new_version_from_db();
384
+ foreach ($templates as $template) {
385
+ $template['js'] = <<<NOWDOC
386
  function stripBorder_%POLL-ID%(object) {
387
  object.each(function() {
388
  if( parseInt(jQuery(this).width() ) > 0) {
491
  NOWDOC;
492
  self::update_poll_template_in_database(($template));
493
  }
494
+ $polls = self::yop_poll_get_polls_for_body_mail_update();
495
+ foreach ($polls as $poll) {
496
+ $current = new YOP_POLL_Poll_Model($poll['ID']);
497
+ $current->email_notifications_body = '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
498
 
499
  <p>Vote Details:</p>
500
 
528
  $current->save();
529
 
530
  }
531
+ update_option("yop_poll_version", YOP_POLL_VERSION);
532
  }
533
+ $installed_version = get_option("yop_poll_version");
534
+ if (version_compare($installed_version, '5.3', '<=')) {
535
+ update_option("yop_poll_version", YOP_POLL_VERSION);
536
  }
537
+ $installed_version = get_option("yop_poll_version");
538
+ if (version_compare($installed_version, '5.5', '<=')) {
539
+ update_option("yop_poll_version", YOP_POLL_VERSION);
540
  }
541
+ $installed_version = get_option("yop_poll_version");
542
 
543
+ if (version_compare($installed_version, '5.6', '<=')) {
544
  global $wpdb;
545
+ update_option("yop_poll_version", YOP_POLL_VERSION);
546
+ $default_poll_options = get_option('yop_poll_options');
547
+ $default_poll_options['show_results_in'] = "bar";
548
+ update_option('yop_poll_options', $default_poll_options);
549
 
550
+ $wpdb->query('ALTER TABLE `' . $wpdb->yop_poll_templates . '` ADD `after_vote_template_chart` text');
551
+ update_option("yop_poll_version", '5.7');
552
 
553
  }
554
+ if (version_compare($installed_version, '5.7', '<=')) {
555
  global $wpdb;
556
+ update_option("yop_poll_version", YOP_POLL_VERSION);
557
 
558
+ $templates = self::yop_poll_get_templates_new_version_from_db();
559
+ foreach ($templates as $template) {
560
+ $template['js'] = <<<NOWDOC
561
  function stripBorder_%POLL-ID%(object) {
562
  object.each(function() {
563
  if( parseInt(jQuery(this).width() ) > 0) {
712
 
713
  };
714
  NOWDOC;
715
+ $template['after_vote_template_chart'] = <<<NOWDOC
716
  [QUESTION_CONTAINER]
717
  <div id = "yop-poll-question-container-%POLL-ID%-%QUESTION-ID%" class = "yop-poll-question-container-%POLL-ID%">
718
  <div id = "yop-poll-question-%POLL-ID%-%QUESTION-ID%"
735
  NOWDOC;
736
  self::update_poll_template_in_database2($template);
737
  }
738
+ update_option("yop_poll_version", '5.7.1');
739
 
740
  }
741
+ if (version_compare($installed_version, '5.7.1', '<=')) {
742
  global $wpdb;
743
+ update_option("yop_poll_version", '5.7.2');
744
  }
745
+ if (version_compare($installed_version, '5.7.2', '<=')) {
746
  global $wpdb;
747
+ update_option("yop_poll_version", '5.7.3');
748
  }
749
+ if (version_compare($installed_version, '5.7.3', '<=')) {
750
  global $wpdb;
751
+ update_option("yop_poll_version", '5.7.4');
752
+ }
753
+ if (version_compare($installed_version, '5.7.4', '<=')) {
754
+ global $wpdb;
755
+ update_option("yop_poll_version", '5.7.5');
756
  }
757
  }
758
+
759
+ private static function update_poll_template_in_database2($template)
760
+ {
761
  global $wpdb;
762
+ $sql = $wpdb->query($wpdb->prepare("
763
  UPDATE " . $wpdb->yop_poll_templates . "
764
  SET name = %s,
765
  before_vote_template = %s,
772
  last_modified = %s
773
  WHERE
774
  id = %d
775
+ ", $template['name'], $template['before_vote_template'], $template['after_vote_template'], $template['after_vote_template_chart'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time('mysql'), $template['id']));
776
  return $sql;
777
  }
778
+
779
+ public function yop_poll_get_polls_for_body_mail_update()
780
+ {
781
  global $wpdb;
782
+ $result = $wpdb->get_results(("
783
  SELECT ID
784
+ FROM " . $wpdb->yop_polls . " ORDER BY ID ASC
785
+ "), ARRAY_A);
786
  return $result;
787
  }
788
+
789
+ private function install_default_options()
790
+ {
791
+ $default_poll_options = get_option('yop_poll_options');
792
 
793
  $default_poll_options['is_default_answer'] = 'no';
794
+ $default_poll_options['poll_start_date'] = current_time('mysql');
795
+ $default_poll_options['poll_end_date'] = '01-01-2038 23:59:59';
796
 
797
+ update_option('yop_poll_options', $default_poll_options);
798
  }
799
 
800
+ private function uninstall_default_options()
801
+ {
802
  // delete_option( "yop_poll_version" );
803
  // delete_option( "yop_poll_options" );
804
  }
805
 
806
+ public function activate($networkwide)
807
+ {
808
+ if (!current_user_can('activate_plugins')) {
809
+ $error = new WP_Error ('Wordpress_version_error', __yop_poll('You need permissions to activate this plugin'), __yop_poll('Error: Wordpress Activation Permissions Problem'));
810
  }
811
 
812
+ if (!version_compare($GLOBALS['wp_version'], YOP_POLL_WP_VERSION, '>=')) {
813
+ $error = new WP_Error ('Wordpress_version_error', sprintf(__yop_poll('You need at least Wordpress version %s to use this plugin'), YOP_POLL_WP_VERSION), __yop_poll('Error: Wordpress Version Problem'));
814
+ $error = new WP_Error ('Wordpress_version_error', sprintf(__yop_poll('You need at least Wordpress version %s to use this plugin'), YOP_POLL_WP_VERSION), __yop_poll('Error: Wordpress Version Problem'));
815
  }
816
 
817
+ if (isset ($error) && is_wp_error($error)) {
818
+ wp_die($error->get_error_message(), $error->get_error_data());
819
  }
820
 
821
 
822
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
823
+ require_once(YOP_POLL_INC . 'db_schema.php');
824
  $this->install_default_options();
825
  $capObj = YOP_POLL_Capabilities::get_instance();
826
  $capObj->install_capabilities();
827
  Yop_Poll_DbSchema::install_database();
828
  }
829
 
830
+ public function deactivatedelete($networkwide)
831
+ {
832
+ require_once(YOP_POLL_INC . 'db_schema.php');
833
  Yop_Poll_DbSchema::delete_database_tables();
834
  $capObj = YOP_POLL_Capabilities::get_instance();
835
  $capObj->uninstall_capabilities();
836
  $this->uninstall_default_options();
837
  }
838
 
839
+ function new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta)
840
+ {
841
+ if (!function_exists('is_plugin_active_for_network')) {
842
+ require_once(ABSPATH . '/wp-admin/includes/plugin.php');
843
  }
844
+ if (is_plugin_active_for_network(YOP_POLL_SHORT_PLUGIN_FILE)) {
845
  $old_blog = $GLOBALS['wpdb']->blogid;
846
+ switch_to_blog($blog_id);
847
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
848
+ $this->activate(null);
849
+ switch_to_blog($old_blog);
850
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
851
  }
852
  }
853
 
854
+ function delete_blog($blog_id)
855
+ {
856
  $old_blog = $GLOBALS['wpdb']->blogid;
857
+ switch_to_blog($blog_id);
858
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
859
+ $this->deactivatedelete(null);
860
+ require_once(YOP_POLL_INC . 'db_schema.php');
861
  // Yop_Poll_DbSchema::delete_database_tables();
862
  $capObj = YOP_POLL_Capabilities::get_instance();
863
  $capObj->uninstall_capabilities();
864
  $this->uninstall_default_options();
865
+ switch_to_blog($old_blog);
866
+ yop_poll_create_table_names($GLOBALS['wpdb']->prefix);
867
  }
868
 
869
+ function update()
870
+ {
871
  }
872
 
873
+ public function activation_hook($default)
874
+ {
875
  ini_set('max_execution_time', 700);
876
+ $current_options = get_option('yop_poll_options');
877
+ $polls = self::yop_poll_get_polls_from_db();
878
+ $answers = self::yop_poll_get_answers_from_db();
879
+ $logs = self::yop_poll_get_logs_from_db();
880
+ $bans = self::yop_poll_get_bans_from_db();
881
  $custom_fields = self::yop_poll_get_custom_fields_from_db();
882
+ $custom_votes = self::yop_poll_get_custom_fields_votes_from_db();
883
+ $metas = self::yop_poll_get_polls_meta_from_db();
884
+ $answers_meta = self::yop_poll_get_answers_meta_from_db();
885
+ $templates = self::yop_poll_get_templates_from_db();
886
+ foreach ($templates as $template) {
887
+ $template['before_vote_template'] = "[QUESTION_CONTAINER]" . $template['before_vote_template'];
888
+ $template['before_vote_template'] = str_replace('%POLL-ANSWER-LABEL%', '%POLL-ANSWER-LABEL% [ANSWER_RESULT_CONTAINER]', $template['before_vote_template']);
889
+ $template['before_vote_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['before_vote_template']);
890
+ $template['before_vote_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['before_vote_template']);
891
+ $template['after_vote_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['after_vote_template']);
892
+ $template['after_vote_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['after_vote_template']);
893
+ $template['after_end_date_template'] = str_replace('%POLL-TOTAL-ANSWERS%', '%POLL-TOTAL-ANSWERS-LABEL%', $template['after_end_date_template']);
894
+ $template['after_end_date_template'] = str_replace('%POLL-TOTAL-VOTES%', '%POLL-TOTAL-VOTES-LABEL%', $template['after_end_date_template']);
895
+ $template['before_vote_template'] = preg_replace('/%POLL-ANSWER-RESULT-BAR%/', '%POLL-ANSWER-RESULT-BAR% [/ANSWER_RESULT_CONTAINER]', $template['before_vote_template'], 1);
896
  $find = '[/ANSWER_RESULT_CONTAINER]';
897
  $replace = '';
898
  // $template['before_vote_template']= preg_replace(strrev("/$find/"),strrev($replace),strrev( $template['before_vote_template']),1);
899
+ $template['after_vote_template'] = "[QUESTION_CONTAINER]" . $template['after_vote_template'];
900
+ $template['after_end_date_template'] = "[QUESTION_CONTAINER]" . $template['after_end_date_template'];
901
  /* if(strpos($template['before_vote_template'],"[CAPTCHA_CONTAINER]"))
902
  $template['before_vote_template']=str_replace('[CAPTCHA_CONTAINER]','[/QUESTION_CONTAINER][CAPTCHA_CONTAINER]',$template['before_vote_template']);
903
  else{
904
  $template['before_vote_template']=str_replace('<div id="yop-poll-vote-%POLL-ID%" class="yop-poll-footer">','[/QUESTION_CONTAINER]<div id="yop-poll-vote-%POLL-ID%" class="yop-poll-footer">',$template['before_vote_template']);
905
  } */
906
+ $template['before_vote_template'] = $template['before_vote_template'] . '[/QUESTION_CONTAINER]';
907
+ if (strpos($template['before_vote_template'], "%POLL-QUESTION%") && strpos($template['before_vote_template'], '%POLL-NAME%')) {
908
+ $template['before_vote_template'] = str_replace('%POLL-QUESTION%', '', $template['before_vote_template']);
909
+ $template['before_vote_template'] = str_replace('%POLL-NAME%', '%POLL-QUESTION%', $template['before_vote_template']);
910
  }
911
+ if (strpos($template['after_vote_template'], "%POLL-QUESTION%") && strpos($template['after_vote_template'], '%POLL-NAME%')) {
912
+ $template['after_vote_template'] = str_replace('%POLL-QUESTION%', '', $template['after_vote_template']);
913
+ $template['after_vote_template'] = str_replace('%POLL-NAME%', '%POLL-QUESTION%', $template['after_vote_template']);
914
  }
915
+ $template['after_vote_template'] = $template['after_vote_template'] . '[/QUESTION_CONTAINER]';
916
+ $template['after_end_date_template'] = $template['after_end_date_template'] . '[/QUESTION_CONTAINER]';
917
+ $template['js'] = <<<NOWDOC
918
  function stripBorder_%POLL-ID%(object) {
919
  object.each(function() {
920
  if( parseInt(jQuery(this).width() ) > 0) {
1070
  };
1071
 
1072
  NOWDOC;
1073
+ $template['js'] = addslashes($template['js']);
1074
+ $templates_ids[$template['id']] = self::insert_template_in_databease(($template));
1075
  }
1076
 
1077
+ foreach ($polls as $poll) {
1078
 
1079
+ foreach ($answers as $answer) {
1080
+ if ($answer['poll_id'] == $poll['id']) {
1081
  $answers_ordonate[$poll['id']][] = (array)$answer;
1082
  }
1083
+ if ($answer['poll_id'] > $poll['id']) {
1084
  break;
1085
  }
1086
 
1087
+ foreach ($logs as $log) {
1088
+ if ($log['poll_id'] == $poll['id'] && $log['answer_id'] == $answer['id']) {
1089
+ $logs_ordonate[$poll['id']][] = (array)$log;
1090
  $logs_ordonate_details[$log['id']][] = $answer['answer'];
1091
  }
1092
  }
1093
+ foreach ($answers_meta as $answer_meta) {
1094
+ if ($answer_meta['yop_poll_answer_id'] == $answer['id']) {
1095
  $answer_meta_ordonate[$answer['id']][] = (array)$answer_meta;
1096
  }
1097
  }
1098
  }
1099
 
1100
+ foreach ($bans as $ban) {
1101
+ if ($ban['poll_id'] == $poll['id']) {
1102
  $bans_ordonate[$poll['id']][] = (array)$ban;
1103
  }
1104
+ if ($ban['poll_id'] > $poll['id']) {
1105
  break;
1106
  }
1107
  }
1108
 
1109
+ foreach ($metas as $meta) {
1110
+ if ($meta['yop_poll_id'] == $poll['id']) {
1111
  $metas_ordonate[$poll['id']][] = (array)$meta;
1112
  }
1113
+ if ($meta['yop_poll_id'] > $poll['id']) {
1114
  break;
1115
  }
1116
  }
1117
 
1118
+ foreach ($custom_fields as $custom_field) {
1119
+ if ($custom_field['poll_id'] == $poll['id']) {
1120
  $custom_fields_ordonate[$poll['id']][] = (array)$custom_field;
1121
+ if ($custom_field['poll_id'] > $poll['id']) {
1122
  break;
1123
  }
1124
 
1125
+ foreach ($custom_votes as $custom_vote) {
1126
+ if ($custom_field['id'] == $custom_vote['custom_field_id']) {
1127
  $custom_votes_fields_ordonate[$custom_field['id']][] = (array)$custom_vote;
1128
  }
1129
  }
1132
  }
1133
 
1134
 
1135
+ foreach ($polls as $poll) {
1136
+ $current_poll = new YOP_POLL_Poll_Model();
1137
+ $current_poll->poll_author = $poll['poll_author'];
1138
+ $current_poll->ID = $poll['id'];
1139
+ $current_poll->poll_title = $poll['name'];
1140
+ $current_poll->poll_name = $poll['name'];
1141
+ $current_poll->poll_date = $poll['date_added'];
1142
  $current_poll->poll_modified = $poll['last_modified'];
1143
+ $current_poll->poll_status = $poll['status'];
1144
+ $current_poll->poll_type = "poll";
1145
+ $current_poll->poll_status = $poll['status'];
1146
+ $current_poll->email_notifications_body = '<p>A new vote was registered on %VOTE_DATE% for %POLL_NAME%</p>
1147
 
1148
  <p>Vote Details:</p>
1149
 
1174
  [/QUESTION]
1175
 
1176
  <p><b>Vote ID:</b> <br />%VOTE_ID%</p>';
1177
+ if ($poll['end_date'] <= "2038-01-18 23:59:59") {
 
 
1178
 
1179
+ $current_poll->poll_end_date = convert_date($poll['end_date'], 'd-m-Y H:i:s', 1);
1180
 
1181
+ } else {
1182
 
1183
  $current_poll->poll_end_date = "01-01-2038 23:59:59";
1184
 
1185
  }
1186
 
1187
+ if ($poll['start_date'] <= "2038-01-18 23:59:59") {
1188
 
1189
+ $current_poll->poll_start_date = convert_date($poll['start_date'], 'd-m-Y H:i:s', 1);
1190
 
1191
+ } else {
 
 
1192
 
1193
  $current_poll->poll_start_date = "01-01-2038 23:59:59";
1194
 
1195
  }
1196
  $current_poll->poll_total_votes = $poll['total_votes'];
1197
+ $question = new YOP_POLL_Question_Model();
1198
+ $question->type = "text";
1199
+ $question->question = $poll['question'];
1200
+ $question->question_date = $current_poll->poll_date;
1201
+ $question->question_author = $current_poll->poll_author;
1202
+ $question->question_modified = $current_poll->poll_modified;
1203
+ $question->question_status = $current_poll->poll_status;
1204
+ $question->poll_order = 1;
1205
+ $i = 0;
1206
+
1207
+
1208
+ foreach ($answers_ordonate[$poll['id']] as $answer_ordonate) {
1209
+
1210
+ if ($answer_ordonate['type'] == "other") {
1211
+ $current_poll->allow_other_answers = 'yes';
1212
+ $question->allow_other_answers = 'yes';
 
1213
  }
1214
  }
1215
+ $q[] = $question;
1216
  // yop_poll_dump($current_poll);
1217
  $current_poll->questions = $q;
1218
+ $current_poll->auto_generate_poll_page = "no";
1219
+ $current_poll_id = $current_poll->insert();
1220
+ $current_poll_id = $current_poll->ID;
1221
  // yop_poll_dump($current_poll->save())
1222
+ $no_modif = 0;
1223
+ $no_modif2 = 0;
1224
+ $current_poll_meta = $current_options;
1225
+ if (isset($metas_ordonate[$poll['id']])) {
1226
+ $poll_option = maybe_unserialize($metas_ordonate[$poll['id']][0]['meta_value']);
1227
+ foreach ($current_options as $key => $value) {
1228
+ if (isset($poll_option[$key])) {
1229
 
1230
+ if ($key == 'view_results_permissions') {
1231
 
1232
+ list($g1, $d) = explode('-', $poll_option[$key]);
1233
+ if ($g1 == "quest") {
1234
+ $g1 = "guest";
1235
 
1236
  }
1237
 
1238
+ $current_poll_meta[$key] = array($g1, $d);
1239
+ $no_modif = 1;
1240
 
1241
+ } else
1242
+ if ($key == 'vote_permisions') {
1243
+ list($g1, $d) = explode('-', $poll_option['vote_permisions']);
1244
+ if ($g1 == "quest") {
1245
+ $g1 = "guest";
 
1246
 
1247
  }
1248
+ $no_modif2 = 1;
1249
+ $current_poll_meta[$key] = array($g1, $d);
1250
+ } else
 
1251
  $current_poll_meta[$key] = $poll_option[$key];
1252
 
1253
 
1254
  } else
1255
+ $current_poll_meta[$key] = $default[$key];
1256
  }
1257
  }
1258
+ $current_poll_meta['view_results'] = array($poll_option['view_results']);
1259
  $current_poll_meta['sorting_results'] = $default['sorting_answers'];
1260
+ if (!isset($poll_option['view_results_link'])) {
1261
+ $current_poll_meta['view_results_link'] = "yes";
1262
+ } else
1263
+ $current_poll_meta['view_results_link'] = $poll_option['view_results_link'];
1264
+
1265
+ if ($poll_option['view_results'] == 'custom-date')
1266
+ $current_poll_meta['view_results_start_date'] = $poll_option['view_results_start_date'];
1267
+ if (empty($current_poll_meta['view_results'][0])) {
 
1268
  $current_poll_meta['view_results'] = array('after');
1269
  }
1270
+ if ($no_modif == 0 || empty($current_poll_meta['view_results'])) {
1271
+ $current_poll_meta['view_results_permissions'] = array('guest', 'registered');
1272
 
1273
  }
1274
 
1275
+ if ($no_modif2 == 0 || empty($current_poll_meta['vote_permisions'])) {
1276
+ $current_poll_meta['vote_permisions'] = array('guest', 'registered');
1277
  }
1278
 
1279
+ if ($poll_option['blocking_voters'] == 'cookie-ip')
1280
+ $current_poll_meta['blocking_voters'] = array("cookie", 'ip');
1281
  else {
1282
+ if ($poll_option['blocking_voters'] == 'username')
1283
+ $current_poll_meta['blocking_voters'] = array("user_id");
1284
  else
1285
+ $current_poll_meta['blocking_voters'] = array('dont-block');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1286
  }
1287
+ $current_poll_meta['facebook_share_after_vote'] = "no";
1288
+ $current_poll_meta['show_google_share_button'] = "no";
1289
+ $current_poll_meta['facebook_show_comments_widget'] = "no";
1290
+ $current_poll_meta['facebook_share_description'] = __yop_poll('Just casted an YOP Poll vote on ') . get_bloginfo('name');
1291
+ if (isset($poll_option['show_in_archive']))
1292
+ $current_poll_meta['show_poll_in_archive'] = $poll_option['show_in_archive'];
1293
+ if (isset($poll_option['schedule_reset_poll_date']))
1294
+ $current_poll_meta['schedule_reset_poll_date'] = $poll_option['schedule_reset_poll_date'];
1295
+ if (isset($poll_option['template'])) {
1296
+ $current_poll_meta['template'] = $templates_ids[$poll_option['template']];
1297
+ } else $current_poll_meta['template'] = 1;
1298
+ if (isset($poll_option['widget_template'])) {
1299
+ $current_poll_meta['widget_template'] = $templates_ids[$poll_option['widget_template']];
1300
+ } else $current_poll_meta['widget_template'] = 1;
1301
+ if (isset($poll_option['widget_template']) && isset($poll_option['template']) && $poll_option['template'] != $poll_option['widget_template']) {
1302
+ $current_poll_meta['use_the_same_template_for_widget'] = "no";
1303
  }
1304
+ if (isset($poll_option['view_total_answers_label'])) {
1305
+ $current_poll_meta['view_total_answers_label'] = $default['view_total_answers_label'];
1306
  }
1307
+ if (isset($poll_option['answer_result_label'])) {
1308
+ $current_poll_meta['answer_result_label'] = $default['answer_result_label'];
1309
  }
1310
+ if ($current_poll_meta['vote_permisions_anonymous'] == "no" && $current_poll_meta['vote_permisions_wordpress'] == "no") {
1311
+ $current_poll_meta['vote_permisions_anonymous'] = "yes";
1312
  }
1313
+ update_yop_poll_question_meta($current_poll_id, 'options', $current_poll_meta);
1314
+ update_yop_poll_meta($current_poll_id, 'options', $current_poll_meta);
1315
+ if ($poll['show_in_archive'] == "yes") {
1316
+ self::save_poll_order($current_poll_id, $poll['archive_order']);
1317
  }
1318
 
1319
+ if ($default['sorting_answers'] == "votes") {
1320
+ $answers_ordonate[$poll['id']] = self::get_answers_order_by_votes($poll['id'], $default['sorting_answers_direction']);
1321
+ }
1322
+ if ($default['sorting_answers'] == "alphabetical") {
1323
+ $answers_ordonate[$poll['id']] = self::get_answers_order_by_alph($poll['id'], $default['sorting_answers_direction']);
1324
  }
1325
+ foreach ($answers_ordonate[$poll['id']] as $answer_ordonate) {
1326
+ $ans = new YOP_POLL_Answer_Model();
1327
+ $ans->answer = $answer_ordonate['answer'];
1328
+ $ans->answer_author = $current_poll->poll_author;
1329
+ $ans->answer_date = $current_poll->poll_date;
1330
  $ans->answer_modified = $poll['last_modified'];
1331
+ if ($answer_ordonate['type'] != "other") {
1332
  $ans->type = "text";
1333
+ } else {
1334
+ $current_poll->allow_other_answers = 'yes';
1335
+ $question->allow_other_answers = 'yes';
 
1336
  $ans->type = "other";
1337
  }
1338
+ $ans->answer_status = $answer['status'];
1339
+ $ans->votes = $answer_ordonate['votes'];
1340
+ $ans->question_order = $i++;
1341
 
1342
+ if ($answer_ordonate['type'] != "other") {
1343
  $answersa[] = $ans;
1344
+ if (isset($answer_meta_ordonate[$answer_ordonate['id']])) {
1345
+ $answer_option = maybe_unserialize($answer_meta_ordonate[$answer_ordonate['id']][0]['meta_value']);
1346
  $answer_options = $ans->options;
1347
+ foreach ($ans->options as $key => &$value) {
1348
+ if (isset($answer_option[$key])) {
1349
  $ans->$key = $answer_option[$key];
1350
  }
1351
 
1353
  $ans->options = $answer_options;
1354
  }
1355
 
1356
+ $question->addAnswer($ans);
1357
 
1358
  $question->save_answers();
1359
  $answersids[$answer_ordonate['id']] = $ans->ID;
1360
  }
1361
 
1362
  }
1363
+ if (!empty($custom_fields_ordonate[$poll['id']]))
1364
+ foreach ($custom_fields_ordonate[$poll['id']] as $custom_ordonate) {
1365
+ $oldid = $custom_ordonate['id'];
1366
+ // $question = $current_poll->questions;
1367
+ $custom_ordonate['question_id'] = $current_poll_id;
1368
+ $custom_ordonate['poll_id'] = $current_poll_id;
1369
+ $newid = insert_custom_field_in_db($custom_ordonate);
1370
+ foreach ($custom_votes_fields_ordonate[$oldid] as $votes) {
1371
+ $votes['custom_field_id'] = $newid;
1372
+ $votes['question_id'] = $current_poll_id;
1373
+ $votes['poll_id'] = $current_poll_id;
1374
+ $votes['id'] = insert_votes_custom_in_db($votes);
1375
+ $custom_field_vote[$poll['id']][] = $votes;
1376
+ }
1377
  }
 
1378
 
1379
+ if (!empty($logs_ordonate[$poll['id']]))
1380
+ foreach ($logs_ordonate[$poll['id']] as $log_ordonate) {
1381
+ $log['poll_id'] = $current_poll_id;
1382
+ $log['vote_id'] = $log_ordonate['vote_id'];
1383
+ $log['ip'] = $log_ordonate['ip'];
1384
+ $log['user_id'] = $log_ordonate['user_id'];
1385
+ $log['user_type'] = $log_ordonate['user_type'];
1386
+ $log['vote_date'] = $log_ordonate['vote_date'];
1387
+ $log['tr_id'] = $log_ordonate['tr_id'];
1388
+ $vote_details[1]["q-" . $current_poll_id]['question'] = $poll['question'];
1389
+ $vote_details[1]["q-" . $current_poll_id]['id'] = $current_poll_id;
1390
+ $vote_details[1]["q-" . $current_poll_id]['a'][] = $answersids[$log_ordonate['answer_id']];
1391
+ if ($log_ordonate['other_answer_value'] != "" && isset($log_ordonate['other_answer_value'])) {
1392
+ $ans = new YOP_POLL_Answer_Model();
1393
+ $ans->answer = $answer_ordonate['answer'];
1394
+ $ans->answer_author = $current_poll->poll_author;
1395
+ $ans->answer_date = $current_poll->poll_date;
1396
+ $ans->answer_modified = $poll['last_modified'];
1397
+ $ans->answer = $log_ordonate['other_answer_value'];
1398
+ $ans->answer_status = 'active';
1399
+ $ans->votes = 1;
1400
+ $ans->type = 'other';
1401
+ $ans->question_order = $i++;
1402
+ $question->addAnswer($ans);
1403
+ $question->save_answers();
 
 
 
 
 
1404
  }
1405
+ if (!empty($custom_field_vote[$poll['id']]))
1406
+ foreach ($custom_field_vote[$poll['id']] as $vote) {
1407
+ if ($vote['vote_id'] == $log_ordonate['vote_id']) {
1408
+ $vote_details[1]["q-" . $current_poll_id]['cf'][] = $vote['id'];
1409
+ }
1410
 
1411
+ }
1412
+ foreach ($logs_ordonate_details[$log_ordonate['id']] as $a) {
1413
+ $vote_details[1]["q-" . $current_poll_id]['answers'][] = $a;
1414
+ $log['vote_details'] = json_encode($vote_details[1]);
1415
+ $log['message'] = "Succes";
1416
+ insert_result_in_db($log);
1417
+ insert_log_in_db($log);
1418
+ unset($vote_details[1]["q-" . $current_poll_id]['answers']);
1419
+ }
1420
+ unset($vote_details);
1421
  }
1422
+ if (!empty($bans_ordonate[$poll['id']]))
1423
+ foreach ($bans_ordonate[$poll['id']] as $ban_ordonate) {
1424
+ $ban = $ban_ordonate;
1425
+ $ban['poll_id'] = $current_poll_id;
1426
+ self::insert_ban_in_db($ban);
 
 
1427
  }
 
 
 
 
 
 
 
 
1428
 
1429
 
1430
  }
1431
 
1432
  }
1433
 
1434
+ public function insert_template_in_databease($template)
1435
+ {
1436
  global $wpdb;
1437
+ $sql = $wpdb->query($wpdb->prepare("
1438
  INSERT INTO " . $wpdb->yop_poll_templates . "
1439
  SET
1440
  template_author = %d,
1448
  date_added = %s,
1449
  last_modified = %s,
1450
  status = %s
1451
+ ", $template['template_author'], $template['name'], $template['before_vote_template'], $template['after_vote_template'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time('mysql'), current_time('mysql'), $template['status']));
1452
  return $GLOBALS['wpdb']->insert_id;
1453
  }
1454
+
1455
+ private static function update_poll_template_in_database($template)
1456
+ {
1457
  global $wpdb;
1458
+ $sql = $wpdb->query($wpdb->prepare("
1459
  UPDATE " . $wpdb->yop_poll_templates . "
1460
  SET name = %s,
1461
  before_vote_template = %s,
1467
  last_modified = %s
1468
  WHERE
1469
  id = %d
1470
+ ", $template['name'], $template['before_vote_template'], $template['after_vote_template'], $template['before_start_date_template'], $template['after_end_date_template'], $template['css'], $template['js'], current_time('mysql'), $template['id']));
1471
  return $sql;
1472
  }
1473
+
1474
+ public function yop_poll_get_polls_from_db()
1475
+ {
1476
  global $wpdb;
1477
+ $result = $wpdb->get_results(("
1478
  SELECT *
1479
  FROM " . $wpdb->prefix . "yop_polls ORDER BY id ASC
1480
+ "), ARRAY_A);
1481
  return $result;
1482
 
1483
  }
1484
 
1485
+ public function yop_poll_get_polls_meta_from_db()
1486
+ {
1487
  global $wpdb;
1488
+ $result = $wpdb->get_results(("
1489
  SELECT *
1490
  FROM " . $wpdb->prefix . "yop_pollmeta ORDER BY yop_poll_id ASC
1491
+ "), ARRAY_A);
1492
  return $result;
1493
 
1494
  }
1495
 
1496
+ public function yop_poll_get_answers_meta_from_db()
1497
+ {
1498
  global $wpdb;
1499
 
1500
+ $result = $wpdb->get_results(("
1501
  SELECT *
1502
  FROM " . $wpdb->prefix . "yop_poll_answermeta
1503
+ "), ARRAY_A);
1504
  return $result;
1505
 
1506
  }
1507
 
1508
+ public function yop_poll_get_templates_from_db()
1509
+ {
1510
  global $wpdb;
1511
+ $result = $wpdb->get_results(("
1512
  SELECT *
1513
  FROM " . $wpdb->prefix . "yop_poll_templates
1514
+ "), ARRAY_A);
1515
  return $result;
1516
  }
1517
+
1518
+ public function yop_poll_get_templates_new_version_from_db()
1519
+ {
1520
  global $wpdb;
1521
+ $result = $wpdb->get_results(("
1522
  SELECT *
1523
  FROM " . $wpdb->yop_poll_templates
1524
+ ), ARRAY_A);
1525
  return $result;
1526
  }
1527
 
1528
+ public function yop_poll_get_custom_fields_from_db()
1529
+ {
1530
  global $wpdb;
1531
+ $result = $wpdb->get_results(("
1532
  SELECT *
1533
  FROM " . $wpdb->prefix . "yop_poll_custom_fields ORDER BY poll_id ASC
1534
+ "), ARRAY_A);
1535
  return $result;
1536
  }
1537
 
1538
+ public function yop_poll_get_custom_fields_votes_from_db()
1539
+ {
1540
  global $wpdb;
1541
+ $result = $wpdb->get_results(("
1542
  SELECT *
1543
  FROM " . $wpdb->prefix . "yop_poll_votes_custom_fields
1544
+ "), ARRAY_A);
1545
  return $result;
1546
  }
1547
 
1548
+ public function yop_poll_get_bans_from_db()
1549
+ {
1550
  global $wpdb;
1551
+ $result = $wpdb->get_results(("
1552
  SELECT *
1553
  FROM " . $wpdb->prefix . "yop_poll_bans ORDER BY poll_id ASC
1554
+ "), ARRAY_A);
1555
  return $result;
1556
  }
1557
+
1558
+ public function yop_poll_get_answers_from_db()
1559
+ {
1560
  global $wpdb;
1561
+ $result = $wpdb->get_results(("
1562
  SELECT *
1563
  FROM " . $wpdb->prefix . "yop_poll_answers ORDER BY poll_id ASC
1564
+ "), ARRAY_A);
1565
  return $result;
1566
  }
1567
+
1568
+ public function get_answers_order_by_votes($poll_id, $dir)
1569
+ {
1570
  global $wpdb;
1571
+ $result = $wpdb->get_results($wpdb->prepare("
1572
  SELECT *
1573
  FROM " . $wpdb->prefix . "yop_poll_answers WHERE poll_id=%d ORDER BY votes $dir
1574
+ ", $poll_id), ARRAY_A);
1575
  return $result;
1576
  }
1577
 
1578
+ public function get_answers_order_by_alph($poll_id, $dir)
1579
+ {
1580
  global $wpdb;
1581
+ $result = $wpdb->get_results($wpdb->prepare("
1582
  SELECT *
1583
  FROM " . $wpdb->prefix . "yop_poll_answers WHERE poll_id=%d ORDER BY answer $dir
1584
+ ", $poll_id), ARRAY_A);
1585
  return $result;
1586
  }
1587
 
1588
+ public function yop_poll_get_logs_from_db()
1589
+ {
1590
  global $wpdb;
1591
+ $result = $wpdb->get_results(("
1592
  SELECT *
1593
  FROM " . $wpdb->prefix . "yop_poll_logs
1594
+ "), ARRAY_A);
1595
  return $result;
1596
  }
1597
 
1598
+ private static function insert_ban_in_db($ban)
1599
+ {
1600
  global $wpdb;
1601
+ $sql = $wpdb->query($wpdb->prepare("
1602
  INSERT INTO $wpdb->yop_poll_bans
1603
  ( poll_id,type,value,period ,unit)
1604
  VALUES(%d,%s,%s,%d,%s)
1605
+ ", $ban['poll_id'], $ban['type'], $ban['value'], intval($ban['period']), $ban['unit']));
1606
+ return $wpdb->get_results($sql);
1607
  }
1608
+
1609
+ private function save_poll_order($poll, $poll_order)
1610
+ {
1611
+ $poll_archive_order = get_option('yop_poll_archive_order', array());
1612
+ if ($poll_archive_order == "") {
1613
  $poll_archive_order = array();
 
 
1614
  }
1615
+ if (trim($poll_order) <= 0) {
1616
+ $poll_order = 1;
 
1617
  }
1618
+ $key = array_search($poll, $poll_archive_order);
1619
+ if ($key !== false) {
1620
+ unset($poll_archive_order[$key]);
1621
  }
1622
+ if ($poll_order > count($poll_archive_order)) {
1623
+ array_push($poll_archive_order, $poll);
1624
+ } else {
1625
+ array_splice($poll_archive_order, trim($poll_order) - 1, 0, array($poll));
1626
  }
1627
+ update_option('yop_poll_archive_order', $poll_archive_order);
1628
  }
1629
 
1630
  }
models/poll_model.php CHANGED
@@ -1,108 +1,111 @@
1
  <?php
2
 
3
- Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
 
4
 
5
  protected $type = 'poll';
6
 
7
- function __construct( $id = 0, $is_view_results = 'no', $question_sort = "poll_order", $question_sort_rule = "ASC", $answer_sort = "question_order", $answer_sort_rule = "ASC" ) {
 
8
 
9
- parent::__construct( $id, $is_view_results, $question_sort, $question_sort_rule, $answer_sort, $answer_sort_rule );
10
 
11
  }
12
 
13
- public static function return_template_preview_html( $template_id = '', $loc = 1 ) {
 
14
 
15
- if( '' == $template_id ) {
16
  return "";
17
- }
18
- else {
19
- $uID = uniqid( 't' );
20
- $poll =new YOP_POLL_Poll_Model();
21
- $template_details = self::get_poll_template_from_database( intval( $template_id ) );
22
- $template = $template_details['before_vote_template'];
23
- $template = stripslashes_deep( $template );
24
 
25
- $template = str_ireplace( '%POLL-NAME%', "Poll Name", $template );
26
- $template = str_ireplace( '%POLL-VOTE-BUTTON%', '<button class="yop_poll_vote_button" onclick="return false;">Vote</button>', $template );
27
 
28
- $question = new YOP_POLL_Question_Model();
29
 
30
- $question->question = "Poll Question";
31
  $question->allow_multiple_answers = "no";
32
- $question->allow_other_answers = "no";
33
 
34
- for( $i = 0; $i < 5; $i ++ ) {
35
- $a = new YOP_POLL_Answer_Model();
36
- $j = $i + 1;
37
- $a->ID = $i + 1;
38
  $a->answer = "Answer {$j}";
39
 
40
- $question->addAnswer( $a );
41
- unset( $a );
42
  }
43
- $poll->questions=$question;
44
- $t = $template;
45
  $pattern = '\[(\[?)(QUESTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
46
- preg_match( "/$pattern/s", $t, $m );
47
  $m = $m[5];
48
 
49
- $m = str_ireplace( "%POLL-QUESTION%", $question->question, $m );
50
 
51
  $pattern = '/\[(\[?)(ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/';
52
- preg_match( $pattern, $m, $m1 );
53
  $m1 = $m1[5];
54
 
55
  $ts = "";
56
 
57
  /** Start Answer Description replace */
58
  $pattern = '\[(\[?)(ANSWER_DESCRIPTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
59
- $m1 = preg_replace( "/$pattern/s", "", $m1 );
60
  /** End Answer Description replace */
61
 
62
  /** Start Answer Result replace */
63
  $pattern = '\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
64
- $m1 = preg_replace( "/$pattern/s", "", $m1 );
65
  /** End Answer Result replace */
66
 
67
- foreach( $question->answers as $answer ) {
68
- $temps = str_ireplace( '%POLL-ANSWER-CHECK-INPUT%', '<input type="radio" value="' . $answer->ID . '" name="yop_poll_answer-' . $uID . '" id="yop-poll-answer-' . $uID . '-' . $answer->ID . '" />', $m1 );
69
- $temps = str_ireplace( '%POLL-ANSWER-LABEL%', '<label>' . $answer->answer . '</label>', $temps );
70
  $ts .= $temps;
71
  }
72
 
73
  $pattern = '/\[(\[?)(ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/';
74
- $m = preg_replace( $pattern, $ts, $m );
75
 
76
- $pattern = '\[(\[?)(QUESTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
77
- $template = preg_replace( "/$pattern/s", $m, $template );
78
 
79
- $pattern = array(
80
  '/\[(\[?)(OTHER_ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/',
81
  '/\[(\[?)(CUSTOM_FIELD_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/',
82
  '/\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/',
83
  '/\[(\[?)(CAPTCHA_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/'
84
  );
85
- $template = preg_replace( $pattern, "", $template );
86
- $template = preg_replace( '/\[\/?QUESTION_CONTAINER\]/', "", $template );
87
- $template = str_ireplace( "%POLL-ID%", "preview-" . $uID, $template );
88
- $template = self::strip_all_tags( $template );
89
-
90
- $t = '<style type="text/css">' . $poll->return_poll_css( $template_details['css'], array(
91
- "location" => 'page',
92
- 'preview' => true,
93
  'template_id' => $uID,
94
- 'loc' => $loc
95
- ) ) . '</style>';
96
  $t .= '<div id="yop-poll-container-preview-' . $uID . '" class="yop-poll-container" style="position: relative; z-index: 1;">';
97
  $t .= '' . $template . '</div>';
98
 
99
- $qID = uniqid( 'q' );
100
- $t = str_ireplace( "%QUESTION-ID%", $qID, $t );
101
  return $t;
102
  }
103
  }
104
 
105
- private static function strip_all_tags( $template ) {
 
106
 
107
  $tags = array(
108
  '%CAPTCHA-PLAY%',
@@ -148,31 +151,31 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
148
  '%SHARE-BUTTON%'
149
  );
150
 
151
- foreach( $tags as $tag ) {
152
- $template = str_ireplace( $tag, '', $template );
153
  }
154
  return $template;
155
  }
156
 
157
  public function return_poll_css(
158
  $css = "", $attr = array(
159
- 'location' => 'page',
160
- 'preview' => false,
161
  'template_id' => '',
162
- 'loc' => 1
163
  )
164
- ) {
165
- $preview = isset( $attr['preview'] ) ? $attr['preview'] : false;
166
- $location = isset( $attr['location'] ) ? $attr['location'] : 'page';
167
- if( $preview ) {
 
168
  $template = $css;
169
- $template.="li.yop-poll-li-answer-%POLL-ID% {width:100%}";
170
- $template.="div.yop-poll-answers-%POLL-ID% ul{width:100%}";
171
- $template = str_ireplace( "%POLL-ID%", 'preview-' . $attr['template_id'] . '', $template );
172
- $template = str_ireplace( "%POLL-WIDTH%", '200px', $template );
173
- return stripslashes( $template );
174
- }
175
- else {
176
  $unique_id = $this->ID . $this->unique_id;
177
 
178
  /*if ( !$poll_id ){
@@ -192,175 +195,175 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
192
  $template_details = self::get_poll_template_from_database( $template_id );
193
  $template = $template_details['css'];*/
194
 
195
- $template = str_ireplace( '%POLL-ID%', $unique_id, $css );
196
- if( 'widget' == $location ) {
197
- $template = str_ireplace( '%POLL-WIDTH%', $this->widget_template_width, $template );
 
 
198
  }
199
- else {
200
- $template = str_ireplace( '%POLL-WIDTH%', $this->template_width, $template );
201
- }
202
- return stripslashes( $template );
203
  }
204
  }
205
 
206
- private static function count_other_answers( $question ) {
207
- $n = count( $question->answers );
 
208
  $nr = 0;
209
- for( $i = 0; $i < $n; $i ++ ) {
210
- if( $question->answers[$i]->type == "other" ) {
211
- $nr ++;
212
  }
213
  }
214
  return $nr;
215
  }
216
 
217
- public function return_poll_js( $attr = array( 'location' => 'page' ) ) {
218
- $poll_id = $this->ID;
219
- $location = isset( $attr['location'] ) ? $attr['location'] : 'page';
 
220
  $unique_id = $this->unique_id;
221
 
222
- if( ! $poll_id ) {
223
  return '';
224
  }
225
 
226
- if( 'widget' == $location ) {
227
  $template_id = $this->widget_template;
228
- }
229
- else {
230
  $template_id = $this->template;
231
  }
232
 
233
- if( '' == $template_id ) {
234
  //get default template
235
  $template_details = self::get_poll_template_from_database();
236
- }
237
- else {
238
- $template_details = self::get_poll_template_from_database( $template_id );
239
  }
240
 
241
  $tabulate = array();
242
 
243
- foreach( $this->questions as $question ) {
244
  $answers_tabulated_cols = 1; //vertical display
245
  $results_tabulated_cols = 1;
246
 
247
- $include_others = false;
248
- $display_answers = array( 'text', 'image', 'video' );
249
 
250
- if( isset( $question->allow_other_answers ) && 'yes' == $question->allow_other_answers ) {
251
 
252
- if( isset( $question->display_other_answers_values ) && 'yes' == $question->display_other_answers_values ) {
253
- $include_others = true;
254
- $display_answers = array( 'text', 'image', 'video', 'other' );
255
  }
256
  }
257
 
258
 
259
- if( 'orizontal' == $question->display_answers ) {
260
- $ans_no = $question->countanswers( $display_answers, $include_others );
261
- if( $ans_no > 0 ) {
262
  $answers_tabulated_cols = $ans_no;
263
  }
264
- if( isset( $question->allow_other_answers ) && 'yes' == $question->allow_other_answers ) {
265
- $answers_tabulated_cols ++;
266
  }
267
- }
268
- else
269
- if( 'tabulated' == $question->display_answers ) {
270
  $answers_tabulated_cols = $question->display_answers_tabulated_cols;
271
  //yop_poll_dump($answers_tabulated_cols);
272
 
273
  }
274
 
275
- if( 'orizontal' == $question->display_results ) {
276
- $ans_no = $question->countanswers( $display_answers, $include_others );
277
- if( $ans_no > 0 ) {
278
  $results_tabulated_cols = $ans_no;
279
  }
280
- }
281
- else if( 'tabulated' == $question->display_results ) {
282
  $results_tabulated_cols = $question->display_results_tabulated_cols;
283
  }
284
 
285
- array_push($tabulate, array( $answers_tabulated_cols, $results_tabulated_cols,$ans_per_question,$question->ID) );
286
  }
287
 
288
  $template = $template_details['js'];
289
- if( 'vertical' == $question->display_answers ) {
290
- $template.="jQuery(document).ready(function(){ jQuery('.yop-poll-li-answer-%POLL-ID%').css('float','none');});" ;
291
 
292
  }
293
- $template = str_ireplace( '%POLL-ID%', $poll_id . $unique_id, $template );
294
- $template = str_ireplace( '%ANSWERS-TABULATED-COLS%', json_encode( $tabulate ), $template );
295
- $template = str_ireplace( '%POLL-WIDTH%',str_replace( "px","",$this->template_width), $template );
296
- $template = str_ireplace( '%RESULTS-TABULATED-COLS%', json_encode( $tabulate ), $template );
297
- return stripslashes( $template );
298
  }
299
 
300
- public function question_replace_callback( $m ) {
301
- $is_voted = $this->is_voted();
 
302
  $return_string = "";
303
- $that=$this;
304
- foreach( $this->questions as $question ) {
305
 
306
  $qunique_id = $question->ID;
307
- $temp = str_ireplace( '%QUESTION-ID%', $qunique_id, $m[5] );
308
- $temp = str_ireplace( '%POLL-QUESTION%', $question->question, $temp );
309
 
310
- $temp = str_ireplace('class = '.'"'. 'yop-poll-li-answer-' . $this->ID . $this->unique_id ,'class='.'"'. 'yop-poll-li-answer-' . $this->ID . $this->unique_id . ' yop-poll-li-answer-' . $this->ID . $this->unique_id."-".$question->ID, $temp);
311
 
312
- if( ! $is_voted ) {
313
  /** Start Anwer replace */
314
- if( $this->count_answers( $question ) > 0 ) {
315
  $pattern = '\[(\[?)(ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
316
- $temp = preg_replace_callback( "/$pattern/s", function ( $m ) use ($that, $question ) {
317
- return $that->answer_replace_callback( $m[5], $question );
318
- }, $temp );
319
  }
320
  /** End Anwer replace */
321
 
322
  /** Start Other Answer replace */
323
  $pattern = '\[(\[?)(OTHER_ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
324
- $temp = str_ireplace('class = '.'"'. 'yop-poll-li-answer-' . $this->ID . $this->unique_id ,'class='.'"'. 'yop-poll-li-answer-' . $this->ID . $this->unique_id . ' yop-poll-li-answer-' . $this->ID . $this->unique_id."-".$question->ID, $temp);
325
 
326
- $temp = preg_replace_callback( "/$pattern/s", function ( $m ) use ( $that, $question ) {
327
- return $that->other_answer_replace_callback( $m[5], $question );
328
- }, $temp );
329
  /** End Other Answer replace */
330
 
331
  /** Start Custom Fields replace*/
332
  $pattern = '\[(\[?)(CUSTOM_FIELD_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
333
- $temp = preg_replace_callback( "/$pattern/s", function ( $m ) use ( $that ,$question ) {
334
- return $that->custom_field_replace_callback( $m[5], $question );
335
- }, $temp );
336
  /** End Custom Fields replace*/
337
  }
338
  $pattern = '\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
339
- $temp = preg_replace_callback( "/$pattern/s", function ( $m ) use ( $that, $question ) {
340
- return $that->answer_result_replace_callback( $m[5], $question );
341
- }, $temp );
342
 
343
  $return_string .= $temp;
344
  }
345
  return $return_string;
346
  }
347
 
348
- private static function count_answers( $question ) {
349
- $n = count( $question->answers );
 
350
  $nr = 0;
351
- for( $i = 0; $i < $n; $i ++ ) {
352
- if( in_array( $question->answers[$i]->type, array( 'text' ) ) ) {
353
- $nr ++;
354
  }
355
  }
356
  return $nr;
357
  }
358
 
359
- public function answer_replace_callback( $m, $question ) {
 
360
  $unique_id = $this->unique_id;
361
 
362
  $multiple_answers = false;
363
- if( $question->allow_multiple_answers == 'yes' ) {
364
  $multiple_answers = true;
365
  }
366
 
@@ -368,77 +371,77 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
368
 
369
  /** Get question total votes( default + other ) */
370
 
 
 
371
  /**Is allowed to display other answers?*/
372
  $display_other_answers = false;
373
 
374
- if( isset( $question->allow_other_answers ) && 'yes' == $question->allow_other_answers ) {
375
- if( isset( $question->display_other_answers_values ) && 'yes' == $question->display_other_answers_values ) {
376
  $display_other_answers = true;
377
  }
378
  }
379
 
380
  $percentages_decimals = 0;
381
- if( isset( $this->percentages_decimals ) ) {
382
  $percentages_decimals = $this->percentages_decimals;
383
  }
384
 
385
- $id = $this->ID;
386
 
387
  $view_results = $this->is_view_poll_results();
388
- //yop_poll_dump($view_results);
389
- $that=$this;
390
- foreach( $question->answers as $answer ) {
391
  /**Check if is allowed to display current answers*/
392
- if( ( $answer->type == "other" ) && ! $display_other_answers ) {
393
  continue;
394
  }
395
- if($view_results){
396
- if( $answer->votes > 0 ) {
397
- $percentages = floatval( $answer->votes * 100 / $total_votes );
398
- }
399
- else {
400
- $percentages = 0;
401
- }
402
- }
403
- if( function_exists( 'icl_translate' ) ) {
404
- $answer->answer = icl_translate( 'yop_poll', $answer->ID . '_answer', $answer->answer );
405
- }
406
- if( $multiple_answers ) {
407
- if( isset( $answer->is_default_answer ) && $answer->is_default_answer == "yes" ) {
408
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-CHECK-INPUT%', '<input type="checkbox" checked="checked" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . '][]" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m );
409
- }
410
- else {
411
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-CHECK-INPUT%', '<input type="checkbox" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . '][]" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m );
412
  }
413
  }
414
- else {
415
- if( isset( $answer->is_default_answer ) && $answer->is_default_answer == "yes" ) {
416
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-CHECK-INPUT%', '<input type="radio" checked="checked" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . ']" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m );
 
 
 
 
 
417
  }
418
- else {
419
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-CHECK-INPUT%', '<input type="radio" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . ']" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m );
 
 
 
420
  }
421
  }
422
 
423
  /** Start Answer Description replace */
424
- $pattern = '\[(\[?)(ANSWER_DESCRIPTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
425
- $temp_answer_model = preg_replace_callback( "/$pattern/s", function ( $m ) use ( $that,$answer, $id, $unique_id ) {
426
- return $that->answer_description_replace_callback( $m[5], $answer, $id, $unique_id );
427
- }, $temp_answer_model );
428
  /** End Answer Description replace */
429
- if($view_results){
430
- /** Start Answer Result replace */
431
- $pattern = '\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
432
- $temp_answer_model = preg_replace_callback( "/$pattern/s", function ( $m ) use ( $that,$answer, $view_results, $id, $unique_id, $percentages, $percentages_decimals ) {
433
- return $that->answer_result_bar_callback( $m[5], $answer, $view_results, $id, $unique_id, $percentages, $percentages_decimals );
434
- }, $temp_answer_model );
435
- /** End Answer Result replace */
436
  }
437
- if( $answer->type == "text" ) {
438
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-LABEL%', '<label for="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '">' . yop_poll_kses( stripslashes( $answer->answer ) ) . '</label>', $temp_answer_model );
439
  }
440
- if( $answer->type == "other" ) {
441
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-LABEL%', '<label style=" cursor: pointer;" for="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '">' . yop_poll_kses( stripslashes( $answer->answer ) ) . '</label>', $temp_answer_model );
442
  }
443
 
444
  $model .= $temp_answer_model;
@@ -447,47 +450,52 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
447
  return $model;
448
  }
449
 
450
- private static function get_question_votes( $question ) {
 
451
  $total_votes = 0;
452
- foreach( $question->answers as $answer ) {
453
- $total_votes += intval( $answer->votes );
454
  }
455
  return $total_votes;
456
  }
457
 
458
- private function is_view_poll_results() {
 
459
  $is_voted = $this->is_voted();
460
- if( ( ( in_array( 'before', $this->view_results ) ) || ( in_array( 'after', $this->view_results ) && $is_voted ) || ( in_array( 'custom-date', $this->view_results ) && self::get_mysql_curent_date() >= convert_date( $this->view_results_start_date, 'Y-m-d H:i:s',1) ) || ( in_array( 'after-poll-end-date', $this->view_results ) && self::get_mysql_curent_date() >= convert_date( $this->poll_end_date, 'Y-m-d H:i:s' ) ) ) && ! in_array( 'never', $this->view_results ) && ( ( in_array( 'guest', $this->view_results_permissions ) && ! is_user_logged_in() ) || ( in_array( 'registered', $this->view_results_permissions ) && is_user_logged_in() ) )
461
  ) {
462
  return true;
463
  }
464
  return false;
465
  }
466
- public function answer_description_replace_callback( $m, $answer, $id, $unique_id ) {
467
- if( "" == $answer->description ) {
 
 
468
  return "";
469
  }
470
- return str_ireplace( "%ANSWER-DESCRIPTION%", '<label for="yop-poll-answer-' . $id . $unique_id . '-' . $answer->ID . '">' . yop_poll_kses( stripslashes( $answer->description ) ) . '</label>', $m );
471
  }
472
 
473
- public function answer_result_bar_callback( $m, $answer, $view_results, $id, $unique_id, $percentages, $percentages_decimals ) {
474
- if( $view_results ) {
475
- $tmp = str_ireplace( '%POLL-ANSWER-RESULT-BAR%', self::display_poll_result_bar( $answer->ID, $percentages, $this->options, $id . $unique_id ), $m );
476
- $tmp = str_ireplace( '%POLL-ANSWER-RESULT-VOTES%', self::display_poll_result_votes( $answer->votes, $this->options ), $tmp );
477
- $tmp = str_ireplace( '- ( )', self::display_poll_result_votes( $answer->votes, $this->options ), $tmp );
478
- $tmp = str_ireplace( '%POLL-ANSWER-RESULT-PERCENTAGES%', self::display_poll_result_percentages( round( $percentages, $percentages_decimals ), $this->options ), $tmp );
 
479
  return $tmp;
480
- }
481
- else {
482
  return "";
483
  }
484
  }
485
 
486
- private static function display_poll_result_bar( $answer_id = 0, $procent = 0, $options = array(), $unique_id = '' ) {
 
487
  $result_bar = ' <div class="yop-poll-results-bar-' . $unique_id . '" ';
488
  $result_bar .= ' ';
489
  $result_bar .= '><div>';
490
- if( floatval( $procent ) > 0 ) {
491
 
492
  $result_bar .= '<div style="' . 'width:' . $procent . '%; ';
493
  $result_bar .= 'height:' . $options['bar_height'] . 'px; ' . 'background-color:#' . $options['bar_background'] . '; ' . 'border-style:' . $options['bar_border_style'] . '; ' . 'border-width:' . $options['bar_border_width'] . 'px; ' . 'border-color:#' . $options['bar_border_color'] . '; ';
@@ -497,93 +505,91 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
497
  return $result_bar;
498
  }
499
 
500
- private static function display_poll_result_votes( $votes = 0, $options = array() ) {
 
501
 
502
- if( 'votes-number' == $options['view_results_type'] || 'votes-number-and-percentages' == $options['view_results_type'] ) {
503
- if( '1' == $votes ) {
504
- $options = get_option('yop_poll_options' );
505
  return $votes . ' ' . $options['singular_answer_result_votes_number_label'];
506
- }
507
- else {
508
- $options = get_option('yop_poll_options' );
509
  return $votes . ' ' . $options['plural_answer_result_votes_number_label'];
510
  }
511
  }
512
  }
513
 
514
- private static function display_poll_result_percentages( $votes, $options = array() ) {
515
- if( 'percentages' == $options['view_results_type'] || 'votes-number-and-percentages' == $options['view_results_type'] ) {
 
516
  return $votes . '%';
517
- }
518
- else {
519
  return '';
520
  }
521
  }
522
 
523
- public function other_answer_replace_callback( $m, $question ) {
 
524
  $unique_id = $this->unique_id;
525
 
526
  $multiple_answers = false;
527
- if( $question->allow_multiple_answers == 'yes' ) {
528
  $multiple_answers = true;
529
  }
530
 
531
  $model = "";
532
 
533
- $allow_other_answers = false;
534
  $display_other_answers = false;
535
- if( isset( $question->allow_other_answers ) && $question->allow_other_answers == 'yes' ) {
536
  $allow_other_answers = true;
537
- if( isset( $question->add_other_answers_to_default_answers ) && ( 'yes' == $question->add_other_answers_to_default_answers ) ) {
538
  $display_other_answers = true;
539
  }
540
  }
541
 
542
- if( $allow_other_answers ) {
543
  /**Display other answer input */
544
- if( function_exists( 'icl_translate' ) ) {
545
- $other_answer_label = icl_translate( 'yop_poll', $this->ID . '_other_answer_label', yop_poll_kses( $question->other_answers_label ) );
546
- }
547
- else {
548
- $other_answer_label = yop_poll_kses( $question->other_answers_label );
549
  }
550
 
551
- if( $multiple_answers ) {
552
- $temp_answer_model = str_ireplace( '%POLL-OTHER-ANSWER-CHECK-INPUT%', '<input type="checkbox" value="other" name="yop_poll_answer[' . $question->ID . '][]" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other" />', $m );
553
- }
554
- else {
555
- $temp_answer_model = str_ireplace( '%POLL-OTHER-ANSWER-CHECK-INPUT%', '<input type="radio" value="other" name="yop_poll_answer[' . $question->ID . ']" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other" />', $m );
556
  }
557
- $temp_answer_model = str_ireplace( '%POLL-OTHER-ANSWER-LABEL%', '<label for="yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other">' . $other_answer_label . '</label>', $temp_answer_model );
558
- $temp_answer_model = str_ireplace( '%POLL-OTHER-ANSWER-TEXT-INPUT%', '<label style="width:100%;"><input onclick="document.getElementById(\'yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other' . '\').checked=true;" type="text" value="" name="yop_poll_other_answer[' . $question->ID . ']" id="yop-poll-other-answer-' . $this->ID . $unique_id . '-other" /></label>', $temp_answer_model );
559
 
560
- if( $this->is_view_poll_results() ) {
561
  /**Display only if other answers were not displayed */
562
- if( ! $display_other_answers ) {
563
  /** Count question total votes( default + other ) */
564
- $total_votes = $this->get_question_votes( $question );
565
 
566
  /** Count other answers votes*/
567
- $other_votes = $this->get_question_other_votes( $question );
568
 
569
 
570
  $percentages_decimals = 0;
571
- if( isset( $this->percentages_decimals ) ) {
572
  $percentages_decimals = $this->percentages_decimals;
573
  }
574
 
575
- if( $other_votes > 0 ) {
576
- $percentages = floatval( $other_votes * 100 / $total_votes );
577
- }
578
- else {
579
  $percentages = 0;
580
  }
581
- if( $this->is_view_poll_results() ) {
582
- $temp_answer_model = str_ireplace( '%POLL-OTHER-ANSWER-RESULT-BAR%', self::display_poll_result_bar( 'other', $percentages, $this->options, $this->ID . $unique_id ), $temp_answer_model );
583
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-RESULT-VOTES%', self::display_poll_result_votes( $other_votes, $this->options ), $temp_answer_model );
584
- $temp_answer_model = str_ireplace( '- ( )', self::display_poll_result_votes( $other_votes, $this->options ), $temp_answer_model );
585
 
586
- $temp_answer_model = str_ireplace( '%POLL-ANSWER-RESULT-PERCENTAGES%', self::display_poll_result_percentages( round( $percentages, $percentages_decimals ), $this->options ), $temp_answer_model );
587
  }
588
  }
589
  }
@@ -592,29 +598,31 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
592
  return $model;
593
  }
594
 
595
- private static function get_question_other_votes( $question ) {
 
596
  $total_votes = 0;
597
- foreach( $question->answers as $answer ) {
598
- if( $answer->type == 'other' ) {
599
- $total_votes += intval( $answer->votes );
600
  }
601
  }
602
  return $total_votes;
603
  }
604
 
605
- public function custom_field_replace_callback( $m, $question ) {
 
606
  $unique_id = $this->unique_id;
607
- $is_voted = $this->is_voted();
608
- $model = "";
609
- if( ! $is_voted ) {
610
- if( count( $question->custom_fields ) > 0 ) {
611
- foreach( $question->custom_fields as $custom_field ) {
612
- if( function_exists( 'icl_translate' ) ) {
613
- $custom_field['custom_field'] = icl_translate( 'yop_poll', $custom_field->ID . '_custom_field', $custom_field->custom_field );
614
  }
615
- $temp_string = str_ireplace( '%POLL-CUSTOM-FIELD-LABEL%', '<label for="yop-poll-customfield-' . $this->ID . $unique_id . '-' . $custom_field->ID . '">' . yop_poll_kses( $custom_field->custom_field ) . '</label>', $m );
616
 
617
- $temp_string = str_ireplace( '%POLL-CUSTOM-FIELD-TEXT-INPUT%', '<input type="text" value="" name="yop_poll_customfield[' . $question->ID . '][' . $custom_field->ID . ']" id="yop-poll-customfield-' . $this->ID . $unique_id .'-'.$custom_field->ID.'" class='.'"yop-poll-customfield-' . $this->ID . $unique_id .'"/>', $temp_string );
618
  $model .= $temp_string;
619
  }
620
  }
@@ -622,99 +630,94 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
622
  return $model;
623
  }
624
 
625
- public function answer_result_replace_callback( $m, $question ) {
626
- $unique_id = $this->unique_id;
 
627
  $return_string = '';
628
- $is_voted = $this->is_voted();
629
- $id = $this->ID;
630
 
631
- if( $this->is_view_poll_results() ) {
632
  $display_other_answers = false;
633
- if( 'yes' == $question->allow_other_answers ) {
634
- if( 'yes' == $question->display_other_answers_values ) {
635
  $display_other_answers = true;
636
  }
637
  }
638
 
639
  $percentages_decimals = 0;
640
- if( isset( $this->percentages_decimals ) ) {
641
  $percentages_decimals = $this->percentages_decimals;
642
  }
643
 
644
- if( isset( $this->sorting_results ) ) {
645
- if( 'as_defined' == $this->sorting_results ) {
646
- $question->sortAnswers( 'question_order', 'asc' );
647
- }
648
- elseif( 'database' == $this->sorting_results ) {
649
  $order_dir = 'asc';
650
- if( isset( $this->sorting_results_direction ) ) {
651
- $order_dir = ( 'asc' == $this->sorting_results_direction ) ? 'asc' : 'desc';
652
  }
653
- $question->sortAnswers( 'ID', $order_dir );
654
- }
655
- elseif( 'alphabetical' == $this->sorting_results ) {
656
  $order_dir = 'asc';
657
- if( isset( $this->sorting_results_direction ) ) {
658
- $order_dir = ( 'asc' == $this->sorting_results_direction ) ? 'asc' : 'desc';
659
  }
660
- $question->sortAnswers( 'alphabetical', $order_dir );
661
- }
662
- elseif( 'votes' == $this->sorting_results ) {
663
  $order_dir = 'asc';
664
- if( isset( $this->sorting_results_direction ) ) {
665
- $order_dir = ( 'asc' == $this->sorting_results_direction ) ? 'asc' : 'desc';
666
  }
667
- $question->sortAnswers( 'votes', $order_dir );
668
- }
669
- else {
670
  $order_dir = 'asc';
671
- if( isset( $this->sorting_results_direction ) ) {
672
- $order_dir = ( 'asc' == $this->sorting_results_direction ) ? 'asc' : 'desc';
673
  }
674
- $question->sortAnswers( 'question_order', $order_dir );
675
  }
676
- }
677
- else {
678
  $order_dir = 'asc';
679
- if( isset( $this->sorting_results_direction ) ) {
680
- $order_dir = ( 'asc' == $this->sorting_results_direction ) ? 'asc' : 'desc';
681
  }
682
- $question->sortAnswers( 'question_order', $order_dir );
683
  }
684
 
685
 
686
- $total_votes = $this->get_question_votes( $question );
687
 
688
- foreach( $question->answers as $ans ) {
689
- if( ( $ans->type == "other" ) && ! $display_other_answers ) {
690
  continue;
691
  }
692
- if( $ans->votes > 0 ) {
693
- $percentages = floatval( $ans->votes * 100 / $total_votes );
694
- }
695
- else {
696
  $percentages = 0;
697
  }
698
 
699
- if( function_exists( 'icl_translate' ) ) {
700
- $ans->answer = icl_translate( 'yop_poll', $ans->ID . '_answer', $ans->answer );
701
  }
702
 
703
  /** Start Answer Description replace */
704
  $pattern = '\[(\[?)(ANSWER_DESCRIPTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
705
- $temp_string = preg_replace( "/$pattern/s", "", $m );
706
  /** End Answer Description replace */
707
  $ans->type = "text";
708
- if( $ans->type == "text" ) {
709
- $temp_string = str_ireplace( '%POLL-ANSWER-LABEL%', '<span>' . yop_poll_kses( stripslashes( $ans->answer ) ) . '</span>', $temp_string );
710
  }
711
- $temp_string = str_ireplace('class = '.'"'. 'yop-poll-li-result-' . $this->ID . $this->unique_id ,'class='.'"'. 'yop-poll-li-result-' . $this->ID . $this->unique_id . ' yop-poll-li-result-' . $this->ID . $this->unique_id."-".$question->ID, $temp_string);
712
 
713
 
714
- $temp_string = str_ireplace( '%POLL-ANSWER-RESULT-VOTES%', self::display_poll_result_votes( $ans->votes, $this->options ), $temp_string );
715
- $temp_string = str_ireplace( '- ( )', self::display_poll_result_votes( $ans->votes, $this->options ), $temp_string );
716
- $temp_string = str_ireplace( '%POLL-ANSWER-RESULT-PERCENTAGES%', self::display_poll_result_percentages( round( $percentages, $percentages_decimals ), $this->options ), $temp_string );
717
- $temp_string = str_ireplace( '%POLL-ANSWER-RESULT-BAR%', self::display_poll_result_bar( $ans->ID, $percentages, $this->options, $this->ID . $unique_id ), $temp_string );
718
  $return_string .= $temp_string;
719
  }
720
  }
@@ -722,31 +725,32 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
722
  return $return_string;
723
  }
724
 
725
- public function register_vote( $request ) {
 
726
 
727
  global $current_user;
728
- $poll_id = $this->id;
729
- $unique_id = strip_tags(xss_clean($this->unique_id));
730
- $location =strip_tags(xss_clean( $request['location']));
731
- $vote_id = uniqid( 'vote_id_' );
732
- $vote_type = $request['vote_type'];
733
- $SuperCookie =strip_tags(xss_clean( $request['supercookie']));
734
- $tr_id = strip_tags(xss_clean( $request['yop_poll_tr_id']));
735
- $votes = 0;
736
- $user_id = 0;
737
- $user_type = 'default';
738
  $user_details = '';
739
- if( wp_verify_nonce( $request['yop-poll-nonce-' . $poll_id . $unique_id], 'yop_poll-' . $this->ID . $unique_id . '-user-actions' ) ) {
740
- switch( $vote_type ) {
741
  default:
742
  {
743
- $user_id = ( $current_user->ID != null ) ? $current_user->ID : 0;
744
  $user_type = 'default';
745
  break;
746
  }
747
  case 'wordpress':
748
  {
749
- $user_id = $current_user->ID;
750
  $user_type = 'wordpress';
751
  break;
752
  }
@@ -758,488 +762,468 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
758
 
759
  }
760
  $log_to_add = array(
761
- 'poll_id' => $this->ID,
762
- 'vote_id' => $vote_id,
763
- 'ip' => yop_poll_get_ip(),
764
- 'user_id' => $user_id,
765
- 'user_type' => $user_type,
766
- 'user_details' => json_encode( $user_details ),
767
- 'tr_id' => $tr_id,
768
  );
769
- }
770
- else {
771
- $this->error = __yop_poll( 'Bad Request!' );
772
- $log_to_add ['message'] = __yop_poll( 'Bad request' );
773
- insert_log_in_db( $log_to_add );
774
  return false;
775
  }
776
- if( wp_verify_nonce( $request['yop-poll-nonce-' . $this->ID . $unique_id], 'yop_poll-' . $this->ID . $unique_id . '-user-actions' ) ) {
777
 
778
- $tr_id = $request['yop_poll_tr_id'];
779
  $super_perm = true;
780
- if( in_array( "supercookie", $this->blocking_voters ) ) {
781
- $super_perm = $this->is_voted_supercookie( $SuperCookie );
782
  }
783
- if( $super_perm == true ) {
784
 
785
  $current_date = yop_poll_get_mysql_curent_date();
786
- if( $this->is_allowed_to_vote( $vote_type ) ) {
787
- if( $current_date >= convert_date( $this->poll_start_date, 'Y-m-d H:i:s' ) ) {
788
- if( $current_date <= convert_date( $this->poll_end_date, 'Y-m-d H:i:s' ) ) {
789
- if( 'closed' == $this->status ) {
790
- $this->error = __yop_poll( 'This poll is closed!' );
791
- $log_to_add ['message'] = __yop_poll( 'Poll Closed' );
792
- insert_log_in_db( $log_to_add );
793
  return false;
794
- }
795
- else {
796
- if( ! $this->is_voted( $vote_type, $facebook_user_details, $google_user_details, true, $SuperCookie ) ) {
797
- $voter = array();
798
- $voter['poll_id'] = $poll_id;
799
- $voter['user_id'] = $current_user->ID;
800
  $voter['user_type'] = $vote_type;
801
 
802
- if( $this->user_have_votes_to_vote( $voter, $SuperCookie ) ) {
803
- $i = 1;
804
  $cookie = '';
805
- $log = array();
806
- foreach( $this->questions as &$question ) {
807
  $answers = array();
808
- if( isset ( $request['yop_poll_answer'][$question->ID] ) ) {
809
- if( 'yes' == $question->allow_multiple_answers ) {
810
- if( count( $request['yop_poll_answer'][$question->ID] ) <= intval( $question->allow_multiple_answers_number ) ) {
811
- if( count( $request['yop_poll_answer'][$question->ID] ) >= intval( $question->allow_multiple_answers_min_number ) ) {
812
  $answers = array();
813
- foreach( $request['yop_poll_answer'][$question->ID] as $answer ) {
814
- $new_answer = array();
815
  $new_answer['answer_id'] = $answer;
816
- $new_answer['type'] = 'default';
817
- if( 'other' == $answer ) {
818
  $a = new YOP_POLL_Answer_Model();
819
- if( isset( $request['yop_poll_other_answer'][$question->ID] ) && '' != strip_tags( trim( $request['yop_poll_other_answer'][$question->ID] ) ) ) {
820
- $a->type = 'other';
821
- $a->poll_id = $poll_id;
822
- $a->question_id = $question->ID;
823
- $a->answer = strip_tags( trim( $request['yop_poll_other_answer'][$question->ID] ) );
824
- $a->answer_date = current_time( 'mysql' );
825
- $a->answer_modified = current_time( 'mysql' );
826
- $a->status = 'active';
827
- $a->question_order = $question->countanswers() + 1;
828
- $a->answer_author = $current_user->ID;
829
  $a->save();
830
 
831
- if( ! $a->id ) {
832
- $this->error = __yop_poll( 'Other answer for question ' ) . $i . __yop_poll( ' could not be inserted!' );
833
- $log_to_add ['message'] = __yop_poll( 'Other answer for question ' ) . $i . __yop_poll( ' could not be inserted' );
834
- insert_log_in_db( $log_to_add );
835
  return false;
836
  }
837
- }
838
- else {
839
- $this->error = __yop_poll( 'Other answer from question ' ) . $i . __yop_poll( ' is empty' );
840
- $log_to_add ['message'] = __yop_poll( 'Other answer from question ' ) . $i . __yop_poll( ' is empty' );
841
- insert_log_in_db( $log_to_add );
842
  return false;
843
  }
844
- $question->addAnswer( $a );
845
  $new_answer['answer_id'] = $a->id;
846
- $new_answer['type'] = 'other';
847
- unset( $a );
848
  }
849
  $new_answer['poll_id'] = $poll_id;
850
  $new_answer['vote_id'] = $vote_id;
851
- $new_answer['ip'] = yop_poll_get_ip();
852
  $new_answer['user_id'] = $current_user->ID;
853
 
854
  $new_answer['user_type'] = 'default';
855
- if( $vote_type=='anonymous' || $vote_type=='wordpress' ) {
856
  $new_answer['user_type'] = $vote_type;
857
  }
858
 
859
- $new_answer['http_referer'] = $_SERVER['HTTP_REFERER'];
860
- $new_answer['tr_id'] = $tr_id;
861
- $new_answer['host'] = esc_attr( @gethostbyaddr( yop_poll_get_ip() ) );
862
  $new_answer['other_answer_value'] = '';
863
 
864
  $answers[] = $new_answer;
865
  }
866
- }
867
- else {
868
- $this->error = __yop_poll( "Too few answers selected for question " ) . $i . __yop_poll( "! Only more than " ) . $question->allow_multiple_answers_min_number . __yop_poll( " answers allowed!" );
869
- $log_to_add ['message'] = __yop_poll( "Too few answers selected for question ") . $i;
870
- insert_log_in_db( $log_to_add );
871
  return false;
872
  }
873
- }
874
- else {
875
- $this->error = __yop_poll( "Too many answers selected for question " ) . $i . __yop_poll( "! Only " ) . $question->allow_multiple_answers_number . __yop_poll( " answers allowed!" );
876
- $log_to_add ['message'] = __yop_poll( "Too many answers selected for question " ) . $i;
877
- insert_log_in_db( $log_to_add );
878
  return false;
879
  }
880
- }
881
- else {
882
- $new_answer = array();
883
  $new_answer['answer_id'] = $request['yop_poll_answer'][$question->ID];
884
- $new_answer['type'] = 'default';
885
- if( 'other' == $request['yop_poll_answer'][$question->ID] ) {
886
  $a = new YOP_POLL_Answer_Model();
887
- if( isset( $request['yop_poll_other_answer'][$question->ID] ) && '' != strip_tags( trim( $request['yop_poll_other_answer'][$question->ID] ) ) ) {
888
- $a->type = 'other';
889
- $a->poll_id = $poll_id;
890
- $a->question_id = $question->ID;
891
- $a->answer = strip_tags( trim( $request['yop_poll_other_answer'][$question->ID] ) );
892
- $a->answer_date = current_time( 'mysql' );
893
  $a->question_order = $question->countanswers();
894
- $a->answer_author = $current_user->ID;
895
- $a->votes = 0;
896
  $a->save();
897
 
898
- if( ! $a->id ) {
899
- $this->error = __yop_poll( "Other answer for question " ) . $i . __yop_poll( " could not be inserted!" );
900
- $log_to_add ['message'] = __yop_poll( "Other answer for question " ) . $i . __yop_poll( " could not be inserted");
901
- insert_log_in_db( $log_to_add );
902
  return false;
903
  }
904
- }
905
- else {
906
- $this->error = __yop_poll( "Other answer from question " ) . $i . ' ' . __yop_poll( 'is empty' );
907
- $log_to_add ['message'] = __yop_poll( "Other answer from question " ) . $i . ' ' . __yop_poll( 'empty' );
908
- insert_log_in_db( $log_to_add );
909
  return false;
910
  }
911
 
912
- $question->addAnswer( $a );
913
  $new_answer['answer_id'] = $a->id;
914
- $new_answer['type'] = 'other';
915
- unset( $a );
916
  }
917
 
918
  $new_answer['poll_id'] = $poll_id;
919
  $new_answer['vote_id'] = $vote_id;
920
- $new_answer['ip'] = yop_poll_get_ip();
921
  $new_answer['user_id'] = $current_user->ID;
922
 
923
  $new_answer['user_type'] = 'default';
924
 
925
 
926
- $new_answer['http_referer'] = $_SERVER['HTTP_REFERER'];
927
- $new_answer['tr_id'] = $tr_id;
928
- $new_answer['host'] = esc_attr( @gethostbyaddr( yop_poll_get_ip() ) );
929
  $new_answer['other_answer_value'] = '';
930
- $answers[] = $new_answer;
931
  }
932
 
933
- if( count( $answers ) > 0 ) {
934
- $custom_fields = array();
935
  $poll_custom_fields = $question->custom_fields;
936
 
937
- if( count( $poll_custom_fields ) > 0 ) {
938
 
939
- if( isset( $request['yop_poll_customfield'][$question->ID] ) ) {
940
 
941
- foreach( $poll_custom_fields as $custom_field ) {
942
 
943
- if( isset( $request['yop_poll_customfield'][$question->ID][$custom_field->ID] ) ) {
944
 
945
- if( '' == trim( strip_tags( $request['yop_poll_customfield'][$question->ID][$custom_field->ID] ) ) && 'yes' == $custom_field->required ) {
946
- $this->error = __yop_poll( "Custom field " ) . $custom_field->custom_field . __yop_poll( " from question " ) . $i . ' ' . __yop_poll( "is required" ) . "!";
947
- $log_to_add ['message'] = __yop_poll( "Custom field " ) . $custom_field->custom_field . __yop_poll( " from question " ) . $i . ' ' . __yop_poll( "required");
948
- insert_log_in_db( $log_to_add );
949
  return false;
950
- }
951
- else {
952
- if( trim( strip_tags( $request['yop_poll_customfield'][$question->ID][$custom_field->ID] ) ) != '' ) {
953
- $new_custom_field = array();
954
- $new_custom_field['poll_id'] = $poll_id;
955
- $new_custom_field['question_id'] = $question->ID;
956
- $new_custom_field['vote_id'] = $vote_id;
957
  $new_custom_field['custom_field_id'] = $custom_field->ID;
958
- $new_custom_field['user_id'] = $current_user->ID;
959
 
960
  $new_custom_field['user_type'] = 'default';
961
 
962
- if( $vote_type=='wordpress' || $vote_type=='anonymous' ) {
963
  $new_custom_field['user_type'] = $vote_type;
964
  }
965
 
966
- $new_custom_field['custom_field_value'] = strip_tags( trim( $request['yop_poll_customfield'][$question->ID][$custom_field->ID] ) );
967
- $custom_fields[] = $new_custom_field;
968
 
969
  }
970
  }
971
- }
972
- else {
973
- $this->error = __yop_poll( "Custom field " ) . '"' . $custom_field->custom_field . '"' . __yop_poll( " from question " ) . $i . ' ' . __yop_poll( "is missing ") . '!';
974
 
975
- $log_to_add ['message'] = __yop_poll( "Custom field " ) . '"' . $custom_field->custom_field . '"' . __yop_poll( " from question " ) . $i . ' ' . __yop_poll( "missing" );
976
- insert_log_in_db( $log_to_add );
977
  return false;
978
  }
979
  }
980
- }
981
- else {
982
- $this->error = __yop_poll( "Custom fields from question " ) . $i . ' ' . __yop_poll( "are missing" ) . '!';
983
- $log_to_add ['message'] = __yop_poll( "Custom fields from question " ) . $i . ' ' . __yop_poll( "missing" ) . '!';
984
- insert_log_in_db( $log_to_add );
985
  return false;
986
  }
987
  }
988
 
989
- if( 'yes' == $this->use_captcha ) {
990
- require_once( YOP_POLL_INC . '/securimage.php' );
991
- $img = new Yop_Poll_Securimage();
992
  $img->namespace = 'yop_poll_' . $poll_id . $unique_id;
993
- if( $img->check( $_REQUEST['yop_poll_captcha_input'][$poll_id] ) ) {
994
  $mail_notifications_answers[$question->ID] = array();
995
 
996
- $add_to_log = $this->update_votes( $question, $answers, $votes, $mail_notifications_answers[$question->ID], $facebook_user_details['id'], $google_user_details['id'] );
997
 
998
  $log["q-" . $question->ID]['question'] = $question->question;
999
- $log["q-" . $question->ID]['a'] = $add_to_log['a'];
1000
- $log["q-" . $question->ID]['answers'] = $add_to_log['answers'];
1001
 
1002
- $mail_notifications_answers[$question->ID] = trim( $mail_notifications_answers[$question->ID], '<br>' );
1003
 
1004
  $mail_notifications_custom_fields[$question->ID] = '';
1005
- foreach( $custom_fields as $custom_field ) {
1006
 
1007
- if( 'anonymous' == $vote_type ) {
1008
  $custom_field['user_id'] = 0;
1009
  }
1010
  $custom_field['tr_id'] = $tr_id;
1011
- self::insert_vote_custom_field_in_database( $custom_field );
1012
 
1013
- $cf = $question->getCustomFieldById( $custom_field['custom_field_id'] );
1014
 
1015
  $mail_notifications_custom_fields[$question->ID][$cf->custom_field] = $custom_field['custom_field_value'];
1016
  }
1017
 
1018
- if( 'yes' == $this->number_of_votes_per_user ) {
1019
- $this->success = str_replace( '%USER-VOTES-LEFT%', intval( $this->number_of_votes_per_user ) - $this->get_voter_number_of_votes( $voter ), $poll_options['message_after_vote'] );
1020
- }
1021
- else {
1022
- $this->success = str_replace( '%USER-VOTES-LEFT%', '', $this->message_after_vote );
1023
  }
1024
- }
1025
- else {
1026
- $this->error = __yop_poll( "Incorrect security code entered!" );
1027
- $log_to_add ['message'] = __yop_poll( "Incorrect security code entered" );
1028
- insert_log_in_db( $log_to_add );
1029
  return false;
1030
  }
1031
- }
1032
- else {
1033
  $mail_notifications_answers[$question->ID] = array();
1034
 
1035
- $add_to_log = $this->update_votes( $question, $answers, $votes, $mail_notifications_answers[$question->ID], $vote_type, $facebook_user_details['id'], $google_user_details['id'] );
1036
 
1037
  $log["q-" . $question->ID]['question'] = $question->question;
1038
- $log["q-" . $question->ID]['id'] = $question->ID;
1039
- $log["q-" . $question->ID]['a'] = $add_to_log['a'];
1040
- $log["q-" . $question->ID]['answers'] = $add_to_log['answers'];
1041
 
1042
 
1043
  $mail_notifications_custom_fields[$question->ID] = array();
1044
  $add_to_log = array();
1045
- foreach( $custom_fields as $custom_field ) {
1046
 
1047
- if( 'google' == $vote_type ) {
1048
  $custom_field['user_id'] = $google_user_details['id'];
1049
  }
1050
- if( 'anonymous' == $vote_type ) {
1051
  $custom_field['user_id'] = 0;
1052
  }
1053
  $custom_field['tr_id'] = $tr_id;
1054
 
1055
- $cf_id = self::insert_vote_custom_field_in_database( $custom_field );
1056
 
1057
  $add_to_log[] = $cf_id;
1058
 
1059
- $cf = $question->getCustomFieldById( $custom_field['custom_field_id'] );
1060
 
1061
  $mail_notifications_custom_fields[$question->ID][$cf->custom_field] = $custom_field['custom_field_value'];
1062
  }
1063
  $log["q-" . $question->ID]['cf'] = $add_to_log;
1064
 
1065
- if( 'yes' == $this->number_of_votes_per_user ) {
1066
- $this->success = str_replace( '%USER-VOTES-LEFT%', intval( $this->number_of_votes_per_user ) - $this->get_voter_number_of_votes( $voter ), $this->message_after_vote );
1067
- }
1068
- else {
1069
- $this->success = str_replace( '%USER-VOTES-LEFT%', '', $this->message_after_vote );
1070
  }
1071
  }
1072
- }
1073
- else {
1074
- $this->error = __yop_poll( "No vote registered!" );
1075
- $log_to_add ['message'] = __yop_poll( "No vote registered" );
1076
- insert_log_in_db( $log_to_add );
1077
  return false;
1078
  }
1079
- }
1080
- else {
1081
- $this->error = __yop_poll( "No answer selected for question " ) . $i;
1082
- $log_to_add ['message'] = __yop_poll( "No answer selected for question " ) . $i;
1083
- insert_log_in_db( $log_to_add );
1084
  return false;
1085
  }
1086
- $i ++;
1087
  }
1088
- }
1089
- else {
1090
- $this->error = __yop_poll( "You have run out of votes!");
1091
- $log_to_add ['message'] = __yop_poll( "Run out of votes" );
1092
- insert_log_in_db( $log_to_add );
1093
  return false;
1094
  }
1095
- }
1096
- else {
1097
- $this->error = __yop_poll( "You Already voted!" );
1098
- $log_to_add ['message'] = __yop_poll( "Already Voted" );
1099
- insert_log_in_db( $log_to_add );
1100
  return false;
1101
  }
1102
  }
1103
- }
1104
- else {
1105
- $this->error = __yop_poll( "This poll is closed!" );
1106
- $log_to_add ['message'] = __yop_poll( "Poll Closed" );
1107
- insert_log_in_db( $log_to_add );
1108
  return false;
1109
  }
1110
- }
1111
- else {
1112
- $this->error = __yop_poll( "You can vote once the poll starts!" );
1113
- $log_to_add ['message'] = __yop_poll( "Poll not started" );
1114
- insert_log_in_db( $log_to_add );
1115
  return false;
1116
  }
1117
- }
1118
- else {
1119
- $this->error = __yop_poll( "You are not allowed to vote!" );
1120
- $log_to_add ['message'] = __yop_poll( "Not allowed to vote" );
1121
- insert_log_in_db( $log_to_add );
1122
  return false;
1123
  }
1124
- }
1125
- else {
1126
- $this->error = __yop_poll( "You are not allowed to vote!" );
1127
  return false;
1128
  }
1129
 
1130
- }
1131
- else {
1132
- $this->error = __yop_poll( "Bad Request!" );
1133
- $log_to_add ['message'] = __yop_poll( "Bad request" );
1134
- insert_log_in_db( $log_to_add );
1135
  return false;
1136
  }
1137
 
1138
- if( $this->send_email_notifications =="yes") {
1139
- $this->sendMail( $mail_notifications_answers, $mail_notifications_custom_fields, $vote_id );
1140
  }
1141
 
1142
  $this->update_poll_total_votes(1);
1143
 
1144
- $log_to_add ['message'] = __yop_poll( 'Success' );
1145
- $log_to_add ['vote_details'] = json_encode( $log );
1146
 
1147
- insert_log_in_db( $log_to_add );
1148
- $ip_data = @json_decode( file_get_contents( "http://www.geoplugin.net/json.gp?ip=" . $log_to_add['ip'] ) );
1149
  $log_to_add['country'] = $ip_data->geoplugin_countryName;
1150
- insert_result_in_db( $log_to_add );
1151
 
1152
- $this->set_vote_cookie( json_encode( $log ), $vote_type, $facebook_user_details, $google_user_details );
1153
 
1154
  $this->vote = true;
1155
- $this->poll_total_votes+=1;
1156
 
1157
- return do_shortcode( $this->return_poll_html( array( 'tr_id' => $tr_id, 'location' => $location ) ) );
1158
  }
1159
 
1160
- function is_voted_supercookie( $SuperCookie ) {
1161
- $current_time = date( 'Y-m-d H:i:s', strtotime( date( "Y-m-d H:i:s", mktime() ) . " + 365 day" ) );
1162
- $cookie = explode( "=", $SuperCookie );
1163
- $num_votes = explode( ";", $cookie[1] );
1164
- if( $num_votes[0] == 0 ) {
 
1165
  return true;
1166
  }
1167
- $cookie_expire = convert_date( $cookie[2], "Y-m-d H:i:s" );
1168
 
1169
 
1170
- if( isset( $this->blocking_voters_interval_value ) ) {
1171
  $value = $this->blocking_voters_interval_value;
1172
  }
1173
  $unit = 'days';
1174
- if( isset( $this->blocking_voters_interval_unit ) ) {
1175
  $unit = $this->blocking_voters_interval_unit;
1176
  }
1177
 
1178
- switch( $unit ) {
1179
  case 'seconds' :
1180
  $expire_cookie = $value;
1181
  break;
1182
  case 'minutes' :
1183
- $expire_cookie = ( 60 * $value );
1184
  break;
1185
  case 'hours' :
1186
- $expire_cookie = ( 60 * 60 * $value );
1187
  break;
1188
  case 'days' :
1189
- $expire_cookie = ( 60 * 60 * 24 * $value );
1190
  break;
1191
  }
1192
- $timeFirst = strtotime( $current_time );
1193
- $timeSecond = strtotime( $cookie_expire );
1194
  $differenceInSeconds = $timeFirst - $timeSecond;
1195
- if( $differenceInSeconds >= 31556926 ) {
1196
  return true;
1197
  }
1198
- if( $expire_cookie > $differenceInSeconds ) {
1199
  return false;
1200
  }
1201
  return true;
1202
  }
1203
 
1204
- private function update_votes( &$question, $answers, &$votes, &$mail_notification = '', $vote_type, $facebook_user_id, $google_user_id ) {
 
1205
 
1206
- foreach( $answers as $answer ) {
1207
 
1208
- $answer_to_update = & $question->getAnswerById( $answer['answer_id'] );
1209
 
1210
 
1211
- if( 'anonymous' == $vote_type ) {
1212
  $answer['user_id'] = 0;
1213
  }
1214
 
1215
- if( $answer['type'] == 'other' ) {
1216
- if( 'yes' == $question->add_other_answers_to_default_answers ) {
1217
  $answer_to_update->type = 'text';
1218
- $answer['type'] = 'text';
1219
  }
1220
  }
1221
- $votes ++;
1222
 
1223
- $answer_to_update->answer_modified = current_time( 'mysql' );
1224
- $answer_to_update->answer_status = 'active';
1225
- $answer_to_update->votes = intval( $answer_to_update->votes ) + 1;
1226
 
1227
  $answer_to_update->save();
1228
 
1229
- $add_to_log['a'][] = $answer_to_update->ID;
1230
  $add_to_log['answers'][] = $answer_to_update->answer;
1231
- $mail_notification[] = $answer_to_update->answer;
1232
 
1233
- unset( $answer_to_update );
1234
  }
1235
  return $add_to_log;
1236
  }
1237
 
1238
- private static function insert_vote_custom_field_in_database( $custom_field = array() ) {
 
1239
  global $wpdb;
1240
 
1241
- $custom_field['custom_field_value'] = strip_tags( $custom_field['custom_field_value'] );
1242
- $wpdb->query( $wpdb->prepare( "
1243
  INSERT INTO " . $wpdb->yop_poll_votes_custom_fields . "
1244
  SET
1245
  poll_id = %d,
@@ -1251,53 +1235,54 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
1251
  custom_field_value = %s,
1252
  tr_id = %s,
1253
  vote_date = %s
1254
- ", $custom_field['poll_id'], $custom_field['question_id'], $custom_field['vote_id'], $custom_field['custom_field_id'], $custom_field['user_id'], $custom_field['user_type'], $custom_field['custom_field_value'], $custom_field['tr_id'], current_time( 'mysql' ) ) );
1255
  return $wpdb->insert_id;
1256
  }
1257
 
1258
- private function update_poll_total_votes( $votes = 0 ) {
 
1259
  global $wpdb;
1260
- $wpdb->query( $wpdb->prepare( "
1261
  UPDATE {$wpdb->yop_polls}
1262
  SET
1263
  poll_total_votes = poll_total_votes + %d
1264
  WHERE
1265
  ID = %d
1266
- ", $votes, $this->ID ) );
1267
 
1268
  }
1269
 
1270
  public function return_poll_html(
1271
  $attr = array(
1272
- 'tr_id' => '',
1273
  'location' => 'page',
1274
  'load_css' => false,
1275
- 'load_js' => false,
1276
- 'show_results'=>''
1277
  )
1278
- ) {
1279
- $time_format="H:i:s";
1280
- $options = get_option('yop_poll_options' );
1281
- if($options['date_format']=="UE")
1282
- $date_format="d-m-Y"; else{
1283
- $date_format="m-d-Y";
1284
- }
1285
- $date_format=$date_format.' '.$time_format;
1286
- $tr_id = isset( $attr['tr_id'] ) ? $attr['tr_id'] : '';
1287
- $show_results = isset( $attr['show_results'] ) ? $attr['show_results'] : '';
1288
- $location = isset( $attr['location'] ) ? $attr['location'] : 'page';
1289
- $load_css = isset( $attr['load_css'] ) ? $attr['load_css'] : false;
 
1290
  $unique_id = $this->unique_id;
1291
- $poll_id = $this->ID;
1292
- if( ! $poll_id ) {
1293
  return '';
1294
  }
1295
 
1296
  //Get template id based on location(widget/page)
1297
- if( 'widget' == $location ) {
1298
  $template_id = $this->widget_template;
1299
- }
1300
- else {
1301
  $template_id = $this->template;
1302
  }
1303
 
@@ -1305,249 +1290,244 @@ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model {
1305
  /**
1306
  * Init Options
1307
  */
1308
- $general_options = get_option( "yop_poll_options" );
1309
- foreach( $general_options as $key => $value ) {
1310
- if( ! isset( $this->$key ) ) {
1311
  $this->$key = $value;
1312
  }
1313
  }
1314
 
1315
- if( '' == $template_id ) {
1316
  //get default template
1317
  $template_details = self::get_poll_template_from_database();
1318
- }
1319
- else {
1320
- $template_details = self::get_poll_template_from_database( $template_id );
1321
  }
1322
 
1323
  $template_css = $template_details['css'];
1324
- $template_details['before_vote_template']= str_replace('id = "yop-poll-li-answer-%POLL-ID%-%QUESTION-ID%"','', $template_details['before_vote_template']);
1325
- $template_details['before_vote_template']= str_replace('id = "yop-poll-li-custom-%POLL-ID%-%QUESTION-ID%"','', $template_details['before_vote_template']);
1326
- $template_details['before_vote_template']= str_replace('id = "yop-poll-customs-%POLL-ID%-%QUESTION-ID%"','', $template_details['before_vote_template']);
1327
- $template_details['after_end_date_template']= str_replace('id = "pds-feedback-label-%POLL-ID%-%QUESTION-ID%"','', $template_details['after_end_date_template']);
1328
- $template_details['after_vote_template']= str_replace('id = "pds-feedback-label-%POLL-ID%-%QUESTION-ID%"','', $template_details['after_vote_template']);
1329
- $template_details['after_end_date_template']= str_replace('id = "yop-poll-li-result-%POLL-ID%-%QUESTION-ID%"','', $template_details['after_end_date_template']);
1330
- $template_details['after_vote_template']= str_replace('id = "yop-poll-li-result-%POLL-ID%-%QUESTION-ID%"','', $template_details['after_vote_template']);
1331
- $template_details['after_end_date_template']= str_replace('id = "pds-answer-text-%POLL-ID%-%QUESTION-ID%"','', $template_details['after_end_date_template']);
1332
- $template_details['after_vote_template']= str_replace('id = "pds-answer-text-%POLL-ID%-%QUESTION-ID%"','', $template_details['after_vote_template']);
1333
- $template_details['after_end_date_template']= str_replace('id = "pds-feedback-result-%POLL-ID%-%QUESTION-ID%"','', $template_details['after_end_date_template']);
1334
- $template_details['after_vote_template']= str_replace('id = "pds-feedback-result-%POLL-ID%-%QUESTION-ID%"','', $template_details['after_vote_template']);
1335
- $template_details['after_end_date_template']= str_replace('id = "pds-feedback-per-%POLL-ID%-%QUESTION-ID%"','', $template_details['after_end_date_template']);
1336
- $template_details['after_vote_template']= str_replace('id = "pds-feedback-per-%POLL-ID%-%QUESTION-ID%"','', $template_details['after_vote_template']);
1337
  $poll_details = $this;
1338
- $this->vote_button_label = empty($this->vote_button_label )?$general_options['vote_button_label']:$this->vote_button_label;
1339
- $this->vote_permisions_wordpress_label = empty($this->vote_permisions_wordpress_label )?$general_options['vote_permisions_wordpress_label']:$this->vote_permisions_wordpress_label;
1340
- $this->vote_permisions_anonymous_label = empty($this->vote_permisions_anonymous_label )?$general_options['vote_permisions_anonymous_label']:$this->vote_permisions_anonymous_label;
1341
 
1342
  //Translate labels
1343
- if( function_exists( 'icl_translate' ) ) {
1344
  // $poll_details = icl_translate( 'yop_poll', $poll_details->ID . '_poll_title', $poll_details->name );
1345
- $this->singular_answer_result_votes_number_label = icl_translate( 'yop_poll', $poll_details->ID . '_singular_answer_result_votes_number_label', $general_options['singular_answer_result_votes_number_label']);
1346
- $this->plural_answer_result_votes_number_label = icl_translate( 'yop_poll', $poll_details->ID . '_plural_answer_result_votes_number_label', $general_options['plural_answer_result_votes_number_label'] );
1347
- $this->vote_button_label = icl_translate( 'yop_poll', $poll_details->ID . '_vote_button_label', empty($this->vote_button_label )?$general_options['vote_button_label']:$this->vote_button_labels );
1348
- $this->view_results_link_label = icl_translate( 'yop_poll', $poll_details->ID . '_view_results_link_label', $this->view_results_link_label );
1349
- $this->view_back_to_vote_link_label = icl_translate( 'yop_poll', $poll_details->ID . '_view_back_to_vote_link_label', $this->view_back_to_vote_link_label );
1350
- $this->view_total_votes_label = icl_translate( 'yop_poll', $poll_details->ID . '_view_total_votes_label', $this->view_total_votes_label );
1351
- $this->view_total_answers_label = icl_translate( 'yop_poll', $poll_details->ID . '_view_total_answers_label', $this->view_total_answers_label );
1352
- $this->view_total_voters_label = icl_translate( 'yop_poll', $poll_details->ID . '_view_total_voters_label', $this->view_total_voters_label );
1353
- $this->archive_link_label = icl_translate( 'yop_poll', $poll_details->ID . '_archive_link_label', $this->archive_link_label );
1354
- $this->answer_result_label = icl_translate( 'yop_poll', $poll_details->ID . '_answer_result_label', $this->answer_result_label );
1355
- $this->vote_permisions_wordpress_label = icl_translate( 'yop_poll', $poll_details->ID . '_vote_permisions_wordpress_label', $this->vote_permisions_wordpress_label );
1356
- $this->vote_share_google_label = icl_translate( 'yop_poll', $poll_details->ID . '_vote_share_google_label', $this->vote_share_google_label );
1357
- $this->vote_permisions_anonymous_label = icl_translate( 'yop_poll', $poll_details->ID . '_vote_permisions_anonymous_label', $this->vote_permisions_anonymous_label );
1358
  }
1359
 
1360
- $is_voted = $this->is_voted();
1361
  $current_date = self::get_mysql_curent_date();
1362
- if( $current_date >= convert_date( $this->poll_start_date, 'Y-m-d H:i:s',1 ) ) {
1363
 
1364
- if( $current_date <= convert_date( $this->poll_end_date, 'Y-m-d H:i:s',1 ) ) {
1365
  //poll is active
1366
- if( ! $is_voted ) {
1367
  //user hasn't voted yet
1368
  $template = $template_details['before_vote_template'];
1369
- if(isset($show_results)&&$show_results==1){
1370
 
1371
  $template = $template_details['after_vote_template'];
1372
- $this->view_results=array('before');
1373
  }
1374
- if( in_array( 'before', $this->view_results ) ) {
1375
- if( $this->is_view_poll_results() ) {
1376
- $template = str_ireplace( '%POLL-ANSWER-RESULT-LABEL%', $this->answer_result_label, $template );
1377
  }
1378
  }
1379
- $template = str_ireplace( '%POLL-VOTE-BUTTON%', '<button class="yop_poll_vote_button" id="yop_poll_vote-button-' . $this->ID . $unique_id . '" onclick="yop_poll_register_vote(\'' . $this->ID . '\', \'' . $location . '\', \'' . $unique_id . '\'); return false;">' . $this->vote_button_label . '</button>', $template );
1380
- }
1381
- else {
1382
  //user has voted
1383
 
1384
- if(
1385
- in_array( 'after', $this->view_results ) ||
1386
- in_array( 'before', $this->view_results ) ||
1387
- ( in_array( 'custom-date', $this->view_results ) && self::get_mysql_curent_date() >= convert_date( $this->view_results_start_date, 'Y-m-d H:i:s' ) )
1388
  ) {
1389
 
1390
  $template = $template_details['after_vote_template'];
1391
 
1392
- if( $this->is_view_poll_results() ) {
1393
- $template = str_ireplace( '%POLL-ANSWER-RESULT-LABEL%', $this->answer_result_label, $template );
1394
  }
1395
  }
1396
 
1397
- if( 'yes' == $this->view_back_to_vote_link ) {
1398
- $vote = $this->vote;
1399
  $this->vote = false;
1400
- if( ! $this->is_voted() ) {
1401
- $template = str_ireplace( '%POLL-BACK-TO-VOTE-LINK%', '<a href="javascript:void(0)" class="yop_poll_back_to_vote_link" id="yop_poll_back_to_vote_link' . $this->ID . $unique_id . '" onClick="yop_poll_back_to_vote(\'' . $this->ID . '\', \'' . $location . '\', \'' . $unique_id . '\')">' . $this->view_back_to_vote_link_label . '</a>', $template );
1402
  }
1403
  $this->vote = $vote;
1404
  }
1405
 
1406
  }
1407
- }
1408
- else {
1409
  //poll has ended
1410
  $template = $template_details['after_end_date_template'];
1411
- if( in_array( 'after-poll-end-date', $this->view_results ) || in_array( 'before', $this->view_results ) || in_array( 'after', $this->view_results ) ) {
1412
- if( $this->is_view_poll_results() ) {
1413
- $template = str_ireplace( '%POLL-ANSWER-RESULT-LABEL%', $this->answer_result_label, $template );
1414
- $template = str_ireplace( '%POLL-END-DATE%', $this->poll_end_date, $template );
1415
- $template = str_ireplace( '%POLL-START-DATE%', $this->poll_start_date, $template );
1416
  }
1417
  }
1418
 
1419
  }
1420
- }
1421
- else {
1422
  //poll hasn't started
1423
  $template = $template_details['before_start_date_template'];
1424
- $template = str_ireplace( '%POLL-END-DATE%', $this->poll_end_date, $template );
1425
- $template = str_ireplace( '%POLL-START-DATE%', $this->poll_start_date, $template );
1426
- if( in_array( 'before', $this->view_results ) ) {
1427
- if( $this->is_view_poll_results() ) {
1428
- $template = str_ireplace( '%POLL-ANSWER-RESULT-LABEL%', $this->answer_result_label, $template );
1429
 
1430
  }
1431
 
1432
  }
1433
  }
1434
 
1435
- if( in_array( 'custom-date', $this->view_results ) ) {
1436
- $template = str_ireplace( '%POLL-END-DATE%', $this->poll_end_date, $template );
1437
- $template = str_ireplace( '%POLL-START-DATE%', $this->poll_start_date, $template );
1438
- if( self::get_mysql_curent_date() >= convert_date( $this->view_results_start_date, 'Y-m-d H:i:s',1 ) ) {
1439
 
1440
- if( $this->is_view_poll_results() ) {
1441
- $template = str_ireplace( '%POLL-ANSWER-RESULT-LABEL%', $this->answer_result_label, $template );
1442
  }
1443
  }
1444
  }
1445
- $template = str_ireplace( '%POLL-END-DATE%', $this->poll_end_date, $template );
1446
- $template = str_ireplace( '%POLL-START-DATE%', $this->poll_start_date, $template );
1447
- $template = stripslashes_deep( $template );
1448
 
1449
- $template = str_ireplace( '%POLL-ID%', $this->ID . $unique_id, $template );
1450
- $template = str_ireplace( "%POLL-NAME%", yop_poll_kses( stripslashes( $this->poll_title ) ), $template );
1451
- $template = str_ireplace( '%POLL-START-DATE%', esc_html( stripslashes( convert_date( $this->start_date,$date_format ) ) ), $template );
1452
- $template = str_ireplace( '%POLL-PAGE-URL%', esc_html( yop_poll_kses( stripslashes( $this->poll_page_url ) ) ), $template );
1453
 
1454
- if( '01-01-2038 23:59:59' == convert_date( $this->poll_end_date, 'Y-m-d H:i:s' ) ) {
1455
- $template = str_ireplace( '%POLL-END-DATE%', __yop_poll( 'Never Expire' ), $template );
1456
- }
1457
- else {
1458
- $template = str_ireplace( '%POLL-END-DATE%', esc_html( stripslashes( convert_date( $this->end_date,$date_format ) ) ), $template );
1459
  }
1460
 
1461
- if( 'yes' == $this->view_results_link ) {
1462
- $template = str_ireplace( '%POLL-VIEW-RESULT-LINK%', '<a href="javascript:void(0)" class="yop_poll_result_link" id="yop_poll_result_link' . $this->ID . $unique_id . '" onClick="yop_poll_view_results(\'' . $this->ID . '\', \'' . $location . '\', \'' . $unique_id . '\')">' . $this->view_results_link_label . '</a>', $template );
1463
  }
1464
- if( 'yes' == $this->view_poll_archive_link ) {
1465
- $template = str_ireplace( '%POLL-VIEW-ARCHIVE-LINK%', '<a href="' . get_permalink( $this->yop_poll_archive_page_id ) . '" class="yop_poll_archive_link" id="yop_poll_archive_link_' . $this->ID . $unique_id . '" >' . $this->archive_link_label . '</a>', $template );
1466
  }
1467
  $poll_total_answers = 0;
1468
- foreach( $this->questions as $q ) {
1469
- foreach($q->answers as $a )
1470
- $poll_total_answers+=$a->votes ;
1471
  }
1472
 
1473
 
1474
- if( 'yes' == $this->view_total_answers ) {
1475
- $template = str_ireplace( '%POLL-TOTAL-ANSWERS-LABEL%', $this->view_total_answers_label, $template );
1476
- $template = str_ireplace( '%POLL-TOTAL-ANSWERS%', $poll_total_answers, $template );
1477
  }
1478
- if( 'yes' == $this->view_total_votes ) {
1479
- $template = str_ireplace( '%POLL-TOTAL-VOTES-LABEL%', $this->view_total_votes_label, $template );
1480
- $template = str_ireplace( '%POLL-TOTAL-VOTES%', $this->poll_total_votes, $template );
1481
  }
1482
 
1483
  $msgDivS = false;
1484
  $msgDivE = false;
1485
 
1486
- if( strpos( $template, "%POLL-SUCCESS-MSG%" ) != false ) {
1487
- $msgDivS = true;
1488
- $template = str_ireplace( '%POLL-SUCCESS-MSG%', '<div id="yop-poll-container-success-' . $this->ID . $unique_id . '" class="yop-poll-container-success"></div>', $template );
1489
  }
1490
- if( strpos( $template, "%POLL-ERROR-MSG%" ) != false ) {
1491
- $msgDivE = true;
1492
- $template = str_ireplace( '%POLL-ERROR-MSG%', '<div id="yop-poll-container-error-' . $this->ID . $unique_id . '" class="yop-poll-container-error"></div>', $template );
1493
  }
1494
 
1495
- $that=$this;
1496
 
1497
  /** Start Question replace*/
1498
- $pattern = '\[(\[?)(QUESTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
1499
- $template = preg_replace_callback( "/$pattern/s", function($m) use ($that){
1500
  return $that->question_replace_callback($m);
1501
- }, $template );
1502
  /** End Question replace*/
1503
 
1504
 
1505
  /** Start CAPTCHA replace*/
1506
- $pattern = '\[(\[?)(CAPTCHA_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
1507
- $template = preg_replace_callback( "/$pattern/s",function ($m) use ($that){
1508
  return $that->captcha_replace_callback($m);
1509
- }, $template );
1510
  /** End CAPTCHA replace*/
1511
 
1512
 
1513
- $temp = self::strip_all_tags( $template );
1514
 
1515
  $template = "";
1516
- if( $load_css ) {
1517
- $template .= '<style scoped>' . self::return_poll_css( $template_css, array( "location" => $location ) ) .' .yop-poll-forms-display{} ' . '</style>';
1518
 
1519
  }
1520
 
1521
 
1522
  $template .= '<div id="yop-poll-container-' . $this->ID . $unique_id . '" class="yop-poll-container">';
1523
- if( ! $msgDivS ) {
1524
  $template .= '<div id="yop-poll-container-success-' . $this->ID . $unique_id . '" class="yop-poll-container-success"></div>';
1525
  }
1526
- if( ! $msgDivE ) {
1527
  $template .= '<div id="yop-poll-container-error-' . $this->ID . $unique_id . '" class="yop-poll-container-error"></div>';
1528
  }
1529
 
1530
- $template .= '<form id="yop-poll-form-' . $this->ID . $unique_id . '" class="yop-poll-forms yop-poll-forms-display">' . $temp . '<input type="hidden" id="yop-poll-tr-id-' . $this->ID . $unique_id . '" name="yop_poll_tr_id" value="' . $tr_id . '"/>' . wp_nonce_field( 'yop_poll-' . $this->ID . $unique_id . '-user-actions', 'yop-poll-nonce-' . $this->ID . $unique_id, false, false ) . '</form></div>';
1531
-
1532
 
1533
 
1534
  return $template;
1535
  }
1536
 
1537
- public function captcha_replace_callback( $m ) {
1538
- $unique_id = $this->unique_id;
 
1539
  $return_string = '';
1540
- $temp_string = '';
1541
-
1542
- if( 'yes' == $this->use_captcha ) {
1543
- $sid = md5( uniqid() );
1544
- $temp_string = str_ireplace( '%CAPTCHA-IMAGE%', '<img class="yop_poll_captcha_image" id="yop_poll_captcha_image_' . $this->ID . $unique_id . '" src="' . admin_url( 'admin-ajax.php', ( is_ssl() ? 'https' : 'http' ) ) . '?action=yop_poll_show_captcha&poll_id=' . $this->ID . '&sid=' . $sid . '&unique_id=' . $this->unique_id . '" />', $m[5] );
1545
- $temp_string = str_ireplace( '%CAPTCHA-INPUT%', '<input type="text" value="" name="yop_poll_captcha_input[' . $this->ID . ']" id="yop-poll-captcha-input-' . $this->ID . $unique_id . '" />', $temp_string );
1546
- $temp_string = str_ireplace( '%RELOAD-CAPTCHA-IMAGE%', '<a href="javascript:void(0)"><img src="' . YOP_POLL_URL . 'images/captcha_reload.png' . '" alt="' . __( 'Reload', 'yop_poll' ) . '" onClick="yop_poll_reloadCaptcha(' . "'" . $this->ID . "', '" . $this->unique_id . "'" . ')" /></a>', $temp_string );
1547
- $temp_string = str_ireplace( '%CAPTCHA-LABEL%', "<br>" . __yop_poll( 'Enter the code' ), $temp_string );
1548
- $temp_string = str_ireplace( '%CAPTCHA-PLAY%', '<object type="application/x-shockwave-flash" data="' . YOP_POLL_URL . 'captcha/securimage_play.swf?bgcol=#ffffff&amp;icon_file=' . YOP_POLL_URL . 'images/captcha-audio.gif&amp;audio_file=' . urlencode( admin_url( 'admin-ajax.php', ( is_ssl() ? 'https' : 'http' ) ) . '?action=yop_poll_play_captcha&poll_id=' . $this->ID . '&unique_id=' . $this->unique_id ) . '" height="30" width="30">
1549
- <param name="movie" value="' . YOP_POLL_URL . 'captcha/securimage_play.swf?bgcol=#ffffff&amp;icon_file=' . YOP_POLL_URL . 'images/captcha-audio.gif&amp;audio_file=' . urlencode( admin_url( 'admin-ajax.php', ( is_ssl() ? 'https' : 'http' ) ) . '?action=yop_poll_play_captcha&poll_id=' . $this->ID . '&unique_id=' . $this->unique_id ) . '" />
1550
- </object>', $temp_string );
1551
  }
1552
  $return_string .= $temp_string;
1553
 
1
  <?php
2
 
3
+ Class YOP_POLL_Poll_Model extends YOP_POLL_Abstract_Model
4
+ {
5
 
6
  protected $type = 'poll';
7
 
8
+ function __construct($id = 0, $is_view_results = 'no', $question_sort = "poll_order", $question_sort_rule = "ASC", $answer_sort = "question_order", $answer_sort_rule = "ASC")
9
+ {
10
 
11
+ parent::__construct($id, $is_view_results, $question_sort, $question_sort_rule, $answer_sort, $answer_sort_rule);
12
 
13
  }
14
 
15
+ public static function return_template_preview_html($template_id = '', $loc = 1)
16
+ {
17
 
18
+ if ('' == $template_id) {
19
  return "";
20
+ } else {
21
+ $uID = uniqid('t');
22
+ $poll = new YOP_POLL_Poll_Model();
23
+ $template_details = self::get_poll_template_from_database(intval($template_id));
24
+ $template = $template_details['before_vote_template'];
25
+ $template = stripslashes_deep($template);
 
26
 
27
+ $template = str_ireplace('%POLL-NAME%', "Poll Name", $template);
28
+ $template = str_ireplace('%POLL-VOTE-BUTTON%', '<button class="yop_poll_vote_button" onclick="return false;">Vote</button>', $template);
29
 
30
+ $question = new YOP_POLL_Question_Model();
31
 
32
+ $question->question = "Poll Question";
33
  $question->allow_multiple_answers = "no";
34
+ $question->allow_other_answers = "no";
35
 
36
+ for ($i = 0; $i < 5; $i++) {
37
+ $a = new YOP_POLL_Answer_Model();
38
+ $j = $i + 1;
39
+ $a->ID = $i + 1;
40
  $a->answer = "Answer {$j}";
41
 
42
+ $question->addAnswer($a);
43
+ unset($a);
44
  }
45
+ $poll->questions = $question;
46
+ $t = $template;
47
  $pattern = '\[(\[?)(QUESTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
48
+ preg_match("/$pattern/s", $t, $m);
49
  $m = $m[5];
50
 
51
+ $m = str_ireplace("%POLL-QUESTION%", $question->question, $m);
52
 
53
  $pattern = '/\[(\[?)(ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/';
54
+ preg_match($pattern, $m, $m1);
55
  $m1 = $m1[5];
56
 
57
  $ts = "";
58
 
59
  /** Start Answer Description replace */
60
  $pattern = '\[(\[?)(ANSWER_DESCRIPTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
61
+ $m1 = preg_replace("/$pattern/s", "", $m1);
62
  /** End Answer Description replace */
63
 
64
  /** Start Answer Result replace */
65
  $pattern = '\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
66
+ $m1 = preg_replace("/$pattern/s", "", $m1);
67
  /** End Answer Result replace */
68
 
69
+ foreach ($question->answers as $answer) {
70
+ $temps = str_ireplace('%POLL-ANSWER-CHECK-INPUT%', '<input type="radio" value="' . $answer->ID . '" name="yop_poll_answer-' . $uID . '" id="yop-poll-answer-' . $uID . '-' . $answer->ID . '" />', $m1);
71
+ $temps = str_ireplace('%POLL-ANSWER-LABEL%', '<label>' . $answer->answer . '</label>', $temps);
72
  $ts .= $temps;
73
  }
74
 
75
  $pattern = '/\[(\[?)(ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/';
76
+ $m = preg_replace($pattern, $ts, $m);
77
 
78
+ $pattern = '\[(\[?)(QUESTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
79
+ $template = preg_replace("/$pattern/s", $m, $template);
80
 
81
+ $pattern = array(
82
  '/\[(\[?)(OTHER_ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/',
83
  '/\[(\[?)(CUSTOM_FIELD_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/',
84
  '/\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/',
85
  '/\[(\[?)(CAPTCHA_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/'
86
  );
87
+ $template = preg_replace($pattern, "", $template);
88
+ $template = preg_replace('/\[\/?QUESTION_CONTAINER\]/', "", $template);
89
+ $template = str_ireplace("%POLL-ID%", "preview-" . $uID, $template);
90
+ $template = self::strip_all_tags($template);
91
+
92
+ $t = '<style type="text/css">' . $poll->return_poll_css($template_details['css'], array(
93
+ "location" => 'page',
94
+ 'preview' => true,
95
  'template_id' => $uID,
96
+ 'loc' => $loc
97
+ )) . '</style>';
98
  $t .= '<div id="yop-poll-container-preview-' . $uID . '" class="yop-poll-container" style="position: relative; z-index: 1;">';
99
  $t .= '' . $template . '</div>';
100
 
101
+ $qID = uniqid('q');
102
+ $t = str_ireplace("%QUESTION-ID%", $qID, $t);
103
  return $t;
104
  }
105
  }
106
 
107
+ private static function strip_all_tags($template)
108
+ {
109
 
110
  $tags = array(
111
  '%CAPTCHA-PLAY%',
151
  '%SHARE-BUTTON%'
152
  );
153
 
154
+ foreach ($tags as $tag) {
155
+ $template = str_ireplace($tag, '', $template);
156
  }
157
  return $template;
158
  }
159
 
160
  public function return_poll_css(
161
  $css = "", $attr = array(
162
+ 'location' => 'page',
163
+ 'preview' => false,
164
  'template_id' => '',
165
+ 'loc' => 1
166
  )
167
+ )
168
+ {
169
+ $preview = isset($attr['preview']) ? $attr['preview'] : false;
170
+ $location = isset($attr['location']) ? $attr['location'] : 'page';
171
+ if ($preview) {
172
  $template = $css;
173
+ $template .= "li.yop-poll-li-answer-%POLL-ID% {width:100%}";
174
+ $template .= "div.yop-poll-answers-%POLL-ID% ul{width:100%}";
175
+ $template = str_ireplace("%POLL-ID%", 'preview-' . $attr['template_id'] . '', $template);
176
+ $template = str_ireplace("%POLL-WIDTH%", '200px', $template);
177
+ return stripslashes($template);
178
+ } else {
 
179
  $unique_id = $this->ID . $this->unique_id;
180
 
181
  /*if ( !$poll_id ){
195
  $template_details = self::get_poll_template_from_database( $template_id );
196
  $template = $template_details['css'];*/
197
 
198
+ $template = str_ireplace('%POLL-ID%', $unique_id, $css);
199
+ if ('widget' == $location) {
200
+ $template = str_ireplace('%POLL-WIDTH%', $this->widget_template_width, $template);
201
+ } else {
202
+ $template = str_ireplace('%POLL-WIDTH%', $this->template_width, $template);
203
  }
204
+ return stripslashes($template);
 
 
 
205
  }
206
  }
207
 
208
+ private static function count_other_answers($question)
209
+ {
210
+ $n = count($question->answers);
211
  $nr = 0;
212
+ for ($i = 0; $i < $n; $i++) {
213
+ if ($question->answers[$i]->type == "other") {
214
+ $nr++;
215
  }
216
  }
217
  return $nr;
218
  }
219
 
220
+ public function return_poll_js($attr = array('location' => 'page'))
221
+ {
222
+ $poll_id = $this->ID;
223
+ $location = isset($attr['location']) ? $attr['location'] : 'page';
224
  $unique_id = $this->unique_id;
225
 
226
+ if (!$poll_id) {
227
  return '';
228
  }
229
 
230
+ if ('widget' == $location) {
231
  $template_id = $this->widget_template;
232
+ } else {
 
233
  $template_id = $this->template;
234
  }
235
 
236
+ if ('' == $template_id) {
237
  //get default template
238
  $template_details = self::get_poll_template_from_database();
239
+ } else {
240
+ $template_details = self::get_poll_template_from_database($template_id);
 
241
  }
242
 
243
  $tabulate = array();
244
 
245
+ foreach ($this->questions as $question) {
246
  $answers_tabulated_cols = 1; //vertical display
247
  $results_tabulated_cols = 1;
248
 
249
+ $include_others = false;
250
+ $display_answers = array('text', 'image', 'video');
251
 
252
+ if (isset($question->allow_other_answers) && 'yes' == $question->allow_other_answers) {
253
 
254
+ if (isset($question->display_other_answers_values) && 'yes' == $question->display_other_answers_values) {
255
+ $include_others = true;
256
+ $display_answers = array('text', 'image', 'video', 'other');
257
  }
258
  }
259
 
260
 
261
+ if ('orizontal' == $question->display_answers) {
262
+ $ans_no = $question->countanswers($display_answers, $include_others);
263
+ if ($ans_no > 0) {
264
  $answers_tabulated_cols = $ans_no;
265
  }
266
+ if (isset($question->allow_other_answers) && 'yes' == $question->allow_other_answers) {
267
+ $answers_tabulated_cols++;
268
  }
269
+ } else
270
+ if ('tabulated' == $question->display_answers) {
 
271
  $answers_tabulated_cols = $question->display_answers_tabulated_cols;
272
  //yop_poll_dump($answers_tabulated_cols);
273
 
274
  }
275
 
276
+ if ('orizontal' == $question->display_results) {
277
+ $ans_no = $question->countanswers($display_answers, $include_others);
278
+ if ($ans_no > 0) {
279
  $results_tabulated_cols = $ans_no;
280
  }
281
+ } else if ('tabulated' == $question->display_results) {
 
282
  $results_tabulated_cols = $question->display_results_tabulated_cols;
283
  }
284
 
285
+ array_push($tabulate, array($answers_tabulated_cols, $results_tabulated_cols, $ans_per_question, $question->ID));
286
  }
287
 
288
  $template = $template_details['js'];
289
+ if ('vertical' == $question->display_answers) {
290
+ $template .= "jQuery(document).ready(function(){ jQuery('.yop-poll-li-answer-%POLL-ID%').css('float','none');});";
291
 
292
  }
293
+ $template = str_ireplace('%POLL-ID%', $poll_id . $unique_id, $template);
294
+ $template = str_ireplace('%ANSWERS-TABULATED-COLS%', json_encode($tabulate), $template);
295
+ $template = str_ireplace('%POLL-WIDTH%', str_replace("px", "", $this->template_width), $template);
296
+ $template = str_ireplace('%RESULTS-TABULATED-COLS%', json_encode($tabulate), $template);
297
+ return stripslashes($template);
298
  }
299
 
300
+ public function question_replace_callback($m)
301
+ {
302
+ $is_voted = $this->is_voted();
303
  $return_string = "";
304
+ $that = $this;
305
+ foreach ($this->questions as $question) {
306
 
307
  $qunique_id = $question->ID;
308
+ $temp = str_ireplace('%QUESTION-ID%', $qunique_id, $m[5]);
309
+ $temp = str_ireplace('%POLL-QUESTION%', $question->question, $temp);
310
 
311
+ $temp = str_ireplace('class = ' . '"' . 'yop-poll-li-answer-' . $this->ID . $this->unique_id, 'class=' . '"' . 'yop-poll-li-answer-' . $this->ID . $this->unique_id . ' yop-poll-li-answer-' . $this->ID . $this->unique_id . "-" . $question->ID, $temp);
312
 
313
+ if (!$is_voted) {
314
  /** Start Anwer replace */
315
+ if ($this->count_answers($question) > 0) {
316
  $pattern = '\[(\[?)(ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
317
+ $temp = preg_replace_callback("/$pattern/s", function ($m) use ($that, $question) {
318
+ return $that->answer_replace_callback($m[5], $question);
319
+ }, $temp);
320
  }
321
  /** End Anwer replace */
322
 
323
  /** Start Other Answer replace */
324
  $pattern = '\[(\[?)(OTHER_ANSWER_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
325
+ $temp = str_ireplace('class = ' . '"' . 'yop-poll-li-answer-' . $this->ID . $this->unique_id, 'class=' . '"' . 'yop-poll-li-answer-' . $this->ID . $this->unique_id . ' yop-poll-li-answer-' . $this->ID . $this->unique_id . "-" . $question->ID, $temp);
326
 
327
+ $temp = preg_replace_callback("/$pattern/s", function ($m) use ($that, $question) {
328
+ return $that->other_answer_replace_callback($m[5], $question);
329
+ }, $temp);
330
  /** End Other Answer replace */
331
 
332
  /** Start Custom Fields replace*/
333
  $pattern = '\[(\[?)(CUSTOM_FIELD_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
334
+ $temp = preg_replace_callback("/$pattern/s", function ($m) use ($that, $question) {
335
+ return $that->custom_field_replace_callback($m[5], $question);
336
+ }, $temp);
337
  /** End Custom Fields replace*/
338
  }
339
  $pattern = '\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
340
+ $temp = preg_replace_callback("/$pattern/s", function ($m) use ($that, $question) {
341
+ return $that->answer_result_replace_callback($m[5], $question);
342
+ }, $temp);
343
 
344
  $return_string .= $temp;
345
  }
346
  return $return_string;
347
  }
348
 
349
+ private static function count_answers($question)
350
+ {
351
+ $n = count($question->answers);
352
  $nr = 0;
353
+ for ($i = 0; $i < $n; $i++) {
354
+ if (in_array($question->answers[$i]->type, array('text'))) {
355
+ $nr++;
356
  }
357
  }
358
  return $nr;
359
  }
360
 
361
+ public function answer_replace_callback($m, $question)
362
+ {
363
  $unique_id = $this->unique_id;
364
 
365
  $multiple_answers = false;
366
+ if ($question->allow_multiple_answers == 'yes') {
367
  $multiple_answers = true;
368
  }
369
 
371
 
372
  /** Get question total votes( default + other ) */
373
 
374
+ $total_votes = $this->get_question_votes($question);
375
+
376
  /**Is allowed to display other answers?*/
377
  $display_other_answers = false;
378
 
379
+ if (isset($question->allow_other_answers) && 'yes' == $question->allow_other_answers) {
380
+ if (isset($question->display_other_answers_values) && 'yes' == $question->display_other_answers_values) {
381
  $display_other_answers = true;
382
  }
383
  }
384
 
385
  $percentages_decimals = 0;
386
+ if (isset($this->percentages_decimals)) {
387
  $percentages_decimals = $this->percentages_decimals;
388
  }
389
 
390
+ $id = $this->ID;
391
 
392
  $view_results = $this->is_view_poll_results();
393
+
394
+ $that = $this;
395
+ foreach ($question->answers as $answer) {
396
  /**Check if is allowed to display current answers*/
397
+ if (($answer->type == "other") && !$display_other_answers) {
398
  continue;
399
  }
400
+ if ($view_results) {
401
+ if ($answer->votes > 0) {
402
+ if (isset($total_votes) && $total_votes > 0) {
403
+ $percentages = floatval($answer->votes * 100 / $total_votes);
404
+ }
405
+ } else {
406
+ $percentages = 0;
 
 
 
 
 
 
 
 
 
 
407
  }
408
  }
409
+ if (function_exists('icl_translate')) {
410
+ $answer->answer = icl_translate('yop_poll', $answer->ID . '_answer', $answer->answer);
411
+ }
412
+ if ($multiple_answers) {
413
+ if (isset($answer->is_default_answer) && $answer->is_default_answer == "yes") {
414
+ $temp_answer_model = str_ireplace('%POLL-ANSWER-CHECK-INPUT%', '<input type="checkbox" checked="checked" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . '][]" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m);
415
+ } else {
416
+ $temp_answer_model = str_ireplace('%POLL-ANSWER-CHECK-INPUT%', '<input type="checkbox" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . '][]" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m);
417
  }
418
+ } else {
419
+ if (isset($answer->is_default_answer) && $answer->is_default_answer == "yes") {
420
+ $temp_answer_model = str_ireplace('%POLL-ANSWER-CHECK-INPUT%', '<input type="radio" checked="checked" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . ']" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m);
421
+ } else {
422
+ $temp_answer_model = str_ireplace('%POLL-ANSWER-CHECK-INPUT%', '<input type="radio" value="' . $answer->ID . '" name="yop_poll_answer[' . $question->ID . ']" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '" />', $m);
423
  }
424
  }
425
 
426
  /** Start Answer Description replace */
427
+ $pattern = '\[(\[?)(ANSWER_DESCRIPTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
428
+ $temp_answer_model = preg_replace_callback("/$pattern/s", function ($m) use ($that, $answer, $id, $unique_id) {
429
+ return $that->answer_description_replace_callback($m[5], $answer, $id, $unique_id);
430
+ }, $temp_answer_model);
431
  /** End Answer Description replace */
432
+ if ($view_results) {
433
+ /** Start Answer Result replace */
434
+ $pattern = '\[(\[?)(ANSWER_RESULT_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
435
+ $temp_answer_model = preg_replace_callback("/$pattern/s", function ($m) use ($that, $answer, $view_results, $id, $unique_id, $percentages, $percentages_decimals) {
436
+ return $that->answer_result_bar_callback($m[5], $answer, $view_results, $id, $unique_id, $percentages, $percentages_decimals);
437
+ }, $temp_answer_model);
438
+ /** End Answer Result replace */
439
  }
440
+ if ($answer->type == "text") {
441
+ $temp_answer_model = str_ireplace('%POLL-ANSWER-LABEL%', '<label for="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '">' . yop_poll_kses(stripslashes($answer->answer)) . '</label>', $temp_answer_model);
442
  }
443
+ if ($answer->type == "other") {
444
+ $temp_answer_model = str_ireplace('%POLL-ANSWER-LABEL%', '<label style=" cursor: pointer;" for="yop-poll-answer-' . $this->ID . $unique_id . '-' . $answer->ID . '">' . yop_poll_kses(stripslashes($answer->answer)) . '</label>', $temp_answer_model);
445
  }
446
 
447
  $model .= $temp_answer_model;
450
  return $model;
451
  }
452
 
453
+ private static function get_question_votes($question)
454
+ {
455
  $total_votes = 0;
456
+ foreach ($question->answers as $answer) {
457
+ $total_votes += intval($answer->votes);
458
  }
459
  return $total_votes;
460
  }
461
 
462
+ private function is_view_poll_results()
463
+ {
464
  $is_voted = $this->is_voted();
465
+ if (((in_array('before', $this->view_results)) || (in_array('after', $this->view_results) && $is_voted) || (in_array('custom-date', $this->view_results) && self::get_mysql_curent_date() >= convert_date($this->view_results_start_date, 'Y-m-d H:i:s', 1)) || (in_array('after-poll-end-date', $this->view_results) && self::get_mysql_curent_date() >= convert_date($this->poll_end_date, 'Y-m-d H:i:s'))) && !in_array('never', $this->view_results) && ((in_array('guest', $this->view_results_permissions) && !is_user_logged_in()) || (in_array('registered', $this->view_results_permissions) && is_user_logged_in()))
466
  ) {
467
  return true;
468
  }
469
  return false;
470
  }
471
+
472
+ public function answer_description_replace_callback($m, $answer, $id, $unique_id)
473
+ {
474
+ if ("" == $answer->description) {
475
  return "";
476
  }
477
+ return str_ireplace("%ANSWER-DESCRIPTION%", '<label for="yop-poll-answer-' . $id . $unique_id . '-' . $answer->ID . '">' . yop_poll_kses(stripslashes($answer->description)) . '</label>', $m);
478
  }
479
 
480
+ public function answer_result_bar_callback($m, $answer, $view_results, $id, $unique_id, $percentages, $percentages_decimals)
481
+ {
482
+ if ($view_results) {
483
+ $tmp = str_ireplace('%POLL-ANSWER-RESULT-BAR%', self::display_poll_result_bar($answer->ID, $percentages, $this->options, $id . $unique_id), $m);
484
+ $tmp = str_ireplace('%POLL-ANSWER-RESULT-VOTES%', self::display_poll_result_votes($answer->votes, $this->options), $tmp);
485
+ $tmp = str_ireplace('- ( )', self::display_poll_result_votes($answer->votes, $this->options), $tmp);
486
+ $tmp = str_ireplace('%POLL-ANSWER-RESULT-PERCENTAGES%', self::display_poll_result_percentages(round($percentages, $percentages_decimals), $this->options), $tmp);
487
  return $tmp;
488
+ } else {
 
489
  return "";
490
  }
491
  }
492
 
493
+ private static function display_poll_result_bar($answer_id = 0, $procent = 0, $options = array(), $unique_id = '')
494
+ {
495
  $result_bar = ' <div class="yop-poll-results-bar-' . $unique_id . '" ';
496
  $result_bar .= ' ';
497
  $result_bar .= '><div>';
498
+ if (floatval($procent) > 0) {
499
 
500
  $result_bar .= '<div style="' . 'width:' . $procent . '%; ';
501
  $result_bar .= 'height:' . $options['bar_height'] . 'px; ' . 'background-color:#' . $options['bar_background'] . '; ' . 'border-style:' . $options['bar_border_style'] . '; ' . 'border-width:' . $options['bar_border_width'] . 'px; ' . 'border-color:#' . $options['bar_border_color'] . '; ';
505
  return $result_bar;
506
  }
507
 
508
+ private static function display_poll_result_votes($votes = 0, $options = array())
509
+ {
510
 
511
+ if ('votes-number' == $options['view_results_type'] || 'votes-number-and-percentages' == $options['view_results_type']) {
512
+ if ('1' == $votes) {
513
+ $options = get_option('yop_poll_options');
514
  return $votes . ' ' . $options['singular_answer_result_votes_number_label'];
515
+ } else {
516
+ $options = get_option('yop_poll_options');
 
517
  return $votes . ' ' . $options['plural_answer_result_votes_number_label'];
518
  }
519
  }
520
  }
521
 
522
+ private static function display_poll_result_percentages($votes, $options = array())
523
+ {
524
+ if ('percentages' == $options['view_results_type'] || 'votes-number-and-percentages' == $options['view_results_type']) {
525
  return $votes . '%';
526
+ } else {
 
527
  return '';
528
  }
529
  }
530
 
531
+ public function other_answer_replace_callback($m, $question)
532
+ {
533
  $unique_id = $this->unique_id;
534
 
535
  $multiple_answers = false;
536
+ if ($question->allow_multiple_answers == 'yes') {
537
  $multiple_answers = true;
538
  }
539
 
540
  $model = "";
541
 
542
+ $allow_other_answers = false;
543
  $display_other_answers = false;
544
+ if (isset($question->allow_other_answers) && $question->allow_other_answers == 'yes') {
545
  $allow_other_answers = true;
546
+ if (isset($question->add_other_answers_to_default_answers) && ('yes' == $question->add_other_answers_to_default_answers)) {
547
  $display_other_answers = true;
548
  }
549
  }
550
 
551
+ if ($allow_other_answers) {
552
  /**Display other answer input */
553
+ if (function_exists('icl_translate')) {
554
+ $other_answer_label = icl_translate('yop_poll', $this->ID . '_other_answer_label', yop_poll_kses($question->other_answers_label));
555
+ } else {
556
+ $other_answer_label = yop_poll_kses($question->other_answers_label);
 
557
  }
558
 
559
+ if ($multiple_answers) {
560
+ $temp_answer_model = str_ireplace('%POLL-OTHER-ANSWER-CHECK-INPUT%', '<input type="checkbox" value="other" name="yop_poll_answer[' . $question->ID . '][]" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other" />', $m);
561
+ } else {
562
+ $temp_answer_model = str_ireplace('%POLL-OTHER-ANSWER-CHECK-INPUT%', '<input type="radio" value="other" name="yop_poll_answer[' . $question->ID . ']" id="yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other" />', $m);
 
563
  }
564
+ $temp_answer_model = str_ireplace('%POLL-OTHER-ANSWER-LABEL%', '<label for="yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other">' . $other_answer_label . '</label>', $temp_answer_model);
565
+ $temp_answer_model = str_ireplace('%POLL-OTHER-ANSWER-TEXT-INPUT%', '<label style="width:100%;"><input onclick="document.getElementById(\'yop-poll-answer-' . $this->ID . $unique_id . '-' . $question->ID . '-other' . '\').checked=true;" type="text" value="" name="yop_poll_other_answer[' . $question->ID . ']" id="yop-poll-other-answer-' . $this->ID . $unique_id . '-other" /></label>', $temp_answer_model);
566
 
567
+ if ($this->is_view_poll_results()) {
568
  /**Display only if other answers were not displayed */
569
+ if (!$display_other_answers) {
570
  /** Count question total votes( default + other ) */
571
+ $total_votes = $this->get_question_votes($question);
572
 
573
  /** Count other answers votes*/
574
+ $other_votes = $this->get_question_other_votes($question);
575
 
576
 
577
  $percentages_decimals = 0;
578
+ if (isset($this->percentages_decimals)) {
579
  $percentages_decimals = $this->percentages_decimals;
580
  }
581
 
582
+ if ($other_votes > 0) {
583
+ $percentages = floatval($other_votes * 100 / $total_votes);
584
+ } else {
 
585
  $percentages = 0;
586
  }
587
+ if ($this->is_view_poll_results()) {
588
+ $temp_answer_model = str_ireplace('%POLL-OTHER-ANSWER-RESULT-BAR%', self::display_poll_result_bar('other', $percentages, $this->options, $this->ID . $unique_id), $temp_answer_model);
589
+ $temp_answer_model = str_ireplace('%POLL-ANSWER-RESULT-VOTES%', self::display_poll_result_votes($other_votes, $this->options), $temp_answer_model);
590
+ $temp_answer_model = str_ireplace('- ( )', self::display_poll_result_votes($other_votes, $this->options), $temp_answer_model);
591
 
592
+ $temp_answer_model = str_ireplace('%POLL-ANSWER-RESULT-PERCENTAGES%', self::display_poll_result_percentages(round($percentages, $percentages_decimals), $this->options), $temp_answer_model);
593
  }
594
  }
595
  }
598
  return $model;
599
  }
600
 
601
+ private static function get_question_other_votes($question)
602
+ {
603
  $total_votes = 0;
604
+ foreach ($question->answers as $answer) {
605
+ if ($answer->type == 'other') {
606
+ $total_votes += intval($answer->votes);
607
  }
608
  }
609
  return $total_votes;
610
  }
611
 
612
+ public function custom_field_replace_callback($m, $question)
613
+ {
614
  $unique_id = $this->unique_id;
615
+ $is_voted = $this->is_voted();
616
+ $model = "";
617
+ if (!$is_voted) {
618
+ if (count($question->custom_fields) > 0) {
619
+ foreach ($question->custom_fields as $custom_field) {
620
+ if (function_exists('icl_translate')) {
621
+ $custom_field['custom_field'] = icl_translate('yop_poll', $custom_field->ID . '_custom_field', $custom_field->custom_field);
622
  }
623
+ $temp_string = str_ireplace('%POLL-CUSTOM-FIELD-LABEL%', '<label for="yop-poll-customfield-' . $this->ID . $unique_id . '-' . $custom_field->ID . '">' . yop_poll_kses($custom_field->custom_field) . '</label>', $m);
624
 
625
+ $temp_string = str_ireplace('%POLL-CUSTOM-FIELD-TEXT-INPUT%', '<input type="text" value="" name="yop_poll_customfield[' . $question->ID . '][' . $custom_field->ID . ']" id="yop-poll-customfield-' . $this->ID . $unique_id . '-' . $custom_field->ID . '" class=' . '"yop-poll-customfield-' . $this->ID . $unique_id . '"/>', $temp_string);
626
  $model .= $temp_string;
627
  }
628
  }
630
  return $model;
631
  }
632
 
633
+ public function answer_result_replace_callback($m, $question)
634
+ {
635
+ $unique_id = $this->unique_id;
636
  $return_string = '';
637
+ $is_voted = $this->is_voted();
638
+ $id = $this->ID;
639
 
640
+ if ($this->is_view_poll_results()) {
641
  $display_other_answers = false;
642
+ if ('yes' == $question->allow_other_answers) {
643
+ if ('yes' == $question->display_other_answers_values) {
644
  $display_other_answers = true;
645
  }
646
  }
647
 
648
  $percentages_decimals = 0;
649
+ if (isset($this->percentages_decimals)) {
650
  $percentages_decimals = $this->percentages_decimals;
651
  }
652
 
653
+ if (isset($this->sorting_results)) {
654
+ if ('as_defined' == $this->sorting_results) {
655
+ $question->sortAnswers('question_order', 'asc');
656
+ } elseif ('database' == $this->sorting_results) {
 
657
  $order_dir = 'asc';
658
+ if (isset($this->sorting_results_direction)) {
659
+ $order_dir = ('asc' == $this->sorting_results_direction) ? 'asc' : 'desc';
660
  }
661
+ $question->sortAnswers('ID', $order_dir);
662
+ } elseif ('alphabetical' == $this->sorting_results) {
 
663
  $order_dir = 'asc';
664
+ if (isset($this->sorting_results_direction)) {
665
+ $order_dir = ('asc' == $this->sorting_results_direction) ? 'asc' : 'desc';
666
  }
667
+ $question->sortAnswers('alphabetical', $order_dir);
668
+ } elseif ('votes' == $this->sorting_results) {
 
669
  $order_dir = 'asc';
670
+ if (isset($this->sorting_results_direction)) {
671
+ $order_dir = ('asc' == $this->sorting_results_direction) ? 'asc' : 'desc';
672
  }
673
+ $question->sortAnswers('votes', $order_dir);
674
+ } else {
 
675
  $order_dir = 'asc';
676
+ if (isset($this->sorting_results_direction)) {
677
+ $order_dir = ('asc' == $this->sorting_results_direction) ? 'asc' : 'desc';
678
  }
679
+ $question->sortAnswers('question_order', $order_dir);
680
  }
681
+ } else {
 
682
  $order_dir = 'asc';
683
+ if (isset($this->sorting_results_direction)) {
684
+ $order_dir = ('asc' == $this->sorting_results_direction) ? 'asc' : 'desc';
685
  }
686
+ $question->sortAnswers('question_order', $order_dir);
687
  }
688
 
689
 
690
+ $total_votes = $this->get_question_votes($question);
691
 
692
+ foreach ($question->answers as $ans) {
693
+ if (($ans->type == "other") && !$display_other_answers) {
694
  continue;
695
  }
696
+ if ($ans->votes > 0) {
697
+ $percentages = floatval($ans->votes * 100 / $total_votes);
698
+ } else {
 
699
  $percentages = 0;
700
  }
701
 
702
+ if (function_exists('icl_translate')) {
703
+ $ans->answer = icl_translate('yop_poll', $ans->ID . '_answer', $ans->answer);
704
  }
705
 
706
  /** Start Answer Description replace */
707
  $pattern = '\[(\[?)(ANSWER_DESCRIPTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
708
+ $temp_string = preg_replace("/$pattern/s", "", $m);
709
  /** End Answer Description replace */
710
  $ans->type = "text";
711
+ if ($ans->type == "text") {
712
+ $temp_string = str_ireplace('%POLL-ANSWER-LABEL%', '<span>' . yop_poll_kses(stripslashes($ans->answer)) . '</span>', $temp_string);
713
  }
714
+ $temp_string = str_ireplace('class = ' . '"' . 'yop-poll-li-result-' . $this->ID . $this->unique_id, 'class=' . '"' . 'yop-poll-li-result-' . $this->ID . $this->unique_id . ' yop-poll-li-result-' . $this->ID . $this->unique_id . "-" . $question->ID, $temp_string);
715
 
716
 
717
+ $temp_string = str_ireplace('%POLL-ANSWER-RESULT-VOTES%', self::display_poll_result_votes($ans->votes, $this->options), $temp_string);
718
+ $temp_string = str_ireplace('- ( )', self::display_poll_result_votes($ans->votes, $this->options), $temp_string);
719
+ $temp_string = str_ireplace('%POLL-ANSWER-RESULT-PERCENTAGES%', self::display_poll_result_percentages(round($percentages, $percentages_decimals), $this->options), $temp_string);
720
+ $temp_string = str_ireplace('%POLL-ANSWER-RESULT-BAR%', self::display_poll_result_bar($ans->ID, $percentages, $this->options, $this->ID . $unique_id), $temp_string);
721
  $return_string .= $temp_string;
722
  }
723
  }
725
  return $return_string;
726
  }
727
 
728
+ public function register_vote($request)
729
+ {
730
 
731
  global $current_user;
732
+ $poll_id = $this->id;
733
+ $unique_id = strip_tags(xss_clean($this->unique_id));
734
+ $location = strip_tags(xss_clean($request['location']));
735
+ $vote_id = uniqid('vote_id_');
736
+ $vote_type = $request['vote_type'];
737
+ $SuperCookie = strip_tags(xss_clean($request['supercookie']));
738
+ $tr_id = strip_tags(xss_clean($request['yop_poll_tr_id']));
739
+ $votes = 0;
740
+ $user_id = 0;
741
+ $user_type = 'default';
742
  $user_details = '';
743
+ if (wp_verify_nonce($request['yop-poll-nonce-' . $poll_id . $unique_id], 'yop_poll-' . $this->ID . $unique_id . '-user-actions')) {
744
+ switch ($vote_type) {
745
  default:
746
  {
747
+ $user_id = ($current_user->ID != null) ? $current_user->ID : 0;
748
  $user_type = 'default';
749
  break;
750
  }
751
  case 'wordpress':
752
  {
753
+ $user_id = $current_user->ID;
754
  $user_type = 'wordpress';
755
  break;
756
  }
762
 
763
  }
764
  $log_to_add = array(
765
+ 'poll_id' => $this->ID,
766
+ 'vote_id' => $vote_id,
767
+ 'ip' => yop_poll_get_ip(),
768
+ 'user_id' => $user_id,
769
+ 'user_type' => $user_type,
770
+ 'user_details' => json_encode($user_details),
771
+ 'tr_id' => $tr_id,
772
  );
773
+ } else {
774
+ $this->error = __yop_poll('Bad Request!');
775
+ $log_to_add ['message'] = __yop_poll('Bad request');
776
+ insert_log_in_db($log_to_add);
 
777
  return false;
778
  }
779
+ if (wp_verify_nonce($request['yop-poll-nonce-' . $this->ID . $unique_id], 'yop_poll-' . $this->ID . $unique_id . '-user-actions')) {
780
 
781
+ $tr_id = $request['yop_poll_tr_id'];
782
  $super_perm = true;
783
+ if (in_array("supercookie", $this->blocking_voters)) {
784
+ $super_perm = $this->is_voted_supercookie($SuperCookie);
785
  }
786
+ if ($super_perm == true) {
787
 
788
  $current_date = yop_poll_get_mysql_curent_date();
789
+ if ($this->is_allowed_to_vote($vote_type)) {
790
+ if ($current_date >= convert_date($this->poll_start_date, 'Y-m-d H:i:s')) {
791
+ if ($current_date <= convert_date($this->poll_end_date, 'Y-m-d H:i:s')) {
792
+ if ('closed' == $this->status) {
793
+ $this->error = __yop_poll('This poll is closed!');
794
+ $log_to_add ['message'] = __yop_poll('Poll Closed');
795
+ insert_log_in_db($log_to_add);
796
  return false;
797
+ } else {
798
+ if (!$this->is_voted($vote_type, $facebook_user_details, $google_user_details, true, $SuperCookie)) {
799
+ $voter = array();
800
+ $voter['poll_id'] = $poll_id;
801
+ $voter['user_id'] = $current_user->ID;
 
802
  $voter['user_type'] = $vote_type;
803
 
804
+ if ($this->user_have_votes_to_vote($voter, $SuperCookie)) {
805
+ $i = 1;
806
  $cookie = '';
807
+ $log = array();
808
+ foreach ($this->questions as &$question) {
809
  $answers = array();
810
+ if (isset ($request['yop_poll_answer'][$question->ID])) {
811
+ if ('yes' == $question->allow_multiple_answers) {
812
+ if (count($request['yop_poll_answer'][$question->ID]) <= intval($question->allow_multiple_answers_number)) {
813
+ if (count($request['yop_poll_answer'][$question->ID]) >= intval($question->allow_multiple_answers_min_number)) {
814
  $answers = array();
815
+ foreach ($request['yop_poll_answer'][$question->ID] as $answer) {
816
+ $new_answer = array();
817
  $new_answer['answer_id'] = $answer;
818
+ $new_answer['type'] = 'default';
819
+ if ('other' == $answer) {
820
  $a = new YOP_POLL_Answer_Model();
821
+ if (isset($request['yop_poll_other_answer'][$question->ID]) && '' != strip_tags(trim($request['yop_poll_other_answer'][$question->ID]))) {
822
+ $a->type = 'other';
823
+ $a->poll_id = $poll_id;
824
+ $a->question_id = $question->ID;
825
+ $a->answer = strip_tags(trim($request['yop_poll_other_answer'][$question->ID]));
826
+ $a->answer_date = current_time('mysql');
827
+ $a->answer_modified = current_time('mysql');
828
+ $a->status = 'active';
829
+ $a->question_order = $question->countanswers() + 1;
830
+ $a->answer_author = $current_user->ID;
831
  $a->save();
832
 
833
+ if (!$a->id) {
834
+ $this->error = __yop_poll('Other answer for question ') . $i . __yop_poll(' could not be inserted!');
835
+ $log_to_add ['message'] = __yop_poll('Other answer for question ') . $i . __yop_poll(' could not be inserted');
836
+ insert_log_in_db($log_to_add);
837
  return false;
838
  }
839
+ } else {
840
+ $this->error = __yop_poll('Other answer from question ') . $i . __yop_poll(' is empty');
841
+ $log_to_add ['message'] = __yop_poll('Other answer from question ') . $i . __yop_poll(' is empty');
842
+ insert_log_in_db($log_to_add);
 
843
  return false;
844
  }
845
+ $question->addAnswer($a);
846
  $new_answer['answer_id'] = $a->id;
847
+ $new_answer['type'] = 'other';
848
+ unset($a);
849
  }
850
  $new_answer['poll_id'] = $poll_id;
851
  $new_answer['vote_id'] = $vote_id;
852
+ $new_answer['ip'] = yop_poll_get_ip();
853
  $new_answer['user_id'] = $current_user->ID;
854
 
855
  $new_answer['user_type'] = 'default';
856
+ if ($vote_type == 'anonymous' || $vote_type == 'wordpress') {
857
  $new_answer['user_type'] = $vote_type;
858
  }
859
 
860
+ $new_answer['http_referer'] = $_SERVER['HTTP_REFERER'];
861
+ $new_answer['tr_id'] = $tr_id;
862
+ $new_answer['host'] = esc_attr(@gethostbyaddr(yop_poll_get_ip()));
863
  $new_answer['other_answer_value'] = '';
864
 
865
  $answers[] = $new_answer;
866
  }
867
+ } else {
868
+ $this->error = __yop_poll("Too few answers selected for question ") . $i . __yop_poll("! Only more than ") . $question->allow_multiple_answers_min_number . __yop_poll(" answers allowed!");
869
+ $log_to_add ['message'] = __yop_poll("Too few answers selected for question ") . $i;
870
+ insert_log_in_db($log_to_add);
 
871
  return false;
872
  }
873
+ } else {
874
+ $this->error = __yop_poll("Too many answers selected for question ") . $i . __yop_poll("! Only ") . $question->allow_multiple_answers_number . __yop_poll(" answers allowed!");
875
+ $log_to_add ['message'] = __yop_poll("Too many answers selected for question ") . $i;
876
+ insert_log_in_db($log_to_add);
 
877
  return false;
878
  }
879
+ } else {
880
+ $new_answer = array();
 
881
  $new_answer['answer_id'] = $request['yop_poll_answer'][$question->ID];
882
+ $new_answer['type'] = 'default';
883
+ if ('other' == $request['yop_poll_answer'][$question->ID]) {
884
  $a = new YOP_POLL_Answer_Model();
885
+ if (isset($request['yop_poll_other_answer'][$question->ID]) && '' != strip_tags(trim($request['yop_poll_other_answer'][$question->ID]))) {
886
+ $a->type = 'other';
887
+ $a->poll_id = $poll_id;
888
+ $a->question_id = $question->ID;
889
+ $a->answer = strip_tags(trim($request['yop_poll_other_answer'][$question->ID]));
890
+ $a->answer_date = current_time('mysql');
891
  $a->question_order = $question->countanswers();
892
+ $a->answer_author = $current_user->ID;
893
+ $a->votes = 0;
894
  $a->save();
895
 
896
+ if (!$a->id) {
897
+ $this->error = __yop_poll("Other answer for question ") . $i . __yop_poll(" could not be inserted!");
898
+ $log_to_add ['message'] = __yop_poll("Other answer for question ") . $i . __yop_poll(" could not be inserted");
899
+ insert_log_in_db($log_to_add);
900
  return false;
901
  }
902
+ } else {
903
+ $this->error = __yop_poll("Other answer from question ") . $i . ' ' . __yop_poll('is empty');
904
+ $log_to_add ['message'] = __yop_poll("Other answer from question ") . $i . ' ' . __yop_poll('empty');
905
+ insert_log_in_db($log_to_add);
 
906
  return false;
907
  }
908
 
909
+ $question->addAnswer($a);
910
  $new_answer['answer_id'] = $a->id;
911
+ $new_answer['type'] = 'other';
912
+ unset($a);
913
  }
914
 
915
  $new_answer['poll_id'] = $poll_id;
916
  $new_answer['vote_id'] = $vote_id;
917
+ $new_answer['ip'] = yop_poll_get_ip();
918
  $new_answer['user_id'] = $current_user->ID;
919
 
920
  $new_answer['user_type'] = 'default';
921
 
922
 
923
+ $new_answer['http_referer'] = $_SERVER['HTTP_REFERER'];
924
+ $new_answer['tr_id'] = $tr_id;
925
+ $new_answer['host'] = esc_attr(@gethostbyaddr(yop_poll_get_ip()));
926
  $new_answer['other_answer_value'] = '';
927
+ $answers[] = $new_answer;
928
  }
929
 
930
+ if (count($answers) > 0) {
931
+ $custom_fields = array();
932
  $poll_custom_fields = $question->custom_fields;
933
 
934
+ if (count($poll_custom_fields) > 0) {
935
 
936
+ if (isset($request['yop_poll_customfield'][$question->ID])) {
937
 
938
+ foreach ($poll_custom_fields as $custom_field) {
939
 
940
+ if (isset($request['yop_poll_customfield'][$question->ID][$custom_field->ID])) {
941
 
942
+ if ('' == trim(strip_tags($request['yop_poll_customfield'][$question->ID][$custom_field->ID])) && 'yes' == $custom_field->required) {
943
+ $this->error = __yop_poll("Custom field ") . $custom_field->custom_field . __yop_poll(" from question ") . $i . ' ' . __yop_poll("is required") . "!";
944
+ $log_to_add ['message'] = __yop_poll("Custom field ") . $custom_field->custom_field . __yop_poll(" from question ") . $i . ' ' . __yop_poll("required");
945
+ insert_log_in_db($log_to_add);
946
  return false;
947
+ } else {
948
+ if (trim(strip_tags($request['yop_poll_customfield'][$question->ID][$custom_field->ID])) != '') {
949
+ $new_custom_field = array();
950
+ $new_custom_field['poll_id'] = $poll_id;
951
+ $new_custom_field['question_id'] = $question->ID;
952
+ $new_custom_field['vote_id'] = $vote_id;
 
953
  $new_custom_field['custom_field_id'] = $custom_field->ID;
954
+ $new_custom_field['user_id'] = $current_user->ID;
955
 
956
  $new_custom_field['user_type'] = 'default';
957
 
958
+ if ($vote_type == 'wordpress' || $vote_type == 'anonymous') {
959
  $new_custom_field['user_type'] = $vote_type;
960
  }
961
 
962
+ $new_custom_field['custom_field_value'] = strip_tags(trim($request['yop_poll_customfield'][$question->ID][$custom_field->ID]));
963
+ $custom_fields[] = $new_custom_field;
964
 
965
  }
966
  }
967
+ } else {
968
+ $this->error = __yop_poll("Custom field ") . '"' . $custom_field->custom_field . '"' . __yop_poll(" from question ") . $i . ' ' . __yop_poll("is missing ") . '!';
 
969
 
970
+ $log_to_add ['message'] = __yop_poll("Custom field ") . '"' . $custom_field->custom_field . '"' . __yop_poll(" from question ") . $i . ' ' . __yop_poll("missing");
971
+ insert_log_in_db($log_to_add);
972
  return false;
973
  }
974
  }
975
+ } else {
976
+ $this->error = __yop_poll("Custom fields from question ") . $i . ' ' . __yop_poll("are missing") . '!';
977
+ $log_to_add ['message'] = __yop_poll("Custom fields from question ") . $i . ' ' . __yop_poll("missing") . '!';
978
+ insert_log_in_db($log_to_add);
 
979
  return false;
980
  }
981
  }
982
 
983
+ if ('yes' == $this->use_captcha) {
984
+ require_once(YOP_POLL_INC . '/securimage.php');
985
+ $img = new Yop_Poll_Securimage();
986
  $img->namespace = 'yop_poll_' . $poll_id . $unique_id;
987
+ if ($img->check($_REQUEST['yop_poll_captcha_input'][$poll_id])) {
988
  $mail_notifications_answers[$question->ID] = array();
989
 
990
+ $add_to_log = $this->update_votes($question, $answers, $votes, $mail_notifications_answers[$question->ID], $facebook_user_details['id'], $google_user_details['id']);
991
 
992
  $log["q-" . $question->ID]['question'] = $question->question;
993
+ $log["q-" . $question->ID]['a'] = $add_to_log['a'];
994
+ $log["q-" . $question->ID]['answers'] = $add_to_log['answers'];
995
 
996
+ $mail_notifications_answers[$question->ID] = trim($mail_notifications_answers[$question->ID], '<br>');
997
 
998
  $mail_notifications_custom_fields[$question->ID] = '';
999
+ foreach ($custom_fields as $custom_field) {
1000
 
1001
+ if ('anonymous' == $vote_type) {
1002
  $custom_field['user_id'] = 0;
1003
  }
1004
  $custom_field['tr_id'] = $tr_id;
1005
+ self::insert_vote_custom_field_in_database($custom_field);
1006
 
1007
+ $cf = $question->getCustomFieldById($custom_field['custom_field_id']);
1008
 
1009
  $mail_notifications_custom_fields[$question->ID][$cf->custom_field] = $custom_field['custom_field_value'];
1010
  }
1011
 
1012
+ if ('yes' == $this->number_of_votes_per_user) {
1013
+ $this->success = str_replace('%USER-VOTES-LEFT%', intval($this->number_of_votes_per_user) - $this->get_voter_number_of_votes($voter), $poll_options['message_after_vote']);
1014
+ } else {
1015
+ $this->success = str_replace('%USER-VOTES-LEFT%', '', $this->message_after_vote);
 
1016
  }
1017
+ } else {
1018
+ $this->error = __yop_poll("Incorrect security code entered!");
1019
+ $log_to_add ['message'] = __yop_poll("Incorrect security code entered");
1020
+ insert_log_in_db($log_to_add);
 
1021
  return false;
1022
  }
1023
+ } else {
 
1024
  $mail_notifications_answers[$question->ID] = array();
1025
 
1026
+ $add_to_log = $this->update_votes($question, $answers, $votes, $mail_notifications_answers[$question->ID], $vote_type, $facebook_user_details['id'], $google_user_details['id']);
1027
 
1028
  $log["q-" . $question->ID]['question'] = $question->question;
1029
+ $log["q-" . $question->ID]['id'] = $question->ID;
1030
+ $log["q-" . $question->ID]['a'] = $add_to_log['a'];
1031
+ $log["q-" . $question->ID]['answers'] = $add_to_log['answers'];
1032
 
1033
 
1034
  $mail_notifications_custom_fields[$question->ID] = array();
1035
  $add_to_log = array();
1036
+ foreach ($custom_fields as $custom_field) {
1037
 
1038
+ if ('google' == $vote_type) {
1039
  $custom_field['user_id'] = $google_user_details['id'];
1040
  }
1041
+ if ('anonymous' == $vote_type) {
1042
  $custom_field['user_id'] = 0;
1043
  }
1044
  $custom_field['tr_id'] = $tr_id;
1045
 
1046
+ $cf_id = self::insert_vote_custom_field_in_database($custom_field);
1047
 
1048
  $add_to_log[] = $cf_id;
1049
 
1050
+ $cf = $question->getCustomFieldById($custom_field['custom_field_id']);
1051
 
1052
  $mail_notifications_custom_fields[$question->ID][$cf->custom_field] = $custom_field['custom_field_value'];
1053
  }
1054
  $log["q-" . $question->ID]['cf'] = $add_to_log;
1055
 
1056
+ if ('yes' == $this->number_of_votes_per_user) {
1057
+ $this->success = str_replace('%USER-VOTES-LEFT%', intval($this->number_of_votes_per_user) - $this->get_voter_number_of_votes($voter), $this->message_after_vote);
1058
+ } else {
1059
+ $this->success = str_replace('%USER-VOTES-LEFT%', '', $this->message_after_vote);
 
1060
  }
1061
  }
1062
+ } else {
1063
+ $this->error = __yop_poll("No vote registered!");
1064
+ $log_to_add ['message'] = __yop_poll("No vote registered");
1065
+ insert_log_in_db($log_to_add);
 
1066
  return false;
1067
  }
1068
+ } else {
1069
+ $this->error = __yop_poll("No answer selected for question ") . $i;
1070
+ $log_to_add ['message'] = __yop_poll("No answer selected for question ") . $i;
1071
+ insert_log_in_db($log_to_add);
 
1072
  return false;
1073
  }
1074
+ $i++;
1075
  }
1076
+ } else {
1077
+ $this->error = __yop_poll("You have run out of votes!");
1078
+ $log_to_add ['message'] = __yop_poll("Run out of votes");
1079
+ insert_log_in_db($log_to_add);
 
1080
  return false;
1081
  }
1082
+ } else {
1083
+ $this->error = __yop_poll("You Already voted!");
1084
+ $log_to_add ['message'] = __yop_poll("Already Voted");
1085
+ insert_log_in_db($log_to_add);
 
1086
  return false;
1087
  }
1088
  }
1089
+ } else {
1090
+ $this->error = __yop_poll("This poll is closed!");
1091
+ $log_to_add ['message'] = __yop_poll("Poll Closed");
1092
+ insert_log_in_db($log_to_add);
 
1093
  return false;
1094
  }
1095
+ } else {
1096
+ $this->error = __yop_poll("You can vote once the poll starts!");
1097
+ $log_to_add ['message'] = __yop_poll("Poll not started");
1098
+ insert_log_in_db($log_to_add);
 
1099
  return false;
1100
  }
1101
+ } else {
1102
+ $this->error = __yop_poll("You are not allowed to vote!");
1103
+ $log_to_add ['message'] = __yop_poll("Not allowed to vote");
1104
+ insert_log_in_db($log_to_add);
 
1105
  return false;
1106
  }
1107
+ } else {
1108
+ $this->error = __yop_poll("You are not allowed to vote!");
 
1109
  return false;
1110
  }
1111
 
1112
+ } else {
1113
+ $this->error = __yop_poll("Bad Request!");
1114
+ $log_to_add ['message'] = __yop_poll("Bad request");
1115
+ insert_log_in_db($log_to_add);
 
1116
  return false;
1117
  }
1118
 
1119
+ if ($this->send_email_notifications == "yes") {
1120
+ $this->sendMail($mail_notifications_answers, $mail_notifications_custom_fields, $vote_id);
1121
  }
1122
 
1123
  $this->update_poll_total_votes(1);
1124
 
1125
+ $log_to_add ['message'] = __yop_poll('Success');
1126
+ $log_to_add ['vote_details'] = json_encode($log);
1127
 
1128
+ insert_log_in_db($log_to_add);
1129
+ $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $log_to_add['ip']));
1130
  $log_to_add['country'] = $ip_data->geoplugin_countryName;
1131
+ insert_result_in_db($log_to_add);
1132
 
1133
+ $this->set_vote_cookie(json_encode($log), $vote_type, $facebook_user_details, $google_user_details);
1134
 
1135
  $this->vote = true;
1136
+ $this->poll_total_votes += 1;
1137
 
1138
+ return do_shortcode($this->return_poll_html(array('tr_id' => $tr_id, 'location' => $location)));
1139
  }
1140
 
1141
+ function is_voted_supercookie($SuperCookie)
1142
+ {
1143
+ $current_time = date('Y-m-d H:i:s', strtotime(date("Y-m-d H:i:s", mktime()) . " + 365 day"));
1144
+ $cookie = explode("=", $SuperCookie);
1145
+ $num_votes = explode(";", $cookie[1]);
1146
+ if ($num_votes[0] == 0) {
1147
  return true;
1148
  }
1149
+ $cookie_expire = convert_date($cookie[2], "Y-m-d H:i:s");
1150
 
1151
 
1152
+ if (isset($this->blocking_voters_interval_value)) {
1153
  $value = $this->blocking_voters_interval_value;
1154
  }
1155
  $unit = 'days';
1156
+ if (isset($this->blocking_voters_interval_unit)) {
1157
  $unit = $this->blocking_voters_interval_unit;
1158
  }
1159
 
1160
+ switch ($unit) {
1161
  case 'seconds' :
1162
  $expire_cookie = $value;
1163
  break;
1164
  case 'minutes' :
1165
+ $expire_cookie = (60 * $value);
1166
  break;
1167
  case 'hours' :
1168
+ $expire_cookie = (60 * 60 * $value);
1169
  break;
1170
  case 'days' :
1171
+ $expire_cookie = (60 * 60 * 24 * $value);
1172
  break;
1173
  }
1174
+ $timeFirst = strtotime($current_time);
1175
+ $timeSecond = strtotime($cookie_expire);
1176
  $differenceInSeconds = $timeFirst - $timeSecond;
1177
+ if ($differenceInSeconds >= 31556926) {
1178
  return true;
1179
  }
1180
+ if ($expire_cookie > $differenceInSeconds) {
1181
  return false;
1182
  }
1183
  return true;
1184
  }
1185
 
1186
+ private function update_votes(&$question, $answers, &$votes, &$mail_notification = '', $vote_type, $facebook_user_id, $google_user_id)
1187
+ {
1188
 
1189
+ foreach ($answers as $answer) {
1190
 
1191
+ $answer_to_update = & $question->getAnswerById($answer['answer_id']);
1192
 
1193
 
1194
+ if ('anonymous' == $vote_type) {
1195
  $answer['user_id'] = 0;
1196
  }
1197
 
1198
+ if ($answer['type'] == 'other') {
1199
+ if ('yes' == $question->add_other_answers_to_default_answers) {
1200
  $answer_to_update->type = 'text';
1201
+ $answer['type'] = 'text';
1202
  }
1203
  }
1204
+ $votes++;
1205
 
1206
+ $answer_to_update->answer_modified = current_time('mysql');
1207
+ $answer_to_update->answer_status = 'active';
1208
+ $answer_to_update->votes = intval($answer_to_update->votes) + 1;
1209
 
1210
  $answer_to_update->save();
1211
 
1212
+ $add_to_log['a'][] = $answer_to_update->ID;
1213
  $add_to_log['answers'][] = $answer_to_update->answer;
1214
+ $mail_notification[] = $answer_to_update->answer;
1215
 
1216
+ unset($answer_to_update);
1217
  }
1218
  return $add_to_log;
1219
  }
1220
 
1221
+ private static function insert_vote_custom_field_in_database($custom_field = array())
1222
+ {
1223
  global $wpdb;
1224
 
1225
+ $custom_field['custom_field_value'] = strip_tags($custom_field['custom_field_value']);
1226
+ $wpdb->query($wpdb->prepare("
1227
  INSERT INTO " . $wpdb->yop_poll_votes_custom_fields . "
1228
  SET
1229
  poll_id = %d,
1235
  custom_field_value = %s,
1236
  tr_id = %s,
1237
  vote_date = %s
1238
+ ", $custom_field['poll_id'], $custom_field['question_id'], $custom_field['vote_id'], $custom_field['custom_field_id'], $custom_field['user_id'], $custom_field['user_type'], $custom_field['custom_field_value'], $custom_field['tr_id'], current_time('mysql')));
1239
  return $wpdb->insert_id;
1240
  }
1241
 
1242
+ private function update_poll_total_votes($votes = 0)
1243
+ {
1244
  global $wpdb;
1245
+ $wpdb->query($wpdb->prepare("
1246
  UPDATE {$wpdb->yop_polls}
1247
  SET
1248
  poll_total_votes = poll_total_votes + %d
1249
  WHERE
1250
  ID = %d
1251
+ ", $votes, $this->ID));
1252
 
1253
  }
1254
 
1255
  public function return_poll_html(
1256
  $attr = array(
1257
+ 'tr_id' => '',
1258
  'location' => 'page',
1259
  'load_css' => false,
1260
+ 'load_js' => false,
1261
+ 'show_results' => ''
1262
  )
1263
+ )
1264
+ {
1265
+ $time_format = "H:i:s";
1266
+ $options = get_option('yop_poll_options');
1267
+ if ($options['date_format'] == "UE")
1268
+ $date_format = "d-m-Y"; else {
1269
+ $date_format = "m-d-Y";
1270
+ }
1271
+ $date_format = $date_format . ' ' . $time_format;
1272
+ $tr_id = isset($attr['tr_id']) ? $attr['tr_id'] : '';
1273
+ $show_results = isset($attr['show_results']) ? $attr['show_results'] : '';
1274
+ $location = isset($attr['location']) ? $attr['location'] : 'page';
1275
+ $load_css = isset($attr['load_css']) ? $attr['load_css'] : false;
1276
  $unique_id = $this->unique_id;
1277
+ $poll_id = $this->ID;
1278
+ if (!$poll_id) {
1279
  return '';
1280
  }
1281
 
1282
  //Get template id based on location(widget/page)
1283
+ if ('widget' == $location) {
1284
  $template_id = $this->widget_template;
1285
+ } else {
 
1286
  $template_id = $this->template;
1287
  }
1288
 
1290
  /**
1291
  * Init Options
1292
  */
1293
+ $general_options = get_option("yop_poll_options");
1294
+ foreach ($general_options as $key => $value) {
1295
+ if (!isset($this->$key)) {
1296
  $this->$key = $value;
1297
  }
1298
  }
1299
 
1300
+ if ('' == $template_id) {
1301
  //get default template
1302
  $template_details = self::get_poll_template_from_database();
1303
+ } else {
1304
+ $template_details = self::get_poll_template_from_database($template_id);
 
1305
  }
1306
 
1307
  $template_css = $template_details['css'];
1308
+ $template_details['before_vote_template'] = str_replace('id = "yop-poll-li-answer-%POLL-ID%-%QUESTION-ID%"', '', $template_details['before_vote_template']);
1309
+ $template_details['before_vote_template'] = str_replace('id = "yop-poll-li-custom-%POLL-ID%-%QUESTION-ID%"', '', $template_details['before_vote_template']);
1310
+ $template_details['before_vote_template'] = str_replace('id = "yop-poll-customs-%POLL-ID%-%QUESTION-ID%"', '', $template_details['before_vote_template']);
1311
+ $template_details['after_end_date_template'] = str_replace('id = "pds-feedback-label-%POLL-ID%-%QUESTION-ID%"', '', $template_details['after_end_date_template']);
1312
+ $template_details['after_vote_template'] = str_replace('id = "pds-feedback-label-%POLL-ID%-%QUESTION-ID%"', '', $template_details['after_vote_template']);
1313
+ $template_details['after_end_date_template'] = str_replace('id = "yop-poll-li-result-%POLL-ID%-%QUESTION-ID%"', '', $template_details['after_end_date_template']);
1314
+ $template_details['after_vote_template'] = str_replace('id = "yop-poll-li-result-%POLL-ID%-%QUESTION-ID%"', '', $template_details['after_vote_template']);
1315
+ $template_details['after_end_date_template'] = str_replace('id = "pds-answer-text-%POLL-ID%-%QUESTION-ID%"', '', $template_details['after_end_date_template']);
1316
+ $template_details['after_vote_template'] = str_replace('id = "pds-answer-text-%POLL-ID%-%QUESTION-ID%"', '', $template_details['after_vote_template']);
1317
+ $template_details['after_end_date_template'] = str_replace('id = "pds-feedback-result-%POLL-ID%-%QUESTION-ID%"', '', $template_details['after_end_date_template']);
1318
+ $template_details['after_vote_template'] = str_replace('id = "pds-feedback-result-%POLL-ID%-%QUESTION-ID%"', '', $template_details['after_vote_template']);
1319
+ $template_details['after_end_date_template'] = str_replace('id = "pds-feedback-per-%POLL-ID%-%QUESTION-ID%"', '', $template_details['after_end_date_template']);
1320
+ $template_details['after_vote_template'] = str_replace('id = "pds-feedback-per-%POLL-ID%-%QUESTION-ID%"', '', $template_details['after_vote_template']);
1321
  $poll_details = $this;
1322
+ $this->vote_button_label = empty($this->vote_button_label) ? $general_options['vote_button_label'] : $this->vote_button_label;
1323
+ $this->vote_permisions_wordpress_label = empty($this->vote_permisions_wordpress_label) ? $general_options['vote_permisions_wordpress_label'] : $this->vote_permisions_wordpress_label;
1324
+ $this->vote_permisions_anonymous_label = empty($this->vote_permisions_anonymous_label) ? $general_options['vote_permisions_anonymous_label'] : $this->vote_permisions_anonymous_label;
1325
 
1326
  //Translate labels
1327
+ if (function_exists('icl_translate')) {
1328
  // $poll_details = icl_translate( 'yop_poll', $poll_details->ID . '_poll_title', $poll_details->name );
1329
+ $this->singular_answer_result_votes_number_label = icl_translate('yop_poll', $poll_details->ID . '_singular_answer_result_votes_number_label', $general_options['singular_answer_result_votes_number_label']);
1330
+ $this->plural_answer_result_votes_number_label = icl_translate('yop_poll', $poll_details->ID . '_plural_answer_result_votes_number_label', $general_options['plural_answer_result_votes_number_label']);
1331
+ $this->vote_button_label = icl_translate('yop_poll', $poll_details->ID . '_vote_button_label', empty($this->vote_button_label) ? $general_options['vote_button_label'] : $this->vote_button_label);
1332
+ $this->view_results_link_label = icl_translate('yop_poll', $poll_details->ID . '_view_results_link_label', $this->view_results_link_label);
1333
+ $this->view_back_to_vote_link_label = icl_translate('yop_poll', $poll_details->ID . '_view_back_to_vote_link_label', $this->view_back_to_vote_link_label);
1334
+ $this->view_total_votes_label = icl_translate('yop_poll', $poll_details->ID . '_view_total_votes_label', $this->view_total_votes_label);
1335
+ $this->view_total_answers_label = icl_translate('yop_poll', $poll_details->ID . '_view_total_answers_label', $this->view_total_answers_label);
1336
+ $this->view_total_voters_label = icl_translate('yop_poll', $poll_details->ID . '_view_total_voters_label', $this->view_total_voters_label);
1337
+ $this->archive_link_label = icl_translate('yop_poll', $poll_details->ID . '_archive_link_label', $this->archive_link_label);
1338
+ $this->answer_result_label = icl_translate('yop_poll', $poll_details->ID . '_answer_result_label', $this->answer_result_label);
1339
+ $this->vote_permisions_wordpress_label = icl_translate('yop_poll', $poll_details->ID . '_vote_permisions_wordpress_label', $this->vote_permisions_wordpress_label);
1340
+ $this->vote_share_google_label = icl_translate('yop_poll', $poll_details->ID . '_vote_share_google_label', $this->vote_share_google_label);
1341
+ $this->vote_permisions_anonymous_label = icl_translate('yop_poll', $poll_details->ID . '_vote_permisions_anonymous_label', $this->vote_permisions_anonymous_label);
1342
  }
1343
 
1344
+ $is_voted = $this->is_voted();
1345
  $current_date = self::get_mysql_curent_date();
1346
+ if ($current_date >= convert_date($this->poll_start_date, 'Y-m-d H:i:s', 1)) {
1347
 
1348
+ if ($current_date <= convert_date($this->poll_end_date, 'Y-m-d H:i:s', 1)) {
1349
  //poll is active
1350
+ if (!$is_voted) {
1351
  //user hasn't voted yet
1352
  $template = $template_details['before_vote_template'];
1353
+ if (isset($show_results) && $show_results == 1) {
1354
 
1355
  $template = $template_details['after_vote_template'];
1356
+ $this->view_results = array('before');
1357
  }
1358
+ if (in_array('before', $this->view_results)) {
1359
+ if ($this->is_view_poll_results()) {
1360
+ $template = str_ireplace('%POLL-ANSWER-RESULT-LABEL%', $this->answer_result_label, $template);
1361
  }
1362
  }
1363
+ $template = str_ireplace('%POLL-VOTE-BUTTON%', '<button class="yop_poll_vote_button" id="yop_poll_vote-button-' . $this->ID . $unique_id . '" onclick="yop_poll_register_vote(\'' . $this->ID . '\', \'' . $location . '\', \'' . $unique_id . '\'); return false;">' . $this->vote_button_label . '</button>', $template);
1364
+ } else {
 
1365
  //user has voted
1366
 
1367
+ if (
1368
+ in_array('after', $this->view_results) ||
1369
+ in_array('before', $this->view_results) ||
1370
+ (in_array('custom-date', $this->view_results) && self::get_mysql_curent_date() >= convert_date($this->view_results_start_date, 'Y-m-d H:i:s'))
1371
  ) {
1372
 
1373
  $template = $template_details['after_vote_template'];
1374
 
1375
+ if ($this->is_view_poll_results()) {
1376
+ $template = str_ireplace('%POLL-ANSWER-RESULT-LABEL%', $this->answer_result_label, $template);
1377
  }
1378
  }
1379
 
1380
+ if ('yes' == $this->view_back_to_vote_link) {
1381
+ $vote = $this->vote;
1382
  $this->vote = false;
1383
+ if (!$this->is_voted()) {
1384
+ $template = str_ireplace('%POLL-BACK-TO-VOTE-LINK%', '<a href="javascript:void(0)" class="yop_poll_back_to_vote_link" id="yop_poll_back_to_vote_link' . $this->ID . $unique_id . '" onClick="yop_poll_back_to_vote(\'' . $this->ID . '\', \'' . $location . '\', \'' . $unique_id . '\')">' . $this->view_back_to_vote_link_label . '</a>', $template);
1385
  }
1386
  $this->vote = $vote;
1387
  }
1388
 
1389
  }
1390
+ } else {
 
1391
  //poll has ended
1392
  $template = $template_details['after_end_date_template'];
1393
+ if (in_array('after-poll-end-date', $this->view_results) || in_array('before', $this->view_results) || in_array('after', $this->view_results)) {
1394
+ if ($this->is_view_poll_results()) {
1395
+ $template = str_ireplace('%POLL-ANSWER-RESULT-LABEL%', $this->answer_result_label, $template);
1396
+ $template = str_ireplace('%POLL-END-DATE%', $this->poll_end_date, $template);
1397
+ $template = str_ireplace('%POLL-START-DATE%', $this->poll_start_date, $template);
1398
  }
1399
  }
1400
 
1401
  }
1402
+ } else {
 
1403
  //poll hasn't started
1404
  $template = $template_details['before_start_date_template'];
1405
+ $template = str_ireplace('%POLL-END-DATE%', $this->poll_end_date, $template);
1406
+ $template = str_ireplace('%POLL-START-DATE%', $this->poll_start_date, $template);
1407
+ if (in_array('before', $this->view_results)) {
1408
+ if ($this->is_view_poll_results()) {
1409
+ $template = str_ireplace('%POLL-ANSWER-RESULT-LABEL%', $this->answer_result_label, $template);
1410
 
1411
  }
1412
 
1413
  }
1414
  }
1415
 
1416
+ if (in_array('custom-date', $this->view_results)) {
1417
+ $template = str_ireplace('%POLL-END-DATE%', $this->poll_end_date, $template);
1418
+ $template = str_ireplace('%POLL-START-DATE%', $this->poll_start_date, $template);
1419
+ if (self::get_mysql_curent_date() >= convert_date($this->view_results_start_date, 'Y-m-d H:i:s', 1)) {
1420
 
1421
+ if ($this->is_view_poll_results()) {
1422
+ $template = str_ireplace('%POLL-ANSWER-RESULT-LABEL%', $this->answer_result_label, $template);
1423
  }
1424
  }
1425
  }
1426
+ $template = str_ireplace('%POLL-END-DATE%', $this->poll_end_date, $template);
1427
+ $template = str_ireplace('%POLL-START-DATE%', $this->poll_start_date, $template);
1428
+ $template = stripslashes_deep($template);
1429
 
1430
+ $template = str_ireplace('%POLL-ID%', $this->ID . $unique_id, $template);
1431
+ $template = str_ireplace("%POLL-NAME%", yop_poll_kses(stripslashes($this->poll_title)), $template);
1432
+ $template = str_ireplace('%POLL-START-DATE%', esc_html(stripslashes(convert_date($this->start_date, $date_format))), $template);
1433
+ $template = str_ireplace('%POLL-PAGE-URL%', esc_html(yop_poll_kses(stripslashes($this->poll_page_url))), $template);
1434
 
1435
+ if ('01-01-2038 23:59:59' == convert_date($this->poll_end_date, 'Y-m-d H:i:s')) {
1436
+ $template = str_ireplace('%POLL-END-DATE%', __yop_poll('Never Expire'), $template);
1437
+ } else {
1438
+ $template = str_ireplace('%POLL-END-DATE%', esc_html(stripslashes(convert_date($this->end_date, $date_format))), $template);
 
1439
  }
1440
 
1441
+ if ('yes' == $this->view_results_link) {
1442
+ $template = str_ireplace('%POLL-VIEW-RESULT-LINK%', '<a href="javascript:void(0)" class="yop_poll_result_link" id="yop_poll_result_link' . $this->ID . $unique_id . '" onClick="yop_poll_view_results(\'' . $this->ID . '\', \'' . $location . '\', \'' . $unique_id . '\')">' . $this->view_results_link_label . '</a>', $template);
1443
  }
1444
+ if ('yes' == $this->view_poll_archive_link) {
1445
+ $template = str_ireplace('%POLL-VIEW-ARCHIVE-LINK%', '<a href="' . get_permalink($this->yop_poll_archive_page_id) . '" class="yop_poll_archive_link" id="yop_poll_archive_link_' . $this->ID . $unique_id . '" >' . $this->archive_link_label . '</a>', $template);
1446
  }
1447
  $poll_total_answers = 0;
1448
+ foreach ($this->questions as $q) {
1449
+ foreach ($q->answers as $a)
1450
+ $poll_total_answers += $a->votes;
1451
  }
1452
 
1453
 
1454
+ if ('yes' == $this->view_total_answers) {
1455
+ $template = str_ireplace('%POLL-TOTAL-ANSWERS-LABEL%', $this->view_total_answers_label, $template);
1456
+ $template = str_ireplace('%POLL-TOTAL-ANSWERS%', $poll_total_answers, $template);
1457
  }
1458
+ if ('yes' == $this->view_total_votes) {
1459
+ $template = str_ireplace('%POLL-TOTAL-VOTES-LABEL%', $this->view_total_votes_label, $template);
1460
+ $template = str_ireplace('%POLL-TOTAL-VOTES%', $this->poll_total_votes, $template);
1461
  }
1462
 
1463
  $msgDivS = false;
1464
  $msgDivE = false;
1465
 
1466
+ if (strpos($template, "%POLL-SUCCESS-MSG%") != false) {
1467
+ $msgDivS = true;
1468
+ $template = str_ireplace('%POLL-SUCCESS-MSG%', '<div id="yop-poll-container-success-' . $this->ID . $unique_id . '" class="yop-poll-container-success"></div>', $template);
1469
  }
1470
+ if (strpos($template, "%POLL-ERROR-MSG%") != false) {
1471
+ $msgDivE = true;
1472
+ $template = str_ireplace('%POLL-ERROR-MSG%', '<div id="yop-poll-container-error-' . $this->ID . $unique_id . '" class="yop-poll-container-error"></div>', $template);
1473
  }
1474
 
1475
+ $that = $this;
1476
 
1477
  /** Start Question replace*/
1478
+ $pattern = '\[(\[?)(QUESTION_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
1479
+ $template = preg_replace_callback("/$pattern/s", function ($m) use ($that) {
1480
  return $that->question_replace_callback($m);
1481
+ }, $template);
1482
  /** End Question replace*/
1483
 
1484
 
1485
  /** Start CAPTCHA replace*/
1486
+ $pattern = '\[(\[?)(CAPTCHA_CONTAINER)\b([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)';
1487
+ $template = preg_replace_callback("/$pattern/s", function ($m) use ($that) {
1488
  return $that->captcha_replace_callback($m);
1489
+ }, $template);
1490
  /** End CAPTCHA replace*/
1491
 
1492
 
1493
+ $temp = self::strip_all_tags($template);
1494
 
1495
  $template = "";
1496
+ if ($load_css) {
1497
+ $template .= '<style scoped>' . self::return_poll_css($template_css, array("location" => $location)) . ' .yop-poll-forms-display{} ' . '</style>';
1498
 
1499
  }
1500
 
1501
 
1502
  $template .= '<div id="yop-poll-container-' . $this->ID . $unique_id . '" class="yop-poll-container">';
1503
+ if (!$msgDivS) {
1504
  $template .= '<div id="yop-poll-container-success-' . $this->ID . $unique_id . '" class="yop-poll-container-success"></div>';
1505
  }
1506
+ if (!$msgDivE) {
1507
  $template .= '<div id="yop-poll-container-error-' . $this->ID . $unique_id . '" class="yop-poll-container-error"></div>';
1508
  }
1509
 
1510
+ $template .= '<form id="yop-poll-form-' . $this->ID . $unique_id . '" class="yop-poll-forms yop-poll-forms-display">' . $temp . '<input type="hidden" id="yop-poll-tr-id-' . $this->ID . $unique_id . '" name="yop_poll_tr_id" value="' . $tr_id . '"/>' . wp_nonce_field('yop_poll-' . $this->ID . $unique_id . '-user-actions', 'yop-poll-nonce-' . $this->ID . $unique_id, false, false) . '</form></div>';
 
1511
 
1512
 
1513
  return $template;
1514
  }
1515
 
1516
+ public function captcha_replace_callback($m)
1517
+ {
1518
+ $unique_id = $this->unique_id;
1519
  $return_string = '';
1520
+ $temp_string = '';
1521
+
1522
+ if ('yes' == $this->use_captcha) {
1523
+ $sid = md5(uniqid());
1524
+ $temp_string = str_ireplace('%CAPTCHA-IMAGE%', '<img class="yop_poll_captcha_image" id="yop_poll_captcha_image_' . $this->ID . $unique_id . '" src="' . admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http')) . '?action=yop_poll_show_captcha&poll_id=' . $this->ID . '&sid=' . $sid . '&unique_id=' . $this->unique_id . '" />', $m[5]);
1525
+ $temp_string = str_ireplace('%CAPTCHA-INPUT%', '<input type="text" value="" name="yop_poll_captcha_input[' . $this->ID . ']" id="yop-poll-captcha-input-' . $this->ID . $unique_id . '" />', $temp_string);
1526
+ $temp_string = str_ireplace('%RELOAD-CAPTCHA-IMAGE%', '<a href="javascript:void(0)"><img src="' . YOP_POLL_URL . 'images/captcha_reload.png' . '" alt="' . __('Reload', 'yop_poll') . '" onClick="yop_poll_reloadCaptcha(' . "'" . $this->ID . "', '" . $this->unique_id . "'" . ')" /></a>', $temp_string);
1527
+ $temp_string = str_ireplace('%CAPTCHA-LABEL%', "<br>" . __yop_poll('Enter the code'), $temp_string);
1528
+ $temp_string = str_ireplace('%CAPTCHA-PLAY%', '<object type="application/x-shockwave-flash" data="' . YOP_POLL_URL . 'captcha/securimage_play.swf?bgcol=#ffffff&amp;icon_file=' . YOP_POLL_URL . 'images/captcha-audio.gif&amp;audio_file=' . urlencode(admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http')) . '?action=yop_poll_play_captcha&poll_id=' . $this->ID . '&unique_id=' . $this->unique_id) . '" height="30" width="30">
1529
+ <param name="movie" value="' . YOP_POLL_URL . 'captcha/securimage_play.swf?bgcol=#ffffff&amp;icon_file=' . YOP_POLL_URL . 'images/captcha-audio.gif&amp;audio_file=' . urlencode(admin_url('admin-ajax.php', (is_ssl() ? 'https' : 'http')) . '?action=yop_poll_play_captcha&poll_id=' . $this->ID . '&unique_id=' . $this->unique_id) . '" />
1530
+ </object>', $temp_string);
1531
  }
1532
  $return_string .= $temp_string;
1533
 
readme.txt CHANGED
@@ -142,6 +142,10 @@ You can have only one question per poll. If you want to ask more than one questi
142
 
143
  == Changelog ==
144
 
 
 
 
 
145
  = 5.7.4 =
146
  * Fixed security issue. A big thank you to [g0blin Research](https://twitter.com/g0blinResearch) for his help in getting this issue fixed
147
 
142
 
143
  == Changelog ==
144
 
145
+ = 5.7.5 =
146
+ * Fixed issue with vote button not showing up
147
+ * Other minor fixes
148
+
149
  = 5.7.4 =
150
  * Fixed security issue. A big thank you to [g0blin Research](https://twitter.com/g0blinResearch) for his help in getting this issue fixed
151
 
templates/polls_add_edit_template.html CHANGED
@@ -62,7 +62,7 @@
62
  {% endif %}
63
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
64
 
65
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}' >
66
  <p>
67
  {{ __('Green v4 Pro')}}
68
  </p><br>
@@ -70,7 +70,7 @@
70
  </li>
71
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
72
 
73
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}' >
74
  <p>
75
  {{ __('Red Pro')}}
76
  </p><br>
@@ -78,7 +78,7 @@
78
  </li>
79
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
80
 
81
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}'>
82
  <p>
83
  {{ __('Green v1 Pro')}}
84
  </p><br>
@@ -86,7 +86,7 @@
86
  </li>
87
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
88
 
89
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}'>
90
  <p>
91
  {{ __('Orange v1 Pro')}}
92
  </p><br>
@@ -94,7 +94,7 @@
94
  </li>
95
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
96
 
97
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}'>
98
  <p>
99
  {{ __('Dark Pro')}}
100
  </p><br>
@@ -102,7 +102,7 @@
102
  </li>
103
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
104
 
105
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}'>
106
  <p>
107
  {{ __('Grey v3 Pro')}}
108
  </p><br>
@@ -110,7 +110,7 @@
110
  </li>
111
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
112
 
113
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}'>
114
  <p>
115
  {{ __('Grey v2 Pro')}}
116
  </p><br>
@@ -118,7 +118,7 @@
118
  </li>
119
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
120
 
121
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}'>
122
  <p>
123
  {{ __('Grey v1 Pro')}}
124
  </p><br>
@@ -126,7 +126,7 @@
126
  </li>
127
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
128
 
129
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}'>
130
  <p>
131
  {{ __('Grey Pro')}}
132
  </p><br>
@@ -134,7 +134,7 @@
134
  </li>
135
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
136
 
137
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}'>
138
  <p>
139
  {{ __('Blue v3 Pro')}}
140
  </p><br>
@@ -142,7 +142,7 @@
142
  </li>
143
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
144
 
145
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}'>
146
  <p>
147
  {{ __('Blue v2 Pro')}}
148
  </p><br>
@@ -150,7 +150,7 @@
150
  </li>
151
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
152
 
153
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}'>
154
  <p>
155
  {{ __('Blue v1 Pro')}}
156
  </p><br>
@@ -158,7 +158,7 @@
158
  </li>
159
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
160
 
161
- class='yop_poll_tooltip-buy_pro yop-poll-page-template-li {% if current_poll.template == template.id %} yop-poll-page-template-selected {% endif%}' >
162
  <p>
163
  {{ __('White Pro')}}
164
  </p><br>
@@ -222,9 +222,32 @@
222
  <div class="yop-poll-widget-slider" id="yop-poll-widget-template-slider">
223
 
224
  <ul>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
226
 
227
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}' >
228
  <p>
229
  {{ __('Red Pro')}}
230
  </p><br>
@@ -232,7 +255,7 @@
232
  </li>
233
  <li id="yop-poll-page-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
234
 
235
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}' >
236
  <p>
237
  {{ __('Green v1 Pro')}}
238
  </p><br>
@@ -240,7 +263,7 @@
240
  </li>
241
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
242
 
243
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}'>
244
  <p>
245
  {{ __('Orange v1 Pro')}}
246
  </p><br>
@@ -248,7 +271,7 @@
248
  </li>
249
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
250
 
251
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}'>
252
  <p>
253
  {{ __('Dark Pro')}}
254
  </p><br>
@@ -256,7 +279,7 @@
256
  </li>
257
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
258
 
259
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}'>
260
  <p>
261
  {{ __('Grey v3 Pro')}}
262
  </p><br>
@@ -264,7 +287,7 @@
264
  </li>
265
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
266
 
267
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}'>
268
  <p>
269
  {{ __('Grey v2 Pro')}}
270
  </p><br>
@@ -272,7 +295,7 @@
272
  </li>
273
  <li id="yop-poll-page-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
274
 
275
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}'>
276
  <p>
277
  {{ __('Grey v1 Pro')}}
278
  </p><br>
@@ -280,7 +303,7 @@
280
  </li>
281
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
282
 
283
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}'>
284
  <p>
285
  {{ __('Grey Pro')}}
286
  </p><br>
@@ -289,7 +312,7 @@
289
 
290
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
291
 
292
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}'>
293
  <p>
294
  {{ __('Blue v3 Pro')}}
295
  </p><br>
@@ -297,7 +320,7 @@
297
  </li>
298
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
299
 
300
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}'>
301
  <p>
302
  {{ __('Blue v2 Pro')}}
303
  </p><br>
@@ -305,7 +328,7 @@
305
  </li>
306
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
307
 
308
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}'>
309
  <p>
310
  {{ __('Blue v1 Pro')}}
311
  </p><br>
@@ -314,7 +337,7 @@
314
 
315
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
316
 
317
- class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li {% if current_poll.template == template.id %} yop-poll-widget-template-selected {% endif%}'>
318
  <p>
319
  {{ __('White Pro')}}
320
  </p><br>
@@ -328,29 +351,7 @@
328
 
329
 
330
 
331
- {% if count( templates ) > 0 %}
332
-
333
- {% set i = 0 %}
334
-
335
- {% for template in templates %}
336
-
337
- <li id="yop-poll-widget-template-{{template.id}}" style="cursor: pointer;margin-left:4px;margin-right:4px"
338
-
339
- class='yop-poll-widget-template-li {% if current_poll.widget_template == template.id %} yop-poll-widget-template-selected {% endif%}'
340
-
341
- onclick="yop_poll_select_template({{template.id}}, 'widget')">
342
 
343
- <p>{{template.name|e}}</p> <br>
344
-
345
- {{template.preview|raw}}
346
-
347
- </li>
348
-
349
- {% set i = i+1 %}
350
-
351
- {% endfor %}
352
-
353
- {% endif %}
354
 
355
  </ul>
356
 
62
  {% endif %}
63
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
64
 
65
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy' >
66
  <p>
67
  {{ __('Green v4 Pro')}}
68
  </p><br>
70
  </li>
71
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
72
 
73
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy' >
74
  <p>
75
  {{ __('Red Pro')}}
76
  </p><br>
78
  </li>
79
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
80
 
81
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy'>
82
  <p>
83
  {{ __('Green v1 Pro')}}
84
  </p><br>
86
  </li>
87
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
88
 
89
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy'>
90
  <p>
91
  {{ __('Orange v1 Pro')}}
92
  </p><br>
94
  </li>
95
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
96
 
97
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy'>
98
  <p>
99
  {{ __('Dark Pro')}}
100
  </p><br>
102
  </li>
103
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
104
 
105
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy'>
106
  <p>
107
  {{ __('Grey v3 Pro')}}
108
  </p><br>
110
  </li>
111
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
112
 
113
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy'>
114
  <p>
115
  {{ __('Grey v2 Pro')}}
116
  </p><br>
118
  </li>
119
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
120
 
121
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy'>
122
  <p>
123
  {{ __('Grey v1 Pro')}}
124
  </p><br>
126
  </li>
127
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
128
 
129
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy'>
130
  <p>
131
  {{ __('Grey Pro')}}
132
  </p><br>
134
  </li>
135
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
136
 
137
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy'>
138
  <p>
139
  {{ __('Blue v3 Pro')}}
140
  </p><br>
142
  </li>
143
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
144
 
145
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy'>
146
  <p>
147
  {{ __('Blue v2 Pro')}}
148
  </p><br>
150
  </li>
151
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
152
 
153
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy'>
154
  <p>
155
  {{ __('Blue v1 Pro')}}
156
  </p><br>
158
  </li>
159
  <li id="yop-poll-1"style="cursor: pointer;margin-left:2px;margin-right:2px"
160
 
161
+ class='yop_poll_tooltip-buy_pro yop-poll-page-template-li yop-poll-page-template-buy' >
162
  <p>
163
  {{ __('White Pro')}}
164
  </p><br>
222
  <div class="yop-poll-widget-slider" id="yop-poll-widget-template-slider">
223
 
224
  <ul>
225
+ {% if count( templates ) > 0 %}
226
+
227
+ {% set i = 0 %}
228
+
229
+ {% for template in templates %}
230
+
231
+ <li id="yop-poll-widget-template-{{template.id}}" style="cursor: pointer;margin-left:4px;margin-right:4px"
232
+
233
+ class='yop-poll-widget-template-li {% if current_poll.widget_template == template.id %} yop-poll-widget-template-selected {% endif%}'
234
+
235
+ onclick="yop_poll_select_template({{template.id}}, 'widget')">
236
+
237
+ <p>{{template.name|e}}</p> <br>
238
+
239
+ {{template.preview|raw}}
240
+
241
+ </li>
242
+
243
+ {% set i = i+1 %}
244
+
245
+ {% endfor %}
246
+
247
+ {% endif %}
248
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
249
 
250
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy' >
251
  <p>
252
  {{ __('Red Pro')}}
253
  </p><br>
255
  </li>
256
  <li id="yop-poll-page-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
257
 
258
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy' >
259
  <p>
260
  {{ __('Green v1 Pro')}}
261
  </p><br>
263
  </li>
264
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
265
 
266
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy'>
267
  <p>
268
  {{ __('Orange v1 Pro')}}
269
  </p><br>
271
  </li>
272
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
273
 
274
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy'>
275
  <p>
276
  {{ __('Dark Pro')}}
277
  </p><br>
279
  </li>
280
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
281
 
282
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy'>
283
  <p>
284
  {{ __('Grey v3 Pro')}}
285
  </p><br>
287
  </li>
288
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
289
 
290
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy'>
291
  <p>
292
  {{ __('Grey v2 Pro')}}
293
  </p><br>
295
  </li>
296
  <li id="yop-poll-page-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
297
 
298
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy'>
299
  <p>
300
  {{ __('Grey v1 Pro')}}
301
  </p><br>
303
  </li>
304
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
305
 
306
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy'>
307
  <p>
308
  {{ __('Grey Pro')}}
309
  </p><br>
312
 
313
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
314
 
315
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy'>
316
  <p>
317
  {{ __('Blue v3 Pro')}}
318
  </p><br>
320
  </li>
321
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
322
 
323
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy'>
324
  <p>
325
  {{ __('Blue v2 Pro')}}
326
  </p><br>
328
  </li>
329
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
330
 
331
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy'>
332
  <p>
333
  {{ __('Blue v1 Pro')}}
334
  </p><br>
337
 
338
  <li id="yop-poll-widget-template-{{template.id}}"style="cursor: pointer;margin-left:2px;margin-right:2px"
339
 
340
+ class='yop_poll_tooltip-buy_pro yop-poll-widget-template-li yop-poll-widget-template-buy'>
341
  <p>
342
  {{ __('White Pro')}}
343
  </p><br>
351
 
352
 
353
 
 
 
 
 
 
 
 
 
 
 
 
354
 
 
 
 
 
 
 
 
 
 
 
 
355
 
356
  </ul>
357
 
yop_poll.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: YOP Poll
5
  * Plugin URI: http://www.yop-poll.com
6
  * Description: Use a full option polling functionality to get the answers you need. YOP Poll is the perfect, easy to use poll plugin for your WordPress website.
7
- * Version: 5.7.4
8
  * Author: yourownprogrammer
9
  * Author URI: http://www.yop-poll.com
10
  * License: GPLv2 or later
@@ -14,7 +14,7 @@ if (!(version_compare(phpversion(), '5.3', '<'))) {
14
 
15
  define ( 'YOP_POLL_DOMAIN', 'yop_poll' );
16
  define ( 'YOP_POLL_WP_VERSION', '3.3' );
17
- define ( 'YOP_POLL_VERSION', '5.7.4' );
18
  define ( 'YOP_POLL_PATH', plugin_dir_path( __FILE__ ) ); ///home/..../wp-content/plugins/yop-poll-2.0/
19
  define ( 'YOP_POLL_URL', plugin_dir_url( __FILE__ ) ); //http://your-domain/wp-content/plugins/yop-poll-2.0/
20
  define ( 'YOP_POLL_PLUGIN_FILE', __FILE__ ); ///home/..../wp-content/plugins/yop-poll-2.0/yop-poll-2.0.php
4
  * Plugin Name: YOP Poll
5
  * Plugin URI: http://www.yop-poll.com
6
  * Description: Use a full option polling functionality to get the answers you need. YOP Poll is the perfect, easy to use poll plugin for your WordPress website.
7
+ * Version: 5.7.5
8
  * Author: yourownprogrammer
9
  * Author URI: http://www.yop-poll.com
10
  * License: GPLv2 or later
14
 
15
  define ( 'YOP_POLL_DOMAIN', 'yop_poll' );
16
  define ( 'YOP_POLL_WP_VERSION', '3.3' );
17
+ define ( 'YOP_POLL_VERSION', '5.7.5' );
18
  define ( 'YOP_POLL_PATH', plugin_dir_path( __FILE__ ) ); ///home/..../wp-content/plugins/yop-poll-2.0/
19
  define ( 'YOP_POLL_URL', plugin_dir_url( __FILE__ ) ); //http://your-domain/wp-content/plugins/yop-poll-2.0/
20
  define ( 'YOP_POLL_PLUGIN_FILE', __FILE__ ); ///home/..../wp-content/plugins/yop-poll-2.0/yop-poll-2.0.php