/** * Statistics about stories, topics and authors * * You can reach the statistics from the admin part of the news module by clicking on the "Statistics" tabs * The number of visible elements in each table is equal to the module's option called "storycountadmin" * There are 3 kind of different statistics : * - Topics statistics * For each topic you can see its number of articles, the number of time each topics was viewed, the number * of attached files, the number of expired articles and the number of unique authors. * - Articles statistics * This part is decomposed in 3 tables : * a) Most readed articles * This table resumes, for all the news in your database, the most readed articles. * The table contains, for each news, its topic, its title, the author and the number of views. * b) Less readed articles * That's the opposite action of the previous table and its content is the same * c) Best rated articles * You will find here the best rated articles, the content is the same that the previous tables, the last column is just changing and contains the article's rating * - Authors statistics * This part is also decomposed in 3 tables * a) Most readed authors * To create this table, the program compute the total number of reads per author and displays the most readed author and the number of views * b) Best rated authors * To created this table's content, the program compute the rating's average of each author and create a table * c) Biggest contributors * The goal of this table is to know who is creating the biggest number of articles. */ function Stats() { global $xoopsModule, $xoopsConfig, $xoopsModuleConfig; xoops_cp_header(); $myts =& MyTextSanitizer::getInstance(); if (file_exists(XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php')) { include_once XOOPS_ROOT_PATH . '/modules/news/language/' . $xoopsConfig['language'] . '/main.php'; } else { include_once XOOPS_ROOT_PATH . '/modules/news/language/english/main.php'; } adminmenu(6); $news = new NewsStory(); $stats = array(); $stats = $news->GetStats($xoopsModuleConfig['storycountadmin']); $totals = array(0, 0, 0, 0, 0); printf("<h1>%s</h1>\n", _AM_NEWS_STATS); // First part of the stats, everything about topics $storiespertopic = $stats['storiespertopic']; $readspertopic = $stats['readspertopic']; $filespertopic = $stats['filespertopic']; $expiredpertopic = $stats['expiredpertopic']; $authorspertopic = $stats['authorspertopic']; $class = ''; echo "<div style='text-align: center;'><b>" . _AM_NEWS_STATS0 . "</b><br />\n"; echo "<table border='1' width='100%'><tr class='bg3'><td align='center'>" . _AM_TOPIC . "</td><td align='center'>" . _NW_ARTICLES . "</td><td>" . _NW_VIEWS . "</td><td>" . _AM_UPLOAD_ATTACHFILE . "</td><td>" . _AM_EXPARTS . "</td><td>" . _AM_NEWS_STATS1 . "</td></tr>"; foreach ($storiespertopic as $topicid => $data) { $url = XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/index.php?storytopic=" . $topicid; $views = 0; if (array_key_exists($topicid, $readspertopic)) { $views = $readspertopic[$topicid]; } $attachedfiles = 0; if (array_key_exists($topicid, $filespertopic)) { $attachedfiles = $filespertopic[$topicid]; } $expired = 0; if (array_key_exists($topicid, $expiredpertopic)) { $expired = $expiredpertopic[$topicid]; } $authors = 0; if (array_key_exists($topicid, $authorspertopic)) { $authors = $authorspertopic[$topicid]; } $articles = $data['cpt']; $totals[0] += $articles; $totals[1] += $views; $totals[2] += $attachedfiles; $totals[3] += $expired; $class = $class == 'even' ? 'odd' : 'even'; printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td><td align='right'>%u</td><td align='right'>%u</td><td align='right'>%u</td><td align='right'>%u</td></tr>\n", $url, $myts->displayTarea($data['topic_title']), $articles, $views, $attachedfiles, $expired, $authors); } $class = $class == 'even' ? 'odd' : 'even'; printf("<tr class='" . $class . "'><td align='center'><b>%s</b></td><td align='right'><b>%u</b></td><td align='right'><b>%u</b></td><td align='right'><b>%u</b></td><td align='right'><b>%u</b></td><td> </td>\n", _AM_NEWS_STATS2, $totals[0], $totals[1], $totals[2], $totals[3]); echo "</table></div><br /><br /><br />"; // Second part of the stats, everything about stories // a) Most readed articles $mostreadednews = $stats['mostreadednews']; echo "<div style='text-align: center;'><b>" . _AM_NEWS_STATS3 . "</b><br /><br />" . _AM_NEWS_STATS4 . "<br />\n"; echo "<table border='1' width='100%'><tr class='bg3'><td align='center'>" . _AM_TOPIC . "</td><td align='center'>" . _AM_TITLE . "</td><td>" . _AM_POSTER . "</td><td>" . _NW_VIEWS . "</td></tr>\n"; foreach ($mostreadednews as $storyid => $data) { $url1 = XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/index.php?storytopic=" . $data['topicid']; $url2 = XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/article.php?storyid=" . $storyid; $url3 = XOOPS_URL . '/userinfo.php?uid=' . $data['uid']; $class = $class == 'even' ? 'odd' : 'even'; printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='left'><a href='%s' target='_blank'>%s</a></td><td><a href='%s' target='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url1, $myts->displayTarea($data['topic_title']), $url2, $myts->displayTarea($data['title']), $url3, $myts->htmlSpecialChars($news->uname($data['uid'])), $data['counter']); } echo "</table>"; // b) Less readed articles $lessreadednews = $stats['lessreadednews']; echo '<br /><br />' . _AM_NEWS_STATS5; echo "<table border='1' width='100%'><tr class='bg3'><td align='center'>" . _AM_TOPIC . "</td><td align='center'>" . _AM_TITLE . "</td><td>" . _AM_POSTER . "</td><td>" . _NW_VIEWS . "</td></tr>\n"; foreach ($lessreadednews as $storyid => $data) { $url1 = XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/index.php?storytopic=" . $data['topicid']; $url2 = XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/article.php?storyid=" . $storyid; $url3 = XOOPS_URL . '/userinfo.php?uid=' . $data['uid']; $class = $class == 'even' ? 'odd' : 'even'; printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='left'><a href='%s' target='_blank'>%s</a></td><td><a href='%s' target='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url1, $myts->displayTarea($data['topic_title']), $url2, $myts->displayTarea($data['title']), $url3, $myts->htmlSpecialChars($news->uname($data['uid'])), $data['counter']); } echo "</table>"; // c) Best rated articles (this is an average) $besratednews = $stats['besratednews']; echo '<br /><br />' . _AM_NEWS_STATS6; echo "<table border='1' width='100%'><tr class='bg3'><td align='center'>" . _AM_TOPIC . "</td><td align='center'>" . _AM_TITLE . "</td><td>" . _AM_POSTER . "</td><td>" . _NW_RATING . "</td></tr>\n"; foreach ($besratednews as $storyid => $data) { $url1 = XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/index.php?storytopic=" . $data['topicid']; $url2 = XOOPS_URL . "/modules/" . $xoopsModule->dirname() . "/article.php?storyid=" . $storyid; $url3 = XOOPS_URL . '/userinfo.php?uid=' . $data['uid']; $class = $class == 'even' ? 'odd' : 'even'; printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='left'><a href='%s' target='_blank'>%s</a></td><td><a href='%s' target='_blank'>%s</a></td><td align='right'>%s</td></tr>\n", $url1, $myts->displayTarea($data['topic_title']), $url2, $myts->displayTarea($data['title']), $url3, $myts->htmlSpecialChars($news->uname($data['uid'])), number_format($data['rating'], 2)); } echo "</table></div><br /><br /><br />"; // Last part of the stats, everything about authors // a) Most readed authors $mostreadedauthors = $stats['mostreadedauthors']; echo "<div style='text-align: center;'><b>" . _AM_NEWS_STATS10 . "</b><br /><br />" . _AM_NEWS_STATS7 . "<br />\n"; echo "<table border='1' width='100%'><tr class='bg3'><td>" . _AM_POSTER . "</td><td>" . _NW_VIEWS . "</td></tr>\n"; foreach ($mostreadedauthors as $uid => $reads) { $url = XOOPS_URL . '/userinfo.php?uid=' . $uid; $class = $class == 'even' ? 'odd' : 'even'; printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, $myts->htmlSpecialChars($news->uname($uid)), $reads); } echo "</table>"; // b) Best rated authors $bestratedauthors = $stats['bestratedauthors']; echo '<br /><br />' . _AM_NEWS_STATS8; echo "<table border='1' width='100%'><tr class='bg3'><td>" . _AM_POSTER . "</td><td>" . _NW_RATING . "</td></tr>\n"; foreach ($bestratedauthors as $uid => $rating) { $url = XOOPS_URL . '/userinfo.php?uid=' . $uid; $class = $class == 'even' ? 'odd' : 'even'; printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, $myts->htmlSpecialChars($news->uname($uid)), $rating); } echo "</table>"; // c) Biggest contributors $biggestcontributors = $stats['biggestcontributors']; echo '<br /><br />' . _AM_NEWS_STATS9; echo "<table border='1' width='100%'><tr class='bg3'><td>" . _AM_POSTER . "</td><td>" . _AM_NEWS_STATS11 . "</td></tr>\n"; foreach ($biggestcontributors as $uid => $count) { $url = XOOPS_URL . '/userinfo.php?uid=' . $uid; $class = $class == 'even' ? 'odd' : 'even'; printf("<tr class='" . $class . "'><td align='left'><a href='%s' target ='_blank'>%s</a></td><td align='right'>%u</td></tr>\n", $url, $myts->htmlSpecialChars($news->uname($uid)), $count); } echo "</table></div><br />"; }