function wppa_insert_photo($file = '', $alb = '', $name = '', $desc = '', $porder = '0', $id = '0', $linkurl = '', $linktitle = '') { global $wpdb; global $warning_given_small; $album = wppa_cache_album($alb); if (!wppa_allow_uploads($alb)) { if (is_admin() && !wppa('ajax')) { wppa_error_message(sprintf(__('Album %s is full', 'wp-photo-album-plus'), wppa_get_album_name($alb))); } else { wppa_alert(sprintf(__('Album %s is full', 'wp-photo-album-plus'), wppa_get_album_name($alb))); } return false; } if ($file != '' && $alb != '') { // Get the name if not given if ($name == '') { $name = basename($file); } // Sanitize name $filename = wppa_sanitize_file_name($name); $name = wppa_sanitize_photo_name($name); // If not dups allowed and its already here, quit if (isset($_POST['wppa-nodups']) || wppa_switch('void_dups')) { $exists = wppa_file_is_in_album($filename, $alb); if ($exists) { if (isset($_POST['del-after-p'])) { unlink($file); $msg = __('Photo %s already exists in album number %s. Removed from depot.', 'wp-photo-album-plus'); } else { $msg = __('Photo %s already exists in album number %s.', 'wp-photo-album-plus'); } wppa_warning_message(sprintf($msg, $name, $alb)); return false; } } // Verify file exists if (!wppa('is_remote') && !file_exists($file)) { if (!is_dir(dirname($file))) { wppa_error_message('Error: Directory ' . dirname($file) . ' does not exist.'); return false; } if (!is_writable(dirname($file))) { wppa_error_message('Error: Directory ' . dirname($file) . ' is not writable.'); return false; } wppa_error_message('Error: File ' . $file . ' does not exist.'); return false; } // else { // wppa_ok_message( 'Good: File '.$file.' exists.' ); // } // Get and verify the size $img_size = getimagesize($file); if ($img_size) { if (wppa_check_memory_limit('', $img_size['0'], $img_size['1']) === false) { wppa_error_message(sprintf(__('ERROR: Attempt to upload a photo that is too large to process (%s).', 'wp-photo-album-plus'), $name) . wppa_check_memory_limit()); wppa('ajax_import_files_error', __('Too big', 'wp-photo-album-plus')); return false; } if (!$warning_given_small && ($img_size['0'] < wppa_get_minisize() && $img_size['1'] < wppa_get_minisize())) { wppa_warning_message(__('WARNING: You are uploading photos that are too small. Photos must be larger than the thumbnail size and larger than the coverphotosize.', 'wp-photo-album-plus')); wppa('ajax_import_files_error', __('Too small', 'wp-photo-album-plus')); $warning_given_small = true; } } else { wppa_error_message(__('ERROR: Unable to retrieve image size of', 'wp-photo-album-plus') . ' ' . $name . ' ' . __('Are you sure it is a photo?', 'wp-photo-album-plus')); wppa('ajax_import_files_error', __('No imagesize', 'wp-photo-album-plus')); return false; } // Get ext based on mimetype, regardless of ext switch ($img_size[2]) { // mime type case 1: $ext = 'gif'; break; case 2: $ext = 'jpg'; break; case 3: $ext = 'png'; break; default: wppa_error_message(__('Unsupported mime type encountered:', 'wp-photo-album-plus') . ' ' . $img_size[2] . '.'); return false; } // Get an id if not yet there if ($id == '0') { $id = wppa_nextkey(WPPA_PHOTOS); } // Get opt deflt desc if empty if ($desc == '' && wppa_switch('apply_newphoto_desc')) { $desc = stripslashes(wppa_opt('newphoto_description')); } // Reset rating $mrat = '0'; // Find ( new ) owner $owner = wppa_get_user(); // Validate album if (!is_numeric($alb) || $alb < '1') { wppa_error_message(__('Album not known while trying to add a photo', 'wp-photo-album-plus')); return false; } if (!wppa_have_access($alb)) { wppa_error_message(sprintf(__('Album %s does not exist or is not accessable while trying to add a photo', 'wp-photo-album-plus'), $alb)); return false; } $status = wppa_switch('upload_moderate') && !current_user_can('wppa_admin') ? 'pending' : 'publish'; // Add photo to db $id = wppa_create_photo_entry(array('id' => $id, 'album' => $alb, 'ext' => $ext, 'name' => $name, 'p_order' => $porder, 'description' => $desc, 'linkurl' => $linkurl, 'linktitle' => $linktitle, 'owner' => $owner, 'status' => $status, 'filename' => $filename)); if (!$id) { wppa_error_message(__('Could not insert photo.', 'wp-photo-album-plus')); } else { // Save the source wppa_save_source($file, $filename, $alb); wppa_flush_treecounts($alb); wppa_update_album(array('id' => $alb, 'modified' => time())); wppa_flush_upldr_cache('photoid', $id); } // Make the photo files if (wppa_make_the_photo_files($file, $id, $ext)) { // Repair photoname if not supplied and not standard wppa_set_default_name($id, $name); // Tags wppa_set_default_tags($id); // Index wppa_index_add('photo', $id); // and add watermark ( optionally ) to fullsize image only wppa_add_watermark($id); // also to thumbnail? if (wppa_switch('watermark_thumbs')) { wppa_create_thumbnail($id); } // Is it a default coverimage? wppa_check_coverimage($id); return $id; } } else { wppa_error_message(__('ERROR: Unknown file or album.', 'wp-photo-album-plus')); return false; } }
function wppa_is_time_up($count = '') { global $wppa_starttime; $timnow = microtime(true); $laptim = $timnow - $wppa_starttime; $maxwppatim = wppa_opt('max_execution_time'); $maxinitim = ini_get('max_execution_time'); if ($maxwppatim && $maxinitim) { $maxtim = min($maxwppatim, $maxinitim); } elseif ($maxwppatim) { $maxtim = $maxwppatim; } elseif ($maxinitim) { $maxtim = $maxinitim; } else { return false; } wppa_dbg_msg('Maxtim = ' . $maxtim . ', elapsed = ' . $laptim, 'red'); if (!$maxtim) { return false; } // No limit or no value if ($maxtim - $laptim > '5') { return false; } if ($count) { if (is_admin()) { if (wppa_switch('auto_continue')) { wppa_warning_message(sprintf(__('Time out after processing %s items.', 'wp-photo-album-plus'), $count)); } else { wppa_error_message(sprintf(__('Time out after processing %s items. Please restart this operation', 'wp-photo-album-plus'), $count)); } } else { wppa_alert(sprintf(__('Time out after processing %s items. Please restart this operation', 'wp-photo-album-plus'), $count)); } } return true; }
function wppa_maintenance_messages() { if (!current_user_can('wppa_settings')) { return; } if (get_option('wppa_remake_index_photos_status') || get_option('wppa_index_need_remake', 'no') == 'yes') { wppa_error_message(__('</strong>The photo index table needs to be rebuilt. Please run <b>Photo Albums -> Settings</b> admin page <b>Table VIII-A9</b><strong>', 'wppa')); update_option('wppa_remake_index_photos_status', 'required'); } if (get_option('wppa_remake_index_albums_status') || get_option('wppa_index_need_remake', 'no') == 'yes') { wppa_error_message(__('</strong>The album index table needs to be rebuilt. Please run <b>Photo Albums -> Settings</b> admin page <b>Table VIII-A8</b><strong>', 'wppa')); update_option('wppa_remake_index_albums_status', 'required'); } if (wppa_switch('wppa_rating_on') && get_option('wppa_rerate_status')) { wppa_error_message(__('</strong>The avarage ratings need to be recalculated. Please run <b>Photo Albums -> Settings</b> admin page <b>Table VIII-A5</b><strong>', 'wppa')); } }
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_import_dir_to_album($file, $parent) { global $photocount; global $wpdb; global $wppa_session; // Session should survive the default hour wppa_extend_session(); // see if album exists if (is_dir($file)) { // Check parent if (wppa_switch('import_parent_check')) { $alb = wppa_get_album_id(basename($file), $parent); // If parent = 0 ( top-level album ) and album not found, // try a 'separate' album ( i.e. parent = -1 ) with this name if (!$alb && $parent == '0') { $alb = wppa_get_album_id(basename($file), '-1'); } } else { $alb = wppa_get_album_id(basename($file), false); } if (!$alb) { // Album must be created $name = basename($file); $uplim = wppa_opt('upload_limit_count') . '/' . wppa_opt('upload_limit_time'); $alb = wppa_create_album_entry(array('name' => $name, 'a_parent' => $parent)); if ($alb === false) { wppa_error_message(__('Could not create album.', 'wp-photo-album-plus') . '<br/>Query = ' . $query); wp_die('Sorry, cannot continue'); } else { wppa_set_last_album($alb); wppa_flush_treecounts($alb); wppa_index_add('album', $alb); wppa_create_pl_htaccess(); wppa_ok_message(__('Album #', 'wp-photo-album-plus') . ' ' . $alb . ' ( ' . $name . ' ) ' . __('Added.', 'wp-photo-album-plus')); if (wppa_switch('newpag_create') && $parent <= '0') { // Create post object $my_post = array('post_title' => $name, 'post_content' => str_replace('w#album', $alb, wppa_opt('newpag_content')), 'post_status' => wppa_opt('newpag_status'), 'post_type' => wppa_opt('newpag_type')); // Insert the post into the database $pagid = wp_insert_post($my_post); if ($pagid) { wppa_ok_message(sprintf(__('Page <a href="%s" target="_blank" >%s</a> created.', 'wp-photo-album-plus'), home_url() . '?page_id=' . $pagid, $name)); $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_ALBUMS . "` SET `cover_linkpage` = %s WHERE `id` = %s", $pagid, $alb)); } else { wppa_error_message(__('Could not create page.', 'wp-photo-album-plus')); } } } } // Now import the files $photofiles = glob($file . '/*'); if ($photofiles) { foreach ($photofiles as $photofile) { if (!is_dir($photofile)) { if (!isset($wppa_session[$photofile]) || !wppa_switch('keep_import_files')) { if (wppa_albumphoto_exists($alb, basename($photofile))) { if (!wppa_switch('keep_import_files')) { wppa_warning_message('Photo ' . basename($photofile) . ' already exists in album ' . $alb . '. Removed. (2)'); } } else { $bret = wppa_insert_photo($photofile, $alb, basename($photofile)); $photocount++; } if (!wppa_switch('keep_import_files')) { @unlink($photofile); } $wppa_session[$photofile] = true; } if (wppa_is_time_up($photocount)) { return false; } } } } // Now go deeper, process the subdirs $subdirs = glob($file . '/*'); if ($subdirs) { foreach ($subdirs as $subdir) { if (is_dir($subdir)) { if (basename($subdir) != '.' && basename($subdir) != '..') { $bret = wppa_import_dir_to_album($subdir, $alb); if (!$bret) { return false; } // Time out } } } } @rmdir($file); // Try to remove dir, ignore error } else { wppa_dbg_msg('Invalid file in wppa_import_dir_to_album(): ' . $file); return false; } return true; }
function wppa_check_dirs() { if (!is_multisite()) { // check if uploads dir exists $upload_dir = wp_upload_dir(); $dir = $upload_dir['basedir']; if (!is_dir($dir)) { wppa_mktree($dir); if (!is_dir($dir)) { wppa_error_message(__('The uploads directory does not exist, please do a regular WP upload first.', 'wp-photo-album-plus') . '<br/>' . $dir); return false; } else { if (WPPA_DEBUG) { wppa_ok_message(__('Successfully created uploads directory.', 'wp-photo-album-plus') . '<br/>' . $dir); } } } @chmod($dir, 0755); } // check if wppa dir exists $dir = WPPA_UPLOAD_PATH; if (!is_dir($dir)) { wppa_mktree($dir); if (!is_dir($dir)) { wppa_error_message(__('Could not create the wppa directory.', 'wp-photo-album-plus') . wppa_credirmsg($dir)); return false; } else { if (WPPA_DEBUG) { wppa_ok_message(__('Successfully created wppa directory.', 'wp-photo-album-plus') . '<br/>' . $dir); } } } @chmod($dir, 0755); // check if thumbs dir exists $dir = WPPA_UPLOAD_PATH . '/thumbs'; if (!is_dir($dir)) { wppa_mktree($dir); if (!is_dir($dir)) { wppa_error_message(__('Could not create the wppa thumbs directory.', 'wp-photo-album-plus') . wppa_credirmsg($dir)); return false; } else { if (WPPA_DEBUG) { wppa_ok_message(__('Successfully created wppa thumbs directory.', 'wp-photo-album-plus') . '<br/>' . $dir); } } } @chmod($dir, 0755); // check if watermarks dir exists $dir = WPPA_UPLOAD_PATH . '/watermarks'; if (!is_dir($dir)) { wppa_mktree($dir); if (!is_dir($dir)) { wppa_error_message(__('Could not create the wppa watermarks directory.', 'wp-photo-album-plus') . wppa_credirmsg($dir)); return false; } else { if (WPPA_DEBUG) { wppa_ok_message(__('Successfully created wppa watermarks directory.', 'wp-photo-album-plus') . '<br/>' . $dir); } } } @chmod($dir, 0755); // check if fonts dir exists $dir = WPPA_UPLOAD_PATH . '/fonts'; if (!is_dir($dir)) { wppa_mktree($dir); if (!is_dir($dir)) { wppa_error_message(__('Could not create the wppa fonts directory.', 'wp-photo-album-plus') . wppa_credirmsg($dir)); return false; } else { if (WPPA_DEBUG) { wppa_ok_message(__('Successfully created wppa fonts directory.', 'wp-photo-album-plus') . '<br/>' . $dir); } } } @chmod($dir, 0755); // check if depot dir exists if (!is_multisite()) { // check if users depot dir exists $dir = WPPA_CONTENT_PATH . '/wppa-depot'; if (!is_dir($dir)) { wppa_mktree($dir); if (!is_dir($dir)) { wppa_error_message(__('Unable to create depot directory.', 'wp-photo-album-plus') . wppa_credirmsg($dir)); return false; } else { if (WPPA_DEBUG) { wppa_ok_message(__('Successfully created wppa depot directory.', 'wp-photo-album-plus') . '<br/>' . $dir); } } } @chmod($dir, 0755); } // check the user depot directory $dir = WPPA_DEPOT_PATH; if (!is_dir($dir)) { wppa_mktree($dir); if (!is_dir($dir)) { wppa_error_message(__('Unable to create user depot directory', 'wp-photo-album-plus') . wppa_credirmsg($dir)); return false; } else { if (WPPA_DEBUG) { wppa_ok_message(__('Successfully created wppa user depot directory.', 'wp-photo-album-plus') . '<br/>' . $dir); } } } @chmod($dir, 0755); // check the temp dir $dir = WPPA_UPLOAD_PATH . '/temp/'; if (!is_dir($dir)) { wppa_mktree($dir); if (!is_dir($dir)) { wppa_error_message(__('Unable to create temp directory', 'wp-photo-album-plus') . wppa_credirmsg($dir)); return false; } else { if (WPPA_DEBUG) { wppa_ok_message(__('Successfully created temp directory.', 'wp-photo-album-plus') . '<br/>' . $dir); } } } @chmod($dir, 0755); return true; }
function wppa_del_album($id, $move = '') { global $wpdb; if ($move && !wppa_have_access($move)) { wppa_error_message(__('Unable to move photos to album %s. Album not deleted.', 'wp-photo-album-plus')); return false; } // Photos in the album $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s', $id), ARRAY_A); if (empty($move)) { // will delete all the album's photos if (is_array($photos)) { $cnt = '0'; foreach ($photos as $photo) { $t = -microtime(true); wppa_delete_photo($photo['id']); $cnt++; $t += microtime(true); // wppa_dbg_msg('Del photo took :'.$t, 'red', 'force'); // Time up? if (wppa_is_time_up()) { wppa_flush_treecounts($id); $msg = sprintf(__('Time is out after %d photo deletes. Please redo this operation', 'wp-photo-album-plus'), $cnt); if (wppa('ajax')) { echo $msg; } else { wppa_error_message($msg); } return; } } } } else { // Move if (is_array($photos)) { foreach ($photos as $photo) { $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `album` = %s WHERE `id` = %s', $move, $photo['id'])); wppa_move_source($photo['filename'], $photo['album'], $move); if (wppa_is_time_up()) { wppa_error_message('Time is out. Please redo this operation'); return; } } } wppa_flush_treecounts($move); } // First flush treecounts, otherwise we do not know the parent if any wppa_flush_treecounts($id); // Now delete the album $wpdb->query($wpdb->prepare('DELETE FROM `' . WPPA_ALBUMS . '` WHERE `id` = %s LIMIT 1', $id)); wppa_delete_album_source($id); wppa_index_remove('album', $id); $msg = __('Album Deleted.', 'wp-photo-album-plus'); if (wppa('ajax')) { echo $msg; } else { wppa_update_message($msg); } }
function wppa_get_date_time_select_html($type, $id, $selectable = true) { $type = strtoupper(substr($type, 0, 1)) . strtolower(substr($type, 1)); if ($type == 'Photo') { $thumb = wppa_cache_thumb($id); } elseif ($type == 'Album') { $album = wppa_cache_album($id); } else { wppa_error_message('Uniplemented type: ' . $type . ' in wppa_get_date_time_select_html()'); } $opt_months = array('1' => __('Jan', 'wp-photo-album-plus'), '2' => __('Feb', 'wp-photo-album-plus'), '3' => __('Mar', 'wp-photo-album-plus'), '4' => __('Apr', 'wp-photo-album-plus'), '5' => __('May', 'wp-photo-album-plus'), '6' => __('Jun', 'wp-photo-album-plus'), '7' => __('Jul', 'wp-photo-album-plus'), '8' => __('Aug', 'wp-photo-album-plus'), '9' => __('Sep', 'wp-photo-album-plus'), '10' => __('Oct', 'wp-photo-album-plus'), '11' => __('Nov', 'wp-photo-album-plus'), '12' => __('Dec', 'wp-photo-album-plus')); $val_months = array('1' => '01', '2' => '02', '3' => '03', '4' => '04', '5' => '05', '6' => '06', '7' => '07', '8' => '08', '9' => '09', '10' => '10', '11' => '11', '12' => '12'); $opt_years = array('2014', '2015', '2016', '2017', '2018', '2019', '2020'); $val_years = $opt_years; $opt_days = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'); $val_days = $opt_days; $opt_hours = array('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23'); $val_hours = $opt_hours; $opt_mins = array('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59'); $val_mins = $opt_mins; $curval = $type == 'Photo' ? $thumb['scheduledtm'] : $album['scheduledtm']; if (!$curval) { $curval = wppa_get_default_scheduledtm(); } $temp = explode(',', $curval); $cur_day = $temp[2]; $cur_month = $temp[1]; $cur_year = $temp[0]; $cur_hour = $temp[3]; $cur_min = $temp[4]; $result = ''; if ($selectable) { $result .= '<select name="wppa-day" id="wppa-day-' . $id . '" class="wppa-datetime-' . $id . '" onchange="wppaAjaxUpdate' . $type . '(' . $id . ', \'day\', this);" >'; foreach (array_keys($opt_days) as $key) { $sel = $val_days[$key] == $cur_day ? 'selected="selected"' : ''; $result .= '<option value="' . $val_days[$key] . '" ' . $sel . ' >' . $opt_days[$key] . '</option>'; } $result .= '</select >'; $result .= '<select name="wppa-month" id="wppa-month-' . $id . '" class="wppa-datetime-' . $id . '" onchange="wppaAjaxUpdate' . $type . '(' . $id . ', \'month\', this);" >'; foreach (array_keys($opt_months) as $key) { $sel = $val_months[$key] == $cur_month ? 'selected="selected"' : ''; $result .= '<option value="' . $val_months[$key] . '" ' . $sel . ' >' . $opt_months[$key] . '</option>'; } $result .= '</select >'; $result .= '<select name="wppa-year" id="wppa-year-' . $id . '" class="wppa-datetime-' . $id . '" onchange="wppaAjaxUpdate' . $type . '(' . $id . ', \'year\', this);" >'; foreach (array_keys($opt_years) as $key) { $sel = $val_years[$key] == $cur_year ? 'selected="selected"' : ''; $result .= '<option value="' . $val_years[$key] . '" ' . $sel . ' >' . $opt_years[$key] . '</option>'; } $result .= '</select >@'; $result .= '<select name="wppa-hour" id="wppa-hour-' . $id . '" class="wppa-datetime-' . $id . '" onchange="wppaAjaxUpdate' . $type . '(' . $id . ', \'hour\', this);" >'; foreach (array_keys($opt_hours) as $key) { $sel = $val_hours[$key] == $cur_hour ? 'selected="selected"' : ''; $result .= '<option value="' . $val_hours[$key] . '" ' . $sel . ' >' . $opt_hours[$key] . '</option>'; } $result .= '</select >:'; $result .= '<select name="wppa-min" id="wppa-min-' . $id . '" class="wppa-datetime-' . $id . '" onchange="wppaAjaxUpdate' . $type . '(' . $id . ', \'min\', this);">'; foreach (array_keys($opt_mins) as $key) { $sel = $val_mins[$key] == $cur_min ? 'selected="selected"' : ''; $result .= '<option value="' . $val_mins[$key] . '" ' . $sel . ' >' . $opt_mins[$key] . '</option>'; } $result .= '</select >'; } else { $result .= '<span class="wppa-datetime-' . $id . '" >' . $cur_day . ' ' . $opt_months[strval(intval($cur_month))] . ' ' . $cur_year . '@' . $cur_hour . ':' . $cur_min . '</span>'; } return $result; }
function wppa_cat_message() { wppa_error_message(__('</strong>The cats system needs to be converted. Please run <b>Photo Albums -> Settings</b> admin page <b>Table VIII-B17</b><strong>', 'wp-photo-album-plus')); }
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; }
function wppa_get_widgetphotos($alb, $option = '') { global $wpdb; if (!$alb) { return false; } $photos = false; $query = ''; // Compile status clause switch (wppa_opt('potd_status_filter')) { case 'publish': $statusclause = " `status` = 'publish' "; break; case 'featured': $statusclause = " `status` = 'featured' "; break; case 'gold': $statusclause = " `status` = 'gold' "; break; case 'silver': $statusclause = " `status` = 'silver' "; break; case 'bronze': $statusclause = " `status` = 'bronze' "; break; case 'anymedal': $statusclause = " `status` IN ( 'gold', 'silver', 'bronze' ) "; break; default: $statusclause = " `status` <> 'scheduled' "; if (!is_user_logged_in()) { $statusclause .= " AND `status` <> 'private' "; } } // If physical album(s) and include subalbums is active, make it an enumeration(with ',' as seperator) if (wppa_opt('potd_album_type') == 'physical' && wppa_switch('potd_include_subs')) { $alb = str_replace(',', '.', $alb); $alb = wppa_expand_enum(wppa_alb_to_enum_children($alb)); $alb = str_replace('.', ',', $alb); } // If physical albums and inverse selection is active, invert selection if (wppa_opt('potd_album_type') == 'physical' && wppa_switch('potd_inverse')) { $albs = explode(',', $alb); $all = $wpdb->get_col("SELECT `id` FROM `" . WPPA_ALBUMS . "` "); $alb = implode(',', array_diff($all, $albs)); } /* Now find out the final query */ /* Physical albums */ // Is it a single album? if (wppa_is_int($alb)) { $query = $wpdb->prepare("SELECT `id`, `p_order` " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` = %s " . "AND " . $statusclause . $option, $alb); } elseif (strchr($alb, ',')) { $alb = trim($alb, ','); $query = "SELECT `id`, `p_order` " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` IN ( " . $alb . " ) " . "AND " . $statusclause . $option; } elseif ($alb == 'all') { $query = "SELECT `id`, `p_order` " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE " . $statusclause . $option; } elseif ($alb == 'sep') { $albs = $wpdb->get_results("SELECT `id`, `a_parent` FROM `" . WPPA_ALBUMS . "`", ARRAY_A); $query = "SELECT `id`, `p_order` FROM `" . WPPA_PHOTOS . "` WHERE ( `album` = '0' "; $first = true; foreach ($albs as $a) { if ($a['a_parent'] == '-1') { $query .= "OR `album` = '" . $a['id'] . "' "; } } $query .= ") AND " . $statusclause . $option; } elseif ($alb == 'all-sep') { $albs = $wpdb->get_results("SELECT `id`, `a_parent` FROM `" . WPPA_ALBUMS . "`", ARRAY_A); $query = "SELECT `id`, `p_order` FROM `" . WPPA_PHOTOS . "` WHERE ( `album` IN ('0'"; foreach ($albs as $a) { if ($a['a_parent'] != '-1') { $query .= ",'" . $a['id'] . "'"; } } $query .= ") ) AND " . $statusclause . $option; } elseif ($alb == 'topten') { // Find the 'top' policy 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; } // It is assumed that status is ok for top rated photos $query = "SELECT `id`, `p_order` FROM `" . WPPA_PHOTOS . "` ORDER BY " . $sortby . " LIMIT " . wppa_opt('topten_count'); $query .= $option; } // Do the query if ($query) { $photos = $wpdb->get_results($query, ARRAY_A); wppa_dbg_msg('Potd query: ' . $query); } else { $photos = array(); } // Ready return $photos; }
function wppa_verify_page($xslug) { global $wpdb; global $wppa_opt; // Does slug exist? if (!isset($wppa_opt[$xslug])) { wppa_error_message('Unexpected error in wppa_verify_page()', 'red', 'force'); return; } // A page number 0 is allowed ( same post/page ) if (!$wppa_opt[$xslug]) { return; } $slug = substr($xslug, 5); // If page vanished, update to 0 $iret = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . $wpdb->posts . "` WHERE `post_type` = 'page' AND `post_status` = 'publish' AND `ID` = %s", wppa_opt($slug))); if (!$iret) { wppa_update_option($slug, '0'); } }
function wppa_write_photo_file($photo) { global $wppa_zip; global $wppa_temp; global $wppa_temp_idx; if ($photo) { $fname = WPPA_DEPOT_PATH . '/' . $photo['id'] . '.pmf'; $file = fopen($fname, 'wb'); $err = false; if ($file) { if (fwrite($file, "name=" . $photo['name'] . "\n") !== FALSE) { if (fwrite($file, "desc=" . wppa_nl_to_txt($photo['description']) . "\n") !== FALSE) { if (fwrite($file, "pord=" . $photo['p_order'] . "\n") !== FALSE) { if (fwrite($file, "albm=" . wppa_get_album_name($photo['album'], 'raw') . "\n") !== FALSE) { if (fwrite($file, "lnku=" . $photo['linkurl'] . "\n") !== FALSE) { if (fwrite($file, "lnkt=" . $photo['linktitle'] . "\n") !== FALSE) { /* ext tinytext NOT NULL, mean_rating tinytext NOT NULL, linktarget tinytext NOT NULL, owner text NOT NULL, timestamp tinytext NOT NULL, status tinytext NOT NULL, rating_count bigint(20) NOT NULL default '0', tags tinytext NOT NULL, alt tinytext NOT NULL, filename tinytext NOT NULL, modified tinytext NOT NULL, location tinytext NOT NULL, */ } else { $err = true; } } else { $err = true; } } else { $err = true; } } else { $err = true; } } else { $err = true; } } else { $err = true; } if ($err) { wppa_error_message(sprintf(__('Cannot write to file %s.', 'wp-photo-album-plus'), $fname)); fclose($file); return false; } else { fclose($file); if ($wppa_zip) { $wppa_zip->addFile($fname, basename($fname)); } $wppa_temp[$wppa_temp_idx] = $fname; $wppa_temp_idx++; } } else { wppa_error_message(__('Could not open photo output file.', 'wp-photo-album-plus')); return false; } } else { wppa_error_message(__('Could not read photo data.', 'wp-photo-album-plus')); return false; } return true; }
function wppa_album_photos_bulk($album) { global $wpdb; // Check input wppa_vfy_arg('wppa-page'); // Init $count = '0'; $abort = false; if (isset($_POST['wppa-bulk-action'])) { check_admin_referer('wppa-bulk', 'wppa-bulk'); if (isset($_POST['wppa-bulk-photo'])) { $ids = $_POST['wppa-bulk-photo']; $newalb = isset($_POST['wppa-bulk-album']) ? $_POST['wppa-bulk-album'] : '0'; $status = isset($_POST['wppa-bulk-status']) ? $_POST['wppa-bulk-status'] : ''; $owner = isset($_POST['wppa-bulk-owner']) ? $_POST['wppa-bulk-owner'] : ''; $totcount = count($ids); if (!is_numeric($newalb)) { wp_die('Security check failure 1'); } if (is_array($ids)) { foreach (array_keys($ids) as $id) { $skip = false; switch ($_POST['wppa-bulk-action']) { case 'wppa-bulk-delete': wppa_delete_photo($id); break; case 'wppa-bulk-move-to': if ($newalb) { $photo = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPPA_PHOTOS . ' WHERE `id` = %s', $id), ARRAY_A); if (wppa_switch('void_dups')) { // Check for already exists $exists = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `filename` = %s AND `album` = %s", $photo['filename'], $newalb)); if ($exists) { // Already exists wppa_error_message(sprintf(__('A photo with filename %s already exists in album %s.', 'wp-photo-album-plus'), $photo['filename'], $newalb)); $skip = true; } } if ($skip) { continue; } wppa_flush_treecounts($photo['album']); // Current album wppa_flush_treecounts($newalb); // New album $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `album` = %s WHERE `id` = %s', $newalb, $id)); wppa_move_source($photo['filename'], $photo['album'], $newalb); } else { wppa_error_message('Unexpected error #4 in wppa_album_photos_bulk().'); } break; case 'wppa-bulk-copy-to': if ($newalb) { $photo = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPPA_PHOTOS . ' WHERE `id` = %s', $id), ARRAY_A); if (wppa_switch('void_dups')) { // Check for already exists $exists = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `filename` = %s AND `album` = %s", $photo['filename'], $newalb)); if ($exists) { // Already exists wppa_error_message(sprintf(__($exists . 'A photo with filename %s already exists in album %s.', 'wp-photo-album-plus'), $photo['filename'], $newalb)); $skip = true; } } if ($skip) { continue; } wppa_copy_photo($id, $newalb); wppa_flush_treecounts($newalb); } else { wppa_error_message('Unexpected error #3 in wppa_album_photos_bulk().'); } break; case 'wppa-bulk-status': if (!in_array($status, array('publish', 'pending', 'featured', 'scheduled', 'gold', 'silver', 'bronze', 'private'))) { wppa_log('error', 'Unknown status ' . strip_tags($status) . ' found in wppa-photo-admin-autosave.php -> wppa_album_photos_bulk()'); $status = 'publish'; } if (current_user_can('wppa_admin') || current_user_can('wppa_moderate')) { if ($status == 'publish' || $status == 'pending' || wppa_user_is('administrator') || !wppa_switch('ext_status_restricted')) { $wpdb->query("UPDATE `" . WPPA_PHOTOS . "` SET `status` = '" . $status . "' WHERE `id` = " . $id); wppa_flush_treecounts($id, wppa_get_photo_item($id, 'album')); } else { wp_die('Security check failure 2'); } } else { wp_die('Security check failure 3'); } break; case 'wppa-bulk-owner': if (wppa_user_is('administrator') && wppa_switch('photo_owner_change')) { if ($owner) { $owner = sanitize_user($owner); $exists = $wpdb->get_var("SELECT COUNT(*) FROM `" . $wpdb->users . "` WHERE `user_login` = '" . $owner . "'"); if ($exists) { $wpdb->query("UPDATE `" . WPPA_PHOTOS . "` SET `owner` = '" . $owner . "' WHERE `id` = " . $id); } else { wppa_error_message('A user with login name ' . $owner . ' does not exist.'); $skip = true; } } else { wp_die('Missing required arg in bulk change owner'); } } else { wp_die('Security check failure 4'); } break; default: wppa_error_message('Unimplemented bulk action requested in wppa_album_photos_bulk().'); break; } if (!$skip) { $count++; } if (wppa_is_time_up()) { wppa_error_message(sprintf(__('Time is out after processing %d out of %d items.', 'wp-photo-album-plus'), $count, $totcount)); $abort = true; } if ($abort) { break; } } } else { wppa_error_message('Unexpected error #2 in wppa_album_photos_bulk().'); } } else { wppa_error_message('Unexpected error #1 in wppa_album_photos_bulk().'); } if ($count && !$abort) { switch ($_POST['wppa-bulk-action']) { case 'wppa-bulk-delete': $message = sprintf(__('%d photos deleted.', 'wp-photo-album-plus'), $count); break; case 'wppa-bulk-move-to': $message = sprintf(__('%1$s photos moved to album %2$s.', 'wp-photo-album-plus'), $count, $newalb . ': ' . wppa_get_album_name($newalb)); break; case 'wppa-bulk-copy-to': $message = sprintf(__('%1$s photos copied to album %2$s.', 'wp-photo-album-plus'), $count, $newalb . ': ' . wppa_get_album_name($newalb)); break; case 'wppa-bulk-status': $message = sprintf(__('Changed status to %1$s on %2$s photos.', 'wp-photo-album-plus'), $status, $count); break; case 'wppa-bulk-owner': $message = sprintf(__('Changed owner to %1$s on %2$s photos.', 'wp-photo-album-plus'), $owner, $count); break; default: $message = sprintf(__('%d photos processed.', 'wp-photo-album-plus'), $count); break; } wppa_ok_message($message); } } $pagesize = wppa_opt('photo_admin_pagesize'); $page = isset($_GET['wppa-page']) ? $_GET['wppa-page'] : '1'; $skip = ($page - '1') * $pagesize; $limit = $pagesize < '1' ? '' : ' LIMIT ' . $skip . ',' . $pagesize; if ($album) { if ($album == 'search') { $count = wppa_get_edit_search_photos('', 'count_only'); $photos = wppa_get_edit_search_photos($limit); $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $album . '&wppa-searchstring=' . wppa_sanitize_searchstring($_REQUEST['wppa-searchstring']) . '&bulk'); wppa_show_search_statistics(); } else { $counts = wppa_treecount_a($album); $count = $counts['selfphotos'] + $counts['pendphotos']; //$wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM `'.WPPA_PHOTOS.'` WHERE `album` = %s', $album ) ); $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s ' . wppa_get_photo_order($album, 'norandom') . $limit, $album), ARRAY_A); $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=' . $album . '&bulk'); } if ($photos) { wppa_admin_page_links($page, $pagesize, $count, $link, '#manage-photos'); ?> <script type="text/javascript" > function wppaBulkActionChange( elm, id ) { wppa_setCookie( 'wppa_bulk_action',elm.value,365 ); if ( elm.value == 'wppa-bulk-move-to' || elm.value == 'wppa-bulk-copy-to' ) jQuery( '#wppa-bulk-album' ).css( 'display', 'inline' ); else jQuery( '#wppa-bulk-album' ).css( 'display', 'none' ); if ( elm.value == 'wppa-bulk-status' ) jQuery( '#wppa-bulk-status' ).css( 'display', 'inline' ); else jQuery( '#wppa-bulk-status' ).css( 'display', 'none' ); if ( elm.value == 'wppa-bulk-owner' ) jQuery( '#wppa-bulk-owner' ).css( 'display', 'inline' ); else jQuery( '#wppa-bulk-owner' ).css( 'display', 'none' ); } function wppaBulkDoitOnClick() { var photos = jQuery( '.wppa-bulk-photo' ); var count=0; for ( i=0; i< photos.length; i++ ) { var photo = photos[i]; if ( photo.checked ) count++; } if ( count == 0 ) { alert( 'No photos selected' ); return false; } var action = document.getElementById( 'wppa-bulk-action' ).value; switch ( action ) { case '': alert( 'No action selected' ); return false; break; case 'wppa-bulk-delete': break; case 'wppa-bulk-move-to': case 'wppa-bulk-copy-to': var album = document.getElementById( 'wppa-bulk-album' ).value; if ( album == 0 ) { alert( 'No album selected' ); return false; } break; case 'wppa-bulk-status': var status = document.getElementById( 'wppa-bulk-status' ).value; if ( status == 0 ) { alert( 'No status selected' ); return false; } break; case 'wppa-bulk-owner': var owner = documnet.getElementById( 'wppa-bulk-owner' ).value; if ( owner == 0 ) { alert( 'No new owner selected' ); return false; } break; default: alert( 'Unimplemented action requested: '+action ); return false; break; } return true; } function wppaSetThumbsize( elm ) { var thumbsize = elm.value; wppa_setCookie( 'wppa_bulk_thumbsize',thumbsize,365 ); jQuery( '.wppa-bulk-thumb' ).css( 'max-width', thumbsize+'px' ); jQuery( '.wppa-bulk-thumb' ).css( 'max-height', ( thumbsize/2 )+'px' ); jQuery( '.wppa-bulk-dec' ).css( 'height', ( thumbsize/2 )+'px' ); } jQuery( document ).ready( function() { var action = wppa_getCookie( 'wppa_bulk_action' ); document.getElementById( 'wppa-bulk-action' ).value = action; if ( action == 'wppa-bulk-move-to' || action == 'wppa-bulk-copy-to' ) { jQuery( '#wppa-bulk-album' ).css( 'display','inline' ); document.getElementById( 'wppa-bulk-album' ).value = wppa_getCookie( 'wppa_bulk_album' ); } if ( action == 'wppa-bulk-status' ) { jQuery( '#wppa-bulk-status' ).css( 'display','inline' ); document.getElementById( 'wppa-bulk-status' ).value = wppa_getCookie( 'wppa_bulk_status' ); } if ( action == 'wppa-bulk-owner' ) { jQuery( '#wppa-bulk-owner' ).css( 'display','inline' ); document.getElementById( 'wppa-bulk-owner' ).value = wppa_getCookie( 'wppa_bulk_owner' ); } } ); </script> <form action="<?php echo $link . '&wppa-page=' . $page . '#manage-photos'; ?> " method="post" > <?php wp_nonce_field('wppa-bulk', 'wppa-bulk'); ?> <h3> <span style="font-weight:bold;" ><?php _e('Bulk action:', 'wp-photo-album-plus'); ?> </span> <select id="wppa-bulk-action" name="wppa-bulk-action" onchange="wppaBulkActionChange( this, 'bulk-album' )" > <option value="" ></option> <option value="wppa-bulk-delete" ><?php _e('Delete', 'wp-photo-album-plus'); ?> </option> <option value="wppa-bulk-move-to" ><?php _e('Move to', 'wp-photo-album-plus'); ?> </option> <option value="wppa-bulk-copy-to" ><?php _e('Copy to', 'wp-photo-album-plus'); ?> </option> <?php if (current_user_can('wppa_admin') || current_user_can('wppa_moderate')) { ?> <option value="wppa-bulk-status" ><?php _e('Set status to', 'wp-photo-album-plus'); ?> </option> <?php } ?> <?php if (wppa_user_is('administrator') && wppa_switch('photo_owner_change')) { ?> <option value="wppa-bulk-owner" ><?php _e('Set owner to', 'wp-photo-album-plus'); ?> </option> <?php } ?> </select> <select name="wppa-bulk-album" id="wppa-bulk-album" style="display:none;" onchange="wppa_setCookie( 'wppa_bulk_album',this.value,365 );" > <?php echo wppa_album_select_a(array('checkaccess' => true, 'path' => wppa_switch('hier_albsel'), 'exclude' => $album, 'selected' => '0', 'addpleaseselect' => true)); ?> </select> <select name="wppa-bulk-status" id="wppa-bulk-status" style="display:none;" onchange="wppa_setCookie( 'wppa_bulk_status',this.value,365 );" > <option value="" ><?php _e('- select a status -', 'wp-photo-album-plus'); ?> </option> <option value="pending" ><?php _e('Pending', 'wp-photo-album-plus'); ?> </option> <option value="publish" ><?php _e('Publish', 'wp-photo-album-plus'); ?> </option> <?php if (wppa_switch('ext_status_restricted') && !wppa_user_is('administrator')) { $dis = ' disabled'; } else { $dis = ''; } ?> <option value="featured"<?php echo $dis; ?> ><?php _e('Featured', 'wp-photo-album-plus'); ?> </option> <option value="gold" <?php echo $dis; ?> ><?php _e('Gold', 'wp-photo-album-plus'); ?> </option> <option value="silver" <?php echo $dis; ?> ><?php _e('Silver', 'wp-photo-album-plus'); ?> </option> <option value="bronze" <?php echo $dis; ?> ><?php _e('Bronze', 'wp-photo-album-plus'); ?> </option> <option value="scheduled" <?php echo $dis; ?> ><?php _e('Scheduled', 'wp-photo-album-plus'); ?> </option> <option value="private" <?php echo $dis; ?> ><?php _e('Private', 'wp-photo-album-plus'); ?> </option> </select> <!-- Owner --> <?php $users = wppa_get_users(); if (count($users)) { ?> <select name="wppa-bulk-owner" id="wppa-bulk-owner" style="display:none;" onchange="wppa_setCookie( 'wppa_bulk_owner',this.value,365 );"> <option value="" ><?php _e('- select an owner -', 'wp-photo-album-plus'); ?> </option> <?php foreach ($users as $user) { echo '<option value="' . $user['user_login'] . '" >' . $user['display_name'] . ' (' . $user['user_login'] . ')</option>'; } ?> </select> <?php } else { ?> <input name="wppa-bulk-owner" id="wppa-bulk-owner" style="display:none;" onchange="wppa_setCookie( 'wppa_bulk_owner',this.value,365 );" /> <?php } ?> <!-- Submit --> <input type="submit" onclick="return wppaBulkDoitOnClick()" class="button-primary" value="<?php _e('Doit!', 'wp-photo-album-plus'); ?> " /> <span style="font-family:sans-serif; font-size:12px; font-style:italic; font-weight:normal;" > <?php _e('Pressing this button will reload the page after executing the selected action', 'wp-photo-album-plus'); ?> </span> </h3> <table class="widefat" > <thead style="font-weight:bold;" > <td><input type="checkbox" class="wppa-bulk-photo" onchange="jQuery( '.wppa-bulk-photo' ).attr( 'checked', this.checked );" /></td> <td><?php _e('ID', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Preview', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Name', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Description', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Status', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Owner', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Remark', 'wp-photo-album-plus'); ?> </td> </thead> <tbody> <?php foreach ($photos as $photo) { ?> <?php $id = $photo['id']; ?> <tr id="photoitem-<?php echo $photo['id']; ?> " > <!-- Checkbox --> <td> <input type="hidden" id="photo-nonce-<?php echo $photo['id']; ?> " value="<?php echo wp_create_nonce('wppa_nonce_' . $photo['id']); ?> " /> <input type="checkbox" name="wppa-bulk-photo[<?php echo $photo['id']; ?> ]" class="wppa-bulk-photo" /> </td> <!-- ID and delete link --> <td><?php echo $photo['id']; ?> <br /><a onclick="if ( confirm( '<?php _e('Are you sure you want to delete this photo?', 'wp-photo-album-plus'); ?> ' ) ) wppaAjaxDeletePhoto( <?php echo $photo['id']; ?> , '<td colspan=3 >', '</td>' )" style="color:red;font-weight:bold;"><?php _e('Delete', 'wp-photo-album-plus'); ?> </a> </td> <!-- Preview --> <td style="min-width:240px; text-align:center;" > <?php if (wppa_is_video($photo['id'])) { ?> <a href="<?php echo str_replace('xxx', 'mp4', wppa_get_photo_url($photo['id'])); ?> " target="_blank" title="Click to see fullsize" > <?php // Animating size changes of a video tag is not a good idea. It will rapidly screw up browser cache and cpu ?> <?php echo wppa_get_video_html(array('id' => $id, 'height' => '60', 'controls' => false, 'tagid' => 'pa-id-' . $id, 'events' => ' onmouseover="jQuery( this ).css( \'height\', \'160\' )" onmouseout="jQuery( this ).css( \'height\', \'60\' )"', 'preload' => 'metadata', 'use_thumb' => true)); ?> <!-- <video preload="metadata" style="height:60px;" onmouseover="jQuery( this ).css( 'height', '160' )" onmouseout="jQuery( this ).css( 'height', '60' )" > <?php // echo wppa_get_video_body( $photo['id'] ) ?> </video> --> </a> <?php } else { ?> <a href="<?php echo wppa_fix_poster_ext(wppa_get_photo_url($photo['id']), $photo['id']); ?> " target="_blank" title="Click to see fullsize" > <img class="wppa-bulk-thumb" src="<?php echo wppa_fix_poster_ext(wppa_get_thumb_url($photo['id']), $photo['id']); ?> " style="height:60px;" onmouseover="jQuery( this ).stop().animate( {height:120}, 100 )" onmouseout="jQuery( this ).stop().animate( {height:60}, 100 )" /> </a> <?php } ?> </td> <td style="width:25%;" > <input type="text" style="width:100%;" id="pname-<?php echo $photo['id']; ?> " onchange="wppaAjaxUpdatePhoto( <?php echo $photo['id']; ?> , 'name', this );" value="<?php echo esc_attr(stripslashes($photo['name'])); ?> " /> <?php if (wppa_is_video($photo['id'])) { echo '<br />' . wppa_get_videox($photo['id']) . ' x ' . wppa_get_videoy($photo['id']) . ' px.'; } else { $sp = wppa_get_source_path($photo['id']); if (is_file($sp)) { $ima = getimagesize($sp); if (is_array($ima)) { echo '<br />' . $ima['0'] . ' x ' . $ima['1'] . ' px.'; } } } ?> </td> <!-- Description --> <td style="width:25%;" > <textarea class="wppa-bulk-dec" style="height:50px; width:100%" onchange="wppaAjaxUpdatePhoto( <?php echo $photo['id']; ?> , 'description', this )" ><?php echo stripslashes($photo['description']); ?> </textarea> </td> <!-- Status --> <td> <?php if (current_user_can('wppa_admin') || current_user_can('wppa_moderate')) { ?> <select id="status-<?php echo $photo['id']; ?> " onchange="wppaAjaxUpdatePhoto( <?php echo $photo['id']; ?> , 'status', this ); wppaPhotoStatusChange( <?php echo $photo['id']; ?> ); "> <option value="pending" <?php if ($photo['status'] == 'pending') { echo 'selected="selected"'; } ?> ><?php _e('Pending', 'wp-photo-album-plus'); ?> </option> <option value="publish" <?php if ($photo['status'] == 'publish') { echo 'selected="selected"'; } ?> ><?php _e('Publish', 'wp-photo-album-plus'); ?> </option> <?php if (wppa_switch('ext_status_restricted') && !wppa_user_is('administrator')) { $dis = ' disabled'; } else { $dis = ''; } ?> <option value="featured" <?php if ($photo['status'] == 'featured') { echo 'selected="selected"'; } echo $dis; ?> ><?php _e('Featured', 'wp-photo-album-plus'); ?> </option> <option value="gold" <?php if ($photo['status'] == 'gold') { echo 'selected="selected"'; } echo $dis; ?> ><?php _e('Gold', 'wp-photo-album-plus'); ?> </option> <option value="silver" <?php if ($photo['status'] == 'silver') { echo 'selected="selected"'; } echo $dis; ?> ><?php _e('Silver', 'wp-photo-album-plus'); ?> </option> <option value="bronze" <?php if ($photo['status'] == 'bronze') { echo 'selected="selected"'; } echo $dis; ?> ><?php _e('Bronze', 'wp-photo-album-plus'); ?> </option> <option value="scheduled" <?php if ($photo['status'] == 'scheduled') { echo 'selected="selected"'; } echo $dis; ?> ><?php _e('Scheduled', 'wp-photo-album-plus'); ?> </option> <option value="private" <?php if ($photo['status'] == 'private') { echo 'selected="selected"'; } echo $dis; ?> ><?php _e('Private', 'wp-photo-album-plus'); ?> </option> </select> <?php } else { if ($photo['status'] == 'pending') { _e('Pending', 'wp-photo-album-plus'); } elseif ($photo['status'] == 'publish') { _e('Publish', 'wp-photo-album-plus'); } elseif ($photo['status'] == 'featured') { e('Featured'); } elseif ($photo['status'] == 'gold') { _e('Gold', 'wp-photo-album-plus'); } elseif ($photo['status'] == 'silver') { _e('Silver', 'wp-photo-album-plus'); } elseif ($photo['status'] == 'bronze') { _e('Bronze', 'wp-photo-album-plus'); } elseif ($photo['status'] == 'scheduled') { _e('Scheduled', 'wp-photo-album-plus'); } elseif ($photo['status'] == 'private') { _e('Private', 'wp-photo-album-plus'); } } ?> </td> <!-- Owner --> <td> <?php echo $photo['owner']; ?> </td> <!-- Remark --> <td id="photostatus-<?php echo $photo['id']; ?> " style="width:25%;" > <?php _e('Not modified', 'wp-photo-album-plus'); ?> <script type="text/javascript">wppaPhotoStatusChange( <?php echo $photo['id']; ?> )</script> </td> </tr> <?php } ?> </tbody> <tfoot style="font-weight:bold;" > <td><input type="checkbox" class="wppa-bulk-photo" onchange="jQuery( '.wppa-bulk-photo' ).attr( 'checked', this.checked );" /></td> <td><?php _e('ID', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Preview', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Name', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Description', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Status', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Owner', 'wp-photo-album-plus'); ?> </td> <td><?php _e('Remark', 'wp-photo-album-plus'); ?> </td> </tfoot> </table> </form> <?php wppa_admin_page_links($page, $pagesize, $count, $link); } else { if ($page == '1') { if (isset($_REQUEST['wppa-searchstring'])) { echo '<h3>' . __('No photos matching your search criteria.', 'wp-photo-album-plus') . '</h3>'; } else { echo '<h3>' . __('No photos yet in this album.', 'wp-photo-album-plus') . '</h3>'; } } else { $page_1 = $page - '1'; echo sprintf(__('Page %d is empty, try <a href="%s" >page %d</a>.', 'wp-photo-album-plus'), $page, $link . '&wppa-page=' . $page_1 . '#manage-photos', $page_1); } } } else { wppa_dbg_msg('Missing required argument in wppa_album_photos() 2', 'red', 'force'); } }
function wppa_get_widgetphotos($alb, $option = '') { global $wpdb; $photos = false; $query = ''; // Compile status clause switch (wppa_opt('widget_status_filter')) { case 'publish': $statusclause = " `status` = 'publish' "; break; case 'featured': $statusclause = " `status` = 'featured' "; break; case 'gold': $statusclause = " `status` = 'gold' "; break; case 'silver': $statusclause = " `status` = 'silver' "; break; case 'bronze': $statusclause = " `status` = 'bronze' "; break; case 'anymedal': $statusclause = " `status` IN ( 'gold', 'silver', 'bronze' ) "; break; default: $statusclause = " `status` <> 'scheduled' "; if (!is_user_logged_in()) { $statusclause .= " AND `status` <> 'private' "; } } // Is it a single album? if (wppa_is_int($alb)) { $query = $wpdb->prepare("SELECT `id`, `p_order` FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s " . " AND " . $statusclause . $option, $alb); } elseif (strchr($alb, ',')) { $alb = trim($alb, ','); // Test for numeric only ( security test ) $t = str_replace(',', '', $alb); if (is_numeric($t)) { $query = "SELECT `id`, `p_order` FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` IN ( " . $alb . " ) " . "AND " . $statusclause . $option; } } elseif ($alb == 'all') { $query = "SELECT `id`, `p_order` FROM `" . WPPA_PHOTOS . "` " . " WHERE " . $statusclause . $option; } elseif ($alb == 'sep') { $albs = $wpdb->get_results("SELECT `id`, `a_parent` FROM `" . WPPA_ALBUMS . "`", ARRAY_A); $query = "SELECT `id`, `p_order` FROM `" . WPPA_PHOTOS . "` WHERE ( `album` = '0' "; $first = true; foreach ($albs as $a) { if ($a['a_parent'] == '-1') { $query .= "OR `album` = '" . $a['id'] . "' "; } } $query .= ") AND " . $statusclause . $option; } elseif ($alb == 'all-sep') { $albs = $wpdb->get_results("SELECT `id`, `a_parent` FROM `" . WPPA_ALBUMS . "`", ARRAY_A); $query = "SELECT `id`, `p_order` FROM `" . WPPA_PHOTOS . "` WHERE ( `album` IN ('0'"; foreach ($albs as $a) { if ($a['a_parent'] != '-1') { $query .= ",'" . $a['id'] . "'"; } } $query .= ") ) AND " . $statusclause . $option; } elseif ($alb == 'topten') { // Find the 'top' policy 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; } // It is assumed that status is ok for top rated photos $query = "SELECT `id`, `p_order` FROM `" . WPPA_PHOTOS . "` ORDER BY " . $sortby . " LIMIT " . wppa_opt('topten_count'); $query .= $option; } // Do the query if ($query) { $photos = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q-Potd'); wppa_dbg_msg('Potd query: ' . $query); } else { $photos = array(); } // Ready return $photos; }
function wppa_get_widgetphotos($alb, $option = '') { global $wpdb; $photos = false; // Is it a single album? if (is_numeric($alb)) { $query = $wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s " . $option, $alb); $photos = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q-WidP1'); wppa_cache_photo('add', $photos); } elseif (strchr($alb, ',')) { $albs = explode(',', $alb); $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = '0' "; foreach ($albs as $a) { if (is_numeric($a)) { $query .= "OR `album` = '" . $a . "' "; } } $query .= $option; $photos = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q-WidP2'); wppa_cache_photo('add', $photos); } elseif ($alb == 'all') { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` " . $option; $photos = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q-WidP3'); wppa_cache_photo('add', $photos); } elseif ($alb == 'sep') { $albs = $wpdb->get_results("SELECT `id`, `a_parent` FROM `" . WPPA_ALBUMS . "`", ARRAY_A); $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = '0' "; $first = true; foreach ($albs as $a) { if ($a['a_parent'] == '-1') { $query .= "OR `album` = '" . $a['id'] . "' "; } } $query .= $option; $photos = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q-WidP4'); wppa_cache_photo('add', $photos); } elseif ($alb == 'all-sep') { $albs = $wpdb->get_results("SELECT `id`, `a_parent` FROM `" . WPPA_ALBUMS . "`", ARRAY_A); $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = '0' "; foreach ($albs as $a) { if ($a['a_parent'] != '-1') { $query .= "OR `album` = '" . $a['id'] . "' "; } } $option; $photos = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q-WidP5'); wppa_cache_photo('add', $photos); } elseif ($alb == 'topten') { // Find the 'top' policy switch (wppa_opt('wppa_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; } $query = "SELECT * FROM `" . WPPA_PHOTOS . "` ORDER BY " . $sortby . " LIMIT " . wppa_opt('wppa_topten_count'); $photos = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q-WidP6'); wppa_cache_photo('add', $photos); } elseif ($alb == 'featured') { $query = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'featured' " . $option; $photos = $wpdb->get_results($query, ARRAY_A); wppa_dbg_q('Q-WidP7'); wppa_cache_photo('add', $photos); } return $photos; }
function wppa_edit_comment($id) { global $wpdb; $record = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WPPA_COMMENTS . " WHERE id = %s LIMIT 0,1", $id), ARRAY_A); if ($record) { if (isset($_POST['comment'])) { $record['comment'] = $_POST['comment']; } if (isset($_POST['email'])) { $record['email'] = $_POST['email']; } if (isset($_POST['user'])) { $record['user'] = $_POST['user']; } $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_COMMENTS . "` SET `comment` = %s, `email` = %s, `user` = %s WHERE `id` = %s LIMIT 1", $record['comment'], $record['email'], $record['user'], $id)); if ($iret === false) { wppa_error_message(__('Unable to update comment. Err =', 'wp-photo-album-plus') . ' 2.'); return false; } return true; } else { wppa_error_message(__('Unable to update comment. Err =', 'wp-photo-album-plus') . ' 1.'); return false; } }
function wppa_upload_zip() { global $target; $file = $_FILES['file_zip']; $name = wppa_sanitize_file_name($file['name']); $type = $file['type']; $error = $file['error']; $size = $file['size']; $temp = $file['tmp_name']; $target = WPPA_DEPOT_PATH . '/' . $name; copy($temp, $target); if ($error == '0') { wppa_ok_message(__('Zipfile', 'wp-photo-album-plus') . ' ' . $name . ' ' . __('sucessfully uploaded.', 'wp-photo-album-plus')); } else { wppa_error_message(__('Error', 'wp-photo-album-plus') . ' ' . $error . ' ' . __('during upload.', 'wp-photo-album-plus')); } return $error; }
function wppa_make_the_photo_files($file, $id, $ext) { global $wpdb; $thumb = wppa_cache_thumb($id); $src_size = @getimagesize($file, $info); // If the given file is not an image file, log error and exit if (!$src_size) { if (is_admin()) { wppa_error_message(sprintf(__('ERROR: File %s is not a valid picture file.', 'wp-photo-album-plus'), $file)); } else { wppa_alert(sprintf(__('ERROR: File %s is not a valid picture file.', 'wp-photo-album-plus'), $file)); } return false; } // Find output path photo file $newimage = wppa_get_photo_path($id); if ($ext) { $newimage = wppa_strip_ext($newimage) . '.' . strtolower($ext); } // If Resize on upload is checked if (wppa_switch('resize_on_upload')) { // Picture sizes $src_width = $src_size[0]; // Temp convert to logical width if stereo if ($thumb['stereo']) { $src_width /= 2; } $src_height = $src_size[1]; // Max sizes if (wppa_opt('resize_to') == '0') { // from fullsize $max_width = wppa_opt('fullsize'); $max_height = wppa_opt('maxheight'); } else { // from selection $screen = explode('x', wppa_opt('resize_to')); $max_width = $screen[0]; $max_height = $screen[1]; } // If orientation needs +/- 90 deg rotation, swap max x and max y $ori = wppa_get_exif_orientation($file); if ($ori >= 5 && $ori <= 8) { $t = $max_width; $max_width = $max_height; $max_height = $t; } // Is source more landscape or more portrait than max window if ($src_width / $src_height > $max_width / $max_height) { // focus on width $focus = 'W'; $need_downsize = $src_width > $max_width; } else { // focus on height $focus = 'H'; $need_downsize = $src_height > $max_height; } // Convert back to physical size if ($thumb['stereo']) { $src_width *= 2; } // Downsize required ? if ($need_downsize) { // Find mime type $mime = $src_size[2]; // Create the source image switch ($mime) { // mime type case 1: // gif $temp = @imagecreatefromgif($file); if ($temp) { $src = imagecreatetruecolor($src_width, $src_height); imagecopy($src, $temp, 0, 0, 0, 0, $src_width, $src_height); imagedestroy($temp); } else { $src = false; } break; case 2: // jpeg if (!function_exists('wppa_imagecreatefromjpeg')) { wppa_log('Error', 'Function wppa_imagecreatefromjpeg does not exist.'); } $src = @wppa_imagecreatefromjpeg($file); break; case 3: // png $src = @imagecreatefrompng($file); break; } if (!$src) { wppa_log('Error', 'Image file ' . $file . ' is corrupt while downsizing photo'); return false; } // Create the ( empty ) destination image if ($focus == 'W') { if ($thumb['stereo']) { $max_width *= 2; } $dst_width = $max_width; $dst_height = round($max_width * $src_height / $src_width); } else { $dst_height = $max_height; $dst_width = round($max_height * $src_width / $src_height); } $dst = imagecreatetruecolor($dst_width, $dst_height); // If Png, save transparancy if ($mime == 3) { imagealphablending($dst, false); imagesavealpha($dst, true); } // Do the copy imagecopyresampled($dst, $src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height); // Remove source image imagedestroy($src); // Save the photo switch ($mime) { // mime type case 1: imagegif($dst, $newimage); break; case 2: imagejpeg($dst, $newimage, wppa_opt('jpeg_quality')); break; case 3: imagepng($dst, $newimage, 6); break; } // Remove destination image imagedestroy($dst); } else { // No downsize needed, picture is small enough copy($file, $newimage); } } else { copy($file, $newimage); } // File successfully created ? if (is_file($newimage)) { // Make sure file is accessable wppa_chmod($newimage); // Optimize file wppa_optimize_image_file($newimage); } else { if (is_admin()) { wppa_error_message(__('ERROR: Resized or copied image could not be created.', 'wp-photo-album-plus')); } else { wppa_alert(__('ERROR: Resized or copied image could not be created.', 'wp-photo-album-plus')); } return false; } // Process the iptc data wppa_import_iptc($id, $info); // Process the exif data wppa_import_exif($id, $file); // GPS wppa_get_coordinates($file, $id); // Set ( update ) exif date-time if available $exdt = wppa_get_exif_datetime($file); if ($exdt) { wppa_update_photo(array('id' => $id, 'exifdtm' => $exdt)); } // Check orientation wppa_orientate_image($id, wppa_get_exif_orientation($file)); // Compute and save sizes wppa_get_photox($id, 'force'); // Show progression if (is_admin() && !wppa('ajax')) { echo '.'; } // Update CDN $cdn = wppa_cdn('admin'); if ($cdn) { switch ($cdn) { case 'cloudinary': wppa_upload_to_cloudinary($id); break; default: wppa_dbg_msg('Missing upload instructions for ' . $cdn, 'red', 'force'); } } // Create stereo images wppa_create_stereo_images($id); // Create thumbnail... wppa_create_thumbnail($id); // Clear (super)cache wppa_clear_cache(); return true; }
function wppa_verify_page($slug) { global $wpdb; global $wppa_opt; if (!isset($wppa_opt[$slug])) { wppa_error_message('Unexpected error in wppa_verify_page()', 'red', 'force'); return; } $iret = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . $wpdb->posts . "` WHERE `post_type` = 'page' AND `post_status` = 'publish' AND `ID` = %s", wppa_opt($slug))); if (!$iret) { wppa_update_option($slug, '0'); } }