rendered paste body<?php// $Id: alexa.module,v 1.0 2006/07/07 xxx_xxx_ Exp $/*** @file* Grab the latest info from Alexa*/ /********************************************************************* Drupal Hooks********************************************************************//** * Implementation of hook_help(). */function alexa_help($section) { switch ($section) { case 'admin/modules#description': return t('grab the latest alexa data from www.alexa.com'); }}function alexa_perm() { return array ('use alexa');}function alexa_link($type, $node = 0, $main = 0) { global $user; $links = array(); if ($type == 'page' && user_access('use alexa')) { $links[] = l(t('alexa'), 'alexa'); } return $links;}function alexa_menu($may_cache) { global $user; $items = array();$access = user_access('use alexa'); $title = t(variable_get('alexa_overview_title', 'alexa')); $path = 'alexa'; $items[] = array( 'path' => $path, 'title' => $title, 'access' => $access, 'callback' => 'alexa_page', 'weight' => 0, ); return $items;}// Display the formfunction alexa_form() { $edit = isset($_POST['edit']) ? $_POST['edit'] : ''; $form['button1'] = array( '#type' => 'textfield', '#title' => t('1st domain'), ); $form['button2'] = array( '#type' => 'textfield', '#title' => t('2nd domain'), ); $form['button3'] = array( '#type' => 'textfield', '#title' => t('3rd domain'), ); $form['button4'] = array( '#type' => 'textfield', '#title' => t('4th domain'), ); $form['button5'] = array( '#type' => 'textfield', '#title' => t('5th domain'), ); } return $form;/** * Fetch the alexa info for a given ticker symbol from alexa! */function alexa_fetch($form) { if (empty($form)) { return FALSE; } $host = 'http://traffic.alexa.com/graph?w=725&h=370&r=1m&y=r&a=1&z=1&u='; $url = $host . urlencode($form['button1']) .'&u='.urlencode($form['button2']).urlencode($form['button3']).urlencode($form['button4']).urlencode($form['button5']); $contents = @file_get_contents($url); if ($contents) { if ($data = explode(',', str_replace('"', '', $contents))) { $data = array_map('trim', $data); return $data; } } return FALSE;}?>