| @@ -8,170 +8,170 @@ discard block | ||
| 8 | 8 | **/ | 
| 9 | 9 |  class UserAPIToken { | 
| 10 | 10 | |
| 11 | - const USER_TOKENS_TABLE = 'user_tokens'; | |
| 11 | + const USER_TOKENS_TABLE = 'user_tokens'; | |
| 12 | 12 | |
| 13 | - /** | |
| 14 | - * @var string $consumerKey The unique ID of the tool consumer from whence the user is making requests to the LTI | |
| 15 | - **/ | |
| 16 | - private $consumerKey; | |
| 13 | + /** | |
| 14 | + * @var string $consumerKey The unique ID of the tool consumer from whence the user is making requests to the LTI | |
| 15 | + **/ | |
| 16 | + private $consumerKey; | |
| 17 | 17 | |
| 18 | - /** | |
| 19 | - * @var string $id The unique ID (within the context of a particular Tool Consumer) of a particular user | |
| 20 | - **/ | |
| 21 | - private $id; | |
| 18 | + /** | |
| 19 | + * @var string $id The unique ID (within the context of a particular Tool Consumer) of a particular user | |
| 20 | + **/ | |
| 21 | + private $id; | |
| 22 | 22 | |
| 23 | - /** | |
| 24 | - * @var mysqli $sql A MySQL connection | |
| 25 | - **/ | |
| 26 | - private $sql; | |
| 23 | + /** | |
| 24 | + * @var mysqli $sql A MySQL connection | |
| 25 | + **/ | |
| 26 | + private $sql; | |
| 27 | 27 | |
| 28 | - /** | |
| 29 | - * @var string|null $token This user's API access token (if acquired) or NULL if not yet acquired | |
| 30 | - **/ | |
| 31 | - private $token = null; | |
| 28 | + /** | |
| 29 | + * @var string|null $token This user's API access token (if acquired) or NULL if not yet acquired | |
| 30 | + **/ | |
| 31 | + private $token = null; | |
| 32 | 32 | |
| 33 | - /** | |
| 34 | - * @var string|null $apiUrl The URL of the API for which this user's token is valid, NULL if no token | |
| 35 | - **/ | |
| 36 | - private $apiUrl = null; | |
| 33 | + /** | |
| 34 | + * @var string|null $apiUrl The URL of the API for which this user's token is valid, NULL if no token | |
| 35 | + **/ | |
| 36 | + private $apiUrl = null; | |
| 37 | 37 | |
| 38 | - /** | |
| 39 | - * Create a new UserAPIToken to either register a new user in the | |
| 40 | - * USER_TOKENS_TABLE or look up an existing user. | |
| 41 | - * | |
| 42 | - * @param string $consumerKey The unique ID of the Tool Consumer from whence the user is making requests to the LTI | |
| 43 | - * @param string $userId The unique ID of the user within that Tool Consumer | |
| 44 | - * @param mysqli $mysqli An active MySQL database connection to update USER_TOKEN_TABLE | |
| 45 | - * | |
| 46 | - * @throws UserAPIToken_Exception CONSUMER_KEY_REQUIRED If no consumer key is provided | |
| 47 | - * @throws UserAPIToken_Exception USER_ID_REQUIRED If no user ID is provided | |
| 48 | - * @throws UserAPIToken_Exception MYSQLI_REQUIRED If no MySQL database connection is provided | |
| 49 | - * @throws UserAPIToken_Excpetion MYSQLI_ERROR If the user cannot be found or inserted in USER_TOKEN_TABLE | |
| 50 | - **/ | |
| 51 | -	public function __construct($consumerKey, $userId, $mysqli) { | |
| 38 | + /** | |
| 39 | + * Create a new UserAPIToken to either register a new user in the | |
| 40 | + * USER_TOKENS_TABLE or look up an existing user. | |
| 41 | + * | |
| 42 | + * @param string $consumerKey The unique ID of the Tool Consumer from whence the user is making requests to the LTI | |
| 43 | + * @param string $userId The unique ID of the user within that Tool Consumer | |
| 44 | + * @param mysqli $mysqli An active MySQL database connection to update USER_TOKEN_TABLE | |
| 45 | + * | |
| 46 | + * @throws UserAPIToken_Exception CONSUMER_KEY_REQUIRED If no consumer key is provided | |
| 47 | + * @throws UserAPIToken_Exception USER_ID_REQUIRED If no user ID is provided | |
| 48 | + * @throws UserAPIToken_Exception MYSQLI_REQUIRED If no MySQL database connection is provided | |
| 49 | + * @throws UserAPIToken_Excpetion MYSQLI_ERROR If the user cannot be found or inserted in USER_TOKEN_TABLE | |
| 50 | + **/ | |
| 51 | +    public function __construct($consumerKey, $userId, $mysqli) { | |
| 52 | 52 | |
| 53 | -		if (empty((string) $consumerKey)) { | |
| 54 | - throw new UserAPIToken_Exception( | |
| 55 | - 'A consumer key is required', | |
| 56 | - UserAPIToken_Exception::CONSUMER_KEY_REQUIRED | |
| 57 | - ); | |
| 58 | - } | |
| 53 | +        if (empty((string) $consumerKey)) { | |
| 54 | + throw new UserAPIToken_Exception( | |
| 55 | + 'A consumer key is required', | |
| 56 | + UserAPIToken_Exception::CONSUMER_KEY_REQUIRED | |
| 57 | + ); | |
| 58 | + } | |
| 59 | 59 | |
| 60 | -		if (empty((string) $userId)) { | |
| 61 | - throw new UserAPIToken_Exception( | |
| 62 | - 'A user ID is required', | |
| 63 | - UserAPIToken_Exception::USER_ID_REQUIRED | |
| 64 | - ); | |
| 65 | - } | |
| 60 | +        if (empty((string) $userId)) { | |
| 61 | + throw new UserAPIToken_Exception( | |
| 62 | + 'A user ID is required', | |
| 63 | + UserAPIToken_Exception::USER_ID_REQUIRED | |
| 64 | + ); | |
| 65 | + } | |
| 66 | 66 | |
| 67 | -		if (!($mysqli instanceof mysqli)) { | |
| 68 | - throw new UserAPIToken_Exception( | |
| 69 | - 'A valid mysqli object is required', | |
| 70 | - UserAPIToken_Exception::MYSQLI_REQUIRED | |
| 71 | - ); | |
| 72 | - } | |
| 67 | +        if (!($mysqli instanceof mysqli)) { | |
| 68 | + throw new UserAPIToken_Exception( | |
| 69 | + 'A valid mysqli object is required', | |
| 70 | + UserAPIToken_Exception::MYSQLI_REQUIRED | |
| 71 | + ); | |
| 72 | + } | |
| 73 | 73 | |
| 74 | - $this->sql = $mysqli; | |
| 75 | - $this->consumerKey = $this->sql->real_escape_string($consumerKey); | |
| 76 | - $this->id = $this->sql->real_escape_string($userId); | |
| 74 | + $this->sql = $mysqli; | |
| 75 | + $this->consumerKey = $this->sql->real_escape_string($consumerKey); | |
| 76 | + $this->id = $this->sql->real_escape_string($userId); | |
| 77 | 77 | |
| 78 | -		$result = $this->sql->query("SELECT * FROM `" . self::USER_TOKENS_TABLE . "` WHERE `consumer_key` = '{$this->consumerKey}' AND `id` = '{$this->id}'"); | |
| 79 | - $row = $result->fetch_assoc(); | |
| 80 | -		if ($row) { | |
| 81 | - $this->token = $row['token']; | |
| 82 | - $this->apiUrl = $row['api_url']; | |
| 83 | -		} else { | |
| 84 | -			if (!$this->sql->query("INSERT INTO `" . self::USER_TOKENS_TABLE . "` (`consumer_key`, `id`) VALUES ('{$this->consumerKey}', '{$this->id}')")) { | |
| 85 | - throw new UserAPIToken_Exception( | |
| 86 | -					"Error inserting a new user: {$this->sql->error}", | |
| 87 | - UserAPIToken_Exception::MYSQLI_ERROR | |
| 88 | - ); | |
| 89 | - } | |
| 90 | - } | |
| 91 | - } | |
| 78 | +        $result = $this->sql->query("SELECT * FROM `" . self::USER_TOKENS_TABLE . "` WHERE `consumer_key` = '{$this->consumerKey}' AND `id` = '{$this->id}'"); | |
| 79 | + $row = $result->fetch_assoc(); | |
| 80 | +        if ($row) { | |
| 81 | + $this->token = $row['token']; | |
| 82 | + $this->apiUrl = $row['api_url']; | |
| 83 | +        } else { | |
| 84 | +            if (!$this->sql->query("INSERT INTO `" . self::USER_TOKENS_TABLE . "` (`consumer_key`, `id`) VALUES ('{$this->consumerKey}', '{$this->id}')")) { | |
| 85 | + throw new UserAPIToken_Exception( | |
| 86 | +                    "Error inserting a new user: {$this->sql->error}", | |
| 87 | + UserAPIToken_Exception::MYSQLI_ERROR | |
| 88 | + ); | |
| 89 | + } | |
| 90 | + } | |
| 91 | + } | |
| 92 | 92 | |
| 93 | - /** | |
| 94 | - * @return string|boolean The API access token for this user, or FALSE if no token has been acquired | |
| 95 | - **/ | |
| 96 | -	public function getToken() { | |
| 97 | -		if ($this->token) { | |
| 98 | - return $this->token; | |
| 99 | - } | |
| 100 | - return false; | |
| 101 | - } | |
| 93 | + /** | |
| 94 | + * @return string|boolean The API access token for this user, or FALSE if no token has been acquired | |
| 95 | + **/ | |
| 96 | +    public function getToken() { | |
| 97 | +        if ($this->token) { | |
| 98 | + return $this->token; | |
| 99 | + } | |
| 100 | + return false; | |
| 101 | + } | |
| 102 | 102 | |
| 103 | - /** | |
| 104 | - * Stores a new API Token into USER_TOKEN_TABLE for this user | |
| 105 | - * | |
| 106 | - * @param string $token A new API access token for this user | |
| 107 | - * | |
| 108 | - * @return boolean Returns TRUE if the token is successfully stored in USER_TOKEN_TABLE, FALSE otherwise | |
| 109 | - * | |
| 110 | - * @throws UserAPIToken_Exception TOKEN_REQUIRED If no token is provided | |
| 111 | - **/ | |
| 112 | -	public function setToken($token) { | |
| 113 | -		if (empty($token)) { | |
| 114 | - throw new UserAPIToken_Exception( | |
| 115 | - 'A token is required', | |
| 116 | - UserAPIToken_Exception::TOKEN_REQUIRED | |
| 117 | - ); | |
| 118 | - } | |
| 119 | -		if($this->consumerKey && $this->id && $this->sql) { | |
| 120 | - $_token = $this->sql->real_escape_string($token); | |
| 121 | -			if (!$this->sql->query("UPDATE `" . self::USER_TOKENS_TABLE . "` set `token` = '$_token' WHERE `consumer_key` = '{$this->consumerKey}' AND `id` = '{$this->id}'")) { | |
| 122 | - throw new UserAPIToken_Exception( | |
| 123 | -					"Error updating token: {$this->sql->error}", | |
| 124 | - UserAPIToken_Exception::MYSQLI_ERROR | |
| 125 | - ); | |
| 126 | - } | |
| 127 | - $this->token = $token; | |
| 103 | + /** | |
| 104 | + * Stores a new API Token into USER_TOKEN_TABLE for this user | |
| 105 | + * | |
| 106 | + * @param string $token A new API access token for this user | |
| 107 | + * | |
| 108 | + * @return boolean Returns TRUE if the token is successfully stored in USER_TOKEN_TABLE, FALSE otherwise | |
| 109 | + * | |
| 110 | + * @throws UserAPIToken_Exception TOKEN_REQUIRED If no token is provided | |
| 111 | + **/ | |
| 112 | +    public function setToken($token) { | |
| 113 | +        if (empty($token)) { | |
| 114 | + throw new UserAPIToken_Exception( | |
| 115 | + 'A token is required', | |
| 116 | + UserAPIToken_Exception::TOKEN_REQUIRED | |
| 117 | + ); | |
| 118 | + } | |
| 119 | +        if($this->consumerKey && $this->id && $this->sql) { | |
| 120 | + $_token = $this->sql->real_escape_string($token); | |
| 121 | +            if (!$this->sql->query("UPDATE `" . self::USER_TOKENS_TABLE . "` set `token` = '$_token' WHERE `consumer_key` = '{$this->consumerKey}' AND `id` = '{$this->id}'")) { | |
| 122 | + throw new UserAPIToken_Exception( | |
| 123 | +                    "Error updating token: {$this->sql->error}", | |
| 124 | + UserAPIToken_Exception::MYSQLI_ERROR | |
| 125 | + ); | |
| 126 | + } | |
| 127 | + $this->token = $token; | |
| 128 | 128 | |
| 129 | - return true; | |
| 130 | - } | |
| 129 | + return true; | |
| 130 | + } | |
| 131 | 131 | |
| 132 | - return false; | |
| 133 | - } | |
| 132 | + return false; | |
| 133 | + } | |
| 134 | 134 | |
| 135 | - /** | |
| 136 | - * @return string|boolean The URL of the API for which the user's API token is valid, or FALSE if no token has been acquired | |
| 137 | - **/ | |
| 138 | -	function getAPIUrl() { | |
| 139 | -		if ($this->apiUrl) { | |
| 140 | - return $this->apiUrl; | |
| 141 | - } | |
| 142 | - return false; | |
| 143 | - } | |
| 135 | + /** | |
| 136 | + * @return string|boolean The URL of the API for which the user's API token is valid, or FALSE if no token has been acquired | |
| 137 | + **/ | |
| 138 | +    function getAPIUrl() { | |
| 139 | +        if ($this->apiUrl) { | |
| 140 | + return $this->apiUrl; | |
| 141 | + } | |
| 142 | + return false; | |
| 143 | + } | |
| 144 | 144 | |
| 145 | - /** | |
| 146 | - * Stores a new URL for the API URL for which the user's API access token is valid in USER_TOKEN_TABLE | |
| 147 | - * | |
| 148 | - * @param string $apiUrl The URL of the API | |
| 149 | - * | |
| 150 | - * @return boolean TRUE if the URL of the API is stored in USER_TOKEN_TABLE, FALSE otherwise | |
| 151 | - * | |
| 152 | - * @throws UserAPITokenException API_URL_REQUIRED If no URL is provided | |
| 153 | - **/ | |
| 154 | -	public function setAPIUrl($apiUrl) { | |
| 155 | -		if (empty($apiUrl)) { | |
| 156 | - throw new UserAPIToken_Exception( | |
| 157 | - 'API URL is required', | |
| 158 | - UserAPIToken_Exception::API_URL_REQUIRED | |
| 159 | - ); | |
| 160 | - } | |
| 145 | + /** | |
| 146 | + * Stores a new URL for the API URL for which the user's API access token is valid in USER_TOKEN_TABLE | |
| 147 | + * | |
| 148 | + * @param string $apiUrl The URL of the API | |
| 149 | + * | |
| 150 | + * @return boolean TRUE if the URL of the API is stored in USER_TOKEN_TABLE, FALSE otherwise | |
| 151 | + * | |
| 152 | + * @throws UserAPITokenException API_URL_REQUIRED If no URL is provided | |
| 153 | + **/ | |
| 154 | +    public function setAPIUrl($apiUrl) { | |
| 155 | +        if (empty($apiUrl)) { | |
| 156 | + throw new UserAPIToken_Exception( | |
| 157 | + 'API URL is required', | |
| 158 | + UserAPIToken_Exception::API_URL_REQUIRED | |
| 159 | + ); | |
| 160 | + } | |
| 161 | 161 | |
| 162 | -		if ($this->consumerKey && $this->id && $this->sql) { | |
| 163 | - $_apiUrl = $this->sql->real_escape_string($apiUrl); | |
| 164 | -			if (!$this->sql->query("UPDATE `" . self::USER_TOKENS_TABLE . "` set `api_url` = '$_apiUrl' WHERE `consumer_key` = '{$this->consumerKey}' AND `id` = '{$this->id}'")) { | |
| 165 | - throw new UserAPIToken_Exception( | |
| 166 | -					"Error updating API URL for user token: {$this->sql->error}", | |
| 167 | - UserAPIToken_Exception::MYSQLI_ERROR | |
| 168 | - ); | |
| 169 | - } | |
| 170 | - $this->apiUrl = $apiUrl; | |
| 171 | - return true; | |
| 172 | - } | |
| 173 | - return false; | |
| 174 | - } | |
| 162 | +        if ($this->consumerKey && $this->id && $this->sql) { | |
| 163 | + $_apiUrl = $this->sql->real_escape_string($apiUrl); | |
| 164 | +            if (!$this->sql->query("UPDATE `" . self::USER_TOKENS_TABLE . "` set `api_url` = '$_apiUrl' WHERE `consumer_key` = '{$this->consumerKey}' AND `id` = '{$this->id}'")) { | |
| 165 | + throw new UserAPIToken_Exception( | |
| 166 | +                    "Error updating API URL for user token: {$this->sql->error}", | |
| 167 | + UserAPIToken_Exception::MYSQLI_ERROR | |
| 168 | + ); | |
| 169 | + } | |
| 170 | + $this->apiUrl = $apiUrl; | |
| 171 | + return true; | |
| 172 | + } | |
| 173 | + return false; | |
| 174 | + } | |
| 175 | 175 | } | 
| 176 | 176 | |
| 177 | 177 | /** | 
| @@ -180,12 +180,12 @@ discard block | ||
| 180 | 180 | * @author Seth Battis <[email protected]> | 
| 181 | 181 | **/ | 
| 182 | 182 |  class UserAPIToken_Exception extends CanvasAPIviaLTI_Exception { | 
| 183 | - const CONSUMER_KEY_REQUIRED = 1; | |
| 184 | - const USER_ID_REQUIRED = 2; | |
| 185 | - const MYSQLI_REQUIRED = 3; | |
| 186 | - const MYSQLI_ERROR = 4; | |
| 187 | - const TOKEN_REQUIRED = 5; | |
| 188 | - const API_URL_REQUIRED = 6; | |
| 183 | + const CONSUMER_KEY_REQUIRED = 1; | |
| 184 | + const USER_ID_REQUIRED = 2; | |
| 185 | + const MYSQLI_REQUIRED = 3; | |
| 186 | + const MYSQLI_ERROR = 4; | |
| 187 | + const TOKEN_REQUIRED = 5; | |
| 188 | + const API_URL_REQUIRED = 6; | |
| 189 | 189 | } | 
| 190 | 190 | |
| 191 | 191 | ?> | 
| 192 | 192 | \ No newline at end of file | 
| @@ -116,7 +116,7 @@ | ||
| 116 | 116 | UserAPIToken_Exception::TOKEN_REQUIRED | 
| 117 | 117 | ); | 
| 118 | 118 | } | 
| 119 | -		if($this->consumerKey && $this->id && $this->sql) { | |
| 119 | +		if ($this->consumerKey && $this->id && $this->sql) { | |
| 120 | 120 | $_token = $this->sql->real_escape_string($token); | 
| 121 | 121 |  			if (!$this->sql->query("UPDATE `" . self::USER_TOKENS_TABLE . "` set `token` = '$_token' WHERE `consumer_key` = '{$this->consumerKey}' AND `id` = '{$this->id}'")) { | 
| 122 | 122 | throw new UserAPIToken_Exception( | 
| @@ -7,98 +7,98 @@ discard block | ||
| 7 | 7 | **/ | 
| 8 | 8 |  class CanvasAPIviaLTI extends LTI_Tool_Provider { | 
| 9 | 9 | |
| 10 | - /** | |
| 11 | - * Handle launch requests, which start the application running | |
| 12 | - **/ | |
| 13 | -	public function onLaunch() { | |
| 14 | - global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 15 | - global $sql; // FIXME:0 grown-ups don't program like this issue:17 | |
| 10 | + /** | |
| 11 | + * Handle launch requests, which start the application running | |
| 12 | + **/ | |
| 13 | +    public function onLaunch() { | |
| 14 | + global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 15 | + global $sql; // FIXME:0 grown-ups don't program like this issue:17 | |
| 16 | 16 | |
| 17 | - /* is this user in a role that can use this app? */ | |
| 18 | -		if ($this->user->isAdmin()) { | |
| 17 | + /* is this user in a role that can use this app? */ | |
| 18 | +        if ($this->user->isAdmin()) { | |
| 19 | 19 | |
| 20 | - /* set up any needed session variables */ | |
| 21 | - $_SESSION['consumer_key'] = $this->consumer->getKey(); | |
| 22 | - $_SESSION['resource_id'] = $this->resource_link->getId(); | |
| 23 | - $_SESSION['user_consumer_key'] = $this->user->getResourceLink()->getConsumer()->getKey(); | |
| 24 | - $_SESSION['user_id'] = $this->user->getId(); | |
| 25 | - $_SESSION['isStudent'] = $this->user->isLearner(); | |
| 26 | - $_SESSION['isContentItem'] = FALSE; | |
| 20 | + /* set up any needed session variables */ | |
| 21 | + $_SESSION['consumer_key'] = $this->consumer->getKey(); | |
| 22 | + $_SESSION['resource_id'] = $this->resource_link->getId(); | |
| 23 | + $_SESSION['user_consumer_key'] = $this->user->getResourceLink()->getConsumer()->getKey(); | |
| 24 | + $_SESSION['user_id'] = $this->user->getId(); | |
| 25 | + $_SESSION['isStudent'] = $this->user->isLearner(); | |
| 26 | + $_SESSION['isContentItem'] = FALSE; | |
| 27 | 27 | |
| 28 | - /* do we have an admin API access token? */ | |
| 29 | - $haveToken = true; | |
| 30 | -			if (empty($metadata['CANVAS_API_TOKEN'])) { | |
| 28 | + /* do we have an admin API access token? */ | |
| 29 | + $haveToken = true; | |
| 30 | +            if (empty($metadata['CANVAS_API_TOKEN'])) { | |
| 31 | 31 | |
| 32 | - /* ...if not, do we have a user API access token for this user? */ | |
| 33 | - $userToken = new UserAPIToken($_SESSION['user_consumer_key'], $_SESSION['user_id'], $sql); | |
| 34 | -				if (empty($userToken->getToken())) { | |
| 32 | + /* ...if not, do we have a user API access token for this user? */ | |
| 33 | + $userToken = new UserAPIToken($_SESSION['user_consumer_key'], $_SESSION['user_id'], $sql); | |
| 34 | +                if (empty($userToken->getToken())) { | |
| 35 | 35 | |
| 36 | - /* ...if this user has no token, let's start by getting one */ | |
| 37 | - $haveToken = false; | |
| 38 | -					$this->redirectURL = "{$metadata['APP_URL']}/lti/token_request.php?oauth=request"; | |
| 39 | -				} else { | |
| 36 | + /* ...if this user has no token, let's start by getting one */ | |
| 37 | + $haveToken = false; | |
| 38 | +                    $this->redirectURL = "{$metadata['APP_URL']}/lti/token_request.php?oauth=request"; | |
| 39 | +                } else { | |
| 40 | 40 | |
| 41 | - /* ...but if the user does have a token, rock on! */ | |
| 42 | - $_SESSION['isUserToken'] = true; | |
| 43 | - $_SESSION['apiToken'] = $userToken->getToken(); | |
| 44 | - //$_SESSION['apiUrl'] = $userToken->getAPIUrl(); | |
| 45 | - } | |
| 46 | -			} else { | |
| 41 | + /* ...but if the user does have a token, rock on! */ | |
| 42 | + $_SESSION['isUserToken'] = true; | |
| 43 | + $_SESSION['apiToken'] = $userToken->getToken(); | |
| 44 | + //$_SESSION['apiUrl'] = $userToken->getAPIUrl(); | |
| 45 | + } | |
| 46 | +            } else { | |
| 47 | 47 | |
| 48 | - /* ...if we have an admin API token, rock on! */ | |
| 49 | - $_SESSION['isUserToken'] = false; | |
| 50 | - $_SESSION['apiToken'] = $metadata['CANVAS_API_TOKEN']; | |
| 51 | - //$_SESSION['apiUrl'] = $metadata['CANVAS_API_URL']; | |
| 52 | - } | |
| 53 | - $_SESSION['apiUrl'] = 'https://' . $this->user->getResourceLink()->settings['custom_canvas_api_domain'] . '/api/v1'; | |
| 48 | + /* ...if we have an admin API token, rock on! */ | |
| 49 | + $_SESSION['isUserToken'] = false; | |
| 50 | + $_SESSION['apiToken'] = $metadata['CANVAS_API_TOKEN']; | |
| 51 | + //$_SESSION['apiUrl'] = $metadata['CANVAS_API_URL']; | |
| 52 | + } | |
| 53 | + $_SESSION['apiUrl'] = 'https://' . $this->user->getResourceLink()->settings['custom_canvas_api_domain'] . '/api/v1'; | |
| 54 | 54 | |
| 55 | - /* pass control off to the app */ | |
| 56 | -	        if ($haveToken) { | |
| 57 | -		        $this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=launch"; | |
| 58 | - } | |
| 55 | + /* pass control off to the app */ | |
| 56 | +            if ($haveToken) { | |
| 57 | +                $this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=launch"; | |
| 58 | + } | |
| 59 | 59 | |
| 60 | - /* ...otherwise set an appropriate error message and fail */ | |
| 61 | -		} else { | |
| 62 | - $this->reason = 'Invalid role'; | |
| 63 | - $this->isOK = false; | |
| 64 | - } | |
| 65 | - } | |
| 60 | + /* ...otherwise set an appropriate error message and fail */ | |
| 61 | +        } else { | |
| 62 | + $this->reason = 'Invalid role'; | |
| 63 | + $this->isOK = false; | |
| 64 | + } | |
| 65 | + } | |
| 66 | 66 | |
| 67 | - /** | |
| 68 | - * Handle errors created while processing the LTI request | |
| 69 | - **/ | |
| 70 | -	public function onError() { | |
| 71 | - global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 67 | + /** | |
| 68 | + * Handle errors created while processing the LTI request | |
| 69 | + **/ | |
| 70 | +    public function onError() { | |
| 71 | + global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 72 | 72 | |
| 73 | -		$this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=error&reason={$this->reason}"; | |
| 74 | - } | |
| 73 | +        $this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=error&reason={$this->reason}"; | |
| 74 | + } | |
| 75 | 75 | |
| 76 | - /** | |
| 77 | - * Handle dashboard requests (coming in LTI v2.0, I guess) | |
| 78 | - **/ | |
| 79 | -	public function onDashboard() { | |
| 80 | - global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 76 | + /** | |
| 77 | + * Handle dashboard requests (coming in LTI v2.0, I guess) | |
| 78 | + **/ | |
| 79 | +    public function onDashboard() { | |
| 80 | + global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 81 | 81 | |
| 82 | -		$this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=dashboard"; | |
| 83 | - } | |
| 82 | +        $this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=dashboard"; | |
| 83 | + } | |
| 84 | 84 | |
| 85 | - /** | |
| 86 | - * Handle configure requests (coming in LTI v2.0, I guess) | |
| 87 | - **/ | |
| 88 | -	public function onConfigure() { | |
| 89 | - global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 85 | + /** | |
| 86 | + * Handle configure requests (coming in LTI v2.0, I guess) | |
| 87 | + **/ | |
| 88 | +    public function onConfigure() { | |
| 89 | + global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 90 | 90 | |
| 91 | -		$this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=configure"; | |
| 92 | - } | |
| 91 | +        $this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=configure"; | |
| 92 | + } | |
| 93 | 93 | |
| 94 | - /** | |
| 95 | - * Handle content-item requests (that is we're a tool provider that adds a button in the content editor) | |
| 96 | - **/ | |
| 97 | -	public function onContentItem() { | |
| 98 | - global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 94 | + /** | |
| 95 | + * Handle content-item requests (that is we're a tool provider that adds a button in the content editor) | |
| 96 | + **/ | |
| 97 | +    public function onContentItem() { | |
| 98 | + global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 99 | 99 | |
| 100 | -		$this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=content-item"; | |
| 101 | - } | |
| 100 | +        $this->redirectURL = "{$metadata['APP_URL']}/app.php?lti-request=content-item"; | |
| 101 | + } | |
| 102 | 102 | } | 
| 103 | 103 | |
| 104 | 104 | /** | 
| @@ -107,10 +107,10 @@ discard block | ||
| 107 | 107 | * @author Seth Battis <[email protected]> | 
| 108 | 108 | **/ | 
| 109 | 109 |  class CanvasAPIviaLTI_Exception extends Exception { | 
| 110 | - const MISSING_SECRETS_FILE = 1; | |
| 111 | - const INVALID_SECRETS_FILE = 2; | |
| 112 | - const MYSQL_CONNECTION = 3; | |
| 113 | - const LAUNCH_REQUEST = 4; | |
| 110 | + const MISSING_SECRETS_FILE = 1; | |
| 111 | + const INVALID_SECRETS_FILE = 2; | |
| 112 | + const MYSQL_CONNECTION = 3; | |
| 113 | + const LAUNCH_REQUEST = 4; | |
| 114 | 114 | } | 
| 115 | 115 | |
| 116 | 116 | ?> | 
| 117 | 117 | \ No newline at end of file | 
| @@ -11,28 +11,28 @@ discard block | ||
| 11 | 11 | * @author Seth Battis <[email protected]> | 
| 12 | 12 | **/ | 
| 13 | 13 |  class CanvasAPIviaLTI_Installer { | 
| 14 | - const SECRETS_NEEDED_STEP = 1; | |
| 15 | - const SECRETS_ENTERED_STEP = 2; | |
| 16 | - const API_DECISION_NEEDED_STEP = 3; | |
| 17 | - const API_DECISION_ENTERED_STEP = 4; | |
| 18 | - const API_TOKEN_PROVIDED_STEP = 5; | |
| 14 | + const SECRETS_NEEDED_STEP = 1; | |
| 15 | + const SECRETS_ENTERED_STEP = 2; | |
| 16 | + const API_DECISION_NEEDED_STEP = 3; | |
| 17 | + const API_DECISION_ENTERED_STEP = 4; | |
| 18 | + const API_TOKEN_PROVIDED_STEP = 5; | |
| 19 | 19 | |
| 20 | - /** | |
| 21 | - * Generate a SECRETS_FILE from user input. | |
| 22 | - * | |
| 23 | - * @param scalar $step optional Where are we in the SECRETS_FILE creation workflow? (defaults to SECRETS_NEEDED_STEP -- the beginning) | |
| 24 | - * | |
| 25 | - * @throws CanvasAPIviaLTI_Installer_Exception If form submission does not contain all required MySQL credentals (host, username, password and database) | |
| 26 | - * @throws CanvasAPIviaLTI_Installer_Exception If SECRETS_FILE cannot be created | |
| 27 | - * @throws CanvasAPIviaLTI_Installer_Exception If $step is not a pre-defined *_STEP constant | |
| 28 | - **/ | |
| 29 | -	public static function createSecretsFile($step = self::SECRETS_NEEDED_STEP) { | |
| 30 | - global $smarty; // FIXME:0 grown-ups don't program like this issue:17 | |
| 20 | + /** | |
| 21 | + * Generate a SECRETS_FILE from user input. | |
| 22 | + * | |
| 23 | + * @param scalar $step optional Where are we in the SECRETS_FILE creation workflow? (defaults to SECRETS_NEEDED_STEP -- the beginning) | |
| 24 | + * | |
| 25 | + * @throws CanvasAPIviaLTI_Installer_Exception If form submission does not contain all required MySQL credentals (host, username, password and database) | |
| 26 | + * @throws CanvasAPIviaLTI_Installer_Exception If SECRETS_FILE cannot be created | |
| 27 | + * @throws CanvasAPIviaLTI_Installer_Exception If $step is not a pre-defined *_STEP constant | |
| 28 | + **/ | |
| 29 | +    public static function createSecretsFile($step = self::SECRETS_NEEDED_STEP) { | |
| 30 | + global $smarty; // FIXME:0 grown-ups don't program like this issue:17 | |
| 31 | 31 | |
| 32 | -		switch ($step) { | |
| 33 | -			case self::SECRETS_NEEDED_STEP: { | |
| 34 | - // FIXME:0 passwords in clear text? oy. issue:17 | |
| 35 | -				$smarty->assign('content', ' | |
| 32 | +        switch ($step) { | |
| 33 | +            case self::SECRETS_NEEDED_STEP: { | |
| 34 | + // FIXME:0 passwords in clear text? oy. issue:17 | |
| 35 | +                $smarty->assign('content', ' | |
| 36 | 36 | <form action="' . $_SERVER['PHP_SELF'] . '" method="post"> | 
| 37 | 37 | <section> | 
| 38 | 38 | <h3>Application Information</h3> | 
| @@ -57,242 +57,242 @@ discard block | ||
| 57 | 57 | <input type="submit" value="Create Secrets File" /> | 
| 58 | 58 | </form> | 
| 59 | 59 | '); | 
| 60 | - $smarty->display(); | |
| 61 | - exit; | |
| 62 | - } | |
| 60 | + $smarty->display(); | |
| 61 | + exit; | |
| 62 | + } | |
| 63 | 63 | |
| 64 | -			case self::SECRETS_ENTERED_STEP: { | |
| 65 | -				if (isset($_REQUEST['name']) && isset($_REQUEST['id']) && isset($_REQUEST['admin_username']) && isset($_REQUEST['admin_password'])) { | |
| 66 | -					if (isset($_REQUEST['host']) && isset($_REQUEST['username']) && isset($_REQUEST['password']) && isset($_REQUEST['database'])) { | |
| 67 | -						$secrets = new SimpleXMLElement('<secrets />'); | |
| 68 | -						$app = $secrets->addChild('app'); | |
| 69 | -						$app->addChild('name', $_REQUEST['name']); | |
| 70 | -						$app->addChild('id', $_REQUEST['id']); | |
| 71 | -						$admin = $app->addChild('admin'); | |
| 72 | -						$admin->addChild('username', $_REQUEST['admin_username']); | |
| 73 | -						$admin->addChild('password', $_REQUEST['admin_password']); | |
| 74 | -						$mysql = $secrets->addChild('mysql'); | |
| 75 | -						$mysql->addChild('host', $_REQUEST['host']); | |
| 76 | -						$mysql->addChild('username', $_REQUEST['username']); | |
| 77 | -						$mysql->addChild('password', $_REQUEST['password']); | |
| 78 | -						$mysql->addChild('database', $_REQUEST['database']); | |
| 79 | -						$oauth = $secrets->addChild('oauth'); | |
| 80 | -						$oauth->addChild('id', $_REQUEST['oauth_id']); | |
| 81 | -						$oauth->addChild('key', $_REQUEST['oauth_key']); | |
| 82 | -						if ($secrets->asXML(SECRETS_FILE) == false) { | |
| 83 | - throw new CanvasAPIviaLTI_Exception( | |
| 84 | - 'Failed to create ' . SECRETS_FILE, | |
| 85 | - CanvasAPIviaLTI_Installer_Exception::SECRETS_FILE_CREATION | |
| 86 | - ); | |
| 87 | - } | |
| 64 | +            case self::SECRETS_ENTERED_STEP: { | |
| 65 | +                if (isset($_REQUEST['name']) && isset($_REQUEST['id']) && isset($_REQUEST['admin_username']) && isset($_REQUEST['admin_password'])) { | |
| 66 | +                    if (isset($_REQUEST['host']) && isset($_REQUEST['username']) && isset($_REQUEST['password']) && isset($_REQUEST['database'])) { | |
| 67 | +                        $secrets = new SimpleXMLElement('<secrets />'); | |
| 68 | +                        $app = $secrets->addChild('app'); | |
| 69 | +                        $app->addChild('name', $_REQUEST['name']); | |
| 70 | +                        $app->addChild('id', $_REQUEST['id']); | |
| 71 | +                        $admin = $app->addChild('admin'); | |
| 72 | +                        $admin->addChild('username', $_REQUEST['admin_username']); | |
| 73 | +                        $admin->addChild('password', $_REQUEST['admin_password']); | |
| 74 | +                        $mysql = $secrets->addChild('mysql'); | |
| 75 | +                        $mysql->addChild('host', $_REQUEST['host']); | |
| 76 | +                        $mysql->addChild('username', $_REQUEST['username']); | |
| 77 | +                        $mysql->addChild('password', $_REQUEST['password']); | |
| 78 | +                        $mysql->addChild('database', $_REQUEST['database']); | |
| 79 | +                        $oauth = $secrets->addChild('oauth'); | |
| 80 | +                        $oauth->addChild('id', $_REQUEST['oauth_id']); | |
| 81 | +                        $oauth->addChild('key', $_REQUEST['oauth_key']); | |
| 82 | +                        if ($secrets->asXML(SECRETS_FILE) == false) { | |
| 83 | + throw new CanvasAPIviaLTI_Exception( | |
| 84 | + 'Failed to create ' . SECRETS_FILE, | |
| 85 | + CanvasAPIviaLTI_Installer_Exception::SECRETS_FILE_CREATION | |
| 86 | + ); | |
| 87 | + } | |
| 88 | 88 | |
| 89 | - $htpasswdFile = __DIR__ . '/.htpasswd'; | |
| 90 | -						shell_exec("htpasswd -bc $htpasswdFile {$_REQUEST['admin_username']} {$_REQUEST['admin_password']}"); | |
| 91 | -						if (!file_exists($htpasswdFile)) { | |
| 92 | - throw new CanvasAPIviaLTI_Installer_Exception( | |
| 93 | - "Failed to create $htpasswdFile", | |
| 94 | - CanvasAPIviaLTI_Installer_Exception::HTPASSWD_FILE | |
| 95 | - ); | |
| 96 | - } | |
| 89 | + $htpasswdFile = __DIR__ . '/.htpasswd'; | |
| 90 | +                        shell_exec("htpasswd -bc $htpasswdFile {$_REQUEST['admin_username']} {$_REQUEST['admin_password']}"); | |
| 91 | +                        if (!file_exists($htpasswdFile)) { | |
| 92 | + throw new CanvasAPIviaLTI_Installer_Exception( | |
| 93 | + "Failed to create $htpasswdFile", | |
| 94 | + CanvasAPIviaLTI_Installer_Exception::HTPASSWD_FILE | |
| 95 | + ); | |
| 96 | + } | |
| 97 | 97 | |
| 98 | - $htaccessFile = __DIR__ . '/.htaccess'; | |
| 99 | -						if(!file_put_contents($htaccessFile, "AuthType Basic\nAuthName \"{$secrets->app->name} Admin\"\nAuthUserFile $htpasswdFile\nRequire valid-user\n")) { | |
| 100 | - throw new CanvasAPIviaLTI_Installer_Exception( | |
| 101 | - "Failed to create $htaccessFile", | |
| 102 | - CanvasAPIviaLTI_Installer_Exception::HTACCESS_FILE | |
| 103 | - ); | |
| 104 | - } | |
| 105 | -					} else { | |
| 106 | - throw new CanvasAPIviaLTI_Installer_Exception( | |
| 107 | - 'Missing a required mysql credential (host, username, password and database all required).', | |
| 108 | - CanvasAPIviaLTI_Installer_Exception::SECRETS_FILE_MYSQL | |
| 109 | - ); | |
| 110 | - } | |
| 111 | - $smarty->addMessage( | |
| 112 | - 'Secrets file created', | |
| 113 | - "<code>secrets.xml</code> contains your authentication credentials and | |
| 98 | + $htaccessFile = __DIR__ . '/.htaccess'; | |
| 99 | +                        if(!file_put_contents($htaccessFile, "AuthType Basic\nAuthName \"{$secrets->app->name} Admin\"\nAuthUserFile $htpasswdFile\nRequire valid-user\n")) { | |
| 100 | + throw new CanvasAPIviaLTI_Installer_Exception( | |
| 101 | + "Failed to create $htaccessFile", | |
| 102 | + CanvasAPIviaLTI_Installer_Exception::HTACCESS_FILE | |
| 103 | + ); | |
| 104 | + } | |
| 105 | +                    } else { | |
| 106 | + throw new CanvasAPIviaLTI_Installer_Exception( | |
| 107 | + 'Missing a required mysql credential (host, username, password and database all required).', | |
| 108 | + CanvasAPIviaLTI_Installer_Exception::SECRETS_FILE_MYSQL | |
| 109 | + ); | |
| 110 | + } | |
| 111 | + $smarty->addMessage( | |
| 112 | + 'Secrets file created', | |
| 113 | + "<code>secrets.xml</code> contains your authentication credentials and | |
| 114 | 114 | should be carefully protected. Be sure not to commit it to a public | 
| 115 | 115 | repository!", | 
| 116 | - NotificationMessage::GOOD | |
| 117 | - ); | |
| 118 | -				} else { | |
| 119 | - throw new CanvasAPIviaLTI_Installer_Exception( | |
| 120 | - 'Missing a required app identity (name, id, admin username and admin password all required).', | |
| 121 | - CanvasAPIviaLTI_Installer_Exception::SECRETS_FILE_APP | |
| 122 | - ); | |
| 123 | - } | |
| 116 | + NotificationMessage::GOOD | |
| 117 | + ); | |
| 118 | +                } else { | |
| 119 | + throw new CanvasAPIviaLTI_Installer_Exception( | |
| 120 | + 'Missing a required app identity (name, id, admin username and admin password all required).', | |
| 121 | + CanvasAPIviaLTI_Installer_Exception::SECRETS_FILE_APP | |
| 122 | + ); | |
| 123 | + } | |
| 124 | 124 | |
| 125 | - /* clear the processed step */ | |
| 126 | - unset($_REQUEST['step']); | |
| 125 | + /* clear the processed step */ | |
| 126 | + unset($_REQUEST['step']); | |
| 127 | 127 | |
| 128 | - break; | |
| 129 | - } | |
| 128 | + break; | |
| 129 | + } | |
| 130 | 130 | |
| 131 | -			default: { | |
| 132 | - throw new CanvasAPIviaLTI_Installer_Exception( | |
| 133 | - "Unknown step ($step) in SECRETS_FILE creation.", | |
| 134 | - CanvasAPIviaLTI_Installer_Exception::SECRETS_NEEDED_STEP | |
| 135 | - ); | |
| 136 | - } | |
| 137 | - } | |
| 138 | - } | |
| 131 | +            default: { | |
| 132 | + throw new CanvasAPIviaLTI_Installer_Exception( | |
| 133 | + "Unknown step ($step) in SECRETS_FILE creation.", | |
| 134 | + CanvasAPIviaLTI_Installer_Exception::SECRETS_NEEDED_STEP | |
| 135 | + ); | |
| 136 | + } | |
| 137 | + } | |
| 138 | + } | |
| 139 | 139 | |
| 140 | - /** | |
| 141 | - * Create database tables to back LTI_Tool_Provider | |
| 142 | - * | |
| 143 | - * @throws CanvasAPIviaLTI_Installer_Exception If database schema not found in vendors directory | |
| 144 | - * @throws CanvasAPIviaLTI_Installer_Exception If database tables are not created | |
| 145 | - **/ | |
| 146 | -	public static function createLTIDatabaseTables() { | |
| 147 | - global $sql; // FIXME:0 grown-ups don't program like this issue:17 | |
| 148 | - global $smarty; // FIXME:0 grown-ups don't program like this issue:17 | |
| 140 | + /** | |
| 141 | + * Create database tables to back LTI_Tool_Provider | |
| 142 | + * | |
| 143 | + * @throws CanvasAPIviaLTI_Installer_Exception If database schema not found in vendors directory | |
| 144 | + * @throws CanvasAPIviaLTI_Installer_Exception If database tables are not created | |
| 145 | + **/ | |
| 146 | +    public static function createLTIDatabaseTables() { | |
| 147 | + global $sql; // FIXME:0 grown-ups don't program like this issue:17 | |
| 148 | + global $smarty; // FIXME:0 grown-ups don't program like this issue:17 | |
| 149 | 149 | |
| 150 | - $ltiSchema = realpath(__DIR__ . '/../vendor/spvsoftwareproducts/LTI_Tool_Provider/lti-tables-mysql.sql'); | |
| 150 | + $ltiSchema = realpath(__DIR__ . '/../vendor/spvsoftwareproducts/LTI_Tool_Provider/lti-tables-mysql.sql'); | |
| 151 | 151 | |
| 152 | -		if ($sql->query("SHOW TABLES LIKE 'lti_%'")->num_rows >= 5) { | |
| 153 | -			$smarty->addMessage('LTI database tables exist', 'Database tables to support the LTI Tool Provider (TP) already exist and have not been re-created.'); | |
| 154 | -		} elseif (file_exists($ltiSchema)) { | |
| 155 | -			$queries = explode(";", file_get_contents($ltiSchema)); | |
| 156 | - $created = true; | |
| 157 | -			foreach($queries as $query) { | |
| 158 | -				if (!empty(trim($query))) { | |
| 159 | -					if (!$sql->query($query)) { | |
| 160 | - throw new CanvasAPIviaLTI_Installer_Exception( | |
| 161 | -							"Error creating LTI database tables: {$sql->error}", | |
| 162 | - CanvasAPIviaLTI_Installer_Exception::LTI_PREPARE_DATABASE | |
| 163 | - ); | |
| 164 | - } | |
| 165 | - } | |
| 166 | - } | |
| 152 | +        if ($sql->query("SHOW TABLES LIKE 'lti_%'")->num_rows >= 5) { | |
| 153 | +            $smarty->addMessage('LTI database tables exist', 'Database tables to support the LTI Tool Provider (TP) already exist and have not been re-created.'); | |
| 154 | +        } elseif (file_exists($ltiSchema)) { | |
| 155 | +            $queries = explode(";", file_get_contents($ltiSchema)); | |
| 156 | + $created = true; | |
| 157 | +            foreach($queries as $query) { | |
| 158 | +                if (!empty(trim($query))) { | |
| 159 | +                    if (!$sql->query($query)) { | |
| 160 | + throw new CanvasAPIviaLTI_Installer_Exception( | |
| 161 | +                            "Error creating LTI database tables: {$sql->error}", | |
| 162 | + CanvasAPIviaLTI_Installer_Exception::LTI_PREPARE_DATABASE | |
| 163 | + ); | |
| 164 | + } | |
| 165 | + } | |
| 166 | + } | |
| 167 | 167 | |
| 168 | - $smarty->addMessage( | |
| 169 | - 'LTI database tables created', | |
| 170 | - 'Database tables to support the LTI Tool Provider (TP) have been created in | |
| 168 | + $smarty->addMessage( | |
| 169 | + 'LTI database tables created', | |
| 170 | + 'Database tables to support the LTI Tool Provider (TP) have been created in | |
| 171 | 171 | your MySQL database.', | 
| 172 | - NotificationMessage::GOOD | |
| 173 | - ); | |
| 174 | -		} else { | |
| 175 | -			throw new CanvasAPIviaLTI_Exception("$ltiSchema not found."); | |
| 176 | - } | |
| 177 | - } | |
| 172 | + NotificationMessage::GOOD | |
| 173 | + ); | |
| 174 | +        } else { | |
| 175 | +            throw new CanvasAPIviaLTI_Exception("$ltiSchema not found."); | |
| 176 | + } | |
| 177 | + } | |
| 178 | 178 | |
| 179 | - /** | |
| 180 | - * Create database tables to back app | |
| 181 | - * | |
| 182 | - * @throws CanvasAPIviaLTI_Installer_Exception If database tables are not created | |
| 183 | - **/ | |
| 184 | -	public static function createAppDatabaseTables() { | |
| 185 | - global $sql; // FIXME:0 grown-ups don't program like this issue:17 | |
| 186 | - global $smarty; // FIXME:0 grown-ups don't program like this issue:17 | |
| 179 | + /** | |
| 180 | + * Create database tables to back app | |
| 181 | + * | |
| 182 | + * @throws CanvasAPIviaLTI_Installer_Exception If database tables are not created | |
| 183 | + **/ | |
| 184 | +    public static function createAppDatabaseTables() { | |
| 185 | + global $sql; // FIXME:0 grown-ups don't program like this issue:17 | |
| 186 | + global $smarty; // FIXME:0 grown-ups don't program like this issue:17 | |
| 187 | 187 | |
| 188 | -		if (file_exists(SCHEMA_FILE)) { | |
| 189 | -			$queries = explode(";", file_get_contents(SCHEMA_FILE)); | |
| 190 | - $created = true; | |
| 191 | -			foreach ($queries as $query) { | |
| 192 | -				if (!empty(trim($query))) { | |
| 193 | -					if (preg_match('/CREATE\s+TABLE\s+(`([^`]+)`|\w+)/i', $query, $tableName)) { | |
| 194 | - $tableName = (empty($tableName[2]) ? $tableName[1] : $tableName[2]); | |
| 195 | -						if ($sql->query("SHOW TABLES LIKE '$tableName'")->num_rows > 0) { | |
| 196 | - $created = false; | |
| 197 | -						} else { | |
| 198 | -							if (!$sql->query($query)) { | |
| 199 | - throw new CanvasAPIviaLTI_Installer_Exception( | |
| 200 | -									"Error creating app database tables: {$sql->error}", | |
| 201 | - CanvasAPIviaLTI_Installer_Exception::APP_CREATE_TABLE | |
| 202 | - ); | |
| 203 | - } | |
| 204 | - } | |
| 205 | -					} else { | |
| 206 | -						if (!$sql->query($query)) { | |
| 207 | - throw new CanvasAPIviaLTI_Installer_Exception( | |
| 208 | -								"Error creating app database tables: {$sql->error}", | |
| 209 | - CanvasAPIviaLTI_Installer_Exception::APP_PREPARE_DATABASE | |
| 210 | - ); | |
| 211 | - } | |
| 212 | - } | |
| 213 | - } | |
| 214 | - } | |
| 188 | +        if (file_exists(SCHEMA_FILE)) { | |
| 189 | +            $queries = explode(";", file_get_contents(SCHEMA_FILE)); | |
| 190 | + $created = true; | |
| 191 | +            foreach ($queries as $query) { | |
| 192 | +                if (!empty(trim($query))) { | |
| 193 | +                    if (preg_match('/CREATE\s+TABLE\s+(`([^`]+)`|\w+)/i', $query, $tableName)) { | |
| 194 | + $tableName = (empty($tableName[2]) ? $tableName[1] : $tableName[2]); | |
| 195 | +                        if ($sql->query("SHOW TABLES LIKE '$tableName'")->num_rows > 0) { | |
| 196 | + $created = false; | |
| 197 | +                        } else { | |
| 198 | +                            if (!$sql->query($query)) { | |
| 199 | + throw new CanvasAPIviaLTI_Installer_Exception( | |
| 200 | +                                    "Error creating app database tables: {$sql->error}", | |
| 201 | + CanvasAPIviaLTI_Installer_Exception::APP_CREATE_TABLE | |
| 202 | + ); | |
| 203 | + } | |
| 204 | + } | |
| 205 | +                    } else { | |
| 206 | +                        if (!$sql->query($query)) { | |
| 207 | + throw new CanvasAPIviaLTI_Installer_Exception( | |
| 208 | +                                "Error creating app database tables: {$sql->error}", | |
| 209 | + CanvasAPIviaLTI_Installer_Exception::APP_PREPARE_DATABASE | |
| 210 | + ); | |
| 211 | + } | |
| 212 | + } | |
| 213 | + } | |
| 214 | + } | |
| 215 | 215 | |
| 216 | -			if ($created) { | |
| 217 | - $smarty->addMessage( | |
| 218 | - 'App database tables created', | |
| 219 | - 'Database tables to support the application have been created in your | |
| 216 | +            if ($created) { | |
| 217 | + $smarty->addMessage( | |
| 218 | + 'App database tables created', | |
| 219 | + 'Database tables to support the application have been created in your | |
| 220 | 220 | MySQL database.', | 
| 221 | - NotificationMessage::GOOD | |
| 222 | - ); | |
| 223 | -			} else { | |
| 224 | - $smarty->addMessage( | |
| 225 | - 'App database tables exist', | |
| 226 | - 'Database tables to support the application already exist and have not | |
| 221 | + NotificationMessage::GOOD | |
| 222 | + ); | |
| 223 | +            } else { | |
| 224 | + $smarty->addMessage( | |
| 225 | + 'App database tables exist', | |
| 226 | + 'Database tables to support the application already exist and have not | |
| 227 | 227 | been re-created.' | 
| 228 | - ); | |
| 229 | - } | |
| 230 | - } | |
| 231 | - } | |
| 228 | + ); | |
| 229 | + } | |
| 230 | + } | |
| 231 | + } | |
| 232 | 232 | |
| 233 | - /** | |
| 234 | - * Initialize the app metadata store, especially the APP_PATH and APP_URL | |
| 235 | - * | |
| 236 | - * @return AppMetadata | |
| 237 | - **/ | |
| 238 | -	public static function createAppMetadata() { | |
| 239 | - global $secrets; // FIXME:0 grown-ups don't program like this issue:17 | |
| 240 | - global $sql; // FIXME:0 grown-ups don't program like this issue:17 | |
| 241 | - global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 242 | - global $smarty; // FIXME:0 grown-ups don't program like this issue:17 | |
| 233 | + /** | |
| 234 | + * Initialize the app metadata store, especially the APP_PATH and APP_URL | |
| 235 | + * | |
| 236 | + * @return AppMetadata | |
| 237 | + **/ | |
| 238 | +    public static function createAppMetadata() { | |
| 239 | + global $secrets; // FIXME:0 grown-ups don't program like this issue:17 | |
| 240 | + global $sql; // FIXME:0 grown-ups don't program like this issue:17 | |
| 241 | + global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 242 | + global $smarty; // FIXME:0 grown-ups don't program like this issue:17 | |
| 243 | 243 | |
| 244 | - $metadata = initAppMetadata(); | |
| 245 | -		$metadata['APP_PATH'] = preg_replace('/\/classes$/', '', __DIR__); | |
| 246 | -		$metadata['APP_URL'] = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on' ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . preg_replace("|^{$_SERVER['DOCUMENT_ROOT']}(.*)$|", '$1', $metadata['APP_PATH']); | |
| 247 | - $metadata['APP_NAME'] = (string) $secrets->app->name; | |
| 248 | - $metadata['APP_ID'] = (string) $secrets->app->id; | |
| 249 | - $metadata['CANVAS_INSTANCE_URL_PLACEHOLDER'] = 'https://canvas.instructure.com'; | |
| 250 | -		$smarty->assign('metadata', $metadata); | |
| 244 | + $metadata = initAppMetadata(); | |
| 245 | +        $metadata['APP_PATH'] = preg_replace('/\/classes$/', '', __DIR__); | |
| 246 | +        $metadata['APP_URL'] = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on' ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . preg_replace("|^{$_SERVER['DOCUMENT_ROOT']}(.*)$|", '$1', $metadata['APP_PATH']); | |
| 247 | + $metadata['APP_NAME'] = (string) $secrets->app->name; | |
| 248 | + $metadata['APP_ID'] = (string) $secrets->app->id; | |
| 249 | + $metadata['CANVAS_INSTANCE_URL_PLACEHOLDER'] = 'https://canvas.instructure.com'; | |
| 250 | +        $smarty->assign('metadata', $metadata); | |
| 251 | 251 | |
| 252 | - $smarty->addMessage( | |
| 253 | - 'App metadata initialized', | |
| 254 | - 'Basic application metadata has been updated, including APP_PATH and APP_URL', | |
| 255 | - NotificationMessage::GOOD | |
| 256 | - ); | |
| 252 | + $smarty->addMessage( | |
| 253 | + 'App metadata initialized', | |
| 254 | + 'Basic application metadata has been updated, including APP_PATH and APP_URL', | |
| 255 | + NotificationMessage::GOOD | |
| 256 | + ); | |
| 257 | 257 | |
| 258 | - return $metadata; | |
| 259 | - } | |
| 258 | + return $metadata; | |
| 259 | + } | |
| 260 | 260 | |
| 261 | - /** | |
| 262 | - * Obtain a Canvas API token, if needed. | |
| 263 | - * | |
| 264 | - * @param scalar $step optional Where are we in the API token negotiation workflow? (defaults to API_DECISION_NEEDED_STEP -- the beginning) | |
| 265 | - * @param boolean $skip optional Skip this step (defaults to FALSE) | |
| 266 | - * | |
| 267 | - * @throws CanvasAPIviaLTI_Installer_Exception If $step is not a pre-defined *_STEP constant | |
| 268 | - **/ | |
| 269 | -	public static function acquireAPIToken($step = self::API_DECISION_NEEDED_STEP, $skip = false) { | |
| 270 | - global $secrets; // FIXME:0 grown-ups don't program like this issue:17 | |
| 271 | - global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 272 | - global $smarty; // FIXME:0 grown-ups don't program like this issue:17 | |
| 261 | + /** | |
| 262 | + * Obtain a Canvas API token, if needed. | |
| 263 | + * | |
| 264 | + * @param scalar $step optional Where are we in the API token negotiation workflow? (defaults to API_DECISION_NEEDED_STEP -- the beginning) | |
| 265 | + * @param boolean $skip optional Skip this step (defaults to FALSE) | |
| 266 | + * | |
| 267 | + * @throws CanvasAPIviaLTI_Installer_Exception If $step is not a pre-defined *_STEP constant | |
| 268 | + **/ | |
| 269 | +    public static function acquireAPIToken($step = self::API_DECISION_NEEDED_STEP, $skip = false) { | |
| 270 | + global $secrets; // FIXME:0 grown-ups don't program like this issue:17 | |
| 271 | + global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 272 | + global $smarty; // FIXME:0 grown-ups don't program like this issue:17 | |
| 273 | 273 | |
| 274 | -		if ($skip) { | |
| 275 | -			if (isset($metadata['CANVAS_API_TOKEN']) || isset($metadata['CANVAS_API_USER'])) { | |
| 276 | -				$api = new CanvasPest("{$metadata['CANVAS_INSTANCE_URL']}/login/oauth2", $metadata['CANVAS_API_TOKEN']); | |
| 277 | -				$api->delete('token'); | |
| 278 | - unset($metadata['CANVAS_API_TOKEN']); | |
| 279 | - unset($metadata['CANVAS_API_USER']); | |
| 280 | - $smarty->addMessage( | |
| 281 | - 'Existing admin Canvas API token information expunged', | |
| 282 | - 'There was already an administrative access token stored in your | |
| 274 | +        if ($skip) { | |
| 275 | +            if (isset($metadata['CANVAS_API_TOKEN']) || isset($metadata['CANVAS_API_USER'])) { | |
| 276 | +                $api = new CanvasPest("{$metadata['CANVAS_INSTANCE_URL']}/login/oauth2", $metadata['CANVAS_API_TOKEN']); | |
| 277 | +                $api->delete('token'); | |
| 278 | + unset($metadata['CANVAS_API_TOKEN']); | |
| 279 | + unset($metadata['CANVAS_API_USER']); | |
| 280 | + $smarty->addMessage( | |
| 281 | + 'Existing admin Canvas API token information expunged', | |
| 282 | + 'There was already an administrative access token stored in your | |
| 283 | 283 | application metadata, and it has now been expunged.' | 
| 284 | - ); | |
| 285 | -			} else { | |
| 286 | - $smarty->addMessage( | |
| 287 | - 'No admin Canvas API token acquired', | |
| 288 | - 'An administrative API token has not been acquired. Users will be asked to | |
| 284 | + ); | |
| 285 | +            } else { | |
| 286 | + $smarty->addMessage( | |
| 287 | + 'No admin Canvas API token acquired', | |
| 288 | + 'An administrative API token has not been acquired. Users will be asked to | |
| 289 | 289 | acquire their own API tokens on their first use of the LTI.' | 
| 290 | - ); | |
| 291 | - } | |
| 292 | -		} else { | |
| 293 | -			switch ($step) { | |
| 294 | -				case self::API_DECISION_NEEDED_STEP: { | |
| 295 | -					$smarty->assign('content', ' | |
| 290 | + ); | |
| 291 | + } | |
| 292 | +        } else { | |
| 293 | +            switch ($step) { | |
| 294 | +                case self::API_DECISION_NEEDED_STEP: { | |
| 295 | +                    $smarty->assign('content', ' | |
| 296 | 296 | <form action="' . $metadata['APP_URL'] . '/admin/oauth.php" method="post"> | 
| 297 | 297 | <label for="url"> Canvas Instance URL <input type="text" name="url" id="url" placeholder="' . $metadata['CANVAS_INSTANCE_URL_PLACEHOLDER'] . '" value="' . (isset($metadata['CANVAS_INSTANCE_URL']) ? $metadata['CANVAS_INSTANCE_URL'] : '') . '" /></label> | 
| 298 | 298 | <label for="token"> API Access Token <input type="text" name="token" id="token" placeholder="Leave blank to acquire a token interactively" /></label> | 
| @@ -307,43 +307,43 @@ discard block | ||
| 307 | 307 | <input type="submit" value="Require users to acquire individual tokens" /> | 
| 308 | 308 | </form> | 
| 309 | 309 | '); | 
| 310 | - $smarty->display(); | |
| 311 | - exit; | |
| 312 | - } | |
| 313 | -				case self::API_DECISION_ENTERED_STEP: { | |
| 314 | - $oauth = new OAuthNegotiator(); | |
| 310 | + $smarty->display(); | |
| 311 | + exit; | |
| 312 | + } | |
| 313 | +                case self::API_DECISION_ENTERED_STEP: { | |
| 314 | + $oauth = new OAuthNegotiator(); | |
| 315 | 315 | |
| 316 | -					if ($oauth->isAPIToken()) { | |
| 317 | - $metadata['CANVAS_API_TOKEN'] = $oauth->getToken(); | |
| 316 | +                    if ($oauth->isAPIToken()) { | |
| 317 | + $metadata['CANVAS_API_TOKEN'] = $oauth->getToken(); | |
| 318 | 318 | |
| 319 | - $smarty->addMessage( | |
| 320 | - 'Admin Canvas API token acquired', | |
| 321 | - 'An administrative API access token has been acquired and stored in your application metadata.', | |
| 322 | - NotificationMessage::GOOD | |
| 323 | - ); | |
| 324 | - } | |
| 319 | + $smarty->addMessage( | |
| 320 | + 'Admin Canvas API token acquired', | |
| 321 | + 'An administrative API access token has been acquired and stored in your application metadata.', | |
| 322 | + NotificationMessage::GOOD | |
| 323 | + ); | |
| 324 | + } | |
| 325 | 325 | |
| 326 | - /* clear the processed step */ | |
| 327 | - unset($_REQUEST['step']); | |
| 326 | + /* clear the processed step */ | |
| 327 | + unset($_REQUEST['step']); | |
| 328 | 328 | |
| 329 | - break; | |
| 330 | - } | |
| 331 | -				case self::API_TOKEN_PROVIDED_STEP: { | |
| 332 | - $smarty->addMessage( | |
| 333 | - 'Admin Canvas API token provided', | |
| 334 | - 'You provided an API access token and it has been stored in your application metadata.' | |
| 335 | - ); | |
| 336 | - break; | |
| 337 | - } | |
| 338 | -				default: { | |
| 339 | - throw new CanvasAPIviaLTI_Installer_Exception( | |
| 340 | - "Unknown step ($step) in obtaining API token.", | |
| 341 | - CanvasAPIviaLTI_Installer_Exception::API_STEP_MISMATCH | |
| 342 | - ); | |
| 343 | - } | |
| 344 | - } | |
| 345 | - } | |
| 346 | - } | |
| 329 | + break; | |
| 330 | + } | |
| 331 | +                case self::API_TOKEN_PROVIDED_STEP: { | |
| 332 | + $smarty->addMessage( | |
| 333 | + 'Admin Canvas API token provided', | |
| 334 | + 'You provided an API access token and it has been stored in your application metadata.' | |
| 335 | + ); | |
| 336 | + break; | |
| 337 | + } | |
| 338 | +                default: { | |
| 339 | + throw new CanvasAPIviaLTI_Installer_Exception( | |
| 340 | + "Unknown step ($step) in obtaining API token.", | |
| 341 | + CanvasAPIviaLTI_Installer_Exception::API_STEP_MISMATCH | |
| 342 | + ); | |
| 343 | + } | |
| 344 | + } | |
| 345 | + } | |
| 346 | + } | |
| 347 | 347 | } | 
| 348 | 348 | |
| 349 | 349 | /** | 
| @@ -352,20 +352,20 @@ discard block | ||
| 352 | 352 | * @author Seth Battis <[email protected]> | 
| 353 | 353 | **/ | 
| 354 | 354 |  class CanvasAPIviaLTI_Installer_Exception extends CanvasAPIviaLTI_Exception { | 
| 355 | - const SECRETS_FILE_CREATION = 1; | |
| 356 | - const SECRETS_FILE_APP = 2; | |
| 357 | - const SECRETS_FILE_MYSQL = 3; | |
| 358 | - const LTI_SCHEMA = 4; | |
| 359 | - const LTI_PREPARE_DATABASE = 5; | |
| 360 | - const LTI_CREATE_TABLE = 6; | |
| 361 | - const APP_SCHEMA = 7; | |
| 362 | - const APP_PREPARE_DATABASE = 8; | |
| 363 | - const APP_CREATE_TABLE = 9; | |
| 364 | - const API_STEP_MISMATCH = 10; | |
| 365 | - const API_URL = 14; | |
| 366 | - const API_TOKEN = 11; | |
| 367 | - const HTPASSWD_FILE = 12; | |
| 368 | - const HTACCESS_FILE = 13; | |
| 355 | + const SECRETS_FILE_CREATION = 1; | |
| 356 | + const SECRETS_FILE_APP = 2; | |
| 357 | + const SECRETS_FILE_MYSQL = 3; | |
| 358 | + const LTI_SCHEMA = 4; | |
| 359 | + const LTI_PREPARE_DATABASE = 5; | |
| 360 | + const LTI_CREATE_TABLE = 6; | |
| 361 | + const APP_SCHEMA = 7; | |
| 362 | + const APP_PREPARE_DATABASE = 8; | |
| 363 | + const APP_CREATE_TABLE = 9; | |
| 364 | + const API_STEP_MISMATCH = 10; | |
| 365 | + const API_URL = 14; | |
| 366 | + const API_TOKEN = 11; | |
| 367 | + const HTPASSWD_FILE = 12; | |
| 368 | + const HTACCESS_FILE = 13; | |
| 369 | 369 | } | 
| 370 | 370 | |
| 371 | 371 | ?> | 
| 372 | 372 | \ No newline at end of file | 
| @@ -96,7 +96,7 @@ discard block | ||
| 96 | 96 | } | 
| 97 | 97 | |
| 98 | 98 | $htaccessFile = __DIR__ . '/.htaccess'; | 
| 99 | -						if(!file_put_contents($htaccessFile, "AuthType Basic\nAuthName \"{$secrets->app->name} Admin\"\nAuthUserFile $htpasswdFile\nRequire valid-user\n")) { | |
| 99 | +						if (!file_put_contents($htaccessFile, "AuthType Basic\nAuthName \"{$secrets->app->name} Admin\"\nAuthUserFile $htpasswdFile\nRequire valid-user\n")) { | |
| 100 | 100 | throw new CanvasAPIviaLTI_Installer_Exception( | 
| 101 | 101 | "Failed to create $htaccessFile", | 
| 102 | 102 | CanvasAPIviaLTI_Installer_Exception::HTACCESS_FILE | 
| @@ -154,7 +154,7 @@ discard block | ||
| 154 | 154 |  		} elseif (file_exists($ltiSchema)) { | 
| 155 | 155 |  			$queries = explode(";", file_get_contents($ltiSchema)); | 
| 156 | 156 | $created = true; | 
| 157 | -			foreach($queries as $query) { | |
| 157 | +			foreach ($queries as $query) { | |
| 158 | 158 |  				if (!empty(trim($query))) { | 
| 159 | 159 |  					if (!$sql->query($query)) { | 
| 160 | 160 | throw new CanvasAPIviaLTI_Installer_Exception( | 
| @@ -15,15 +15,15 @@ | ||
| 15 | 15 | "); | 
| 16 | 16 | |
| 17 | 17 |  while($schedule = $schedulesResponse->fetch_assoc()) { | 
| 18 | -	$calendarResponse = $sql->query(" | |
| 18 | +    $calendarResponse = $sql->query(" | |
| 19 | 19 | SELECT * | 
| 20 | 20 | FROM `calendars` | 
| 21 | 21 | WHERE | 
| 22 | 22 |  				`id` = '{$schedule['calendar']}' | 
| 23 | 23 | "); | 
| 24 | -	if ($calendar = $calendarResponse->fetch_assoc()) { | |
| 25 | -		echo shell_exec('php ' . __DIR__ . '/import.php ' . $calendar['ics_url'] . ' ' . $calendar['canvas_url'] . ' ' . $schedule['id']); | |
| 26 | - } | |
| 24 | +    if ($calendar = $calendarResponse->fetch_assoc()) { | |
| 25 | +        echo shell_exec('php ' . __DIR__ . '/import.php ' . $calendar['ics_url'] . ' ' . $calendar['canvas_url'] . ' ' . $schedule['id']); | |
| 26 | + } | |
| 27 | 27 | } | 
| 28 | 28 | |
| 29 | 29 | ?> | 
| 30 | 30 | \ No newline at end of file | 
| @@ -14,7 +14,7 @@ | ||
| 14 | 14 | `synced` ASC | 
| 15 | 15 | "); | 
| 16 | 16 | |
| 17 | -while($schedule = $schedulesResponse->fetch_assoc()) { | |
| 17 | +while ($schedule = $schedulesResponse->fetch_assoc()) { | |
| 18 | 18 |  	$calendarResponse = $sql->query(" | 
| 19 | 19 | SELECT * | 
| 20 | 20 | FROM `calendars` | 
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 |  $smarty->assign('category', ''); | 
| 7 | 7 |  $smarty->assign('formAction', $metadata['APP_URL'] . '/import.php'); | 
| 8 | 8 |  $smarty->assign('formHidden', array( | 
| 9 | - 'canvas_url' => $_SESSION['canvasInstanceUrl']. '/courses/' . $_SESSION['toolProvider']->user->getResourceLink()->settings['custom_canvas_course_id'] | |
| 9 | + 'canvas_url' => $_SESSION['canvasInstanceUrl']. '/courses/' . $_SESSION['toolProvider']->user->getResourceLink()->settings['custom_canvas_course_id'] | |
| 10 | 10 | )); | 
| 11 | 11 |  $smarty->display('course.tpl'); | 
| 12 | 12 | |
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 |  $smarty->assign('category', ''); | 
| 7 | 7 |  $smarty->assign('formAction', $metadata['APP_URL'] . '/import.php'); | 
| 8 | 8 |  $smarty->assign('formHidden', array( | 
| 9 | - 'canvas_url' => $_SESSION['canvasInstanceUrl']. '/courses/' . $_SESSION['toolProvider']->user->getResourceLink()->settings['custom_canvas_course_id'] | |
| 9 | + 'canvas_url' => $_SESSION['canvasInstanceUrl'] . '/courses/' . $_SESSION['toolProvider']->user->getResourceLink()->settings['custom_canvas_course_id'] | |
| 10 | 10 | )); | 
| 11 | 11 |  $smarty->display('course.tpl'); | 
| 12 | 12 | |
| @@ -10,8 +10,8 @@ discard block | ||
| 10 | 10 | $smarty->addTemplateDir(__DIR__ . '/templates'); | 
| 11 | 11 | |
| 12 | 12 |  if (empty($_REQUEST['url'])) { | 
| 13 | -	$smarty->display('visualize-form.tpl'); | |
| 14 | - exit; | |
| 13 | +    $smarty->display('visualize-form.tpl'); | |
| 14 | + exit; | |
| 15 | 15 | } | 
| 16 | 16 | |
| 17 | 17 | $config = new ConfigXML(__DIR__ . '/secrets.xml'); | 
| @@ -22,14 +22,14 @@ discard block | ||
| 22 | 22 | |
| 23 | 23 | $ics = $cache->getCache($_REQUEST['url']); | 
| 24 | 24 |  if (empty($ics)) { | 
| 25 | - $ics = new vcalendar( | |
| 26 | - array( | |
| 27 | - 'unique_id' => basename(__FILE__, '.php'), | |
| 28 | - 'url' => $_REQUEST['url'] | |
| 29 | - ) | |
| 30 | - ); | |
| 31 | - $ics->parse(); | |
| 32 | - $cache->setCache($_REQUEST['url'], $ics); | |
| 25 | + $ics = new vcalendar( | |
| 26 | + array( | |
| 27 | + 'unique_id' => basename(__FILE__, '.php'), | |
| 28 | + 'url' => $_REQUEST['url'] | |
| 29 | + ) | |
| 30 | + ); | |
| 31 | + $ics->parse(); | |
| 32 | + $cache->setCache($_REQUEST['url'], $ics); | |
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | 35 |  $smarty->assign('ics', $ics); | 
| @@ -33,5 +33,5 @@ | ||
| 33 | 33 | } | 
| 34 | 34 | |
| 35 | 35 |  $smarty->assign('ics', $ics); | 
| 36 | -$smarty->assign('veventProperties', array('unique' => array('CLASS','CREATED','SUMMARY','DESCRIPTION','DTSTART','X-CURRENT-DTSTART','DTEND','X-CURRENT-DTEND','DURATION','GEO','LAST-MOD','LOCATION','ORGANIZER','PRIORITY','DTSTAMP','SEQ','STATUS','TRANSP','UID','URL','RECURID'),'multiple'=>array('ATTACH','ATTENDEE','CATEGORIES','COMMENT','CONTACT','EXDATE','EXRULE','RSTATUS','RELATED','RESOURCES','RDATE','RRULE','X-PROP'))); | |
| 36 | +$smarty->assign('veventProperties', array('unique' => array('CLASS', 'CREATED', 'SUMMARY', 'DESCRIPTION', 'DTSTART', 'X-CURRENT-DTSTART', 'DTEND', 'X-CURRENT-DTEND', 'DURATION', 'GEO', 'LAST-MOD', 'LOCATION', 'ORGANIZER', 'PRIORITY', 'DTSTAMP', 'SEQ', 'STATUS', 'TRANSP', 'UID', 'URL', 'RECURID'), 'multiple'=>array('ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'EXDATE', 'EXRULE', 'RSTATUS', 'RELATED', 'RESOURCES', 'RDATE', 'RRULE', 'X-PROP'))); | |
| 37 | 37 |  $smarty->display('visualize.tpl'); | 
| 38 | 38 | \ No newline at end of file | 
| @@ -18,8 +18,8 @@ discard block | ||
| 18 | 18 | * @return boolean | 
| 19 | 19 | **/ | 
| 20 | 20 |  function midLaunch() { | 
| 21 | - global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 22 | - return $metadata['APP_LAUNCH_URL'] === (($_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); | |
| 21 | + global $metadata; // FIXME:0 grown-ups don't program like this issue:17 | |
| 22 | + return $metadata['APP_LAUNCH_URL'] === (($_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); | |
| 23 | 23 | } | 
| 24 | 24 | |
| 25 | 25 | /** | 
| @@ -31,22 +31,22 @@ discard block | ||
| 31 | 31 | * @throws CanvasAPIviaLTI_Exception INVALID_SECRETS_FILE if the SECRETS_FILE exists, but cannot be parsed | 
| 32 | 32 | **/ | 
| 33 | 33 |  function initSecrets() { | 
| 34 | -	if (file_exists(SECRETS_FILE)) { | |
| 35 | - // http://stackoverflow.com/a/24760909 (oy!) | |
| 36 | -		if (($secrets = simplexml_load_string(file_get_contents(SECRETS_FILE))) !== false) { | |
| 37 | - return $secrets; | |
| 38 | -		} else { | |
| 39 | - throw new CanvasAPIviaLTI_Exception( | |
| 40 | - SECRETS_FILE . ' could not be loaded. ', | |
| 41 | - CanvasAPIviaLTI_Exception::INVALID_SECRETS_FILE | |
| 42 | - ); | |
| 43 | - } | |
| 44 | -	} else { | |
| 45 | - throw new CanvasAPIviaLTI_Exception( | |
| 46 | - SECRETS_FILE . " could not be found.", | |
| 47 | - CanvasAPIviaLTI_Exception::MISSING_SECRETS_FILE | |
| 48 | - ); | |
| 49 | - } | |
| 34 | +    if (file_exists(SECRETS_FILE)) { | |
| 35 | + // http://stackoverflow.com/a/24760909 (oy!) | |
| 36 | +        if (($secrets = simplexml_load_string(file_get_contents(SECRETS_FILE))) !== false) { | |
| 37 | + return $secrets; | |
| 38 | +        } else { | |
| 39 | + throw new CanvasAPIviaLTI_Exception( | |
| 40 | + SECRETS_FILE . ' could not be loaded. ', | |
| 41 | + CanvasAPIviaLTI_Exception::INVALID_SECRETS_FILE | |
| 42 | + ); | |
| 43 | + } | |
| 44 | +    } else { | |
| 45 | + throw new CanvasAPIviaLTI_Exception( | |
| 46 | + SECRETS_FILE . " could not be found.", | |
| 47 | + CanvasAPIviaLTI_Exception::MISSING_SECRETS_FILE | |
| 48 | + ); | |
| 49 | + } | |
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | 52 | /** | 
| @@ -59,28 +59,28 @@ discard block | ||
| 59 | 59 | * @throws CanvasAPIviaLTI_Exception MYSQL_CONNECTION if a mysqli connection cannot be established | 
| 60 | 60 | **/ | 
| 61 | 61 |  function initMySql() { | 
| 62 | - global $secrets; // FIXME:0 grown-ups don't program like this issue:17 | |
| 63 | -	if (!($secrets instanceof SimpleXMLElement)) { | |
| 64 | - $secrets = initSecrets(); | |
| 65 | - } | |
| 66 | - | |
| 67 | - /* turn off warnings, since we're going to test the connection ourselves */ | |
| 68 | -	set_error_handler(function() {}); | |
| 69 | - $sql = new mysqli( | |
| 70 | - (string) $secrets->mysql->host, | |
| 71 | - (string) $secrets->mysql->username, | |
| 72 | - (string) $secrets->mysql->password, | |
| 73 | - (string) $secrets->mysql->database | |
| 74 | - ); | |
| 75 | - restore_error_handler(); | |
| 76 | - | |
| 77 | -	if ($sql->connect_error) { | |
| 78 | - throw new CanvasAPIviaLTI_Exception( | |
| 79 | - $sql->connect_error, | |
| 80 | - CanvasAPIviaLTI_Exception::MYSQL_CONNECTION | |
| 81 | - ); | |
| 82 | - } | |
| 83 | - return $sql; | |
| 62 | + global $secrets; // FIXME:0 grown-ups don't program like this issue:17 | |
| 63 | +    if (!($secrets instanceof SimpleXMLElement)) { | |
| 64 | + $secrets = initSecrets(); | |
| 65 | + } | |
| 66 | + | |
| 67 | + /* turn off warnings, since we're going to test the connection ourselves */ | |
| 68 | +    set_error_handler(function() {}); | |
| 69 | + $sql = new mysqli( | |
| 70 | + (string) $secrets->mysql->host, | |
| 71 | + (string) $secrets->mysql->username, | |
| 72 | + (string) $secrets->mysql->password, | |
| 73 | + (string) $secrets->mysql->database | |
| 74 | + ); | |
| 75 | + restore_error_handler(); | |
| 76 | + | |
| 77 | +    if ($sql->connect_error) { | |
| 78 | + throw new CanvasAPIviaLTI_Exception( | |
| 79 | + $sql->connect_error, | |
| 80 | + CanvasAPIviaLTI_Exception::MYSQL_CONNECTION | |
| 81 | + ); | |
| 82 | + } | |
| 83 | + return $sql; | |
| 84 | 84 | } | 
| 85 | 85 | |
| 86 | 86 | /** | 
| @@ -89,12 +89,12 @@ discard block | ||
| 89 | 89 | * @return \Battis\AppMetadata | 
| 90 | 90 | **/ | 
| 91 | 91 |  function initAppMetadata() { | 
| 92 | - global $secrets; // FIXME:0 grown-ups don't program like this issue:17 | |
| 93 | - global $sql; // FIXME:0 grown-ups don't program like this issue:17 | |
| 92 | + global $secrets; // FIXME:0 grown-ups don't program like this issue:17 | |
| 93 | + global $sql; // FIXME:0 grown-ups don't program like this issue:17 | |
| 94 | 94 | |
| 95 | - $metadata = new AppMetadata($sql, (string) $secrets->app->id); | |
| 95 | + $metadata = new AppMetadata($sql, (string) $secrets->app->id); | |
| 96 | 96 | |
| 97 | - return $metadata; | |
| 97 | + return $metadata; | |
| 98 | 98 | } | 
| 99 | 99 | |
| 100 | 100 | /** | 
| @@ -105,9 +105,9 @@ discard block | ||
| 105 | 105 | * @return void | 
| 106 | 106 | **/ | 
| 107 | 107 |  function html_var_dump($var) { | 
| 108 | - echo '<pre>'; | |
| 109 | - var_dump($var); | |
| 110 | - echo '</pre>'; | |
| 108 | + echo '<pre>'; | |
| 109 | + var_dump($var); | |
| 110 | + echo '</pre>'; | |
| 111 | 111 | } | 
| 112 | 112 | |
| 113 | 113 | /***************************************************************************** | 
| @@ -121,68 +121,68 @@ discard block | ||
| 121 | 121 | |
| 122 | 122 | /* preliminary interactive only initialization */ | 
| 123 | 123 |  if (php_sapi_name() != 'cli') { | 
| 124 | - session_start(); | |
| 124 | + session_start(); | |
| 125 | 125 | |
| 126 | - /* fire up the templating engine for interactive scripts */ | |
| 127 | - $smarty = StMarksSmarty::getSmarty(); | |
| 128 | - $smarty->addTemplateDir(__DIR__ . '/templates', 'starter-canvas-api-via-lti'); | |
| 129 | - $smarty->setFramed(true); | |
| 126 | + /* fire up the templating engine for interactive scripts */ | |
| 127 | + $smarty = StMarksSmarty::getSmarty(); | |
| 128 | + $smarty->addTemplateDir(__DIR__ . '/templates', 'starter-canvas-api-via-lti'); | |
| 129 | + $smarty->setFramed(true); | |
| 130 | 130 | } | 
| 131 | 131 | |
| 132 | 132 | /* initialization that needs to happen for interactive and CLI scripts */ | 
| 133 | 133 |  try { | 
| 134 | - /* initialize global variables */ | |
| 135 | - $secrets = initSecrets(); | |
| 136 | - $sql = initMySql(); | |
| 137 | - $metadata = initAppMetadata(); | |
| 134 | + /* initialize global variables */ | |
| 135 | + $secrets = initSecrets(); | |
| 136 | + $sql = initMySql(); | |
| 137 | + $metadata = initAppMetadata(); | |
| 138 | 138 |  } catch (CanvasAPIviaLTI_Exception $e) { | 
| 139 | -	if (php_sapi_name() == 'cli') { | |
| 140 | - echo 'Initialization Failure [' . $e->getCode() . ']' . PHP_EOL . $e->getMessage() . PHP_EOL; | |
| 141 | - exit; | |
| 142 | -	} else { | |
| 143 | - $smarty->addMessage( | |
| 144 | - 'Initialization Failure [' . $e->getCode() . ']', | |
| 145 | - $e->getMessage(), | |
| 146 | - NotificationMessage::ERROR | |
| 147 | - ); | |
| 148 | - $smarty->display(); | |
| 149 | - exit; | |
| 150 | - } | |
| 139 | +    if (php_sapi_name() == 'cli') { | |
| 140 | + echo 'Initialization Failure [' . $e->getCode() . ']' . PHP_EOL . $e->getMessage() . PHP_EOL; | |
| 141 | + exit; | |
| 142 | +    } else { | |
| 143 | + $smarty->addMessage( | |
| 144 | + 'Initialization Failure [' . $e->getCode() . ']', | |
| 145 | + $e->getMessage(), | |
| 146 | + NotificationMessage::ERROR | |
| 147 | + ); | |
| 148 | + $smarty->display(); | |
| 149 | + exit; | |
| 150 | + } | |
| 151 | 151 | } | 
| 152 | 152 | |
| 153 | 153 | /* interactive initialization only */ | 
| 154 | 154 |  if ($ready && php_sapi_name() != 'cli') { | 
| 155 | 155 | |
| 156 | - /* allow web apps to use common.inc.php without LTI authentication */ | |
| 157 | -	if (!defined('IGNORE_LTI')) { | |
| 158 | - | |
| 159 | -		try { | |
| 160 | -			if (midLaunch()) { | |
| 161 | - $ready = false; | |
| 162 | -			} elseif (isset($_SESSION['toolProvider'])) { | |
| 163 | - $toolProvider = $_SESSION['toolProvider']; | |
| 164 | -			} else { | |
| 165 | - throw new CanvasAPIviaLTI_Exception( | |
| 166 | - 'The LTI launch request is missing', | |
| 167 | - CanvasAPIviaLTI_Exception::LAUNCH_REQUEST | |
| 168 | - ); | |
| 169 | - } | |
| 170 | - | |
| 171 | -		} catch (CanvasAPIviaLTI_Exception $e) { | |
| 172 | - $ready = false; | |
| 173 | - } | |
| 174 | - } | |
| 175 | - | |
| 176 | -	if ($ready) { | |
| 177 | - $smarty->addStylesheet($metadata['APP_URL'] . '/css/canvas-api-via-lti.css', 'starter-canvas-api-via-lti'); | |
| 178 | - $smarty->addStylesheet($metadata['APP_URL'] . '/css/app.css'); | |
| 179 | - | |
| 180 | -		if (!midLaunch() || !defined('IGNORE_LTI')) { | |
| 181 | - require_once(__DIR__ . '/common-app.inc.php'); | |
| 182 | - } | |
| 183 | - } | |
| 156 | + /* allow web apps to use common.inc.php without LTI authentication */ | |
| 157 | +    if (!defined('IGNORE_LTI')) { | |
| 158 | + | |
| 159 | +        try { | |
| 160 | +            if (midLaunch()) { | |
| 161 | + $ready = false; | |
| 162 | +            } elseif (isset($_SESSION['toolProvider'])) { | |
| 163 | + $toolProvider = $_SESSION['toolProvider']; | |
| 164 | +            } else { | |
| 165 | + throw new CanvasAPIviaLTI_Exception( | |
| 166 | + 'The LTI launch request is missing', | |
| 167 | + CanvasAPIviaLTI_Exception::LAUNCH_REQUEST | |
| 168 | + ); | |
| 169 | + } | |
| 170 | + | |
| 171 | +        } catch (CanvasAPIviaLTI_Exception $e) { | |
| 172 | + $ready = false; | |
| 173 | + } | |
| 174 | + } | |
| 175 | + | |
| 176 | +    if ($ready) { | |
| 177 | + $smarty->addStylesheet($metadata['APP_URL'] . '/css/canvas-api-via-lti.css', 'starter-canvas-api-via-lti'); | |
| 178 | + $smarty->addStylesheet($metadata['APP_URL'] . '/css/app.css'); | |
| 179 | + | |
| 180 | +        if (!midLaunch() || !defined('IGNORE_LTI')) { | |
| 181 | + require_once(__DIR__ . '/common-app.inc.php'); | |
| 182 | + } | |
| 183 | + } | |
| 184 | 184 |  } elseif (php_sapi_name() == 'cli') { | 
| 185 | - require_once(__DIR__ . '/common-app.inc.php'); | |
| 185 | + require_once(__DIR__ . '/common-app.inc.php'); | |
| 186 | 186 | } | 
| 187 | 187 | |
| 188 | 188 | |
| @@ -29,9 +29,9 @@ | ||
| 29 | 29 | $metadata['USER_NAVIGATION_LINK_TEXT'] = '@ACCOUNT_NAVIGATION_LINK_TEXT'; | 
| 30 | 30 | |
| 31 | 31 | $smarty->addMessage( | 
| 32 | - 'App metadata updated', | |
| 33 | - 'Application metadata has been updated to create config.xml', | |
| 34 | - NotificationMessage::GOOD | |
| 32 | + 'App metadata updated', | |
| 33 | + 'Application metadata has been updated to create config.xml', | |
| 34 | + NotificationMessage::GOOD | |
| 35 | 35 | ); | 
| 36 | 36 | |
| 37 | 37 | ?> | 
| @@ -7,21 +7,21 @@ discard block | ||
| 7 | 7 | |
| 8 | 8 | /* test if we already have a working install... */ | 
| 9 | 9 |  if ($ready && (!isset($_REQUEST['step']))) { | 
| 10 | - $smarty->addMessage( | |
| 11 | - 'App already installed', | |
| 12 | - 'It appears that the application has already been installed and is ready for | |
| 10 | + $smarty->addMessage( | |
| 11 | + 'App already installed', | |
| 12 | + 'It appears that the application has already been installed and is ready for | |
| 13 | 13 | use.' | 
| 14 | - ); | |
| 14 | + ); | |
| 15 | 15 | |
| 16 | 16 | /* ...otherwise, let's start with the SECRETS_FILE */ | 
| 17 | 17 |  } else { | 
| 18 | -	if(!file_exists(SECRETS_FILE)) { | |
| 19 | -		if (isset($_REQUEST['step']) && $_REQUEST['step'] == CanvasAPIviaLTI_Installer::SECRETS_ENTERED_STEP) { | |
| 20 | - CanvasAPIviaLTI_Installer::createSecretsFile(CanvasAPIviaLTI_Installer::SECRETS_ENTERED_STEP); | |
| 21 | -		} else { | |
| 22 | - CanvasAPIviaLTI_Installer::createSecretsFile(); | |
| 23 | - } | |
| 24 | - } | |
| 18 | +    if(!file_exists(SECRETS_FILE)) { | |
| 19 | +        if (isset($_REQUEST['step']) && $_REQUEST['step'] == CanvasAPIviaLTI_Installer::SECRETS_ENTERED_STEP) { | |
| 20 | + CanvasAPIviaLTI_Installer::createSecretsFile(CanvasAPIviaLTI_Installer::SECRETS_ENTERED_STEP); | |
| 21 | +        } else { | |
| 22 | + CanvasAPIviaLTI_Installer::createSecretsFile(); | |
| 23 | + } | |
| 24 | + } | |
| 25 | 25 | } | 
| 26 | 26 | |
| 27 | 27 | /* establish our database connection */ | 
| @@ -29,40 +29,40 @@ discard block | ||
| 29 | 29 | $sql = initMySql(); | 
| 30 | 30 | |
| 31 | 31 |  try {	 | 
| 32 | -	if (!isset($_REQUEST['step'])) { | |
| 33 | - /* load all of our various schema into the database... */ | |
| 34 | - CanvasAPIviaLTI_Installer::createLTIDatabaseTables(); | |
| 35 | - CanvasAPIviaLTI_Installer::createAppDatabaseTables(); | |
| 32 | +    if (!isset($_REQUEST['step'])) { | |
| 33 | + /* load all of our various schema into the database... */ | |
| 34 | + CanvasAPIviaLTI_Installer::createLTIDatabaseTables(); | |
| 35 | + CanvasAPIviaLTI_Installer::createAppDatabaseTables(); | |
| 36 | 36 | |
| 37 | - /* ...and initialize the app metadata... */ | |
| 38 | - $metadata = CanvasAPIviaLTI_Installer::createAppMetadata(); | |
| 37 | + /* ...and initialize the app metadata... */ | |
| 38 | + $metadata = CanvasAPIviaLTI_Installer::createAppMetadata(); | |
| 39 | 39 | |
| 40 | - /* ...optionally, acquire an API token for the app */ | |
| 41 | - CanvasAPIviaLTI_Installer::acquireAPIToken(CanvasAPIviaLTI_Installer::API_DECISION_NEEDED_STEP); | |
| 42 | -	} else { | |
| 43 | - $metadata = new AppMetadata($sql, $secrets->app->id); | |
| 44 | - $skip = (isset($_REQUEST['skip']) ? $_REQUEST['skip'] : false); | |
| 45 | - CanvasAPIviaLTI_Installer::acquireAPIToken($_REQUEST['step'], $skip); | |
| 46 | - } | |
| 40 | + /* ...optionally, acquire an API token for the app */ | |
| 41 | + CanvasAPIviaLTI_Installer::acquireAPIToken(CanvasAPIviaLTI_Installer::API_DECISION_NEEDED_STEP); | |
| 42 | +    } else { | |
| 43 | + $metadata = new AppMetadata($sql, $secrets->app->id); | |
| 44 | + $skip = (isset($_REQUEST['skip']) ? $_REQUEST['skip'] : false); | |
| 45 | + CanvasAPIviaLTI_Installer::acquireAPIToken($_REQUEST['step'], $skip); | |
| 46 | + } | |
| 47 | 47 |  } catch (CanvasAPIviaLTI_Installer_Exception $e) { | 
| 48 | - $smarty->addMessage( | |
| 49 | - 'LTI Installer error', | |
| 50 | - $e->getMessage() . ' [Error ' . $e->getCode() . ']', | |
| 51 | - NotificationMessage::ERROR | |
| 52 | - ); | |
| 53 | - $smarty->display(); | |
| 54 | - exit; | |
| 48 | + $smarty->addMessage( | |
| 49 | + 'LTI Installer error', | |
| 50 | + $e->getMessage() . ' [Error ' . $e->getCode() . ']', | |
| 51 | + NotificationMessage::ERROR | |
| 52 | + ); | |
| 53 | + $smarty->display(); | |
| 54 | + exit; | |
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | 57 |  try { | 
| 58 | - /* any additional app-specific install steps */ | |
| 59 | -	require_once('install-app.inc.php'); | |
| 58 | + /* any additional app-specific install steps */ | |
| 59 | +    require_once('install-app.inc.php'); | |
| 60 | 60 |  } catch (CanvasAPIviaLTI_Installer_Exception $e) { | 
| 61 | - $smarty->addMessage( | |
| 62 | - 'App Installer error', | |
| 63 | - $e->getMessage() . ' [Error ' . $e->getCode() . ']', | |
| 64 | - NotificationMessage::ERROR | |
| 65 | - ); | |
| 61 | + $smarty->addMessage( | |
| 62 | + 'App Installer error', | |
| 63 | + $e->getMessage() . ' [Error ' . $e->getCode() . ']', | |
| 64 | + NotificationMessage::ERROR | |
| 65 | + ); | |
| 66 | 66 | } | 
| 67 | 67 | |
| 68 | 68 | /* reset $metadata to get update any computed values */ | 
| @@ -15,7 +15,7 @@ | ||
| 15 | 15 | |
| 16 | 16 | /* ...otherwise, let's start with the SECRETS_FILE */ | 
| 17 | 17 |  } else { | 
| 18 | -	if(!file_exists(SECRETS_FILE)) { | |
| 18 | +	if (!file_exists(SECRETS_FILE)) { | |
| 19 | 19 |  		if (isset($_REQUEST['step']) && $_REQUEST['step'] == CanvasAPIviaLTI_Installer::SECRETS_ENTERED_STEP) { | 
| 20 | 20 | CanvasAPIviaLTI_Installer::createSecretsFile(CanvasAPIviaLTI_Installer::SECRETS_ENTERED_STEP); | 
| 21 | 21 |  		} else { |