function wppa_user_upload() { global $wpdb; static $done; wppa_dbg_msg('Usr_upl entered'); if ($done) { return; } // Already done $done = true; // Mark as done // Upload possible? $may_upload = wppa_switch('user_upload_on'); if (wppa_switch('user_upload_login')) { if (!is_user_logged_in()) { $may_upload = false; } // Must login } // Create album possible? $may_create = wppa_switch('user_create_on'); if (wppa_switch('user_create_login')) { if (!is_user_logged_in()) { $may_create = false; } // Must login } // Edit album possible? $may_edit = wppa_switch('user_album_edit_on'); // Do create if ($may_create) { if (wppa_get_post('wppa-fe-create')) { // Create album $nonce = wppa_get_post('nonce'); if (wppa_get_post('wppa-album-name')) { $albumname = trim(strip_tags(wppa_get_post('wppa-album-name'))); } if (!wppa_sanitize_file_name($albumname)) { $albumname = __('New Album', 'wp-photo-album-plus'); } $ok = wp_verify_nonce($nonce, 'wppa-album-check'); if (!$ok) { die('<b>' . __('ERROR: Illegal attempt to create an album.', 'wp-photo-album-plus') . '</b>'); } // Check captcha $captkey = wppa_get_randseed('session'); if (!wppa_check_captcha($captkey)) { wppa_alert(__('Wrong captcha, please try again', 'wp-photo-album-plus')); return; } $parent = strval(intval(wppa_get_post('wppa-album-parent'))); if (!wppa_user_is('administrator') && wppa_switch('default_parent_always')) { $parent = wppa_opt('default_parent'); } $album = wppa_create_album_entry(array('name' => $albumname, 'description' => strip_tags(wppa_get_post('wppa-album-desc')), 'a_parent' => $parent, 'owner' => wppa_switch('frontend_album_public') ? '--- public ---' : wppa_get_user())); if ($album) { wppa_alert(sprintf(__('Album #%s created', 'wp-photo-album-plus'), $album)); wppa_flush_treecounts($parent); wppa_create_pl_htaccess(); } else { wppa_alert(__('Could not create album', 'wp-photo-album-plus')); } } } // Do Upload if ($may_upload) { if (wppa_get_post('wppa-upload-album')) { // Upload photo $nonce = wppa_get_post('nonce'); $ok = wp_verify_nonce($nonce, 'wppa-check'); if (!$ok) { die('<b>' . __('ERROR: Illegal attempt to upload a file.', 'wp-photo-album-plus') . '</b>'); } //print_r($_POST); $alb = wppa_get_post('wppa-upload-album'); if (is_array($_FILES)) { $bret = true; $filecount = '1'; $done = '0'; $fail = '0'; foreach ($_FILES as $file) { if (!is_array($file['error'])) { $bret = wppa_do_frontend_file_upload($file, $alb); // this should no longer happen since the name is incl [] if ($bret) { $done++; } else { $fail++; } } else { $filecount = count($file['error']); for ($i = '0'; $i < $filecount; $i++) { if ($bret) { $f['error'] = $file['error'][$i]; $f['tmp_name'] = $file['tmp_name'][$i]; $f['name'] = $file['name'][$i]; $f['type'] = $file['type'][$i]; $f['size'] = $file['size'][$i]; $bret = wppa_do_frontend_file_upload($f, $alb); if ($bret) { $done++; } else { $fail++; } } } } } $points = '0'; $alert = ''; if ($done) { //SUCCESSFUL UPLOAD, ADD POINTS $points = wppa_opt('cp_points_upload') * $done; $bret = wppa_add_credit_points($points, __('Photo upload', 'wp-photo-album-plus')); $alert .= sprintf(_n('Photo successfully uploaded.', '%s photos successfully uploaded.', $done, 'wp-photo-album-plus'), $done); if ($bret) { $alert .= ' ' . sprintf(__('%s points added.', 'wp-photo-album-plus'), $points); } } if ($fail) { if (!$done) { $alert .= __('Upload failed', 'wp-photo-album-plus'); } else { $alert .= sprintf(_n('1 Upload failed', '%s uploads failed.', $fail, 'wp-photo-album-plus'), $fail); } } $reload = wppa_switch('home_after_upload') && $done ? 'home' : false; wppa_alert($alert, $reload); } } } // Do Edit if ($may_edit) { if (wppa_get_post('wppa-albumeditsubmit')) { $alb = wppa_get_post('wppa-albumeditid'); $name = wppa_get_post('wppa-albumeditname'); $name = trim(strip_tags($name)); if (!wppa_sanitize_file_name($name)) { // Empty album name is not allowed $name = 'Album-#' . $alb; } $description = wppa_get_post('wppa-albumeditdesc'); if (!wp_verify_nonce(wppa_get_post('wppa-albumeditnonce'), 'wppa_nonce_' . $alb)) { die('Security check failure'); } wppa_update_album(array('id' => $alb, 'name' => $name, 'description' => $description, 'modified' => time())); wppa_create_pl_htaccess(); } } }
function wppa_get_photo_order($id = '0', $no_random = false) { global $wpdb; global $wppa; if ($id == '0') { $order = '0'; } else { $order = $wpdb->get_var($wpdb->prepare("SELECT `p_order_by` FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $id)); wppa_dbg_q('Q201'); } if (!$order) { $order = wppa_opt('wppa_list_photos_by'); } switch ($order) { case '': case '0': $result = ''; break; case '1': $result = 'ORDER BY p_order'; break; case '-1': $result = 'ORDER BY p_order DESC'; break; case '2': $result = 'ORDER BY name'; break; case '-2': $result = 'ORDER BY name DESC'; break; case '3': if ($no_random) { $result = 'ORDER BY name'; } else { $result = 'ORDER BY RAND( ' . wppa_get_randseed() . ' )'; } break; case '-3': if ($no_random) { $result = 'ORDER BY name DESC'; } else { $result = 'ORDER BY RAND( ' . wppa_get_randseed() . ' ) DESC'; } break; case '4': $result = 'ORDER BY mean_rating'; break; case '-4': $result = 'ORDER BY mean_rating DESC'; break; case '5': $result = 'ORDER BY timestamp'; break; case '-5': $result = 'ORDER BY timestamp DESC'; break; case '6': $result = 'ORDER BY rating_count'; break; case '-6': $result = 'ORDER BY rating_count DESC'; break; case '7': $result = 'ORDER BY exifdtm'; break; case '-7': $result = 'ORDER BY exifdtm DESC'; break; default: wppa_dbg_msg('Unimplemented photo order: ' . $order, 'red'); $result = ''; } return $result; }
function wppa_user_upload() { global $wpdb; static $done; wppa_dbg_msg('Usr_upl entered'); if ($done) { return; } // Already done $done = true; // Mark as done // Upload possible? $may_upload = wppa_switch('user_upload_on'); if (wppa_switch('user_upload_login')) { if (!is_user_logged_in()) { $may_upload = false; } // Must login } // Create album possible? $may_create = wppa_switch('user_create_on'); if (wppa_switch('user_create_login')) { if (!is_user_logged_in()) { $may_create = false; } // Must login } // Edit album possible? $may_edit = wppa_switch('user_album_edit_on'); // Do create if ($may_create) { if (wppa_get_post('wppa-fe-create')) { // Create album $nonce = wppa_get_post('nonce'); if (wppa_get_post('wppa-album-name')) { $albumname = trim(strip_tags(wppa_get_post('wppa-album-name'))); } if (!wppa_sanitize_file_name($albumname)) { $albumname = __('New Album', 'wp-photo-album-plus'); } $ok = wp_verify_nonce($nonce, 'wppa-album-check'); if (!$ok) { die('<b>' . __('ERROR: Illegal attempt to create an album.', 'wp-photo-album-plus') . '</b>'); } // Check captcha if (wppa_switch('user_create_captcha')) { $captkey = wppa_get_randseed('session'); if (!wppa_check_captcha($captkey)) { wppa_alert(__('Wrong captcha, please try again', 'wp-photo-album-plus')); return; } } $parent = strval(intval(wppa_get_post('wppa-album-parent'))); if (!wppa_user_is('administrator') && wppa_switch('default_parent_always')) { $parent = wppa_opt('default_parent'); } $album = wppa_create_album_entry(array('name' => $albumname, 'description' => strip_tags(wppa_get_post('wppa-album-desc')), 'a_parent' => $parent, 'owner' => wppa_switch('frontend_album_public') ? '--- public ---' : wppa_get_user())); if ($album) { if (wppa_switch('fe_alert')) { wppa_alert(sprintf(__('Album #%s created', 'wp-photo-album-plus'), $album)); } wppa_flush_treecounts($parent); wppa_create_pl_htaccess(); } else { wppa_alert(__('Could not create album', 'wp-photo-album-plus')); } } } // Do Upload if ($may_upload) { $blogged = false; if (wppa_get_post('wppa-upload-album')) { // Upload photo $nonce = wppa_get_post('nonce'); $ok = wp_verify_nonce($nonce, 'wppa-check'); if (!$ok) { die('<b>' . __('ERROR: Illegal attempt to upload a file.', 'wp-photo-album-plus') . '</b>'); } $alb = wppa_get_post('wppa-upload-album'); $alb = strval(intval($alb)); // Force numeric if (!wppa_album_exists($alb)) { $alert = sprintf(__('Album %s does not exist', 'wp-photo-album-plus'), $alb); wppa_alert($alert); return; } $uploaded_ids = array(); if (is_array($_FILES)) { $iret = true; $filecount = '1'; $done = '0'; $fail = '0'; foreach ($_FILES as $file) { if (!is_array($file['error'])) { $iret = wppa_do_frontend_file_upload($file, $alb); // this should no longer happen since the name is incl [] if ($iret) { $uploaded_ids[] = $iret; $done++; wppa_set_last_album($alb); } else { $fail++; } } else { $filecount = count($file['error']); for ($i = '0'; $i < $filecount; $i++) { if ($iret) { $f['error'] = $file['error'][$i]; $f['tmp_name'] = $file['tmp_name'][$i]; $f['name'] = $file['name'][$i]; $f['type'] = $file['type'][$i]; $f['size'] = $file['size'][$i]; $iret = wppa_do_frontend_file_upload($f, $alb); if ($iret) { $uploaded_ids[] = $iret; $done++; wppa_set_last_album($alb); } else { $fail++; } } } } } $points = '0'; $alert = ''; $reload = wppa_switch('home_after_upload') && $done ? 'home' : false; if ($done) { // SUCCESSFUL UPLOAD, Blog It? if (current_user_can('edit_posts') && isset($_POST['wppa-blogit'])) { $title = $_POST['wppa-post-title']; if (!$title) { $title = wppa_local_date(); } $pretxt = $_POST['wppa-blogit-pretext']; $posttxt = $_POST['wppa-blogit-posttext']; $status = wppa_switch('blog_it_moderate') ? 'pending' : 'publish'; $post_content = $pretxt; foreach ($uploaded_ids as $id) { $post_content .= str_replace('#id', $id, wppa_opt('blog_it_shortcode')); } $post_content .= $posttxt; $post = array('post_title' => $title, 'post_content' => $post_content, 'post_status' => $status); $post = sanitize_post($post, 'db'); $iret = wp_insert_post($post); $blogged = true; } // ADD POINTS $points = wppa_opt('cp_points_upload') * $done; $bret = wppa_add_credit_points($points, __('Photo upload', 'wp-photo-album-plus')); $alert .= sprintf(_n('%d photo successfully uploaded', '%d photos successfully uploaded', $done, 'wp-photo-album-plus'), $done); if ($bret) { $alert .= ' ' . sprintf(__('%s points added', 'wp-photo-album-plus'), $points); } if (wppa_switch('fe_alert')) { wppa_alert($alert, $reload); } else { wppa_alert('', $reload); } // Blogged? if ($blogged) { if (wppa_switch('fe_alert')) { if ($status == 'pending') { wppa_alert(__('Your post is awaiting moderation.', 'wp-photo-album-plus')); } } echo '<script type="text/javascript" >document.location.href=\'' . home_url() . '\';</script>'; wppa_exit(); } } if ($fail) { if (!$done) { $alert .= __('Upload failed', 'wp-photo-album-plus'); } else { $alert .= sprintf(_n('%d upload failed', '%d uploads failed', $fail, 'wp-photo-album-plus'), $fail); } wppa_alert($alert, $reload); } } } } // Do Edit if ($may_edit) { if (wppa_get_post('wppa-albumeditsubmit')) { // Get album id $alb = wppa_get_post('wppa-albumeditid'); if (!$alb || !wppa_album_exists($alb)) { die('Security check failure'); } // Valid request? if (!wp_verify_nonce(wppa_get_post('wppa-albumeditnonce'), 'wppa_nonce_' . $alb)) { die('Security check failure'); } // Name $name = wppa_get_post('wppa-albumeditname'); $name = trim(strip_tags($name)); if (!$name) { // Empty album name is not allowed $name = 'Album-#' . $alb; } // Description $description = wppa_get_post('wppa-albumeditdesc'); // Custom data $custom = wppa_get_album_item($alb, 'custom'); if ($custom) { $custom_data = unserialize($custom); } else { $custom_data = array('', '', '', '', '', '', '', '', '', ''); } $idx = '0'; while ($idx < '10') { if (isset($_POST['custom_' . $idx])) { $value = wppa_get_post('custom_' . $idx); $custom_data[$idx] = wppa_sanitize_custom_field($value); } $idx++; } $custom = serialize($custom_data); // Update wppa_update_album(array('id' => $alb, 'name' => $name, 'description' => $description, 'custom' => $custom, 'modified' => time())); wppa_index_update('album', $alb); wppa_create_pl_htaccess(); } } }
/** @see WP_Widget::widget */ function widget($args, $instance) { global $wpdb; global $wppa_opt; global $wppa; require_once dirname(__FILE__) . '/wppa-links.php'; require_once dirname(__FILE__) . '/wppa-styles.php'; require_once dirname(__FILE__) . '/wppa-functions.php'; require_once dirname(__FILE__) . '/wppa-thumbnails.php'; require_once dirname(__FILE__) . '/wppa-boxes-html.php'; require_once dirname(__FILE__) . '/wppa-slideshow.php'; wppa_initialize_runtime(); extract($args); $instance = wp_parse_args((array) $instance, array('title' => '', 'album' => '')); $widget_title = apply_filters('widget_title', $instance['title']); $page = in_array($wppa_opt['wppa_featen_widget_linktype'], $wppa['links_no_page']) ? '' : wppa_get_the_landing_page('wppa_featen_widget_linkpage', __a('Featured photos')); $max = $wppa_opt['wppa_featen_count']; $album = $instance['album']; $generic = $album == '-2'; if ($generic) { $album = '0'; $max += '1000'; } if ($album) { $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status`= 'featured' AND `album` = %s ORDER BY RAND(" . wppa_get_randseed() . ") DESC LIMIT " . $max, $album), ARRAY_A); } else { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'featured' ORDER BY RAND(" . wppa_get_randseed() . ") DESC LIMIT " . $max, ARRAY_A); } $widget_content = "\n" . '<!-- WPPA+ FeaTen Widget start -->'; $maxw = $wppa_opt['wppa_featen_size']; $maxh = $maxw; $lineheight = $wppa_opt['wppa_fontsize_widget_thumb'] * 1.5; $maxh += $lineheight; if (false) { $maxh += $lineheight; } $count = '0'; if ($thumbs) { foreach ($thumbs as $image) { global $thumb; $thumb = $image; if ($generic && wppa_is_separate($thumb['album'])) { continue; } // Make the HTML for current picture $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">'; if ($image) { $no_album = !$album; if ($no_album) { $tit = __a('View the featured photos', 'wppa_theme'); } else { $tit = esc_attr(wppa_qtrans(stripslashes($image['description']))); } $link = wppa_get_imglnk_a('featen', $image['id'], '', $tit, '', $no_album); $file = wppa_get_thumb_path($image['id']); $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'ttthumb'); $imgstyle = $imgstyle_a['style']; $width = $imgstyle_a['width']; $height = $imgstyle_a['height']; $cursor = $imgstyle_a['cursor']; $imgurl = wppa_get_thumb_url($image['id'], '', $width, $height); $imgevents = wppa_get_imgevents('thumb', $image['id'], true); if ($link) { $title = esc_attr(stripslashes($link['title'])); } else { $title = ''; } $album = '0'; $display = 'thumbs'; $widget_content .= wppa_get_the_widget_thumb('featen', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents); } else { // No image $widget_content .= __a('Photo not found.', 'wppa_theme'); } $widget_content .= "\n" . '</div>'; $count++; if ($count == $wppa_opt['wppa_featen_count']) { break; } } } else { $widget_content .= 'There are no featured photos (yet).'; } $widget_content .= '<div style="clear:both"></div>'; $widget_content .= "\n" . '<!-- WPPA+ FeaTen Widget end -->'; echo "\n" . $before_widget; if (!empty($widget_title)) { echo $before_title . $widget_title . $after_title; } echo $widget_content . $after_widget; }
function wppa_get_user_create_html($alb, $width, $where = '', $mcr = false) { // Init $result = ''; $mocc = wppa('mocc'); $occur = wppa('occur'); if ($alb < '0') { $alb = '0'; } // Feature enabled ? if (!wppa_switch('user_create_on')) { return ''; } // Have access? if ($alb && !wppa_have_access($alb)) { return ''; } // Can create album? if (!$alb && !wppa_can_create_top_album()) { return ''; } if ($alb && !wppa_can_create_album()) { return ''; } if (!wppa_user_is('administrator') && wppa_switch('owner_only')) { if ($alb) { $album = wppa_cache_album($alb); // Need to be admin to create public subalbums if ($album['owner'] == '--- public ---') { return ''; } } } // In a widget or multi column responsive? $small = wppa_in_widget() == 'upload' || $mcr; // Create the return url $returnurl = wppa_get_permalink(); if ($where == 'cover') { $returnurl .= 'wppa-album=' . $alb . '&wppa-cover=0&wppa-occur=' . $occur; } elseif ($where == 'thumb') { $returnurl .= 'wppa-album=' . $alb . '&wppa-cover=0&wppa-occur=' . $occur; } elseif ($where == 'widget' || $where == 'uploadbox') { } if (wppa('page')) { $returnurl .= '&wppa-page=' . wppa('page'); } $returnurl = trim($returnurl, '?'); $returnurl = wppa_trim_wppa_($returnurl); $t = $mcr ? 'mcr-' : ''; // The links $result .= '<div style="clear:both"></div>' . '<a' . ' id="wppa-cr-' . $alb . '-' . $mocc . '"' . ' class="wppa-create-' . $where . '"' . ' onclick="' . 'jQuery( \'#wppa-create-' . $t . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-cr-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-up-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-ea-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cats-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#_wppa-cr-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . '_wppaDoAutocol( ' . $mocc . ' )' . '"' . ' style="float:left; cursor:pointer;"' . '> ' . __('Create Album', 'wp-photo-album-plus') . '</a>' . '<a' . ' id="_wppa-cr-' . $alb . '-' . $mocc . '"' . ' class="wppa-create-' . $where . '"' . ' onclick="' . 'jQuery( \'#wppa-create-' . $t . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . 'jQuery( \'#wppa-cr-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-up-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-ea-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#wppa-cats-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'block\' );' . 'jQuery( \'#_wppa-cr-' . $alb . '-' . $mocc . '\' ).css( \'display\',\'none\' );' . '_wppaDoAutocol( ' . $mocc . ' )' . '"' . ' style="float:right; cursor:pointer;display:none;"' . ' >' . __(wppa_opt('close_text'), 'wp-photo-album-plus') . '</a>'; // The create form $result .= '<div' . ' id="wppa-create-' . $t . $alb . '-' . $mocc . '"' . ' class="wppa-file-' . $t . $mocc . '"' . ' style="width:' . $width . 'px;text-align:center;display:none;"' . ' >' . '<form' . ' id="wppa-creform-' . $alb . '-' . $mocc . '"' . ' action="' . $returnurl . '"' . ' method="post"' . ' >' . wppa_nonce_field('wppa-album-check', 'wppa-nonce', false, false, $alb) . '<input type="hidden" name="wppa-album-parent" value="' . $alb . '" />' . '<input type="hidden" name="wppa-fe-create" value="yes" />' . '<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' . ' type="text"' . ' class="wppa-box-text wppa-file-' . $t . $mocc . '"' . ' style="padding:0; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-album-name"' . ' />' . '<div' . ' class="wppa-box-text wppa-td"' . ' style="' . 'clear:both;' . 'float:left;' . 'text-align:left;' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' >' . __('Enter album description', 'wp-photo-album-plus') . '</div>' . '<textarea' . ' class="wppa-user-textarea wppa-box-text wppa-file-' . $t . $mocc . '"' . ' style="padding:0;height:120px; width:' . ($width - 6) . 'px; ' . __wcs('wppa-box-text') . '"' . ' name="wppa-album-desc" >' . '</textarea>' . '<div style="float:left; margin: 6px 0;" >' . '<div style="float:left;">' . wppa_make_captcha(wppa_get_randseed('session')) . '</div>' . '<input' . ' type="text"' . ' id="wppa-captcha-' . $mocc . '"' . ' name="wppa-captcha"' . ' style="margin-left: 6px; width:50px; ' . __wcs('wppa-box-text') . __wcs('wppa-td') . '"' . ' />' . '</div>' . '<input' . ' type="submit"' . ' class="wppa-user-submit"' . ' style="margin: 6px 0; float:right; ' . __wcs('wppa-box-text') . '"' . ' value="' . __('Create album', 'wp-photo-album-plus') . '"' . ' />' . '</form>' . '</div>'; return $result; }
function wppa_get_photo_order($id = '0', $no_random = false) { global $wpdb; global $wppa; // Album specified? if (wppa_is_int($id) && $id > '0') { $order = wppa_get_album_item($id, 'p_order_by'); } else { $order = '0'; } // No order yet? Use default if (!$order) { $order = wppa_opt('list_photos_by'); } switch ($order) { case '': case '0': $result = ''; break; case '1': $result = 'ORDER BY p_order'; break; case '-1': $result = 'ORDER BY p_order DESC'; break; case '2': $result = 'ORDER BY name'; break; case '-2': $result = 'ORDER BY name DESC'; break; case '3': if ($no_random) { $result = 'ORDER BY name'; } else { $result = 'ORDER BY RAND( ' . wppa_get_randseed() . ' )'; } break; case '-3': if ($no_random) { $result = 'ORDER BY name DESC'; } else { $result = 'ORDER BY RAND( ' . wppa_get_randseed() . ' ) DESC'; } break; case '4': $result = 'ORDER BY mean_rating'; break; case '-4': $result = 'ORDER BY mean_rating DESC'; break; case '5': $result = 'ORDER BY timestamp'; break; case '-5': $result = 'ORDER BY timestamp DESC'; break; case '6': $result = 'ORDER BY rating_count'; break; case '-6': $result = 'ORDER BY rating_count DESC'; break; case '7': $result = 'ORDER BY exifdtm'; break; case '-7': $result = 'ORDER BY exifdtm DESC'; break; default: wppa_dbg_msg('Unimplemented photo order: ' . $order, 'red'); $result = ''; } return $result; }
function wppa_get_coverphoto_ids($alb, $count) { global $wpdb; if (!$alb) { return false; } // no album, no coverphoto // Find cover photo id $id = wppa_get_album_item($alb, 'main_photo'); // main_photo is a positive integer ( photo id )? if ($id > '0') { // 1 coverphoto explicitly given $photo = wppa_cache_photo($id); if (!$photo) { // Photo gone, set id to 0 $id = '0'; } elseif ($photo['album'] != $alb) { // Photo moved to other album, set id to 0 $id = '0'; } else { $temp['0'] = $photo; // Found! } } // main_photo is 0? Random if ('0' == $id) { if (current_user_can('wppa_moderate')) { $temp = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s ORDER BY RAND( " . wppa_get_randseed('page') . " ) LIMIT %d", $alb, $count), ARRAY_A); } else { $temp = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s AND ( ( `status` <> 'pending' AND `status` <> 'scheduled' ) OR `owner` = %s ) ORDER BY RAND( " . wppa_get_randseed('page') . " ) LIMIT %d", $alb, wppa_get_user(), $count), ARRAY_A); } } // main_photo is -2? Last upload if ('-2' == $id) { if (current_user_can('wppa_moderate')) { $temp = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s ORDER BY `timestamp` DESC LIMIT %d", $alb, $count), ARRAY_A); } else { $temp = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s AND ( ( `status` <> 'pending' AND `status` <> 'scheduled' ) OR `owner` = %s ) ORDER BY `timestamp` DESC LIMIT %d", $alb, wppa_get_user(), $count), ARRAY_A); } } // main_phtot is -1? Random featured if ('-1' == $id) { $temp = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s AND `status` = 'featured' ORDER BY RAND( " . wppa_get_randseed('page') . " ) LIMIT %d", $alb, $count), ARRAY_A); } // Random from children if ('-3' == $id) { $allalb = wppa_expand_enum(wppa_alb_to_enum_children($alb)); $temp = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` IN ( " . str_replace('.', ',', $allalb) . " ) " . "AND ( ( `status` <> 'pending' AND `status` <> 'scheduled' ) OR `owner` = %s ) " . "ORDER BY RAND( " . wppa_get_randseed('page') . " ) LIMIT %d", wppa_get_user(), $count), ARRAY_A); } // Most recent from children if ('-4' == $id) { $allalb = wppa_expand_enum(wppa_alb_to_enum_children($alb)); $temp = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` IN ( " . str_replace('.', ',', $allalb) . " ) " . "AND ( ( `status` <> 'pending' AND `status` <> 'scheduled' ) OR `owner` = %s ) " . "ORDER BY `timestamp` DESC LIMIT %d", wppa_get_user(), $count), ARRAY_A); } // Report query wppa_dbg_q('Q-gcovp'); // Add to 2nd level cache wppa_cache_photo('add', $temp); // Extract the ids only $ids = array(); if (is_array($temp)) { foreach ($temp as $item) { $ids[] = $item['id']; } } return $ids; }