'',
'return_limit' => 5,
'display_direction' => 'vertical',
'published_within' => 0,
'sort' => 'score',
'personalize_results' => false,
'img_src' => 'parsely_thumb',
'display_author' => false,
);
/**
* Constructor.
*
* @param Parsely $parsely Instance of Parsely class.
*/
public function __construct( Parsely $parsely ) {
parent::__construct(
'Parsely_Recommended_Widget',
__( 'Parse.ly Recommended Widget', 'wp-parsely' ),
array(
'classname' => 'Recommended_Widget parsely-recommended-widget-hidden',
'description' => __( 'Display a list of post recommendations, personalized for a visitor or the current post.', 'wp-parsely' ),
)
);
$this->parsely = $parsely;
}
/**
* Gets the URL for the Recommendations API (GET /related).
*
* @since 2.5.0
*
* @see https://docs.parse.ly/content-recommendations/
*
* @internal While this is a public method now, this should be moved to a new class.
*
* @param string $site_id Publisher Site ID.
* @param int|null $published_within Publication filter start date; see https://docs.parse.ly/api-date-time/ for
* formatting details. No restriction by default.
* @param string|null $sort What to sort the results by. There are currently 2 valid options: `score`,
* which will sort articles by overall relevance and `pub_date` which will sort
* results by their publication date. The default is `score`.
* @param int $return_limit Number of records to retrieve; defaults to "10".
* @return string API URL.
*/
private function get_api_url( string $site_id, ?int $published_within, ?string $sort, int $return_limit ): string {
$related_api_endpoint = $this->parsely->get_content_api()->get_endpoint( '/related' );
$query_args = array(
'apikey' => $site_id,
'sort' => $sort,
'limit' => $return_limit,
);
if ( null !== $published_within && 0 !== $published_within ) {
$query_args['pub_date_start'] = $published_within . 'd';
}
return $related_api_endpoint->get_endpoint_url( $query_args );
}
/**
* This is the widget function.
*
* @param array ', wp_kses_post( $message ), '
/>
/>