@@ -5,7 +5,7 @@ |
||
| 5 | 5 | header('Content-Type: application/javascript'); |
| 6 | 6 | |
| 7 | 7 | if (!empty($_REQUEST['download'])) { |
| 8 | - header("Content-Disposition: attachment; filename=canvashack-loader.js"); |
|
| 8 | + header("Content-Disposition: attachment; filename=canvashack-loader.js"); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | ?> |
@@ -5,16 +5,16 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | function canonicalNamespaceId($id) |
| 7 | 7 | { |
| 8 | - return preg_replace('/[^a-z0-9]+/i', '_', $id); |
|
| 8 | + return preg_replace('/[^a-z0-9]+/i', '_', $id); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | function canvasHackNamespace($id, $javascript) |
| 12 | 12 | { |
| 13 | - return preg_replace( |
|
| 14 | - '/^(\s*var\s+)?canvashack\s*=\s*{\n*(.*)};/is', |
|
| 15 | - canonicalNamespaceId($id) . ": {\n$2\n}", |
|
| 16 | - $javascript |
|
| 17 | - ); |
|
| 13 | + return preg_replace( |
|
| 14 | + '/^(\s*var\s+)?canvashack\s*=\s*{\n*(.*)};/is', |
|
| 15 | + canonicalNamespaceId($id) . ": {\n$2\n}", |
|
| 16 | + $javascript |
|
| 17 | + ); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | header('Content-Type: application/javascript'); |
@@ -36,14 +36,14 @@ discard block |
||
| 36 | 36 | p.`include` DESC |
| 37 | 37 | "); |
| 38 | 38 | while ($page = $enabledPages->fetch_assoc()) { |
| 39 | - if ((!empty($page['url']) && $page['url'] == $_REQUEST['location']) || |
|
| 40 | - (!empty($page['pattern']) && preg_match($page['pattern'], $_REQUEST['location']))) { |
|
| 41 | - if ($page['include']) { |
|
| 42 | - $canvashacks[$page['canvashack']] = true; |
|
| 43 | - } else { |
|
| 44 | - unset($canvashacks[$page['canvashack']]); |
|
| 45 | - } |
|
| 46 | - } |
|
| 39 | + if ((!empty($page['url']) && $page['url'] == $_REQUEST['location']) || |
|
| 40 | + (!empty($page['pattern']) && preg_match($page['pattern'], $_REQUEST['location']))) { |
|
| 41 | + if ($page['include']) { |
|
| 42 | + $canvashacks[$page['canvashack']] = true; |
|
| 43 | + } else { |
|
| 44 | + unset($canvashacks[$page['canvashack']]); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $dom = array(); |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | WHERE |
| 54 | 54 | `canvashack` = '" . implode("' OR `canvashack` = '", array_keys($canvashacks)) . "' |
| 55 | 55 | ")) == false) { |
| 56 | - exit; |
|
| 56 | + exit; |
|
| 57 | 57 | } |
| 58 | 58 | while ($entry = $applicableDOM->fetch_assoc()) { |
| 59 | - $dom[$entry['canvashack']] = "$('{$entry['selector']}').{$entry['event']}(" . |
|
| 60 | - (empty($entry['action']) ? '' : "this." . canonicalNamespaceId($entry['canvashack']) . |
|
| 61 | - ".{$entry['action']}") . ");"; |
|
| 59 | + $dom[$entry['canvashack']] = "$('{$entry['selector']}').{$entry['event']}(" . |
|
| 60 | + (empty($entry['action']) ? '' : "this." . canonicalNamespaceId($entry['canvashack']) . |
|
| 61 | + ".{$entry['action']}") . ");"; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $javascript = array('go' => 'go: function() { |
@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | WHERE |
| 73 | 73 | `canvashack` = '" . implode("' OR `canvashack` = '", array_keys($canvashacks)) . "' |
| 74 | 74 | ")) == false) { |
| 75 | - exit; |
|
| 75 | + exit; |
|
| 76 | 76 | } |
| 77 | 77 | while ($entry = $response->fetch_assoc()) { |
| 78 | - $javascript[$entry['canvashack']] = canvasHackNamespace( |
|
| 79 | - $entry['canvashack'], |
|
| 80 | - shell_exec("php \"{$entry['path']}\" \"" . addslashes(serialize($_REQUEST)) . "\" 2>&1") |
|
| 81 | - ); |
|
| 78 | + $javascript[$entry['canvashack']] = canvasHackNamespace( |
|
| 79 | + $entry['canvashack'], |
|
| 80 | + shell_exec("php \"{$entry['path']}\" \"" . addslashes(serialize($_REQUEST)) . "\" 2>&1") |
|
| 81 | + ); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | ?> |
@@ -12,165 +12,165 @@ discard block |
||
| 12 | 12 | class CanvasHack |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - private $sql; |
|
| 16 | - |
|
| 17 | - private $path; |
|
| 18 | - |
|
| 19 | - private $table = 'canvashacks'; |
|
| 20 | - private $css = 'css'; |
|
| 21 | - private $javascript = 'javascript'; |
|
| 22 | - private $pages = 'pages'; |
|
| 23 | - private $dom = 'dom'; |
|
| 24 | - |
|
| 25 | - private $id = null; |
|
| 26 | - private $name = null; |
|
| 27 | - private $abstract = null; |
|
| 28 | - private $description = null; |
|
| 29 | - |
|
| 30 | - public function __construct($sql, $path) |
|
| 31 | - { |
|
| 32 | - |
|
| 33 | - if ($sql instanceof \mysqli) { |
|
| 34 | - $this->sql = $sql; |
|
| 35 | - } else { |
|
| 36 | - throw new CanvasHack_Exception( |
|
| 37 | - 'Expected mysqli object, received ' . get_class($sql), |
|
| 38 | - CanvasHack_Exception::MYSQL |
|
| 39 | - ); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if (file_exists($path) && file_exists($manifest = realpath("$path/manifest.xml"))) { |
|
| 43 | - $this->path = dirname($manifest); |
|
| 44 | - $this->parseManifest($manifest); |
|
| 45 | - $pluginMetadata = new \Battis\AppMetadata($this->sql, $this->id); |
|
| 46 | - $pluginMetadata['PLUGIN_PATH'] = $path; |
|
| 47 | - $pluginMetadata['PLUGIN_URL'] = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on' ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . preg_replace("|^{$_SERVER['DOCUMENT_ROOT']}(.*)$|", '$1', $pluginMetadata['PLUGIN_PATH']); |
|
| 48 | - } else { |
|
| 49 | - if (isset($manifest)) { |
|
| 50 | - throw new CanvasHack_Exception( |
|
| 51 | - "Manifest file missing, expected <code>$path/manifest.xml</code>", |
|
| 52 | - CanvasHack_Exception::MANIFEST |
|
| 53 | - ); |
|
| 54 | - } else { |
|
| 55 | - $this->loadManifestEntry($path); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public static function getCanvasHackById($sql, $id) |
|
| 61 | - { |
|
| 62 | - if (!($sql instanceof \mysqli)) { |
|
| 63 | - throw new CanvasHack_Exception( |
|
| 64 | - 'Expected mysqli object, received ' . get_class($sql), |
|
| 65 | - CanvasHack_Exception::MYSQL |
|
| 66 | - ); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $_id = $sql->real_escape_string($id); |
|
| 70 | - $result = $sql->query("SELECT * FROM `canvashacks` WHERE `id` = '$_id'"); |
|
| 71 | - if ($result->num_rows === 0) { |
|
| 72 | - throw new CanvasHack_Exception( |
|
| 73 | - "No existing CanvasHacks matching ID `$id`", |
|
| 74 | - CanvasHack_Exception::ID |
|
| 75 | - ); |
|
| 76 | - } else { |
|
| 77 | - $row = $result->fetch_assoc(); |
|
| 78 | - return new CanvasHack($sql, $row['path']); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - private function loadManifestEntry($id) |
|
| 83 | - { |
|
| 84 | - $response = $this->sql->query(" |
|
| 15 | + private $sql; |
|
| 16 | + |
|
| 17 | + private $path; |
|
| 18 | + |
|
| 19 | + private $table = 'canvashacks'; |
|
| 20 | + private $css = 'css'; |
|
| 21 | + private $javascript = 'javascript'; |
|
| 22 | + private $pages = 'pages'; |
|
| 23 | + private $dom = 'dom'; |
|
| 24 | + |
|
| 25 | + private $id = null; |
|
| 26 | + private $name = null; |
|
| 27 | + private $abstract = null; |
|
| 28 | + private $description = null; |
|
| 29 | + |
|
| 30 | + public function __construct($sql, $path) |
|
| 31 | + { |
|
| 32 | + |
|
| 33 | + if ($sql instanceof \mysqli) { |
|
| 34 | + $this->sql = $sql; |
|
| 35 | + } else { |
|
| 36 | + throw new CanvasHack_Exception( |
|
| 37 | + 'Expected mysqli object, received ' . get_class($sql), |
|
| 38 | + CanvasHack_Exception::MYSQL |
|
| 39 | + ); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if (file_exists($path) && file_exists($manifest = realpath("$path/manifest.xml"))) { |
|
| 43 | + $this->path = dirname($manifest); |
|
| 44 | + $this->parseManifest($manifest); |
|
| 45 | + $pluginMetadata = new \Battis\AppMetadata($this->sql, $this->id); |
|
| 46 | + $pluginMetadata['PLUGIN_PATH'] = $path; |
|
| 47 | + $pluginMetadata['PLUGIN_URL'] = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on' ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . preg_replace("|^{$_SERVER['DOCUMENT_ROOT']}(.*)$|", '$1', $pluginMetadata['PLUGIN_PATH']); |
|
| 48 | + } else { |
|
| 49 | + if (isset($manifest)) { |
|
| 50 | + throw new CanvasHack_Exception( |
|
| 51 | + "Manifest file missing, expected <code>$path/manifest.xml</code>", |
|
| 52 | + CanvasHack_Exception::MANIFEST |
|
| 53 | + ); |
|
| 54 | + } else { |
|
| 55 | + $this->loadManifestEntry($path); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public static function getCanvasHackById($sql, $id) |
|
| 61 | + { |
|
| 62 | + if (!($sql instanceof \mysqli)) { |
|
| 63 | + throw new CanvasHack_Exception( |
|
| 64 | + 'Expected mysqli object, received ' . get_class($sql), |
|
| 65 | + CanvasHack_Exception::MYSQL |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $_id = $sql->real_escape_string($id); |
|
| 70 | + $result = $sql->query("SELECT * FROM `canvashacks` WHERE `id` = '$_id'"); |
|
| 71 | + if ($result->num_rows === 0) { |
|
| 72 | + throw new CanvasHack_Exception( |
|
| 73 | + "No existing CanvasHacks matching ID `$id`", |
|
| 74 | + CanvasHack_Exception::ID |
|
| 75 | + ); |
|
| 76 | + } else { |
|
| 77 | + $row = $result->fetch_assoc(); |
|
| 78 | + return new CanvasHack($sql, $row['path']); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + private function loadManifestEntry($id) |
|
| 83 | + { |
|
| 84 | + $response = $this->sql->query(" |
|
| 85 | 85 | SELECT * FROM `{$this->table}` WHERE `id` = '" . $this->sql->real_escape_string($id) . "' |
| 86 | 86 | "); |
| 87 | - $row = $response->fetch_assoc(); |
|
| 88 | - if ($row) { |
|
| 89 | - $this->id = $row['id']; |
|
| 90 | - $this->name = $row['name']; |
|
| 91 | - if (!empty($row['abstract'])) { |
|
| 92 | - $this->abstract = $row['abstract']; |
|
| 93 | - } |
|
| 94 | - if (!empty($row['description'])) { |
|
| 95 | - $this->description = $row['description']; |
|
| 96 | - } |
|
| 97 | - } else { |
|
| 98 | - throw new CanvasHack_Exception( |
|
| 99 | - "Manifest database entry missing for $id", |
|
| 100 | - CanvasHack_Exception::MANIFEST |
|
| 101 | - ); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - private function parseManifest($manifest) |
|
| 106 | - { |
|
| 107 | - $xml = simplexml_load_string(file_get_contents($manifest)); |
|
| 108 | - if ($xml === false) { |
|
| 109 | - throw new CanvasHack_Exception( |
|
| 110 | - "$manifest could not be parsed as a valid XML document", |
|
| 111 | - CanvasHack_Exception::MANIFEST |
|
| 112 | - ); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $this->parseManifestMetadata($xml); |
|
| 116 | - $this->parseManifestComponents($xml->components); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - private function parseManifestMetadata($xml) |
|
| 120 | - { |
|
| 121 | - $this->required('id', $this->sql->real_escape_string($xml->id)); |
|
| 122 | - $this->required('name', $xml->name); |
|
| 123 | - $this->optional('abstract', $xml->abstract); |
|
| 124 | - $this->optional('description', $xml->description); |
|
| 125 | - if (!isset($this->abstract) && !isset($this->description)) { |
|
| 126 | - throw new CanvasHack_Exception( |
|
| 127 | - 'Either an abstract or a description must be provided in the manifest', |
|
| 128 | - CanvasHack_Exception::REQUIRED |
|
| 129 | - ); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // TODO deal with authors |
|
| 133 | - |
|
| 134 | - $_name = $this->sql->real_escape_string($this->name); |
|
| 135 | - $_abstract = ( |
|
| 136 | - isset($this->abstract) ? |
|
| 137 | - $this->sql->real_escape_string($this->abstract) : |
|
| 138 | - $this->sql->real_escape_string($this->description) |
|
| 139 | - ); |
|
| 140 | - $_description = ( |
|
| 141 | - isset($this->description) ? |
|
| 142 | - $this->sql->real_escape_string($this->description) : |
|
| 143 | - $this->sql->real_escape_string($this->abstract) |
|
| 144 | - ); |
|
| 145 | - $_path = $this->sql->real_escape_string($this->path); |
|
| 146 | - |
|
| 147 | - $this->updateDb($this->table, $this->id, array('name' => $_name, 'path' => $_path, 'abstract' => $_abstract, 'description' => $_description), 'id'); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - private function parseManifestCSS($css) |
|
| 151 | - { |
|
| 152 | - if (!empty($css)) { |
|
| 153 | - $this->updateDb($this->css, $this->id, array('path' => realpath($this->path . '/' . $css))); |
|
| 154 | - } else { |
|
| 155 | - $this->clearDb($this->css, $this->id); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - private function parseManifestJavascript($javascript) |
|
| 160 | - { |
|
| 161 | - if (!empty($javascript)) { |
|
| 162 | - $this->updateDb($this->javascript, $this->id, array('path' => realpath($this->path) . '/' . $javascript)); |
|
| 163 | - } else { |
|
| 164 | - $this->clearDb($this->javascript, $this->id); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - private function parseManifestCanvasPages($pages) |
|
| 169 | - { |
|
| 170 | - $this->clearDb($this->pages, $this->id); |
|
| 171 | - if (!empty($pages->include)) { |
|
| 172 | - foreach ($pages->include->children() as $page) { |
|
| 173 | - if (!$this->sql->query(" |
|
| 87 | + $row = $response->fetch_assoc(); |
|
| 88 | + if ($row) { |
|
| 89 | + $this->id = $row['id']; |
|
| 90 | + $this->name = $row['name']; |
|
| 91 | + if (!empty($row['abstract'])) { |
|
| 92 | + $this->abstract = $row['abstract']; |
|
| 93 | + } |
|
| 94 | + if (!empty($row['description'])) { |
|
| 95 | + $this->description = $row['description']; |
|
| 96 | + } |
|
| 97 | + } else { |
|
| 98 | + throw new CanvasHack_Exception( |
|
| 99 | + "Manifest database entry missing for $id", |
|
| 100 | + CanvasHack_Exception::MANIFEST |
|
| 101 | + ); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + private function parseManifest($manifest) |
|
| 106 | + { |
|
| 107 | + $xml = simplexml_load_string(file_get_contents($manifest)); |
|
| 108 | + if ($xml === false) { |
|
| 109 | + throw new CanvasHack_Exception( |
|
| 110 | + "$manifest could not be parsed as a valid XML document", |
|
| 111 | + CanvasHack_Exception::MANIFEST |
|
| 112 | + ); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $this->parseManifestMetadata($xml); |
|
| 116 | + $this->parseManifestComponents($xml->components); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + private function parseManifestMetadata($xml) |
|
| 120 | + { |
|
| 121 | + $this->required('id', $this->sql->real_escape_string($xml->id)); |
|
| 122 | + $this->required('name', $xml->name); |
|
| 123 | + $this->optional('abstract', $xml->abstract); |
|
| 124 | + $this->optional('description', $xml->description); |
|
| 125 | + if (!isset($this->abstract) && !isset($this->description)) { |
|
| 126 | + throw new CanvasHack_Exception( |
|
| 127 | + 'Either an abstract or a description must be provided in the manifest', |
|
| 128 | + CanvasHack_Exception::REQUIRED |
|
| 129 | + ); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // TODO deal with authors |
|
| 133 | + |
|
| 134 | + $_name = $this->sql->real_escape_string($this->name); |
|
| 135 | + $_abstract = ( |
|
| 136 | + isset($this->abstract) ? |
|
| 137 | + $this->sql->real_escape_string($this->abstract) : |
|
| 138 | + $this->sql->real_escape_string($this->description) |
|
| 139 | + ); |
|
| 140 | + $_description = ( |
|
| 141 | + isset($this->description) ? |
|
| 142 | + $this->sql->real_escape_string($this->description) : |
|
| 143 | + $this->sql->real_escape_string($this->abstract) |
|
| 144 | + ); |
|
| 145 | + $_path = $this->sql->real_escape_string($this->path); |
|
| 146 | + |
|
| 147 | + $this->updateDb($this->table, $this->id, array('name' => $_name, 'path' => $_path, 'abstract' => $_abstract, 'description' => $_description), 'id'); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + private function parseManifestCSS($css) |
|
| 151 | + { |
|
| 152 | + if (!empty($css)) { |
|
| 153 | + $this->updateDb($this->css, $this->id, array('path' => realpath($this->path . '/' . $css))); |
|
| 154 | + } else { |
|
| 155 | + $this->clearDb($this->css, $this->id); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + private function parseManifestJavascript($javascript) |
|
| 160 | + { |
|
| 161 | + if (!empty($javascript)) { |
|
| 162 | + $this->updateDb($this->javascript, $this->id, array('path' => realpath($this->path) . '/' . $javascript)); |
|
| 163 | + } else { |
|
| 164 | + $this->clearDb($this->javascript, $this->id); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + private function parseManifestCanvasPages($pages) |
|
| 169 | + { |
|
| 170 | + $this->clearDb($this->pages, $this->id); |
|
| 171 | + if (!empty($pages->include)) { |
|
| 172 | + foreach ($pages->include->children() as $page) { |
|
| 173 | + if (!$this->sql->query(" |
|
| 174 | 174 | INSERT INTO `{$this->pages}` |
| 175 | 175 | ( |
| 176 | 176 | `canvashack`, |
@@ -184,16 +184,16 @@ discard block |
||
| 184 | 184 | TRUE |
| 185 | 185 | ) |
| 186 | 186 | ")) { |
| 187 | - throw new CanvasHack_Exception( |
|
| 188 | - "Could not insert included page entry for {$this->id}: " . $page->asXml() . PHP_EOL . $this->sql->error, |
|
| 189 | - CanvasHack_Exception::SQL |
|
| 190 | - ); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - if (!empty($pages->exclude)) { |
|
| 195 | - foreach ($pages->exclude->children() as $page) { |
|
| 196 | - if (!$this->sql->query(" |
|
| 187 | + throw new CanvasHack_Exception( |
|
| 188 | + "Could not insert included page entry for {$this->id}: " . $page->asXml() . PHP_EOL . $this->sql->error, |
|
| 189 | + CanvasHack_Exception::SQL |
|
| 190 | + ); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + if (!empty($pages->exclude)) { |
|
| 195 | + foreach ($pages->exclude->children() as $page) { |
|
| 196 | + if (!$this->sql->query(" |
|
| 197 | 197 | INSERT INTO `{$this->pages}` |
| 198 | 198 | ( |
| 199 | 199 | `canvashack`, |
@@ -207,22 +207,22 @@ discard block |
||
| 207 | 207 | FALSE |
| 208 | 208 | ) |
| 209 | 209 | ")) { |
| 210 | - // TODO wording could be improved |
|
| 211 | - throw new CanvasHack_Exception( |
|
| 212 | - "Could not insert included page entry for {$this->id}: " . $page->asXml() . PHP_EOL . $this->sql->error, |
|
| 213 | - CanvasHack_Exception::SQL |
|
| 214 | - ); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - private function parseManifestCanvasDOM($dom) |
|
| 221 | - { |
|
| 222 | - $this->clearDb($this->dom, $this->id); |
|
| 223 | - if (!empty($dom)) { |
|
| 224 | - foreach ($dom->children() as $bundle) { |
|
| 225 | - if (!$this->sql->query(" |
|
| 210 | + // TODO wording could be improved |
|
| 211 | + throw new CanvasHack_Exception( |
|
| 212 | + "Could not insert included page entry for {$this->id}: " . $page->asXml() . PHP_EOL . $this->sql->error, |
|
| 213 | + CanvasHack_Exception::SQL |
|
| 214 | + ); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + private function parseManifestCanvasDOM($dom) |
|
| 221 | + { |
|
| 222 | + $this->clearDb($this->dom, $this->id); |
|
| 223 | + if (!empty($dom)) { |
|
| 224 | + foreach ($dom->children() as $bundle) { |
|
| 225 | + if (!$this->sql->query(" |
|
| 226 | 226 | INSERT INTO `{$this->dom}` |
| 227 | 227 | ( |
| 228 | 228 | `canvashack`, |
@@ -236,111 +236,111 @@ discard block |
||
| 236 | 236 | '" . $this->sql->real_escape_string($bundle->action) . "' |
| 237 | 237 | ) |
| 238 | 238 | ")) { |
| 239 | - // TODO wording could be improved |
|
| 240 | - throw new CanvasHack_Exception( |
|
| 241 | - "Could not insert DOM entry for {$this->id}: " . $dom->asXml() . PHP_EOL . $this->sql->error, |
|
| 242 | - CanvasHack_Exception::SQL |
|
| 243 | - ); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - private function parseManifestCanvas($canvas) |
|
| 250 | - { |
|
| 251 | - $this->parseManifestCanvasPages($canvas->pages); |
|
| 252 | - $this->parseManifestCanvasDOM($canvas->dom); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - private function parseManifestComponents($components) |
|
| 256 | - { |
|
| 257 | - $this->parseManifestCSS($components->css); |
|
| 258 | - $this->parseManifestJavascript($components->javascript); |
|
| 259 | - $this->parseManifestCanvas($components->canvas); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - private function required($field, $value) |
|
| 263 | - { |
|
| 264 | - if (!empty($value)) { |
|
| 265 | - $this->$field = (string) $value; |
|
| 266 | - } else { |
|
| 267 | - throw new CanvasHack_Exception( |
|
| 268 | - "`$field` is required and was not found in the manifest", |
|
| 269 | - CanvasHack_Exception::REQUIRED |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - private function optional($field, $value) |
|
| 275 | - { |
|
| 276 | - if (isset($value)) { |
|
| 277 | - $this->$field = (string) $value; |
|
| 278 | - } else { |
|
| 279 | - $this->$field = null; |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - public function getId() |
|
| 284 | - { |
|
| 285 | - return $this->id; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - public function getName() |
|
| 289 | - { |
|
| 290 | - return $this->name; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - public function getAbstract() |
|
| 294 | - { |
|
| 295 | - if (empty($this->abstract)) { |
|
| 296 | - return $this->description; |
|
| 297 | - } else { |
|
| 298 | - return $this->abstract; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - public function getDescription() |
|
| 303 | - { |
|
| 304 | - if (empty($this->description)) { |
|
| 305 | - return $this->abstract; |
|
| 306 | - } else { |
|
| 307 | - return $this->description; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - public function isEnabled() |
|
| 312 | - { |
|
| 313 | - $result = $this->sql->query(" |
|
| 239 | + // TODO wording could be improved |
|
| 240 | + throw new CanvasHack_Exception( |
|
| 241 | + "Could not insert DOM entry for {$this->id}: " . $dom->asXml() . PHP_EOL . $this->sql->error, |
|
| 242 | + CanvasHack_Exception::SQL |
|
| 243 | + ); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + private function parseManifestCanvas($canvas) |
|
| 250 | + { |
|
| 251 | + $this->parseManifestCanvasPages($canvas->pages); |
|
| 252 | + $this->parseManifestCanvasDOM($canvas->dom); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + private function parseManifestComponents($components) |
|
| 256 | + { |
|
| 257 | + $this->parseManifestCSS($components->css); |
|
| 258 | + $this->parseManifestJavascript($components->javascript); |
|
| 259 | + $this->parseManifestCanvas($components->canvas); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + private function required($field, $value) |
|
| 263 | + { |
|
| 264 | + if (!empty($value)) { |
|
| 265 | + $this->$field = (string) $value; |
|
| 266 | + } else { |
|
| 267 | + throw new CanvasHack_Exception( |
|
| 268 | + "`$field` is required and was not found in the manifest", |
|
| 269 | + CanvasHack_Exception::REQUIRED |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + private function optional($field, $value) |
|
| 275 | + { |
|
| 276 | + if (isset($value)) { |
|
| 277 | + $this->$field = (string) $value; |
|
| 278 | + } else { |
|
| 279 | + $this->$field = null; |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + public function getId() |
|
| 284 | + { |
|
| 285 | + return $this->id; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + public function getName() |
|
| 289 | + { |
|
| 290 | + return $this->name; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + public function getAbstract() |
|
| 294 | + { |
|
| 295 | + if (empty($this->abstract)) { |
|
| 296 | + return $this->description; |
|
| 297 | + } else { |
|
| 298 | + return $this->abstract; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + public function getDescription() |
|
| 303 | + { |
|
| 304 | + if (empty($this->description)) { |
|
| 305 | + return $this->abstract; |
|
| 306 | + } else { |
|
| 307 | + return $this->description; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + public function isEnabled() |
|
| 312 | + { |
|
| 313 | + $result = $this->sql->query(" |
|
| 314 | 314 | SELECT * FROM `{$this->table}` WHERE `id` = '{$this->id}' |
| 315 | 315 | "); |
| 316 | - $row = $result->fetch_assoc(); |
|
| 317 | - return (isset($row['enabled']) && $row['enabled']); |
|
| 318 | - } |
|
| 316 | + $row = $result->fetch_assoc(); |
|
| 317 | + return (isset($row['enabled']) && $row['enabled']); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - public function enable() |
|
| 321 | - { |
|
| 322 | - $this->sql->query(" |
|
| 320 | + public function enable() |
|
| 321 | + { |
|
| 322 | + $this->sql->query(" |
|
| 323 | 323 | UPDATE `{$this->table}` SET `enabled` = '1' WHERE `id` = '{$this->id}' |
| 324 | 324 | "); |
| 325 | - } |
|
| 325 | + } |
|
| 326 | 326 | |
| 327 | - public function disable() |
|
| 328 | - { |
|
| 329 | - $this->sql->query(" |
|
| 327 | + public function disable() |
|
| 328 | + { |
|
| 329 | + $this->sql->query(" |
|
| 330 | 330 | UPDATE `{$this->table}` SET `enabled` = '0' WHERE `id` = '{$this->id}' |
| 331 | 331 | "); |
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * Helper function to insert/update into a SQL table |
|
| 336 | - * |
|
| 337 | - * @param string $table |
|
| 338 | - * @param string $id CanvasHack identifier |
|
| 339 | - * @param array $fields |
|
| 340 | - **/ |
|
| 341 | - private function updateDb($table, $id, $fields, $idKey = 'canvashack') |
|
| 342 | - { |
|
| 343 | - $response = $this->sql->query(" |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * Helper function to insert/update into a SQL table |
|
| 336 | + * |
|
| 337 | + * @param string $table |
|
| 338 | + * @param string $id CanvasHack identifier |
|
| 339 | + * @param array $fields |
|
| 340 | + **/ |
|
| 341 | + private function updateDb($table, $id, $fields, $idKey = 'canvashack') |
|
| 342 | + { |
|
| 343 | + $response = $this->sql->query(" |
|
| 344 | 344 | SELECT * |
| 345 | 345 | FROM `$table` |
| 346 | 346 | WHERE |
@@ -348,51 +348,51 @@ discard block |
||
| 348 | 348 | LIMIT 1 |
| 349 | 349 | "); |
| 350 | 350 | |
| 351 | - $params = array(); |
|
| 352 | - foreach ($fields as $field => $value) { |
|
| 353 | - $params[] = "`$field` = '$value'"; |
|
| 354 | - } |
|
| 351 | + $params = array(); |
|
| 352 | + foreach ($fields as $field => $value) { |
|
| 353 | + $params[] = "`$field` = '$value'"; |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - if ($response->num_rows > 0) { |
|
| 357 | - if (!$this->sql->query(" |
|
| 356 | + if ($response->num_rows > 0) { |
|
| 357 | + if (!$this->sql->query(" |
|
| 358 | 358 | UPDATE `$table` |
| 359 | 359 | SET " . |
| 360 | - implode(', ', $params) . |
|
| 361 | - "WHERE |
|
| 360 | + implode(', ', $params) . |
|
| 361 | + "WHERE |
|
| 362 | 362 | `$idKey` = '$id' |
| 363 | 363 | ")) { |
| 364 | - throw new CanvasHack_Exception( |
|
| 365 | - "Could not update `$table` with `$idKey` = '$id' and fields `$params'. " . $this->sql->error, |
|
| 366 | - CanvasHack_Exception::SQL |
|
| 367 | - ); |
|
| 368 | - } |
|
| 369 | - } else { |
|
| 370 | - $fields[$idKey] = $this->id; |
|
| 371 | - if (!$this->sql->query(" |
|
| 364 | + throw new CanvasHack_Exception( |
|
| 365 | + "Could not update `$table` with `$idKey` = '$id' and fields `$params'. " . $this->sql->error, |
|
| 366 | + CanvasHack_Exception::SQL |
|
| 367 | + ); |
|
| 368 | + } |
|
| 369 | + } else { |
|
| 370 | + $fields[$idKey] = $this->id; |
|
| 371 | + if (!$this->sql->query(" |
|
| 372 | 372 | INSERT INTO `$table` |
| 373 | 373 | (`" . implode('`, `', array_keys($fields)) . "`) |
| 374 | 374 | VALUES |
| 375 | 375 | ('" . implode("', '", $fields) . "') |
| 376 | 376 | ")) { |
| 377 | - throw new CanvasHack_Exception( |
|
| 378 | - "Could not insert a new row into `$table` with `$idkey` = '$id' and fields `$params'. " . $this->sql->error, |
|
| 379 | - CanvasHack_Exception::SQL |
|
| 380 | - ); |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - private function clearDb($table, $id, $idKey = 'canvashack') |
|
| 386 | - { |
|
| 387 | - if (!$this->sql->query(" |
|
| 377 | + throw new CanvasHack_Exception( |
|
| 378 | + "Could not insert a new row into `$table` with `$idkey` = '$id' and fields `$params'. " . $this->sql->error, |
|
| 379 | + CanvasHack_Exception::SQL |
|
| 380 | + ); |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + private function clearDb($table, $id, $idKey = 'canvashack') |
|
| 386 | + { |
|
| 387 | + if (!$this->sql->query(" |
|
| 388 | 388 | DELETE FROM `$table` |
| 389 | 389 | WHERE |
| 390 | 390 | `$idKey` = '$id' |
| 391 | 391 | ")) { |
| 392 | - throw new CanvasHack_Exception( |
|
| 393 | - "Could not clear `$table` of `$idKey` = '$id' entries. " . $this->sql->error, |
|
| 394 | - CanvasHack_Exception::SQL |
|
| 395 | - ); |
|
| 396 | - } |
|
| 397 | - } |
|
| 392 | + throw new CanvasHack_Exception( |
|
| 393 | + "Could not clear `$table` of `$idKey` = '$id' entries. " . $this->sql->error, |
|
| 394 | + CanvasHack_Exception::SQL |
|
| 395 | + ); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | 398 | } |
@@ -134,13 +134,11 @@ |
||
| 134 | 134 | $_name = $this->sql->real_escape_string($this->name); |
| 135 | 135 | $_abstract = ( |
| 136 | 136 | isset($this->abstract) ? |
| 137 | - $this->sql->real_escape_string($this->abstract) : |
|
| 138 | - $this->sql->real_escape_string($this->description) |
|
| 137 | + $this->sql->real_escape_string($this->abstract) : $this->sql->real_escape_string($this->description) |
|
| 139 | 138 | ); |
| 140 | 139 | $_description = ( |
| 141 | 140 | isset($this->description) ? |
| 142 | - $this->sql->real_escape_string($this->description) : |
|
| 143 | - $this->sql->real_escape_string($this->abstract) |
|
| 141 | + $this->sql->real_escape_string($this->description) : $this->sql->real_escape_string($this->abstract) |
|
| 144 | 142 | ); |
| 145 | 143 | $_path = $this->sql->real_escape_string($this->path); |
| 146 | 144 | |
@@ -9,8 +9,8 @@ |
||
| 9 | 9 | **/ |
| 10 | 10 | class CanvasHack_Exception extends \Exception |
| 11 | 11 | { |
| 12 | - const MANIFEST = 1; |
|
| 13 | - const SQL = 2; |
|
| 14 | - const REQUIRED = 3; |
|
| 15 | - const ID = 4; |
|
| 12 | + const MANIFEST = 1; |
|
| 13 | + const SQL = 2; |
|
| 14 | + const REQUIRED = 3; |
|
| 15 | + const ID = 4; |
|
| 16 | 16 | } |
@@ -13,62 +13,62 @@ |
||
| 13 | 13 | |
| 14 | 14 | /* store any requested actions for future handling */ |
| 15 | 15 | $action = (empty($_REQUEST['action']) ? |
| 16 | - ACTION_UNSPECIFIED : |
|
| 17 | - strtolower($_REQUEST['action']) |
|
| 16 | + ACTION_UNSPECIFIED : |
|
| 17 | + strtolower($_REQUEST['action']) |
|
| 18 | 18 | ); |
| 19 | 19 | |
| 20 | 20 | /* action requests only come from outside the LTI! */ |
| 21 | 21 | if ($action) { |
| 22 | - unset($_SESSION[ToolProvider::class]); |
|
| 22 | + unset($_SESSION[ToolProvider::class]); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /* authenticate LTI launch request, if present */ |
| 26 | 26 | if ($toolbox->lti_isLaunching()) { |
| 27 | - $toolbox->resetSession(); |
|
| 28 | - $toolbox->lti_authenticate(); |
|
| 29 | - exit; |
|
| 27 | + $toolbox->resetSession(); |
|
| 28 | + $toolbox->lti_authenticate(); |
|
| 29 | + exit; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /* if authenticated LTI launch, head off to app.php */ |
| 33 | 33 | if (!empty($_SESSION[ToolProvider::class]['canvas'])) { |
| 34 | - header("Location: control-panel.php"); |
|
| 35 | - exit; |
|
| 34 | + header("Location: control-panel.php"); |
|
| 35 | + exit; |
|
| 36 | 36 | |
| 37 | 37 | /* if not authenticated, default to showing credentials */ |
| 38 | 38 | } else { |
| 39 | - $action = (empty($action) ? |
|
| 40 | - ACTION_CONFIG : |
|
| 41 | - $action |
|
| 42 | - ); |
|
| 39 | + $action = (empty($action) ? |
|
| 40 | + ACTION_CONFIG : |
|
| 41 | + $action |
|
| 42 | + ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /* process any actions */ |
| 46 | 46 | switch ($action) { |
| 47 | - /* reset cached install data from config file */ |
|
| 48 | - case ACTION_INSTALL: |
|
| 49 | - $_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true); |
|
| 50 | - $toolbox =& $_SESSION['toolbox']; |
|
| 47 | + /* reset cached install data from config file */ |
|
| 48 | + case ACTION_INSTALL: |
|
| 49 | + $_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true); |
|
| 50 | + $toolbox =& $_SESSION['toolbox']; |
|
| 51 | 51 | |
| 52 | - /* test to see if we can connect to the API */ |
|
| 53 | - try { |
|
| 54 | - $toolbox->getAPI(); |
|
| 55 | - } catch (ConfigurationException $e) { |
|
| 56 | - /* if there isn't an API token in config.xml, are there OAuth credentials? */ |
|
| 57 | - if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) { |
|
| 58 | - $toolbox->interactiveGetAccessToken(); |
|
| 59 | - exit; |
|
| 60 | - } else { /* no (understandable) API credentials available -- doh! */ |
|
| 61 | - throw $e; |
|
| 62 | - } |
|
| 63 | - } |
|
| 52 | + /* test to see if we can connect to the API */ |
|
| 53 | + try { |
|
| 54 | + $toolbox->getAPI(); |
|
| 55 | + } catch (ConfigurationException $e) { |
|
| 56 | + /* if there isn't an API token in config.xml, are there OAuth credentials? */ |
|
| 57 | + if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) { |
|
| 58 | + $toolbox->interactiveGetAccessToken(); |
|
| 59 | + exit; |
|
| 60 | + } else { /* no (understandable) API credentials available -- doh! */ |
|
| 61 | + throw $e; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /* finish by opening consumers control panel */ |
|
| 66 | - header('Location: consumers.php'); |
|
| 67 | - exit; |
|
| 65 | + /* finish by opening consumers control panel */ |
|
| 66 | + header('Location: consumers.php'); |
|
| 67 | + exit; |
|
| 68 | 68 | |
| 69 | - /* show LTI configuration XML file */ |
|
| 70 | - case ACTION_CONFIG: |
|
| 71 | - header('Content-type: application/xml'); |
|
| 72 | - echo $toolbox->saveConfigurationXML(); |
|
| 73 | - exit; |
|
| 69 | + /* show LTI configuration XML file */ |
|
| 70 | + case ACTION_CONFIG: |
|
| 71 | + header('Content-type: application/xml'); |
|
| 72 | + echo $toolbox->saveConfigurationXML(); |
|
| 73 | + exit; |
|
| 74 | 74 | } |
@@ -13,8 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | /* store any requested actions for future handling */ |
| 15 | 15 | $action = (empty($_REQUEST['action']) ? |
| 16 | - ACTION_UNSPECIFIED : |
|
| 17 | - strtolower($_REQUEST['action']) |
|
| 16 | + ACTION_UNSPECIFIED : strtolower($_REQUEST['action']) |
|
| 18 | 17 | ); |
| 19 | 18 | |
| 20 | 19 | /* action requests only come from outside the LTI! */ |
@@ -37,8 +36,7 @@ discard block |
||
| 37 | 36 | /* if not authenticated, default to showing credentials */ |
| 38 | 37 | } else { |
| 39 | 38 | $action = (empty($action) ? |
| 40 | - ACTION_CONFIG : |
|
| 41 | - $action |
|
| 39 | + ACTION_CONFIG : $action |
|
| 42 | 40 | ); |
| 43 | 41 | } |
| 44 | 42 | |
@@ -47,7 +45,7 @@ discard block |
||
| 47 | 45 | /* reset cached install data from config file */ |
| 48 | 46 | case ACTION_INSTALL: |
| 49 | 47 | $_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true); |
| 50 | - $toolbox =& $_SESSION['toolbox']; |
|
| 48 | + $toolbox = & $_SESSION['toolbox']; |
|
| 51 | 49 | |
| 52 | 50 | /* test to see if we can connect to the API */ |
| 53 | 51 | try { |
@@ -8,79 +8,79 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Toolbox extends \smtech\StMarksReflexiveCanvasLTI\Toolbox |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * Custom Preferences database |
|
| 13 | - * @var mysqli |
|
| 14 | - */ |
|
| 15 | - protected $customPrefs; |
|
| 11 | + /** |
|
| 12 | + * Custom Preferences database |
|
| 13 | + * @var mysqli |
|
| 14 | + */ |
|
| 15 | + protected $customPrefs; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Configure account navigation placement |
|
| 19 | - * |
|
| 20 | - * @return Generator |
|
| 21 | - */ |
|
| 22 | - public function getGenerator() |
|
| 23 | - { |
|
| 24 | - parent::getGenerator(); |
|
| 17 | + /** |
|
| 18 | + * Configure account navigation placement |
|
| 19 | + * |
|
| 20 | + * @return Generator |
|
| 21 | + */ |
|
| 22 | + public function getGenerator() |
|
| 23 | + { |
|
| 24 | + parent::getGenerator(); |
|
| 25 | 25 | |
| 26 | - $this->generator->setOptionProperty( |
|
| 27 | - Option::ACCOUNT_NAVIGATION(), |
|
| 28 | - 'visibility', |
|
| 29 | - 'admins' |
|
| 30 | - ); |
|
| 26 | + $this->generator->setOptionProperty( |
|
| 27 | + Option::ACCOUNT_NAVIGATION(), |
|
| 28 | + 'visibility', |
|
| 29 | + 'admins' |
|
| 30 | + ); |
|
| 31 | 31 | |
| 32 | - return $this->generator; |
|
| 33 | - } |
|
| 32 | + return $this->generator; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Update a Toolbox instance from a configuration file |
|
| 37 | - * |
|
| 38 | - * @see Toolbox::fromConfiguration() Use `Toolbox::fromConfiguration()` |
|
| 39 | - * |
|
| 40 | - * @param string $configFilePath |
|
| 41 | - * @param boolean $forceRecache |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - protected function loadConfiguration($configFilePath, $forceRecache = false) |
|
| 45 | - { |
|
| 46 | - parent::loadConfiguration($configFilePath, $forceRecache); |
|
| 35 | + /** |
|
| 36 | + * Update a Toolbox instance from a configuration file |
|
| 37 | + * |
|
| 38 | + * @see Toolbox::fromConfiguration() Use `Toolbox::fromConfiguration()` |
|
| 39 | + * |
|
| 40 | + * @param string $configFilePath |
|
| 41 | + * @param boolean $forceRecache |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + protected function loadConfiguration($configFilePath, $forceRecache = false) |
|
| 45 | + { |
|
| 46 | + parent::loadConfiguration($configFilePath, $forceRecache); |
|
| 47 | 47 | |
| 48 | - $config = new ConfigXML($configFilePath); |
|
| 48 | + $config = new ConfigXML($configFilePath); |
|
| 49 | 49 | |
| 50 | - /* configure database connections */ |
|
| 51 | - $this->setCustomPrefs($config->newInstanceOf(mysqli::class, '/config/customprefs')); |
|
| 52 | - } |
|
| 50 | + /* configure database connections */ |
|
| 51 | + $this->setCustomPrefs($config->newInstanceOf(mysqli::class, '/config/customprefs')); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Set MySQL connection object |
|
| 56 | - * |
|
| 57 | - * @param mysqli $mysql |
|
| 58 | - */ |
|
| 59 | - public function setCustomPrefs(mysqli $mysql) |
|
| 60 | - { |
|
| 61 | - $this->customPrefs = $mysql; |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Set MySQL connection object |
|
| 56 | + * |
|
| 57 | + * @param mysqli $mysql |
|
| 58 | + */ |
|
| 59 | + public function setCustomPrefs(mysqli $mysql) |
|
| 60 | + { |
|
| 61 | + $this->customPrefs = $mysql; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Get MySQL connection object |
|
| 66 | - * |
|
| 67 | - * @return mysqli |
|
| 68 | - */ |
|
| 69 | - public function getCustomPrefs() |
|
| 70 | - { |
|
| 71 | - return $this->customPrefs; |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * Get MySQL connection object |
|
| 66 | + * |
|
| 67 | + * @return mysqli |
|
| 68 | + */ |
|
| 69 | + public function getCustomPrefs() |
|
| 70 | + { |
|
| 71 | + return $this->customPrefs; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Make a MySQL query |
|
| 76 | - * |
|
| 77 | - * @link http://php.net/manual/en/mysqli.query.php Pass-through to `mysqli::query()` |
|
| 78 | - * @param string $query |
|
| 79 | - * @param int $resultMode (Optional, defaults to `MYSQLI_STORE_RESULT`) |
|
| 80 | - * @return mixed |
|
| 81 | - */ |
|
| 82 | - public function customPrefs_query($query, $resultMode = MYSQLI_STORE_RESULT) |
|
| 83 | - { |
|
| 84 | - return $this->getCustomPrefs()->query($query, $resultMode); |
|
| 85 | - } |
|
| 74 | + /** |
|
| 75 | + * Make a MySQL query |
|
| 76 | + * |
|
| 77 | + * @link http://php.net/manual/en/mysqli.query.php Pass-through to `mysqli::query()` |
|
| 78 | + * @param string $query |
|
| 79 | + * @param int $resultMode (Optional, defaults to `MYSQLI_STORE_RESULT`) |
|
| 80 | + * @return mixed |
|
| 81 | + */ |
|
| 82 | + public function customPrefs_query($query, $resultMode = MYSQLI_STORE_RESULT) |
|
| 83 | + { |
|
| 84 | + return $this->getCustomPrefs()->query($query, $resultMode); |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -17,16 +17,16 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | function canonicalNamespaceId($id) |
| 19 | 19 | { |
| 20 | - return preg_replace('/[^a-z0-9]+/i', '_', $id); |
|
| 20 | + return preg_replace('/[^a-z0-9]+/i', '_', $id); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | function canvasHackNamespace($id, $javascript) |
| 24 | 24 | { |
| 25 | - return preg_replace( |
|
| 26 | - '/^(\s*var\s+)?canvashack\s*=\s*{\n*(.*)};/is', |
|
| 27 | - canonicalNamespaceId($id) . ": {\n$2\n}", |
|
| 28 | - $javascript |
|
| 29 | - ); |
|
| 25 | + return preg_replace( |
|
| 26 | + '/^(\s*var\s+)?canvashack\s*=\s*{\n*(.*)};/is', |
|
| 27 | + canonicalNamespaceId($id) . ": {\n$2\n}", |
|
| 28 | + $javascript |
|
| 29 | + ); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $canvashacks = array(); |
@@ -42,14 +42,14 @@ discard block |
||
| 42 | 42 | "); |
| 43 | 43 | |
| 44 | 44 | 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 | - } |
|
| 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 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $css = array(); |
@@ -59,15 +59,15 @@ discard block |
||
| 59 | 59 | WHERE |
| 60 | 60 | `canvashack` = '" . implode("' OR `canvashack` = '", array_keys($canvashacks)) . "' |
| 61 | 61 | ")) == false) { |
| 62 | - exit; |
|
| 62 | + exit; |
|
| 63 | 63 | } |
| 64 | 64 | while ($entry = $applicableCSS->fetch_assoc()) { |
| 65 | - $css[$entry['canvashack']] = shell_exec("php \"{$entry['path']}\" \"{$location}\" 2>&1"); |
|
| 65 | + $css[$entry['canvashack']] = shell_exec("php \"{$entry['path']}\" \"{$location}\" 2>&1"); |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 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"; |
|
| 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 | 73 | } |
@@ -7,40 +7,40 @@ |
||
| 7 | 7 | use Battis\BootstrapSmarty\NotificationMessage; |
| 8 | 8 | |
| 9 | 9 | if (isset($_REQUEST['hack'])) { |
| 10 | - while (list($id, $setting) = each($_REQUEST['hack'])) { |
|
| 11 | - try { |
|
| 12 | - $hack = CanvasHack::getCanvasHackById($toolbox->getMySQL(), $id); |
|
| 13 | - if ($setting === 'enable') { |
|
| 14 | - $hack->enable(); |
|
| 15 | - } else { |
|
| 16 | - $hack->disable(); |
|
| 17 | - } |
|
| 18 | - } catch (CanvasHack_Exception $e) { |
|
| 19 | - $smarty->addMessage('Exception ' . $e->getCode(), $e->getMessage(), NotificationMessage::ERROR); |
|
| 20 | - } |
|
| 21 | - } |
|
| 10 | + while (list($id, $setting) = each($_REQUEST['hack'])) { |
|
| 11 | + try { |
|
| 12 | + $hack = CanvasHack::getCanvasHackById($toolbox->getMySQL(), $id); |
|
| 13 | + if ($setting === 'enable') { |
|
| 14 | + $hack->enable(); |
|
| 15 | + } else { |
|
| 16 | + $hack->disable(); |
|
| 17 | + } |
|
| 18 | + } catch (CanvasHack_Exception $e) { |
|
| 19 | + $smarty->addMessage('Exception ' . $e->getCode(), $e->getMessage(), NotificationMessage::ERROR); |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | $hacksContents = scandir(realpath(__DIR__ . '/hacks'), SCANDIR_SORT_ASCENDING); |
| 25 | 25 | $hacks = array(); |
| 26 | 26 | foreach ($hacksContents as $item) { |
| 27 | - if (is_dir($path = realpath(__DIR__ . "/hacks/$item")) && file_exists($manifest = "$path/manifest.xml")) { |
|
| 28 | - try { |
|
| 29 | - $hacks[$item] = new CanvasHack($toolbox->getMySQL(), $path); |
|
| 30 | - } catch (CanvasHack_Exception $e) { |
|
| 31 | - $smarty->addMessage( |
|
| 32 | - 'CanvasHack Manifest Error [' . $e->getCode() . ']', |
|
| 33 | - $e->getMessage(), |
|
| 34 | - NotificationMessage::ERROR |
|
| 35 | - ); |
|
| 36 | - } |
|
| 37 | - } |
|
| 27 | + if (is_dir($path = realpath(__DIR__ . "/hacks/$item")) && file_exists($manifest = "$path/manifest.xml")) { |
|
| 28 | + try { |
|
| 29 | + $hacks[$item] = new CanvasHack($toolbox->getMySQL(), $path); |
|
| 30 | + } catch (CanvasHack_Exception $e) { |
|
| 31 | + $smarty->addMessage( |
|
| 32 | + 'CanvasHack Manifest Error [' . $e->getCode() . ']', |
|
| 33 | + $e->getMessage(), |
|
| 34 | + NotificationMessage::ERROR |
|
| 35 | + ); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $smarty->assign([ |
| 41 | - 'appURL' => $toolbox->config('APP_URL'), |
|
| 42 | - 'hacks' => $hacks, |
|
| 43 | - 'name' => 'CanvasHack', |
|
| 44 | - 'category' => 'Control Panel' |
|
| 41 | + 'appURL' => $toolbox->config('APP_URL'), |
|
| 42 | + 'hacks' => $hacks, |
|
| 43 | + 'name' => 'CanvasHack', |
|
| 44 | + 'category' => 'Control Panel' |
|
| 45 | 45 | ]); |
| 46 | 46 | $smarty->display('control-panel.tpl'); |
@@ -5,5 +5,5 @@ |
||
| 5 | 5 | require_once __DIR__ . '/../common.inc.php'; |
| 6 | 6 | |
| 7 | 7 | if (empty($_REQUEST) && !empty($argv[1])) { |
| 8 | - $_REQUEST = unserialize($argv[1]); |
|
| 8 | + $_REQUEST = unserialize($argv[1]); |
|
| 9 | 9 | } |