Changeset 2770094
- Timestamp:
- 08/13/2022 11:31:33 AM (4 years ago)
- Location:
- notify-events/trunk
- Files:
-
- 4 edited
-
notify-events.php (modified) (1 diff)
-
php/Message.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
views/layout/default.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
notify-events/trunk/notify-events.php
r2532490 r2770094 6 6 Author: Notify.Events 7 7 Author URI: https://notify.events/ 8 Version: 1.3. 08 Version: 1.3.1 9 9 License: GPL-2.0 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
notify-events/trunk/php/Message.php
r2383243 r2770094 12 12 class Message 13 13 { 14 const PRIORITY_LOWEST = 'lowest'; 15 const PRIORITY_LOW = 'low'; 16 const PRIORITY_NORMAL = 'normal'; 17 const PRIORITY_HIGH = 'high'; 18 const PRIORITY_HIGHEST = 'highest'; 19 20 const LEVEL_VERBOSE = 'verbose'; 21 const LEVEL_INFO = 'info'; 22 const LEVEL_NOTICE = 'notice'; 23 const LEVEL_WARNING = 'warning'; 24 const LEVEL_ERROR = 'error'; 25 const LEVEL_SUCCESS = 'success'; 26 27 /** @var string */ 28 protected static $_baseUrl = 'https://notify.events/api/v1/channel/source/%s/execute'; 29 30 /** @var string */ 31 protected $_title; 32 /** @var string */ 33 protected $_content; 34 /** @var string */ 35 protected $_priority; 36 /** @var string */ 37 protected $_level; 38 39 CONST FILE_TYPE_FILE = 'file'; 40 CONST FILE_TYPE_CONTENT = 'content'; 41 CONST FILE_TYPE_URL = 'url'; 42 43 /** @var array */ 44 protected $_files = []; 45 /** @var array */ 46 protected $_images = []; 47 48 /** 49 * Message constructor. 50 * 51 * @param string $content Message text 52 * @param string $title Message title 53 * @param string $priority Priority 54 * @param string $level Level 55 */ 56 public function __construct($content = '', $title = '', $priority = self::PRIORITY_NORMAL, $level = self::LEVEL_INFO) 57 { 58 $this 59 ->setTitle($title) 60 ->setContent($content) 61 ->setPriority($priority) 62 ->setLevel($level); 63 } 64 65 /** 66 * Prepares a param to sending. 67 * 68 * @param string $boundary 69 * @param string $name 70 * @param string $content 71 * @return string 72 */ 73 protected static function prepareParam($boundary, $name, $content) 74 { 75 return self::prepareBoundaryPart($boundary, $content, [ 76 'Content-Disposition' => 'form-data; name="' . $name . '"', 77 'Content-Type' => 'text/plain; charset=utf-8', 78 ]); 79 } 80 81 /** 82 * Prepares a boundary param part for file. 83 * 84 * @param string $boundary 85 * @param string $name 86 * @param array $files 87 * @return string 88 * @throws ErrorException 89 */ 90 protected static function boundaryFiles($boundary, $name, $files) 91 { 92 $result = ''; 93 94 foreach ($files as $idx => $file) { 95 switch ($file['type']) { 96 case self::FILE_TYPE_FILE: { 97 $content = file_get_contents($file['fileName']); 98 $fileName = basename($file['fileName']); 99 $mimeType = !empty($file['mimeType']) ? $file['mimeType'] : (extension_loaded('fileinfo') ? mime_content_type($file['fileName']) : 'application/octet-stream'); 100 } break; 101 case self::FILE_TYPE_CONTENT: { 102 $content = $file['content']; 103 $fileName = !empty($file['fileName']) ? $file['fileName'] : 'file.dat'; 104 $mimeType = !empty($file['mimeType']) ? $file['mimeType'] : 'application/octet-stream'; 105 } break; 106 case self::FILE_TYPE_URL: { 107 $content = file_get_contents($file['url']); 108 $fileName = !empty($file['fileName']) ? $file['fileName'] : basename($file['url']); 109 $mimeType = !empty($file['mimeType']) ? $file['mimeType'] : 'application/octet-stream'; 110 } break; 111 default: { 112 throw new ErrorException('Unknown file type'); 113 } 114 } 115 116 $result .= self::prepareBoundaryPart($boundary, $content, [ 117 'Content-Disposition' => 'form-data; name="' . $name . '[' . $idx . ']"; filename="' . $fileName . '"', 118 'Content-Type' => $mimeType, 119 ]); 120 } 121 122 return $result; 123 } 124 125 /** 126 * Prepares a boundary param part. 127 * 128 * @param string $boundary 129 * @param string $content 130 * @param string[] $headers 131 * @return string 132 */ 133 protected static function prepareBoundaryPart($boundary, $content, $headers) 134 { 135 $headers['Content-Length'] = strlen($content); 136 137 $result = '--' . $boundary . PHP_EOL; 138 139 foreach ($headers as $key => $value) { 140 $result .= $key . ': ' . $value . PHP_EOL; 141 } 142 143 $result .= PHP_EOL; 144 $result .= $content . PHP_EOL; 145 146 return $result; 147 } 148 149 /** 150 * Sends the message to the specified channel. 151 * You can get the source token when connecting the PHP source 152 * to your channel on the Notify.Events service side. 153 * 154 * @param string $token Source token 155 * @return void 156 * @throws ErrorException 157 */ 158 public function send($token) 159 { 160 $url = sprintf(self::$_baseUrl, $token); 161 162 $boundary = uniqid(); 163 164 $content = ''; 165 166 if (!empty($this->_title)) { 167 $content .= self::prepareParam($boundary, 'title', $this->_title); 168 } 169 170 $content .= self::prepareParam($boundary, 'content', $this->_content); 171 $content .= self::prepareParam($boundary, 'priority', $this->_priority); 172 $content .= self::prepareParam($boundary, 'level', $this->_level); 173 174 $content .= self::boundaryFiles($boundary, 'files', $this->_files); 175 $content .= self::boundaryFiles($boundary, 'images', $this->_images); 176 177 $content .= '--' . $boundary . '--'; 178 179 $context = stream_context_create([ 180 'http' => [ 181 'method' => 'POST', 182 'header' => 183 'Content-Type: multipart/form-data; boundary="' . $boundary . '"' . PHP_EOL . 184 'Content-Length: ' . strlen($content) . PHP_EOL, 185 'content' => $content, 186 ], 187 ]); 188 189 file_get_contents($url, false, $context); 190 } 191 192 /** 193 * Sets the value of the Title property. 194 * 195 * @param string $title Message title 196 * @return $this 197 */ 198 public function setTitle($title) 199 { 200 $this->_title = $title; 201 202 return $this; 203 } 204 205 /** 206 * Returns the value of the Title property. 207 * 208 * @return string 209 */ 210 public function getTitle() 211 { 212 return $this->_title; 213 } 214 215 /** 216 * Sets the value of the Content property. 217 * 218 * @param string $content Message content 219 * @return $this 220 */ 221 public function setContent($content) 222 { 223 $this->_content = $content; 224 225 return $this; 226 } 227 228 /** 229 * Returns the value of the Content property. 230 * 231 * @return string 232 */ 233 public function getContent() 234 { 235 return $this->_content; 236 } 237 238 /** 239 * Sets the value of the Priority property. 240 * For recipients which supports priority, the message will be highlighted accordingly. 241 * This method checks that $priority is in the list of available message priorities. 242 * 243 * @param string $priority Message priority 244 * @return $this 245 */ 246 public function setPriority($priority) 247 { 248 if (!in_array($priority, [ 249 self::PRIORITY_LOWEST, 250 self::PRIORITY_LOW, 251 self::PRIORITY_NORMAL, 252 self::PRIORITY_HIGH, 253 self::PRIORITY_HIGHEST, 254 ])) { 255 throw new InvalidArgumentException('Invalid priority value'); 256 } 257 258 $this->_priority = $priority; 259 260 return $this; 261 } 262 263 /** 264 * Returns the value of the Priority property. 265 * 266 * @return string 267 */ 268 public function getPriority() 269 { 270 return $this->_priority; 271 } 272 273 /** 274 * Sets the value of the Level property. 275 * This method checks that $level is in the list of available message levels. 276 * For recipients which have differences in the display of messages at different levels, this level will be applied. 277 * 278 * @param string $level Message Level 279 * @return $this 280 */ 281 public function setLevel($level) 282 { 283 if (!in_array($level, [ 284 self::LEVEL_VERBOSE, 285 self::LEVEL_INFO, 286 self::LEVEL_NOTICE, 287 self::LEVEL_WARNING, 288 self::LEVEL_ERROR, 289 self::LEVEL_SUCCESS, 290 ])) { 291 throw new InvalidArgumentException('Invalid level value'); 292 } 293 294 $this->_level = $level; 295 296 return $this; 297 } 298 299 /** 300 * Returns the value of the Level property. 301 * 302 * @return string 303 */ 304 public function getLevel() 305 { 306 return $this->_level; 307 } 308 309 /** 310 * Adds a new File by local file path 311 * to the message attached files list. 312 * 313 * @param string $filePath Local file path 314 * @param string|null $fileName Attachment file name 315 * @param string|null $mimeType Attachment file MimeType 316 * @return $this 317 */ 318 public function addFile($filePath, $fileName = null, $mimeType = null) 319 { 320 $this->_files[] = [ 321 'type' => self::FILE_TYPE_FILE, 322 'fileName' => $fileName ?: basename($filePath), 323 'mimeType' => $mimeType, 324 ]; 325 326 return $this; 327 } 328 329 /** 330 * Adds a new File by content 331 * to the message attached files list. 332 * 333 * @param string $content File content 334 * @param string|null $fileName Attachment file name 335 * @param string|null $mimeType Attachment file MimeType 336 * @return $this 337 */ 338 public function addFileFromContent($content, $fileName = null, $mimeType = null) 339 { 340 $this->_files[] = [ 341 'type' => self::FILE_TYPE_CONTENT, 342 'content' => $content, 343 'fileName' => $fileName, 344 'mimeType' => $mimeType, 345 ]; 346 347 return $this; 348 } 349 350 /** 351 * Adds a new File by URL 352 * to the message attached files list. 353 * 354 * @param string $url File remote URL 355 * @param string|null $fileName Attachment file name 356 * @param string|null $mimeType Attachment file MimeType 357 * @return $this 358 */ 359 public function addFileFromUrl($url, $fileName = null, $mimeType = null) 360 { 361 $this->_files[] = [ 362 'type' => self::FILE_TYPE_URL, 363 'url' => $url, 364 'fileName' => $fileName, 365 'mimeType' => $mimeType, 366 ]; 367 368 return $this; 369 } 370 371 /** 372 * Adds a new Image by filename 373 * to the message attached images list. 374 * 375 * @param string $filePath Local file path 376 * @param string|null $fileName Attachment file name 377 * @param string|null $mimeType Attachment file MimeType 378 * @return $this 379 */ 380 public function addImage($filePath, $fileName = null, $mimeType = null) 381 { 382 $this->_images[] = [ 383 'type' => self::FILE_TYPE_FILE, 384 'fileName' => $fileName ?: basename($filePath), 385 'mimeType' => $mimeType, 386 ]; 387 388 return $this; 389 } 390 391 /** 392 * Adds a new Image by content 393 * to the message attached images list. 394 * 395 * @param string $content File content 396 * @param string|null $fileName Attachment file name 397 * @param string|null $mimeType Attachment file MimeType 398 * @return $this 399 */ 400 public function addImageFromContent($content, $fileName = null, $mimeType = null) 401 { 402 $this->_images[] = [ 403 'type' => self::FILE_TYPE_CONTENT, 404 'content' => $content, 405 'fileName' => $fileName, 406 'mimeType' => $mimeType, 407 ]; 408 409 return $this; 410 } 411 412 /** 413 * Adds a new Image by URL 414 * to the message attached images list. 415 * 416 * @param string $url File remote URL 417 * @param string|null $fileName Attachment file name 418 * @param string|null $mimeType Attachment file MimeType 419 * @return $this 420 */ 421 public function addImageFromUrl($url, $fileName = null, $mimeType = null) 422 { 423 $this->_images[] = [ 424 'type' => self::FILE_TYPE_URL, 425 'url' => $url, 426 'fileName' => $fileName, 427 'mimeType' => $mimeType, 428 ]; 429 430 return $this; 431 } 14 const PRIORITY_LOWEST = 'lowest'; 15 const PRIORITY_LOW = 'low'; 16 const PRIORITY_NORMAL = 'normal'; 17 const PRIORITY_HIGH = 'high'; 18 const PRIORITY_HIGHEST = 'highest'; 19 20 const LEVEL_VERBOSE = 'verbose'; 21 const LEVEL_INFO = 'info'; 22 const LEVEL_NOTICE = 'notice'; 23 const LEVEL_WARNING = 'warning'; 24 const LEVEL_ERROR = 'error'; 25 const LEVEL_SUCCESS = 'success'; 26 27 const CALLBACK_METHOD_HEAD = 'head'; 28 const CALLBACK_METHOD_GET = 'get'; 29 const CALLBACK_METHOD_POST = 'post'; 30 const CALLBACK_METHOD_PUT = 'put'; 31 const CALLBACK_METHOD_PATCH = 'patch'; 32 const CALLBACK_METHOD_DELETE = 'delete'; 33 34 /** @var string */ 35 protected static $_baseUrl = 'https://notify.events/api/v1/channel/source/%s/execute'; 36 37 /** @var string */ 38 protected $_title; 39 /** @var string */ 40 protected $_content; 41 /** @var string */ 42 protected $_priority; 43 /** @var string */ 44 protected $_level; 45 46 CONST FILE_TYPE_FILE = 'file'; 47 CONST FILE_TYPE_CONTENT = 'content'; 48 CONST FILE_TYPE_URL = 'url'; 49 50 /** @var array */ 51 protected $_files = []; 52 /** @var array */ 53 protected $_images = []; 54 /** @var array */ 55 protected $_actions = []; 56 57 /** 58 * Message constructor. 59 * 60 * @param string $content Message text 61 * @param string $title Message title 62 * @param string $priority Priority 63 * @param string $level Level 64 */ 65 public function __construct($content = '', $title = '', $priority = self::PRIORITY_NORMAL, $level = self::LEVEL_INFO) 66 { 67 $this 68 ->setTitle($title) 69 ->setContent($content) 70 ->setPriority($priority) 71 ->setLevel($level); 72 } 73 74 /** 75 * Prepares a param to sending. 76 * 77 * @param string $boundary 78 * @param string $name 79 * @param string $content 80 * @return string 81 */ 82 protected static function prepareParam($boundary, $name, $content) 83 { 84 return self::prepareBoundaryPart($boundary, $content, [ 85 'Content-Disposition' => 'form-data; name="' . $name . '"', 86 'Content-Type' => 'text/plain; charset=utf-8', 87 ]); 88 } 89 90 /** 91 * Prepares a boundary param part for file. 92 * 93 * @param string $boundary 94 * @param string $name 95 * @param array $files 96 * @return string 97 * @throws ErrorException 98 */ 99 protected static function boundaryFiles($boundary, $name, $files) 100 { 101 $result = ''; 102 103 foreach ($files as $idx => $file) { 104 switch ($file['type']) { 105 case self::FILE_TYPE_FILE: { 106 $content = file_get_contents($file['fileName']); 107 $fileName = basename($file['fileName']); 108 $mimeType = !empty($file['mimeType']) ? $file['mimeType'] : (extension_loaded('fileinfo') ? mime_content_type($file['fileName']) : 'application/octet-stream'); 109 } break; 110 case self::FILE_TYPE_CONTENT: { 111 $content = $file['content']; 112 $fileName = !empty($file['fileName']) ? $file['fileName'] : 'file.dat'; 113 $mimeType = !empty($file['mimeType']) ? $file['mimeType'] : 'application/octet-stream'; 114 } break; 115 case self::FILE_TYPE_URL: { 116 $content = file_get_contents($file['url']); 117 $fileName = !empty($file['fileName']) ? $file['fileName'] : basename($file['url']); 118 $mimeType = !empty($file['mimeType']) ? $file['mimeType'] : 'application/octet-stream'; 119 } break; 120 default: { 121 throw new ErrorException('Unknown file type'); 122 } 123 } 124 125 $result .= self::prepareBoundaryPart($boundary, $content, [ 126 'Content-Disposition' => 'form-data; name="' . $name . '[' . $idx . ']"; filename="' . $fileName . '"', 127 'Content-Type' => $mimeType, 128 ]); 129 } 130 131 return $result; 132 } 133 134 /** 135 * Prepares a boundary param part. 136 * 137 * @param string $boundary 138 * @param string $content 139 * @param string[] $headers 140 * @return string 141 */ 142 protected static function prepareBoundaryPart($boundary, $content, $headers) 143 { 144 $headers['Content-Length'] = strlen($content); 145 146 $result = '--' . $boundary . PHP_EOL; 147 148 foreach ($headers as $key => $value) { 149 $result .= $key . ': ' . $value . PHP_EOL; 150 } 151 152 $result .= PHP_EOL; 153 $result .= $content . PHP_EOL; 154 155 return $result; 156 } 157 158 /** 159 * @return bool 160 */ 161 protected static function capabilityCheckFOpen() 162 { 163 return ini_get('allow_url_fopen') == '1'; 164 } 165 166 /** 167 * @return bool 168 */ 169 protected static function capabilityCheckCurl() 170 { 171 return function_exists('curl_init'); 172 } 173 174 /** 175 * Capability check. 176 * 177 * @return bool 178 */ 179 public static function capabilityCheck() 180 { 181 return static::capabilityCheckFOpen() || static::capabilityCheckCurl(); 182 } 183 184 /** 185 * Sends the message to the specified channel. 186 * You can get the source token when connecting the PHP source 187 * to your channel on the Notify.Events service side. 188 * 189 * @param string $token Source token 190 * @return void 191 * @throws ErrorException 192 */ 193 public function send($token) 194 { 195 $url = sprintf(self::$_baseUrl, $token); 196 197 $boundary = uniqid(); 198 199 $content = ''; 200 201 if (!empty($this->_title)) { 202 $content .= self::prepareParam($boundary, 'title', $this->_title); 203 } 204 205 $content .= self::prepareParam($boundary, 'content', $this->_content); 206 $content .= self::prepareParam($boundary, 'priority', $this->_priority); 207 $content .= self::prepareParam($boundary, 'level', $this->_level); 208 209 $content .= self::boundaryFiles($boundary, 'files', $this->_files); 210 $content .= self::boundaryFiles($boundary, 'images', $this->_images); 211 212 $content .= '--' . $boundary . '--'; 213 214 if (static::capabilityCheckFOpen()) { 215 216 $context = stream_context_create([ 217 'http' => [ 218 'method' => 'POST', 219 'header' => 220 'Content-Type: multipart/form-data; boundary="' . $boundary . '"' . PHP_EOL . 221 'Content-Length: ' . strlen($content) . PHP_EOL, 222 'content' => $content, 223 ], 224 ]); 225 226 file_get_contents($url, false, $context); 227 228 } elseif (static::capabilityCheckCurl()) { 229 230 static $curl; 231 232 if ($curl === null) { 233 $curl = curl_init(); 234 } 235 236 curl_setopt_array($curl, [ 237 CURLOPT_URL => $url, 238 CURLOPT_HTTPHEADER => [ 239 'Content-Type: multipart/form-data; boundary="' . $boundary . '"', 240 'Content-Length: ' . strlen($content), 241 ], 242 CURLOPT_POST => true, 243 CURLOPT_POSTFIELDS => $content, 244 ]); 245 246 curl_exec($curl); 247 248 } else { 249 throw new ErrorException('Can\'t detect capability method for sending!'); 250 } 251 } 252 253 /** 254 * Sets the value of the Title property. 255 * 256 * @param string $title Message title 257 * @return $this 258 */ 259 public function setTitle($title) 260 { 261 $this->_title = $title; 262 263 return $this; 264 } 265 266 /** 267 * Returns the value of the Title property. 268 * 269 * @return string 270 */ 271 public function getTitle() 272 { 273 return $this->_title; 274 } 275 276 /** 277 * Sets the value of the Content property. 278 * 279 * @param string $content Message content 280 * @return $this 281 */ 282 public function setContent($content) 283 { 284 $this->_content = $content; 285 286 return $this; 287 } 288 289 /** 290 * Returns the value of the Content property. 291 * 292 * @return string 293 */ 294 public function getContent() 295 { 296 return $this->_content; 297 } 298 299 /** 300 * Sets the value of the Priority property. 301 * For recipients which supports priority, the message will be highlighted accordingly. 302 * This method checks that $priority is in the list of available message priorities. 303 * 304 * @param string $priority Message priority 305 * @return $this 306 */ 307 public function setPriority($priority) 308 { 309 if (!in_array($priority, [ 310 self::PRIORITY_LOWEST, 311 self::PRIORITY_LOW, 312 self::PRIORITY_NORMAL, 313 self::PRIORITY_HIGH, 314 self::PRIORITY_HIGHEST, 315 ])) { 316 throw new InvalidArgumentException('Invalid priority value'); 317 } 318 319 $this->_priority = $priority; 320 321 return $this; 322 } 323 324 /** 325 * Returns the value of the Priority property. 326 * 327 * @return string 328 */ 329 public function getPriority() 330 { 331 return $this->_priority; 332 } 333 334 /** 335 * Sets the value of the Level property. 336 * This method checks that $level is in the list of available message levels. 337 * For recipients which have differences in the display of messages at different levels, this level will be applied. 338 * 339 * @param string $level Message Level 340 * @return $this 341 */ 342 public function setLevel($level) 343 { 344 if (!in_array($level, [ 345 self::LEVEL_VERBOSE, 346 self::LEVEL_INFO, 347 self::LEVEL_NOTICE, 348 self::LEVEL_WARNING, 349 self::LEVEL_ERROR, 350 self::LEVEL_SUCCESS, 351 ])) { 352 throw new InvalidArgumentException('Invalid level value'); 353 } 354 355 $this->_level = $level; 356 357 return $this; 358 } 359 360 /** 361 * Returns the value of the Level property. 362 * 363 * @return string 364 */ 365 public function getLevel() 366 { 367 return $this->_level; 368 } 369 370 /** 371 * Adds a new File by local file path 372 * to the message attached files list. 373 * 374 * @param string $filePath Local file path 375 * @param string|null $fileName Attachment file name 376 * @param string|null $mimeType Attachment file MimeType 377 * @return $this 378 */ 379 public function addFile($filePath, $fileName = null, $mimeType = null) 380 { 381 $this->_files[] = [ 382 'type' => self::FILE_TYPE_FILE, 383 'fileName' => $fileName ?: basename($filePath), 384 'mimeType' => $mimeType, 385 ]; 386 387 return $this; 388 } 389 390 /** 391 * Adds a new File by content 392 * to the message attached files list. 393 * 394 * @param string $content File content 395 * @param string|null $fileName Attachment file name 396 * @param string|null $mimeType Attachment file MimeType 397 * @return $this 398 */ 399 public function addFileFromContent($content, $fileName = null, $mimeType = null) 400 { 401 $this->_files[] = [ 402 'type' => self::FILE_TYPE_CONTENT, 403 'content' => $content, 404 'fileName' => $fileName, 405 'mimeType' => $mimeType, 406 ]; 407 408 return $this; 409 } 410 411 /** 412 * Adds a new File by URL 413 * to the message attached files list. 414 * 415 * @param string $url File remote URL 416 * @param string|null $fileName Attachment file name 417 * @param string|null $mimeType Attachment file MimeType 418 * @return $this 419 */ 420 public function addFileFromUrl($url, $fileName = null, $mimeType = null) 421 { 422 $this->_files[] = [ 423 'type' => self::FILE_TYPE_URL, 424 'url' => $url, 425 'fileName' => $fileName, 426 'mimeType' => $mimeType, 427 ]; 428 429 return $this; 430 } 431 432 /** 433 * Adds a new Image by filename 434 * to the message attached images list. 435 * 436 * @param string $filePath Local file path 437 * @param string|null $fileName Attachment file name 438 * @param string|null $mimeType Attachment file MimeType 439 * @return $this 440 */ 441 public function addImage($filePath, $fileName = null, $mimeType = null) 442 { 443 $this->_images[] = [ 444 'type' => self::FILE_TYPE_FILE, 445 'fileName' => $fileName ?: basename($filePath), 446 'mimeType' => $mimeType, 447 ]; 448 449 return $this; 450 } 451 452 /** 453 * Adds a new Image by content 454 * to the message attached images list. 455 * 456 * @param string $content File content 457 * @param string|null $fileName Attachment file name 458 * @param string|null $mimeType Attachment file MimeType 459 * @return $this 460 */ 461 public function addImageFromContent($content, $fileName = null, $mimeType = null) 462 { 463 $this->_images[] = [ 464 'type' => self::FILE_TYPE_CONTENT, 465 'content' => $content, 466 'fileName' => $fileName, 467 'mimeType' => $mimeType, 468 ]; 469 470 return $this; 471 } 472 473 /** 474 * Adds a new Image by URL 475 * to the message attached images list. 476 * 477 * @param string $url File remote URL 478 * @param string|null $fileName Attachment file name 479 * @param string|null $mimeType Attachment file MimeType 480 * @return $this 481 */ 482 public function addImageFromUrl($url, $fileName = null, $mimeType = null) 483 { 484 $this->_images[] = [ 485 'type' => self::FILE_TYPE_URL, 486 'url' => $url, 487 'fileName' => $fileName, 488 'mimeType' => $mimeType, 489 ]; 490 491 return $this; 492 } 493 494 /** 495 * @param string $name 496 * @param string $title 497 * @param string|null $callback_url 498 * @param string $callback_method 499 * @param array $callback_headers 500 * @param string $callback_content 501 * @return $this 502 */ 503 public function addAction($name, $title, $callback_url = null, $callback_method = 'get', $callback_headers = [], $callback_content = '') 504 { 505 if (!in_array($callback_method, [ 506 self::CALLBACK_METHOD_HEAD, 507 self::CALLBACK_METHOD_GET, 508 self::CALLBACK_METHOD_POST, 509 self::CALLBACK_METHOD_PUT, 510 self::CALLBACK_METHOD_PATCH, 511 self::CALLBACK_METHOD_DELETE, 512 ])) { 513 throw new InvalidArgumentException('Invalid callback_method value'); 514 } 515 516 $this->_actions[] = [ 517 'name' => $name, 518 'title' => $title, 519 'callback_url' => $callback_url, 520 'callback_method' => $callback_method, 521 'callback_headers' => $callback_headers, 522 'callback_content' => $callback_content, 523 ]; 524 525 return $this; 526 } 432 527 } -
notify-events/trunk/readme.txt
r2719071 r2770094 5 5 Requires PHP: 5.6 6 6 Tested up to: 6.0 7 Stable tag: 1.3. 07 Stable tag: 1.3.1 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
notify-events/trunk/views/layout/default.php
r2383243 r2770094 15 15 use notify_events\models\Controller; 16 16 use notify_events\models\View; 17 use notify_events\php\Message; 17 18 18 19 add_thickbox(); 20 21 if (!Message::capabilityCheck()) { 22 Alert::success(__('Your server configuration does not meet the requirements. Make sure you have the allow_url_fopen directive or cURL support enabled!', WPNE)); 23 } 19 24 20 25 ?>
Note: See TracChangeset
for help on using the changeset viewer.