PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/packages/Invites/src/site/components/com_invites/mixins/facebook.php

https://github.com/bhar1red/anahita
PHP | 78 lines | 41 code | 3 blank | 34 comment | 1 complexity | f4f06a4ad55a6e221625bf00e9f496e8 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * LICENSE: ##LICENSE##
  4. *
  5. * @category Anahita
  6. * @package Com_Invites
  7. * @subpackage Mixins
  8. * @author Arash Sanieyan <ash@anahitapolis.com>
  9. * @author Rastin Mehr <rastin@anahitapolis.com>
  10. * @copyright 2008 - 2010 rmdStudio Inc./Peerglobe Technology Inc
  11. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
  12. * @version SVN: $Id$
  13. * @link http://www.anahitapolis.com
  14. */
  15. /**
  16. * Set of people who are an actor fb friends
  17. *
  18. * @category Anahita
  19. * @package Com_Invites
  20. * @subpackage Mixins
  21. * @author Arash Sanieyan <ash@anahitapolis.com>
  22. * @author Rastin Mehr <rastin@anahitapolis.com>
  23. * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl-3.0.html>
  24. * @link http://www.anahitapolis.com
  25. */
  26. class ComInvitesMixinFacebook extends KMixinAbstract
  27. {
  28. /**
  29. * Return the APPID
  30. *
  31. * @return int
  32. */
  33. public function getAppID()
  34. {
  35. $key = md5($this->_mixer->getToken());
  36. $cache = JFactory::getCache((string) 'ComInvitesMixinFacebook');
  37. $cache->setLifeTime(5*1000);
  38. $data = $cache->get(function($session) {
  39. $info = $session->get('/app');
  40. return $info;
  41. }, array($this->_mixer) , '/app'.$key);
  42. return $data['id'];
  43. }
  44. /**
  45. * Return a set of people who are fb friends
  46. *
  47. * @return set
  48. */
  49. public function getConnections()
  50. {
  51. $cache = JFactory::getCache((string) 'ComInvitesMixinFacebook', '');
  52. $key = 'ids_'.md5($this->_mixer->getToken());
  53. $data = $cache->get($key);
  54. if ( !$data )
  55. {
  56. try {
  57. $data = $this->_mixer->get('/me/friends');
  58. } catch(Exception $e) {
  59. throw new \LogicException("Can't get connections from facebook");
  60. }
  61. if ( $data->error ) {
  62. throw new \LogicException("Can't get connections from facebook");
  63. }
  64. $data = KConfig::unbox($data);
  65. $data = array_map(function($user) {return $user['id'];}, $data['data']);
  66. $data['data'][] = '-1';
  67. $cache->store($data, $key);
  68. }
  69. $query = $this->getService('repos://site/people')->getQuery(true)
  70. ->where(array(
  71. 'sessions.profileId'=> $data,
  72. 'sessions.api' => 'facebook'));
  73. return $query->toEntitySet();
  74. }
  75. }