Depuración y preparación de plantilla

This commit is contained in:
2025-09-13 13:33:41 -06:00
parent 3517b1cfb2
commit 21a09f2fa9
1587 changed files with 2663 additions and 87357 deletions

View File

@ -1,89 +0,0 @@
<?php
/**
* Facebook
*
* with help of the API this class delivers album images from Facebook
*
* @package socialstreams
* @subpackage socialstreams/facebook
* @author ThemePunch <info@themepunch.com>
*/
class TP_facebook {
/**
* Get User ID from its URL
*
* @since 1.0.0
* @param string $user_url URL of the Page
*/
public function get_user_from_url($user_url){
$theid = str_replace("https", "", $user_url);
$theid = str_replace("http", "", $theid);
$theid = str_replace("://", "", $theid);
$theid = str_replace("www.", "", $theid);
$theid = str_replace("facebook", "", $theid);
$theid = str_replace(".com", "", $theid);
$theid = str_replace("/", "", $theid);
$theid = explode("?", $theid);
return $theid[0];
}
/**
* Get Photosets List from User
*
* @since 1.0.0
* @param string $user_id Facebook User id (not name)
* @param int $item_count number of photos to pull
*/
public function get_photo_sets($user_id,$item_count=10){
//photoset params
$url = "https://graph.facebook.com/$user_id/albums";
$photo_sets_list = json_decode(file_get_contents($url));
return $photo_sets_list->data;
}
/**
* Get Photoset Photos
*
* @since 1.0.0
* @param string $photo_set_id Photoset ID
* @param int $item_count number of photos to pull
*/
public function get_photo_set_photos($photo_set_id,$item_count=10){
$url = "https://graph.facebook.com/v2.0/$photo_set_id?fields=photos";
$photo_set_photos = json_decode(file_get_contents($url));
return $photo_set_photos->photos->data;
}
/**
* Get Feed
*
* @since 1.0.0
* @param string $user User ID
* @param int $item_count number of itmes to pull
*/
public function get_post_feed($user,$app_id,$app_secret,$item_count=10){
$oauth = file_get_contents("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=".$app_id."&client_secret=".$app_secret);
$url = "https://graph.facebook.com/$user/feed?".$oauth."&fields=id,from,message,picture,link,name,icon,privacy,type,status_type,object_id,application,created_time,updated_time,is_hidden,is_expired,likes,comments";
$feed = json_decode(file_get_contents($url));
return $feed->data;
}
/**
* Decode URL from feed
*
* @since 1.0.0
* @param string $url facebook Output Data
*/
public static function decode_facebook_url($url) {
$url = str_replace('u00253A',':',$url);
$url = str_replace('\u00255C\u00252F','/',$url);
$url = str_replace('u00252F','/',$url);
$url = str_replace('u00253F','?',$url);
$url = str_replace('u00253D','=',$url);
$url = str_replace('u002526','&',$url);
return $url;
}
}
?>

View File

@ -1,265 +0,0 @@
<?php
/**
* Flickr
*
* with help of the API this class delivers all kind of Images from flickr
*
* @package socialstreams
* @subpackage socialstreams/flickr
* @author ThemePunch <info@themepunch.com>
*/
class TP_flickr {
/**
* API key
*
* @since 1.0.0
* @access private
* @var string $api_key flickr API key
*/
private $api_key;
/**
* API params
*
* @since 1.0.0
* @access private
* @var array $api_param_defaults Basic params to call with API
*/
private $api_param_defaults;
/**
* Basic URL
*
* @since 1.0.0
* @access private
* @var string $url Url to fetch user from
*/
private $flickr_url;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $api_key flickr API key.
*/
public function __construct($api_key) {
$this->api_key = $api_key;
$this->api_param_defaults = array(
'api_key' => $this->api_key,
'format' => 'json',
'nojsoncallback' => 1,
);
}
/**
* Calls Flicker API with set of params, returns json
*
* @since 1.0.0
* @param array $params Parameter build for API request
*/
private function call_flickr_api($params){
//build url
$encoded_params = array();
foreach ($params as $k => $v){
$encoded_params[] = urlencode($k).'='.urlencode($v);
}
//call the API and decode the response
$url = "https://api.flickr.com/services/rest/?".implode('&', $encoded_params);
$rsp = json_decode(file_get_contents($url));
return $rsp;
}
/**
* Get User ID from its URL
*
* @since 1.0.0
* @param string $user_url URL of the Gallery
*/
public function get_user_from_url($user_url){
//gallery params
$user_params = $this->api_param_defaults + array(
'method' => 'flickr.urls.lookupUser',
'url' => $user_url,
);
//set User Url
$this->flickr_url = $user_url;
//get gallery info
$user_info = $this->call_flickr_api($user_params);
return $user_info->user->id;
}
/**
* Get Group ID from its URL
*
* @since 1.0.0
* @param string $group_url URL of the Gallery
*/
public function get_group_from_url($group_url){
//gallery params
$group_params = $this->api_param_defaults + array(
'method' => 'flickr.urls.lookupGroup',
'url' => $group_url,
);
//set User Url
$this->flickr_url = $group_url;
//get gallery info
$group_info = $this->call_flickr_api($group_params);
return $group_info->group->id;
}
/**
* Get Public Photos
*
* @since 1.0.0
* @param string $user_id flicker User id (not name)
* @param int $item_count number of photos to pull
*/
public function get_public_photos($user_id,$item_count=10){
//public photos params
$public_photo_params = $this->api_param_defaults + array(
'method' => 'flickr.people.getPublicPhotos',
'user_id' => $user_id,
'extras' => 'description, license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l, url_o',
'per_page'=> $item_count,
'page' => 1
);
//get photo list
$public_photos_list = $this->call_flickr_api($public_photo_params);
return $public_photos_list->photos->photo;
}
/**
* Get Photosets List from User
*
* @since 1.0.0
* @param string $user_id flicker User id (not name)
* @param int $item_count number of photos to pull
*/
public function get_photo_sets($user_id,$item_count=10){
//photoset params
$photo_set_params = $this->api_param_defaults + array(
'method' => 'flickr.photosets.getList',
'user_id' => $user_id,
'per_page'=> $item_count,
'page' => 1
);
//get photoset list
$photo_sets_list = $this->call_flickr_api($photo_set_params);
return $photo_sets_list->photosets->photoset;
}
/**
* Get Photoset Photos
*
* @since 1.0.0
* @param string $photo_set_id Photoset ID
* @param int $item_count number of photos to pull
*/
public function get_photo_set_photos($photo_set_id,$item_count=10){
//photoset photos params
$photo_set_params = $this->api_param_defaults + array(
'method' => 'flickr.photosets.getPhotos',
'photoset_id' => $photo_set_id,
'per_page' => $item_count,
'page' => 1,
'extras' => 'license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l, url_o'
);
//get photo list
$photo_set_photos = $this->call_flickr_api($photo_set_params);
return $photo_set_photos->photoset->photo;
}
/**
* Get Groop Pool Photos
*
* @since 1.0.0
* @param string $group_id Photoset ID
* @param int $item_count number of photos to pull
*/
public function get_group_photos($group_id,$item_count=10){
//photoset photos params
$group_pool_params = $this->api_param_defaults + array(
'method' => 'flickr.groups.pools.getPhotos',
'group_id' => $group_id,
'per_page' => $item_count,
'page' => 1,
'extras' => 'license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l, url_o'
);
//get photo list
$group_pool_photos = $this->call_flickr_api($group_pool_params);
return $group_pool_photos->photos->photo;
}
/**
* Get Gallery ID from its URL
*
* @since 1.0.0
* @param string $gallery_url URL of the Gallery
* @param int $item_count number of photos to pull
*/
public function get_gallery_from_url($gallery_url){
//gallery params
$gallery_params = $this->api_param_defaults + array(
'method' => 'flickr.urls.lookupGallery',
'url' => $gallery_url,
);
//get gallery info
$gallery_info = $this->call_flickr_api($gallery_params);
return $gallery_info->gallery->id;
}
/**
* Get Gallery Photos
*
* @since 1.0.0
* @param string $gallery_id flicker Gallery id (not name)
* @param int $item_count number of photos to pull
*/
public function get_gallery_photos($gallery_id,$item_count=10){
//gallery photos params
$gallery_photo_params = $this->api_param_defaults + array(
'method' => 'flickr.galleries.getPhotos',
'gallery_id' => $gallery_id,
'extras' => 'description, license, date_upload, date_taken, owner_name, icon_server, original_format, last_update, geo, tags, machine_tags, o_dims, views, media, path_alias, url_sq, url_t, url_s, url_q, url_m, url_n, url_z, url_c, url_l, url_o',
'per_page'=> $item_count,
'page' => 1
);
//get photo list
$gallery_photos_list = $this->call_flickr_api($gallery_photo_params);
return $gallery_photos_list->photos->photo;
}
/**
* Encode the flickr ID for URL (base58)
*
* @since 1.0.0
* @param string $num flickr photo id
*/
public static function base_encode($num, $alphabet='123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ') {
$base_count = strlen($alphabet);
$encoded = '';
while ($num >= $base_count) {
$div = $num/$base_count;
$mod = ($num-($base_count*intval($div)));
$encoded = $alphabet[$mod] . $encoded;
$num = intval($div);
}
if ($num) $encoded = $alphabet[$num] . $encoded;
return $encoded;
}
}
?>

View File

@ -1,48 +0,0 @@
<?php
/**
* Instagram
*
* with help of the API this class delivers all kind of Images from instagram
*
* @package socialstreams
* @subpackage socialstreams/instagram
* @author ThemePunch <info@themepunch.com>
*/
class TP_instagram {
/**
* API key
*
* @since 1.0.0
* @access private
* @var string $api_key Instagram API key
*/
private $api_key;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $api_key Instagram API key.
*/
public function __construct($api_key) {
$this->api_key = $api_key;
}
/**
* Get Instagram Pictures
*
* @since 1.0.0
* @param string $user_id Instagram User id (not name)
*/
public function get_public_photos($search_user_id){
//call the API and decode the response
$url = "https://api.instagram.com/v1/users/".$search_user_id."/media/recent?access_token=".$this->api_key."&client_id=".$search_user_id;
$rsp = json_decode(file_get_contents($url));
return $rsp->data;
}
}
?>

View File

@ -1,93 +0,0 @@
<?php
/**
* @author Albert Kozlowski <vojant@gmail.com>
* @license MIT License
* @link https://github.com/vojant/Twitter-php
*/
namespace TwitterPhp;
use \TwitterPhp\Connection\Application;
use \TwitterPhp\Connection\User;
require_once 'connection/ConnectionAbstract.php';
require_once 'connection/Application.php';
require_once 'connection/User.php';
/**
* Class TwitterRestApiException
*/
class RestApiException extends \Exception {};
/**
* Class RestApi
* @package TwitterPhp
*/
class RestApi
{
/**
* @var string
*/
private $_consumerKey;
/**
* @var string
*/
private $_consumerSecret;
/**
* @var string
*/
private $_accessToken;
/**
* @var string
*/
private $_accessTokenSecret;
/**
* @param string $consumerKey
* @param string $consumerSecret
* @param null|string $accessToken
* @param null|string $accessTokenSecret
* @throws TwitterRestApiException
*/
public function __construct($consumerKey,$consumerSecret,$accessToken = null,$accessTokenSecret = null)
{
if (!function_exists('curl_init')) {
throw new TwitterRestApiException('You must have the cURL extension enabled to use this library');
}
$this->_consumerKey = $consumerKey;
$this->_consumerSecret = $consumerSecret;
$this->_accessToken = $accessToken;
$this->_accessTokenSecret = $accessTokenSecret;
}
/**
* Connect to Twitter API as application.
* @link https://dev.twitter.com/docs/auth/application-only-auth
*
* @return \TwitterPhp\Connection\Application
*/
public function connectAsApplication()
{
return new Application($this->_consumerKey,$this->_consumerSecret);
}
/**
* Connect to Twitter API as user.
* @link https://dev.twitter.com/docs/auth/oauth/single-user-with-examples
*
* @return \TwitterPhp\Connection\User
* @throws TwitterRestApiException
*/
public function connectAsUser()
{
if (!$this->_accessToken || !$this->_accessTokenSecret) {
throw new TwitterRestApiException('Missing ACCESS_TOKEN OR ACCESS_TOKEN_SECRET');
}
return new User($this->_consumerKey,$this->_consumerSecret,$this->_accessToken,$this->_accessTokenSecret);
}
}

View File

@ -1,122 +0,0 @@
<?php
include 'RestApi.php';
/**
* Twitter
*
* with help of the API this class delivers all kind of tweeted images from twitter
*
* @package socialstreams
* @subpackage socialstreams/twitter
* @author ThemePunch <info@themepunch.com>
*/
class TP_twitter {
/**
* Consumer Key
*
* @since 1.0.0
* @access private
* @var string $consumer_key Consumer Key
*/
private $consumer_key;
/**
* Consumer Secret
*
* @since 1.0.0
* @access private
* @var string $consumer_secret Consumer Secret
*/
private $consumer_secret;
/**
* Access Token
*
* @since 1.0.0
* @access private
* @var string $access_token Access Token
*/
private $access_token;
/**
* Access Token Secret
*
* @since 1.0.0
* @access private
* @var string $access_token_secret Access Token Secret
*/
private $access_token_secret;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $api_key flickr API key.
*/
public function __construct($consumer_key,$consumer_secret,$access_token,$access_token_secret) {
$this->consumer_key = $consumer_key;
$this->consumer_secret = $consumer_secret;
$this->access_token = $access_token;
$this->access_token_secret = $access_token_secret;
}
/**
* Get Tweets
*
* @since 1.0.0
* @param string $twitter_account Twitter account without trailing @ char
*/
public function get_public_photos($twitter_account){
$twitter = new \TwitterPhp\RestApi($this->consumer_key,$this->consumer_secret,$this->access_token,$this->access_token_secret);
/*
* Connect as application
* https://dev.twitter.com/docs/auth/application-only-auth
*/
$connection = $twitter->connectAsApplication();
/*
* Collection of the most recent Tweets posted by the user indicated by the screen_name, without replies
* https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
*/
$tweets = $connection->get('/statuses/user_timeline',array('screen_name' => $twitter_account, 'entities' => 1, 'trim_user' => 0 , 'exclude_replies' => 'true'));
//var_dump($tweets);
return $tweets;
}
/**
* Find Key in array and return value (multidim array possible)
*
* @since 1.0.0
* @param string $key Needle
* @param array $form Haystack
*/
public static function array_find_element_by_key($key, $form) {
if (array_key_exists($key, $form)) {
$ret =& $form[$key];
return $ret;
}
foreach ($form as $k => $v) {
if (is_array($v)) {
$ret =TP_twitter::array_find_element_by_key($key, $form[$k]);
if ($ret) {
return $ret;
}
}
}
return FALSE;
}
/**
* Prepare output array $stream
*
* @since 1.0.0
* @param string $tweets Twitter Output Data
*/
public static function makeClickableLinks($s) {
return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', $s);
}
}
?>

View File

@ -1,80 +0,0 @@
<?php
namespace TwitterPhp\Connection;
use TwitterPhp\RestApiException;
class Application extends Base
{
/**
* @var string
*/
private $_consumerKey;
/**
* @var string
*/
private $_consumerSecret;
/**
* @var string
*/
private $_bearersToken = null;
/**
* @param string $consumerKey
* @param string $consumerSecret
*/
public function __construct($consumerKey,$consumerSecret)
{
$this->_consumerKey = $consumerKey;
$this->_consumerSecret = $consumerSecret;
}
/**
* @param string $url
* @param array $parameters
* @param $method
* @return array
*/
protected function _buildHeaders($url,array $parameters = null,$method)
{
return $headers = array(
"Authorization: Bearer " . $this->_getBearerToken()
);
}
/**
* Get Bearer token
*
* @link https://dev.twitter.com/docs/auth/application-only-auth
*
* @throws \TwitterPhp\RestApiException
* @return string
*/
private function _getBearerToken() {
if (!$this->_bearersToken) {
$token = urlencode($this->_consumerKey) . ':' . urlencode($this->_consumerSecret);
$token = base64_encode($token);
$headers = array(
"Authorization: Basic " . $token
);
$options = array (
CURLOPT_URL => self::TWITTER_API_AUTH_URL,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => "grant_type=client_credentials"
);
$response = $this->_callApi($options);
if (isset($response["token_type"]) && $response["token_type"] == 'bearer') {
$this->_bearersToken = $response["access_token"];
} else {
throw new RestApiException('Error while getting access token');
}
}
return $this->_bearersToken;
}
}

View File

@ -1,120 +0,0 @@
<?php
namespace TwitterPhp\Connection;
/**
* Class Base
* @package TwitterPhp
* @subpackage Connection
*/
abstract class Base
{
/**
* Url for Twitter api
*/
const TWITTER_API_URL = 'https://api.twitter.com';
/**
* Twitter URL that authenticates bearer tokens
*/
const TWITTER_API_AUTH_URL = 'https://api.twitter.com/oauth2/token/';
/**
* Version of Twitter api
*/
const TWITTER_API_VERSION = '1.1';
/**
* Timeout value for curl connections
*/
const DEFAULT_TIMEOUT = 10;
/**
* METHOD GET
*/
const METHOD_GET = 'GET';
/**
* METHOD POST
*/
const METHOD_POST = 'POST';
/**
* @param string $url
* @param array $parameters
* @param $method
* @return array
*/
abstract protected function _buildHeaders($url,array $parameters = null,$method);
/**
* Do GET request to Twitter api
*
* @link https://dev.twitter.com/docs/api/1.1
*
* @param $resource
* @param array $parameters
* @return mixed
*/
public function get($resource, array $parameters = array())
{
$url = $this->_prepareUrl($resource);
$headers = $this->_buildHeaders($url,$parameters,self::METHOD_GET);
$url = $url . '?' . http_build_query($parameters);
$curlParams = array (
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $headers
);
return $this->_callApi($curlParams);
}
/**
* Do POST request to Twitter api
*
* @link https://dev.twitter.com/docs/api/1.1
*
* @param $resource
* @param array $parameters
* @return mixed
*/
public function post($resource, array $parameters = array())
{
$url = $this->_prepareUrl($resource);
$headers = $this->_buildHeaders($url,$parameters,self::METHOD_POST);
$curlParams = array (
CURLOPT_URL => $url,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $parameters,
CURLOPT_HTTPHEADER => $headers
);
return $this->_callApi($curlParams);
}
/**
* Call Twitter api
*
* @param array $params
* @return array
*/
protected function _callApi(array $params)
{
$curl = curl_init();
curl_setopt_array($curl,$params);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, self::DEFAULT_TIMEOUT);
$response = curl_exec($curl);
return json_decode($response,true);
}
/**
* @param string $resource
* @return string
*/
private function _prepareUrl($resource)
{
return self::TWITTER_API_URL . '/' . self::TWITTER_API_VERSION . '/' . ltrim($resource,'/') . '.json';
}
}

View File

@ -1,92 +0,0 @@
<?php
namespace TwitterPhp\Connection;
class User extends Base
{
/**
* @var string
*/
private $_consumerKey;
/**
* @var string
*/
private $_consumerSecret;
/**
* @var string
*/
private $_accessToken;
/**
* @var string
*/
private $_accessTokenSecret;
/**
* @param string $consumerKey
* @param string $consumerSecret
* @param string $accessToken
* @param string $accessTokenSecret
*/
public function __construct($consumerKey,$consumerSecret,$accessToken,$accessTokenSecret)
{
$this->_consumerKey = $consumerKey;
$this->_consumerSecret = $consumerSecret;
$this->_accessToken = $accessToken;
$this->_accessTokenSecret = $accessTokenSecret;
}
/**
* @param string $url
* @param array $parameters
* @param $method
* @return array
*/
protected function _buildHeaders($url,array $parameters = null,$method)
{
$oauthHeaders = array(
'oauth_version' => '1.0',
'oauth_consumer_key' => $this->_consumerKey,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $this->_accessToken,
'oauth_timestamp' => time()
);
$data = $oauthHeaders;
if ($method == self::METHOD_GET) {
$data = array_merge($oauthHeaders,$parameters);
}
$oauthHeaders['oauth_signature'] = $this->_buildOauthSignature($url,$data,$method);
ksort($oauthHeaders);
$oauthHeader = array();
foreach($oauthHeaders as $key => $value) {
$oauthHeader[] = $key . '="' . rawurlencode($value) . '"';
}
$headers[] = 'Authorization: OAuth ' . implode(', ', $oauthHeader);
return $headers;
}
/**
* @param $url
* @param array $params
* @param $method
* @return string
*/
private function _buildOauthSignature($url,array $params,$method)
{
ksort($params);
$sortedParams = array();
foreach($params as $key=>$value) {
$sortedParams[] = $key . '=' . $value;
}
$signatureBaseString = $method . "&" . rawurlencode($url) . '&' . rawurlencode(implode('&', $sortedParams));
$compositeKey = rawurlencode($this->_consumerSecret) . '&' . rawurlencode($this->_accessTokenSecret);
return base64_encode(hash_hmac('sha1', $signatureBaseString, $compositeKey, true));
}
}

