Welcome to Geeklog Saturday, May 18 2013 @ 08:33 AM EDT
|
||||||||
![]() |
Forum Index > Support > General Geeklog Support |
New Topic
|
Post Reply
|
can anonymous users change the language? |
|||
| Anonymous: cesar |
|
||||||
|
|
Hi,
I need, in my site, allow to anonymous users change language. Is it possible? My GL version 1.8.1 Sorry by my english, Thanks |
||||||
|
|||||||
| Roccivic |
|
||||||
![]() ![]() ![]() ![]() ![]() Moderator ![]() Status: offline ![]() Registered: 05/19/10 Posts: 136 |
No, not out of the box. That said, here's a quick and dirty solution that will work with Javascript enabled.
Login as root Download and install the autotags plugin: http://code.google.com/p/geeklog/downloads/detail?name=autotags_1.1.0_1.8.0.zip Enable PHP code execution in autotags: From "Admins only" menu select "Groups" Find "Autotags Admin" and click "Edit" Tick the box "autotags.PHP" and click "Save" Create a new autotag: From "Admins only" menu select "Autotags" Click "Create new" For "Tag" enter "langsel" Tick the box near "Replace with PHP?" Click "Save" Open the file "system/lib-custom.php" At the bottom of the file (but before the line "?>" ) add the below code and save the file. PHP Formatted Code function phpautotags_langsel(){ global $_USER, $_CONF, $_SCRIPTS; if ($_USER['uid'] ) { $retval = "<a href='" . $_CONF['site_url'] . "/usersettings.php'>Change in profile</a>"; } else { $_SCRIPTS->setJavascript(' <script type="text/javascript"> $(document).ready(function () { $("#langsel").show().change(function () { var selection = $("#langsel option:selected").val(); document.cookie = "' . $_CONF['cookie_language'] . '=" + escape(selection); location.href = ""; }); }); </script> '); $language = MBYTE_languageList($_CONF['default_charset']); $retval = '<noscript>This functionality requires JavaScript</noscript>' . LB; $retval .= '<form><div><select id="langsel" style="display: none">' . LB; foreach ($language as $langFile => $langName) { $retval .= '<option value="' . $langFile . '"'; if ($langFile == COM_getLanguage()) { $retval .= ' selected="selected"'; } $retval .= '>' . $langName . '</option>' . LB; } $retval .= '</select></div></form>'; } return $retval; } Create a new block: From "Admins only" menu select "blocks" Click on create new Enter "Language selection" as title and whatever you like for the name For block content add: PHP Formatted Code [langsel:]Tick the box near "Autotags" Save and logout Done. You should now have a language selection block for anonymous users. |
||||||
|
|||||||
| ::Ben |
|
||||||
![]() ![]() ![]() ![]() ![]() Full Member ![]() Status: offline ![]() Registered: 01/14/05 Posts: 1359 |
Hi,
This is also working as a block without the autotag step. I only changed $_USER['uid'] > 1 PHP Formatted Code function phpblock_langsel(){ global $_USER, $_CONF, $_SCRIPTS; if ($_USER['uid'] > 1 ) { $retval = "<a href='" . $_CONF['site_url'] . "/usersettings.php'>Change in profile</a>"; } else { $_SCRIPTS->setJavascript(' <script type="text/javascript"> $(document).ready(function () { $("#langsel").show().change(function () { var selection = $("#langsel option:selected").val(); document.cookie = "' . $_CONF['cookie_language'] . '=" + escape(selection); location.href = ""; }); }); </script> '); $language = MBYTE_languageList($_CONF['default_charset']); $retval = '<noscript>This functionality requires JavaScript</noscript>' . LB; $retval .= '<form><div><select id="langsel" style="display: none">' . LB; foreach ($language as $langFile => $langName) { $retval .= '<option value="' . $langFile . '"'; if ($langFile == COM_getLanguage()) { $retval .= ' selected="selected"'; } $retval .= '>' . $langName . '</option>' . LB; } $retval .= '</select></div></form>'; } return $retval; } Ben We speak french on http://geeklog.fr |
||||||
|
|||||||
| Roccivic |
|
||||||
![]() ![]() ![]() ![]() ![]() Moderator ![]() Status: offline ![]() Registered: 05/19/10 Posts: 136 |
Quote by: ::Ben I only changed $_USER['uid'] > 1 Good catch |
||||||
|
|||||||
| ironmax |
|
||||||
![]() ![]() ![]() ![]() ![]() Moderator ![]() Status: offline ![]() Registered: 06/20/03 Posts: 645 |
Nice job guys!!!! I'll make this as part of the demo site so that new users will find it easier to navigate.
Michael Have you seen the Geeklog Demo site? Check it out by clicking on the Demo Site link to the left under Resources - Getting started. |
||||||
|
|||||||
| ::Ben |
|
||||||
![]() ![]() ![]() ![]() ![]() Full Member ![]() Status: offline ![]() Registered: 01/14/05 Posts: 1359 |
Yes it is a really good feature and it could become a default block on new Geeklog install
Ben We speak french on http://geeklog.fr |
||||||
|
|||||||
| Anonymous: cesar |
|
||||||
|
|
thanks for all but i don't use java in my server.
may be a code for php? i tride this but don't work. PHP Formatted Code function phpblock_langsel(){ global $_USER, $_CONF; $id_language=$_POST['id_language']; if ($_POST['id_language']) { $_CONF['cookie_language']=$id_language; } if ($_USER['uid'] > 1 ) { $retval = "<a href='" . $_CONF['site_url'] . "/usersettings.php'>Change in profile</a>"; } else { $language = array_flip(MBYTE_languageList($_CONF['default_charset'])); $retval .= "<form method='post' action='index.php'><select name='id_language'>"; foreach ($language as $langName) { $retval .= '<option>'.$langName.'</option>'; } $retval .= "</select><input type='submit' value='Choose'></form>"; } return $retval; } thanks |
||||||
|
|||||||
| Roccivic |
|
||||||
![]() ![]() ![]() ![]() ![]() Moderator ![]() Status: offline ![]() Registered: 05/19/10 Posts: 136 |
The solution is in PHP, in fact no one said anything about Java. I mentioned JavaScript, which is a client side scripting language that most modern browsers have built-in, so you don't have to worry about that.
Anyway, read this: http://www.geeklog.net/article.php/20011231130438109 And then use the code from Ben's post. |
||||||
|
|||||||
| Anonymous: cesar |
|
||||||
|
|
Ok, so it is an error in my server i think.
i think i know how to create a new php block because i've got a site where it uses more of 100 phpblocks but i'll say you what i did. 1-. Copy and paste the Ben's code in my system/lib-custom.php at the end but before ?> 2-. Create a new block: Title "Language selection" (i think it is no important but i do it), Type phpblock, in options of php block i write "phpblock_langsel" without (). Permisions all checked. 3-. Save There are some part of code that not work and i don't know why. 1-. I exit of system and visit it like anonymous. (Before i clean cockies in firefox). 2-. Only show the tittle of block (Language selection) If i delete, in Ben's code, the part PHP Formatted Code style="display: none"But i switch languages in box and it do nothing. My site, under construction, www.lawebdelcamping.com thanks for all. |
||||||
|
|||||||
| Roccivic |
|
||||||
![]() ![]() ![]() ![]() ![]() Moderator ![]() Status: offline ![]() Registered: 05/19/10 Posts: 136 |
OK, i can see the problem on your site, you are missing jQuery.
Please put back: PHP Formatted Code style="display: none"And include jQuery: PHP Formatted Code function phpblock_langsel(){ global $_USER, $_CONF, $_SCRIPTS; if ($_USER['uid'] > 1 ) { $retval = "<a href='" . $_CONF['site_url'] . "/usersettings.php'>Change in profile</a>"; } else { $_SCRIPTS->setJavascriptLibrary('jquery'); // Add this line $_SCRIPTS->setJavascript(' <script type="text/javascript"> $(document).ready(function () { $("#langsel").show().change(function () { var selection = $("#langsel option:selected").val(); document.cookie = "' . $_CONF['cookie_language'] . '=" + escape(selection); location.href = ""; }); }); </script> '); // etc... |
||||||
|
|||||||
| ::Ben |
|
||||||
![]() ![]() ![]() ![]() ![]() Full Member ![]() Status: offline ![]() Registered: 01/14/05 Posts: 1359 |
Try this code below as jQuery library is not set on new install. Do not remove the display: none, It must be working (see demo here).
PHP Formatted Code function phpblock_langsel() { global $_USER, $_CONF, $_SCRIPTS; $_SCRIPTS->setJavaScriptLibrary('jquery'); if ($_USER['uid'] > 1 ) { $retval = "<a href='" . $_CONF['site_url'] . "/usersettings.php'>Change in profile</a>"; } else { $_SCRIPTS->setJavascript(' <script type="text/javascript"> $(document).ready(function () { $("#langsel").show().change(function () { var selection = $("#langsel option:selected").val(); document.cookie = "' . $_CONF['cookie_language'] . '=" + escape(selection); location.href = ""; }); }); </script> '); $language = MBYTE_languageList($_CONF['default_charset']); $retval = '<noscript>This functionality requires JavaScript</noscript>' . LB; $retval .= '<form><div><select id="langsel" style="display: none">' . LB; foreach ($language as $langFile => $langName) { $retval .= '<option value="' . $langFile . '"'; if ($langFile == COM_getLanguage()) { $retval .= ' selected="selected"'; } $retval .= '>' . $langName . '</option>' . LB; } $retval .= '</select></div></form>'; } return $retval; } Ben We speak french on http://geeklog.fr |
||||||
|
|||||||
| Anonymous: cesar |
|
||||||
|
|
Perfect.
thanks for all. |
||||||
|
|||||||
| Roccivic |
|
||||||
![]() ![]() ![]() ![]() ![]() Moderator ![]() Status: offline ![]() Registered: 05/19/10 Posts: 136 |
I've created an improved solution for this issue.
The new solution also works without JavaScript and for logged-in users. Please see here: http://www.geeklog.net/forum/viewtopic.php?showtopic=93490 |
||||||
|
|||||||
| mocoli |
|
||||||
![]() ![]() ![]() ![]() ![]() Junior Status: offline ![]() Registered: 02/10/12 Posts: 19 |
Quote by: Roccivic I've created an improved solution for this issue. It works fine for me, Thanks a lot this coding. |
||||||
|
|||||||
| Content generated in: 3.08 seconds |
|
|
|