コード例 #1
0
ファイル: ajax.php プロジェクト: javed2015/WindowsDefender
/**
 * Inserts one or more slides into a slider.
 *
 * @since 1.0.0
 */
function soliloquy_lite_ajax_insert_slides()
{
    // Run a security check first.
    check_ajax_referer('soliloquy-insert-images', 'nonce');
    // Prepare variables.
    $images = !empty($_POST['images']) ? stripslashes_deep((array) $_POST['images']) : array();
    $videos = !empty($_POST['videos']) ? stripslashes_deep((array) $_POST['videos']) : array();
    $html = !empty($_POST['html']) ? stripslashes_deep((array) $_POST['html']) : array();
    $post_id = absint($_POST['post_id']);
    // Grab and update any slider data if necessary.
    $in_slider = get_post_meta($post_id, '_sol_in_slider', true);
    if (empty($in_slider)) {
        $in_slider = array();
    }
    // Set data and order of image in slider.
    $slider_data = get_post_meta($post_id, '_sol_slider_data', true);
    if (empty($slider_data)) {
        $slider_data = array();
    }
    // If no slider ID has been set, set it now.
    if (empty($slider_data['id'])) {
        $slider_data['id'] = $post_id;
    }
    // Loop through the images and add them to the slider.
    foreach ((array) $images as $i => $id) {
        // Update the attachment image post meta first.
        $has_slider = get_post_meta($id, '_sol_has_slider', true);
        if (empty($has_slider)) {
            $has_slider = array();
        }
        $has_slider[] = $post_id;
        update_post_meta($id, '_sol_has_slider', $has_slider);
        // Now add the image to the slider for this particular post.
        $in_slider[] = $id;
        $slider_data = soliloquy_ajax_prepare_slider_data($slider_data, $id);
    }
    // Loop through the videos and add them to the slider.
    foreach ((array) $videos as $i => $data) {
        // Pass over if the main items necessary for the video are not set.
        if (!isset($data['title']) || !isset($data['url']) || !isset($data['thumb'])) {
            continue;
        }
        // Generate a custom ID for the video.
        $id = sanitize_title_with_dashes($slider_data['id'] . '-' . $data['title']);
        // Now add the image to the slider for this particular post.
        $in_slider[] = $id;
        $slider_data = soliloquy_lite_ajax_prepare_slider_data($slider_data, $id, 'video', $data);
    }
    // Loop through the videos and add them to the slider.
    foreach ((array) $html as $i => $data) {
        // Pass over if the main items necessary for the video are not set.
        if (empty($data['title']) || empty($data['code'])) {
            continue;
        }
        // Generate a custom ID for the video.
        $id = sanitize_title_with_dashes($slider_data['id'] . '-' . $data['title']);
        // Now add the image to the slider for this particular post.
        $in_slider[] = $id;
        $slider_data = soliloquy_lite_ajax_prepare_slider_data($slider_data, $id, 'html', $data);
    }
    // Update the slider data.
    update_post_meta($post_id, '_sol_in_slider', $in_slider);
    update_post_meta($post_id, '_sol_slider_data', $slider_data);
    // Run hook before finishing.
    do_action('soliloquy_ajax_insert_slides', $images, $videos, $html, $post_id);
    // Flush the slider cache.
    Soliloquy_Common_Lite::get_instance()->flush_slider_caches($post_id);
    echo json_encode(true);
    die;
}
コード例 #2
0
ファイル: ajax.php プロジェクト: duongnguyen92/tvd12v2
/**
 * Loads an image into a slider.
 *
 * @since 1.0.0
 */
function soliloquy_lite_ajax_load_image()
{
    // Run a security check first.
    check_ajax_referer('soliloquy-load-image', 'nonce');
    // Prepare variables.
    $id = absint($_POST['id']);
    $post_id = absint($_POST['post_id']);
    // Set post meta to show that this image is attached to one or more Soliloquy sliders.
    $has_slider = get_post_meta($id, '_sol_has_slider', true);
    if (empty($has_slider)) {
        $has_slider = array();
    }
    $has_slider[] = $post_id;
    update_post_meta($id, '_sol_has_slider', $has_slider);
    // Set post meta to show that this image is attached to a slider on this page.
    $in_slider = get_post_meta($post_id, '_sol_in_slider', true);
    if (empty($in_slider)) {
        $in_slider = array();
    }
    $in_slider[] = $id;
    update_post_meta($post_id, '_sol_in_slider', $in_slider);
    // Set data and order of image in slider.
    $slider_data = get_post_meta($post_id, '_sol_slider_data', true);
    if (empty($slider_data)) {
        $slider_data = array();
    }
    // If no slider ID has been set, set it now.
    if (empty($slider_data['id'])) {
        $slider_data['id'] = $post_id;
    }
    // Set data and update the meta information.
    $slider_data = soliloquy_lite_ajax_prepare_slider_data($slider_data, $id);
    update_post_meta($post_id, '_sol_slider_data', $slider_data);
    // Run hook before building out the item.
    do_action('soliloquy_ajax_load_image', $id, $post_id);
    // Build out the individual HTML output for the slider image that has just been uploaded.
    $html = Soliloquy_Metaboxes_Lite::get_instance()->get_slider_item($id, $slider_data['slider'][$id], 'image', $post_id);
    // Flush the slider cache.
    Soliloquy_Common_Lite::get_instance()->flush_slider_caches($post_id);
    echo json_encode($html);
    die;
}