/** * Apply per page content width * * @since 1.0 */ function sklc_ppcw_apply($lc_width) { // Post types that support templates global $dslc_post_types; $new_width = $lc_width; $post_ID = false; // If single, load template if (is_singular($dslc_post_types)) { $post_ID = dslc_st_get_template_ID(get_the_ID()); } // If archive, load template if (is_archive() && !is_author() && !is_search()) { $post_ID = dslc_get_option(get_post_type(), 'dslc_plugin_options_archives'); } // If author archives if (is_author()) { $post_ID = dslc_get_option('author', 'dslc_plugin_options_archives'); } // If search results page if (is_search()) { $post_ID = dslc_get_option('search_results', 'dslc_plugin_options_archives'); } // If 404 page if (is_404()) { $post_ID = dslc_get_option('404_page', 'dslc_plugin_options_archives'); } // If a page or post template if (is_singular(array('page', 'dslc_templates'))) { $post_ID = get_the_ID(); } // If we have a post ID if ($post_ID) { // Get custom width $custom_width = get_post_meta($post_ID, 'sklc_ppcw_content_width', true); // If custom width set if ($custom_width) { // Set new width $new_width = $custom_width; // If px or % not included add px if (strpos($new_width, 'px') === false && strpos($new_width, '%') === false) { $new_width = $new_width . 'px'; } } } return $new_width; }
/** * Add custom classes to the body tag * * @since 1.0 */ function dslc_body_class($classes) { global $dslc_post_types; $proceed = false; $has_lc_content = false; $has_lc_header_footer = false; if (is_archive() && !is_author() && !is_search()) { $template_id = dslc_get_option(get_post_type(), 'dslc_plugin_options_archives'); if ($template_id) { $proceed = true; $has_lc_content = true; } } if (is_author()) { $template_id = dslc_get_option('author', 'dslc_plugin_options_archives'); if ($template_id) { $proceed = true; $has_lc_content = true; } } if (is_search()) { $template_id = dslc_get_option('search_results', 'dslc_plugin_options_archives'); if ($template_id) { $proceed = true; $has_lc_content = true; } } if (is_singular()) { $proceed = true; } if (false === $proceed) { return $classes; } // If page in LC mode, force the class? if (isset($_GET['dslc'])) { $has_lc_content = true; } // Still nothing, let's check if there's real LC content on the page. if (!$has_lc_content) { // Get the dslc_code custom field. $dslc_code = get_post_meta(get_the_ID(), 'dslc_code', true); // If there is LC content, allow the class? if ($dslc_code) { $has_lc_content = true; } } // Still nothing, let's check if it's a post and has an LC template. if (!$has_lc_content && is_singular($dslc_post_types)) { // Get the ID of the template. $template_id = dslc_st_get_template_ID(get_the_ID()); // If template exists, allow the class. if ($template_id) { $has_lc_content = true; } } // Let's check if it has LC powered header/footer. $header_footer = dslc_hf_get_ID(get_the_ID()); if ($header_footer['header'] || $header_footer['footer']) { $has_lc_header_footer = true; } // If has LC content append class. if ($has_lc_content || $has_lc_header_footer) { $classes[] = 'dslc-page'; } if ($has_lc_content) { $classes[] = 'dslc-page-has-content'; } if ($has_lc_header_footer) { $classes[] = 'dslc-page-has-hf'; } // If responsive disabled append class. if (defined('DS_LIVE_COMPOSER_RESPONSIVE') && !DS_LIVE_COMPOSER_RESPONSIVE) { $classes[] = 'dslc-res-disabled'; } // Return the modified array. return $classes; }
/** * Custom CSS * * @since 1.0 */ function dslc_custom_css() { if (!is_singular() && !is_archive() && !is_author() && !is_search() && !is_404() && !is_home()) { return; } global $dslc_active; global $dslc_css_style; global $content_width; global $dslc_googlefonts_array; global $dslc_all_googlefonts_array; global $dslc_post_types; $composer_code = ''; $template_code = ''; $lc_width = dslc_get_option('lc_max_width', 'dslc_plugin_options'); if (empty($lc_width)) { $lc_width = $content_width . 'px'; } else { if (strpos($lc_width, 'px') === false && strpos($lc_width, '%') === false) { $lc_width = $lc_width . 'px'; } } // Filter $lc_width ( for devs ) $lc_width = apply_filters('dslc_content_width', $lc_width); $template_ID = false; // If single, load template if (is_singular($dslc_post_types)) { $template_ID = dslc_st_get_template_ID(get_the_ID()); } // If archive, load template if (is_archive() && !is_author() && !is_search()) { $template_ID = dslc_get_option(get_post_type(), 'dslc_plugin_options_archives'); } if (is_author()) { $template_ID = dslc_get_option('author', 'dslc_plugin_options_archives'); } if (is_search()) { $template_ID = dslc_get_option('search_results', 'dslc_plugin_options_archives'); } if (is_404()) { $template_ID = dslc_get_option('404_page', 'dslc_plugin_options_archives'); } // Header/Footer if ($template_ID) { $header_footer = dslc_hf_get_ID($template_ID); } else { if (is_singular($dslc_post_types)) { $template_ID = dslc_st_get_template_ID(get_the_ID()); $header_footer = dslc_hf_get_ID($template_ID); } else { $header_footer = dslc_hf_get_ID(get_the_ID()); } } // Header if ($header_footer['header']) { $header_code = get_post_meta($header_footer['header'], 'dslc_code', true); $composer_code .= $header_code; } // Footer if ($header_footer['footer']) { $footer_code = get_post_meta($header_footer['footer'], 'dslc_code', true); $composer_code .= $footer_code; } // Template content if ($template_ID) { $composer_code .= get_post_meta($template_ID, 'dslc_code', true); } // Post/Page content $post_id = get_the_ID(); $composer_code .= get_post_meta($post_id, 'dslc_code', true); echo '<style type="text/css">'; // If composer not used on this page stop execution if ($composer_code) { // Replace shortcode names $composer_code = str_replace('dslc_modules_section', 'dslc_modules_section_gen_css', $composer_code); $composer_code = str_replace('dslc_modules_area', 'dslc_modules_area_gen_css', $composer_code); $composer_code = str_replace('[dslc_module]', '[dslc_module_gen_css]', $composer_code); $composer_code = str_replace('[dslc_module ', '[dslc_module_gen_css ', $composer_code); $composer_code = str_replace('[/dslc_module]', '[/dslc_module_gen_css]', $composer_code); // Do CSS shortcode do_shortcode($composer_code); // Google Fonts Import $gfonts_output_subsets = ''; $gfonts_subsets_arr = dslc_get_option('lc_gfont_subsets', 'dslc_plugin_options_performance'); if (!$gfonts_subsets_arr) { $gfonts_subsets_arr = array('latin', 'latin-ext', 'cyrillic', 'cyrillic-ext'); } foreach ($gfonts_subsets_arr as $gfonts_subset) { if ($gfonts_output_subsets == '') { $gfonts_output_subsets .= $gfonts_subset; } else { $gfonts_output_subsets .= ',' . $gfonts_subset; } } if (!defined('DS_LIVE_COMPOSER_GFONTS') || DS_LIVE_COMPOSER_GFONTS) { $gfonts_output_prepend = '@import url("//fonts.googleapis.com/css?family='; $gfonts_output_append = '&subset=' . $gfonts_output_subsets . '"); '; $gfonts_ouput_inner = ''; foreach ($dslc_googlefonts_array as $gfont) { if (in_array($gfont, $dslc_all_googlefonts_array)) { $gfont = str_replace(' ', '+', $gfont); if ($gfont != '') { if ($gfonts_ouput_inner == '') { $gfonts_ouput_inner .= $gfont . ':100,200,300,400,500,600,700,800,900'; } else { $gfonts_ouput_inner .= '|' . $gfont . ':100,200,300,400,500,600,700,800,900'; } } } } $gfonts_output = $gfonts_output_prepend . $gfonts_ouput_inner . $gfonts_output_append; if ($gfonts_ouput_inner != '') { echo $gfonts_output; } } } // Wrapper width echo '.dslc-modules-section-wrapper, .dslca-add-modules-section { width : ' . $lc_width . '; } '; // Initial ( default ) row CSS echo dslc_row_get_initial_style(); // Echo CSS style if (!$dslc_active && $composer_code) { echo $dslc_css_style; } echo '</style>'; }
/** * Get the header and footer IDs of a specific post/page * * @since 1.0 * * @param int $post_ID ID of the post/page. Default false ( Automatically finds ID ). * @return array The IDs of the header and footer associated with the post/page. False if none. */ function dslc_hf_get_ID($post_ID = false) { // If theme does not define header/footer compatibility return false if (!defined('DS_LIVE_COMPOSER_HF') || !DS_LIVE_COMPOSER_HF) { return array('header' => false, 'footer' => false); } // If current page is actually header/footer post, return false if (is_singular('dslc_hf')) { return array('header' => false, 'footer' => false); } // Global vars global $dslc_post_types; // If post ID not supplied, figure it out if (!$post_ID) { // If currently showing a singular post of a post type that supports "post templates" if (is_singular($dslc_post_types)) { $post_ID = dslc_st_get_template_ID(get_the_ID()); // If currently showing a category archive page } elseif (is_archive() && !is_author() && !is_search()) { $post_ID = dslc_get_option(get_post_type(), 'dslc_plugin_options_archives'); // If currently showing an author archive page } elseif (is_author()) { $post_ID = dslc_get_option('author', 'dslc_plugin_options_archives'); // If currently showing a search results page } elseif (is_search()) { $post_ID = dslc_get_option('search_results', 'dslc_plugin_options_archives'); // If currently showina 404 page } elseif (is_404()) { $post_ID = dslc_get_option('404_page', 'dslc_plugin_options_archives'); // Otherwise just get the ID } else { $post_ID = get_the_ID(); } } // Get header/footer template $header_tpl = get_post_meta($post_ID, 'dslc_header', true); $footer_tpl = get_post_meta($post_ID, 'dslc_footer', true); // If no header template set, make it "default" if (!$header_tpl) { $header_tpl = 'default'; } // If no footer template set make it "default" if (!$footer_tpl) { $footer_tpl = 'default'; } // Default header template supplied, find it and return the ID if ($header_tpl == 'default') { // Query for default template $args = array('post_type' => 'dslc_hf', 'post_status' => 'publish', 'posts_per_page' => 1, 'meta_query' => array(array('key' => 'dslc_hf_for', 'value' => 'header', 'compare' => '='), array('key' => 'dslc_hf_type', 'value' => 'default', 'compare' => '=')), 'order' => 'DESC'); $tpls = get_posts($args); // If default template found set the ID if not make it false if ($tpls) { $header_tpl_ID = $tpls[0]->ID; } else { $header_tpl_ID = false; } // Specific template supplied, return the ID } elseif ($header_tpl && $header_tpl != '_disabled_') { $header_tpl_ID = $header_tpl; } elseif ($header_tpl && $header_tpl == '_disabled_') { $header_tpl_ID = false; } // Default footer template supplied, find it and return the ID if ($footer_tpl == 'default') { // Query for default template $args = array('post_type' => 'dslc_hf', 'post_status' => 'publish', 'posts_per_page' => 1, 'meta_query' => array(array('key' => 'dslc_hf_for', 'value' => 'footer', 'compare' => '='), array('key' => 'dslc_hf_type', 'value' => 'default', 'compare' => '=')), 'order' => 'DESC'); $tpls = get_posts($args); // If default template found set the ID if not make it false if ($tpls) { $footer_tpl_ID = $tpls[0]->ID; } else { $footer_tpl_ID = false; } // Specific template supplied, return the ID } elseif ($footer_tpl && $footer_tpl != '_disabled_') { $footer_tpl_ID = $footer_tpl; } elseif ($footer_tpl && $footer_tpl == '_disabled_') { $footer_tpl_ID = false; } // Return the template ID return array('header' => $header_tpl_ID, 'footer' => $footer_tpl_ID); }
/** * Display post options * * @since 1.0 */ function dslc_display_post_options($object, $metabox) { global $dslc_var_post_options; $post_options_id = $metabox['id']; $post_options = $dslc_var_post_options[$post_options_id]['options']; ?> <div class="dslca-post-options"> <?php foreach ($post_options as $post_option) { ?> <?php $curr_value_no_esc = get_post_meta($object->ID, $post_option['id'], true); if (!$curr_value_no_esc) { $curr_value_no_esc = $post_option['std']; } $curr_value = esc_attr($curr_value_no_esc); ?> <div class="dslca-post-option"> <div class="dslca-post-option-label"> <span><?php echo $post_option['label']; ?> </span> </div><!-- .dslca-post-option-label --> <?php if (isset($post_option['descr'])) { ?> <div class="dslca-post-option-description"> <?php echo $post_option['descr']; ?> </div><!-- .dslca-post-option-description --> <?php } ?> <div class="dslca-post-option-field dslca-post-option-field-<?php echo $post_option['type']; ?> "> <?php if ($post_option['type'] == 'text') { ?> <input type="text" name="<?php echo $post_option['id']; ?> " id="<?php echo $post_option['id']; ?> " value="<?php echo $curr_value; ?> " size="30" /> <?php } elseif ($post_option['type'] == 'textarea') { ?> <textarea name="<?php echo $post_option['id']; ?> " id="<?php echo $post_option['id']; ?> "><?php echo $curr_value; ?> </textarea> <?php } elseif ($post_option['type'] == 'select') { ?> <select type="text" name="<?php echo $post_option['id']; ?> " id="<?php echo $post_option['id']; ?> "> <?php foreach ($post_option['choices'] as $choice) { ?> <option value="<?php echo $choice['value']; ?> " <?php if ($curr_value == $choice['value']) { echo 'selected="selected"'; } ?> ><?php echo $choice['label']; ?> </option> <?php } ?> </select> <?php global $current_screen; $template = dslc_st_get_template_ID(get_the_ID()); if ($current_screen->action != 'add' && $object->post_type != 'dslc_templates') { echo '<a class="button" href="' . get_home_url() . '/?page_id=' . $template . '&dslc=active">' . __('Edit Template', 'live-composer-page-builder') . '</a>'; } ?> <?php } elseif ($post_option['type'] == 'checkbox') { ?> <?php $curr_value_array = maybe_unserialize($curr_value_no_esc); if (!is_array($curr_value_array)) { $curr_value_array = array(); } ?> <?php foreach ($post_option['choices'] as $key => $choice) { ?> <div class="dslca-post-option-field-choice"> <input type="checkbox" name="<?php echo $post_option['id']; ?> []" id="<?php echo $post_option['id']; ?> " value="<?php echo $choice['value']; ?> " <?php if (in_array($choice['value'], $curr_value_array)) { echo 'checked="checked"'; } ?> /> <?php echo $choice['label']; ?> <br> </div><!-- .dslca-post-option-field-choice --> <?php } ?> <?php } elseif ($post_option['type'] == 'radio') { ?> <?php foreach ($post_option['choices'] as $key => $choice) { ?> <div class="dslca-post-option-field-choice"> <input type="radio" name="<?php echo $post_option['id']; ?> " id="<?php echo $post_option['id']; ?> " value="<?php echo $choice['value']; ?> " <?php if ($choice['value'] == $curr_value) { echo 'checked="checked"'; } ?> /> <?php echo $choice['label']; ?> <br> </div><!-- .dslca-post-option-field-choice --> <?php } ?> <?php } elseif ($post_option['type'] == 'file') { ?> <span class="dslca-post-option-add-file-hook">Choose File</span><br> <?php if ($curr_value) { ?> <div class="dslca-post-options-images dslca-clearfix"> <div class="dslca-post-option-image"> <div class="dslca-post-option-image-inner"> <?php if (wp_attachment_is_image($curr_value)) { ?> <?php $image = wp_get_attachment_image_src($curr_value, 'full'); ?> <img src="<?php echo $image[0]; ?> " /> <?php } else { ?> <strong><?php echo basename(get_attached_file($curr_value)); ?> </strong> <?php } ?> </div><!-- .dslca-post-option-image-inner --> <span class="dslca-post-option-image-remove">x</span> </div><!-- .dslca-post-option-image --> </div><!-- .dslca-post-options-images --> <?php } else { ?> <div class="dslca-post-options-images dslca-clearfix"></div> <?php } ?> <input type="hidden" class="dslca-post-options-field-file" name="<?php echo $post_option['id']; ?> " id="<?php echo $post_option['id']; ?> " value="<?php echo $curr_value; ?> " /> <?php } elseif ($post_option['type'] == 'files') { ?> <span class="dslca-post-option-add-file-hook" data-multiple="true">Add Files</span><br> <?php if ($curr_value) { ?> <div class="dslca-post-options-images dslca-clearfix"> <?php $images = explode(' ', trim($curr_value)); foreach ($images as $image_ID) { $image = wp_get_attachment_image_src($image_ID, 'full'); ?> <div class="dslca-post-option-image" data-id="<?php echo $image_ID; ?> "> <div class="dslca-post-option-image-inner"> <img src="<?php echo $image[0]; ?> " /> <span class="dslca-post-option-image-remove">x</span> </div> </div> <?php } ?> </div><!-- .dslca-post-options-images --> <?php } else { ?> <div class="dslca-post-options-images dslca-clearfix"></div> <?php } ?> <input type="hidden" class="dslca-post-options-field-file" name="<?php echo $post_option['id']; ?> " id="<?php echo $post_option['id']; ?> " value="<?php echo $curr_value; ?> " /> <?php } elseif ($post_option['type'] == 'date') { ?> <input class="dslca-post-options-field-datepicker" type="text" name="<?php echo $post_option['id']; ?> " id="<?php echo $post_option['id']; ?> " value="<?php echo $curr_value; ?> " size="30" /> <?php } ?> </div><!-- .dslca-post-option-field --> </div><!-- .dslca-post-options --> <?php } ?> <input type="hidden" name="dslc_post_options[]" value="<?php echo $post_options_id; ?> " /> </div><!-- .dslca-post-options --> <?php }
function dslc_st_template_switch() { global $post; global $dslc_post_types; // If there's no post, stop execution if (!isset($post)) { return; } // If the post is not supporting templates or it's not a template itself, stop execution if (is_singular($dslc_post_types) || is_singular('dslc_templates')) { } else { return; } // If the currently shown page is the template CPT if ($post->post_type == 'dslc_templates') { // Get template base $template_base = get_post_meta($post->ID, 'dslc_template_base', true); // If custom base if ($template_base == 'custom') { // The template filename $templatefilename = 'dslc-single.php'; // If the template file is in the theme if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) { $return_template = TEMPLATEPATH . '/' . $templatefilename; // If not in the theme use the default one from the plugin } else { $return_template = DS_LIVE_COMPOSER_ABS . '/templates/dslc-single.php'; } // Redirect include $return_template; // Bye bye exit; } } // If the currently shown page is actually a post we should filter if (in_array($post->post_type, $dslc_post_types)) { // Get template ID $template_ID = dslc_st_get_template_ID($post->ID); // If the post has specific template, set it in variable if ($template_ID) { $template_base = get_post_meta($template_ID, 'dslc_template_base', true); // If the post does not have a specific template, just use regular base from theme } else { $template_base = 'theme'; } if ($template_base == 'custom') { // The template filename $templatefilename = 'dslc-single.php'; // If the template file is in the theme if (file_exists(TEMPLATEPATH . '/' . $templatefilename)) { $return_template = TEMPLATEPATH . '/' . $templatefilename; // If not in the theme use the default one from the plugin } else { $return_template = DS_LIVE_COMPOSER_ABS . '/templates/dslc-single.php'; } // Redirect include $return_template; // Bye bye exit; } } }
function dslc_post_add_row_action($actions, $post) { global $dslc_var_templates_pt; $post_status = $post->post_status; $post_type = $post->post_type; $dslc_admin_interface_on = apply_filters('dslc_admin_interface_on_listing', true); if (true === $dslc_admin_interface_on && $post_status != 'trash') { if (array_key_exists($post_type, $dslc_var_templates_pt)) { $template_id = dslc_st_get_template_ID($post->ID); $url = DSLC_EditorInterface::get_editor_link($template_id, $post->ID); $actions = array('edit-in-live-composer' => '<a href="' . $url . '">' . __('Edit Template', 'live-composer-page-builder') . '</a>') + $actions; } else { $url = DSLC_EditorInterface::get_editor_link($post->ID); $actions = array('edit-in-live-composer' => '<a href="' . $url . '">' . __('Edit in Live Composer', 'live-composer-page-builder') . '</a>') + $actions; } } return $actions; }