Thứ Sáu, 31 tháng 5, 2013

Joomla template Vertex

Vertex

Vertex is a free responsive Joomla template, however the download will require a free membership. Vertex is built on Shape5 framework which offers 95 module positions, custom row and column width, and much more.
Vertex

Framework Leo Restro

Leo Restro

Leo Restro comes in 3 theme colors to suit your style and support customization for background and fonts via template configuration. Leo Restro is built on the Leo Framework.
Leo Restro

Responsive Joomla template Puresite

Puresite

Puresite is a simple and clean yet beautifully presented responsive Joomla template. This template works well and fits any screen sizes, and the minimalistic design makes it look great.
Puresite

Responsive template Joomla Dagen

JoomlaDagen

JoomlaDagen is a responsive template for Joomla 1.7. The template is also using Twitter Bootstrap, Skeleton and Google Fonts.
JoomlaDagen

CMS Blue

CMS Blue

CMS Blue is a simple responsive theme that offers the basics but you can always use your creativity to modify. This CMS Theme also comes in different colors and style; CMS Grey, CMS Water and CMS White.
CMS Blue

Thứ Năm, 23 tháng 5, 2013

Auto redirect guests to login

Desired Functionality

Suppose you have some menu choices that require a user to be logged in, like "Submit an Article". You would like all users to be able to see the restricted menu item, whether or not they are logged in.
If the user is logged in, they just go directly to the restricted menu item.
If the user is not logged in
  • they are presented with the login form, and
  • once they log in successfully, they continue on to the restricted page.
If they are not registered, they have the option to register or navigate to another page.

Solution

Here is how you do this in Joomla!.
  1. Create a new menu from menu manager, say it is named "hidden menu".
  2. Add any menu items that will be accessible only to registered users (for example, "Submit an Article"). Set the required access levels of these menu items ("Special" in this example, but it could also be "Registered").
  3. Do NOT create a module for the "hidden menu". It will not be displayed on any page, so it doesn't need a module.
  4. Create your "real" menu (for example, "main menu") and the menu item that will display for all users (for example "Submit an Article").
    • The menu item will have a menu item type of "Alias".
    • It's "Menu Item" parameter will be the "Submit an Article" menu item on the "hidden menu".
    • The Access Level for this menu item will be "Public", since we want everyone to be able to see and use it.
  5. Create a module of type "mod_mainmenu" for this menu, just like you do for any menu.
  6. If you want sub-menus, make sure you've added the sub-menu items in the "main menu" and not the "hidden menu".
Now, when a guest (non-logged-in user) accesses the "Submit an Article" menu choice, it redirects them to the login page. If they log in successfully, they are taken to the desired page (in this case, "Submit an Article"). If there were already logged in, they go there directly.

Example

In my case, I've added the following menu items:
  1. HOME
  2. BLOG (IDOBlog)
  3. WIKI (A Wiki)
  4. DIRECTORY (SOBI2)
  5. CLASSIFIEDS (ads)
  6. FAQS (Articles section)
  7. SHOP (VirtueMart)
  8. Contact US (contacts)
I wanted that ALL the menu items are viewable by public (non-registered users included) at the front end. But I want that menu items 3,4,5,6 & 7 are accesible by REGISTERED users only. In other words if anyone clicks on menu item 3/4/5/6/7 they'll be lead to the login modules.
So, I created a "hidden menu" with the menu items for 3 - 7, using the restricted access level. Then, when I created the "real" menu, I used the menu type "Alias" for these items and set the "Menu Item" Parameter to the corresponding menu item in the "hidden menu".
As far as I know, this method is applicable to all menus in the menu manager. In case of any help or suggestion please contact me on forums.joomla.org my username is ziggy03. In case of a better or alternate method please feel free to edit this page. Thanks.

Adding access keys

Here's a quick way to add access keys to Joomla! 1.5.
Firstly edit the component.xml parameter definiton file in \administrator\components\com_menus\models\metadata and add to it an accesskey parameter:
<param name="accesskey" type="text" size="1" default="" label="Accessibility Access Key"
description="Accessibility Access Key for the page which this Menu item points to" />
Your file should now look something like:
    <?xml version="1.0" encoding="utf-8"?>
<metadata>
<state>
<name>Component</name>
<description>Component Parameters</description>
<params>
<param name="page_title" type="text" size="30" default="" label="Page Title"
description="PARAMPAGETITLE" />
<param name="show_page_title" type="radio" default="1" label="Show Page Title"
description="SHOW/HIDE THE PAGES TITLE">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="pageclass_sfx" type="text" size="20" default="" label="Page Class Suffix"
description="PARAMPAGECLASSSFX" />
<param name="@spacer" type="spacer" default="" label="" description="" />
<param name="menu_image" type="imagelist" directory="/images/stories" hide_default="1"
default="" label="Menu Image" description="PARAMMENUIMAGE" />
<param name="@spacer" type="spacer" default="" label="" description="" />
<param name="secure" type="radio" default="0" label="SSL Enabled" description="PARAMSECURE">
<option value="-1">Off</option>
<option value="0">Ignore</option>
<option value="1">On</option>
</param>
<param name="@spacer" type="spacer" default="" label="" description="" />
<param name="accesskey" type="text" size="1" default="" label="Accessibility Access Key"
description="Accessibility Access Key for the page which this Menu item points to" />
</params>
<advanced />
</state>
</metadata>
Now edit the frontend file \modules\mod_mainmenu\helper.php:
    // ACCESS KEY HACK - Part 1
$accessKey = $iParams->get('accesskey');
$tmp->accessKey = $accessKey;
and
    // ACCESS KEY HACK - Part 2
if ($tmp->accessKey)
$data = '<a href="'.$tmp->url.'" accesskey="'.$tmp->accessKey.'">'.$image.$tmp->name.'</a>';
else
$data = '<a href="'.$tmp->url.'" >'.$image.$tmp->name.'</a>';
into the _getItemData($item) function so that it looks like this
    function _getItemData($item)
{
$data = null;
 
// Menu Link is a special type that is a link to another item
if ($item->type == 'menulink')
{
$menu = &JSite::getMenu();
if ($tmp = clone($menu->getItem($item->query['Itemid']))) {
$tmp->name = '<span><![CDATA['.$item->name.']]></span>';
$tmp->mid = $item->id;
$tmp->parent = $item->parent;
} else {
return false;
}
} else {
$tmp = clone($item);
$tmp->name = '<span><![CDATA['.$item->name.']]></span>';
}
 
$iParams = new JParameter($tmp->params);
if ($iParams->get('menu_image') && $iParams->get('menu_image') != -1) {
$image = '<img src="'.JURI::base(true).'/images/stories/'.$iParams->get('menu_image').'" alt="" />';
} else {
$image = null;
}
 
 
// ACCESS KEY HACK - Part 1
$accessKey = $iParams->get('accesskey');
$tmp->accessKey = $accessKey;
 
switch ($tmp->type)
{
case 'separator' :
return '<span class="separator">'.$image.$tmp->name.'</span>';
break;
 
case 'url' :
if ((strpos($tmp->link, 'index.php?') !== false) && (strpos($tmp->link, 'Itemid=') === false)) {
$tmp->url = $tmp->link.'&amp;Itemid='.$tmp->id;
} else {
$tmp->url = $tmp->link;
}
break;
 
default :
$router = JSite::getRouter();
$tmp->url = $router->getMode() == JROUTER_MODE_SEF ?
'index.php?Itemid='.$tmp->id : $tmp->link.'&Itemid='.$tmp->id;
break;
}
 
// Print a link if it exists
if ($tmp->url != null)
{
// Handle SSL links
$iSecure = $iParams->def('secure', 0);
if ($tmp->home == 1) {
$tmp->url = JURI::base();
} elseif (strcasecmp(substr($tmp->url, 0, 4), 'http') && (strpos($tmp->link, 'index.php?') !== false)) {
$tmp->url = JRoute::_($tmp->url, true, $iSecure);
} else {
$tmp->url = str_replace('&', '&amp;', $tmp->url);
}
 
switch ($tmp->browserNav)
{
default:
case 0:
// _top
// ACCESS KEY HACK - Part 2 ###############################
if ($tmp->accessKey)
$data = '<a href="'.$tmp->url.'" accesskey="'.$tmp->accessKey.'">'.$image.$tmp->name.'</a>';
else
$data = '<a href="'.$tmp->url.'" >'.$image.$tmp->name.'</a>';
break;
case 1:
// _blank
$data = '<a href="'.$tmp->url.'" target="_blank">'.$image.$tmp->name.'</a>';
break;
case 2:
// window.open
$attribs = 'toolbar=no,location=no,status=no,menubar=no,
scrollbars=yes,resizable=yes,'
.$this->_params->get('window_open');
 
// hrm...this is a bit dickey
$link = str_replace('index.php', 'index2.php', $tmp->url);
$data = '<a href="'.$link.'" onclick="window.open(this.href,\'targetWindow\',\''.$attribs.'\');
return false;">'
.$image.$tmp->name.'</a>';
break;
}
} else {
$data = '<a>'.$image.$tmp->name.'</a>';
}
 
return $data;
 
}
Login to your admin site and edit a menu item. Now open the "Parameters - System" accordion item on the right and you will see your accesskey parameter. Set a value, save the menu item and voila.

J1.5:Add article title to read more link

How to add an article title to the “Read more...” link?
For this you can use the overrides...
If they are not already there, in your template folder: create a new folder called 'html'.
In that folder you create a folder called 'com_content'.
And in that folder you create the folders called "category", "frontpage", "section"

Then locate the following files
  • (joomla)/components/com_content/views/category/tmpl/blog_item.php
  • (joomla)/components/com_content/views/frontpage/tmpl/default_item.php
  • (joomla)/components/com_content/views/section/tmpl/blog_item.php

Copy the files to your template's html folders
  • (yourtemplate)/html/com_content/category/blog_item.php
  • (yourtemplate)/html/com_content/frontpage/default_item.php
  • (yourtemplate)/html/com_content/section/blog_item.php

Open these files.
Nearly at the bottom of these files you should be seeing something like:
<a href="<?php echo $this->item->readmore_link; ?>" class="readon<?php echo $this->item->params->get('pageclass_sfx'); ?>">
<?php if ($this->item->readmore_register) :
echo JText::_('Register to read more...');
elseif ($readmore = $this->item->params->get('readmore')) :
echo $readmore;
else :
echo JText::sprintf('Read more...');
endif; ?></a>
Change the line
echo JText::sprintf('Read more...');
into
echo JText::sprintf('Read more', $this->item->title);
The “Read more” link should now look like this: Read more: (Article title)

J2.5:Add article title to read more link

Some people want to add the article title to the readmore link. To achieve this you can use a template override.
If they are not already there, in your template folder:
  1. Create a new folder called 'html'.
  2. In that folder you create a folder called 'com_content'.
  3. And in that folder you create the folders called "category", "frontpage" and "article"
Then locate the following files:
  • (joomla)/components/com_content/views/category/tmpl/blog_item.php
  • (joomla)/components/com_content/views/featured/tmpl/default_item.php
  • (joomla)/components/com_content/views/article/tmpl/default.php
Copy the files to their respective locations in the template's html file:
  • (yourtemplate)/html/com_content/category/blog_item.php
  • (yourtemplate)/html/com_content/featured/default_item.php
  • (yourtemplate)/html/com_content/article/default.php
Open these files. Towards the bottom of each of these files you should see something like:
<p class="readmore"><a class="btn" href="<?php echo $link; ?>"> <span class="icon-chevron-right"></span>
<?php if (!$params->get('access-view')) :
echo JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
elseif ($readmore = $this->item->alternative_readmore) :
echo $readmore;
if ($params->get('show_readmore_title', 0) != 0) :
echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
endif;
elseif ($params->get('show_readmore_title', 0) == 0) :
echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
else :
echo JText::_('COM_CONTENT_READ_MORE');
echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
endif; ?>
</a></p>
Change the line
echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
into
echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE', $this->item->title);
The “Read more” link should now look like this: Read more: (Article title)

Changing article background color based on creation date

