external-sources.class.php
30.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
<?php
/**
* External Sources Input Classes for Back and Front End
* @since: 5.0
**/
if( !defined( 'ABSPATH') ) die();
/**
* Facebook
*
* with help of the API this class delivers album images from Facebook
*
* @package socialstreams
* @subpackage socialstreams/facebook
* @author ThemePunch <info@themepunch.com>
*/
class RevSliderFacebook {
/**
* Stream Array
*
* @since 1.0.0
* @access private
* @var array $stream Stream Data Array
*/
private $stream;
/**
* Transient seconds
*
* @since 1.0.0
* @access private
* @var number $transient Transient time in seconds
*/
private $transient_sec;
public function __construct($transient_sec = 1200) {
$this->transient_sec = $transient_sec;
}
/**
* 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 trim($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,$app_id,$app_secret){
//photoset params
$oauth = wp_remote_fopen("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=".$app_id."&client_secret=".$app_secret);
$url = "https://graph.facebook.com/$user_id/albums?".$oauth;
$photo_sets_list = json_decode(wp_remote_fopen($url));
//echo '<pre>';
//print_r($photo_sets_list);
//echo '</pre>';
if(isset($photo_sets_list->data))
return $photo_sets_list->data;
else return '';
}
/**
* 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,$app_id,$app_secret){
$oauth = wp_remote_fopen("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=".$app_id."&client_secret=".$app_secret);
$url = "https://graph.facebook.com/$photo_set_id?fields=photos&".$oauth;
$transient_name = 'revslider_' . md5($url);
if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
return ($data);
$photo_set_photos = json_decode(wp_remote_fopen($url));
if(isset($photo_set_photos->photos->data)){
set_transient( $transient_name, $photo_set_photos->photos->data, $this->transient_sec );
return $photo_set_photos->photos->data;
}
else return '';
}
/**
* Get Photosets List from User as Options for Selectbox
*
* @since 1.0.0
* @param string $user_url Facebook User id (not name)
* @param int $item_count number of photos to pull
*/
public function get_photo_set_photos_options($user_url,$current_album,$app_id,$app_secret,$item_count=99){
$user_id = $this->get_user_from_url($user_url);
$photo_sets = $this->get_photo_sets($user_id,999,$app_id,$app_secret);
if(empty($current_album)) $current_album = "";
$return = array();
if(is_array($photo_sets)){
foreach($photo_sets as $photo_set){
$return[] = '<option title="'.$photo_set->name.'" '.selected( $photo_set->id , $current_album , false ).' value="'.$photo_set->id.'">'.$photo_set->name.'</option>"';
}
}
return $return;
}
/**
* Get Feed
*
* @since 1.0.0
* @param string $user User ID
* @param int $item_count number of itmes to pull
*/
public function get_photo_feed($user,$app_id,$app_secret,$item_count=10){
$oauth = wp_remote_fopen("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;
$transient_name = 'revslider_' . md5($url);
if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
return ($data);
$feed = json_decode(wp_remote_fopen($url));
if(isset($feed->data)){
set_transient( $transient_name, $feed->data, $this->transient_sec );
return $feed->data;
}
else return '';
}
/**
* Decode URL from feed
*
* @since 1.0.0
* @param string $url facebook Output Data
*/
private 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;
}
} // End Class
/**
* 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 RevSliderTwitter {
/**
* 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;
/**
* Twitter Account
*
* @since 1.0.0
* @access private
* @var string $twitter_account Account User Name
*/
private $twitter_account;
/**
* Transient seconds
*
* @since 1.0.0
* @access private
* @var number $transient Transient time in seconds
*/
private $transient_sec;
/**
* Stream Array
*
* @since 1.0.0
* @access private
* @var array $stream Stream Data Array
*/
private $stream;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $consumer_key Twitter App Registration Consomer Key
* @param string $consumer_secret Twitter App Registration Consomer Secret
* @param string $access_token Twitter App Registration Access Token
* @param string $access_token_secret Twitter App Registration Access Token Secret
*/
public function __construct($consumer_key,$consumer_secret,$access_token,$access_token_secret,$transient_sec = 1200) {
$this->consumer_key = $consumer_key;
$this->consumer_secret = $consumer_secret;
$this->access_token = $access_token;
$this->access_token_secret = $access_token_secret;
$this->transient_sec = $transient_sec;
}
/**
* Get Tweets
*
* @since 1.0.0
* @param string $twitter_account Twitter account without trailing @ char
*/
public function get_public_photos($twitter_account,$include_rts,$exclude_replies,$count,$imageonly){
//require_once( 'class-wp-twitter-api.php' );
// Set your personal data retrieved at https://dev.twitter.com/apps
$credentials = array(
'consumer_key' => $this->consumer_key,
'consumer_secret' => $this->consumer_secret
);
// Let's instantiate our class with our credentials
$twitter_api = new RevSliderTwitterApi( $credentials , $this->transient_sec);
$include_rts = $include_rts=="on" ? "true" : "false";
$exclude_replies = $include_rts=="on" ? "false" : "true";
$query = 'count=500&include_entities=true&include_rts='.$include_rts.'&exclude_replies='.$exclude_replies.'&screen_name='.$twitter_account;
$tweets = $twitter_api->query( $query );
if(!empty($tweets)){
return $tweets;
}
else return '';
}
/**
* Find Key in array and return value (multidim array possible)
*
* @since 1.0.0
* @param string $key Needle
* @param array $form Haystack
*/
public function array_find_element_by_key($key, $form) {
if (is_array($form) && array_key_exists($key, $form)) {
$ret = $form[$key];
return $ret;
}
if(is_array($form))
foreach ($form as $k => $v) {
if (is_array($v)) {
$ret = $this->array_find_element_by_key($key, $form[$k]);
if ($ret) {
return $ret;
}
}
}
return FALSE;
}
} // End Class
/**
* Class WordPress Twitter API
*
* https://github.com/micc83/Twitter-API-1.1-Client-for-Wordpress/blob/master/class-wp-twitter-api.php
* @version 1.0.0
*/
class RevSliderTwitterApi {
var $bearer_token,
// Default credentials
$args = array(
'consumer_key' => 'default_consumer_key',
'consumer_secret' => 'default_consumer_secret'
),
// Default type of the resource and cache duration
$query_args = array(
'type' => 'statuses/user_timeline',
'cache' => 1800
),
$has_error = false;
/**
* WordPress Twitter API Constructor
*
* @param array $args
*/
public function __construct( $args = array() , $transient_sec = 1200 ) {
if ( is_array( $args ) && !empty( $args ) )
$this->args = array_merge( $this->args, $args );
if ( ! $this->bearer_token = get_option( 'twitter_bearer_token' ) )
$this->bearer_token = $this->get_bearer_token();
$this->query_args['cache'] = $transient_sec;
}
/**
* Get the token from oauth Twitter API
*
* @return string Oauth Token
*/
private function get_bearer_token() {
$bearer_token_credentials = $this->args['consumer_key'] . ':' . $this->args['consumer_secret'];
$bearer_token_credentials_64 = base64_encode( $bearer_token_credentials );
$args = array(
'method' => 'POST',
'timeout' => 5,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(
'Authorization' => 'Basic ' . $bearer_token_credentials_64,
'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8',
'Accept-Encoding' => 'gzip'
),
'body' => array( 'grant_type' => 'client_credentials' ),
'cookies' => array()
);
$response = wp_remote_post( 'https://api.twitter.com/oauth2/token', $args );
if ( is_wp_error( $response ) || 200 != $response['response']['code'] )
return $this->bail( __( 'Can\'t get the bearer token, check your credentials', 'wp_twitter_api' ), $response );
$result = json_decode( $response['body'] );
update_option( 'twitter_bearer_token', $result->access_token );
return $result->access_token;
}
/**
* Query twitter's API
*
* @uses $this->get_bearer_token() to retrieve token if not working
*
* @param string $query Insert the query in the format "count=1&include_entities=true&include_rts=true&screen_name=micc1983!
* @param array $query_args Array of arguments: Resource type (string) and cache duration (int)
* @param bool $stop Stop the query to avoid infinite loop
*
* @return bool|object Return an object containing the result
*/
public function query( $query, $query_args = array(), $stop = false ) {
if ( $this->has_error )
return false;
if ( is_array( $query_args ) && !empty( $query_args ) )
$this->query_args = array_merge( $this->query_args, $query_args );
$transient_name = 'wta_' . md5( $query );
if ($this->query_args['cache'] > 0 && false !== ( $data = get_transient( $transient_name ) ) )
return json_decode( $data );
$args = array(
'method' => 'GET',
'timeout' => 5,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(
'Authorization' => 'Bearer ' . $this->bearer_token,
'Accept-Encoding' => 'gzip'
),
'body' => null,
'cookies' => array()
);
$response = wp_remote_get( 'https://api.twitter.com/1.1/' . $this->query_args['type'] . '.json?' . $query, $args );
if ( is_wp_error( $response ) || 200 != $response['response']['code'] ){
if ( !$stop ){
$this->bearer_token = $this->get_bearer_token();
return $this->query( $query, $this->query_args, true );
} else {
return $this->bail( __( 'Bearer Token is good, check your query', 'wp_twitter_api' ), $response );
}
}
set_transient( $transient_name, $response['body'], $this->query_args['cache'] );
return json_decode( $response['body'] );
}
/**
* Let's manage errors
*
* WP_DEBUG has to be set to true to show errors
*
* @param string $error_text Error message
* @param string $error_object Server response or wp_error
*/
private function bail( $error_text, $error_object = '' ) {
$this->has_error = true;
if ( is_wp_error( $error_object ) ){
$error_text .= ' - Wp Error: ' . $error_object->get_error_message();
} elseif ( !empty( $error_object ) && isset( $error_object['response']['message'] ) ) {
$error_text .= ' ( Response: ' . $error_object['response']['message'] . ' )';
}
trigger_error( $error_text , E_USER_NOTICE );
}
}
/**
* 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 RevSliderInstagram {
/**
* API key
*
* @since 1.0.0
* @access private
* @var string $api_key Instagram API key
*/
private $api_key;
/**
* Stream Array
*
* @since 1.0.0
* @access private
* @var array $stream Stream Data Array
*/
private $stream;
/**
* Transient seconds
*
* @since 1.0.0
* @access private
* @var number $transient Transient time in seconds
*/
private $transient_sec;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $api_key Instagram API key.
*/
public function __construct($api_key,$transient_sec=1200) {
$this->api_key = $api_key;
$this->transient_sec = $transient_sec;
}
/**
* Get Instagram Pictures
*
* @since 1.0.0
* @param string $user_id Instagram User id (not name)
*/
public function get_public_photos($search_user_id,$count){
//call the API and decode the response
$url = "https://api.instagram.com/v1/users/".$search_user_id."/media/recent?count=".$count."&access_token=".$this->api_key."&client_id=".$search_user_id;
$transient_name = 'revslider_' . md5($url);
if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
return ($data);
$rsp = json_decode(wp_remote_fopen($url));
if(isset($rsp->data)){
set_transient( $transient_name, $rsp->data, $this->transient_sec );
return $rsp->data;
}
else return '';
}
} // End Class
/**
* 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 RevSliderFlickr {
/**
* 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;
/**
* Stream Array
*
* @since 1.0.0
* @access private
* @var array $stream Stream Data Array
*/
private $stream;
/**
* Basic URL
*
* @since 1.0.0
* @access private
* @var string $url Url to fetch user from
*/
private $flickr_url;
/**
* Transient seconds
*
* @since 1.0.0
* @access private
* @var number $transient Transient time in seconds
*/
private $transient_sec;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $api_key flickr API key.
*/
public function __construct($api_key,$transient_sec=1200) {
$this->api_key = $api_key;
$this->api_param_defaults = array(
'api_key' => $this->api_key,
'format' => 'json',
'nojsoncallback' => 1,
);
$this->transient_sec = $transient_sec;
}
/**
* 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);
$transient_name = 'revslider_' . md5($url);
if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
return ($data);
$rsp = json_decode(file_get_contents($url));
if(isset($rsp)){
set_transient( $transient_name, $rsp, $this->transient_sec );
return $rsp;
}
else return '';
}
/**
* 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);
if(isset($user_info->user->id))
return $user_info->user->id;
else return '';
}
/**
* 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);
if(isset($group_info->group->id))
return $group_info->group->id;
else return '';
}
/**
* 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);
if(isset($public_photos_list->photos->photo))
return $public_photos_list->photos->photo;
else return '';
}
/**
* 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,$current_photoset){
//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 = array();
foreach($photo_sets_list->photosets->photoset as $photo_set){
if(empty($photo_set->title->_content)) $photo_set->title->_content = "";
if(empty($photo_set->photos)) $photo_set->photos = 0;
$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>"';
}
return $return;
}
/**
* 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
$this->stream = array();
$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);
if(isset($photo_set_photos->photoset->photo))
return $photo_set_photos->photoset->photo;
else return '';
}
/**
* 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);
if(isset($group_pool_photos->photos->photo))
return $group_pool_photos->photos->photo;
else
return '';
}
/**
* 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);
if(isset($gallery_info->gallery->id))
return $gallery_info->gallery->id;
else return '';
}
/**
* 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);
if(isset($gallery_photos_list->photos->photo))
return $gallery_photos_list->photos->photo;
else return '';
}
/**
* Encode the flickr ID for URL (base58)
*
* @since 1.0.0
* @param string $num flickr photo id
*/
private 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;
}
} // End Class
/**
* 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 RevSliderYoutube {
/**
* 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;
/**
* Stream Array
*
* @since 1.0.0
* @access private
* @var array $stream Stream Data Array
*/
private $stream;
/**
* Transient seconds
*
* @since 1.0.0
* @access private
* @var number $transient Transient time in seconds
*/
private $transient_sec;
/**
* 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,$transient_sec=1200) {
$this->api_key = $api_key;
$this->channel_id = $channel_id;
$this->transient_sec = $transient_sec;
}
/**
* 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(wp_remote_fopen($url));
if(isset($rsp->items)){
return $rsp->items;
}else{
return false;
}
}
/**
* 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
if(empty($count)) $count = 50;
$url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=".$playlist_id."&maxResults=".$count."&fields=items%2Fsnippet&key=".$this->api_key;
$transient_name = 'revslider_' . md5($url);
if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
return ($data);
$rsp = json_decode(wp_remote_fopen($url));
set_transient( $transient_name, $rsp->items, $this->transient_sec );
return $rsp->items;
}
/**
* Get Youtube Channel Items
*
* @since 1.0.0
* @param integer $count Max videos count
*/
public function show_channel_videos($count=50){
if(empty($count)) $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";
$transient_name = 'revslider_' . md5($url);
if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
return ($data);
$rsp = json_decode(wp_remote_fopen($url));
set_transient( $transient_name, $rsp->items, $this->transient_sec );
return $rsp->items;
}
/**
* Get Playlists from Channel as Options for Selectbox
*
* @since 1.0.0
*/
public function get_playlist_options($current_playlist){
$return = array();
$playlists = $this->get_playlists();
if(!empty($playlists)){
foreach($playlists as $playlist){
$return[] = '<option title="'.$playlist->snippet->description.'" '.selected( $playlist->id , $current_playlist , false ).' value="'.$playlist->id.'">'.$playlist->snippet->title.'</option>"';
}
}
return $return;
}
} // End Class
/**
* 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 RevSliderVimeo {
/**
* Stream Array
*
* @since 1.0.0
* @access private
* @var array $stream Stream Data Array
*/
private $stream;
/**
* Transient seconds
*
* @since 1.0.0
* @access private
* @var number $transient Transient time in seconds
*/
private $transient_sec;
/**
* Initialize the class and set its properties.
*
* @since 1.0.0
* @param string $api_key Youtube API key.
*/
public function __construct($transient_sec=1200) {
$this->transient_sec = $transient_sec;
}
/**
* 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";
}
$transient_name = 'revslider_' . md5($url);
if ($this->transient_sec > 0 && false !== ($data = get_transient( $transient_name)))
return ($data);
$rsp = json_decode(wp_remote_fopen($url));
set_transient( $transient_name, $rsp, $this->transient_sec );
return $rsp;
}
} // End Class
?>