Exemplo n.º 1
0
 public static function mainSearch($user_id, $tracker, $user)
 {
     $user = iconv("utf-8", "windows-1251", $user);
     $page = tfileSearch::getSearchPage($user);
     if (preg_match_all('/<td class=\\"f\\">\\n\\t\\t\\t\\t\\n\\t\\t\\t\\t\\t(.*)\\n\\t\\t\\t\\t<\\/td>/', $page, $section)) {
         for ($i = 0; $i < count($section[1]); $i++) {
             preg_match_all('/<a href=\\"viewforum\\.php\\?f=\\d{1,9}\\">(.*)<\\/a>/U', $section[1][$i], $sections);
             $sectionStr = '';
             for ($x = 0; $x < count($sections[1]); $x++) {
                 $sectionStr .= $sections[1][$x] . ', ';
             }
             $sectionStr = substr($sectionStr, 0, -2);
             $sectionArr[] = $sectionStr;
         }
     }
     preg_match_all('/<a href=\\"viewtopic\\.php\\?t=(\\d{1,9})\\">(.*)<\\/a>/U', $page, $threme);
     if (!empty($threme)) {
         for ($i = 0; $i < count($threme[1]); $i++) {
             Database::addThremeToBuffer($user_id, $sectionArr[$i], $threme[1][$i], $threme[2][$i], $tracker);
         }
     }
     $toDownload = Database::takeToDownload($tracker);
     if (count($toDownload) > 0) {
         for ($i = 0; $i < count($toDownload); $i++) {
             //получаем страницу для парсинга
             $page = tfile::getContent($toDownload[$i]['threme_id']);
             //сохраняем торрент в файл
             $torrent_id = tfile::findId($page);
             if (is_string($torrent_id)) {
                 if (Database::getSetting('download')) {
                     $torrent = tfile::getTorrent($torrent_id);
                     $client = ClientAdapterFactory::getStorage('file');
                     $client->store($torrent, $toDownload[$i]['id'], $tracker, $toDownload[$i]['threme'], $toDownload[$i]['threme_id'], time());
                 }
                 //обновляем время регистрации торрента в базе
                 Database::setDownloaded($toDownload[$i]['id']);
                 //отправляем уведомлении о новом торренте
                 $message = $toDownload[$i]['threme'] . ' добавлена для скачивания.';
                 $date = date('d M Y H:i');
                 Notification::sendNotification('notification', $date, $tracker, $message);
             } else {
                 //устанавливаем варнинг
                 if (tfile::$warning == NULL) {
                     tfile::$warning = TRUE;
                     Errors::setWarnings($tracker, 'not_available');
                 }
                 //останавливаем процесс выполнения, т.к. не может работать без кук
                 tfile::$exucution = FALSE;
             }
         }
     }
 }
Exemplo n.º 2
0
 public static function main($id, $tracker, $name, $torrent_id, $timestamp)
 {
     tfile::$exucution = TRUE;
     if (tfile::$exucution) {
         //получаем страницу для парсинга
         $page = tfile::getContent($torrent_id);
         if (!empty($page)) {
             //ищем на странице дату регистрации торрента
             if (preg_match("/class=\"regDate\">(.+)<\\/span>/", $page, $array)) {
                 //проверяем удалось ли получить дату со страницы
                 if (isset($array[1])) {
                     //если дата не равна ничему
                     if (!empty($array[1])) {
                         //сбрасываем варнинг
                         Database::clearWarnings($tracker);
                         //приводим дату к общему виду
                         $date = tfile::dateStringToNum($array[1]);
                         $date_str = tfile::dateNumToString($array[1]);
                         //если даты не совпадают, перекачиваем торрент
                         if ($date != $timestamp) {
                             //ищем на странице id торрента
                             $torrent_id = tfile::findId($page);
                             if (is_string($torrent_id)) {
                                 if (Database::getSetting('download')) {
                                     //сохраняем торрент в файл
                                     $torrent = tfile::getTorrent($torrent_id);
                                     $client = ClientAdapterFactory::getStorage('file');
                                     $client->store($torrent, $id, $tracker, $name, $torrent_id, $timestamp);
                                 }
                                 //обновляем время регистрации торрента в базе
                                 Database::setNewDate($id, $date);
                                 //отправляем уведомлении о новом торренте
                                 $message = $name . ' обновлён.';
                                 Notification::sendNotification('notification', $date_str, $tracker, $message);
                             } else {
                                 //устанавливаем варнинг
                                 if (tfile::$warning == NULL) {
                                     tfile::$warning = TRUE;
                                     Errors::setWarnings($tracker, 'not_available');
                                 }
                                 //останавливаем процесс выполнения, т.к. не может работать без кук
                                 tfile::$exucution = FALSE;
                             }
                         }
                     } else {
                         //устанавливаем варнинг
                         if (tfile::$warning == NULL) {
                             tfile::$warning = TRUE;
                             Errors::setWarnings($tracker, 'not_available');
                         }
                         //останавливаем процесс выполнения, т.к. не может работать без кук
                         tfile::$exucution = FALSE;
                     }
                 } else {
                     //устанавливаем варнинг
                     if (tfile::$warning == NULL) {
                         tfile::$warning = TRUE;
                         Errors::setWarnings($tracker, 'not_available');
                     }
                     //останавливаем процесс выполнения, т.к. не может работать без кук
                     tfile::$exucution = FALSE;
                 }
             } else {
                 //устанавливаем варнинг
                 if (tfile::$warning == NULL) {
                     tfile::$warning = TRUE;
                     Errors::setWarnings($tracker, 'not_available');
                 }
                 //останавливаем процесс выполнения, т.к. не может работать без кук
                 tfile::$exucution = FALSE;
             }
         } else {
             //устанавливаем варнинг
             if (tfile::$warning == NULL) {
                 tfile::$warning = TRUE;
                 Errors::setWarnings($tracker, 'not_available');
             }
             //останавливаем процесс выполнения, т.к. не может работать без кук
             tfile::$exucution = FALSE;
         }
     }
 }