function wppa_filter_exif($desc, $photo) { global $wpdb; if (strpos($desc, 'E#') === false) { return $desc; } // No tags in desc: Nothing to do $exiflabels = $wpdb->get_results("SELECT * FROM `" . WPPA_EXIF . "` WHERE `photo` = '0' ORDER BY `id`", ARRAY_A); $exifdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_EXIF . "` WHERE `photo`=%s ORDER BY `id`", $photo), ARRAY_A); wppa_dbg_q('Q61v'); // Init $temp = $desc; $prevtag = ''; $combined = ''; // Process all exiflines of this photo if ($exifdata) { foreach ($exifdata as $exifline) { $tag = $exifline['tag']; if ($prevtag == $tag) { // add a next item for this tag $combined .= ', ' . htmlspecialchars(strip_tags($exifline['description'])); } else { // first item of this tag if ($combined) { // Process if required $temp = str_replace($prevtag, $combined, $temp); } $combined = htmlspecialchars(strip_tags($exifline['description'])); $prevtag = $tag; } } // Process last $temp = str_replace($tag, $combined, $temp); } // Process all labels if ($exiflabels) { foreach ($exiflabels as $exiflabel) { $tag = $exiflabel['tag']; // convert E#XXX to E#LXXX to indicate the label $t = substr($tag, 0, 2) . 'L' . substr($tag, 2); $tag = $t; $temp = str_replace($tag, __a($exiflabel['description']), $temp); } } // Remove untranslated $pos = strpos($temp, 'E#'); while ($pos !== false) { $tmp = substr($temp, 0, $pos) . __a('n.a.') . substr($temp, $pos + 6); $temp = $tmp; $pos = strpos($temp, 'E#'); } // Return result return $temp; }
function wppa_load_footer() { global $wppa; global $wpdb; global $wppa_session; if (wppa_opt('wppa_lightbox_name') == 'wppa') { $fontsize_lightbox = wppa_opt('wppa_fontsize_lightbox') ? wppa_opt('wppa_fontsize_lightbox') : '10'; $d = wppa_switch('wppa_ovl_show_counter') ? 1 : 0; $ovlh = wppa_opt('wppa_ovl_txt_lines') == 'auto' ? 'auto' : (wppa_opt('wppa_ovl_txt_lines') + $d) * ($fontsize_lightbox + 2); $txtcol = wppa_opt('wppa_ovl_theme') == 'black' ? '#a7a7a7' : '#272727'; echo ' <!-- start WPPA+ Footer data --> <div id="wppa-overlay-bg" style="text-align:center; display:none; position:fixed; top:0; left:0; z-index:100090; width:100%; height:2048px; background-color:' . wppa_opt('wppa_ovl_bgcolor') . ';" onclick="wppaOvlOnclick(event)" >'; if (wppa_switch('ovl_show_legenda') && !wppa('is_mobile')) { echo ' <div id="wppa-ovl-legenda-1" onmouseover="jQuery(this).css(\'visibility\',\'visible\');" onmouseout="jQuery(this).css(\'visibility\',\'hidden\');" style="position:absolute; left:0; top:0; background-color:' . wppa_opt('wppa_ovl_theme') . ';color:' . $txtcol . '; visibility:visible;" > ' . __a('Press f for fullscreen.') . ' </div>'; } echo ' </div> <div id="wppa-overlay-ic" style="position:fixed; top:0; padding-top:10px; z-index:100095; opacity:1; box-shadow:none;" > </div> <img id="wppa-overlay-sp" alt="spinner" style="position:fixed; top:200px; left:200px; z-index:100100; opacity:1; visibility:hidden; box-shadow:none;" src="' . wppa_get_imgdir() . 'loading.gif" /> <script type="text/javascript">jQuery("#wppa-overlay-bg").css({height:window.innerHeight}); wppaOvlTxtHeight = "' . $ovlh . '"; wppaOvlCloseTxt = "' . __(wppa_opt('wppa_ovl_close_txt')) . '"; wppaOvlOpacity = ' . wppa_opt('wppa_ovl_opacity') / 100 . '; wppaOvlOnclickType = "' . wppa_opt('wppa_ovl_onclick') . '"; wppaOvlTheme = "' . wppa_opt('wppa_ovl_theme') . '"; wppaOvlAnimSpeed = ' . wppa_opt('wppa_ovl_anim') . '; wppaOvlSlideSpeed = ' . wppa_opt('wppa_ovl_slide') . '; wppaVer4WindowWidth = 800; wppaVer4WindowHeight = 600; wppaOvlShowCounter = ' . (wppa_switch('wppa_ovl_show_counter') ? 'true' : 'false') . '; ' . (wppa_opt('wppa_fontfamily_lightbox') ? 'wppaOvlFontFamily = "' . wppa_opt('wppa_fontfamily_lightbox') . '"' : '') . ' wppaOvlFontSize = "' . $fontsize_lightbox . '"; ' . (wppa_opt('wppa_fontcolor_lightbox') ? 'wppaOvlFontColor = "' . wppa_opt('wppa_fontcolor_lightbox') . '"' : '') . ' ' . (wppa_opt('wppa_fontweight_lightbox') ? 'wppaOvlFontWeight = "' . wppa_opt('wppa_fontweight_lightbox') . '"' : '') . ' ' . (wppa_opt('wppa_fontsize_lightbox') ? 'wppaOvlLineHeight = "' . (wppa_opt('wppa_fontsize_lightbox') + '2') . '"' : '') . ' wppaOvlFullLegenda = "' . __a('Keys: f = next mode; escape = exit; p = previous, n = next, s = start/stop, d = dismiss this notice.') . '"; wppaOvlFullLegendaSingle = "' . __a('Keys: f = next mode; escape = exit; d = dismiss this notice.') . '"; wppaOvlVideoStart = ' . (wppa_switch('ovl_video_start') ? 'true' : 'false') . '; wppaOvlAudioStart = ' . (wppa_switch('ovl_audio_start') ? 'true' : 'false') . '; wppaOvlShowLegenda = ' . (wppa_switch('ovl_show_legenda') && !wppa('is_mobile') ? 'true' : 'false') . '; wppaOvlShowStartStop = ' . (wppa_switch('ovl_show_startstop') ? 'true' : 'false') . '; </script> '; wp_nonce_field('wppa-check', 'wppa-nonce', false, true); // Nonce field for Ajax bump view counter from lightbox echo ' <script type="text/javascript">'; if (isset($wppa_session['photo'])) { foreach (array_keys($wppa_session['photo']) as $p) { echo ' wppaPhotoView[' . $p . '] = true;'; } } echo ' </script> <!-- end WPPA+ Footer data --> '; } wppa_dbg_q('print'); if ($wppa['debug']) { $plugins = get_option('active_plugins'); wppa_dbg_msg('Active Plugins'); foreach ($plugins as $plugin) { wppa_dbg_msg($plugin); } wppa_dbg_msg('End Active Plugins'); } echo ' <!-- Do user upload -->'; wppa_user_upload(); // Do the upload if required and not yet done echo ' <!-- Done user upload -->'; }
function wppa_cache_thumb($id, $data = '') { global $wpdb; global $thumb; static $thumb_cache_2; // Action? if ($id == 'invalidate') { if (isset($thumb_cache_2[$data])) { unset($thumb_cache_2[$data]); } $thumb = false; return false; } if ($id == 'add') { if (!$data) { // Nothing to add return false; } elseif (isset($data['id'])) { // Add a single thumb to 2nd level cache $thumb_cache_2[$data['id']] = $data; // Looks valid } elseif (count($data) > 10000) { return false; // Too many, may cause out of memory error } else { foreach ($data as $thumb) { // Add multiple if (isset($thumb['id'])) { // Looks valid $thumb_cache_2[$thumb['id']] = $thumb; } } } return false; } if ($id == 'count') { if (is_array($thumb_cache_2)) { return count($thumb_cache_2); } else { return false; } } if (!wppa_is_int($id) || $id < '1') { wppa_dbg_msg('Invalid arg wppa_cache_thumb(' . $id . ')', 'red'); $thumb = false; return false; } // In first level cache? if (isset($thumb['id']) && $thumb['id'] == $id) { wppa_dbg_q('G-T1'); return $thumb; } // In second level cache? if (!empty($thumb_cache_2)) { if (in_array($id, array_keys($thumb_cache_2))) { $thumb = $thumb_cache_2[$id]; wppa_dbg_q('G-T2'); return $thumb; } } // Not in cache, do query $thumb = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $id), ARRAY_A); wppa_dbg_q('Q-P'); // Found one? if ($thumb) { // Store in second level cache $thumb_cache_2[$id] = $thumb; return $thumb; } else { wppa_dbg_msg('Photo ' . $id . ' does not exist', 'red'); return false; } }
function wppa_get_potd() { global $wpdb; $image = ''; switch (wppa_opt('widget_method')) { case '1': // Fixed photo $id = wppa_opt('widget_photo'); if ($id != '') { $image = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s LIMIT 0,1", $id), ARRAY_A); wppa_dbg_q('Q-Potd'); wppa_cache_photo('add', $image); } break; case '2': // Random $album = wppa_opt('widget_album'); if ($album == 'topten') { $images = wppa_get_widgetphotos($album); if (count($images) > 1) { // Select a random first from the current selection $idx = rand(0, count($images) - 1); $image = $images[$idx]; } } elseif ($album != '') { $images = wppa_get_widgetphotos($album, "ORDER BY RAND() LIMIT 0,1"); $image = $images[0]; } break; case '3': // Last upload $album = wppa_opt('widget_album'); if ($album == 'topten') { $images = wppa_get_widgetphotos($album); if ($images) { // fid last uploaded image in the $images pool $temp = 0; foreach ($images as $img) { if ($img['timestamp'] > $temp) { $temp = $img['timestamp']; $image = $img; } } } } elseif ($album != '') { $images = wppa_get_widgetphotos($album, "ORDER BY timestamp DESC LIMIT 0,1"); $image = $images[0]; } break; case '4': // Change every $album = wppa_opt('widget_album'); if ($album != '') { $per = wppa_opt('widget_period'); $photos = wppa_get_widgetphotos($album); if ($per == '0') { if ($photos) { $image = $photos[rand(0, count($photos) - 1)]; } else { $image = ''; } } elseif ($per == 'day-of-week') { $image = ''; if ($photos) { $d = date_i18n("w"); $d -= get_option('wppa_potd_offset', '0'); while ($d < '1') { $d += '7'; } foreach ($photos as $img) { if ($img['p_order'] == $d) { $image = $img; } } } } elseif ($per == 'day-of-month') { $image = ''; if ($photos) { $d = strval(intval(date_i18n("d"))); $d -= get_option('wppa_potd_offset', '0'); while ($d < '1') { $d += '31'; } foreach ($photos as $img) { if ($img['p_order'] == $d) { $image = $img; } } } } elseif ($per == 'day-of-year') { $image = ''; if ($photos) { $d = strval(intval(date_i18n("z"))); $d -= get_option('wppa_potd_offset', '0'); while ($d < '0') { $d += '366'; } foreach ($photos as $img) { if ($img['p_order'] == $d) { $image = $img; } } } } else { $u = date_i18n("U"); // Seconds since 1-1-1970, local $u /= 3600; // hours since $u = floor($u); $u /= $per; $u = floor($u); // Find the right photo out of the photos found by wppa_get_widgetphotos(), // based on the Change every { any timeperiod } algorithm. if ($photos) { $p = count($photos); $idn = fmod($u, $p); // If from topten,... if ($album == 'topten') { // Do a re-read of the same to order by rand, reproduceable // This can not be done by wppa_get_widgetphotos(), // it does already ORDER BY for the top selection criterium. // So we save the ids, and do a SELECT WHERE id IN ( array of found ids ) ORDER BY RAND( seed ) $ids = array(); foreach ($photos as $photo) { $ids[] = $photo['id']; } $photos = $wpdb->get_results("SELECT `id`, `p_order` " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `id` IN (" . implode(',', $ids) . ") " . "ORDER BY RAND(" . $idn . ")", ARRAY_A); } else { $photos = wppa_get_widgetphotos($album, " ORDER BY RAND(" . $idn . ")"); } // Image found $image = $photos[$idn]; } else { $image = ''; } } } else { $image = ''; } break; default: $image = ''; } if ($image) { $image = wppa_cache_photo($image['id']); } return $image; }
function wppa_get_album_title_linktype($alb) { global $wpdb; if (is_numeric($alb)) { $result = $wpdb->get_var($wpdb->prepare("SELECT cover_linktype FROM " . WPPA_ALBUMS . " WHERE id = %s LIMIT 1", $alb)); } else { $result = ''; } wppa_dbg_q('Q59'); return $result; }
function wppa_load_footer() { global $wpdb; global $wppa_session; echo ' <!-- start WPPA+ Footer data --> '; // Do they use our lightbox? if (wppa_opt('lightbox_name') == 'wppa') { $fontsize_lightbox = wppa_opt('fontsize_lightbox') ? wppa_opt('fontsize_lightbox') : '10'; $d = wppa_switch('wppa_ovl_show_counter') ? 1 : 0; $ovlh = wppa_opt('ovl_txt_lines') == 'auto' ? 'auto' : (wppa_opt('ovl_txt_lines') + $d) * ($fontsize_lightbox + 2); $txtcol = wppa_opt('ovl_theme') == 'black' ? '#a7a7a7' : '#272727'; // The lightbox overlay background echo '<div' . ' id="wppa-overlay-bg"' . ' style="' . 'text-align:center;' . 'display:none;' . 'position:fixed;' . 'top:0;' . 'left:0;' . 'z-index:100090;' . 'width:100%;' . 'height:2048px;' . 'background-color:' . wppa_opt('ovl_bgcolor') . ';' . '"' . ' onclick="wppaOvlOnclick(event)"' . ' >'; // Display legenda if (wppa_switch('ovl_show_legenda') && !wppa('is_mobile')) { echo '<div' . ' id="wppa-ovl-legenda-1"' . ' onmouseover="jQuery(this).css(\'visibility\',\'visible\');"' . ' onmouseout="jQuery(this).css(\'visibility\',\'hidden\');"' . ' style="' . 'position:absolute;' . 'left:0;' . 'top:0;' . 'background-color:' . wppa_opt('ovl_theme') . ';' . 'color:' . $txtcol . ';' . 'visibility:visible;' . '"' . ' > ' . __('Press f for fullscreen.', 'wp-photo-album-plus') . ' </div>'; } // The fullscreen button echo '<img' . ' id="wppa-fulls-btn"' . ' src="' . wppa_get_imgdir('fulls.png') . '"' . ' style="height:32px;z-index:100091;position:fixed;top:0;right:0;"' . ' onclick="wppaOvlFull()"' . ' ontouchstart="wppaOvlFull()"' . ' onmouseover="jQuery(this).fadeTo(600,1);"' . ' onmouseout="jQuery(this).fadeTo(600,0);"' . ' />'; // Close lightbox overlay background echo '</div>'; // The Lightbox Image container echo '<div' . ' id="wppa-overlay-ic"' . ' style="' . 'position:fixed;' . 'top:50%;' . 'left:50%;' . 'z-index:100095;' . 'opacity:1;' . 'box-shadow:none;' . 'box-sizing:content-box;' . '"' . ' >' . '</div>'; // The Spinner image echo ' <img' . ' id="wppa-overlay-sp"' . ' alt="spinner"' . ' style="' . 'position:fixed;' . 'top:50%;' . 'margin-top:-16px;' . 'left:50%;' . 'margin-left:-16px;' . 'z-index:100100;' . 'opacity:1;' . 'visibility:hidden;' . 'box-shadow:none;' . '"' . ' src="' . wppa_get_imgdir() . 'loading.gif"' . ' />'; // The init vars echo ' <script type="text/javascript"> jQuery("#wppa-overlay-bg").css({height:window.innerHeight}); wppaOvlTxtHeight = "' . $ovlh . '"; wppaOvlOpacity = ' . wppa_opt('ovl_opacity') / 100 . '; wppaOvlOnclickType = "' . wppa_opt('ovl_onclick') . '"; wppaOvlTheme = "' . wppa_opt('ovl_theme') . '"; wppaOvlAnimSpeed = ' . wppa_opt('ovl_anim') . '; wppaOvlSlideSpeed = ' . wppa_opt('ovl_slide') . '; wppaVer4WindowWidth = 800; wppaVer4WindowHeight = 600; wppaOvlShowCounter = ' . (wppa_switch('wppa_ovl_show_counter') ? 'true' : 'false') . '; ' . (wppa_opt('fontfamily_lightbox') ? 'wppaOvlFontFamily = "' . wppa_opt('fontfamily_lightbox') . '"' : '') . ' wppaOvlFontSize = "' . $fontsize_lightbox . '"; ' . (wppa_opt('fontcolor_lightbox') ? 'wppaOvlFontColor = "' . wppa_opt('fontcolor_lightbox') . '"' : '') . ' ' . (wppa_opt('fontweight_lightbox') ? 'wppaOvlFontWeight = "' . wppa_opt('fontweight_lightbox') . '"' : '') . ' ' . (wppa_opt('fontsize_lightbox') ? 'wppaOvlLineHeight = "' . (wppa_opt('fontsize_lightbox') + '2') . '"' : '') . ' wppaOvlFullLegenda = "' . __('Keys: f = next mode; q,x = exit; p = previous, n = next, s = start/stop, d = dismiss this notice.', 'wp-photo-album-plus') . '"; wppaOvlFullLegendaSingle = "' . __('Keys: f = next mode; q,x = exit; d = dismiss this notice.', 'wp-photo-album-plus') . '"; wppaOvlVideoStart = ' . (wppa_switch('ovl_video_start') ? 'true' : 'false') . '; wppaOvlAudioStart = ' . (wppa_switch('ovl_audio_start') ? 'true' : 'false') . '; wppaOvlShowLegenda = ' . (wppa_switch('ovl_show_legenda') && !wppa('is_mobile') ? 'true' : 'false') . '; wppaOvlShowStartStop = ' . (wppa_switch('ovl_show_startstop') ? 'true' : 'false') . '; </script> '; } // The photo views cache echo ' <script type="text/javascript">'; if (isset($wppa_session['photo'])) { foreach (array_keys($wppa_session['photo']) as $p) { echo ' wppaPhotoView[' . $p . '] = true;'; } } echo ' </script> <!-- end WPPA+ Footer data --> '; // Debugging, show queries wppa_dbg_q('print'); // Debugging, show active plugins if (wppa('debug')) { $plugins = get_option('active_plugins'); wppa_dbg_msg('Active Plugins'); foreach ($plugins as $plugin) { wppa_dbg_msg($plugin); } wppa_dbg_msg('End Active Plugins'); } echo ' <!-- Nonce for various wppa actions -->'; // Nonce field for Ajax bump view counter from lightbox, and rating wp_nonce_field('wppa-check', 'wppa-nonce', false, true); echo ' <!-- Do user upload -->'; // Do the upload if required and not yet done wppa_user_upload(); // Done echo ' <!-- Done user upload -->'; }
function wppa_allow_user_uploads() { global $wpdb; // Get the limits $limits = wppa_get_user_upload_limits(); $temp = explode('/', $limits); $limit_max = isset($temp[0]) ? $temp[0] : '0'; $limit_time = isset($temp[1]) ? $temp[1] : '0'; if (!$limit_max) { return '-1'; } // Unlimited max $user = wppa_get_user('login'); if (!$limit_time) { // For ever $curcount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s", $user)); wppa_dbg_q('Q326'); } else { // Time criterium in place $timnow = time(); $timthen = $timnow - $limit_time; $curcount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s AND `timestamp` > %s", $user, $timthen)); wppa_dbg_q('Q327'); } if ($curcount >= $limit_max) { $result = '0'; } else { $result = $limit_max - $curcount; } return $result; }
function wppa_time_to_wait_html($album, $user = false) { global $wpdb; if (!$album && !$user) { return '0'; } if ($user) { $limits = wppa_get_user_upload_limits(); } else { $limits = $wpdb->get_var($wpdb->prepare("SELECT `upload_limit` FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $album)); } wppa_dbg_q('Q62'); $temp = explode('/', $limits); $limit_max = isset($temp[0]) ? $temp[0] : '0'; $limit_time = isset($temp[1]) ? $temp[1] : '0'; $result = ''; if (!$limit_max || !$limit_time) { return $result; } if ($user) { $owner = wppa_get_user('login'); $last_upload_time = $wpdb->get_var($wpdb->prepare("SELECT `timestamp` FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s ORDER BY `timestamp` DESC LIMIT 1", $owner)); } else { $last_upload_time = $wpdb->get_var($wpdb->prepare("SELECT `timestamp` FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s ORDER BY `timestamp` DESC LIMIT 1", $album)); } wppa_dbg_q('Q63'); $timnow = time(); // For simplicity: a year is 364 days = 52 weeks, we skip the months $seconds = array('min' => '60', 'hour' => '3600', 'day' => '86400', 'week' => '604800', 'month' => '2592000', 'year' => '31449600'); $deltatim = $last_upload_time + $limit_time - $timnow; $temp = $deltatim; // $months = floor( $temp / $seconds['month'] ); // $temp = $temp % $seconds['month']; $weeks = floor($temp / $seconds['week']); $temp = $temp % $seconds['week']; $days = floor($temp / $seconds['day']); $temp = $temp % $seconds['day']; $hours = floor($temp / $seconds['hour']); $temp = $temp % $seconds['hour']; $mins = floor($temp / $seconds['min']); $secs = $temp % $seconds['min']; $switch = false; $string = __('You can upload after', 'wp-photo-album-plus') . ' '; // if ( $months ) { $string .= $months.' '.'months'.', '; $switch = true; } if ($weeks || $switch) { $string .= $weeks . ' ' . __('weeks', 'wp-photo-album-plus') . ', '; $switch = true; } if ($days || $switch) { $string .= $days . ' ' . __('days', 'wp-photo-album-plus') . ', '; $switch = true; } if ($hours || $switch) { $string .= $hours . ' ' . __('hours', 'wp-photo-album-plus') . ', '; $switch = true; } if ($mins || $switch) { $string .= $mins . ' ' . __('minutes', 'wp-photo-album-plus') . ' ' . __('and', 'wp-photo-album-plus') . ' '; $switch = true; } if ($switch) { $string .= $secs . ' ' . __('seconds', 'wp-photo-album-plus'); } $string .= '.'; $result = '<span style="font-size:9px;"> ' . $string . '</span>'; return $result; }
function wppa_get_potd() { global $wpdb; global $thumb; $image = ''; switch (wppa_opt('wppa_widget_method')) { case '1': // Fixed photo $id = wppa_opt('wppa_widget_photo'); if ($id != '') { $image = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s LIMIT 0,1", $id), ARRAY_A); wppa_dbg_q('Q-Potd'); wppa_cache_photo('add', $image); } break; case '2': // Random $album = wppa_opt('wppa_widget_album'); if ($album == 'topten') { $images = wppa_get_widgetphotos($album); if (count($images) > 1) { // Select a random first from the current selection $idx = rand(0, count($images) - 1); $image = $images[$idx]; } } elseif ($album != '') { $images = wppa_get_widgetphotos($album, "ORDER BY RAND() LIMIT 0,1"); $image = $images[0]; } break; case '3': // Last upload $album = wppa_opt('wppa_widget_album'); if ($album == 'topten') { $images = wppa_get_widgetphotos($album); if ($images) { // fid last uploaded image in the $images pool $temp = 0; foreach ($images as $img) { if ($img['timestamp'] > $temp) { $temp = $img['timestamp']; $image = $img; } } } } elseif ($album != '') { $images = wppa_get_widgetphotos($album, "ORDER BY timestamp DESC LIMIT 0,1"); $image = $images[0]; } break; case '4': // Change every $album = wppa_opt('wppa_widget_album'); if ($album != '') { $per = wppa_opt('wppa_widget_period'); $photos = wppa_get_widgetphotos($album); if ($per == '0') { if ($photos) { $image = $photos[rand(0, count($photos) - 1)]; } else { $image = ''; } } elseif ($per == 'day-of-week') { $image = ''; if ($photos) { $d = wppa_local_date('w'); if (!$d) { $d = '7'; } foreach ($photos as $img) { if ($img['p_order'] == $d) { $image = $img; } } } } elseif ($per == 'day-of-month') { $image = ''; if ($photos) { $d = wppa_local_date('d'); if (substr($d, '0', '1') == '0') { $d = substr($d, '1'); } foreach ($photos as $img) { if ($img['p_order'] == $d) { $image = $img; } } } } else { $u = date("U"); // Seconds since 1-1-1970 $u /= 3600; // hours since $u = floor($u); $u /= $per; $u = floor($u); if ($photos) { $p = count($photos); $idn = fmod($u, $p); $image = $photos[$idn]; } else { $image = ''; } } } else { $image = ''; } break; default: $image = ''; } $thumb = $image; return $image; }
function wppa_crumb_page_ancestors($page = '0') { global $wpdb; $query = "SELECT post_parent FROM " . $wpdb->posts . " WHERE post_type = 'page' AND post_status = 'publish' AND id = %s LIMIT 0,1"; $parent = $wpdb->get_var($wpdb->prepare($query, $page)); wppa_dbg_q('Q-bc4'); if (!is_numeric($parent) || $parent == '0') { return; } wppa_crumb_page_ancestors($parent); $query = "SELECT post_title FROM " . $wpdb->posts . " WHERE post_type = 'page' AND post_status = 'publish' AND id = %s LIMIT 0,1"; $title = $wpdb->get_var($wpdb->prepare($query, $parent)); wppa_dbg_q('Q-bc5'); $title = __(stripslashes($title)); if (!$title) { $title = '****'; // Page exists but is not publish wppa_bcitem($title, '#', __('Unpublished', 'wp-photo-album-plus'), $class = 'b2'); } else { wppa_bcitem($title, get_page_link($parent), __('Page:', 'wp-photo-album-plus') . ' ' . $title, 'b2'); } }
function wppa_get_youngest_album_name() { global $wpdb; $result = $wpdb->get_var("SELECT `name` FROM `" . WPPA_ALBUMS . "` ORDER BY `id` DESC LIMIT 1"); wppa_dbg_q('Q17'); return stripslashes($result); }
function wppa_is_user_blacklisted($user = -1) { global $wpdb; static $result = -1; $cur = -1 == $user; if ($cur && -1 != $result) { // Already found out for current user return $result; } if ($cur && !is_user_logged_in()) { // An logged out user can not be on the blacklist $result = false; return false; } $blacklist = get_option('wppa_black_listed_users', array()); if (empty($blacklist)) { // Anybody on the blacklist? $result = false; return false; } if ($cur) { $user = get_current_user_id(); } if (is_numeric($user)) { $user = $wpdb->get_var($wpdb->prepare("SELECT `user_login` FROM `" . $wpdb->users . "` WHERE `ID` = %d", $user)); wppa_dbg_q('Q-iub'); } else { return false; } if ($cur) { $result = in_array($user, $blacklist); // Save current users result. } return in_array($user, $blacklist); }
function wppa_auto_page_links($where) { global $wpdb; $m = $where == 'bottom' ? 'margin-top:8px;' : ''; $mustwhere = wppa_opt('auto_page_links'); if (($mustwhere == 'top' || $mustwhere == 'both') && $where == 'top' || ($mustwhere == 'bottom' || $mustwhere == 'both') && $where == 'bottom') { wppa_out(' <div' . ' id="prevnext1-' . wppa('mocc') . '"' . ' class="wppa-box wppa-nav wppa-nav-text"' . ' style="text-align: center; ' . __wcs('wppa-box') . __wcs('wppa-nav') . __wcs('wppa-nav-text') . $m . '"' . ' >'); $photo = wppa('single_photo'); $thumb = wppa_cache_thumb($photo); $album = $thumb['album']; $photos = $wpdb->get_results($wpdb->prepare("SELECT `id`, `page_id` FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s " . wppa_get_photo_order($album), $album), ARRAY_A); wppa_dbg_q('Q-Ppag'); $prevpag = '0'; $nextpag = '0'; $curpag = get_the_ID(); $count = count($photos); $count_ = $count - 1; $current = '0'; if ($photos) { foreach (array_keys($photos) as $idx) { if ($photos[$idx]['page_id'] == $curpag) { if ($idx != '0') { $prevpag = wppa_get_the_auto_page($photos[$idx - 1]['id']); } // ['page_id']; if ($idx != $count_) { $nextpag = wppa_get_the_auto_page($photos[$idx + 1]['id']); } // ['page_id']; $current = $idx; } } } if ($prevpag) { wppa_out('<a href="' . get_permalink($prevpag) . '" style="float:left" >' . __('< Previous', 'wp-photo-album-plus') . '</a>'); } else { wppa_out('<span style="visibility:hidden" >' . __('< Previous', 'wp-photo-album-plus') . '</span>'); } wppa_out(++$current . '/' . $count); if ($nextpag) { wppa_out('<a href="' . get_permalink($nextpag) . '" style="float:right" >' . __('Next >', 'wp-photo-album-plus') . '</a>'); } else { wppa_out('<span style="visibility:hidden" >' . __('Next >', 'wp-photo-album-plus') . '</span>'); } wppa_out('</div><div style="clear:both"></div>'); } }
function do_album_navigator($parent, $page, $skip, $propclass) { 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 " . wppa_get_album_order(max('0', $parent)), $parent), ARRAY_A); wppa_dbg_q('Q-WidANav'); 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_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) . '</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_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; }
function wppa_is_id_free($type, $id) { global $wpdb; if (!is_numeric($id)) { return false; } if ($id == '0') { return false; } $table = ''; if ($type == 'album') { $table = WPPA_ALBUMS; } elseif ($type == 'photo') { $table = WPPA_PHOTOS; } else { $table = $type; } // $type may be the tablename itsself if ($table == '') { echo 'Unexpected error in wppa_is_id_free()'; return false; } $exists = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . $table . "` WHERE `id` = %s", $id), ARRAY_A); wppa_dbg_q('Q208'); if ($exists) { return false; } return true; }