<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Library_External extends vB_Library { const ROUTE_PATH = '/external'; public function checkExternalForChannels($channelids, $type) { $check = $this->validateExternalType($type); $enabled = true; if ($check['valid'] === false) { $enabled = false; } $result = array(); $gcontext = vB::getUserContext(0); foreach ($channelids AS $channel) { $result[$channel][$type . '_enabled'] = ($enabled AND $gcontext->getChannelPermission('forumpermissions', 'canview', $channel)) ? 1 : 0; } return $result; } public function getExternalRouteForChannels($channelids, $type) { $check = $this->validateExternalType($type); $enabled = true; if ($check['valid'] === false) { $enabled = false; } $result = array(); foreach ($channelids AS $channel) { $result[$channel][$type . '_route'] = $this->getExternalRoute(array('nodeid' => $channel, 'type' => $type), array('nodeid' => '', 'type' => '')); } return $result; } public function getExternalDataForChannels($channelids, $type) { $result = array(); $routes = $this->getExternalRouteForChannels($channelids, $type); $status = $this->checkExternalForChannels($channelids, $type); foreach ($channelids AS $channel) { $result[$channel][$type . '_enabled'] = $status[$channel][$type . '_enabled']; $result[$channel][$type . '_route'] = ($status[$channel][$type . '_enabled'] ? $routes[$channel][$type . '_route'] : ''); } return $result; } public function validateExternalType($type) { $type = trim(strtolower($type)); switch ($type) { case vB_Api_External::TYPE_JS: if (!vB::getDatastore()->getOption('externaljs')) { return array('valid' => false, 'phraseid' => 'external_js_disabled'); } break; case vB_Api_External::TYPE_XML: if (!vB::getDatastore()->getOption('externalxml')) { return array('valid' => false, 'phraseid' => 'external_xml_disabled'); } break; case vB_Api_External::TYPE_RSS: case vB_Api_External::TYPE_RSS1: case vB_Api_External::TYPE_RSS2: if (!vB::getDatastore()->getOption('externalrss')) { return array('valid' => false, 'phraseid' => 'external_rss_disabled'); } break; default: return array('valid' => false, 'phraseid' => 'invalid_external_type'); break; } return array('valid' => true, 'phraseid' => ''); } public function getExternalRoute($data = array(), $options = array()) { $params = array(); if (!empty($data['type'])) { $params['type'] = 'type=' . $data['type']; unset($data['type']); } foreach ($data AS $name => $val) { if (isset($options[$name])) { $params[$name] = ($name . '=' . (is_array($val) ? implode(',', $val) : $val)); } } return ( !empty($params) ? (self::ROUTE_PATH . '?' . (implode('&', $params))) : self::ROUTE_PATH ); } } 