@@ -24,13 +24,13 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | 26 | //the plugin title |
| 27 | -$plugin_info['title']='PENS'; |
|
| 27 | +$plugin_info['title'] = 'PENS'; |
|
| 28 | 28 | //the comments that go with the plugin |
| 29 | -$plugin_info['comment']="PENS implementation for Chamilo"; |
|
| 29 | +$plugin_info['comment'] = "PENS implementation for Chamilo"; |
|
| 30 | 30 | //the locations where this plugin can be shown |
| 31 | -$plugin_info['location']=array(); |
|
| 31 | +$plugin_info['location'] = array(); |
|
| 32 | 32 | //the plugin version |
| 33 | -$plugin_info['version']='1.1'; |
|
| 33 | +$plugin_info['version'] = '1.1'; |
|
| 34 | 34 | //the plugin author |
| 35 | -$plugin_info['author']='Guillaume Viguier-Just, Yannick Warnier'; |
|
| 35 | +$plugin_info['author'] = 'Guillaume Viguier-Just, Yannick Warnier'; |
|
| 36 | 36 | $plugin_info = PENSPlugin::create()->get_info(); |
| 37 | 37 | \ No newline at end of file |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | * @licence http://www.gnu.org/licenses/gpl.txt |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | -require_once __DIR__ . '/../../main/inc/global.inc.php'; |
|
| 29 | -require_once __DIR__ . '/lib/pens.php'; |
|
| 28 | +require_once __DIR__.'/../../main/inc/global.inc.php'; |
|
| 29 | +require_once __DIR__.'/lib/pens.php'; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * ChamiloPens |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @param PENSRequest Request |
| 115 | 115 | */ |
| 116 | 116 | public function __construct($request) { |
| 117 | - if($request instanceof PENSRequest) { |
|
| 117 | + if ($request instanceof PENSRequest) { |
|
| 118 | 118 | $this->_id = 0; |
| 119 | 119 | $this->_pens_version = $request->getPensVersion(); |
| 120 | 120 | $this->_package_type = $request->getPackageType(); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $this->_client = $request->getClient(); |
| 125 | 125 | $this->_vendor_data = $request->getVendorData(); |
| 126 | 126 | $this->_package_name = $request->getFilename(); |
| 127 | - } else if(is_array($request)) { |
|
| 127 | + } else if (is_array($request)) { |
|
| 128 | 128 | $this->_id = $request['id']; |
| 129 | 129 | $this->_pens_version = $request['pens_version']; |
| 130 | 130 | $this->_package_type = $request['package_type']; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | $this->_vendor_data = $request['vendor_data']; |
| 136 | 136 | $this->_package_name = $request['package_name']; |
| 137 | 137 | $this->_created_at = new DateTime($request['created_at'], new DateTimeZone('UTC')); |
| 138 | - if(!empty($request['updated_at'])) { |
|
| 138 | + if (!empty($request['updated_at'])) { |
|
| 139 | 139 | $this->_updated_at = new DateTime($request['updated_at'], new DateTimeZone('UTC')); |
| 140 | 140 | } |
| 141 | 141 | } |
@@ -151,16 +151,16 @@ discard block |
||
| 151 | 151 | $clean_vendor_data = Database::escape_string($this->_vendor_data); |
| 152 | 152 | $created_at = api_get_utc_datetime(); |
| 153 | 153 | $table = Database::get_main_table(ChamiloPens::TABLE_NAME); |
| 154 | - $sql_query = "INSERT INTO $table (pens_version, package_type, package_type_version, package_format, package_id, client, vendor_data, package_name, created_at) VALUES (" . |
|
| 155 | - "'". $this->_pens_version. "', " . |
|
| 156 | - "'".$this->_package_type. "', " . |
|
| 157 | - "'".$clean_package_type_version. "', " . |
|
| 158 | - "'".$this->_package_format. "', " . |
|
| 159 | - "'".$clean_package_id. "', " . |
|
| 160 | - "'".$clean_client."', " . |
|
| 161 | - "'".$clean_vendor_data."', " . |
|
| 162 | - "'".$this->_package_name."', " . |
|
| 163 | - "'".$created_at."') ON DUPLICATE KEY UPDATE " . |
|
| 154 | + $sql_query = "INSERT INTO $table (pens_version, package_type, package_type_version, package_format, package_id, client, vendor_data, package_name, created_at) VALUES (". |
|
| 155 | + "'".$this->_pens_version."', ". |
|
| 156 | + "'".$this->_package_type."', ". |
|
| 157 | + "'".$clean_package_type_version."', ". |
|
| 158 | + "'".$this->_package_format."', ". |
|
| 159 | + "'".$clean_package_id."', ". |
|
| 160 | + "'".$clean_client."', ". |
|
| 161 | + "'".$clean_vendor_data."', ". |
|
| 162 | + "'".$this->_package_name."', ". |
|
| 163 | + "'".$created_at."') ON DUPLICATE KEY UPDATE ". |
|
| 164 | 164 | "pens_version = VALUES(pens_version), ". |
| 165 | 165 | "package_type = VALUES(package_type), ". |
| 166 | 166 | "package_type_version = VALUES(package_type_version), ". |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $sql_query = "SELECT * FROM $table WHERE package_id = '".$package_id."';"; |
| 183 | 183 | $results = Database::query($sql_query); |
| 184 | 184 | $number = Database::num_rows($results); |
| 185 | - if($number == 1) { |
|
| 185 | + if ($number == 1) { |
|
| 186 | 186 | $obj = Database::fetch_assoc($results); |
| 187 | 187 | return new ChamiloPens($obj); |
| 188 | 188 | } else { |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | $sql_query = "SELECT * FROM $table ORDER BY created_at;"; |
| 201 | 201 | $results = Database::query($sql_query); |
| 202 | 202 | $return = array(); |
| 203 | - while($assoc = Database::fetch_assoc($results)) { |
|
| 203 | + while ($assoc = Database::fetch_assoc($results)) { |
|
| 204 | 204 | $return[] = new ChamiloPens($assoc); |
| 205 | 205 | } |
| 206 | 206 | return $return; |
@@ -24,19 +24,19 @@ |
||
| 24 | 24 | * @licence http://www.gnu.org/licenses/gpl.txt |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | -require_once __DIR__ . '/../../main/inc/global.inc.php'; |
|
| 28 | -require_once __DIR__ . '/lib/pens.php'; |
|
| 29 | -require_once __DIR__ . '/chamilo_pens.php'; |
|
| 27 | +require_once __DIR__.'/../../main/inc/global.inc.php'; |
|
| 28 | +require_once __DIR__.'/lib/pens.php'; |
|
| 29 | +require_once __DIR__.'/chamilo_pens.php'; |
|
| 30 | 30 | |
| 31 | 31 | class ChamiloPackageHandler extends PENSPackageHandler { |
| 32 | 32 | public function processPackage($request, $path_to_package) { |
| 33 | 33 | $server = PENSServer::singleton(); |
| 34 | 34 | // Moves the package to archive/pens |
| 35 | - $path_to_archives = api_get_path(SYS_ARCHIVE_PATH) . 'pens'; |
|
| 36 | - if(!is_dir($path_to_archives)) { |
|
| 35 | + $path_to_archives = api_get_path(SYS_ARCHIVE_PATH).'pens'; |
|
| 36 | + if (!is_dir($path_to_archives)) { |
|
| 37 | 37 | mkdir($path_to_archives, 0777, true); |
| 38 | 38 | } |
| 39 | - rename($path_to_package, $path_to_archives . '/' . $request->getFilename()); |
|
| 39 | + rename($path_to_package, $path_to_archives.'/'.$request->getFilename()); |
|
| 40 | 40 | // Insert the request in the database |
| 41 | 41 | $chamilo_pens = new ChamiloPens($request); |
| 42 | 42 | $chamilo_pens->save(); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * Singleton method |
| 62 | 62 | */ |
| 63 | 63 | public static function singleton() { |
| 64 | - if(!isset(self::$_instance)) { |
|
| 64 | + if (!isset(self::$_instance)) { |
|
| 65 | 65 | $c = __CLASS__; |
| 66 | 66 | self::$_instance = new $c; |
| 67 | 67 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @param PENSRequestHandler Request handler |
| 86 | 86 | */ |
| 87 | 87 | public function setRequestHandler($request_handler) { |
| 88 | - if($request_handler instanceof PENSRequestHandler) { |
|
| 88 | + if ($request_handler instanceof PENSRequestHandler) { |
|
| 89 | 89 | $this->_request_handler = $request_handler; |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | try { |
| 99 | 99 | $request = $this->parseRequest(); |
| 100 | 100 | $command = $request->getCommand(); |
| 101 | - if($command == "alert" || $command == "receipt") { |
|
| 102 | - if(!is_null($this->_request_handler)) { |
|
| 101 | + if ($command == "alert" || $command == "receipt") { |
|
| 102 | + if (!is_null($this->_request_handler)) { |
|
| 103 | 103 | // Call the handler |
| 104 | 104 | $this->_request_handler->processRequest($request, new PENSResponse($_REQUEST)); |
| 105 | 105 | } |
| 106 | 106 | $this->sendResponse(new PENSResponse(0, $command." received and understood")); |
| 107 | 107 | } |
| 108 | - } catch(PENSException $e) { |
|
| 108 | + } catch (PENSException $e) { |
|
| 109 | 109 | // If we could not parse the request, send the error |
| 110 | 110 | $this->sendResponse(new PENSResponse($e)); |
| 111 | 111 | } |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | * Sets the message based on the code |
| 91 | 91 | */ |
| 92 | 92 | protected function setMessageBasedOnCode() { |
| 93 | - if(empty($this->message) && !empty(self::$_code_to_messages[$this->code])) { |
|
| 93 | + if (empty($this->message) && !empty(self::$_code_to_messages[$this->code])) { |
|
| 94 | 94 | $this->message = self::$_code_to_messages[$this->code]; |
| 95 | 95 | } |
| 96 | 96 | } |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public function setSupportedPackageTypes($supported_package_types) { |
| 74 | 74 | $this->_supported_package_types = null; |
| 75 | - if(is_array($supported_package_types)) { |
|
| 76 | - foreach($supported_package_types as $package_type) { |
|
| 77 | - if(in_array($package_type, PENSConfig::$allowed_package_types)) { |
|
| 75 | + if (is_array($supported_package_types)) { |
|
| 76 | + foreach ($supported_package_types as $package_type) { |
|
| 77 | + if (in_array($package_type, PENSConfig::$allowed_package_types)) { |
|
| 78 | 78 | $this->_supported_package_types[] = $package_type; |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -94,9 +94,9 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | public function setSupportedPackageFormats($supported_package_formats) { |
| 96 | 96 | $this->_supported_package_formats = null; |
| 97 | - if(is_array($supported_package_formats)) { |
|
| 98 | - foreach($supported_package_formats as $package_format) { |
|
| 99 | - if(in_array($package_format, PENSConfig::$allowed_package_formats)) { |
|
| 97 | + if (is_array($supported_package_formats)) { |
|
| 98 | + foreach ($supported_package_formats as $package_format) { |
|
| 99 | + if (in_array($package_format, PENSConfig::$allowed_package_formats)) { |
|
| 100 | 100 | $this->_supported_package_formats[] = $package_format; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | * @licence http://www.gnu.org/licenses/gpl.txt |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | -require_once __DIR__ . '/pens_request.php'; |
|
| 29 | +require_once __DIR__.'/pens_request.php'; |
|
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * PENSRequestReceipt |
@@ -26,10 +26,10 @@ discard block |
||
| 26 | 26 | * @licence http://www.gnu.org/licenses/gpl.txt |
| 27 | 27 | */ |
| 28 | 28 | |
| 29 | -require_once __DIR__ . '/pens_controller.php'; |
|
| 30 | -require_once __DIR__ . '/pens_package_handler.php'; |
|
| 31 | -require_once __DIR__ . '/pens_exception.php'; |
|
| 32 | -require_once __DIR__ . '/pens_response.php'; |
|
| 29 | +require_once __DIR__.'/pens_controller.php'; |
|
| 30 | +require_once __DIR__.'/pens_package_handler.php'; |
|
| 31 | +require_once __DIR__.'/pens_exception.php'; |
|
| 32 | +require_once __DIR__.'/pens_response.php'; |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * PENSServer |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * Singleton method |
| 65 | 65 | */ |
| 66 | 66 | public static function singleton() { |
| 67 | - if(!isset(self::$_instance)) { |
|
| 67 | + if (!isset(self::$_instance)) { |
|
| 68 | 68 | $c = __CLASS__; |
| 69 | 69 | self::$_instance = new $c; |
| 70 | 70 | } |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | * @param PENSPackageHandler Package handler |
| 89 | 89 | */ |
| 90 | 90 | public function setPackageHandler($package_handler) { |
| 91 | - if($package_handler instanceof PENSPackageHandler) { |
|
| 91 | + if ($package_handler instanceof PENSPackageHandler) { |
|
| 92 | 92 | $this->_package_handler = $package_handler; |
| 93 | 93 | } |
| 94 | 94 | } |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | try { |
| 102 | 102 | // First, try to parse the request |
| 103 | 103 | $request = $this->parseRequest(); |
| 104 | - if($request->getCommand() == "collect") { |
|
| 105 | - if(isset($_REQUEST['process'])) { |
|
| 104 | + if ($request->getCommand() == "collect") { |
|
| 105 | + if (isset($_REQUEST['process'])) { |
|
| 106 | 106 | // Collect the package and process it |
| 107 | 107 | $receipt = null; |
| 108 | 108 | $path_to_package = null; |
@@ -110,13 +110,13 @@ discard block |
||
| 110 | 110 | // Collect the package |
| 111 | 111 | $path_to_package = $this->collectPackage($request); |
| 112 | 112 | $receipt = new PENSResponse(0, "package successfully collected"); |
| 113 | - } catch(PENSException $e) { |
|
| 113 | + } catch (PENSException $e) { |
|
| 114 | 114 | $receipt = new PENSResponse($e); |
| 115 | 115 | } |
| 116 | 116 | // Send receipt |
| 117 | 117 | $response = $this->sendReceipt($request, $receipt); |
| 118 | - if(!is_null($response) && !is_null($path_to_package)) { |
|
| 119 | - if($response->getError() === 0) { |
|
| 118 | + if (!is_null($response) && !is_null($path_to_package)) { |
|
| 119 | + if ($response->getError() === 0) { |
|
| 120 | 120 | // Process package |
| 121 | 121 | $this->processPackage($request, $path_to_package); |
| 122 | 122 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | $params = $_REQUEST; |
| 130 | 130 | $params['process'] = 1; |
| 131 | 131 | $scheme = "http"; |
| 132 | - if(!empty($_SERVER['HTTPS'])) { |
|
| 132 | + if (!empty($_SERVER['HTTPS'])) { |
|
| 133 | 133 | $scheme = "https"; |
| 134 | 134 | } |
| 135 | 135 | $ch = curl_init(); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - } catch(PENSException $e) { |
|
| 144 | + } catch (PENSException $e) { |
|
| 145 | 145 | // If we could not parse the request, send the error back to the client |
| 146 | 146 | $this->sendResponse(new PENSResponse($e)); |
| 147 | 147 | } |
@@ -156,20 +156,20 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | protected function collectPackage($request) { |
| 158 | 158 | $supported_package_types = $this->_package_handler->getSupportedPackageTypes(); |
| 159 | - if(!in_array($request->getPackageType(), $supported_package_types)) { |
|
| 159 | + if (!in_array($request->getPackageType(), $supported_package_types)) { |
|
| 160 | 160 | throw new PENSException(1430); |
| 161 | 161 | } |
| 162 | 162 | $supported_package_formats = $this->_package_handler->getSupportedPackageFormats(); |
| 163 | - if(!in_array($request->getPackageFormat(), $supported_package_formats)) { |
|
| 163 | + if (!in_array($request->getPackageFormat(), $supported_package_formats)) { |
|
| 164 | 164 | throw new PENSException(1431); |
| 165 | 165 | } |
| 166 | - if(!$this->isExpiryDateValid($request->getPackageUrlExpiry())) { |
|
| 166 | + if (!$this->isExpiryDateValid($request->getPackageUrlExpiry())) { |
|
| 167 | 167 | throw new PENSException(1322); |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // Try to download the package in the temporary directory |
| 171 | 171 | $tmp = null; |
| 172 | - if(function_exists("sys_get_temp_dir")) { |
|
| 172 | + if (function_exists("sys_get_temp_dir")) { |
|
| 173 | 173 | $tmp = sys_get_temp_dir(); |
| 174 | 174 | } else { |
| 175 | 175 | $tmp = "/tmp"; |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | curl_setopt($ch, CURLOPT_URL, $request->getPackageUrl()); |
| 181 | 181 | curl_setopt($ch, CURLOPT_HEADER, false); |
| 182 | 182 | curl_setopt($ch, CURLOPT_FILE, $fp); |
| 183 | - if(!is_null($request->getPackageUrlUserId())) { |
|
| 183 | + if (!is_null($request->getPackageUrlUserId())) { |
|
| 184 | 184 | curl_setopt($ch, CURLOPT_USERPWD, $request->getPackageUrlUserId().":".$request->getPackageUrlPassword()); |
| 185 | 185 | } |
| 186 | - if(curl_exec($ch) === false) { |
|
| 186 | + if (curl_exec($ch) === false) { |
|
| 187 | 187 | $errno = curl_errno($ch); |
| 188 | 188 | curl_close($ch); |
| 189 | 189 | // Error occured. Throw an exception |
| 190 | - switch($errno) { |
|
| 190 | + switch ($errno) { |
|
| 191 | 191 | case CURLE_UNSUPPORTED_PROTOCOL: |
| 192 | 192 | throw new PENSException(1301); |
| 193 | 193 | break; |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | date_default_timezone_set('UTC'); |
| 224 | 224 | $current_time = time(); |
| 225 | 225 | $expiry_time = strtotime($expiry->format(DateTime::ISO8601)); |
| 226 | - if($current_time > $expiry_time) { |
|
| 226 | + if ($current_time > $expiry_time) { |
|
| 227 | 227 | return false; |
| 228 | 228 | } else { |
| 229 | 229 | return true; |
@@ -239,17 +239,17 @@ discard block |
||
| 239 | 239 | * @return PENSResponse Response |
| 240 | 240 | */ |
| 241 | 241 | protected function sendAlertOrReceipt($request, $response, $mode) { |
| 242 | - if($mode == "alert") { |
|
| 242 | + if ($mode == "alert") { |
|
| 243 | 243 | $url = $request->getAlerts(); |
| 244 | 244 | } else { |
| 245 | 245 | $url = $request->getReceipt(); |
| 246 | 246 | } |
| 247 | - if(!empty($url)) { |
|
| 247 | + if (!empty($url)) { |
|
| 248 | 248 | $url_components = parse_url($url); |
| 249 | 249 | $scheme = $url_components["scheme"]; |
| 250 | - if($scheme == "mailto") { |
|
| 250 | + if ($scheme == "mailto") { |
|
| 251 | 251 | $to = $url_components["path"]; |
| 252 | - if($mode == "alert") { |
|
| 252 | + if ($mode == "alert") { |
|
| 253 | 253 | $subject = "PENS Alert for ".$request->getPackageId(); |
| 254 | 254 | } else { |
| 255 | 255 | $subject = "PENS Receipt for ".$request->getPackageId(); |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | $message = $response->__toString(); |
| 258 | 258 | mail($to, $subject, $message); |
| 259 | 259 | return new PENSResponse(0, ""); |
| 260 | - } else if($scheme == "http" || $scheme == "https") { |
|
| 261 | - if($mode == "alert") { |
|
| 260 | + } else if ($scheme == "http" || $scheme == "https") { |
|
| 261 | + if ($mode == "alert") { |
|
| 262 | 262 | $params = array_merge($request->getSendAlertArray(), $response->getArray()); |
| 263 | 263 | } else { |
| 264 | 264 | $params = array_merge($request->getSendReceiptArray(), $response->getArray()); |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 270 | 270 | $data = curl_exec($ch); |
| 271 | 271 | curl_close($ch); |
| 272 | - if($data === false) { |
|
| 272 | + if ($data === false) { |
|
| 273 | 273 | return null; |
| 274 | 274 | } else { |
| 275 | 275 | return new PENSResponse($data); |
@@ -27,10 +27,10 @@ discard block |
||
| 27 | 27 | * @licence http://www.gnu.org/licenses/gpl.txt |
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | -require_once __DIR__ . '/pens_exception.php'; |
|
| 31 | -require_once __DIR__ . '/pens_request_receipt.php'; |
|
| 32 | -require_once __DIR__ . '/pens_request_collect.php'; |
|
| 33 | -require_once __DIR__ . '/pens_request_alert.php'; |
|
| 30 | +require_once __DIR__.'/pens_exception.php'; |
|
| 31 | +require_once __DIR__.'/pens_request_receipt.php'; |
|
| 32 | +require_once __DIR__.'/pens_request_collect.php'; |
|
| 33 | +require_once __DIR__.'/pens_request_alert.php'; |
|
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | 36 | * PENSRequestFactory |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | public static function createPENSRequest($arguments) { |
| 57 | 57 | $command = $arguments["command"]; |
| 58 | - if($command == "alert") { |
|
| 58 | + if ($command == "alert") { |
|
| 59 | 59 | return new PENSRequestAlert($arguments); |
| 60 | - } else if($command == "collect") { |
|
| 60 | + } else if ($command == "collect") { |
|
| 61 | 61 | return new PENSRequestCollect($arguments); |
| 62 | - } else if($command == "receipt") { |
|
| 62 | + } else if ($command == "receipt") { |
|
| 63 | 63 | return new PENSRequestReceipt($arguments); |
| 64 | 64 | } else { |
| 65 | 65 | throw new PENSException(2002); |