PluginProbe ʕ •ᴥ•ʔ
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress / 4.12.0
Smash Balloon Social Post Feed – Simple Social Feeds for WordPress v4.12.0
4.12.0 4.10.0 4.9.0 4.8.1 trunk 1.0 1.1 1.12.1 1.2.3 1.2.4 1.2.5 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.5.1 1.6.6 1.6.6.1 1.6.6.2 1.6.6.3 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.9.0 1.9.1 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.8.1 1.9.9 1.9.9.1 1.9.9.2 1.9.9.3 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.10 2.11 2.11.1 2.12 2.12.1 2.12.2 2.12.3 2.12.4 2.13 2.14 2.14.1 2.15 2.15.1 2.16 2.16.1 2.17 2.17.1 2.18 2.18.1 2.18.2 2.18.3 2.19 2.19.1 2.19.2 2.19.3 2.2 2.2.1 2.3 2.3.1 2.3.10 2.3.2 2.3.3 2.3.4 2.3.6 2.3.7 2.3.8 2.3.9 2.4 2.4.1 2.4.1.1 2.4.1.2 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5 2.5.1 2.5.2 2.6 2.6.1 2.6.2 2.6.3 2.6.4 2.7 2.7.1 2.7.2 2.8 2.9 2.9.1 4.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.3.0 4.3.1 4.3.2 4.3.3 4.3.4 4.7.5 4.7.6 4.7.7
custom-facebook-feed / inc / Integrations / CFF_Graph_Url.php
custom-facebook-feed / inc / Integrations Last commit date
Analytics 2 weeks ago Divi 2 weeks ago Elementor 2 weeks ago CFF_API_Connect.php 2 weeks ago CFF_Graph_Data.php 2 weeks ago CFF_Graph_Url.php 2 weeks ago CFF_Integration.php 2 weeks ago index.php 2 weeks ago
CFF_Graph_Url.php
189 lines
1 <?php
2
3 /**
4 * The Settings Trait
5 *
6 * @since 4.0
7 */
8
9 namespace CustomFacebookFeed\Integrations;
10
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly.
13 }
14
15
16 class CFF_Graph_Url
17 {
18 /**
19 * Return URL String Depeding on the $feed_type and settings
20 *
21 * @param string $type Call Type (Header or Feed Type).
22 * @param array $settings feed settings.
23 * @since 4.0
24 *
25 * @return mixed|string|boolean
26 */
27 public static function get_url($type, $source_id, $settings = [], $misc_args = [])
28 {
29 if (is_array($source_id) || strpos($source_id, ',') !== false) {
30 $ids = explode(',', $source_id);
31 $source_id = $ids[0];
32 }
33 if (!isset($type) || empty($type)) {
34 return false;
35 }
36 $page_type = $settings['pagetype'];
37 $is_group = ($page_type === 'group') ? true : false;
38
39 $url_builder = [
40 'query' => 'posts',
41 'version' => '23.0',
42 'source_id' => $source_id
43 ];
44
45 switch ($type) {
46 case 'timeline':
47 // Logic to get the Graph query
48 if ($settings['showpostsby'] === 'others' || $is_group) {
49 $url_builder['query'] = 'feed';
50 }
51 if ($settings['showpostsby'] === 'onlyothers' && !$is_group) {
52 $url_builder['query'] = 'visitor_posts';
53 }
54 break;
55 }
56 $misc_args['source_id'] = $source_id;
57 $url_builder['fields'] = CFF_Graph_Url::get_call_type_fields_args($type, $settings, $misc_args);
58 return 'https://graph.facebook.com/v' . $url_builder['version'] . '/' . $url_builder['source_id'] . '/' . $url_builder['query'] . '?' . $url_builder['fields'];
59 }
60
61
62 /**
63 * A List of Common Fields that can be used in different API calls
64 *
65 * @param string $type Call Type (Comment, Likes....).
66 * @param array $settings Feed Settings.
67 * @since 4.0
68 *
69 * @return string
70 */
71 public static function get_common_fields($type, $args = [])
72 {
73 $common_fields = [
74 'comments' => 'comments.summary(true)' . (isset($args['comments_limit']) ? '.limit(' . $args['comments_limit'] . ')' : '') .
75 (isset($args['comments_childs']) ? '{created_time,from{name,id,picture{url},link},id,message,message_tags,attachment,like_count}' : '') .
76 (isset($args['short_comments_childs']) ? '{message,created_time}' : ''),
77 'likes' => 'likes.summary(true)' . (isset($args['likes_limit']) ? '.limit(' . $args['likes_limit'] . ')' : ''),
78 'reactions' => 'reactions.summary(true)' . (isset($args['reactions_limit']) ? '.limit(' . $args['reactions_limit'] . ')' : ''),
79 'from' => 'from{picture,id,name,link}',
80 'attachments' => 'attachments{title' . (!isset($args['salesposts']) || $args['salesposts'] !== 'true' ? ',description' : '') . ',media_type,unshimmed_url,target{id},multi_share_end_card,media{source,image},subattachments}'
81 ];
82 return $common_fields[$type];
83 }
84
85 /**
86 * A list of all API URL args depending on the FeedType
87 *
88 * @param string $type Call Type (Comment, Likes....).
89 * @param array $settings Feed Settings.
90 * @since 4.0
91 *
92 * @return string
93 */
94 public static function get_call_type_fields_args($type, $settings = [], $graph_args = [])
95 {
96 $feed_type_fields = [
97 'timeline' => [
98 'fields' => 'id,updated_time,message,message_tags,story,picture,full_picture,status_type,created_time,backdated_time,shares,call_to_action,privacy' . (!isset($settings['storytags']) || $settings['storytags'] !== 'true' ? ',story_tags' : ''),
99 'common_fields' => [
100 'comments' => [
101 'short_comments_childs' => true
102 ],
103 'from',
104 'attachments'
105 ],
106 'common_args' => [
107 'token', 'limit', 'locale', 'ssl'
108 ]
109 ]
110 ];
111
112 if ($settings['pagetype'] === 'group') {
113 array_merge(
114 $feed_type_fields['timeline']['common_fields'],
115 [
116 'reactions' => [
117 'reactions_limit' => 0
118 ]
119 ]
120 );
121 } else {
122 array_merge(
123 $feed_type_fields['timeline']['common_fields'],
124 [
125 'likes' => [
126 'likes_limit' => 0
127 ]
128 ]
129 );
130 }
131
132 if (!isset($feed_type_fields[$type])) {
133 return false;
134 }
135 $fields_string_arr = [];
136 $fields_args_arr = [];
137 foreach ($feed_type_fields[$type] as $key => $element) {
138 if ($key === 'fields') {
139 array_push($fields_string_arr, $element);
140 }
141 if ($key === 'common_fields') {
142 foreach ($element as $ckey => $value) {
143 $c_type = is_array($value) ? $ckey : $value;
144 $c_value = is_array($value) ? $value : [];
145 array_push($fields_string_arr, CFF_Graph_Url::get_common_fields($c_type, $c_value));
146 }
147 }
148 if ($key === 'common_args') {
149 foreach ($element as $argvalue) {
150 $single_arg = CFF_Graph_Url::get_common_args($argvalue, $graph_args);
151 if (!empty($single_arg)) {
152 array_push($fields_args_arr, $single_arg);
153 }
154 }
155 }
156 }
157 $url_string = '';
158 if (sizeof($fields_string_arr) > 0) {
159 $url_string .= 'fields=' . implode(',', $fields_string_arr);
160 }
161 if (sizeof($fields_args_arr) > 0) {
162 $url_string .= '&' . implode('&', $fields_args_arr);
163 }
164 return $url_string;
165 }
166
167 /**
168 * A List of Common Args
169 *
170 * @param string $type Call Type (Comment, Likes....).
171 * @param array $settings Feed Settings.
172 * @since 4.0
173 *
174 * @return array
175 */
176 public static function get_common_args($type, $args = [])
177 {
178 $token = is_array($args['token']) ? (isset($args['token'][$args['source_id']]) ? $args['token'][$args['source_id']] : '') : $args['token'];
179 $api_call_args = [
180 'token' => 'access_token=' . $token,
181 'limit' => 'limit=' . $args['limit'],
182 'locale' => 'locale=' . $args['locale'],
183 'photos_type' => 'type=uploaded',
184 'ssl' => (is_ssl()) ? 'return_ssl_resources=true' : ''
185 ];
186 return isset($args[$type]) && !empty($args[$type]) ? $api_call_args[$type] : '';
187 }
188 }
189