-
Notifications
You must be signed in to change notification settings - Fork 8
/
zem_tpl.php
105 lines (78 loc) · 3.07 KB
/
zem_tpl.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
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
// Either:
// a) Copy a full single-file version of classTextile.php to your plugin directory.
// b) Uncomment the following line and edit it to give the location where
// classTextile.php can be found
#ini_set('include_path', ini_get('include_path') . ':/full/path/to/textile');
// c) Uncomment the following line and edit it to give the location of the textpattern
// directory inside a nearby, full Textpattern installation.
#define('txpath', '/full/path/to/textpattern');
if (empty($test)) {
exit(compile_plugin());
}
// -----------------------------------------------------
function extract_section($lines, $section)
{
$result = "";
$start_delim = "# --- BEGIN PLUGIN $section ---";
$end_delim = "# --- END PLUGIN $section ---";
$start = array_search($start_delim, $lines) + 1;
$end = array_search($end_delim, $lines);
$content = array_slice($lines, $start, $end-$start);
return join("\n", $content);
}
function compile_plugin($file = '')
{
global $plugin;
if (empty($file)) {
$file = $_SERVER['SCRIPT_FILENAME'];
}
if (!isset($plugin['name'])) {
$plugin['name'] = basename($file, '.php');
}
// Read the contents of this file, and strip line ends.
$content = file($file);
for ($i = 0; $i < count($content); $i++) {
$content[$i] = rtrim($content[$i]);
}
$plugin['help'] = trim(extract_section($content, 'HELP'));
$plugin['code'] = extract_section($content, 'CODE');
// Textpattern will textile it, and encode html.
$plugin['help_raw'] = $plugin['help'];
// This is for bc; and for help that needs to use it.
if (class_exists('Textile')) {
$textile = new Textile();
$plugin['help'] = $textile->parse($plugin['help']);
} elseif (defined('txpath')) {
global $trace;
include txpath.'/lib/txplib_misc.php';
include txpath.'/lib/class.trace.php';
include txpath.'/vendors/Textpattern/Loader.php';
$trace = new Trace();
$loader = new \Textpattern\Loader(txpath.'/vendors');
$loader->register();
$loader = new \Textpattern\Loader(txpath.'/lib');
$loader->register();
if (class_exists('\Netcarver\Textile\Parser')) {
$textile = new Netcarver\Textile\Parser();
$plugin['help'] = $textile->parse($plugin['help']);
}
}
$plugin['md5'] = md5( $plugin['code'] );
$header = <<<EOF
# {$plugin['name']} v{$plugin['version']}
# {$plugin['description']}
# {$plugin['author']}
# {$plugin['author_uri']}
# ......................................................................
# This is a plugin for Textpattern - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the 'Install plugin' box:
# ......................................................................
EOF;
$body = trim(chunk_split(base64_encode(gzencode(serialize($plugin))), 72));
// To produce a copy of the plugin for distribution, load this file in a browser.
header('Content-type: text/plain');
return $header."\n\n".$body;
}
?>