%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/lightco1/www/lightingrepublic.com.au/plugins/content/articletool/
Upload File :
Create Path :
Current File : /home/lightco1/www/lightingrepublic.com.au/plugins/content/articletool/articletool.php

<?php				
/*
* @name article tool 1.0
* Created By Guarneri Iacopo
* http://www.iacopo-guarneri.me/
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );

$app = JFactory::getApplication();
if ($app->isSite()){
	require_once("plugins/content/articletool/dompdf/autoload.inc.php");	
}
use Dompdf\Dompdf;

class Charset extends JFactory{
	function get(){
		$charset=$this->createDocument();
		return $charset->_charset;
	}
}
class plgContentarticletool extends JPlugin
{
	function onContentPrepare( $context, &$article, &$params, $page = 0)
	{
		if(!function_exists('relative_to_absolute')) {
			function relative_to_absolute($article,$home){
				preg_match_all('/src="(.+?)"/', $article->text, $src);
				preg_match_all('/href="(.+?)"/', $article->text, $href);
				$urls=array_merge($src[1], $href[1]);
				foreach($urls as $url){
					if(!strstr($url,"http://") && !strstr($url,"https://")){
						$path=str_replace("/","",str_replace("index.php","",$_SERVER["SCRIPT_NAME"]));
						
						$newurl=$home."/".$url;
						$n_replace=1;
						
						while(substr_count($newurl, "/".$path."/")>1){
							$oldurl=$newurl;
							$newurl=preg_replace('/'.preg_quote($path, '/').'/', "", $newurl, 1);
							if($oldurl==$newurl)
								break;
						}
						
						while(strstr($newurl,"//"))
							$newurl=str_replace("//","/",$newurl);
						
						$newurl=str_replace("http:/","http://",$newurl);
						$newurl=str_replace("https:/","https://",$newurl);

						$article->text=str_replace('"'.$url.'"', $newurl, $article->text);
					}
				}
				return $article->text;
			}
		}

		if(!function_exists('get_article_by_get')) {
			function get_article_by_get($use_curl){
				$articleId=JRequest::getVar('id', 0, 'get');
				$db = JFactory::getDBO();
				$sql = "SELECT * FROM #__content WHERE id = ".$articleId;
				$db->setQuery($sql);
					
				if($use_curl=="1"){	
					$rows = $db->loadObjectList();
					foreach ( $rows as $row )
						$articleLink[$row->id] = $row->catid;

					$content=get_web_page(JURI::base().ContentHelperRoute::getArticleRoute($articleId, $articleLink[$articleId])."&articletoolcurl=1");
					preg_match("/\[ARTICLETOOL\](.*?)\[\/ARTICLETOOL\]/ims", $content, $matches);
					$ret=$matches[1];
					$ret=preg_replace("/<div class='article_tool_container'>(.*?)<\/div>/ims", "", $ret);
					return $ret;
				} else {
					$fullArticle = $db->loadAssocList();
					return $fullArticle[0]["introtext"].$fullArticle[0]["fulltext"];
				}
			}
		}
		
		if(!function_exists('get_web_page')) {
			function get_web_page( $url )
			{
				$options = array(
					CURLOPT_RETURNTRANSFER => true,     // return web page
					CURLOPT_HEADER         => false,    // don't return headers
					CURLOPT_FOLLOWLOCATION => true,     // follow redirects
					CURLOPT_ENCODING       => "",       // handle all encodings
					CURLOPT_USERAGENT      => "spider", // who am i
					CURLOPT_AUTOREFERER    => true,     // set referer on redirect
					CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
					CURLOPT_TIMEOUT        => 120,      // timeout on response
					CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
					CURLOPT_SSL_VERIFYPEER => false     // Disabled SSL Cert checks
				);

				$ch      = curl_init( $url );
				curl_setopt_array( $ch, $options );
				$content = curl_exec( $ch );
				$err     = curl_errno( $ch );
				$errmsg  = curl_error( $ch );
				$header  = curl_getinfo( $ch );
				curl_close( $ch );

				$header['errno']   = $err;
				$header['errmsg']  = $errmsg;
				$header['content'] = $content;
				return $content;
			}
		}
			
		$input = JFactory::getApplication()->input;
		$view = $input->get('view'); 

		if(strstr(@$_SERVER["HTTP_REFERER"],"view=form") && strstr(@$_SERVER["HTTP_REFERER"],"layout=edit")){return false;}
		$cosa_mostrare=$this->params->get("cosa_mostrare");
		if(!is_array($cosa_mostrare)){$cosa_mostrare=array($cosa_mostrare);}
		$cats=$this->params->get("category");
		if(!is_array($cats)){$cats=array($cats);}
		$counter=$this->params->get("counter","0");
		$position=$this->params->get("position","top");
		$css=$this->params->get("css","color:#000; font-family: DejaVu Sans, sans-serif; font-size:14px; line-height:19px; padding:20px;");
		$memory_limit=$this->params->get("memory_limit","25");
		$visual_pdf=$this->params->get("visual_pdf","0");
		$show_in_blog=$this->params->get("show_in_blog","0");
		$icon_position=$this->params->get("icon_position","left");
		$show_subcategory=$this->params->get("show_subcategory","0");
		$use_curl=$this->params->get("use_curl","0");

		if($show_in_blog==0 && ($view=="featured" || $view=="category")){return false;}

		if($icon_position=="right"){
			$document = JFactory::getDocument();
			$style = '.stButton {
			    float: right !important;
			}';
			$document->addStyleDeclaration( $style );
		}

		if($visual_pdf==1){$visual_pdf=0;}else{$visual_pdf=1;}

		//se l'articolo non รจ della giusta categoria esce subito
		$database = JFactory::getDBO();
		$categoria_presente=0;
		foreach($cats as $cat){
			if(@$article->catid==$cat){
				$categoria_presente=1;
			} else if($show_subcategory=="1" && !is_null($article->catid)){
				$database->setQuery('SELECT * FROM #__categories WHERE id='.@$article->catid);
				$results = $database->loadAssocList();
				$parent=$results[0]["parent_id"];

				while($parent!="1"){
					$database->setQuery('SELECT * FROM #__categories WHERE id='.$parent);
					$results = $database->loadAssocList();
					$parent=$results[0]["parent_id"];
					
					if($results[0]["id"]==$cat)
						$categoria_presente=1;
				}
			}
			
			if($categoria_presente!=0)
				break;
		}
		if($categoria_presente==0){return false;}
		else{
			if(JRequest::getVar('download', 0, 'get')!=1)
				echo '<link rel="stylesheet" href="'.JURI::base().'plugins/content/articletool/style/style.css" type="text/css" />';
			if(JRequest::getVar('print', 0, 'get')!=1 && JRequest::getVar('download', 0, 'get')!=1){	
				//inserisce gli script per far funzionare sharethis
				foreach($cosa_mostrare as $ico){
					if($ico!="stampa" && $ico!="scarica"){
						$http="";
						if($_SERVER["REQUEST_SCHEME"]=="https")
							$http="s";
						$article->text.='<script type="text/javascript">var switchTo5x=true;</script>
						<script type="text/javascript" src="http'.$http.'://w'.$http.'.sharethis.com/button/buttons.js"></script>
						<script type="text/javascript">stLight.options({publisher: "cf4e376e-1d9c-43b1-8df7-617e403ae918", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>';
						break;
					}
				}
				
				$icone="";
				$uri = JFactory::getURI();
				//mostro le icone dei social, invia per mail, stampa e scarica
				foreach($cosa_mostrare as $ico){
					if($ico=="stampa"){
						$uri->setVar('print', 1);
						$uri->setVar('download', 0);
						$uri->setVar('id', $article->id);
						if($counter==0){
							$icone.="
							<span class='stButton stButton_print'>
							<a id='article_tool_print' href='".$uri->toString()."' target='_blank'>
								<img src='".JURI::base()."plugins/content/articletool/images/print.png' />
							</a></span>";
						}else{
							$icone.="<a id='article_tool_print' href='".$uri->toString()."' target='_blank'>
							<span class='stButton'><span class='stButton_gradient'>
								<img src='".JURI::base()."plugins/content/articletool/images/print.png' />
							<span class='chicklets chicklets_article_tool_print'>Print</span></span></span></a>";
						}
						
					}else if($ico=="scarica"){
						$uri->setVar('print', 0);
						$uri->setVar('download', 1);
						$uri->setVar('id', $article->id);
						if($counter==0){
							$icone.="
							<span class='stButton stButton_pdf'>
							<a id='article_tool_pdf' href='".$uri->toString()."' target='_blank'>
								<img src='".JURI::base()."plugins/content/articletool/images/pdf.png' />
							</a></span>";
						}else{
							$icone.="<a id='article_tool_pdf' href='".$uri->toString()."' target='_blank'>
							<span class='stButton'><span class='stButton_gradient'>
								<img src='".JURI::base()."plugins/content/articletool/images/pdf.png' />
							<span class='chicklets chicklets_article_tool_pdf'>Download</span></span></span></a>";
						}
					}else{
						$url_corrente=substr(JURI::base(),0,-1).JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid));
						if($counter==0){$type="large";}else{$type="hcount";}
						$icone.='<span class="st_'.$ico.'_'.$type.'" st_url="'.$url_corrente.'" displayText="'.$ico.'"></span>';
					}
					$uri->delVar('print');
					$uri->delVar('download');
					$uri->delVar('id');
				}
				
				if($position=="top"){
					$article->text = "<div class='article_tool_container'>".$icone."</div><div class='article_tool_separator'></div>".$article->text;
				}
				if($position=="bottom"){
					$article->text.="<div class='article_tool_container'>".$icone."</div><div class='article_tool_separator'></div>";
				}
			}
			
			//$article->text=relative_to_absolute($article,JURI::base());
			
			$charset=new Charset();
			if(JRequest::getVar('print', 0, 'get')==1){
				$article->text=get_article_by_get($use_curl);
				$article->text=relative_to_absolute($article,JURI::base());

				$article->text.='
					<script type="text/javascript">
						window.print();
						setTimeout(function(){window.close();}, 1000);
					</script>
				';
				
				echo "<meta http-equiv='content-type' content='text/html; charset=".$charset->get()."' /><div style='".$css."'><h2>".$article->title."</h2>".$article->text."</div>";
				JFactory::getApplication()->close();
				die("");
			}
			if(JRequest::getVar('download', 0, 'get')==1){
				$article->text=get_article_by_get($use_curl); 
				$article->text=relative_to_absolute($article,JURI::base());

				//$txt_to_rend=file_get_contents(JURI::current());
				$txt_to_rend="<meta http-equiv='content-type' content='text/html; charset=".$charset->get()."' /><div style='".$css."'><h2>".$article->title."</h2>".$article->text."</div>";

				if ( get_magic_quotes_gpc() )
					$txt_to_rend = stripslashes($txt_to_rend);
				$txt_to_rend=str_replace("undefinedpx","12px",$txt_to_rend);

				$old_limit = ini_set("memory_limit", $memory_limit."M");

				$dompdf = new DOMPDF();
				$dompdf->loadHtml($txt_to_rend);
				$dompdf->setPaper("portrait","letter");
				$dompdf->render();

				/*i pdf possono essere messi in cache, vedere se nella jed ci sono componenti article to pdf*/
				$dompdf->stream($article->title.".pdf", array("Attachment" => $visual_pdf));
				
				JFactory::getApplication()->close();
				die("");
			}
			if(JRequest::getVar('articletoolcurl', 0, 'get')==1){
				$article->text="[ARTICLETOOL]".$article->text."[/ARTICLETOOL]";
			}

			return true;
		}
	}
}

Zerion Mini Shell 1.0