public function Index($params)
 {
     $this->view->Show('articles.tpl', array('articles' => Article::Find($this->conn, $params['authId'], $params['catId'], $params['pubDate']), 'authors' => array(-1 => '- Все -') + Author::GetAll($this->conn), 'authId' => $params['authId'], 'cats' => array(-1 => '- Все -') + Category::GetAll($this->conn), 'catId' => $params['catId'], 'pubDates' => array(-1 => '- Все -', -2 => 'За эту неделю', -3 => 'За этот год'), 'pubDate ' => $params['pubDate']));
 }
Example #2
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');
 }
Example #3
0
 public function Recalculate()
 {
     try {
         $this->size = (double) 0;
         $this->files = 0;
         $this->parts_total = 0;
         $this->parts_found = 0;
         $altsize = (double) 0;
         $stats = array();
         $articles = Article::Find(null, 'SELECT "subject","authorid","parts_total","parts_found","size","post_date" FROM "articles" WHERE "postid" = ' . $this->id . ' ORDER BY "post_date" ASC');
         if (!is_array($articles)) {
             $articles = array($articles);
         }
         foreach ($articles as $article) {
             $this->files++;
             if (!preg_match('/(\\.)(par2|nzb|sfv|md5|nfo)/i', $article->subject, $matches)) {
                 $this->size += (double) $article->size;
             }
             $altsize += (double) $article->size;
             if (empty($this->subject) || empty($this->authorid) || empty($this->post_date) || $article->post_date > $this->post_date) {
                 $this->subject = $article->subject;
                 $this->authorid = $article->authorid;
                 if ($article->post_date < time()) {
                     $this->post_date = $article->post_date;
                 }
             }
             $this->parts_total += $article->parts_total;
             $this->parts_found += $article->parts_found;
             // Build stats
             if (stripos($article->subject, '.par2') !== false) {
                 $stats['par2'] = isset($stats['par2']) ? $stats['par2'] + 1 : 1;
             } elseif (stripos($article->subject, '.exe') !== false) {
                 $stats['exe'] = isset($stats['exe']) ? $stats['exe'] + 1 : 1;
             } elseif (preg_match('/(\\.)(part\\d+)(\\.rar)/i', $article->subject, $matches)) {
                 $stats['rar'] = isset($stats['rar']) ? $stats['rar'] + 1 : 1;
             } elseif (preg_match('/(\\.)(r\\d{2,3})/i', $article->subject, $matches)) {
                 $stats['rar'] = isset($stats['rar']) ? $stats['rar'] + 1 : 1;
             } elseif (preg_match('/(\\.)(\\d{3,4})/i', str_ireplace(array('.264', '.480', '.720', '.1080'), '', $article->subject), $matches)) {
                 $stats['split'] = isset($stats['split']) ? $stats['split'] + 1 : 1;
             } elseif (stripos($article->subject, '.par') !== false) {
                 $stats['par'] = isset($stats['par']) ? $stats['par'] + 1 : 1;
             } elseif (stripos($article->subject, '.nzb') !== false) {
                 $stats['nzb'] = isset($stats['nzb']) ? $stats['nzb'] + 1 : 1;
             } elseif (stripos($article->subject, '.sfv') !== false) {
                 $stats['sfv'] = isset($stats['sfv']) ? $stats['sfv'] + 1 : 1;
             } elseif (stripos($article->subject, '.md5') !== false) {
                 $stats['md5'] = isset($stats['md5']) ? $stats['md5'] + 1 : 1;
             } elseif (stripos($article->subject, '.rar') !== false) {
                 $stats['rar'] = isset($stats['rar']) ? $stats['rar'] + 1 : 1;
             } elseif (stripos($article->subject, '.zip') !== false) {
                 $stats['zip'] = isset($stats['zip']) ? $stats['zip'] + 1 : 1;
             } elseif (stripos($article->subject, '.nfo') !== false) {
                 $stats['nfo'] = isset($stats['nfo']) ? $stats['nfo'] + 1 : 1;
             } elseif (stripos($article->subject, '.jpg') !== false) {
                 $stats['jpg'] = isset($stats['jpg']) ? $stats['jpg'] + 1 : 1;
             } elseif (stripos($article->subject, '.jpeg') !== false) {
                 $stats['jpg'] = isset($stats['jpg']) ? $stats['jpg'] + 1 : 1;
             } elseif (stripos($article->subject, '.gif') !== false) {
                 $stats['gif'] = isset($stats['gif']) ? $stats['gif'] + 1 : 1;
             } elseif (stripos($article->subject, '.png') !== false) {
                 $stats['png'] = isset($stats['png']) ? $stats['png'] + 1 : 1;
             } elseif (stripos($article->subject, '.mp3') !== false) {
                 $stats['mp3'] = isset($stats['mp3']) ? $stats['mp3'] + 1 : 1;
             } elseif (stripos($article->subject, '.ogg') !== false) {
                 $stats['ogg'] = isset($stats['ogg']) ? $stats['ogg'] + 1 : 1;
             } elseif (stripos($article->subject, '.flac') !== false) {
                 $stats['flac'] = isset($stats['flac']) ? $stats['flac'] + 1 : 1;
             } else {
                 $stats['other'] = isset($stats['other']) ? $stats['other'] + 1 : 1;
             }
         }
         // Check if filtering out files caused size to be zero, if so, forget filtering
         if ($this->size == 0) {
             $this->size = $altsize;
         }
         ksort($stats);
         $this->stats = http_build_query($stats);
     } catch (ActiveRecord_NotFoundException $e) {
     }
 }