PageRenderTime 17ms CodeModel.GetById 2ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

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