LinCountModule
<?php // -*-php-*-
/*
* Original module by Alaa Abd El Fatah.
* Modifications to enclude the admin configuration by Mohammed Sameer.
* Copyright (c) 2004 Mohammed Sameer, All rights reserved.
* Mohammed Sameer: My Modifications are under the GNU GPL v2 or later.
* Mohammed Sameer: 2004 09 10:
* * Output is themed by drupal.
* * Don't modify the variables if you can't open the file.
* * The "more..." link should include the country ISO code.
* * s/||/|/ between the 2 links at the bottom per alaa's request.
* 2004 10 29L
* * Ported to drupal 4.5 API.
*/
function lincount_help($section) {
switch ($section) {
case 'admin/modules#description':
$output = "<p>displays a block with the current Egypt statistics from Linux Counter Project</p>";
break;
}
return $output;
}
function lincount_cron() {
$file = 'http://counter.li.org/reports/short.txt';
$data = file_get_contents($file);
if ($data == FALSE)
{
return;
}
$country = variable_get("lincount_country", "EG");
$matches = array();
preg_match("|([0-9]+)\s*$country\s*([0-9a-zA-Z]+)\s*([0-9]+)\s*([0-9]+)\s*([0-9]+)\s*([0-9]+\.[0-9]+)\s*([0-9]+.[0-9]+)|", $data, $matches);
$rank = $matches[1];
$country = $matches[2];
$users = $matches[3] + $matches[4];
$machines = $matches[5];
$userdensity = $matches[6];
variable_set("lincount_rank", $rank);
variable_set("lincount_users", $users);
variable_set("lincount_machines", $machines);
variable_set("lincount_userdensity", $userdensity);
variable_set("lincount_country_long", $country);
}
function lincount_block($op = "list", $delta = 0) {
if ($op == "list") {
$blocks[0]["info"] = t("Linux Counter Statistics");
return $blocks;
}
else {
$country = variable_get("lincount_country_long", "Egypt");
$block["subject"] = t("Linux Counter %s Statistics",array("%s" => $country));
$block["content"] = lincount_display_block();
return $block;
}
}
function lincount_display_block() {
$rank = variable_get("lincount_rank",0);
$users = variable_get("lincount_users",0);
$machines = variable_get("lincount_machines",0);
$userdensity = variable_get("lincount_userdensity",0);
$country = variable_get("lincount_country","EGY");
$lincount_array[] = "Country Rank: $rank";
$lincount_array[] = "Number Of Users: $users";
$lincount_array[] = "Number Of Machines: $machines";
$lincount_array[] = "User Density: $userdensity";
$output = theme_node_list($lincount_array);
$output .= "<br />";
$output_array[] = l("Get Counted","http://counter.li.org/enter-person.php");
$output_array[] = l("more...","http://counter.li.org/reports/arearank.php?area=$country");
$output .= "<div class=\"more-link\">";
$output .= theme_links($output_array, ' | ');
$output .= "</div>";
return $output;
}
function lincount_settings()
{
$country = variable_get("lincount_country", "EG");
$output .= form_textfield(t("Enter the ISO code for the country:"), "lincount_country", $country, 55, 100);
return $output;
}
?>