/**
  * Vote a node
  *
  * @param int $nodeid Node ID.
  * @return array New Node info.
  * @see vB_Api_Node::getNode()
  * @throws vB_Exception_Api
  */
 public function vote($nodeid)
 {
     $node = vB_Api::instanceInternal('node')->getNodeFullContent($nodeid);
     $node = $node[$nodeid];
     $this->checkCanUseRep($node);
     $loginuser =& vB::getCurrentSession()->fetch_userinfo();
     if ($node['userid'] == $loginuser['userid']) {
         // Can't vote own node
         throw new vB_Exception_Api('reputationownpost');
     }
     $score = $this->fetchReppower($loginuser['userid']);
     // Check if the user has already reputation this node
     $check = $this->assertor->getRow('vBForum:reputation', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'nodeid' => $node['nodeid'], 'whoadded' => $loginuser['userid']));
     if (!empty($check)) {
         throw new vB_Exception_Api('reputationsamepost');
     }
     $userinfo = vB_Api::instanceInternal('user')->fetchUserinfo($node['userid']);
     if (!$userinfo['userid']) {
         throw new vB_Exception_Api('invalidid', 'User');
     }
     $usergroupcache = vB::getDatastore()->getValue('usergroupcache');
     $bf_ugp_genericoptions = vB::getDatastore()->getValue('bf_ugp_genericoptions');
     if (!($usergroupcache["{$userinfo['usergroupid']}"]['genericoptions'] & $bf_ugp_genericoptions['isnotbannedgroup'])) {
         throw new vB_Exception_Api('reputationbanned');
     }
     $usercontext =& vB::getUserContext($loginuser['userid']);
     $vboptions = vB::getDatastore()->getValue('options');
     $userinfo['reputation'] += $score;
     // Determine this user's reputationlevelid.
     $reputationlevelid = $this->assertor->getField('vBForum:reputation_userreputationlevel', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'reputation' => $userinfo['reputation']));
     // init user data manager
     $userdata = new vB_Datamanager_User(NULL, vB_DataManager_Constants::ERRTYPE_STANDARD);
     $userdata->set_existing($userinfo);
     $userdata->set('reputation', $userinfo['reputation']);
     $userdata->set('reputationlevelid', intval($reputationlevelid));
     $userdata->pre_save();
     /*insert query*/
     $this->assertor->assertQuery('vBForum:reputation', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_INSERTIGNORE, 'nodeid' => $node['nodeid'], 'reputation' => $score, 'userid' => $userinfo['userid'], 'whoadded' => $loginuser['userid'], 'dateline' => vB::getRequest()->getTimeNow()));
     if ($this->assertor->affected_rows() == 0) {
         // attempt Zat a flood!
         throw new vB_Exception_Api('reputationsamepost');
     }
     $userdata->save();
     $condition = array('nodeid' => $nodeid);
     $this->assertor->assertQuery('vBForum:updateNodeVotes', $condition);
     // Send notification
     $recipients = array($node['userid']);
     $contextData = array('sentbynodeid' => $nodeid, 'sender' => vB::getUserContext()->fetchUserId());
     vB_Library::instance('notification')->triggerNotificationEvent('node-reputation-vote', $contextData, $recipients);
     vB_Library::instance('notification')->insertNotificationsToDB();
     // Expire node cache so this like displays correctly
     vB_Cache::instance()->allCacheEvent('nodeChg_' . $nodeid);
     $votesCount = $this->assertor->getField('vBForum:node', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, vB_dB_Query::COLUMNS_KEY => array('votes'), vB_dB_Query::CONDITIONS_KEY => $condition));
     return array('nodeid' => $nodeid, 'votes' => $votesCount);
 }
Exemple #2
0
 /**
  * Fetch Human Verification Image Data
  *
  * @param $hash
  * @return array 'type' => Image type 'data' => Image binary data
  */
 public function fetchHvImage($hash = '')
 {
     $vboptions = vB::getDatastore()->getValue('options');
     $moveabout = true;
     if (!$hash or $hash == 'test' or $vboptions['hv_type'] != 'Image') {
         $imageinfo = array('answer' => 'vBulletin');
         $moveabout = $hash == 'test' ? true : false;
     } else {
         if (!($imageinfo = $this->assertor->getRow('humanverify', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'hash' => $hash, 'viewed' => 0)))) {
             return array('type' => 'gif', 'data' => file_get_contents(DIR . '/' . $vboptions['cleargifurl']));
         } else {
             $this->assertor->assertQuery('humanverify', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_UPDATE, 'viewed' => 1, vB_dB_Query::CONDITIONS_KEY => array('hash' => $hash, 'viewed' => 0)));
             if ($this->assertor->affected_rows() == 0) {
                 // image managed to get viewed by someone else between the $imageinfo query above and now
                 return array('type' => 'gif', 'data' => file_get_contents(DIR . '/' . $vboptions['cleargifurl']));
             }
         }
     }
     $image = vB_Image::instance();
     $imageInfo = $image->getImageFromString($imageinfo['answer'], $moveabout);
     return array('type' => $imageInfo['filetype'], 'data' => $imageInfo['filedata']);
 }