external-sources.class.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  1. <?php
  2. /**
  3. * External Sources Input Classes for Back and Front End
  4. * @since: 5.0
  5. **/
  6. if( !defined( 'ABSPATH') ) die();
  7. /**
  8. * Facebook
  9. *
  10. * with help of the API this class delivers album images from Facebook
  11. *
  12. * @package socialstreams
  13. * @subpackage socialstreams/facebook
  14. * @author ThemePunch <info@themepunch.com>
  15. */
  16. class RevSliderFacebook {
  17. /**
  18. * Stream Array
  19. *
  20. * @since 1.0.0
  21. * @access private
  22. * @var array $stream Stream Data Array
  23. */
  24. private $stream;
  25. /**
  26. * Transient seconds
  27. *
  28. * @since 1.0.0
  29. * @access private
  30. * @var number $transient Transient time in seconds
  31. */
  32. private $transient_sec;
  33. public function __construct($transient_sec = 1200) {
  34. $this->transient_sec = $transient_sec;
  35. }
  36. /**
  37. * Get User ID from its URL
  38. *
  39. * @since 1.0.0
  40. * @param string $user_url URL of the Page
  41. */
  42. public function get_user_from_url($user_url){
  43. $theid = str_replace("https", "", $user_url);
  44. $theid = str_replace("http", "", $theid);
  45. $theid = str_replace("://", "", $theid);
  46. $theid = str_replace("www.", "", $theid);
  47. $theid = str_replace("facebook", "", $theid);
  48. $theid = str_replace(".com", "", $theid);
  49. $theid = str_replace("/", "", $theid);
  50. $theid = explode("?", $theid);
  51. return trim($theid[0]);
  52. }
  53. /**
  54. * Get Photosets List from User
  55. *
  56. * @since 1.0.0
  57. * @param string $user_id Facebook User id (not name)
  58. * @param int $item_count number of photos to pull
  59. */
  60. public function get_photo_sets($user_id,$item_count=10,$app_id,$app_secret){
  61. //photoset params
  62. $oauth = wp_remote_fopen("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=".$app_id."&client_secret=".$app_secret);
  63. $oauth = json_decode($oauth);
  64. $url = "https://graph.facebook.com/$user_id/albums?access_token=".$oauth->access_token;
  65. $photo_sets_list = json_decode(wp_remote_fopen($url));
  66. //echo '<pre>';
  67. //print_r($photo_sets_list);
  68. //echo '</pre>';
  69. if(isset($photo_sets_list->data))
  70. return $photo_sets_list->data;
  71. else return '';
  72. }
  73. /**
  74. * Get Photoset Photos
  75. *
  76. * @since 5.1.1
  77. * @param string $photo_set_id Photoset ID
  78. * @param int $item_count number of photos to pull
  79. */
  80. public function get_photo_set_photos($photo_set_id,$item_count=10,$app_id,$app_secret){
  81. $oauth = wp_remote_fopen("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=".$app_id."&client_secret=".$app_secret);
  82. $oauth = json_decode($oauth);
  83. $url = "https://graph.facebook.com/$photo_set_id/photos?fields=photos&access_token=".$oauth->access_token."&fields=id,from,message,picture,link,name,icon,privacy,type,status_type,object_id,application,created_time,updated_time,is_hidden,is_expired,comments.limit(1).summary(true),likes.limit(1).summary(true)";
  84. $transient_name = 'revslider_' . md5($url);
  85. if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
  86. return ($data);
  87. $photo_set_photos = json_decode(wp_remote_fopen($url));
  88. /*
  89. echo '<pre>';
  90. print_r($photo_set_photos);
  91. echo '</pre>';
  92. */
  93. if(isset($photo_set_photos->data)){
  94. set_transient( $transient_name, $photo_set_photos->data, $this->transient_sec );
  95. return $photo_set_photos->data;
  96. }
  97. else return '';
  98. }
  99. /**
  100. * Get Photosets List from User as Options for Selectbox
  101. *
  102. * @since 1.0.0
  103. * @param string $user_url Facebook User id (not name)
  104. * @param int $item_count number of photos to pull
  105. */
  106. public function get_photo_set_photos_options($user_url,$current_album,$app_id,$app_secret,$item_count=99){
  107. $user_id = $this->get_user_from_url($user_url);
  108. $photo_sets = $this->get_photo_sets($user_id,999,$app_id,$app_secret);
  109. if(empty($current_album)) $current_album = "";
  110. $return = array();
  111. if(is_array($photo_sets)){
  112. foreach($photo_sets as $photo_set){
  113. $return[] = '<option title="'.$photo_set->name.'" '.selected( $photo_set->id , $current_album , false ).' value="'.$photo_set->id.'">'.$photo_set->name.'</option>"';
  114. }
  115. }
  116. return $return;
  117. }
  118. /**
  119. * Get Feed
  120. *
  121. * @since 1.0.0
  122. * @param string $user User ID
  123. * @param int $item_count number of itmes to pull
  124. */
  125. public function get_photo_feed($user,$app_id,$app_secret,$item_count=10){
  126. $oauth = wp_remote_fopen("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=".$app_id."&client_secret=".$app_secret);
  127. $oauth = json_decode($oauth);
  128. $url = "https://graph.facebook.com/$user/feed?access_token=".$oauth->access_token."&fields=id,from,message,picture,link,name,icon,privacy,type,status_type,object_id,application,created_time,updated_time,is_hidden,is_expired,comments.limit(1).summary(true),likes.limit(1).summary(true)";
  129. $transient_name = 'revslider_' . md5($url);
  130. if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
  131. return ($data);
  132. $feed = json_decode(wp_remote_fopen($url));
  133. if(isset($feed->data)){
  134. set_transient( $transient_name, $feed->data, $this->transient_sec );
  135. return $feed->data;
  136. }
  137. else return '';
  138. }
  139. /**
  140. * Decode URL from feed
  141. *
  142. * @since 1.0.0
  143. * @param string $url facebook Output Data
  144. */
  145. private function decode_facebook_url($url) {
  146. $url = str_replace('u00253A',':',$url);
  147. $url = str_replace('\u00255C\u00252F','/',$url);
  148. $url = str_replace('u00252F','/',$url);
  149. $url = str_replace('u00253F','?',$url);
  150. $url = str_replace('u00253D','=',$url);
  151. $url = str_replace('u002526','&',$url);
  152. return $url;
  153. }
  154. } // End Class
  155. /**
  156. * Twitter
  157. *
  158. * with help of the API this class delivers all kind of tweeted images from twitter
  159. *
  160. * @package socialstreams
  161. * @subpackage socialstreams/twitter
  162. * @author ThemePunch <info@themepunch.com>
  163. */
  164. class RevSliderTwitter {
  165. /**
  166. * Consumer Key
  167. *
  168. * @since 1.0.0
  169. * @access private
  170. * @var string $consumer_key Consumer Key
  171. */
  172. private $consumer_key;
  173. /**
  174. * Consumer Secret
  175. *
  176. * @since 1.0.0
  177. * @access private
  178. * @var string $consumer_secret Consumer Secret
  179. */
  180. private $consumer_secret;
  181. /**
  182. * Access Token
  183. *
  184. * @since 1.0.0
  185. * @access private
  186. * @var string $access_token Access Token
  187. */
  188. private $access_token;
  189. /**
  190. * Access Token Secret
  191. *
  192. * @since 1.0.0
  193. * @access private
  194. * @var string $access_token_secret Access Token Secret
  195. */
  196. private $access_token_secret;
  197. /**
  198. * Twitter Account
  199. *
  200. * @since 1.0.0
  201. * @access private
  202. * @var string $twitter_account Account User Name
  203. */
  204. private $twitter_account;
  205. /**
  206. * Transient seconds
  207. *
  208. * @since 1.0.0
  209. * @access private
  210. * @var number $transient Transient time in seconds
  211. */
  212. private $transient_sec;
  213. /**
  214. * Stream Array
  215. *
  216. * @since 1.0.0
  217. * @access private
  218. * @var array $stream Stream Data Array
  219. */
  220. private $stream;
  221. /**
  222. * Initialize the class and set its properties.
  223. *
  224. * @since 1.0.0
  225. * @param string $consumer_key Twitter App Registration Consomer Key
  226. * @param string $consumer_secret Twitter App Registration Consomer Secret
  227. * @param string $access_token Twitter App Registration Access Token
  228. * @param string $access_token_secret Twitter App Registration Access Token Secret
  229. */
  230. public function __construct($consumer_key,$consumer_secret,$access_token,$access_token_secret,$transient_sec = 1200) {
  231. $this->consumer_key = $consumer_key;
  232. $this->consumer_secret = $consumer_secret;
  233. $this->access_token = $access_token;
  234. $this->access_token_secret = $access_token_secret;
  235. $this->transient_sec = $transient_sec;
  236. }
  237. /**
  238. * Get Tweets
  239. *
  240. * @since 1.0.0
  241. * @param string $twitter_account Twitter account without trailing @ char
  242. */
  243. public function get_public_photos($twitter_account,$include_rts,$exclude_replies,$count,$imageonly){
  244. //require_once( 'class-wp-twitter-api.php' );
  245. // Set your personal data retrieved at https://dev.twitter.com/apps
  246. $credentials = array(
  247. 'consumer_key' => $this->consumer_key,
  248. 'consumer_secret' => $this->consumer_secret
  249. );
  250. // Let's instantiate our class with our credentials
  251. $twitter_api = new RevSliderTwitterApi( $credentials , $this->transient_sec);
  252. $include_rts = $include_rts=="on" ? "true" : "false";
  253. $exclude_replies = $include_rts=="on" ? "false" : "true";
  254. $query = '&tweet_mode=extended&count=500&include_entities=true&include_rts='.$include_rts.'&exclude_replies='.$exclude_replies.'&screen_name='.$twitter_account;
  255. $tweets = $twitter_api->query( $query );
  256. if(!empty($tweets)){
  257. return $tweets;
  258. }
  259. else return '';
  260. }
  261. /**
  262. * Find Key in array and return value (multidim array possible)
  263. *
  264. * @since 1.0.0
  265. * @param string $key Needle
  266. * @param array $form Haystack
  267. */
  268. public function array_find_element_by_key($key, $form) {
  269. if (is_array($form) && array_key_exists($key, $form)) {
  270. $ret = $form[$key];
  271. return $ret;
  272. }
  273. if(is_array($form))
  274. foreach ($form as $k => $v) {
  275. if (is_array($v)) {
  276. $ret = $this->array_find_element_by_key($key, $form[$k]);
  277. if ($ret) {
  278. return $ret;
  279. }
  280. }
  281. }
  282. return FALSE;
  283. }
  284. } // End Class
  285. /**
  286. * Class WordPress Twitter API
  287. *
  288. * https://github.com/micc83/Twitter-API-1.1-Client-for-Wordpress/blob/master/class-wp-twitter-api.php
  289. * @version 1.0.0
  290. */
  291. class RevSliderTwitterApi {
  292. var $bearer_token,
  293. // Default credentials
  294. $args = array(
  295. 'consumer_key' => 'default_consumer_key',
  296. 'consumer_secret' => 'default_consumer_secret'
  297. ),
  298. // Default type of the resource and cache duration
  299. $query_args = array(
  300. 'type' => 'statuses/user_timeline',
  301. 'cache' => 1800
  302. ),
  303. $has_error = false;
  304. /**
  305. * WordPress Twitter API Constructor
  306. *
  307. * @param array $args
  308. */
  309. public function __construct( $args = array() , $transient_sec = 1200 ) {
  310. if ( is_array( $args ) && !empty( $args ) )
  311. $this->args = array_merge( $this->args, $args );
  312. if ( ! $this->bearer_token = get_option( 'twitter_bearer_token' ) )
  313. $this->bearer_token = $this->get_bearer_token();
  314. $this->query_args['cache'] = $transient_sec;
  315. }
  316. /**
  317. * Get the token from oauth Twitter API
  318. *
  319. * @return string Oauth Token
  320. */
  321. private function get_bearer_token() {
  322. $bearer_token_credentials = $this->args['consumer_key'] . ':' . $this->args['consumer_secret'];
  323. $bearer_token_credentials_64 = base64_encode( $bearer_token_credentials );
  324. $args = array(
  325. 'method' => 'POST',
  326. 'timeout' => 5,
  327. 'redirection' => 5,
  328. 'httpversion' => '1.0',
  329. 'blocking' => true,
  330. 'headers' => array(
  331. 'Authorization' => 'Basic ' . $bearer_token_credentials_64,
  332. 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8',
  333. 'Accept-Encoding' => 'gzip'
  334. ),
  335. 'body' => array( 'grant_type' => 'client_credentials' ),
  336. 'cookies' => array()
  337. );
  338. $response = wp_remote_post( 'https://api.twitter.com/oauth2/token', $args );
  339. if ( is_wp_error( $response ) || 200 != $response['response']['code'] )
  340. return $this->bail( __( 'Can\'t get the bearer token, check your credentials', 'wp_twitter_api' ), $response );
  341. $result = json_decode( $response['body'] );
  342. update_option( 'twitter_bearer_token', $result->access_token );
  343. return $result->access_token;
  344. }
  345. /**
  346. * Query twitter's API
  347. *
  348. * @uses $this->get_bearer_token() to retrieve token if not working
  349. *
  350. * @param string $query Insert the query in the format "count=1&include_entities=true&include_rts=true&screen_name=micc1983!
  351. * @param array $query_args Array of arguments: Resource type (string) and cache duration (int)
  352. * @param bool $stop Stop the query to avoid infinite loop
  353. *
  354. * @return bool|object Return an object containing the result
  355. */
  356. public function query( $query, $query_args = array(), $stop = false ) {
  357. if ( $this->has_error )
  358. return false;
  359. if ( is_array( $query_args ) && !empty( $query_args ) )
  360. $this->query_args = array_merge( $this->query_args, $query_args );
  361. $transient_name = 'wta_' . md5( $query );
  362. if ($this->query_args['cache'] > 0 && false !== ( $data = get_transient( $transient_name ) ) )
  363. return json_decode( $data );
  364. $args = array(
  365. 'method' => 'GET',
  366. 'timeout' => 5,
  367. 'redirection' => 5,
  368. 'httpversion' => '1.0',
  369. 'blocking' => true,
  370. 'headers' => array(
  371. 'Authorization' => 'Bearer ' . $this->bearer_token,
  372. 'Accept-Encoding' => 'gzip'
  373. ),
  374. 'body' => null,
  375. 'cookies' => array()
  376. );
  377. $response = wp_remote_get( 'https://api.twitter.com/1.1/' . $this->query_args['type'] . '.json?' . $query, $args );
  378. if ( is_wp_error( $response ) || 200 != $response['response']['code'] ){
  379. if ( !$stop ){
  380. $this->bearer_token = $this->get_bearer_token();
  381. return $this->query( $query, $this->query_args, true );
  382. } else {
  383. return $this->bail( __( 'Bearer Token is good, check your query', 'wp_twitter_api' ), $response );
  384. }
  385. }
  386. set_transient( $transient_name, $response['body'], $this->query_args['cache'] );
  387. return json_decode( $response['body'] );
  388. }
  389. /**
  390. * Let's manage errors
  391. *
  392. * WP_DEBUG has to be set to true to show errors
  393. *
  394. * @param string $error_text Error message
  395. * @param string $error_object Server response or wp_error
  396. */
  397. private function bail( $error_text, $error_object = '' ) {
  398. $this->has_error = true;
  399. if ( is_wp_error( $error_object ) ){
  400. $error_text .= ' - Wp Error: ' . $error_object->get_error_message();
  401. } elseif ( !empty( $error_object ) && isset( $error_object['response']['message'] ) ) {
  402. $error_text .= ' ( Response: ' . $error_object['response']['message'] . ' )';
  403. }
  404. trigger_error( $error_text , E_USER_NOTICE );
  405. }
  406. }
  407. /**
  408. * Instagram
  409. *
  410. * with help of the API this class delivers all kind of Images from instagram
  411. *
  412. * @package socialstreams
  413. * @subpackage socialstreams/instagram
  414. * @author ThemePunch <info@themepunch.com>
  415. */
  416. class RevSliderInstagram {
  417. /**
  418. * API key
  419. *
  420. * @since 1.0.0
  421. * @access private
  422. * @var string $api_key Instagram API key
  423. */
  424. private $api_key;
  425. /**
  426. * Stream Array
  427. *
  428. * @since 1.0.0
  429. * @access private
  430. * @var array $stream Stream Data Array
  431. */
  432. private $stream;
  433. /**
  434. * Transient seconds
  435. *
  436. * @since 1.0.0
  437. * @access private
  438. * @var number $transient Transient time in seconds
  439. */
  440. private $transient_sec;
  441. /**
  442. * Initialize the class and set its properties.
  443. *
  444. * @since 1.0.0
  445. * @param string $api_key Instagram API key.
  446. */
  447. public function __construct($transient_sec=1200) {
  448. $this->transient_sec = $transient_sec;
  449. }
  450. /**
  451. * Get Instagram Pictures Public by User
  452. *
  453. * @since 1.0.0
  454. * @param string $user_id Instagram User id (not name)
  455. */
  456. public function get_public_photos($search_user_id,$count){
  457. if(!empty($search_user_id)){
  458. $url = 'https://www.instagram.com/'.$search_user_id.'/?__a=1';
  459. $transient_name = 'revslider_' . md5($url);
  460. if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
  461. return ($data);
  462. $rsp = json_decode(json_encode($this->getFallbackImages($search_user_id)));
  463. for($i=0;$i<$count;$i++) {
  464. if(isset($rsp->edge_owner_to_timeline_media->edges[$i])){
  465. $return[] = $rsp->edge_owner_to_timeline_media->edges[$i];
  466. }
  467. }
  468. if(isset($return)){
  469. $rsp->edge_owner_to_timeline_media->edges = $return;
  470. set_transient( $transient_name, $return, $this->transient_sec );
  471. return $return;
  472. }
  473. else return '';
  474. }
  475. else return '';
  476. }
  477. /**
  478. * Get user ID if necessary
  479. * @since 5.4.6.3
  480. */
  481. public function get_user_id($search_user_id) {
  482. // $url = 'https://api.instagram.com/v1/users/search?q='.$search_user_id.'&access_token='.$this->api_key;
  483. $url = 'https://www.instagram.com/'.$search_user_id.'/?__a=1';
  484. // check for transient
  485. $transient_name = 'revslider_' . md5($url);
  486. if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
  487. return ($data);
  488. // contact API
  489. $rsp = json_decode(wp_remote_fopen($url));
  490. // set new transient
  491. if(isset($rsp->user->id))
  492. set_transient( $transient_name, $rsp->user->id, 604800 );
  493. // return user id
  494. if(isset($rsp->user->id))
  495. return $rsp->user->id;
  496. else
  497. return false;
  498. }
  499. /**
  500. * Fallback method to get 12 latest photos
  501. * @param String $search_user_id (name of instagram user)
  502. */
  503. private function getFallbackImages($search_user_id) {
  504. //FALLBACK 12 ELEMENTS
  505. $page_res = $this->client_request('get', '/' . $search_user_id . '/');
  506. switch ($page_res['http_code']) {
  507. default:
  508. break;
  509. case 404:
  510. break;
  511. case 200:
  512. $page_data_matches = array();
  513. if (!preg_match('#window\._sharedData\s*=\s*(.*?)\s*;\s*</script>#', $page_res['body'], $page_data_matches)) {
  514. _e('Instagram reports: Parse script error',EG_TEXTDOMAIN);
  515. } else {
  516. $page_data = json_decode($page_data_matches[1], true);
  517. if (!$page_data || empty($page_data['entry_data']['ProfilePage'][0]['graphql']['user'])) {
  518. _e('Instagram reports: Content did not match expected',EG_TEXTDOMAIN);
  519. } else {
  520. $user_data = $page_data['entry_data']['ProfilePage'][0]['graphql']['user'];
  521. if ($user_data['is_private']) {
  522. _e('Instagram reports: Content is private',EG_TEXTDOMAIN);
  523. }
  524. }
  525. }
  526. break;
  527. }
  528. $user_data = $page_data['entry_data']['ProfilePage'][0]['graphql']['user'];
  529. return $user_data;
  530. }
  531. /**
  532. * Cliente request to get 12 instagram photos fallback
  533. * @param unknown $type
  534. * @param unknown $url
  535. * @param unknown $options
  536. * @return number[]|string[]|NULL|number[]|string[]|number[]|unknown[]|string[]|number[]|unknown[]|unknown[][]|string[][]|number[][]|NULL[][]
  537. */
  538. private function client_request($type, $url, $options = null) {
  539. $this->index('client', array(
  540. 'base_url' => 'https://www.instagram.com/',
  541. 'cookie_jar' => array(),
  542. 'headers' => array(
  543. // 'Accept-Encoding' => supports_gz () ? 'gzip' : null,
  544. 'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36',
  545. 'Origin' => 'https://www.instagram.com',
  546. 'Referer' => 'https://www.instagram.com',
  547. 'Connection' => 'close'
  548. )
  549. ));
  550. $client = $this->index('client');
  551. $type = strtoupper($type);
  552. $options = is_array($options) ? $options : array();
  553. $url = (!empty($client['base_url']) ? rtrim($client['base_url'], '/') : '') . $url;
  554. $url_info = parse_url($url);
  555. $scheme = !empty($url_info['scheme']) ? $url_info['scheme'] : '';
  556. $host = !empty($url_info['host']) ? $url_info['host'] : '';
  557. $port = !empty($url_info['port']) ? $url_info['port'] : '';
  558. $path = !empty($url_info['path']) ? $url_info['path'] : '';
  559. $query_str = !empty($url_info['query']) ? $url_info['query'] : '';
  560. if (!empty($options['query'])) {
  561. $query_str = http_build_query($options['query']);
  562. }
  563. $headers = !empty($client['headers']) ? $client['headers'] : array();
  564. if (!empty($options['headers'])) {
  565. $headers = $this->array_merge_assoc($headers, $options['headers']);
  566. }
  567. $headers['Host'] = $host;
  568. $client_cookies = $this->client_get_cookies_list($host);
  569. $cookies = $client_cookies;
  570. if (!empty($options['cookies'])) {
  571. $cookies = $this->array_merge_assoc($cookies, $options['cookies']);
  572. }
  573. if ($cookies) {
  574. $request_cookies_raw = array();
  575. foreach ($cookies as $cookie_name => $cookie_value) {
  576. $request_cookies_raw[] = $cookie_name . '=' . $cookie_value;
  577. }
  578. unset($cookie_name, $cookie_data);
  579. $headers['Cookie'] = implode('; ', $request_cookies_raw);
  580. }
  581. if ($type === 'POST' && !empty($options['data'])) {
  582. $data_str = http_build_query($options['data']);
  583. $headers['Content-Type'] = 'application/x-www-form-urlencoded';
  584. $headers['Content-Length'] = strlen($data_str);
  585. } else {
  586. $data_str = '';
  587. }
  588. $headers_raw_list = array();
  589. foreach ($headers as $header_key => $header_value) {
  590. $headers_raw_list[] = $header_key . ': ' . $header_value;
  591. }
  592. unset($header_key, $header_value);
  593. $transport_error = null;
  594. $curl_support = function_exists('curl_init');
  595. $sockets_support = function_exists('fsockopen');
  596. if (!$curl_support && !$sockets_support) {
  597. log_error('Curl and sockets are not supported on this server');
  598. return array(
  599. 'status' => 0,
  600. 'transport_error' => 'php on web-server does not support curl and sockets'
  601. );
  602. }
  603. if ($curl_support) {
  604. $curl = curl_init();
  605. $curl_options = array(
  606. CURLOPT_RETURNTRANSFER => true,
  607. CURLOPT_HEADER => true,
  608. CURLOPT_URL => $scheme . '://' . $host . $path . (!empty($query_str) ? '?' . $query_str : ''),
  609. CURLOPT_HTTPHEADER => $headers_raw_list,
  610. CURLOPT_SSL_VERIFYPEER => false,
  611. CURLOPT_CONNECTTIMEOUT => 15,
  612. CURLOPT_TIMEOUT => 60,
  613. );
  614. if ($type === 'POST') {
  615. $curl_options[CURLOPT_POST] = true;
  616. $curl_options[CURLOPT_POSTFIELDS] = $data_str;
  617. }
  618. curl_setopt_array($curl, $curl_options);
  619. $response_str = curl_exec($curl);
  620. $curl_info = curl_getinfo($curl);
  621. $curl_error = curl_error($curl);
  622. curl_close($curl);
  623. if ($curl_info['http_code'] === 0) {
  624. log_error('An error occurred while loading data. curl_error: ' . $curl_error);
  625. $transport_error = array('status' => 0, 'transport_error' => 'curl');
  626. if (!$sockets_support) {
  627. return $transport_error;
  628. }
  629. }
  630. }
  631. if (!$curl_support || $transport_error) {
  632. log_error('Trying to load data using sockets');
  633. $headers_str = implode("\r\n", $headers_raw_list);
  634. $out = sprintf("%s %s HTTP/1.1\r\n%s\r\n\r\n%s", $type, $path . (!empty($query_str) ? '?' . $query_str : ''), $headers_str, $data_str);
  635. if ($scheme === 'https') {
  636. $scheme = 'ssl';
  637. $port = !empty($port) ? $port : 443;
  638. }
  639. $scheme = !empty($scheme) ? $scheme . '://' : '';
  640. $port = !empty($port) ? $port : 80;
  641. $sock = @fsockopen($scheme . $host, $port, $err_num, $err_str, 15);
  642. if (!$sock) {
  643. log_error('An error occurred while loading data error_number: ' . $err_num . ', error_number: ' . $err_str);
  644. return array(
  645. 'status' => 0,
  646. 'error_number' => $err_num,
  647. 'error_message' => $err_str,
  648. 'transport_error' => $transport_error ? 'curl and sockets' : 'sockets'
  649. );
  650. }
  651. fwrite($sock, $out);
  652. $response_str = '';
  653. while ($line = fgets($sock, 128)) {
  654. $response_str .= $line;
  655. }
  656. fclose($sock);
  657. }
  658. @list ($response_headers_str, $response_body_encoded, $alt_body_encoded) = explode("\r\n\r\n", $response_str);
  659. if ($alt_body_encoded) {
  660. $response_headers_str = $response_body_encoded;
  661. $response_body_encoded = $alt_body_encoded;
  662. }
  663. $response_body = $response_body_encoded;
  664. $response_headers_raw_list = explode("\r\n", $response_headers_str);
  665. $response_http = array_shift($response_headers_raw_list);
  666. preg_match('#^([^\s]+)\s(\d+)\s([^$]+)$#', $response_http, $response_http_matches);
  667. array_shift($response_http_matches);
  668. list ($response_http_protocol, $response_http_code, $response_http_message) = $response_http_matches;
  669. $response_headers = array();
  670. $response_cookies = array();
  671. foreach ($response_headers_raw_list as $header_row) {
  672. list ($header_key, $header_value) = explode(': ', $header_row, 2);
  673. if (strtolower($header_key) === 'set-cookie') {
  674. $cookie_params = explode('; ', $header_value);
  675. if (empty($cookie_params[0])) {
  676. continue;
  677. }
  678. list ($cookie_name, $cookie_value) = explode('=', $cookie_params[0]);
  679. $response_cookies[$cookie_name] = $cookie_value;
  680. } else {
  681. $response_headers[$header_key] = $header_value;
  682. }
  683. }
  684. unset($header_row, $header_key, $header_value, $cookie_name, $cookie_value);
  685. if ($response_cookies) {
  686. $response_cookies['ig_or'] = 'landscape-primary';
  687. $response_cookies['ig_pr'] = '1';
  688. $response_cookies['ig_vh'] = rand(500, 1000);
  689. $response_cookies['ig_vw'] = rand(1100, 2000);
  690. $client['cookie_jar'][$host] = $this->array_merge_assoc($client_cookies, $response_cookies);
  691. $this->index('client', $client);
  692. }
  693. return array(
  694. 'status' => 1,
  695. 'http_protocol' => $response_http_protocol,
  696. 'http_code' => $response_http_code,
  697. 'http_message' => $response_http_message,
  698. 'headers' => $response_headers,
  699. 'cookies' => $response_cookies,
  700. 'body' => $response_body
  701. );
  702. }
  703. /**
  704. * Helper function for fallback photos function
  705. * @param unknown $domain
  706. * @return unknown
  707. */
  708. private function client_get_cookies_list($domain) {
  709. $client = $this->index('client');
  710. $cookie_jar = $client['cookie_jar'];
  711. return !empty($cookie_jar[$domain]) ? $cookie_jar[$domain] : array();
  712. }
  713. /**
  714. * Helper function for fallback photos function
  715. * @param unknown $key
  716. * @param unknown $value
  717. * @param string $f
  718. * @return NULL|string
  719. */
  720. private function index($key, $value = null, $f = false) {
  721. static $index = array();
  722. if ($value || $f) {
  723. $index[$key] = $value;
  724. }
  725. return !empty($index[$key]) ? $index[$key] : null;
  726. }
  727. /**
  728. * Helper function for fallback photos function
  729. * @return NULL
  730. */
  731. private function array_merge_assoc() {
  732. $mixed = null;
  733. $arrays = func_get_args();
  734. foreach ($arrays as $k => $arr) {
  735. if ($k === 0) {
  736. $mixed = $arr;
  737. continue;
  738. }
  739. $mixed = array_combine(
  740. array_merge(array_keys($mixed), array_keys($arr)),
  741. array_merge(array_values($mixed), array_values($arr))
  742. );
  743. }
  744. return $mixed;
  745. }
  746. /**
  747. * Get Instagram Pictures Public by Tag
  748. *
  749. * @since 1.0.0
  750. * @param string $user_id Instagram User id (not name)
  751. */
  752. public function get_tag_photos($search_tag,$count){
  753. //call the API and decode the response
  754. $url = "https://www.instagram.com/explore/tags/".$search_tag."/?__a=1";
  755. $transient_name = 'revslider_' . md5($url);
  756. /*if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
  757. return ($data);
  758. */
  759. $rsp = json_decode(wp_remote_fopen($url));
  760. for($i=0;$i<$count;$i++) {
  761. $return[] = $rsp->tag->media->nodes[$i];
  762. }
  763. if(isset($rsp->tag->media->nodes)){
  764. $rsp->tag->media->nodes = $return;
  765. set_transient( $transient_name, $rsp->tag->media->nodes, $this->transient_sec );
  766. return $rsp->tag->media->nodes;
  767. }
  768. else return '';
  769. }
  770. } // End Class
  771. /**
  772. * Flickr
  773. *
  774. * with help of the API this class delivers all kind of Images from flickr
  775. *
  776. * @package socialstreams
  777. * @subpackage socialstreams/flickr
  778. * @author ThemePunch <info@themepunch.com>
  779. */
  780. class RevSliderFlickr {
  781. /**
  782. * API key
  783. *
  784. * @since 1.0.0
  785. * @access private
  786. * @var string $api_key flickr API key
  787. */
  788. private $api_key;
  789. /**
  790. * API params
  791. *
  792. * @since 1.0.0
  793. * @access private
  794. * @var array $api_param_defaults Basic params to call with API
  795. */
  796. private $api_param_defaults;
  797. /**
  798. * Stream Array
  799. *
  800. * @since 1.0.0
  801. * @access private
  802. * @var array $stream Stream Data Array
  803. */
  804. private $stream;
  805. /**
  806. * Basic URL
  807. *
  808. * @since 1.0.0
  809. * @access private
  810. * @var string $url Url to fetch user from
  811. */
  812. private $flickr_url;
  813. /**
  814. * Transient seconds
  815. *
  816. * @since 1.0.0
  817. * @access private
  818. * @var number $transient Transient time in seconds
  819. */
  820. private $transient_sec;
  821. /**
  822. * Initialize the class and set its properties.
  823. *
  824. * @since 1.0.0
  825. * @param string $api_key flickr API key.
  826. */
  827. public function __construct($api_key,$transient_sec=1200) {
  828. $this->api_key = $api_key;
  829. $this->api_param_defaults = array(
  830. 'api_key' => $this->api_key,
  831. 'format' => 'json',
  832. 'nojsoncallback' => 1,
  833. );
  834. $this->transient_sec = $transient_sec;
  835. }
  836. /**
  837. * Calls Flicker API with set of params, returns json
  838. *
  839. * @since 1.0.0
  840. * @param array $params Parameter build for API request
  841. */
  842. private function call_flickr_api($params){
  843. //build url
  844. $encoded_params = array();
  845. foreach ($params as $k => $v){
  846. $encoded_params[] = urlencode($k).'='.urlencode($v);
  847. }
  848. //call the API and decode the response
  849. $url = "https://api.flickr.com/services/rest/?".implode('&', $encoded_params);
  850. $transient_name = 'revslider_' . md5($url);
  851. if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
  852. return ($data);
  853. $rsp = json_decode(file_get_contents($url));
  854. if(isset($rsp)){
  855. set_transient( $transient_name, $rsp, $this->transient_sec );
  856. return $rsp;
  857. }
  858. else return '';
  859. }
  860. /**
  861. * Get User ID from its URL
  862. *
  863. * @since 1.0.0
  864. * @param string $user_url URL of the Gallery
  865. */
  866. public function get_user_from_url($user_url){
  867. //gallery params
  868. $user_params = $this->api_param_defaults + array(
  869. 'method' => 'flickr.urls.lookupUser',
  870. 'url' => $user_url,
  871. );
  872. //set User Url
  873. $this->flickr_url = $user_url;
  874. //get gallery info
  875. $user_info = $this->call_flickr_api($user_params);
  876. if(isset($user_info->user->id))
  877. return $user_info->user->id;
  878. else return '';
  879. }
  880. /**
  881. * Get Group ID from its URL
  882. *
  883. * @since 1.0.0
  884. * @param string $group_url URL of the Gallery
  885. */
  886. public function get_group_from_url($group_url){
  887. //gallery params
  888. $group_params = $this->api_param_defaults + array(
  889. 'method' => 'flickr.urls.lookupGroup',
  890. 'url' => $group_url,
  891. );
  892. //set User Url
  893. $this->flickr_url = $group_url;
  894. //get gallery info
  895. $group_info = $this->call_flickr_api($group_params);
  896. if(isset($group_info->group->id))
  897. return $group_info->group->id;
  898. else return '';
  899. }
  900. /**
  901. * Get Public Photos
  902. *
  903. * @since 1.0.0
  904. * @param string $user_id flicker User id (not name)
  905. * @param int $item_count number of photos to pull
  906. */
  907. public function get_public_photos($user_id,$item_count=10){
  908. //public photos params
  909. $public_photo_params = $this->api_param_defaults + array(
  910. 'method' => 'flickr.people.getPublicPhotos',
  911. 'user_id' => $user_id,
  912. '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',
  913. 'per_page'=> $item_count,
  914. 'page' => 1
  915. );
  916. //get photo list
  917. $public_photos_list = $this->call_flickr_api($public_photo_params);
  918. //var_dump($public_photos);
  919. if(isset($public_photos_list->photos->photo))
  920. return $public_photos_list->photos->photo;
  921. else return '';
  922. }
  923. /**
  924. * Get Photosets List from User
  925. *
  926. * @since 1.0.0
  927. * @param string $user_id flicker User id (not name)
  928. * @param int $item_count number of photos to pull
  929. */
  930. public function get_photo_sets($user_id,$item_count=10,$current_photoset){
  931. //photoset params
  932. $photo_set_params = $this->api_param_defaults + array(
  933. 'method' => 'flickr.photosets.getList',
  934. 'user_id' => $user_id,
  935. 'per_page'=> $item_count,
  936. 'page' => 1
  937. );
  938. //get photoset list
  939. $photo_sets_list = $this->call_flickr_api($photo_set_params);
  940. $return = array();
  941. foreach($photo_sets_list->photosets->photoset as $photo_set){
  942. if(empty($photo_set->title->_content)) $photo_set->title->_content = "";
  943. if(empty($photo_set->photos)) $photo_set->photos = 0;
  944. $return[] = '<option title="'.$photo_set->description->_content.'" '.selected( $photo_set->id , $current_photoset , false ).' value="'.$photo_set->id.'">'.$photo_set->title->_content.' ('.$photo_set->photos.' photos)</option>"';
  945. }
  946. return $return;
  947. }
  948. /**
  949. * Get Photoset Photos
  950. *
  951. * @since 1.0.0
  952. * @param string $photo_set_id Photoset ID
  953. * @param int $item_count number of photos to pull
  954. */
  955. public function get_photo_set_photos($photo_set_id,$item_count=10){
  956. //photoset photos params
  957. $this->stream = array();
  958. $photo_set_params = $this->api_param_defaults + array(
  959. 'method' => 'flickr.photosets.getPhotos',
  960. 'photoset_id' => $photo_set_id,
  961. 'per_page' => $item_count,
  962. 'page' => 1,
  963. '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'
  964. );
  965. //get photo list
  966. $photo_set_photos = $this->call_flickr_api($photo_set_params);
  967. if(isset($photo_set_photos->photoset->photo))
  968. return $photo_set_photos->photoset->photo;
  969. else return '';
  970. }
  971. /**
  972. * Get Groop Pool Photos
  973. *
  974. * @since 1.0.0
  975. * @param string $group_id Photoset ID
  976. * @param int $item_count number of photos to pull
  977. */
  978. public function get_group_photos($group_id,$item_count=10){
  979. //photoset photos params
  980. $group_pool_params = $this->api_param_defaults + array(
  981. 'method' => 'flickr.groups.pools.getPhotos',
  982. 'group_id' => $group_id,
  983. 'per_page' => $item_count,
  984. 'page' => 1,
  985. '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'
  986. );
  987. //get photo list
  988. $group_pool_photos = $this->call_flickr_api($group_pool_params);
  989. if(isset($group_pool_photos->photos->photo))
  990. return $group_pool_photos->photos->photo;
  991. else
  992. return '';
  993. }
  994. /**
  995. * Get Gallery ID from its URL
  996. *
  997. * @since 1.0.0
  998. * @param string $gallery_url URL of the Gallery
  999. * @param int $item_count number of photos to pull
  1000. */
  1001. public function get_gallery_from_url($gallery_url){
  1002. //gallery params
  1003. $gallery_params = $this->api_param_defaults + array(
  1004. 'method' => 'flickr.urls.lookupGallery',
  1005. 'url' => $gallery_url,
  1006. );
  1007. //get gallery info
  1008. $gallery_info = $this->call_flickr_api($gallery_params);
  1009. if(isset($gallery_info->gallery->id))
  1010. return $gallery_info->gallery->id;
  1011. else return '';
  1012. }
  1013. /**
  1014. * Get Gallery Photos
  1015. *
  1016. * @since 1.0.0
  1017. * @param string $gallery_id flicker Gallery id (not name)
  1018. * @param int $item_count number of photos to pull
  1019. */
  1020. public function get_gallery_photos($gallery_id,$item_count=10){
  1021. //gallery photos params
  1022. $gallery_photo_params = $this->api_param_defaults + array(
  1023. 'method' => 'flickr.galleries.getPhotos',
  1024. 'gallery_id' => $gallery_id,
  1025. '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',
  1026. 'per_page'=> $item_count,
  1027. 'page' => 1
  1028. );
  1029. //get photo list
  1030. $gallery_photos_list = $this->call_flickr_api($gallery_photo_params);
  1031. if(isset($gallery_photos_list->photos->photo))
  1032. return $gallery_photos_list->photos->photo;
  1033. else return '';
  1034. }
  1035. /**
  1036. * Encode the flickr ID for URL (base58)
  1037. *
  1038. * @since 1.0.0
  1039. * @param string $num flickr photo id
  1040. */
  1041. private function base_encode($num, $alphabet='123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ') {
  1042. $base_count = strlen($alphabet);
  1043. $encoded = '';
  1044. while ($num >= $base_count) {
  1045. $div = $num/$base_count;
  1046. $mod = ($num-($base_count*intval($div)));
  1047. $encoded = $alphabet[$mod] . $encoded;
  1048. $num = intval($div);
  1049. }
  1050. if ($num) $encoded = $alphabet[$num] . $encoded;
  1051. return $encoded;
  1052. }
  1053. } // End Class
  1054. /**
  1055. * Youtube
  1056. *
  1057. * with help of the API this class delivers all kind of Images/Videos from youtube
  1058. *
  1059. * @package socialstreams
  1060. * @subpackage socialstreams/youtube
  1061. * @author ThemePunch <info@themepunch.com>
  1062. */
  1063. class RevSliderYoutube {
  1064. /**
  1065. * API key
  1066. *
  1067. * @since 1.0.0
  1068. * @access private
  1069. * @var string $api_key Youtube API key
  1070. */
  1071. private $api_key;
  1072. /**
  1073. * Channel ID
  1074. *
  1075. * @since 1.0.0
  1076. * @access private
  1077. * @var string $channel_id Youtube Channel ID
  1078. */
  1079. private $channel_id;
  1080. /**
  1081. * Stream Array
  1082. *
  1083. * @since 1.0.0
  1084. * @access private
  1085. * @var array $stream Stream Data Array
  1086. */
  1087. private $stream;
  1088. /**
  1089. * Transient seconds
  1090. *
  1091. * @since 1.0.0
  1092. * @access private
  1093. * @var number $transient Transient time in seconds
  1094. */
  1095. private $transient_sec;
  1096. /**
  1097. * Initialize the class and set its properties.
  1098. *
  1099. * @since 1.0.0
  1100. * @param string $api_key Youtube API key.
  1101. */
  1102. public function __construct($api_key,$channel_id,$transient_sec=1200) {
  1103. $this->api_key = $api_key;
  1104. $this->channel_id = $channel_id;
  1105. $this->transient_sec = $transient_sec;
  1106. }
  1107. /**
  1108. * Get Youtube Playlists
  1109. *
  1110. * @since 1.0.0
  1111. */
  1112. public function get_playlists(){
  1113. //call the API and decode the response
  1114. $url = "https://www.googleapis.com/youtube/v3/playlists?part=snippet&maxResults=50&channelId=".$this->channel_id."&key=".$this->api_key;
  1115. $rsp = json_decode(wp_remote_fopen($url));
  1116. if(isset($rsp->items)){
  1117. return $rsp->items;
  1118. }else{
  1119. return false;
  1120. }
  1121. }
  1122. /**
  1123. * Get Youtube Playlist Items
  1124. *
  1125. * @since 1.0.0
  1126. * @param string $playlist_id Youtube Playlist ID
  1127. * @param integer $count Max videos count
  1128. */
  1129. public function show_playlist_videos($playlist_id,$count=50){
  1130. //call the API and decode the response
  1131. if(empty($count)) $count = 50;
  1132. $url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=".$playlist_id."&maxResults=".$count."&fields=items%2Fsnippet&key=".$this->api_key;
  1133. $transient_name = 'revslider_' . md5($url);
  1134. if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
  1135. return ($data);
  1136. $rsp = json_decode(wp_remote_fopen($url));
  1137. set_transient( $transient_name, $rsp->items, $this->transient_sec );
  1138. return $rsp->items;
  1139. }
  1140. /**
  1141. * Get Youtube Channel Items
  1142. *
  1143. * @since 1.0.0
  1144. * @param integer $count Max videos count
  1145. */
  1146. public function show_channel_videos($count=50){
  1147. if(empty($count)) $count = 50;
  1148. //call the API and decode the response
  1149. $url = "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=".$this->channel_id."&maxResults=".$count."&key=".$this->api_key."&order=date";
  1150. $transient_name = 'revslider_' . md5($url);
  1151. if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
  1152. return ($data);
  1153. $rsp = json_decode(wp_remote_fopen($url));
  1154. set_transient( $transient_name, $rsp->items, $this->transient_sec );
  1155. return $rsp->items;
  1156. }
  1157. /**
  1158. * Get Playlists from Channel as Options for Selectbox
  1159. *
  1160. * @since 1.0.0
  1161. */
  1162. public function get_playlist_options($current_playlist){
  1163. $return = array();
  1164. $playlists = $this->get_playlists();
  1165. if(!empty($playlists)){
  1166. foreach($playlists as $playlist){
  1167. $return[] = '<option title="'.$playlist->snippet->description.'" '.selected( $playlist->id , $current_playlist , false ).' value="'.$playlist->id.'">'.$playlist->snippet->title.'</option>"';
  1168. }
  1169. }
  1170. return $return;
  1171. }
  1172. } // End Class
  1173. /**
  1174. * Vimeo
  1175. *
  1176. * with help of the API this class delivers all kind of Images/Videos from Vimeo
  1177. *
  1178. * @package socialstreams
  1179. * @subpackage socialstreams/vimeo
  1180. * @author ThemePunch <info@themepunch.com>
  1181. */
  1182. class RevSliderVimeo {
  1183. /**
  1184. * Stream Array
  1185. *
  1186. * @since 1.0.0
  1187. * @access private
  1188. * @var array $stream Stream Data Array
  1189. */
  1190. private $stream;
  1191. /**
  1192. * Transient seconds
  1193. *
  1194. * @since 1.0.0
  1195. * @access private
  1196. * @var number $transient Transient time in seconds
  1197. */
  1198. private $transient_sec;
  1199. /**
  1200. * Initialize the class and set its properties.
  1201. *
  1202. * @since 1.0.0
  1203. * @param string $api_key Youtube API key.
  1204. */
  1205. public function __construct($transient_sec=1200) {
  1206. $this->transient_sec = $transient_sec;
  1207. }
  1208. /**
  1209. * Get Vimeo User Videos
  1210. *
  1211. * @since 1.0.0
  1212. */
  1213. public function get_vimeo_videos($type,$value){
  1214. //call the API and decode the response
  1215. if($type=="user"){
  1216. $url = "https://vimeo.com/api/v2/".$value."/videos.json";
  1217. }
  1218. else{
  1219. $url = "https://vimeo.com/api/v2/".$type."/".$value."/videos.json";
  1220. }
  1221. $transient_name = 'revslider_' . md5($url);
  1222. if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
  1223. return ($data);
  1224. $rsp = json_decode(wp_remote_fopen($url));
  1225. set_transient( $transient_name, $rsp, $this->transient_sec );
  1226. return $rsp;
  1227. }
  1228. } // End Class
  1229. ?>