-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincludePHP.php
More file actions
106 lines (91 loc) · 3.51 KB
/
includePHP.php
File metadata and controls
106 lines (91 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
defined('_JEXEC') or die( "Direct Access Is Not Allowed" );
jimport('joomla.event.plugin');
jimport('joomla.user.helper');
class plgContentIncludePHP extends JPlugin {
function plgContentIncludePHP( &$subject ) {
parent::__construct( $subject );
}
function onPrepareContent(&$article, &$params, $limitstart) {
if (!property_exists($article, "modified_by")) {
return;
}
// if($article->usertype != "Super Administrator" && $article->usertype != "Administrator") return true;
// if (!array_key_exists('Super Users', JUserHelper::getUserGroups($article->modified_by))) return true;
if (!in_array('8', JUserHelper::getUserGroups($article->modified_by))) return true;
$regex = "#{php}(.*?){/php}#s";
$article->text = preg_replace_callback($regex, array($this,"execphp"), $article->text);
$regex = "#{phpfile}(.*?){/phpfile}#s";
$article->text = preg_replace_callback($regex, array($this,"incphp"), $article->text);
$regex = "#{js}(.*?){/js}#s";
$article->text = preg_replace_callback($regex, array($this,"execjs"), $article->text);
$regex = "#{jsfile}(.*?){/jsfile}#s";
$article->text = preg_replace_callback($regex, array($this,"incjs"), $article->text);
$regex = "#{htmlfile}(.*?){/htmlfile}#s";
$article->text = preg_replace_callback($regex, array($this,"inchtml"), $article->text);
$regex = "#{css}(.*?){/css}#s";
$article->text = preg_replace_callback($regex, array($this,"css"), $article->text);
$regex = "#{jshead}(.*?){/jshead}#s";
$article->text = preg_replace_callback($regex, array($this,"jshead"), $article->text);
$regex = "#{jsheadfile}(.*?){/jsheadfile}#s";
$article->text = preg_replace_callback($regex, array($this,"jsheadfile"), $article->text);
$article->text = str_replace('<p>{deleteme}</p>', '', $article->text);
return true;
}
/** Layer di compatibilità 1.7 -> 1.5 */
function onContentPrepare($context, &$article, &$params, $page = 0) {
$this->onPrepareContent($article, $params, $page);
}
private function execphp($matches) {
ob_start();
eval($matches[1]);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
private function execjs($matches) {
$output = "<script type='text/javascript'>{$matches[1]}</script>";
return $output;
}
private function incjs($matches) {
$output = "<script type='text/javascript' src='{$matches[1]}'></script>";
return $output;
}
private function inchtml($matches) {
$output = '';
if(file_exists($matches[1]) && is_readable($matches[1])) {
$body = file_get_contents($matches[1]);
if(empty($body)) return '';
preg_match("#<body(.*?)>(.*?)</body>#si",$body, $matches2);
if(isset($matches2[2])) $output = $matches2[2];
if(empty($output)) $output = $body;
}
return $output;
}
private function incphp($matches) {
if(!file_exists($matches[1])) return '';
ob_start();
include($matches[1]);
$output = ob_get_contents();
ob_end_clean();
return $output;
}
private function jshead($matches) {
$head = '<script type="text/javascript">'.$matches[1].'</script>'.PHP_EOL;
$document = &JFactory::getDocument();
$document->addCustomTag($head);
return "{deleteme}";
}
private function jsheadfile($matches) {
$head = '<script type="text/javascript" src="'.$matches[1].'"></script>'.PHP_EOL;
$document = &JFactory::getDocument();
$document->addCustomTag($head);
return "{deleteme}";
}
private function css($matches) {
$head = '<style type="text/css">'.$matches[1].'</style>'.PHP_EOL;
$document = &JFactory::getDocument();
$document->addCustomTag($head);
return "{deleteme}";
}
}