root/utils/stats.php

Revision 2162, 3.3 kB (checked in by Andrew Dolgov <fox@madoka.spb.ru>, 1 year ago)

[project @ tweak stats.php]

Line 
1 <?php
2     require_once "sessions.php";
3
4     require_once "sanity_check.php";
5     require_once "version.php";
6     require_once "config.php";
7     require_once "db-prefs.php";
8     require_once "functions.php";
9
10     $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);   
11
12     login_sequence($link);
13
14     if ($_SESSION["access_level"] < 10) {
15         print "<p>Error: your access level is insufficient to run this script.</p>";
16         exit;
17     }
18 ?>
19
20 <html>
21 <head>
22     <title>Tiny Tiny Statistics</title>
23     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
24 </head>
25
26 <body>
27
28 <h1>Tiny Tiny Statistics</h1>
29
30 <h2>Counters</h2>
31
32 <?php
33     $result = db_query($link, "SELECT count(id) AS cid,
34         SUM(LENGTH(content)) AS size
35         FROM ttrss_entries");
36
37     $total_articles = db_fetch_result($result, 0, "cid");
38     $articles_size = round(db_fetch_result($result, 0, "size") / 1024);
39
40     print "<p>Total articles stored: $total_articles (${articles_size}K)</p>";
41
42 /*    $result = db_query($link, "SELECT COUNT(int_id) as cid,owner_uid,login
43         FROM ttrss_user_entries
44             LEFT JOIN ttrss_users ON (owner_uid = ttrss_users.id)
45         GROUP BY owner_uid,login ORDER BY cid DESC"); */
46
47     $result = db_query($link, "SELECT count(ttrss_entries.id) AS cid,
48         login FROM ttrss_entries
49         LEFT JOIN ttrss_user_entries ON (ref_id = ttrss_entries.id)
50         LEFT JOIN ttrss_users ON (ttrss_users.id = ttrss_user_entries.owner_uid)
51             GROUP BY login");
52
53     print "<h2>Per-user storage</h2>";
54
55     print "<table border width='100%'>";
56     
57     print "<tr>
58         <td>Articles</td>
59         <td>Owner</td>
60     </tr>";
61
62     while ($line = db_fetch_assoc($result)) {
63         print "<tr>";
64         print "<td>" . $line["cid"] . "</td>";
65         print "<td>" . $line["login"] . "</td>";
66         print "</tr>";
67     }
68
69     print "</table>";
70
71     $result = db_query($link, "SELECT COUNT(ttrss_feeds.id) AS fc,
72         login FROM ttrss_users, ttrss_feeds
73             WHERE ttrss_users.id = ttrss_feeds.owner_uid
74         GROUP BY login ORDER BY fc DESC");
75
76     print "<h2>Per-user subscriptions</h2>";
77
78     print "<table border width='100%'>";
79     
80     print "<tr>
81         <td>Owner</td>
82         <td>Feeds</td>
83     </tr>";
84
85     while ($line = db_fetch_assoc($result)) {
86         print "<tr>";
87         print "<td>" . $line["login"] . "</td>";
88         print "<td>" . $line["fc"] . "</td>";
89         print "</tr>";
90     }
91
92     print "</table>";
93
94     print "<h2>User subscriptions</h2>";
95
96     $result = db_query($link, "SELECT title,feed_url,site_url,login,
97         (SELECT count(int_id) FROM ttrss_user_entries
98             WHERE feed_id = ttrss_feeds.id) AS num_articles,
99         (SELECT count(int_id) FROM ttrss_user_entries
100             WHERE feed_id = ttrss_feeds.id AND unread = true) AS num_articles_unread
101         FROM ttrss_feeds,ttrss_users
102         WHERE owner_uid = ttrss_users.id ORDER BY login");
103
104     print "<table border width='100%'>";
105     print "<tr>
106         <td>Site</td>
107         <td>Feed</td>
108         <td>Owner</td>
109         <td>Stored Articles</td>
110         <td>Unread Articles</td>
111     </tr>";
112
113     $cur_login = "";
114
115     while ($line = db_fetch_assoc($result)) {
116         print "<tr>";
117         print "<td><a href=\"".$line["site_url"]."\">".$line["title"]."</a></td>";
118         print "<td><a href=\"".$line["feed_url"]."\">".$line["feed_url"]."</a></td>";
119         print "<td>" . $line["login"] . "</td>";
120         print "<td>" . $line["num_articles"] . "</td>";
121         print "<td>" . $line["num_articles_unread"] . "</td>";
122         print "</tr>";
123
124         if ($cur_login != $line["login"] && $cur_login != "") {
125             print "<tr><td>&nbsp;</td></tr>";
126             $cur_login = $line["login"];
127         }
128     }
129
130     print "</table>";
131
132 ?>
133 </pre>
134
135 </body>
136 </html>
137
Note: See TracBrowser for help on using the browser.