~ubuntu-branches/ubuntu/lucid/boinc/lucid

« back to all changes in this revision

Viewing changes to html/inc/forum_forum.inc

  • Committer: Bazaar Package Importer
  • Author(s): Frank S. Thomas, Frank S. Thomas
  • Date: 2008-05-31 08:02:47 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20080531080247-4ce890lp2rc768cr
Tags: 6.2.7-1
[ Frank S. Thomas ]
* New upstream release.
  - BOINC Manager: Redraw disk usage charts immediately after connecting to
    a (different) client. (closes: 463823)
* debian/copyright:
  - Added the instructions from debian/README.Debian-source about how
    repackaged BOINC tarballs can be reproduced because DevRef now
    recommends to put this here instead of in the afore-mentioned file.
  - Updated for the new release.
* Removed the obsolete debian/README.Debian-source.
* For consistency upstream renamed the core client and the command tool
  ("boinc_client" to "boinc" and "boinc_cmd" to "boinccmd"). Done the same
  in all packages and created symlinks with the old names for the binaries
  and man pages. Also added an entry in debian/boinc-client.NEWS explaining
  this change.
* debian/rules: Do not list Makefile.ins in the clean target individually,
  just remove all that can be found.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
/**
4
 
 * This class serves to represent a forum under some category
5
 
 **/
6
 
define('THREADS_PER_PAGE',50);
7
 
// Forum sorting styles available
8
 
define('MODIFIED_NEW', 1);
9
 
define('MODIFIED_OLD',2);
10
 
define('VIEWS_MOST',3);
11
 
define('REPLIES_MOST',4);
12
 
define('CREATE_TIME_NEW',5);
13
 
define('CREATE_TIME_OLD',6);
14
 
unset ($forum_sort_styles);
15
 
$forum_sort_styles[MODIFIED_NEW] = "Most recent reply first";
16
 
//$forum_sort_styles[MODIFIED_OLD] = "Least recent reply first";
17
 
$forum_sort_styles[VIEWS_MOST] = "Most views first";
18
 
$forum_sort_styles[REPLIES_MOST] = "Most posts first";
19
 
$forum_sort_styles[CREATE_TIME_NEW] = "Most recently created first";
20
 
//$forum_sort_styles[CREATE_TIME_OLD] = "Least recently created first";
21
 
 
22
 
 
23
 
class Forum {
24
 
    // Container for the variables in the forum
25
 
    var $dbObj;
26
 
    // Container for the threads in this forum
27
 
    var $threads;
28
 
    var $dbhandler;
29
 
    /**
30
 
     * Constructor
31
 
     **/
32
 
    function Forum($id){
33
 
        global $mainFactory;
34
 
        $this->dbhandler = $mainFactory->getDatabaseHandler();
35
 
        $this->dbObj = $this->dbhandler->getForum($id);
36
 
        if (!$this->dbObj) error_page("Forum with id $id created but nothing returned from DB layer");
37
 
    }
38
 
    
39
 
    /**
40
 
     * The following functions simply return the fields for the forum. 
41
 
     **/
42
 
    function getID(){
43
 
        return $this->dbObj->id;
44
 
    }
45
 
    function getTitle(){
46
 
        return $this->dbObj->title;
47
 
    }
48
 
    function getDescription(){
49
 
        return $this->dbObj->description;
50
 
    }
51
 
    function getPostCount(){
52
 
        return $this->dbObj->posts;
53
 
    }
54
 
    function getThreadCount(){
55
 
        return $this->dbObj->threads;
56
 
    }
57
 
    function getLastTimestamp(){
58
 
        return $this->dbObj->timestamp;
59
 
    }
60
 
    function getPostMinTotalCredit(){
61
 
        return $this->dbObj->post_min_total_credit;
62
 
    }
63
 
    function getPostMinExpavgCredit(){
64
 
        return $this->dbObj->post_min_expavg_credit;
65
 
    }
66
 
    function getPostMinInterval(){
67
 
        return $this->dbObj->post_min_interval;
68
 
    }
69
 
    function getRateMinTotalCredit(){
70
 
        return $this->dbObj->rate_min_total_credit;
71
 
    }
72
 
    function getRateMinExpavgCredit(){
73
 
        return $this->dbObj->rate_min_expavg_credit;
74
 
    }
75
 
    function getCategory(){
76
 
        return new Category($this->dbObj->category);
77
 
    }
78
 
    function isDevBlog(){
79
 
       return $this->dbObj->is_dev_blog;
80
 
    }
81
 
    
82
 
