forked from lat9/notifier_report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifier_report.php
103 lines (91 loc) · 3.71 KB
/
notifier_report.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
<?php
// -----
// A tool to create a report identifying the notifiers present in a store's file-system.
//
require 'includes/application_top.php';
// -----
// Add support for generation of a markdown (.md) output file.
//
if (isset($_GET['markdown'])) {
$is_markdown = true;
$filename_string = '#### %s' . PHP_EOL . '```';
$notifier_string = '#%1$s: %2$s';
$report_file = DIR_FS_LOGS . '/notifier_report_' . date('Ymd_His') . '.md';
$md_header =
'---' . PHP_EOL .
'title: Notifier Report' . PHP_EOL .
'description: Zen Cart Notifier Report' . PHP_EOL .
'category: code' . PHP_EOL .
'type: codepage' . PHP_EOL .
'weight: 10' . PHP_EOL .
'---' . PHP_EOL . PHP_EOL .
'<!-- RELEASETIME - update -->' . PHP_EOL;
error_log($md_header . PHP_EOL, 3, $report_file);
} else {
$is_markdown = false;
$filename_string = '%s';
$notifier_string = "\t\t" . 'line#$1$s: %2$s';
$report_file = DIR_FS_LOGS . '/notifier_report_' . date('Ymd_His') . '.txt';
error_log('Start notifier report (v1.0.0), created ' . date('Y-m-d H:i:s') . PHP_EOL, 3, $report_file);
}
$dir_fs_catalog = str_replace('\\', '/', DIR_FS_CATALOG);
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(DIR_FS_CATALOG));
$it->rewind();
$found_first_file = false;
while ($it->valid()) {
if (!$it->isDot() && pathinfo($it->key(), PATHINFO_EXTENSION) == 'php') {
$lines = file($it->key());
for ($i = 0, $n = count($lines), $found_semi = false, $found_first = false; $i < $n; $i++) {
// -----
// Determine if the current line contains a '->notify', continuing if not.
//
$next_pos = strpos($lines[$i], '->notify');
if ($next_pos === false) {
continue;
}
// -----
// The notification's event and parameters list ends with a semi-colon.
//
// Build up the parameters present in the notification, for output once the semi-colon (or
// end-of-file) is found.
//
$parameters = trim($lines[$i]);
$start_line = $i;
$notify_end_found = strpos($parameters, ';');
while ($i < $n && $notify_end_found === false) {
if ($i != $start_line) {
$parameters .= ' ' . trim($lines[$i]);
}
$notify_end_found = strpos($parameters, ';');
$i++;
}
$parameters = str_replace(
array(
'$this->notify(',
'$zco_notifier->notify(',
'$zco_notifier->notify (',
'$GLOBALS[\'zco_notifier\']->notify(',
');',
),
'',
$parameters
);
// -----
// If we get here, there was "something" found ... so output the current record.
//
if (!$found_first) {
$found_first = true;
$file_stripped = str_replace($dir_fs_catalog, '', str_replace('\\', '/', $it->key()));
error_log(PHP_EOL . sprintf($filename_string, $file_stripped) . PHP_EOL, 3, $report_file);
if ($is_markdown && !$found_first_file) {
$found_first_file = true;
$filename_string = '```' . PHP_EOL . PHP_EOL . $filename_string;
}
}
error_log(sprintf($notifier_string, $start_line, $parameters) . PHP_EOL, 3, $report_file);
}
}
$it->next();
}
echo "Report created: $report_file.";
require DIR_WS_INCLUDES . 'application_bottom.php';