Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore Beginning Joomla!: From Novice to Professional

Beginning Joomla!: From Novice to Professional

Published by ainmohd, 2016-11-16 15:53:25

Description: Do you want the ability to manage documents, photos, and other content over the Web, but don't want to shell out thousands of dollars in proprietary solutions? Want to create an online community for your hobby or user group? You're not alone. For thousands of like-minded users around the globe, the answer is Joomla!, an open-source content management system used to manage all sorts of data over the Web.

While Joomla! is relatively easy to install, a fair amount of knowledge is required in order to configure the application to your specific needs. Beginning Joomla! answers many of the questions you're sure to have, guiding you through the process of creating your own design templates, adding and managing content, and adding popular community features such as article commenting, user profile management, and forums. Later chapters discuss e-commerce integration, explore search engine optimization, and show you how to extend Joomla! by creating your own plug-ins.

Search

Read the Text Version

432 CHAPTER 12 s SEARCH ENGINE OPTIMIZATION AND JOOMLA! Keyword-Rich Content Keyword lists should contain all of the important variations of a topic. Whatever the web page is about, the keyword list should contain all the various synonyms of the central terms related to the content in order to encompass each term a person might search for information about. A page on loans, for example, might have a keyword list like this: mortgage, trust deed, grant deed, equity, lending, lender, origination, payee, and note. Because of the abuse of the technology by spammers, metadata keywords are scarcely given attention by search engine spiders. For search optimization, it is not important to spend much time creating the list of keywords to include in the metadata—except for the advantage of generating the list itself. The keyword list can be used to ensure that the keywords are located in the content of the article. If all of the important keywords are included in the headlines and body of the article, the search engine indexing system will rate the relevance of the page very highly in terms of loan information because of the association of the common terms. Preventing Content Listing Most web sites need to be found by the general public. However, there are some web sites, or even specific pages on a web site, that have reasons to remain invisible. These pages are generally either completely private or needed only by authorized personnel who will be given the URLs individually and won’t need to locate the references in a search engine. A common example of this type of site is a wholesale lending site in the mortgage industry. Since these sites themselves require authorized brokers to have usernames and passwords (and therefore the site address), there is no reason to advertise the site URL to the world. Keeping the site off the search engines prevents unwanted random traffic, confusion by consumers (such as a retail bank customer finding the wholesale loan site of the company and attempting to log in), and targeting by hackers. You can also be more specific than keeping your entire site off the search engines by explicitly listing individual pages or directories that the spider should ignore. By creating a list of excluded pages, you can hide content that should only be viewed by targeted visi- tors of the site. For example, you may want to provide a mortgage calculator to potential clients who are geographically local. Having the calculator listed on a search engine will bring worldwide visitors who have no potential to become customers yet still use up your bandwidth. The excluded files or directories must be listed in a text file that sits at the root direc- tory of the site. The file, named robots.txt, contains a case-insensitive list of fields. The pound sign (#) can be used to include comments in the file, which will be ignored by the spider. The User-agent field can be used to explicitly specify which spider (such as the Yahoo spider) should use the file. More commonly this parameter is set to the * (which

CHAPTER 12 s SEARCH ENGINE OPTIMIZATION AND JOOMLA! 433means “all”) setting to indicate that all spiders should restrict their spidering based onthe file contents. For example, the robots.txt file for restricting the contents of the forum directoryand the clientlist.htm file would appear like this:# Spidering exclusion file for http://www.example.com/User-agent: *Disallow: /forum # Don't spider anything in the forum directoryDisallow: /clientlist.htm # Don't spider the client list file. The Disallow field for the \forum folder excludes all references to items in the direc-tory. You may want to only disallow the index file in a folder, for example, to eliminatespidering of the central listing of all the articles, but allow spidering of articles that arelocated in the folder but linked from other articles. To exclude only the index file(whether it is default.htm, index.html, index.php, or a different file configured for thatweb server), you can add an extra forward slash (/) after the directory reference:Disallow: /forum/ # Don't spider anything in the index file Unfortunately, you cannot do exclusion on query string parameters. Therefore, therobots.txt file will require you to have the Joomla SEF option turned on for it to workproperly. Otherwise, the exclusion file can only be used practically with Joomla toprovide exclusion of the entire web site from the search engine spider.Linking StrategyIt is useful to have a linking strategy in place when you are attempting to increase yourplacement. Tabulating the number of other important web sites on a particular topic thatlink to your site is one of the primary methods search engines use to determine if a sitehas important information on that topic. For example, ESPN is a very important web site for sports fans. If you run a web sitethat focuses on football memorabilia, a link from the ESPN site would dramatically ele-vate your ranking in any searches related to sports. Notice that the link will help you mostif it is in your same topic area. A link from a very popular clothing manufacturer wouldnot help the sports memorabilia site nearly as much—even if the clothing site had morepopularity than ESPN. Likewise, a prominent link on a small, rarely visited site is not worth nearly as muchas one on a popular site. With this basic understanding of how links from other sites canaffect your search engine ranking, you can begin to develop a linking strategy that willhelp you decide where to focus your efforts in obtaining links from other web sites.

