~ubuntu-branches/ubuntu/saucy/php-net-nntp/saucy

« back to all changes in this revision

Viewing changes to Net_NNTP-1.5.0RC3/docs/examples/demo/groups.php

  • Committer: Package Import Robot
  • Author(s): Jan-Pascal van Best
  • Date: 2013-05-31 23:38:17 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130531233817-4yi3exxgq17g6c4h
Tags: 1.5.0-1
New upstream release 1.5.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
 
 
4
 
/**
5
 
 * 
6
 
 * 
7
 
 * PHP versions 4 and 5
8
 
 *
9
 
 * <pre>
10
 
 * +-----------------------------------------------------------------------+
11
 
 * |                                                                       |
12
 
 * | W3C� SOFTWARE NOTICE AND LICENSE                                      |
13
 
 * | http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231   |
14
 
 * |                                                                       |
15
 
 * | This work (and included software, documentation such as READMEs,      |
16
 
 * | or other related items) is being provided by the copyright holders    |
17
 
 * | under the following license. By obtaining, using and/or copying       |
18
 
 * | this work, you (the licensee) agree that you have read, understood,   |
19
 
 * | and will comply with the following terms and conditions.              |
20
 
 * |                                                                       |
21
 
 * | Permission to copy, modify, and distribute this software and its      |
22
 
 * | documentation, with or without modification, for any purpose and      |
23
 
 * | without fee or royalty is hereby granted, provided that you include   |
24
 
 * | the following on ALL copies of the software and documentation or      |
25
 
 * | portions thereof, including modifications:                            |
26
 
 * |                                                                       |
27
 
 * | 1. The full text of this NOTICE in a location viewable to users       |
28
 
 * |    of the redistributed or derivative work.                           |
29
 
 * |                                                                       |
30
 
 * | 2. Any pre-existing intellectual property disclaimers, notices,       |
31
 
 * |    or terms and conditions. If none exist, the W3C Software Short     |
32
 
 * |    Notice should be included (hypertext is preferred, text is         |
33
 
 * |    permitted) within the body of any redistributed or derivative      |
34
 
 * |    code.                                                              |
35
 
 * |                                                                       |
36
 
 * | 3. Notice of any changes or modifications to the files, including     |
37
 
 * |    the date changes were made. (We recommend you provide URIs to      |
38
 
 * |    the location from which the code is derived.)                      |
39
 
 * |                                                                       |
40
 
 * | THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT    |
41
 
 * | HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED,    |
42
 
 * | INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR        |
43
 
 * | FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE    |
44
 
 * | OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS,           |
45
 
 * | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.                               |
46
 
 * |                                                                       |
47
 
 * | COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT,        |
48
 
 * | SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE        |
49
 
 * | SOFTWARE OR DOCUMENTATION.                                            |
50
 
 * |                                                                       |
51
 
 * | The name and trademarks of copyright holders may NOT be used in       |
52
 
 * | advertising or publicity pertaining to the software without           |
53
 
 * | specific, written prior permission. Title to copyright in this        |
54
 
 * | software and any associated documentation will at all times           |
55
 
 * | remain with copyright holders.                                        |
56
 
 * |                                                                       |
57
 
 * +-----------------------------------------------------------------------+
58
 
 * </pre>
59
 
 *
60
 
 * @category   Net
61
 
 * @package    Net_NNTP
62
 
 * @author     Heino H. Gehlsen <heino@gehlsen.dk>
63
 
 * @copyright  2002-2011 Heino H. Gehlsen <heino@gehlsen.dk>. All Rights Reserved.
64
 
 * @license    http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 W3C� SOFTWARE NOTICE AND LICENSE
65
 
 * @version    SVN: $Id: groups.php 306619 2010-12-24 12:16:07Z heino $
66
 
 * @link       http://pear.php.net/package/Net_NNTP
67
 
 * @see        
68
 
 * @since      File available since release 1.3.0
69
 
 */
70
 
 
71
 
/**
72
 
 *
73
 
 */
74
 
require_once 'config.inc.php';
75
 
 
76
 
/**
77
 
 * 
78
 
 */
79
 
require_once 'common.inc.php';
80
 
 
81
 
 
82
 
/* Prepare breadcrumbs */
83
 
 
84
 
