PluginProbe
Parse.ly / 3.8.4
Parse.ly v3.8.4
3.24.2 3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 All 106 releases
← All changes | src/UI/class-recommended-widget.php +64 -7 3.16.4 → 3.8.4 View file →
@@ -26,8 +26,9 @@
26 26 * return_limit: int,
27 27 * display_direction: string,
28 28 * published_within: int,
29 29 * sort: string,
30 + * boost: string,
30 31 * personalize_results: bool,
31 32 * img_src: string,
32 33 * display_author: bool,
33 34 * }
@@ -50,8 +51,9 @@
50 51 'return_limit' => 5,
51 52 'display_direction' => 'vertical',
52 53 'published_within' => 0,
53 54 'sort' => 'score',
55 + 'boost' => 'views',
54 56 'personalize_results' => false,
55 57 'img_src' => 'parsely_thumb',
56 58 'display_author' => false,
57 59 );
@@ -76,24 +78,26 @@
76 78
77 79 /**
78 80 * Gets the URL for the Recommendations API (GET /related).
79 81 *
80 - * @since 2.5.0
82 + * @see https://www.parse.ly/help/api/recommendations#get-related
81 83 *
82 - * @see https://docs.parse.ly/content-recommendations/
84 + * @internal While this is a public method now, this should be moved to a new class.
83 85 *
84 - * @internal While this is a public method now, this should be moved to a new class.
86 + * @since 2.5.0
85 87 *
86 88 * @param string $site_id Publisher Site ID.
87 - * @param int|null $published_within Publication filter start date; see https://docs.parse.ly/api-date-time/ for
89 + * @param int|null $published_within Publication filter start date; see https://www.parse.ly/help/api/time for
88 90 * formatting details. No restriction by default.
89 91 * @param string|null $sort What to sort the results by. There are currently 2 valid options: `score`,
90 92 * which will sort articles by overall relevance and `pub_date` which will sort
91 93 * results by their publication date. The default is `score`.
94 + * @param string|null $boost Available for sort=score only. Sub-sort value to re-rank relevant posts that
95 + * received high e.g. views; default is undefined.
92 96 * @param int $return_limit Number of records to retrieve; defaults to "10".
93 97 * @return string API URL.
94 98 */
95 - private function get_api_url( string $site_id, ?int $published_within, ?string $sort, int $return_limit ): string {
99 + private function get_api_url( string $site_id, ?int $published_within, ?string $sort, ?string $boost, int $return_limit ): string {
96 100 $related_api_endpoint = Parsely::PUBLIC_API_BASE_URL . '/related';
97 101
98 102 $query_args = array(
99 103 'apikey' => $site_id,
@@ -100,8 +104,12 @@
100 104 'sort' => $sort,
101 105 'limit' => $return_limit,
102 106 );
103 107
108 + if ( 'score' === $sort && 'no-boost' !== $boost ) {
109 + $query_args['boost'] = $boost;
110 + }
111 +
104 112 if ( null !== $published_within && 0 !== $published_within ) {
105 113 $query_args['pub_date_start'] = $published_within . 'd';
106 114 }
107 115
@@ -136,8 +144,9 @@
136 144 $api_url = $this->get_api_url(
137 145 $this->parsely->get_site_id(),
138 146 (int) $instance['published_within'], // @phpstan-ignore-line
139 147 $instance['sort'],
148 + $instance['boost'],
140 149 (int) $instance['return_limit'] // @phpstan-ignore-line
141 150 );
142 151
143 152 ?>
@@ -204,8 +213,9 @@
204 213 $return_limit = $instance['return_limit'];
205 214 $display_direction = $instance['display_direction'];
206 215 $published_within = $instance['published_within'];
207 216 $sort = $instance['sort'];
217 + $boost = $instance['boost'];
208 218 $personalize_results = $instance['personalize_results'];
209 219 $img_src = $instance['img_src'];
210 220 $display_author = $instance['display_author'];
211 221
@@ -212,12 +222,14 @@
212 222 $instance['return_limit'] = $return_limit;
213 223 $instance['display_direction'] = $display_direction;
214 224 $instance['published_within'] = $published_within;
215 225 $instance['sort'] = $sort;
226 + $instance['boost'] = $boost;
216 227 $instance['personalize_results'] = $personalize_results;
217 228 $instance['img_src'] = $img_src;
218 229 $instance['display_author'] = $display_author;
219 230
231 + $boost_params = $this->get_boost_params();
220 232 ?>
221 233 <p>
222 234 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'wp-parsely' ); ?></label>
223 235 <br>
@@ -248,13 +260,23 @@
248 260 <p>
249 261 <label for="<?php echo esc_attr( $this->get_field_id( 'sort' ) ); ?>"><?php esc_html_e( 'Sort by:', 'wp-parsely' ); ?></label>
250 262 <br>
251 263 <select id="<?php echo esc_attr( $this->get_field_id( 'sort' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'sort' ) ); ?>" class="widefat">
252 - <option<?php selected( $instance['sort'], 'score' ); ?> value="score"><?php esc_html_e( 'Score', 'wp-parsely' ); ?></option>
253 - <option<?php selected( $instance['sort'], 'pub_date' ); ?> value="pub_date"><?php esc_html_e( 'Publish date', 'wp-parsely' ); ?></option>
264 + <option<?php selected( $instance['sort'], 'score' ); ?> value="score"><?php esc_html_e( 'Score (relevancy, boostable)', 'wp-parsely' ); ?></option>
265 + <option<?php selected( $instance['sort'], 'pub_date' ); ?> value="pub_date"><?php esc_html_e( 'Publish date (not boostable)', 'wp-parsely' ); ?></option>
254 266 </select>
255 267 </p>
256 268 <p>
269 + <label for="<?php echo esc_attr( $this->get_field_id( 'boost' ) ); ?>"><?php esc_html_e( 'Boost by:', 'wp-parsely' ); ?></label>
270 + <br>
271 + <select id="<?php echo esc_attr( $this->get_field_id( 'boost' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'boost' ) ); ?>" class="widefat">
272 + <?php foreach ( $boost_params as $boost_param => $description ) { ?>
273 + <option<?php selected( $instance['boost'], $boost_param ); ?> value="<?php echo esc_attr( $boost_param ); ?>"><?php echo esc_html( $description ); ?></option>
274 + <?php } ?>
275 + </select>
276 +
277 + </p>
278 + <p>
257 279 <label for="<?php echo esc_attr( $this->get_field_id( 'img_src' ) ); ?>"><?php esc_html_e( 'Image source:', 'wp-parsely' ); ?></label>
258 280 <br>
259 281 <select id="<?php echo esc_attr( $this->get_field_id( 'img_src' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'img_src' ) ); ?>" class="widefat">
260 282 <option<?php selected( $instance['img_src'], 'parsely_thumb' ); ?> value="parsely_thumb"><?php esc_html_e( 'Parse.ly generated thumbnail (85x85px)', 'wp-parsely' ); ?></option>
@@ -278,8 +300,9 @@
278 300 * This is the update function.
279 301 *
280 302 * @param Widget_Settings $new_instance The new values for the db.
281 303 * @param Widget_Settings $old_instance Values saved to the db.
304 + *
282 305 * @return Widget_Settings
283 306 */
284 307 public function update( $new_instance, $old_instance ) /* @phpstan-ignore-line */ {
285 308 $instance = $old_instance;
@@ -287,8 +310,9 @@
287 310 $instance['published_within'] = $new_instance['published_within'];
288 311 $instance['return_limit'] = $new_instance['return_limit'] <= 20 ? $new_instance['return_limit'] : 20;
289 312 $instance['display_direction'] = trim( $new_instance['display_direction'] );
290 313 $instance['sort'] = trim( $new_instance['sort'] );
314 + $instance['boost'] = trim( $new_instance['boost'] );
291 315 $instance['display_author'] = $new_instance['display_author'];
292 316 $instance['personalize_results'] = $new_instance['personalize_results'];
293 317 $instance['img_src'] = trim( $new_instance['img_src'] );
294 318
@@ -295,8 +319,40 @@
295 319 return $instance;
296 320 }
297 321
298 322 /**
323 + * Returns the list of boost parameters, values and labels.
324 + *
325 + * @since 2.5.0
326 + *
327 + * @return array<string, string> Boost parameters values and labels.
328 + */
329 + private function get_boost_params(): array {
330 + return array(
331 + 'no-boost' => __( 'No boost', 'wp-parsely' ),
332 + 'views' => __( 'Page views', 'wp-parsely' ),
333 + 'mobile_views' => __( 'Page views on mobile devices', 'wp-parsely' ),
334 + 'tablet_views' => __( 'Page views on tablet devices', 'wp-parsely' ),
335 + 'desktop_views' => __( 'Page views on desktop devices', 'wp-parsely' ),
336 + 'visitors' => __( 'Unique page visitors, total', 'wp-parsely' ),
337 + 'visitors_new' => __( 'New visitors', 'wp-parsely' ),
338 + 'visitors_returning' => __( 'Returning visitors', 'wp-parsely' ),
339 + 'engaged_minutes' => __( 'Total engagement time in minutes', 'wp-parsely' ),
340 + 'avg_engaged' => __( 'Engaged minutes spent by total visitors', 'wp-parsely' ),
341 + 'avg_engaged_new' => __( 'Average engaged minutes spent by new visitors', 'wp-parsely' ),
342 + 'avg_engaged_returning' => __( 'Average engaged minutes spent by returning visitors', 'wp-parsely' ),
343 + 'social_interactions' => __( 'Total social interactions', 'wp-parsely' ),
344 + 'fb_interactions' => __( 'Count of Facebook shares, likes, and comments', 'wp-parsely' ),
345 + 'tw_interactions' => __( 'Count of Twitter tweets and retweets', 'wp-parsely' ),
346 + 'pi_interactions' => __( 'Count of Pinterest pins', 'wp-parsely' ),
347 + 'social_referrals' => __( 'Page views where the referrer was any social network', 'wp-parsely' ),
348 + 'fb_referrals' => __( 'Page views where the referrer was facebook.com', 'wp-parsely' ),
349 + 'tw_referrals' => __( 'Page views where the referrer was twitter.com', 'wp-parsely' ),
350 + 'pi_referrals' => __( 'Page views where the referrer was pinterest.com', 'wp-parsely' ),
351 + );
352 + }
353 +
354 + /**
299 355 * Checks if both the Site ID and API secret settings are populated with
300 356 * non-empty values.
301 357 *
302 358 * @since 2.5.0
@@ -313,8 +369,9 @@
313 369 *
314 370 * @since 3.7.0
315 371 *
316 372 * @param array<string, mixed> $settings Widget Options.
373 + *
317 374 * @return Widget_Settings
318 375 */
319 376 public function get_widget_settings( array $settings ) {
320 377 /**