/** * Returns an array of partial refresh data. * * @since 1.7 * @access private * @return array */ private static function get_partial_refresh_data() { // Get the data if it's not cached. if (!self::$partial_refresh_data) { $post_data = FLBuilderModel::get_post_data(); $partial_refresh = false; // Check for partial refresh if we have a node ID. if (isset($post_data['node_id'])) { // Get the node. $node_id = $post_data['node_id']; $node = FLBuilderModel::get_node($post_data['node_id']); // Check a module for partial refresh. if ($node && 'module' == $node->type) { $node = FLBuilderModel::get_module($node_id); $node_type = 'module'; $partial_refresh = $node->partial_refresh; } else { if ($node) { $node_type = $node->type; $partial_refresh = self::node_modules_support_partial_refresh($node); } } } // Clear the node data if we're not doing a partial refresh. if (!$partial_refresh) { $node_id = null; $node = null; $node_type = null; } // Cache the partial refresh data. self::$partial_refresh_data = array('is_partial_refresh' => $partial_refresh, 'node_id' => $node_id, 'node' => $node, 'node_type' => $node_type); } // Return the data. return self::$partial_refresh_data; }
/** * Render the markup for service specific fields. * * @since 1.5.4 * @param string $account The name of the saved account. * @param object $settings Saved module settings. * @return array { * @type bool|string $error The error message or false if no error. * @type string $html The field markup. * } */ public function render_fields($account, $settings) { $post_data = FLBuilderModel::get_post_data(); $account_data = $this->get_account_data($account); $api = $this->get_api($account_data['api_key']); $response = array('error' => false, 'html' => ''); // Lists field try { if (!isset($post_data['list_id'])) { $lists = $api->lists->getList(); $response['html'] .= $this->render_list_field($lists, $settings); } } catch (Mailchimp_Error $e) { $response['error'] = $e->getMessage(); } // Groups field try { if (isset($post_data['list_id']) || isset($settings->list_id)) { if (isset($post_data['list_id'])) { $list_id = $post_data['list_id']; } else { $list_id = $settings->list_id; } $groups = $api->lists->interestGroupings($list_id); $response['html'] .= $this->render_groups_field($list_id, $groups, $settings); } } catch (Mailchimp_Error $e) { } return $response; }
/** * Delete a saved account from the database. * * Called via the fl_ajax_fl_builder_delete_service_account action. * * @since 1.5.4 * @return void */ public static function delete_account() { $post_data = FLBuilderModel::get_post_data(); if (!isset($post_data['service']) || !isset($post_data['account'])) { return; } FLBuilderModel::delete_service_account($post_data['service'], $post_data['account']); }
<div class="fl-widget"> <?php global $wp_widget_factory; // Get builder post data. $post_data = FLBuilderModel::get_post_data(); // Widget class if (isset($settings->widget)) { $widget_slug = $settings->widget; } else { if (isset($post_data['widget']) && FLBuilderModel::is_builder_active()) { $widget_slug = $post_data['widget']; } } if (isset($widget_slug) && isset($wp_widget_factory->widgets[$widget_slug])) { // Widget instance $factory_instance = $wp_widget_factory->widgets[$widget_slug]; $widget_class = get_class($factory_instance); $widget_instance = new $widget_class($factory_instance->id_base, $factory_instance->name, $factory_instance->widget_options); // Widget settings $settings_key = 'widget-' . $widget_instance->id_base; $widget_settings = isset($settings->{$settings_key}) ? (array) $settings->{$settings_key} : array(); // Render the widget the_widget($widget_slug, $widget_settings, array('widget_id' => 'fl_builder_widget_' . $module->node)); } else { if (isset($widget_slug) && FLBuilderModel::is_builder_active()) { // Widget doesn't exist! printf(_x('%s no longer exists.', '%s stands for widget slug.', 'fl-builder'), $widget_slug); } } ?> </div>
/** * Renders the settings lightbox for a module. * * @since 1.0 * @param string $node_id The module node ID. * @param string $type The type of module. * @param string $parent_id The parent column node ID. * @param bool $return Whether to return the layout data or echo it. * @return void */ public static function render_module_settings($node_id = null, $type = null, $parent_id = null, $return = false) { $post_data = FLBuilderModel::get_post_data(); $node_id = isset($post_data['node_id']) ? $post_data['node_id'] : $node_id; $type = isset($post_data['type']) ? $post_data['type'] : $type; $parent_id = isset($post_data['parent_id']) ? $post_data['parent_id'] : $parent_id; $buttons = array(); // Get the module and settings. if ($node_id) { $module = FLBuilderModel::get_module($node_id); $settings = $module->settings; } else { $module = FLBuilderModel::$modules[$type]; $settings = FLBuilderModel::get_module_defaults($type); } // Is this module global? $global = FLBuilderModel::is_node_global($module); // Add the Save As button? if (!$global && !FLBuilderModel::is_post_node_template() && FLBuilderModel::node_templates_enabled()) { $buttons[] = 'save-as'; } // Render the settings CSS/JS. if (file_exists($module->dir . 'css/settings.css')) { echo '<link class="fl-builder-settings-css" rel="stylesheet" href="' . $module->url . 'css/settings.css" />'; } if (file_exists($module->dir . 'js/settings.js')) { echo '<script class="fl-builder-settings-js" src="' . $module->url . 'js/settings.js"></script>'; } // Render the form. echo self::render_settings(array('class' => 'fl-builder-module-settings fl-builder-' . $type . '-settings', 'attrs' => 'data-node="' . $node_id . '" data-parent="' . $parent_id . '" data-type="' . $type . '"', 'title' => sprintf(_x('%s Settings', '%s stands for module name.', 'fl-builder'), $module->name), 'badges' => $global ? array('global' => _x('Global', 'Indicator for global node templates.', 'fl-builder')) : array(), 'tabs' => $module->form, 'buttons' => $buttons), $settings, $return); }
function zestsms_select2_field($name, $value, $field, $settings) { $options = $field['options'] ? $field['options'] : array(); if ($options_field = $field['options_from_field']) { $post_data = FLBuilderModel::get_post_data(); $parent_settings = $post_data['node_settings']; $options = zestsms_get_field_options($parent_settings, $options_field, $options); } // Create attributes $attributes = ''; if (is_array($field['attributes'])) { foreach ($field['attributes'] as $key => $val) { $attributes .= $key . '="' . $val . '" '; } } // Show the select field ?> <select name="<?php echo $name; if (isset($field['multi-select'])) { echo '[]'; } ?> " class="zestsms-select2 <?php echo $field['class']; ?> " <?php if (isset($field['multi-select'])) { echo 'multiple '; } echo $attributes; ?> > <?php foreach ($options as $option_key => $option_val) { if (is_array($option_val) && isset($option_val['premium']) && $option_val['premium'] && true === FL_BUILDER_LITE) { continue; } $label = is_array($option_val) ? $option_val['label'] : $option_val; if (is_array($value) && in_array($option_key, $value)) { $selected = ' selected="selected"'; } else { if (!is_array($value) && selected($value, $option_key, true)) { $selected = ' selected="selected"'; } else { $selected = ''; } } ?> <option value="<?php echo $option_key; ?> " <?php echo $selected; ?> ><?php echo $label; ?> </option> <?php } ?> </select> <?php }
/** * Render the markup for service specific fields. * * @since 1.6.0 * @param string $account The name of the saved account. * @param object $settings Saved module settings. * @return array { * @type bool|string $error The error message or false if no error. * @type string $html The field markup. * } */ public function render_fields($account, $settings) { $post_data = FLBuilderModel::get_post_data(); $account_data = $this->get_account_data($account); $api = $this->get_api($account_data['api_url'], $account_data['api_key']); $response = array('error' => false, 'html' => ''); $lists = $api->api('list/list?ids=all'); $response['html'] = $this->render_list_field($lists, $settings); return $response; }
/** * Render markup for the list field. * * @since 1.5.4 * @param array $account_data Saved account data. * @param object $settings Saved module settings. * @return string The markup for the list field. * @access private */ private function render_list_field($account_data, $settings) { $post_data = FLBuilderModel::get_post_data(); // Get the client ID. Return an empty string if we don't have one yet. if (isset($post_data['client'])) { $client_id = $post_data['client']; } else { if (isset($settings->client_id)) { $client_id = $settings->client_id; } else { return ''; } } // Get the list data. $api = new CS_REST_Clients($client_id, $account_data); $lists = $api->get_lists(); // Render the list field. ob_start(); $options = array('' => __('Choose...', 'fl-builder')); foreach ($lists->response as $list) { $options[$list->ListID] = $list->Name; } FLBuilder::render_settings_field('list_id', array('row_class' => 'fl-builder-service-field-row', 'class' => 'fl-builder-service-list-select', 'type' => 'select', 'label' => _x('List', 'An email list from a third party provider.', 'fl-builder'), 'options' => $options, 'preview' => array('type' => 'none')), $settings); return ob_get_clean(); }
/** * Renders layouts using a new instance of WP_Query with the provided * args and enqueues the necessary styles and scripts. We set the global * $wp_query variable so the builder thinks we are in the loop when content * is rendered without having to call query_posts. * * @link https://codex.wordpress.org/Class_Reference/WP_Query See for a complete list of args. * * @since 1.7 * @param array|string $args An array or string of args to be passed to a new instance of WP_Query. * @return void */ public static function render_query($args) { global $post; global $wp_query; $original_post = $post; $wp_query = new WP_Query($args); $post_data = FLBuilderModel::get_post_data(); // Unset the builder's post_data post ID so the global $post is used. FLBuilderModel::update_post_data('post_id', null); // Loop through the posts. while ($wp_query->have_posts()) { // Set the global post. $wp_query->the_post(); // Make sure this isn't the same post as the original post to prevent infinite loops. if ($original_post->ID === $post->ID) { continue; } // Enqueue styles and scripts for this post. self::enqueue_layout_styles_scripts($post->ID); // Print the styles since we are outside of the head tag. ob_start(); wp_print_styles(); $styles = str_replace("\n", '', ob_get_clean()); // Added stylesheets inline can mess with specificity, so we add them to the head with JS. if (!empty($styles)) { echo '<script>jQuery("head").prepend("' . $styles . '");</script>'; } // Render the content. the_content(); } // Reset the post_id if we have one in $post_data. if (isset($post_data['post_id'])) { FLBuilderModel::update_post_data('post_id', $post_data['post_id']); } // Reset the global query. wp_reset_query(); }
/** * Runs the current AJAX action. * * @since 1.7 * @access private * @return void */ private static function call_action() { // Only run for logged in users. if (!is_user_logged_in()) { return; } // Get the $_POST data. $post_data = FLBuilderModel::get_post_data(); // Get the post ID. $post_id = FLBuilderModel::get_post_id(); // Make sure the user can edit this post. if ($post_id && !current_user_can('edit_post', $post_id)) { return; } // Get the action. if (!empty($_REQUEST['fl_action'])) { $action = $_REQUEST['fl_action']; } else { if (!empty($post_data['fl_action'])) { $action = $post_data['fl_action']; } else { return; } } // Make sure the action exists. if (!isset(self::$actions[$action])) { return; } // Get the action data. $action = self::$actions[$action]; $args = array(); // Build the args array. foreach ($action['args'] as $arg) { $args[] = isset($post_data[$arg]) ? $post_data[$arg] : null; } // Tell WordPress this is an AJAX request. define('DOING_AJAX', true); // Call the method. $result = call_user_func_array($action['method'], $args); // JSON encode the result. echo json_encode($result); // Complete the request. die; }
/** * Renders the settings lightbox for a module. * * @since 1.0 * @param string $node_id The module node ID. * @param string $type The type of module. * @param string $parent_id The parent column node ID. * @param bool $return Whether to return the layout data or echo it. * @return void */ public static function render_module_settings($node_id = null, $type = null, $parent_id = null, $return = false) { $post_data = FLBuilderModel::get_post_data(); $node_id = isset($post_data['node_id']) ? $post_data['node_id'] : $node_id; $type = isset($post_data['type']) ? $post_data['type'] : $type; $parent_id = isset($post_data['parent_id']) ? $post_data['parent_id'] : $parent_id; if ($node_id) { $module = FLBuilderModel::get_module($node_id); $settings = $module->settings; } else { $module = FLBuilderModel::$modules[$type]; $settings = FLBuilderModel::get_module_defaults($type); } if (file_exists($module->dir . 'css/settings.css')) { echo '<link class="fl-builder-settings-css" rel="stylesheet" href="' . $module->url . 'css/settings.css" />'; } if (file_exists($module->dir . 'js/settings.js')) { echo '<script class="fl-builder-settings-js" src="' . $module->url . 'js/settings.js"></script>'; } echo self::render_settings(array('class' => 'fl-builder-module-settings fl-builder-' . $type . '-settings', 'attrs' => 'data-node="' . $node_id . '" data-parent="' . $parent_id . '" data-type="' . $type . '"', 'title' => sprintf(_x('%s Settings', '%s stands for module name.', 'fl-builder'), $module->name), 'tabs' => $module->form), $settings, $return); }
/** * Checks to make sure the AJAX nonce is valid. * * @since 1.7.2 * @access private * @return bool */ private static function verify_nonce() { $post_data = FLBuilderModel::get_post_data(); $nonce = false; if (isset($post_data['_wpnonce'])) { $nonce = $post_data['_wpnonce']; } else { if (isset($_REQUEST['_wpnonce'])) { $nonce = $_REQUEST['_wpnonce']; } } if (!$nonce || !wp_verify_nonce($nonce, 'fl_ajax_update')) { return false; } return true; }