434 CHAPTER 12 s SEARCH ENGINE OPTIMIZATION AND JOOMLA! Some ways to obtain links are as follows: • Offer reciprocal link placement: If you can find the administrator e-mail for a popular site, you can offer to exchange reciprocal links. Your web site must have a fair amount of content or a substantial page ranking to make this worth the while of the other site’s web master. • Write articles for web publication: There are a number of sites that will publish articles that they will syndicate for republication across the Web (e.g., www.ezinearticles.com and www.onlypunjab.com). An article can contain a link to your web site. Writing a general description article (or more than one) on a topic relevant to your site can be an excellent way to promote yourself as a field expert. • Post to relevant message boards with a signature link: There are forums and mes- sage boards on the Web dedicated to almost any topic under the sun. Often these sites have new users posting basic questions that you, as an expert in your field, can answer. It is typically acceptable behavior on these sites to have a small advertisement link for your web site in the signature text that follows your post- ing. Be sure not to simply spam a forum advertising your wares. Not only will the advertisement likely be removed, but you will also have generated some ill will toward your site. If you can provide value through useful and informative posts, your small link should not raise the ire of any forum members, and could help generate new traffic. Avoid Keyword Spamming Most of the advice for adapting your site to make it the most friendly to search engines is also useful advice for simply making your site well designed for your visitors. Likewise, the presentation aspects that can hurt your site rating also generally fall under the cate- gory of bad web design. You should avoid keyword spamming on your page. This form of spamming entails placing a text field at the bottom of your web page that includes hundreds if not thou- sands of keywords in small or invisible text. Previously, search engines would be fooled by these masses of keywords and increase the site’s ranking. No more. If a search engine recognizes that your site is attempting this sort of rank manipulation, the page may very well be penalized in the search index. In the past, it was generally considered poor form to attempt this strategy—now it can have the opposite of the intended effect.

CHAPTER 12 s SEARCH ENGINE OPTIMIZATION AND JOOMLA! 435ConclusionIt requires some effort to ensure that your web site has the highest possible rankings onthe search terms relevant to the site. Joomla makes it fairly easy to implement SEO func-tionality on your web site, and you should take advantage of its features. Despite having to deal with a little complexity in configuration, one of the first stepsyou should take in optimizing your site is setting Joomla to use the Search EngineFriendly URLs option for content addressing. The sooner you activate this option, thesooner the search engines will have a proper list of article URLs. This setting alone cansignificantly increase your web presence. It is worth the trouble of configuring your webserver to enable this option. So far you have used extensions written by other developers for everything frome-commerce to SEF functionality. In the next chapter, you will learn how to create yourown modules and components to add any capabilities to a Joomla site that you mightneed.



C H A P T E R 13Creating ExtensionsIn addition to being very friendly to administrators, the Joomla system is also pleasantto developers. Creating an extension (module, component, or plug-in) can be a pleas-ure, since the Joomla framework is designed with the developer in mind. In fact, sinceJoomla takes care of most of the interface presentation and has built-in routines fordatabase access and security, creating a Joomla extension can be quite a bit easier thanauthoring even a simple standalone PHP application. In this chapter, you’ll learn to create three different types of extensions: a front-endmodule, an Administrator module, and a component. You’ll find that implementation ofeach of these adds-on is very similar, as Joomla implements both a unified installer thatworks the same regardless of extension type and common presentation routines that aredesigned to minimize complexity.Writing a Front-End ModuleAs you learned in Chapter 7, modules are primarily used for displaying data. To providea sample of this capability, I’ll walk you through the creation of a module that presents asimple greeting. This module, called mod_hellofrom, has a single parameter, location, thatis set in the Module Manager and displayed along with the welcome message. As shownin Figure 13-1, the module will be displayed in the top of the left column. All front-end modules are stored in the \modules directory by the Extension Managerafter installation. The name of each folder matches the name of the module. All the filesof the module, including the installation directives file, will be placed in this folder. Later,when you create a component, you’ll notice that (unlike a module) the installation direc-tives file is not copied into the associated component folder. 437

