'. t("This module provides Drupal status notifications and an API for the Prowl iPhone push notification client.") .'

'; break; } return $output; } // function prowl_help /** * Valid permissions for this module * @return array An array of valid permissions for the prowl module */ function prowl_perm() { return array('Receive prowl notifications', 'Administer prowl notifications'); } // function prowl_perm() /** * Prowl administration settings Menu * @return array administration menu array */ function prowl_admin() { // check for curl if (!in_array('curl', get_loaded_extensions())) { drupal_set_message('The cURL extension was not detected - you will need to install it before the prowl module will work - see http://www.php.net/curl', 'error'); } else { $curl_version = (curl_version()); if ($curl_version['ssl_version'] == '') { drupal_set_message('The cURL SSL extensions were not detected - you will need to install phpCurl with SSL support before the prowl module will work - see http://www.php.net/curl', 'error'); } } $form = array(); $form['api_key_info'] = array( '#type' => 'fieldset', '#title' => t('API Key settings'), '#weight' => -1, '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['api_key_info']['prowl_admin_api_key'] = array( '#type' => 'textfield', '#title' => t('API key for the prowl account to which to send system notifications.'), '#default_value' => variable_get('prowl_admin_api_key', ''), '#size' => 40, '#maxlength' => 40, '#description' => t("Go to https://prowl.weks.net/settings.php to view/generate your API key ."), '#required' => TRUE, ); $form['api_key_info']['test_button'] = array( '#type' => 'submit', '#value' => t('Send a test notification'), '#submit' => array('prowl_send_admin_notification_test'), ); $form['system_notifications'] = array( '#type' => 'fieldset', '#title' => t('System Notification Settings'), '#weight' => 0, '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form['system_notifications']['prowl_send_module_updates'] = array( '#type' => 'select', '#title' => t('Send module status update information'), '#default_value' => variable_get('prowl_send_module_updates', 'none'), '#options' => array( 'none' => t('None'), 'sec' => t('Modules with security updates only'), 'all' => t('All modules with updates'), ), '#description' => t('Send push notifications when Drupal core and contributed module updates are available'), ); // disable module updates menu if update status module is disabled if (!module_exists('update')) { $form['prowl_send_module_updates']['#disabled'] = True; $form['prowl_send_module_updates']['#description'] = t('You must enable the update status module to use this feature.'); } return system_settings_form($form); } // function prowl_admin() /** * Implementation of hook_menu() */ function prowl_menu() { $items = array(); $items['admin/settings/prowl'] = array( 'title' => 'Prowl push notifications', 'description' => 'Set up Prowl push notifications here.', 'page callback' => 'drupal_get_form', 'page arguments' => array('prowl_admin'), 'access arguments' => array('Administer prowl notifications'), 'type' => MENU_NORMAL_ITEM, ); return $items; } /** * Implementation of hook_cron(). */ function prowl_cron() { if (module_exists('update') && variable_get('prowl_send_module_updates', 'none') != 'none') { // cribbed most of this from update.module $frequency = variable_get('prowl_send_update_frequency', 1); $interval = 60 * 60 * 24 * $frequency; if ((time() - variable_get('prowl_update_last_check', 0)) > $interval) { $status = update_requirements('runtime'); $message_text = ''; $priority = PROWL_MODERATE; $notify_all = (variable_get('prowl_send_module_updates', 'none') == 'all'); foreach (array('core', 'contrib') as $report_type) { $type = 'update_'. $report_type; if (isset($status[$type]['severity']) && ($status[$type]['severity'] == REQUIREMENT_ERROR || ($notify_all && $status[$type]['reason'] == UPDATE_NOT_CURRENT))) { if ($status[$type]['severity'] == REQUIREMENT_ERROR) $priority = PROWL_HIGH; $message_text = $status[$type]['title'] . "\n"; $message_text .= $status[$type]['description'] . "\n"; $message_text .= "\n\n"; } } if ($message_text .= '') { // Send prowl notification to admin(s) prowl_send_admin_notification($message_text, 'updates available', $priority); } variable_set('prowl_update_last_check', time()); } } } /** * Send prowl notification to site admin(s) * @return boolean success */ function prowl_send_admin_notification($message, $event, $priority = PROWL_MODERATE, $application = PROWL_APPLICATION) { $success = True; if ($apikey = variable_get('prowl_admin_api_key', '')) { $prowl = new Prowl($apikey); $prowl->push(array( 'application' => $application, 'event' => $event, 'description' => $message, 'priority' => $priority, )); if (PROWL_DEBUG) { watchdog('prowl', 'api key: %apikey | priority: %priority | message: %message | event: %event | application: %application', array('%apikey' => $apikey, '%message' => $message, '%priority' => $priority, '%event' => $event, '%application' => $application), WATCHDOG_ERROR); } // log errors (if any) if ($prowl_errors = $prowl->getError()) { watchdog('prowl', 'Push Notification Error: %error', array('%error' => $prowl_errors), WATCHDOG_ERROR); $success = False; } } return $success; } // prowl_send_admin_notification() /** * Send test prowl notification to site admin(s) * @return boolean success */ function prowl_send_admin_notification_test() { return prowl_send_admin_notification('mic check 1 2', 'notification test'); } // prowl_send_admin_notification_test()