<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Api extends vB_Api { protected $dbassertor; protected function __construct() { parent::__construct(); $this->dbassertor = vB::getDbAssertor(); } public function init($clientname, $clientversion, $platformname, $platformversion, $uniqueid, $api_c = 0) { $clientname = strip_tags($clientname); $clientversion = strip_tags($clientversion); $platformname = strip_tags($platformname); $platformversion = strip_tags($platformversion); $uniqueid = strip_tags($uniqueid); $api_c = intval($api_c); $oldclientid = $api_c; if (!$api_c) { if (!$clientname OR !$clientversion OR !$platformname OR !$platformversion OR !$uniqueid) { throw new vB_Exception_Api('apiclientinfomissing'); } $clienthash = md5($clientname . $platformname . $uniqueid); $random = new vB_Utility_Random(); $secret = $random->alphanumeric(32); $client = $this->dbassertor->getRow('apiclient', array('clienthash' => $clienthash)); if (!empty($client['apiclientid'])) { $api_c = $client['apiclientid']; $this->dbassertor->update('apiclient', array( 'secret' => $secret, 'apiaccesstoken' => vB::getCurrentSession()->get('apiaccesstoken'), 'lastactivity' => vB::getRequest()->getTimeNow(), 'clientversion' => $clientversion, 'platformversion' => $platformversion, 'userid' => 0 ), array( 'apiclientid' => $api_c, ) ); } else { $api_c = $this->dbassertor->insert('apiclient', array( 'secret' => $secret, 'clienthash' => $clienthash, 'clientname' => $clientname, 'clientversion' => $clientversion, 'platformname' => $platformname, 'platformversion' => $platformversion, 'initialipaddress' => vB::getRequest()->getAltIp(), 'apiaccesstoken' => vB::getCurrentSession()->get('apiaccesstoken'), 'dateline' => vB::getRequest()->getTimeNow(), 'lastactivity' => vB::getRequest()->getTimeNow(), )); if (is_array($api_c)) { $api_c = array_pop($api_c); } $api_c = (int) $api_c; } vB::getCurrentSession()->set('apiclientid', $api_c); } else { $api_c = intval($api_c); $this->dbassertor->update('apiclient', array( 'lastactivity' => vB::getRequest()->getTimeNow(), ), array( 'apiclientid' => $api_c, ) ); } $contenttypescache = vB_Types::instance()->getContentTypes(); $contenttypes = array(); foreach ($contenttypescache as $contenttype) { $contenttypes[$contenttype['class']] = $contenttype['id']; } $vboptions = vB::getDatastore()->getValue('publicoptions'); $session = vB::getCurrentSession(); $userinfo = $session->fetch_userinfo(); try { vB_Api::instanceInternal('paidsubscription')->checkStatus(); $paidsubs = 1; } catch (Exception $e) { $paidsubs = 0; } $forumHome = vB_Library::instance('content_channel')->getForumHomeChannel(); try{ $forumhomeUrl = vB5_Route::buildUrl($forumHome['routeid'] . '|fullurl'); } catch(Exception $e) { $forumhomeUrl = ""; } $facebookenabled = vB_Api::instanceInternal('Facebook')->isFacebookEnabled(); $channelLibrary = vB_Library::instance('Content_Channel'); $nodeApi = vB_Api::instance('Node'); $articlesId = $channelLibrary->fetchChannelIdByGUID(vB_Channel::DEFAULT_ARTICLE_PARENT); $article = $nodeApi->getNodeFullContent($articlesId); $canViewArticles = (empty($article['errors']) AND !empty($article[$articlesId])); $blogsId = $channelLibrary->fetchChannelIdByGUID(vB_Channel::DEFAULT_BLOG_PARENT); $blog = $nodeApi->getNodeFullContent($blogsId); $canViewBlogs = (empty($blog['errors']) AND !empty($blog[$blogsId])); $userApi = vB_Api::instanceInternal('user'); $registered = $userApi->checkPrivacyOption('enable_privacy_registered'); $guest = $userApi->checkPrivacyOption('enable_privacy_guest'); $data = array( 'apiversion' => VB_API_VERSION, 'apiaccesstoken' => $session->get('apiaccesstoken'), 'bbtitle' => $vboptions['bbtitle'], 'bburl' => $vboptions['bburl'], 'bbactive' => $vboptions['bbactive'], 'forumhome' => $forumhomeUrl, 'vbulletinversion' => $vboptions['templateversion'], 'contenttypes' => $contenttypes, 'features' => array( 'blogenabled' => $canViewBlogs ? 1 : 0, 'cmsenabled' => $canViewArticles ? 1: 0, 'pmsenabled' => $vboptions['enablepms'] ? 1 : 0, 'searchesenabled' => $vboptions['enablesearches'] ? 1 : 0, 'groupsenabled' => 1, 'albumsenabled' => 0, 'multitypesearch' => 1, 'visitor_messagingenabled' => 1, 'taggingenabled' => $vboptions['threadtagging'] ? 1 : 0, 'visitor_trackingenabled' => 0, 'paidsubs' => $paidsubs, 'friendsenabled' => 1, 'activitystream' => 1, 'facebookenabled' => $facebookenabled ? 1 : 0, 'calendarenabled' => 1, 'privacyenabled' => $registered['required'] ? 1 : 0, 'privacyguestenabled' => $guest['required'] ? 1 : 0, ), 'permissions' => array(), 'show' => array( 'registerbutton' => $vboptions['allowregistration'] ? 1 : 0, 'rtl' => $userinfo['lang_options']['direction'] ? 0 : 1, ), ); if (!$vboptions['bbactive']) { $data['bbclosedreason'] = $vboptions['bbclosedreason']; } $data['apiclientid'] = $api_c; if (!$oldclientid) { $data['secret'] = $secret; } return $data; } } 