/** * Recursively maps the styles to create a flat array of styles with depth. * * @param int $styleid - Root style to map from * @param int $depth - Current depth * @param array $styles - Current style map * @return array - Finished map */ public function getStyles($styleid = -1, $depth = 1, &$styles = false) { if ((-1 == $styleid) AND isset(self::$styles)) { return self::$styles; } $styles = $styles ? $styles : array(); foreach (vB::$vbulletin->stylecache[$styleid][1] AS $style) { $style['depth'] = $depth; $styles[$style['styleid']] = $style; // check for children if (isset(vB::$vbulletin->stylecache[$style['styleid']])) { self::getStyles($style['styleid'], $depth + 1, $styles); } } if (-1 == $styleid) { self::$styles = $styles; } return $styles; }
/** * Verifies that a styleid is valid. * * @param mixed $value - The value to validate * @param mixed $error - The var to assign an error to * @return mixed | bool - The filtered value or boolean false */ public static function StyleID($value, &$error) { if (!vB_Style::validStyle($value)) { $error = new vB_Phrase('error', 'validation_style_x', htmlspecialchars($value)); return false; } return $value; }
/** * Handles adding a new content node. * * @return string */ public function actionNodeOptions() { // Create AJAX view for html replacement $view = new vB_View_AJAXHTML('vbcms_options_view'); // Add location info for where the new content will reside $view->rawtitle = $this->node->getTitle(); vB::$vbulletin->options['description'] = $this->node->getDescription(); vB::$vbulletin->options['keywords'] = $this->node->getKeywords(); vB::$vbulletin->input->clean_array_gpc('p', array( 'do' => vB_Input::TYPE_STR, 'style' => vB_Input::TYPE_UINT, 'layout' => vB_Input::TYPE_UINT, 'url' => vB_Input::TYPE_NOHTMLCOND, 'title' => vB_Input::TYPE_NOHTML, 'contenttype' => vB_Input::TYPE_UINT )); if ((vB::$vbulletin->GPC['do'] == 'update') AND $this->verifyPostId()) { // update the node $nodedm = $this->node->getDM(); $nodedm->set('url', vB::$vbulletin->GPC['url']); $nodedm->set('userid', vB::$vbulletin->userinfo['userid']); $nodedm->set('title', vB::$vbulletin->GPC['title']); $nodedm->set('title', vB::$vbulletin->GPC['title']); if (vB::$vbulletin->GPC['style']) { $nodedm->set('styleid', vB::$vbulletin->GPC['style']); } if (vB::$vbulletin->GPC['layout']) { $nodedm->set('layoutid', vB::$vbulletin->GPC['layout']); } if (!$nodedm->save()) { $fieldnames = array( 'title' => new vB_Phrase('vbcms', 'title'), 'url' => new vB_Phrase('vbcms', 'url_segment') ); $view->addErrors($nodedm->getErrors(array_keys($fieldnames)), $fieldnames); return $this->saveError($view, 'Node DM save failed'); } $finishurl = vBCms_Route_Content::getURL(array('node' => $this->node->getUrlSegment())); $view->setUrl(vB_View_AJAXHTML::URL_FINISHED, $finishurl); $view->setStatus(vB_View_AJAXHTML::STATUS_FINISHED, new vB_Phrase('vbcms', 'page_updated')); } else { // get the content controller $this->content = vBCms_Content::create($this->node->getPackage(), $this->node->getClass(), $this->node->getContentId()); // add the node as content $this->content->castFrom($this->node); // create the form view $formview = new vB_View('vbcms_node_options_form'); $formview->title = $this->node->getTitle(); // add the available styles // TODO: Allow configured constraints $formview->styles = vB_Style::getStyles(); $formview->style_phrase = new vB_Phrase('vbcms', 'style'); $formview->current_style = $this->node->getStyleSetting(); // add the available layouts // TODO: Allow configured constraints. $layout_collection = new vBCms_Collection_Layout(); $layouts = array(); foreach ($layout_collection AS $id => $layout) { $layouts[$id]['id'] = $id; $layouts[$id]['title'] = $layout->getTitle(); $layouts[$id]['selected'] = ($id == $this->node->getLayoutSetting()); } unset($layout_collection); $formview->layouts = $layouts; $formview->layout_phrase = new vB_Phrase('vbcms', 'layout'); // some useful phrases $formview->url_segment_phrase = new vB_Phrase('vbcms', 'url_segment'); $formview->title_phrase = new vB_Phrase('vbcms', 'title'); $formview->dont_change_phrase = new vB_Phrase('vbcms', 'dont_change'); $formview->url_segment = $this->node->getUrlTitle(); // item id to ensure form is submitted to us $this->addPostId($formview); // add form to the html replacement output $view->setContent($formview); // send the view // TODO: update overlay handler to accept an empty status $view->setStatus(vB_View_AJAXHTML::STATUS_VIEW, ' '); } return $view->render(true); }