'url', '#type' => 'textarea', '#title' => t("URLs (@max_url max)", array('@max_url' => $max_url)), '#default_value' => '', '#rows' => 5, '#description' => t('URLs separated by newline. Example: www.pagerankandalexa.com'), '#resizable' => FALSE, ); $form['submit'] =array( '#type' => 'submit', '#value' => 'Go', '#name' => 'submit', ); return $form; } function sitestats_getform_submit($form, &$form_state) { $form_state['redirect'] = array('sitestats', array('urls' => $_REQUEST['url'])); } function _sitestats_statswithoutajax($urls) { module_load_include('inc', 'sitestats'); $urls = explode("\r", $urls); $urls = array_map('trim', $urls); $urls = array_filter($urls); $urls = array_slice($urls, 0, variable_get('sitestats_max', 5)); $r = ''; foreach ($urls as $url) { $x = theme('sitestats_view', sitestats_getstats($url)); $r .= $x; } return $r; } function sitestats_stats(){ drupal_set_header('Content-Type: text/plain; charset: utf-8'); module_load_include('inc', 'sitestats'); $urls = $_POST['url']; $urls = explode("\n", $urls); $urls = array_map('trim', $urls); $urls = array_filter($urls); $urls = array_slice($urls, 0, variable_get('sitestats_max', 5)); $r = ''; foreach ($urls as $url) { $x = theme('sitestats_view', sitestats_getstats($url)); $r .= $x; } echo $r; } function _sitestats_subscribe(&$form_state, $url) { $form['#prefix'] = '
'; $form['#suffix'] = '
'; $form['mail'] = array( '#type' => 'fieldset', '#title' => 'Subscribe', ); $form['mail']['notified'] = array( '#value' => t("Be notified when pagerank on %url changes!", array('%url' => $url)), ); $form['mail']['url'] = array( '#type' => 'hidden', '#name' => 'url', '#value' => check_plain($url), ); $form['mail']['email'] = array( '#type' => 'textfield', '#name' => 'email', '#size' => 50, '#id' => 'validate', '#title' => 'Email Address', '#field_suffix' => '', ); $form['mail']['register'] = array( '#type' => 'submit', '#name' => 'register', '#value' => 'Get Update By E-mail', ); return $form; } function _sitestats_subscribe_mail() { drupal_set_header('Content-Type: text/plain; charset: utf-8'); module_load_include('inc', 'sitestats'); $r['url'] = $url = $_POST['url']; $r['mail'] = $email = $_POST['email']; $r['hashelement'] = md5($url.$email); $r['pr'] = _sitestats_getpagerank($url); $r['last_checked'] = time(); if ( !db_result(db_query("SELECT hashelement FROM {sitestats} WHERE hashelement='%s'", $r['hashelement']))) { $return = drupal_write_record('sitestats', $r); } $msg = '!mail is now registered to the pagerank update on !url'; $vars = array('!mail' => $r['mail'], '!url' => $r['url']); watchdog('sitestats', $msg, $vars, WATCHDOG_INFO); echo t($msg, $vars); } function sitestats_page() { $urls = $_REQUEST['urls']; $module_path = drupal_get_path('module', 'sitestats'); drupal_add_js($module_path .'/sitestats.js'); drupal_add_css($module_path .'/sitestats.css'); drupal_add_js('misc/collapse.js'); if ($urls) { $stats = _sitestats_statswithoutajax($urls); } $output = ''; $output .= drupal_get_form('sitestats_getform'); $result = "
'
$stats
"; $output .= $result; return $output; } function sitestats_getstats($url) { $url = str_replace(array('www.', 'http://', 'https://'), '', $url); $to_fetch = variable_get('sitestats_getstats', array()); if ($to_fetch['PR']) { $result['pr_1'] = _sitestats_getpagerank($url); } if ($to_fetch['GB']) { $result['google_backlink'] = _sitestats_google_backlink($url); } if ($to_fetch['AP']) { $result['alexa_rank'] = _sitestats_get_alexa_popularity($url); } if ($to_fetch['GI']) { $result['google_indexed'] = _sitestats_google_indexed($url); } if ($to_fetch['AI']) { $result['alltheweb'] = _sitestats_alltheweb_link($url); } if ($to_fetch['DM']) { $result['dmoz'] = _sitestats_dmoz_listed($url); } if ($to_fetch['DA']) { $result['age'] = _sitestats_getage("www.$url"); } $result['register'] = drupal_get_form('_sitestats_subscribe', $url); $length = variable_get('sitestats_url_length', 25); $url = truncate_utf8($url, $length, FALSE, TRUE); $result['url'] = $url; $result['to_fetch'] = $to_fetch; return $result; } /** * Implementation of hook_menu */ function sitestats_menu() { $items['sitestats'] = array( 'title' => 'Check Statistics of any site instantly', 'page callback' => 'sitestats_page', 'access arguments' => array('access sitestats'), 'type' => MENU_NORMAL_ITEM, ); $items['sitestats/path'] = array( 'page callback' => 'sitestats_stats', 'type' => MENU_CALLBACK, 'access arguments' => array('access content'), ); $items['sitestats/mail'] = array( 'page callback' => '_sitestats_subscribe_mail', 'type' => MENU_CALLBACK, 'access arguments' => array('access content'), ); $items['admin/settings/sitestats'] = array( 'title' => 'Sitestats', 'description' => 'Check the Statistics of any Site', 'page callback' => 'drupal_get_form', 'page arguments' => array('sitestats_admin_settings'), 'access arguments' => array('administer sitestats'), 'type' => MENU_NORMAL_ITEM, ); return $items; } /** * Implementation of hook_theme() */ function sitestats_theme() { return array( 'sitestats_view' => array( 'template' => 'sitestats_view', 'arguments' => array( 'rows' => NULL, ), ), ); } /** * Implementation of hook_cron() */ function sitestats_cron() { $now = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time(); // Is it time to run again? $last = variable_get('sitestats_cron_last', $now); // 1 day = 86400 AND 12 hrs = 43200 $interval = variable_get('sitestats_cron_interval', 43200); if ($now - $last < $interval) { return; } $how_many = variable_get('sitestats_links_per_cron', 10); $query = "SELECT * FROM {sitestats} ORDER BY last_checked ASC "; $cursor = db_query_range($query, $how_many); module_load_include('inc','sitestats'); while ($result = db_fetch_object($cursor)) { $url = $result->url; $oldpr = $result->pr; $newpr = _sitestats_getpagerank($url); $result->last_checked = $now; if ($oldpr != $newpr) { $result->pr = $newpr; $to = $result->mail; $vars = array( '!url' => $result->url, '!pr' => $result->pr, '!site_name' => variable_get('site_name', FALSE), ); $params['subject'] = variable_get('sitestats_mail_sub', SITESTATS_MAIL_SUB); $params['body'] = strtr(variable_get('sitestats_mail_body', SITESTATS_MAIL_BODY), $vars); if (variable_get('sitestats_mail_default',SITESTATS_MAIL_DEFAULT)) { drupal_mail('sitestats', 'notify', $to, language_default(), $params); watchdog('sitestats', "Mail sent to !mail, updated pagerank of !url from !oldpr to !newpr", array('!mail' => $result->mail, '!url' => $result->url, '!oldpr' => $oldpr, '!newpr' => $newpr), WATCHDOG_INFO); } drupal_write_record('sitestats', $result, 'hashelement'); } } watchdog('sitestats', 'Pagerank Updation Check', NULL, WATCHDOG_INFO); variable_set('sitestats_cron_last', $now); } function sitestats_mail($key, &$message, $params) { switch ($key) { case 'notify': $message['subject'] = $params['subject']; $message['body'] = $params['body']; break; } } function sitestats_admin_settings() { $form = array(); $form['email'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Email '), ); $form['email']['sitestats_mail_default'] = array( '#type' => 'checkbox', '#title' => 'Send Mail', '#default_value' => variable_get('sitestats_mail_default', TRUE), '#description' => t('If this is uncheck, then users will not be able to subscribe via emails.'), ); $form['email']['sitestats_mail_sub'] = array( '#type' => 'textfield', '#size' => 57, '#default_value' => variable_get('sitestats_mail_sub',SITESTATS_MAIL_SUB), ); $form['email']['sitestats_mail_body'] = array( '#type' => 'textarea', '#rows' => 3, '#default_value' => variable_get('sitestats_mail_body',SITESTATS_MAIL_BODY), '#description' => t('Available variables are !site_name, !url and !pr'), ); $interval = array(0, 30*60, 60*60, 2*60*60, 3*60*60, 4*60*60, 6*60*60, 12*60*60, 24*60*60, 2*24*60*60, 3*24*60*60, 7*24*60*60, 14*24*60*60); $form['sitestats_cron_interval'] = array( '#type' => 'select', '#options' => drupal_map_assoc($interval, 'format_interval'), '#title' => t('Cron interval'), '#description' => t("This sets the frequency of checking. If you run Cron frequently, you may wish to set this higher than your Cron frequency so that you don't overload the ranking sites. An interval of 0 means every cron run."), '#size' => count($interval) / 2, '#default_value' => variable_get('sitestats_cron_interval', 43200), ); $form['sitestats_links_per_cron'] = array( '#type' => 'textfield', '#title' => t('Links per cron'), '#default_value' => variable_get('sitestats_links_per_cron', 10), '#size' => 8, '#description' => t('This sets the number of links that will be checked per Cron run.'), ); $form['sitestats_max'] = array( '#type' => 'textfield', '#title' => t('Max no of URL.'), '#default_value' => variable_get('sitestats_max', 5), '#size' => 3, '#description' => t('The greater the number the more is the time taken to fetch the data'), ); $form['sitestats_url_length'] = array( '#type' => 'textfield', '#title' => t('Max URL Length'), '#default_value' => variable_get('sitestats_url_length',25), '#size' => 3, '#description' => t('Some templates may break if URL length is too big'), ); $options = array( 'PR' => t("Show google pr"), 'AP' => t("Show alexa Popularity"), 'GB' => t("Show google backlink"), 'GI' => t("Show google indexed"), 'AI' => t("Show alltheweb indexed"), 'DM' => t("Listed in DMOZ.org"), 'DA' => t("Show domain age") ); $form['sitestats_getstats'] = array( '#type' => 'checkboxes', // '#multicolumn' => array('width' => 3, 'row-major' => TRUE), '#title' => t('Select statistics to fetch'), '#options' => $options, '#default_value' => variable_get('sitestats_getstats', array()), ); return system_settings_form($form); }