/[drupal]/contributions/themes/flatforum/flatforum.module
ViewVC logotype

Contents of /contributions/themes/flatforum/flatforum.module

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


Revision 1.6 - (show annotations) (download) (as text)
Sun Oct 1 21:57:32 2006 UTC (3 years, 1 month ago) by ayman
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +1 -8 lines
File MIME type: text/x-php
Moved module description from .module to .info.
1 <?php
2 // $Id: flatforum.module,v 1.5 2006/05/11 18:17:16 ayman Exp $
3
4 function flatforum_nodeapi($node, $op) {
5 _flatforum_act($op, is_object($node) ? $node->uid : $node['uid']);
6 }
7
8 function flatforum_comment($comment, $op) {
9 _flatforum_act($op, is_object($comment) ? $comment->uid : $comment['uid']);
10 }
11
12 function _flatforum_act($op, $uid) {
13 static $deltas = array('insert' => 1, 'delete' => -1);
14 if (isset($deltas[(string)$op])) {
15 _flatforum_db($uid, $deltas[$op]);
16 }
17 }
18
19 function flatforum_get($uid) {
20 $result = db_query('SELECT posts FROM {flatforum} WHERE uid = %d', $uid);
21 if (db_num_rows($result)) {
22 return db_result($result);
23 }
24 else {
25 return _flatforum_db($uid, 0);
26 }
27 }
28
29 function flatforum_get_created($uid) {
30 return db_result(db_query('SELECT created FROM {users} WHERE uid = %d', $uid));
31 }
32
33 function _flatforum_db($uid, $delta) {
34 if ($delta && db_num_rows(db_query('SELECT uid FROM {flatforum} WHERE uid = %d', $uid))) {
35 db_query('UPDATE {flatforum} SET posts = posts + %d WHERE uid = %d', $delta, $uid);
36 }
37 else {
38 // the hooks are always called after the relevant INSERT/DELETE, so $delta is not relevant here
39 $posts = db_result(db_query("SELECT COUNT(nid) FROM {node} n WHERE uid = %d", $uid));
40 $posts += db_result(db_query("SELECT COUNT(cid) FROM {comments} c WHERE uid = %d", $uid));
41 db_query('INSERT INTO {flatforum} (uid, posts) VALUES (%d, %d) ', $uid, $posts);
42 return $posts;
43 }
44 }
45

  ViewVC Help
Powered by ViewVC 1.1.2