[ Index ] |
PHP Cross Reference of MyBB 1.8.38 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.8 4 * Copyright 2014 MyBB Group, All Rights Reserved 5 * 6 * Website: http://www.mybb.com 7 * License: http://www.mybb.com/about/license 8 * 9 */ 10 11 define("IN_MYBB", 1); 12 define('THIS_SCRIPT', 'ratethread.php'); 13 14 $templatelist = 'forumdisplay_password_wrongpass,forumdisplay_password'; 15 require_once "./global.php"; 16 17 // Verify incoming POST request 18 verify_post_check($mybb->get_input('my_post_key')); 19 20 $lang->load("ratethread"); 21 22 $tid = $mybb->get_input('tid'); 23 $thread = get_thread($tid); 24 if(!$thread) 25 { 26 error($lang->error_invalidthread); 27 } 28 29 // Is the currently logged in user a moderator of this forum? 30 $ismod = is_moderator($thread['fid']); 31 32 // Make sure we are looking at a real thread here. 33 if(($thread['visible'] != 1 && $ismod == false) || ($thread['visible'] > 1 && $ismod == true)) 34 { 35 error($lang->error_invalidthread); 36 } 37 38 if($thread['visible'] == -1) 39 { 40 error($lang->thread_doesnt_exist); 41 } 42 43 if($thread['uid'] == $mybb->user['uid']) 44 { 45 error($lang->error_cannotrateownthread); 46 } 47 48 $forumpermissions = forum_permissions($thread['fid']); 49 if($forumpermissions['canview'] == 0 || $forumpermissions['canratethreads'] == 0 || $mybb->usergroup['canratethreads'] == 0 || $mybb->settings['allowthreadratings'] == 0 || (isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] != 0)) 50 { 51 error_no_permission(); 52 } 53 54 // Get forum info 55 $fid = $thread['fid']; 56 $forum = get_forum($fid); 57 if(!$forum) 58 { 59 error($lang->error_invalidforum); 60 } 61 else 62 { 63 // Is our forum closed? 64 if($forum['open'] == 0) 65 { 66 // Doesn't look like it is 67 error($lang->error_closedinvalidforum); 68 } 69 } 70 71 // Check if this forum is password protected and we have a valid password 72 check_forum_password($forum['fid']); 73 74 if($forum['allowtratings'] == 0) 75 { 76 error_no_permission(); 77 } 78 $mybb->input['rating'] = $mybb->get_input('rating', MyBB::INPUT_INT); 79 if($mybb->input['rating'] < 1 || $mybb->input['rating'] > 5) 80 { 81 error($lang->error_invalidrating); 82 } 83 $plugins->run_hooks("ratethread_start"); 84 85 if($mybb->user['uid'] != 0) 86 { 87 $whereclause = "uid='{$mybb->user['uid']}'"; 88 } 89 else 90 { 91 $whereclause = "ipaddress=".$db->escape_binary($session->packedip); 92 } 93 $query = $db->simple_select("threadratings", "*", "{$whereclause} AND tid='{$tid}'"); 94 $ratecheck = $db->fetch_array($query); 95 96 if($ratecheck || isset($mybb->cookies['mybbratethread'][$tid])) 97 { 98 error($lang->error_alreadyratedthread); 99 } 100 else 101 { 102 $plugins->run_hooks("ratethread_process"); 103 104 $db->write_query(" 105 UPDATE ".TABLE_PREFIX."threads 106 SET numratings=numratings+1, totalratings=totalratings+'{$mybb->input['rating']}' 107 WHERE tid='{$tid}' 108 "); 109 if($mybb->user['uid'] != 0) 110 { 111 $insertarray = array( 112 'tid' => $tid, 113 'uid' => $mybb->user['uid'], 114 'rating' => $mybb->input['rating'], 115 'ipaddress' => $db->escape_binary($session->packedip) 116 ); 117 $db->insert_query("threadratings", $insertarray); 118 } 119 else 120 { 121 $insertarray = array( 122 'tid' => $tid, 123 'rating' => $mybb->input['rating'], 124 'ipaddress' => $db->escape_binary($session->packedip) 125 ); 126 $db->insert_query("threadratings", $insertarray); 127 $time = TIME_NOW; 128 my_setcookie("mybbratethread[{$tid}]", $mybb->input['rating']); 129 } 130 } 131 $plugins->run_hooks("ratethread_end"); 132 133 if(!empty($mybb->input['ajax'])) 134 { 135 $json = array("success" => $lang->rating_added); 136 $query = $db->simple_select("threads", "totalratings, numratings", "tid='$tid'", array('limit' => 1)); 137 $fetch = $db->fetch_array($query); 138 $width = 0; 139 if($fetch['numratings'] >= 0) 140 { 141 $averagerating = (float)round($fetch['totalratings']/$fetch['numratings'], 2); 142 $width = (int)round($averagerating)*20; 143 $fetch['numratings'] = (int)$fetch['numratings']; 144 $ratingvotesav = $lang->sprintf($lang->rating_votes_average, $fetch['numratings'], $averagerating); 145 $json = $json + array("average" => $ratingvotesav); 146 } 147 $json = $json + array("width" => $width); 148 149 @header("Content-type: application/json; charset={$lang->settings['charset']}"); 150 echo json_encode($json); 151 exit; 152 } 153 154 redirect(get_thread_link($thread['tid']), $lang->redirect_threadrated);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |