[Elgg 1.8-1.12 & 2.X: Login required] v1.8.3

Release Notes

Changelog:

  • Only code clean-up. No changed functionality.
  • @Daniel: the code for hiding the search box is from another plugin of mine: http://community.elgg.org/plugins/1101722/1.0/minimal-hide-search-box-plugin-for-elgg-18. If you don't want to use this separate plugin to disable the search box you would only need to include the lines

    if(!elgg_is_logged_in()){

        elgg_unextend_view('page/elements/header', 'search/header');

    }

    in an init function of another plugin, e.g. your theme plugin. There's no need to include the whole function.

    Regarding the "Login with Facebook" (which "Facebook" plugin exactly?) and "Uservalidation by Admin" problem I'm not sure it's only caused by the Loginrequired plugin - if at all. Maybe the Facebook login plugin simply fails to work with the "Uservalidation by Admin" plugin even with no walled-garden plugin used. Have you tried this yet? Second thing to check is if the Facebook login plugin and the Admin Uservalidation plugin each work separately with the Loginrequired plugin. You should/must also place the Loginrequired plugin below both other plugins for it to work best / work at all. You can also try changing the order of the Facebook and Admin Validation plugins if they fail to work together. Maybe this helps. Regarding the registration page not be displayed I can't say what might cause it right now. It might be solved by bringing the plugins in the correct order. But it might also be a problem caused by yet another plugin (your theme?) that might override the registration page view and then fails to work in connection with the Facebook login plugin.

  • Thanks. I use Easytheme 1.3.2 and Facebook Connect 1.8. I noticed that the Facebook plugin allows anyone with a valid FB account access, and it sends out a mail with a temporary password.

    I'll keep digging.

  • Hi,

    Is there a way, when using this plugin, to add items to the navigation menu that are for public view only?? Currently the navigation menu (top bar menu) is not displayed. I would like to add my custom public pages here for the non logged in user to navigate to.

     

    Thank you much.. Odin.

  • @Odin: yes, it's possible to have a navigation menu that includes entries for your public pages. Though it requires a bit of work to get the menu show up. Best would be to create a new menu and not add the menu items of the public pages to the normal site menu as this would result in all the other menu items to show up, too (if you don't unregister them all).

    First thing to do is to re-enable the menu when logged out or better create the new menu. In mod/loginrequired/views/default/page/elements/header.php add the line shown in bold:

    <?php
    /**
     * Elgg page header
     * In the default theme, the header lives between the topbar and main content area.
     */

    if (!elgg_is_logged_in()) {

      // link back to main site.
      echo elgg_view('page/elements/header_logo', $vars);

      // drop-down login
      echo elgg_view('core/account/login_dropdown');

    // insert custom site-wide navigation
      echo elgg_view_menu('public');
    }
    else {

      // link back to main site.
      echo elgg_view('page/elements/header_logo', $vars);

      // drop-down login
      echo elgg_view('core/account/login_dropdown');

      // insert site-wide navigation
      echo elgg_view_menu('site');
    }

    Next you need to add a view for this new menu by adding the file mod/loginrequired/views/default/navigation/menu/public.php:

    <?php
    /**
     * Custom public navigation menu
     *
     * @uses $vars['menu']['default']
     * @uses $vars['menu']['more']
     */

    $default_items = elgg_extract('default', $vars['menu'], array());

    echo '<ul class="elgg-menu elgg-menu-site elgg-menu-site-default clearfix">';
    foreach ($default_items as $menu_item) {
        echo elgg_view('navigation/menu/elements/item', array('item' => $menu_item));
    }

    echo '</ul>';

    (I've not included the "More" menu item here. If you have so many public menu items that the "More" dropdown menu item is necessary then check out the core view views/default/navigation/menu/site.php to see how to create the "More" menu item).

    Last thing to do is to register your custom menu items to the new "public" menu in start.php of the loginrequired plugin. For each page you would need to add something like (blog page as example):

    // add a public menu navigation item
      $item = new ElggMenuItem('blog', elgg_echo('blog:blogs'), 'blog/all');
      elgg_register_menu_item('public', $item);

    In the "new ElggMenuItem" line the first parameter is an identifier of your choice for the menu item, the second parameter is the Menu text you can either provide here directly or better via a language file string to allow for multiple language menu texts. The last parameter is the page url where your public page is to be found.

  • iionly.. great info thankyou! I will implement it.. check out my implementation using login required, i extende3d it to integrate with facebook api, it has proved extremely useful plugin. http://www.worldrainbowfamily.org

     

  • Hello! How add widget on loginrequired_index.php file? For example Latest activity (show code please).

     

  • I don't know what the sense of adding a latest activity widget to the index page would be as this seems to contradict the purpose of a walled garden site but... well...

    In loginrequired/views/default/page/layouts/login_required_index.php add the lines

    $activity = elgg_list_river(array("pagination" => false, "limit" => 10));
    echo elgg_view_module('featured', elgg_echo('river:widget:title'), $activity, $mod_params);

    for example below the line

    echo elgg_view("index/lefthandside");

    to get a latest activity widget on the index page. Though it will not be very useful because the visitors won't be able to follow the links in the entries when logged out. Depending on the access level settings of the site and the site content respectively the shown entries might also be incomplete.

    More examples of how to add widgets to the index page can be found in the code of the bundled custom_index plugin. The structure of the loginrequired plugin follows the structure of the custom_index plugin. In the custom_index plugin the content of the widgets is fetched in custom_inxex/index.php and the output is done in custom_index/views/default/page/layouts/custom_index.php. In the loginrequired plugin the corresponding files are loginrequired/index.php and loginrequired/views/default/page/layouts/login_required_index.php. So, you could add the code from the custom_index plugin to the loginrequired plugin in the corresponding files to add widgets. For other content / other widgets not included in the custom_index plugin default layout it works according to the same lines.

  • This is a wonderful plugin, i recomend it. It morks with twitter-api login but it is not working with facebook connect login v1.3 by Chetan Varshney. it pops up "you must be logged in to view that page" every time i try to login with but when i deactivate Login Required, facebook login works perfectly. pleace is there anyway i can permit facebook login?

  • @idorenyin: place the Loginrequired plugin below the Facebook connect plugin, if you have not already done so. Actually, placing the Loginrequired plugin at the bottom of the plugin list should work best.

    If placing below the Facebook connect plugin is not enough add the lines that I marked bold in the following in start.php of the Loginrequired plugin:

    // Add more allowed URL's...
    function login_required_default_allowed_list($hook, $type, $returnvalue, $params) {
      global $CONFIG;

      // If externalpages plugin is active allow access to its pages
      $add = array();
      $add[] = 'terms/';
      $add[] = 'terms';
      $add[] = 'privacy/';
      $add[] = 'privacy';
      $add[] = 'about/';
      $add[] = 'about';
    $add[] = 'facebook_connect/forward';
      $add[] = 'facebook_connect/login';

      return $add;
    }

    I've only looked into the start.php of the Facebook connect plugin to find out which pages need to be accessible when logged out for the Facebook connect plugin to work. If the Loginrequired plugin is below the Facebook connect plugin these pages should be considered to be accessible when logged out by the Loginrequired plugin already.

    If both changing the plugin order and (in case this first options fails) also adding the two page entries to the array of allowed URLs within start.php of the Loginrequired plugin does not work, you might want to ask the developer of the Facebook connect plugin if there might be other pages and or actions need to be accessible when logged out for the Facebook login to worked on walled-garden Elgg sites. I can't test this on my own (or rather I'm not willing to register a Facebook API key to test this out). If both options I described fail I assume that also the built-in walled-garden feature of Elgg fails to work and this would mean that the Facebook plugin does not define all pages necessary for it to work as public.

  • hey @iionly really good plugin :) thank you, how do you make the text bold for this:

    $infobox = 

     

    Line 31  loginrequired_index_example.php

  • also i have login then right side pic and a little text, can i put another box below that is full width ? etc : )

  • @UK:

    You can make the text shown to be bold by using the html <b> tag, e.g.

    $infobox = '<b>'.'Text shown in right column widget in bold.'.'</b>';

    Of course, you could use other html tags in the same way to change the style of the text like using italics, colors etc. If you don't add the text directly in the loginrequired_index.php view but use elgg_echo() to display any language string defined in a language file, you could also use the html tags in the language strings directly.

    Here's an example of how to add a full widgth column below the two-column widgets:

    <?php
    /**
     * Loginrequired Login page layout
     *
     */

    $mod_params = array('class' => 'elgg-module-highlight');
    ?>

    <div class="loginrequired-index elgg-main elgg-grid clearfix">
            <div class="elgg-col elgg-col-1of2">
                    <div class="elgg-inner pvm prl">
    <?php
    $top_box = $vars['login'];

    echo elgg_view_module('featured',  '', $top_box, $mod_params);

    echo elgg_view("index/lefthandside");
    ?>
                    </div>
            </div>

            <div class="elgg-col elgg-col-1of2">
                    <div class="elgg-inner pvm">
    <?php
    // right column

    // a view for plugins to extend
    echo elgg_view("index/righthandside");

    $infobox = '<b>'.'Text shown in right column widget in bold.'.'</b>';
    $infobox .= '<img src="./frontpage_image.jpg" alt="Frontpage_Image">';

    echo elgg_view_module('featured',  elgg_echo("Title of right column widget"), $infobox, $mod_params);

    ?>
                    </div>
            </div>
            <div class="elgg-col elgg-col-2of2">
                    <div class="elgg-inner pvm">
    <?php
    // full width column content

    $infobox = '<i>'.'Text in italic shown in full width column widget.'.'</i>'.' And now without italic.';

    echo elgg_view_module('featured',  elgg_echo("Title of full width column widget"), $infobox, $mod_params);

    ?>
                    </div>
            </div>
    </div>

    The bundled developers plugin shows examples of the grid usage in the theming sandbox (in the admin section of the site). The code that gives the exmple grid layout is in mod/developers/views/default/theme_preview/grid.php.

    The "pvm", "prl" used in the class names define padding around the widgets. The padding is defined in views/default/css/elements/helpers.php.

    As a sitenote, in Elgg 1.9 the class names for the grid layout have changed slightly. So, if you update your site once Elgg 1.9 is finished and released you would need to adjust the class names in any custom index page you have created. This is not difficult though and I've already released an Elgg 1.9 version of the Loginrequired plugin with an updated example.

  • @iionly thank you so much for this very detailed reply much appreciated, so when 1.9 comes out you have the same plugin for that very nice! ^_^ 

     

    So i just add this code below to the bottom of inex.php of your plugin and edit it then job done? : )

     

    <?php
    /**
     * Loginrequired Login page layout
     *
     */

    $mod_params = array('class' => 'elgg-module-highlight');
    ?>

    <div class="loginrequired-index elgg-main elgg-grid clearfix">
            <div class="elgg-col elgg-col-1of2">
                    <div class="elgg-inner pvm prl">
    <?php
    $top_box = $vars['login'];

    echo elgg_view_module('featured',  '', $top_box, $mod_params);

    echo elgg_view("index/lefthandside");
    ?>
                    </div>
            </div>

            <div class="elgg-col elgg-col-1of2">
                    <div class="elgg-inner pvm">
    <?php
    // right column

    // a view for plugins to extend
    echo elgg_view("index/righthandside");

    $infobox = '<b>'.'Text shown in right column widget in bold.'.'</b>';
    $infobox .= '<img src="./frontpage_image.jpg" alt="Frontpage_Image">';

    echo elgg_view_module('featured',  elgg_echo("Title of right column widget"), $infobox, $mod_params);

    ?>
                    </div>
            </div>
            <div class="elgg-col elgg-col-2of2">
                    <div class="elgg-inner pvm">
    <?php
    // full width column content

    $infobox = '<i>'.'Text in italic shown in full width column widget.'.'</i>'.' And now without italic.';

    echo elgg_view_module('featured',  elgg_echo("Title of full width column widget"), $infobox, $mod_params);

    ?>
                    </div>
            </div>
    </div>

  • It's what should go into mod/loginrequired/views/default/page/layouts/loginrequired_index.php

  • i see i just copy all of that over the whole index code and then edit, very nice! ^_^

  • do i need custom idex to be enabled for this plugin? i am using profile manager too, would you suggest i have custom index activiated? : ) thank you

  • its not this plugin i am sure it is somthing else as i have disabled this plugin and still same problem maybe i have no clue but i dont see a solution here or have i missed somthing? sorry for my stupidity please help me : )

  • were do i add the privacy about terms links so they show as public i seen your explanation but i do not know were to add i keep getting error

  • want to show them in the footer too, basically need about terms and privacy to be public and it is possible with editing the start.php but how lol? whch lines etc i keep getting errors siote goes dead and then i put back to the way it was before and no problems but i can not show about terms privacy : ( excuse my lack of knowledge

  • i have a small problem i have my header image at 230 high 975 wide it looks ok when not logged in but when you login the bottom of the image is missing by around 1 inch and i have no clue how to fix this : (

  • @UK: you don't need the custom_index plugin to be enabled to be able to use the Loginrequired plugin.

    The content of the About, Terms and Privacy pages (and the pages itself) are handled by the bundled externalpages plugin. You need to enter the content that should be shown on these pages in the corresponding admin section on your site (Configure - Appearance - Site pages). The links to these pages should show up automatically in the footer of your site. If not, some plugin overrides the footer view and hides these links. These pages are public (accessible when logged out) even with a walled-garden plugin like the Loginrequired plugin enabled.

    Place the Loginrequired plugin at the bottom of your plugin list. Any pages defined as "public" by other plugins should be considered then. If the Loginrequired plugin is placed above a plugin that adds a public page, the access to this page might fail otherwise.

    I don't know how you can fix the problem with the header image. I can only guess that a plugin (most likely the theme plugin used on your site) makes the height of the header area fixed in size so the bottom of the image is hidden. Or do you have the same problem when using an image that is smaller in height. If the same problem occurs then the layout of your theme might add a border around the header section. What does it look like with the Elgg default site theme used? Is it the same?

  • the image problem is only with this plugin but it is easly fixed by leaving a little space at the bottom of the image so its not a big issue, when you say at the top of the plugin list you mean at the top of all plugins or at the bottom of all plugins, as my emails did not work when i had it above other plugins here some screen shots of how it is setup and everything is working good execpt for the fotter link about privacy etc even though they are not shown i still can not acess them directly unless i am logged in. thanks for the reply : )

     

     

     

    image

     

     

     

  • i could just add in the links in the fotter quite easly though they woul;d still be only for logged in users so i dont know lol

  • @UK: when I say "bottom" I mean "bottom" and not "top". The meaning of top and bottom is already defined by the "Top", "Up", "Down" and "Bottom" links in the plugin list which move a plugin also in the corresponding direction if you don't drag+drop it with the mouse directly.

    So, when I say "put the Loginrequired plugin at the bottom of the list" I mean put it at the last place. As you already noticed you need to placve the Uservalidationbyemail plugin above the Loginrequired plugin. The same is true for other plugins which might define "public pages" or need some service to be available when logged out.

    The Loginrequired plugin does nothing when a user is logged in. Therefore, I would be rather surprised if there's any effect when a user is logged in. It don't know how exactly you added your header image - and I'm most likely not the best choice to ask about theming issues as I don't have much knowledge in this area. But I've tried adding a image (with 975x230 px dimensions) to the header. I've done it by adding it as a background image to the elgg-page-header class in Elgg's CSS. What I noticed is that I had to add a height:230px; to this class in order for the whole image showing. But this was necessary to get the image correctly displayed both when logged in and logged out. There's nothing the Loginrequired plugin has to do with that. Though the min height is not the only change that would be necessary for the image to show up correctly. When logged in the site menu is over the image and this would have to get moved down, too (though I'm stopped the testing here). So, the problem on your site with part of the image being hidden is most likely not because of the Loginrequired plugin but because the site menu is overlaying the header image. The only reason you don't have the same problem when logged out is because the Loginrequired plugin hides the site menu here.

    If you only want to hide the Elgg logo/ the link to the Elgg site in the footer then you could simply override the views/default/page/elements/footer.php view and remove the link and logo by modifying your version of the view accordingly. The Footer Editor plugin does basically the same and overrides this view with whatever you entered in the plugin settings of this plugin as content. Unfortunately, this plugin also removes the Footer menu which would add the links to the About, Terms and Privacy pages. Nonetheless, you could also add these links on your own when using the Footer editor plugin. I've just tested this when logged out and the Loginrequired plugin active. It worked without problems. So, you might have entered the wrong urls for the links.

Stats

  • Category: Misc
  • License: GNU General Public License (GPL) version 2
  • Updated: 2016-12-11
  • Downloads: 8389
  • Recommendations: 26

Other Projects

View iionly's plugins