function wppa_get_keywords($id) { static $wppa_void_keywords; if (!$id) { return ''; } if (empty($wppa_void_keywords)) { $wppa_void_keywords = array(__('Not Defined', 'wp-photo-album-plus'), __('Manual', 'wp-photo-album-plus'), __('Program AE', 'wp-photo-album-plus'), __('Aperture-priority AE', 'wp-photo-album-plus'), __('Shutter speed priority AE', 'wp-photo-album-plus'), __('Creative (Slow speed)', 'wp-photo-album-plus'), __('Action (High speed)', 'wp-photo-album-plus'), __('Portrait', 'wp-photo-album-plus'), __('Landscape', 'wp-photo-album-plus'), __('Bulb', 'wp-photo-album-plus'), __('Average', 'wp-photo-album-plus'), __('Center-weighted average', 'wp-photo-album-plus'), __('Spot', 'wp-photo-album-plus'), __('Multi-spot', 'wp-photo-album-plus'), __('Multi-segment', 'wp-photo-album-plus'), __('Partial', 'wp-photo-album-plus'), __('Other', 'wp-photo-album-plus'), __('No Flash', 'wp-photo-album-plus'), __('Fired', 'wp-photo-album-plus'), __('Fired, Return not detected', 'wp-photo-album-plus'), __('Fired, Return detected', 'wp-photo-album-plus'), __('On, Did not fire', 'wp-photo-album-plus'), __('On, Fired', 'wp-photo-album-plus'), __('On, Return not detected', 'wp-photo-album-plus'), __('On, Return detected', 'wp-photo-album-plus'), __('Off, Did not fire', 'wp-photo-album-plus'), __('Off, Did not fire, Return not detected', 'wp-photo-album-plus'), __('Auto, Did not fire', 'wp-photo-album-plus'), __('Auto, Fired', 'wp-photo-album-plus'), __('Auto, Fired, Return not detected', 'wp-photo-album-plus'), __('Auto, Fired, Return detected', 'wp-photo-album-plus'), __('No flash function', 'wp-photo-album-plus'), __('Off, No flash function', 'wp-photo-album-plus'), __('Fired, Red-eye reduction', 'wp-photo-album-plus'), __('Fired, Red-eye reduction, Return not detected', 'wp-photo-album-plus'), __('Fired, Red-eye reduction, Return detected', 'wp-photo-album-plus'), __('On, Red-eye reduction', 'wp-photo-album-plus'), __('Red-eye reduction, Return not detected', 'wp-photo-album-plus'), __('On, Red-eye reduction, Return detected', 'wp-photo-album-plus'), __('Off, Red-eye reduction', 'wp-photo-album-plus'), __('Auto, Did not fire, Red-eye reduction', 'wp-photo-album-plus'), __('Auto, Fired, Red-eye reduction', 'wp-photo-album-plus'), __('Auto, Fired, Red-eye reduction, Return not detected', 'wp-photo-album-plus'), __('Auto, Fired, Red-eye reduction, Return detected', 'wp-photo-album-plus'), 'album', 'albums', 'content', 'http', 'source', 'wp', 'uploads', 'thumbs', 'wp-content', 'wppa-source', 'border', 'important', 'label', 'padding', 'segment', 'shutter', 'style', 'table', 'times', 'value', 'views', 'wppa-label', 'wppa-value', 'weighted', 'wppa-pl', 'datetime', 'exposureprogram', 'focallength', 'isospeedratings', 'meteringmode', 'model', 'photographer', str_replace('/', '', site_url())); // make a string $temp = implode(',', $wppa_void_keywords); // Downcase $temp = strtolower($temp); // Remove spaces and funny chars $temp = str_replace(array(' ', '-', '"', "'", '\\', '>', '<', ',', ':', ';', '!', '?', '=', '_', '[', ']', '(', ')', '{', '}'), ',', $temp); $temp = str_replace(',,', ',', $temp); //wppa_log('dbg', $temp); // Make array $wppa_void_keywords = explode(',', $temp); // Sort array sort($wppa_void_keywords); // Remove dups $start = 0; foreach (array_keys($wppa_void_keywords) as $key) { if ($key > 0) { if ($wppa_void_keywords[$key] == $wppa_void_keywords[$start]) { unset($wppa_void_keywords[$key]); } else { $start = $key; } } } } $text = wppa_get_photo_name($id) . ' ' . wppa_get_photo_desc($id); $text = str_replace(array('/', '-'), ' ', $text); $words = wppa_index_raw_to_words($text); foreach (array_keys($words) as $key) { if (wppa_is_int($words[$key]) || in_array($words[$key], $wppa_void_keywords) || strlen($words[$key]) < 5) { unset($words[$key]); } } $result = implode(', ', $words); return $result; }
function wppa_index_compute_skips() { $user_skips = ''; $words = wppa_index_raw_to_words(wppa_opt('newphoto_description') . ' ' . $user_skips, 'noskips'); sort($words); $result = array(); $last = ''; foreach ($words as $word) { // Remove dups if ($word != $last) { $result[] = $word; $last = $word; } } update_option('wppa_index_skips', $result); }
function wppa_get_thumbs() { global $wpdb; global $thumbs; global $wppa_session; // Log we are in wppa_dbg_msg('Get_thumbs entered, mocc = ' . wppa('mocc') . ', Start_album=' . wppa('start_album') . ', Cover=' . wppa('is_cover')); // Done already this occ? if (is_array($thumbs)) { wppa_dbg_msg('Cached thumbs used'); return $thumbs; } // A cover -> no thumbs if (wppa('is_cover')) { wppa_dbg_msg('Its cover, leave get_thumbs'); return false; } // Albums only -> no thumbs if (wppa('albums_only')) { wppa_dbg_msg('Albums only, leave get_thumbs'); return false; } // Init $count_first = true; // Start timer $time = -microtime(true); // Make Album clause $fullalb = wppa('start_album'); // See if album is an enumeration or range if (strpos($fullalb, '.') == false) { $album_clause = ' `album` = ' . $fullalb; } else { $ids = wppa_series_to_array($fullalb); $album_clause = ' `album` IN ( ' . implode(',', $ids) . ' )'; } // So far so good // Now make the query, dependant of type of selection // Init $query = ''; // Single image slideshow? if (wppa('start_photo') && wppa('is_single')) { $query = $wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `id` = %s', wppa('start_photo')); } elseif (wppa('is_upldr')) { $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } if (wppa('start_album')) { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $album_clause . " AND `owner` = %s AND ( ( " . $status . " ) OR `owner` = %s ) " . "ORDER BY `timestamp` DESC", wppa('is_upldr'), wppa_get_user()); } else { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `owner` = %s AND ( ( " . $status . " ) OR `owner` = %s ) " . "ORDER BY `timestamp` DESC", wppa('is_upldr'), wppa_get_user()); } } elseif (wppa('is_topten')) { $max = wppa('topten_count'); 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 (wppa('start_album')) { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $album_clause . " AND ( " . $status . " ) " . "ORDER BY " . $sortby . " LIMIT " . $max; } else { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE ( " . $status . " ) " . "ORDER BY " . $sortby . " LIMIT " . $max; } $count_first = false; } elseif (wppa('is_featen')) { $max = wppa('featen_count'); if (wppa('start_album')) { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $album_clause . " AND `status` = 'featured' " . "ORDER BY RAND( " . wppa_get_randseed() . " ) DESC LIMIT " . $max; } else { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `status` = 'featured' " . "ORDER BY RAND( " . wppa_get_randseed() . " ) DESC LIMIT " . $max; } $count_first = false; } elseif (wppa('is_lasten')) { $max = wppa('lasten_count'); $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } $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 (current_user_can('wppa_moderate')) { if (wppa('start_album')) { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE ( " . $album_clause . " ) AND ( " . $newtime . " ) " . "ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } else { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $newtime . " " . "ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } } else { if (wppa('start_album')) { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE ( " . $album_clause . " ) AND ( " . $status . " ) AND ( " . $newtime . " ) " . "ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } else { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE ( " . $status . " ) AND (" . $newtime . ") " . "ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } } } else { if (current_user_can('wppa_moderate')) { if (wppa('start_album')) { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $album_clause . " " . "ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } else { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } } else { if (wppa('start_album')) { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE ( " . $album_clause . " ) AND ( " . $status . " ) " . "ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } else { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $status . " " . "ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } } } $count_first = false; } elseif (wppa('is_comten')) { $alb_ids = wppa('start_album'); if (strpos($alb_ids, '.') !== false) { $alb_ids = wppa_series_to_array($alb_ids); } // Comments only visible if logged in or not required to log in if (!wppa_switch('comment_view_login') || is_user_logged_in()) { $photo_ids = wppa_get_comten_ids(wppa('comten_count'), (array) $alb_ids); } else { $photo_ids = false; } $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } // To keep the sequence ok ( in sequence of comments desc ), do the queries one by one $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; } } } wppa('any', !empty($thumbs)); wppa('thumb_count', empty($thumbs) ? '0' : count($thumbs)); $time += microtime(true); wppa_dbg_msg('Get thumbs exit is_comten took ' . $time . ' seconds. ' . 'Found: ' . wppa('thumb_count') . ' items. ' . 'Mem used=' . ceil(memory_get_peak_usage(true) / (1024 * 1024)) . ' Mb.'); return $thumbs; } elseif (wppa('is_tag')) { // Init $andor = 'AND'; if (strpos(wppa('is_tag'), ';')) { $andor = 'OR'; } // Compute status clause for query $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } // Define tags clause for query $seltags = explode(',', trim(wppa_sanitize_tags(wppa('is_tag')), ',')); $tags_like = ''; $first = true; foreach ($seltags as $tag) { if (!$first) { $tags_like .= " " . $andor; } $tags_like .= " `tags` LIKE '%," . $tag . ",%'"; $first = false; } // Prepare the query if (current_user_can('wppa_moderate')) { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE (" . $tags_like . " ) " . wppa_get_photo_order('0'); } else { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE (" . $tags_like . " ) AND " . $status . " " . wppa_get_photo_order('0'); } } 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')) { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `name` " . $is . " %s " . wppa_get_photo_order('0'), $data); } else { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `name` " . $is . " %s AND " . $status . " " . wppa_get_photo_order('0'), $data); } break; // Owner // Owner case 'o': if (current_user_can('wppa_moderate')) { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `owner` = %s " . wppa_get_photo_order('0'), $data); } else { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `owner` = %s AND " . $status . " " . wppa_get_photo_order('0'), $data); } 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) . ")"; } 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 (" . trim(implode(',', $ids), ',') . ")"; 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 . ")"; 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 . ")"; break; } } elseif (wppa('src')) { // Searching $status = "`status` <> 'pending' AND `status` <> 'scheduled'"; if (!is_user_logged_in()) { $status .= " AND `status` <> 'private'"; } $searchstring = wppa('searchstring'); if (!empty($wppa_session['use_searchstring'])) { $searchstring = $wppa_session['use_searchstring']; } $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']); } // Remove dups $final_array = array_unique($final_array); } } // Remove scheduled and pending when not can moderate if (!current_user_can('wppa_moderate')) { $needmod = $wpdb->get_results("SELECT `id` FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'scheduled' OR `status` = 'pending'", ARRAY_A); if (is_array($needmod)) { $delta = array(); foreach ($needmod as $item) { $delta[] = $item['id']; } } $final_array = array_diff($final_array, $delta); } // Remove private when not logged in if (!is_user_logged_in()) { $needlogin = $wpdb->get_results("SELECT `id` FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'private'", ARRAY_A); if (is_array($needlogin)) { $delta = array(); foreach ($needlogin as $item) { $delta[] = $item['id']; } } $final_array = array_diff($final_array, $delta); } // remove dups from $final_array $final_array = array_unique($final_array); // Make album clause $alb_clause = ''; // If rootsearch, the album clause resticts to sub the root // else: maybe exclude separates // See for rootsearch if (wppa('is_rootsearch') && isset($wppa_session['search_root'])) { // Find all albums below root $root = $wppa_session['search_root']; $root_albs = wppa_expand_enum(wppa_alb_to_enum_children($root)); $root_albs = str_replace('.', ',', $root_albs); $alb_clause = $root_albs ? ' AND `album` IN (' . $root_albs . ') ' : ''; } elseif (!$alb_clause && wppa_switch('excl_sep')) { $sep_albs = ''; $temp = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = '-1'", ARRAY_A); if (!empty($temp)) { $t = array(); foreach ($temp as $item) { $t[] = $item['id']; } $sep_albs = implode('.', $t); $sep_albs = wppa_expand_enum(wppa_alb_to_enum_children($sep_albs)); $sep_albs = str_replace('.', ',', $sep_albs); $alb_clause = $sep_albs ? ' AND `album` NOT IN (' . $sep_albs . ') ' : ''; } } // compose photo selection if (!empty($final_array)) { $selection = " `id` IN ("; $selection .= implode(',', $final_array); $selection .= ") "; } else { $selection = " `id` = '0' "; } // Construct the query $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE " . $selection . $alb_clause . wppa_get_photo_order('0'); } elseif (wppa('calendar')) { if (wppa('start_album')) { $alb_clause = " AND `album` IN ( " . str_replace('.', ',', wppa_expand_enum(wppa('start_album'))) . " ) "; } else { $alb_clause = ''; } switch (wppa('calendar')) { case 'exifdtm': $selection = "`exifdtm` LIKE '" . strip_tags(wppa('caldate')) . "%' AND `status` <> 'pending' AND `status` <> 'scheduled' "; $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $selection . $alb_clause . wppa_get_photo_order('0'); break; case 'timestamp': $t1 = strval(intval(wppa('caldate') * 24 * 60 * 60)); $t2 = $t1 + 24 * 60 * 60; $selection = "`timestamp` >= {$t1} AND `timestamp` < {$t2} AND `status` <> 'pending' AND `status` <> 'scheduled' "; $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $selection . $alb_clause . wppa_get_photo_order('0'); break; case 'modified': $t1 = strval(intval(wppa('caldate') * 24 * 60 * 60)); $t2 = $t1 + 24 * 60 * 60; $selection = "`modified` >= {$t1} AND `modified` < {$t2} AND `status` <> 'pending' AND `status` <> 'scheduled' "; $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $selection . $alb_clause . wppa_get_photo_order('0'); break; } } else { // 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')); // All albums ? if (wppa('start_album') == -2) { if (current_user_can('wppa_moderate')) { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . wppa_get_photo_order('0'); } else { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE ( ( " . $status . " ) OR `owner` = %s ) " . wppa_get_photo_order('0'), wppa_get_user()); } } elseif (wppa_is_int(wppa('start_album'))) { if (current_user_can('wppa_moderate')) { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` = " . wppa('start_album') . " " . wppa_get_photo_order(wppa('start_album')); } else { $query = $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()); } } elseif (is_array($allalb)) { $wherealbum = ' `album` IN (' . implode(',', $allalb) . ') '; if (current_user_can('wppa_moderate')) { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $wherealbum . " " . wppa_get_photo_order('0'); } else { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE ( ( " . $status . " ) OR `owner` = %s ) AND " . $wherealbum . " " . wppa_get_photo_order('0'), wppa_get_user()); } } } // Anything to look for? if (!$query) { // Not implemented or impossable shortcode return false; } // Do query and return result after copy result to $thumbs!! $thumbs = wppa_do_get_thumbs_query($query); return $thumbs; }
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; }