-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.php
74 lines (57 loc) · 1.65 KB
/
mod.php
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
<?php
/*
PHP-Mod
A simple utility class for manipulating html or include files.
This may be useful for projects such as Wordpress child themes or plugins.
*/
class Mod
{
protected $html;
function __construct($html)
{
$this->html = $html;
}
function append($html) //Append some html
{
$this->html .= $html;
}
function prepend($html) //Prepend some html
{
$this->html = $html.$this->html;
}
function insertBefore($regex, $html) //Insert some html before a regex match
{
$this->html = preg_replace($regex, "$html$0", $this->html);
}
function insertAfter($regex, $html) //Insert some html after a regex match
{
$this->html = preg_replace($regex, "$0$html", $this->html);
}
function pregReplace($regex, $replacement)
{
$this->html = preg_replace($regex, $replacement, $this->html);
}
function output() //Output some html
{
echo $this->html;
}
}
class IncludeMod extends Mod
{
protected $html;
//Use include file output for html
function __construct($includefile)
{
ob_start();
include ( $includefile );
$this->html = ob_get_clean();
}
//Use parent class functions
function output(){parent::output();}
function insertBefore($regex, $html){parent::insertBefore($regex, $html);}
function insertAfter($regex, $html){parent::insertAfter($regex, $html);}
function append($html){parent::append($html);}
function prepend($html){parent::prepend($html);}
function pregReplace($regex, $replacement){parent::pregReplace($regex, $replacement);}
}
?>