<?php
 class vB_Api_Site extends vB_Api { protected $disableWhiteList = [ 'loadHeaderNavbar', 'loadFooterNavbar', 'getAppManifest', ]; public function saveHeaderNavbar($siteId, $data) { $this->checkHasAdminPermission('canusesitebuilder'); $this->logAdminAction(__FUNCTION__); return vB_Library::instance('site')->saveHeaderNavbar($siteId, $data); } public function saveFooterNavbar($siteId, $data) { $this->checkHasAdminPermission('canusesitebuilder'); $this->logAdminAction(__FUNCTION__); return vB_Library::instance('site')->saveFooterNavbar($siteId, $data); } public function loadHeaderNavbar($siteId, $url = false, $edit = false, $channelId = 0) { if ($this->disabled) { return []; } return vB_Library::instance('site')->loadHeaderNavbar($siteId, $url, $edit, $channelId); } public function loadFooterNavbar($siteId, $url = false, $edit = false) { if ($this->disabled) { return []; } return vB_Library::instance('site')->loadFooterNavbar($siteId, $url, $edit); } public function getSiteStatistics() { return vB_Library::instance('site')->getSiteStatistics(); } public function getAppManifest() : array { $vboptions = vB::getDatastore()->getValue('options'); $stringUtil = vB::getString(); $homepage = []; $styleApi = vB_Api::instanceInternal('style'); $styleVars = $styleApi->fetchStyleVars([$vboptions['styleid']]); $frontendurl = $vboptions['frontendurl']; $iconsSetting = json_decode($vboptions['manifest_icon'] ?? '[]', true); $sizes = $iconsSetting['sizes'] ?? [512]; $firstSize = reset($sizes); $firstFiledataid = $iconsSetting['filedataid_' . $firstSize] ?? 0; if (!empty($firstFiledataid)) { if (!empty($iconsSetting['isSVG'])) { $icons = [ [ 'src' => $frontendurl . '/filedata/fetch?filedataid=' . intval($firstFiledataid), 'sizes' => 'any', 'type' => 'image/svg+xml', ], ]; } else { $icons = []; foreach ($sizes AS $__size) { $__size = intval($__size); if (!empty($iconsSetting['filedataid_' . $__size])) $icons[] = [ 'src' => $frontendurl . '/filedata/fetch?filedataid=' . intval($iconsSetting['filedataid_' . $__size]), 'sizes' => $__size . 'x' . $__size, 'type' => $iconsSetting['mimetype'], ]; } } } else { $defaultIcon = $frontendurl . '/images/misc/vb_logo_square_darkblue.svg'; $icons = [ [ 'src' => $defaultIcon, 'sizes' => 'any', 'type' => 'image/svg+xml', ], ]; } $manifest = new vB_Entity_WebManifest( $stringUtil->toUtf8($vboptions['bbtitle']), $icons, $frontendurl, 'standalone' ); return ['manifest' => (string)$manifest]; } public function saveSiteNameAndUrl(?string $sitename = null) : array { $update = []; if (!is_null($sitename)) { $this->checkHasAdminPermission(['canadminsettings', 'canadminsettingsall']); $update['bbtitle'] = $sitename; } if (count($update)) { $this->logAdminAction(__FUNCTION__, 'Site Name: ' . $update['bbtitle']); } $optionsLib = vB_Library::instance('options'); $i = 1; $max = count($update); foreach ($update AS $__varname => $__value) { $__rebuild = ($i++ == $max); $optionsLib->updateValue($__varname, $__value, $__rebuild); } $datastore = vB::getDatastore(); $bbtitle = $datastore->getOption('bbtitle'); $frontendurl = $datastore->getOption('frontendurl'); return [ 'success' => true, 'bbtitle' => $bbtitle, 'frontendurl' => $frontendurl, ]; } } 