Advertisement

[SOLVED] Enable PDF button in YOOtheme Zoo

This forum is for general questions about extensions for Joomla! version 1.5.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
Fireflight
Joomla! Intern
Joomla! Intern
Posts: 65
Joined: Fri Mar 30, 2007 4:29 pm

[SOLVED] Enable PDF button in YOOtheme Zoo

Post by Fireflight » Tue Oct 27, 2009 6:45 pm

After much finagling I've managed to get Joomla to generate a pdf from one of YOOTheme Zoo's pages, a third party component.

In components/com_zoo/views/item create a view.pdf.php file. Into that file, copy the following code.

Code: Select all

<?php
/**
 * @version		$Id: view.pdf.php 11371 2008-12-30 01:31:50Z ian $
 * @package		Joomla
 * @subpackage	Content
 * @copyright	Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
 * @license		GNU/GPL, see LICENSE.php
 * Joomla! is free software. This version may have been modified pursuant to the
 * GNU General Public License, and as distributed it includes or is derivative
 * of works licensed under the GNU General Public License or other free or open
 * source software licenses. See COPYRIGHT.php for copyright notices and
 * details.
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

/**
 * HTML Article View class for the Content component
 *
 * @package		Joomla
 * @subpackage	Content
 * @since 1.5
 */
class ZooViewItem extends YView {
	
	function display($tpl = null) {
		global $mainframe, $Itemid;

		// get dispatcher
		JPluginHelper::importPlugin('zoo');
		$dispatcher =& JDispatcher::getInstance();

		// get params
		$params =& $mainframe->getParams();

		// init vars
		$db          =& JFactory::getDBO();
		$user        =& JFactory::getUser();
		$document    =& JFactory::getDocument();
		$date        =& JFactory::getDate();
		$pathway     =& $mainframe->getPathway();
		$template    = $mainframe->getTemplate();
		$option      = JRequest::getCmd('option');
		$controller  = JRequest::getWord('controller');
		$catalog_id  = 0;
		$category_id = (int) JRequest::getInt('category_id', 0);
		
		// if category_id is set, generate pathway
		if ($category_id) {

			// parse catalog/category
			$catalog_category = $params->get('catalog_category', '0:0');
			if (strpos($catalog_category, ':')) {
				list($catalog_id, $params_category_id) = explode(':', $catalog_category, 2);
			}		

			// if category set, get categories from model data
			$categories =& $this->get('categories');

			// raise warning when category can not be accessed
			if (!isset($categories[$category_id])) {
				JError::raiseWarning(500, JText::_('Unable to access category'));
				return;
			}
			
			// create pathway
			$addpath = false;
			foreach ($categories[$category_id]->getPathway() as $cat) {
				if (!$params_category_id || $addpath) {
					$link = JRoute::_('index.php?Itemid='.$Itemid.'&option='.$option.'&view=category&category_id='.$cat->id);
					$pathway->addItem($cat->getName(), $link);
				}
				if ($params_category_id && $params_category_id == $cat->id) {
					$addpath = true;
				}
			}
		}

		// get item from model data
		$item =& $this->get('item');

		// fire trigger
		$dispatcher->trigger('onPrepareDisplayItem', array(&$this, &$item));	
		
		// raise warning when item can not be accessed
		if (empty($item->id) || !$item->canAccess($user)) {
			JError::raiseError(500, JText::_('Unable to access item'));
			return;
		}

		// raise warning when item is not published
		$publish_up   =& JFactory::getDate($item->publish_up);
		$publish_down =& JFactory::getDate($item->publish_down);
		if ($item->state != 1 || !(
		   ($item->publish_up == $db->getNullDate() || $publish_up->toUnix() <= $date->toUnix()) &&
		   ($item->publish_down == $db->getNullDate() || $publish_down->toUnix() >= $date->toUnix()))) {
			JError::raiseError(404, JText::_('Item not published'));
			return;
		}

		// create item pathway
		$link = JRoute::_('index.php?Itemid='.$Itemid.'&option='.$option.'&view=item'.($category_id ? '&category_id='.$category_id : '').'&item_id='.$item->id);
		$pathway->addItem($item->name, $link);

		// update hit count
		$item->hit();

		// get page title, if exists
		$title = $item->name;
		$menus = &JSite::getMenu();
		$menu  = $menus->getActive();
		if ($menu) {
			$menu_params = new JParameter($menu->params);
			if ($menu_params->get('page_title')) {
				$title = $menu_params->get('page_title');
			}
		}

	 	// set metadata
		$document->setTitle($title);
		if ($item->metadesc) $document->setDescription($item->metadesc);
		if ($item->metakey) $document->setMetadata('keywords', $item->metakey);
		if ($mainframe->getCfg('MetaTitle')) $document->setMetadata('title', $item->name);
		if ($mainframe->getCfg('MetaAuthor')) $document->setMetadata('author', $item->author);
		$metadata = new JParameter($item->metadata);
		foreach ($metadata->toArray() as $tag => $value) {
			if ($value) $document->setMetadata($tag, $value);
		}

		// set default layout
		$this->setLayout('item');

		// set layout override, if exists
		$type          = $item->getType();
		$path_default  = JPATH_BASE."/templates/$template/html/$option/".$this->getName();
		$path_template = $params->get('template') ? ZOO_SITE_PATH.'/templates/'.$params->get('template') : null;
		$layout_type   = $type->alias;
		$layout_item   = "item_".$item->id;

		if (JPath::find($path_default, $layout_item.'.php')) {
			$this->setLayout($layout_item);
		} else if (JPath::find($path_default, $layout_type.'.php')) {
			$this->setLayout($layout_type);
		} else if ($path_template && JPath::find($path_template, 'item.php')) {
			$this->addTemplatePath($path_template);
		}

		// set template vars
		$this->assignRef('option', $option);
		$this->assignRef('catalog_id', $catalog_id);
		$this->assignRef('category_id', $category_id);
		$this->assignRef('item', $item);
		$this->assign('link_base', 'index.php?Itemid='.$Itemid.'&option='.$option);

		// fire trigger
		$dispatcher->trigger('onBeforeDisplayItem', array(&$this));	

		// call parent display 
		parent::display($tpl);

		// fire trigger
		$dispatcher->trigger('onAfterDisplayItem', array(&$this));	
	}

}