View File

@ -1,74 +0,0 @@
<?php
/**
* Vimeo
*
* with help of the API this class delivers all kind of Images/Videos from Vimeo
*
* @package socialstreams
* @subpackage socialstreams/vimeo
* @author ThemePunch <info@themepunch.com>
*/
class TP_vimeo {
/**
* Stream Array
*
* @since 1.0.0
* @access private
* @var array $stream Stream Data Array
*/
private $stream;
/**
* Get Vimeo User Videos
*
* @since 1.0.0
*/
public function get_vimeo_videos($type,$value){
//call the API and decode the response
if($type=="user"){
$url = "https://vimeo.com/api/v2/".$value."/videos.json";
}
else{
$url = "https://vimeo.com/api/v2/".$type."/".$value."/videos.json";
}
$rsp = json_decode(file_get_contents($url));
return $rsp;
}
/**
* Prepare output array $stream for Vimeo videos
*
* @since 1.0.0
* @param string $videos Vimeo Output Data
*/
private function vimeo_output_array($videos,$count){
foreach ($videos as $video) {
if($count-- == 0) break;
$stream = array();
$image_url = @array(
'thumbnail_small' => array($video->thumbnail_small),
'thumbnail_medium' => array($video->thumbnail_medium),
'thumbnail_large' => array($video->thumbnail_large),
);
$stream['custom-image-url'] = $image_url; //image for entry
$stream['custom-type'] = 'vimeo'; //image, vimeo, youtube, soundcloud, html
$stream['custom-vimeo'] = $video->id;
$stream['post_url'] = $video->url;
$stream['post_link'] = $video->url;
$stream['title'] = $video->title;
$stream['content'] = $video->description;
$stream['date_modified'] = $video->upload_date;
$stream['author_name'] = $video->user_name;
$this->stream[] = $stream;
}
}
}
?>

View File

@ -1,85 +0,0 @@
<?php
/**
* Youtube
*
* with help of the API this class delivers all kind of Images/Videos from youtube
*
* @package socialstreams
* @subpackage socialstreams/youtube
* @author ThemePunch <info@themepunch.com>
*/
class TP_youtube {
/**
* API key
*
* @since 1.0.0
* @access private
* @var string $api_key Youtube API key
*/
private $api_key;
/**
* Channel ID
*
* @since 1.0.0
* @access private
* @var string $channel_id Youtube Channel ID
*/
private $channel_id;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $api_key Youtube API key.
*/
public function __construct($api_key,$channel_id) {
$this->api_key = $api_key;
$this->channel_id = $channel_id;
}
/**
* Get Youtube Playlists
*
* @since 1.0.0
*/
public function get_playlists(){
//call the API and decode the response
$url = "https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=".$this->channel_id."&key=".$this->api_key;
$rsp = json_decode(file_get_contents($url));
return $rsp->items;
}
/**
* Get Youtube Playlist Items
*
* @since 1.0.0
* @param string $playlist_id Youtube Playlist ID
* @param integer $count Max videos count
*/
public function show_playlist_videos($playlist_id,$count=50){
//call the API and decode the response
$url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=".$playlist_id."&maxResults=".$count."&fields=items%2Fsnippet&key=".$this->api_key;
$rsp = json_decode(file_get_contents($url));
return $rsp->items;
}
/**
* Get Youtube Channel Items
*
* @since 1.0.0
* @param integer $count Max videos count
*/
public function show_channel_videos($count=50){
//call the API and decode the response
$url = "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=".$this->channel_id."&maxResults=".$count."&key=".$this->api_key."&order=date";
echo $url;
$rsp = json_decode(file_get_contents($url));
return $rsp->items;
}
}
?>

View File

