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;
    }
    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 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;
    }
Пример #4
0
    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;
    }
Пример #5
0
    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;
    }
    function render_album_home()
    {
        global $wpdb;
        global $wp_photo_gallery;
        $album_table_name = WPPG_TBL_ALBUM;
        //TODO - add sort order for album home page in future release
        $items = $wpdb->get_results("SELECT * FROM {$album_table_name}", OBJECT);
        WP_Photo_Gallery_Utility::start_buffer();
        //echo '<link type="text/css" rel="stylesheet" href="'.WP_PHOTO_URL.'/classes/album-templates/css/wppg-photo-album-home.css?ver='.WP_PHOTO_VERSION.'" />';//Load the CSS file for this view
        //we will use the same CSS file for home page as for template 1 for now
        echo '<link type="text/css" rel="stylesheet" href="' . WP_PHOTO_URL . '/classes/album-templates/css/wppg-photo-album-template-1.css?ver=' . WP_PHOTO_VERSION . '" />';
        //Load the CSS file for this view
        ?>

        <div id="wppg_albumcontainer"> 
<?php 
        if ($wpdb->num_rows > 0 && $items != NULL) {
            foreach ($items as $item) {
                $p = get_post($item->page_id);
                $page_link = get_permalink($p->ID);
                $album_thumb_url = $item->thumbnail_url;
                //Check image size
                $image_info = getimagesize($album_thumb_url);
                if (!$image_info || $image_info[0] > 150 && $image_info[1] > 150) {
                    $image_filename = basename($album_thumb_url);
                    //extract filename
                    //First check if standard 150x150 thumb file exists
                    $extension_pos = strrpos($image_filename, '.');
                    // find position of the last dot, so where the extension starts
                    $standard_thumb = substr($image_filename, 0, $extension_pos) . '-150x150' . substr($image_filename, $extension_pos);
                    //add "-150x150" to original filename
                    $path_without_file_name = dirname($album_thumb_url);
                    $std_thumb_image_url = $path_without_file_name . '/' . $standard_thumb;
                    if (@getimagesize($std_thumb_image_url) !== false) {
                        $album_thumb_url = $std_thumb_image_url;
                    } else {
                        $image_id = WP_Photo_Gallery_Utility::get_attachment_id_from_url($album_thumb_url);
                        if ($image_id != NULL) {
                            $image_meta = wp_get_attachment_metadata($image_id);
                            $upload_dir = wp_upload_dir();
                            $image_path = $upload_dir['basedir'] . '/' . $image_meta['file'];
                            //lets make our own 150x150 thumb
                            $resized_file = image_make_intermediate_size($image_path, '150', '150');
                            if ($resized_file === false) {
                                $album_thumb_url = '';
                                //To avoid PHP undeclared variable error. In this case we don't have a default thumb to revert to.
                                $wp_photo_gallery->debug_logger->log_debug("Album Home - Unable to create thumb because image_make_intermediate_size failed and returned false");
                            } else {
                                $album_thumb_url = $path_without_file_name . '/' . $resized_file['file'];
                            }
                        }
                    }
                    $thumb_image_url = $album_thumb_url;
                } else {
                    if ($image_info[0] <= 150 && $image_info[1] <= 150) {
                        $thumb_image_url = $album_thumb_url;
                    }
                }
                $album_name = $item->album_name;
                if (strlen($album_name) > 14) {
                    $album_name_short = substr($album_name, 0, 14) . "...";
                } else {
                    $album_name_short = $album_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_thumb" src='<?php 
                echo $thumb_image_url;
                ?>
' alt='<?php 
                echo $album_name;
                ?>
' title="<?php 
                echo $album_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 $album_name;
                ?>
"><?php 
                echo $album_name_short;
                ?>
</a></div>
                    </div>
                </div>
<?php 
            }
        } else {
            //No galleries found!
            echo '<div class="wppg_red_box_front_end">' . __('There are currently no albums configured!', 'spgallery') . '</div>';
        }
        ?>

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