rendered paste body<?php
// $Id: alexa.module,v 1.0 2006/07/07 on #drupal : xxx_xxx_ , brainless, advice from #drupal-support: heine, merlinofchaos, 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 ('access 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) {
if ($may_cache) {
$items[] = array(
'path' => 'alexa',
'title' => t('Alexa'),
'callback' => 'alexa_page',
'access' => user_access('access alexa'),
);
}
return $items;
}
function alexa_page() {
$form['text1'] = array(
'#type' => 'textfield',
'#default_value' => 'www.thingstoday.com' ,
);
$form['text2'] = array(
'#type' => 'textfield',
'#default_value' => 'www.americanlocalnews.com' ,
);
$form['text3'] = array(
'#type' => 'textfield',
'#default_value' => 'www.4pir2.org' ,
);
$form['text4'] = array(
'#type' => 'textfield',
'#default_value' => 'www.pagecharts.com' ,
);
$form['text5'] = array(
'#type' => 'textfield',
'#default_value' => 'www.alexacharts.com' ,
);
$form['chart_type'] = array(
'#type' => 'select',
'#title' => t('Type of Chart'),
'#options' => array(
'r' => t('Reach'),
'p' => t('Page Views'),
't' => t('Traffic Rank'),
),
'#description' => t('This is the Type of Chart to be displayed.'),
);
$form['chart_range'] = array(
'#type' => 'select',
'#title' => t('Display Range of Chart'),
'#options' => array(
'7d' => t('7 days'),
'14d' => t('14 days'),
'1m' => t('1 month'),
'3m' => t('3 month'),
'6m' => t('6 month'),
'1y' => t('1 year'),
'2y' => t('2 year'),
'3y' => t('3 year'),
'4y' => t('4 year'),
'5y' => t('5 year'),
),
'#description' => t('Time Frame of the page to be displayed.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Get Alexa Charts'),
);
return drupal_get_form('alexa_page',$form);
}
function alexa_page_submit($form_id, $form_values) {
$image = 'http://traffic.alexa.com/graph?w=450&h=285&z=1';
($form_values['text1'] != '')?($image.='&u='.$form_values['text1']):'';
($form_values['text2'] != '')?($image.='&u='.$form_values['text2']):'';
($form_values['text3'] != '')?($image.='&u='.$form_values['text3']):'';
($form_values['text4'] != '')?($image.='&u='.$form_values['text4']):'';
($form_values['text5'] != '')?($image.='&u='.$form_values['text5']):'';
($form_values['chart_type'] != '')?($image.='&y='.$form_values['chart_type']):'';
($form_values['chart_range'] != '')?($image.='&r='.$form_values['chart_range']):'';
if($image != 'http://traffic.alexa.com/graph?w=379&h=216&&z=1')
drupal_set_message('<img src="'.$image.'" width="450" height="285" alt="Alexa">'.
'<br>Link to the Alexa Image is: <a href="'.$image.'">'.here.'</a>');
'<br>link <a href="'.$form_values['text1'].'">'.$form_values['text1'].'</a>';
'<br>link <a href="'.$form_values['text2'].'">'.$form_values['text2'].'</a>';
'<br>link <a href="'.$form_values['text3'].'">'.$form_values['text3'].'</a>';
'<br>link <a href="'.$form_values['text4'].'">'.$form_values['text4'].'</a>';
'<br>link <a href="'.$form_values['text5'].'">'.$form_values['text5'].'</a>';
return ('alexa');
}
function alexa2_page() {
$form['text1'] = array(
'#type' => 'textfield',
'#default_value' => 'www.myspace.com' ,
);
$form['text2'] = array(
'#type' => 'textfield',
'#default_value' => 'www.facebook.com' ,
);
$form['text3'] = array(
'#type' => 'textfield',
'#default_value' => 'www.blogger.com' ,
);
$form['text4'] = array(
'#type' => 'textfield',
'#default_value' => 'www.feedster.com' ,
);
$form['text5'] = array(
'#type' => 'textfield',
'#default_value' => 'www.friendster.com' ,
);
$form['chart_type'] = array(
'#type' => 'select',
'#title' => t('Type of Chart'),
'#options' => array(
'r' => t('Reach'),
'p' => t('Page Views'),
't' => t('Traffic Rank'),
),
'#description' => t('This is the Type of Chart to be displayed.'),
);
$form['chart_range'] = array(
'#type' => 'select',
'#title' => t('Display Range of Chart'),
'#options' => array(
'7d' => t('7 days'),
'14d' => t('14 days'),
'1m' => t('1 month'),
'3m' => t('3 month'),
'6m' => t('6 month'),
'1y' => t('1 year'),
'2y' => t('2 year'),
'3y' => t('3 year'),
'4y' => t('4 year'),
'5y' => t('5 year'),
),
'#description' => t('Time Frame of the page to be displayed.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Get Alexa Charts'),
);
return drupal_get_form('alexa2_page',$form);
}
function alexa2_page_submit($form_id, $form_values) {
$image = 'http://traffic.alexa.com/graph?w=450&h=285&z=1';
($form_values['text1'] != '')?($image.='&u='.$form_values['text1']):'';
($form_values['text2'] != '')?($image.='&u='.$form_values['text2']):'';
($form_values['text3'] != '')?($image.='&u='.$form_values['text3']):'';
($form_values['text4'] != '')?($image.='&u='.$form_values['text4']):'';
($form_values['text5'] != '')?($image.='&u='.$form_values['text5']):'';
($form_values['chart_type'] != '')?($image.='&y='.$form_values['chart_type']):'';
($form_values['chart_range'] != '')?($image.='&r='.$form_values['chart_range']):'';
if($image != 'http://traffic.alexa.com/graph?w=379&h=216&&z=1')
drupal_set_message('<img src="'.$image.'" width="450" height="285" alt="Alexa">'.
'<br>Link to the Alexa Image is: <a href="'.$image.'">'.here.'</a>');
'<br>link <a href="'.$form_values['text1'].'">'.$form_values['text1'].'</a>';
'<br>link <a href="'.$form_values['text2'].'">'.$form_values['text2'].'</a>';
'<br>link <a href="'.$form_values['text3'].'">'.$form_values['text3'].'</a>';
'<br>link <a href="'.$form_values['text4'].'">'.$form_values['text4'].'</a>';
'<br>link <a href="'.$form_values['text5'].'">'.$form_values['text5'].'</a>';
return ('alexa2');
}
function alexa3_page() {
$form['text1'] = array(
'#type' => 'textfield',
'#default_value' => 'www.drupal.org' ,
);
$form['text2'] = array(
'#type' => 'textfield',
'#default_value' => 'www.digg.com' ,
);
$form['text3'] = array(
'#type' => 'textfield',
'#default_value' => 'www.slashdot.org' ,
);
$form['text4'] = array(
'#type' => 'textfield',
'#default_value' => 'www.stumbleupon.com' ,
);
$form['text5'] = array(
'#type' => 'textfield',
'#default_value' => 'www.flickr.com' ,
);
$form['chart_type'] = array(
'#type' => 'select',
'#title' => t('Type of Chart'),
'#options' => array(
'r' => t('Reach'),
'p' => t('Page Views'),
't' => t('Traffic Rank'),
),
'#description' => t('This is the Type of Chart to be displayed.'),
);
$form['chart_range'] = array(
'#type' => 'select',
'#title' => t('Display Range of Chart'),
'#options' => array(
'7d' => t('7 days'),
'14d' => t('14 days'),
'1m' => t('1 month'),
'3m' => t('3 month'),
'6m' => t('6 month'),
'1y' => t('1 year'),
'2y' => t('2 year'),
'3y' => t('3 year'),
'4y' => t('4 year'),
'5y' => t('5 year'),
),
'#description' => t('Time Frame of the page to be displayed.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Get Alexa Charts'),
);
return drupal_get_form('alexa3_page',$form);
}
function alexa3_page_submit($form_id, $form_values) {
$image = 'http://traffic.alexa.com/graph?w=450&h=285&z=1';
($form_values['text1'] != '')?($image.='&u='.$form_values['text1']):'';
($form_values['text2'] != '')?($image.='&u='.$form_values['text2']):'';
($form_values['text3'] != '')?($image.='&u='.$form_values['text3']):'';
($form_values['text4'] != '')?($image.='&u='.$form_values['text4']):'';
($form_values['text5'] != '')?($image.='&u='.$form_values['text5']):'';
($form_values['chart_type'] != '')?($image.='&y='.$form_values['chart_type']):'';
($form_values['chart_range'] != '')?($image.='&r='.$form_values['chart_range']):'';
if($image != 'http://traffic.alexa.com/graph?w=379&h=216&&z=1')
drupal_set_message('<img src="'.$image.'" width="450" height="285" alt="Alexa">'.
'<br>Link to the Alexa Image is: <a href="'.$image.'">'.here.'</a>');
'<br>link <a href="'.$form_values['text1'].'">'.$form_values['text1'].'</a>';
'<br>link <a href="'.$form_values['text2'].'">'.$form_values['text2'].'</a>';
'<br>link <a href="'.$form_values['text3'].'">'.$form_values['text3'].'</a>';
'<br>link <a href="'.$form_values['text4'].'">'.$form_values['text4'].'</a>';
'<br>link <a href="'.$form_values['text5'].'">'.$form_values['text5'].'</a>';
return ('alexa3');
}