This repository was archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcanvashack.css.php
73 lines (61 loc) · 1.91 KB
/
canvashack.css.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
<?php
header("Content-Type: text/css");
/* don't cache me! */
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1
header("Pragma: no-cache"); // HTTP 1.0
header("Expires: 0"); // Proxies
define('IGNORE_LTI', true);
require_once 'common.inc.php';
use \Battis\AppMetadata;
$location = (!empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_REQUEST['location']);
function canonicalNamespaceId($id)
{
return preg_replace('/[^a-z0-9]+/i', '_', $id);
}
function canvasHackNamespace($id, $javascript)
{
return preg_replace(
'/^(\s*var\s+)?canvashack\s*=\s*{\n*(.*)};/is',
canonicalNamespaceId($id) . ": {\n$2\n}",
$javascript
);
}
$canvashacks = array();
$enabledPages = $toolbox->mysql_query("
SELECT p.*
FROM `pages` AS p
INNER JOIN `canvashacks` AS c
ON c.`id` = p.`canvashack`
WHERE
c.`enabled` = TRUE
ORDER BY
p.`include` DESC
");
while ($page = $enabledPages->fetch_assoc()) {
if ((!empty($page['url']) && $page['url'] == $location) ||
(!empty($page['pattern']) && preg_match($page['pattern'], $location))) {
if ($page['include']) {
$canvashacks[$page['canvashack']] = true;
} else {
unset($canvashacks[$page['canvashack']]);
}
}
}
$css = array();
if (($applicableCSS = $toolbox->mysql_query("
SELECT *
FROM `css`
WHERE
`canvashack` = '" . implode("' OR `canvashack` = '", array_keys($canvashacks)) . "'
")) == false) {
exit;
}
while ($entry = $applicableCSS->fetch_assoc()) {
$css[$entry['canvashack']] = shell_exec("php \"{$entry['path']}\" \"{$location}\" 2>&1");
}
foreach ($css as $id => $stylesheet) {
$plugin = new AppMetadata($toolbox->getMySQL(), $id);
echo "/* CanvasHack ID $id begin */\n";
echo $plugin->derivedValues($stylesheet);
echo "\n/* CanvasHack ID $id end */\n\n";
}