YaWK  24.1
Yet another WebKit
YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery Class Reference

Facebook Gallery Widget - grab photos from your Facebook albums. More...

Public Member Functions

 __construct ($db)
 fbGallery constructor. Get widget settings into this->settings array and call checkRequirements More...
 
 checkAccessToken ()
 Check if access token is correctly set. Returns true or abort with an error message. More...
 
 checkAlbumId ()
 Check if album id is correctly set. Returns true or abort with an error message. More...
 
 checkApiObjectData ()
 Check if api object is set and not empty. More...
 
 checkAppId ()
 Check if App ID is set, not empty and numeric. Returns true if app ID is ok or abort with an error message. More...
 
 checkRequirements ()
 Check if all requirements are fulfilled to perform api call. More...
 
 drawGallery ()
 The heart of this widget: this method draws the gallery. More...
 
 loadJSSDK ()
 Load Facebook JS Code. More...
 
 makeApiCall ()
 Prepare object data, set json link, make API call and return apiObject. More...
 

Public Attributes

 $apiObject
 
 $fbGalleryAccessToken = ''
 
 $fbGalleryAlbumId = ''
 
 $fbGalleryAppId = ''
 
 $fbGalleryEndDate = ''
 
 $fbGalleryFields = 'images,source,name,id'
 
 $fbGalleryFixedImageHeight = 'auto'
 
 $fbGalleryGraphRequest = '/albums/'
 
 $fbGalleryHeading = ''
 
 $fbGalleryImageInfo = 1
 
 $fbGalleryLayout = 6
 
 $fbGalleryLimit = 0
 
 $fbGallerySortation = 'desc'
 
 $fbGalleryStartDate = ''
 
 $fbGallerySubtext = ''
 
 $fbGalleryType = 'past'
 
 $fbGalleryYearRange = '10'
 
 $jsSDKLoaded = 'false'
 
 $settings
 
 $shuffle = 0
 
 $sinceDate = ''
 
 $untilDate = ''
 

Detailed Description

Facebook Gallery Widget - grab photos from your Facebook albums.

Use Facebook Graph API to get album photos from a Facebook Page. Requires an App ID and a valid access token.

With this widget, you are able to embed photos from your facebook page onto your website. It helps you to keep your website up to date. Have you ever been bored of adding the same content twice? If you change your facebook photo album the data on your website will be updated automatically.

You need an APP ID, as well as a valid access token for the facebook page you want to embed photos from. For reasons, you (respectively the app id / access token) needs administrative access rights to the facebook page you want to grab photos from. Create a new fb gallery widget in the backend, enter app id, access token and press save widget settings. The page reloads and your albums will get loaded into a select field.

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0

Definition at line 23 of file fbGallery.php.

Constructor & Destructor Documentation

◆ __construct()

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::__construct (   $db)

fbGallery constructor. Get widget settings into this->settings array and call checkRequirements

Parameters
$db

Definition at line 76 of file fbGallery.php.

