<?php
 abstract class vB_External_Export_Rss extends vB_External_Export { protected $rssinfo = []; protected $defaultLang = []; protected $assertor; public function __construct() { $this->loadDefLanguage(); $this->assertor = vB::getDbAssertor(); } protected function loadDefLanguage() { $langid = vB::getDatastore()->getOption('languageid'); $languages = vB_Api::instanceInternal('language')->fetchAll(); $this->defaultLang = $languages[$langid]; } protected function loadRssInfo($options) { $description = $this->getPhraseFromGuid(vB_Page::PAGE_HOME, 'metadesc'); $ds = vB::getDatastore(); $frontendurl = $ds->getOption('frontendurl'); $facebookfeedimageurl = $ds->getOption('facebookfeedimageurl'); if ($facebookfeedimageurl) { $rssicon = $facebookfeedimageurl; } else { $stylevars = vB_Api::instanceInternal('style')->fetchStylevars([vB::getDatastore()->getOption('styleid')]); $imgdir = (!empty($stylevars['imgdir_misc']['imagedir'])) ? $stylevars['imgdir_misc']['imagedir'] : ''; $isAbsoluteUrl = (bool) preg_match('#^(https?://:)#i', $imgdir); if (!$isAbsoluteUrl) { $imgdir = $frontendurl . '/' . $imgdir; } $rssicon = $imgdir . '/rss.png'; } $this->rssinfo = [ 'title' => $ds->getOption('bbtitle'), 'link' => $frontendurl, 'icon' => $rssicon, 'description' => $description, 'ttl' => 60 ]; $this->rssinfo = $this->applyRssOptions($options, $this->rssinfo); } protected function getItemsChannelInfo($items) { $info = []; foreach ($items AS $id => $item) { if (!isset($info[$item['content']['channelid']])) { $info[$item['content']['channelid']] = vB_Library::instance('node')->getNodeBare($item['content']['channelid']); } } return $info; } protected function getItemDescription($text, $options) { if (!empty($options['fulldesc'])) { $description = vB_String::htmlSpecialCharsUni( vB_String::fetchCensoredText( vB_String::stripBbcode($text, true, false, true, true) ) ); } else { $description = vB_String::htmlSpecialCharsUni( vB_String::fetchCensoredText( vB_String::fetchTrimmedTitle( vB_String::stripBbcode($text, true, false, true, true), vB::getDatastore()->getOption('threadpreview') ) ) ); } return $description; } private function applyRssOptions($options, $info) { if (isset($options['nodeid'])) { if (sizeof($options['nodeid']) == 1) { $channel = $this->assertor->getRow('vBForum:getPageInfoFromChannelId', ['nodeid' => $options['nodeid']]); $info['title'] = vB_Phrase::fetchSinglePhrase('external_x_hyphen_y', [$info['title'], $this->getPhraseFromGuid($channel['guid'], 'title')]); $info['description'] = $this->getPhraseFromGuid($channel['guid'], 'metadesc'); } else { $info['title'] = vB_Phrase::fetchSinglePhrase('external_x_hyphen_y', [$info['title'], implode(', ', $options['nodeid'])]); } } return $info; } private function getPhraseFromGuid($guid, $phrase) { $guidforphrase = vB_Library::instance('phrase')->cleanGuidForPhrase($guid); $rows = $this->assertor->getRows('vBForum:phrase', [ 'languageid' => [$this->defaultLang['languageid'], 0, -1], 'varname' => ('page_' . $guidforphrase . '_' . $phrase) ]); $description = ''; if (!empty($rows) AND is_array($rows) AND !isset($rows['errors'])) { foreach ($rows AS $row) { if ($row['languageid'] == $this->defaultLang['languageid']) { $description = $row['text']; } else if (in_array($row['languageid'], [0, -1])) { $description = $row['text']; } } } else { $page = $this->assertor->getRow('vBForum:page', ['guid' => $guid]); $description = $page[($phrase == 'title' ? $phrase : 'metadescription')]; } return $description; } } 