/** * Returns the config view for the widget. * * @return vBCms_View_Widget - The view result */ public function getConfigView($widget = false) { global $vbulletin, $messagearea, $vbphrase; $this->assertWidget(); require_once DIR . '/includes/functions_editor.php'; require_once DIR . '/packages/vbcms/wysiwyghtmlparser.php'; require_once DIR . '/packages/vbcms/editor/override.php'; require_once DIR . '/packages/vbcms/bbcode/html.php'; require_once DIR . '/packages/vbcms/bbcode/wysiwyg.php'; require_once DIR . '/includes/functions_databuild.php'; fetch_phrase_group('posting'); vB::$vbulletin->input->clean_array_gpc('r', array( 'do' => vB_Input::TYPE_STR, 'message' => vB_Input::TYPE_STR, 'wysiwyg' => vB_Input::TYPE_BOOL, 'template_name' => vB_Input::TYPE_STR )); $view = new vB_View_AJAXHTML('cms_widget_config'); $view->title = new vB_Phrase('vbcms', 'configuring_widget_x', $this->widget->getTitle()); $config = $this->widget->getConfig(); if ((vB::$vbulletin->GPC['do'] == 'config') AND $this->verifyPostId()) { if (vB::$vbulletin->GPC['wysiwyg']) { $html_parser = new vBCms_WysiwygHtmlParser(vB::$vbulletin); $message = $html_parser->parse(vB::$vbulletin->GPC['message']); } else { $message = convert_urlencoded_unicode(vB::$vbulletin->GPC['message']); } $widgetdm = new vBCms_DM_Widget($this->widget); if (vB::$vbulletin->GPC_exists['template_name']) { $config['template_name'] = vB::$vbulletin->GPC['template_name']; } $widgetdm->set('config', $config); if ($this->content) { $widgetdm->setConfigNode($this->content->getNodeId()); } $widgetdm->save(); if (!$widgetdm->hasErrors()) { if ($this->content) { $segments = array('node' => $this->content->getNodeURLSegment(), 'action' => vB_Router::getUserAction('vBCms_Controller_Content', 'EditPage')); $view->setUrl(vB_View_AJAXHTML::URL_FINISHED, vBCms_Route_Content::getURL($segments)); } $view->setStatus(vB_View_AJAXHTML::STATUS_FINISHED, new vB_Phrase('vbcms', 'configuration_saved')); } else { if (vB::$vbulletin->debug) { $view->addErrors($widgetdm->getErrors()); } // only send a message $view->setStatus(vB_View_AJAXHTML::STATUS_MESSAGE, new vB_Phrase('vbcms', 'configuration_failed')); } } else { // add the config content $configview = $this->createView('config'); if (!isset($config['template_name']) OR ($config['template_name'] == '') ) { $config['template_name'] = 'vbcms_widget_staticbb_page'; } // add the config content $configview->template_name = $config['template_name']; //make the editor $configview->editorid = construct_edit_toolbar( $pagetext, false, new vBCms_Editor_Override(vB::$vbulletin), true, true, true, 'cms_article', '', array() ); $templater = vB_Template::create('vbcms_widgetcontent_editor'); $templater->register('values', $values); $templater->register('widgetid', $this->widget->getId()); $templater->register('disablesmiliesoption', true); $templater->register('editorid', $configview->editorid); $templater->register('messagearea', $messagearea); $configview->editor = $templater->render(); // $configview->editor = $this->getConfigEditorView(); // item id to ensure form is submitted to us $this->addPostId($configview); $view->setContent($configview); // send the view $view->setStatus(vB_View_AJAXHTML::STATUS_VIEW, new vB_Phrase('vbcms', 'configuring_widget')); } return $view; }
/** * Gets editor in the selected mode. * * @return string */ public function actionSwitchMode() { // Set up the style info - we need charset to be set for convert_urlencoded_unicode $this->bootstrap->force_styleid(0); $this->bootstrap->load_style(); require_once DIR . '/includes/class_xml.php'; vB::$vbulletin->input->clean_array_gpc('r', array( 'towysiwyg' => vB_Input::TYPE_BOOL, 'allowsmilie' => vB_Input::TYPE_BOOL, 'message' => vB_Input::TYPE_STR, )); vB::$vbulletin->GPC['message'] = convert_urlencoded_unicode(vB::$vbulletin->GPC['message']); $xml = new vB_AJAX_XML_Builder(vB::$vbulletin, 'text/xml'); if (vB::$vbulletin->GPC['towysiwyg']) { $wysiwyg_parser = new vBCms_BBCode_Wysiwyg(vB::$vbulletin, vBCms_BBCode_Wysiwyg::fetchCmsTags()); // todo: options $wysiwyg_html = $wysiwyg_parser->do_parse(vB::$vbulletin->GPC['message'], false, vB::$vbulletin->GPC['allowsmilie'], true, true, true); $xml->add_tag('message', process_replacement_vars($wysiwyg_html)); } else { $html_parser = new vBCms_WysiwygHtmlParser(vB::$vbulletin); $do_html = false; // todo: option $message = $html_parser->parse(vB::$vbulletin->GPC['message'], $do_html); $xml->add_tag('message', process_replacement_vars($message)); } if (!vB::contentHeadersSent()) { $xml->send_content_type_header(); $xml->send_content_length_header(); vB::contentHeadersSent(true); } return $xml->fetch_xml(); }
protected function saveData($view) { if ($this->data_saved) { return true; } $this->data_saved = true; if (!$this->content->canEdit() AND !$this->content->canPublish() ) { return $vb_phrase['no_edit_permissions']; } require_once DIR . '/includes/functions.php'; // collect error messages $errors = array(); vB::$vbulletin->input->clean_array_gpc('p', array( 'do' => vB_Input::TYPE_STR, 'cms_node_title' => vB_Input::TYPE_STR, 'cms_node_url' => vB_Input::TYPE_STR, 'message' => vB_Input::TYPE_STR, 'url' => vB_Input::TYPE_NOHTML, 'title' => vB_Input::TYPE_NOHTML, 'setpublish' => vB_Input::TYPE_UINT, 'publishdate' => vB_Input::TYPE_UINT, 'html_title' => vB_Input::TYPE_NOHTML, 'publicpreview' => vB_Input::TYPE_UINT, 'new_parentid' => vB_Input::TYPE_UINT, 'comments_enabled' => vB_Input::TYPE_UINT, 'wysiwyg' => vB_Input::TYPE_BOOL, 'parseurl' => vB_Input::TYPE_BOOL, 'posthash' => vB_Input::TYPE_NOHTML, 'poststarttime' => vB_Input::TYPE_UINT, 'htmlstate' => vB_Input::TYPE_NOHTML, )); ($hook = vBulletinHook::fetch_hook('vbcms_article_save_start')) ? eval($hook) : false; $dm = $this->content->getDM(); $dm->set('contentid', $this->content->getId()); if ($this->content->canEdit()) { // get pagetext $pagetext = vB::$vbulletin->GPC['message']; $html_title = vB::$vbulletin->GPC['html_title']; $title = vB::$vbulletin->GPC['title']; // unwysiwygify the incoming data if (vB::$vbulletin->GPC['wysiwyg']) { $html_parser = new vBCms_WysiwygHtmlParser(vB::$vbulletin); $pagetext = $html_parser->parse($pagetext); } $dm->info['parseurl'] = true; $dm->set('pagetext', $pagetext); if ($title) { $dm->set('title', $pagetext); } $bbcodesearch = array(); $video_location = stripos($pagetext, '[video'); $found_image = false; // populate the preview image field with [img] if we can find one if (($i = stripos($pagetext, '[IMG]')) !== false and ($j = stripos($pagetext, '[/IMG]')) AND $j > $i) { $previewimage = htmlspecialchars_uni(substr($pagetext, $i+5, $j - $i - 5)); $image_location = $i; if ($size = @getimagesize($previewimage)) { $dm->set('previewimage', $previewimage); $dm->set('imagewidth', $size[0]); $dm->set('imageheight', $size[1]); $bbcodesearch[] = substr($pagetext, $i, $j + 6); $found_image = true; } } // or populate the preview image field with [attachment] if we can find one if (!$found_image) { $i = stripos($pagetext, "[ATTACH=CONFIG]"); $j = stripos($pagetext, '[/ATTACH]'); if ($j !== false) { if ($i === false) { $i = stripos($pagetext, "[ATTACH]"); if ($i !== false AND ($i > $j)) { $attachmentid = substr($pagetext, $i + 15, $j - $i - 15); $found_image = $this->getAttachData($attachmentid, $dm, $bbcodesearch); } } else if ($i > $j) { $attachmentid = substr($pagetext, $i + 15, $j - $i - 15); $found_image = $this->getAttachData($attachmentid, $dm, $bbcodesearch); } } } if (!$found_image AND $this->content->canDownload()) { require_once(DIR . '/packages/vbattach/attach.php'); $attach = new vB_Attach_Display_Content(vB::$vbulletin, 'vBCms_Article'); $attachments = $attach->fetch_postattach(0, $this->content->getNodeId(), $this->content->getUserId()); if (!empty($attachments)) { foreach($attachments as $attachment) { if ($attachment['hasthumbnail']) { $found_image = $this->getAttachData($attachment['attachmentid'], $dm, $bbcodesearch); if ($found_image) { break; } } } } } // if there are no images in the article body, make sure we unset the preview in the db if (!$found_image ) { $dm->set('previewimage', ''); $dm->set('imagewidth', 0); $dm->set('imageheight', 0); $image_location = intval($video_location) + 1; } $parseurl = false; $providers = $search = $replace = $previewvideo = array(); ($hook = vBulletinHook::fetch_hook('data_preparse_bbcode_video_start')) ? eval($hook) : false; // Convert video bbcode with no option if ((($video_location !== false) AND (intval($video_location) < intval($image_location))) OR $parseurl) { if (!$providers) { $bbcodes = vB::$db->query_read_slave(" SELECT provider, url, regex_url, regex_scrape, tagoption FROM " . TABLE_PREFIX . "bbcode_video ORDER BY priority "); while ($bbcode = vB::$db->fetch_array($bbcodes)) { $providers["$bbcode[tagoption]"] = $bbcode; } } $scraped = 0; if (!empty($providers) AND preg_match_all('#\[video[^\]]*\](.*?)\[/video\]#si', $pagetext, $matches)) { foreach ($matches[1] AS $key => $url) { $match = false; foreach ($providers AS $provider) { $addcaret = ($provider['regex_url'][0] != '^') ? '^' : ''; if (preg_match('#' . $addcaret . $provider['regex_url'] . '#si', $url, $match)) { break; } } if ($match) { if (!$provider['regex_scrape'] AND $match[1]) { $previewvideo['provider'] = $provider['tagoption']; $previewvideo['code'] = $match[1]; $previewvideo['url'] = $url; $bbcodesearch[] = $matches[0][$key]; break; } else if ($provider['regex_scrape'] AND vB::$vbulletin->options['bbcode_video_scrape'] > 0 AND $scraped < vB::$vbulletin->options['bbcode_video_scrape']) { require_once(DIR . '/includes/functions_file.php'); $result = fetch_body_request($url); if (preg_match('#' . $provider['regex_scrape'] . '#si', $result, $scrapematch)) { $previewvideo['provider'] = $provider['tagoption']; $previewvideo['code'] = $scrapematch[1]; $previewvideo['url'] = $url; $bbcodesearch[] = $matches[0][$key]; break; } $scraped++; } } } } } $htmlstate = vB::$vbulletin->GPC_exists['htmlstate'] ? vB::$vbulletin->GPC['htmlstate'] : $this->content->getHtmlState(); // Try to populate previewvideo html if ($previewvideo) { $templater = vB_Template::create('bbcode_video'); $templater->register('url', $previewvideo['url']); $templater->register('provider', $previewvideo['provider']); $templater->register('code', $previewvideo['code']); $dm->set('previewvideo', $templater->render()); $dm->set('previewimage', ''); $dm->set('imagewidth', 0); $dm->set('imageheight', 0); $image_location = -1; } else { $dm->set('previewvideo', ''); } } if ($this->content->canPublish()) { $old_sectionid = $this->content->getParentId(); //set the values, for the dm and update the content. if ( vB::$vbulletin->GPC_exists['new_parentid'] AND intval(vB::$vbulletin->GPC['new_parentid'])) { vBCms_ContentManager::moveSection(array($this->content->getNodeId()), vB::$vbulletin->GPC['new_parentid']); $new_sectionid = vB::$vbulletin->GPC['new_parentid']; } if (vB::$vbulletin->GPC_exists['publicpreview']) { $dm->set('publicpreview', vB::$vbulletin->GPC['publicpreview']); } if (vB::$vbulletin->GPC_exists['comments_enabled']) { $dm->set('comments_enabled', vB::$vbulletin->GPC['comments_enabled']); } if (vB::$vbulletin->GPC_exists['setpublish']) { $dm->set('setpublish', vB::$vbulletin->GPC['setpublish']); } } if (vB::$vbulletin->GPC_exists['html_title']) { $dm->set('html_title', vB::$vbulletin->GPC['html_title']); } if (vB::$vbulletin->GPC_exists['url']) { $dm->set('url', vB::$vbulletin->GPC['url']); } if (vB::$vbulletin->GPC_exists['htmlstate']) { $dm->set('htmlstate', vB::$vbulletin->GPC['htmlstate']); } //We may have some processing to do for public preview. Let's see if comments // are enabled. We never enable them for sections, and they might be turned off globally. vB::$vbulletin->input->clean_array_gpc('r', array( 'publicpreview' => TYPE_UINT)); $success = $dm->saveFromForm($this->content->getNodeId()); $this->changed = true; if ($dm->hasErrors()) { $fieldnames = array( 'html_title' => new vB_Phrase('vbcms', 'html_title'), 'title' => new vB_Phrase('global', 'title') ); $view->errors = $dm->getErrors(array_keys($fieldnames)); $view->error_summary = self::getErrorSummary($dm->getErrors(array_keys($fieldnames)), $fieldnames); $view->status = $view->error_view->title; } else { $view->status = new vB_Phrase('vbcms', 'content_saved'); $this->cleanContentCache(); // Make sure the posthash is valid if (md5(vB::$vbulletin->GPC['poststarttime'] . vB::$vbulletin->userinfo['userid'] . vB::$vbulletin->userinfo['salt']) == vB::$vbulletin->GPC['posthash']) { vB::$vbulletin->db->query_write(" UPDATE " . TABLE_PREFIX . "attachment SET posthash = '', contentid = " . intval($this->content->getNodeId()) . " WHERE posthash = '" . vB::$vbulletin->db->escape_string(vB::$vbulletin->GPC['posthash']) . "' AND contenttypeid = " . intval(vB_Types::instance()->getContentTypeID("vBCms_Article")) . " "); } // only publish to Facebook if we are going from not-published to published, and the date is in the past if (is_facebookenabled() AND $this->content->isPublished()) { $message = new vB_Phrase('posting', 'fbpublish_message_newarticle', vB::$vbulletin->options['bbtitle']); $fblink = vBCms_Route_Content::getURL(array( 'node' => $this->content->getUrlSegment(), 'action' =>'view' )); $fblink = str_ireplace('&', '&', $fblink); publishtofacebook_newarticle($message, $this->content->getTitle(), $this->content->getPageText(), create_full_url($fblink)); } } ($hook = vBulletinHook::fetch_hook('vbcms_article_save_end')) ? eval($hook) : false; //invalidate the navigation cache. vB_Cache::instance()->event('sections_updated'); vB_Cache::instance()->event('articles_updated'); vB_Cache::instance()->event(array_merge($this->content->getCacheEvents(), array($this->content->getContentCacheEvent()))); //Make sure comment count will be updated when a comment is posted if ($threadid = $this->content->getAssociatedThreadId()) { vB_Cache::instance()->event("cms_comments_thread_$threadid"); } vB_Cache::instance()->cleanNow(); $this->content->reset(); //reset the required information $this->content->requireInfo(vBCms_Item_Content::INFO_BASIC); $this->content->requireInfo(vBCms_Item_Content::INFO_CONTENT); $this->content->requireInfo(vBCms_Item_Content::INFO_CONFIG); $this->content->requireInfo(vBCms_Item_Content::INFO_NODE); $this->content->requireInfo(vBCms_Item_Content::INFO_PARENTS); }