78  {
79  // load this widget settings from db
80  $widget = new \YAWK\widget();
81  $this->settings = $widget->getWidgetSettingsArray($db);
82  foreach ($this->settings as $property => $value)
83  {
84  $this->$property = $value;
85  }
86  // check if required settings are set
87  $this->checkRequirements();
checkRequirements()
Check if all requirements are fulfilled to perform api call.
Definition: fbGallery.php:92
$value

References $db, $value, and YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\checkRequirements().

Member Function Documentation

◆ checkAccessToken()

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::checkAccessToken ( )

Check if access token is correctly set. Returns true or abort with an error message.

Returns
bool

Definition at line 126 of file fbGallery.php.

128  { // check if access token is set and not empty
129  if (isset($this->fbGalleryAccessToken) && (!empty($this->fbGalleryAccessToken)))
130  { // check if access token is a string
131  if (is_string($this->fbGalleryAccessToken))
132  { // access token seems legit
133  return true;
134  }
135  else
136  { // access token is not a string, abort with error message
137  die ("Access token is set, but not a string value! Please check your access token.");
138  }
139  }
140  else
141  { // access token is not set or empty, abort with error message
142  die ("Access token is not set. Please add your access token. You can obtain it from http://developers.facebook.com/apps");
143  }
die
Definition: block-user.php:27

References die.

Referenced by YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\checkRequirements().

◆ checkAlbumId()

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::checkAlbumId ( )

Check if album id is correctly set. Returns true or abort with an error message.

Returns
bool

Definition at line 149 of file fbGallery.php.

151  { // check if Album ID is set and not empty
152  if (isset($this->fbGalleryAlbumId) && (!empty($this->fbGalleryAlbumId)))
153  { // check if album ID is a string
154  if (is_string($this->fbGalleryAlbumId))
155  { // seems legit
156  return true;
157  }
158  else
159  { // album id is not a string, abort with error msg
160  die ("Album ID is set, but not a string value! Please check your photo album ID.");
161  }
162  }
163  else
164  { // album id is not set or empty, abort with error msg
165  die ("Album ID is not set. Please add your photo album ID.");
166  }

References die.

Referenced by YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\checkRequirements().

◆ checkApiObjectData()

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::checkApiObjectData ( )

Check if api object is set and not empty.

Returns
bool returns true or false

Definition at line 283 of file fbGallery.php.

285  { // check if object data is set and not empty
286  if (isset($this->apiObject['data']) && (!empty($this->apiObject['data'])))
287  { // seems legit
288  return true;
289  }
290  else
291  { // object not set or empty
292  return false;
293  }

◆ checkAppId()

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::checkAppId ( )

Check if App ID is set, not empty and numeric. Returns true if app ID is ok or abort with an error message.

Returns
bool

Definition at line 103 of file fbGallery.php.

105  { // check if App ID is set and not empty
106  if (isset($this->fbGalleryAppId) && (!empty($this->fbGalleryAppId)))
107  { // is app ID a number for sure?
108  if (is_numeric($this->fbGalleryAppId))
109  { // app id seems legit
110  return true;
111  }
112  else
113  { // app id not numeric, abort with error message
114  die ("app ID is set, but not a numeric value! Please check your app ID - it should contain numbers only.");
115  }
116  }
117  else
118  { // app id not set or empty, abort with error message
119  die ("app ID is not set. Please add your app ID. You can obtain it from http://developers.facebook.com");
120  }

References die.

Referenced by YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\checkRequirements(), and YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\loadJSSDK().

◆ checkRequirements()

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::checkRequirements ( )

Check if all requirements are fulfilled to perform api call.

Definition at line 92 of file fbGallery.php.

94  {
95  $this->checkAppId();
96  $this->checkAccessToken();
97  $this->checkAlbumId();
checkAccessToken()
Check if access token is correctly set. Returns true or abort with an error message.
Definition: fbGallery.php:126
checkAppId()
Check if App ID is set, not empty and numeric. Returns true if app ID is ok or abort with an error me...
Definition: fbGallery.php:103
checkAlbumId()
Check if album id is correctly set. Returns true or abort with an error message.
Definition: fbGallery.php:149

References YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\checkAccessToken(), YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\checkAlbumId(), and YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\checkAppId().

Referenced by YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\__construct().

◆ drawGallery()

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::drawGallery ( )

The heart of this widget: this method draws the gallery.

Definition at line 298 of file fbGallery.php.

300  {
301  // load facebook JS
302  $this->loadJSSDK();
303  // make facebook api call
304  $this->makeApiCall();
305 
306  /* ALBUM DETAILED VIEW */
307  if (isset($this->apiObject['data']) && (!empty($this->apiObject))) {
308 
309  // check if array needs to be sorted
310  if (is_string($this->fbGallerySortation) && ($this->fbGallerySortation == "desc"))
311  {
312  // sort array ascending / descending
313  $this->apiObject['data'] = array_reverse($this->apiObject['data']);
314  }
315 
316  // check if images needs to be shuffled
317  elseif ($this->fbGallerySortation == "shuffle")
318  { // shuffle images on page load
319  shuffle($this->apiObject['data']);
320  }
321 
322  // check if limit is set
323  if ($this->fbGalleryLimit > 0 && ($this->fbGalleryLimit != 25))
324  { // limit images to x entries
325  $this->apiObject['data'] = array_slice($this->apiObject['data'], 0, $this->fbGalleryLimit);
326  }
327 
328  // check gallery layout
329  if (!isset($this->fbGalleryLayout) || (empty($this->fbGalleryLayout)))
330  { // if no layout is set, use this as default value
331  $this->fbGalleryLayout = 6;
332  }
333 
334  // check heading
335  if (isset($this->fbGalleryHeading) && (!empty($this->fbGalleryHeading)))
336  {
337  // if heading is set, build markup
338  $this->fbGalleryHeading = "$this->fbGalleryHeading";
339  }
340  else
341  { // no heading was set, leave empty
342  $this->fbGalleryHeading = '';
343  }
344 
345  // check subtext
346  if (isset($this->fbGallerySubtext) && (!empty($this->fbGallerySubtext)))
347  {
348  // if subtext is set, build markup
349  $this->fbGallerySubtext = "<small>$this->fbGallerySubtext</small>";
350  }
351  else
352  { // no subtext was set, leave empty
353  $this->fbGallerySubtext = '';
354  }
355 
356  // draw heading + subtext
357  echo "<div class=\"row padding\"><div class=\"col-md-12\"><h1>$this->fbGalleryHeading&nbsp;$this->fbGallerySubtext</h1></div></div>";
358 
359 
360  $i = 0; // loop indicator
361  // walk through data array to help animation (first items fadeIn on load)
362  echo "<div class=\"row padding\">";
363  foreach ($this->apiObject['data'] as $property => $value)
364  {
365  // if loop runs for the first time
366  if (isset($i) && ($i <= 3))
367  { // first element get this css class
368  $animateMarkup = 'animated fadeIn';
369  }
370  else
371  { // all other items - set animate class on them
372  $animateMarkup = "animate";
373  }
374 
375  $i++; // raise loop indicator
376 
377  // check if image info is set
378  if (isset($this->fbGalleryImageInfo) && (!empty($this->fbGalleryImageInfo)))
379  {
380  // if image info is on
381  $this->fbGalleryImageInfo = $value['name'];
382  }
383  else
384  { // leave image info empty
385  $this->fbGalleryImageInfo = '';
386  }
387 
388  // random align images
389  $randomInt = rand(1,4);
390  if ($randomInt == 1)
391  {
392  $imgClass = "img-lefty";
393  }
394  elseif ($randomInt == 2)
395  {
396  $imgClass = "img-lefty-less";
397  }
398  elseif ($randomInt == 3)
399  {
400  $imgClass = "img-righty";
401  }
402  elseif ($randomInt == 4)
403  {
404  $imgClass = "img-righty-less";
405  }
406  /*
407  elseif ($randomInt == 5)
408  {
409  $imgClass = "img-thumbnail";
410  }
411  else
412  { // default value:
413  $imgClass = "img-thumbnail";
414  }
415  */
416 
417  // set filename to biggest image source
418  $fn = $value['images'][0]['source'];
419  // set layout div box, containing every single image
420  echo "<div class=\"col-md-$this->fbGalleryLayout text-center $animateMarkup\">
421  <a href=\"$fn\" data-lightbox=\"example-set\" data-title=\"$value[name]\">
422  <img src=\"$fn\" alt=\"$value[name]\" style=\"width:auto; height:$this->fbGalleryFixedImageHeight;\" class=\"img-thumbnail img-fluid ".$imgClass." hvr-grow\">
423  </a><br><br><small>$this->fbGalleryImageInfo</small><br><br><hr></div>";
424  } // end foreach
425  echo "</div>";
426  }
427  else
428  { // api object not set or empty - abort with error
429  die("Unable to load Images from Facebook API because the apiObject is not set or empty.");
430  }
makeApiCall()
Prepare object data, set json link, make API call and return apiObject.
Definition: fbGallery.php:213
loadJSSDK()
Load Facebook JS Code.
Definition: fbGallery.php:171
$i

References $i, $value, die, YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\loadJSSDK(), and YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\makeApiCall().

◆ loadJSSDK()

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::loadJSSDK ( )

Load Facebook JS Code.

Definition at line 171 of file fbGallery.php.

173  { // check if fb JS SDK was loaded before
174  if ($this->jsSDKLoaded == 'false')
175  { // check if app ID is set
176  if ($this->checkAppId() == true)
177  {
178  /*
179  // include facebook SDK JS
180  echo "<script>
181  window.fbAsyncInit = function() {
182  FB.init({
183  appId : '" . $this->fbGalleryAppId . "',
184  xfbml : true,
185  version : 'v3.3'
186  });
187  FB.AppITEMS.logPageView();
188  };
189 
190  (function(d, s, id){
191  var js, fjs = d.getElementsByTagName(s)[0];
192  if (d.getElementById(id)) {return;}
193  js = d.createElement(s); js.id = id;
194  js.src = \"https://connect.facebook.net/en_US/sdk.js\";
195  fjs.parentNode.insertBefore(js, fjs);
196  }(document, 'script', 'facebook-jssdk'));
197  </script>";
198  $this->jsSDKLoaded = 'true';
199  */
200  }
201  /*
202  else
203  { // check app ID failed, abort with error msg (app id not set correctly)
204  die ("unable to include facebook js SDK - checkAppId failed. Please check your app ID in the widget settings!");
205  }
206  */
207  }

References YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\checkAppId().

Referenced by YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\drawGallery().

◆ makeApiCall()

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::makeApiCall ( )

Prepare object data, set json link, make API call and return apiObject.

Returns
object

Definition at line 213 of file fbGallery.php.

215  {
216  // WHICH ITEMS TO DISPLAY?
217  // evaluation of event type select field
218  if ($this->fbGalleryType == "all")
219  {
220  // ALL ITEMS (FUTURE + PAST)
221  $this->sinceDate = date('Y-01-01', strtotime('-' . $this->fbGalleryYearRange . ' years'));
222  $this->untilDate = date('Y-01-01', strtotime('+' . $this->fbGalleryYearRange . ' years'));
223  }
224  elseif ($this->fbGalleryType == "future")
225  {
226  // UPCOMING ITEMS
227  $this->sinceDate = date('Y-m-d');
228  $this->untilDate = date('Y-12-31', strtotime('+' . $this->fbGalleryYearRange . ' years'));
229  }
230  elseif ($this->fbGalleryType == "past")
231  {
232  // PAST ITEMS
233  $this->sinceDate = date('Y-01-01', strtotime('-' . $this->fbGalleryYearRange . ' years'));
234  $this->untilDate = date('Y-m-d');
235  }
236  else
237  { // IF NOT SET - use default:
238  // UPCOMING ITEMS
239  $this->sinceDate = date('Y-m-d');
240  $this->untilDate = date('Y-12-31', strtotime('+' . $this->fbGalleryYearRange . ' years'));
241  }
242 
243  // IF START + END DATE IS SET
244  if (isset($this->fbGalleryStartDate) && (!empty($this->fbGalleryStartDate))
245  && (isset($this->fbGalleryEndDate) && (!empty($this->fbGalleryEndDate))))
246  {
247  $this->sinceDate = date($this->fbGalleryStartDate);
248  $this->untilDate = date($this->fbGalleryEndDate);
249  }
250 
251  // unix timestamp years
252  $since_unix_timestamp = strtotime($this->sinceDate);
253  $until_unix_timestamp = strtotime($this->untilDate);
254 
255  // check if fields are set
256  if (isset($this->fbGalleryFields) && (!empty($this->fbGalleryFields)))
257  { // set markup for api query string
258  $fieldsMarkup = "?fields={$this->fbGalleryFields}";
259  }
260  else
261  { // no fields wanted, leave markup empty
262  $fieldsMarkup = '';
263  }
264 
265  // prepare API call - get photos
266  $json_link = "https://graph.facebook.com/v3.3/{$this->fbGalleryAlbumId}/photos$fieldsMarkup&access_token={$this->fbGalleryAccessToken}";
267 
268  // get json string
269  $curl = curl_init();
270  curl_setopt($curl, CURLOPT_URL, $json_link);
271  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
272  $this->apiObject = json_decode(curl_exec($curl), true, 512, JSON_BIGINT_AS_STRING);
273  curl_close($curl);
274 
275  // $json = file_get_contents($json_link);
276  // convert json to object
277  return $this->apiObject;
print $tourdates date

References YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\$apiObject, and date.

Referenced by YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\drawGallery().

Member Data Documentation

◆ $apiObject

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$apiObject
Parameters
objectapi result (as object)

Definition at line 66 of file fbGallery.php.

Referenced by YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery\makeApiCall().

◆ $fbGalleryAccessToken

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryAccessToken = ''
Parameters
stringyour access token (secret word from developers.facebook.com)

Definition at line 30 of file fbGallery.php.

◆ $fbGalleryAlbumId

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryAlbumId = ''
Parameters
stringyour page ID (http://facebook.com/{YOURPAGEID}

Definition at line 28 of file fbGallery.php.

◆ $fbGalleryAppId

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryAppId = ''
Parameters
stringyour app ID (from developers.facebook.com)

Definition at line 26 of file fbGallery.php.

◆ $fbGalleryEndDate

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryEndDate = ''
Parameters
stringuser defined end date

Definition at line 40 of file fbGallery.php.

◆ $fbGalleryFields

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryFields = 'images,source,name,id'
Parameters
stringfields that should be selected from facebook graph

Definition at line 34 of file fbGallery.php.

◆ $fbGalleryFixedImageHeight

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryFixedImageHeight = 'auto'
Parameters
stringfixed image height in pixels or auto (select field)

Definition at line 58 of file fbGallery.php.

◆ $fbGalleryGraphRequest

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryGraphRequest = '/albums/'
Parameters
stringyour graph request (the Album ID)

Definition at line 32 of file fbGallery.php.

◆ $fbGalleryHeading

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryHeading = ''
Parameters
stringgallery heading

Definition at line 44 of file fbGallery.php.

◆ $fbGalleryImageInfo

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryImageInfo = 1
Parameters
intshow info under the gallery? 0|1

Definition at line 56 of file fbGallery.php.

◆ $fbGalleryLayout

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryLayout = 6
Parameters
intlayout

Definition at line 54 of file fbGallery.php.

◆ $fbGalleryLimit

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryLimit = 0
Parameters
intlimit entries to (n)

Definition at line 50 of file fbGallery.php.

◆ $fbGallerySortation

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGallerySortation = 'desc'
Parameters
stringsortation

Definition at line 52 of file fbGallery.php.

◆ $fbGalleryStartDate

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryStartDate = ''
Parameters
stringuser defined start date

Definition at line 38 of file fbGallery.php.

◆ $fbGallerySubtext

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGallerySubtext = ''
Parameters
stringgallery small subtext beside heading

Definition at line 46 of file fbGallery.php.

◆ $fbGalleryType

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryType = 'past'
Parameters
stringwhich items should be shown? future|past|all

Definition at line 42 of file fbGallery.php.

◆ $fbGalleryYearRange

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$fbGalleryYearRange = '10'
Parameters
stringshow ITEMS of this time range

Definition at line 36 of file fbGallery.php.

◆ $jsSDKLoaded

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$jsSDKLoaded = 'false'
Parameters
stringtrue|false was the js SDK loaded?

Definition at line 64 of file fbGallery.php.

◆ $settings

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$settings
Parameters
arraytemporary settings array

Definition at line 68 of file fbGallery.php.

◆ $shuffle

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$shuffle = 0
Parameters
intshuffle 0|1 if true, images get shuffled on page load

Definition at line 60 of file fbGallery.php.

◆ $sinceDate

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$sinceDate = ''
Parameters
stringITEMS since this date (used for calc)

Definition at line 48 of file fbGallery.php.

◆ $untilDate

YAWK\WIDGETS\FACEBOOK\GALLERY\fbGallery::$untilDate = ''
Parameters
stringITEMS until this date (used for calc)

Definition at line 62 of file fbGallery.php.


The documentation for this class was generated from the following file: