d34c96f4608566729b92392dd5980a689b1ca418
[banana.git] / include / groups.inc.php
1 <?php
2 /********************************************************************************
3 * include/groups.inc.php : class for group lists
4 * ------------------------
5 *
6 * This file is part of the banana distribution
7 * Copyright: See COPYING files that comes with this distribution
8 ********************************************************************************/
9
10 /** class for group lists
11 */
12
13 class BananaGroups {
14 /** group list */
15 var $overview;
16 /** last update */
17 var $date;
18
19 /** constructor
20 * @param $_nntp RESOURCE handle to NNTP socket
21 */
22
23 function BananaGroups(&$_nntp,$_type=0) {
24 global $profile;
25 $desc=$_nntp->xgtitle();
26 if ($_type==1) {
27 $list=$_nntp->newgroups($profile['lastnews']);
28 } else {
29 $list=$_nntp->liste();
30 }
31 if (!$list) {
32 $this->overview=array();
33 return false;
34 }
35 if (isset($desc)) {
36 foreach ($desc as $g=>$d) {
37 if ((($_type==0) and (in_array($g,$profile['subscribe']) or !count($profile['subscribe'])))
38 or (($_type==1) and in_array($g,array_keys($list)))
39 or ($_type==2)) {
40 $this->overview[$g][0]=$d;
41 $this->overview[$g][1]=$list[$g][0];
42 }
43 }
44 foreach (array_diff(array_keys($list),array_keys($desc)) as $g) {
45 if ((($_type==0) and (in_array($g,$profile['subscribe']) or !count($profile['subscribe'])))
46 or (($_type==1) and in_array($g,array_keys($list)))
47 or ($_type==2)) {
48 $this->overview[$g][0]="-";
49 $this->overview[$g][1]=$list[$g][0];
50 }
51 }
52 } else {
53 foreach ($list as $g=>$l) {
54 if ((($_type==0) and (!count($profile['subscribe']) and in_array($g,$profile['subscribe'])))
55 or (($_type==1) and in_array($g,array_keys($list)))
56 or ($_type==2)) {
57 $this->overview[$g][0]="-";
58 $this->overview[$g][1]=$l[0];
59 }
60 }
61 }
62 return true;
63 }
64
65 /** updates overview
66 * @param $_nntp RESOURCE handle to NNTP socket
67 * @param date INTEGER date of last update
68 */
69 function update(&$_nntp,$_date) {
70 $serverdate = $_nntp->date();
71 if (!$serverdate) $serverdate=time();
72 $newlist = $_nntp->newgroups($_date);
73 if (!$newlist) return false;
74 $this->date = $serverdate;
75 foreach (array_keys($newlist) as $g) {
76 $groupstat = $_nntp->group($g);
77 $groupdesc = $_nntp->xgtitle($g);
78 $this->overview[$g][0]=($groupdesc?$groupdesc:"-");
79 $this->overview[$g][1]=$groupstat[0];
80 }
81 return true;
82 }
83 }
84
85 ?>