public function reward() { global $vbulletin, $vbphrase; // <editor-fold defaultstate="collapsed" desc="analysis information"> if ($this->type == 2) { $this->chapternumber = ""; } $this->fansubmember = str_replace('false', '', $this->fansubmember); $this->fansubmember = str_replace(',,', '', $this->fansubmember); if ($this->postid == 0) { $this->postid = $this->manga->postid; } // </editor-fold> // <editor-fold defaultstate="collapsed" desc="create new update post, and new read online thread"> // <editor-fold defaultstate="collapsed" desc=" create new update post "> //normal case: there is update post for the chapter, or there is not but no 18+ content. //reward and add chapter to the database only, no need to make any new post. Only set the post to yrmspost. if ($this->postid != $this->manga->postid) { $vbulletin->db->query_write("UPDATE `" . TABLE_PREFIX . "post` " . "SET `yrmspost`=1 " . "WHERE `postid` = '{$this->postid}'"); if ($this->rate == 1 && !empty($this->numberofhost)) { $downloadpost = $this->buildpost('download'); editPost($downloadpost); } } else { if ($this->postid == $this->manga->postid && $this->rate == 1) { $downloadpost = $this->buildpost('download'); $this->postid = newPost($downloadpost, $this->poster); $vbulletin->db->query_write("UPDATE `" . TABLE_PREFIX . "post` " . "SET `yrmspost`=1 " . "WHERE `postid` = '{$this->postid}'"); } } //abnormal case 2: no download link, only readonline link. //Skip this step // </editor-fold> // <editor-fold defaultstate="collapsed" desc=" create new read online thread "> //normal case: readonline post is a separate topic //do nothing but set the post to yrms post, and reformat it if the chapter is 18+ content if (!empty($this->onlinelink)) { $vbulletin->db->query_write("UPDATE `" . TABLE_PREFIX . "post` " . "SET `yrmspost`=1 " . "WHERE `postid` = '{$this->readonlinepostid}'"); if ($this->rate == 1) { $readonlinepost = $this->buildpost('online'); editPost($readonlinepost); } } //abnormal case: readonline post is the same as update post, or manga post //turn it into normal case and treat as normal case if (!empty($this->onlinelink) && ($this->readonlinepostid == $this->postid || $this->readonlinepostid == $this->manga->postid || $this->readonlinepostid == 0)) { $readonlinepost = $this->buildpost('online'); $idpack = newThread($readonlinepost, $this->readonlineposter); $this->readonlinepostid = $idpack['postid']; $vbulletin->db->query_write("UPDATE `" . TABLE_PREFIX . "post` " . "SET `yrmspost`=1 " . "WHERE `postid` = '{$this->readonlinepostid}'"); } // </editor-fold> // </editor-fold> // <editor-fold defaultstate="collapsed" desc="add chapter to the database "> $vbulletin->db->query_write("INSERT INTO `" . TABLE_PREFIX . "yrms_vietsubmanga_chapter`" . "(`mangaid`," . "`postid`, " . "`readonlinepostid`, " . "`active`, " . "`status`, " . "`type`, " . "`chapternumber`, " . "`chaptertitle`, " . "`rate`, " . "`numberofhost`, " . "`downloadlink`, " . "`onlinelink`, " . "`fansubmember`, " . "`fansubnote`) " . "VALUES ('{$this->manga->mangaid}'," . "'{$this->postid}'," . "'{$this->readonlinepostid}'," . "'1'," . "'{$this->status}'," . "'{$this->type}'," . "'{$this->chapternumber}'," . "'{$this->chaptertitle}'," . "'{$this->rate}'," . "'{$this->numberofhost}'," . "'" . serialize($this->downloadlink) . "'," . "'{$this->onlinelink}'," . "'" . serialize($this->fansubmember) . "'," . "'{$this->fansubnote}')"); $this->chapterid = $vbulletin->db->insert_id(); // </editor-fold> // <editor-fold defaultstate="collapsed" desc="update manga"> $this->manga->fansubmember = update_array_to_array($this->fansubmember, $this->manga->fansubmember); $this->manga->fansubmember = reindex_array($this->manga->fansubmember, array("translator", "proofreader", "editor", "qualitychecker", "uploader")); if ($this->type == 1 || $this->type == 2) { $this->manga->finishedchapter++; } if (!empty($this->onlinelink)) { $this->manga->readonlinestatus = 1; } $chapterhostname = array(); if (!empty($this->numberofhost)) { foreach ($this->downloadlink as $hostname => $hostlink) { $chapterhostname[] = $hostname; } $this->manga->hostname = update_array_to_array($chapterhostname, $this->manga->hostname); $this->manga->numberofhost = count($this->manga->hostname); } $this->manga->update(); // </editor-fold> // <editor-fold defaultstate="collapsed" desc=" reward "> //For download post $award_download = new Award(); $award_download->postid = $this->postid; if (strpos(strtolower($this->manga->fansubsite), 'yurivn')) { $award_download->awardcontent = $this->build_awardcontent_fansubmember(); } if (!empty($this->numberofhost)) { if (array_key_exists($this->poster, $award_download->awardcontent)) { $award_download->awardcontent[$this->poster] += $vbulletin->options['yrms_vietsubmanga_yun_uploader']; } else { $award_download->awardcontent += array($this->poster => $vbulletin->options['yrms_vietsubmanga_yun_uploader']); } if ($this->numberofhost >= 2) { if (array_key_exists($this->poster, $award_download->awardcontent)) { $award_download->awardcontent[$this->poster] += $vbulletin->options['yrms_vietsubmanga_yun_mirror']; } else { $award_download->awardcontent += array($this->poster => $vbulletin->options['yrms_vietsubmanga_yun_mirror']); } } } $award_download->resourcetype = 'vietsubmanga'; $award_download->resourceid = $this->chapterid; $award_download->resourceheadid = $this->manga->mangaid; $award_download->add(); //For readonline post if (!empty($this->readonlinepostid)) { $award_online = new Award(); $award_online->postid = $this->readonlinepostid; $award_online->awardcontent = array($this->readonlineposter => $vbulletin->options['yrms_vietsubmanga_yun_online']); $award_online->resourcetype = 'vietsubmanga'; $award_online->resourceid = $this->chapterid; $award_online->resourceheadid = $this->manga->mangaid; $award_online->add(); } // </editor-fold> // <editor-fold defaultstate="collapsed" desc=" return the success message "> if (isset($award_online)) { $awardcontent = $award_download->awardcontent + $award_online->awardcontent; } else { $awardcontent = $award_download->awardcontent; } $awardinfo = array(); foreach ($awardcontent as $userid => $amount) { $userinfo = fetch_userinfo($userid); $username = $userinfo["username"]; $awardinfo[] = "{$username}: {$amount} {$vbulletin->options['yrms_main_moneyname']}"; } $awardinfo = implode("\n", $awardinfo); $return_message = construct_phrase($vbphrase['yrms_msg_success_rewardchapter'], $vbulletin->userinfo['username'], $vbphrase["yrms_chaptertype{$this->type}"] . " " . $this->chapternumber, $this->manga->mangatitle, nl2br($awardinfo)); return $return_message; // </editor-fold> }