function wppa_is_separate($id) { if ($id == '') { return false; } if (!wppa_is_int($id)) { return false; } if ($id == '-1') { return true; } if ($id < '1') { return false; } $alb = wppa_get_parentalbumid($id); return wppa_is_separate($alb); }
function wppa_album_select_a($args) { global $wpdb; $args = wp_parse_args($args, array('exclude' => '', 'selected' => '', 'disabled' => '', 'addpleaseselect' => false, 'addnone' => false, 'addall' => false, 'addgeneric' => false, 'addblank' => false, 'addselected' => false, 'addseparate' => false, 'addselbox' => false, 'disableancestors' => false, 'checkaccess' => false, 'checkowner' => false, 'checkupload' => false, 'addmultiple' => false, 'addnumbers' => false, 'path' => false, 'root' => false, 'content' => false, 'sort' => true)); // Provide default selection if no selected given if ($args['selected'] === '') { $args['selected'] = wppa_get_last_album(); } // See if selection is valid if ($args['selected'] == $args['exclude'] || $args['checkupload'] && !wppa_allow_uploads($args['selected']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $args['selected'])) { $args['selected'] = '0'; } $albums = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "` " . wppa_get_album_order($args['root']), ARRAY_A); // Add to secondary cache if ($albums) { wppa_cache_album('add', $albums); } if ($albums) { // Filter for root if ($args['root']) { $root = $args['root']; switch ($root) { // case '0': all, will be skipped as it returns false in 'if ( $args['root'] )' case '-2': // Generic only foreach (array_keys($albums) as $albidx) { if (wppa_is_separate($albums[$albidx]['id'])) { unset($albums[$albidx]); } } break; case '-1': // Separate only foreach (array_keys($albums) as $albidx) { if (!wppa_is_separate($albums[$albidx]['id'])) { unset($albums[$albidx]); } } break; default: foreach (array_keys($albums) as $albidx) { if (!wppa_is_ancestor($root, $albums[$albidx]['id'])) { unset($albums[$albidx]); } } break; } } // Filter for must have content if ($args['content']) { foreach (array_keys($albums) as $albidx) { if (wppa_get_photo_count($albums[$albidx]['id']) <= wppa_get_mincount()) { unset($albums[$albidx]); } } } // Add paths if ($args['path']) { $albums = wppa_add_paths($albums); } else { foreach (array_keys($albums) as $index) { $albums[$index]['name'] = __(stripslashes($albums[$index]['name'])); } } // Sort if ($args['sort']) { $albums = wppa_array_sort($albums, 'name'); } } // Output $result = ''; $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addpleaseselect']) { $result .= '<option value="0" disabled="disabled" ' . $selected . ' >' . (is_admin() ? __('- select an album -', 'wppa') : __a('- select an album -')) . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addnone']) { $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- none ---', 'wppa') : __a('--- none ---')) . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addall']) { $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- all ---', 'wppa') : __a('--- all ---')) . '</option>'; } $selected = $args['selected'] == '-2' ? ' selected="selected"' : ''; if ($args['addall']) { $result .= '<option value="-2"' . $selected . ' >' . (is_admin() ? __('--- generic ---', 'wppa') : __a('--- generic ---')) . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addblank']) { $result .= '<option value="0"' . $selected . ' >' . '</option>'; } $selected = $args['selected'] == '-99' ? ' selected="selected"' : ''; if ($args['addmultiple']) { $result .= '<option value="-99"' . $selected . ' >' . (is_admin() ? __('--- multiple see below ---', 'wppa') : __a('--- multiple see below ---')) . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addselbox']) { $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- a selection box ---', 'wppa') : __a('--- a selection box ---')) . '</option>'; } if ($albums) { foreach ($albums as $album) { if ($args['disabled'] == $album['id'] || $args['exclude'] == $album['id'] || $args['checkupload'] && !wppa_allow_uploads($album['id']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $album['id'])) { $disabled = ' disabled="disabled"'; } else { $disabled = ''; } if ($args['selected'] == $album['id'] && !$disabled) { $selected = ' selected="selected"'; } else { $selected = ''; } $ok = true; // Assume this will be in the list if ($args['checkaccess'] && !wppa_have_access($album['id'])) { $ok = false; } if ($args['checkowner'] && wppa_switch('upload_owner_only')) { // Need to check if ($album['owner'] != wppa_get_user() && $album['owner'] != '--- public ---') { // Not 'mine' if (!wppa_user_is('administrator')) { // No admin $ok = false; } } } if ($selected && $args['addselected']) { $ok = true; } if ($ok) { if ($args['addnumbers']) { $number = ' ( ' . $album['id'] . ' )'; } else { $number = ''; } $result .= '<option value="' . $album['id'] . '" ' . $selected . $disabled . '>' . $album['name'] . $number . '</option>'; } } } $selected = $args['selected'] == '-1' ? ' selected="selected"' : ''; if ($args['addseparate']) { $result .= '<option value="-1"' . $selected . '>' . (is_admin() ? __('--- separate ---', 'wppa') : __a('--- separate ---')) . '</option>'; } return $result; }
function wppa_breadcrumb($opt = '') { global $wpdb; global $wppa_session; // See if they need us // Check Table II-A1 a and b if ($opt == 'optional') { $pid = wppa_get_the_page_id(); $type = $wpdb->get_var($wpdb->prepare("SELECT `post_type` FROM `" . $wpdb->posts . "` WHERE `ID` = %s", $pid)); wppa_dbg_q('Q-bc1'); if ($type == 'post' && !wppa_switch('show_bread_posts')) { return; // Nothing to do here } if ($type != 'post' && !wppa_switch('show_bread_pages')) { return; // Nothing to do here } } // Check special cases if (wppa('is_single')) { return; } // A single image slideshow needs no navigation if (wppa_page('oneofone')) { return; } // Never at a single image page if (wppa('is_slideonly')) { return; } // Not when slideonly if (wppa_in_widget()) { return; } // Not in a widget if (is_feed()) { return; } // Not in a feed $thumbhref = ''; // Any special selection has its own switch if (wppa('is_topten') && !wppa_switch('bc_on_topten')) { return; } if (wppa('is_lasten') && !wppa_switch('bc_on_lasten')) { return; } if (wppa('is_comten') && !wppa_switch('bc_on_comten')) { return; } if (wppa('is_featen') && !wppa_switch('bc_on_featen')) { return; } if (wppa('is_related') && !wppa_switch('bc_on_related')) { return; } if (wppa('is_tag') && !wppa_switch('bc_on_tag')) { return; } if (wppa('src') && !wppa_switch('bc_on_search')) { return; } // Get the album number $alb = wppa_is_int(wppa('start_album')) ? wppa('start_album') : '0'; // A single album or all ( all = 0 here ) $is_albenum = strlen(wppa('start_album')) > '0' && !wppa_is_int(wppa('start_album')); wppa_dbg_msg('alb=' . $alb . ', albenum=' . $is_albenum, 'green'); $virtual = wppa_is_virtual() || wppa('last_albums'); if (wppa('last_albums')) { $alb = wppa('last_albums_parent'); } wppa_dbg_msg('alb=' . $alb . ', albenum=' . $is_albenum . ', l_a=' . wppa('last_albums') . ', l_a_p=' . wppa('last_albums_parent'), 'green'); // See if the album is a 'stand alone' album $separate = wppa_is_separate($alb); // See if the album links to slides in stead of thumbnails $slide = wppa_get_album_title_linktype($alb) == 'slide' ? '&wppa-slide' : ''; // See if we link to covers or to contents $to_cover = wppa_opt('thumbtype') == 'none' ? '1' : '0'; // Photo number? $photo = wppa('start_photo'); wppa_dbg_msg('pid=' . $pid . ', type=' . $type . ', alb=' . $alb . ', sep=' . $separate . ', slide=' . $slide . ', t_c=0, ph=' . $photo, 'green'); // Open the breadcrumb box wppa_out('<div' . ' id="wppa-bc-' . wppa('mocc') . '"' . ' class="wppa-nav wppa-box wppa-nav-text" ' . 'style="' . __wcs('wppa-nav') . __wcs('wppa-box') . __wcs('wppa-nav-text') . '" >'); // Do we need Home? if (wppa_switch('show_home')) { $value = __(wppa_opt('home_text')); $href = wppa_dbg_url(get_bloginfo('url')); $title = get_bloginfo('title'); wppa_bcitem($value, $href, $title, 'b1'); } // Page ( grand )parents ? if ($type == 'page' && wppa_switch('show_page')) { wppa_crumb_page_ancestors($pid); } // Do the post/page if (wppa_switch('show_page')) { $value = __(stripslashes($wpdb->get_var($wpdb->prepare("SELECT `post_title` FROM `" . $wpdb->posts . "` WHERE `post_status` = 'publish' AND `ID` = %s LIMIT 0,1", $pid)))); wppa_dbg_q('Q-bc2'); $href = $alb || $virtual || $is_albenum ? wppa_get_permalink($pid, true) : ''; $title = $type == 'post' ? __('Post:', 'wp-photo-album-plus') . ' ' . $value : __('Page:', 'wp-photo-album-plus') . ' ' . $value; wppa_bcitem($value, $href, $title, 'b3'); } // The album ( grand ) parents if not separate // if ( ! $separate ) { wppa_crumb_ancestors($alb, $to_cover); // } // The album and optional placeholder for photo // Supersearch ? if (wppa('supersearch')) { $value = ' '; $ss_data = explode(',', wppa('supersearch')); switch ($ss_data['0']) { case 'a': $value .= ' ' . __('Albums', 'wp-photo-album-plus'); switch ($ss_data['1']) { case 'c': $value .= ' ' . __('with category:', 'wp-photo-album-plus'); break; case 'n': $value .= ' ' . __('with name:', 'wp-photo-album-plus'); break; case 't': $value .= ' ' . __('with words:', 'wp-photo-album-plus'); break; } $value .= ' <b>' . str_replace('.', '</b> ' . __('and', 'wp-photo-album-plus') . ' <b>', $ss_data['3']) . '</b>'; break; case 'p': $value .= ' ' . __('Photos', 'wp-photo-album-plus'); switch ($ss_data['1']) { case 'g': $value .= ' ' . __('with tag:', 'wp-photo-album-plus') . ' <b>' . str_replace('.', '</b> ' . __('and', 'wp-photo-album-plus') . ' <b>', $ss_data['3']) . '</b>'; break; case 'n': $value .= ' ' . __('with name:', 'wp-photo-album-plus') . ' <b>' . $ss_data['3'] . '</b>'; break; case 't': $ss_data['3'] = str_replace('...', '***', $ss_data['3']); $value .= ' ' . __('with words:', 'wp-photo-album-plus') . ' <b>' . str_replace('.', '</b> ' . __('and', 'wp-photo-album-plus') . ' <b>', $ss_data['3']) . '</b>'; $value = str_replace('***', '...', $value); break; case 'o': $value .= ' ' . __('of owner:', 'wp-photo-album-plus') . ' <b>' . $ss_data['3'] . '</b>'; break; case 'i': $label = $wpdb->get_var($wpdb->prepare("SELECT `description` FROM `" . WPPA_IPTC . "` WHERE `tag` = %s AND `photo` = '0'", str_replace('H', '#', $ss_data['2']))); $label = trim($label, ':'); $value .= ' ' . __('with iptc tag:', 'wp-photo-album-plus') . ' <b>' . __($label, 'wp-photo-album-plus') . '</b> ' . __('with content:', 'wp-photo-album-plus') . ' <b>' . $ss_data['3'] . '</b>'; break; case 'e': $label = $wpdb->get_var($wpdb->prepare("SELECT `description` FROM `" . WPPA_EXIF . "` WHERE `tag` = %s AND `photo` = '0'", str_replace('H', '#', $ss_data['2']))); $label = trim($label, ':'); $value .= ' ' . __('with exif tag:', 'wp-photo-album-plus') . ' <b>' . __($label, 'wp-photo-album-plus') . '</b> ' . __('with content:', 'wp-photo-album-plus') . ' <b>' . $ss_data['3'] . '</b>'; break; } break; } if (wppa('is_slide')) { $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-supersearch=' . stripslashes(wppa('supersearch')); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-supersearch=' . stripslashes(wppa('supersearch')); $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $thumbhref, $title, 'b8', $thumbajax); } $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('src') && !wppa('is_related')) { $searchroot = $wppa_session['search_root']; if (!$searchroot) { $searchroot = '-2'; // To get 'All albums' } $albtxt = wppa('is_rootsearch') ? ' <span style="cursor:pointer;" title="' . esc_attr(sprintf(__('Searchresults from album %s and its subalbums', 'wp-photo-album-plus'), wppa_display_root($searchroot))) . '">*</span> ' : ''; if (wppa('is_slide')) { $value = __('Searchstring:', 'wp-photo-album-plus') . ' ' . (isset($wppa_session['display_searchstring']) ? $wppa_session['display_searchstring'] : stripslashes(wppa('searchstring'))) . $albtxt; $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-searchstring=' . stripslashes(str_replace(' ', '+', $wppa_session['use_searchstring'])); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-searchstring=' . stripslashes(str_replace(' ', '+', $wppa_session['use_searchstring'])); $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $thumbhref, $title, 'b8', $thumbajax); } $value = __('Searchstring:', 'wp-photo-album-plus') . ' ' . (isset($wppa_session['display_searchstring']) ? $wppa_session['display_searchstring'] : stripslashes(wppa('searchstring'))) . $albtxt; $href = ''; $title = isset($wppa_session['display_searchstring']) ? wppa_dss_to_title($wppa_session['display_searchstring']) : ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('calendar')) { if (wppa('is_slide')) { switch (wppa('calendar')) { case 'exifdtm': $value = __('Photos by EXIF date', 'wp-photo-album-plus') . ': ' . wppa('caldate'); break; case 'timestamp': $value = __('Photos by date of upload', 'wp-photo-album-plus') . ': ' . date('M d D Y', wppa('caldate') * 24 * 60 * 60); break; case 'modified': $value = __('Photos by date last modified', 'wp-photo-album-plus') . ': ' . date('M d D Y', wppa('caldate') * 24 * 60 * 60); break; } $thumbhref = '#'; $title = 'T8'; wppa_bcitem($value, $thumbhref, $title, 'b8'); } switch (wppa('calendar')) { case 'exifdtm': $value = __('Photos by EXIF date', 'wp-photo-album-plus') . ': ' . wppa('caldate'); break; case 'timestamp': $value = __('Photos by date of upload', 'wp-photo-album-plus') . ': ' . date('M d D Y', wppa('caldate') * 24 * 60 * 60); break; case 'modified': $value = __('Photos by date last modified', 'wp-photo-album-plus') . ': ' . date('M d D Y', wppa('caldate') * 24 * 60 * 60); break; } $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('is_upldr')) { $usr = get_user_by('login', wppa('is_upldr')); if ($usr) { $user = $usr->display_name; } else { $user = wppa('is_upldr'); } if (wppa('is_slide')) { $value = sprintf(__('Photos by %s', 'wp-photo-album-plus'), $user); if (wppa('start_album')) { $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-upldr=' . wppa('is_upldr') . '&wppa-album=' . wppa('start_album'); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-upldr=' . wppa('is_upldr') . '&wppa-album=' . wppa('start_album'); } else { $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-upldr=' . wppa('is_upldr'); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-upldr=' . wppa('is_upldr'); } $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $thumbhref, $title, 'b8', $thumbajax); } $value = sprintf(__('Photos by %s', 'wp-photo-album-plus'), $user); $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('is_topten')) { // TopTen if (wppa('start_album')) { $value = $is_albenum ? __('Various albums', 'wp-photo-album-plus') : wppa_get_album_name($alb); $href = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $ajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $title = $is_albenum ? __('Albums:', 'wp-photo-album-plus') . ' ' . wppa('start_album') : __('Album:', 'wp-photo-album-plus') . ' ' . $value; wppa_bcitem($value, $href, $title, 'b7', $ajax); } if (wppa('is_slide')) { $value = __('Top rated photos', 'wp-photo-album-plus'); $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-topten=' . wppa('topten_count') . '&wppa-album=' . wppa('start_album'); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-topten=' . wppa('topten_count') . '&wppa-album=' . wppa('start_album'); $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $thumbhref, $title, 'b8', $thumbajax); } $value = __('Top rated photos', 'wp-photo-album-plus'); $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('is_lasten')) { // Lasten if (wppa('start_album')) { $value = $is_albenum ? __('Various albums', 'wp-photo-album-plus') : wppa_get_album_name($alb); $href = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $ajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $title = $is_albenum ? __('Albums:', 'wp-photo-album-plus') . ' ' . wppa('start_album') : __('Album:', 'wp-photo-album-plus') . ' ' . $value; wppa_bcitem($value, $href, $title, 'b7', $ajax); } if (wppa('is_slide')) { if (wppa_switch('lasten_use_modified')) { $value = __('Recently modified photos', 'wp-photo-album-plus'); } else { $value = __('Recently uploaded photos', 'wp-photo-album-plus'); } $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-lasten=' . wppa('lasten_count') . '&wppa-album=' . wppa('start_album'); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-lasten=' . wppa('lasten_count') . '&wppa-album=' . wppa('start_album'); $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $thumbhref, $title, 'b8', $thumbajax); } if (wppa_switch('lasten_use_modified')) { $value = __('Recently modified photos', 'wp-photo-album-plus'); } else { $value = __('Recently uploaded photos', 'wp-photo-album-plus'); } $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('is_comten')) { // Comten if (wppa('start_album')) { $value = $is_albenum ? __('Various albums', 'wp-photo-album-plus') : wppa_get_album_name($alb); $href = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $ajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $title = $is_albenum ? __('Albums:', 'wp-photo-album-plus') . ' ' . wppa('start_album') : __('Album:', 'wp-photo-album-plus') . ' ' . $value; wppa_bcitem($value, $href, $title, 'b7', $ajax); } if (wppa('is_slide')) { $value = __('Recently commented photos', 'wp-photo-album-plus'); $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-comten=' . wppa('comten_count') . '&wppa-album=' . wppa('start_album'); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-comten=' . wppa('comten_count') . '&wppa-album=' . wppa('start_album'); $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $thumbhref, $title, 'b8', $thumbajax); } $value = __('Recently commented photos', 'wp-photo-album-plus'); $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('is_featen')) { // Featen if (wppa('start_album')) { $value = $is_albenum ? __('Various albums', 'wp-photo-album-plus') : wppa_get_album_name($alb); $href = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $ajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $title = $is_albenum ? __('Albums:', 'wp-photo-album-plus') . ' ' . wppa('start_album') : __('Album:', 'wp-photo-album-plus') . ' ' . $value; wppa_bcitem($value, $href, $title, 'b7', $ajax); } if (wppa('is_slide')) { $value = __('Featured photos', 'wp-photo-album-plus'); $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-featen=' . wppa('featen_count') . '&wppa-album=' . wppa('start_album'); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-featen=' . wppa('featen_count') . '&wppa-album=' . wppa('start_album'); $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $thumbhref, $title, 'b8', $thumbajax); } $value = __('Featured photos', 'wp-photo-album-plus'); $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('is_related')) { // Related photos if (wppa('is_slide')) { $value = __('Related photos', 'wp-photo-album-plus'); $href = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-tag=' . wppa('is_tag') . '&wppa-album=' . wppa('start_album'); $ajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-tag=' . wppa('is_tag') . '&wppa-album=' . wppa('start_album'); $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $href, $title, 'b8', $ajax); } $value = __('Related photos', 'wp-photo-album-plus'); $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('is_tag')) { // Tagged photos if (wppa('is_slide')) { $value = __('Tagged photos:', 'wp-photo-album-plus') . ' ' . str_replace(';', ' ' . __('or', 'wp-photo-album-plus') . ' ', str_replace(',', ' ' . __('and', 'wp-photo-album-plus') . ' ', trim(wppa('is_tag'), ',;'))); if (wppa_get_get('inv')) { $value .= ' (' . __('Inverted', 'wp-photo-album-plus') . ')'; } $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-tag=' . wppa('is_tag') . '&wppa-album=' . wppa('start_album'); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-tag=' . wppa('is_tag') . '&wppa-album=' . wppa('start_album'); if (wppa('is_inverse')) { $thumbhref .= '&wppa-inv=1'; $thumbajax .= '&wppa-inv=1'; } $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $thumbhref, $title, 'b8', $thumbajax); } $value = __('Tagged photos:', 'wp-photo-album-plus') . ' ' . str_replace(';', ' ' . __('or', 'wp-photo-album-plus') . ' ', str_replace(',', ' ' . __('and', 'wp-photo-album-plus') . ' ', trim(wppa('is_tag'), ',;'))); if (wppa_get_get('inv')) { $value .= ' (' . __('Inverted', 'wp-photo-album-plus') . ')'; } $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('is_cat')) { // Categorized albums if (wppa('is_slide')) { $value = __('Category:', 'wp-photo-album-plus') . ' ' . wppa('is_cat'); //str_replace( ';', ' '.__( 'or' ).' ', str_replace( ',', ' '.__( 'and' ).' ', trim( wppa( 'is_tag' ), ',;' ) ) ); $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-cat=' . wppa('is_cat') . '&wppa-album=' . wppa('start_album'); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-cat=' . wppa('is_cat') . '&wppa-album=' . wppa('start_album'); $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $thumbhref, $title, 'b8', $thumbajax); } $value = __('Category:', 'wp-photo-album-plus') . ' ' . wppa('is_cat'); //str_replace( ';', ' '.__( 'or' ).' ', str_replace( ',', ' '.__( 'and' ).' ', trim( wppa( 'is_tag' ), ',;' ) ) ); $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } elseif (wppa('last_albums')) { // Recently modified albums( s ) if (wppa('last_albums_parent')) { $value = wppa_get_album_name($alb); $href = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $ajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $title = __('Album:', 'wp-photo-album-plus') . ' ' . $value; wppa_bcitem($value, $href, $title, 'b7', $ajax); } if (wppa('is_slide')) { $value = __('Recently updated albums', 'wp-photo-album-plus'); $thumbhref = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $thumbajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $title = __('View the thumbnails', 'wp-photo-album-plus'); wppa_bcitem($value, $thumbhref, $title, 'b8', $thumbajax); } $value = __('Recently updated albums', 'wp-photo-album-plus'); $href = ''; $title = ''; wppa_bcitem($value, $href, $title, 'b9'); } else { // Maybe a simple normal standard album??? if (wppa('is_owner')) { $usr = get_user_by('login', wppa('is_owner')); if ($usr) { $dispname = $usr->display_name; } else { $dispname = wppa('is_owner'); } // User deleted $various = sprintf(__('Various albums by %s', 'wp-photo-album-plus'), $dispname); } else { $various = __('Various albums', 'wp-photo-album-plus'); } if (wppa('is_slide')) { $value = $is_albenum ? $various : wppa_get_album_name($alb); $href = wppa_get_permalink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $ajax = wppa_get_ajaxlink() . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); $title = $is_albenum ? __('Albums:', 'wp-photo-album-plus') . ' ' . wppa('start_album') : __('Album:', 'wp-photo-album-plus') . ' ' . $value; wppa_bcitem($value, $href, $title, 'b7', $ajax); } $value = $is_albenum ? $various : wppa_get_album_name($alb); $href = ''; $title = ''; $class = 'b10'; wppa_bcitem($value, $href, $title, $class); } // 'Go to thumbnail display' - icon if (wppa('is_slide') && !wppa('calendar')) { if (wppa_switch('bc_slide_thumblink')) { // $pg = ( ( wppa_opt('thumb_page_size' ) == wppa_opt( 'slideshow_pagesize' ) ) && wppa_get_curpage() != '1' ) ? '&wppa-page='.wppa_get_curpage() : ''; // $thumbhref .= $pg; if ($virtual) { if ($thumbhref) { $thumbhref = wppa_trim_wppa_($thumbhref); $fs = wppa_opt('fontsize_nav'); if ($fs != '') { $fs += 3; } else { $fs = '15'; } // iconsize = fontsize+3, Default to 15 $imgs = 'height: ' . $fs . 'px; margin:0 0 -3px 0; padding:0; box-shadow:none;'; wppa_out('<a href="' . $thumbhref . '" title="' . __('Thumbnail view', 'wp-photo-album-plus') . '" class="wppa-nav-text" style="' . __wcs('wppa-nav-text') . 'float:right; cursor:pointer;" ' . 'onmouseover="jQuery(\'#wppa-tnv-' . wppa('mocc') . '\').css(\'display\', \'none\'); jQuery(\'#wppa-tnvh-' . wppa('mocc') . '\').css(\'display\', \'\')" ' . 'onmouseout="jQuery(\'#wppa-tnv-' . wppa('mocc') . '\').css(\'display\', \'\'); jQuery(\'#wppa-tnvh-' . wppa('mocc') . '\').css(\'display\', \'none\')" >' . '<img id="wppa-tnv-' . wppa('mocc') . '" class="wppa-tnv" src="' . wppa_get_imgdir() . 'application_view_icons.png" alt="' . __('Thumbs', 'wp-photo-album-plus') . '" style="' . $imgs . '" />' . '<img id="wppa-tnvh-' . wppa('mocc') . '" class="wppa-tnv" src="' . wppa_get_imgdir() . 'application_view_icons_hover.png" alt="' . __('Thumbs', 'wp-photo-album-plus') . '" style="display:none;' . $imgs . '" />' . '</a>'); } } else { $s = wppa('src') ? '&wppa-searchstring=' . urlencode(wppa('searchstring')) : ''; $onclick = "wppaDoAjaxRender( " . wppa('mocc') . ", '" . wppa_get_album_url_ajax(wppa('start_album'), '0') . "&wppa-photos-only=1" . $s . "', '" . wppa_convert_to_pretty(wppa_get_album_url(wppa('start_album'), '0') . '&wppa-photos-only=1' . $s) . "' )"; $fs = wppa_opt('fontsize_nav'); if ($fs != '') { $fs += 3; } else { $fs = '15'; } // iconsize = fontsize+3, Default to 15 $imgs = 'height: ' . $fs . 'px; margin:0 0 -3px 0; padding:0; box-shadow:none;'; wppa_out('<a title="' . __('Thumbnail view', 'wp-photo-album-plus') . '" class="wppa-nav-text" style="' . __wcs('wppa-nav-text') . 'float:right; cursor:pointer;" ' . 'onclick="' . $onclick . '" ' . 'onmouseover="jQuery(\'#wppa-tnv-' . wppa('mocc') . '\').css(\'display\', \'none\'); jQuery(\'#wppa-tnvh-' . wppa('mocc') . '\').css(\'display\', \'\')" ' . 'onmouseout="jQuery(\'#wppa-tnv-' . wppa('mocc') . '\').css(\'display\', \'\'); jQuery(\'#wppa-tnvh-' . wppa('mocc') . '\').css(\'display\', \'none\')" >' . '<img id="wppa-tnv-' . wppa('mocc') . '" class="wppa-tnv" src="' . wppa_get_imgdir() . 'application_view_icons.png" alt="' . __('Thumbs', 'wp-photo-album-plus') . '" style="' . $imgs . '" />' . '<img id="wppa-tnvh-' . wppa('mocc') . '" class="wppa-tnv" src="' . wppa_get_imgdir() . 'application_view_icons_hover.png" alt="' . __('Thumbs', 'wp-photo-album-plus') . '" style="display:none;' . $imgs . '" />' . '</a>'); } } } // Close the breadcrumb box wppa_out('<div style="clear:both;" ></div>'); wppa_out('</div>'); }
function wppa_do_get_thumbs_query($query, $count_first = true) { global $wpdb; // Anything to do here? if (!$query) { wppa('thumb_count', '0'); wppa('any', false); wppa_dbg_msg('Empty query photos', 'red'); return false; } // Init $time = -microtime(true); // Inverse requested? $invers = false; if (wppa('is_inverse')) { $invers = true; } // Do we need to get the count first to dicede if we get the full data and probably cache it ? if ($count_first || $invers) { // First get the count of the result $count = $wpdb->get_var(str_replace('SELECT *', 'SELECT COUNT(*)', $query)); // If less than 2500, get them and cache them if ($count <= 2500 && !$invers) { $thumbs = $wpdb->get_results($query, ARRAY_A); $caching = true; } else { $query = str_replace('SELECT *', 'SELECT `id`', $query); $thumbs = $wpdb->get_results($query, ARRAY_A); $caching = false; } } else { $thumbs = $wpdb->get_results($query, ARRAY_A); $caching = true; $count = empty($thumbs) ? '0' : count($thumbs); } // Inverse selection requested? if ($invers) { $all = $wpdb->get_results("SELECT `id`, `album` FROM `" . WPPA_PHOTOS . "` " . wppa_get_photo_order('0'), ARRAY_A); if (is_array($thumbs)) { foreach (array_keys($thumbs) as $thumbs_key) { foreach (array_keys($all) as $all_key) { if ($thumbs[$thumbs_key]['id'] == $all[$all_key]['id']) { unset($all[$all_key]); } } } } // Exclude separate albums? if (wppa_switch('excl_sep')) { foreach (array_keys($all) as $all_key) { if (wppa_is_separate($all[$all_key]['album'])) { unset($all[$all_key]); } } } // Resequence for slideshow pagination $thumbs = array(); if (!empty($all)) { foreach ($all as $item) { $thumbs[] = $item; } } } // Log query wppa_dbg_q('Q-TG'); wppa_dbg_msg($query); wppa('thumb_count', $count); $time += microtime(true); wppa_dbg_msg('Get thumbs query took ' . $time . ' seconds. ' . 'Found: ' . $count . ' items. ' . 'Mem used=' . ceil(memory_get_peak_usage(true) / (1024 * 1024)) . ' Mb.'); if ($caching) { wppa_cache_photo('add', $thumbs); } wppa('any', !empty($thumbs)); return $thumbs; }
/** @see WP_Widget::widget */ function widget($args, $instance) { global $wpdb; global $wppa_opt; require_once dirname(__FILE__) . '/wppa-links.php'; require_once dirname(__FILE__) . '/wppa-styles.php'; require_once dirname(__FILE__) . '/wppa-functions.php'; require_once dirname(__FILE__) . '/wppa-thumbnails.php'; require_once dirname(__FILE__) . '/wppa-boxes-html.php'; require_once dirname(__FILE__) . '/wppa-slideshow.php'; wppa_initialize_runtime(); wppa('in_widget', 'lasten'); wppa_bump_mocc(); extract($args); $instance = wp_parse_args((array) $instance, array('title' => '', 'album' => '', 'albumenum' => '', 'timesince' => 'yes', 'display' => 'thumbs')); $widget_title = apply_filters('widget_title', $instance['title']); $page = in_array(wppa_opt('lasten_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('wppa_lasten_widget_linkpage', __('Last Ten Uploaded Photos', 'wp-photo-album-plus')); $max = wppa_opt('lasten_count'); $album = $instance['album']; $timesince = $instance['timesince']; $display = $instance['display']; $albumenum = $instance['albumenum']; $generic = $album == '-2'; if ($generic) { $album = '0'; $max += '1000'; } if ($album == '-99') { $album = implode("' OR `album` = '", explode(',', $albumenum)); } // Eiter look at timestamp or at date/time modified $order_by = wppa_switch('lasten_use_modified') ? 'modified' : 'timestamp'; // If you want only 'New' photos in the selection, the period must be <> 0; if (wppa_switch('wppa_lasten_limit_new') && wppa_opt('max_photo_newtime')) { $newtime = " `" . $order_by . "` >= " . (time() - wppa_opt('max_photo_newtime')); if ($album) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE (" . $newtime . ") AND ( `album` = '" . $album . "' ) AND ( `status` <> 'pending' AND `status` <> 'scheduled' ) ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } else { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE (" . $newtime . ") AND `status` <> 'pending' AND `status` <> 'scheduled' ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } } else { if ($album) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( `album` = '" . $album . "' ) AND ( `status` <> 'pending' AND `status` <> 'scheduled' ) ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } else { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` <> 'pending' AND `status` <> 'scheduled' ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } } // echo $q; $thumbs = $wpdb->get_results($q, ARRAY_A); $widget_content = "\n" . '<!-- WPPA+ LasTen Widget start -->'; $maxw = wppa_opt('lasten_size'); $maxh = $maxw; $lineheight = wppa_opt('fontsize_widget_thumb') * 1.5; $maxh += $lineheight; if ($timesince == 'yes') { $maxh += $lineheight; } $count = '0'; if ($thumbs) { foreach ($thumbs as $image) { $thumb = $image; if ($generic && wppa_is_separate($thumb['album'])) { continue; } // Make the HTML for current picture if ($display == 'thumbs') { $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">'; } else { $widget_content .= "\n" . '<div class="wppa-widget" >'; } if ($image) { $no_album = !$album; if ($no_album) { $tit = __('View the most recent uploaded photos', 'wp-photo-album-plus'); } else { $tit = esc_attr(__(stripslashes($image['description']))); } $link = wppa_get_imglnk_a('lasten', $image['id'], '', $tit, '', $no_album, $albumenum); $file = wppa_get_thumb_path($image['id']); $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'ltthumb'); $imgurl = wppa_get_thumb_url($image['id'], '', $imgstyle_a['width'], $imgstyle_a['height']); $imgevents = wppa_get_imgevents('thumb', $image['id'], true); $title = $link ? esc_attr(stripslashes($link['title'])) : ''; $widget_content .= wppa_get_the_widget_thumb('lasten', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents); $widget_content .= "\n\t" . '<div style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; line-height:' . $lineheight . 'px;">'; if ($timesince == 'yes') { $widget_content .= "\n\t" . '<div>' . wppa_get_time_since($image[$order_by]) . '</div>'; } $widget_content .= '</div>'; } else { // No image $widget_content .= __('Photo not found', 'wp-photo-album-plus'); } $widget_content .= "\n" . '</div>'; $count++; if ($count == wppa_opt('lasten_count')) { break; } } } else { $widget_content .= __('There are no uploaded photos (yet)', 'wp-photo-album-plus'); } $widget_content .= '<div style="clear:both"></div>'; $widget_content .= "\n" . '<!-- WPPA+ LasTen Widget end -->'; echo "\n" . $before_widget; if (!empty($widget_title)) { echo $before_title . $widget_title . $after_title; } echo $widget_content . $after_widget; wppa('in_widget', false); }
/** @see WP_Widget::widget */ function widget($args, $instance) { global $wpdb; require_once dirname(__FILE__) . '/wppa-links.php'; require_once dirname(__FILE__) . '/wppa-styles.php'; require_once dirname(__FILE__) . '/wppa-functions.php'; require_once dirname(__FILE__) . '/wppa-thumbnails.php'; require_once dirname(__FILE__) . '/wppa-boxes-html.php'; require_once dirname(__FILE__) . '/wppa-slideshow.php'; wppa_initialize_runtime(); wppa('in_widget', 'tn'); wppa_bump_mocc(); extract($args); $instance = wp_parse_args((array) $instance, array('title' => '', 'album' => 'no', 'link' => '', 'linktitle' => '', 'name' => 'no', 'display' => 'thumbs', 'sortby' => wppa_get_photo_order('0'), 'limit' => wppa_opt('thumbnail_widget_count'))); // $widget_title = apply_filters('widget_title', $instance['title']); $widget_title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base); $widget_link = $instance['link']; $page = in_array(wppa_opt('thumbnail_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('wppa_thumbnail_widget_linkpage', __('Thumbnail photos', 'wp-photo-album-plus')); $max = $instance['limit']; $sortby = $instance['sortby']; $album = $instance['album']; $name = $instance['name']; $display = $instance['display']; $linktitle = $instance['linktitle']; $generic = $album == '-2'; if ($generic) { $album = '0'; $max += '1000'; } $separate = $album == '-1'; if ($separate) { $album = '0'; $max += '1000'; } if ($album) { $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` <> 'pending' AND `status` <> 'scheduled' AND `album` = %s " . $sortby . " LIMIT %d", $album, $max), 'ARRAY_A'); } else { $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` <> 'pending' AND `status` <> 'scheduled'" . $sortby . " LIMIT %d", $max), 'ARRAY_A'); } global $widget_content; $widget_content = "\n" . '<!-- WPPA+ thumbnail Widget start -->'; $maxw = wppa_opt('thumbnail_widget_size'); $maxh = $maxw; $lineheight = wppa_opt('fontsize_widget_thumb') * 1.5; $maxh += $lineheight; if ($name == 'yes') { $maxh += $lineheight; } $count = '0'; if ($thumbs) { foreach ($thumbs as $image) { $thumb = $image; if ($generic && wppa_is_separate($thumb['album'])) { continue; } if ($separate && !wppa_is_separate($thumb['album'])) { continue; } // Make the HTML for current picture if ($display == 'thumbs') { $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">'; } else { $widget_content .= "\n" . '<div class="wppa-widget" >'; } if ($image) { $link = wppa_get_imglnk_a('tnwidget', $image['id']); $file = wppa_get_thumb_path($image['id']); $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'twthumb'); $imgurl = wppa_get_thumb_url($image['id'], '', $imgstyle_a['width'], $imgstyle_a['height']); $imgevents = wppa_get_imgevents('thumb', $image['id'], true); $title = $link ? esc_attr(stripslashes($link['title'])) : ''; wppa_do_the_widget_thumb('thumbnail', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents); $widget_content .= "\n\t" . '<div style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; line-height:' . $lineheight . 'px;">'; if ($name == 'yes' && $display == 'thumbs') { $widget_content .= "\n\t" . '<div>' . __(stripslashes($image['name']), 'wp-photo-album-plus') . '</div>'; } $widget_content .= "\n\t" . '</div>'; } else { // No image $widget_content .= __('Photo not found', 'wp-photo-album-plus'); } $widget_content .= "\n" . '</div>'; $count++; if ($count == $instance['limit']) { break; } } } else { $widget_content .= __('There are no photos (yet)', 'wp-photo-album-plus'); } $widget_content .= '<div style="clear:both"></div>'; $widget_content .= "\n" . '<!-- WPPA+ thumbnail Widget end -->'; echo "\n" . $before_widget; if (!empty($widget_title)) { echo $before_title; if (!empty($widget_link)) { echo "\n" . '<a href="' . $widget_link . '" title="' . $linktitle . '" >' . $widget_title . '</a>'; } else { echo $widget_title; } echo $after_title; } echo $widget_content . $after_widget; wppa('in_widget', false); }
/** @see WP_Widget::widget */ function widget($args, $instance) { global $wpdb; global $wppa_opt; global $wppa; require_once dirname(__FILE__) . '/wppa-links.php'; require_once dirname(__FILE__) . '/wppa-styles.php'; require_once dirname(__FILE__) . '/wppa-functions.php'; require_once dirname(__FILE__) . '/wppa-thumbnails.php'; require_once dirname(__FILE__) . '/wppa-boxes-html.php'; require_once dirname(__FILE__) . '/wppa-slideshow.php'; wppa_initialize_runtime(); extract($args); $instance = wp_parse_args((array) $instance, array('title' => '', 'album' => '')); $widget_title = apply_filters('widget_title', $instance['title']); $page = in_array($wppa_opt['wppa_featen_widget_linktype'], $wppa['links_no_page']) ? '' : wppa_get_the_landing_page('wppa_featen_widget_linkpage', __a('Featured photos')); $max = $wppa_opt['wppa_featen_count']; $album = $instance['album']; $generic = $album == '-2'; if ($generic) { $album = '0'; $max += '1000'; } if ($album) { $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status`= 'featured' AND `album` = %s ORDER BY RAND(" . wppa_get_randseed() . ") DESC LIMIT " . $max, $album), ARRAY_A); } else { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'featured' ORDER BY RAND(" . wppa_get_randseed() . ") DESC LIMIT " . $max, ARRAY_A); } $widget_content = "\n" . '<!-- WPPA+ FeaTen Widget start -->'; $maxw = $wppa_opt['wppa_featen_size']; $maxh = $maxw; $lineheight = $wppa_opt['wppa_fontsize_widget_thumb'] * 1.5; $maxh += $lineheight; if (false) { $maxh += $lineheight; } $count = '0'; if ($thumbs) { foreach ($thumbs as $image) { global $thumb; $thumb = $image; if ($generic && wppa_is_separate($thumb['album'])) { continue; } // Make the HTML for current picture $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">'; if ($image) { $no_album = !$album; if ($no_album) { $tit = __a('View the featured photos', 'wppa_theme'); } else { $tit = esc_attr(wppa_qtrans(stripslashes($image['description']))); } $link = wppa_get_imglnk_a('featen', $image['id'], '', $tit, '', $no_album); $file = wppa_get_thumb_path($image['id']); $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'ttthumb'); $imgstyle = $imgstyle_a['style']; $width = $imgstyle_a['width']; $height = $imgstyle_a['height']; $cursor = $imgstyle_a['cursor']; $imgurl = wppa_get_thumb_url($image['id'], '', $width, $height); $imgevents = wppa_get_imgevents('thumb', $image['id'], true); if ($link) { $title = esc_attr(stripslashes($link['title'])); } else { $title = ''; } $album = '0'; $display = 'thumbs'; $widget_content .= wppa_get_the_widget_thumb('featen', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents); } else { // No image $widget_content .= __a('Photo not found.', 'wppa_theme'); } $widget_content .= "\n" . '</div>'; $count++; if ($count == $wppa_opt['wppa_featen_count']) { break; } } } else { $widget_content .= 'There are no featured photos (yet).'; } $widget_content .= '<div style="clear:both"></div>'; $widget_content .= "\n" . '<!-- WPPA+ FeaTen Widget end -->'; echo "\n" . $before_widget; if (!empty($widget_title)) { echo $before_title . $widget_title . $after_title; } echo $widget_content . $after_widget; }
function wppa_album_select_a($args) { global $wpdb; $args = wp_parse_args($args, array('exclude' => '', 'selected' => '', 'disabled' => '', 'addpleaseselect' => false, 'addnone' => false, 'addall' => false, 'addgeneric' => false, 'addblank' => false, 'addselected' => false, 'addseparate' => false, 'addselbox' => false, 'addowner' => false, 'disableancestors' => false, 'checkaccess' => false, 'checkowner' => false, 'checkupload' => false, 'addmultiple' => false, 'addnumbers' => false, 'path' => false, 'root' => false, 'content' => false, 'sort' => true, 'checkarray' => false, 'array' => array(), 'optionclass' => '')); // Provide default selection if no selected given if ($args['selected'] === '') { $args['selected'] = wppa_get_last_album(); } // See if selection is valid if ($args['selected'] == $args['exclude'] || $args['checkupload'] && !wppa_allow_uploads($args['selected']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $args['selected'])) { $args['selected'] = '0'; } // Get roughly the albums that might be in the selection if ($args['checkarray'] && !empty($args['array'])) { $albums = $wpdb->get_results("SELECT `id`, `name` " . "FROM `" . WPPA_ALBUMS . "` " . "WHERE `id` IN (" . implode(',', $args['array']) . ") " . ($args['checkowner'] && wppa_switch('upload_owner_only') && !wppa_user_is('administrator') ? "AND `owner` IN ( '--- public ---', '" . wppa_get_user() . "' ) " : "") . wppa_get_album_order($args['root']), ARRAY_A); } else { $albums = $wpdb->get_results("SELECT `id`, `name` " . "FROM `" . WPPA_ALBUMS . "` " . ($args['checkowner'] && wppa_switch('upload_owner_only') && !wppa_user_is('administrator') ? "WHERE `owner` IN ( '--- public ---', '" . wppa_get_user() . "' ) " : "") . wppa_get_album_order($args['root']), ARRAY_A); } /* Can not add to cache because only "SELECT * " can be added // Add to secondary cache if ( $albums ) { wppa_cache_album( 'add', $albums ); } */ if ($albums) { // Filter for root if ($args['root']) { $root = $args['root']; switch ($root) { // case '0': all, will be skipped as it returns false in 'if ( $args['root'] )' case '-2': // Generic only foreach (array_keys($albums) as $albidx) { if (wppa_is_separate($albums[$albidx]['id'])) { unset($albums[$albidx]); } } break; case '-1': // Separate only foreach (array_keys($albums) as $albidx) { if (!wppa_is_separate($albums[$albidx]['id'])) { unset($albums[$albidx]); } } break; default: foreach (array_keys($albums) as $albidx) { if (!wppa_is_ancestor($root, $albums[$albidx]['id'])) { unset($albums[$albidx]); } } break; } } // Filter for must have content if ($args['content']) { foreach (array_keys($albums) as $albidx) { if (wppa_get_photo_count($albums[$albidx]['id']) <= wppa_get_mincount()) { unset($albums[$albidx]); } } } // Add paths if ($args['path']) { $albums = wppa_add_paths($albums); } else { foreach (array_keys($albums) as $index) { $albums[$index]['name'] = __(stripslashes($albums[$index]['name'])); } } // Sort if ($args['sort']) { $albums = wppa_array_sort($albums, 'name'); } } // Output $result = ''; $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addpleaseselect']) { $result .= '<option value="0" disabled="disabled" ' . $selected . ' >' . __('- select an album -', 'wp-photo-album-plus') . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addnone']) { $result .= '<option value="0"' . $selected . ' >' . __('--- none ---', 'wp-photo-album-plus') . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addall']) { $result .= '<option value="0"' . $selected . ' >' . __('--- all ---', 'wp-photo-album-plus') . '</option>'; } $selected = $args['selected'] == '-2' ? ' selected="selected"' : ''; if ($args['addall']) { $result .= '<option value="-2"' . $selected . ' >' . __('--- generic ---', 'wp-photo-album-plus') . '</option>'; } $selected = $args['selected'] == '-3' ? ' selected="selected"' : ''; if ($args['addowner']) { $result .= '<option value="-3"' . $selected . ' >' . __('--- owner/public ---', 'wp-photo-album-plus') . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addblank']) { $result .= '<option value="0"' . $selected . ' >' . '</option>'; } $selected = $args['selected'] == '-99' ? ' selected="selected"' : ''; if ($args['addmultiple']) { $result .= '<option value="-99"' . $selected . ' >' . __('--- multiple see below ---', 'wp-photo-album-plus') . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addselbox']) { $result .= '<option value="0"' . $selected . ' >' . __('--- a selection box ---', 'wp-photo-album-plus') . '</option>'; } // In case multiple if (strpos($args['selected'], ',') !== false) { $selarr = explode(',', $args['selected']); } else { $selarr = array($args['selected']); } if ($albums) { foreach ($albums as $album) { if ($args['disabled'] == $album['id'] || $args['exclude'] == $album['id'] || $args['checkupload'] && !wppa_allow_uploads($album['id']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $album['id'])) { $disabled = ' disabled="disabled"'; } else { $disabled = ''; } if (in_array($album['id'], $selarr, true) && !$disabled) { $selected = ' selected="selected"'; } else { $selected = ''; } $ok = true; // Assume this will be in the list if ($args['checkaccess'] && !wppa_have_access($album['id'])) { $ok = false; } /* This is in the query now if ( $args['checkowner'] && wppa_switch( 'upload_owner_only' ) ) { // Need to check if ( $album['owner'] != wppa_get_user() && $album['owner'] != '--- public ---' ) { // Not 'mine' if ( ! wppa_user_is( 'administrator' ) ) { // No admin $ok = false; } } } */ /* This is in the query now if ( $args['checkarray'] ) { if ( ! in_array( $album['id'], $args['array'] ) ) { $ok = false; } } */ if ($selected && $args['addselected']) { $ok = true; } if ($ok) { if ($args['addnumbers']) { $number = ' ( ' . $album['id'] . ' )'; } else { $number = ''; } $result .= '<option class="' . $args['optionclass'] . '" value="' . $album['id'] . '" ' . $selected . $disabled . '>' . $album['name'] . $number . '</option>'; } } } $selected = $args['selected'] == '-1' ? ' selected="selected"' : ''; if ($args['addseparate']) { $result .= '<option value="-1"' . $selected . '>' . __('--- separate ---', 'wp-photo-album-plus') . '</option>'; } return $result; }
function wppa_get_thumbs() { global $wpdb; global $wppa; global $thumbs; global $wppa_session; if ($wppa['is_owner'] && !$wppa['start_album']) { return false; } // No owner album( s ) -> no photos wppa_dbg_msg('get_thumbs entered: ' . $wppa['mocc'] . ' Start_album=' . $wppa['start_album'] . ', Cover=' . $wppa['is_cover']); if ($wppa['is_cover']) { wppa_dbg_msg('its cover, leave get_thumbs'); return; } if ($wppa['albums_only']) { return false; } if (is_array($thumbs)) { // Done already? wppa_dbg_msg('cached thumbs used'); return $thumbs; } $time = -microtime(true); // See if album is an enumeration or range $fullalb = $wppa['start_album']; // Assume not if (strpos($fullalb, '.') !== false) { $ids = wppa_series_to_array($fullalb); $fullalb = implode(' OR `album` = ', $ids); } // Single image slideshow? if ($wppa['start_photo'] && $wppa['is_single']) { $thumbs = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `id` = %s', $wppa['start_photo']), ARRAY_A); wppa_dbg_q('Q-SIS'); } elseif ($wppa['is_upldr']) { $max = '1000000'; $alb = $fullalb; $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } if ($alb) { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( `album` = " . $alb . " ) AND `owner` = %s AND ( ( " . $status . " ) OR `owner` = %s ) ORDER BY `timestamp` DESC LIMIT %d", $wppa['is_upldr'], wppa_get_user(), $max); //, ARRAY_A ); } else { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s AND ( ( " . $status . " ) OR `owner` = %s ) ORDER BY `timestamp` DESC LIMIT %d", $wppa['is_upldr'], wppa_get_user(), $max); //, ARRAY_A ); } $thumbs = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q-UPL'); } elseif ($wppa['is_topten']) { $max = $wppa['topten_count']; $alb = $fullalb; switch (wppa_opt('topten_sortby')) { case 'mean_rating': $sortby = '`mean_rating` DESC, `rating_count` DESC, `views` DESC'; break; case 'rating_count': $sortby = '`rating_count` DESC, `mean_rating` DESC, `views` DESC'; break; case 'views': $sortby = '`views` DESC, `mean_rating` DESC, `rating_count` DESC'; break; default: wppa_error_message('Unimplemented sorting method'); $sortby = ''; break; } $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } if ($alb) { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( `album` = " . $alb . " AND " . $status . " ) ORDER BY " . $sortby . " LIMIT " . $max, ARRAY_A); } else { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( " . $status . " ) ORDER BY " . $sortby . " LIMIT " . $max, ARRAY_A); } wppa_dbg_q('Q-TT'); } elseif ($wppa['is_featen']) { $max = $wppa['featen_count']; $alb = $fullalb; if ($alb) { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'featured' AND ( `album` = " . $alb . " ) ORDER BY RAND( " . wppa_get_randseed() . " ) DESC LIMIT " . $max, ARRAY_A); } else { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'featured' ORDER BY RAND( " . wppa_get_randseed() . " ) DESC LIMIT " . $max, ARRAY_A); } wppa_dbg_q('Q-FT'); } elseif ($wppa['is_lasten']) { $max = $wppa['lasten_count']; $alb = $fullalb; $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } // If you want only 'New' photos in the selection, the period must be <> 0; if (wppa_switch('wppa_lasten_limit_new') && wppa_opt('max_photo_newtime')) { $newtime = " `timestamp` >= " . (time() - wppa_opt('max_photo_newtime')); if (current_user_can('wppa_moderate')) { if ($alb) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( `album` = " . $alb . " ) AND (" . $newtime . ") ORDER BY `timestamp` DESC LIMIT " . $max; } else { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $newtime . " ORDER BY `timestamp` DESC LIMIT " . $max; } } else { if ($alb) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( `album` = " . $alb . " ) AND ( " . $status . " ) AND ( " . $newtime . " ) ORDER BY `timestamp` DESC LIMIT " . $max; } else { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( " . $status . " ) AND (" . $newtime . ") ORDER BY `timestamp` DESC LIMIT " . $max; } } } else { if (current_user_can('wppa_moderate')) { if ($alb) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = " . $alb . " ORDER BY `timestamp` DESC LIMIT " . $max; } else { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` ORDER BY `timestamp` DESC LIMIT " . $max; } } else { if ($alb) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( `album` = " . $alb . " ) AND ( " . $status . " ) ORDER BY `timestamp` DESC LIMIT " . $max; } else { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $status . " ORDER BY `timestamp` DESC LIMIT " . $max; } } } // echo $q; $thumbs = $wpdb->get_results($q, ARRAY_A); wppa_dbg_q('Q-LT'); } elseif ($wppa['is_comten']) { $alb_ids = $wppa['start_album']; if (strpos($alb_ids, '.') !== false) { $alb_ids = wppa_series_to_array($alb_ids); } $photo_ids = wppa_get_comten_ids($wppa['comten_count'], (array) $alb_ids); $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } $thumbs = array(); if (is_array($photo_ids)) { foreach ($photo_ids as $id) { $temp = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $status . " AND `id` = %s", $id), ARRAY_A); if ($temp) { $thumbs[] = $temp; } } } } elseif ($wppa['is_tag']) { $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } if (current_user_can('wppa_moderate')) { $temp = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `tags` <> '' " . wppa_get_photo_order('0'), ARRAY_A); } else { $temp = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $status . " AND `tags` <> '' " . wppa_get_photo_order('0'), ARRAY_A); } wppa_dbg_q('Q-TG'); $tags = wppa_get_taglist(); $thumbs = false; $andor = 'and'; if (strpos($wppa['is_tag'], ';')) { $andor = 'or'; } foreach (array_keys($temp) as $index) { if ($andor == 'and') { // and $seltags = explode(',', $wppa['is_tag']); $in = true; if ($seltags) { foreach ($seltags as $seltag) { if ($seltag && !@in_array($temp[$index]['id'], $tags[$seltag]['ids'])) { $in = false; } } } } else { // or $seltags = explode(';', $wppa['is_tag']); $in = false; if ($seltags) { foreach ($seltags as $seltag) { if ($seltag && @in_array($temp[$index]['id'], $tags[$seltag]['ids'])) { $in = true; } } } } if ($in) { if ($wppa['is_related'] != 'tags' || count($thumbs) < $wppa['related_count']) { $thumbs[] = $temp[$index]; } } } wppa_dbg_msg('Found:' . count($thumbs) . ' thumbs'); } elseif ($wppa['supersearch']) { $ss_data = explode(',', $wppa['supersearch']); $data = $ss_data['3']; $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } switch ($ss_data['1']) { // Name case 'n': $is = '='; if (substr($data, -3) == '...') { $data = substr($data, 0, strlen($data) - 3) . '%'; $is = 'LIKE'; } if (current_user_can('wppa_moderate')) { $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `name` " . $is . " %s " . wppa_get_photo_order('0'), $data), ARRAY_A); } else { $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `name` " . $is . " %s AND " . $status . " " . wppa_get_photo_order('0'), $data), ARRAY_A); } wppa_dbg_q('Q-SS'); break; // Owner // Owner case 'o': if (current_user_can('wppa_moderate')) { $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s " . wppa_get_photo_order('0'), $data), ARRAY_A); } else { $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s AND " . $status . " " . wppa_get_photo_order('0'), $data), ARRAY_A); } wppa_dbg_q('Q-SS'); break; // Tag // Tag case 'g': $taglist = wppa_get_taglist(); if (strpos($data, '.')) { $qtags = explode('.', $data); $tagids = $taglist[$qtags['0']]['ids']; $i = '0'; while ($i < count($qtags)) { $tagids = array_intersect($tagids, $taglist[$qtags[$i]]['ids']); $i++; } } else { $tagids = $taglist[$data]['ids']; } if (count($tagids) > '0') { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $status . " AND `id` IN (" . implode(',', $tagids) . ")"; $thumbs = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q-SS'); } break; // Text // Text case 't': // To distinguish items with ellipses, we temporary replace them with *** $data = str_replace('...', '***', $data); if (strpos($data, '.')) { $temp = explode('.', $data); $is = '='; if (wppa_opt('ss_text_max')) { if (substr($temp['0'], -3) == '***') { $temp['0'] = substr($temp['0'], 0, strlen($temp['0']) - 3) . '%'; $is = 'LIKE'; } } $query = $wpdb->prepare("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` " . $is . " %s", $temp['0']); $indexes = $wpdb->get_results($query, ARRAY_A); $ids = array(); foreach ($indexes as $item) { $ids = array_merge($ids, explode('.', wppa_expand_enum($item['photos']))); } $i = '1'; while ($i < count($temp)) { $is = '='; if (wppa_opt('ss_text_max')) { if (substr($temp[$i], -3) == '***') { $temp[$i] = substr($temp[$i], 0, strlen($temp[$i]) - 3) . '%'; $is = 'LIKE'; } } $query = $wpdb->prepare("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` " . $is . " %s", $temp[$i]); $indexes = $wpdb->get_results($query, ARRAY_A); $deltaids = array(); foreach ($indexes as $item) { $deltaids = array_merge($deltaids, explode('.', wppa_expand_enum($item['photos']))); } $ids = array_intersect($ids, $deltaids); $i++; } } else { $is = '='; if (wppa_opt('ss_text_max')) { if (substr($data, -3) == '***') { $data = substr($data, 0, strlen($data) - 3) . '%'; $is = 'LIKE'; } } $query = $wpdb->prepare("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` " . $is . " %s", $data); $indexes = $wpdb->get_results($query, ARRAY_A); $ids = array(); foreach ($indexes as $item) { $ids = array_merge($ids, explode('.', wppa_expand_enum($item['photos']))); } } if (empty($ids)) { $ids = array('0'); // Dummy } $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $status . " AND `id` IN (" . implode(',', $ids) . ")"; $thumbs = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q_SS'); break; // Iptc // Iptc case 'i': $itag = str_replace('H', '#', $ss_data['2']); $desc = $ss_data['3']; $query = $wpdb->prepare("SELECT * FROM `" . WPPA_IPTC . "` WHERE `tag` = %s AND `description` = %s", $itag, $desc); $iptclines = $wpdb->get_results($query, ARRAY_A); $ids = '0'; if (is_array($iptclines)) { foreach ($iptclines as $item) { $ids .= ',' . $item['photo']; } } $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $status . " AND `id` IN (" . $ids . ")"; $thumbs = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q_SS'); break; // Exif // Exif case 'e': $etag = str_replace('H', '#', $ss_data['2']); $desc = $ss_data['3']; $query = $wpdb->prepare("SELECT * FROM `" . WPPA_EXIF . "` WHERE `tag` = %s AND `description` = %s", $etag, $desc); $exiflines = $wpdb->get_results($query, ARRAY_A); $ids = '0'; if (is_array($exiflines)) { foreach ($exiflines as $item) { $ids .= ',' . $item['photo']; } } $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $status . " AND `id` IN (" . $ids . ")"; $thumbs = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q_SS'); break; } } elseif ($wppa['src']) { // Searching $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } $searchstring = $wppa['searchstring']; if (isset($wppa_session['use_searchstring']) && !empty($wppa_session['use_searchstring'])) { $searchstring = $wppa_session['use_searchstring']; } // Indexed search?? // if ( wppa_switch( 'indexed_search' ) ) { $final_array = array(); $chunks = explode(',', stripslashes(strtolower($searchstring))); // all chunks foreach ($chunks as $chunk) { if (strlen(trim($chunk))) { $words = wppa_index_raw_to_words($chunk); $photo_array = array(); // all words in the searchstring foreach ($words as $word) { $word = trim($word); if (strlen($word) > 1) { if (strlen($word) > 20) { $word = substr($word, 0, 20); } if (wppa_switch('wild_front')) { $pidxs = $wpdb->get_results("SELECT `slug`, `photos` FROM `" . WPPA_INDEX . "` WHERE `slug` LIKE '%" . $word . "%'", ARRAY_A); } else { $pidxs = $wpdb->get_results("SELECT `slug`, `photos` FROM `" . WPPA_INDEX . "` WHERE `slug` LIKE '" . $word . "%'", ARRAY_A); } wppa_dbg_q('Q-IX'); $photos = ''; if ($pidxs) { foreach ($pidxs as $pi) { $photos .= $pi['photos'] . ','; } } $photo_array[] = wppa_index_string_to_array(trim($photos, ',')); } } // Must meet all words: intersect photo sets foreach (array_keys($photo_array) as $idx) { if ($idx > '0') { $photo_array['0'] = array_intersect($photo_array['0'], $photo_array[$idx]); } } // Save partial result if (isset($photo_array['0'])) { $final_array = array_merge($final_array, $photo_array['0']); } } } // Compose WHERE clause $selection = " `id` = '0' "; $count = '0'; foreach (array_keys($final_array) as $p) { if (wppa_opt('max_search_photos')) { $selection .= "OR `id` = '" . $final_array[$p] . "' "; $count++; } } // Get them, depending of 'pending' criteria if (current_user_can('wppa_moderate')) { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $selection . wppa_get_photo_order('0'), ARRAY_A); } else { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $status . " AND ( " . $selection . " ) " . wppa_get_photo_order('0'), ARRAY_A); } wppa_dbg_q('Q-SR'); // Check on seperate albums? if (wppa_switch('excl_sep')) { $broken = false; foreach (array_keys($thumbs) as $idx) { $alb = $thumbs[$idx]['album']; if (wppa_is_separate($alb)) { unset($thumbs[$idx]); $broken = true; } } // Sequence broken?, create new indexes for thumbs array if ($broken) { $temp = $thumbs; $thumbs = array(); foreach ($temp as $item) { $thumbs[] = $item; } } } // } /* else { // Conventional search if ( current_user_can( 'wppa_moderate' ) ) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` " . wppa_get_photo_order( '0' ); } else { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` <> 'pending' AND `status` <> 'scheduled' " . wppa_get_photo_order( '0' ); } $tmbs = $wpdb->get_results( $q, ARRAY_A ); wppa_dbg_q( 'Q-SR' ); $thumbs = array(); foreach ( $tmbs as $thumb ) { if ( ! wppa_switch( 'excl_sep' ) || ! wppa_is_separate( $thumb['album'] ) ) { // Not exclude sepreate or not seperate $haystack = __( $thumb['name'] ).' '.wppa_filter_exif( wppa_filter_iptc( __( stripslashes( $thumb['description'] ) ),$thumb['id'] ),$thumb['id'] ); if ( wppa_switch( 'search_tags' ) ) { $haystack .= ' '.str_replace( ',', ' ', $thumb['tags'] ); } if ( wppa_switch( 'search_comments' ) ) { $comms = $wpdb->get_results( $wpdb->prepare( " SELECT * FROM `".WPPA_COMMENTS."` WHERE `photo` = %s", $thumb['id'] ), ARRAY_A ); wppa_dbg_q( 'Q-CM' ); if ( $comms ) foreach ( $comms as $comm ) { $haystack .= $comm['comment']; } } if ( wppa_deep_stristr( strtolower( $haystack ), $searchstring ) ) { $thumbs[] = $thumb; } } } } // end conventional search */ // Rootsearch? if ($wppa['is_rootsearch'] && isset($wppa_session['search_root'])) { // Find all albums below root $root = $wppa_session['search_root']; $albs = array($root); $albs = array_merge($albs, wppa_get_all_children($root)); // Now remove the thumbs that are not in any of these albums $c1 = count($thumbs); $broken = false; foreach (array_keys($thumbs) as $idx) { if (!in_array($thumbs[$idx]['album'], $albs)) { unset($thumbs[$idx]); $broken = true; } } $c2 = count($thumbs); wppa_dbg_msg('Rootsearch thumbs:' . $c1 . ' -> ' . $c2); // Sequence broken?, create new indexes for thumbs array. required for filmstrip to be able to use the cached thumbs. It relies on uninterrupted sequence if ($broken) { $temp = $thumbs; $thumbs = array(); foreach ($temp as $item) { $thumbs[] = $item; } } } // Check maximum if (is_array($thumbs) && count($thumbs) > wppa_opt('max_search_photos') && wppa_opt('max_search_photos') != '0') { $alert_text = sprintf(__a('There are %s photos found. Only the first %s will be shown. Please refine your search criteria.'), count($thumbs), wppa_opt('max_search_photos')); wppa_alert($alert_text); foreach (array_keys($thumbs) as $idx) { if ($idx >= wppa_opt('max_search_photos')) { unset($thumbs[$idx]); } } } $wppa['any'] = !empty($thumbs); } else { // Not search, normal // Init $thumbs $thumbs = array(); // Status $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } // On which album( s )? if (strpos($wppa['start_album'], '.') !== false) { $allalb = wppa_series_to_array($wppa['start_album']); } else { $allalb = false; } wppa_dbg_msg('Startalbum = ' . $wppa['start_album'], 'red'); /* Nieuwe versie */ // All albums ? if ($wppa['start_album'] == -2) { if (current_user_can('wppa_moderate')) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` " . wppa_get_photo_order('0'); } else { $q = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( ( " . $status . " ) OR `owner` = %s ) " . wppa_get_photo_order('0'), wppa_get_user()); } wppa_dbg_msg('Q-PH1 ' . $q); wppa_dbg_q('Q-PH1'); $thumbs = $wpdb->get_results($q, ARRAY_A); } elseif (wppa_is_int($wppa['start_album'])) { if (current_user_can('wppa_moderate')) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = " . $wppa['start_album'] . " " . wppa_get_photo_order($wppa['start_album']); } else { $q = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( ( " . $status . " ) OR `owner` = %s ) AND `album` = " . $wppa['start_album'] . " " . wppa_get_photo_order($wppa['start_album']), wppa_get_user()); } wppa_dbg_msg('Q-PH2 ' . $q); wppa_dbg_q('Q-PH2'); $thumbs = $wpdb->get_results($q, ARRAY_A); } elseif (is_array($allalb)) { $wherealbum = ' `album` IN (' . implode(',', $allalb) . ') '; if (current_user_can('wppa_moderate')) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $wherealbum . " " . wppa_get_photo_order('0'); } else { $q = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE ( ( " . $status . " ) OR `owner` = %s ) AND " . $wherealbum . " " . wppa_get_photo_order('0'), wppa_get_user()); } wppa_dbg_msg('Q-PH3 ' . $q); wppa_dbg_q('Q-PH3'); $thumbs = $wpdb->get_results($q, ARRAY_A); } else { $thumbs = array(); } } $wppa['thumb_count'] = empty($thumbs) ? '0' : count($thumbs); $time += microtime(true); wppa_dbg_msg('Get thumbs took ' . $time . ' seconds, found: ' . $wppa['thumb_count'] . ' items.'); wppa_cache_photo('add', $thumbs); return $thumbs; }