Saturday, February 7, 2009

Switch off Joomla Statistics, switch on search stats

This article applies to Joomla 1.0 only

The default Joomla statistics (and other statistics components) capture a lot of mostly useless data, might cause your database to grow and then degrade the performance of your website.

The data gathered by these components is mostly insignificant anyway. On the other hand, it is strongly recommended to switch on only your search strings statistics, because knowing what people are searching for on your site is quite useful and gives you insight on what your users need when they come to your website.

Statistics are defined in Site > Global Configuration > Statistics tab

Statistics: No

Log Content Hits by Date: No

Log Search Strings: Yes

If you think you require these kinds of statistics, rather than storing this information in your database, use Google Analytics rather than clutter your database Wink

Optimize the default search options

By default the Joomla search searches for any word. That is if you look for "Joomla components", you will find any page which contains either Joomla or components. People require AND search. The following hack to the core code will enable all words searching by default.

In /components/com_search/search.html.php:

Find: $searchphrase = strtolower( strval( mosGetParam( $_REQUEST, 'searchphrase', 'any' ) ) );
Change to: $searchphrase = strtolower( strval( mosGetParam( $_REQUEST, 'searchphrase', 'all' ) ) );
This occurs twice in approximaletely lines 126 and 215

Also, in /components/com_search/search.php:

Find: $searchphrase = mosGetParam( $_REQUEST, 'searchphrase', 'any' );

Change to: $searchphrase = mosGetParam( $_REQUEST, 'searchphrase', 'all' );
This occurs in approximately line 103


Rememer to make a backup of each files in case something goes wrong.

Use Joomap and Google Sitemaps

Joomap coupled with Google Webmaster Tools is the sure way of getting your site's content in the Google index as soon as possible.

Sitemaps are the newest way of submitting content to search engines. There are several ways of creating sitemaps, however since Joomla contains dynamically changing content, you want your sitemap to be updated constantly to update your current content.

Joomap allows you to create a dynamic sitemap, always staying current with any changes in your content. Thus instead of waiting for the GoogleBot to index your content, using a sitemap, you are ensuring that all your content is being indexed as soon as the Google crawler accesses your sitemap url.

Therefore, if you still haven't done this, create a Google Webmaster account, verify your website, and submit the url created by Joomap as a sitemap.

Joomla not working?

This is quite a vague statement, and there is a multitude of reasons why this could be happening. However, the following might eliminate one of the reasons why a Joomla site is not working, i.e. corruption of files during upload.

Have you recently installed or uploaded your site to the web server and it is not working? Is your site acting strangely or funnily, or you have blank pages coming up in certain areas? This is usually a problem with having corrupt / missing files in the installation. The best way to check for this is to use the Joomla Diagnostics tool to check whether and files are missing or corrupt during installation.

Image

The tool consists of two files which you upload to the root of your Joomla installation. You then access the http://www.yourdomain.com/diagnostics.php file and this will give show you whether any files are missing or corrupt. You can then replace any missing files using an FTP client, or JoomlaXplorer.

Turn off TinyMCE Cleanup Code

TinyMCE, the default WYSIWYG editor in Joomla, is set to strip away "unsafe" HTML tags in order to protect you from certain exploits. This article shows you how to switch this off to be able to insert srcipt tags.

A safety feature of the TinyMCE WYSIWYG editor is the stripping off of certain html codes such as . Sometimes though you need to be free to insert these codes at will. To switch the safety feature off you need to turn this off from the Mambot parameters:
  • Mambots > Site Mambots
  • Click on TinyMCE Editor
  • Turn off the Code Cleanup parameter.

N.B. Switching off this protection exposes you to significant security risks. DO NOT switch this off, if you have enabled components which allow users to submit content via TinyMCE because they would be able to insert exploits into the content.

Load a module within an article

Did you know it is possible to actually load a module directly in your content? E.g. We want to load our Featured Articles module in an article rather than in a module position. We can do this using the Load Module Position defaultJoomla mambot.

Joomla 1.5

In Joomla 1.5, there is a default plugin which does this. You can call any module position in a content item with the following code:

{loadposition user4}

Remember, you have to enable the loadmodule plugin from the Plugin Manager.

Joomla 1.0

Edit: See bottom for a new way of doing this, using a 3rd party module though

The Load Module positions mambot allows us to load any mambot position as a mambot. Therefore to load the module in a content article we can use the following workaround.

  • From the Template Positions (Site > Template Manager > User Positions), choose a module position which is not used in your template e.g. user8. If all your positions are used in the template, create a new position.

Create a new template position

  • Assign the module you want to display to the position you have chosen above - Modules > Site Modules. Make sure that Menu Item links is set to All (otherwise the position will not load)

Setup the module with all necessary parameters

  • In your content item enter the following: { mosloadposition user8 } (be sure to remove extra spaces before mosloadposition and after user8, spaces were added intentionally in this example). This will be replaced by the content of the module(s) assigned to that position.

Insert the mambot text into your content

Below is an example of usage of this module. We are loading the Featured Articles Module in the content of this article:

