コード例 #1
0
 /** 
  *  GET THE REVIEWS
  *  Our main function for getting the reviews
  *  and splittting them up into individual reviews
  *  and their parts
  *
  *  @since 1.0
  *	@var $instance
  **/
 public function wprrw_split_reviews($instance)
 {
     // Create DOM from reviews output string
     $wprepo = new WP_Ratings_Widget();
     $xpath = $wprepo->wprrw_get_xpath($instance);
     // Target the class of the reviews element
     $reviewclass = './/div[contains(concat(" ", normalize-space(@class), " "), " review ")]';
     // Loop through all review elements
     // and output the markup accordingly
     foreach ($xpath->evaluate($reviewclass) as $div) {
         $i = 0;
         // Save each review as an XML instance
         $raw_review = $div->ownerDocument->saveXML($div);
         // Grab all "a" elements from each review
         $linkhrefs = array();
         $linkTags = $div->getElementsByTagName('a');
         // Grab the links from each "a" element
         // and define the Author according to the
         // text inside the "a" element
         foreach ($linkTags as $tag) {
             $linkhrefs[] = $tag->getAttribute('href');
             $author = trim(strip_tags($tag->ownerDocument->saveXML($tag)));
         }
         // If a reviewer added any links into their
         // review, it will return as their author link
         // So we'll grab their author url instead and
         // trim that to be their name
         if (strpos($author, 'http') !== false) {
             $profile = str_replace("//profiles.wordpress.org/", "", $linkhrefs[0]);
             $author = $profile;
         } else {
             $author = $author;
         }
         // Grab and define each element of the review
         $gettitle = $this->wprrw_getElementsByClass($div, 'div', 'review-title-section');
         $title = substr($gettitle[0]->textContent, 0, -13);
         $getstars = $this->wprrw_getElementsByClass($div, 'div', 'star-rating');
         $stars = $getstars[0]->textContent;
         $getrevdate = $this->wprrw_getElementsByClass($div, 'span', 'review-date');
         $revdate = $getrevdate[0]->textContent;
         $getcontent = $this->wprrw_getElementsByClass($div, 'div', 'review-body');
         $content = $getcontent[0]->textContent;
         $trimmedcontent = wp_trim_words($content, 50);
         $starnum = substr($stars, 0, -9);
         $i = 0;
         if ($starnum >= 4) {
             include WPRRW_PATH . 'views/default-reviews.php';
         }
         // For testing you can always echo $raw_review
         // to see the original output that the plugins_api returns
         //echo $raw_review;
     }
 }
コード例 #2
0
<?php

// Creates the DOM and XPath out of the review string
// returned by the plugins_api
// Last but not least, Output the reviews function
$wprepo = new WP_Ratings_Widget();
?>

	<div class="wprrw_reviews_enabled">
		<h4 class="wprrw_reviews_title">Reviews</h4>
		<div class="wprrw_reviews_wrap" data-slick=\'{"slidesToShow": 1, "slidesToScroll": 1}\'>

			<?php 
$wprepo->wprrw_split_reviews($instance);
//echo $showreviews;
?>

		</div>
	</div>

	<div class="reviews_nav">
		<span class="prevArrow"><?php 
echo __('Previous Review', 'wppluginratings');
?>
</span>
		<span class="nextArrow"><?php 
echo __('Next Review', 'wppluginratings');
?>
</span>
	</div>
	<div class="reviews_all">
コード例 #3
0
<?php

/*
 *  Widget Template Loader
 */
$wprepo = new WP_Ratings_Widget();
$var = $wprepo->variables($instance);
//Enqueue necessary styles and scripts for the widget
wp_enqueue_style('wprrw-default-css', WPRRW_URL . 'css/wprrw-widget-default.css', false);
wp_enqueue_style('wprrw-slick-css', WPRRW_URL . 'vendor/slick/slick.css', false);
wp_enqueue_style('wprrw-slick-theme-css', WPRRW_URL . 'vendor/slick/slick-theme.css', false);
wp_enqueue_script('wprrw-slick-js', WPRRW_URL . 'vendor/slick/slick.min.js', '', '', true);
// Get the Widget Title
if (isset($instance['wprrw_title'])) {
    echo $before_title . esc_attr($instance['wprrw_title']) . $after_title;
}
// Get Plugin Slug
if (isset($var['slug'])) {
    $slug = $var['slug'];
}
?>

<div class="wprrw_plugin_data_wrapper plugin-<?php 
echo $slug;
?>
">

<?php 
// Get the Plugin Active Installs
if (!empty($var['installs'])) {
    $installs = $var['installs'];