Publishing guestbook entries from the front end

Phoca Guestbook - creating guestbooks in Joomla! CMS
jbudd
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 24 Mar 2009, 14:04

Publishing guestbook entries from the front end

Post by jbudd »

In case it is of use to anyone else, I got Phoca Guestbook 1.3.2 to allow publishing from the front end.
It seems to work, though I have not tested it very extensively!
phoca1.jpg
phoca2.jpg
How to do it:
Step 1: Show unpublished entries if user is an administrator or super administrator.
Modify function buildQuery() in models/phocaguestbook.php

Code: Select all

	function _buildQuery()
	{
		// We need to get a list of all items in the given category
$user=&JFactory::getUser();
if ($user->usertype == "Super Administrator" || $user->usertype == "Administrator") { /* jb */
		$query = 'SELECT *' .
			' FROM #__phocaguestbook_items' .
			' WHERE catid = '.(int) $this->_id.
			' ORDER BY ordering DESC';
		}
		else
		{
		$query = 'SELECT *' .
			' FROM #__phocaguestbook_items' .
			' WHERE catid = '.(int) $this->_id.
			' AND published = 1 ' . 
			' ORDER BY ordering DESC';
		}
		return $query;
	}
Modify function countItem() in models/phocaguestbook.php

Code: Select all

	function countItem($id = 0)
	{
		$user=&JFactory::getUser();
		if ($user->usertype == "Super Administrator" || $user->usertype == "Administrator") { /* jb */
		$query = 'SELECT COUNT(id) FROM #__phocaguestbook_items'
			. ' WHERE  catid = '.$id;
		}
		else {
		$query = 'SELECT COUNT(id) FROM #__phocaguestbook_items'
			. ' WHERE published = 1 AND catid = '.$id;
		}
		;
		$this->_db->setQuery( $query );
		if (!$this->_db->query()) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}
		return $this->_db->loadRow();
	}
Step 2: Print "(UNPUBLISHED)" on the title line, include "publish" button rather than "unpublish" as appropriate
Modify views/phocaguestbook/tmpl/default.php
Just above "//SECURITY" insert

Code: Select all

/* jb */ if ($values->published != 1){ $msgpg .= " (UNPUBLISHED)"; }
Just above "//--Messages (Posts, Items)" modify the code

Code: Select all

	if ($this->administrator != 0) {
		$msgpg.='<a href="'.JRoute::_('index.php?option=com_phocaguestbook&view=phocaguestbook&id='.$this->id.'&Itemid='.$this->itemid.'&controller=phocaguestbook&task=delete&mid='.$values->id.'&limitstart='.$this->pagination->limitstart).'" onclick="return confirm(\''.JText::_( 'Delete Message' ).'\');">'.JHTML::_('image', 'components/com_phocaguestbook/assets/images/icon-trash.gif', JText::_( 'Delete' )).'</a>';
		
/* jb add publish link */ if ($values->published != 1){ 
		$msgpg.='<a href="'.JRoute::_('index.php?option=com_phocaguestbook&view=phocaguestbook&id='.$this->id.'&Itemid='.$this->itemid.'&controller=phocaguestbook&task=publish&mid='.$values->id.'&limitstart='.$this->pagination->limitstart).'">'.JHTML::_('image', 'components/com_phocaguestbook/assets/images/icon-publish.gif', JText::_( 'publish' )).'</a>';
}
else
{
		$msgpg.='<a href="'.JRoute::_('index.php?option=com_phocaguestbook&view=phocaguestbook&id='.$this->id.'&Itemid='.$this->itemid.'&controller=phocaguestbook&task=unpublish&mid='.$values->id.'&limitstart='.$this->pagination->limitstart).'">'.JHTML::_('image', 'components/com_phocaguestbook/assets/images/icon-unpublish.gif', JText::_( 'Unpublish' )).'</a>';
}
	}
	$msgpg.='</p></div>';	
}

//--Messages (Posts, Items)
Step 3: Create publish() function in controllers/phocaguestbook.php (It's pretty much a copy of unpublish())
Insert in function __construct()

Code: Select all

		$this->registerTask('publish', 'publish');// Register Extra tasks
Insert new function

Code: Select all

	function publish() /* this function jb */
	{
		global $mainframe;
		$user 		=& JFactory::getUser();
		$cid 		= JRequest::getVar( 'mid', null, '', 'int' );
		$id 		= JRequest::getVar( 'id', null, '', 'int' );
		$itemid 	= JRequest::getVar( 'Itemid', null, '', 'int' );
		$limitstart = JRequest::getVar( 'limitstart', null, '', 'int' );
		$model 		= $this->getModel('phocaguestbook');
		
		if (strtolower($user->usertype) == strtolower('super administrator') || $user->usertype == strtolower('administrator')) {
			
			if (count( $cid ) < 1) {
				JError::raiseError(500, JText::_( 'Select an item to publish' ) );
			}
			if(!$model->publish($cid, 1))
			{
				echo "<script> alert('".$model->getError(true)."'); window.history.go(-1); </script>\n";
				$msg = JText::_( 'Error publishing Phoca Guestbook Item' );
			}
			else {
				$msg = JText::_( 'Phoca Guestbook Item published' );
			}
		} else {
			$msg = JText::_( 'You are not authorized to publish selected item' );
		}
		
		// Limitstart (if we delete the last item from last pagination, this pagination will be lost, we must change limitstart)
		$countItem = $model->countItem($id);

		if ((int)$countItem[0] == $limitstart) {
			$limitstart = 0;
		}
		
		// Redirect
		$link	= 'index.php?option=com_phocaguestbook&view=phocaguestbook&id='.$id.'&Itemid='.$itemid.'&limitstart='.$limitstart;
		$link	= JRoute::_($link);
		$this->setRedirect( $link, $msg );
	}
Step 4: Create assets/images/icon-publish.gif
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48689
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Publishing guestbook entries from the front end

Post by Jan »

Hi, thank your for this guide, Jan
If you find Phoca extensions useful, please support the project
X-Bit
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 25 Mar 2010, 15:47

Re: Publishing guestbook entries from the front end

Post by X-Bit »

Hello @all!

I do understand, that this thread is rather old. But, as I stated here
viewtopic.php?f=2&t=8778&p=35880#p35880
I am looking for such a solution!

Trying to work through the manual with the version of Phoca Guestbook 1.4.0, I am not sure if I am doing something wrong or if it just doesn´t work anymore because I get an error

Code: Select all

Parse error: parse error in D:\XAMPP\htdocs\migration_Lehmibou_1.5.15\components\com_phocaguestbook\views\phocaguestbook\tmpl\default.php  on line 88
Did somebody managed to get this working under 1.4?
Thanks for your appreciated help!
jbudd
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 24 Mar 2009, 14:04

Re: Publishing guestbook entries from the front end

Post by jbudd »

I have not tried making it work with 1.4, still on 1.3.2. I cant see any reason why it shouldnt work though!

jb
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48689
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Publishing guestbook entries from the front end

Post by Jan »

Ok
If you find Phoca extensions useful, please support the project
Post Reply