/**
 * Displays a list of templates
 *
 * @since 1.0
 */
function dslc_display_templates()
{
    // Get all the templates
    $templates = dslc_get_templates();
    // Array to store different types of templates
    $templates_arr = array();
    // If there are active templates
    if ($templates) {
        // Go through all templates, popular array
        foreach ($templates as $template) {
            $template['section'] = strtolower(str_replace(' ', '_', $template['section']));
            $templates_arr[$template['section']][$template['id']] = $template;
        }
        // If there are templates
        if (!empty($templates_arr)) {
            // Go through each section
            foreach ($templates_arr as $template_section_id => $template_section_tpls) {
                // Go through each template of a section
                foreach ($templates_arr[$template_section_id] as $template) {
                    ?>
					<div class="dslca-template dslca-scroller-item dslca-origin dslca-template-origin-<?php 
                    echo $template_section_id;
                    ?>
" data-origin="<?php 
                    echo $template_section_id;
                    ?>
" data-id="<?php 
                    echo $template['id'];
                    ?>
">
						<span class="dslca-template-title"><?php 
                    echo $template['title'];
                    ?>
</span>
						<?php 
                    if ($template_section_id == 'user') {
                        ?>
							<span class="dslca-delete-template-hook" data-id="<?php 
                        echo $template['id'];
                        ?>
">
								<span class="dslca-icon dslc-icon-trash"></span>
							</span>
						<?php 
                    }
                    ?>
					</div><!-- .dslc-template -->
					<?php 
                }
            }
        } else {
            echo 'No Templates Found';
        }
    }
}
示例#2
0
/**
 * Displays a list of templates
 *
 * @since 1.0
 */
function dslc_display_templates()
{
    // Get all the templates
    $templates = dslc_get_templates();
    // Arrays to store different types of templates
    $original_templates = array();
    $plugin_templates = array();
    $theme_templates = array();
    $user_templates = array();
    // If there are active templates
    if ($templates) {
        // Go through all templates
        foreach ($templates as $template) {
            // Append template to the appropriate templates array
            if ($template['section'] == 'original') {
                $original_templates[$template['id']] = $template;
            } elseif ($template['section'] == 'plugin') {
                $plugin_templates[$template['id']] = $template;
            } elseif ($template['section'] == 'theme') {
                $theme_templates[$template['id']] = $template;
            } elseif ($template['section'] == 'user') {
                $user_templates[$template['id']] = $template;
            }
        }
        // User templates output
        if (!empty($user_templates)) {
            foreach ($user_templates as $template) {
                ?>

				<div class="dslca-template dslca-scroller-item dslca-origin dslca-template-origin-user" data-origin="user" data-id="<?php 
                echo $template['id'];
                ?>
" style="display: none;">
					<span class="dslca-template-title"><?php 
                echo $template['title'];
                ?>
</span>
					<span class="dslca-delete-template-hook" data-id="<?php 
                echo $template['id'];
                ?>
">
						<span class="dslca-icon dslc-icon-trash"></span>
					</span>
				</div><!-- .dslc-template -->

			<?php 
            }
        }
        // Original templates output
        if (!empty($original_templates)) {
            foreach ($original_templates as $template) {
                ?>

					<div class="dslca-template dslca-scroller-item dslca-origin dslca-template-origin-lc" data-origin="lc" data-id="<?php 
                echo $template['id'];
                ?>
">
						<span class="dslca-template-title"><?php 
                echo $template['title'];
                ?>
</span>
					</div><!-- .dslc-template -->

				<?php 
            }
        }
        // Plugin templates output
        if (!empty($plugin_templates)) {
            foreach ($plugin_templates as $template) {
                ?>

					<div class="dslca-template dslca-scroller-item dslca-origin dslca-template-origin-plugin" data-origin="plugin" data-id="<?php 
                echo $template['id'];
                ?>
" style="display: none;">
						<span class="dslca-template-title"><?php 
                echo $template['title'];
                ?>
</span>
					</div><!-- .dslc-template -->

				<?php 
            }
        }
        // Theme templates output
        if (!empty($theme_templates)) {
            foreach ($theme_templates as $template) {
                ?>

					<div class="dslca-template dslca-scroller-item dslca-origin dslca-template-origin-theme" data-origin="theme" data-id="<?php 
                echo $template['id'];
                ?>
" style="display: none;">
						<span class="dslca-template-title"><?php 
                echo $template['title'];
                ?>
</span>
					</div><!-- .dslc-template -->

				<?php 
            }
        }
    } else {
        echo 'No templates found.';
    }
}
/**
 * Displays a list of templates
 *
 * @since 1.0
 */
function dslc_display_templates()
{
    // Get all the templates. Original data.
    $templates = dslc_get_templates();
    // Modified array to store templates by section.
    $templates_arr = array();
    // If there are active templates?
    if ($templates) {
        // Go through all templates, populate array.
        foreach ($templates as $template) {
            $section_title = $template['section'];
            $template['section'] = strtolower(str_replace(' ', '_', $template['section']));
            $templates_arr[$template['section']][$template['id']] = $template;
            $templates_arr[$template['section']][$template['id']]['section_title'] = $section_title;
        }
        // If there are templates?
        if (!empty($templates_arr)) {
            // Go through each section.
            foreach ($templates_arr as $template_section_id => $template_section_tpls) {
                // Go through each template in a section.
                foreach ($template_section_tpls as $template) {
                    ?>

					<a href="#" class="dslca-template dslca-scroller-item dslca-origin dslca-template-origin-<?php 
                    echo esc_attr($template_section_id);
                    ?>
" data-origin="<?php 
                    echo esc_attr($template['section_title']);
                    ?>
" data-id="<?php 
                    echo esc_attr($template['id']);
                    ?>
">
						<span class="dslca-template-title"><?php 
                    echo esc_html($template['title']);
                    ?>
</span>
						<?php 
                    if ('user' === $template_section_id) {
                        ?>
							<span class="dslca-delete-template-hook" data-id="<?php 
                        echo esc_attr($template['id']);
                        ?>
">
								<span class="dslca-icon dslc-icon-trash"></span>
							</span>
						<?php 
                    }
                    ?>
					</a><!-- .dslc-template -->

					<?php 
                }
            }
        } else {
            echo 'No Templates Found';
        }
    }
}
示例#4
0
/**
 * Load a template
 *
 * @since 1.0
 */
function dslc_ajax_load_template($atts)
{
    // Allowed to do this?
    if (is_user_logged_in() && current_user_can(DS_LIVE_COMPOSER_CAPABILITY)) {
        // The array that holds active templates.
        $templates = dslc_get_templates();
        // The array we'll pass back to the AJAX call.
        $response = array();
        // The ID of the template to load.
        $template_id = $_POST['dslc_template_id'];
        // The code of the template to load.
        $template_code = $templates[$template_id]['code'];
        // Apply for new ID.
        $template_code = str_replace('[dslc_module ', '[dslc_module give_new_id="true" ', $template_code);
        $template_code = str_replace('[dslc_module]', '[dslc_module give_new_id="true"]', $template_code);
        // Get the front-end output.
        $response['output'] = do_shortcode($template_code);
        // Encode response.
        $response_json = wp_json_encode($response);
        // Send the response.
        header('Content-Type: application/json');
        echo $response_json;
        // Cheers.
        exit;
    }
}