-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christian Seel
committed
Apr 15, 2012
0 parents
commit be3fbca
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
/** | ||
* fbLikes | ||
* | ||
* Returns the number of fans for a facebook fanpage (via the graph api) | ||
* | ||
* @author Christian Seel | ||
* @version 1.0.0 - 2012-04-15 | ||
* | ||
* OPTIONS | ||
* pageid - the facebook id of your fanpage | ||
* expiretime - lifetime of the cache in seconds (default: "10800", 3 hours) | ||
* | ||
* EXAMPLE | ||
* [[!fbLikes? &pageid=`19110642979` &expiretime=`10800`]] | ||
* | ||
* fbLikes is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License as published by the Free Software | ||
* Foundation; either version 2 of the License, or (at your option) any later | ||
* version. | ||
* | ||
* fbLikes is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
* A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* fbLikes; if not, write to the Free Software Foundation, Inc., 59 Temple Place, | ||
* Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
$pageid = $modx->getOption('pageid',$scriptProperties,"19110642979"); | ||
$expiretime = $modx->getOption('expiretime',$scriptProperties,"10800"); | ||
$cacheKey = $modx->resource->getCacheKey().'/fblikes'; | ||
|
||
// get data from cache | ||
$cached_data = $modx->cacheManager->get($cacheKey); | ||
|
||
if (!$cached_data) { | ||
|
||
// if there's no cached data create it and save it... | ||
|
||
// get page information from facebooks graph api (returns json data) | ||
$graphdata = file_get_contents("http://graph.facebook.com/".$pageid); | ||
// decode json response | ||
$response = json_decode($graphdata, true); | ||
// get like number | ||
$data = $response['likes']; | ||
|
||
// save data to the cache | ||
$modx->cacheManager->set($cacheKey,$data,$expiretime); | ||
$cached_data = $data; | ||
|
||
} | ||
|
||
// return data | ||
return $cached_data; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# fbLikes | ||
fbLikes is a snippet for MODX Revolution that returns the number of fans for a facebook page and caches the results for specific time. | ||
|
||
## License | ||
fbLikes has been released as open source under the GPL v2 (or later) license. This means that while I hope this is useful, | ||
I am not responsible for the effects of using it and can not be held liable for any (financial) damage incurred from using it. | ||
|
||
I welcome people taking this addon and customizing it to their needs. A pull request for any improvements would be great! | ||
|
||
## Installation Instructions | ||
|
||
1. Copy the contents of the snippet file (fblikes.snippet.php) from github | ||
2. Go to your MODX Revolution Manager, create a new snippet, paste the content from your clipboard and save it | ||
3. Open a resource or chunk (or wherever you want to display your fan number) and add the snippet call | ||
[[!fbLikes? &pageid=`19110642979` &expiretime=`10030`]] | ||
|
||
# Developed by | ||
**chsmedien** | ||
Christian Seel | ||
E-Mail: [email protected] | ||
Website: www.chsmedien.com |