Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PushoverClient
- {
- private $settings = [];
- public function __construct(array $settings)
- {
- foreach (['app_token', 'user_token', 'base_url'] as $option) {
- if (empty($settings[$option])) {
- throw new Exception(t('Setting %s is required to Pushover', $option));
- }
- }
- $this->settings = $settings;
- }
- private function getClient()
- {
- $client = new Pushover();
- $client->setToken($this->settings['app_token']);
- $client->setUser($this->settings['user_token']);
- $client->setTimestamp(time());
- return $client;
- }
- public function userLogin($account)
- {
- if (((int)$account->uid !== 1) || in_array(ip_address(), ['1.1.1.1'])) {
- return false;
- }
- $client = $this->getClient();
- $client->setTitle('Admin user sign in');
- $client->setMessage('Admin user has logged into this site: '.variable_get('site_name').'!');
- $client->setUrl($this->settings['base_url']);
- $client->setPriority(2);
- $client->setRetry(30);
- $client->setExpire(60);
- if ($client->send()) {
- return true;
- }
- watchdog('Pushover', t('An admin user has logged into the site but there was an error pushing this over.'), [], WATCHDOG_ERROR, NULL);
- return false;
- }
- public function commentInsert($comment)
- {
- if (((int)$comment->status !== 0) || ($comment->is_anonymous !== true)) {
- return false;
- }
- $client = $this->getClient();
- $client->setTitle('New comment on '.variable_get('site_name').'!');
- $client->setMessage('Subject: '.$comment->subject);
- $client->setUrl($this->settings['base_url'].'/node/'.$comment->nid.'#comment-'.$comment->cid);
- $client->setDevice('Nexus');
- if ($client->send()) {
- return true;
- }
- watchdog('Pushover', t('A comment has been created but there was an error pushing that over.'), [], WATCHDOG_ERROR, NULL);
- return false;
- }
- }
- $Pushover = new PushoverClient([
- 'user_token' => 'uCpygdjfsndfi7233sdasdo33Yv',
- 'app_token' => 'aKH8Nwsdasdanl342jmsdaBWgoVe',
- 'base_url' => '/'
- ]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement