forked from steve228uk/WordPress-Social-Stream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
93 lines (82 loc) · 2.02 KB
/
functions.php
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
<?php
/**
* Get the posts that make up the social stream
* @return array
*/
function get_social_stream() {
global $ss_stream;
return $ss_stream->fetch();
}
/**
* Render the social stream using the default template
* @return void
*/
function the_social_stream() {
$posts = get_social_stream();
$theme_file = get_stylesheet_directory().'/social_stream.php';
if(file_exists($theme_file)) {
require_once $theme_file;
} else {
require_once __DIR__.'/views/social_stream.php';
}
}
/**
* Pull out the social stream via Ajax
* @return void
*/
function ajax_social_stream() {
require_once __DIR__.'/views/loader.php';
}
/**
* Pull out an array of Twitter posts on their own
* @param int $number Number or twitter posts to pull out
* @return array
*/
function twitter_posts($number) {
global $ss_stream;
$chunks = array_chunk($ss_stream->twitter->fetch()->posts, $number);
return $chunks[0];
}
/**
* Pull out an array of Facebook posts on their own
* @param int $number Number or posts posts to pull out
* @return array
*/
function facebook_posts($number) {
global $ss_stream;
$chunks = array_chunk($ss_stream->facebook->fetch()->posts, $number);
return $chunks[0];
}
/**
* Pull out an array of Instagram posts on their own
* @param int $number Number or posts posts to pull out
* @return array
*/
function instagram_posts($number) {
global $ss_stream;
$chunks = array_chunk($ss_stream->instagram->fetch()->posts, $number);
return $chunks[0];
}
/**
* Fetch the last post from a feed that has an image
* @param string Feed type
* @return array
*/
function fetch_last_posts_with_image($type = 'twitter', $total = 1)
{
global $ss_stream;
$feed = $ss_stream->{$type}->fetch()->posts;
$image_posts = [];
foreach($feed as $item)
{
if($item->post['image'])
{
array_push($image_posts, $item);
}
}
if(!$image_posts)
{
return [];
}
return array_slice($image_posts, 0, $total);
}