Push your Drupal Site's Events to your Phone with Pushover

Ok, I know, but I haven’t talking about finger, but about the moon.

Nested ifs, globals, simple comparisons, code not clear, not spaces, etc…

Here my constructive contribution to this article, using same functions and idea about Drupal.

<?php
define('PUSHOVER_APP_TOKEN', 'aKH8Nwsdasdanl342jmsdaBWgoVe');
define('PUSHOVER_USER_TOKEN', 'uCpygdjfsndfi7233sdasdo33Yv');

function pushover_send($vars)
{
    if (!defined('PUSHOVER_APP_TOKEN') || !defined('PUSHOVER_USER_TOKEN')) {
        return false;
    }

    $error = false;

    $push = new Pushover();
    $push->setToken(PUSHOVER_APP_TOKEN);
    $push->setUser(PUSHOVER_APP_TOKEN);
    $push->setTimestamp(time());

    if (array_key_exists('error', $vars)) {
        $error = $vars['error'];
        unset($vars['error']);
    }

    foreach ($vars as $key => $value) {
        if (method_exists($push, $key)) {
            call_user_func_array(array($push, 'set'.$key), array($value));
        }
    }

    if ($push->send()) {
        return true;
    }

    if ($error) {
        watchdog('Pushover', $error, array(), WATCHDOG_ERROR, NULL);
    }

    return false;
}

/**
* Implements hook_comment_insert().
*/
function pushover_comment_insert($comment) {
    if (($comment->status !== 0) || ($comment->is_anonymous !== true)) {
        return false;
    }

    return pushover_send(array(
        'title' => 'New comment on ' . variable_get('site_name') . '!',
        'message' => 'Subject: ' . $comment->subject,
        'url' => url('/node/'.$comment->nid.'#comment-'.$comment->cid, array('absolute' => true)),
        'device' => 'Nexus',
        'error' => t('A comment has been created but there was an error pushing that over.')
    ));
}

/**
* Implements hook_user_login().
*/
function pushover_user_login($account) {
    if (($account->uid !== 1) || in_array(ip_address(), array('1.1.1.1'))) {
        return false;
    }

    return pushover_send(array(
        'title' => 'Admin user sign in',
        'message' => 'Admin user has logged into this site: '.variable_get('site_name').'!',
        'url' => url('/', array('absolute' => true)),
        'priority' => 2,
        'retry' => 30,
        'expire' => 60,
        'error' => t('An admin user has logged into the site but there was an error pushing this over.')
    ));
}

Do you think that this code is enough professional and clear?

Anyway, thanks for your article and sorry my lack of tact.
Lito.