<?php

    /**
     * @package action
     */


	include_once( PLOG_CLASS_PATH.'class/action/blogaction.class.php' );
	include_once( PLOG_CLASS_PATH.'class/view/plugintemplatedview.class.php' );
    include_once( PLOG_CLASS_PATH.'class/view/errorview.class.php' );
    include_once( PLOG_CLASS_PATH.'plugins/linktracker/class/dao/linktracker.class.php' );
    include_once( PLOG_CLASS_PATH.'plugins/linktracker/class/dao/linktrackerresult.class.php' );

	define( 'LINKTRACKER_TEMPLATE', 'linktracker' );

    /**
     * Action that receives the input when the operation called
     * is "LinkTracker"
     */
    class LinkTrackerAction extends BlogAction 
	{

    	/**
         * Constructor
         */
    	function LinkTrackerAction( $blogInfo, $request )
        {
        	$this->BlogAction( $blogInfo, $request );
        }

        /**
         * Carries out the action
         */
        function perform()
        {
            $this->_view = new PluginTemplatedView( $this->_blogInfo,
			                             'linktracker',
			                             LINKTRACKER_TEMPLATE, 
										 SMARTY_VIEW_CACHE_CHECK,
										 Array( 'blogId' => $this->_blogInfo->getId()));
			if( $this->_view->isCached()) {
				return true;
			}
		
        	$l = new LinkTracker();
            $links =  $l->getLinks( $this->_blogInfo->getId());

            // if any error, return the error view
            if( ($links == '') || (empty($links))) {
            	$this->_view = new ErrorView( $this->_blogInfo );
                $this->_view->setValue( 'message', 'error_blog_has_no_links' );
                $this->setCommonData();
                return false;
            }

            $this->_view->setValue( 'links', $links );
            $this->setCommonData();

            return true;
        }
    }
?>
