YaWK  24.1
Yet another WebKit
YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover Class Reference

Facebook Cover widget - Embed current cover image from your Facebook page. More...

Public Member Functions

 __construct ($db)
 
 checkAccessToken ()
 
 checkAppId ()
 
 checkRequirements ()
 
 drawCoverImage ()
 
 loadJSSDK ()
 
 makeApiCall ()
 

Public Attributes

 $apiObject
 
 $fbCoverAccessToken = ''
 
 $fbCoverAppId = ''
 
 $fbCoverImageAlt = ''
 
 $fbCoverImageClass = ''
 
 $fbCoverImageHeight = ''
 
 $fbCoverImageStyle = ''
 
 $fbCoverImageTitle = ''
 
 $fbCoverImageWidth = ''
 
 $jsSDKLoaded = 'false'
 
 $settings
 

Detailed Description

Facebook Cover widget - Embed current cover image from your Facebook page.

Use Facebook Graph API to get you latest cover image of your Facebook Page. Require an App ID and a valid Access Token.

This widget shows always your current (newest / latest) cover image of your Facebook page. It is meant to be used as header on top of your template design - or wherever it makes sense.

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

Definition at line 17 of file fbCover.php.

Constructor & Destructor Documentation

◆ __construct()

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::__construct (   $db)

fbCover constructor. Loads all widget settings

Parameters
$db

Definition at line 46 of file fbCover.php.

