Beispiel #1
0
 protected function Details($id)
 {
     // Details screen may use a lot of memory if there are a lot of files in a post
     ini_set('memory_limit', '512M');
     $template = new Template();
     $result = '';
     // Get post
     try {
         $post = Post::FindByID($id);
         $author = Author::FindByID($post->authorid);
     } catch (ActiveRecord_NotFoundException $e) {
         die('<b>Error</b>: post ' . SafeHTML($this->params[0]) . ' does not exist.');
     }
     // Cache newsgroups
     try {
         $newsgroups = array();
         $groups = Newsgroup::FindAll();
         if (!is_array($groups)) {
             $groups = array($groups);
         }
         foreach ($groups as $group) {
             $newsgroups[$group->id] = $group->name;
         }
     } catch (ActiveRecord_NotFoundException $e) {
         die('<b>Error</b>: database problem - no newsgroups defined.');
     }
     $result .= '<table cellspacing="0"><tr><th>Poster</th><th>Newsgroups</th></tr>' . "\n";
     $poster = trim(preg_replace('/\\s+/', ' ', str_replace(array('@', '(', ')', '[', ']', ',', '.', '!', '-', '#', '^', '$', '+', '/', '\\'), ' ', $author->name)));
     $result .= '<tr><td class="split"><a href="' . static::$config['url']['base'] . '?' . http_build_query(array('q' => '@poster ' . $poster), '', '&amp;') . '">' . SafeHTML($author->name) . '</a></td><td class="split">';
     try {
         $list = array();
         $groups = PostGroup::FindByPostID($post->id);
         if (!is_array($groups)) {
             $list[] = $newsgroups[$groups->groupid];
         } else {
             foreach ($groups as $group) {
                 $list[] = $newsgroups[$group->groupid];
             }
         }
         $result .= implode('<br />', $list);
     } catch (ActiveRecord_NotFoundException $e) {
         die('<b>Error</b>: database problem - post is not associated with any newsgroup.');
     }
     $result .= '</tr>' . "\n" . '</table><br />' . "\n";
     // Get files
     try {
         $result .= '<table cellspacing="0">' . "\n";
         $result .= '<tr><th>Date</th><th>Subject</th><th>Parts</th><th>Size</th></tr>' . "\n";
         $articles = Article::Find(null, 'SELECT * FROM `articles` WHERE `postid` = ' . $post->id . ' ORDER BY `subject` ASC');
         if (!is_array($articles)) {
             $articles = array($articles);
         }
         foreach ($articles as $article) {
             $result .= '<tr>' . "\n";
             $result .= '<td class="date">' . gmdate('Y-m-d H:i', $article->post_date) . '</td>' . "\n";
             $result .= '<td class="subject">' . SafeHTML($article->subject) . '</td>';
             if ($article->parts_found != $article->parts_total) {
                 $result .= '<td class="parts"><span class="warning">' . SafeHTML($article->parts_found) . ' / ' . SafeHTML($article->parts_total) . '</span></td>';
             } else {
                 $result .= '<td class="parts">' . SafeHTML($article->parts_found) . ' / ' . SafeHTML($article->parts_total) . '</span></td>';
             }
             $result .= '<td class="size">' . FormatSize($article->size, 2) . '</td>';
             $result .= '</tr>' . "\n";
         }
         $result .= '</table>' . "\n";
     } catch (ActiveRecord_NotFoundException $e) {
         die('<b>Error</b>: database problem - post has no associated articles.');
     }
     $template->body = $result;
     $template->Display('layout_ajax');
 }
Beispiel #2
0
 public static function NZB($postid)
 {
     static::Init();
     $result = '';
     // Get newsgroups
     $groups = '';
     $rs = static::$conn->Execute('SELECT "groupid" FROM "postgroup" WHERE "postid" = ? ', $postid);
     while ($row = $rs->Fetch()) {
         $groups .= "\t\t\t<group>" . Newsgroup::Lookup($row['groupid']) . "</group>\n";
     }
     // Get files
     $rs = static::$conn->Execute('SELECT "subject","authorid","parts","post_date" FROM "articles" WHERE "postid" = ? ', $postid);
     while ($row = $rs->Fetch()) {
         if (strlen($row['parts']) == 0) {
             continue;
         }
         // Empty parts value = SKIP file
         $parts = unserialize(gzinflate($row['parts']));
         if (isset($parts['id']) && isset($parts['size'])) {
             $result .= "\t" . '<file poster="' . SafeHTML(Author::Lookup($row['authorid'])) . '" date="' . $row['post_date'] . '" subject="' . SafeHTML($row['subject']) . '">' . "\n";
             // Groups
             $result .= "\t\t<groups>\n" . $groups . "\t\t</groups>\n";
             // Segments
             $result .= "\t\t<segments>\n";
             ksort($parts['size']);
             foreach ($parts['size'] as $key => $value) {
                 if (isset($parts['id'][$key])) {
                     $result .= "\t\t\t" . '<segment bytes="' . $value . '" number="' . $key . '">' . SafeHTML($parts['id'][$key]) . "</segment>\n";
                 }
             }
             $result .= "\t\t</segments>\n";
             $result .= "\t</file>\n";
         }
     }
     return $result;
 }