$breadcrumbs = array();
85
 
$breadcrumbs['Frontpage'] = './index.php?' . query();
86
 
$breadcrumbs['Groups @ ' . ($host == null ? 'localhost' : $host)] = null;
87
 
 
88
 
// Connect
89
 
$posting = $nntp->connect($host, $encryption, $port);
90
 
if (PEAR::isError($posting)) {
91
 
    error('Unable to connect to NNTP server: ' . $posting->getMessage());
92
 
}
93
 
 
94
 
// Start TLS encryption
95
 
if ($starttls) {
96
 
    $R = $nntp->cmdStartTLS();
97
 
    if (PEAR::isError($R)) {
98
 
        error('Unable to connect to NNTP server: ' . $R->getMessage());
99
 
    }
100
 
}
101
 
 
102
 
// Authenticate
103
 
if (!is_null($user) && !is_null($pass)) {
104
 
    $authenticated = $nntp->authenticate($user, $pass);
105
 
    if (PEAR::isError($authenticated)) {
106
 
        error('Unable to authenticate: ' . $authenticated->getMessage());
107
 
    }
108
 
}
109
 
 
110
 
// Fetch list of groups
111
 
$groups = $nntp->getGroups($wildmat);
112
 
if (PEAR::isError($groups)) {
113
 
    error('Fetching list of groups failed: ' . $groups->getMessage());
114
 
}
115
 
 
116
 
// Fetch known (to the server) group descriptions
117
 
$descriptions = $nntp->getDescriptions($wildmat);
118
 
if (PEAR::isError($descriptions)) {
119
 
    $logger->notice('Fetching group descriptions failes: ' . $descriptions->getMessage());
120
 
 
121
 
    //
122
 
    $descriptions = array();
123
 
}
124
 
 
125
 
// Close connection
126
 
$nntp->disconnect();
127
 
 
128
 
 
129
 
/**
130
 
 *
131
 
 */
132
 
function groups()
133
 
{
134
 
    //
135
 
    extract($GLOBALS);
136
 
        
137
 
    //
138
 
    echo '<table border="0" cellpadding="3" cellspacing="4">', "\r\n";
139
 
    echo '<tr><th>Group</th><th>Articles</th><th>Description</th><th>Posting</th></tr>', "\r\n";
140
 
 
141
 
    // Loop through groups
142
 
    $i = 0;
143
 
    foreach ($groups as $group) {
144
 
 
145
 
        $link = 'group.php?' . query('group='.urlencode($group['group']));
146
 
 
147
 
        $messageCount = $group['last'] - $group['first'] + 1;
148
 
 
149
 
        $description = empty($descriptions[$group['group']]) ? '' : $descriptions[$group['group']];
150
 
 
151
 
        switch ($group['posting']) {
152
 
        case 'y': $posting = 'yes'; break;
153
 
        case 'n': $posting = 'no'; break;
154
 
        case 'm': $posting = 'moderated'; break;
155
 
        default: $posting = 'unknown';
156
 
        }
157
 
 
158
 
        echo ' <tr class="group ', ($i++ % 2 ? 'even' : 'odd'), ' posting-', $posting, '">', "\r\n";
159
 
        echo '  <td align="left" class="name"><a href="', $link, '">', $group['group'], '</a></td>', "\r\n";
160
 
        echo '  <td align="center" class="count">', $messageCount, '</td>', "\r\n";
161
 
        echo '  <td align="left" class="description">', $description, '</td>', "\r\n";
162
 
        echo '  <td align="center" class="posting">', $posting, '</td>', "\r\n";
163
 
        echo ' </tr>', "\r\n";
164
 
    }
165
 
 
166
 
    //
167
 
    echo '</table>', "\r\n";
168
 
}
169
 
 
170
 
 
171
 
/**********/
172
 
/* Output */
173
 
/**********/
174
 
 
175
 
/**
176
 
 * Output header
177
 
 */
178
 
include 'header.inc.php';
179
 
 
180
 
 
181
 
//
182
 
$logger->dump();
183
 
 
184
 
// 
185
 
groups();
186
 
 
187
 
/**
188
 
 * Output footer
189
 
 */
190
 
include 'footer.inc.php';
191
 
 
192
 
?>