Completed
Pull Request — development (#2540)
by
unknown
03:04
created

Notifications_Pushover::notify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 3
1
<?php
2
	class Notifications_Pushover implements IPushNotification {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
3
		
4
		private $token;
5
		private $user;
6
		public function __construct($token, $user){
7
			$this->token = $token;
8
			$this->user = $user;
9
		}
10
		
11
		static $priorities = array(
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $priorities.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
12
			0 => 'info',
13
			1 => 'warning',
14
			2 => 'error',
15
		);
16
		
17
		public static function getName(){
18
			return  "pushover.net";
19
		}
20
		
21
		public static function getParameters(){
22
			return array(
23
				'token' => 'API Token/Key',
24
				'user' => 'Your User Key',
25
			);
26
		}
27
		
28
		public function notify($message, $severity = 'info', $event = null){
29
			curl_setopt_array($ch = curl_init(), array(
30
				CURLOPT_URL => "https://api.pushover.net/1/messages.json",
31
				CURLOPT_POST => true,
32
				CURLOPT_RETURNTRANSFER => true,
33
				CURLOPT_POSTFIELDS => http_build_query($data = array(
34
					"token" => $this->token,
35
					"user" => $this->user,
36
					"message" => $code = strip_tags(preg_replace('/<([\/]?)span[^>]*>/i', '<\1b>', $message), "<b><i><u><a><font><p><br>"),
37
					"title" => strip_tags($event),
38
					"priority" => (int)array_search($severity, self::$priorities),
39
					"timestamp" => time(),
40
					"html" => preg_match('/<[^>]+>/', $code),
41
				)),
42
			));
43
			curl_exec($ch);
44
			curl_close($ch);
45
		}
46
	}