From be3fbca127daf3740dc7e787279d1f4060114d51 Mon Sep 17 00:00:00 2001 From: Christian Seel Date: Mon, 16 Apr 2012 00:53:05 +0200 Subject: [PATCH] first commit --- fblikes.snippet.php | 56 +++++++++++++++++++++++++++++++++++++++++++++ readme.md | 21 +++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 fblikes.snippet.php create mode 100644 readme.md diff --git a/fblikes.snippet.php b/fblikes.snippet.php new file mode 100644 index 0000000..da369eb --- /dev/null +++ b/fblikes.snippet.php @@ -0,0 +1,56 @@ +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; \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..93d50c2 --- /dev/null +++ b/readme.md @@ -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: hello@chsmedien.com +Website: www.chsmedien.com \ No newline at end of file