/**
  *set status of builder (open/closed) and save the shortcodes that are used in the post
  **/
 public function meta_box_save()
 {
     if (isset($_POST['post_ID'])) {
         //save if the editor is active
         if (isset($_POST['aviaLayoutBuilder_active'])) {
             update_post_meta((int) $_POST['post_ID'], '_aviaLayoutBuilder_active', $_POST['aviaLayoutBuilder_active']);
             $_POST['content'] = ShortcodeHelper::clean_up_shortcode($_POST['content']);
         }
         //save the hidden container with unmodified shortcode
         if (isset($_POST['_aviaLayoutBuilderCleanData'])) {
             update_post_meta((int) $_POST['post_ID'], '_aviaLayoutBuilderCleanData', $_POST['_aviaLayoutBuilderCleanData']);
         }
         //extract all shortcodes from the post array and store them so we know what we are dealing with when the user opens a page.
         //usesfull for special elements that we might need to render outside of the default loop like fullscreen slideshows
         preg_match_all("/" . ShortcodeHelper::get_fake_pattern() . "/s", $_POST['content'], $matches);
         if (is_array($matches) && !empty($matches[0])) {
             $matches = ShortcodeHelper::build_shortcode_tree($matches);
             update_post_meta((int) $_POST['post_ID'], '_avia_builder_shortcode_tree', $matches);
         }
     }
 }
 /**
  * Ajax Function that checks if template can be saved
  *
  */
 public function save_builder_template($name = "%", $value = "")
 {
     check_ajax_referer('avia_nonce_save', 'avia-save-nonce');
     $name = isset($_POST['templateName']) ? $_POST['templateName'] : $name;
     $value = isset($_POST['templateValue']) ? $_POST['templateValue'] : $value;
     $id = AviaStoragePost::get_custom_post('template_builder_snippets');
     $key = $this->generate_key($name);
     $old = $this->get_meta_values($key);
     if (!empty($old)) {
         echo __('Template name already in use. Please delete the template with this name first or choose a different name', 'avia_framework');
     } else {
         $value = ShortcodeHelper::clean_up_shortcode($value);
         $result = update_post_meta($id, $key, '{{{' . $name . '}}}' . $value);
         echo 'avia_template_saved';
     }
     die;
 }