[ Index ]

PHP Cross Reference of MyBB 1.8.17

title

Body

[close]

/ -> ratethread.php (source)

   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['uid'] == $mybb->user['uid'])
  39  {
  40      error($lang->error_cannotrateownthread);
  41  }
  42  
  43  $forumpermissions = forum_permissions($thread['fid']);
  44  if($forumpermissions['canview'] == 0 || $forumpermissions['canratethreads'] == 0 || $mybb->usergroup['canratethreads'] == 0 || $mybb->settings['allowthreadratings'] == 0 || (isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] != 0))
  45  {
  46      error_no_permission();
  47  }
  48  
  49  // Get forum info
  50  $fid = $thread['fid'];
  51  $forum = get_forum($fid);
  52  if(!$forum)
  53  {
  54      error($lang->error_invalidforum);
  55  }
  56  else
  57  {
  58      // Is our forum closed?
  59      if($forum['open'] == 0)
  60      {
  61          // Doesn't look like it is
  62          error($lang->error_closedinvalidforum);
  63      }
  64  }
  65  
  66  // Check if this forum is password protected and we have a valid password
  67  check_forum_password($forum['fid']);
  68  
  69  if($forum['allowtratings'] == 0)
  70  {
  71      error_no_permission();
  72  }
  73  $mybb->input['rating'] = $mybb->get_input('rating', MyBB::INPUT_INT);
  74  if($mybb->input['rating'] < 1 || $mybb->input['rating'] > 5)
  75  {
  76      error($lang->error_invalidrating);
  77  }
  78  $plugins->run_hooks("ratethread_start");
  79  
  80  if($mybb->user['uid'] != 0)
  81  {
  82      $whereclause = "uid='{$mybb->user['uid']}'";
  83  }
  84  else
  85  {
  86      $whereclause = "ipaddress=".$db->escape_binary($session->packedip);
  87  }
  88  $query = $db->simple_select("threadratings", "*", "{$whereclause} AND tid='{$tid}'");
  89  $ratecheck = $db->fetch_array($query);
  90  
  91  if($ratecheck['rid'] || isset($mybb->cookies['mybbratethread'][$tid]))
  92  {
  93      error($lang->error_alreadyratedthread);
  94  }
  95  else
  96  {
  97      $plugins->run_hooks("ratethread_process");
  98  
  99      $db->write_query("
 100          UPDATE ".TABLE_PREFIX."threads
 101          SET numratings=numratings+1, totalratings=totalratings+'{$mybb->input['rating']}'
 102          WHERE tid='{$tid}'
 103      ");
 104      if($mybb->user['uid'] != 0)
 105      {
 106          $insertarray = array(
 107              'tid' => $tid,
 108              'uid' => $mybb->user['uid'],
 109              'rating' => $mybb->input['rating'],
 110              'ipaddress' => $db->escape_binary($session->packedip)
 111          );
 112          $db->insert_query("threadratings", $insertarray);
 113      }
 114      else
 115      {
 116          $insertarray = array(
 117              'tid' => $tid,
 118              'rating' => $mybb->input['rating'],
 119              'ipaddress' => $db->escape_binary($session->packedip)
 120          );
 121          $db->insert_query("threadratings", $insertarray);
 122          $time = TIME_NOW;
 123          my_setcookie("mybbratethread[{$tid}]", $mybb->input['rating']);
 124      }
 125  }
 126  $plugins->run_hooks("ratethread_end");
 127  
 128  if(!empty($mybb->input['ajax']))
 129  {
 130      $json = array("success" => $lang->rating_added);
 131      $query = $db->simple_select("threads", "totalratings, numratings", "tid='$tid'", array('limit' => 1));
 132      $fetch = $db->fetch_array($query);
 133      $width = 0;
 134      if($fetch['numratings'] >= 0)
 135      {
 136          $averagerating = (float)round($fetch['totalratings']/$fetch['numratings'], 2);
 137          $width = (int)round($averagerating)*20;
 138          $fetch['numratings'] = (int)$fetch['numratings'];
 139          $ratingvotesav = $lang->sprintf($lang->rating_votes_average, $fetch['numratings'], $averagerating);
 140          $json = $json + array("average" => $ratingvotesav);
 141      }
 142      $json = $json + array("width" => $width);
 143  
 144      @header("Content-type: application/json; charset={$lang->settings['charset']}");
 145      echo json_encode($json);
 146      exit;
 147  }
 148  
 149  redirect(get_thread_link($thread['tid']), $lang->redirect_threadrated);


2005 - 2018 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref 0.7.1