/
find_help.php
191 lines (168 loc) · 6.02 KB
/
find_help.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/env php
<?php
##################################################
#
# Copyright (c) 2004-2018 OIC Group, Inc.
#
# This file is part of Exponent
#
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################
$param_array = array();
$verbose = false;
$recur = true;
$total_new = 0;
include_once('../exponent.php');
if (php_sapi_name() == 'cli') {
$nl = "\n";
if (!empty($_SERVER['argc'])) for ($ac = 1; $ac < $_SERVER['argc']; $ac++) {
if ($_SERVER['argv'][$ac] == '-v') {
$verbose = true;
} elseif (!empty($_SERVER['argv'][$ac])) {
$version_title = $_SERVER['argv'][$ac];
$version = $db->selectValue('help_version', 'id', 'version="' . $_SERVER['argv'][$ac] . '"');
}
}
} else {
$nl = '<br>';
if (!empty($_GET['verbose'])) {
$verbose = true;
}
if (!empty($_GET['version'])) {
$version_title = $_GET['version'];
$version = $db->selectValue('help_version', 'id', 'version="' . expString::escape($_GET['version']) . '"');
}
}
/**
* find_help.php - attempts to auto-check all ExponentCMS help links
* by collecting them and checking them against the doc.exponentcms.org db tables
*/
print $nl . "Checking the Exponent Help System!" . $nl . $nl;
print "Grabbing links from the folders!" . $nl;
parse_files('..', false);
$filelist = array('../cron', '../framework', '../install', '../themes');
foreach ($filelist as $file) {
parse_files($file);
}
print $nl . "Completed grabbing " . $total_new . " Total Help Links!" . $nl . $nl;
if (empty($version)) {
$version = $db->selectValue('help_version', 'id', 'is_current=1');
$version_title = 'Current';
}
print "Using Help Version - " . $version_title . "!" . $nl . $nl;
// match condensed lists against db tables
print "List of Missing Help Page Links" . $nl;
$pages = array_unique($param_array['page']);
sort($pages);
foreach ($pages as $page) {
if (!$db->selectObject('section', 'sef_name=' . $page)) {
print $page . $nl;
}
}
print $nl . "List of Missing Help Document Links" . $nl;
$docs = array_unique(array_merge($param_array['doc'],$param_array['module']));
sort($docs);
foreach ($docs as $doc) {
if (!$db->selectObject('help', 'sef_url=' . $doc . ' AND help_version_id=' . $version)) {
print $doc . $nl;
}
}
print $nl . "Completed Checking the Exponent Help System!" . $nl;
// traverse all the files
function parse_files($filename, $recurse = true) {
global $recur, $verbose, $nl;
if ($verbose) print "Grabbing help links" . $nl;
$recur = $recurse;
if (is_dir($filename)) { // go through directory
do_dir($filename);
} else { // do file
$pi = pathinfo($filename);
if (empty($pi['extension'])) $pi['extension'] = null;
do_file($filename, $pi['extension']);
}
}
// parse all the files
// processes file for assoc strings
function do_file($file, $fileext) {
if ($fileext == 'tpl') {
do_extract($file);
}
}
// go through a directory
function do_dir($dir) {
global $recur;
$d = dir($dir);
while (false !== ($entry = $d->read())) {
if ($entry == '.' || $entry == '..') {
continue;
}
$entry = $dir . '/' . $entry;
if (is_dir($entry)) { // if a directory, go through it
if ($recur) do_dir($entry);
} else { // if file, parse only if extension is matched
$pi = pathinfo($entry);
if (empty($pi['extension'])) $pi['extension'] = null;
if (isset($pi['extension']) && $pi['extension'] == 'tpl') {
do_file($entry, $pi['extension']);
}
}
}
$d->close();
}
//parse the help function lines
// rips gettext strings from $file and prints them in C format
function do_extract($file) {
global $total_new, $param_array, $verbose, $nl;
// regex for the help shortcut function
$regex_help = '/(?<=help\s)((page=[\'"]|[^\'"])*)([^}]*)(?=\})/';
// regex for the parameter list
$regex_params = '/([^=\s]+)=["\']([^"\']+)["\']/';
$content = @file_get_contents($file);
if (empty($content)) {
return;
}
preg_match_all(
$regex_help,
$content,
$matches,
PREG_PATTERN_ORDER
);
if ($verbose) print "$file" . " - ";
$num_added = 0;
$parsed = null;
for ($i = 0, $iMax = count($matches[0]); $i < $iMax; $i++) {
// str_replace('"', "\'", $matches[0][$i]); // remove the killer double-quotes
// segregate params
preg_match_all(
$regex_params,
$matches[0][$i],
$parsed,
PREG_PATTERN_ORDER
);
//print_r(explode('=',$s[0][0]));
foreach ($parsed[0] as $pair) {
if (strpos($pair, '=')) {
list($key, $val) = explode('=', $pair, 2);
$param_array[trim($key)][] = trim($val);
$num_added++;
}
}
}
$total_new += $num_added;
if ($verbose) print $num_added . $nl;
}
function output($text) {
global $nl;
if (!is_array($text)) $text = array($text);
foreach ($text as $string) {
print $string . $nl;
}
}
?>