function wppa_do_frontend_file_upload($file, $alb) { global $wpdb; // Log upload attempt wppa_log('Upl', 'FE Upload attempt of file ' . $file['name'] . ', size=' . filesize($file['tmp_name'])); $album = wppa_cache_album($alb); if (!wppa_allow_uploads($alb) || !wppa_allow_user_uploads()) { wppa_alert(__('Max uploads reached', 'wp-photo-album-plus')); return false; } if ($file['error'] != '0') { wppa_alert(__('Error during upload', 'wp-photo-album-plus')); return false; } $imgsize = getimagesize($file['tmp_name']); if (!is_array($imgsize)) { wppa_alert(__('Uploaded file is not an image', 'wp-photo-album-plus')); return false; } if ($imgsize[2] < 1 || $imgsize[2] > 3) { wppa_alert(sprintf(__('Only gif, jpg and png image files are supported. Returned filetype = %d.', 'wp-photo-album-plus'), $imagesize[2])); return false; } $ms = wppa_opt('upload_fronend_maxsize'); if ($ms) { // Max size configured if ($imgsize[0] > $ms || $imgsize[0] > $ms) { wppa_alert(sprintf(__('Uploaded file is larger than the allowed maximum of %d x %d pixels.', 'wp-photo-album-plus'), $ms, $ms)); return false; } } if (wppa_switch('void_dups')) { // Check for already exists if (wppa_file_is_in_album(wppa_sanitize_file_name($file['name']), $alb)) { wppa_alert(sprintf(__('Uploaded file %s already exists in this album.', 'wp-photo-album-plus'), wppa_sanitize_file_name($file['name']))); return false; } } $mayupload = wppa_check_memory_limit('', $imgsize[0], $imgsize[1]); if ($mayupload === false) { $maxsize = wppa_check_memory_limit(false); if (is_array($maxsize)) { wppa_alert(sprintf(__('The image is too big. Max photo size: %d x %d (%2.1f MegaPixel)', 'wp-photo-album-plus'), $maxsize['maxx'], $maxsize['maxy'], $maxsize['maxp'] / (1024 * 1024))); return false; } } switch ($imgsize[2]) { // mime type case 1: $ext = 'gif'; break; case 2: $ext = 'jpg'; break; case 3: $ext = 'png'; break; } if (wppa_get_post('user-name')) { $name = wppa_get_post('user-name'); } else { $name = $file['name']; } $name = wppa_sanitize_photo_name($name); $desc = balanceTags(wppa_get_post('user-desc'), true); $linktarget = '_self'; $status = wppa_switch('upload_moderate') && !current_user_can('wppa_admin') ? 'pending' : 'publish'; $filename = wppa_sanitize_file_name($file['name']); $id = wppa_create_photo_entry(array('album' => $alb, 'ext' => $ext, 'name' => $name, 'description' => $desc, 'status' => $status, 'filename' => $filename)); if (!$id) { wppa_alert(__('Could not insert photo into db.', 'wp-photo-album-plus')); return false; } else { wppa_save_source($file['tmp_name'], $filename, $alb); wppa_update_album(array('id' => $alb, 'modified' => time())); wppa_flush_treecounts($alb); wppa_flush_upldr_cache('photoid', $id); } if (wppa_make_the_photo_files($file['tmp_name'], $id, $ext)) { // Repair photoname if not standard if (!wppa_get_post('user-name')) { wppa_set_default_name($id, $file['name']); } // Custom data if (wppa_switch('fe_custom_fields')) { $custom_data = array('', '', '', '', '', '', '', '', '', ''); for ($i = '0'; $i < '10'; $i++) { if (isset($_POST['wppa-user-custom-' . $i])) { $custom_data[$i] = strip_tags($_POST['wppa-user-custom-' . $i]); } } wppa_update_photo(array('id' => $id, 'custom' => serialize($custom_data))); } // Default tags wppa_set_default_tags($id); // Custom tags $tags = wppa_get_photo_item($id, 'tags'); $oldt = $tags; for ($i = '1'; $i < '4'; $i++) { if (isset($_POST['wppa-user-tags-' . $i])) { // Existing tags $tags .= ',' . implode(',', $_POST['wppa-user-tags-' . $i]); } } if (isset($_POST['wppa-new-tags'])) { // New tags $newt = $_POST['wppa-new-tags']; $tags .= ',' . $newt; } else { $newt = ''; } $tags = wppa_sanitize_tags(str_replace(array('\'', '"'), ',', wppa_filter_iptc(wppa_filter_exif($tags, $id), $id))); if ($tags != $oldt) { // Added tag(s) wppa_update_photo(array('id' => $id, 'tags' => $tags)); } // Index wppa_index_add('photo', $id); // Tags if ($tags) { wppa_clear_taglist(); // Forces recreation } // and add watermark ( optionally ) to fullsize image only wppa_add_watermark($id); // Also to thumbnail? if (wppa_switch('watermark_thumbs')) { wppa_create_thumbnail($id); // create new thumb } // Is it a default coverimage? wppa_check_coverimage($id); // Mail if (wppa_switch('upload_notify')) { $to = get_bloginfo('admin_email'); $subj = sprintf(__('New photo uploaded: %s', 'wp-photo-album-plus'), $name); $cont['0'] = sprintf(__('User %1$s uploaded photo %2$s into album %3$s', 'wp-photo-album-plus'), wppa_get_user(), $id, wppa_get_album_name($alb)); if (wppa_switch('upload_moderate') && !current_user_can('wppa_admin')) { $cont['1'] = __('This upload requires moderation', 'wp-photo-album-plus'); $cont['2'] = '<a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Moderate manage photo', 'wp-photo-album-plus') . '</a>'; } else { $cont['1'] = __('Details:', 'wp-photo-album-plus'); $cont['1'] .= ' <a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Manage photo', 'wp-photo-album-plus') . '</a>'; } wppa_send_mail($to, $subj, $cont, $id); } return true; } else { return false; } }
function wppa_set_default_tags($id) { global $wpdb; $thumb = wppa_cache_thumb($id); $album = wppa_cache_album($thumb['album']); $tags = wppa_sanitize_tags(str_replace(array('\'', '"'), ',', wppa_filter_iptc(wppa_filter_exif($album['default_tags'], $id), $id))); if ($tags) { wppa_update_photo(array('id' => $id, 'tags' => $tags)); wppa_clear_taglist(); wppa_cache_thumb('invalidate', $id); } }
function wppa_do_frontend_file_upload($file, $alb) { global $wpdb; global $wppa_supported_video_extensions; global $wppa_supported_audio_extensions; // Log upload attempt wppa_log('Upl', 'FE Upload attempt of file ' . $file['name'] . ', size=' . filesize($file['tmp_name'])); $album = wppa_cache_album($alb); // Legal here? if (!wppa_allow_uploads($alb) || !wppa_allow_user_uploads()) { wppa_alert(__('Max uploads reached', 'wp-photo-album-plus')); return false; } // No error during upload? if ($file['error'] != '0') { wppa_alert(__('Error during upload', 'wp-photo-album-plus')); return false; } // Find the filename $filename = wppa_sanitize_file_name($file['name']); $filename = wppa_strip_ext($filename); // See if this filename with any extension already exists in this album $id = $wpdb->get_var("SELECT `id` FROM `" . WPPA_PHOTOS . "` WHERE `filename` LIKE '" . $filename . ".%' AND `album` = " . $alb); // Addition to an av item? if ($id) { $is_av = wppa_get_photo_item($id, 'ext') == 'xxx'; } else { $is_av = false; } // see if audio / video and process if (wppa_switch('enable_video') && wppa_switch('user_upload_video_on') && in_array(strtolower(wppa_get_ext($file['name'])), $wppa_supported_video_extensions) || wppa_switch('enable_audio') && wppa_switch('user_upload_audio_on') && in_array(strtolower(wppa_get_ext($file['name'])), $wppa_supported_audio_extensions)) { $is_av = true; // Find the name if (wppa_get_post('user-name')) { $name = wppa_get_post('user-name'); } else { $name = $file['name']; } $name = wppa_sanitize_photo_name($name); $filename .= '.xxx'; // update entry if ($id) { wppa_update_photo(array('id' => $id, 'ext' => 'xxx', 'filename' => $filename)); } // Add new entry if (!$id) { $id = wppa_create_photo_entry(array('album' => $alb, 'filename' => $filename, 'ext' => 'xxx', 'name' => $name, 'description' => balanceTags(wppa_get_post('user-desc'), true))); if (!$id) { wppa_alert(__('Could not insert media into db.', 'wp-photo-album-plus')); return false; } } // Housekeeping wppa_update_album(array('id' => $alb, 'modified' => time())); wppa_flush_treecounts($alb); wppa_flush_upldr_cache('photoid', $id); // Add video filetype $ext = strtolower(wppa_get_ext($file['name'])); $newpath = wppa_strip_ext(wppa_get_photo_path($id)) . '.' . $ext; copy($file['tmp_name'], $newpath); // Repair name if not standard if (!wppa_get_post('user-name')) { wppa_set_default_name($id, $file['name']); } // tags wppa_fe_add_tags($id); // custom wppa_fe_add_custom($id); // Done! return $id; } // If not already an existing audio / video; Forget the id from a previously found item with the same filename. if (!$is_av) { $id = false; } // Is it an image? $imgsize = getimagesize($file['tmp_name']); if (!is_array($imgsize)) { wppa_alert(__('Uploaded file is not an image', 'wp-photo-album-plus')); return false; } // Is it a supported image filetype? if ($imgsize[2] != IMAGETYPE_GIF && $imgsize[2] != IMAGETYPE_JPEG && $imgsize[2] != IMAGETYPE_PNG) { wppa_alert(sprintf(__('Only gif, jpg and png image files are supported. Returned info = %s.', 'wp-photo-album-plus'), wppa_serialize($imgsize)), false, false); return false; } // Is it not too big? $ms = wppa_opt('upload_fronend_maxsize'); if ($ms) { // Max size configured if ($imgsize[0] > $ms || $imgsize[1] > $ms) { wppa_alert(sprintf(__('Uploaded file is larger than the allowed maximum of %d x %d pixels.', 'wp-photo-album-plus'), $ms, $ms)); return false; } } // Check for already exists if (wppa_switch('void_dups')) { if (wppa_file_is_in_album(wppa_sanitize_file_name($file['name']), $alb)) { wppa_alert(sprintf(__('Uploaded file %s already exists in this album.', 'wp-photo-album-plus'), wppa_sanitize_file_name($file['name']))); return false; } } // Check for max memory needed to rocess image? $mayupload = wppa_check_memory_limit('', $imgsize[0], $imgsize[1]); if ($mayupload === false) { $maxsize = wppa_check_memory_limit(false); if (is_array($maxsize)) { wppa_alert(sprintf(__('The image is too big. Max photo size: %d x %d (%2.1f MegaPixel)', 'wp-photo-album-plus'), $maxsize['maxx'], $maxsize['maxy'], $maxsize['maxp'] / (1024 * 1024))); return false; } } // Find extension from mimetype switch ($imgsize[2]) { // mime type case 1: $ext = 'gif'; break; case 2: $ext = 'jpg'; break; case 3: $ext = 'png'; break; } // Did the user supply a photoname? if (wppa_get_post('user-name')) { $name = wppa_get_post('user-name'); } else { $name = $file['name']; } // Sanitize input $name = wppa_sanitize_photo_name($name); $desc = balanceTags(wppa_get_post('user-desc'), true); // If BlogIt! and no descrption given, use name field - this is for the shortcode used: typ"mphoto" if (!$desc && isset($_POST['wppa-blogit'])) { $desc = 'w#name'; } // Find status and other needed data $linktarget = '_self'; $status = wppa_switch('upload_moderate') && !current_user_can('wppa_admin') ? 'pending' : 'publish'; if (wppa_switch('fe_upload_private')) { $status = 'private'; } $filename = wppa_sanitize_file_name($file['name']); // Create new entry if this is not a posterfile if (!$is_av) { $id = wppa_create_photo_entry(array('album' => $alb, 'ext' => $ext, 'name' => $name, 'description' => $desc, 'status' => $status, 'filename' => $filename)); } if (!$id) { wppa_alert(__('Could not insert photo into db.', 'wp-photo-album-plus')); return false; } else { wppa_save_source($file['tmp_name'], $filename, $alb); wppa_make_o1_source($id); wppa_update_album(array('id' => $alb, 'modified' => time())); wppa_flush_treecounts($alb); wppa_flush_upldr_cache('photoid', $id); } if (wppa_make_the_photo_files($file['tmp_name'], $id, $ext)) { // Repair photoname if not standard if (!wppa_get_post('user-name')) { wppa_set_default_name($id, $file['name']); } // Custom data wppa_fe_add_custom($id); // Add tags wppa_fe_add_tags($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); // create new thumb } // Is it a default coverimage? wppa_check_coverimage($id); // Mail if (wppa_switch('upload_notify')) { $to = get_bloginfo('admin_email'); $subj = sprintf(__('New photo uploaded: %s', 'wp-photo-album-plus'), $name); $cont['0'] = sprintf(__('User %1$s uploaded photo %2$s into album %3$s', 'wp-photo-album-plus'), wppa_get_user(), $id, wppa_get_album_name($alb)); if (wppa_switch('upload_moderate') && !current_user_can('wppa_admin')) { $cont['1'] = __('This upload requires moderation', 'wp-photo-album-plus'); $cont['2'] = '<a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Moderate manage photo', 'wp-photo-album-plus') . '</a>'; } else { $cont['1'] = __('Details:', 'wp-photo-album-plus'); $cont['1'] .= ' <a href="' . get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=pmod&photo=' . $id . '" >' . __('Manage photo', 'wp-photo-album-plus') . '</a>'; } wppa_send_mail($to, $subj, $cont, $id); } return $id; } return false; }
function wppa_do_maintenance_proc($slug) { global $wpdb; global $thumb; global $wppa_opt; global $wppa_session; global $wppa_supported_video_extensions; global $wppa_supported_audio_extensions; // Check for multiple maintenance procs if (!wppa_switch('wppa_maint_ignore_concurrency_error')) { $all_slugs = array('wppa_remake_index_albums', 'wppa_remove_empty_albums', 'wppa_remake_index_photos', 'wppa_apply_new_photodesc_all', 'wppa_append_to_photodesc', 'wppa_remove_from_photodesc', 'wppa_remove_file_extensions', 'wppa_readd_file_extensions', 'wppa_regen_thumbs', 'wppa_rerate', 'wppa_recup', 'wppa_file_system', 'wppa_cleanup', 'wppa_remake', 'wppa_list_index', 'wppa_blacklist_user', 'wppa_un_blacklist_user', 'wppa_rating_clear', 'wppa_viewcount_clear', 'wppa_iptc_clear', 'wppa_exif_clear', 'wppa_watermark_all', 'wppa_create_all_autopages', 'wppa_leading_zeros', 'wppa_add_gpx_tag', 'wppa_optimize_ewww', 'wppa_comp_sizes', 'wppa_edit_tag'); foreach (array_keys($all_slugs) as $key) { if ($all_slugs[$key] != $slug) { if (get_option($all_slugs[$key] . '_togo', '0')) { // Process running return __('You can run only one maintenance procedure at a time', 'wppa') . '||' . $slug . '||' . __('Error', 'wppa') . '||' . '' . '||' . ''; } } } } // Lock this proc update_option($slug . '_user', wppa_get_user()); // Initialize $endtime = time() + '5'; // Allow for 5 seconds $chunksize = '1000'; $lastid = strval(intval(get_option($slug . '_last', '0'))); $errtxt = ''; $id = '0'; $topid = '0'; $reload = ''; if (!isset($wppa_session)) { $wppa_session = array(); } if (!isset($wppa_session[$slug . '_fixed'])) { $wppa_session[$slug . '_fixed'] = '0'; } if (!isset($wppa_session[$slug . '_deleted'])) { $wppa_session[$slug . '_deleted'] = '0'; } if (!isset($wppa_session[$slug . '_skipped'])) { $wppa_session[$slug . '_skipped'] = '0'; } if ($lastid == '0') { $wppa_session[$slug . '_fixed'] = '0'; $wppa_session[$slug . '_deleted'] = '0'; $wppa_session[$slug . '_skipped'] = '0'; } // Pre-processing needed? if ($lastid == '0') { switch ($slug) { case 'wppa_remake_index_albums': $wpdb->query("UPDATE `" . WPPA_INDEX . "` SET `albums` = ''"); break; case 'wppa_remake_index_photos': $wpdb->query("UPDATE `" . WPPA_INDEX . "` SET `photos` = ''"); wppa_index_compute_skips(); break; case 'wppa_recup': $wpdb->query("DELETE FROM `" . WPPA_IPTC . "` WHERE `photo` <> '0'"); $wpdb->query("DELETE FROM `" . WPPA_EXIF . "` WHERE `photo` <> '0'"); break; case 'wppa_file_system': if (get_option('wppa_file_system') == 'flat') { update_option('wppa_file_system', 'to-tree'); } if (get_option('wppa_file_system') == 'tree') { update_option('wppa_file_system', 'to-flat'); } break; case 'wppa_cleanup': $orphan_album = get_option('wppa_orphan_album', '0'); $album_exists = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM`" . WPPA_ALBUMS . "` WHERE `id` = %s", $orphan_album)); if (!$album_exists) { $orphan_album = false; } if (!$orphan_album) { $orphan_album = wppa_create_album_entry(array('name' => __('Orphan photos', 'wppa'), 'a_parent' => '-1', 'description' => __('This album contains refound lost photos', 'wppa'))); update_option('wppa_orphan_album', $orphan_album); } break; } } // Dispatch on albums / photos / single actions switch ($slug) { case 'wppa_remake_index_albums': case 'wppa_remove_empty_albums': // Process albums $table = WPPA_ALBUMS; $topid = $wpdb->get_var("SELECT `id` FROM `" . WPPA_ALBUMS . "` ORDER BY `id` DESC LIMIT 1"); $albums = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `id` > " . $lastid . " ORDER BY `id` LIMIT 100", ARRAY_A); wppa_cache_album('add', $albums); if ($albums) { foreach ($albums as $album) { $id = $album['id']; switch ($slug) { case 'wppa_remake_index_albums': wppa_index_add('album', $id); break; case 'wppa_remove_empty_albums': $p = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s", $id)); $a = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = %s", $id)); if (!$a && !$p) { $wpdb->query($wpdb->prepare("DELETE FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $id)); wppa_delete_album_source($id); wppa_flush_treecounts($id); wppa_index_remove('album', $id); } break; } // Test for timeout / ready $lastid = $id; update_option($slug . '_last', $lastid); if (time() > $endtime) { break; } // Time out } } else { // Nothing to do, Done anyway $lastid = $topid; } break; // End process albums // End process albums case 'wppa_remake_index_photos': $chunksize = '100'; case 'wppa_apply_new_photodesc_all': case 'wppa_append_to_photodesc': case 'wppa_remove_from_photodesc': case 'wppa_remove_file_extensions': case 'wppa_readd_file_extensions': case 'wppa_regen_thumbs': case 'wppa_rerate': case 'wppa_recup': case 'wppa_file_system': case 'wppa_cleanup': case 'wppa_remake': case 'wppa_watermark_all': case 'wppa_create_all_autopages': case 'wppa_leading_zeros': case 'wppa_add_gpx_tag': case 'wppa_optimize_ewww': case 'wppa_comp_sizes': case 'wppa_edit_tag': // Process photos $table = WPPA_PHOTOS; if ($slug == 'wppa_cleanup') { $topid = get_option('wppa_' . WPPA_PHOTOS . '_lastkey', '1') * 10; $photos = array(); for ($i = $lastid + '1'; $i <= $topid; $i++) { $photos[]['id'] = $i; } } else { $topid = $wpdb->get_var("SELECT `id` FROM `" . WPPA_PHOTOS . "` ORDER BY `id` DESC LIMIT 1"); $photos = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` > " . $lastid . " ORDER BY `id` LIMIT " . $chunksize, ARRAY_A); } if ($slug == 'wppa_edit_tag') { $edit_tag = get_option('wppa_tag_to_edit'); $new_tag = get_option('wppa_new_tag_value'); } if (!$photos && $slug == 'wppa_file_system') { $fs = get_option('wppa_file_system'); if ($fs == 'to-tree') { $to = 'tree'; } elseif ($fs == 'to-flat') { $to = 'flat'; } else { $to = $fs; } } if ($photos) { foreach ($photos as $photo) { $thumb = $photo; // Make globally known $id = $photo['id']; switch ($slug) { case 'wppa_remake_index_photos': wppa_index_add('photo', $id); break; case 'wppa_apply_new_photodesc_all': $value = $wppa_opt['wppa_newphoto_description']; $description = trim($value); if ($description != $photo['description']) { // Modified photo description $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `description` = %s WHERE `id` = %s", $description, $id)); } break; case 'wppa_append_to_photodesc': $value = trim($wppa_opt['wppa_append_text']); if (!$value) { return 'Unexpected error: missing text to append||' . $slug . '||Error||0'; } $description = rtrim($photo['description'] . ' ' . $value); if ($description != $photo['description']) { // Modified photo description $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `description` = %s WHERE `id` = %s", $description, $id)); } break; case 'wppa_remove_from_photodesc': $value = trim($wppa_opt['wppa_remove_text']); if (!$value) { return 'Unexpected error: missing text to remove||' . $slug . '||Error||0'; } $description = rtrim(str_replace($value, '', $photo['description'])); if ($description != $photo['description']) { // Modified photo description $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `description` = %s WHERE `id` = %s", $description, $id)); } break; case 'wppa_remove_file_extensions': if (!wppa_is_video($id)) { $name = str_replace(array('.jpg', '.png', '.gif', '.JPG', '.PNG', '.GIF'), '', $photo['name']); if ($name != $photo['name']) { // Modified photo name $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `name` = %s WHERE `id` = %s", $name, $id)); } } break; case 'wppa_readd_file_extensions': if (!wppa_is_video($id)) { $name = str_replace(array('.jpg', '.png', 'gif', '.JPG', '.PNG', '.GIF'), '', $photo['name']); if ($name == $photo['name']) { // Name had no fileextension $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `name` = %s WHERE `id` = %s", $name . '.' . $photo['ext'], $id)); } } break; case 'wppa_regen_thumbs': if (!wppa_is_video($id) || file_exists(str_replace('xxx', 'jpg', wppa_get_photo_path($id)))) { wppa_create_thumbnail($id); } break; case 'wppa_rerate': wppa_rate_photo($id); break; case 'wppa_recup': $a_ret = wppa_recuperate($id); if ($a_ret['iptcfix']) { $wppa_session[$slug . '_fixed']++; } if ($a_ret['exiffix']) { $wppa_session[$slug . '_fixed']++; } break; case 'wppa_file_system': $fs = get_option('wppa_file_system'); if ($fs == 'to-tree' || $fs == 'to-flat') { if ($fs == 'to-tree') { $from = 'flat'; $to = 'tree'; } else { $from = 'tree'; $to = 'flat'; } // Media files if (wppa_is_multi($id)) { // Can NOT use wppa_has_audio() or wppa_is_video(), they use wppa_get_photo_path() without fs switch!! $exts = array_merge($wppa_supported_video_extensions, $wppa_supported_audio_extensions); $pathfrom = wppa_get_photo_path($id, $from); $pathto = wppa_get_photo_path($id, $to); // wppa_log( 'dbg', 'Trying: '.$pathfrom ); foreach ($exts as $ext) { if (is_file(str_replace('.xxx', '.' . $ext, $pathfrom))) { // wppa_log( 'dbg', str_replace( '.xxx', '.'.$ext, $pathfrom ).' -> '.str_replace( '.xxx', '.'.$ext, $pathto )); @rename(str_replace('.xxx', '.' . $ext, $pathfrom), str_replace('.xxx', '.' . $ext, $pathto)); } } } // Poster / photo if (file_exists(wppa_fix_poster_ext(wppa_get_photo_path($id, $from), $id))) { @rename(wppa_fix_poster_ext(wppa_get_photo_path($id, $from), $id), wppa_fix_poster_ext(wppa_get_photo_path($id, $to), $id)); } // Thumbnail if (file_exists(wppa_fix_poster_ext(wppa_get_thumb_path($id, $from), $id))) { @rename(wppa_fix_poster_ext(wppa_get_thumb_path($id, $from), $id), wppa_fix_poster_ext(wppa_get_thumb_path($id, $to), $id)); } } break; case 'wppa_cleanup': $photo_files = glob(WPPA_UPLOAD_PATH . '/' . $id . '.*'); // Remove dirs if ($photo_files) { foreach (array_keys($photo_files) as $key) { if (is_dir($photo_files[$key])) { unset($photo_files[$key]); } } } // files left? process if ($photo_files) { foreach ($photo_files as $photo_file) { $basename = basename($photo_file); $ext = substr($basename, strpos($basename, '.') + '1'); if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $id))) { // no db entry for this photo if (wppa_is_id_free(WPPA_PHOTOS, $id)) { if (wppa_create_photo_entry(array('id' => $id, 'album' => $orphan_album, 'ext' => $ext, 'filename' => $basename))) { // Can create entry $wppa_session[$slug . '_fixed']++; // Bump counter wppa_log('Debug', 'Lost photo file ' . $photo_file . ' recovered'); } else { wppa_log('Debug', 'Unable to recover lost photo file ' . $photo_file . ' Create photo entry failed'); } } else { wppa_log('Debug', 'Could not recover lost photo file ' . $photo_file . ' The id is not free'); } } } } break; case 'wppa_remake': if (wppa_remake_files('', $id)) { $wppa_session[$slug . '_fixed']++; } else { $wppa_session[$slug . '_skipped']++; } break; case 'wppa_watermark_all': if (!wppa_is_video($id)) { if (wppa_add_watermark($id)) { wppa_create_thumbnail($id); // create new thumb $wppa_session[$slug . '_fixed']++; } else { $wppa_session[$slug . '_skipped']++; } } else { $wppa_session[$slug . '_skipped']++; } break; case 'wppa_create_all_autopages': wppa_get_the_auto_page($id); break; case 'wppa_leading_zeros': $name = $photo['name']; if (wppa_is_int($name)) { $target_len = wppa_opt('wppa_zero_numbers'); $name = strval(intval($name)); while (strlen($name) < $target_len) { $name = '0' . $name; } } if ($name !== $photo['name']) { $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `name` = %s WHERE `id` = %s", $name, $id)); } break; case 'wppa_add_gpx_tag': $tags = $photo['tags']; $temp = explode('/', $photo['location']); if (!isset($temp['2'])) { $temp['2'] = false; } if (!isset($temp['3'])) { $temp['3'] = false; } $lat = $temp['2']; $lon = $temp['3']; if ($lat < 0.01 && $lat > -0.01 && $lon < 0.01 && $lon > -0.01) { $lat = false; $lon = false; } if ($photo['location'] && strpos($tags, 'Gpx') === false && $lat && $lon) { // Add it $tags = wppa_sanitize_tags($tags . ',Gpx'); wppa_update_photo(array('id' => $photo['id'], 'tags' => $tags)); wppa_index_update('photo', $photo['id']); wppa_clear_taglist(); } elseif (strpos($tags, 'Gpx') !== false && !$lat && !$lon) { // Remove it $tags = wppa_sanitize_tags(str_replace('Gpx', '', $tags)); wppa_update_photo(array('id' => $photo['id'], 'tags' => $tags)); wppa_index_update('photo', $photo['id']); wppa_clear_taglist(); } break; case 'wppa_optimize_ewww': $file = wppa_get_photo_path($photo['id']); if (is_file($file)) { ewww_image_optimizer($file, 4, false, false, false); } $file = wppa_get_thumb_path($photo['id']); if (is_file($file)) { ewww_image_optimizer($file, 4, false, false, false); } break; case 'wppa_comp_sizes': $tx = 0; $ty = 0; $px = 0; $py = 0; $file = wppa_get_photo_path($photo['id']); if (is_file($file)) { $temp = getimagesize($file); if (is_array($temp)) { $px = $temp[0]; $py = $temp[1]; } } $file = wppa_get_thumb_path($photo['id']); if (is_file($file)) { $temp = getimagesize($file); if (is_array($temp)) { $tx = $temp[0]; $ty = $temp[1]; } } wppa_update_photo(array('id' => $photo['id'], 'thumbx' => $tx, 'thumby' => $ty, 'photox' => $px, 'photoy' => $py)); break; case 'wppa_edit_tag': $phototags = explode(',', wppa_get_photo_item($photo['id'], 'tags')); if (in_array($edit_tag, $phototags)) { foreach (array_keys($phototags) as $key) { if ($phototags[$key] == $edit_tag) { $phototags[$key] = $new_tag; } } $tags = wppa_sanitize_tags(implode(',', $phototags)); wppa_update_photo(array('id' => $photo['id'], 'tags' => $tags)); $wppa_session[$slug . '_fixed']++; } else { $wppa_session[$slug . '_skipped']++; } break; } // Test for timeout / ready $lastid = $id; update_option($slug . '_last', $lastid); if (time() > $endtime) { break; } // Time out } } else { // Nothing to do, Done anyway $lastid = $topid; wppa_log('Debug', 'Maintenance proc ' . $slug . ': Done!'); } break; // End process photos // Single action maintenance modules // case 'wppa_list_index': // break; // case 'wppa_blacklist_user': // break; // case 'wppa_un_blacklist_user': // break; // case 'wppa_rating_clear': // break; // case 'wppa_viewcount_clear': // break; // case 'wppa_iptc_clear': // break; // case 'wppa_exif_clear': // break; // End process photos // Single action maintenance modules // case 'wppa_list_index': // break; // case 'wppa_blacklist_user': // break; // case 'wppa_un_blacklist_user': // break; // case 'wppa_rating_clear': // break; // case 'wppa_viewcount_clear': // break; // case 'wppa_iptc_clear': // break; // case 'wppa_exif_clear': // break; default: $errtxt = 'Unimplemented maintenance slug: ' . strip_tags($slug); } // either $albums / $photos has been exhousted ( for this try ) or time is up if ($slug == 'wppa_cleanup') { $togo = $topid - $lastid; } else { $togo = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . $table . "` WHERE `id` > %s ", $lastid)); } $status = $togo ? 'Pending' : 'Ready'; if ($togo) { update_option($slug . '_togo', $togo); update_option($slug . '_status', $status); } else { // Really done // Report fixed/skipped/deleted if ($wppa_session[$slug . '_fixed']) { $status .= ' fixed:' . $wppa_session[$slug . '_fixed']; unset($wppa_session[$slug . '_fixed']); } if ($wppa_session[$slug . '_skipped']) { $status .= ' skipped:' . $wppa_session[$slug . '_skipped']; unset($wppa_session[$slug . '_skipped']); } if ($wppa_session[$slug . '_deleted']) { $status .= ' deleted:' . $wppa_session[$slug . '_deleted']; unset($wppa_session[$slug . '_deleted']); } // Re-Init options delete_option($slug . '_togo', ''); delete_option($slug . '_status', ''); delete_option($slug . '_last', '0'); delete_option($slug . '_user', ''); // Post-processing needed? switch ($slug) { case 'wppa_remake_index_albums': case 'wppa_remake_index_photos': $wpdb->query("DELETE FROM `" . WPPA_INDEX . "` WHERE `albums` = '' AND `photos` = ''"); // Remove empty entries delete_option('wppa_index_need_remake'); break; case 'wppa_apply_new_photodesc_all': case 'wppa_append_to_photodesc': case 'wppa_remove_from_photodesc': update_option('wppa_remake_index_photos_status', __('Required', 'wppa')); break; case 'wppa_regen_thumbs': wppa_bump_thumb_rev(); break; case 'wppa_file_system': wppa_update_option('wppa_file_system', $to); $reload = 'reload'; break; case 'wppa_remake': wppa_bump_photo_rev(); wppa_bump_thumb_rev(); break; case 'wppa_edit_tag': wppa_clear_taglist(); $reload = 'reload'; break; } } return $errtxt . '||' . $slug . '||' . $status . '||' . $togo . '||' . $reload; }
function do_album_navigator($parent, $page, $skip, $propclass, $extraclause = '') { global $wpdb; static $level; static $ca; if (!$level) { $level = '1'; if (isset($_REQUEST['wppa-album'])) { $ca = $_REQUEST['wppa-album']; } elseif (isset($_REQUEST['album'])) { $ca = $_REQUEST['album']; } else { $ca = '0'; } $ca = wppa_force_numeric_else($ca, '0'); if ($ca && !wppa_album_exists($ca)) { // wppa_log('dbg', 'Non-existent album '.$ca.' in url. Referrer= '.$_ENV["HTTP_REFERER"].', Request uri= '.$_ENV["REQUEST_URI"]); $ca = '0'; } } else { $level++; } $slide = wppa_opt('album_navigator_widget_linktype') == 'slide' ? '&wppa-slide=1' : ''; $w = $this->get_widget_id(); $p = $parent; $result = ''; $albums = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = %s " . $extraclause . wppa_get_album_order(max('0', $parent)), $parent), ARRAY_A); if (!empty($albums)) { wppa_cache_album('add', $albums); $result .= '<ul>'; foreach ($albums as $album) { $a = $album['id']; $treecount = wppa_treecount_a($a); if ($treecount['albums'] || $treecount['photos'] > wppa_opt('min_thumbs') || $skip == 'no') { $result .= ' <li class="anw-' . $w . '-' . $p . $propclass . '" style="list-style:none; display:' . ($level == '1' ? '' : 'none') . ';">'; if (wppa_has_children($a)) { $result .= ' <div style="cursor:default;width:12px;float:left;text-align:center;font-weight:bold;" class="anw-' . $w . '-' . $a . '-" onclick="jQuery(\'.anw-' . $w . '-' . $a . '\').css(\'display\',\'\'); jQuery(\'.anw-' . $w . '-' . $a . '-\').css(\'display\',\'none\');" >' . ($a == $ca ? '»' : '+') . '</div> <div style="cursor:default;width:12px;float:left;text-align:center;font-weight:bold;display:none;" class="anw-' . $w . '-' . $a . '" onclick="jQuery(\'.anw-' . $w . '-' . $a . '-\').css(\'display\',\'\'); jQuery(\'.anw-' . $w . '-' . $a . '\').css(\'display\',\'none\'); jQuery(\'.p-' . $w . '-' . $a . '\').css(\'display\',\'none\');" >' . ($a == $ca ? '»' : '-') . '</div>'; } else { $result .= ' <div style="width:12px;float:left;" > ' . ($a == $ca ? '»' : '') . '</div>'; } $result .= ' <a href="' . wppa_encrypt_url(wppa_get_permalink($page) . '&wppa-album=' . $a . '&wppa-cover=0&wppa-occur=1' . $slide) . '">' . wppa_get_album_name($a) . '</a> </li>'; $newpropclass = $propclass . ' p-' . $w . '-' . $p; $result .= '<li class="anw-' . $w . '-' . $p . $propclass . '" style="list-style:none;" >' . $this->do_album_navigator($a, $page, $skip, $newpropclass, $extraclause) . '</li>'; } } $result .= '</ul>'; if ($level == '1' && $ca) { // && $parent != '-1' ) { $result .= '<script type="text/javascript" >'; while ($ca != '0' && $ca != '-1') { $result .= ' jQuery(\'.anw-' . $w . '-' . $ca . '\').css(\'display\',\'\'); jQuery(\'.anw-' . $w . '-' . $ca . '-\').css(\'display\',\'none\');'; $ca = wppa_get_parentalbumid($ca); } $result .= '</script>'; } } $level--; return str_replace('<ul></ul>', '', $result); }
function wppa_the_album_title($alb, $href_title, $onclick_title, $title, $target) { $album = wppa_cache_album($alb); wppa_out('<h2 class="wppa-title" style="clear:none; ' . __wcs('wppa-title') . '">'); if ($href_title) { if ($href_title == '#') { wppa_out('<a onclick="' . $onclick_title . '" title="' . $title . '" class="wppa-title" style="cursor:pointer; ' . __wcs('wppa-title') . '">' . wppa_get_album_name($alb) . '</a>'); } else { wppa_out('<a href="' . $href_title . '" target="' . $target . '" onclick="' . $onclick_title . '" title="' . $title . '" class="wppa-title" style="' . __wcs('wppa-title') . '">' . wppa_get_album_name($alb) . '</a>'); } } else { wppa_out(wppa_get_album_name($alb)); } // Photo count? if (wppa_opt('count_on_title') != '-none-') { if (wppa_opt('count_on_title') == 'self') { $cnt = wppa_get_photo_count($alb); } if (wppa_opt('count_on_title') == 'total') { $temp = wppa_treecount_a($alb); $cnt = $temp['photos']; if (current_user_can('wppa_moderate')) { $cnt += $temp['pendphotos']; } } if ($cnt) { wppa_out(' <span class="wppa-cover-pcount" >(' . $cnt . ')</span>'); } } $fsize = '12'; if (wppa_is_album_new($alb)) { $type = 'new'; } elseif (wppa_is_album_modified($alb)) { $type = 'mod'; } else { $type = ''; } $do_image = !wppa_switch('new_mod_label_is_text'); if ($type) { if ($do_image) { wppa_out('<img' . ' src="' . wppa_opt($type . '_label_url') . '"' . ' title="' . __('New!', 'wp-photo-album-plus') . '"' . ' class="wppa-albumnew"' . ' style="border:none;margin:0;padding:0;box-shadow:none;"' . ' alt="' . __('New', 'wp-photo-album-plus') . '"' . ' />'); } else { wppa_out(' <span' . ' style="' . 'display:inline;' . 'box-sizing:border-box;' . 'font-size:' . $fsize . 'px;' . 'line-height:' . $fsize . 'px;' . 'font-family:\'Arial Black\', Gadget, sans-serif;' . 'border-radius:4px;' . 'border-width:2px;' . 'border-style:solid;' . wppa_get_text_medal_color_style($type, '2') . '"' . ' >' . ' ' . __(wppa_opt($type . '_label_text')) . ' ' . '</span>'); } } wppa_out('</h2>'); }
function wppa_index_quick_remove($type, $id) { global $wpdb; if ($type == 'album') { $album = wppa_cache_album($id); $words = stripslashes($album['name']) . ' ' . stripslashes($album['description']) . ' ' . $album['cats']; $words = wppa_index_raw_to_words($words); foreach ($words as $word) { $indexline = $wpdb->get_row("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` = '" . $word . "'", ARRAY_A); $array = wppa_index_string_to_array($indexline['albums']); foreach (array_keys($array) as $k) { if ($array[$k] == $id) { unset($array[$k]); $string = wppa_index_array_to_string($array); if ($string || $indexline['photos']) { $wpdb->query("UPDATE `" . WPPA_INDEX . "` SET `albums` = '" . $string . "' WHERE `id` = " . $indexline['id']); } else { $wpdb->query("DELETE FROM `" . WPPA_INDEX . "` WHERE `id` = " . $indexline['id']); } } } } } elseif ($type == 'photo') { $thumb = wppa_cache_thumb($id); // Find the raw text $words = stripslashes($thumb['name']) . ' ' . $thumb['filename'] . ' ' . stripslashes($thumb['description']) . ' ' . $thumb['tags']; $coms = $wpdb->get_results($wpdb->prepare("SELECT `comment` FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s AND `status` = 'approved'", $thumb['id']), ARRAY_A); if ($coms) { foreach ($coms as $com) { $words .= ' ' . stripslashes($com['comment']); } } $words = wppa_index_raw_to_words($words, 'noskips'); foreach ($words as $word) { $indexline = $wpdb->get_row("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` = '" . $word . "'", ARRAY_A); $array = wppa_index_string_to_array($indexline['photos']); foreach (array_keys($array) as $k) { if ($array[$k] == $id) { unset($array[$k]); $string = wppa_index_array_to_string($array); if ($string || $indexline['albums']) { $wpdb->query("UPDATE `" . WPPA_INDEX . "` SET `photos` = '" . $string . "' WHERE `id` = " . $indexline['id']); } else { $wpdb->query("DELETE FROM `" . WPPA_INDEX . "` WHERE `id` = " . $indexline['id']); } } } } } }
function wppa_walbum_select($sel = '') { global $wpdb; $albums = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "` ORDER BY `name`", ARRAY_A); wppa_dbg_q('Q-Asel'); wppa_cache_album('add', $albums); if (is_numeric($sel)) { $type = 1; } elseif (strchr($sel, ',')) { $type = 2; // Array $albs = explode(',', $sel); } elseif ($sel == 'all') { $type = 3; } elseif ($sel == 'sep') { $type = 4; } elseif ($sel == 'all-sep') { $type = 5; } elseif ($sel == 'topten') { $type = 6; } else { $type = 0; } // Nothing yet $result = '<option value="" >' . __('- select (another) album or a set -', 'wp-photo-album-plus') . '</option>'; foreach ($albums as $album) { switch ($type) { case 1: $dis = $album['id'] == $sel; break; case 2: $dis = in_array($album['id'], $albs); break; case 3: $dis = true; break; case 4: $dis = $album['a_parent'] == '-1'; break; case 5: $dis = $album['a_parent'] != '-1'; break; case 6: $dis = false; break; default: $dis = false; } if ($dis) { $dis = 'disabled="disabled"'; } else { $dis = ''; } $result .= '<option ' . $dis . ' value="' . $album['id'] . '">( ' . $album['id'] . ' )'; if ($album['id'] < '1000') { $result .= ' '; } if ($album['id'] < '100') { $result .= ' '; } if ($album['id'] < '10') { $result .= ' '; } $result .= __(stripslashes($album['name'])) . '</option>'; } $sel = $type == 3 ? 'selected="selected"' : ''; $result .= '<option value="all" ' . $sel . ' >' . __('- all albums -', 'wp-photo-album-plus') . '</option>'; $sel = $type == 4 ? 'selected="selected"' : ''; $result .= '<option value="sep" ' . $sel . ' >' . __('- all -separate- albums -', 'wp-photo-album-plus') . '</option>'; $sel = $type == 5 ? 'selected="selected"' : ''; $result .= '<option value="all-sep" ' . $sel . ' >' . __('- all albums except -separate-', 'wp-photo-album-plus') . '</option>'; $sel = $type == 6 ? 'selected="selected"' : ''; $result .= '<option value="topten" ' . $sel . ' >' . __('- top rated photos -', 'wp-photo-album-plus') . '</option>'; $result .= '<option value="clr" >' . __('- start over -', 'wp-photo-album-plus') . '</option>'; return $result; }
function wppa_update_album($args) { global $wpdb; if (!is_array($args)) { return false; } if (!$args['id']) { return false; } if (!wppa_cache_album($args['id'])) { return false; } $id = $args['id']; foreach (array_keys($args) as $itemname) { $itemvalue = $args[$itemname]; $doit = false; // Sanitize input switch ($itemname) { case 'id': break; case 'name': $itemvalue = wppa_strip_tags($itemvalue, 'all'); $doit = true; break; case 'description': $itemvalue = balanceTags($itemvalue, true); $itemvalue = wppa_strip_tags($itemvalue, 'script&style'); $doit = true; break; case 'modified': if (!$itemvalue) { $itemvalue = time(); } $doit = true; break; case 'cats': $itemvalue = wppa_sanitize_tags($itemvalue); $doit = true; break; case 'scheduledtm': $doit = true; break; case 'main_photo': if (wppa_is_int($itemvalue)) { $doit = true; } break; default: wppa_log('Error', 'Not implemented in wppa_update_album(): ' . $itemname); return false; } if ($doit) { if ($wpdb->query($wpdb->prepare("UPDATE `" . WPPA_ALBUMS . "` SET `" . $itemname . "` = %s WHERE `id` = %s LIMIT 1", $itemvalue, $id))) { wppa_cache_album('invalidate'); } } } return true; /* `a_order`, `main_photo`, `a_parent`, `p_order_by`, `cover_linktype`, `cover_linkpage`, `owner`, `upload_limit`, `alt_thumbsize`, `default_tags`, `cover_type`, `suba_order_by`, `views`, `cats` */ }
function wppa_the_album_title($alb, $href_title, $onclick_title, $title, $target) { $album = wppa_cache_album($alb); wppa_out('<h2 class="wppa-title" style="clear:none; ' . __wcs('wppa-title') . '">'); if ($href_title) { if ($href_title == '#') { wppa_out('<a onclick="' . $onclick_title . '" title="' . $title . '" class="wppa-title" style="cursor:pointer; ' . __wcs('wppa-title') . '">' . wppa_get_album_name($alb) . '</a>'); } else { wppa_out('<a href="' . $href_title . '" target="' . $target . '" onclick="' . $onclick_title . '" title="' . $title . '" class="wppa-title" style="' . __wcs('wppa-title') . '">' . wppa_get_album_name($alb) . '</a>'); } } else { wppa_out(wppa_get_album_name($alb)); } $fsize = '12'; if (wppa_is_album_new($alb)) { $type = 'new'; } elseif (wppa_is_album_modified($alb)) { $type = 'mod'; } else { $type = ''; } $do_image = !wppa_switch('wppa_new_mod_label_is_text'); if ($type) { if ($do_image) { wppa_out('<img' . ' src="' . wppa_opt($type . '_label_url') . '"' . ' title="' . __('New!', 'wp-photo-album-plus') . '"' . ' class="wppa-albumnew"' . ' style="border:none;margin:0;padding:0;box-shadow:none;"' . ' alt="' . __('New', 'wp-photo-album-plus') . '"' . ' />'); } else { wppa_out(' <div' . ' style="' . 'display:inline;' . 'box-sizing:border-box;' . 'font-size:' . $fsize . 'px;' . 'line-height:' . $fsize . 'px;' . 'font-family:\'Arial Black\', Gadget, sans-serif;' . 'border-radius:4px;' . 'border-width:2px;' . 'border-style:solid;' . wppa_get_text_medal_color_style($type, '2') . '"' . ' >' . ' ' . __(wppa_opt($type . '_label_text')) . ' ' . '</div>'); } } wppa_out('</h2>'); }
function wppa_the_album_title($alb, $href_title, $onclick_title, $title, $target) { global $wppa; $album = wppa_cache_album($alb); $wppa['out'] .= wppa_nltab('+') . '<h2 class="wppa-title" style="clear:none; ' . __wcs('wppa-title') . '">'; if ($href_title) { if ($href_title == '#') { $wppa['out'] .= wppa_nltab() . '<a onclick="' . $onclick_title . '" title="' . $title . '" class="wppa-title" style="cursor:pointer; ' . __wcs('wppa-title') . '">' . wppa_get_album_name($alb) . '</a>'; } else { $wppa['out'] .= wppa_nltab() . '<a href="' . $href_title . '" target="' . $target . '" onclick="' . $onclick_title . '" title="' . $title . '" class="wppa-title" style="' . __wcs('wppa-title') . '">' . wppa_get_album_name($alb) . '</a>'; } } else { $wppa['out'] .= wppa_get_album_name($alb); } if (wppa_is_album_new($alb)) { $wppa['out'] .= wppa_nltab() . '<img src="' . WPPA_URL . '/images/new.png" title="' . __a('New!') . '" class="wppa-albumnew" style="border:none; margin:0; padding:0; box-shadow:none; " alt="' . __a('New') . '" />'; } $wppa['out'] .= wppa_nltab('-') . '</h2>'; }
function _wppa_admin() { global $wpdb; global $q_config; global $wppa_revno; if (get_option('wppa_revision') != $wppa_revno) { wppa_check_database(true); } echo ' <script type="text/javascript"> /* <![CDATA[ */ wppaAjaxUrl = "' . admin_url('admin-ajax.php') . '"; wppaUploadToThisAlbum = "' . __('Upload to this album', 'wp-photo-album-plus') . '"; wppaImageDirectory = "' . wppa_get_imgdir() . '"; /* ]]> */ </script> '; // Delete trashed comments $query = "DELETE FROM " . WPPA_COMMENTS . " WHERE status='trash'"; $wpdb->query($query); $sel = 'selected="selected"'; // warn if the uploads directory is no writable if (!is_writable(WPPA_UPLOAD_PATH)) { wppa_error_message(__('Warning:', 'wp-photo-album-plus') . sprintf(__('The uploads directory does not exist or is not writable by the server. Please make sure that %s is writeable by the server.', 'wp-photo-album-plus'), WPPA_UPLOAD_PATH)); } // Fix orphan albums and deleted target pages $albs = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "`", ARRAY_A); // Now we have tham, put them in cache wppa_cache_album('add', $albs); if ($albs) { foreach ($albs as $alb) { if ($alb['a_parent'] > '0' && wppa_get_parentalbumid($alb['a_parent']) == '-9') { // Parent died? $wpdb->query("UPDATE `" . WPPA_ALBUMS . "` SET `a_parent` = '-1' WHERE `id` = '" . $alb['id'] . "'"); } if ($alb['cover_linkpage'] > '0') { $iret = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . $wpdb->posts . "` WHERE `ID` = %s AND `post_type` = 'page' AND `post_status` = 'publish'", $alb['cover_linkpage'])); if (!$iret) { // Page gone? $wpdb->query("UPDATE `" . WPPA_ALBUMS . "` SET `cover_linkpage` = '0' WHERE `id` = '" . $alb['id'] . "'"); } } } } if (isset($_REQUEST['tab'])) { // album edit page if ($_REQUEST['tab'] == 'edit') { if (isset($_REQUEST['edit_id'])) { $ei = $_REQUEST['edit_id']; if ($ei != 'new' && $ei != 'search' && !is_numeric($ei)) { wp_die('Security check failure 1'); } } if ($_REQUEST['edit_id'] == 'search') { $back_url = get_admin_url() . 'admin.php?page=wppa_admin_menu'; if (isset($_REQUEST['wppa-searchstring'])) { $back_url .= '&wppa-searchstring=' . wppa_sanitize_searchstring($_REQUEST['wppa-searchstring']); } $back_url .= '#wppa-edit-search-tag'; ?> <a name="manage-photos" id="manage-photos" ></a> <h2><?php _e('Manage Photos', 'wp-photo-album-plus'); if (isset($_REQUEST['bulk'])) { echo ' - <small><i>' . __('Copy / move / delete / edit name / edit description / change status', 'wp-photo-album-plus') . '</i></small>'; } elseif (isset($_REQUEST['quick'])) { echo ' - <small><i>' . __('Edit photo information except copy and move', 'wp-photo-album-plus') . '</i></small>'; } else { echo ' - <small><i>' . __('Edit photo information', 'wp-photo-album-plus') . '</i></small>'; } ?> </h2> <a href="<?php echo $back_url; ?> "><?php _e('Back to album table', 'wp-photo-album-plus'); ?> </a><br /><br /> <?php if (isset($_REQUEST['bulk'])) { wppa_album_photos_bulk($ei); } else { wppa_album_photos($ei); } ?> <br /><a href="#manage-photos"><?php _e('Top of page', 'wp-photo-album-plus'); ?> </a> <br /><a href="<?php echo $back_url; ?> "><?php _e('Back to album table', 'wp-photo-album-plus'); ?> </a> <?php return; } if ($_REQUEST['edit_id'] == 'new') { if (!wppa_can_create_album()) { wp_die('No rights to create an album'); } $id = wppa_nextkey(WPPA_ALBUMS); if (isset($_REQUEST['parent_id'])) { $parent = $_REQUEST['parent_id']; if (!is_numeric($parent)) { wp_die('Security check failure 2'); } $name = wppa_get_album_name($parent) . '-#' . $id; if (!current_user_can('administrator')) { // someone creating an album for someone else? $parentowner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $parent)); if ($parentowner !== wppa_get_user()) { wp_die('You are not allowed to create an album for someone else'); } } } else { $parent = wppa_opt('default_parent'); if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $parent))) { // Deafault parent vanished wppa_update_option('wppa_default_parent', '0'); $parent = '0'; } $name = __('New Album', 'wp-photo-album-plus'); if (!wppa_can_create_top_album()) { wp_die('No rights to create a top-level album'); } } $id = wppa_create_album_entry(array('id' => $id, 'name' => $name, 'a_parent' => $parent)); if (!$id) { wppa_error_message(__('Could not create album.', 'wp-photo-album-plus')); wp_die('Sorry, cannot continue'); } else { $edit_id = $id; wppa_set_last_album($edit_id); wppa_flush_treecounts($edit_id); wppa_index_add('album', $id); wppa_update_message(__('Album #', 'wp-photo-album-plus') . ' ' . $edit_id . ' ' . __('Added.', 'wp-photo-album-plus')); wppa_create_pl_htaccess(); } } else { $edit_id = $_REQUEST['edit_id']; } $album_owner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM " . WPPA_ALBUMS . " WHERE `id` = %s", $edit_id)); if ($album_owner == '--- public ---' && !current_user_can('wppa_admin') || !wppa_have_access($edit_id)) { wp_die('You do not have the rights to edit this album'); } // Apply new desc if (isset($_REQUEST['applynewdesc'])) { if (!wp_verify_nonce($_REQUEST['wppa_nonce'], 'wppa_nonce')) { wp_die('You do not have the rights to do this'); } $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `description` = %s WHERE `album` = %s", wppa_opt('newphoto_description'), $edit_id)); wppa_ok_message($iret . ' descriptions updated.'); } // Remake album if (isset($_REQUEST['remakealbum'])) { if (!wp_verify_nonce($_REQUEST['wppa_nonce'], 'wppa_nonce')) { wp_die('You do not have the rights to do this'); } if (get_option('wppa_remake_start_album_' . $edit_id)) { // Continue after time up wppa_ok_message('Continuing remake, please wait'); } else { update_option('wppa_remake_start_album_' . $edit_id, time()); wppa_ok_message('Remaking photofiles, please wait'); } $iret = wppa_remake_files($edit_id); if ($iret) { wppa_ok_message('Photo files remade'); update_option('wppa_remake_start_album_' . $edit_id, '0'); } else { wppa_error_message('Remake of photo files did NOT complete'); } } // Get the album information $albuminfo = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . WPPA_ALBUMS . '` WHERE `id` = %s', $edit_id), ARRAY_A); // We may not use extract(), so we do something like it here manually, hence controlled. $id = $albuminfo['id']; $crypt = $albuminfo['crypt']; $timestamp = $albuminfo['timestamp']; $modified = $albuminfo['modified']; $views = $albuminfo['views']; $owner = $albuminfo['owner']; $a_order = $albuminfo['a_order']; $p_order_by = $albuminfo['p_order_by']; $a_parent = $albuminfo['a_parent']; $suba_order_by = $albuminfo['suba_order_by']; $name = stripslashes($albuminfo['name']); $description = stripslashes($albuminfo['description']); $alt_thumbsize = $albuminfo['alt_thumbsize']; $cover_type = $albuminfo['cover_type']; $main_photo = $albuminfo['main_photo']; $upload_limit = $albuminfo['upload_limit']; $cats = stripslashes(trim($albuminfo['cats'], ',')); $default_tags = trim($albuminfo['default_tags'], ','); $cover_linktype = $albuminfo['cover_linktype']; // Open the photo album admin page echo '<div class="wrap">'; // The spinner to indicate busyness wppa_admin_spinner(); // Local js functions placed here as long as there is not yet a possibility to translate texts in js files ?> <script> function wppaTryInheritCats( id ) { var query; query = '<?php echo esc_js(__('Are you sure you want to inherit categories to all (grand)children of this album?', 'wp-photo-album-plus')); ?> '; if ( confirm( query ) ) { wppaAjaxUpdateAlbum( id, 'inherit_cats', Math.random() ); } } function wppaTryAddCats( id ) { var query; query = '<?php echo esc_js(__('Are you sure you want to add the categories to all (grand)children of this album?', 'wp-photo-album-plus')); ?> '; if ( confirm( query ) ) { wppaAjaxUpdateAlbum( id, 'inhadd_cats', Math.random() ); } } function wppaTryApplyDeftags( id ) { var query; query = '<?php echo esc_js(__('Are you sure you want to set the default tags to all photos in this album?', 'wp-photo-album-plus')); ?> '; if ( confirm( query ) ) { wppaAjaxUpdateAlbum( id, 'set_deftags', Math.random(), true ); } } function wppaTryAddDeftags( id ) { var query; query = '<?php echo esc_js(__('Are you sure you want to add the default tags to all photos in this album?', 'wp-photo-album-plus')); ?> '; if ( confirm( query ) ) { wppaAjaxUpdateAlbum( id, 'add_deftags', Math.random(), true ); } } function wppaTryScheduleAll( id ) { var query; if ( jQuery( '#schedule-box' ).attr( 'checked' ) != 'checked' ) { query = '<?php echo esc_js(__('Please switch feature on and set dat/time to schedule first', 'wp-photo-album-plus')); ?> '; alert( query ); return; } query = '<?php echo esc_js(__('Are you sure you want to schedule all photos in this album?', 'wp-photo-album-plus')); ?> '; if ( confirm( query ) ) { wppaAjaxUpdateAlbum( id, 'setallscheduled', Math.random(), true ); } } </script> <?php // The header echo '<img src="' . WPPA_URL . '/img/album32.png' . '" alt="Album icon" />' . '<h1 style="display:inline;" >' . __('Edit Album Information', 'wp-photo-album-plus') . '</h1>' . '<p class="description">' . __('All modifications are instantly updated on the server, except for those that require a button push.', 'wp-photo-album-plus') . ' ' . __('The <b style="color:#070" >Remark</b> fields keep you informed on the actions taken at the background.', 'wp-photo-album-plus') . '</p>' . '<input' . ' type="hidden"' . ' id="album-nonce-' . $id . '"' . ' value="' . wp_create_nonce('wppa_nonce_' . $id) . '"' . ' />'; // The edit albuminfo panel echo '<div' . ' id="albumitem-' . $id . '"' . ' class="wppa-table-wrap"' . ' style="width:100%;position:relative;"' . ' >'; // Section 1 echo "\n" . '<!-- Album Section 1 -->' . '<table' . ' class="wppa-table wppa-album-table"' . ' >' . '<tbody>' . '<tr>' . '<td>'; // More or less static data // Album number echo __('Album number:', 'wp-photo-album-plus') . ' ' . $id . '. '; // Crypt echo __('Crypt:', 'wp-photo-album-plus') . ' ' . $crypt . '. '; // Created echo __('Created:', 'wp-photo-album-plus') . ' ' . wppa_local_date('', $timestamp) . ' ' . __('local time', 'wp-photo-album-plus') . '. '; // Modified echo __('Modified:', 'wp-photo-album-plus') . ' '; if ($modified > $timestamp) { echo wppa_local_date('', $modified) . ' ' . __('local time', 'wp-photo-album-plus') . '. '; } else { echo __('Not modified', 'wp-photo-album-plus') . '. '; } // Views if (wppa_switch('track_viewcounts')) { echo __('Views:', 'wp-photo-album-plus') . ' ' . $views . '. '; } // Clicks if (wppa_switch('track_clickcounts')) { $click_arr = $wpdb->get_col("SELECT `clicks` FROM `" . WPPA_PHOTOS . "` WHERE `album` = {$id}"); echo __('Clicks:', 'wp-photo-album-plus') . ' ' . array_sum($click_arr) . '. '; } // Owner echo __('Owned by:', 'wp-photo-album-plus') . ' '; if (!wppa_user_is('administrator')) { if ($owner == '--- public ---') { echo __('--- public ---', 'wp-photo-album-plus') . ' '; } else { echo $owner . '. '; } } else { $usercount = wppa_get_user_count(); if ($usercount > wppa_opt('max_users')) { echo '<input' . ' type="text"' . ' value="' . esc_attr($owner) . '"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'owner\', this )"' . ' />'; } else { echo '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'owner\', this )"' . ' >'; wppa_user_select($owner); echo '</select>' . ' '; } } // Order # --> echo __('Album sort order #:', 'wp-photo-album-plus') . ' ' . '<input' . ' type="text"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'a_order\', this )"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'a_order\', this )"' . ' value="' . esc_attr($a_order) . '"' . ' style="width:50px;' . '" />' . ' '; if (wppa_opt('list_albums_by') != '1' && $a_order != '0') { echo '<small class="description" style="color:red" >' . __('Album order # has only effect if you set the album sort order method to <b>Order #</b> in the Photo Albums -> Settings screen.<br />', 'wp-photo-album-plus') . '</small>' . ' '; } // Parent echo __('Parent album:', 'wp-photo-album-plus') . ' '; if (wppa_extended_access()) { echo '<select' . ' id="wppa-parsel"' . ' style="max-width:100%;"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'a_parent\', this )"' . ' >' . wppa_album_select_a(array('checkaccess' => true, 'exclude' => $id, 'selected' => $a_parent, 'addselected' => true, 'addnone' => true, 'addseparate' => true, 'disableancestors' => true, 'path' => wppa_switch('hier_albsel'))) . '</select>'; } else { echo '<select' . ' id="wppa-parsel"' . ' style="max-width:100%;"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'a_parent\', this )"' . ' >' . wppa_album_select_a(array('checkaccess' => true, 'exclude' => $id, 'selected' => $a_parent, 'addselected' => true, 'disableancestors' => true, 'path' => wppa_switch('hier_albsel'))) . '</select>'; } echo ' '; // P-order-by echo __('Photo order:', 'wp-photo-album-plus') . ' '; $options = array(__('--- default --- See Table IV-C1', 'wp-photo-album-plus'), __('Order #', 'wp-photo-album-plus'), __('Name', 'wp-photo-album-plus'), __('Random', 'wp-photo-album-plus'), __('Rating mean value', 'wp-photo-album-plus'), __('Number of votes', 'wp-photo-album-plus'), __('Timestamp', 'wp-photo-album-plus'), __('EXIF Date', 'wp-photo-album-plus'), __('Order # desc', 'wp-photo-album-plus'), __('Name desc', 'wp-photo-album-plus'), __('Rating mean value desc', 'wp-photo-album-plus'), __('Number of votes desc', 'wp-photo-album-plus'), __('Timestamp desc', 'wp-photo-album-plus'), __('EXIF Date desc', 'wp-photo-album-plus')); $values = array('0', '1', '2', '3', '4', '6', '5', '7', '-1', '-2', '-4', '-6', '-5', '-7'); echo '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'p_order_by\', this )"' . ' >'; foreach (array_keys($options) as $key) { $sel = $values[$key] == $p_order_by ? ' selected="selected"' : ''; echo '<option value="' . $values[$key] . '"' . $sel . ' >' . $options[$key] . '</option>'; } echo '</select>' . ' '; // Child album order echo __('Sub album sort order:', 'wp-photo-album-plus') . ' ' . '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'suba_order_by\', this )"' . ' >' . '<option value="0"' . ($suba_order_by == '0' ? 'selected="selected"' : '') . ' >' . __('--- default --- See Table IV-D1', 'wp-photo-album-plus') . '</option>' . '<option value="3"' . ($suba_order_by == '3' ? 'selected="selected"' : '') . ' >' . __('Random', 'wp-photo-album-plus') . '</option>' . '<option value="1"' . ($suba_order_by == '1' ? 'selected="selected"' : '') . ' >' . __('Order #', 'wp-photo-album-plus') . '</option>' . '<option value="-1"' . ($suba_order_by == '-1' ? 'selected="selected"' : '') . ' >' . __('Order # reverse', 'wp-photo-album-plus') . '</option>' . '<option value="2"' . ($suba_order_by == '2' ? 'selected="selected"' : '') . ' >' . __('Name', 'wp-photo-album-plus') . '</option>' . '<option value="-2"' . ($suba_order_by == '-2' ? 'selected="selected"' : '') . ' >' . __('Name reverse', 'wp-photo-album-plus') . '</option>' . '<option value="5"' . ($suba_order_by == '5' ? 'selected="selected"' : '') . ' >' . __('Timestamp', 'wp-photo-album-plus') . '</option>' . '<option value="-5"' . ($suba_order_by == '-5' ? 'selected="selected"' : '') . ' >' . __('Timestamp reverse', 'wp-photo-album-plus') . '</option>' . '</select>' . ' '; // Alternative thumbnail size if (!wppa_switch('alt_is_restricted') || current_user_can('administrator')) { echo __('Use alt thumbsize:', 'wp-photo-album-plus') . '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'alt_thumbsize\', this )"' . ' >' . '<option value="0"' . ($alt_thumbsize ? '' : ' selected="selected"') . ' >' . __('no', 'wp-photo-album-plus') . '</option>' . '<option value="yes"' . ($alt_thumbsize ? ' selected="selected"' : '') . ' >' . __('yes', 'wp-photo-album-plus') . '</option>' . '</select>' . ' '; } // Cover type if (!wppa_switch('covertype_is_restricted') || wppa_user_is('administrator')) { echo __('Cover Type:', 'wp-photo-album-plus') . ' '; $sel = ' selected="selected"'; echo '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'cover_type\', this )"' . ' >' . '<option value=""' . ($cover_type == '' ? $sel : '') . ' >' . __('--- default --- See Table IV-D6', 'wp-photo-album-plus') . '</option>' . '<option value="default"' . ($cover_type == 'default' ? $sel : '') . ' >' . __('Standard', 'wp-photo-album-plus') . '</option>' . '<option value="longdesc"' . ($cover_type == 'longdesc' ? $sel : '') . ' >' . __('Long Descriptions', 'wp-photo-album-plus') . '</option>' . '<option value="imagefactory"' . ($cover_type == 'imagefactory' ? $sel : '') . ' >' . __('Image Factory', 'wp-photo-album-plus') . '</option>' . '<option value="default-mcr"' . ($cover_type == 'default-mcr' ? $sel : '') . ' >' . __('Standard mcr', 'wp-photo-album-plus') . '</option>' . '<option value="longdesc-mcr"' . ($cover_type == 'longdesc-mcr' ? $sel : '') . ' >' . __('Long Descriptions mcr', 'wp-photo-album-plus') . '</option>' . '<option value="imagefactory-mcr"' . ($cover_type == 'imagefactory-mcr' ? $sel : '') . ' >' . __('Image Factory mcr', 'wp-photo-album-plus') . '</option>' . '</select>' . ' '; } // Cover photo echo __('Cover Photo:', 'wp-photo-album-plus') . ' ' . wppa_main_photo($main_photo, $cover_type) . ' '; // Upload limit echo __('Upload limit:', 'wp-photo-album-plus') . ' '; $lims = explode('/', $upload_limit); if (!is_array($lims)) { $lims = array('0', '0'); } if (wppa_user_is('administrator')) { echo '<input' . ' type="text"' . ' id="upload_limit_count"' . ' value="' . $lims[0] . '"' . ' style="width:50px"' . ' title="' . esc_attr(__('Set the upload limit (0 means unlimited).', 'wp-photo-album-plus')) . '"' . ' onchange="wppaRefreshAfter(); wppaAjaxUpdateAlbum( ' . $id . ', \'upload_limit_count\', this )"' . ' />'; $sel = ' selected="selected"'; echo '<select onchange="wppaRefreshAfter(); wppaAjaxUpdateAlbum( ' . $id . ', \'upload_limit_time\', this )" >' . '<option value="0"' . ($lims[1] == '0' ? $sel : '') . ' >' . __('for ever', 'wp-photo-album-plus') . '</option>' . '<option value="3600"' . ($lims[1] == '3600' ? $sel : '') . ' >' . __('per hour', 'wp-photo-album-plus') . '</option>' . '<option value="86400"' . ($lims[1] == '86400' ? $sel : '') . ' >' . __('per day', 'wp-photo-album-plus') . '</option>' . '<option value="604800"' . ($lims[1] == '604800' ? $sel : '') . ' >' . __('per week', 'wp-photo-album-plus') . '</option>' . '<option value="2592000"' . ($lims[1] == '2592000' ? $sel : '') . ' >' . __('per month', 'wp-photo-album-plus') . '</option>' . '<option value="31536000"' . ($lims[1] == '31536000' ? $sel : '') . ' >' . __('per year', 'wp-photo-album-plus') . '</option>' . '</select>' . ' '; } else { if ($lims[0] == '0') { _e('Unlimited', 'wp-photo-album-plus'); } else { echo $lims[0] . ' '; switch ($lims[1]) { case '3600': _e('per hour', 'wp-photo-album-plus'); break; case '86400': _e('per day', 'wp-photo-album-plus'); break; case '604800': _e('per week', 'wp-photo-album-plus'); break; case '2592000': _e('per month', 'wp-photo-album-plus'); break; case '31536000': _e('per year', 'wp-photo-album-plus'); break; } } echo '. '; } // Status echo __('Remark:', 'wp-photo-album-plus') . ' ' . '<span' . ' id="albumstatus-' . $id . '"' . ' style="font-weight:bold;color:#00AA00;"' . ' >' . sprintf(__('Album %s is not modified yet', 'wp-photo-album-plus'), $id) . '</span>'; echo '</td>' . '</tr>' . '</tbody>' . '</table>'; // Section 2 echo "\n" . '<!-- Album Section 2 -->' . '<table' . ' class="wppa-table wppa-album-table"' . ' >' . '<tbody>'; // Name echo '<tr>' . '<td>' . __('Name:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' type="text"' . ' style="width:100%;"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'name\', this )"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'name\', this )"' . ' value="' . esc_attr($name) . '"' . ' />' . '<span class="description" >' . __('Type the name of the album. Do not leave this empty.', 'wp-photo-album-plus') . '</span>' . '</td>' . '<td>' . '</td>' . '</tr>'; // Description echo '<tr>' . '<td>' . __('Description:', 'wp-photo-album-plus') . '</td>'; if (wppa_switch('use_wp_editor')) { echo '<td>'; wp_editor($description, 'wppaalbumdesc', array('wpautop' => true, 'media_buttons' => false, 'textarea_rows' => '6', 'tinymce' => true)); echo '<input' . ' type="button"' . ' class="button-secundary"' . ' value="' . esc_attr(__('Update Album description', 'wp-photo-album-plus')) . '"' . ' onclick="wppaAjaxUpdateAlbum( ' . $id . ', \'description\', document.getElementById( \'wppaalbumdesc\' ) )"' . ' />' . '<img' . ' id="wppa-album-spin"' . ' src="' . wppa_get_imgdir() . 'spinner.gif' . '"' . ' alt="Spin"' . ' style="visibility:hidden"' . ' />' . '</td>'; } else { echo '<td>' . '<textarea' . ' style="width:100%;height:60px;"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'description\', this )"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'description\', this )"' . ' >' . $description . '</textarea>' . '</td>'; } echo '<td>' . '</td>' . '</tr>'; // Categories echo '<tr>' . '<td>' . __('Catogories:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' id="cats"' . ' type="text"' . ' style="width:100%;"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'cats\', this )"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'cats\', this )"' . ' value="' . esc_attr($cats) . '"' . ' />' . '<br />' . '<span class="description" >' . __('Separate categories with commas.', 'wp-photo-album-plus') . '</span>' . '</td>' . '<td>' . '<select' . ' onchange="wppaAddCat( this.value, \'cats\' ); wppaAjaxUpdateAlbum( ' . $id . ', \'cats\', document.getElementById( \'cats\' ) )"' . ' >'; $catlist = wppa_get_catlist(); if (is_array($catlist)) { echo '<option value="" >' . __('- select to add -', 'wp-photo-album-plus') . '</option>'; foreach ($catlist as $cat) { echo '<option value="' . $cat['cat'] . '" >' . $cat['cat'] . '</option>'; } } else { echo '<option value="0" >' . __('No categories yet', 'wp-photo-album-plus') . '</option>'; } echo '</select>' . '</td>' . '</tr>'; // Default tags echo '<tr>' . '<td>' . __('Default photo tags:', 'wp-photo-album-plus') . '</td>' . '<td>' . '<input' . ' type="text"' . ' id="default_tags"' . ' value="' . esc_attr($default_tags) . '"' . ' style="width:100%"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'default_tags\', this )"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'default_tags\', this )"' . ' />' . '<br />' . '<span class="description">' . __('Enter the tags that you want to be assigned to new photos in this album.', 'wp-photo-album-plus') . '</span>' . '</td>' . '<td>' . '</td>' . '</tr>'; // Custom if (wppa_switch('album_custom_fields')) { $custom = wppa_get_album_item($edit_id, 'custom'); if ($custom) { $custom_data = unserialize($custom); } else { $custom_data = array('', '', '', '', '', '', '', '', '', ''); } foreach (array_keys($custom_data) as $key) { if (wppa_opt('album_custom_caption_' . $key)) { echo '<tr>' . '<td>' . apply_filters('translate_text', wppa_opt('album_custom_caption_' . $key)) . '<small style="float:right" >' . '(w#cc' . $key . ')' . '</small>:' . '</td>' . '<td>' . '<input' . ' type="text"' . ' style="width:100%;"' . ' id="album_custom_' . $key . '-' . $id . '"' . ' onkeyup="wppaAjaxUpdateAlbum( ' . $id . ', \'album_custom_' . $key . '\', this );"' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'album_custom_' . $key . '\', this );"' . ' value="' . esc_attr(stripslashes($custom_data[$key])) . '"' . ' />' . '</td>' . '<td>' . '<small>' . '(w#cd' . $key . ')' . '</small>' . '</td>' . '</tr>'; } } } // Link type echo '<tr>' . '<td>' . __('Link type:', 'wp-photo-album-plus') . '</td>' . '<td>'; $sel = ' selected="selected"'; $lt = $cover_linktype; /* if ( !$linktype ) $linktype = 'content'; /* Default */ /* if ( $albuminfo['cover_linkpage'] == '-1' ) $linktype = 'none'; /* for backward compatibility */ echo '<select onchange="wppaAjaxUpdateAlbum( ' . $id . ', \'cover_linktype\', this )" >' . '<option value="content"' . ($lt == 'content' ? $sel : '') . ' >' . __('the sub-albums and thumbnails', 'wp-photo-album-plus') . '</option>' . '<option value="albums"' . ($lt == 'albums' ? $sel : '') . ' >' . __('the sub-albums', 'wp-photo-album-plus') . '</option>' . '<option value="thumbs"' . ($lt == 'thumbs' ? $sel : '') . ' >' . __('the thumbnails', 'wp-photo-album-plus') . '</option>' . '<option value="slide"' . ($lt == 'slide' ? $sel : '') . ' >' . __('the album photos as slideshow', 'wp-photo-album-plus') . '</option>' . '<option value="page"' . ($lt == 'page' ? $sel : '') . ' >' . __('the link page with a clean url', 'wp-photo-album-plus') . '</option>' . '<option value="none"' . ($lt == 'none' ? $sel : '') . ' >' . __('no link at all', 'wp-photo-album-plus') . '</option>' . '</select>' . '<br />' . '<span class="description">'; if (wppa_switch('auto_page')) { _e('If you select "the link page with a clean url", select an Auto Page of one of the photos in this album.', 'wp-photo-album-plus'); } else { _e('If you select "the link page with a clean url", make sure you enter the correct shortcode on the target page.', 'wp-photo-album-plus'); } echo '</span>' . '</td>' . '<td>' . '</td>' . '</tr>'; // Link page if (!wppa_switch('link_is_restricted') || wppa_user_is('administrator')) { echo '<tr>' . '<td>' . __('Link to:', 'wp-photo-album-plus') . '</td>' . '<td>'; $query = "SELECT `ID`, `post_title` FROM `" . $wpdb->posts . "` WHERE `post_type` = 'page' AND `post_status` = 'publish' ORDER BY `post_title` ASC"; $pages = $wpdb->get_results($query, ARRAY_A); if (empty($pages)) { _e('There are no pages (yet) to link to.', 'wp-photo-album-plus'); } else { $linkpage = $albuminfo['cover_linkpage']; if (!is_numeric($linkpage)) { $linkpage = '0'; } echo '<select' . ' onchange="wppaAjaxUpdateAlbum( ' . $id . ' , \'cover_linkpage\', this )"' . ' style="max-width:100%;"' . '>' . '<option value="0"' . ($linkpage == '0' ? $sel : '') . ' >' . __('--- the same page or post ---', 'wp-photo-album-plus') . '</option>'; foreach ($pages as $page) { echo '<option value="' . $page['ID'] . '"' . ($linkpage == $page['ID'] ? $sel : '') . ' >' . __($page['post_title']) . '</option>'; } echo '</select>' . '<br />' . '<span class="description" >' . __('If you want, you can link the title to a WP page in stead of the album\'s content. If so, select the page the title links to.', 'wp-photo-album-plus') . '</span>'; } echo '</td>' . '<td>' . '</td>' . '</tr>'; } // Schedule echo '<tr>' . '<td>' . __('Schedule:', 'wp-photo-album-plus') . ' ' . '<input' . ' type="checkbox"' . ' id="schedule-box"' . ($albuminfo['scheduledtm'] ? ' checked="checked"' : '') . ' onchange="wppaChangeScheduleAlbum(' . $id . ', this );"' . ' />' . '</td>' . '<td>' . '<input type="hidden" value="" id="wppa-dummy" />' . '<span class="wppa-datetime-' . $id . '"' . ($albuminfo['scheduledtm'] ? '' : ' style="display:none;"') . ' >' . wppa_get_date_time_select_html('album', $id, true) . '</span>' . '<br />' . '<span class="description" >' . __('If enabled, new photos will have their status set scheduled for publication on the date/time specified here.', 'wp-photo-album-plus') . '</span>' . '</td>' . '<td>' . '</td>' . '</tr>'; echo '</tbody>' . '</table>'; // Section 3, Actions echo "\n" . '<!-- Album Section 3 -->' . '<table' . ' class="wppa-table wppa-album-table"' . ' >' . '<tbody>' . '<tr>' . '<td>'; // Inherit cats echo '<input' . ' type="button"' . ' title="' . esc_attr(__('Apply categories to all (grand)children.', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryInheritCats( ' . $id . ' )"' . ' value="' . esc_attr(__('Inherit Cats', 'wp-photo-album-plus')) . '"' . ' />' . '<input' . ' type="button"' . ' title="' . esc_attr(__('Add categories to all (grand)children.', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryAddCats( ' . $id . ' )"' . ' value="' . esc_attr(__('Add Inherit Cats', 'wp-photo-album-plus')) . '"' . ' />'; // Apply default tags echo '<input' . ' type="button"' . ' title="' . esc_attr(__('Tag all photos in this album with the default tags.', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryApplyDeftags( ' . $id . ' )"' . ' value="' . esc_attr(__('Apply default tags', 'wp-photo-album-plus')) . '"' . ' />' . '<input' . ' type="button"' . ' title="' . esc_attr(__('Add the default tags to all photos in this album.', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryAddDeftags( ' . $id . ' )"' . ' value="' . esc_attr(__('Add default tags', 'wp-photo-album-plus')) . '"' . ' />'; // Schedule all echo '<input' . ' type="button"' . ' title="' . esc_attr(__('Tag all photos in this album with the default tags.', 'wp-photo-album-plus')) . '"' . ' onclick="wppaTryScheduleAll( ' . $id . ' )"' . ' value="' . esc_attr(__('Schedule all', 'wp-photo-album-plus')) . '"' . ' />'; // Reset Ratings if (wppa_switch('rating_on')) { $onc = 'if (confirm(\'' . __('Are you sure you want to clear the ratings in this album?', 'wp-photo-album-plus') . '\')) { wppaRefreshAfter(); wppaAjaxUpdateAlbum( ' . $id . ', \'clear_ratings\', 0 ); }'; echo '<input' . ' type="button"' . ' onclick="' . $onc . '"' . ' value="' . esc_attr(__('Reset ratings', 'wp-photo-album-plus')) . '"' . ' />'; } // Apply New photo desc if (wppa_switch('apply_newphoto_desc')) { $onc = 'if ( confirm(\'Are you sure you want to set the description of all photos to \\n\\n' . esc_js(wppa_opt('newphoto_description')) . '\')) document.location=\'' . wppa_ea_url($albuminfo['id'], 'edit') . '&applynewdesc\''; echo '<input' . ' type="button"' . ' onclick="' . $onc . '"' . ' value="' . esc_attr(__('Apply new photo desc', 'wp-photo-album-plus')) . '"' . ' />'; } // Remake all if (wppa_user_is('administrator')) { $onc = 'if ( confirm(\'Are you sure you want to remake the files for all photos in this album?\')) document.location=\'' . wppa_ea_url($albuminfo['id'], 'edit') . '&remakealbum\''; echo '<input' . ' type="button"' . ' onclick="' . $onc . '"' . ' value="' . esc_attr(__('Remake all', 'wp-photo-album-plus')) . '"' . ' />'; } // Goto Upload if (current_user_can('wppa_upload')) { $a = wppa_allow_uploads($id); if ($a) { $full = false; } else { $full = true; } $onc = $full ? 'alert(\'' . __('Change the upload limit or remove photos to enable new uploads.', 'wp-photo-album-plus') . '\')' : 'document.location = \'' . wppa_dbg_url(get_admin_url()) . '/admin.php?page=wppa_upload_photos&wppa-set-album=' . $id . '\''; $val = $full ? __('Album is full', 'wp-photo-album-plus') : __('Upload to this album', 'wp-photo-album-plus') . ($a > '0' ? ' ' . sprintf(__('(max %d)', 'wp-photo-album-plus'), $a) : ''); echo '<input' . ' type="button"' . ' onclick="' . $onc . '"' . ' value="' . $val . '"' . ' />'; } echo '</td>' . '</tr>' . '</tbody>' . '</table>'; ?> </div> <?php wppa_album_sequence($edit_id); ?> <a id="manage-photos" ></a> <img src="<?php echo WPPA_URL . '/img/camera32.png'; ?> " alt="Camera icon" /> <h1 style="display:inline;" ><?php _e('Manage Photos', 'wp-photo-album-plus'); if (isset($_REQUEST['bulk'])) { echo ' - <small><i>' . __('Copy / move / delete / edit name / edit description / change status', 'wp-photo-album-plus') . '</i></small>'; } elseif (isset($_REQUEST['seq'])) { echo ' - <small><i>' . __('Change sequence order by drag and drop', 'wp-photo-album-plus') . '</i></small>'; } elseif (isset($_REQUEST['quick'])) { echo ' - <small><i>' . __('Edit photo information except copy and move', 'wp-photo-album-plus') . '</i></small>'; } else { echo ' - <small><i>' . __('Edit photo information', 'wp-photo-album-plus') . '</i></small>'; } ?> </h1><div style="clear:both;" > </div> <?php if (isset($_REQUEST['bulk'])) { wppa_album_photos_bulk($edit_id); } elseif (isset($_REQUEST['seq'])) { wppa_album_photos_sequence($edit_id); } else { wppa_album_photos($edit_id); } ?> <br /><a href="#manage-photos"><?php _e('Top of page', 'wp-photo-album-plus'); ?> </a> </div> <?php } else { if ($_REQUEST['tab'] == 'cmod') { $photo = $_REQUEST['photo']; $alb = wppa_get_album_id_by_photo_id($photo); if (current_user_can('wppa_comments') && wppa_have_access($alb)) { ?> <div class="wrap"> <img src="<?php echo WPPA_URL . '/img/page_green.png'; ?> " /> <h1 style="display:inline;" ><?php _e('Moderate comment', 'wp-photo-album-plus'); ?> </h1> <div style="clear:both;" > </div> <?php wppa_album_photos('', $photo); ?> </div> <?php } else { wp_die('You do not have the rights to do this'); } } elseif ($_REQUEST['tab'] == 'pmod' || $_REQUEST['tab'] == 'pedit') { $photo = $_REQUEST['photo']; $alb = wppa_get_album_id_by_photo_id($photo); if (current_user_can('wppa_admin') && wppa_have_access($alb)) { ?> <div class="wrap"> <img src="<?php echo WPPA_URL . '/img/page_green.png'; ?> " /> <h1 style="display:inline;" ><?php if ($_REQUEST['tab'] == 'pmod') { _e('Moderate photo', 'wp-photo-album-plus'); } else { _e('Edit photo', 'wp-photo-album-plus'); } ?> </h1><div style="clear:both;" > </div> <?php wppa_album_photos('', $photo); ?> </div> <?php } else { wp_die('You do not have the rights to do this'); } } else { if ($_REQUEST['tab'] == 'del') { $album_owner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM " . WPPA_ALBUMS . " WHERE `id` = %s", $_REQUEST['edit_id'])); if ($album_owner == '--- public ---' && !current_user_can('administrator') || !wppa_have_access($_REQUEST['edit_id'])) { wp_die('You do not have the rights to delete this album'); } ?> <div class="wrap"> <img src="<?php echo WPPA_URL . '/img/albumdel32.png'; ?> " /> <h1 style="display:inline;" ><?php _e('Delete Album', 'wp-photo-album-plus'); ?> </h1> <p><?php _e('Album:', 'wp-photo-album-plus'); ?> <b><?php echo wppa_get_album_name($_REQUEST['edit_id']); ?> .</b></p> <p><?php _e('Are you sure you want to delete this album?', 'wp-photo-album-plus'); ?> <br /> <?php _e('Press Delete to continue, and Cancel to go back.', 'wp-photo-album-plus'); ?> </p> <form name="wppa-del-form" action="<?php echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu'); ?> " method="post"> <?php wp_nonce_field('$wppa_nonce', WPPA_NONCE); ?> <p> <?php _e('What would you like to do with photos currently in the album?', 'wp-photo-album-plus'); ?> <br /> <input type="radio" name="wppa-del-photos" value="delete" checked="checked" /> <?php _e('Delete', 'wp-photo-album-plus'); ?> <br /> <input type="radio" name="wppa-del-photos" value="move" /> <?php _e('Move to:', 'wp-photo-album-plus'); ?> <select name="wppa-move-album"> <?php echo wppa_album_select_a(array('checkaccess' => true, 'path' => wppa_switch('hier_albsel'), 'selected' => '0', 'exclude' => $_REQUEST['edit_id'], 'addpleaseselect' => true)); ?> </select> </p> <input type="hidden" name="wppa-del-id" value="<?php echo $_REQUEST['edit_id']; ?> " /> <input type="button" class="button-primary" value="<?php _e('Cancel', 'wp-photo-album-plus'); ?> " onclick="parent.history.back()" /> <input type="submit" class="button-primary" style="color: red" name="wppa-del-confirm" value="<?php _e('Delete', 'wp-photo-album-plus'); ?> " /> </form> </div> <?php } } } } else { // 'tab' not set. default, album manage page. // if add form has been submitted // if (isset($_POST['wppa-na-submit'])) { // check_admin_referer( '$wppa_nonce', WPPA_NONCE ); // wppa_add_album(); // } // if album deleted if (isset($_POST['wppa-del-confirm'])) { check_admin_referer('$wppa_nonce', WPPA_NONCE); $album_owner = $wpdb->get_var($wpdb->prepare("SELECT `owner` FROM " . WPPA_ALBUMS . " WHERE `id` = %s", $_POST['wppa-del-id'])); if ($album_owner == '--- public ---' && !current_user_can('administrator') || !wppa_have_access($_POST['wppa-del-id'])) { wp_die('You do not have the rights to delete this album'); } if ($_POST['wppa-del-photos'] == 'move') { $move = $_POST['wppa-move-album']; if (wppa_have_access($move)) { wppa_del_album($_POST['wppa-del-id'], $move); } else { wppa_error_message(__('Unable to move photos. Album not deleted.', 'wp-photo-album-plus')); } } else { wppa_del_album($_POST['wppa-del-id'], ''); } } if (wppa_extended_access()) { if (isset($_REQUEST['switchto'])) { update_option('wppa_album_table_' . wppa_get_user(), $_REQUEST['switchto']); } $style = get_option('wppa_album_table_' . wppa_get_user(), 'flat'); } else { $style = 'flat'; } // The Manage Album page ?> <div class="wrap"> <?php wppa_admin_spinner(); ?> <img src="<?php echo WPPA_URL . '/img/album32.png'; ?> " /> <h1 style="display:inline;" ><?php _e('Manage Albums', 'wp-photo-album-plus'); ?> </h1> <div style="clear:both;" > </div> <?php // The Create new album button if (wppa_can_create_top_album()) { $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&tab=edit&edit_id=new'); $vfy = __('Are you sure you want to create a new album?', 'wp-photo-album-plus'); echo '<form method="post" action="' . get_admin_url() . 'admin.php?page=wppa_admin_menu" style="float:left; margin-right:12px;" >'; echo '<input type="hidden" name="tab" value="edit" />'; echo '<input type="hidden" name="edit_id" value="new" />'; $onc = wppa_switch('confirm_create') ? 'onclick="return confirm(\'' . $vfy . '\');"' : ''; echo '<input type="submit" class="button-primary" ' . $onc . ' value="' . __('Create New Empty Album', 'wp-photo-album-plus') . '" style="height:28px;" />'; echo '</form>'; } // The switch to button(s) if (wppa_extended_access()) { if ($style == 'flat') { ?> <input type="button" class="button-secundary" onclick="document.location='<?php echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&switchto=collapsable'); ?> '" value="<?php _e('Switch to Collapsable table', 'wp-photo-album-plus'); ?> " /> <?php } if ($style == 'collapsable') { ?> <input type="button" class="button-secundary" onclick="document.location='<?php echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_admin_menu&switchto=flat'); ?> '" value="<?php _e('Switch to Flat table', 'wp-photo-album-plus'); ?> " /> <input type="button" class="button-secundary" id="wppa-open-all" style="display:inline;" onclick=" jQuery('#wppa-close-all').css('display','inline'); jQuery(this).css('display','none'); jQuery('.wppa-alb-onoff').css('display',''); jQuery('.alb-arrow-off').css('display',''); jQuery('.alb-arrow-on').css('display','none'); " value="<?php _e('Open all', 'wp-photo-album-plus'); ?> " /> <input type="button" class="button-secundary" id="wppa-close-all" style="display:none;" onclick=" jQuery('#wppa-open-all').css('display','inline'); jQuery(this).css('display','none'); jQuery('.wppa-alb-onoff').css('display','none'); jQuery('.alb-arrow-on').css('display',''); jQuery('.alb-arrow-off').css('display','none'); " value="<?php _e('Close all', 'wp-photo-album-plus'); ?> " /> <?php } } ?> <br /> <?php // The table of existing albums if ($style == 'flat') { wppa_admin_albums_flat(); } else { wppa_admin_albums_collapsable(); } ?> <br /> <?php wppa_album_sequence('0'); ?> </div> <?php } }
function wppa_do_maintenance_proc($slug) { global $wpdb; global $wppa_session; global $wppa_supported_video_extensions; global $wppa_supported_audio_extensions; // Check for multiple maintenance procs if (!wppa_switch('maint_ignore_concurrency_error') && !wppa_is_cron()) { $all_slugs = array('wppa_remake_index_albums', 'wppa_remove_empty_albums', 'wppa_remake_index_photos', 'wppa_apply_new_photodesc_all', 'wppa_append_to_photodesc', 'wppa_remove_from_photodesc', 'wppa_remove_file_extensions', 'wppa_readd_file_extensions', 'wppa_all_ext_to_lower', 'wppa_regen_thumbs', 'wppa_rerate', 'wppa_recup', 'wppa_file_system', 'wppa_cleanup', 'wppa_remake', 'wppa_list_index', 'wppa_blacklist_user', 'wppa_un_blacklist_user', 'wppa_rating_clear', 'wppa_viewcount_clear', 'wppa_iptc_clear', 'wppa_exif_clear', 'wppa_watermark_all', 'wppa_create_all_autopages', 'wppa_delete_all_autopages', 'wppa_leading_zeros', 'wppa_add_gpx_tag', 'wppa_optimize_ewww', 'wppa_comp_sizes', 'wppa_edit_tag', 'wppa_sync_cloud', 'wppa_sanitize_tags', 'wppa_sanitize_cats', 'wppa_test_proc', 'wppa_crypt_photos', 'wppa_crypt_albums', 'wppa_create_o1_files', 'wppa_owner_to_name_proc', 'wppa_move_all_photos'); foreach (array_keys($all_slugs) as $key) { if ($all_slugs[$key] != $slug) { if (get_option($all_slugs[$key] . '_togo', '0')) { // Process running return __('You can run only one maintenance procedure at a time', 'wp-photo-album-plus') . '||' . $slug . '||' . __('Error', 'wp-photo-album-plus') . '||' . '' . '||' . ''; } } } } // Lock this proc if (wppa_is_cron()) { update_option($slug . '_user', 'cron-job'); update_option($slug . '_lasttimestamp', time()); } else { update_option($slug . '_user', wppa_get_user()); } // Extend session wppa_extend_session(); // Initialize // Cron job: 30 sec, realtime: 5 sec $endtime = wppa_is_cron() ? time() + '30' : time() + '5'; $chunksize = '1000'; $lastid = strval(intval(get_option($slug . '_last', '0'))); $errtxt = ''; $id = '0'; $topid = '0'; $reload = ''; $to_delete_from_cloudinary = array(); if (!isset($wppa_session)) { $wppa_session = array(); } if (!isset($wppa_session[$slug . '_fixed'])) { $wppa_session[$slug . '_fixed'] = '0'; } if (!isset($wppa_session[$slug . '_added'])) { $wppa_session[$slug . '_added'] = '0'; } if (!isset($wppa_session[$slug . '_deleted'])) { $wppa_session[$slug . '_deleted'] = '0'; } if (!isset($wppa_session[$slug . '_skipped'])) { $wppa_session[$slug . '_skipped'] = '0'; } if ($lastid == '0') { $wppa_session[$slug . '_fixed'] = '0'; $wppa_session[$slug . '_deleted'] = '0'; $wppa_session[$slug . '_skipped'] = '0'; } wppa_save_session(); // Pre-processing needed? if ($lastid == '0') { if (wppa_is_cron()) { wppa_log('Obs', 'Cron job ' . $slug . ' started.'); } else { wppa_log('Obs', 'Maintenance proc ' . $slug . ' started.'); } switch ($slug) { case 'wppa_remake_index_albums': // Pre-Clear album index only if not cron if (!wppa_is_cron()) { $wpdb->query("UPDATE `" . WPPA_INDEX . "` SET `albums` = ''"); } break; case 'wppa_remake_index_photos': // Pre-Clear photo index only if not cron if (!wppa_is_cron()) { $wpdb->query("UPDATE `" . WPPA_INDEX . "` SET `photos` = ''"); } wppa_index_compute_skips(); break; case 'wppa_recup': // Pre-Clear exif and iptc tables only if not cron if (!wppa_is_cron()) { $wpdb->query("DELETE FROM `" . WPPA_IPTC . "` WHERE `photo` <> '0'"); $wpdb->query("DELETE FROM `" . WPPA_EXIF . "` WHERE `photo` <> '0'"); } break; case 'wppa_file_system': if (get_option('wppa_file_system') == 'flat') { update_option('wppa_file_system', 'to-tree'); } if (get_option('wppa_file_system') == 'tree') { update_option('wppa_file_system', 'to-flat'); } break; case 'wppa_cleanup': $orphan_album = get_option('wppa_orphan_album', '0'); $album_exists = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM`" . WPPA_ALBUMS . "` WHERE `id` = %s", $orphan_album)); if (!$album_exists) { $orphan_album = false; } if (!$orphan_album) { $orphan_album = wppa_create_album_entry(array('name' => __('Orphan photos', 'wp-photo-album-plus'), 'a_parent' => '-1', 'description' => __('This album contains refound lost photos', 'wp-photo-album-plus'))); update_option('wppa_orphan_album', $orphan_album); } break; case 'wppa_sync_cloud': if (!wppa_get_present_at_cloudinary_a()) { // Still Initializing $status = 'Initializing'; if (!isset($wppa_session['fun-count'])) { $wppa_session['fun-count'] = 0; } $wppa_session['fun-count'] = ($wppa_session['fun-count'] + 1) % 3; for ($i = 0; $i < $wppa_session['fun-count']; $i++) { $status .= '.'; } $togo = 'all'; $reload = false; echo '||' . $slug . '||' . $status . '||' . $togo . '||' . $reload; wppa_exit(); } break; case 'wppa_crypt_albums': update_option('wppa_album_crypt_0', wppa_get_unique_album_crypt()); update_option('wppa_album_crypt_1', wppa_get_unique_album_crypt()); update_option('wppa_album_crypt_2', wppa_get_unique_album_crypt()); update_option('wppa_album_crypt_3', wppa_get_unique_album_crypt()); update_option('wppa_album_crypt_9', wppa_get_unique_album_crypt()); break; case 'wppa_owner_to_name_proc': if (!wppa_switch('owner_to_name')) { echo __('Feature must be enabled in Table IV-A28 first', 'wp-photo-album-plus') . '||' . $slug . '||||||'; wppa_exit(); } break; case 'wppa_move_all_photos': $fromalb = get_option('wppa_move_all_photos_from'); if (!wppa_album_exists($fromalb)) { echo sprintf(__('From album %d does not exist', 'wp-photo-album-plus'), $fromalb); wppa_exit(); } $toalb = get_option('wppa_move_all_photos_to'); if (!wppa_album_exists($toalb)) { echo sprintf(__('To album %d does not exist', 'wp-photo-album-plus'), $toalb); wppa_exit(); } if ($fromalb == $toalb) { echo __('From and To albums are identical', 'wp-photo-album-plus'); wppa_exit(); } break; } wppa_save_session(); } // Dispatch on albums / photos / single actions switch ($slug) { case 'wppa_remake_index_albums': case 'wppa_remove_empty_albums': case 'wppa_sanitize_cats': case 'wppa_crypt_albums': // Process albums $table = WPPA_ALBUMS; $topid = $wpdb->get_var("SELECT `id` FROM `" . WPPA_ALBUMS . "` ORDER BY `id` DESC LIMIT 1"); $albums = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `id` > " . $lastid . " ORDER BY `id` LIMIT 100", ARRAY_A); wppa_cache_album('add', $albums); if ($albums) { foreach ($albums as $album) { $id = $album['id']; switch ($slug) { case 'wppa_remake_index_albums': // If done as cron job, no initial clear has been done if (wppa_is_cron()) { wppa_index_remove('album', $id); } wppa_index_add('album', $id); break; case 'wppa_remove_empty_albums': $p = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s", $id)); $a = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = %s", $id)); if (!$a && !$p) { $wpdb->query($wpdb->prepare("DELETE FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $id)); wppa_delete_album_source($id); wppa_flush_treecounts($id); wppa_index_remove('album', $id); } break; case 'wppa_sanitize_cats': $cats = $album['cats']; if ($cats) { wppa_update_album(array('id' => $album['id'], 'cats' => wppa_sanitize_tags($cats))); } break; case 'wppa_crypt_albums': wppa_update_album(array('id' => $album['id'], 'crypt' => wppa_get_unique_album_crypt())); break; } // Test for timeout / ready $lastid = $id; update_option($slug . '_last', $lastid); if (time() > $endtime) { break; } // Time out } } else { // Nothing to do, Done anyway $lastid = $topid; } break; // End process albums // End process albums case 'wppa_remake_index_photos': case 'wppa_apply_new_photodesc_all': case 'wppa_append_to_photodesc': case 'wppa_remove_from_photodesc': case 'wppa_remove_file_extensions': case 'wppa_readd_file_extensions': case 'wppa_all_ext_to_lower': case 'wppa_regen_thumbs': case 'wppa_rerate': case 'wppa_recup': case 'wppa_file_system': case 'wppa_cleanup': case 'wppa_remake': case 'wppa_watermark_all': case 'wppa_create_all_autopages': case 'wppa_delete_all_autopages': case 'wppa_leading_zeros': case 'wppa_add_gpx_tag': case 'wppa_optimize_ewww': case 'wppa_comp_sizes': case 'wppa_edit_tag': case 'wppa_sync_cloud': case 'wppa_sanitize_tags': case 'wppa_crypt_photos': case 'wppa_test_proc': case 'wppa_create_o1_files': case 'wppa_owner_to_name_proc': case 'wppa_move_all_photos': // Process photos $table = WPPA_PHOTOS; if ($slug == 'wppa_cleanup') { $topid = get_option('wppa_' . WPPA_PHOTOS . '_lastkey', '1') * 10; $photos = array(); for ($i = $lastid + '1'; $i <= $topid; $i++) { $photos[]['id'] = $i; } } else { $topid = $wpdb->get_var("SELECT `id` FROM `" . WPPA_PHOTOS . "` ORDER BY `id` DESC LIMIT 1"); $photos = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` > " . $lastid . " ORDER BY `id` LIMIT " . $chunksize, ARRAY_A); } if ($slug == 'wppa_edit_tag') { $edit_tag = get_option('wppa_tag_to_edit'); $new_tag = get_option('wppa_new_tag_value'); } if (!$photos && $slug == 'wppa_file_system') { $fs = get_option('wppa_file_system'); if ($fs == 'to-tree') { $to = 'tree'; } elseif ($fs == 'to-flat') { $to = 'flat'; } else { $to = $fs; } } if ($photos) { foreach ($photos as $photo) { $thumb = $photo; // Make globally known $id = $photo['id']; switch ($slug) { case 'wppa_remake_index_photos': // If done as cron job, no initial clear has been done if (wppa_is_cron()) { wppa_index_remove('photo', $id); } wppa_index_add('photo', $id); break; case 'wppa_apply_new_photodesc_all': $value = wppa_opt('newphoto_description'); $description = trim($value); if ($description != $photo['description']) { // Modified photo description $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `description` = %s WHERE `id` = %s", $description, $id)); } break; case 'wppa_append_to_photodesc': $value = trim(wppa_opt('append_text')); if (!$value) { return 'Unexpected error: missing text to append||' . $slug . '||Error||0'; } $description = rtrim($photo['description'] . ' ' . $value); if ($description != $photo['description']) { // Modified photo description $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `description` = %s WHERE `id` = %s", $description, $id)); } break; case 'wppa_remove_from_photodesc': $value = trim(wppa_opt('remove_text')); if (!$value) { return 'Unexpected error: missing text to remove||' . $slug . '||Error||0'; } $description = rtrim(str_replace($value, '', $photo['description'])); if ($description != $photo['description']) { // Modified photo description $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `description` = %s WHERE `id` = %s", $description, $id)); } break; case 'wppa_remove_file_extensions': if (!wppa_is_video($id)) { $name = str_replace(array('.jpg', '.png', '.gif', '.JPG', '.PNG', '.GIF'), '', $photo['name']); if ($name != $photo['name']) { // Modified photo name $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `name` = %s WHERE `id` = %s", $name, $id)); } } break; case 'wppa_readd_file_extensions': if (!wppa_is_video($id)) { $name = str_replace(array('.jpg', '.png', 'gif', '.JPG', '.PNG', '.GIF'), '', $photo['name']); if ($name == $photo['name']) { // Name had no fileextension $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `name` = %s WHERE `id` = %s", $name . '.' . $photo['ext'], $id)); } } break; case 'wppa_all_ext_to_lower': $EXT = wppa_get_photo_item($id, 'ext'); $ext = strtolower($EXT); if ($EXT != $ext) { wppa_update_photo(array('id' => $id, 'ext' => $ext)); $fixed_this = true; } $EXT = strtoupper($ext); $rawpath = wppa_strip_ext(wppa_get_photo_path($id)); $rawthumb = wppa_strip_ext(wppa_get_thumb_path($id)); $fixed_this = false; if (wppa_is_multi($id)) { } else { if (is_file($rawpath . '.' . $EXT)) { if (is_file($rawpath . '.' . $ext)) { unlink($rawpath . '.' . $EXT); } else { rename($rawpath . '.' . $EXT, $rawpath . '.' . $ext); } $fixed_this = true; } if (is_file($rawthumb . '.' . $EXT)) { if (is_file($rawthumb . '.' . $ext)) { unlink($rawthumb . '.' . $EXT); } else { rename($rawthumb . '.' . $EXT, $rawthumb . '.' . $ext); } $fixed_this = true; } } if ($fixed_this) { $wppa_session[$slug . '_fixed']++; } else { $wppa_session[$slug . '_skipped']++; } break; case 'wppa_regen_thumbs': if (!wppa_is_video($id) || file_exists(str_replace('xxx', 'jpg', wppa_get_photo_path($id)))) { wppa_create_thumbnail($id); } break; case 'wppa_rerate': wppa_rate_photo($id); break; case 'wppa_recup': $a_ret = wppa_recuperate($id); if ($a_ret['iptcfix']) { $wppa_session[$slug . '_fixed']++; } if ($a_ret['exiffix']) { $wppa_session[$slug . '_fixed']++; } break; case 'wppa_file_system': $fs = get_option('wppa_file_system'); if ($fs == 'to-tree' || $fs == 'to-flat') { if ($fs == 'to-tree') { $from = 'flat'; $to = 'tree'; } else { $from = 'tree'; $to = 'flat'; } // Media files if (wppa_is_multi($id)) { // Can NOT use wppa_has_audio() or wppa_is_video(), they use wppa_get_photo_path() without fs switch!! $exts = array_merge($wppa_supported_video_extensions, $wppa_supported_audio_extensions); $pathfrom = wppa_get_photo_path($id, $from); $pathto = wppa_get_photo_path($id, $to); // wppa_log( 'dbg', 'Trying: '.$pathfrom ); foreach ($exts as $ext) { if (is_file(str_replace('.xxx', '.' . $ext, $pathfrom))) { // wppa_log( 'dbg', str_replace( '.xxx', '.'.$ext, $pathfrom ).' -> '.str_replace( '.xxx', '.'.$ext, $pathto )); @rename(str_replace('.xxx', '.' . $ext, $pathfrom), str_replace('.xxx', '.' . $ext, $pathto)); } } } // Poster / photo if (file_exists(wppa_fix_poster_ext(wppa_get_photo_path($id, $from), $id))) { @rename(wppa_fix_poster_ext(wppa_get_photo_path($id, $from), $id), wppa_fix_poster_ext(wppa_get_photo_path($id, $to), $id)); } // Thumbnail if (file_exists(wppa_fix_poster_ext(wppa_get_thumb_path($id, $from), $id))) { @rename(wppa_fix_poster_ext(wppa_get_thumb_path($id, $from), $id), wppa_fix_poster_ext(wppa_get_thumb_path($id, $to), $id)); } } break; case 'wppa_cleanup': $photo_files = glob(WPPA_UPLOAD_PATH . '/' . $id . '.*'); // Remove dirs if ($photo_files) { foreach (array_keys($photo_files) as $key) { if (is_dir($photo_files[$key])) { unset($photo_files[$key]); } } } // files left? process if ($photo_files) { foreach ($photo_files as $photo_file) { $basename = basename($photo_file); $ext = substr($basename, strpos($basename, '.') + '1'); if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $id))) { // no db entry for this photo if (wppa_is_id_free(WPPA_PHOTOS, $id)) { if (wppa_create_photo_entry(array('id' => $id, 'album' => $orphan_album, 'ext' => $ext, 'filename' => $basename))) { // Can create entry $wppa_session[$slug . '_fixed']++; // Bump counter wppa_log('Debug', 'Lost photo file ' . $photo_file . ' recovered'); } else { wppa_log('Debug', 'Unable to recover lost photo file ' . $photo_file . ' Create photo entry failed'); } } else { wppa_log('Debug', 'Could not recover lost photo file ' . $photo_file . ' The id is not free'); } } } } break; case 'wppa_remake': $doit = true; if (wppa_switch('remake_orientation_only')) { $ori = wppa_get_exif_orientation(wppa_get_source_path($id)); if ($ori < '2') { $doit = false; } } if (wppa_switch('remake_missing_only')) { if (is_file(wppa_get_thumb_path($id)) && is_file(wppa_get_photo_path($id))) { $doit = false; } } if ($doit && wppa_remake_files('', $id)) { $wppa_session[$slug . '_fixed']++; } else { $wppa_session[$slug . '_skipped']++; } break; case 'wppa_watermark_all': if (!wppa_is_video($id)) { if (wppa_add_watermark($id)) { wppa_create_thumbnail($id); // create new thumb $wppa_session[$slug . '_fixed']++; } else { $wppa_session[$slug . '_skipped']++; } } else { $wppa_session[$slug . '_skipped']++; } break; case 'wppa_create_all_autopages': wppa_get_the_auto_page($id); break; case 'wppa_delete_all_autopages': wppa_remove_the_auto_page($id); break; case 'wppa_leading_zeros': $name = $photo['name']; if (wppa_is_int($name)) { $target_len = wppa_opt('zero_numbers'); $name = strval(intval($name)); while (strlen($name) < $target_len) { $name = '0' . $name; } } if ($name !== $photo['name']) { $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `name` = %s WHERE `id` = %s", $name, $id)); } break; case 'wppa_add_gpx_tag': $tags = $photo['tags']; $temp = explode('/', $photo['location']); if (!isset($temp['2'])) { $temp['2'] = false; } if (!isset($temp['3'])) { $temp['3'] = false; } $lat = $temp['2']; $lon = $temp['3']; if ($lat < 0.01 && $lat > -0.01 && $lon < 0.01 && $lon > -0.01) { $lat = false; $lon = false; } if ($photo['location'] && strpos($tags, 'Gpx') === false && $lat && $lon) { // Add it $tags = wppa_sanitize_tags($tags . ',Gpx'); wppa_update_photo(array('id' => $photo['id'], 'tags' => $tags)); wppa_index_update('photo', $photo['id']); wppa_clear_taglist(); } elseif (strpos($tags, 'Gpx') !== false && !$lat && !$lon) { // Remove it $tags = wppa_sanitize_tags(str_replace('Gpx', '', $tags)); wppa_update_photo(array('id' => $photo['id'], 'tags' => $tags)); wppa_index_update('photo', $photo['id']); wppa_clear_taglist(); } break; case 'wppa_optimize_ewww': $file = wppa_get_photo_path($photo['id']); if (is_file($file)) { ewww_image_optimizer($file, 4, false, false, false); } $file = wppa_get_thumb_path($photo['id']); if (is_file($file)) { ewww_image_optimizer($file, 4, false, false, false); } break; case 'wppa_comp_sizes': $tx = 0; $ty = 0; $px = 0; $py = 0; $file = wppa_get_photo_path($photo['id']); if (is_file($file)) { $temp = getimagesize($file); if (is_array($temp)) { $px = $temp[0]; $py = $temp[1]; } } $file = wppa_get_thumb_path($photo['id']); if (is_file($file)) { $temp = getimagesize($file); if (is_array($temp)) { $tx = $temp[0]; $ty = $temp[1]; } } wppa_update_photo(array('id' => $photo['id'], 'thumbx' => $tx, 'thumby' => $ty, 'photox' => $px, 'photoy' => $py)); break; case 'wppa_edit_tag': $phototags = explode(',', wppa_get_photo_item($photo['id'], 'tags')); if (in_array($edit_tag, $phototags)) { foreach (array_keys($phototags) as $key) { if ($phototags[$key] == $edit_tag) { $phototags[$key] = $new_tag; } } $tags = wppa_sanitize_tags(implode(',', $phototags)); wppa_update_photo(array('id' => $photo['id'], 'tags' => $tags)); $wppa_session[$slug . '_fixed']++; } else { $wppa_session[$slug . '_skipped']++; } break; case 'wppa_sync_cloud': $is_old = wppa_opt('max_cloud_life') && time() > $photo['timestamp'] + wppa_opt('max_cloud_life'); // $is_in_cloud = @ getimagesize( wppa_get_cloudinary_url( $photo['id'], 'test_only' ) ); $is_in_cloud = isset($wppa_session['cloudinary_ids'][$photo['id']]); // wppa_log('Obs', 'Id='.$photo['id'].', is old='.$is_old.', in cloud='.$is_in_cloud); if ($is_old && $is_in_cloud) { $to_delete_from_cloudinary[] = strval($photo['id']); if (count($to_delete_from_cloudinary) == 10) { wppa_delete_from_cloudinary($to_delete_from_cloudinary); $to_delete_from_cloudinary = array(); } $wppa_session[$slug . '_deleted']++; } if (!$is_old && !$is_in_cloud) { wppa_upload_to_cloudinary($photo['id']); $wppa_session[$slug . '_added']++; } if ($is_old && !$is_in_cloud) { $wppa_session[$slug . '_skipped']++; } if (!$is_old && $is_in_cloud) { $wppa_session[$slug . '_skipped']++; } break; case 'wppa_sanitize_tags': $tags = $photo['tags']; if ($tags) { wppa_update_photo(array('id' => $photo['id'], 'tags' => wppa_sanitize_tags($tags))); } break; case 'wppa_crypt_photos': wppa_update_photo(array('id' => $photo['id'], 'crypt' => wppa_get_unique_photo_crypt())); break; case 'wppa_create_o1_files': wppa_make_o1_source($photo['id']); break; case 'wppa_owner_to_name_proc': $iret = wppa_set_owner_to_name($id); if ($iret === true) { $wppa_session[$slug . '_fixed']++; } if ($iret === '0') { $wppa_session[$slug . '_skipped']++; } break; case 'wppa_move_all_photos': $fromalb = get_option('wppa_move_all_photos_from'); $toalb = get_option('wppa_move_all_photos_to'); $alb = wppa_get_photo_item($id, 'album'); if ($alb == $fromalb) { wppa_update_photo(array('id' => $id, 'album' => $toalb)); wppa_move_source(wppa_get_photo_item($id, 'filename'), $fromalb, $toalb); wppa_flush_treecounts($fromalb); wppa_flush_treecounts($toalb); $wppa_session[$slug . '_fixed']++; } break; case 'wppa_test_proc': $tags = ''; $albid = $photo['album']; $albnam = wppa_get_album_item($albid, 'name'); $tags .= $albnam; while ($albid > '0') { $albid = wppa_get_album_item($albid, 'a_parent'); if ($albid > '0') { $tags .= ',' . wppa_get_album_item($albid, 'name'); } } wppa_update_photo(array('id' => $photo['id'], 'tags' => wppa_sanitize_tags($tags))); break; } // Test for timeout / ready $lastid = $id; update_option($slug . '_last', $lastid); if (time() > $endtime) { break; } // Time out } } else { // Nothing to do, Done anyway $lastid = $topid; wppa_log('Debug', 'Maintenance proc ' . $slug . ': Done!'); } break; // End process photos // Single action maintenance modules // case 'wppa_list_index': // break; // case 'wppa_blacklist_user': // break; // case 'wppa_un_blacklist_user': // break; // case 'wppa_rating_clear': // break; // case 'wppa_viewcount_clear': // break; // case 'wppa_iptc_clear': // break; // case 'wppa_exif_clear': // break; // End process photos // Single action maintenance modules // case 'wppa_list_index': // break; // case 'wppa_blacklist_user': // break; // case 'wppa_un_blacklist_user': // break; // case 'wppa_rating_clear': // break; // case 'wppa_viewcount_clear': // break; // case 'wppa_iptc_clear': // break; // case 'wppa_exif_clear': // break; default: $errtxt = 'Unimplemented maintenance slug: ' . strip_tags($slug); } // either $albums / $photos has been exhousted ( for this try ) or time is up // Post proc this try: switch ($slug) { case 'wppa_sync_cloud': if (count($to_delete_from_cloudinary) > 0) { wppa_delete_from_cloudinary($to_delete_from_cloudinary); } break; } // Find togo if ($slug == 'wppa_cleanup') { $togo = $topid - $lastid; } else { $togo = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . $table . "` WHERE `id` > %s ", $lastid)); } // Find status if (!$errtxt) { $status = $togo ? 'Working' : 'Ready'; } else { $status = 'Error'; } // Not done yet? if ($togo) { // If a cron job, reschedule next chunk if (wppa_is_cron()) { update_option($slug . '_togo', $togo); update_option($slug . '_status', 'Running cron'); wppa_schedule_maintenance_proc($slug); } else { update_option($slug . '_togo', $togo); update_option($slug . '_status', 'Pending'); } } else { // Report fixed/skipped/deleted if ($wppa_session[$slug . '_fixed']) { $status .= ' fixed:' . $wppa_session[$slug . '_fixed']; unset($wppa_session[$slug . '_fixed']); } if ($wppa_session[$slug . '_added']) { $status .= ' added:' . $wppa_session[$slug . '_added']; unset($wppa_session[$slug . '_added']); } if ($wppa_session[$slug . '_deleted']) { $status .= ' deleted:' . $wppa_session[$slug . '_deleted']; unset($wppa_session[$slug . '_deleted']); } if ($wppa_session[$slug . '_skipped']) { $status .= ' skipped:' . $wppa_session[$slug . '_skipped']; unset($wppa_session[$slug . '_skipped']); } // Re-Init options update_option($slug . '_togo', ''); update_option($slug . '_status', ''); update_option($slug . '_last', '0'); update_option($slug . '_user', ''); update_option($slug . '_lasttimestamp', '0'); // Post-processing needed? switch ($slug) { case 'wppa_remake_index_albums': case 'wppa_remake_index_photos': $wpdb->query("DELETE FROM `" . WPPA_INDEX . "` WHERE `albums` = '' AND `photos` = ''"); // Remove empty entries delete_option('wppa_index_need_remake'); break; case 'wppa_apply_new_photodesc_all': case 'wppa_append_to_photodesc': case 'wppa_remove_from_photodesc': update_option('wppa_remake_index_photos_status', __('Required', 'wp-photo-album-plus')); break; case 'wppa_regen_thumbs': wppa_bump_thumb_rev(); break; case 'wppa_file_system': wppa_update_option('wppa_file_system', $to); $reload = 'reload'; break; case 'wppa_remake': wppa_bump_photo_rev(); wppa_bump_thumb_rev(); break; case 'wppa_edit_tag': wppa_clear_taglist(); if (wppa_switch('search_tags')) { update_option('wppa_remake_index_photos_status', __('Required', 'wp-photo-album-plus')); } $reload = 'reload'; break; case 'wppa_sanitize_tags': wppa_clear_taglist(); break; case 'wppa_sanitize_cats': wppa_clear_catlist(); break; case 'wppa_test_proc': wppa_clear_taglist(); break; case 'wppa_sync_cloud': unset($wppa_session['cloudinary_ids']); break; } wppa_log('Obs', 'Maintenance proc ' . $slug . ' completed'); } wppa_save_session(); if (wppa_is_cron()) { wppa_log('obs', $errtxt . '||' . $slug . '||' . $status . '||' . $togo . '||' . $reload); } return $errtxt . '||' . $slug . '||' . $status . '||' . $togo . '||' . $reload; }
function wppa_album_select_a($args) { global $wpdb; $args = wp_parse_args($args, array('exclude' => '', 'selected' => '', 'disabled' => '', 'addpleaseselect' => false, 'addnone' => false, 'addall' => false, 'addgeneric' => false, 'addblank' => false, 'addselected' => false, 'addseparate' => false, 'addselbox' => false, 'disableancestors' => false, 'checkaccess' => false, 'checkowner' => false, 'checkupload' => false, 'addmultiple' => false, 'addnumbers' => false, 'path' => false, 'root' => false, 'content' => false, 'sort' => true)); // Provide default selection if no selected given if ($args['selected'] === '') { $args['selected'] = wppa_get_last_album(); } // See if selection is valid if ($args['selected'] == $args['exclude'] || $args['checkupload'] && !wppa_allow_uploads($args['selected']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $args['selected'])) { $args['selected'] = '0'; } $albums = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "` " . wppa_get_album_order($args['root']), ARRAY_A); // Add to secondary cache if ($albums) { wppa_cache_album('add', $albums); } if ($albums) { // Filter for root if ($args['root']) { $root = $args['root']; switch ($root) { // case '0': all, will be skipped as it returns false in 'if ( $args['root'] )' case '-2': // Generic only foreach (array_keys($albums) as $albidx) { if (wppa_is_separate($albums[$albidx]['id'])) { unset($albums[$albidx]); } } break; case '-1': // Separate only foreach (array_keys($albums) as $albidx) { if (!wppa_is_separate($albums[$albidx]['id'])) { unset($albums[$albidx]); } } break; default: foreach (array_keys($albums) as $albidx) { if (!wppa_is_ancestor($root, $albums[$albidx]['id'])) { unset($albums[$albidx]); } } break; } } // Filter for must have content if ($args['content']) { foreach (array_keys($albums) as $albidx) { if (wppa_get_photo_count($albums[$albidx]['id']) <= wppa_get_mincount()) { unset($albums[$albidx]); } } } // Add paths if ($args['path']) { $albums = wppa_add_paths($albums); } else { foreach (array_keys($albums) as $index) { $albums[$index]['name'] = __(stripslashes($albums[$index]['name'])); } } // Sort if ($args['sort']) { $albums = wppa_array_sort($albums, 'name'); } } // Output $result = ''; $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addpleaseselect']) { $result .= '<option value="0" disabled="disabled" ' . $selected . ' >' . (is_admin() ? __('- select an album -', 'wppa') : __a('- select an album -')) . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addnone']) { $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- none ---', 'wppa') : __a('--- none ---')) . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addall']) { $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- all ---', 'wppa') : __a('--- all ---')) . '</option>'; } $selected = $args['selected'] == '-2' ? ' selected="selected"' : ''; if ($args['addall']) { $result .= '<option value="-2"' . $selected . ' >' . (is_admin() ? __('--- generic ---', 'wppa') : __a('--- generic ---')) . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addblank']) { $result .= '<option value="0"' . $selected . ' >' . '</option>'; } $selected = $args['selected'] == '-99' ? ' selected="selected"' : ''; if ($args['addmultiple']) { $result .= '<option value="-99"' . $selected . ' >' . (is_admin() ? __('--- multiple see below ---', 'wppa') : __a('--- multiple see below ---')) . '</option>'; } $selected = $args['selected'] == '0' ? ' selected="selected"' : ''; if ($args['addselbox']) { $result .= '<option value="0"' . $selected . ' >' . (is_admin() ? __('--- a selection box ---', 'wppa') : __a('--- a selection box ---')) . '</option>'; } if ($albums) { foreach ($albums as $album) { if ($args['disabled'] == $album['id'] || $args['exclude'] == $album['id'] || $args['checkupload'] && !wppa_allow_uploads($album['id']) || $args['disableancestors'] && wppa_is_ancestor($args['exclude'], $album['id'])) { $disabled = ' disabled="disabled"'; } else { $disabled = ''; } if ($args['selected'] == $album['id'] && !$disabled) { $selected = ' selected="selected"'; } else { $selected = ''; } $ok = true; // Assume this will be in the list if ($args['checkaccess'] && !wppa_have_access($album['id'])) { $ok = false; } if ($args['checkowner'] && wppa_switch('upload_owner_only')) { // Need to check if ($album['owner'] != wppa_get_user() && $album['owner'] != '--- public ---') { // Not 'mine' if (!wppa_user_is('administrator')) { // No admin $ok = false; } } } if ($selected && $args['addselected']) { $ok = true; } if ($ok) { if ($args['addnumbers']) { $number = ' ( ' . $album['id'] . ' )'; } else { $number = ''; } $result .= '<option value="' . $album['id'] . '" ' . $selected . $disabled . '>' . $album['name'] . $number . '</option>'; } } } $selected = $args['selected'] == '-1' ? ' selected="selected"' : ''; if ($args['addseparate']) { $result .= '<option value="-1"' . $selected . '>' . (is_admin() ? __('--- separate ---', 'wppa') : __a('--- separate ---')) . '</option>'; } return $result; }
function wppa_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_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_dbg_cachecounts($what) { static $counters; // Init $indexes = array('albumhit', 'albummis', 'photohit', 'photomis'); foreach ($indexes as $i) { if (!isset($counters[$i])) { $counters[$i] = 0; } } if (wppa('debug')) { switch ($what) { case 'albumhit': case 'albummis': case 'photohit': case 'photomis': $counters[$what]++; break; case 'print': if ($counters['albumhit'] + $counters['albummis'] && $counters['photohit'] + $counters['photomis']) { wppa_dbg_msg('Cache usage: ' . 'Album hits: ' . $counters['albumhit'] . ', ' . 'Album misses: ' . $counters['albummis'] . ' = ' . sprintf('%6.2f', 100 * $counters['albummis'] / ($counters['albumhit'] + $counters['albummis'])) . '%; ' . 'Photo hits: ' . $counters['photohit'] . ', ' . 'Photo misses: ' . $counters['photomis'] . ' = ' . sprintf('%6.2f', 100 * $counters['photomis'] / ($counters['photohit'] + $counters['photomis'])) . '%; '); wppa_dbg_msg('2nd level cache entries: ' . 'albums: ' . wppa_cache_album('count') . ', ' . 'photos: ' . wppa_cache_photo('count') . '. ' . 'NQ=' . get_num_queries()); } else { wppa_dbg_msg('Cache usage: ' . 'Album hits: ' . $counters['albumhit'] . ', ' . 'Album misses: ' . $counters['albummis'] . ', ' . 'Photo hits: ' . $counters['photohit'] . ', ' . 'Photo misses: ' . $counters['photomis'] . '.'); } break; default: wppa_log('err', 'Illegal $what in wppa_dbg_cachecounts(): ' . $what); } } }
function wppa_get_thumb_masonry($id) { global $wpdb; // Init if (!$id) { wppa_dbg_msg('Please check file wppa-theme.php or any other php file that calls wppa_thumb_masonry(). Argument 1: photo id is missing!', 'red', 'force'); die('Please check your configuration'); } $result = ''; $cont_width = wppa_get_container_width(); $count_cols = ceil($cont_width / wppa_opt('thumbsize')); // Get the photo info $thumb = wppa_cache_thumb($id); // Get the album info $album = wppa_cache_album($thumb['album']); // Get photo info $is_video = wppa_is_video($id); $has_audio = wppa_has_audio($id); $imgsrc = wppa_fix_poster_ext(wppa_get_thumb_path($id), $id); if (!wppa_is_video($id) && !is_file($imgsrc)) { $result .= '<div' . ' class=""' . ' style="' . 'font-size:10px;' . 'color:red;' . 'width:' . wppa_opt('thumbsize') . 'px;' . 'position:static;' . 'float:left;' . '"' . ' >' . sprintf(__('Missing thumbnail image #%s', 'wp-photo-album-plus'), $id) . '</div>'; return $result; } $alt = $album['alt_thumbsize'] == 'yes' ? '_alt' : ''; $imgattr_a = wppa_get_imgstyle_a($id, $imgsrc, wppa_opt('thumbsize' . $alt), 'optional', 'thumb'); // Verical style ? if (wppa_opt('thumbtype') == 'masonry-v') { $imgwidth = wppa_opt('thumbsize'); $imgheight = $imgwidth * wppa_get_thumbratioyx($id); $imgstyle = 'width:100%; height:auto; margin:0; position:relative; box-sizing:border-box;'; $frame_h = ''; } else { $imgheight = wppa_opt('thumbsize'); $imgwidth = $imgheight * wppa_get_thumbratioxy($id); $imgstyle = 'height:100%;' . 'width:auto;' . 'margin:0;' . 'position:relative;' . 'box-sizing:border-box;' . ''; $frame_h = 'height:100%; '; } // Mouseover effect? if (wppa_switch('use_thumb_opacity')) { $opac = wppa_opt('thumb_opacity'); $imgstyle .= ' opacity:' . $opac / 100 . '; filter:alpha( opacity=' . $opac . ' );'; } // Padding if (wppa_is_int(wppa_opt('tn_margin') / 2)) { $imgstyle .= ' padding:' . wppa_opt('tn_margin') / 2 . 'px;'; } else { $p1 = floor(wppa_opt('tn_margin') / 2); $p2 = ceil(wppa_opt('tn_margin') / 2); $imgstyle .= ' padding:' . $p1 . 'px ' . $p2 . 'px ' . $p2 . 'px ' . $p1 . 'px;'; } // Cursor $cursor = $imgattr_a['cursor']; // Popup ? if (wppa_switch('use_thumb_popup')) { // Landscape? if ($imgwidth > $imgheight) { $popwidth = wppa_opt('popupsize'); $popheight = round($popwidth * $imgheight / $imgwidth); } else { $popheight = wppa_opt('popupsize'); $popwidth = round($popheight * $imgwidth / $imgheight); } } else { $popwidth = $imgwidth; $popheight = $imgheight; } $imgurl = wppa_fix_poster_ext(wppa_get_thumb_url($id, '', $popwidth, $popheight), $id); $events = wppa_get_imgevents('thumb', $id); $imgalt = wppa_get_imgalt($id); // returns something like ' alt="Any text" ' $title = esc_attr(wppa_get_masonry_title($id)); // esc_attr( wppa_get_photo_name( $id ) ); // Feed ? if (is_feed()) { $imgattr_a = wppa_get_imgstyle_a($id, $imgsrc, '100', '4', 'thumb'); $style = $imgattr_a['style']; $result .= '<a href="' . get_permalink() . '">' . '<img' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' style="' . $style . '"' . ' />' . '</a>'; return; } // Get the image link if (wppa('is_topten')) { $no_album = !wppa('start_album'); if ($no_album) { $tit = __('View the top rated photos', 'wp-photo-album-plus'); } else { $tit = esc_attr(__(stripslashes($thumb['description']))); } $link = wppa_get_imglnk_a('thumb', $id, '', $tit, '', $no_album); } else { $link = wppa_get_imglnk_a('thumb', $id); } // voor parent uplr // Open the thumbframe // Add class wppa-mas-h-{mocc} for ie if horizontal $is_ie_or_chrome = strpos($_SERVER["HTTP_USER_AGENT"], 'Trident') || strpos($_SERVER["HTTP_USER_AGENT"], 'Chrome'); $result .= ' <div' . ' id="thumbnail_frame_masonry_' . $id . '_' . wppa('mocc') . '"' . ($is_ie_or_chrome && wppa_opt('thumbtype') == 'masonry-h' ? ' class="wppa-mas-h-' . wppa('mocc') . '"' : '') . ' style="' . $frame_h . 'position:static;' . 'float:left;' . 'font-size:12px;' . 'line-height:8px;' . 'overflow:hidden;' . 'box-sizing:content-box;' . '" >'; // The medals $result .= wppa_get_medal_html_a(array('id' => $id, 'size' => 'M', 'where' => 'top')); // See if ajax possible if ($link) { if ($link['is_url']) { // is url if (wppa_switch('allow_ajax') && wppa_opt('thumb_linktype') == 'photo' && wppa_opt('thumb_linkpage') == '0' && !wppa_switch('thumb_blank') && !(wppa_switch('thumb_overrule') && $thumb['linkurl']) && !wppa('is_topten') && !wppa('is_lasten') && !wppa('is_comten') && !wppa('is_featen') && !wppa('is_tag') && !wppa('is_upldr') && !wppa('src') && !wppa('supersearch') && (wppa_is_int(wppa('start_album')) || wppa('start_album') == '')) { // Ajax possible // The a img ajax $p = wppa('calendar') ? '' : '&wppa-photo=' . $id; $onclick = 'wppaDoAjaxRender( ' . wppa('mocc') . ', \'' . wppa_get_slideshow_url_ajax(wppa('start_album'), '0') . '&wppa-photo=' . $id . '\', \'' . wppa_convert_to_pretty(wppa_get_slideshow_url(wppa('start_album'), '0') . $p) . '\' )'; // old $onclick = "wppaDoAjaxRender( ".wppa( 'mocc' ).", '".wppa_get_slideshow_url_ajax( wppa( 'start_album' ), '0' ).'&wppa-photo='.$id."', '".wppa_convert_to_pretty( wppa_get_slideshow_url( wppa( 'start_album' ), '0' )."&wppa-photo=".$id )."' )"; $result .= '<a style="position:static;" class="thumb-img" id="x-' . $id . '-' . wppa('mocc') . '">'; if ($is_video) { // $result .= '<video preload="metadata" onclick="'.$onclick.'" id="i-'.$id.'-'.wppa( 'mocc' ).'" '.$imgalt.' title="'.$title.'" style="'.$imgstyle.' cursor:pointer;" '.$events.' >'.wppa_get_video_body( $id ).'</video>'; $result .= wppa_get_video_html(array('id' => $id, 'controls' => false, 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $id . '-' . wppa('mocc'), 'cursor' => 'cursor:pointer;', 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => $onclick, 'lb' => false, 'class' => '', 'style' => $imgstyle, 'use_thumb' => true)); } else { $result .= '<img' . ' onclick="' . $onclick . '"' . ' id="i-' . $id . '-' . wppa('mocc') . '"' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' style="' . $imgstyle . ' cursor:pointer;"' . ' ' . $events . ' />'; } $result .= '</a>'; } else { // non ajax // The a img non ajax $result .= '<a style="position:static;" href="' . $link['url'] . '" target="' . $link['target'] . '" class="thumb-img" id="x-' . $id . '-' . wppa('mocc') . '">'; if ($is_video) { // $result .= '<video preload="metadata" id="i-'.$id.'-'.wppa( 'mocc' ).'" '.$imgalt.' title="'.$title.'" width="'.$imgwidth.'" height="'.$imgheight.'" style="'.$imgstyle.' cursor:pointer;" '.$events.' >'.wppa_get_video_body( $id ).'</video>'; $result .= wppa_get_video_html(array('id' => $id, 'controls' => false, 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $id . '-' . wppa('mocc'), 'cursor' => 'cursor:pointer;', 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => $imgstyle, 'use_thumb' => true)); } else { $result .= '<img' . ' id="i-' . $id . '-' . wppa('mocc') . '"' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' style="' . $imgstyle . 'cursor:pointer;"' . ' ' . $events . ' />'; } $result .= '</a>'; } } elseif ($link['is_lightbox']) { // The a img $title = wppa_get_lbtitle('thumb', $id); $result .= '<a href="' . $link['url'] . '"' . ' target="' . $link['target'] . '"' . ($is_video ? ' data-videohtml="' . esc_attr(wppa_get_video_body($id)) . '"' . ' data-videonatwidth="' . wppa_get_videox($id) . '"' . ' data-videonatheight="' . wppa_get_videoy($id) . '"' : '') . ($has_audio ? ' data-audiohtml="' . esc_attr(wppa_get_audio_body($id)) . '"' : '') . ' ' . wppa('rel') . '="' . wppa_opt('lightbox_name') . '[occ' . wppa('mocc') . ']"' . ($title ? ' ' . wppa('lbtitle') . '="' . $title . '"' : '') . ' class="thumb-img"' . ' id="x-' . $id . '-' . wppa('mocc') . '">'; // The image $title = wppa_zoom_in($id); // Video? if ($is_video) { $result .= wppa_get_video_html(array('id' => $id, 'controls' => false, 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $id . '-' . wppa('mocc'), 'cursor' => $cursor, 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => $imgstyle, 'use_thumb' => true)); } else { $result .= '<img' . ' id="i-' . $id . '-' . wppa('mocc') . '"' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' style="' . $imgstyle . $cursor . '"' . ' ' . $events . ' />'; } $result .= '</a>'; } else { // The div img $result .= '<div onclick="' . $link['url'] . '" class="thumb-img" id="x-' . $id . '-' . wppa('mocc') . '" style="height:100%;" >'; // Video? if ($is_video) { $result .= wppa_get_video_html(array('id' => $id, 'controls' => false, 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $id . '-' . wppa('mocc'), 'cursor' => 'cursor:pointer;', 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => $imgstyle, 'use_thumb' => true)); } else { $result .= '<img' . ' id="i-' . $id . '-' . wppa('mocc') . '"' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' style="' . $imgstyle . 'cursor:pointer;"' . ' ' . $events . ' />'; } $result .= '</div>'; $result .= '<script type="text/javascript">'; $result .= '/* <![CDATA[ */'; $result .= 'wppaPopupOnclick[' . $id . '] = "' . $link['url'] . '";'; $result .= '/* ]]> */'; $result .= '</script>'; } } else { // no link if (wppa_switch('use_thumb_popup')) { $result .= '<div id="x-' . $id . '-' . wppa('mocc') . '" style="height:100%" >'; if ($is_video) { $result .= wppa_get_video_html(array('id' => $id, 'controls' => false, 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $id . '-' . wppa('mocc'), 'cursor' => '', 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => $imgstyle, 'use_thumb' => true)); } else { $result .= '<img' . ' id="i-' . $id . '-' . wppa('mocc') . '"' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' width="' . $imgwidth . '"' . ' height="' . $imgheight . '"' . ' style="' . $imgstyle . '"' . ' ' . $events . ' />'; } $result .= '</div>'; } else { if ($is_video) { // $result .= '<video preload="metadata" '.$imgalt.' title="'.$title.'" width="'.$imgwidth.'" height="'.$imgheight.'" style="'.$imgstyle.'" '.$events.' >'.wppa_get_video_body( $id ).'</video>'; $result .= wppa_get_video_html(array('id' => $id, 'controls' => false, 'margin_top' => '0', 'margin_bottom' => '0', 'tagid' => 'i-' . $id . '-' . wppa('mocc'), 'cursor' => '', 'events' => $events, 'title' => $title, 'preload' => 'metadata', 'onclick' => '', 'lb' => false, 'class' => '', 'style' => $imgstyle, 'use_thumb' => true)); } else { $result .= '<img' . ' id="i-' . $id . '-' . wppa('mocc') . '"' . ' src="' . $imgurl . '"' . ' ' . $imgalt . ($title ? ' title="' . $title . '"' : '') . ' width="' . $imgwidth . '"' . ' height="' . $imgheight . '"' . ' style="' . $imgstyle . '" ' . $events . ' />'; } } } // The audio when no popup if (wppa_switch('thumb_audio') && wppa_has_audio($id)) { $result .= '<div style="position:relative;z-index:11;">'; // $is_safari = strpos( $_SERVER["HTTP_USER_AGENT"], 'Safari' ); // $cont_h = $is_safari ? 16 : 28; // $audiotop = $imgattr_a['height'] + $imgattr_a['margin-top'] - $cont_h; // if ( ! is_file( $imgsrc ) ) { // Audio without image // $audiotop = wppa_get_audio_control_height(); // $imgwidth = wppa_opt( 'tf_width' ); // $imgheight = wppa_get_audio_control_height(); // } $result .= wppa_get_audio_html(array('id' => $id, 'tagid' => 'a-' . $id . '-' . wppa('mocc'), 'style' => 'width:100%;position:absolute;bottom:0;margin:0;padding:' . wppa_opt('tn_margin') / 2 . 'px;left:0;border:none;z-index:10;')); $result .= '</div>'; } // The medals $result .= wppa_get_medal_html_a(array('id' => $id, 'size' => 'M', 'where' => 'bot')); // Close the thumbframe $result .= '</div>'; return $result; }
function wppa_user_albumedit_html($alb, $width, $where = '', $mcr = false) { $album = wppa_cache_album($alb); if (!wppa_switch('user_album_edit_on')) { return; } // Feature not enabled if (!$alb) { return; } // No album given if (!wppa_have_access($alb)) { return; } // No rights if (!is_user_logged_in()) { return; } // Must login if ($album['owner'] == '--- public ---' && !current_user_can('wppa_admin')) { return; } // Public albums are not publicly editable $t = $mcr ? 'mcr-' : ''; // Create the return url $returnurl = wppa_get_permalink(); if ($where == 'cover') { $returnurl .= 'wppa-album=' . $alb . '&wppa-cover=1&wppa-occur=' . wppa('occur'); } elseif ($where == 'thumb') { $returnurl .= 'wppa-album=' . $alb . '&wppa-cover=0&wppa-occur=' . wppa('occur'); } elseif ($where == 'widget' || $where == 'uploadbox') { } if (wppa('page')) { $returnurl .= '&wppa-page=' . wppa('page'); } $returnurl = trim($returnurl, '?'); $result = ' <div style="clear:both;"></div> <a id="wppa-ea-' . $alb . '-' . wppa('mocc') . '" class="wppa-aedit-' . $where . '" onclick="' . 'jQuery( \'#wppa-fe-div-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-ea-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-up-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cats-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#_wppa-ea-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'block\' );' . '_wppaDoAutocol( ' . wppa('mocc') . ' )' . '" style="float:left; cursor:pointer;"> ' . __('Edit albuminfo', 'wp-photo-album-plus') . ' </a> <a id="_wppa-ea-' . $alb . '-' . wppa('mocc') . '" class="wppa-aedit-' . $where . '" onclick="' . 'jQuery( \'#wppa-fe-div-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-ea-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-cats-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#_wppa-ea-' . $alb . '-' . wppa('mocc') . '\' ).css( \'display\',\'none\' );' . '_wppaDoAutocol( ' . wppa('mocc') . ' )' . '" style="float:right; cursor:pointer;display:none;"> ' . __(wppa_opt('close_text'), 'wp-photo-album-plus') . '</a>'; // Get name and description, if possible multilanguage editable. ( if qTranslate-x content filter not active ) $name = stripslashes($album['name']); $desc = stripslashes($album['description']); // qTranslate(-x) not active or not properly closed tag? if (substr($name, -3) != '[:]') { $name = __($name); } // qTranslate(-x) not active or not properly closed tag? if (substr($desc, -3) != '[:]') { $desc = __($desc); } // Escape $name = esc_attr($name); $desc = esc_textarea($desc); $result .= '<div id="wppa-fe-div-' . $alb . '-' . wppa('mocc') . '" style="display:none;" > <form action="' . $returnurl . '" method="post"> <input' . ' type="hidden"' . ' name="wppa-albumeditnonce"' . ' id="album-nonce-' . wppa('mocc') . '-' . $alb . '"' . ' value="' . wp_create_nonce('wppa_nonce_' . $alb) . '"' . ' /> <input' . ' type="hidden"' . ' name="wppa-albumeditid"' . ' id="wppaalbum-id-' . wppa('mocc') . '-' . $alb . '"' . ' value="' . $alb . '"' . ' /> <div' . ' class="wppa-box-text wppa-td"' . ' style="' . 'clear:both;' . 'float:left;' . 'text-align:left;' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Enter album name', 'wp-photo-album-plus') . ' ' . '<span style="font-size:10px;" >' . __('Don\'t leave this blank!', 'wp-photo-album-plus') . '</span> </div> <input' . ' name="wppa-albumeditname"' . ' id="wppaalbum-name-' . wppa('mocc') . '-' . $alb . '"' . ' class="wppa-box-text wppa-file-' . $t . wppa('mocc') . '"' . ' value="' . $name . '"' . ' style="padding:0; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '"' . ' /> <div' . ' class="wppa-box-text wppa-td"' . ' style="' . 'clear:both;' . 'float:left;' . 'text-align:left;' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Album description:', 'wp-photo-album-plus') . ' </div> <textarea' . ' name="wppa-albumeditdesc"' . ' id="wppaalbum-desc-' . wppa('mocc') . '-' . $alb . '"' . ' class="wppa-user-textarea wppa-box-text wppa-file-' . $t . wppa('mocc') . '"' . ' style="' . 'padding:0;' . 'height:120px;' . 'width:' . ($width - 6) . 'px;' . __wcs('wppa-box-text') . '"' . ' >' . $desc . '</textarea>' . '<input' . ' type="submit"' . ' name="wppa-albumeditsubmit"' . ' class="wppa-user-submit"' . ' style="margin: 6px 0; float:right; ' . __wcs('wppa-box-text') . '"' . ' value="' . __('Update album', 'wp-photo-album-plus') . '"' . ' /> </form> </div>'; wppa_out($result); }
function wppa_get_album_item($id, $item) { $album = wppa_cache_album($id); if ($album) { if (isset($album[$item])) { return trim($album[$item]); } else { wppa_dbg_msg('Album item ' . $item . ' does not exist. ( get_album_item )', 'red'); } } else { wppa_dbg_msg('Album ' . $id . ' does not exist. ( get_album_item )', 'red'); } return false; }
function wppa_user_albumedit_html($alb, $width, $where = '', $mcr = false) { global $wppa; $album = wppa_cache_album($alb); if (!wppa_switch('user_album_edit_on')) { return; } // Feature not enabled if (!$alb) { return; } // No album given if (!wppa_have_access($alb)) { return; } // No rights if ($album['owner'] == '--- public ---' && !current_user_can('wppa_admin')) { return; } // Public albums are not publicly editable $t = $mcr ? 'mcr-' : ''; // Create the return url $returnurl = wppa_get_permalink(); if ($where == 'cover') { $returnurl .= 'wppa-album=' . $alb . '&wppa-cover=1&wppa-occur=' . $wppa['occur']; } elseif ($where == 'thumb') { $returnurl .= 'wppa-album=' . $alb . '&wppa-cover=0&wppa-occur=' . $wppa['occur']; } elseif ($where == 'widget' || $where == 'uploadbox') { } if ($wppa['page']) { $returnurl .= '&wppa-page=' . $wppa['page']; } $returnurl = trim($returnurl, '?'); $result = ' <div style="clear:both;"></div> <a id="wppa-ea-' . $alb . '-' . $wppa['mocc'] . '" class="wppa-aedit-' . $where . '" onclick="' . 'jQuery( \'#wppa-fe-div-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-ea-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-up-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cats-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#_wppa-ea-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'block\' );' . '_wppaDoAutocol( ' . $wppa['mocc'] . ' )' . '" style="float:left; cursor:pointer;"> ' . __a('Edit albuminfo') . ' </a> <a id="_wppa-ea-' . $alb . '-' . $wppa['mocc'] . '" class="wppa-aedit-' . $where . '" onclick="' . 'jQuery( \'#wppa-fe-div-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-ea-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-cats-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#_wppa-ea-' . $alb . '-' . $wppa['mocc'] . '\' ).css( \'display\',\'none\' );' . '_wppaDoAutocol( ' . $wppa['mocc'] . ' )' . '" style="float:right; cursor:pointer;display:none;"> ' . __a('Close') . ' </a> <div id="wppa-fe-div-' . $alb . '-' . $wppa['mocc'] . '" style="display:none;" > <form action="' . $returnurl . '" method="post"> <input type="hidden" name="wppa-albumeditnonce" id="album-nonce-' . $wppa['mocc'] . '-' . $alb . '" value="' . wp_create_nonce('wppa_nonce_' . $alb) . '" /> <input type="hidden" name="wppa-albumeditid" id="wppaalbum-id-' . $wppa['mocc'] . '-' . $alb . '" value="' . $alb . '" /> <div class="wppa-box-text wppa-td" style="clear:both; float:left; text-align:left; ' . __wcs('wppa-box-text') . __wcs('wppa-td') . '" >' . __a('Enter album name.') . ' <span style="font-size:10px;" >' . __a('Don\'t leave this blank!') . '</span> </div> <input name="wppa-albumeditname" id="wppaalbum-name-' . $wppa['mocc'] . '-' . $alb . '" class="wppa-box-text wppa-file-' . $t . $wppa['mocc'] . '" value="' . esc_attr(stripslashes($album['name'])) . '" style="padding:0; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '" /> <div class="wppa-box-text wppa-td" style="clear:both; float:left; text-align:left; ' . __wcs('wppa-box-text') . __wcs('wppa-td') . '" >' . __a('Album description:') . ' </div> <textarea name="wppa-albumeditdesc" id="wppaalbum-desc-' . $wppa['mocc'] . '-' . $alb . '" class="wppa-user-textarea wppa-box-text wppa-file-' . $t . $wppa['mocc'] . '" style="padding:0;height:120px; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '" >' . esc_textarea(stripslashes($album['description'])) . '</textarea> <input type="submit" name="wppa-albumeditsubmit" class="wppa-user-submit" style="margin: 6px 0; float:right; ' . __wcs('wppa-box-text') . '" value="' . __a('Update album') . '" /> </form> </div>'; $wppa['out'] .= $result; }