    /**
83
 
     * Increase the post count for the forum (default by one)
84
 
     **/
85
 
    function incPostCount($amount=1){
86
 
        return ($this->dbhandler->updateForum($this, "posts", ($this->getPostCount()+$amount)) && 
87
 
                $this->dbhandler->updateForum($this, "timestamp", time()));
88
 
    }
89
 
    
90
 
    /**
91
 
     * Decrease the post count for the forum (default by one)
92
 
     **/
93
 
    function decPostCount($amount=1){
94
 
        return $this->dbhandler->updateForum($this, "posts", ($this->getPostCount()-$amount));
95
 
    }
96
 
    
97
 
    /**
98
 
     * Increase the thread count for the forum by one
99
 
     **/
100
 
    function incThreadCount(){
101
 
        return $this->dbhandler->updateForum($this, "threads", ($this->getThreadCount()+1));
102
 
    }
103
 
    
104
 
    /**
105
 
     * Decrease the thread count for the forum by one
106
 
     **/
107
 
    function decThreadCount(){
108
 
        return $this->dbhandler->updateForum($this, "threads", ($this->getThreadCount()-1));
109
 
    }
110
 
        
111
 
    /**
112
 
     * Return a list of threads for this forum
113
 
     **/
114
 
    function getThreads($start, $count, $sort_style=MODIFIED_NEW, $show_hidden=false, $sticky_first=true){
115
 
        if (!$this->threads){
116
 
            $list = $this->dbhandler->getThreads($this, $start, $count, $sort_style, $show_hidden, $sticky_first);
117
 
            if ($list) {
118
 
                foreach ($list as $key => $thread){
119
 
                    $this->threads[] = new Thread($thread->id, $thread);
120
 
                }
121
 
            } else {
122
 
                $this->threads = array();
123
 
            }
124
 
        }
125
 
        return $this->threads;
126
 
    }
127
 
    
128
 
    /**
129
 
     * Create a thread in this forum
130
 
     **/
131
 
    function createThread($title, $content, $user, $signature){
132
 
        return Thread::createNewThread($title, $content, $user, $this, $signature);
133
 
    }
134
 
 
135
 
}
136
 
 
137
 
/** 
138
 
 * This function returns a string containing a paged navigation bar 
139
 
 * for the given forum.  The default start place is 0. 
140
 
 **/
141
 
function show_page_nav($forum, $start=0){
142
 
    // How many pages to potentially show before and after this one:
143
 
    $preshow = 5; $postshow = 10;
144
 
    
145
 
    if ($forum->getThreadCount() > THREADS_PER_PAGE) {
146
 
        $total = ceil($forum->getThreadCount() / THREADS_PER_PAGE);
147
 
        $curpage = ceil($start / THREADS_PER_PAGE);
148
 
        // If this is not the first page, display "previous"
149
 
        if ($curpage > 0){
150
 
            $navbar = '<a href="forum_forum.php?id='.get_int("id").'&start='.(($curpage-1)*THREADS_PER_PAGE);
151
 
            $sort = get_int("sort",true);
152
 
            if ($sort) $navbar.='&sort='.$sort;
153
 
            $navbar.= '"> &lt;-- Previous</a> ';
154
 
        }
155
 
        
156
 
        // Display a list of pages surrounding this one
157
 
        for ($i=$curpage-$preshow;$i<($curpage+$postshow);$i++){
158
 
            if ($i<1) continue;
159
 
            if ($i>$total) break;
160
 
            if ($i == $curpage+1){$navbar.="<em>";} // If this is the current page, emphasize it.
161
 
            $navbar.='<a href="forum_forum.php?id='.get_int("id").'&start='.(($i-1)*THREADS_PER_PAGE);
162
 
            $sort = get_int("sort",true);
163
 
            if ($sort) $navbar.='&sort='.$sort;
164
 
            $navbar.='">'.$i.' |</a> ';
165
 
            if ($i == $curpage+1){$navbar.="</em>";}
166
 
        }
167
 
 
168
 
        // If there is a next page
169
 
        if ($curpage+1 < $total){
170
 
            $navbar.= '<a href="forum_forum.php?id='.get_int("id").'&start='.(($curpage+1)*THREADS_PER_PAGE);
171
 
            $sort = get_int("sort",true);
172
 
            if ($sort) $navbar.='&sort='.$sort;
173
 
            $navbar.= '"> Next --&gt;</a>';
174
 
        }
175
 
 
176
 
    }
177
 
    return $navbar;
178
 
}
179
 
?>