From 6c3c57b43e35e2a22c516519fea31c31fd2f3ecb Mon Sep 17 00:00:00 2001 From: lolandese Date: Tue, 4 Aug 2015 23:06:51 +0200 Subject: lolandese: Generated with Drush iq --- simplytest/uptime_simplytest.info | 7 ++ simplytest/uptime_simplytest.install | 67 ++++++++++++ simplytest/uptime_simplytest.module | 11 ++ uptime.admin.inc | 53 ++++++++-- uptime.info | 3 +- uptime_widget_test/uptime_widget_test.info | 7 -- uptime_widget_test/uptime_widget_test.install | 135 ------------------------- uptime_widget_test/uptime_widget_test.module | 11 -- 8 files changed, 128 insertions(+), 166 deletions(-) create mode 100644 simplytest/uptime_simplytest.info create mode 100644 simplytest/uptime_simplytest.install create mode 100644 simplytest/uptime_simplytest.module delete mode 100644 uptime_widget_test/uptime_widget_test.info delete mode 100644 uptime_widget_test/uptime_widget_test.install delete mode 100644 uptime_widget_test/uptime_widget_test.module diff --git a/simplytest/uptime_simplytest.info b/simplytest/uptime_simplytest.info new file mode 100644 index 0000000..67eb1cb --- /dev/null +++ b/simplytest/uptime_simplytest.info @@ -0,0 +1,7 @@ +name = Uptime Widget Simplytest +description = A Simplytest.me demo for this module. +version = 7.0 +core = 7.x +hidden = TRUE + +dependencies[] = uptime diff --git a/simplytest/uptime_simplytest.install b/simplytest/uptime_simplytest.install new file mode 100644 index 0000000..6ba2705 --- /dev/null +++ b/simplytest/uptime_simplytest.install @@ -0,0 +1,67 @@ + $t('UpTime Widget settings'), + 'link_path' => 'admin/config/system/uptime', + 'menu_name' => 'main-menu', + 'weight' => 1, + ); + menu_link_save($item); + + // Create a sample page. + $results = array( + 'module_path' => drupal_get_path('module', 'uptime'), + ); + $node = new stdClass(); + $node->uid = 1; + $node->language = LANGUAGE_NONE; + $node->type = 'page'; + $node->status = 1; + $node->promote = 1; + $node->title = $t('Demo of the UpTime Widget module.'); + $node->body[LANGUAGE_NONE][0]['value'] = $t('

Log in and check out the UpTime Widget settings HERE.
The actual font color of the optional copyright notice can differ depending on the background color of the region the widget is in.

' . theme('uptime', array('results' => $results)) . '

Note:
The demo on the left does not get updated. Instead the block in the footer and the preview on the settings page do get refreshed.