?>
Basically all I've done is take components/com_content/views/article/view.pdf.php and copied it to the directory above. I then replaced the "class ContentViewArticle" code with the similar code from Zoo's view.item.php page. Then adding &format=pdf&tmpl=component to the existing Zoo URL generates a pdf file.

Thanks to these posts for pointing me in the right direction.
http://forum.joomla.org/viewtopic.php?f ... 79&start=0
http://forum.joomla.org/viewtopic.php?f ... 93&start=0
Last edited by Fireflight on Tue Oct 27, 2009 6:55 pm, edited 1 time in total.

Advertisement
Fireflight
Joomla! Intern
Joomla! Intern
Posts: 65
Joined: Fri Mar 30, 2007 4:29 pm

Re: [SOLVED] Enable PDF button in YOOtheme Zoo

Post by Fireflight » Tue Oct 27, 2009 6:48 pm

I my case I also had to copy a few images from the images/M_Images directory to the libraries/tcpdf/images directory.

Specifically:
emailButton.png
pdf_button.png
printButton.png

Your mileage may vary on this one.

Fireflight
Joomla! Intern
Joomla! Intern
Posts: 65
Joined: Fri Mar 30, 2007 4:29 pm

Re: [SOLVED] Enable PDF button in YOOtheme Zoo

Post by Fireflight » Tue Oct 27, 2009 6:54 pm

Finally, this is the code that's used to create the link for the pdf.

Code: Select all

<a href="<?php echo $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'].'&format=pdf&tmpl=component' ?>">Stuff goes here</a>

bragamiguel
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Jul 26, 2011 11:34 am

Re: [SOLVED] Enable PDF button in YOOtheme Zoo

Post by bragamiguel » Tue Jul 26, 2011 11:38 am

Hi Guys,

Nice solution, perhaps the best that i came across...
I'm a very good Web designer/CSS developer, but i'm very new to php; can you please explain me how to apply the link in an Zoo items?

Best regards,
Miguel

Fireflight
Joomla! Intern
Joomla! Intern
Posts: 65
Joined: Fri Mar 30, 2007 4:29 pm

Re: [SOLVED] Enable PDF button in YOOtheme Zoo

Post by Fireflight » Thu Aug 18, 2011 2:05 am

It's been a long time since I had to deal with Zoo now. I'd guess you'd have to edit the view.php (or something similar) file in the components/com_zoo/views/item/ directory. Then just place the create link code I posted last.

I really hated Zoo, so I'm sorry I can't be of more help.

bragamiguel
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Jul 26, 2011 11:34 am

Re: [SOLVED] Enable PDF button in YOOtheme Zoo

Post by bragamiguel » Thu Aug 18, 2011 8:46 am

Hi Fireflight!

Thanks for taking the time to answer me.
I'm gona check your solution and i'll get back to you.
Do you know any other component to make product catalogs?

Regards,
Miguel

r_clinton
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Thu Mar 12, 2009 5:08 pm

Re: [SOLVED] Enable PDF button in YOOtheme Zoo

Post by r_clinton » Fri Nov 25, 2011 5:14 pm

Hi FireFlight.
Thanks for your work on this.

Code: Select all

<a href="<?php echo $_SERVER['SCRIPT_NAME'].'?'.$_SERVER['QUERY_STRING'].'&format=pdf&tmpl=component' ?>">Stuff goes here</a>
Where do I add this code? Is there a particular file in /components/com_zoo?

Advertisement

Locked

Return to “Extensions for Joomla! 1.5”