ElkArte Community

Extending Elk => Addons => Addons ideas and questions => Topic started by: ahrasis on August 12, 2016, 09:47:05 pm

Title: Social Login
Post by: ahrasis on August 12, 2016, 09:47:05 pm
I intend to conver this mod (http://custom.simplemachines.org/mods/index.php?mod=3580) to Elkarte since it seems easy enough.

Do advice if there is anything I need to watch for.

The sharing of this addon later will depend on its current license.
Title: Re: Social Login
Post by: emanuele on August 13, 2016, 02:56:03 am
Wrong link. :P
At sm.org, if you want to link the parsing you have to copy&paste the url linked in the text "Installation Instructions for x.x.xx". ;)
Anyway the link to the mod page is enough. ;)
Title: Re: Social Login
Post by: ahrasis on August 13, 2016, 04:50:24 am
Fixed it. Anyway it is at http://custom.simplemachines.org/mods/index.php?mod=3580

The license seems to be GPL2: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. I think the code may be modified and its modification may be re-distributed.

I am also going to do this step by step and post what file that has been modified in here, so that everybody can follow and correct any mistakes, if any.
Title: Re: Social Login
Post by: ahrasis on August 13, 2016, 06:13:34 am
Currently, I have converted some of the files i.e. package-info.xml, uninstall-optional.php and install.php.[1]
They are attached below.
Title: Re: Social Login
Post by: emanuele on August 13, 2016, 07:36:51 am
Ever considered Hybridauth?
I'm not sure how many people are willing to pay at least 8€/month to have social logins.
Title: Re: Social Login
Post by: ahrasis on August 13, 2016, 08:32:40 am
QuoteWe also have a Free Plan which includes the core features, basic support by email, all social networks and up to 2,500 unique users per year
They are free as above only. I am actually revising my skill in converting the code to Elkarte.

Any clue on how to start with that?
Title: Re: Social Login
Post by: emanuele on August 13, 2016, 10:48:39 am
Ohhh... okay, I didn't notice it. lol

I could tell you to pick ideas from Ant59 addon, but I wouldn't influence the way you'll build it (mainly because his addon is not open source and so you should not take it verbatim).
Title: Re: Social Login
Post by: ahrasis on August 13, 2016, 01:13:20 pm
May be I'll just finish with this social login first. I just need to check something up in converting modification.xml to hooks whenever possible. Original modification.xml file is attached together with unfinished package for reference.
Code: [Select]
[b][u]First modification[/u][/b]
<file name="$languagedir/Modifications.english.php">
<operation>
<search position="end" />
<add><![CDATA[
// OneAll Social Login (https://docs.oneall.com/plugins/)
$txt['oasl_title'] = 'OneAll Social Login';
$txt['oasl_config'] = 'Configuration';
$txt['oasl_settings_descr'] = 'OneAll Social Login Settings';
$txt['oasl_user_does_not_exist'] = "<strong>This social network has not yet been linked to an account.</strong><br /><br />Please use the registration form to create a new account. If you already have an account, open your profile settings to connect the social network to it.";
$txt['oasl_user_may_not_register'] = 'Sorry, but the admistration has disabled the registration for new users.';
$txt['oasl_user_require_activation'] = 'Your account has been created but it needs to be verified. Please check your mailbox and click on the link in the verification email.';

]]></add>
</operation>
</file>

