<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Reputation extends vB_Api { protected $assertor; protected function __construct() { parent::__construct(); $this->assertor = vB::getDbAssertor(); } public function vote($nodeid) { $reactionsApi = vB_Api::instanceInternal('reactions'); $reactionsLib = vB_Library::instance('reactions'); $thumbsup = $reactionsLib->getThumbsUp(); $thumbsupid = $thumbsup['votetypeid'] ?? 0; $result = $reactionsApi->voteNode($nodeid, $thumbsupid); $votesCount = $result['nodevotes'][$thumbsupid]['votes']; return ['nodeid' => $nodeid, 'votes' => $votesCount]; } public function unvote($nodeid) { $reactionsApi = vB_Api::instanceInternal('reactions'); $reactionsLib = vB_Library::instance('reactions'); $thumbsup = $reactionsLib->getThumbsUp(); $thumbsupid = $thumbsup['votetypeid'] ?? 0; $result = $reactionsApi->unvoteNode($nodeid, $thumbsupid); $votesCount = $result['nodevotes'][$thumbsupid]['votes']; return ['nodeid' => $nodeid, 'votes' => $votesCount]; } protected function checkCanUseRep($node) { $loginuser = &vB::getCurrentSession()->fetch_userinfo(); if (!$loginuser['userid']) { throw new vB_Exception_Api('not_logged_no_permission'); } $usercontext = &vB::getUserContext($loginuser['userid']); if (!$usercontext->hasPermission('genericpermissions', 'canuserep')) { throw new vB_Exception_Api('no_permission'); } $contenttypes = vB_Types::instance()->getContentTypes(); if (!in_array($node['contenttypeid'], array( $contenttypes['vBForum_Text']['id'], $contenttypes['vBForum_Gallery']['id'], $contenttypes['vBForum_Video']['id'], $contenttypes['vBForum_Link']['id'], $contenttypes['vBForum_Poll']['id'], $contenttypes['vBForum_Event']['id'], ))) { throw new vB_Exception_Api('invalid_vote_node'); } } } 