Skip to Content

LinCountModule

Alaa's picture
<?php // -*-php-*-
/*
 * Original module by Alaa Abd El Fatah.
 * Modifications to include 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.
 *
 * 04/04/2005: Ported to drupal 4.6 API by Amr Mostafa
 * 29/01/2007: Ported to drupal 4.7 API by Amr Mostafa
 * 24/04/2008: Ported to drupal 5.7 API by Abdelrahman Ghareeb
 */

function lincount_help($path$arg) {
  switch (
$path) {
    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';
  
$ch curl_init($file);
  
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  
$data curl_exec($ch);
  if (
curl_errno($ch) != 0)
  { 
    return;
  }
  
curl_close($ch);
  
    
$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;
  }
  elseif (
$op == "view")
  {
    
$country variable_get("lincount_country_long""Egypt");
    
$block["subject"] = t("Linux Counter %s Statistics",array("%s" => $country));
    
$block["content"] = lincount_display_block();
    return 
$block;
  }
  else {
    return;
  }
}

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[] = array('title' => "Get Counted",
                          
'href' =>"http://counter.li.org/enter-person.php"
                        
);
  
$output_array[] = array('title' => "more...",
                          
'href' => "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()
{
    
$form['lincount_country'] = array(
        
'#type' => 'textfield',
        
'#title' => t("Enter the ISO code for the country:"),
        
'#default_value' => variable_get("lincount_country""EG"),
        
'#size' => 55,
        
'#maxlength' => 100);

  return 
$form;
}
?>

Comments

whirlpool's picture

+6 this week

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

MSameer's picture

Help me Help you!

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 ??

whirlpool's picture

administration -> configuration -> blocs

enable the block, choose it side and weight

MSameer's picture

Re: administration -> configuration -> blocs

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

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

MSameer's picture

Solved! the module must b

Solved!

the module must be named "lincount.module"

MSameer's picture

Alaa, How about this for a st

Alaa, How about this for a start ?

MSameer's picture

My module is currently runnin

My module is currently running.

Comment viewing options

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


Dr. Radut | book