PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_jfbconnect/install/packages/install_51498ea168717/helper.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 366 lines | 306 code | 46 blank | 14 comment | 86 complexity | 577861e723862504ebe7a78e5c59e3da MD5 | raw file
  1. <?php
  2. /**
  3. * @package JFBConnect/JLinked
  4. * @copyright (C) 2011-2013 by Source Coast - All rights reserved
  5. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
  6. */
  7. // no direct access
  8. defined('_JEXEC') or die('Restricted access');
  9. jimport('joomla.filesystem.file');
  10. class modSCLoginHelper
  11. {
  12. var $isJLinkedInstalled = false;
  13. var $isJFBConnectInstalled = false;
  14. var $jlinkedLibrary = null;
  15. var $jfbcLibrary = null;
  16. var $params;
  17. function __construct($params)
  18. {
  19. $this->params = $params;
  20. //Check to see if JLinked is installed
  21. if (class_exists("JLinkedApiLibrary"))
  22. {
  23. $this->isJLinkedInstalled = true;
  24. $this->jlinkedLibrary = JLinkedApiLibrary::getInstance();
  25. $renderKey = $this->jlinkedLibrary->getSocialTagRenderKey();
  26. $this->jlinkedRenderKey = $renderKey != "" ? " key=" . $renderKey : "";
  27. }
  28. //Check to see if JFBConnect is installed
  29. if (class_exists("JFBConnectFacebookLibrary"))
  30. {
  31. $this->isJFBConnectInstalled = true;
  32. $this->jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
  33. }
  34. }
  35. function getPoweredByLink()
  36. {
  37. $showPoweredBy = $this->params->get('showPoweredByLink');
  38. if ($showPoweredBy == 0)
  39. return;
  40. if ($this->isJLinkedInstalled)
  41. {
  42. $jlConfigModel = $this->jlinkedLibrary->getConfigModel();
  43. $jlinkedAffiliateID = $jlConfigModel->getSetting('affiliate_id');
  44. $showJLinkedPoweredBy = (($showPoweredBy == '2' && $jlConfigModel->getSetting('show_powered_by_link')) || ($showPoweredBy == '1'));
  45. }
  46. else
  47. $showJLinkedPoweredBy = false;
  48. if ($this->isJFBConnectInstalled)
  49. {
  50. $jfbcConfigModel = $this->jfbcLibrary->getConfigModel();
  51. $jfbcAffiliateID = $jfbcConfigModel->getSetting('affiliate_id');
  52. $showJFBCPoweredBy = (($showPoweredBy == '2' && $jfbcConfigModel->getSetting('show_powered_by_link')) || ($showPoweredBy == '1'));
  53. }
  54. else
  55. $showJFBCPoweredBy = false;
  56. if ($showJFBCPoweredBy && $showJLinkedPoweredBy)
  57. {
  58. $link = 'http://www.sourcecoast.com/';
  59. $title = 'Facebook and LinkedIn for Joomla';
  60. $poweredByLabel = 'SourceCoast';
  61. if ($jfbcAffiliateID)
  62. $affiliate_id = $jfbcAffiliateID;
  63. else
  64. $affiliate_id = $jlinkedAffiliateID;
  65. }
  66. else if ($showJFBCPoweredBy)
  67. {
  68. $link = 'http://www.sourcecoast.com/joomla-facebook/';
  69. $title = 'Facebook for Joomla';
  70. $poweredByLabel = 'JFBConnect';
  71. $affiliate_id = $jfbcAffiliateID;
  72. }
  73. else if ($showJLinkedPoweredBy)
  74. {
  75. $link = 'http://www.sourcecoast.com/jlinked/';
  76. $title = 'LinkedIn for Joomla';
  77. $poweredByLabel = 'JLinked';
  78. $affiliate_id = $jlinkedAffiliateID;
  79. }
  80. if (isset($link))
  81. {
  82. if ($affiliate_id)
  83. $link .= '?amigosid=' . $affiliate_id;
  84. return '<div class="powered_by">'.JText::_('MOD_SCLOGIN_POWERED_BY').' <a target="_blank" href="' . $link . '" title="' . $title . '">' . $poweredByLabel . '</a></div>';
  85. }
  86. return "";
  87. }
  88. function getType()
  89. {
  90. $user = JFactory::getUser();
  91. return (!$user->get('guest')) ? 'logout' : 'login';
  92. }
  93. function getLoginRedirect($loginType)
  94. {
  95. if (JRequest::getString('return'))
  96. return JRequest::getString('return');
  97. $url = '';
  98. if (($loginType == 'jlogin' && $this->params->get('jlogin_redirect')))
  99. {
  100. $itemId = $this->params->get($loginType);
  101. if ($itemId)
  102. {
  103. $app = JFactory::getApplication();
  104. $router = $app->getRouter();
  105. $db = JFactory::getDbo();
  106. //Derived from mod_login Joomla 1.6, but modified to be backwards compatible
  107. $query = "SELECT link FROM #__menu WHERE published=1 AND id=" . $db->quote($itemId);
  108. $db->setQuery($query);
  109. if ($link = $db->loadResult())
  110. {
  111. // Use this default for Joomla 1.5 or Non-SEF Joomla 2.5
  112. $url = $link . '&Itemid=' . $itemId;
  113. if ($router->getMode() == JROUTER_MODE_SEF)
  114. {
  115. $url = 'index.php?Itemid=' . $itemId;
  116. }
  117. }
  118. }
  119. }
  120. if (!$url)
  121. {
  122. $uri = JURI::getInstance();
  123. $url = $uri->toString(array('scheme', 'host', 'path', 'query'));
  124. }
  125. return base64_encode($url);
  126. }
  127. function getAvatarDimensions(&$width, &$height)
  128. {
  129. $picHeightParam = $this->params->get("profileHeight");
  130. $picWidthParam = $this->params->get("profileWidth");
  131. $height = $picHeightParam != "" ? 'height="' . $picHeightParam . 'px"' : "";
  132. $width = $picWidthParam != "" ? 'width="' . $picWidthParam . 'px"' : "";
  133. }
  134. function getSocialAvatarImage($avatarURL, $profileURL)
  135. {
  136. $html = '';
  137. if($avatarURL)
  138. {
  139. $picWidth = "";
  140. $picHeight = "";
  141. $this->getAvatarDimensions($picWidth, $picHeight);
  142. $html = '<img src="' . $avatarURL . '" ' . $picWidth . " " . $picHeight . ' />';
  143. $linked = ($this->params->get("linkProfile") == 1);
  144. if ($linked && $profileURL != '')
  145. $html = '<a target="_BLANK" href="' . $profileURL . '">' . $html . '</a>';
  146. }
  147. return $html;
  148. }
  149. function showSecurely()
  150. {
  151. $uri = JURI::getInstance();
  152. $scheme = $uri->getScheme();
  153. return $scheme == 'https';
  154. }
  155. function getFacebookAvatar()
  156. {
  157. $html = "";
  158. if ($this->isJFBConnectInstalled)
  159. {
  160. $fbUserId = $this->jfbcLibrary->getMappedFbUserId();
  161. # Show their FB avatar (if desired), or give them the option to link accounts
  162. if ($fbUserId)
  163. {
  164. $fbProfileURL = 'https://www.facebook.com/profile.php?id='.$fbUserId;
  165. $fbAvatarSize = $this->getJFBConnectAvatarSize();
  166. $fbAvatarURL = 'https://graph.facebook.com/'.$fbUserId.'/picture?type='.$fbAvatarSize;
  167. if($this->showSecurely())
  168. $fbAvatarURL .= '&return_ssl_resources=1';
  169. $html = $this->getSocialAvatarImage($fbAvatarURL, $fbProfileURL);
  170. }
  171. }
  172. return $html;
  173. }
  174. function getLinkedInAvatar()
  175. {
  176. $html = "";
  177. if ($this->isJLinkedInstalled && $this->jlinkedLibrary->getMappedLinkedInUserId())
  178. {
  179. $app = JFactory::getApplication();
  180. $liAvatarUrl = $app->getUserState('modScLoginLiAvatar', null);
  181. $liProfileURL = $app->getUserState('modScLoginLiProfileURL', null);
  182. if ($liAvatarUrl == null || $liProfileURL == null)
  183. {
  184. $data = $this->jlinkedLibrary->api('profile', '~:(picture-url,public-profile-url)');
  185. //Avatar URL
  186. $liAvatarUrl = $data->get('picture-url');
  187. $app->setUserState('modScLoginLiAvatar', $liAvatarUrl);
  188. //Profile URL
  189. $liProfileURL = $data->get('public-profile-url');
  190. $app->setUserState('modScLoginLiProfileURL', $liProfileURL);
  191. }
  192. $html = $this->getSocialAvatarImage($liAvatarUrl, $liProfileURL);
  193. }
  194. return $html;
  195. }
  196. function getJoomlaAvatar($registerType, $profileLink, $user)
  197. {
  198. $html = '';
  199. if($registerType == 'jomsocial')
  200. {
  201. $jsUser = & CFactory::getUser($user->id);
  202. $avatarURL = $jsUser->get('_avatar');
  203. $html = $this->getSocialAvatarImage($avatarURL, $profileLink);
  204. }
  205. else if($registerType == 'communitybuilder')
  206. {
  207. $db = JFactory::getDbo();
  208. $query = "SELECT avatar FROM #__comprofiler WHERE id = " . $user->id;
  209. $db->setQuery($query);
  210. $avatarURL = $db->loadResult();
  211. if($avatarURL)
  212. $avatarURL = JRoute::_('images/comprofiler/' . $avatarURL, false);
  213. $html = $this->getSocialAvatarImage($avatarURL, $profileLink);
  214. }
  215. return $html;
  216. }
  217. function getSocialAvatar($registerType, $profileLink, $user)
  218. {
  219. $html = "";
  220. $enableProfilePic = $this->params->get('enableProfilePic');
  221. if ($enableProfilePic == 'facebook')
  222. {
  223. $html = $this->getFacebookAvatar();
  224. if ($html == "")
  225. $html = $this->getLinkedInAvatar();
  226. }
  227. else if ($enableProfilePic == 'linkedin')
  228. {
  229. $html = $this->getLinkedInAvatar();
  230. if ($html == "")
  231. $html = $this->getFacebookAvatar();
  232. }
  233. else if ($enableProfilePic == 'joomla')
  234. {
  235. $html = $this->getJoomlaAvatar($registerType, $profileLink, $user);
  236. }
  237. if ($html != "")
  238. $html = '<div id="scprofile-pic">' . $html . '</div>';
  239. return $html;
  240. }
  241. function getJFBConnectAvatarSize()
  242. {
  243. $picHeightParam = $this->params->get("profileHeight");
  244. $picWidthParam = $this->params->get("profileWidth");
  245. $picHeight = intval($picHeightParam);
  246. $picWidth = intval($picWidthParam);
  247. if($picWidth > 100)
  248. return "large";
  249. else if($picWidth > 50)
  250. return "normal";
  251. else if($picWidth <= 50 & $picHeight == $picWidth)
  252. return "square";
  253. else
  254. return "small";
  255. }
  256. function getJFBConnectLoginButton()
  257. {
  258. if ($this->isJFBConnectInstalled)
  259. {
  260. $buttonSize = $this->params->get("loginButtonSize");
  261. $showFaces = $this->params->get("showFaces");
  262. $maxRows = $this->params->get("maxRows");
  263. $loginButton = $this->jfbcLibrary->getLoginButton($buttonSize, $showFaces, $maxRows);
  264. $loginButton = '<div class="jfbcLogin">'.$loginButton.'</div>';
  265. return $loginButton;
  266. }
  267. return "";
  268. }
  269. function getJLinkedLoginButton()
  270. {
  271. //Show JLinked Login Button
  272. if ($this->isJLinkedInstalled)
  273. {
  274. $buttonSize = $this->params->get("loginButtonSize");
  275. return '{JLinkedLogin size=' . $buttonSize . $this->jlinkedRenderKey . '}';
  276. }
  277. return "";
  278. }
  279. function getLogoutButton()
  280. {
  281. if ($this->isJFBConnectInstalled)
  282. return $this->jfbcLibrary->getLogoutButton();
  283. else if ($this->isJLinkedInstalled)
  284. return $this->jlinkedLibrary->getLogoutButton();
  285. }
  286. function getJFBCConnectButton()
  287. {
  288. $buttonHtml = "";
  289. if (!$this->jfbcLibrary->getMappedFbUserId())
  290. {
  291. $buttonHtml = '<div class="fb_connect_user">';
  292. $buttonHtml .= '<div class="fb-login-button" onlogin="javascript:jfbc.login.on_login();">' . JText::_('MOD_SCLOGIN_CONNECT_BUTTON') .'</div>';
  293. $buttonHtml .= '</div>';
  294. }
  295. return $buttonHtml;
  296. }
  297. function getJLinkedConnectButton()
  298. {
  299. $buttonHtml = "";
  300. if (!$this->jlinkedLibrary->getMappedLinkedInUserId())
  301. {
  302. $buttonHtml = '<link rel="stylesheet" href="components/com_jlinked/assets/jlinked.css" type="text/css" />';
  303. $buttonHtml .= '<div class="li_connect_user">';
  304. $buttonHtml .= '<div class="jLinkedLogin"><a href="' . $this->jlinkedLibrary->getLoginURL() . '"><span class="jlinkedButton"></span><span class="jlinkedLoginButton">'.JText::_('MOD_SCLOGIN_CONNECT_BUTTON').'</span></a></div>';
  305. $buttonHtml .= '</div>';
  306. }
  307. return $buttonHtml;
  308. }
  309. function getReconnectButtons()
  310. {
  311. $buttonHtml = '';
  312. if ($this->isJFBConnectInstalled)
  313. $buttonHtml .= $this->getJFBCConnectButton();
  314. if ($this->isJLinkedInstalled)
  315. $buttonHtml .= $this->getJLinkedConnectButton();
  316. if($buttonHtml)
  317. $buttonHtml = '<div class="sc_connect_user">'. JText::_('MOD_SCLOGIN_CONNECT_USER') . '</div>' . $buttonHtml;
  318. return $buttonHtml;
  319. }
  320. }