/**
  * Renders the settings lightbox for when a module template
  * is added to a layout.
  *
  * @since 1.6.3
  * @param string $parent_id A column node ID.
  * @param string $type The type of module.
  * @param int $position The new module position.
  * @return array|void An array of layout data or nothing if called via AJAX.
  */
 public static function render_module_template_settings($parent_id = null, $type = null, $position = false)
 {
     $post_data = FLBuilderModel::get_post_data();
     $template_id = isset($post_data['template_id']) ? $post_data['template_id'] : $template_id;
     $parent_id = isset($post_data['parent_id']) ? $post_data['parent_id'] : $parent_id;
     $position = isset($post_data['position']) ? (int) $post_data['position'] : $position;
     $module = FLBuilderModel::apply_node_template($template_id, $parent_id, $position);
     // Force the global parent id.
     FLBuilderModel::update_post_data('parent_id', $module->parent);
     // Get the settings html.
     ob_start();
     self::render_module_settings($module->node, $module->type, $module->parent, true);
     $settings = ob_get_clean();
     // Build the response.
     $response = array('layout' => self::render_layout(true), 'settings' => $settings);
     // Echo or return the response.
     if (defined('DOING_AJAX')) {
         echo json_encode($response);
         die;
     } else {
         return $response;
     }
 }
 /**
  * Renders the layout data for a new module.
  *
  * @since 1.7
  * @param string $parent_id A column node ID.
  * @param int $position The new module position.
  * @param string $type The type of module.
  * @param string $template_id The ID of a module template to render.
  * @return array
  */
 public static function render_new_module($parent_id, $position = false, $type = null, $template_id = null)
 {
     // Add a module template?
     if ($template_id) {
         $module = FLBuilderModel::apply_node_template($template_id, $parent_id, $position);
     } else {
         $module = FLBuilderModel::add_default_module($parent_id, $type, $position);
     }
     // Render the new module's settings.
     $settings = FLBuilder::render_module_settings($module->node, $module->settings->type, $module->parent, false);
     // Maybe render the module's parent for a partial refresh?
     if ($module->partial_refresh) {
         // Get the new module parent.
         $parent = !$parent_id ? null : FLBuilderModel::get_node($parent_id);
         // Get the node to render.
         if (!$parent) {
             $row = FLBuilderModel::get_module_parent('row', $module);
             $render_id = $row->node;
         } else {
             if ($parent->type == 'row') {
                 $col = FLBuilderModel::get_module_parent('column-group', $module);
                 $render_id = $col->node;
             } else {
                 $render_id = $module->node;
             }
         }
     } else {
         $render_id = null;
     }
     // Return the response.
     return array('layout' => self::render($render_id), 'settings' => $settings['settings']);
 }
 /**
  * Applies a node template that is defined as network-wide.
  *
  * @since 1.6.3
  * @param int $template_id The node template post ID.
  * @param string $parent_id The new parent node ID for the template.
  * @param int $position The position of the template within the layout.
  * @return void
  */
 public static function apply_node($template_id = null, $parent_id = null, $position = 0)
 {
     $site_id = self::get_source_site_id();
     $template = new StdClass();
     if ($site_id) {
         if (is_multisite()) {
             switch_to_blog($site_id);
         }
         $template->data = FLBuilderModel::get_layout_data('published', $template_id);
         $template->settings = FLBuilderModel::get_layout_settings('published', $template_id);
         $template->type = FLBuilderModel::get_user_template_type($template_id);
         $template->global = false;
         if (is_multisite()) {
             restore_current_blog();
         }
         return FLBuilderModel::apply_node_template($template_id, $parent_id, $position, $template);
     }
     return false;
 }