The following code contains a modification I made to the loadArticle function in J1.5.6 from article.php:
(joomla_root)/components/com_content/models/article.php
-->beginning at line 556 (assuming no other hacks)
IMPORTANT: The code modifications below are aimed at users of JACLplus pro because of the the reference to JACL subgroups. ALSO, you must implement SEF urls so that the url redirection can be properly created.
The key to the functionality of this hack is the function JURI::getInstance. Used in conjunction with base64 encoding, I assembled a method for capturing the current url request, encoding it, and returning in the form:
http://www.yoursite.com/Log-in.html?ret ... TERSGOHERE
This creates a redirect to the login page which, most importantly, redirects you to the originally requested page, assuming your login credentials provide suffecient access rights.
Remember, this is just a temporary hack, though it does work quite well.
Code: Select all
/**
* Method to load content article data
*
* @access private
* @return boolean True on success
* @since 1.5
*/
function _loadArticle()
{
global $mainframe;
if($this->_id == '0')
{
return false;
}
// Load the content if it doesn't already exist
if (empty($this->_article))
{
// Get the page/component configuration
$params = &$mainframe->getParams();
// If voting is turned on, get voting data as well for the article
$voting = ContentHelperQuery::buildVotingQuery($params);
// Get the WHERE clause
$where = $this->_buildContentWhere();
$query = 'SELECT a.*, u.name AS author, u.usertype, cc.title AS category, s.title AS section,' .
' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(":", a.id, a.alias) ELSE a.id END as slug,'.
' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug,'.
' g.name AS groups, s.published AS sec_pub, cc.published AS cat_pub, s.access AS sec_access, cc.access AS cat_access '.$voting['select'].
' FROM #__content AS a' .
' LEFT JOIN #__categories AS cc ON cc.id = a.catid' .
' LEFT JOIN #__sections AS s ON s.id = cc.section AND s.scope = "content"' .
' LEFT JOIN #__users AS u ON u.id = a.created_by' .
' LEFT JOIN #__groups AS g ON a.access = g.id'.
$voting['join'].
$where;
$this->_db->setQuery($query);
$this->_article = $this->_db->loadObject();
// if ( ! $this->_article ) {
// return false;
// }
//Modification to resolve 404 redirect error from registered page
//Prevent from throwing 404 and redirect to any desired page e.g. login/register or content page
if ( ! $this->_article ) {
//Retrieve content access level
$user =& JFactory::getUser();
$myquery = "SELECT `access` FROM #__content WHERE `id`=". (int) $this->_id;
$this->_db->setQuery($myquery);
$myrow = $this->_db->loadObject();
//Retrieve JACLplus access levels
defined('_JACL');
$user = &JFactory::getUser();
$gids = $user->get( 'jaclplus', '0' );
$myJACLGids = explode(",", trim($gids));
if (in_array($myrow->access , $myJACLGids)) {
return true;
} else {
//Here we retrieve the url instance, encode it, and assemble
//the url for the login page with the redirect appended to it.
$uri =& JURI::getInstance();
$url = $uri->getPath();
$url = base64_encode($url);
$mainframe->redirect("Log-in.html?return=".$url);
exit();
}
}
//End Modification to resolve 404 redirct error from registered page
if($this->_article->publish_down == $this->_db->getNullDate()) {
$this->_article->publish_down = JText::_('Never');
}
// These attributes need to be defined in order for the voting plugin to work
if ( count($voting) && ! isset($this->_article->rating_count) ) {
$this->_article->rating_count = 0;
$this->_article->rating = 0;
}
return true;
}
return true;
}