These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
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()) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
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(" |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
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. ![]() |
|||
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 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.