Elgg unextend view

Posted on Dec 24, 2011 in News, Tips & Tricks, Tutorials | 0 comments

Elgg unextend view

Just like you can extend Elgg views you can unextend views. The function elgg_unextend_view takes two parameters. The view that was extended and the view that was extending that view. elgg_unextend_view($view, $view_extension) When you look at a fresh Elgg installation, you’ll notice the search form on the front page. If your content is meant for logged in users it does not make sence to display a search form when not logged in. So let’s remove the form from the front page. Find your plugin “myplugin” and add this snippet to your init function in start.php, if (!elgg_is_logged_in()) { elgg_unextend_view('page/elements/header', 'search/header'); } That’s all you need, the search form is gone. Let’s find another view to remove. Log in and go to your profile. Right next to your profile icon, your latest wire post is displayed. The wire extend your profile page with that view. You can remove it by adding this to myplugin start.php, elgg_unextend_view('profile/status', 'thewire/profile_status'); This was the fourth tutorial in the series on how to modify elgg through your own plugin, myplugin. We have replaced the Elgg topbar logo, Elgg favicon icon and reviewed elgg extend view and elgg unextend view. You can download a copy of myplugin below, everything is included. Elgg Tutorial Last Updated: February 8, 2015...

Read More

Elgg extend view

Posted on Dec 21, 2011 in News, Tips & Tricks, Tutorials | 5 comments

Elgg extend view

In the previous tutorial, we used myplugin to override views. Let us now look at how to extend a view through myplugin. In some situations, you do not want to override the entire view, you just want to add more content to it. In Elgg this is called extending a view. Let’s say you want to add some sort of content to the sidebar, an informational text for example. This can be done by calling elgg_extend_view() in start.php. Open engine/lib/views.php and find the function elgg_extend_view, elgg_extend_view($view, $view_extension, $priority = 501, $viewtype = '') As you’ll notice the function takes three parameters ($viewtype, not used), the view to extend, the view you add and the priority. The default priority is 501, and priorities less than 500 are displayed before the primary view and greater than 500 after. Now call elgg_extend_view in myplugin/start.php by adding this line, elgg_extend_view('page/elements/sidebar', 'page/elements/info', '1'); This will prepare the sidebar to be extended with the view we want to create right now, info. Priority 1 will put it right at the top of the sidebar. Create a new php file in the directory page/elements/ and name it info.php. In this file, you can add almost any content and the content will be displayed in the sidebar. Let us add a module, $title = elgg_echo('myplugin:title'); $content = elgg_echo('myplugin:text'); echo elgg_view_module('featured', $title, $content); Create a new directory in myplugin/ called language, and add a new php file called en.php. Open en.php and copy/paste the snippet below, $english = array( 'myplugin:title' => 'Information', 'myplugin:text' => 'This is some information from your admin!', ); add_translation("en", $english); Save your files and refresh your page and you will see a new module added at the top of the sidebar. Elgg Tutorial Last Updated: February 8, 2015...

Read More

Replace Elgg favicon icon

Posted on Dec 20, 2011 in News, Tips & Tricks, Tutorials | 4 comments

Replace Elgg favicon icon

Once you have installed Elgg, you’ll notice that it comes with an Elgg favicon. If you want to use your own favicon, find your plugin ”myplugin” that we already created and follow the next steps. If you look in the folder elgg/_graphics, you’ll see a file named favicon.ico, that’s the one we want to replace. The easy way would be to just dump your own favicon.ico into the folder, but as you know now if you’ve read the previous tutorial, we do not change elgg core. So instead add your favicon.ico into the folder, myplugin/graphics. Since the favicon we want to use is in a different locaton now, we need to track down the old favicon.ico path in order to change it. I use Dreamweaver and when I search for favicon.ico, I find the path in views/default/page/elements/shortcut_icon.php. We are now going to override that view, by adding a view directory to “myplugin”. The view directory has special meaning to Elgg as views defined in your plugin automatically override Elgg core’s version of those views. So add a directory called views to your plugin, in that directory create the directory default. From this level you can override any elgg view, and since we want to override shortcut_icon.php in page/elements, add these two directories. You now have a plugin structure like this, myplugin/views/default/page/elements/ Go to elgg/views/default/page/elements/ and copy the file shorcut_icon.php and paste it into the folder elements in “myplugin”. Open shortcut_icon.php and change the path to the new favicon.ico location: <?php /** * Displays the default shortcut icon */ ?> <link rel="SHORTCUT ICON" href="<?php echo elgg_get_site_url(); ?>mod/myplugin/graphics/favicon.ico" /> That’s it. You changed an Elgg “view” to display an element the way you prefer. If you have any questions or comments, please leave your responses in the comments below. If you want to create a favicon of your own you can genererate one here: http://www.favicon.cc/ The plugin “myplugin”, created in the previous tutorial and used in this post can be downloaded below. Elgg Tutorial Last Updated: February 8, 2015...

Read More

Replace Elgg topbar logo

Posted on Dec 19, 2011 in News, Tips & Tricks, Tutorials | 0 comments

Replace Elgg topbar logo

This is the first tutorial of a series on how to modify elgg through your own plugin. We will deal with simple elgg changes, so if you already have experience with elgg modification, you probably don’t need to read this. Okay, if you want to remove the Elgg logo from the top bar or replace it with your own logo, this is how to do it, and actually it’s really simple to do, because the logo is registered as a menu item. One of the major changes in Elgg 1.8 is the new menu system. If you want to have a closer look at the functions and parameters that are available when handling menus, open engine/lib/navigation.php, it’s well commented. But please do not edit anything in this file, you should never edit the Elgg core files, all changes must be made through your own plugin. So if you haven’t created your own plugin already lets start by creating the simplest elgg plugin possible. Elgg plugins are required to have a manifest.xml and a start.php in the root folder. Create your plugin folder, name it myplugin and in that folder create the two files mentioned. If you don’t know how to create a manifest.xml you can check Elgg wiki, http://docs.elgg.org/wiki/Manifests Back to the topbar menu item and navigation.php. As you can see the function to remove menu items takes two parameters, elgg_unregister_menu_item($menu_name, $item_name); the name of the menu, in this case topbar and the unique identifier for this menu item, elgg_logo. Now you can call the function with the proper parameters in your start.php init function: register_elgg_event_handler('init','system','myplugin_init'); function myplugin_init() { elgg_unregister_menu_item('topbar', 'elgg_logo'); } Elgg logo is now gone and you can register your own topbar replacement if you want. Create a new folder in your plugin, name it graphics and add the file topbar_logo.png. Add this to your init function: $logo_url = elgg_get_site_url() . "mod/myplugin/graphics/topbar_logo.png"; elgg_register_menu_item('topbar', array( 'name' => 'my_logo', 'href' => 'http://www.mysite.com/', 'text' => "<img src=\"$logo_url\" alt=\"My logo\" width=\"38\" height=\"20\" />", 'priority' => 1, 'link_class' => 'elgg-topbar-logo', )); That’s it for this tutorial. You have now replaced Elgg logo with your own and have a plugin where you can add future changes. If you have any questions or comments, leave your responses in the comments...

Read More