Dotclear

source: plugins/socialLogin/inc/class.SocialLoginPublic.php @ 3102

Revision 3102, 3.4 KB checked in by nicofrand, 11 years ago (diff)

Version 1.0: Initial commit

Line 
1<?php
2/**
3 * This file is part of socialLogin, a plugin for Dotclear.
4 *
5 * @author Nicolas Frandeboeuf <nicofrand@gmail.com>
6 * @version 1.0
7 * @package socialLogin
8 * Licensed under the GPL version 3 license.
9 * http://www.gnu.org/licenses/gpl-3.0.html
10 */
11
12class SocialLoginPublic
13{
14    /**
15     * Inserts the javascript provided by janrain in the head.
16     * @param dcCore $core
17     */
18    public static function getScript($core)
19    {
20     if (!session_id())
21         session_start();
22
23     $tokenUrl = $core->blog->url . $core->url->getBase("socialLoginOn") . "-" . uniqid();
24
25     $applicationDomain = $core->blog->settings->socialLogin->janrain_app_domain;
26     if (!$applicationDomain)
27         return;
28
29     $applicationName = str_replace("https://", "", $applicationDomain);
30     $applicationName = str_replace(".rpxnow.com/", "", $applicationName);
31
32     $securedUrl = "https://rpxnow.com/js/lib/" . $applicationName . "/engage.js";
33     $unsecuredUrl = "http://widget-cdn.rpxnow.com/js/lib/" . $applicationName . "/engage.js";
34
35     $content = "
36         <script type=\"text/javascript\">
37          $(document).ready(function()
38          {
39              // Hide comment fields
40     ";
41
42     if (isset($_SESSION["socialLogin_pseudo"]))
43         $content .= "$('#c_name').val('" . $_SESSION["socialLogin_pseudo"] . "').parent().hide();";
44
45     if (isset($_SESSION["socialLogin_email"]))
46         $content .= "$('#c_mail').val('" . $_SESSION["socialLogin_email"] . "').parent().hide();";
47
48     if (isset($_SESSION["socialLogin_website"]))
49         $content .= "$('#c_site').val('" . $_SESSION["socialLogin_website"] . "').parent().hide();";
50
51     $content .= "
52          });
53
54          (function()
55          {
56              if (typeof window.janrain !== 'object') window.janrain = {};
57              window.janrain.settings = {};
58              janrain.settings.tokenUrl = '" . $tokenUrl . "';
59
60              function isReady() { janrain.ready = true; };
61              if (document.addEventListener){
62              document.addEventListener('DOMContentLoaded', isReady, false);
63              } else {
64              window.attachEvent('onload', isReady);
65              }
66
67              var e = document.createElement('script');
68              e.type = 'text/javascript';
69              e.id = 'janrainAuthWidget';
70
71              if (document.location.protocol === 'https:') {
72              e.src = '" . $securedUrl . "';
73              } else {
74              e.src = '" . $unsecuredUrl . "';
75              }
76
77              var s = document.getElementsByTagName('script')[0];
78              s.parentNode.insertBefore(e, s);
79          })();
80         </script>";
81     echo($content);
82    }
83
84    /**
85     * Gets the widget content to display on the public area.
86     * @global dcCore $core
87     * @param object $widget the widget.
88     * @return string the widget content
89     */
90    public static function getWidgetContent($widget)
91    {
92     global $core;
93
94     $scheme = (isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on")) ? "https://" : "http://";
95     $_SESSION["socialLogin_previous_url"] = $scheme . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
96
97     if (isset($_SESSION["socialLogin_identifier"]))
98         return "<a href=\"" . $core->blog->url . $core->url->getBase("socialLoginOff") . "/deco\" id=\"socialLogin_deconnect\" href=\"socialLogin_button\">" . $widget->deconnexion_text . "</a>";
99
100     if (!$core->blog->settings->socialLogin->janrain_app_domain)
101         return;
102
103     $widgetContent = "";
104
105     if (isset($_SESSION["socialLogin_error"]))
106         $widgetContent .= "<p class=\"socialLogin_error\">" . $_SESSION["socialLogin_error"] . "</p>";
107
108     $widgetContent .= "<a class=\"janrainEngage socialLogin_button\" href=\"#\">" . $widget->connexion_text . "</a>";
109
110     return $widgetContent;
111    }
112}
113?>
Note: See TracBrowser for help on using the repository browser.

Sites map