-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdm_functions.php
More file actions
147 lines (122 loc) · 4.11 KB
/
dm_functions.php
File metadata and controls
147 lines (122 loc) · 4.11 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
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
<?php
// returns the current query string excluding any specfied keys
function getQueryStringExcludingKeys( $aExcludedKeys = NULL )
{
// if no keys supplied then set to blank array
if ($aExcludedKeys == NULL) {
$aExcludedKeys = array();
}
// if string is supplied then convert to a single element array
if (is_string($aExcludedKeys)) {
$s = $aExcludedKeys;
$aExcludedKeys = array();
$aExcludedKeys[] = $s;
}
$aNewParts = array();
$aOldParts = explode('&', $_SERVER['QUERY_STRING']);
// loop through each key of current URL
foreach ($aOldParts as $sOldPart) {
$bUsePart = true;
// loop through each excluded key
foreach ($aExcludedKeys as $key) {
// if we have a match then set flag to false
if (substr($sOldPart, 0, strlen($key)) == $key) {
$bUsePart = false;
}
}
// add key to new array if flag not set to false
if ($bUsePart == true) {
$aNewParts[] = $sOldPart;
}
}
// put together new query string from array and return
$aNewParts = implode('&', $aNewParts);
return $aNewParts;
}
function returnTokenTypeCount($tokens, $type)
{
$kount = 0;
foreach ($tokens as $aaToken) {
if ($aaToken['type'] == $type) {
$kount++;
}
}
return $kount;
}
function getLogFilename($filename)
{
$log_filename = $filename;
$log_filename = str_replace('\\', '_', $log_filename);
$log_filename = str_replace('/', '_', $log_filename);
$log_filename = str_replace('___', '_', $log_filename);
$log_filename = str_replace(':', '', $log_filename);
$log_filename = str_replace('__', '_', $log_filename);
$log_filename = urlencode($log_filename);
return $log_filename;
}
function logResults($filename, $errors, $warnings, $log_folder = 'Logs' )
{
if (!is_dir($log_folder)) {
echo '<h2>Warning: Log folder not found - Create a folder called "Logs" inside the "CodeSniffer" folder.</h2>';
return false;
}
$log_filename = getLogFilename($filename);
$fp = fopen($log_folder.'/'.$log_filename, 'w');
$file_last_change = date("F d Y H:i:s.", filemtime($filename));
$file_error_count = $errors;
$file_warning_count = $warnings;
$log_content = "$file_last_change\n$file_error_count\n$file_warning_count";
fwrite($fp, $log_content);
}
function includeJslintFiles( $url)
{
?>
<div class="report_filename hide"><p></p><input type="image" src="wcs_images/refresh.png" class="submit_back sniff-refresh" onclick="location.reload();"></div><div class="report_summary"> </div></pre></div>
<script src="jslint/web_jslint.js"></script>
<script src="jquery-1.10.2.min.js"></script>
<script src="jslint/lint_remote_file.js"></script>
<div id="JSLINT_" style="display:none;">
<div id=JSLINT_EDITION></div>
<div id=JSLINT_SOURCE><textarea></textarea></div>
<div id=JSLINT_BUTTON></div>
<div id=JSLINT_ERRORS></div>
<div id=JSLINT_REPORT></div>
<div id=JSLINT_PROPERTIES><textarea></textarea></div>
<div id=JSLINT_OPTIONS></div>
<input id=JSLINT_INDENT>
<input id=JSLINT_MAXLEN>
<input id=JSLINT_MAXERR>
<textarea id=JSLINT_PREDEF></textarea>
<div id=JSLINT_JSLINT><textarea></textarea></div>
<script>ADSAFE.id("JSLINT_");</script>
<script src="jslint/init_ui.js"></script>
<script>
ADSAFE.go("JSLINT_", function (dom, lib) {
'use strict';
lib.init_ui(dom);
<?php
echo 'lintExternalFile(lib, "'.$url.'");'."\n";
?>
});
</script>
</div>
<?php
}
function updateIcon($type)
{
$icons['good'] = 'tick';
$icons['bad'] = 'cross';
$icoName = $icons[$type];
?>
<script>
(function() {
var link = document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = 'wcs_images/<?php echo $icoName; ?>.ico';
document.getElementsByTagName('head')[0].appendChild(link);
}());
</script>
<?php
}
?>