<?php
 class vB_Api_Editor extends vB_Api { protected $disableFalseReturnOnly = ['fetchAutoLoadText', 'fetchAllSmilies', 'fetchCustomBbcode']; public function fetchCustomBbcode() { $bbcodeCache = vB::getDatastore()->getValue('bbcodecache'); $data = []; if ($bbcodeCache) { foreach ($bbcodeCache AS $bbcode) { if ($bbcode['buttonimage'] != '') { $data[$bbcode['bbcodetag']] = [ 'title' => $bbcode['title'], 'buttonimage' => $bbcode['buttonimage'], 'twoparams' => $bbcode['twoparams'], ]; } } } return $data; } public function fetchAllSmilies() { $smilies = vB::getDbAssertor()->getRows('vBForum:fetchImagesSortedLimited', ['table' => 'smilie']); $options = vB::getDatastore()->getValue('options'); $smilieInfo = []; $previewSmilies = []; $previewCount = 0; $smilieCount = 0; foreach ($smilies AS $smilie) { if (!isset($smilieInfo[$smilie['category']])) { $smilieInfo[$smilie['category']] = []; } $smilieInfo[$smilie['category']][$smilie['smilieid']] = [ 'image' => $smilie['smiliepath'], 'description' => vB_String::htmlSpecialCharsUni($smilie['title'] . ' ' . $smilie['smilietext']), ]; ++$smilieCount; if ($previewCount < $options['wysiwyg_smtotal']) { $previewSmilies[$smilie['smilieid']] = $smilieInfo[$smilie['category']][$smilie['smilieid']]; } ++$previewCount; } return [ 'categories' => $smilieInfo, 'previewSmilies' => $previewSmilies, 'categoryCount' => count($smilieInfo), 'smilieCount' => $smilieCount, 'previewCount' => count($previewSmilies), 'moreSmilies' => ($smilieCount > count($previewSmilies)), ]; } public function convertHtmlToBbcode($data) { return ['data' => vB_Api::instanceInternal('bbcode')->parseWysiwygHtmlToBbcode($data)]; } public function getSuggestedTagsForEditorText($text) { $text = vB_Api::instanceInternal('bbcode')->parseWysiwygHtmlToBbcode($text); return vB_Api::instanceInternal('tags')->getSuggestedTagsForNodeText($text); } public function fetchVideoProviders() { $bbcodes = vB::getDbAssertor()->assertQuery('bbcode_video', [], ['field' => ['priority'], 'direction' => [vB_dB_Query::SORT_ASC]]); $codes = []; foreach ($bbcodes AS $bbcode) { $codes[$bbcode['provider']] = $bbcode['url']; } return ['data' => $codes]; } public function autosave($nodeid, $parentid, $mode, $pagetext) { $options = vB::getDatastore()->getValue('options'); if (!$options['autosave']) { return ['success' => false]; } if (!vB::getCurrentSession()->get('userid')) { return ['success' => false]; } if ($mode != 'source') { $pagetext = vB_Api::instanceInternal('bbcode')->parseWysiwygHtmlToBbcode($pagetext); } vB::getDbAssertor()->replace('vBForum:autosavetext', [ 'nodeid' => intval($nodeid), 'parentid' => intval($parentid), 'userid' => vB::getCurrentSession()->get('userid'), 'pagetext' => $pagetext, 'dateline' => vB::getRequest()->getTimeNow() ]); return ['success' => true]; } public function discardAutosave($nodeid, $parentid) { if (!vB::getCurrentSession()->get('userid')) { throw new vB_Exception_Api('no_permission'); } vB::getDbAssertor()->delete('vBForum:autosavetext', [ 'nodeid' => intval($nodeid), 'parentid' => intval($parentid), 'userid' => vB::getCurrentSession()->get('userid') ]); return ['success' => true]; } public function fetchAutoLoadText($parentid, $nodeid) { $options = vB::getDatastore()->getValue('options'); if (!$options['autosave']) { return false; } if (!vB::getCurrentSession()->get('userid')) { return false; } $row = vB::getDbAssertor()->getRow('vBForum:autosavetext', [ 'nodeid' => intval($nodeid), 'parentid' => intval($parentid), 'userid' => vB::getCurrentSession()->get('userid') ] ); return $row; } public function fetchContentEntryLimits($channelInfo = [], $conversation = []) { if (!empty($conversation['channelid'])) { $nodeid = $conversation['channelid']; } else if (!empty($channelInfo['channelid'])) { $nodeid = $channelInfo['channelid']; } else { } $options = vB::getDatastore()->getValue('options'); $enableUsermention = ( $options['allowedbbcodes'] & vB_Api_Bbcode::ALLOW_BBCODE_USER ); return [ 'enabled' => [ 'bbcode_user' => $enableUsermention, 'bbcode_hashtag' => $options['allowedbbcodes'] & vB_Api_Bbcode::ALLOW_BBCODE_HASHTAG, ], 'limits' => [ 'bbcode_user' => 0, ], ]; } } 