Esempio n. 1
0
 public function actionSave()
 {
     $this->_assertPostOnly();
     if ($this->_input->filterSingle('delete', XenForo_Input::STRING)) {
         return $this->responseReroute(__CLASS__, 'deleteConfirm');
     }
     $data = $this->_input->filter(array('title' => XenForo_Input::STRING, 'description' => XenForo_Input::STRING, 'node_name' => XenForo_Input::STRING, 'node_type_id' => XenForo_Input::BINARY, 'parent_node_id' => XenForo_Input::UINT, 'display_order' => XenForo_Input::UINT, 'display_in_list' => XenForo_Input::UINT, 'style_id' => XenForo_Input::UINT, 'options' => XenForo_Input::ARRAY_SIMPLE));
     $widgetsInput = $this->_input->filterSingle('widgets', XenForo_Input::ARRAY_SIMPLE);
     $toggler = $this->_input->filterSingle('toggler', XenForo_Input::ARRAY_SIMPLE);
     if (!$this->_input->filterSingle('style_override', XenForo_Input::UINT)) {
         $data['style_id'] = 0;
     }
     $nodeId = $this->_input->filterSingle('node_id', XenForo_Input::UINT);
     // save page
     $dw = $this->_getNodeDataWriter();
     if ($nodeId) {
         $dw->setExistingData($nodeId);
     }
     $dw->bulkSet($data);
     $dw->save();
     if ($this->_input->filterSingle('is_index', XenForo_Input::UINT)) {
         WidgetFramework_Option::setIndexNodeId($dw->get('node_id'));
     } elseif (WidgetFramework_Option::get('indexNodeId') == $dw->get('node_id')) {
         WidgetFramework_Option::setIndexNodeId(0);
     }
     // save widgets
     $widgets = $this->_getWidgetModel()->getWidgetPageWidgets($dw->get('node_id'));
     $widgetOptionsChanged = 0;
     $preferStaying = 0;
     foreach ($widgets as $widget) {
         $changed = 0;
         $newOptions = $widget['options'];
         $newValues = array();
         if (!empty($widgetsInput[$widget['widget_id']])) {
             $inputRef =& $widgetsInput[$widget['widget_id']];
             if (isset($inputRef['layout_row']) and (!isset($widget['options']['layout_row']) or $inputRef['layout_row'] != $widget['options']['layout_row'])) {
                 $changed++;
                 $widgetOptionsChanged++;
                 $newOptions['layout_row'] = $inputRef['layout_row'];
             }
             if (isset($inputRef['layout_col']) and (!isset($widget['options']['layout_col']) or $inputRef['layout_col'] != $widget['options']['layout_col'])) {
                 $changed++;
                 $widgetOptionsChanged++;
                 $newOptions['layout_col'] = $inputRef['layout_col'];
             }
             if (isset($inputRef['layout_sizeRow']) and (!isset($widget['options']['layout_sizeRow']) or $inputRef['layout_sizeRow'] != $widget['options']['layout_sizeRow'])) {
                 $changed++;
                 $widgetOptionsChanged++;
                 $newOptions['layout_sizeRow'] = $inputRef['layout_sizeRow'];
             }
             if (isset($inputRef['layout_sizeCol']) and (!isset($widget['options']['layout_sizeCol']) or $inputRef['layout_sizeCol'] != $widget['options']['layout_sizeCol'])) {
                 $changed++;
                 $widgetOptionsChanged++;
                 $newOptions['layout_sizeCol'] = $inputRef['layout_sizeCol'];
             }
         }
         if (!empty($toggler['exists'][$widget['widget_id']])) {
             $widgetActive = empty($toggler['id'][$widget['widget_id']]) ? 0 : intval($toggler['id'][$widget['widget_id']]);
             if ($widgetActive != $widget['active']) {
                 $changed++;
                 $preferStaying++;
                 $newValues['active'] = $widgetActive;
             }
         }
         if ($changed > 0) {
             $widgetDw = XenForo_DataWriter::create('WidgetFramework_DataWriter_Widget');
             $widgetDw->setExistingData($widget, true);
             $widgetDw->set('options', $newOptions);
             $widgetDw->bulkSet($newValues);
             $widgetDw->save();
         }
     }
     $link = XenForo_Link::buildAdminLink('widget-pages/edit', $dw->getMergedData());
     if ($widgetOptionsChanged == 0 and $preferStaying > 0 and $this->_noRedirect()) {
         // skip redirect
         $link = false;
     }
     if ($link !== false) {
         $response = $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, $link);
     } else {
         $response = $this->responseMessage(new XenForo_Phrase('redirect_changes_saved_successfully'));
     }
     if (XenForo_Application::isRegistered('nodesAsTabsAPI')) {
         NodesAsTabs_API::actionSave($response, $this);
     }
     return $response;
 }