Submitted by Alaa on Thu, 10/06/2004 - 11:32.
( categories: )
<?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;
}

?>
whirlpool's picture
Submitted by whirlpool on Thu, 10/06/2004 - 15:05.

The counter block is very cool, but can we have it report how many new users in the current week.


MohammedSameer's picture
Submitted by MohammedSameer on Mon, 16/08/2004 - 02:06.

I think i'll try to work on this one, However I can't install it on my local drupal to test, I enabled it in the modules, but i didn't find a block in the blocks page.

Any special thing required ??

-- I was known as Uniball!
Katoob Main developer
PekSysTray - GtkFlame


whirlpool's picture
Submitted by whirlpool on Mon, 16/08/2004 - 08:27.

enable the block, choose it side and weight


MohammedSameer's picture
Submitted by MohammedSameer on Mon, 16/08/2004 - 09:21.

{quote=whirlpool}enable the block, choose it side and weight{/quote}

I enabled the module, but didn't find it in the blocks page.


MohammedSameer's picture
Submitted by MohammedSameer on Mon, 16/08/2004 - 09:32.

Solved!

the module must be named "lincount.module"

-- I was known as Uniball!
Katoob Main developer
PekSysTray - GtkFlame


MohammedSameer's picture
Submitted by MohammedSameer on Mon, 16/08/2004 - 10:14.

Alaa, How about this for a start ?

http://home.foolab.org/files/lincount.module

-- I was known as Uniball!
Katoob Main developer
PekSysTray - GtkFlame


MohammedSameer's picture
Submitted by MohammedSameer on Mon, 16/08/2004 - 17:27.

My module is currently running.

-- I was known as Uniball!
Katoob Main developer
PekSysTray - GtkFlame


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.