Another good example of usage of this module is this. You want to create an advert (or affiliate link), but instead of copying and pasting the code, you want to be able to replicate this advert at will in your content items. Therefore you use the mod_html module to create the advert you need. Now, each time you want to display this advert, you just insert the { mosloadposition xxxx } (be sure to remove extra spaces before mosloadpostion and after xxxx, spaces were added intentionally in this example) in the content. The good thing about this is that if you want to change the advert, you only need to change this in the module rather than in every content item.

Edit: There is a cool module which allows you to avoid all the hassle above. Amongst various functions it allows you to use code as follows to do the above in a much simpler manner:

{mosmodule modulename} and the module is immediately loaded.

Switch off the WYSIWYG Editor when inserting HTML code

The default Joomla WYSIWYG editor is great when you want to be able to format your content articles. However, the editor will strip off any HTML you try to insert. Therefore, to insert certain HTML code you need to make sure that it is switched off.

To switch off the Editor for the current user you need to logon on to the Administrator backend, click to Site > User Manager. Click on the account you logon with, and choose No WYSIWYG editor. Once this has been done, any content items you create / edit will feature pure HTML which will not get stripped off by the Editor.

Back up your Joomla website

Ok we all know you have taken all steps to prevent your website to secure your website and prevent it from being hacked. However, there are many other things which can go wrong with your Joomla website. When you have a busy site, you can never have enough backups. The following are easy ways to have a complete set of backups of your Joomla website. Did I mention that each of these comes for free?

Backup your SQL data

Backing up the content of your Joomla website is critical. You will probably be able to recreate your template if you lose it, however recreating your content is a much harder thing to do especially if you rely on several 3rd parties / visitors for your the content.

The jombackup mambot from Jomres is a small mambot which when published creates a MySql backup, compresses the file and sends it to you. The default settings are enough, no playing around with parameters is required. Just enter your email address, publish and you'll soon start getting a daily backup right to your mailbox. Try not to obliterate your mailbox too, and don't use the same email server as the host of your site, so that if you lose your site, you don't lose your email too Wink

Backup your template / media / customisations etc.

These are things which do not change often ... so a simple FTP transfer to a backup area should be sufficient. You can also choose to use a component for your backups.

A good component for backup is the JoomlaCloner backup component. This allows you to backup and restore your website easily. It also allows you to move your website from host to host.

Another non-commercial one which comes to mind is the JoomlaPack component. This creates a zipped file of all the content in your website which you can just download. This also makes it easier for you to take a backup whenever you need.

Testing Joomla site changes while site is offline

Sometimes when you need to make drastic changes to your website, you put you site offline, so that your clients get a site offline message and don't see any temporary incorrect configurations.

You as the developer / administrator of the website need to be able to see the live changes. To do this you need to open a new tab / window (and connent to your live site url) in the same browser where you are logged on as administrator doing the backend changes. If you have maintained the browser session correctly the actual current content is generated beneath the site offline message. Other users who hit your site while the site is configured as offline will only see the site offline message, and only you (due to being logged on as administrator) will be able to see the changes.

The essential thing for this to work, is that you need to ensure that you need to have two windows / tabs running under the same browser session.

Switch on the Cache

Switch on Caching to give your Joomla website an instant performance boost.


What is a cache? Wiki says:

A Cache is a collection of data duplicating original values stored elsewhere or computed earlier, where the original data is expensive to fetch (due to slow slow access time) or to compute, relative to the cost of reading the cache. In other words, a cache is a temporary storage area where frequently accessed data can be stored for rapid access. Once the data is stored in the cache, future use can be made by accessing the cached copy rather than re-fetching or recomputing the original data, so that the average access time is lower.

What does this mean in terms of Joomla? Instead of hitting your MySql database with same queries over and over again, your data is stored to a local storage (in the Joomla cache directory) and retrieved from there, instead of from the database. This means that your database will perform better, and your website will feel faster, and be able to support more simultaneous users.

Joomla 1.5

Activitating the Joomla Cache is quite straight forward. From the Global Configuration, click on System Tab, and on the right hand side there is the Cache Settings section. Click Yes on Cache Settings, and put a reasonable amount in minutes (60 minutes should be quite good for most websites). Once you press Apply, Caching will be enabled.

Joomla 1.0

The standard Joomla cache is enabled from Site > Global Configuration > System > Cache Settings (or Site > Global Configuration > Cache tab for Joomla 1.0), and mark it as enabled.

Though there are components written for caching the out of the box caching will give your website an instant boost.

Changing the default frontpage

Another easy to do but often asked question about Joomla is how to change the default homepage from the frontpage component to another page.

Joomla 1.0

The page which is displayed when you first hit a Joomla website is the first menu item in the main menu. Therefore, if you want to change the default frontpage, go to the main menu (Menu > mainmenu) and change the ordering of the menu items such that the page you want to display first is at the top of the list.



Joomla 1.5

In Joomla 1.5, this has become easier to handle. You just go to the main menu
where your homepage is, select the menu item, and mark it as default. You'll notice that the menu which is default is marked with a start next to it. You'll also notice that in the Menus module, there is an asterisk in the menu which contains the default frontpage.

