コード例 #1
0
function wpv_create_layout_content_template()
{
    if (!current_user_can('manage_options')) {
        $data = array('type' => 'capability', 'message' => __('You do not have permissions for that.', 'wpv-views'));
        wp_send_json_error($data);
    }
    if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'layout_wizard_nonce')) {
        $data = array('type' => 'nonce', 'message' => __('Your security credentials have expired. Please reload the page to get new ones.', 'wpv-views'));
        wp_send_json_error($data);
    }
    if (!isset($_POST["view_id"]) || !is_numeric($_POST["view_id"]) || intval($_POST['view_id']) < 1) {
        $data = array('type' => 'id', 'message' => __('Wrong or missing ID.', 'wpv-views'));
        wp_send_json_error($data);
    }
    $template = wpv_create_content_template('Loop item in ' . $_POST['view_name']);
    $view_id = $_POST['view_id'];
    if (isset($template['success'])) {
        update_post_meta($view_id, '_view_loop_template', $template['success']);
        update_post_meta($template['success'], '_view_loop_id', $view_id);
        $ct_post_id = $template['success'];
        $data = array('id' => $view_id, 'message' => __('Content Template for this Loop Output created', 'wpv-views'), 'template_id' => $ct_post_id, 'template_title' => $template['title']);
        $post = get_post($ct_post_id);
        $meta = get_post_meta($view_id, '_wpv_layout_settings', true);
        $reg_templates = array();
        if (isset($meta['included_ct_ids'])) {
            $reg_templates = explode(',', $meta['included_ct_ids']);
        }
        if (!in_array($ct_post_id, $reg_templates)) {
            array_unshift($reg_templates, $ct_post_id);
            $meta['included_ct_ids'] = implode(',', $reg_templates);
            update_post_meta($view_id, '_wpv_layout_settings', $meta);
            ob_start();
            wpv_list_view_ct_item($post, $ct_post_id, $view_id, true);
            $data['template_html'] = ob_get_clean();
        }
        do_action('wpv_action_wpv_save_item', $view_id);
        wp_send_json_success($data);
    } else {
        $data = array('type' => 'error', 'message' => __('Could not create a Content Template for this Loop Output. Please reload the page and try again.', 'wpv-views'));
        wp_send_json_error($data);
    }
}
コード例 #2
0
function add_view_layout_template($view_settings, $view_layout_settings, $view_id)
{
    global $views_edit_help;
    wp_nonce_field('wpv-ct-inline-edit', 'wpv-ct-inline-edit');
    $templates = array();
    $valid_templates = array();
    $first_time = get_post_meta($view_id, '_wpv_first_time_load', true);
    if (isset($view_layout_settings['included_ct_ids'])) {
        $templates = explode(',', $view_layout_settings['included_ct_ids']);
        $valid_templates = $templates;
    }
    $template_list = '';
    if (count($templates) > 0) {
        $attached_templates = count($templates);
        for ($i = 0; $i < $attached_templates; $i++) {
            if (is_numeric($templates[$i])) {
                $template_post = get_post($templates[$i]);
                if (is_object($template_post)) {
                    $template_list .= wpv_list_view_ct_item($template_post, $templates[$i], $view_id);
                } else {
                    unset($valid_templates[$i]);
                    // remove Templates that might have been deleted or are missing
                }
            } else {
                unset($valid_templates[$i]);
                // remove Templates that might have been deleted or are missing
            }
        }
        if (count($templates) != count($valid_templates)) {
            $view_layout_settings['included_ct_ids'] = implode(',', $valid_templates);
            update_post_meta($view_id, '_wpv_layout_settings', $view_layout_settings);
        }
    }
    ?>
        <script type="application/javascript">
            var wpv_view_ct_msg1 = '<?php 
    echo esc_js(__('Content Template was successfully assigned to view.', 'wpv-views'));
    ?>
';
            var wpv_view_ct_msg2 = '<?php 
    echo esc_js(__('This Content Template already assigned to this view.', 'wpv-views'));
    ?>
';
            var wpv_view_ct_msg3 = '<?php 
    echo esc_js(__('Content Template was successfully unassigned from view.', 'wpv-views'));
    ?>
';
            var wpv_view_ct_msg4 = '<?php 
    echo esc_js(__('Content Template was successfully updated.', 'wpv-views'));
    ?>
';
            var wpv_view_ct_msg5 = '<?php 
    echo esc_js(__('Views', 'wpv-views'));
    ?>
';
            var wpv_view_ct_msg6 = '<?php 
    echo esc_js(__('No Content Templates assigned to this view', 'wpv-views'));
    ?>
';
            var wpv_view_ct_msg7 = '<?php 
    echo esc_js(__('There are no Content Templates for this View. You can add a Content Template using the Content Template button in the Layout editor tool bar.', 'wpv-views'));
    ?>
';
            var wpv_view_ct_msg8 = '<?php 
    echo esc_js(__('A Content Template with that name already exists. Please use another name.', 'wpv-views'));
    ?>
';
        </script>
		<div id="attached-content-templates" class="wpv-settings-templates wpv-setting-container wpv-setting-container-horizontal wpv-settings-layout-markup"<?php 
    echo empty($template_list) ? ' style="display:none;"' : '';
    ?>
>
            <div class="wpv-settings-header">
				<h3><?php 
    _e('Templates for this View', 'wpv-views');
    ?>
					<i class="icon-question-sign js-display-tooltip" data-header="<?php 
    echo $views_edit_help['templates_for_view']['title'];
    ?>
" data-content="<?php 
    echo $views_edit_help['templates_for_view']['content'];
    ?>
"></i>
				</h3>
			</div>
			<?php 
    if ($first_time == 'on') {
        $data = wpv_get_view_ct_slider_introduction_data();
        wpv_toolset_help_box($data);
    }
    ?>

			<div class="js-wpv-content-template-view-list wpv-content-template-view-list wpv-setting">
			    <ul>
			        <?php 
    echo $template_list;
    ?>
                </ul>
                <div class="js-wpv-content-template-section-errors"></div>
			</div>
		</div>
<?php 
}
コード例 #3
0
function wpv_add_view_template_callback()
{
    if (!current_user_can('manage_options')) {
        die("Security check");
    }
    if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'wpv_inline_content_template') && !wp_verify_nonce($_POST["wpnonce"], 'wpv-ct-inline-edit')) {
        die("Security check");
    }
    if (!isset($_POST['view_id']) || !is_numeric($_POST["view_id"]) || intval($_POST['view_id']) < 1) {
        echo 'error';
        die;
    }
    $ct_post_id = 0;
    $view_id = sanitize_text_field($_POST['view_id']);
    if (isset($_POST['template_name'])) {
        // We need to create a new Content Template based on the POSTed template_name
        $template_name = sanitize_text_field($_POST['template_name']);
        $response = wpv_create_content_template($template_name, '', false, '');
        if (isset($response['error'])) {
            // Another Content Template with that title or name already exists
            echo 'error_name';
            die;
        } else {
            if (isset($response['success'])) {
                // Everything went well
                $ct_post_id = $response['success'];
            }
        }
    } else {
        if (isset($_POST['template_id'])) {
            $ct_post_id = sanitize_text_field($_POST['template_id']);
        }
    }
    $ct_post_object = get_post($ct_post_id);
    if (!is_object($ct_post_object)) {
        echo 'error';
        die;
    }
    $meta = get_post_meta($view_id, '_wpv_layout_settings', true);
    $reg_templates = array();
    if (isset($meta['included_ct_ids'])) {
        $reg_templates = explode(',', $meta['included_ct_ids']);
    }
    if (in_array($ct_post_id, $reg_templates)) {
        // The Content Template was already on the inline list
        echo 'wp_success';
    } else {
        // Add the Content Template to the inline list and save it
        $reg_templates[] = $ct_post_id;
        $meta['included_ct_ids'] = implode(',', $reg_templates);
        update_post_meta($view_id, '_wpv_layout_settings', $meta);
        do_action('wpv_action_wpv_save_item', $view_id);
        wpv_list_view_ct_item($ct_post_object, $ct_post_id, $view_id, true);
    }
    die;
}
コード例 #4
0
function wpv_add_view_template_callback()
{
    global $wpdb;
    //add new content template
    if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'wpv-ct-inline-edit')) {
        die("Undefined Nonce.");
    }
    if (isset($_POST['template_name'])) {
        $postid = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_title = '" . mysql_real_escape_string($_POST['template_name']) . "' AND post_type='view-template'");
        if (!empty($postid)) {
            echo 'error_name';
            die;
        }
        $new_template = array('post_title' => $_POST['template_name'], 'post_type' => 'view-template', 'post_content' => '', 'post_status' => 'publish', 'post_author' => 1);
        $ct_post_id = wp_insert_post($new_template);
        update_post_meta($ct_post_id, '_wpv_view_template_mode', 'raw_mode');
        update_post_meta($ct_post_id, '_wpv-content-template-decription', '');
    } else {
        $ct_post_id = $_POST['template_id'];
    }
    $post = get_post($ct_post_id);
    if (!is_object($post)) {
        echo 'error';
        die;
    }
    $meta = get_post_meta($_POST['view_id'], '_wpv_layout_settings', true);
    $templates = $exists = '';
    $reg_templates = array();
    if (isset($meta['included_ct_ids'])) {
        $reg_templates = explode(',', $meta['included_ct_ids']);
        if (in_array($ct_post_id, $reg_templates)) {
            $exists = 1;
        }
    }
    if ($exists == '') {
        $reg_templates[] = $ct_post_id;
        $templates = implode(',', $reg_templates);
        $meta['included_ct_ids'] = $templates;
        update_post_meta($_POST['view_id'], '_wpv_layout_settings', $meta);
        echo wpv_list_view_ct_item($post, $ct_post_id, $_POST['view_id']);
    } else {
        echo '1';
    }
    die;
}