48  {
49  // create new widget object
50  $widget = new \YAWK\widget();
51  // load this widget settings from db into array
52  $this->settings = $widget->getWidgetSettingsArray($db);
53  // add settings to object property
54  foreach ($this->settings as $property => $value)
55  {
56  $this->$property = $value;
57  }
58  // check if required settings are set
59  $this->checkRequirements();
$value

References $db, $value, and YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\checkRequirements().

Member Function Documentation

◆ checkAccessToken()

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::checkAccessToken ( )

check if access token is set

Returns
bool return true or die with error message

Definition at line 98 of file fbCover.php.

100  { // check if access token is set and not empty
101  if (isset($this->fbCoverAccessToken) && (!empty($this->fbCoverAccessToken)))
102  { // check if access token is a string
103  if (is_string($this->fbCoverAccessToken))
104  { // ok...
105  return true;
106  }
107  else
108  { // access token is not a string - abort with error msg
109  die ("Access token is set, but not a string value! Please check your access token.");
110  }
111  }
112  else
113  { // access token is not set or empty - abort with error msg
114  die ("Access token is not set. Please add your access token. You can obtain it from http://developers.facebook.com");
115  }
die
Definition: block-user.php:27

References die.

Referenced by YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\checkRequirements().

◆ checkAppId()

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::checkAppId ( )

check if app id is set

Returns
bool return true or die with error message

Definition at line 75 of file fbCover.php.

77  { // check of app id is set and not empty
78  if (isset($this->fbCoverAppId) && (!empty($this->fbCoverAppId)))
79  { // app id is set - check if its a number
80  if (is_numeric($this->fbCoverAppId))
81  { // ok, seems good
82  return true;
83  }
84  else
85  { // not a number - abort with error msg
86  die ("app ID is set, but not a numeric value! Please check your app ID - it should contain numbers only.");
87  }
88  }
89  else
90  { // app id not set or empty - abort with error msg
91  die ("app ID is not set. Please add your app ID. You can obtain it from http://developers.facebook.com");
92  }

References die.

Referenced by YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\checkRequirements(), and YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\loadJSSDK().

◆ checkRequirements()

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::checkRequirements ( )

◆ drawCoverImage()

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::drawCoverImage ( )

Draws the cover image onto screen.

Definition at line 186 of file fbCover.php.

188  {
189  $this->loadJSSDK();
190  $this->makeApiCall();
191 
192  // check if image class is set
193  if (isset($this->fbCoverImageClass) && (empty($this->fbCoverImageClass)))
194  { // if not, use this as default value:
195  $this->fbCoverImageClass = "img-responsive";
196  }
197 
198  // check if alt tag was set
199  if (isset($this->fbCoverImageAlt) && (!empty($this->fbCoverImageAlt)))
200  { // it is, generate markup
201  $altMarkup = " alt=\"$this->fbCoverImageAlt\"";
202  }
203  else
204  { // not set, leave empty
205  $altMarkup = '';
206  }
207 
208  // check if cover image title is set
209  if (isset($this->fbCoverImageTitle) && (!empty($this->fbCoverImageTitle)))
210  { // it is, generate markup
211  $titleMarkup = " title=\"$this->fbCoverImageTitle\"";
212  }
213  else
214  { // not set, leave empty
215  $titleMarkup = '';
216  }
217 
218  // check if image height is set
219  if (isset($this->fbCoverImageHeight) && (!empty($this->fbCoverImageHeight)))
220  { // it is, set markup
221  $heightMarkup = " height=\"$this->fbCoverImageHeight;\"";
222  }
223  else
224  { // leave empty
225  $heightMarkup = '';
226  }
227 
228  // check if image width is set
229  if (isset($this->fbCoverImageWidth) && (!empty($this->fbCoverImageWidth)))
230  { // if height is set
231  if (isset($heightMarkup) && (!empty($heightMarkup)))
232  { // leave a space between tags
233  $widthMarkup = " width=\"$this->fbCoverImageWidth\"";
234  }
235  else
236  { // height is not set - no space needed
237  $widthMarkup = "width=\"$this->fbCoverImageWidth\"";
238  }
239  }
240  else
241  { // width not set - leave markup empty
242  $widthMarkup = '';
243  }
244 
245  // check if css style is set
246  if (isset($this->fbCoverImageStyle) && (!empty($this->fbCoverImageStyle)))
247  { // add style markup
248  $styleMarkup = " style=\"$this->fbCoverImageStyle\"";
249  }
250  else
251  { // no style markup needed
252  $styleMarkup = '';
253  }
254 
255  // finally: output the cover image
256  echo "<img src=\"".$this->apiObject['cover']['source']."\" class=\"$this->fbCoverImageClass\"$styleMarkup"."$heightMarkup"."$widthMarkup"."$altMarkup"."$titleMarkup>";

References YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\loadJSSDK(), and YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\makeApiCall().

◆ loadJSSDK()

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::loadJSSDK ( )

Load Facebook JS Code

Definition at line 120 of file fbCover.php.

122  { // check if fb JS SDK was loaded before
123  if ($this->jsSDKLoaded == 'false')
124  { // check if app ID is set
125  if ($this->checkAppId() == true)
126  {
127  /*
128  // include facebook SDK JS
129  echo "<script>
130  window.fbAsyncInit = function() {
131  FB.init({
132  appId : '" . $this->fbCoverAppId . "',
133  xfbml : true,
134  version : 'v3.1'
135  });
136  FB.AppEvents.logPageView();
137  };
138 
139  (function(d, s, id){
140  var js, fjs = d.getElementsByTagName(s)[0];
141  if (d.getElementById(id)) {return;}
142  js = d.createElement(s); js.id = id;
143  js.src = \"https://connect.facebook.net/en_US/sdk.js\";
144  fjs.parentNode.insertBefore(js, fjs);
145  }(document, 'script', 'facebook-jssdk'));
146  </script>";
147  $this->jsSDKLoaded = 'true';
148  */
149  }
150  else
151  {
152  die ("unable to include facebook js SDK - checkAppId failed. Please check your app ID in the widget settings!");
153  }
154  }

References YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\checkAppId(), and die.

Referenced by YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\drawCoverImage().

◆ makeApiCall()

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::makeApiCall ( )

Prepare and make the API call and decode the json into the apiObject property

Returns
mixed Returns an array as obj property, containing the data

Definition at line 160 of file fbCover.php.

162  {
163  // prepare API call
164  $json_link = "https://graph.facebook.com/v3.3/me?fields=cover&access_token={$this->fbCoverAccessToken}";
165 
166  $curl = curl_init();
167  curl_setopt($curl, CURLOPT_URL, $json_link);
168  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
169  // decode json and create object
170  $this->apiObject = json_decode(curl_exec($curl), true, 512, JSON_BIGINT_AS_STRING);
171  curl_close($curl);
172 
173  return $this->apiObject;
174 
175  // OUTDATED:
176  // get json string
177  // $json = file_get_contents($json_link);
178  // convert json to object
179  // return $this->apiObject = json_decode($json, true, 512, JSON_BIGINT_AS_STRING);

References YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\$apiObject.

Referenced by YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\drawCoverImage().

Member Data Documentation

◆ $apiObject

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::$apiObject
Parameters
objectapi result (as object)

Definition at line 40 of file fbCover.php.

Referenced by YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover\makeApiCall().

◆ $fbCoverAccessToken

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::$fbCoverAccessToken = ''
Parameters
stringyour access token (secret word from developers.facebook.com)

Definition at line 22 of file fbCover.php.

◆ $fbCoverAppId

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::$fbCoverAppId = ''
Parameters
stringyour app ID (from developers.facebook.com)

Definition at line 20 of file fbCover.php.

◆ $fbCoverImageAlt

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::$fbCoverImageAlt = ''
Parameters
stringany image alt tag you like (for screenreaders)

Definition at line 32 of file fbCover.php.

◆ $fbCoverImageClass

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::$fbCoverImageClass = ''
Parameters
stringcss class to be set on the cover image

Definition at line 24 of file fbCover.php.

◆ $fbCoverImageHeight

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::$fbCoverImageHeight = ''
Parameters
stringimage height in px or %

Definition at line 28 of file fbCover.php.

◆ $fbCoverImageStyle

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::$fbCoverImageStyle = ''
Parameters
stringcustom css style attributes

Definition at line 34 of file fbCover.php.

◆ $fbCoverImageTitle

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::$fbCoverImageTitle = ''
Parameters
stringany title you like (important for SEO)

Definition at line 30 of file fbCover.php.

◆ $fbCoverImageWidth

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::$fbCoverImageWidth = ''
Parameters
stringimage width in px or %

Definition at line 26 of file fbCover.php.

◆ $jsSDKLoaded

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

Definition at line 36 of file fbCover.php.

◆ $settings

YAWK\WIDGETS\FACEBOOK\FBCOVER\fbCover::$settings
Parameters
arrayarray: holds the current widget settings

Definition at line 38 of file fbCover.php.


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