-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyourshare.module
executable file
·155 lines (119 loc) · 4.28 KB
/
yourshare.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
Your Share - a Drupal module that shows members contribution ratio on a Drupal site
Written by Jonas Björk <[email protected]> 2009-07-03
Licensed under European Union Public License (EUPL) version 1.1
that can be found at http://ec.europa.eu/idabc/eupl
*/
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
//Drupal Functions
function yourshare_help($section='') {
$output = '';
switch ($section) {
case "admin/help#yourshare":
$output = '<p>'. t("Your Share is a Drupal module that shows members contribution to a Drupal website."). '</p>';
break;
}
return $output;
}
function yourshare_perm() {
return array('access yourshare content');
}
function yourshare_menu() {
$items = array();
$items[] = array(
'path' => 'yourshare',
'title' => t('Your share'),
'callback' => 'yourshare_all',
'access' => user_access('access yourshare content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function yourshare_block($op='list', $delta=0) {
if ($op == "list") {
$block[0]["info"] = t('Your Share');
return $block;
}
else if ($op == 'view') {
$block_content = "Total nodes: " . tot_nodes();
$block_content .= "<br>Total comments: " . tot_comments();
$block['subject'] = 'Your Share';
$block['content'] = $block_content;
return $block;
}
}
//End Drupal functions
//Non-drupal functions
function tot_nodes() {
$r = db_query("SELECT COUNT(nid) AS total FROM {node}");
$o = db_fetch_object($r);
return $o->total;
}
function tot_comments() {
$r = db_query("SELECT COUNT(cid) AS total FROM {comments}");
$o = db_fetch_object($r);
return $o->total;
}
function get_username($uid) {
$r = db_query("SELECT name FROM {users} WHERE uid='%d' LIMIT 1", $uid);
$o = db_fetch_object($r);
return $o->name;
}
function get_user_nodes($uid) {
$r = db_query("SELECT COUNT(nid) AS usernodes FROM {node} WHERE uid='%d'", $uid);
$o = db_fetch_object($r);
return $o->usernodes;
}
function get_user_comments($uid) {
$r = db_query("SELECT COUNT(cid) AS usercomments FROM {comments} WHERE uid='%d'", $uid);
$o = db_fetch_object($r);
return $o->usercomments;
}
function avrunda($t, $d = 2) {
$a = pow(10, $d);
return round($t*$a)/$a;
}
//End Non Drupal functions
//Huvudfunktionen för att generera sidan
function yourshare_all() {
$tot_nodes = tot_nodes();
$tot_comments = tot_comments();
global $user;
$username = $user->name;
$output = "<p><strong>".t('Totals')."</strong>";
$output .= "<br>".t('Nodes').": ".$tot_nodes;
$output .= "<br>".t('Comments').": ".$tot_comments ."</p>";
$r = db_query("SELECT uid FROM {users} WHERE name='%s' LIMIT 1", $username);
$o = db_fetch_object($r);
$uid = $o->uid;
$usernodes = get_user_nodes($uid);
$usercomments = get_user_comments($uid);
$output .= "<p><b>".$user->name."</b><br>";
$output .= "Antal kommentarer: ".avrunda(($usercomments/$tot_comments)*100)."%";
$output .= "<br />Antal noder: ".avrunda(($usernodes/$tot_nodes)*100)."%</p>";
$output .= "<b>Tio i topp - noder</b><br>";
$r = db_query("select node.uid,count(node.nid) AS antal, users.name AS username FROM {node} INNER JOIN {users} ON node.uid=users.uid WHERE node.uid != 0 GROUP BY uid ORDER BY antal DESC LIMIT 10");
while($o = db_fetch_object($r)) {
if($o->uid == $uid) {
$output .= "<div style='background: yellow'>";
}
$output .= $o->username." : ".$o->antal." noder (".avrunda(($o->antal/$tot_nodes)*100)."%)<br />";
if($o->uid == $uid) {
$output .= "</div>";
}
}
$output .= "<b>Tio i topp - kommentarer</b><br>";
$r = db_query("select comments.uid,count(comments.cid) AS antal, users.name AS username FROM {comments} INNER JOIN {users} ON comments.uid=users.uid WHERE comments.uid != 0 GROUP BY uid ORDER BY antal DESC LIMIT 10");
while($o = db_fetch_object($r)) {
if($o->uid == $uid) {
$output .= "<div style='background: yellow'>";
}
$output .= $o->username." : ".$o->antal." kommentarer (".avrunda(($o->antal/$tot_nodes)*100)."%)<br />";
if($o->uid == $uid) {
$output .= "</div>";
}
}
return $output;
}