menuasterisk.jpgdefaultmenu.jpg

The images above show the default icons which are used to set a menu item as the default frontpage.

Changing the default frontpage

Another easy to do but often asked question about Joomla is how to change the default homepage from the frontpage component to another page.

Joomla 1.0

The page which is displayed when you first hit a Joomla website is the first menu item in the main menu. Therefore, if you want to change the default frontpage, go to the main menu (Menu > mainmenu) and change the ordering of the menu items such that the page you want to display first is at the top of the list.



Joomla 1.5

In Joomla 1.5, this has become easier to handle. You just go to the main menu
where your homepage is, select the menu item, and mark it as default. You'll notice that the menu which is default is marked with a start next to it. You'll also notice that in the Menus module, there is an asterisk in the menu which contains the default frontpage.

menuasterisk.jpgdefaultmenu.jpg

The images above show the default icons which are used to set a menu item as the default frontpage.

Hiding a menu once logged in

Have you ever wanted to hide one of your menus if your users have logged on? The following small template hack will hide your menu once your user has logged on.

The idea behind this is to actually load a particular position (the menu position) only if the user has not logged in:

Joomla 1.0

if( !$my->id )mosLoadModules ( 'left' );

and should be placed in the index.php of the template you are using (/templates//index.php). The code will hide all modules which are assigned to the left position. If you only want to hide your menu item, you should create an additional position in your template (e.g. hidingmenu), assign your hideable menu to this position and then hide that position only.

if( !$my->id )mosLoadModules ( 'hidingmenu' );

Joomla 1.5

This has changed for J1.5

$user =& JFactory::getUser();
$user_id = $user->get('id');

This returns the user id of the user. Therefore the code to do this is check whether the current user has a valid id (i.e. they are logged), if not load the module:

$user =& JFactory::getUser();
$user_id = $user->get('id');
if (!$user_id)
{
?>
}
?>


Sorting and Ordering

Joomla provides a various sorting options for articles, sections, categories, menu items and other content. These tend to confuse users due to so many different possibilites.

The best thing is to define all items to be shown by Ordering. Then manually adjust the Ordering. However, instead of using the Ordering dropdown where you would have to go into each menu and select the ordering from the dropdown (and sometimes the dropdown may misbehave and not do exactly as specified):

Ordering Dropdown



you should be using the content items listing to change the ordering. You can either use the up / down arrows to move the item up or down. Or even nicer you can enter the order into the boxes, and once you have determined the correct order click on the diskette to save the order.

Content Item Ordering

Removing Joomla footer

How to change / remove the Joomla footer (remove joomla! is free software released under the gnu/gpl license)

Removing / changing the powered by Joomla! footer message

Although we all know what a great content management system Joomla is, sometimes situations call for the link not to be visible in your website footer.

Joomla 1.5

With Joomla 1.5 if you want to remove the footer, simple go to Extensions > Module Manager and unpublish the footer module. If you want to change the text, go to the language directory, go to the folder of the language you want to change, find the mod_footer.ini and change the text in there to whatever you want your text in the footer to be!

Joomla 1.0

To remove this from the default (1.0.x) template, you need to browse via ftp or otherwise to the file includes/version.php. Open it with your favourite editor, find the $URL line and change it to your liking. If you want nothing at all leave the line as $URL = '' (2 apostrophes). Do not remove the whole line because you might break your template.

This applies to the default template (rhuk_solarflare_ii). Other templates are likely to not use the URL and use their own links. You would have to use some kind of software on your local installation which looks within text files, and search for the text you want to change. Once you find it, you can change it to suit your needs.

Tuesday, January 13, 2009

Customising the Joomla Frontpage

This simple question is asked over and over again on the Joomla forums by newbies. The most popular question would be, how do I change from two columns to one column display.

Understanding the FrontPage component

The Joomla frontpage is a component which allows you to control how your homepage looks. It is slightly different from standard components in the fact that its configuration is not done via the Components menu. Instead you need to find the Home link in your main menu. In a default installation the Home points to the frontpage component.

To customise the look and feel of the frontpage you need to edit the Parameters of the Home menu item link. Therefore go to Menu > mainmenu > and click on the Home link.

Joomla frontpage parameters

#Leading - This parameter determines the number of full width articles to display. Articles displayed in the Leading will have the Intro text displayed. This setting overrides the columns parameter i.e. if you have decided to have 2 columns and 1 items in the leading intro you will have a layout as follows:

Article 1 - Full Width (Row 1 - Leading)

Article 2 (Row 2, Column 1) Article 3 (Row2, Column 2)

Article 4 (Row 3, Colum 1) Article 5 (Row 3, Column 2)

Columns - the columns determines how many columns will feature in each row. If you want more than a single column, set the number of columns here.

#Intro - the number of articles whose Intro text will be displayed (excludes the number of items in the Leading parameter).

#Links - the number of links to articles to display (excludes the number of items in the Leading and Intro parameters). Items showed in the Links section will feature just the title of the article (with no Intro text displayed).