1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
header("Content-Type: text/css"); |
4
|
|
|
|
5
|
|
|
/* don't cache me! */ |
6
|
|
|
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1 |
7
|
|
|
header("Pragma: no-cache"); // HTTP 1.0 |
8
|
|
|
header("Expires: 0"); // Proxies |
9
|
|
|
|
10
|
|
|
define('IGNORE_LTI', true); |
11
|
|
|
|
12
|
|
|
require_once 'common.inc.php'; |
13
|
|
|
|
14
|
|
|
use \Battis\AppMetadata; |
15
|
|
|
|
16
|
|
|
$location = (!empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_REQUEST['location']); |
17
|
|
|
|
18
|
|
|
function canonicalNamespaceId($id) |
19
|
|
|
{ |
20
|
|
|
return preg_replace('/[^a-z0-9]+/i', '_', $id); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
function canvasHackNamespace($id, $javascript) |
24
|
|
|
{ |
25
|
|
|
return preg_replace( |
26
|
|
|
'/^(\s*var\s+)?canvashack\s*=\s*{\n*(.*)};/is', |
27
|
|
|
canonicalNamespaceId($id) . ": {\n$2\n}", |
28
|
|
|
$javascript |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$canvashacks = array(); |
33
|
|
|
$enabledPages = $toolbox->mysql_query(" |
34
|
|
|
SELECT p.* |
35
|
|
|
FROM `pages` AS p |
36
|
|
|
INNER JOIN `canvashacks` AS c |
37
|
|
|
ON c.`id` = p.`canvashack` |
38
|
|
|
WHERE |
39
|
|
|
c.`enabled` = TRUE |
40
|
|
|
ORDER BY |
41
|
|
|
p.`include` DESC |
42
|
|
|
"); |
43
|
|
|
|
44
|
|
View Code Duplication |
while ($page = $enabledPages->fetch_assoc()) { |
|
|
|
|
45
|
|
|
if ((!empty($page['url']) && $page['url'] == $location) || |
46
|
|
|
(!empty($page['pattern']) && preg_match($page['pattern'], $location))) { |
47
|
|
|
if ($page['include']) { |
48
|
|
|
$canvashacks[$page['canvashack']] = true; |
49
|
|
|
} else { |
50
|
|
|
unset($canvashacks[$page['canvashack']]); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$css = array(); |
56
|
|
View Code Duplication |
if (($applicableCSS = $toolbox->mysql_query(" |
|
|
|
|
57
|
|
|
SELECT * |
58
|
|
|
FROM `css` |
59
|
|
|
WHERE |
60
|
|
|
`canvashack` = '" . implode("' OR `canvashack` = '", array_keys($canvashacks)) . "' |
61
|
|
|
")) == false) { |
62
|
|
|
exit; |
63
|
|
|
} |
64
|
|
|
while ($entry = $applicableCSS->fetch_assoc()) { |
65
|
|
|
$css[$entry['canvashack']] = shell_exec("php \"{$entry['path']}\" \"{$location}\" 2>&1"); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
foreach ($css as $id => $stylesheet) { |
69
|
|
|
$plugin = new AppMetadata($toolbox->getMySQL(), $id); |
70
|
|
|
echo "/* CanvasHack ID $id begin */\n"; |
71
|
|
|
echo $plugin->derivedValues($stylesheet); |
72
|
|
|
echo "\n/* CanvasHack ID $id end */\n\n"; |
73
|
|
|
} |
74
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.