'); + $node->body[LANGUAGE_NONE][0]['format'] = 'full_html'; + node_save($node); + + // Create some admin quick links in the navigation menu. + $item = array( + 'link_title' => $t('Configure Uptime block'), + 'link_path' => 'admin/structure/block/manage/uptime/uptime_widget/configure', + ); + menu_link_save($item); + $item = array( + 'link_title' => $t('Uptime settings'), + 'link_path' => 'admin/config/system/uptime', + ); + menu_link_save($item); + + // New settings for testing. + variable_set('uptime_api_key', 'u67898-e10c189beee66ab36cc2045c'); + variable_set('uptime_monitor_id', '775659447'); + variable_set('uptime_enabled', '1'); + variable_set('uptime_notice_enabled', '1'); + variable_set('uptime_url_name', 'simplytest.me'); +} + +/** + * Implements hook_uninstall(). + */ +function uptime_simplytest_uninstall() { + + // Remove the admin quick links. + $path = 'admin/structure/block/manage/uptime/uptime_widget/configure'; + menu_link_delete(NULL, $path); + $path = 'admin/config/system/uptime'; + menu_link_delete(NULL, $path); +} diff --git a/simplytest/uptime_simplytest.module b/simplytest/uptime_simplytest.module new file mode 100644 index 0000000..8410e79 --- /dev/null +++ b/simplytest/uptime_simplytest.module @@ -0,0 +1,11 @@ + 'fieldset', @@ -318,4 +307,46 @@ function uptime_admin_settings_submit($form, &$form_state) { // Make sure changes are visible right after saving the settings. _drupal_flush_css_js(); } + $api_key = variable_get('uptime_api_key', ''); + $monitor_id = variable_get('uptime_monitor_id', ''); + // Pause or activate update monitoring depending on the 'enabled' checkbox. + $status = variable_get('uptime_enabled', 1); + $url_status = "http://api.uptimerobot.com/editMonitor?apiKey=" . $api_key . "&monitorID=" . $monitor_id . "&monitorStatus=" . $status . "&format=xml"; + // Create a new cURL resource. + $ch = curl_init(); + // Set URL and other appropriate options. + curl_setopt($ch, CURLOPT_URL, $url_status); + curl_setopt($ch, CURLOPT_HEADER, 0); + // Grab URL and pass it to the browser. + curl_exec($ch); + // Close cURL resource, and free up system resources. + curl_close($ch); + + // Refresh the uptime ratio. + $api_key = variable_get('uptime_api_key', ''); + if (empty($api_key)) { + variable_set('uptime_ratio', '[Missing API key] '); + // Leave a message. + $message = t('UpTime: Missing API key'); + drupal_set_message($message, 'warning', FALSE); + watchdog('uptime', $message, NULL, WATCHDOG_WARNING); + } + else { + $monitor_id = variable_get('uptime_monitor_id', ''); + $url = "http://api.uptimerobot.com/getMonitors?apiKey=" . $api_key . "&monitors=" . $monitor_id . "&format=xml"; + // Curl request. + $c = curl_init($url); + curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE); + $response_xml = curl_exec($c); + curl_close($c); + // XML parsing. + $xml = simplexml_load_string($response_xml); + foreach ($xml->monitor as $monitor) { + variable_set('uptime_ratio', (string) $monitor['alltimeuptimeratio']); + } + // Leave a message. + $message = t('UpTime updated successfully = %uptime %', array('%uptime' => variable_get('uptime_ratio', (string) $monitor['alltimeuptimeratio']))); + drupal_set_message($message, 'status', FALSE); + watchdog('uptime', $message); + } } diff --git a/uptime.info b/uptime.info index f33ab87..e13996e 100644 --- a/uptime.info +++ b/uptime.info @@ -3,7 +3,6 @@ description = A block showing the uptime ratio of the site using the free servic core = 7.x configure = admin/structure/block -test_dependencies[] = uptime_widget_test -simplytest_dependencies[] = uptime_widget_test +simplytest_dependencies[] = uptime_simplytest simplytest_dependencies[] = style_settings soft_dependencies[] = style_settings diff --git a/uptime_widget_test/uptime_widget_test.info b/uptime_widget_test/uptime_widget_test.info deleted file mode 100644 index bcc4f59..0000000 --- a/uptime_widget_test/uptime_widget_test.info +++ /dev/null @@ -1,7 +0,0 @@ -name = Uptime test -description = "Set/unset test configuration and add quick admin links. UNINSTALL TO RESET SETTINGS TO OLD VALUES !!!" -package = Development -version = 7.0 -core = 7.x - -dependencies[] = uptime diff --git a/uptime_widget_test/uptime_widget_test.install b/uptime_widget_test/uptime_widget_test.install deleted file mode 100644 index a497f10..0000000 --- a/uptime_widget_test/uptime_widget_test.install +++ /dev/null @@ -1,135 +0,0 @@ -uid = 1; - $node->language = LANGUAGE_NONE; - $node->type = 'page'; - $node->status = 1; - $node->promote = 1; - $node->title = $t('Demo site'); - $node->body[LANGUAGE_NONE][0]['value'] = $t('

This is the demo site for both the UpTime Widget and PageRank Widget module.

NOTE: Once you enter the PageRank settings page, cron will run and the actual host of the current site is loaded. This might result in a Pagerank of N/A or a Google error on a development site.

Features

Customizable

Advantage over embedding third party scripts is the possibility to change the color of the widget to fit your theme. A CSS file is provided.

Lightweight

An external script makes a request on each page load. The modules once every 24 hours.'); - $node->body[LANGUAGE_NONE][0]['format'] = 'full_html'; - node_save($node); - - // Enable the PageRank Widget module to showcase as well. - module_enable(array('pr_widget'), 'FALSE'); - - // Create some admin quick links in the navigation menu. - $item = array( - 'link_title' => $t('Configure Uptime block'), - 'link_path' => 'admin/structure/block/manage/uptime/uptime_widget/configure', - ); - menu_link_save($item); - $item = array( - 'link_title' => $t('Uptime settings'), - 'link_path' => 'admin/config/system/uptime', - ); - menu_link_save($item); - if (module_exists('pr_widget')) { - $item = array( - 'link_title' => $t('Configure PageRank block'), - 'link_path' => 'admin/structure/block/manage/pr_widget/pr_widget_widget/configure', - ); - menu_link_save($item); - $item = array( - 'link_title' => $t('PageRank settings'), - 'link_path' => 'admin/config/system/pr_widget', - ); - menu_link_save($item); - } - - // Save old settings. - variable_set('uptime_old_api_key', variable_get('uptime_api_key', '')); - variable_set('uptime_old_monitor_id', variable_get('uptime_monitor_id', '')); - variable_set('uptime_old_enabled', variable_get('uptime_enabled', '1')); - variable_set('uptime_old_notice_enabled', variable_get('uptime_notice_enabled', '0')); - variable_set('uptime_old_url_name', variable_get('uptime_url_name', '')); - if (module_exists('pr_widget')) { - variable_set('pr_widget_old_interval', variable_get('pr_widget_interval', 24 * 60 * 60)); - variable_set('pr_widget_old_ratio', variable_get('pr_widget_ratio', 'N/A')); - variable_set('pr_widget_old_url', variable_get('pr_widget_url', parse_url($GLOBALS['base_url'], PHP_URL_HOST))); - } - - // New settings for testing. - variable_set('uptime_api_key', 'u67898-e10c189beee66ab36cc2045c'); - variable_set('uptime_monitor_id', '775659447'); - variable_set('uptime_enabled', '1'); - variable_set('uptime_notice_enabled', '1'); - variable_set('uptime_url_name', 'simplytest.me'); - if (module_exists('pr_widget')) { - variable_set('pr_widget_url', 'simplytest.me'); - } - - // New uptime ratio must be grabbed. - drupal_cron_run(); - - // New uptime ratio needs to be grabbed. - if (module_exists('pr_widget')) { - $interval = variable_get('pr_widget_interval', 24 * 60 * 60); - $url = 'http://simplytest.me/'; - if (pr_widget_pagerank($url) == -1) { - variable_set('pr_widget_ratio', 'N/A'); - } - else { - variable_set('pr_widget_ratio', pr_widget_pagerank($url)); - } - watchdog('pr_widget', 'PageRank updated successfully'); - variable_set('pr_widget_next_execution', time() + $interval); - } -} - -/** - * Implements hook_uninstall(). - */ -function uptime_widget_test_uninstall() { - - // Remove the admin quick links. - $path = 'admin/structure/block/manage/uptime/uptime_widget/configure'; - menu_link_delete(NULL, $path); - $path = 'admin/config/system/uptime'; - menu_link_delete(NULL, $path); - if (module_exists('pr_widget')) { - $path = 'admin/structure/block/manage/pr_widget/pr_widget_widget/configure'; - menu_link_delete(NULL, $path); - $path = 'admin/config/system/pr_widget'; - menu_link_delete(NULL, $path); - } - // Reset settings to their old values. - variable_set('uptime_api_key', variable_get('uptime_old_api_key', '')); - variable_set('uptime_monitor_id', variable_get('uptime_old_monitor_id', '')); - variable_set('uptime_enabled', variable_get('uptime_old_enabled', '1')); - variable_set('uptime_notice_enabled', variable_get('uptime_old_notice_enabled', '0')); - variable_set('uptime_url_name', variable_get('uptime_old_url_name', '')); - if (module_exists('pr_widget')) { - variable_set('pr_widget_interval', variable_get('pr_widget_old_interval', 24 * 60 * 60)); - variable_set('pr_widget_ratio', variable_get('pr_widget_old_ratio', 'N/A')); - variable_set('pr_widget_url', variable_get('pr_widget_old_url', parse_url($GLOBALS['base_url'], PHP_URL_HOST))); - // The cron needs to run asap after uninstall of the test. - variable_set('pr_widget_next_execution', 0); - } - // Cleanup saved variables. - db_delete('variable') - ->condition('name', 'uptime_old_%', 'LIKE') - ->execute(); - cache_clear_all('variables', 'cache_bootstrap'); - if (module_exists('pr_widget')) { - db_delete('variable') - ->condition('name', 'pr_widget_old_%', 'LIKE') - ->execute(); - cache_clear_all('variables', 'cache_bootstrap'); - // Old uptime ratio needs to be grabbed. - drupal_cron_run(); - } -} - diff --git a/uptime_widget_test/uptime_widget_test.module b/uptime_widget_test/uptime_widget_test.module deleted file mode 100644 index 8410e79..0000000 --- a/uptime_widget_test/uptime_widget_test.module +++ /dev/null @@ -1,11 +0,0 @@ -