| 1 |
<?php |
| 2 |
/** |
| 3 |
* The public-facing functionality of the plugin. |
| 4 |
* |
| 5 |
* @link http://ays-pro.com/ |
| 6 |
* @since 1.0.0 |
| 7 |
* |
| 8 |
* @package Poll_Maker |
| 9 |
* @subpackage Poll_Maker/includes |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* The public-facing functionality of the plugin. |
| 14 |
* |
| 15 |
* Defines the plugin name, version, and two examples hooks for how to |
| 16 |
* enqueue the public-facing stylesheet and JavaScript. |
| 17 |
* |
| 18 |
* @package Poll_Maker |
| 19 |
* @subpackage Poll_Maker/includes |
| 20 |
* @author AYS Pro LLC <info@ays-pro.com> |
| 21 |
*/ |
| 22 |
class Poll_Maker_Data { |
| 23 |
|
| 24 |
// Retrieves the attachment ID from the file URL |
| 25 |
public static function ays_poll_get_image_id_by_url( $image_url ) { |
| 26 |
global $wpdb; |
| 27 |
|
| 28 |
$image_alt_text = ""; |
| 29 |
if ( !empty( $image_url ) ) { |
| 30 |
|
| 31 |
$re = '/-\d+[Xx]\d+\./'; |
| 32 |
$subst = '.'; |
| 33 |
|
| 34 |
$image_url = preg_replace($re, $subst, $image_url, 1); |
| 35 |
|
| 36 |
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url )); |
| 37 |
if ( !is_null( $attachment ) && !empty( $attachment ) ) { |
| 38 |
|
| 39 |
$image_id = (isset( $attachment[0] ) && $attachment[0] != "") ? absint( $attachment[0] ) : ""; |
| 40 |
if ( $image_id != "" ) { |
| 41 |
$image_alt_text = self::ays_poll_get_image_alt_text_by_id( $image_id ); |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
return $image_alt_text; |
| 47 |
} |
| 48 |
|
| 49 |
public static function ays_poll_get_image_alt_text_by_id( $image_id ) { |
| 50 |
|
| 51 |
$image_data = ""; |
| 52 |
if ( $image_id != "" ) { |
| 53 |
|
| 54 |
$result = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE); |
| 55 |
if ( $result && $result != "" ) { |
| 56 |
$image_data = esc_attr( $result ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
return $image_data; |
| 61 |
} |
| 62 |
|
| 63 |
public static function ays_poll_autoembed( $content ) { |
| 64 |
global $wp_embed; |
| 65 |
$content = stripslashes( wpautop( $content ) ); |
| 66 |
$content = $wp_embed->autoembed( $content ); |
| 67 |
if ( strpos( $content, '[embed]' ) !== false ) { |
| 68 |
$content = $wp_embed->run_shortcode( $content ); |
| 69 |
} |
| 70 |
$content = do_shortcode( $content ); |
| 71 |
return $content; |
| 72 |
} |
| 73 |
|
| 74 |
public static function ays_poll_is_elementor(){ |
| 75 |
if( isset( $_GET['action'] ) && $_GET['action'] == 'elementor' ){ |
| 76 |
$is_elementor = true; |
| 77 |
}elseif( isset( $_REQUEST['elementor-preview'] ) && $_REQUEST['elementor-preview'] != '' ){ |
| 78 |
$is_elementor = true; |
| 79 |
}else{ |
| 80 |
$is_elementor = false; |
| 81 |
} |
| 82 |
|
| 83 |
if ( ! $is_elementor ) { |
| 84 |
$is_elementor = ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ? true : false; |
| 85 |
} |
| 86 |
|
| 87 |
return $is_elementor; |
| 88 |
} |
| 89 |
|
| 90 |
public static function ays_poll_is_editor(){ |
| 91 |
$is_editor = false; |
| 92 |
if( isset( $_GET['action'] ) && ( $_GET['action'] == 'add' || $_GET['action'] == 'edit' ) ){ |
| 93 |
if ( isset( $_GET['post'] ) && absint( $_GET['post'] ) > 0 ) { |
| 94 |
$is_editor = true; |
| 95 |
} |
| 96 |
} elseif ( isset( $_GET['context'] ) && ( $_GET['context'] == 'add' || $_GET['context'] == 'edit' ) ) { |
| 97 |
if( isset( $_GET['post_id'] ) & absint( $_GET['post_id'] ) > 0 ){ |
| 98 |
$is_editor = true; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
return $is_editor; |
| 103 |
} |
| 104 |
|
| 105 |
public static function get_user_passed_polls_count( $user_id ){ |
| 106 |
global $wpdb; |
| 107 |
|
| 108 |
if (is_null($user_id) || $user_id == 0 ) { |
| 109 |
return null; |
| 110 |
} |
| 111 |
|
| 112 |
$user_id = absint( $user_id ); |
| 113 |
|
| 114 |
$reports_table = esc_sql($wpdb->prefix."ayspoll_reports"); |
| 115 |
$answ_table = esc_sql($wpdb->prefix."ayspoll_answers"); |
| 116 |
$polls_table = esc_sql($wpdb->prefix."ayspoll_polls"); |
| 117 |
|
| 118 |
$sql = "SELECT COUNT(*) FROM {$reports_table} AS r |
| 119 |
JOIN {$answ_table} AS a |
| 120 |
ON a.id = r.answer_id |
| 121 |
JOIN {$polls_table} AS p |
| 122 |
ON a.poll_id = p.id |
| 123 |
WHERE r.user_id = ".$user_id; |
| 124 |
|
| 125 |
$results = $wpdb->get_var($sql); |
| 126 |
|
| 127 |
if ( ! empty( $results ) ) { |
| 128 |
$results = absint( $results ); |
| 129 |
} else { |
| 130 |
$results = 0; |
| 131 |
} |
| 132 |
|
| 133 |
return $results; |
| 134 |
} |
| 135 |
|
| 136 |
public static function get_all_polls(){ |
| 137 |
global $wpdb; |
| 138 |
$polls_table = $wpdb->prefix."ayspoll_polls"; |
| 139 |
$sql = "SELECT id,title FROM ".$polls_table; |
| 140 |
$result = $wpdb->get_results($sql , "ARRAY_A"); |
| 141 |
return $result; |
| 142 |
} |
| 143 |
|
| 144 |
public static function check_user_capability(){ |
| 145 |
return current_user_can( 'manage_options' ) && is_user_logged_in(); |
| 146 |
} |
| 147 |
|
| 148 |
public static function ays_poll_allowed_html() { |
| 149 |
$additionalAllowedTags = wp_kses_allowed_html('post'); |
| 150 |
return array_merge( |
| 151 |
$additionalAllowedTags, |
| 152 |
array( |
| 153 |
'div' => array( |
| 154 |
'class' => true, |
| 155 |
'id' => true, |
| 156 |
'style' => true, |
| 157 |
'data-*' => true, |
| 158 |
'aria-selected' => true, |
| 159 |
), |
| 160 |
'svg' => array( |
| 161 |
'class' => true, |
| 162 |
'width' => true, |
| 163 |
'height' => true, |
| 164 |
'viewBox' => true, |
| 165 |
'viewbox' => true, |
| 166 |
'xmlns' => true, |
| 167 |
'fill' => true, |
| 168 |
), |
| 169 |
'path' => array( |
| 170 |
'class' => true, |
| 171 |
'd' => true, |
| 172 |
'fill' => true, |
| 173 |
'fill-rule' => true, |
| 174 |
'clip-rule' => true, |
| 175 |
'stroke-width' => true, |
| 176 |
'stroke-linecap' => true, |
| 177 |
), |
| 178 |
'circle' => array( |
| 179 |
'style' => true, |
| 180 |
'id' => true, |
| 181 |
'class' => true, |
| 182 |
'r' => true, |
| 183 |
'cx' => true, |
| 184 |
'cy' => true, |
| 185 |
), |
| 186 |
'rect' => array( |
| 187 |
'class' => true, |
| 188 |
'x' => true, |
| 189 |
'y' => true, |
| 190 |
'width' => true, |
| 191 |
'height' => true, |
| 192 |
'rx' => true, |
| 193 |
'fill' => true, |
| 194 |
'stroke' => true, |
| 195 |
'style' => true, |
| 196 |
'transform' => true, |
| 197 |
), |
| 198 |
'defs' => array( |
| 199 |
'class' => true, |
| 200 |
'width' => true, |
| 201 |
'height' => true, |
| 202 |
'fill' => true, |
| 203 |
'style' => true, |
| 204 |
), |
| 205 |
'pattern' => array( |
| 206 |
'class' => true, |
| 207 |
'id' => true, |
| 208 |
'width' => true, |
| 209 |
'height' => true, |
| 210 |
'patternContentUnits' => true, |
| 211 |
'patterncontentunits' => true, |
| 212 |
'style' => true, |
| 213 |
), |
| 214 |
'use' => array( |
| 215 |
'class' => true, |
| 216 |
'id' => true, |
| 217 |
'xlink' => true, |
| 218 |
'xlink:href' => true, |
| 219 |
'transform' => true, |
| 220 |
'style' => true, |
| 221 |
), |
| 222 |
'image' => array( |
| 223 |
'class' => true, |
| 224 |
'id' => true, |
| 225 |
'xlink' => true, |
| 226 |
'xlink:href' => true, |
| 227 |
'width' => true, |
| 228 |
'height' => true, |
| 229 |
'style' => true, |
| 230 |
), |
| 231 |
'video' => array( |
| 232 |
'class' => true, |
| 233 |
'id' => true, |
| 234 |
'controls' => true, |
| 235 |
'style' => true, |
| 236 |
), |
| 237 |
'source' => array( |
| 238 |
'class' => true, |
| 239 |
'id' => true, |
| 240 |
'src' => true, |
| 241 |
'style' => true, |
| 242 |
), |
| 243 |
'form' => array( |
| 244 |
'name' => true, |
| 245 |
'id' => true, |
| 246 |
'action' => true, |
| 247 |
'method' => true, |
| 248 |
'data-*' => true, |
| 249 |
'style' => true, |
| 250 |
), |
| 251 |
'input' => array( |
| 252 |
'id' => true, |
| 253 |
'name' => true, |
| 254 |
'class' => true, |
| 255 |
'type' => true, |
| 256 |
'value' => true, |
| 257 |
'size' => true, |
| 258 |
'required' => true, |
| 259 |
'readonly' => true, |
| 260 |
'data-*' => true, |
| 261 |
'style' => true, |
| 262 |
), |
| 263 |
'select' => array( |
| 264 |
'id' => true, |
| 265 |
'name' => true, |
| 266 |
'class' => true, |
| 267 |
'type' => true, |
| 268 |
'value' => true, |
| 269 |
'size' => true, |
| 270 |
'required' => true, |
| 271 |
'readonly' => true, |
| 272 |
'data-*' => true, |
| 273 |
'style' => true, |
| 274 |
), |
| 275 |
'option' => array( |
| 276 |
'id' => true, |
| 277 |
'class' => true, |
| 278 |
'type' => true, |
| 279 |
'value' => true, |
| 280 |
'size' => true, |
| 281 |
'required' => true, |
| 282 |
'readonly' => true, |
| 283 |
'data-*' => true, |
| 284 |
'style' => true, |
| 285 |
), |
| 286 |
'progress' => array( |
| 287 |
'id' => true, |
| 288 |
'class' => true, |
| 289 |
'max' => true, |
| 290 |
'value' => true, |
| 291 |
'data-*' => true, |
| 292 |
'style' => true, |
| 293 |
), |
| 294 |
'img' => array( |
| 295 |
'id' => true, |
| 296 |
'class' => true, |
| 297 |
'loading' => true, |
| 298 |
'decoding' => true, |
| 299 |
'src' => true, |
| 300 |
'sizes' => true, |
| 301 |
'srcset' => true, |
| 302 |
'width' => true, |
| 303 |
'height' => true, |
| 304 |
), |
| 305 |
'a' => array( |
| 306 |
'aria-selected' => true, |
| 307 |
'data-*' => true, |
| 308 |
'style' => true, |
| 309 |
'target' => true, |
| 310 |
), |
| 311 |
), |
| 312 |
$additionalAllowedTags |
| 313 |
); |
| 314 |
} |
| 315 |
|
| 316 |
public static function ays_poll_custom_allowed_html() { |
| 317 |
$additionalAllowedTags = self::ays_poll_allowed_html(); |
| 318 |
return array_merge( |
| 319 |
$additionalAllowedTags, |
| 320 |
array( |
| 321 |
'iframe' => array( |
| 322 |
'class' => true, |
| 323 |
'id' => true, |
| 324 |
'width' => true, |
| 325 |
'height' => true, |
| 326 |
'src' => true, |
| 327 |
'title' => true, |
| 328 |
'frameborder' => true, |
| 329 |
'allow' => true, |
| 330 |
'allowfullscreen' => true, |
| 331 |
'loading' => true, |
| 332 |
'referrerpolicy' => true, |
| 333 |
'style' => true, |
| 334 |
), |
| 335 |
'audio' => array( |
| 336 |
'class' => true, |
| 337 |
'id' => true, |
| 338 |
'controls' => true, |
| 339 |
'autoplay' => true, |
| 340 |
'loop' => true, |
| 341 |
'muted' => true, |
| 342 |
'preload' => true, |
| 343 |
'src' => true, |
| 344 |
'style' => true, |
| 345 |
), |
| 346 |
'source' => array( |
| 347 |
'src' => true, |
| 348 |
'type' => true, |
| 349 |
), |
| 350 |
'track' => array( |
| 351 |
'kind' => true, |
| 352 |
'src' => true, |
| 353 |
'srclang' => true, |
| 354 |
'label' => true, |
| 355 |
'default' => true, |
| 356 |
), |
| 357 |
'video' => array( |
| 358 |
'class' => true, |
| 359 |
'id' => true, |
| 360 |
'width' => true, |
| 361 |
'height' => true, |
| 362 |
'controls' => true, |
| 363 |
'autoplay' => true, |
| 364 |
'loop' => true, |
| 365 |
'muted' => true, |
| 366 |
'poster' => true, |
| 367 |
'preload' => true, |
| 368 |
'src' => true, |
| 369 |
'style' => true, |
| 370 |
), |
| 371 |
'picture' => array( |
| 372 |
'class' => true, |
| 373 |
'id' => true, |
| 374 |
), |
| 375 |
'figure' => array( |
| 376 |
'class' => true, |
| 377 |
'id' => true, |
| 378 |
'style' => true, |
| 379 |
), |
| 380 |
'figcaption' => array( |
| 381 |
'class' => true, |
| 382 |
'id' => true, |
| 383 |
'style' => true, |
| 384 |
), |
| 385 |
), |
| 386 |
$additionalAllowedTags |
| 387 |
); |
| 388 |
} |
| 389 |
} |