Пример #1
0
 function save_layout()
 {
     if (!Upfront_Permissions::current(Upfront_Permissions::SAVE)) {
         $this->_reject();
     }
     $data = !empty($_POST['data']) ? json_decode(stripslashes_deep($_POST['data']), true) : false;
     if (!$data) {
         $this->_out(new Upfront_JsonResponse_Error("Unknown layout"));
     }
     $storage_key = $_POST['storage_key'];
     $stylesheet = $_POST['stylesheet'] ? $_POST['stylesheet'] : get_stylesheet();
     upfront_switch_stylesheet($stylesheet);
     $layout = Upfront_Layout::from_php($data, $storage_key);
     $key = $layout->save();
     // For single page layouts, also drop page templates
     $layout_data = $layout->get('layout');
     if (!empty($layout_data['specificity']) && preg_match('/single-page-\\d+$/', $layout_data['specificity'])) {
         $page_id = preg_replace('/single-page-(\\d+)$/', '\\1', $layout_data['specificity']);
         // If we have a page template set...
         if (!empty($page_id) && get_post_meta($page_id, '_wp_page_template', true)) {
             // Kill it, as we just saved the layout for it
             delete_post_meta($page_id, '_wp_page_template');
         }
         if (!empty($page_id)) {
             wp_update_post(array('ID' => $page_id, 'post_status' => 'publish'));
         }
     }
     $this->_out(new Upfront_JsonResponse_Success($key));
 }
 /**
  * This fires in style parsing AJAX request and overrides the used layout.
  *
  * @param Upfront_Layout $layout Style layout for parsing
  * @return Upfront_Layout
  */
 public function intercept_style_loading($layout)
 {
     $key = !empty($_GET['layout']['layout_revision']) ? $_GET['layout']['layout_revision'] : false;
     if (empty($key)) {
         return $layout;
     }
     $cascade = $layout->get_cascade();
     $src_key = !empty($cascade['layout_revision']) ? $cascade['layout_revision'] : false;
     if ($key != $src_key) {
         return $layout;
     }
     $raw = $this->_data->get_revision($key);
     if (!empty($raw)) {
         $layout = Upfront_Layout::from_php($raw);
     }
     return $layout;
 }