Example #1
0
function wppa_theme()
{
    global $wppa_version;
    $wppa_version = '6-1-15-000';
    // The version number of this file
    global $wppa;
    global $wppa_show_statistics;
    // Can be set to true by a custom page template
    $curpage = wppa_get_curpage();
    // Get the page # we are on when pagination is on, or 1
    $didsome = false;
    // Required initializations for pagination
    $n_album_pages = '0';
    // "
    $n_thumb_pages = '0';
    // "
    // Open container
    wppa_container('open');
    // Show statistics if set so by the page template
    if ($wppa_show_statistics) {
        wppa_statistics();
    }
    // Display breadcrumb navigation only if it is set in the settings page
    wppa_breadcrumb('optional');
    if (wppa_page('albums')) {
        // Page 'Albums' requested
        // Get the albums and the thumbs and the number of pages for each set
        $albums = wppa_get_albums();
        // Get the albums
        $n_album_pages = wppa_get_npages('albums', $albums);
        // Get the number of album pages
        if (wppa_opt('thumbtype') != 'none') {
            $thumbs = wppa_get_thumbs();
            // Get the Thumbs
        } else {
            $thumbs = false;
        }
        $wanted_empty = wppa_is_wanted_empty($thumbs);
        // See if we need to display an empty thumbnail area
        $n_thumb_pages = wppa_get_npages('thumbs', $thumbs);
        // Get the number of thumb pages
        if ($n_thumb_pages == '0' && !$wanted_empty) {
            $thumbs = false;
        }
        // No pages: no thumbs. Maybe want covers only
        if ($wanted_empty) {
            $n_thumb_pages = '1';
        }
        // Get total number of pages
        if (!wppa_is_pagination()) {
            $totpag = '1';
        } else {
            $totpag = $n_album_pages + $n_thumb_pages;
        }
        // Make pagelinkbar if requested on top
        if (wppa_opt('pagelink_pos') == 'top' || wppa_opt('pagelink_pos') == 'both') {
            wppa_page_links($totpag, $curpage);
        }
        // Process the albums
        if (!wppa_switch('wppa_thumbs_first')) {
            if ($albums) {
                $counter_albums = '0';
                wppa_album_list('open');
                // Open Albums sub-container
                foreach ($albums as $album) {
                    // Loop the albums
                    $counter_albums++;
                    if (wppa_onpage('albums', $counter_albums, $curpage)) {
                        wppa_album_cover($album['id']);
                        // Show the cover
                        $didsome = true;
                    }
                    // End if on page
                }
                wppa_album_list('close');
                // Close Albums sub-container
            }
            // If albums
        }
        if ($didsome && wppa_is_pagination()) {
            $thumbs = false;
        }
        // Pag on and didsome: force a pagebreak by faking no thumbs
        if (count($thumbs) <= wppa_get_mincount() && !$wanted_empty) {
            $thumbs = false;
        }
        // Less than treshold value
        if (wppa_switch('wppa_thumbs_first') && $curpage > $n_thumb_pages) {
            $thumbs = false;
        }
        // If thumbs done, do not display an empty thumbarea
        // Process the thumbs
        if ($thumbs || $wanted_empty) {
            if (!$wanted_empty || !wppa_switch('thumbs_first') || wppa_get_curpage() == '1') {
                if (!$wanted_empty || wppa_switch('thumbs_first') || wppa_get_curpage() == $totpag) {
                    // Init
                    $counter_thumbs = '0';
                    // As covers
                    if (wppa_opt('wppa_thumbtype') == 'ascovers' || wppa_opt('wppa_thumbtype') == 'ascovers-mcr') {
                        // Do the thumbs As covers
                        wppa_thumb_list('open');
                        // Open Thumblist sub-container
                        $relpage = wppa_switch('wppa_thumbs_first') ? $curpage : $curpage - $n_album_pages;
                        foreach ($thumbs as $tt) {
                            global $thumb;
                            $thumb = $tt;
                            // Loop the Thumbs
                            $counter_thumbs++;
                            if (wppa_onpage('thumbs', $counter_thumbs, $relpage)) {
                                $didsome = true;
                                wppa_thumb_ascover($thumb['id']);
                                // Show Thumb as cover
                            }
                            // End if on page
                        }
                        wppa_thumb_list('close');
                        // Close Thumblist sub-container
                    } elseif (wppa_opt('wppa_thumbtype') == 'masonry-v') {
                        // Masonry
                        // The header
                        wppa_thumb_area('open');
                        // Open Thumbarea sub-container
                        wppa_popup();
                        // Prepare Popup box
                        wppa_album_name('top');
                        // Optionally display album name
                        wppa_album_desc('top');
                        // Optionally display album description
                        // Init
                        $relpage = wppa_switch('wppa_thumbs_first') ? $curpage : $curpage - $n_album_pages;
                        $cont_width = wppa_get_container_width();
                        $count_cols = ceil($cont_width / (wppa_opt('wppa_thumbsize') + wppa_opt('wppa_tn_margin')));
                        $correction = wppa_opt('wppa_tn_margin') * ($cont_width / $count_cols) / 100;
                        // Init the table
                        wppa_out('<table class="wppa-masonry" style="margin-top:3px;" ><tbody class="wppa-masonry" ><tr class="wppa-masonry" >');
                        // Init the columns
                        $col_headers = array();
                        $col_contents = array();
                        $col_heights = array();
                        $col_widths = array();
                        for ($col = 0; $col < $count_cols; $col++) {
                            $col_headers[$col] = '';
                            $col_contents[$col] = '';
                            $col_heights[$col] = 0;
                            $col_widths[$col] = 100;
                        }
                        // Process the thumbnails
                        $col = '0';
                        if ($thumbs) {
                            foreach ($thumbs as $tt) {
                                $id = $tt['id'];
                                $counter_thumbs++;
                                if (wppa_onpage('thumbs', $counter_thumbs, $relpage)) {
                                    $col_contents[$col] .= wppa_get_thumb_masonry($id);
                                    $col_heights[$col] += ($correction + wppa_get_thumby($id)) / ($correction + wppa_get_thumbx($id)) * $col_widths[$col];
                                    $col += '1';
                                    if ($col == $count_cols) {
                                        $col = '0';
                                    }
                                    $didsome = true;
                                }
                            }
                        }
                        // Find longest column
                        $long = 0;
                        for ($col = 0; $col < $count_cols; $col++) {
                            if ($col_heights[$col] > $long) {
                                $long = $col_heights[$col];
                            }
                        }
                        // Adjust column widths to resize lengths to equal lengths
                        for ($col = 0; $col < $count_cols; $col++) {
                            if ($col_heights[$col]) {
                                $col_widths[$col] = $long / $col_heights[$col] * $col_widths[$col];
                            }
                        }
                        // Adjust column widths to total 100
                        $wide = 0;
                        for ($col = 0; $col < $count_cols; $col++) {
                            $wide += $col_widths[$col];
                        }
                        for ($col = 0; $col < $count_cols; $col++) {
                            $col_widths[$col] = $col_widths[$col] * 100 / $wide;
                        }
                        // Make column headers
                        for ($col = 0; $col < $count_cols; $col++) {
                            $col_headers[$col] = '<td style="width: ' . $col_widths[$col] . '%; vertical-align:top;" class="wppa-masonry" >';
                        }
                        // Add the columns to the output stream
                        for ($col = 0; $col < $count_cols; $col++) {
                            wppa_out($col_headers[$col]);
                            wppa_out($col_contents[$col]);
                            wppa_out('</td>');
                        }
                        // Close the table
                        wppa_out('</tr></tbody></table>');
                        // The footer
                        wppa_album_name('bottom');
                        // Optionally display album name
                        wppa_album_desc('bottom');
                        // Optionally display album description
                        wppa_thumb_area('close');
                        // Close Thumbarea sub-container
                    } elseif (wppa_opt('wppa_thumbtype') == 'masonry-h') {
                        // Masonry
                        // The header
                        wppa_thumb_area('open');
                        // Open Thumbarea sub-container
                        wppa_popup();
                        // Prepare Popup box
                        wppa_album_name('top');
                        // Optionally display album name
                        wppa_album_desc('top');
                        // Optionally display album description
                        // Init
                        $relpage = wppa_switch('wppa_thumbs_first') ? $curpage : $curpage - $n_album_pages;
                        $cont_width = wppa_get_container_width('netto');
                        $correction = wppa_opt('wppa_tn_margin');
                        // Init the table
                        wppa_out('<table class="wppa-masonry" style="margin-top:3px;" ><tbody class="wppa-masonry" >');
                        // Process the thumbnails
                        $row_content = '';
                        $row_width = 0;
                        $target_row_height = wppa_opt('wppa_thumbsize') * 0.75 + $correction;
                        $rw_count = 0;
                        $tr_count = '1';
                        $done_count = 0;
                        $last = false;
                        $max_row_height = $target_row_height * 0.8;
                        // Init keep track for last
                        if ($thumbs) {
                            foreach ($thumbs as $tt) {
                                $id = $tt['id'];
                                $counter_thumbs++;
                                if (wppa_onpage('thumbs', $counter_thumbs, $relpage)) {
                                    $row_content .= wppa_get_thumb_masonry($tt['id']);
                                    $rw_count += 1;
                                    $row_width += wppa_get_thumbratioxy($id) * ($target_row_height - $correction);
                                    $didsome = true;
                                }
                                $done_count += 1;
                                $last = $done_count == count($thumbs);
                                if ($row_width > $cont_width || $last) {
                                    $tot_marg = $rw_count * $correction;
                                    $row_height = $row_width ? ($target_row_height - $correction) * ($cont_width - '3' - $tot_marg) / $row_width + $correction : '0';
                                    if (!$last) {
                                        $max_row_height = max($max_row_height, $row_height);
                                    }
                                    if ($last && $row_height > wppa_get_thumby($id)) {
                                        $row_height = $max_row_height;
                                    }
                                    $row_height_p = $row_height / $cont_width * 100;
                                    wppa_out('<tr class="wppa-masonry" >' . '<td style="border:none;padding:0;margin:0" >' . '<div' . ' id="wppa-mas-h-' . $tr_count . '-' . wppa('mocc') . '"' . ' style="height:' . $row_height . 'px;"' . ' class="wppa-masonry"' . ' data-height-perc="' . $row_height_p . '"' . ' >');
                                    wppa_out($row_content);
                                    wppa_out('</div></td></tr>');
                                    $row_content = '';
                                    $row_width = 0;
                                    $row_height = wppa_opt('wppa_thumbsize');
                                    $rw_count = 0;
                                    $tr_count += '1';
                                }
                            }
                        }
                        wppa_out('</tbody></table>');
                        // The footer
                        wppa_album_name('bottom');
                        // Optionally display album name
                        wppa_album_desc('bottom');
                        // Optionally display album description
                        wppa_thumb_area('close');
                        // Close Thumbarea sub-container
                    } elseif (wppa_opt('wppa_thumbtype') == 'default') {
                        // Do the thumbs As default
                        // The header
                        wppa_thumb_area('open');
                        // Open Thumbarea sub-container
                        wppa_popup();
                        // Prepare Popup box
                        wppa_album_name('top');
                        // Optionally display album name
                        wppa_album_desc('top');
                        // Optionally display album description
                        // Init
                        $relpage = wppa_switch('wppa_thumbs_first') ? $curpage : $curpage - $n_album_pages;
                        // Process the thumbnails
                        if ($thumbs) {
                            foreach ($thumbs as $tt) {
                                $counter_thumbs++;
                                if (wppa_onpage('thumbs', $counter_thumbs, $relpage)) {
                                    $didsome = true;
                                    wppa_thumb_default($tt['id']);
                                    // Show Thumb as default
                                }
                                // End if on page
                            }
                        }
                        // The footer
                        wppa_album_name('bottom');
                        // Optionally display album name
                        wppa_album_desc('bottom');
                        // Optionally display album description
                        wppa_thumb_area('close');
                        // Close Thumbarea sub-container
                    } else {
                        wppa_out('Unimplemented thumbnail type');
                    }
                }
            }
        }
        // If thumbs
        if ($didsome && wppa_is_pagination()) {
            $albums = false;
        }
        // Pag on and didsome: force a pagebreak by faking no albums
        if (!wppa_is_pagination()) {
            $n_thumb_pages = '0';
        }
        // Still on page one
        // Process the albums
        if (wppa_switch('wppa_thumbs_first')) {
            if ($albums) {
                $counter_albums = '0';
                wppa_album_list('open');
                // Open Albums sub-container
                foreach ($albums as $album) {
                    // Loop the albums
                    $counter_albums++;
                    if (wppa_onpage('albums', $counter_albums, $curpage - $n_thumb_pages)) {
                        wppa_album_cover($album['id']);
                        // Show the cover
                        $didsome = true;
                    }
                    // End if on page
                }
                wppa_album_list('close');
                // Close Albums sub-container
            }
            // If albums
        }
        // Make pagelinkbar if requested on bottom
        if (wppa_opt('pagelink_pos') == 'bottom' || wppa_opt('pagelink_pos') == 'both') {
            wppa_page_links($totpag, $curpage);
        }
        // Empty results?
        if (!$didsome && !$wanted_empty) {
            if (wppa('photos_only')) {
                wppa_out(wppa_errorbox(__a('No photos found matching your search criteria.', 'wppa_theme')));
            } elseif (wppa('albums_only')) {
                wppa_out(wppa_errorbox(__a('No albums found matching your search criteria.', 'wppa_theme')));
            } else {
                wppa_out(wppa_errorbox(__a('No albums or photos found matching your search criteria.', 'wppa_theme')));
            }
        }
    } elseif (wppa_page('slide') || wppa_page('single')) {
        // Page 'Slideshow' or 'Single' in browsemode requested
        $thumbs = wppa_get_thumbs();
        wppa_dbg_msg('From theme: #thumbs=' . ($thumbs ? count($thumbs) : '0'));
        if ($thumbs) {
            wppa_the_slideshow();
            // Producs all the html required for the slideshow
            wppa_run_slidecontainer('slideshow');
            // Fill in the photo array and display it.
        } else {
            wppa_out(wppa_errorbox(__a('No photos found matching your search criteria.', 'wppa_theme')));
        }
    }
    // wppa_page( 'slide' )
    // Close container
    wppa_container('close');
}
Example #2
0
function wppa_get_imagey($id, $key = 'photo')
{
    if (wppa_is_video($id)) {
        $result = wppa_get_videoy($id);
    } elseif ($key == 'thumb') {
        $result = wppa_get_thumby($id);
    } else {
        $result = wppa_get_photoy($id);
    }
    return $result;
}
function wppa_album_photos_sequence($album)
{
    global $wpdb;
    if ($album) {
        $photoorder = wppa_get_photo_order($album, 'norandom');
        $is_descending = strpos($photoorder, 'DESC') !== false;
        $is_p_order = strpos($photoorder, 'p_order') !== false;
        $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s ' . $photoorder, $album), ARRAY_A);
        $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $album . '&bulk');
        $size = '180';
        if ($photos) {
            ?>
			<style>
				.sortable-placeholder {
					width: <?php 
            echo $size;
            ?>
px;
					height: <?php 
            echo $size;
            ?>
px;
					margin: 5px;
					border: 1px solid #cccccc;
					border-radius:3px;
					float: left;
				}
				.ui-state-default {
					position: relative;
					width: <?php 
            echo $size;
            ?>
px;
					height: <?php 
            echo $size;
            ?>
px;
					margin: 5px;
					border-radius:3px;
					float: left;
				}
				.wppa-publish {
					border: 1px solid;
					background-color: rgb( 255, 255, 224 );
					border-color: rgb( 230, 219, 85 );
				}
				.wppa-featured {
					border: 1px solid;
					background-color: rgb( 224, 255, 224 );
					border-color: rgb( 85, 238, 85 );
				}
				.wppa-pending {
					border: 1px solid;
					background-color: rgb( 255, 235, 232 );
					border-color: rgb( 204, 0, 0 );
				}
			</style>
			<script>
				jQuery( function() {
					jQuery( "#sortable" ).sortable( {
						cursor: "move",
						placeholder: "sortable-placeholder",
						stop: function( event, ui ) {
							var ids = jQuery( ".wppa-sort-item" );
							var seq = jQuery( ".wppa-sort-seqn" );
							var idx = 0;
							var descend = <?php 
            if ($is_descending) {
                echo 'true';
            } else {
                echo 'false';
            }
            ?>
;
							while ( idx < ids.length ) {
								var newvalue;
								if ( descend ) newvalue = ids.length - idx;
								else newvalue = idx + 1;
								var oldvalue = seq[idx].value;
								var photo = ids[idx].value;
								if ( newvalue != oldvalue ) {
									wppaDoSeqUpdate( photo, newvalue );
								}
								idx++;
							}
						}
					} );
				} );
				function wppaDoSeqUpdate( photo, seqno ) {
					var data = 'action=wppa&wppa-action=update-photo&photo-id='+photo+'&item=p_order&wppa-nonce='+document.getElementById( 'photo-nonce-'+photo ).value+'&value='+seqno;
					var xmlhttp = new XMLHttpRequest();

					xmlhttp.onreadystatechange = function() {
						if ( xmlhttp.readyState == 4 && xmlhttp.status != 404 ) {
							var ArrValues = xmlhttp.responseText.split( "||" );
							if ( ArrValues[0] != '' ) {
								alert( 'The server returned unexpected output:\n'+ArrValues[0] );
							}
							switch ( ArrValues[1] ) {
								case '0':	// No error
									jQuery( '#wppa-seqno-'+photo ).html( seqno );
									break;
								case '99':	// Photo is gone
									jQuery( '#wppa-seqno-'+photo ).html( '<span style="color"red" >deleted</span>' );
									break;
								default:	// Any error
									jQuery( '#wppa-seqno-'+photo ).html( '<span style="color"red" >Err:'+ArrValues[1]+'</span>' );
									break;
							}
						}
					}
					xmlhttp.open( 'POST',wppaAjaxUrl,true );
					xmlhttp.setRequestHeader( "Content-type","application/x-www-form-urlencoded" );
					xmlhttp.send( data );
					jQuery( "#wppa-sort-seqn-"+photo ).attr( 'value', seqno );	// set hidden value to new value to prevent duplicate action
					var spinnerhtml = '<img src="'+wppaImageDirectory+'wpspin.gif'+'" />';
					jQuery( '#wppa-seqno-'+photo ).html( spinnerhtml );
				}
			</script>
			<?php 
            if (!$is_p_order) {
                wppa_warning_message(__('Setting photo sequence order has only effect if the photo order method is set to <b>Order#</b>', 'wp-photo-album-plus'));
            }
            ?>
			<div class="widefat" style="border-color:#cccccc" >
				<div id="sortable">
					<?php 
            foreach ($photos as $photo) {
                if (wppa_is_video($photo['id'])) {
                    $imgs['0'] = wppa_get_videox($photo['id']);
                    $imgs['1'] = wppa_get_videoy($photo['id']);
                } else {
                    //							$imgs = getimagesize( wppa_get_thumb_path( $photo['id'] ) );
                    $imgs['0'] = wppa_get_thumbx($photo['id']);
                    $imgs['1'] = wppa_get_thumby($photo['id']);
                }
                if (!$imgs['0']) {
                    // missing thuimbnail, prevent division by zero
                    $imgs['0'] = 200;
                    $imgs['1'] = 150;
                }
                $mw = $size - '20';
                $mh = $mw * '3' / '4';
                if ($imgs[1] / $imgs[0] > $mh / $mw) {
                    // more portrait than 200x150, y is limit
                    $mt = '15';
                } else {
                    // x is limit
                    $mt = ($mh - $imgs[1] / $imgs[0] * $mw) / '2' + '15';
                }
                ?>
					<div id="photoitem-<?php 
                echo $photo['id'];
                ?>
" class="ui-state-default wppa-<?php 
                echo $photo['status'];
                ?>
" style="background-image:none; text-align:center; cursor:move;" >
					<?php 
                if (wppa_is_video($photo['id'])) {
                    ?>
					<?php 
                    $id = $photo['id'];
                    ?>
					<?php 
                    $imgstyle = 'max-width:' . $mw . 'px; max-height:' . $mh . 'px; margin-top:' . $mt . 'px;';
                    ?>
					<?php 
                    echo wppa_get_video_html(array('id' => $id, 'controls' => false, 'tagid' => 'pa-id-' . $id, 'preload' => 'metadata', 'class' => 'wppa-bulk-thumb', 'style' => $imgstyle, 'use_thumb' => true));
                    ?>
	<!--					<video preload="metadata" class="wppa-bulk-thumb" style="max-width:<?php 
                    echo $mw;
                    ?>
px; max-height:<?php 
                    echo $mh;
                    ?>
px; margin-top: <?php 
                    echo $mt;
                    ?>
px;" >
						 // echo //wppa_get_video_body( $photo['id'] ) ?>
						</video>
	-->
					<?php 
                } else {
                    ?>
						<img class="wppa-bulk-thumb" src="<?php 
                    echo wppa_fix_poster_ext(wppa_get_thumb_url($photo['id']), $photo['id']);
                    ?>
" style="max-width:<?php 
                    echo $mw;
                    ?>
px; max-height:<?php 
                    echo $mh;
                    ?>
px; margin-top: <?php 
                    echo $mt;
                    ?>
px;" />
					<?php 
                }
                ?>
						<div style="font-size:9px; position:absolute; bottom:24px; text-align:center; width:<?php 
                echo $size;
                ?>
px;" ><?php 
                echo wppa_get_photo_name($photo['id']);
                ?>
</div>
						<div style="text-align: center; width: <?php 
                echo $size;
                ?>
px; position:absolute; bottom:8px;" >
							<span style="margin-left:15px;float:left"><?php 
                echo __('Id: ', 'wp-photo-album-plus') . $photo['id'];
                ?>
</span>
							<?php 
                if (wppa_is_video($photo['id'])) {
                    _e('Video', 'wp-photo-album-plus');
                }
                ?>
							<?php 
                if (wppa_has_audio($photo['id'])) {
                    _e('Audio', 'wp-photo-album-plus');
                }
                ?>
							<span style="float:right; margin-right:15px;"><?php 
                echo __('Ord: ', 'wp-photo-album-plus') . '<span id="wppa-seqno-' . $photo['id'] . '" >' . $photo['p_order'];
                ?>
</span>
						</div>
						<input type="hidden" id="photo-nonce-<?php 
                echo $photo['id'];
                ?>
" value="<?php 
                echo wp_create_nonce('wppa_nonce_' . $photo['id']);
                ?>
" />
						<input type="hidden" class="wppa-sort-item" value="<?php 
                echo $photo['id'];
                ?>
" />
						<input type="hidden" class="wppa-sort-seqn" id="wppa-sort-seqn-<?php 
                echo $photo['id'];
                ?>
" value="<?php 
                echo $photo['p_order'];
                ?>
" />
					</div>
					<?php 
            }
            ?>
				</div>
				<div style="clear:both;"></div>
			</div>
			<?php 
        } else {
            echo '<h3>' . __('The album is empty.', 'wp-photo-album-plus') . '</h3>';
        }
    } else {
        wppa_dbg_msg('Missing required argument in wppa_album_photos() 3', 'red', 'force');
    }
}