PluginProbe
Crowdsignal Dashboard – Polls, Surveys & more / 3.1.5
Crowdsignal Dashboard – Polls, Surveys & more v3.1.5
3.1.8 3.1.7 trunk 0.8 0.9 1.0 1.2 1.3 1.4 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 All 97 releases
polldaddy / rating.php

rating.php in Crowdsignal Dashboard – Polls, Surveys & more 3.1.5, at rating.php

160 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( function_exists( 'get_option' ) == false )
4 die( "Cheatin' eh?" );
5
6 function polldaddy_show_rating_comments( $content, $comment = 0, $args = 0 ) {
7 if ( is_numeric( $comment ) && $comment == 0 )
8 return $content;
9
10 if ( !is_feed() && !defined( 'DOING_AJAX' ) ) {
11 global $post;
12
13 if ( isset( $comment->comment_ID ) && $comment->comment_ID > 0 ) {
14 $unique_id = '';
15 $title = '';
16 $permalink = '';
17 $html = '';
18 $rating_pos = 0;
19
20 if ( (int) get_option( 'pd-rating-comments' ) > 0 ) {
21 $rating_id = (int) get_option( 'pd-rating-comments' );
22 $unique_id = 'wp-comment-' . $comment->comment_ID;
23 $rating_pos = (int) get_option( 'pd-rating-comments-pos' );
24 $title = mb_substr( preg_replace( '/[\x00-\x1F\x80-\xFF]/', '', $comment->comment_content ), 0, 195 ) . '';
25 $permalink = get_permalink( $post->ID ) . '#comment-' . $comment->comment_ID;
26 $html = polldaddy_get_rating_code( $rating_id, $unique_id, $title, $permalink, '_comm_' . $comment->comment_ID );
27
28 if ( $rating_pos == 0 )
29 $content = $html . '<br/>' . $content;
30 else
31 $content .= $html;
32 }
33 }
34 }
35 return $content;
36 }
37
38 function polldaddy_show_rating( $content ) {
39 global $wp_current_filter;
40 if ( !in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) {
41 if ( !is_feed() && !is_attachment() ) {
42 if ( is_single() || is_page() || is_home() || is_archive() || is_search() || is_category() ) {
43 $html = polldaddy_get_rating_html( 'check-options' );
44
45 if ( !empty( $html ) ) {
46 $rating_pos = 0;
47
48 if ( is_page() ) {
49 $rating_pos = (int) get_option( 'pd-rating-pages-pos' );
50 } elseif ( is_home() || is_archive() || is_search() || is_category() ) {
51 $rating_pos = (int) get_option( 'pd-rating-posts-index-pos' );
52 } else {
53 $rating_pos = (int) get_option( 'pd-rating-posts-pos' );
54 }
55
56 if ( $rating_pos == 0 )
57 $content = $html . "\n" . $content;
58 else
59 $content .= $html;
60 }
61 }
62 }
63 }
64 return $content;
65 }
66
67 function polldaddy_get_rating_html( $condition = '' ) {
68 global $post;
69 $html = '';
70
71 if ( $post->ID > 0 ) {
72 $unique_id = '';
73 $title = '';
74 $permalink = '';
75 $rating_id = 0;
76 $item_id = '';
77 $exclude_posts = explode( ',', get_option( 'pd-rating-exclude-post-ids' ) );
78 $exclude_pages = explode( ',', get_option( 'pd-rating-exclude-page-ids' ) );
79
80 if ( is_page() ) {
81 if ( !in_array( $post->ID, $exclude_pages ) ) {
82 $unique_id = 'wp-page-' . $post->ID;
83 $item_id = '_page_' . $post->ID;
84 if ( $condition == 'check-options' ) {
85 if ( (int) get_option( 'pd-rating-pages' ) > 0 ) {
86 $rating_id = (int) get_option( 'pd-rating-pages-id' );
87 }
88 } else {
89 $rating_id = (int) get_option( 'pd-rating-pages-id' );
90 }
91 }
92 } elseif ( !in_array( $post->ID, $exclude_posts ) ) {
93 $unique_id = 'wp-post-' . $post->ID;
94 $item_id = '_post_' . $post->ID;
95 if ( is_home() || is_archive() || is_search() || is_category() ) {
96 if ( $condition == 'check-options' ) {
97 if ( (int) get_option( 'pd-rating-posts-index' ) > 0 ) {
98 $rating_id = (int) get_option( 'pd-rating-posts-id' );
99 }
100 } else {
101 $rating_id = (int) get_option( 'pd-rating-posts-id' );
102 }
103 } else {
104 if ( $condition == 'check-options' ) {
105 if ( (int) get_option( 'pd-rating-posts' ) > 0 ) {
106 $rating_id = (int) get_option( 'pd-rating-posts-id' );
107 }
108 } else {
109 $rating_id = (int) get_option( 'pd-rating-posts-id' );
110 }
111 }
112 }
113
114 if ( $rating_id > 0 ) {
115 if ( defined( 'CS_RATING_TITLE_FILTER' ) ) {
116 if ( strlen( constant( 'CS_RATING_TITLE_FILTER' ) ) > 0 ) {
117 $title = apply_filters( constant( 'CS_RATING_TITLE_FILTER' ), $post->post_title, $post->ID, '' );
118 } else {
119 $title = $post->post_title;
120 }
121 } else {
122 $title = apply_filters( 'the_title', $post->post_title, $post->ID, '' );
123 }
124
125 $permalink = get_permalink( $post->ID );
126 $html = polldaddy_get_rating_code( $rating_id, $unique_id, $title, $permalink, $item_id );
127 }
128 }
129 return $html;
130 }
131
132 /**
133 * Construct a Polldaddy target div for a given rating_id and optional item_id
134 * Define a Polldaddy ratings variable for a given rating_id and optional item_id
135 *
136 * @param int $rating_id
137 * @param string $unique_id
138 * @param string $title Post title
139 * @param string $permalink Post permalink
140 * @param string $item_id
141 * @return HTML snippet with a ratings container and a related JS block defining a new variable
142 */
143 function polldaddy_get_rating_code( $rating_id, $unique_id, $title, $permalink, $item_id = '' ) {
144 $html = sprintf( '[polldaddy rating="%d" item_id="%s" unique_id="%s" title="%s" permalink="%s"]', absint( $rating_id ), polldaddy_sanitize_shortcode( $item_id ), polldaddy_sanitize_shortcode( $unique_id ), polldaddy_sanitize_shortcode( $title ), polldaddy_sanitize_shortcode( $permalink ) );
145 return do_shortcode( $html );
146 }
147
148 function polldaddy_sanitize_shortcode( $text ) {
149 $text = preg_replace( array( '/\[/', '/\]/' ), array( '&#91;', '&#93;' ), $text );
150 return esc_attr( $text );
151 }
152
153 if ( (int) get_option( 'pd-rating-pages' ) > 0 || (int) get_option( 'pd-rating-posts-index' ) > 0 || (int) get_option( 'pd-rating-posts' ) > 0 ) {
154 add_filter( 'the_content', 'polldaddy_show_rating', 5 );
155 add_filter( 'the_excerpt', 'polldaddy_show_rating' );
156 }
157
158 add_filter( 'comment_text', 'polldaddy_show_rating_comments', 50, 3 );
159 ?>
160