The first modification is to add languages for the addon settings itself, so I will move the texts are move to the language file and load it via integrate_admin_areas. This will be done together with the fourth modification that will add menu in admin page.  
Code: [Select]
[b][u]Fourth modification[/u][/b]
<file name="$sourcedir/Admin.php">
<operation>
<search position="after"><![CDATA['layout' => array(
'title' => $txt['layout_controls'],]]></search>
<add><![CDATA[
// OneAll Social Login (https://docs.oneall.com/plugins/)
'oasl' => array(
'title' => $txt['oasl_title'],
'permission' => array('admin_forum'),
'areas' => array(
'oasl' => array(
'label' => $txt['oasl_config'],
'file' => 'Subs-OneallSocialLogin.php',
'function' => 'oneall_social_login_config',
'custom_url' => $scripturl . '?action=admin;area=oasl;sa=settings;sesc=' . $sc,
'icon' => 'server.gif'
)
)
),
]]></add>
</operation>
</file>

For the time being the menu will be put under members areas. The above two modifications will be in 1ASL.subs.php as follows:
Code: [Select]
function 1ASL_AdminMenu(&$menudata)
{
global $scripturl, $txt;

// Load language(s)
loadLanguage('1ASL/1ASL');

// Insert 1ASL inside layout menu instead of having its main admin menu.
$menudata['members']['areas'] = array_merge(
array(
'oasl' => array(
'label' => $txt['oasl_config'],
'file' => '1ASL.subs.php',
'function' => '1ASL_config',
'custom_url' => $scripturl . '?action=admin;area=oasl;sa=settings;sesc=' . $sc,
'icon' => 'server.gif' ,
'subsections' => array(
),
),
),
$menudata['members']['areas']
);
}

The second modification can be converted to hook but the third one seems not possible to the same so it will stay as it is.
Code: [Select]
[b][u]Second and third modification[/u][/b]
<file name="$boarddir/index.php">
<operation>
<search position="before"><![CDATA[
'editpoll2' => array('Poll.php', 'EditPoll2'),]]></search>
<add><![CDATA[
'oasl' => array('Subs-OneallSocialLogin.php', 'oneall_social_login_config'),
'oasl_registration' => array('Subs-OneallSocialLogin.php', 'oneall_social_login_registration'),
'oasl_callback' => array('Subs-OneallSocialLogin.php', 'oneall_social_login_callback'),]]></add>
</operation>
</file>

<file name="$boarddir/index.php">
<operation>
<search position="after"><![CDATA['coppa', 'login',]]></search>
<add><![CDATA['oasl_registration', 'oasl_callback', ]]></add>
</operation>
</file>

I think in 1ASL.subs.php, as a hook using integrate_actions, the second modification should look something like this:
Code: [Select]
function 1ASL_Action(&$actionArray, &$adminActions)
{
$actionArray = array(
'oasl' => array('BOARDDIR/addons/1ASL/1ASL.subs.php', '1ASL_login_config'),
'oasl_registration' => array('BOARDDIR/addons/1ASL/', '1ASL_login_registration'),
'oasl_callback' => array('BOARDDIR/addons/1ASL/', '1ASL_login_callback'),
);

return $actionArray;
}

I am not so sure about the fifth modification below:
Code: [Select]
[b][u]Fifth modification[/u][/b]
<file name="$sourcedir/Load.php">
<operation>
<search position="before"><![CDATA[// Some basic information...
if (!isset($context['html_headers']))
$context['html_headers'] = '';]]></search>
<add><![CDATA[

// OneAll Social Login (https://docs.oneall.com/plugins/)
if ( ! empty ($modSettings['oasl_api_subdomain']))
{
$context['html_headers'] .= "\n<!-- OneAll.com / Social Login for SMF //-->\n";
$context['html_headers'] .= '<script type="text/javascript" src="//' . htmlspecialchars ($modSettings['oasl_api_subdomain']) . '.api.oneall.com/socialize/library.js"></script>';
}]]></add>
</operation>
</file>

I am thinking to load this as early as intergrate_pre_load or during integrate_theme_load. May be the later is more appropriate.
Code: [Select]
function 1ASL_PreLoad(&$actionArray, &$adminActions)
{
global $context, $modSettings;

if (!empty($modSettings['oasl_api_subdomain']))
$context['html_headers'] .= '<script type="text/javascript" src="//' . htmlspecialchars ($modSettings['oasl_api_subdomain']) . '.api.oneall.com/socialize/library.js"></script>';

}

Just few more lines to be converted and then finish this up for a good test. Any supports, feedbacks and comments on the above and other converted files[1] are appreciated.
All files, I think, are duly converted except few more things in modification.xml discussed above and they are packaged and attached below.
Title: Re: Social Login
Post by: meetdilip on August 13, 2016, 02:06:39 pm
Social log in is an awesome concept. Especially in these days.
Title: Re: Social Login
Post by: emanuele on August 13, 2016, 02:44:46 pm
Quote
Code: [Select]
function 1ASL_
http://php.net/manual/en/functions.user-defined.php
QuoteA valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
You cannot use 1 as first letter of a function name.
Title: Re: Social Login
Post by: ahrasis on August 15, 2016, 09:37:33 am
I think I converted everything as it installed fine now but its settings menu do not appear. Nothing in the error log. I attached the packaged file.
Title: Re: Social Login
Post by: meetdilip on August 15, 2016, 10:47:05 am
Thanks @ahrasis
Title: Re: Social Login
Post by: emanuele on August 15, 2016, 03:24:57 pm
Where did you put the files?
Code: [Select]
add_integration_function('integrate_pre_include', 'SOURCEDIR/OASL.subs.php');
add_integration_function('integrate_pre_load', 'OASL_PreLoad');
add_integration_function('integrate_actions', 'OASL_Action');
add_integration_function('integrate_admin_areas', 'OASL_Admin_Menu');
in SOURCEDIR or in ADDONSDIR?
And are you coding it for 1.1 or 1.0?
Title: Re: Social Login
Post by: ahrasis on August 15, 2016, 08:38:46 pm
Noted that. I think I have moved it to ADDONSDIR. Anyway, there are lots of bugs in this package. May be I'll redo it again later.
Title: Re: Social Login
Post by: billwill on March 22, 2017, 10:30:08 am
@ahrasis

Glad you took this on, but it isn't visible in the addon area.  Did you get this to work, or give up on in?  Sure would be a great thing to have!
Title: Re: Social Login
Post by: ahrasis on March 22, 2017, 11:35:07 pm
Sorry. I forgot this addon altogether. I'll see to it soon.
Title: Re: Social Login
Post by: ahrasis on March 23, 2017, 01:19:04 am
While fixing the addon's broken code I got this error:
Quote "PHP message: PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function OASL_PreLoad(), 0 passed in /sources/Subs.php on line 3848 and exactly 2 expected in /sources/addons/OASL/OASL.subs.php:921
Stack trace:
#0 /sources/Subs.php(3848): OASL_PreLoad()
#1 /sources/Load.php(135): call_integration_hook('integrate_pre_l...')
#2 /index.php(102): reloadSettings()
#3 {main}
  thrown in /var/www/clients/client2/web1/web/sources/addons/OASL/OASL.subs.php on line 921"

Line 921 is this function:
Code: [Select]
function OASL_PreLoad(&$actionArray, &$adminActions)
{
global $context, $modSettings;

if (!empty($modSettings['oasl_api_subdomain']))
$context['html_headers'] .= '<script type="text/javascript" src="//' . htmlspecialchars ($modSettings['oasl_api_subdomain']) . '.api.oneall.com/socialize/library.js"></script>';

}

The latest package (containing the above error) is attached.
Title: Re: Social Login
Post by: ahrasis on March 23, 2017, 04:37:14 am
I forgot why did I want to preload the above but I think it has to be put in the header so I did minor changes to to the hook. Now, it get to another error causing admin page not accessible (it will get you back to forum frontpage):
Code: [Select]
A non well formed numeric value encountered
index.php?action=admin;area=packages;sa=install2;package=OASL.zip;pid=0
/sources/ext/cssmin.php
Line: 769
What does this means anyway?

The latest package is attached.[1]
I think I need to rewrite this from the beginning so I know what I did last time.
Title: Re: Social Login
Post by: emanuele on March 23, 2017, 06:14:56 am
Would you mind having a look and see what line 769 of cssmin.php looks like?
Title: Re: Social Login
Post by: ahrasis on March 24, 2017, 07:37:43 am
@emanuele, the above could be due to using php7.1 though (int) seems in place. Using php5.6 seems fine though.

Code: [Select]
765: 	    private function normalize_int($size)
766:     {
767:         if (is_string($size)) {
768:             switch (substr($size, -1)) {
==>769:                 case 'M': case 'm': return $size * 1048576;
770:                 case 'K': case 'k': return $size * 1024;
771:                 case 'G': case 'g': return $size * 1073741824;
772:             }
773:         }
774:
775:         return (int) $size;

Anyway, the package has re-converted and so far it went smooth except for minor error. I attached it here for everybody's testing.
Title: Re: Social Login
Post by: ahrasis on March 24, 2017, 08:12:08 am
Missed changing $sourcedir to SOURCEDIR in subs file. I attached here the latest one. Hopefully, this time is more useful. You can check https://elkarte.sch.my by clicking on its login and registration button.
Title: Re: Social Login
Post by: emanuele on March 24, 2017, 08:50:31 am
Can you report the bug?
It's in SiteCombiner:
Code: [Select]
$compressor = new CSSmin($this->_cache);
should be:
Code: [Select]
$compressor = new CSSmin();
Title: Re: Social Login
Post by: ahrasis on March 24, 2017, 09:00:26 am
Done.
Title: Re: Social Login
Post by: ahrasis on March 24, 2017, 09:10:54 am
Note that the error is still there when I did the required change inn SiteCombiner and tried installing two more addons (after the above post). Do I have to clear caches / cookies or anything first?

EDITED: I cleared the caches and the cookies but the error is still there.
Title: Re: Social Login
Post by: Spuds on March 24, 2017, 11:28:26 am
Please try the attached version of cssmin.php (for sources/ext)

@emanuele‍ if this fixes the issue we should add this to 1.0.10 since its another php7 fix :(
Title: Re: Social Login
Post by: ahrasis on March 24, 2017, 11:59:46 am
Thank you very much. That fixed it alright.
Title: Re: Social Login
Post by: billwill on March 28, 2017, 01:06:48 pm
Hooray! :D