/Templating/Helper/FacebookHelper.php

http://github.com/FriendsOfSymfony/FOSFacebookBundle · PHP · 104 lines · 62 code · 11 blank · 31 comment · 0 complexity · aa025014bb133502f1a68f122e7ff00f MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of the FOSFacebookBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace FOS\FacebookBundle\Templating\Helper;
  11. use Symfony\Component\Templating\Helper\Helper;
  12. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  13. use Symfony\Component\Templating\EngineInterface;
  14. class FacebookHelper extends Helper
  15. {
  16. protected $templating;
  17. protected $logging;
  18. protected $urlGenerator;
  19. protected $culture;
  20. protected $scope;
  21. protected $facebook;
  22. public function __construct(EngineInterface $templating, \BaseFacebook $facebook, UrlGeneratorInterface $urlGenerator, $logging = true, $culture = 'en_US', array $scope = array())
  23. {
  24. $this->templating = $templating;
  25. $this->logging = $logging;
  26. $this->urlGenerator = $urlGenerator;
  27. $this->culture = $culture;
  28. $this->scope = $scope;
  29. $this->facebook = $facebook;
  30. }
  31. /**
  32. * Returns the HTML necessary for initializing the JavaScript SDK.
  33. *
  34. * The default template includes the following parameters:
  35. *
  36. * * async
  37. * * fbAsyncInit
  38. * * appId
  39. * * xfbml
  40. * * oauth
  41. * * status
  42. * * cookie
  43. * * logging
  44. * * culture
  45. *
  46. * @param array $parameters An array of parameters for the initialization template
  47. * @param string $name A template name
  48. *
  49. * @return string An HTML string
  50. */
  51. public function initialize($parameters = array(), $name = null)
  52. {
  53. $name = $name ?: 'FOSFacebookBundle::initialize.html.php';
  54. return $this->templating->render($name, $parameters + array(
  55. 'async' => true,
  56. 'fbAsyncInit' => '',
  57. 'appId' => (string) $this->facebook->getAppId(),
  58. 'xfbml' => false,
  59. 'oauth' => true,
  60. 'status' => false,
  61. 'cookie' => true,
  62. 'logging' => $this->logging,
  63. 'channelUrl' => $this->urlGenerator->generate('fos_facebook_channel', array(), true),
  64. 'culture' => $this->culture,
  65. ));
  66. }
  67. public function loginButton($parameters = array(), $name = null)
  68. {
  69. $name = $name ?: 'FOSFacebookBundle::loginButton.html.php';
  70. return $this->templating->render($name, $parameters + array(
  71. 'autologoutlink' => 'false',
  72. 'label' => '',
  73. 'showFaces' => 'false',
  74. 'width' => '',
  75. 'maxRows' => '1',
  76. 'scope' => implode(',', $this->scope),
  77. 'registrationUrl' => '',
  78. 'size' => 'medium',
  79. 'onlogin' => ''
  80. ));
  81. }
  82. public function logoutUrl($parameters = array(), $name = null)
  83. {
  84. return $this->facebook->getLogoutUrl($parameters);
  85. }
  86. /**
  87. * @codeCoverageIgnore
  88. */
  89. public function getName()
  90. {
  91. return 'facebook';
  92. }
  93. }