Example #1
0
function handle_get_diapo_video_by_id()
{
    $id = $_REQUEST['id'];
    //trace($_REQUEST);
    //print_r($gallery_items);
    $html = '<div class="diapo">';
    foreach ($_REQUEST['video'] as $video) {
        $css = 'style="background-image:url(' . $video['video_thumbnail'] . ')"';
        $html .= '<div class="diapo_item diapo_item_video" data-video="' . $video['video_url'] . '">';
        $html .= '<div class="diapo_item_image" ' . $css . '></div>';
        $html .= '<div class="diapo_play ">';
        $html .= '<div class="diapo_play_fond"></div>';
        $html .= '<div class="stripes">';
        $html .= '<div class="stripe0 anime"></div>';
        $html .= '<div class="stripe1 anime"></div>';
        $html .= '<div class="stripe2 anime"></div>';
        $html .= '<div class="stripe3 anime"></div>';
        $html .= '<div class="stripe4 anime"></div>';
        $html .= '<div class="stripe5 anime"></div>';
        $html .= '<div class="stripe6 anime"></div>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
    }
    global $wp_photo_gallery;
    foreach ($_REQUEST['diaporama'] as $diaporama) {
        $gallery = new WPPGPhotoGallery($diaporama["diaporama_id"]);
        $gallery_items = WPPGPhotoGallery::getGalleryItems($diaporama["diaporama_id"]);
        foreach ($gallery_items as $item) {
            $css = 'style="background-image:url(' . $item["image_url"] . ')"';
            $html .= '<div class="diapo_item">';
            $html .= '<div class="diapo_item_image" ' . $css . '></div>';
            $desc = $item["description"];
            if ($desc == "") {
                $desc = "desciption de l'image";
            }
            $desc = str_replace("_", " ", $item["alt_text"]);
            $html .= '<div class="diapo_description">' . $desc . '</div>';
            $html .= '</div>';
        }
    }
    $html .= '</div>';
    echo $html;
    die;
}
 static function apply_gallery_pagination($gallery, $gallery_items)
 {
     $thumbs_per_page = $gallery->thumbs_per_page != NULL ? $gallery->thumbs_per_page : '20';
     $page_query_param = 'g_page';
     $page = isset($_GET[$page_query_param]) ? $_GET[$page_query_param] : '';
     //Get current page from query var
     global $wp;
     $current_url = add_query_arg($wp->query_string, '', home_url($wp->request));
     //Get current url
     $pagination = WPPGPhotoGallery::pagination_array($gallery_items, $page, $page_query_param, $current_url, $thumbs_per_page);
     return $pagination;
 }
    function render_gallery($gallery_id)
    {
        global $wp_photo_gallery;
        $pagination = false;
        //Initialize
        $gallery = new WPPGPhotoGallery($gallery_id);
        $display_photo_details_page = $gallery->display_image_on_page;
        $gallery_items = WPPGPhotoGallery::getGalleryItems($gallery_id);
        WP_Photo_Gallery_Utility::start_buffer();
        ?>
        <link type="text/css" rel="stylesheet" href="<?php 
        echo WP_PHOTO_URL . '/classes/gallery-templates/css/wppg-photo-gallery-template-3.css?ver=' . WP_PHOTO_VERSION;
        ?>
" />
        <div id="wppg-gallery-template-3">
<?php 
        //Add Pagination if applicable
        if ($gallery->enable_pagination == 1) {
            echo '<link type="text/css" rel="stylesheet" href="' . WP_PHOTO_URL . '/classes/gallery-templates/css/wppg-pagination.css?ver=' . WP_PHOTO_VERSION . '" />';
            //Load the CSS file for this view
            $pagination = WPPGPhotoGallery::apply_gallery_pagination($gallery, $gallery_items);
            if ($pagination !== false) {
                $gallery_items = $pagination['array'];
            }
        }
        foreach ($gallery_items as $p) {
            $image_id = $p['id'];
            //Now let's create a PhotoProduct object for this item
            $wppgPhotoObj = new WPPGPhotoGalleryItem();
            $wppgPhotoObj->create_photo_item_by_id($image_id);
            $water_mark_url = '';
            $file_name = $wppgPhotoObj->image_file_name;
            $upload_dir = wp_upload_dir();
            $path = $wppgPhotoObj->thumb_url;
            $image_file_url = $wppgPhotoObj->image_file_url;
            if ($display_photo_details_page == 1) {
                $details_page_id = $wp_photo_gallery->configs->get_value('wppg_photo_details_page_id');
                if (empty($details_page_id)) {
                    $photo_details_page = get_page_by_path('wppg_photogallery/wppg_photo_details');
                    if ($photo_details_page == NULL) {
                        $wp_photo_gallery->debug_logger->log_debug('Gallery template 3: get_page_by_path returned NULL!', 4);
                    }
                    $preview_page = $photo_details_page->guid;
                } else {
                    $preview_page = get_permalink($details_page_id);
                }
                //Check if this gallery is password protected
                if (!empty($gallery->password)) {
                    //This gallery is password protected - so let's add an encoded string
                    $encoded_str = base64_encode(WPPS_PHOTO_VIEW_AUTH_STRING);
                    $query_params = array('gallery_id' => $gallery_id, 'image_id' => $image_id, 'auth_key' => $encoded_str);
                } else {
                    $query_params = array('gallery_id' => $gallery_id, 'image_id' => $image_id);
                }
                $preview_url = add_query_arg($query_params, $preview_page);
                $button_html = '<span class="wpsg-t3-buy-link"><a href="' . $preview_url . '">' . __("View", "spgallery") . '</a></span>';
            } else {
                $source_dir = $upload_dir['basedir'] . '/' . WPPG_UPLOAD_SUB_DIRNAME . '/' . $gallery_id . '/';
                if ($gallery->watermark != NULL) {
                    //Get the gallery settings values for watermark placement, width and font size
                    $watermark_placement = $gallery->watermark_placement;
                    if ($watermark_placement === NULL) {
                        $watermark_placement = '0';
                    }
                    $desired_width = $gallery->watermark_width;
                    if ($desired_width == 0 || empty($desired_width)) {
                        $desired_width = '600';
                    }
                    $wm_font_size = $gallery->watermark_font_size;
                    if ($wm_font_size == 0 || empty($wm_font_size)) {
                        $wm_font_size = '14';
                    }
                    $watermark_opacity = $gallery->watermark_opacity;
                    if ($watermark_opacity === NULL) {
                        $watermark_opacity = '35';
                    }
                    //If the image is a portrait then instead of setting max width, we want to set max height otherwise the preview comes out too big
                    if ($wppgPhotoObj->image_height > $wppgPhotoObj->image_width) {
                        $args = array('watermark_height' => $desired_width, 'watermark_font_size' => $wm_font_size, 'watermark_placement' => $watermark_placement, 'watermark_opacity' => $watermark_opacity);
                    } else {
                        $args = array('watermark_width' => $desired_width, 'watermark_font_size' => $wm_font_size, 'watermark_placement' => $watermark_placement, 'watermark_opacity' => $watermark_opacity);
                    }
                    $args = array('watermark_width' => $desired_width, 'watermark_font_size' => $wm_font_size, 'watermark_placement' => $watermark_placement);
                    WPPGPhotoGallery::createWatermarkImage($source_dir, $source_dir, $file_name, false, $gallery->watermark, $args);
                    $water_mark_url = $upload_dir['baseurl'] . '/' . WPPG_UPLOAD_SUB_DIRNAME . '/' . $gallery_id . '/watermark_' . $file_name;
                    $preview_url = $water_mark_url;
                } else {
                    //Don't create a watermark URL if the watermark field was empty in the gallery settings. Display original image instead
                    $preview_url = $wppgPhotoObj->image_file_url;
                }
                $button_html = '<input type="button" id="viewPhotoDetails_' . $wppgPhotoObj->id . '" class="wppg_popup wppg-gallery-button wpsg-t3-buy-input" value="' . __("View", "spgallery") . '">';
            }
            ?>
	<div class="wpsg-t3-item">
            <a class="wppg_popup" title="<?php 
            echo $wppgPhotoObj->name;
            ?>
" href="<?php 
            echo $preview_url;
            ?>
">
                <img alt="<?php 
            echo $wppgPhotoObj->alt_text;
            ?>
" src="<?php 
            echo $image_file_url;
            ?>
">
            </a>
	</div><!-- end of .wpsg-t3-item -->
    <?php 
        }
        //End foreach loop
        ?>
        <div class="clear"></div>
    <?php 
        //Insert pagination nav bar at bottom
        if ($gallery->enable_pagination == 1 && $pagination !== false) {
            echo '<div class="wppg_photo_gallery_pagination">' . $pagination['panel'] . '</div>';
        }
        ?>
            
        </div> <!--end wppg-gallery-display div --> 
       
     
<!-- Masonry stuff -->
<?php 
        //wp_enqueue_script('masonry');
        echo '<script type="text/javascript" src="' . WP_PHOTO_URL . '/js/masonry.pkgd.min.js?ver=' . WP_PHOTO_VERSION . '"></script>';
        ?>
<script type="text/javascript">
window.onload = function(){ 
var container = document.querySelector('#wppg-gallery-template-3');
var msnry = new Masonry( container, {
  // options
  columnWidth: '.wpsg-t3-item',
  itemSelector: '.wpsg-t3-item'
});
}
</script>
<!-- End Masonry stuff -->


<?php 
        if ($display_photo_details_page == 0) {
            //Load lightbox css file
            wp_enqueue_style('jquery-lightbox-css', WP_PHOTO_URL . '/js/jquery-lightbox/css/jquery.lightbox-0.5.css');
            //Load lightbox js files
            wp_enqueue_script('wppg-lb-script-js', WP_PHOTO_URL . '/js/simple_photo_gallery_js.js', array('jquery'));
            wp_localize_script('wppg-lb-script-js', 'WPPG_LIGHTBOX_JS', array('imgLoading' => WP_PHOTO_URL . '/js/jquery-lightbox/images/lightbox-ico-loading.gif', 'imgbtnPrev' => WP_PHOTO_URL . '/js/jquery-lightbox/images/lightbox-btn-prev.gif', 'imgbtnNext' => WP_PHOTO_URL . '/js/jquery-lightbox/images/lightbox-btn-next.gif', 'imgBlank' => WP_PHOTO_URL . '/js/jquery-lightbox/images/lightbox-blank.gif', 'imgbtnClose' => WP_PHOTO_URL . '/js/jquery-lightbox/images/lightbox-btn-close.gif'));
        }
        $output = WP_Photo_Gallery_Utility::end_buffer_and_collect();
        return $output;
    }
    function render_tab2()
    {
        global $wp_photo_gallery;
        $gallery_id = '';
        if (isset($_GET['wppg_gallery_id'])) {
            $gallery_id = strip_tags($_GET['wppg_gallery_id']);
        } elseif (!isset($_POST['wppg_save_gallery'])) {
            //check if there is a hanging temp upload directory and if so delete it
            $upload_dir = wp_upload_dir();
            $tmp_dir = $upload_dir['basedir'] . '/' . WPPG_UPLOAD_SUB_DIRNAME . '/' . WPPG_UPLOAD_TEMP_DIRNAME;
            if (file_exists($tmp_dir)) {
                WP_Photo_Gallery_Utility::deleteFolder($tmp_dir);
            }
            //Delete attachment posts and related post meta data of photos which were in the tmp upload dir
            WPPGPhotoGallery::deleteUnsavedTmpImages();
        }
        //Initialize some variables
        $new_gallery_id = '';
        $existing_gallery_id = '';
        $g = new WPPGPhotoGallery($gallery_id);
        $gallery_name = $g->name != NULL ? $g->name : '';
        $gallery_watermark = $g->watermark != NULL ? $g->watermark : '';
        $gallery_watermark_opacity = $g->watermark_opacity != NULL ? $g->watermark_opacity : '35';
        $gallery_watermark_placement = $g->watermark_placement != NULL ? $g->watermark_placement : '0';
        $gallery_watermark_width = $g->watermark_width != NULL ? $g->watermark_width : '';
        $gallery_watermark_font_size = $g->watermark_font_size != NULL ? $g->watermark_font_size : '';
        $gallery_sort_order = $g->sort_order != NULL ? $g->sort_order : '0';
        $gallery_thumb_template = $g->gallery_thumb_template != NULL ? $g->gallery_thumb_template : '0';
        $gallery_photo_preview = $g->display_image_on_page != NULL ? $g->display_image_on_page : '1';
        $gallery_category = $g->category != NULL ? $g->category : '';
        $gallery_pagination = $g->enable_pagination != NULL ? $g->enable_pagination : '';
        $gallery_thumbs_per_page = $g->thumbs_per_page != NULL ? $g->thumbs_per_page : '';
        $gallery_page_id = $g->page_id != NULL ? $g->page_id : '0';
        include_once 'wppg-list-gallery-images.php';
        //For rendering the gallery images table
        $gallery_image_list = new WPPG_List_Gallery_Images();
        $gallery_page_url = '';
        $preview_gallery_page_msg = '';
        if ($gallery_page_id != 0) {
            $gallery_page_url = get_permalink($gallery_page_id);
            $preview_gallery_page_msg .= '<div class="wppg_blue_box wppg_one_third_width">';
            $preview_link = '<a href="' . $gallery_page_url . '" target="_blank">' . __('click here', 'spgallery') . '</a>';
            $preview_gallery_page_msg .= '<p>' . sprintf(__('To preview your gallery page on the front end %s', 'spgallery'), $preview_link) . '</p>';
            $preview_gallery_page_msg .= '</div>';
        }
        if (isset($_REQUEST['action'])) {
            if ($_REQUEST['action'] == 'gallery_saved') {
                $this->show_msg_updated(__('The Gallery was saved successfully.', 'spgallery'));
            }
            if ($_REQUEST['action'] == 'remove_from_gallery') {
                //"Remove From Gallery" link was clicked for a row in the list table
                $gallery_image_list->remove_image_from_gallery(strip_tags($_REQUEST['image_id']));
            }
        }
        if (isset($_GET['page']) && isset($_GET['task']) && isset($_GET['deleted'])) {
            if ($_GET['page'] == WP_PHOTO_GALLERY_MENU_SLUG && $_GET['deleted'] == 1) {
                echo '<div id="message" class="updated fade"><p><strong>';
                _e('You have successfully deleted the selected gallery image(s) permanently!', 'spgallery');
                echo '</strong></p></div>';
            }
        }
        if (isset($_POST['wppg_save_gallery'])) {
            $errors = '';
            $num_gallery_images = '';
            $nonce = $_REQUEST['_wpnonce'];
            if (!wp_verify_nonce($nonce, 'wppg-save-gallery')) {
                $wp_photo_gallery->debug_logger->log_debug("Nonce check failed on gallery settings save!", 4);
                die("Nonce check failed on gallery settings save!");
            }
            if (empty($_POST['wppg_gallery_name'])) {
                $errors .= '<p>' . __('Please enter a gallery name', 'spgallery') . '</p>';
                //TODO
            } else {
                $gallery_name = stripslashes(trim($_POST['wppg_gallery_name']));
            }
            //If images have been added to the gallery
            if (isset($_POST['wppg_img_count'])) {
                if (ctype_digit($_POST['wppg_img_count'])) {
                    $num_gallery_images = $_POST['wppg_img_count'];
                    //get the number of gallery images from the hidden field
                }
            }
            if (!empty($_POST['wppg_gallery_watermark'])) {
                $gallery_watermark = wp_strip_all_tags(trim($_POST['wppg_gallery_watermark']));
            } else {
                $gallery_watermark = '';
            }
            $gallery_watermark_width = sanitize_text_field($_POST['wppg_watermark_width']);
            if (!is_numeric($gallery_watermark_width)) {
                $errors .= '<p>' . __('You entered a non numeric value for the Watermark Photo Width field. It has been set to the default value.', 'spgallery') . '</p>';
                $gallery_watermark_width = '600';
                //Set it to the default value for this field
            }
            $gallery_watermark_font_size = sanitize_text_field($_POST['wppg_watermark_font_size']);
            if (!is_numeric($gallery_watermark_font_size)) {
                $errors .= '<p>' . __('You entered a non numeric value for the Watermark Font Size field. It has been set to the default value.', 'spgallery') . '</p>';
                $gallery_watermark_font_size = '35';
                //Set it to the default value for this field
            }
            $gallery_watermark_placement = $_POST['wppg_watermark_placement'];
            $gallery_watermark_opacity = sanitize_text_field($_POST['wppg_watermark_opacity']);
            if (!is_numeric($gallery_watermark_opacity)) {
                $errors .= '<p>' . __('You entered a non numeric value for the Watermark Opacity field. It has been set to the default value.', 'spgallery') . '</p>';
                $gallery_watermark_opacity = '35';
                //Set it to the default value for this field
            } else {
                if ($gallery_watermark_opacity > 100 || $gallery_watermark_opacity < 0) {
                    $errors .= '<p>' . __('The Watermark Opacity value must be between and including 0 and 100. It has been set to the default value.', 'spgallery') . '</p>';
                    $gallery_watermark_opacity = '35';
                    //Set it to the default value for this field
                }
            }
            //Check if watermark text has changed - if so delete existing WM image
            if ($g->watermark != $gallery_watermark || $g->watermark_opacity != $gallery_watermark_opacity || $g->watermark_width != $gallery_watermark_width || $g->watermark_font_size != $gallery_watermark_font_size || $g->watermark_placement != $gallery_watermark_placement) {
                WPPGPhotoGallery::deleteWatermarkImages($gallery_id);
            }
            $gallery_sort_order = $_POST['wppg_gallery_sort_order'];
            $gallery_thumb_template = $_POST['wppg_gallery_thumb_template'];
            $gallery_photo_preview = isset($_POST['wppg_gallery_photo_preview']) ? '1' : '0';
            $gallery_pagination = isset($_POST['wppg_gallery_pagination']) ? '1' : '0';
            $gallery_thumbs_per_page = sanitize_text_field($_POST['wppg_thumbs_per_page']);
            if (strlen($errors) > 0) {
                $this->show_msg_error($errors);
            } else {
                if ($gallery_id != NULL) {
                    //Update existing gallery
                    $existing_gallery_id = $gallery_id;
                    $gallery_data = array('id' => $gallery_id, 'name' => $gallery_name, 'category' => $gallery_category, 'watermark' => $gallery_watermark, 'watermark_opacity' => $gallery_watermark_opacity, 'watermark_placement' => $gallery_watermark_placement, 'watermark_width' => $gallery_watermark_width, 'watermark_font_size' => $gallery_watermark_font_size, 'sort_order' => $gallery_sort_order, 'gallery_thumb_template' => $gallery_thumb_template, 'display_image_on_page' => $gallery_photo_preview, 'enable_pagination' => $gallery_pagination, 'thumbs_per_page' => $gallery_thumbs_per_page, 'updated' => date('Y-m-d H:i:s'));
                    $g->create_or_update_gallery($gallery_data);
                } else {
                    //Create new gallery
                    $gallery_data = array('name' => $gallery_name, 'category' => $gallery_category, 'watermark' => $gallery_watermark, 'watermark_opacity' => $gallery_watermark_opacity, 'watermark_placement' => $gallery_watermark_placement, 'watermark_width' => $gallery_watermark_width, 'watermark_font_size' => $gallery_watermark_font_size, 'sort_order' => $gallery_sort_order, 'gallery_thumb_template' => $gallery_thumb_template, 'created' => date('Y-m-d H:i:s'), 'display_image_on_page' => $gallery_photo_preview, 'enable_pagination' => $gallery_pagination, 'thumbs_per_page' => $gallery_thumbs_per_page, 'updated' => date('Y-m-d H:i:s'));
                    $new_gallery_id = $g->create_or_update_gallery($gallery_data);
                    $gallery_id = $new_gallery_id;
                    if ($gallery_id === false) {
                        $gallery_id = NULL;
                        $errors .= '<p>' . __('Gallery DB insert or update failed!', 'spgallery') . '</p>';
                    }
                    WPPGPhotoGallery::create_gallery_page($gallery_id);
                    //Create gallery page with shortcode
                }
                //Now let's process the selected gallery photos
                if (isset($_POST['wppg_img_count']) && $num_gallery_images != NULL) {
                    $existing_gallery = empty($existing_gallery_id) ? false : true;
                    $g->process_gallery_images($num_gallery_images, $existing_gallery, $gallery_id);
                }
                //Now let's rename the temp dir if applicable
                if (!isset($_GET['wppg_gallery_id']) && $gallery_id != NULL) {
                    $upload_dir = wp_upload_dir();
                    if (isset($_POST['wppg_img_count'])) {
                        //case where photos were uploaded
                        $old_dir = $upload_dir['basedir'] . '/' . WPPG_UPLOAD_SUB_DIRNAME . '/' . WPPG_UPLOAD_TEMP_DIRNAME;
                        $new_dir = $upload_dir['basedir'] . '/' . WPPG_UPLOAD_SUB_DIRNAME . '/' . $gallery_id;
                        if (file_exists($old_dir)) {
                            //Let's first create an empty index.html file
                            $index_file = $old_dir . '/index.html';
                            $handle = fopen($index_file, 'w') or die('Cannot open file:  ' . $index_file);
                            fclose($handle);
                            if (!rename($old_dir, $new_dir)) {
                                $wp_photo_gallery->debug_logger->log_debug("Upload directory rename failed upon creation of new gallery with ID: " . $gallery_id, 4);
                            }
                        } elseif (file_exists($new_dir)) {
                            $index_file = $new_dir . '/index.html';
                            $handle = fopen($index_file, 'w') or die('Cannot open file:  ' . $index_file);
                            fclose($handle);
                        }
                        //We must also modify any meta_data for each image which had reference to the temp dir
                        WPPGPhotoGallery::replace_image_meta_info_temp_dir($gallery_id);
                    } else {
                        //Handles case where a new gallery was created but no images uploaded - so simply create the gallery directory
                        $gallery_dir = $upload_dir['basedir'] . '/' . WPPG_UPLOAD_SUB_DIRNAME . '/' . $gallery_id;
                        if (!is_dir($gallery_dir)) {
                            $mkdir_res = mkdir($gallery_dir, 0755, true);
                            if ($mkdir_res === false) {
                                $wp_photo_gallery->debug_logger->log_debug("ERROR: Could not create gallery upload directory for gallery ID " . $gallery_id, 4);
                            } else {
                                //Let's also create an empty index.html file in this folder
                                $index_file = $gallery_dir . '/index.html';
                                $handle = fopen($index_file, 'w');
                                //or die('Cannot open file:  '.$index_file);
                                fclose($handle);
                            }
                        }
                    }
                }
                if (strlen($errors) > 0) {
                    //echo '<div id="message" class="error">' . $errors . '</div>';
                    $this->show_msg_error($errors);
                } else {
                    $tab = isset($_GET['tab']) ? strip_tags($_GET['tab']) : '';
                    $url = "admin.php?page=wppg_gallery&tab=" . $tab . "&wppg_gallery_id=" . $gallery_id . "&action=gallery_saved";
                    WP_Photo_Gallery_Utility::redirect_to_url($url);
                }
            }
        }
        ?>
        <h2><?php 
        _e('Create/Edit Gallery', 'spgallery');
        ?>
</h2>
        <?php 
        echo $preview_gallery_page_msg;
        ?>

        <div class="postbox wppg-gallery-settings-section">
        <h3><label for="title"><?php 
        _e('Gallery Settings', 'spgallery');
        ?>
</label></h3>
        <div class="inside">
        <form action="" method="POST">
        <?php 
        wp_nonce_field('wppg-save-gallery');
        ?>
        <table class="form-table">
            <tr>
                <th scope="row"><?php 
        _e('Gallery Name', 'spgallery');
        ?>
:</th>
                <td><input type="text" size="25" name="wppg_gallery_name" value="<?php 
        echo $gallery_name;
        ?>
" />
                <span class="description"><?php 
        _e('This is the name of your gallery', 'spgallery');
        ?>
</span>
                </td> 
            </tr>
            <tr>
                <th scope="row"><?php 
        _e('Gallery Thumbnail Template', 'spgallery');
        ?>
:</th>
                <td>
                    <select id="wppg_gallery_thumb_template" name="wppg_gallery_thumb_template">
                        <option value="0" <?php 
        selected($gallery_thumb_template, '0');
        ?>
><?php 
        _e('Template 1', 'spgallery');
        ?>
</option>
                        <option value="1" <?php 
        selected($gallery_thumb_template, '1');
        ?>
><?php 
        _e('Template 2', 'spgallery');
        ?>
</option>
                        <option value="2" <?php 
        selected($gallery_thumb_template, '2');
        ?>
><?php 
        _e('Template 3 (Masonry)', 'spgallery');
        ?>
</option>
                    </select>
                <span class="description"><?php 
        _e('Choose the template style for displaying your gallery thumbnails', 'spgallery');
        ?>
</span>
                <span class="wppg_more_info_anchor"><span class="wppg_more_info_toggle_char">+</span><span class="wppg_more_info_toggle_text"><?php 
        _e('More Info', 'spgallery');
        ?>
</span></span>
                <div class="wppg_more_info_body">
                        <?php 
        echo '<p class="description">' . __('Template 1: Will display your gallery thumbnails in a grid with thumbnail size 150x150.', 'spgallery') . '</p>';
        echo '<p class="description">' . __('Template 2: Will display your gallery thumbnails using true landscape/portrait proportions.', 'spgallery') . '</p>';
        ?>
                </div>

                </td>
            </tr>
            <tr>
                <th scope="row"><?php 
        _e('Sort Order Of Gallery Images', 'spgallery');
        ?>
:</th>
                <td>
                    <select id="wppg_gallery_sort_order" name="wppg_gallery_sort_order">
                        <option value="0" <?php 
        selected($gallery_sort_order, '0');
        ?>
><?php 
        _e('By ID Ascending', 'spgallery');
        ?>
</option>
                        <option value="1" <?php 
        selected($gallery_sort_order, '1');
        ?>
><?php 
        _e('By ID Descending', 'spgallery');
        ?>
</option>
                        <option value="2" <?php 
        selected($gallery_sort_order, '2');
        ?>
><?php 
        _e('By Date Ascending', 'spgallery');
        ?>
</option>
                        <option value="3" <?php 
        selected($gallery_sort_order, '3');
        ?>
><?php 
        _e('By Date Descending', 'spgallery');
        ?>
</option>
                    </select>
                <span class="description"><?php 
        _e('Choose the sort order of your gallery images when they are displayed on the front end of your site', 'spgallery');
        ?>
</span>
                </td>
            </tr>
            <tr>
                <th scope="row"><?php 
        _e('Preview Photo via Page', 'spgallery');
        ?>
:</th>
                <td><input name="wppg_gallery_photo_preview" type="checkbox" <?php 
        echo $gallery_photo_preview == '1' ? 'checked="checked"' : '';
        ?>
/>
                <span class="description"><?php 
        _e('When enabled this setting will show previews of your photos on a separate page. When disabled your photo previews will be via a lightbox. (Activating this option is recommended)', 'spgallery');
        ?>
</span>
                </td> 
            </tr>
            <tr><td colspan="2"><div class="wppg_section_separator_1"></div></td></tr>
            <tr>
                <th scope="row"><?php 
        _e('Watermark Text', 'spgallery');
        ?>
:</th>
                <td><input type="text" size="25" name="wppg_gallery_watermark" value="<?php 
        echo $gallery_watermark;
        ?>
" />
                <span class="description"><?php 
        _e('The text which you enter here will appear as a watermark on all photos in this gallery when they are being previewed by your visitors.', 'spgallery');
        ?>
</span>
                <span class="wppg_more_info_anchor"><span class="wppg_more_info_toggle_char">+</span><span class="wppg_more_info_toggle_text"><?php 
        _e('More Info', 'spgallery');
        ?>
</span></span>
                <div class="wppg_more_info_body">
                        <?php 
        echo '<p class="description">' . __('Leave this field blank if you wish to display the original photo to your customers when they are previewing this gallery.', 'spgallery') . '</p>';
        ?>
                </div>
                </td> 
            </tr>
            <tr>
                <th scope="row"><?php 
        _e('Watermark Text Opacity', 'spgallery');
        ?>
:</th>
                <td><input type="text" size="25" name="wppg_watermark_opacity" value="<?php 
        echo $gallery_watermark_opacity;
        ?>
" />
                <span class="description"><?php 
        _e('Enter a value between 0 and 100 where 0 is most transparent and 100 is least transparent.', 'spgallery');
        ?>
</span>
                <span class="wppg_more_info_anchor"><span class="wppg_more_info_toggle_char">+</span><span class="wppg_more_info_toggle_text"><?php 
        _e('More Info', 'spgallery');
        ?>
</span></span>
                <div class="wppg_more_info_body">
                        <?php 
        echo '<p class="description">' . __('This field enables you to set the transparency of your watermark text.
                                                        A value of 0 will make your watermark text fully transparent and a value of 100 will make it non-transparent.', 'spgallery') . '</p>';
        ?>
                </div>
                </td> 
            </tr>
            <tr>
                <th scope="row"><?php 
        _e('Watermark Text Placement', 'spgallery');
        ?>
:</th>
                <td>
                    <select id="wppg_watermark_placement" name="wppg_watermark_placement">
                        <option value="0" <?php 
        selected($gallery_watermark_placement, '0');
        ?>
><?php 
        _e('Centered', 'spgallery');
        ?>
</option>
                        <option value="5" <?php 
        selected($gallery_watermark_placement, '5');
        ?>
><?php 
        _e('Repeated Grid', 'spgallery');
        ?>
</option>
                        <option value="1" <?php 
        selected($gallery_watermark_placement, '1');
        ?>
><?php 
        _e('Top Left', 'spgallery');
        ?>
</option>
                        <option value="2" <?php 
        selected($gallery_watermark_placement, '2');
        ?>
><?php 
        _e('Top Right', 'spgallery');
        ?>
</option>
                        <option value="3" <?php 
        selected($gallery_watermark_placement, '3');
        ?>
><?php 
        _e('Bottom Right', 'spgallery');
        ?>
</option>
                        <option value="4" <?php 
        selected($gallery_watermark_placement, '4');
        ?>
><?php 
        _e('Bottom Left', 'spgallery');
        ?>
</option>
                    </select>
                <span class="description"><?php 
        _e('Choose the placement location of your watermark text', 'spgallery');
        ?>
</span>
                </td>
            </tr>
            <tr>
                <th scope="row"><?php 
        _e('Watermarked Max Preview Dimension (px)', 'spgallery');
        ?>
:</th>
                <td><input type="text" size="25" name="wppg_watermark_width" value="<?php 
        echo empty($gallery_watermark_width) ? '600' : $gallery_watermark_width;
        ?>
" />
                <span class="description"><?php 
        _e('Enter a desired max dimension size for your watermarked preview', 'spgallery');
        ?>
</span>
                <span class="wppg_more_info_anchor"><span class="wppg_more_info_toggle_char">+</span><span class="wppg_more_info_toggle_text"><?php 
        _e('More Info', 'spgallery');
        ?>
</span></span>
                <div class="wppg_more_info_body">
                        <?php 
        echo '<div class="description">' . __('<p>This field enables you to set the maximum desired width or height of the watermarked version of your photos in this gallery depending on whether the photo is a portrait or landscape.</p>
                                                        <p>For instance if your photo is a landscape style image then the value you enter here will represent the maximum desired width of the preview image.</p>
                                                        <p>Conversely, if your photo is a portrait style image then the value you enter here will represent the maximum desired height of the preview image.</p>
                                                        <p>The plugin will automatically scale the watermarked photo\'s other dimension to the appropriate value based on the value entered in this field.<p>', 'spgallery') . '</div>';
        ?>
                </div>
                </td> 
            </tr>
            <tr>
                <th scope="row"><?php 
        _e('Watermark Font Size (px)', 'spgallery');
        ?>
:</th>
                <td><input type="text" size="25" name="wppg_watermark_font_size" value="<?php 
        echo empty($gallery_watermark_font_size) ? '35' : $gallery_watermark_font_size;
        ?>
" />
                <span class="description"><?php 
        _e('Set the font size of the watermark text', 'spgallery');
        ?>
</span>
                <span class="wppg_more_info_anchor"><span class="wppg_more_info_toggle_char">+</span><span class="wppg_more_info_toggle_text"><?php 
        _e('More Info', 'spgallery');
        ?>
</span></span>
                <div class="wppg_more_info_body">
                        <?php 
        echo '<p class="description">' . __('This field enables you to set the font size of the watermark text for all photos in this gallery. 
                                                        If left blank the plugin will default to 35px.', 'spgallery') . '</p>';
        ?>
                </div>
                </td> 
            </tr>
            <tr><td colspan="2"><div class="wppg_section_separator_1"></div></td></tr>
            <tr>
                <th scope="row"><?php 
        _e('Use Pagination', 'spgallery');
        ?>
:</th>
                <td>
                <input id="wppg_gallery_pagination" name="wppg_gallery_pagination" type="checkbox" <?php 
        echo $gallery_pagination == '1' ? 'checked="checked"' : '';
        ?>
>
                <span class="description"><?php 
        _e('Click this to enable pagination when displaying your gallery\'s photo thumbnails.', 'spgallery');
        ?>
</span>
                </td> 
            </tr>
            <tr>
                <th scope="row"><?php 
        _e('Thumbs Per Page', 'spgallery');
        ?>
:</th>
                <td><input type="text" size="25" name="wppg_thumbs_per_page" value="<?php 
        echo empty($gallery_thumbs_per_page) ? '20' : $gallery_thumbs_per_page;
        ?>
" />
                <span class="description"><?php 
        _e('Set the number of thumbnails to display per page', 'spgallery');
        ?>
</span>
                </td> 
            </tr>
            <tr><td colspan="2"><div class="wppg_section_separator_1"></div></td></tr>
            <tr  class="uploader wppg_upload_button_row">
                <th scope="row"><?php 
        _e('Upload Images', 'spgallery');
        ?>
:</th>
                <td><input type="submit" class="wppg_upload_image_button button" name="wppg_upload_image_button" value="Upload"/>
                    <span class="description"><?php 
        _e('To upload or select your images from the media library please click this button', 'spgallery');
        ?>
</span>
                </td>
            </tr>

        </table>
        <input type="submit" name="wppg_save_gallery" value="Save Gallery" class="button-primary" />
        </form>   
        </div></div>
        <div class="postbox">
        <h3><label for="title"><?php 
        _e('Gallery Images', 'spgallery');
        ?>
</label></h3>
        <div class="inside">
            <?php 
        //Fetch, prepare, sort, and filter our data...
        $gallery_image_list->prepare_items();
        //echo "put table of locked entries here";
        ?>
            <form id="tables-filter" method="get" onSubmit="return confirm('Are you sure you want to perform this bulk operation on the selected entries?');">
            <!-- For plugins, we also need to ensure that the form posts back to our current page -->
            <input type="hidden" name="page" value="<?php 
        echo $_REQUEST['page'];
        ?>
" />
            <input type="hidden" name="tab" value="<?php 
        echo $_REQUEST['tab'];
        ?>
" />
            <input type="hidden" name="id" value="<?php 
        echo isset($_REQUEST['id']) ? $_REQUEST['id'] : '';
        ?>
" />
            <!-- Now we can render the completed list table -->
            <?php 
        $gallery_image_list->display();
        ?>
            </form>
        </div></div>
        <script type="text/javascript">
            jQuery(document).ready(function($){
                wp.media.controller.Library.prototype.defaults.contentUserSetting=false; //Display the "Upload Files" tab by default when media uploader window is launched
            });
        </script>        
            <?php 
    }
Example #5
0
				
			<div id="article-carrousel">
				<div class="diapos">
				<?php 
global $wp_photo_gallery;
$gallery = new WPPGPhotoGallery($id);
$gallery_items = WPPGPhotoGallery::getGalleryItems($id);
foreach ($gallery_items as $item) {
    $large = wp_get_attachment_image_src($item["id"], "img_medium");
    //print_r($large);
    //$css = 'style="background-image:url('.$item["image_url"].')"';
    $css = 'style="background-image:url(' . $large[0] . ')"';
    include locate_template('_/inc/carrousel-item.php');
}
?>
				 </div>
			</div>
    static function wppg_slider_output_sc($ids, $attrs)
    {
        if (is_array($ids)) {
            //get photos for each gallery id
            $image_data = array();
            foreach ($ids as $id) {
                $image_data_temp = WPPGPhotoGallery::getGalleryItems($id);
                $image_data = array_merge($image_data, $image_data_temp);
            }
        } else {
            //get photos for single gallery
            $image_data = WPPGPhotoGallery::getGalleryItems($ids);
        }
        $slider_id = uniqid();
        $carousel_id = uniqid();
        $carousel_js_code = '';
        $show_carousel = false;
        if (isset($attrs['show_carousel']) && $attrs['show_carousel'] == '1') {
            $show_carousel = true;
            $carousel_js_code = <<<EOT
            \$('#{$carousel_id}').flexslider({
                animation: "slide",
                controlNav: false,
                animationLoop: false,
                slideshow: false,
                itemWidth: 150,
                itemMargin: 5,
                asNavFor: '#{$slider_id}'
              });
EOT;
        }
        WP_Photo_Gallery_Utility::start_buffer();
        ?>
        <div class="wppg-slider-container flexslider" id="<?php 
        echo $slider_id;
        ?>
">
            <ul class="wppg-slides slides">
                <?php 
        foreach ($image_data as $image) {
            echo '<li><img src="' . $image['image_url'] . '"/></li>';
        }
        ?>
            </ul>
        </div>

        <?php 
        if ($show_carousel) {
            ?>
        <div class="wppg-slider-container flexslider" id="<?php 
            echo $carousel_id;
            ?>
">
            <ul class="wppg-slides slides">
                <?php 
            foreach ($image_data as $image) {
                echo '<li><img src="' . $image['image_url'] . '"/></li>';
            }
            ?>
            </ul>
        </div>        
        <?php 
        }
        $slider_js_code = <<<EOT
<script type="text/javascript" charset="utf-8">
/* <![CDATA[ */
jQuery(document).ready(function(\$) {
    {$carousel_js_code}
    \$('#{$slider_id}').flexslider({
        animation: "slide",
        smoothHeight: true,
        prevText: '',
        nextText: '',
        controlNav: false,
        slideshow: false
    });
});      
/* ]]> */
</script> 
EOT;
        echo $slider_js_code;
        $output = WP_Photo_Gallery_Utility::end_buffer_and_collect();
        return $output;
    }
 function delete_gallery($entries)
 {
     global $wpdb;
     $errors = '';
     $gallery_table = WPPG_TBL_GALLERY;
     if (is_array($entries)) {
         foreach ($entries as $entry) {
             //Delete all attachment posts
             $gallery_delete_result = WPPGPhotoGallery::deleteGalleryItems($entry);
             if (!$gallery_delete_result) {
                 $errors .= '<p>Unable to delete gallery images</p>';
                 //TODO
             }
             //Delete the gallery folder
             $gallery_folder_delete_result = WPPGPhotoGallery::deleteGalleryFolder($entry);
             if (!$gallery_folder_delete_result) {
                 $errors .= '<p>Unable to delete gallery folder</p>';
                 //TODO
             }
             //Delete gallery page if it exists
             $g = new WPPGPhotoGallery($entry);
             $p = get_post($g->page_id);
             if ($p) {
                 wp_delete_post($p->ID, true);
             }
         }
         //Now delete the gallery row in the gallery table
         $id_list = "(" . implode(",", $entries) . ")";
         //Create comma separate list for DB operation
         $delete_command = "DELETE FROM " . $gallery_table . " WHERE id IN " . $id_list;
         $result = $wpdb->query($delete_command);
         if ($result != NULL) {
             $success_msg = '<div id="message" class="updated fade"><p><strong>';
             $success_msg .= __('The selected entries were deleted successfully!', 'spgallery');
             $success_msg .= '</strong></p></div>';
             _e($success_msg);
         } else {
             $wp_photo_gallery->debug_logger->log_debug("There was an error deleting one or more of the selected galleries with ids: " . print_r($entries, true), 4);
         }
     } elseif ($entries != NULL) {
         //Delete all attachment posts
         $gallery_delete_result = WPPGPhotoGallery::deleteGalleryItems($entries);
         if (!$gallery_delete_result) {
             $errors .= '<p>Unable to delete gallery images</p>';
             //TODO
         }
         //Delete the gallery folder
         $gallery_folder_delete_result = WPPGPhotoGallery::deleteGalleryFolder($entries);
         if (!$gallery_folder_delete_result) {
             $errors .= '<p>Unable to delete gallery folder</p>';
             //TODO
         }
         //Delete gallery page if it exists
         $g = new WPPGPhotoGallery($entries);
         $p = get_post($g->page_id);
         if ($p) {
             wp_delete_post($p->ID, true);
         }
         $delete_command = $wpdb->prepare("DELETE FROM " . $gallery_table . " WHERE id = %d", absint($entries));
         $result = $wpdb->query($delete_command);
         if ($result != NULL) {
             $success_msg = '<div id="message" class="updated fade"><p><strong>';
             $success_msg .= __('The selected entry was deleted successfully!', 'spgallery');
             $success_msg .= '</strong></p></div>';
             _e($success_msg);
         } else {
             $wp_photo_gallery->debug_logger->log_debug("There was an error deleting the gallery with id: " . $entries, 4);
         }
     }
 }
    function render_album($album_id)
    {
        global $wp_photo_gallery;
        global $wpdb;
        $album_table_name = WPPG_TBL_ALBUM;
        $album_object = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$album_table_name} WHERE id = %d", $album_id), OBJECT);
        if ($album_object == NULL) {
            $wp_photo_gallery->debug_logger->log_debug('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] wppg_photo_album shortcode - No album found with ID " . $album_id);
            return '<div class="wppg_red_box_front_end">No album was found with ID ' . $album_id . '</div>';
        }
        WP_Photo_Gallery_Utility::start_buffer();
        ?>
        <link type="text/css" rel="stylesheet" href="<?php 
        echo WP_PHOTO_URL . '/classes/album-templates/css/wppg-photo-album-template-1.css?ver=' . WP_PHOTO_VERSION;
        ?>
" />
        
<?php 
        $gallery_array_list = maybe_unserialize($album_object->gallery_list);
        //Get the galleries associated with this album
        if (!empty($gallery_array_list)) {
            //
            $gallery_id_list = "(" . implode(",", $gallery_array_list) . ")";
            //Create comma separate list for DB operation
            $album_contents_sort_order = $album_object->sort_order;
            switch ($album_contents_sort_order) {
                case 0:
                    //Sort By ID Ascending
                    $orderBy = 'ORDER BY id ASC';
                    break;
                case 1:
                    //Sort By ID Descending
                    $orderBy = 'ORDER BY id DESC';
                    break;
                case 2:
                    //Sort By Created Date Ascending
                    $orderBy = 'ORDER BY created ASC';
                    break;
                case 3:
                    //Sort By Created Date Descending
                    $orderBy = 'ORDER BY created DESC';
                    break;
                case 4:
                    //Sort By Name Ascending
                    $orderBy = 'ORDER BY name ASC';
                    break;
                case 5:
                    //Sort By Name Descending
                    $orderBy = 'ORDER BY name DESC';
                    break;
                default:
                    //Default to ID ascending
                    $orderBy = 'ORDER BY id DESC';
                    break;
            }
            $gallery_table_name = WPPG_TBL_GALLERY;
            $query = "Select * from " . $gallery_table_name . " WHERE id IN " . $gallery_id_list;
            $items = $wpdb->get_results($query);
            ?>

            <div id="wppg_albumcontainer"> 
<?php 
            if (!empty($items)) {
                foreach ($items as $item) {
                    $p = get_post($item->page_id);
                    $page_link = get_permalink($p->ID);
                    $thumb_image_url = '#';
                    $gallery_items = WPPGPhotoGallery::getGalleryItems($item->id);
                    if ($gallery_items) {
                        $thumb_image_url = $gallery_items[0]['thumb_url'];
                        //Get the thumb URL of the first gallery item
                    }
                    $gallery_name = $item->name;
                    if (strlen($gallery_name) > 14) {
                        $gallery_name_short = substr($gallery_name, 0, 14) . "...";
                    } else {
                        $gallery_name_short = $gallery_name;
                    }
                    ?>
 
                    <div class="wppg_album_item_container">
                        <div class="wppg_album_item_top">
                            <div class="wppg_album_item_thumbnail">
                            <a href='<?php 
                    echo $page_link;
                    ?>
'>
                                    <img class="wppg_album_item_thumbnail" src='<?php 
                    echo $thumb_image_url;
                    ?>
' alt='<?php 
                    echo $gallery_name;
                    ?>
' title="<?php 
                    echo $gallery_name;
                    ?>
" />
                            </a>
                            </div>
                        </div>
                        <div class="wppg_album_item_bottom">
                            <div class="wppg_album_item_name"><a href="<?php 
                    echo $page_link;
                    ?>
" title="<?php 
                    echo $gallery_name;
                    ?>
"><?php 
                    echo $gallery_name_short;
                    ?>
</a></div>
                        </div>
                    </div>
    <?php 
                }
            } else {
                //No galleries found for the whole site!
                echo '<div class="wppg_red_box_front_end">' . __('There are currently no galleries configured in the system!', 'spgallery') . '</div>';
            }
        }
        $output = WP_Photo_Gallery_Utility::end_buffer_and_collect();
        return $output;
    }
 function fetch_gallery_images($gallery_id, $orderby, $order)
 {
     global $wpdb;
     //$posts = $wpdb->get_col( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wppg_gallery_id' AND meta_value = $gallery_id" );
     $gallery_image_ids_array = WPPGPhotoGallery::get_gallery_image_ids($gallery_id);
     $gallery_images_array = array();
     foreach ($gallery_image_ids_array as $image_id) {
         $thumb_url = wp_get_attachment_thumb_url($image_id);
         $attachment_img = wp_get_attachment_image($image_id);
         $alt_text = get_post_meta($image_id, '_wp_attachment_image_alt', true);
         $image_post = get_post($image_id);
         $image_desc = $image_post->post_content;
         $upload_date = $image_post->post_date;
         //if the alt text meta is blank, let's set it to the image name
         if ($alt_text == '' || $alt_text == NULL) {
             $alt_text = $image_post->post_name;
             update_post_meta($image_id, '_wp_attachment_image_alt', $alt_text);
             //update the post_meta table
         }
         $image_info = array('id' => $image_id, 'thumb_url' => $thumb_url, 'alt_text' => $alt_text, 'description' => $image_desc, 'date_uploaded' => $upload_date);
         $gallery_images_array[] = $image_info;
     }
     //Let's take care of sorting
     $sortArray = array();
     foreach ($gallery_images_array as $g_img) {
         $sortArray[] = $g_img[$orderby];
     }
     //$sort_order = strtoupper('SORT_'.$order);
     if (strtoupper($order) == 'DESC') {
         array_multisort($sortArray, SORT_DESC, $gallery_images_array);
     } else {
         array_multisort($sortArray, SORT_ASC, $gallery_images_array);
     }
     return $gallery_images_array;
 }
    function render_photo_details()
    {
        global $wp_photo_gallery;
        WP_Photo_Gallery_Utility::start_buffer();
        if (!isset($_GET['image_id']) && !isset($_GET['gallery_id'])) {
            echo '<div class="wppg_yellow_box_front_end">' . __('This page is for displaying the details of a selected photo. Please click on a photo from one of the galleries to see the details.') . '</div>';
            $output = WP_Photo_Gallery_Utility::end_buffer_and_collect();
            return $output;
        }
        $image_id = strip_tags($_GET['image_id']);
        $gallery_id = strip_tags($_GET['gallery_id']);
        $gallery = new WPPGPhotoGallery($gallery_id);
        $url_param_encoded = '';
        //$c_g = get_post($gallery->page_id);
        //$current_gallery_page = $c_g->guid;
        $current_gallery_page = get_permalink($gallery->page_id);
        $wppgPhotoObj = new WPPGPhotoGalleryItem();
        $wppgPhotoObj->create_photo_item_by_id($image_id);
        $photo_name = $wppgPhotoObj->name;
        $image_display_url = '';
        $water_mark_url = '';
        $photo_nav_info = '';
        $file_name = $wppgPhotoObj->image_file_name;
        $full_size_image = $wppgPhotoObj->image_file_url;
        $upload_dir = wp_upload_dir();
        $path = $wppgPhotoObj->thumb_url;
        $source_dir = $upload_dir['basedir'] . '/' . WPPG_UPLOAD_SUB_DIRNAME . '/' . $gallery_id . '/';
        $gallery_home_page_id = $wp_photo_gallery->configs->get_value('wppg_gallery_home_page_id');
        if (empty($gallery_home_page_id)) {
            $g_p = get_page_by_path('wppg_photogallery');
            //$gallery_page = $g_p->guid;
            $gallery_page = get_permalink($g_p->ID);
        } else {
            $gallery_page = get_permalink($gallery_home_page_id);
        }
        $items_to_add = array();
        $display_msg = '';
        $watermark_placement = $gallery->watermark_placement;
        if ($watermark_placement === NULL) {
            $watermark_placement = '0';
        }
        $desired_width = $gallery->watermark_width;
        if ($desired_width == 0 || empty($desired_width)) {
            $desired_width = '600';
        }
        $wm_font_size = $gallery->watermark_font_size;
        if ($wm_font_size == 0 || empty($wm_font_size)) {
            $wm_font_size = '35';
        }
        $watermark_opacity = $gallery->watermark_opacity;
        if ($watermark_opacity === NULL) {
            $watermark_opacity = '35';
        }
        //If the image is a portrait then instead of setting max width, we want to set max height otherwise the preview comes out too big
        if ($wppgPhotoObj->image_height > $wppgPhotoObj->image_width) {
            $args = array('watermark_height' => $desired_width, 'watermark_font_size' => $wm_font_size, 'watermark_placement' => $watermark_placement, 'watermark_opacity' => $watermark_opacity);
        } else {
            $args = array('watermark_width' => $desired_width, 'watermark_font_size' => $wm_font_size, 'watermark_placement' => $watermark_placement, 'watermark_opacity' => $watermark_opacity);
        }
        if ($gallery->watermark != NULL) {
            WPPGPhotoGallery::createWatermarkImage($source_dir, $source_dir, $file_name, false, $gallery->watermark, $args);
            $water_mark_url = $upload_dir['baseurl'] . '/' . WPPG_UPLOAD_SUB_DIRNAME . '/' . $gallery_id . '/watermark_' . $file_name;
            $image_display_url = $water_mark_url;
        } else {
            //Don't create a watermark URL if the watermark field was empty in the gallery settings.  Display original image instead
            $image_display_url = $wppgPhotoObj->image_file_url;
        }
        //Get variations
        //$variations_data = WPSPhotoProduct::get_all_photo_variations($image_id);
        //array_shift($variations_data); //remove the first item which is the image title
        //$digital_variations = array();
        //$physical_variations = array();
        //foreach ($variations_data as $variation)
        //{
        //    if(strtolower($variation['type']) == 'digital'){
        //        $digital_variations[] = $variation;
        //    }else if(strtolower($variation['type']) == 'physical'){
        //        $physical_variations[] = $variation;
        //    }
        //}
        //Get gallery items
        //Initialize some variables
        $prev_img_id = '';
        $next_img_id = '';
        $query_params_prev = '';
        $query_params_next = '';
        $preview_url_prev = '';
        $preview_url_next = '';
        $gallery_items = WPPGPhotoGallery::getGalleryItems($gallery_id);
        $gallery_count = count($gallery_items);
        $x = 0;
        $img_index = 0;
        foreach ($gallery_items as $p) {
            $img_id = $p['id'];
            if ($img_id == $image_id) {
                $img_index = $x;
                break;
            }
            $x++;
        }
        $details_page_id = $wp_photo_gallery->configs->get_value('wppg_photo_details_page_id');
        if (empty($details_page_id)) {
            $photo_details_page = get_page_by_path('wppg_photogallery/wppg_photo_details');
            $preview_page = get_permalink($photo_details_page->ID);
        } else {
            $preview_page = get_permalink($details_page_id);
        }
        //Let's now determine the previous and next gallery image ids
        if ($img_index == 0) {
            //Means that current image is the first in the gallery
            $prev_img_id = $gallery_items[$gallery_count - 1]['id'];
            //Last image in the gallery
            if ($img_index == $gallery_count - 1) {
                //If there is a single image in the gallery then the first image will be the last too
                $next_img_id = $gallery_items[$img_index]['id'];
            } else {
                $next_img_id = $gallery_items[$img_index + 1]['id'];
            }
            $query_params_prev = array('gallery_id' => $gallery_id, 'image_id' => $prev_img_id);
            $query_params_next = array('gallery_id' => $gallery_id, 'image_id' => $next_img_id);
            $preview_url_prev = add_query_arg($query_params_prev, $preview_page);
            $preview_url_next = add_query_arg($query_params_next, $preview_page);
        } else {
            if ($img_index == $gallery_count - 1) {
                //Means that current image is the last in the gallery
                $prev_img_id = $gallery_items[$img_index - 1]['id'];
                $next_img_id = $gallery_items[0]['id'];
                //First image in the gallery
                $query_params_prev = array('gallery_id' => $gallery_id, 'image_id' => $prev_img_id);
                $query_params_next = array('gallery_id' => $gallery_id, 'image_id' => $next_img_id);
                $preview_url_prev = add_query_arg($query_params_prev, $preview_page);
                $preview_url_next = add_query_arg($query_params_next, $preview_page);
            } else {
                //Current image has a previous and a next image
                $prev_img_id = $gallery_items[$img_index - 1]['id'];
                $next_img_id = $gallery_items[$img_index + 1]['id'];
                $query_params_prev = array('gallery_id' => $gallery_id, 'image_id' => $prev_img_id);
                $query_params_next = array('gallery_id' => $gallery_id, 'image_id' => $next_img_id);
                $preview_url_prev = add_query_arg($query_params_prev, $preview_page);
                $preview_url_next = add_query_arg($query_params_next, $preview_page);
            }
        }
        //Let's add the special auth_key if the gallery is password protected
        if (!empty($gallery->password)) {
            $query_params = array('auth_key' => $url_param_encoded);
            $preview_url_prev = add_query_arg($query_params, $preview_url_prev);
            $preview_url_next = add_query_arg($query_params, $preview_url_next);
        }
        if ($gallery_count > 0) {
            //Photo navigation info eg, - "Displaying photo 1 of 20"
            $photo_nav_info = sprintf(__('Displaying photo %s of %s', 'spgallery'), $img_index + 1, $gallery_count);
        }
        ?>
        <div class="wppg-image-details">
        <h2><?php 
        echo $photo_name;
        ?>
</h2>
        <div class="wppg-image-details-watermark-section">
            <img src="<?php 
        echo $image_display_url;
        ?>
" alt="<?php 
        echo $wppgPhotoObj->alt_text;
        ?>
" class="wppg-image-details-watermarked-img" />
        </div>
        <div class="wppg-digital-details">
        <div class="wppg-photo-description-text"><?php 
        _e($wppgPhotoObj->description, 'spgallery');
        ?>
</div>
        </div><!-- end of .wppg-digital-details -->

        <div class="wppg-css-clear"></div>
        <div class="wppg_photo_details_navigation_info">
            <?php 
        echo $photo_nav_info;
        ?>
        </div>

        <div class="wppg-digital-details-prev-next">
        <span class="wppg_photo_details_previous_photo_section wppg_photo_details_navigation_links">
            <?php 
        echo '<a href="' . $preview_url_prev . '" class="wppg_photo_details_previous_photo">&laquo; ' . __("Previous Photo", 'spgallery') . '</a>';
        ?>
        </span>
        <span class="wppg_photo_details_next_photo_section wppg_photo_details_navigation_links">
            <?php 
        echo '<a href="' . $preview_url_next . '" class="wppg_photo_details_next_photo">' . __("Next Photo", 'spgallery') . ' &raquo;</a>';
        ?>
        </span>
        </div>
        <span class="wppg_photo_details_bottom_section"><a href="<?php 
        echo $current_gallery_page;
        ?>
"><span class="wppg_photo_details_back_to_gallery"><?php 
        _e("Back To Gallery Page", 'spgallery');
        ?>
</span></a></span>
        </div><!-- end of .wppg-image-details -->
<?php 
        $output = WP_Photo_Gallery_Utility::end_buffer_and_collect();
        return $output;
    }
    function render_gallery_home()
    {
        global $wpdb, $wp_photo_gallery;
        $gallery_table = WPPG_TBL_GALLERY;
        $gallery_selection_sort_order = $wp_photo_gallery->configs->get_value('wppg_gallery_home_sort_order');
        switch ($gallery_selection_sort_order) {
            case 0:
                //Sort By ID Ascending
                $orderBy = 'ORDER BY id ASC';
                break;
            case 1:
                //Sort By ID Descending
                $orderBy = 'ORDER BY id DESC';
                break;
            case 2:
                //Sort By Created Date Ascending
                $orderBy = 'ORDER BY created ASC';
                break;
            case 3:
                //Sort By Created Date Descending
                $orderBy = 'ORDER BY created DESC';
                break;
            case 4:
                //Sort By Name Ascending
                $orderBy = 'ORDER BY name ASC';
                break;
            case 5:
                //Sort By Name Descending
                $orderBy = 'ORDER BY name DESC';
                break;
            default:
                //Default to ID ascending
                $orderBy = 'ORDER BY id DESC';
                break;
        }
        //Get galleries
        $galleries = $wpdb->get_results("SELECT * FROM {$gallery_table} {$orderBy}", OBJECT);
        WP_Photo_Gallery_Utility::start_buffer();
        echo '<link type="text/css" rel="stylesheet" href="' . WP_PHOTO_URL . '/classes/gallery-templates/css/wppg-gallery-home.css?ver=' . WP_PHOTO_VERSION . '" />';
        //Load the CSS file for this view
        ?>
        <div id="wppg_gallery_container"> 
        <?php 
        if (!empty($galleries)) {
            foreach ($galleries as $item) {
                //$p = get_page_by_path('photogallery/gallery' . $item->id);
                $p = get_post($item->page_id);
                $page_link = get_permalink($p->ID);
                $thumb_image_url = '#';
                $gallery_items = WPPGPhotoGallery::getGalleryItems($item->id);
                if ($gallery_items) {
                    $thumb_image_url = $gallery_items[0]['thumb_url'];
                    //Get the thumb URL of the first gallery item
                }
                $gallery_name = $item->name;
                if (strlen($gallery_name) > 14) {
                    $gallery_name_short = substr($gallery_name, 0, 14) . "...";
                } else {
                    $gallery_name_short = $gallery_name;
                }
                ?>
 
                <div class="wppg_gallery_item_container">
                    <div class="wppg_gallery_item_top">
                        <div class="wppg_gallery_item_thumbnail">
                        <a href='<?php 
                echo $page_link;
                ?>
'>
                                <img class="wppg_gallery_item_thumb" src='<?php 
                echo $thumb_image_url;
                ?>
' alt='<?php 
                echo $gallery_name;
                ?>
' title="<?php 
                echo $gallery_name;
                ?>
" />
                        </a>
                        </div>
                    </div>
                    <div class="wppg_gallery_item_bottom">
                        <div class="wppg_gallery_item_name"><a href="<?php 
                echo $page_link;
                ?>
" title="<?php 
                echo $gallery_name;
                ?>
"><?php 
                echo $gallery_name_short;
                ?>
</a></div>
                    </div>
                </div>
    <?php 
            }
        } else {
            //No galleries found!
            echo '<div class="wppg_yellow_box_front_end">' . __("There are currently no galleries!", "WPPG") . '</div>';
        }
        ?>

                <div class="clear"></div>
        </div>
    <?php 
        $output = WP_Photo_Gallery_Utility::end_buffer_and_collect();
        return $output;
    }