/[drupal]/contributions/sandbox/alaa/lincount.module
ViewVC logotype

Contents of /contributions/sandbox/alaa/lincount.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Fri May 6 13:43:51 2005 UTC (4 years, 6 months ago) by alaa
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +16 -11 lines
File MIME type: text/x-php
updated to 4.6
1 <?php // -*-php-*-
2 /*
3 * Original module by Alaa Abd El Fatah.
4 * Modifications to include the admin configuration by Mohammed Sameer.
5 * Copyright (c) 2004 Mohammed Sameer, All rights reserved.
6 * Mohammed Sameer: My Modifications are under the GNU GPL v2 or later.
7 * Mohammed Sameer: 2004 09 10:
8 * * Output is themed by drupal.
9 * * Don't modify the variables if you can't open the file.
10 * * The "more..." link should include the country ISO code.
11 * * s/||/|/ between the 2 links at the bottom per alaa's request.
12 * 2004 10 29L
13 * * Ported to drupal 4.5 API.
14 *
15 * 04/04/2005: Ported to drupal 4.6 API by Amr Mostafa
16 */
17
18 function lincount_help($section) {
19 switch ($section) {
20 case 'admin/modules#description':
21 $output = "<p>displays a block with the current Egypt statistics from Linux Counter Project</p>";
22 break;
23 }
24
25 return $output;
26 }
27
28 function lincount_cron() {
29 $file = 'http://counter.li.org/reports/short.txt';
30 $data = file_get_contents($file);
31 if ($data == FALSE)
32 {
33 return;
34 }
35 $country = variable_get("lincount_country", "EG");
36 $matches = array();
37 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);
38
39 $rank = $matches[1];
40 $country = $matches[2];
41 $users = $matches[3] + $matches[4];
42 $machines = $matches[5];
43 $userdensity = $matches[6];
44
45 variable_set("lincount_rank", $rank);
46 variable_set("lincount_users", $users);
47 variable_set("lincount_machines", $machines);
48 variable_set("lincount_userdensity", $userdensity);
49 variable_set("lincount_country_long", $country);
50 }
51
52 function lincount_block($op = "list", $delta = 0) {
53 if ($op == "list") {
54 $blocks[0]["info"] = t("Linux Counter Statistics");
55 return $blocks;
56 }
57 elseif ($op == "view")
58 {
59 $country = variable_get("lincount_country_long", "Egypt");
60 $block["subject"] = t("Linux Counter %s Statistics",array("%s" => $country));
61 $block["content"] = lincount_display_block();
62 return $block;
63 }
64 else {
65 return;
66 }
67 }
68
69 function lincount_display_block() {
70 $rank = variable_get("lincount_rank",0);
71 $users = variable_get("lincount_users",0);
72 $machines = variable_get("lincount_machines",0);
73 $userdensity = variable_get("lincount_userdensity",0);
74 $country = variable_get("lincount_country","EGY");
75
76 $lincount_array[] = "Country Rank: $rank";
77 $lincount_array[] = "Number Of Users: $users";
78 $lincount_array[] = "Number Of Machines: $machines";
79 $lincount_array[] = "User Density: $userdensity";
80 $output = theme_node_list($lincount_array);
81
82 $output .= "<br />";
83 $output_array[] = l("Get Counted","http://counter.li.org/enter-person.php");
84 $output_array[] = l("more...","http://counter.li.org/reports/arearank.php?area=$country");
85 $output .= "<div class=\"more-link\">";
86 $output .= theme_links($output_array, ' | ');
87 $output .= "</div>";
88 return $output;
89 }
90
91 function lincount_settings()
92 {
93 $country = variable_get("lincount_country", "EG");
94 $output .= form_textfield(t("Enter the ISO code for the country:"), "lincount_country", $country, 55, 100);
95 return $output;
96 }
97 ?>

  ViewVC Help
Powered by ViewVC 1.1.2