438 CHAPTER 13 s CREATING EXTENSIONS Figure 13-1. The mod_hellofrom module will display the time and date, as well as a greeting. sTip When developing a new extension, the simplest process is usually to begin by roughing out the extension, compressing it into an archive, and then installing it into the Joomla system. The installation process will set up all of the necessary parameters within the Joomla database. Then you can access the actual code files in the \modules folder of the web site to make changes, add features, and perform debug- ging. When you make changes to the actual file, simply clicking the reload or refresh button of the browser will execute the new code. Structure of the Module At the most basic level, every module package contains a minimum of two files: a code file and an XML descriptor file. The code file is a PHP file that holds the execution code of the module display. The XML descriptor file contains all of the installation directives and information about the module. It also holds the module parameters that can be configured through the Module Manager interface. Begin by creating a folder named mod_hellofrom on your local drive. All of the module files will be placed in this folder, and then an archive file (such as ZIP or TAR file) can be created from it and installed via the Extension Manager.

CHAPTER 13 s CREATING EXTENSIONS 439The mod_hellofrom XML Descriptor FileFor the Hello From module, the XML descriptor file will include all of the central ele-ments (installation directives, module name, and file listing) plus some of the optionalelements (creation date, version, author, etc.) that are used to document the module. Thefile also contains a single parameter that can be set to display the current server location. Create a new file named mod_hellofrom.xml in the \mod_hellofrom folder, and enter thefollowing code:<?xml version=\"1.0\" encoding=\"utf-8\"?><install type=\"module\" version=\"1.5.0\"> <name>Hello From</name> <author>Dan Rahmel</author> <creationDate>July 2007</creationDate> <copyright>(C) 2007 Dan Rahmel. All rights reserved.</copyright> <authorEmail>[email protected]</authorEmail> <authorUrl>www.joomlajumpstart.org</authorUrl> <version>1.0.0</version> <description>Module that displays the date/time of the server. <p /> Be sure to set the Location parameter in the Module Manager.</description> <files> <filename module=\"mod_hellofrom\" >mod_hellofrom.php</filename> </files> <params> <param name=\"location\" type=\"text\" default=\"Los Angeles, CA\" label=\"Server Location\" description=\"The location of the server.\" /> </params></install> The descriptor file begins with a standard XML properties tag. The <install> tag thatfollows tells Joomla about the extension to be installed. The type attribute declares theextension type—which in this case is module. The version attribute specifies that thisextension was made to run on Joomla version 1.5 or above. The <name> element specifies the name of the module instance that will be created byJoomla when the module is installed. In Chapter 7, you learned that a module type is likea document template, and the module instance is like the document created from it. For

440 CHAPTER 13 s CREATING EXTENSIONS this module, the module type is mod_hellofrom and the initial module instance will be named Hello From. The text in the <description> element will be displayed when the module is installed, so it should have any necessary instructions to the administrator regarding the use of the module. In the <filename> element, note that the module attribute will be stored in the Joomla database and used to reference the module. This name will be the module type that you will select when creating new instances of the module. Once the descriptor file is com- plete, you can create the PHP file that is the core of the module. The PHP Code File The main module file contains all of the PHP code that executes when the module is ren- dered. This code will strongly resemble standard PHP page code in that it uses the echo statement to send any output text to the user’s browser. You should always begin any extension with a check (under the no direct access section of this module) to ensure that the code is being executed by the Joomla system. This prevents hackers from using a direct URL and executing the extension, possibly using parameters that could compromise security. By ensuring execution through the Joomla framework, the module is shielded by the robust security built into the system. Create a file named mod_hellofrom.php in the \mod_hellofrom folder and enter the following code: <?php /** * @version $Id: mod_hellofrom.php 5203 2007-07-17 02:45:14Z Danr $ * @copyright Copyright (C) 2007 Dan Rahmel. All rights reserved. * A module to display a hello from the location of the server. */ // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); // Get the location parameter that was set in the Module Manager $myLocation = $params->get('location', 0); // Set a formatted date string $myDateTime = date(\"l, F dS, Y\"); // Output the greeting echo \"<small>\" . JText::_('Hello from ') . '<b>' . $myLocation . \"</b>.\"; echo JText::_(\" Right now, it is \") . $myDateTime . JText::_(\" here.\") . \"</small><br />\";?>

