Beispiel #1
0
    function widget($args, $instance)
    {
        extract($args);
        echo $before_widget;
        echo $before_title . $instance['title'] . $after_title;
        //
        // Partially from
        // http://non-diligent.com/articles/yelp-apiv2-php-example/
        // https://github.com/Yelp/yelp-api/blob/master/v2/php/example.php
        //
        // Enter the path that the oauth library is in relation to the php file
        require_once 'lib/OAuth.php';
        // Set instance values
        $speed = $instance['speed'];
        $pause = $instance['pause'];
        $showitems = $instance['showitems'];
        $animation = $instance['animation'];
        $mousepause = $instance['mousepause'];
        $direction = $instance['direction'];
        $yelp_url = $instance['yelp_url'];
        $unsigned_url = $instance['unsigned_url'];
        $consumer_key = $instance['consumer_key'];
        $consumer_secret = $instance['consumer_secret'];
        $token = $instance['token'];
        $token_secret = $instance['token_secret'];
        // Token object built using the OAuth library
        $token = new YRTOAuthToken($token, $token_secret);
        // Consumer object built using the OAuth library
        $consumer = new YRTOAuthConsumer($consumer_key, $consumer_secret);
        // Yelp uses HMAC SHA1 encoding
        $signature_method = new YRTOAuthSignatureMethod_HMAC_SHA1();
        // Build OAuth Request using the OAuth PHP library. Uses the consumer and token object created above.
        $oauthrequest = YRTOAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_url);
        // Sign the request
        $oauthrequest->sign_request($signature_method, $consumer, $token);
        // Get the signed URL
        $signed_url = $oauthrequest->to_url();
        // Send Yelp API Call
        $ch = curl_init($signed_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $data = curl_exec($ch);
        // Yelp response
        curl_close($ch);
        // Handle Yelp response data
        $response = json_decode($data);
        $arr = (array) $response;
        if (is_array($arr['reviews'])) {
            $ratingimg = plugins_url('images/rating.png', __FILE__);
            ?>

<div>
<?php 
            echo '	<h2><a href="' . $response->url . '" title="' . $response->url . '">' . $response->name . '</a></h2>' . "\n";
            echo '	<i title="' . $response->rating . ' star rating">' . "\n";
            echo '	<img style="vertical-align:middle" alt="' . $response->rating . ' star rating" src="' . $ratingimg . '" class="';
            if ($response->rating == "0") {
                echo 'yrtstars_0_l';
            }
            if ($response->rating == "1") {
                echo 'yrtstars_1_l';
            }
            if ($response->rating == "1.5") {
                echo 'yrtstars_1h_l';
            }
            if ($response->rating == "2.") {
                echo 'yrtstars_2_l';
            }
            if ($response->rating == "2.5") {
                echo 'yrtstars_2h_l';
            }
            if ($response->rating == "3") {
                echo 'yrtstars_3_l';
            }
            if ($response->rating == "3.5") {
                echo 'yrtstars_3h_l';
            }
            if ($response->rating == "4") {
                echo 'yrtstars_4_l';
            }
            if ($response->rating == "4.5") {
                echo 'yrtstars_4h_l';
            }
            if ($response->rating == "5") {
                echo 'yrtstars_5_l';
            }
            echo "\">\n";
            ?>

	</i>
	<?php 
            echo $response->review_count;
            ?>
 reviews
</div>
<br />
<?php 
            if ($response->review_count == 2 && $showitems > 2) {
                $showitems = "2";
            }
            if ($response->review_count == 1 && $showitems > 1) {
                $showitems = "1";
            }
            ?>

<!-- Start Yelp Reviews Ticker -->
<script type="text/javascript">
jQuery(function(){
	jQuery('#<?php 
            echo "ticker_", $this->id;
            ?>
').vTicker({ 
	<?php 
            echo "\tspeed: " . $instance['speed'] . ",\n";
            echo "\tpause: " . $instance['pause'] . ",\n";
            echo "\tanimation: '" . $instance['animation'] . "',\n";
            echo "\tmousePause: " . $instance['mousepause'] . ",\n";
            echo "\tdirection: '" . $instance['direction'] . "',\n";
            echo "\tshowItems: " . $showitems . "\n";
            ?>

	});
});
</script>
<!-- End Yelp Reviews Ticker -->

<div id="yrtcssmarkup">
<div id="<?php 
            echo "ticker_", $this->id;
            ?>
">
	<ul>
<?php 
            foreach ($arr['reviews'] as $review) {
                ?>

		<li>
            <div class="yrtTable">
                <div class="yrtRow">
                    <div class="yrtCell1">
<?php 
                echo '				<img alt="' . $review->user->name . '" src="' . $review->user->image_url . '" width="60"/>' . "\n";
                echo '					<br />' . $review->user->name . ' <br />' . "\n";
                echo '					<img alt="' . $review->rating . ' star" src="' . $ratingimg . '" class="';
                if ($review->rating == "0") {
                    echo 'yrtstars_0_s';
                }
                if ($review->rating == "1") {
                    echo 'yrtstars_1_s';
                }
                if ($review->rating == "1.5") {
                    echo 'yrtstars_1h_s';
                }
                if ($review->rating == "2") {
                    echo 'yrtstars_2_s';
                }
                if ($review->rating == "2.5") {
                    echo 'yrtstars_2h_s';
                }
                if ($review->rating == "3") {
                    echo 'yrtstars_3_s';
                }
                if ($review->rating == "3.5") {
                    echo 'yrtstars_3h_s';
                }
                if ($review->rating == "4") {
                    echo 'yrtstars_4_s';
                }
                if ($review->rating == "4.5") {
                    echo 'yrtstars_4h_s';
                }
                if ($review->rating == "5") {
                    echo 'yrtstars_5_s';
                }
                echo "\">\n";
                ?>

                   </div>
                    <div class="yrtCell2">
<?php 
                echo '				<p>' . $review->excerpt . '</p>' . "\n";
                ?>

                    </div>
                </div>
            </div>
<?php 
                echo '					<div class="yrtYelp"><a href="' . $response->url . '#hrid:' . $review->id . '" target="_blank" title="Read the review in full at Yelp.com"> ' . gmdate("m/d/Y", $review->time_created) . ' read the full review at ' . "\n";
                echo '						<img style="vertical-align:middle" alt="Yelp" src="' . plugins_url('images/miniMapLogo.png', __FILE__) . '"/></a></div>' . "\n";
                ?>

        </li>
<?php 
            }
            ?>

	</ul>
</div>

<div class="yrtFoot">
		<a href="http://www.yelp.com" title="www.Yelp.com" target="_blank">Reviews powered by <img alt="Yelp" style="vertical-align:middle" src="<?php 
            echo plugins_url('images/yelp_logo_50x25.png', __FILE__);
            ?>
" /></a>
</div>
</div>

<?php 
        }
        echo $after_widget;
    }
Beispiel #2
0
 /**
  * pretty much a helper function to set up the request
  */
 public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters = NULL)
 {
     $parameters = $parameters ? $parameters : array();
     $defaults = array("oauth_version" => YRTOAuthRequest::$version, "oauth_nonce" => YRTOAuthRequest::generate_nonce(), "oauth_timestamp" => YRTOAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key);
     if ($token) {
         $defaults['oauth_token'] = $token->key;
     }
     $parameters = array_merge($defaults, $parameters);
     return new YRTOAuthRequest($http_method, $http_url, $parameters);
 }