From 2 column to 3 column

I want to develop a plugin to change the Friends page from one sidebar to a 3 colume layout. Can it be done because there's no Friends plugin?

  • It is possible. Create a plugin that does the following:

    Unregister the default ''friends" page handler and register your own:

    myplugin_init () {
        elgg_unregister_page_handler('friends');
        elgg_register_page_handler('friends', 'myplugin_friends_page_handler');

    Copy the contents of the original friends_page_handler() found in engine/lib/users.php to your own page handler.

    Also copy the file pages/friends/index.php to your plugin.

    Then change the paths in the page handler so that they are pointing to the index.php that you just copied:

    elgg_get_plugins_path() . "/yourplugin/pages/index.php"

    Then in the index.php change this:

    $body = elgg_view_layout('one_sidebar', $params);

    To this:

    $body = elgg_view_layout('two_sidebar', $params);

    And now you should have the page with one main column and two sidebars. You can pass content to the left sidebar in index.php with:

    $params['sidebar_alt'] = 'Some content here';

    The two_sidebar is one of the default layouts in Elgg. If it's not what you are looking for you can create your own layout instead. Your own layout becomes available to the elgg_view_layout() function if it is placed in directory views/default/page/layouts/.

  • Thanks JJ very concise and perfectly pitched to my current level. Will be back with my progress.

  • When I click on Friends I get an internal server error 500, here's my start.php code and I copied pages/friends/index.php to mod/mytheme/pages/friends/index.php, can anyone see where I've gone wrong...

    <?php

    register_elgg_event_handler('init','system','mytheme_init');

     

    function mytheme_init() {

    // Replace the default friends page

    elgg_unregister_page_handler('friends');

        elgg_register_page_handler('friends', 'mytheme_friends_page_handler');

    }

    function mytheme_friends_page_handler($page_elements, $handler) {

    elgg_set_context('friends');

     

    if (isset($page_elements[0]) && $user = get_user_by_username($page_elements[0])) {

    elgg_set_page_owner_guid($user->getGUID());

    }

    if (elgg_get_logged_in_user_guid() == elgg_get_page_owner_guid()) {

    collections_submenu_items();

    }

     

    switch ($handler) {

    case 'friends':

    require_once(dirname(dirname(dirname(__FILE__))) . "/mytheme/pages/friends/index.php");

    break;

    case 'friendsof':

    require_once(dirname(dirname(dirname(__FILE__))) . "/pages/friends/of.php");

    break;

    default:

    return false;

    }

    return true;

    }

     

     

     

     

     

  • look first into your apache logs to see exactly what is going on;-O

  • @Burgs

    Yep, the fastest way to see what exactly is wrong is to check the apache error log. (Supposing that you have access to it.)

    Oh, and code in messages is much more readable if you but it inside a blockquote and also spend some time to nest it with four spaces where needed:

    function placed_inside_a_blockquote() {
        // There's four spaces at the beginning of these
        // two rows so the function is easier to read.

    You can make line breaks with Shift + Enter. (Whereas Enter starts a completely new paragraph.)

  • @Juho J... I've been wondering how that was done. Just requested access to the logs.

  • Does this tell you anything. I've checked the file and it's on the server. I uploaded an unedited copy of index.php but still the same 500 error

     

    [Tue May 29 16:21:14 2012] [error] [client 91.125.74.254] PHP WARNING: 2012-05-29 16:21:14 (BST): "require_once(/home/sites/mytestsite.com/public_html/elgg/mytheme/pages/friends/index.php): failed to open stream: No such file or directory" in file /home/sites/mytestsite.com/public_html/elgg/mod/mytheme/start.php (line 41), referer: http://community.mytestsite.com/activity/

    [Tue May 29 16:21:14 2012] [error] [client 91.125.74.254] PHP Fatal error:  require_once(): Failed opening required '/home/sites/mytestsite.com/public_html/elgg/mytheme/pages/friends/index.php' (include_path='.:/usr/share/pear53:/usr/share/php') in /home/sites/mytestsite.com/public_html/elgg/mod/mytheme/start.php on line 41, referer: http://community.mytestsite.com/activity/

     

     

  • It says "No such file or directory" so there has to be something wrong with the path to the index.php file. As you look at the path you see that the mod directory is missing:

    /home/sites/mytestsite.com/public_html/elgg/mod/mytheme/pages/friends/index.php

    Instead of calling the file with:

    require_once(dirname(dirname(dirname(__FILE__))) . "/mytheme/pages/friends/index.php");

    It might be better to call it with this:

    include elgg_get_plugins_path() . 'mytheme/pages/friends/index.php';

    Function elgg_get_plugins_path() always gets the correct plugin directory so you don't have to use dirname(__FILE__) for that.

  • @Juho J... That works, well done. I owe you a beer.