From 1c065fdf6549c3969f3a9c8fa67e8b9c9176653c Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 11 Apr 2022 19:34:49 +0800 Subject: [PATCH] fix report error, improve announce, add youtube tag --- app/Repositories/TrackerRepository.php | 57 +++++++++++++++----------- include/functions.php | 26 ++++++++++++ lang/chs/lang_tags.php | 4 +- lang/cht/lang_tags.php | 4 +- lang/en/lang_tags.php | 4 +- public/offers.php | 20 ++++----- public/report.php | 6 +-- public/tags.php | 4 +- public/viewrequests.php | 16 ++++---- 9 files changed, 88 insertions(+), 53 deletions(-) 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("
". - "\n"); + "
".$lang_offers['text_offers_open_to_all']."
\n"); $s = "\n"; print("". - "". + "
".$lang_offers['text_link_to_picture']."". "
".$lang_offers['text_offers_open_to_all']."
".$lang_offers['row_type']."* $s
".$lang_offers['row_title']."*". + "
".$lang_offers['row_title']."*". "
".$lang_offers['row_post_or_photo']."". - "
".$lang_offers['text_link_to_picture']."
".$lang_offers['row_description']."*\n"); - textbbcode("compose","body",$body,false); + textbbcode("compose","body",$body,false, 130, true); print("

\n"); stdfoot(); die; @@ -85,7 +85,7 @@ if (isset($_GET['new_offer']) && $_GET["new_offer"]){ if (!empty($_POST['picture'])){ $picture = unesc($_POST["picture"]); - if(!preg_match("/^http:\/\/[^\s'\"<>]+\.(jpg|gif|png)$/i", $picture)) + if(!preg_match("/^https?:\/\/[^\s'\"<>]+\.(jpg|gif|png)$/i", $picture)) stderr($lang_offers['std_error'], $lang_offers['std_wrong_image_format']); $pic = "[img]".$picture."[/img]\n"; } @@ -355,10 +355,10 @@ if (isset($_GET["edit_offer"]) && $_GET["edit_offer"]) { print("
". ""); tr($lang_offers['row_type']."*", $s2, 1); - tr($lang_offers['row_title']."*", "", 1); - tr($lang_offers['row_post_or_photo'], "
".$lang_offers['text_link_to_picture'], 1); + tr($lang_offers['row_title']."*", "", 1); + tr($lang_offers['row_post_or_photo'], "
".$lang_offers['text_link_to_picture'], 1); print(""); print("
".$lang_offers['text_edit_offer']."
".$lang_offers['row_description']."*"); - textbbcode("compose","body",$body,false); + textbbcode("compose","body",$body, false, 130, true); print("

\n"); stdfoot(); @@ -385,7 +385,7 @@ if (isset($_GET["take_off_edit"]) && $_GET["take_off_edit"]){ if (!empty($_POST['picture'])){ $picture = unesc($_POST["picture"]); - if(!preg_match("/^http:\/\/[^\s'\"<>]+\.(jpg|gif|png)$/i", $picture)) + if(!preg_match("/^https?:\/\/[^\s'\"<>]+\.(jpg|gif|png)$/i", $picture)) stderr($lang_offers['std_error'], $lang_offers['std_wrong_image_format']); $pic = "[img]".$picture."[/img]\n"; } @@ -708,7 +708,7 @@ if ($offeruptimeout_main) print("
  • ".$lang_offers['text_rule_four_one']."".($offeruptimeout_main / 3600)."".$lang_offers['text_rule_four_two']."
  • \n"); print("
    "); if (get_user_class() >= $addoffer_class) -print("
    ". +print("
    ". "".$lang_offers['text_add_offer']."
    "); print("
    ".$lang_offers['text_search_offers']."    "); $cats = genrelist($browsecatmode); diff --git a/public/report.php b/public/report.php index 40350adc..17e24a51 100644 --- a/public/report.php +++ b/public/report.php @@ -102,7 +102,7 @@ elseif ((isset($takesubtitleid)) && (isset($takereason))) elseif (isset($user)) { int_check($user); - if ($user == $CURUSER[id]) { + if ($user == $CURUSER['id']) { stderr($lang_report['std_sorry'],$lang_report['std_cannot_report_oneself']); die; } @@ -200,7 +200,7 @@ elseif (isset($reportofferid)) stderr($lang_report['std_error'],$lang_report['std_invalid_offer_id']); } $arr = mysql_fetch_array($res); - stderr($lang_report['std_are_you_sure'], $lang_report['text_are_you_sure_offer']."".htmlspecialchars($arr['name'])."".$lang_report['text_to_staff']."
    ".$lang_report['text_reason_note']."
    ".$lang_report['text_reason_is']."
    ", false); + stderr($lang_report['std_are_you_sure'], $lang_report['text_are_you_sure_offer']."".htmlspecialchars($arr['name'])."".$lang_report['text_to_staff']."
    ".$lang_report['text_reason_note']."
    ".$lang_report['text_reason_is']."
    ", false); } //////////OFFERT #2 END////////// @@ -214,7 +214,7 @@ elseif (isset($reportrequestid)) stderr($lang_report['std_error'],$lang_report['std_invalid_request_id']); } $arr = mysql_fetch_array($res); - stderr($lang_report['std_are_you_sure'], $lang_report['text_are_you_sure_request']."".htmlspecialchars($arr['request'])."".$lang_report['text_to_staff']."
    ".$lang_report['text_reason_note']."
    ".$lang_report['text_reason_is']."
    ", false); + stderr($lang_report['std_are_you_sure'], $lang_report['text_are_you_sure_request']."".htmlspecialchars($arr['request'])."".$lang_report['text_to_staff']."
    ".$lang_report['text_reason_note']."
    ".$lang_report['text_reason_is']."
    ", false); } //////////REQUEST #2 END////////// diff --git a/public/tags.php b/public/tags.php index 4f7074f9..6715678d 100644 --- a/public/tags.php +++ b/public/tags.php @@ -219,7 +219,7 @@ insert_tag( "" ); -/* + insert_tag( $lang_tags['text_youtube'], $lang_tags['text_youtube_description'], @@ -227,7 +227,7 @@ insert_tag( $lang_tags['text_youtube_example'], "" ); - +/* insert_tag( $lang_tags['text_youku'], $lang_tags['text_youku_description'], diff --git a/public/viewrequests.php b/public/viewrequests.php index 3c638433..6b4b3e1b 100644 --- a/public/viewrequests.php +++ b/public/viewrequests.php @@ -116,7 +116,7 @@ else { else $arr = mysql_fetch_assoc($res); stdhead($lang_viewrequests['page_title']); print("

    {$lang_viewrequests['request']}-" . htmlspecialchars($arr["request"]) . "

    \n"); - print("\n"); + print("
    \n"); $res = sql_query("SELECT * FROM resreq WHERE reqid ='" . $_GET["id"] . "'" . $limit) or sqlerr(__FILE__, __LINE__); tr($lang_viewrequests['basic_info'], get_username($arr['userid']) . $lang_viewrequests['created_at'] . gettime($arr["added"], true, false) . "\n", 1); tr($lang_viewrequests['reward'], $lang_viewrequests['newest_bidding'] . $arr['amount'] . " {$lang_viewrequests['original_bidding']}" . $arr["ori_amount"] . "\n", 1); @@ -200,10 +200,10 @@ else { "); - print("
    "); + print("
    {$lang_functions['title_edit']}{$lang_viewrequests['request']}
    "); tr("{$lang_functions['col_name']}:", "
    ", 1); print(""); print("
    {$lang_functions['title_edit']}{$lang_viewrequests['request']}
    {$lang_functions['std_desc']}:"); - textbbcode("edit", "descr", $arr["descr"]); + textbbcode("edit", "descr", $arr["descr"], false, 130, true); print("

    \n"); stdfoot(); @@ -217,11 +217,11 @@ else { stdhead($lang_viewrequests['add_request']); print( "
    \n\n"); - print("\n"); + print("
    {$lang_viewrequests['add_request']}
    \n"); tr("{$lang_functions['col_name']}:", "
    ", 1); tr("{$lang_viewrequests['reward']}:", "{$lang_viewrequests['add_request_desc']}
    ", 1); print(""); print("
    {$lang_viewrequests['add_request']}
    {$lang_functions['std_desc']}:"); - textbbcode("edit", "descr", $arr["descr"]); + textbbcode("edit", "descr", $arr["descr"], false, 130, true); print("

    \n"); @@ -246,7 +246,7 @@ else { print( "
    \n\n"); - print("\n"); + print("
    \n"); print("
    "); if ($ruserid) { @@ -308,14 +308,14 @@ else { case "takeedit": { if (!is_numeric($_POST["reqid"])) stderr($lang_functions['std_error'], "{$lang_viewrequests['request_id_must_be_numeric']}{$lang_functions['std_click_here_to_goback']}", 0); - $res = sql_query("SELECT * FROM requests WHERE id ='" . sqlesc( $_POST["reqid"]) . "'") or sqlerr(__FILE__, __LINE__); + $res = sql_query("SELECT * FROM requests WHERE id =" . sqlesc( $_POST["reqid"])) or sqlerr(__FILE__, __LINE__); if (!$_POST["descr"]) stderr($lang_functions['std_error'], "{$lang_viewrequests['description_required']}{$lang_functions['std_click_here_to_goback']}", 0); if (!$_POST["request"]) stderr($lang_functions['std_error'], "{$lang_viewrequests['name_required']}{$lang_functions['std_click_here_to_goback']}", 0); if (mysql_num_rows($res) == 0) stderr($lang_functions['std_error'], "{$lang_viewrequests['request_deleted']}{$lang_functions['std_click_here_to_goback']}", 0); $arr = mysql_fetch_assoc($res); if ($arr["finish"] == "yes") stderr($lang_functions['std_error'], "{$lang_viewrequests['request_already_resolved']}{$lang_functions['std_click_here_to_goback']}", 0); if ($arr['userid'] == $CURUSER['id'] || get_user_class() >= UC_UPLOADER) { - sql_query("UPDATE requests SET descr = " . sqlesc($_POST["descr"]) . " , request = " . sqlesc($_POST["request"]) . " WHERE id ='" . sqlesc($_POST["reqid"]) . "'") or sqlerr(__FILE__, __LINE__); + sql_query("UPDATE requests SET descr = " . sqlesc($_POST["descr"]) . " , request = " . sqlesc($_POST["request"]) . " WHERE id =" . sqlesc($_POST["reqid"])) or sqlerr(__FILE__, __LINE__); stderr($lang_functions['std_success'], "{$lang_viewrequests['edit_request_success']},{$lang_functions['std_click_here_to_goback']}", 0); } else stderr($lang_functions['std_error'], "{$lang_functions['std_permission_denied']}{$lang_functions['std_click_here_to_goback']}", 0); die;