@ -1,448 +0,0 @@
<?php
/**
* The public-facing functionality of the plugin.
*
* @link https://www.themepunch.com
* @since 1.0.0
*
* @package Revslider_Weather_Addon
* @subpackage Revslider_Weather_Addon/public
*/
/**
* The public-facing functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package Revslider_Weather_Addon
* @subpackage Revslider_Weather_Addon/public
* @author ThemePunch <info@themepunch.com>
*/
class Revslider_Weather_Addon_Public {
/**
* The ID of this plugin.
*
* @since 1.0.0
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
/**
* The version of this plugin.
*
* @since 1.0.0
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
private $weather;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $plugin_name The name of the plugin.
* @param string $version The version of this plugin.
*/
public function __construct( $plugin_name, $version ) {
$this->plugin_name = $plugin_name;
$this->version = $version;
}
/**
* Register the stylesheets for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_styles() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Revslider_Weather_Addon_Loader as all of the hooks are defined
* in that particular class.
*
* The Revslider_Weather_Addon_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
//wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/revslider-weather-addon-public.css', array(), $this->version, 'all' );
}
/**
* Register the JavaScript for the public-facing side of the site.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
/**
* This function is provided for demonstration purposes only.
*
* An instance of this class should be passed to the run() function
* defined in Revslider_Weather_Addon_Loader as all of the hooks are defined
* in that particular class.
*
* The Revslider_Weather_Addon_Loader will then create the relationship
* between the defined hooks and the functions defined in this
* class.
*/
}
/**
* Get Information from Slide and call the weather
* @since 1.0.0
*/
public function revslider_add_layer_html($slider, $slide){
//global $revslider_weather;
$sliderParams = $slider->getParams();
if( isset($sliderParams["revslider-weather-enabled"]) && $sliderParams["revslider-weather-enabled"] == "true" ){
wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/revslider-weather-addon-public.css', array(), $this->version, 'all' );
}
if( isset($sliderParams["revslider-weather-enabled"]) && $sliderParams["revslider-weather-enabled"] == "true" && !empty( $sliderParams["revslider-weather-refresh"] ) ){
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/revslider-weather-addon-public.js', array( 'jquery' ), $this->version, false );
wp_localize_script( $this->plugin_name, 'rev_slider_weather_addon', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'interval' => $sliderParams["revslider-weather-refresh"]
));
}
}
/**
* Connects to Yahoo API and collects Weather Info
* @since 1.0.0
*/
public function get_weather($type,$woeid,$name,$unit){
//Get weather information dependent from Slider options
$revslider_weather = RevAddOnWeatherYahoo::get_weather_infos($type,$woeid,$name,$unit);
return $revslider_weather;
}
/**
* Filters the custom meta placeholders and calls function to replace
* @since 1.0.0
*/
public function rev_addon_insert_meta($record){
$params = json_decode($record["params"]);
$type = isset($params->{"revslider-weather-location-type"}) ? $params->{"revslider-weather-location-type"} : '';
$woeid = isset($params->{"revslider-weather-location-woeid"}) ? $params->{"revslider-weather-location-woeid"} : '';
$name = isset($params->{"revslider-weather-location-name"}) ? $params->{"revslider-weather-location-name"} : '';
$unit = isset($params->{"revslider-weather-unit"}) ? $params->{"revslider-weather-unit"} : '';
$params->params_10 = (!isset($params->params_10)) ? '' : $params->params_10;
//Get weather information dependent from Slider options
$revslider_weather = $this->get_weather($type,$woeid,$name,$unit);
// $revslider_weather = '';
$params->params_10_chars = 1200;
$params->params_10 = $params->params_10 . '{"revslider-weather-addon" : { "type" : "' . $type . '" ,"name" : "' . $name . '" ,"woeid" : "' . $woeid . '" ,"unit" : "' . $unit . '" }}';
$record["params"] = json_encode($params);
if(strpos($record["layers"], "%weather_icon%")) wp_enqueue_style( $this->plugin_name . '_icons', plugin_dir_url( __FILE__ ) . 'css/revslider-weather-addon-icon.css', array(), $this->version, 'all' );
// if(!isset($revslider_weather->query->results->channel)) return $record;
$def_value = '--';
$def_fc = 'F';
$def_icon = '30';
$results = false;
if(!empty($revslider_weather) && isset($revslider_weather->query) && isset($revslider_weather->query->results) && isset($revslider_weather->query->results->channel)) {
$results = true;
$values = array(
'revslider_data_weather_title' => $revslider_weather->query->results->channel->item->title,
'revslider_data_weather_temp' => $revslider_weather->query->results->channel->item->condition->temp,
'revslider_data_weather_code' => $revslider_weather->query->results->channel->item->condition->code,
'revslider_data_weather_todayCode' => $revslider_weather->query->results->channel->item->forecast[0]->code,
'revslider_data_weather_date' => $revslider_weather->query->results->channel->item->forecast[0]->date,
'revslider_data_weather_day' => $revslider_weather->query->results->channel->item->forecast[0]->day,
'revslider_data_weather_currently' => RevAddOnWeatherYahoo::condition_lang($revslider_weather->query->results->channel->item->condition->text),
'revslider_data_weather_high' => $revslider_weather->query->results->channel->item->forecast[0]->high,
'revslider_data_weather_low' => $revslider_weather->query->results->channel->item->forecast[0]->low,
'revslider_data_weather_text' => RevAddOnWeatherYahoo::condition_lang($revslider_weather->query->results->channel->item->forecast[0]->text),
'revslider_data_weather_humidity' => $revslider_weather->query->results->channel->atmosphere->humidity,
'revslider_data_weather_pressure' => $revslider_weather->query->results->channel->atmosphere->pressure,
'revslider_data_weather_rising' => $revslider_weather->query->results->channel->atmosphere->rising,
'revslider_data_weather_visbility' => $revslider_weather->query->results->channel->atmosphere->visibility,
'revslider_data_weather_sunrise' => $revslider_weather->query->results->channel->astronomy->sunrise,
'revslider_data_weather_sunset' => $revslider_weather->query->results->channel->astronomy->sunset,
'revslider_data_weather_city' => $revslider_weather->query->results->channel->location->city,
'revslider_data_weather_country' => $revslider_weather->query->results->channel->location->country,
'revslider_data_weather_region' => $revslider_weather->query->results->channel->location->region,
'revslider_data_weather_updated' => $revslider_weather->query->results->channel->item->pubDate,
'revslider_data_weather_link' => $revslider_weather->query->results->channel->item->link,
'revslider_data_weather_thumbnail' => $revslider_weather->query->results->channel->item->forecast[0]->code . 'ds.png',
'revslider_data_weather_image' => $revslider_weather->query->results->channel->item->forecast[0]->code . 'd.png',
'revslider_data_weather_units_temp' => $revslider_weather->query->results->channel->units->temperature,
'revslider_data_weather_units_distance' => $revslider_weather->query->results->channel->units->distance,
'revslider_data_weather_units_pressure' => $revslider_weather->query->results->channel->units->pressure,
'revslider_data_weather_units_speed' => $revslider_weather->query->results->channel->units->speed,
'revslider_data_weather_wind_chill' => $revslider_weather->query->results->channel->wind->chill,
'revslider_data_weather_wind_direction' => $revslider_weather->query->results->channel->wind->direction,
'revslider_data_weather_wind_speed' => $revslider_weather->query->results->channel->wind->speed,
'revslider_data_weather_alt_temp' => $this->get_alt_temp($revslider_weather->query->results->channel->units->temperature,$revslider_weather->query->results->channel->item->condition->temp),
'revslider_data_weather_alt_high' => $this->get_alt_temp($revslider_weather->query->results->channel->units->temperature,$revslider_weather->query->results->channel->item->forecast[0]->high),
'revslider_data_weather_alt_low' => $this->get_alt_temp($revslider_weather->query->results->channel->units->temperature,$revslider_weather->query->results->channel->item->forecast[0]->low),
'revslider_data_weather_alt_unit' => $revslider_weather->query->results->channel->units->temperature == "F" ? "C" : "F",
'revslider_data_weather_description' => $revslider_weather->query->results->channel->item->description,
'revslider_data_weather_icon' => $revslider_weather->query->results->channel->item->forecast[0]->code
);
}
else {
$values = array(
'revslider_data_weather_title' => $def_value,
'revslider_data_weather_temp' => $def_value,
'revslider_data_weather_code' => $def_value,
'revslider_data_weather_todayCode' => $def_value,
'revslider_data_weather_date' => $def_value,
'revslider_data_weather_day' => $def_value,
'revslider_data_weather_currently' => $def_value,
'revslider_data_weather_high' => $def_value,
'revslider_data_weather_low' => $def_value,
'revslider_data_weather_text' => $def_value,
'revslider_data_weather_humidity' => $def_value,
'revslider_data_weather_pressure' => $def_value,
'revslider_data_weather_rising' => $def_value,
'revslider_data_weather_visbility' => $def_value,
'revslider_data_weather_sunrise' => $def_value,
'revslider_data_weather_sunset' => $def_value,
'revslider_data_weather_city' => $def_value,
'revslider_data_weather_country' => $def_value,
'revslider_data_weather_region' => $def_value,
'revslider_data_weather_updated' => $def_value,
'revslider_data_weather_link' => $def_value,
'revslider_data_weather_thumbnail' => $def_value,
'revslider_data_weather_image' => $def_value,
'revslider_data_weather_units_temp' => $def_value,
'revslider_data_weather_units_distance' => $def_value,
'revslider_data_weather_units_pressure' => $def_value,
'revslider_data_weather_units_speed' => $def_value,
'revslider_data_weather_wind_chill' => $def_value,
'revslider_data_weather_wind_direction' => $def_value,
'revslider_data_weather_wind_speed' => $def_value,
'revslider_data_weather_alt_temp' => $def_value,
'revslider_data_weather_alt_high' => $def_value,
'revslider_data_weather_alt_low' => $def_value,
'revslider_data_weather_alt_unit' => $def_fc,
'revslider_data_weather_description' => $def_value,
'revslider_data_weather_icon' => $def_icon
);
}
//Replace Placeholders on Slide Layers
$record["layers"] = str_replace(
array(
"%weather_title%",
"%weather_temp%",
"%weather_code%",
"%weather_todayCode%",
"%weather_date%",
"%weather_day%",
"%weather_currently%",
"%weather_high%",
"%weather_low%",
"%weather_text%",
"%weather_humidity%",
"%weather_pressure%",
"%weather_rising%",
"%weather_visbility%",
"%weather_sunrise%",
"%weather_sunset%",
"%weather_city%",
"%weather_country%",
"%weather_region%",
"%weather_updated%",
"%weather_link%",
"%weather_thumbnail%",
"%weather_image%",
"%weather_units_temp%",
"%weather_units_distance%",
"%weather_units_pressure%",
"%weather_units_speed%",
"%weather_wind_chill%",
"%weather_wind_direction%",
"%weather_wind_speed%",
"%weather_alt_temp%",
"%weather_alt_high%",
"%weather_alt_low%",
"%weather_alt_unit%",
"%weather_description%",
"%weather_icon%"
),
array(
'<span class=\"revslider-weather-data revslider_data_weather_title\">' . $values['revslider_data_weather_title'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_temp\">' . $values['revslider_data_weather_temp'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_code\">' . $values['revslider_data_weather_code'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_todayCode\">' . $values['revslider_data_weather_todayCode'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_date\">' . $values['revslider_data_weather_date'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_day\">' . $values['revslider_data_weather_day'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_currently\">' . $values['revslider_data_weather_currently'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_high\">' . $values['revslider_data_weather_high'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_low\">' . $values['revslider_data_weather_low'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_text\">' . $values['revslider_data_weather_text'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_humidity\">' . $values['revslider_data_weather_humidity'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_pressure\">' . $values['revslider_data_weather_pressure'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_rising\">' . $values['revslider_data_weather_rising'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_visbility\">' . $values['revslider_data_weather_visbility'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_sunrise\">' . $values['revslider_data_weather_sunrise'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_sunset\">' . $values['revslider_data_weather_sunset'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_city\">' . $values['revslider_data_weather_city'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_country\">' . $values['revslider_data_weather_country'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_region\">' . $values['revslider_data_weather_region'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_updated\">' . $values['revslider_data_weather_updated'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_link\">' . $values['revslider_data_weather_link'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_thumbnail\">' . $values['revslider_data_weather_thumbnail'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_image\">' . $values['revslider_data_weather_image'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_units_temp\">' . $values['revslider_data_weather_units_temp'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_units_distance\">' . $values['revslider_data_weather_units_distance'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_units_pressure\">' . $values['revslider_data_weather_units_pressure'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_units_speed\">' . $values['revslider_data_weather_units_speed'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_wind_chill\">' . $values['revslider_data_weather_wind_chill'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_wind_direction\">' . $values['revslider_data_weather_wind_direction'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_wind_speed\">' . $values['revslider_data_weather_wind_speed'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_alt_temp\">' . $values['revslider_data_weather_alt_temp'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_alt_high\">' . $values['revslider_data_weather_alt_high'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_alt_low\">' . $values['revslider_data_weather_alt_low'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_alt_unit\">' . $values['revslider_data_weather_alt_unit']. '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_description\">' . $values['revslider_data_weather_description'] . '</span>',
'<span class=\"revslider-weather-data revslider_data_weather_icon\"><i class=\"revslider-weather-icon revslider-weather-icon-' . $values['revslider_data_weather_icon'] . '\"></i>' . '</span>'
),
$record["layers"]);
//Check for forecasts
$forecasts = preg_match_all('/\\%weather_.*?_forecast:[0-9]\\%/', $record["layers"], $matches);
if($forecasts){
foreach ($matches as $forecast_array) {
if(is_array($forecast_array)){
foreach ($forecast_array as $forecast) {
$orig_forecast = $forecast;
$forecast = str_replace(array("%","_forecast","weather_"), "", $forecast);
$forecast = explode(":", $forecast);
$what = $forecast[0];
$when = $forecast[1];
if(strpos($what, "alt_") !== false){
$what = str_replace("alt_", "", $what);
$temp = $results ? $revslider_weather->query->results->channel->item->forecast[$when]->$what : $def_value;
$what = $what == "text" ? RevAddOnWeatherYahoo::condition_lang($temp) : $temp;
$fc = $results ? $revslider_weather->query->results->channel->units->temperature : $def_fc;
$record["layers"] = str_replace( $orig_forecast , $this->get_alt_temp( $def_fc , $what ) , $record["layers"] );
}
else{
$what_orig = $what;
switch($what) {
case 'image':
$temp = $results ? $revslider_weather->query->results->channel->item->forecast[$when]->code : $def_value;
$what = 'https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/'. $temp . 'd.png';
break;
case 'thumbnail':
$temp = $results ? $revslider_weather->query->results->channel->item->forecast[$when]->code : $def_value;
$what = 'https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/'. $temp . 'ds.png';
break;
case 'icon':
$temp = $results ? $revslider_weather->query->results->channel->item->forecast[$when]->code : $def_icon;
$what = '<i class=\"revslider-weather-icon revslider-weather-icon-' . $temp . '\"></i>';
break;
case 'text':
$temp = $results ? $revslider_weather->query->results->channel->item->forecast[$when]->$what : $def_value;
$what = RevAddOnWeatherYahoo::condition_lang($revslider_weather->query->results->channel->item->forecast[$when]->$what);
break;
default:
$what = $results ? $revslider_weather->query->results->channel->item->forecast[$when]->$what : $def_value;
}
$what = '<span class=\"revslider-weather-data revslider_weather_'.$what_orig.'_forecast_'.$when.'\">' . $what . '</span>';
$record["layers"] = str_replace($orig_forecast, $what , $record["layers"]);
}
}
}
}
}
return $record;
}
/**
* Get alternative temp unit data
* @since 1.0.0
*/
public function get_alt_temp($unit, $temp) {
if($unit === 'F') {
return $this->fahrenheit_to_celsius($temp);
}
else {
return $this->celsius_to_fahrenheit($temp);
}
}
/**
* Convert Temp Fahrenheit to Celsius
* @since 1.0.0
*/
public function fahrenheit_to_celsius($given_value)
{
$celsius=5/9*($given_value-32);
return $celsius ;
}
/**
* Convert Temp Celsius to Fahrenheit
* @since 1.0.0
*/
public function celsius_to_fahrenheit($given_value)
{
$fahrenheit=$given_value*9/5+32;
return $fahrenheit ;
}
/**
* Ajax Function for refreshing on screen weather data dynamically
* @since 1.0.0
*/
public function revslider_weather_addon_refresh(){
$weather_data = $_POST["weather"]["revslider-weather-addon"];
$weather_data["type"] = sanitize_title( $weather_data["type"] );
$weather_data["name"] = sanitize_title( $weather_data["name"] );
$weather_data["unit"] = sanitize_title( $weather_data["unit"] );
$weather_data["woeid"] = intval( $weather_data["woeid"] );
$revslider_weather = $this->get_weather( $weather_data["type"] , $weather_data["woeid"] , $weather_data["name"] , $weather_data["unit"] );
echo json_encode($revslider_weather);
}
}

View File

@ -1 +0,0 @@
<?php // Silence is golden

View File

@ -1,16 +0,0 @@
<?php
/**
* Provide a public-facing view for the plugin
*
* This file is used to markup the public-facing aspects of the plugin.
*
* @link https://www.themepunch.com
* @since 1.0.0
*
* @package Revslider_Weather_Addon
* @subpackage Revslider_Weather_Addon/public/partials
*/
?>
<!-- This file should primarily consist of HTML with a little bit of PHP. -->