diff --git a/app/Repositories/TrackerRepository.php b/app/Repositories/TrackerRepository.php index dfc70f20..203b8508 100644 --- a/app/Repositories/TrackerRepository.php +++ b/app/Repositories/TrackerRepository.php @@ -90,16 +90,19 @@ class TrackerRepository extends BaseRepository } /** - * Note: Must update snatch first, otherwise peer last_action already change + * Note: Must update snatch first, otherwise peer `last_action` already change */ $snatch = $this->updateSnatch($peerSelf, $queries, $dataTraffic); if ($queries['event'] == 'completed') { $this->handleHitAndRun($user, $torrent, $snatch); } - $this->updatePeer($peerSelf, $queries); + /** + * Note: Must update torrent first, otherwise peer `exists` property already change + */ + $this->updateTorrent($torrent, $queries, $peerSelf); - $this->updateTorrent($torrent, $queries); + $this->updatePeer($peerSelf, $queries); if ($dataTraffic['uploaded_increment_for_user'] > 0) { $this->userUpdates['uploaded'] = DB::raw('uploaded + ' . $dataTraffic['uploaded_increment_for_user']); @@ -628,24 +631,30 @@ class TrackerRepository extends BaseRepository $realUploaded = max(bcsub($queries['uploaded'], $peer->uploaded), 0); $realDownloaded = max(bcsub($queries['downloaded'], $peer->downloaded), 0); $log .= ", [PEER_EXISTS], realUploaded: $realUploaded, realDownloaded: $realDownloaded"; + $spStateReal = $torrent->spStateReal; + $uploaderRatio = Setting::get('torrent.uploaderdouble'); + $log .= ", spStateReal: $spStateReal, uploaderRatio: $uploaderRatio"; + if ($torrent->owner == $user->id) { + //uploader, use the bigger one + $upRatio = max($uploaderRatio, Torrent::$promotionTypes[$spStateReal]['up_multiplier']); + $log .= ", [IS_UPLOADER], upRatio: $upRatio"; + } else { + $upRatio = Torrent::$promotionTypes[$spStateReal]['up_multiplier']; + $log .= ", [IS_NOT_UPLOADER], upRatio: $upRatio"; + } + $downRatio = Torrent::$promotionTypes[$spStateReal]['down_multiplier']; + $log .= ", downRatio: $downRatio"; } else { $realUploaded = $queries['uploaded']; $realDownloaded = $queries['downloaded']; - $log .= ", [PEER_NOT_EXISTS],, realUploaded: $realUploaded, realDownloaded: $realDownloaded"; + /** + * If peer not exits, user increment = 0; + */ + $upRatio = 0; + $downRatio = 0; + $log .= ", [PEER_NOT_EXISTS], realUploaded: $realUploaded, realDownloaded: $realDownloaded, upRatio: $upRatio, downRatio: $downRatio"; } - $spStateReal = $torrent->spStateReal; - $uploaderRatio = Setting::get('torrent.uploaderdouble'); - $log .= ", spStateReal: $spStateReal, uploaderRatio: $uploaderRatio"; - if ($torrent->owner == $user->id) { - //uploader, use the bigger one - $upRatio = max($uploaderRatio, Torrent::$promotionTypes[$spStateReal]['up_multiplier']); - $log .= ", [IS_UPLOADER], upRatio: $upRatio"; - } else { - $upRatio = Torrent::$promotionTypes[$spStateReal]['up_multiplier']; - $log .= ", [IS_NOT_UPLOADER], upRatio: $upRatio"; - } - $downRatio = Torrent::$promotionTypes[$spStateReal]['down_multiplier']; - $log .= ", downRatio: $downRatio"; + $result = [ 'uploaded_increment' => $realUploaded, 'uploaded_increment_for_user' => $realUploaded * $upRatio, @@ -705,7 +714,7 @@ class TrackerRepository extends BaseRepository * @param Torrent $torrent * @param $queries */ - private function updateTorrent(Torrent $torrent, $queries) + private function updateTorrent(Torrent $torrent, $queries, Peer $peer) { if (empty($queries['event'])) { do_log("no event, return", 'debug'); @@ -724,7 +733,7 @@ class TrackerRepository extends BaseRepository $torrent->visible = Torrent::VISIBLE_YES; $torrent->last_action = Carbon::now(); - if ($queries['event'] == 'completed') { + if ($peer->exists && $queries['event'] == 'completed') { $torrent->times_completed = DB::raw("times_completed + 1"); } @@ -766,7 +775,7 @@ class TrackerRepository extends BaseRepository } $peer->save(); - do_log(last_query(), 'debug'); + do_log(last_query()); } /** @@ -788,11 +797,11 @@ class TrackerRepository extends BaseRepository //torrentid, userid, ip, port, uploaded, downloaded, to_go, ,seedtime, leechtime, last_action, startdat, completedat, finished if (!$snatch) { $snatch = new Snatch(); - //initial + //initial, use report uploaded + downloaded $snatch->torrentid = $peer->torrent; $snatch->userid = $peer->userid; - $snatch->uploaded = $dataTraffic['uploaded_increment']; - $snatch->downloaded = $dataTraffic['downloaded_increment']; + $snatch->uploaded = $queries['uploaded']; + $snatch->downloaded = $queries['downloaded']; $snatch->startdat = $nowStr; } else { //increase, use the increment value @@ -813,7 +822,7 @@ class TrackerRepository extends BaseRepository $snatch->port = $queries['port']; $snatch->to_go = $queries['left']; $snatch->last_action = $nowStr; - if ($queries['event'] == 'completed') { + if ($queries['event'] == 'completed' && $peer->exists) { $snatch->completedat = $nowStr; $snatch->finished = 'yes'; } diff --git a/include/functions.php b/include/functions.php index 19ea3952..bbeddac2 100644 --- a/include/functions.php +++ b/include/functions.php @@ -242,6 +242,26 @@ function formatFlv($src, $width, $height) { } return addTempCode(""); } +function formatYoutube($src, $width = '', $height = ''): string +{ + if (!$width) { + $width = 560; + } + if (!$height) { + $height = 315; + } + $queryString = parse_url($src, PHP_URL_QUERY); + parse_str($queryString, $parameters); + if (empty($parameters['v'])) { + $videoId = ''; + } else { + $videoId = $parameters['v']; + } + return addTempCode(sprintf( + '', + $width, $height, $videoId + )); +} function format_urls($text, $newWindow = false) { // return preg_replace("/((https?|ftp|gopher|news|telnet|mms|rtsp):\/\/[^()\[\]<>\s]+)/ei", "formatUrl('\\1', ".($newWindow==true ? 1 : 0).", '', 'faqlink')", $text); return preg_replace_callback("/((https?|ftp|gopher|news|telnet|mms|rtsp):\/\/[^()\[\]<>\s]+)/i", function ($matches) use ($newWindow) { @@ -324,6 +344,12 @@ function format_comment($text, $strip_html = true, $xssclean = false, $newtab = $s = preg_replace("/\[flv(\,([1-9][0-9]*)\,([1-9][0-9]*))?\]((http|ftp):\/\/[^\s'\"<>]+(\.(flv)))\[\/flv\]/i", '', $s); } } + //[youtube,560,315]https://www.youtube.com/watch?v=DWDL3VTCcCg&ab_channel=ESPNMMA[/youtube] + if (str_contains($s, '[youtube') && str_contains($s, 'v=')) { + $s = preg_replace_callback("/\[youtube(\,([1-9][0-9]*)\,([1-9][0-9]*))?\]((http|https):\/\/[^\s'\"<>]+)\[\/youtube\]/i", function ($matches) { + return formatYoutube($matches[4], $matches[2], $matches[3]); + }, $s); + } // [url=http://www.example.com]Text[/url] if ($adid) { diff --git a/lang/chs/lang_tags.php b/lang/chs/lang_tags.php index 52f0735c..fe3d7266 100644 --- a/lang/chs/lang_tags.php +++ b/lang/chs/lang_tags.php @@ -114,8 +114,8 @@ $lang_tags = array 'text_flv_two_example' => "[flv]http://$BASEURL/flash.video.demo.flv[/flv]", 'text_youtube' => "YouTube", 'text_youtube_description' => "在页面内插入YouTube网站的在线视频", - 'text_youtube_syntax' => "[youtube]YouTube视频的URL[/youtube]", - 'text_youtube_example' => "[youtube]http://www.youtube.com/watch?v=EsWKVcZ88Jw[/youtube]", + 'text_youtube_syntax' => "[youtube,width,height]YouTube视频的URL[/youtube]", + 'text_youtube_example' => "[youtube,560,315]https://www.youtube.com/watch?v=DWDL3VTCcCg&ab_channel=ESPNMMA[/youtube]", 'text_youku' => "优酷", 'text_youku_description' => "在页面内插入优酷网的在线视频", 'text_youku_syntax' => "[youku]优酷网视频的URL[/youku]", diff --git a/lang/cht/lang_tags.php b/lang/cht/lang_tags.php index 1bf9d4b1..dadffada 100644 --- a/lang/cht/lang_tags.php +++ b/lang/cht/lang_tags.php @@ -114,8 +114,8 @@ $lang_tags = array 'text_flv_two_example' => "[flv]http://$BASEURL/flash.video.demo.flv[/flv]", 'text_youtube' => "YouTube", 'text_youtube_description' => "在頁面內插入YouTube網站的在線視頻", - 'text_youtube_syntax' => "[youtube]YouTube視頻的URL[/youtube]", - 'text_youtube_example' => "[youtube]http://www.youtube.com/watch?v=EsWKVcZ88Jw[/youtube]", + 'text_youtube_syntax' => "[youtube,width,height]YouTube視頻的URL[/youtube]", + 'text_youtube_example' => "[youtube,560,315]https://www.youtube.com/watch?v=DWDL3VTCcCg&ab_channel=ESPNMMA[/youtube]", 'text_youku' => "優酷", 'text_youku_description' => "在頁面內插入優酷網的在線視頻", 'text_youku_syntax' => "[youku]優酷網視頻的URL[/youku]", diff --git a/lang/en/lang_tags.php b/lang/en/lang_tags.php index 11905b90..b96e7aa5 100644 --- a/lang/en/lang_tags.php +++ b/lang/en/lang_tags.php @@ -114,8 +114,8 @@ $lang_tags = array 'text_flv_two_example' => "[flv]http://$BASEURL/flash.video.demo.flv[/flv]", 'text_youtube' => "YouTube", 'text_youtube_description' => "Insert YouTube online video in webpages", - 'text_youtube_syntax' => "[youtube]Video URL on YouTube[/youtube]", - 'text_youtube_example' => "[youtube]http://www.youtube.com/watch?v=EsWKVcZ88Jw[/youtube]", + 'text_youtube_syntax' => "[youtube,width,height]Video URL on YouTube[/youtube]", + 'text_youtube_example' => "[youtube,560,315]https://www.youtube.com/watch?v=DWDL3VTCcCg&ab_channel=ESPNMMA[/youtube]", 'text_youku' => "YouKu", 'text_youku_description' => "Insert YouKu online video in webpages", 'text_youku_syntax' => "[youku]Video URL on YouKu[/youku]", diff --git a/public/offers.php b/public/offers.php index a59d5632..2cd10ca8 100644 --- a/public/offers.php +++ b/public/offers.php @@ -40,7 +40,7 @@ if (isset($_GET['add_offer']) && $_GET["add_offer"]){ print("
".$lang_offers['text_red_star_required']."
"); print("