CHAPTER 13 s CREATING EXTENSIONS 441 If you understand PHP coding, the process of this module should be straightforward.After the check to make sure the code is executing under Joomla, the $myLocation variableis created. You can see that it uses the get() method of the $params object to obtain thecurrent value of the module parameter called location, which was defined earlier in theXML descriptor file. A second variable, named $myDateTime, is set to a formatted string holding the currentsystem time and date. If you want to actually use this module, you may have to makesome adjustments to the time if the web server that hosts your site resides in a differenttime zone than the location parameter indicates. The lines of code that follow these defi-nitions use the echo() function to output the text to the browser page. You might notice that all of the text is sent to the JText::_() method. This Joomlamethod sends any text passed to it to the Language Manager. If a language other thanthe default is selected for display, and the Language Manager (or Joom!Fish) has a trans-lation of the current text in the selected language, the translation will be substituted andreturned by the method. If not, the same text that was sent will simply be returned.Using this method allows your extension to expose itself to the Joomla internationaliza-tion features where, if translation text exists in the system, it can output text that can beread in one of the dozens of languages Joomla supports. Archive the folder with both files into a file named after the module (e.g.,mod_hellofrom.zip). To install this module, go to the Extension Manager, browse to thearchive file, and install it. Once installed, you can publish the module, set the locationparameter (see Figure 13-2), and select where the module will be displayed in the Mod-ule Manager. Click the Save button to store these parameters to the Joomla system.Figure 13-2. Set the location parameter to match the geographic location of your web server.

442 CHAPTER 13 s CREATING EXTENSIONS If you set the module to display in the left column location, open a browser window and you should see the greeting displayed. If you didn’t change the order of the module in the Module Manager to appear first in the left column, you may have to scroll to the bottom of the column to see the display. Congratulations! You’ve just implemented your first extension. However, this primi- tive module is probably not anything you would want to use in a real Joomla deployment. Most modules have more complex functions and often need to perform database access. The next module will add to the complexity of the current one and also throw in another twist—it will be an Administrator module. Writing a Missing Metadata Administrator Module Administrator modules function in the same way as front-end modules, but they are used within the Administrator interface. An Administrator module is never seen by a front-end user because it generally exposes private system information and may help with maintenance and administration of the site—neither of which you want shown to the visiting public. In this example, the module will list content articles that are missing key information—the article metadata. For proper SEO, each web page should contain two pieces of unique metadata infor- mation: the metadescription and metakeywords fields. These fields are used by the search engine spider to determine how to index and display the content. In fact, Google uses the metadescription field of an article to display the brief summary of the page, as shown in Figure 13-3. Figure 13-3. The metadescription field of a web page is displayed as the summary in search engines such as Google.

CHAPTER 13 s CREATING EXTENSIONS 443 Despite the importance of this information, many Joomla sites have numerous arti-cles where this information is left blank. Blank metadata fields can hurt the search engineranking of the site and also make it more difficult for search engine users to know whichpages they might want to examine. It is preferable for every article to have these twofields completed. To solve this problem, you’ll create an Administrator module that lists all articlesthat have empty metadata fields. Each article title will be an edit link, so an administra-tor can simply click the title and the article will be displayed in Edit mode. The missinginformation can then be immediately added to the content. Only articles that are pub-lished will be displayed in the list presented by the module (unpublished and archivedarticles will not be displayed). Begin by creating a folder named \mod_missingmeta on your local drive. Inside you willput the XML descriptor file and the module code file.Creating the XML DescriptorThe XML descriptor file is much the same as the file for the previous Hello From module.This module also consists of a single code file (mod_missingmeta.php) that contains all ofthe querying code. In the \mod_missingmeta folder, create a file named mod_missingmeta.xmland enter the following code:<?xml version=\"1.0\" encoding=\"utf-8\"?><install type=\"module\" version=\"1.5.0\" client=\"administrator\"> <name>Missing Metadata Items</name> <author>Dan Rahmel</author> <creationDate>July 2007</creationDate> <copyright>(C) 2007 Dan Rahmel. All rights reserved.</copyright> <authorEmail>[email protected]</authorEmail> <authorUrl>www.joomlajumpstart.org</authorUrl> <version>1.0.0</version> <description>Module to display any articles that have missing metadescription or metakeywords fields.</description> <files> <filename module=\"mod_missingmeta\" >mod_missingmeta.php</filename> </files></install> Notice that the <install> tag has an additional attribute named client that wasn’tused in the previous module. If the client attribute is not included, the module isassumed to be a front-end module and is assigned the site client type. Since you want
































































Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook