Tuesday, October 6, 2009

Joomla component access plugin

working on a site need such functionality like a guest don't able to see some component, need to login to view the component. in joomla how you will do it? i have found a plug-in for joomla to do that.


comcontrol.php

comcontrol.xml


here is the code for comcontrol.php


toString();

$u_host = $uri->getHost();

$u_path = $uri->getPath();


// Get parameters

$com_name = $this->params->get('com_name', '');

$com_substring = $this->params->get('com_substring', '');

$com_redirect_url = $this->params->get('com_redirect_url', '');

$com_mode = $this->params->get('com_mode', '');

$com_debug = $this->params->get('com_debug', '');

$com_message = $this->params->get('com_message', '');


// Get usertype to see if logged-in

$user =& JFactory::getUser();

$user_type = $user->get('usertype');



// Display debug info

if ($com_debug=='1') {

$mainframe->enqueueMessage( 'ComControl Plugin Debug Messages:') ;

$mainframe->enqueueMessage( 'JFactory::getURI =' . $url ) ;

$mainframe->enqueueMessage( 'getHost =' . $u_host ) ;

$mainframe->enqueueMessage( 'JRequest::getCmd(option) =' . $option ) ;

$mainframe->enqueueMessage( 'getPath =' . $u_path ) ;

$mainframe->enqueueMessage( '$com_name =' . $com_name ) ;

$mainframe->enqueueMessage( '$user_type =' . $user_type ) ;

}


// Main

if ($user_type != "" && $user_type != "Public Frontend") { return ;} //if user logged-in, then return from function

if (stripos($com_name, $option)===false) {return;} //return from function if this is not the com we're interested in

// if ($option != $com_name) { return;} //return from function if this is not the com we're interested in


$substring = explode(" ",$com_substring); // get all substring tags, space delimited

$tag_match = false; // initialize as false



foreach($substring as $tag) {

if ( empty($tag) ) {break;} // stop if tag empty

$tag_match = strpos($url, $tag); //See if the substring tag is present in the path

if ($tag_match !== false) {break;} // stop if there is a match

}



if ($com_debug=='1') { $mainframe->enqueueMessage( '$tag_match =' . $tag_match ) ;}


if ( ($com_mode == '0') && ($tag_match !== false) ) { return ;} // return from function if login not required

if ( ($com_mode == '1') && ($tag_match === false) ) { return ;} // return from function if login not required


// Redirect to login page

if ( empty($com_redirect_url) ) { $com_redirect_url = '/index.php?option=com_user&view=login';} //standard joomla login page

if ($com_debug != '1') {$mainframe->redirect( $com_redirect_url, $com_message );}


Return ;// return from function

}


}

?>


Here is the code for comcontrol.xml




<install version="1.50" type="plugin" group="system">

<name>System - Component Content Control</name>

<author>Your Name</author>

<creationdate>September 1, 2009</creationdate>

<copyright>Copyright (C) 2009 Your name. All rights reserved.</copyright>

<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>

<authoremail>webmaster@Yourdomain.com</authoremail>

<authorurl>www.yourdomain.com</authorurl>

<version>1.51</version>

<description>Component Content Control - this plugin allows you to specify the pages of a particular component that are visible to guests versus those pages of the component that require the user to login first. You can make multiple copies of this plugin in the Plugin Manager page if you need to apply it to more than one component. There are 2 modes: Mode 0 requires guests to login in order to see any of the pages for the specified component, EXCEPT for pages tagged with the substring. Mode 1 allows guests to see all pages of the specified component, EXCEPT for pages tagged with the substring. </description>

<files>

<filename plugin="comcontrol">comcontrol.php</filename>

</files>

<params>

<param name="com_name" type="text" size="75" default="com_myblog" label="Component Names" description="Name of the extensions (leave a space between names) that you wish to control. This is the portion of the joomla URL after the ?option= ">

<param name="com_mode" type="radio" default="0" label="Mode" description="Mode 0: block guest access to component pages except for tagged pages. Mode 1: allow guest access to component pages except for tagged pages.">

Mode 0

Mode 1



<param name="com_substring" type="text" size="75" default="" label="Substring Tag" description="Enter the substring tags that you wish to use for allowing or disallowing guest access (see Mode options above). You can use multiple tags - leave a space between tags">

<param name="com_message" type="text" size="75" default="" label="Display message" description="This message is displayed when the user must login to access the component.">

<param name="com_redirect_url" type="text" size="75" default="" label="Redirect URL" description="This is the page where users are redirected to login. Leave this blank for the default Joomla login page. If you are not using the default Joomla login page, then you can enter in the full path of the login page you are using.">

<param name="com_debug" type="radio" default="0" label="Turn on debugging mode" description="Normally leave this off.">

Off

On



</params>

</install>



I need to save those two files and zip it. then from joomla admin panel I can able to install the plug-in. it works fine for me.


Or you can download the plug-in directly from the link http://joomlacode.org/gf/project/plgcomcontrol/frs/ from where i download the plugin.


all da best.

3 comments:

  1. \What a useful information you shared in this post! Thanks for sharing.
    Loaded Templates

    ReplyDelete
  2. I am happy to found your blogs.It is really great.I learnt new things from your website.I like your thoughts.Thanks for making such a cool post.

    Hire website developers

    ReplyDelete
  3. Hi, thanks for your great information! Well, it really seems so great. http://www.lowhosting.com/networksolutions-review/

    ReplyDelete