| Server IP : 195.130.67.5 / Your IP : 216.73.217.154 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Old Sites/ees_request/plugins/system/ |
Upload File : |
<?php
/**
* @package Printme
* @author Dioscouri Design
* @link http://www.dioscouri.com
* @copyright Copyright (C) 2007 Dioscouri Design. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*/
/** ensure this file is being included by a parent file */
defined('_JEXEC') or die('Restricted access');
/** Import library dependencies */
jimport('joomla.plugin.plugin');
class plgSystemPrintme extends JPlugin
{
function plgSystemPrintme(& $subject, $config)
{
parent::__construct($subject, $config);
}
/**
* Checks if the core extension is installed
*
* @return boolean
*/
function _isInstalled()
{
$success = false;
jimport('joomla.filesystem.file');
if (JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_printme'.DS.'defines.php'))
{
$success = true;
JLoader::register('Printme', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_printme'.DS.'defines.php');
}
return $success;
}
/**
* Checks if this system plugin should even run
*
* @return boolean
*/
function _canRun()
{
$success = false;
if (!$this->_isInstalled())
{
return $success;
}
// don't run if we're on the admin-side
$mainframe = JFactory::getApplication();
if ($mainframe->isAdmin())
{
return $success;
}
// we should only continue if we're printing (which means the URL contains &print=1
$print = (int) JRequest::getVar('print');
if ($print != '1')
{
return $success;
}
// we should only continue if the URL contains &tmpl=component
$tmpl = JRequest::getVar('tmpl');
if ($tmpl != 'component')
{
return $success;
}
// TODO research if we need to do anything special to support when format=pdf || format=raw || format=feed
$format = JRequest::getVar('format');
// if we're here, then all is OK
$success = true;
return $success;
}
/**
* Inject our CSS file if the plugin is supposed to run
*
* @return void
*/
function onAfterInitialise()
{
$success = null;
if (!$this->_canRun())
{
return $success;
}
// CSS files must be included before rendering
// which is why we need to use a separate system event
$document =& JFactory::getDocument();
$document->addStyleSheet( JURI::root(true).'/media/com_printme/css/printme.css');
// get the option variable
$option = JRequest::getVar( 'option' );
// does a connector exist for this option?
if ($this->connectorExists( $option ))
{
// if connector exists, create its object
$name = str_replace("_", "", $option);
$classname = 'plgPrintme'.$name;
$object = new $classname();
// let the connector add any CSS files desired
if (method_exists($object, 'addStyleSheet'))
{
$object->addStyleSheet();
}
}
return $success;
}
/**
* Modify the Response Body
* if the plugin is supposed to run
*
* @return void
*/
function onAfterRender()
{
$success = null;
if (!$this->_canRun())
{
return $success;
}
// get the output
$body = JResponse::getBody();
// This needs to work with any and all body tags, so we need to use some regex
$regex = "#(.*?)<body (.*?)>(.*?)</body>(.*?)#s";
$matches = array();
preg_match( $regex, $body, $matches );
// preg_match regex returns this array:
// $matches[0] = [Anything before the body]<body id="something" class="whatever">All the HTML of the body</body>[Anything after the body]
// $matches[1] = [Anything before the body]
// $matches[2] = id="something" class="whatever"
// $matches[3] = All the HTML of the body
// $matches[4] = [Anything after the body]
// At this point, $matches[3] (the main body of the document)
// could be modified by component-specific connector classes
// which could independently work around things such as Read More links, list pagination, etc,
// so that the output is (for example) a full article rather than a paginated one
// get the option variable
$option = JRequest::getVar( 'option' );
// does a connector exist for this option?
if ($this->connectorExists( $option ))
{
// if connector exists, create its object
$name = str_replace("_", "", $option);
$classname = 'plgPrintme'.$name;
$object = new $classname();
// let the connector set the body HTML
$matches[3] = $object->setBodyHTML( $matches[3] );
}
// if a custom header exists, add it
$header_html = "";
if (Printme::getInstance()->get('header_html'))
{
$header_html = "\n";
$header_html .= "<div id='printme_header'>";
$header_html .= Printme::getInstance()->get('header_html');
$header_html .= "</div>";
}
// if breadcrumb is enabled, add it
$breadcrumb_html = "";
if (Printme::getInstance()->get('display_breadcrumb'))
{
// load the breadcrumbs module
jimport( 'joomla.application.module.helper' );
$module = JModuleHelper::getModule('mod_breadcrumbs');
// create the breadcrumbs html by rendering the module
$breadcrumb_html = "\n";
$breadcrumb_html .= "<div id='printme_breadcrumb'>";
$breadcrumb_html .= JModuleHelper::renderModule($module);
$breadcrumb_html .= "</div>";
}
// if pagetitle is enabled, add it
$pagetitle_html = "";
if (Printme::getInstance()->get('display_pagetitle'))
{
// get the pagetitle
$document =& JFactory::getDocument();
$pagetitle = $document->getTitle();
// include the pagetitle
$pagetitle_html = "\n";
$pagetitle_html .= "<div id='printme_pagetitle'>";
$pagetitle_html .= $pagetitle;
$pagetitle_html .= "</div>";
}
// if a custom footer exists, add it
$footer_html = "";
if (Printme::getInstance()->get('footer_html'))
{
$footer_html = "\n";
$footer_html .= "<div id='printme_footer'>";
$footer_html .= Printme::getInstance()->get('footer_html');
$footer_html .= "</div>";
}
// OK now let's rebuild the body html
$body_tag_opening = "<body $matches[2]>";
$body_tag_closing = "</body>";
if (Printme::getInstance()->get('print_dialog', '0'))
{
// TODO Figure out why chrome doesn't load the entire page first
$print_dialog = "
<script type='text/javascript'>
window.onload = printmePrintPage();
function printmePrintPage()
{
window.print();
}
</script>
";
$body_tag_closing = $print_dialog."</body>";
}
$new_body = $matches[1].$body_tag_opening.$header_html.$breadcrumb_html.$pagetitle_html.'<div id="printme_body">'.$matches[3].'</div>'.$footer_html.$body_tag_closing.$matches[4];
// and now set the body
JResponse::setBody($new_body);
// then quietly exit
return $success;
}
/**
* Checks if a component-specific connector exists
*
* @return boolean
*/
function connectorExists( $option )
{
$success = false;
jimport('joomla.filesystem.file');
$file = JPATH_SITE.DS.'plugins'.DS.'system'.DS.'printme'.DS.$option.'.php';
if (JFile::exists( $file ))
{
require_once( $file );
$success = true;
}
return $success;
}
}