Suppose you want to show articles on your frontpage layout in different colors, depending on how old the article is. You can do this with a little bit of work using a template override. Here is a general link about template overrides: http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core.
The file you need to override is components/com_content/views/frontpage/tmpl/default_item.php. You would copy this file to <your template>/html/com_content/frontpage/default_item.php. Depending on your template, this file might already be there as an existing override file. In that case, just modify that file. For this example, we'll use the rhuk_milkyway template, so I copied it to templates/rhuk_milkyway/html/com_content/frontpage/default_item.php.
Ok, here is the idea. At this point in the program (when we're in the default_items.php program), the article create date is available as $this->item->created. So we can use that date, compared to the current date, to see how old the article is. Then we can add a different CSS class for articles of different ages.
To make the code easier to work with, we'll create a separate file for the method to calculate the dates and set the CSS class. I called this filetemplates/rhuk_milkyway/html/com_content/frontpage/myfrontpagehelper.php. Here is the code:
<?php
/**
* Gets class based on today's date and article date
* @param $date
* @return string containing CSS class name
*/

class MyFrontpageHelper {
 
function MyFrontPageHelper() {
parent::_constructor();
}
 
function getCSSClassFromDate($date) {
$dateClass = ''; // default to blank
// subtract create date from current date. both dates in seconds
$elapsedDays = (time() - strtotime($date)) / 86400; // 86400=number of seconds per day
if ($elapsedDays <= 7) $dateClass = 'dateCurrent';
if (($elapsedDays > 7) && ($elapsedDays <= 14)) $dateClass = 'dateLastWeek';
if ($elapsedDays > 14) $dateClass = "dateOld";
 
return $dateClass;
}
}
?>
This new class just has a constructor and one method. In the method, we're setting the class to "dateCurrent" if it's less than 7 days old, "dateLastWeek" if it's 7 to 14 days old, and "dateOld" if it's more than 14 days old.
Now, we can use this method to style our front page inside the override default_items.php file. The first thing we need to do is include this new program file. We do that at the top of thedefault_items.php file, right after the "defined..." line, as follows:
defined('_JEXEC') or die('Restricted access');
require_once('myfrontpagehelper.php');
Notice that we use the require_once statement. We need to use this (as opposed to the include statement) because this code gets executed multiple times, once for each article. So therequire_once statement makes sure we only include this file the first time.
Now we can get the date-based class name by calling this method with the current article's date. Where do we put the class? It depends on what we want to style. For example, say we want to style the article title block. In that case we would change line 11 (for the rhuk_milkyway template) as follows:
<?php if ($canEdit || $this->item->params->get('show_title') || $this->item->params->get('show_pdf_icon') || $this->item->params->get('show_print_icon') || $this->item->params->get('show_email_icon')) : ?>
<table class="contentpaneopen <?php echo MyFrontpageHelper::getCSSClassFromDate($this->item->created); ?>">
In line 11, instead of adding the Page Class Suffix, we're adding the special date CSS style by calling our new method. Notice that there is a space between the "contentpaneopen" style and the new date style. That is important, since that adds the date style as a second CSS style instead of changing the name of the contentpaneopen style.
Before we can test this, we need to make sure we have some articles in the proper date range. So I went into the Article Manager and changed the create dates so that some articles were current, some were 7-14 days old, and some were older. After doing that, I checked the HTML page source for the front page to make sure the class was being added correctly. Here is an example of what you should see:
<table class="contentpaneopen dateCurrent">
<tr>
<td class="contentheading" width="100%">
Joomla! Security Strike Team </td>
So our new "dateCurrent" class is being added as a separate class.
Now, we just have to add styling in our CSS file. I added this to the end of the file templates/rhuk_milkyway/css/template.css:
.contentpaneopen.dateCurrent {
background: #F0FFFF;
}
 
.contentpaneopen.dateLastWeek {
background: #FFF8DC;
}
 
.contentpaneopen.dateOld {
background: #DCDCDC;
}
Notice we're using both the contentpaneopen and the new "date" classes in the CSS selector. With the changes, the front page looks like this:
Tips frontpage date tip 20090215.png
We could change the background of the article text by adding the new class to line 53, as shown below:
<?php echo $this->item->event->beforeDisplayContent; ?>
<table class="contentpaneopen <?php echo MyFrontpageHelper::getCSSClassFromDate($this->item->created); ?>">
With this change, the front page now looks like this:
Tips frontpage date tip2 20090215.png
The exact location of where you use the new classes will depend on your template and what type of styling you want to do.