function wppa_series_to_array($xtxt) { if (is_array($xtxt)) { return false; } $txt = str_replace(' ', '', $xtxt); // Remove spaces if (strpos($txt, '.') === false) { return false; } // Not an enum/series, the only legal way to return false if (strpos($txt, '...') !== false) { wppa_stx_err('Max 2 successive dots allowed. ' . $txt); return false; } if (substr($txt, 0, 1) == '.') { wppa_stx_err('Missing starting number. ' . $txt); return false; } if (substr($txt, -1) == '.') { wppa_stx_err('Missing ending number. ' . $txt); return false; } $t = str_replace(array('.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'), '', $txt); if ($t) { wppa_stx_err('Illegal character(s): "' . $t . '" found. ' . $txt); return false; } // Trim leading '0.' if (substr($txt, 0, 2) == '0.') { $txt = substr($txt, 2); } $temp = explode('.', $txt); $tempcopy = $temp; foreach (array_keys($temp) as $i) { if (!$temp[$i]) { // found a '..' if ($temp[$i - '1'] >= $temp[$i + '1']) { wppa_stx_err('Start > end. ' . $txt); return false; } for ($j = $temp[$i - '1'] + '1'; $j < $temp[$i + '1']; $j++) { $tempcopy[] = $j; } } else { if (!is_numeric($temp[$i])) { wppa_stx_err('A enum or range token must be a number. ' . $txt); return false; } } } $result = $tempcopy; foreach (array_keys($result) as $i) { if (!$result[$i]) { unset($result[$i]); } } return $result; }
function wppa_albums($id = '', $type = '', $size = '', $align = '') { global $wppa_lang; global $wppa_locale; global $wpdb; global $thumbs; global $wppa_session; // Diagnostics wppa_dbg_msg('Entering wppa_albums'); wppa_dbg_msg('Lang=' . $wppa_lang . ', Locale=' . $wppa_locale . ', Ajax=' . wppa('ajax')); wppa_dbg_msg('$wppa_session = ' . serialize($wppa_session)); // List content filters // Data struct: $wp_filter[$tag][$priority][$idx] = array( 'function' => $function_to_add, 'accepted_args' => $accepted_args ); if (wppa('debug') && wppa('mocc') == '0') { global $wp_filter; wppa_dbg_msg('Start content filters', 'green'); foreach (array_keys($wp_filter['the_content']) as $key) { foreach (array_keys($wp_filter['the_content'][$key]) as $key2) { $func = is_array($wp_filter['the_content'][$key][$key2]['function']) ? serialize($wp_filter['the_content'][$key][$key2]['function']) : $wp_filter['the_content'][$key][$key2]['function']; wppa_dbg_msg('Pri:' . $key . ', func: ' . $func . ', args: ' . $wp_filter['the_content'][$key][$key2]['accepted_args']); } } wppa_dbg_msg('End content filters', 'green'); } // Process a user upload request, if any. Do it here: it may affect this occurences display wppa_user_upload(); // Test for scheduled publications wppa_publish_scheduled(); // First calculate the occurance if (wppa('ajax')) { if (wppa_get_get('moccur')) { wppa('mocc', wppa_get_get('moccur')); if (!is_numeric(wppa('mocc'))) { wp_die('Security check failure 1'); } } else { wppa('mocc', '1'); } wppa('fullsize', wppa_get_get('wppa-size', wppa_get_container_width())); if (wppa_get_get('occur')) { wppa('occur', wppa_get_get('occur')); if (!is_numeric(wppa('occur'))) { wp_die('Security check failure 2'); } } if (wppa_get_get('woccur')) { wppa('widget_occur', wppa_get_get('woccur')); wppa('in_widget', true); if (!is_numeric(wppa('widget_occur'))) { wp_die('Security check failure 3'); } } } else { wppa('mocc', wppa('mocc') + '1'); if (wppa_in_widget()) { wppa('widget_occur', wppa('widget_occur') + '1'); } else { wppa('occur', wppa('occur') + '1'); } } // Set wppa( 'src' ) = true and wppa( 'searchstring' ) if this occurrance processes a search request. wppa_test_for_search(); // There are 3 ways to get here: // in order of priority: // 1. The given query string applies to this invocation ( occurrance ) // This invocation requires the ignorance of the filter results and the interpretation of the querystring. if ((wppa_get_get('occur') || wppa_get_get('woccur')) && (wppa_in_widget() && wppa('widget_occur') == wppa_get_get('woccur') || !wppa_in_widget() && wppa('occur') == wppa_get_get('occur')) && !wppa('is_autopage')) { // Process query string wppa_out(wppa_dbg_msg('Querystring applied', 'brown', false, true)); wppa('start_album', wppa_get_get('album')); wppa('is_cover', wppa_get_get('cover')); wppa('is_slide', wppa_get_get('slide') || wppa_get_get('album') !== false && wppa_get_get('photo')); if (wppa('is_slide')) { wppa('start_photo', wppa_get_get('photo')); // Start a slideshow here } else { wppa('single_photo', wppa_get_get('photo')); // Photo is the single photoid } wppa('is_single', wppa_get_get('single')); // Is a one image slideshow wppa('topten_count', wppa_force_numeric_else(wppa_get_get('topten'), wppa_opt('topten_count'))); wppa('is_topten', wppa('topten_count') != '0'); wppa('lasten_count', wppa_force_numeric_else(wppa_get_get('lasten'), wppa_opt('lasten_count'))); wppa('is_lasten', wppa('lasten_count') != '0'); wppa('comten_count', wppa_force_numeric_else(wppa_get_get('comten'), wppa_opt('comten_count'))); wppa('is_comten', wppa('comten_count') != '0'); wppa('featen_count', wppa_force_numeric_else(wppa_get_get('featen'), wppa_opt('featen_count'))); wppa('is_featen', wppa('featen_count') != '0'); wppa('albums_only', wppa_get_get('albums-only')); wppa('photos_only', wppa_get_get('photos-only')); wppa('related_count', wppa_force_numeric_else(wppa_get_get('relcount'), wppa_opt('related_count'))); wppa('is_related', wppa_get_get('rel')); if (wppa('is_related') == 'tags') { wppa('is_tag', wppa_get_related_data()); if (wppa('related_count') == '0') { wppa('related_count', wppa_opt('related_count')); } } else { wppa('is_tag', trim(strip_tags(wppa_get_get('tag')), ',;')); } if (wppa('is_related') == 'desc') { wppa('src', true); if (wppa('related_count') == '0') { wppa('related_count', wppa_opt('related_count')); } wppa('searchstring', str_replace(';', ',', wppa_get_related_data())); wppa('photos_only', true); } if (wppa('is_tag')) { wppa_dbg_msg('Is Tag: ' . wppa('is_tag')); } else { wppa_dbg_msg('Is NOT Tag'); } wppa('page', wppa_get_get('page')); if (wppa_get_get('superview')) { $wppa_session['superview'] = wppa('is_slide') ? 'slide' : 'thumbs'; $wppa_session['superalbum'] = wppa('start_album'); wppa_save_session(); wppa('photos_only', true); } wppa('is_upldr', wppa_get_get('upldr')); if (wppa('is_upldr')) { wppa('photos_only', true); } wppa('is_owner', wppa_get_get('owner')); if (wppa('is_owner')) { $albs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `owner` = %s ", wppa('is_owner')), ARRAY_A); wppa_dbg_q('Q-Main-1'); wppa_cache_album('add', $albs); $id = ''; if ($albs) { foreach ($albs as $alb) { $id .= $alb['id'] . '.'; } } $id = rtrim($id, '.'); wppa('start_album', $id); } wppa('supersearch', strip_tags(wppa_get_get('supersearch'))); $wppa_session['supersearch'] = wppa('supersearch'); wppa_save_session(); if (wppa('supersearch')) { $ss_info = explode(',', wppa('supersearch')); if ($ss_info['0'] == 'a') { wppa('albums_only', true); } else { wppa('photos_only', true); } } wppa('calendar', strip_tags(wppa_get_get('calendar'))); wppa('caldate', strip_tags(wppa_get_get('caldate'))); wppa('is_inverse', wppa_get_get('inv')); } elseif ($id != '' || $type != '' || $size != '' || $align != '') { // Do NOT Set internal defaults here, they may be set before the call // Interprete function args if ($type == 'album') { } elseif ($type == 'cover') { wppa('is_cover', true); } elseif ($type == 'slide') { wppa('is_slide', true); } elseif ($type == 'slideonly') { wppa('is_slideonly', true); } if ($type == 'photo' || $type == 'mphoto' || $type == 'slphoto') { // Any type of single photo? id given is photo id if ($id) { wppa('single_photo', $id); } } else { // Not single photo: id given is album id if ($id) { wppa('start_album', $id); } } } else { if (wppa('bestof')) { $args = wppa('bestof_args'); wppa_bestof_box($args); $out = wppa('out'); wppa_reset_occurrance(); return $out; } elseif (wppa('is_landing') && !wppa('src')) { wppa_dbg_msg('Nothing to do...'); wppa_reset_occurrance(); return ''; // Do nothing on a landing page without a querystring while it is also not a search operation } elseif (wppa('is_autopage')) { $photo = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . WPPA_PHOTOS . "` WHERE `page_id` = %d LIMIT 1", get_the_ID())); wppa('single_photo', $photo); wppa_dbg_q('Q-main-2'); if (!wppa('single_photo')) { wppa_dbg_msg('No photo found for page ' . get_the_ID(), 'red', 'force'); wppa_reset_occurrance(); return ''; // Give up } $type = wppa_opt('auto_page_type'); switch ($type) { case 'photo': break; case 'mphoto': wppa('is_mphoto', true); break; case 'slphoto': wppa('is_slide', true); wppa('start_photo', wppa('single_photo')); wppa('is_single', true); break; default: wppa_dbg_msg('Unimplemented type autopage display: ' . $type, 'red', 'force'); } } } // Convert any keywords and / or names to numbers // Search for album keyword if (wppa('start_album') && !wppa_is_int(wppa('start_album'))) { if (substr(wppa('start_album'), 0, 1) == '#') { // Keyword $keyword = wppa('start_album'); if (strpos($keyword, ',')) { $keyword = substr($keyword, 0, strpos($keyword, ',')); } switch ($keyword) { // ( substr( wppa( 'start_album'], 0, 5 ) ) { case '#last': // Last upload $id = wppa_get_youngest_album_id(); if (wppa('is_cover')) { // To make sure the ordering sequence is ok. $temp = explode(',', wppa('start_album')); if (isset($temp['1'])) { wppa('last_albums_parent', $temp['1']); } else { wppa('last_albums_parent', '0'); } if (isset($temp['2'])) { wppa('last_albums', $temp['2']); } else { wppa('last_albums', false); } } else { // Ordering seq is not important, convert to album enum $temp = explode(',', wppa('start_album')); if (isset($temp['1'])) { $parent = wppa_album_name_to_number($temp['1']); } else { $parent = '0'; } if ($parent === false) { return; } if (isset($temp['2'])) { $limit = $temp['2']; } else { $limit = false; } if ($limit) { if ($parent) { if ($limit) { $q = $wpdb->prepare("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = %s ORDER BY `timestamp` DESC LIMIT %d", $parent, $limit); } else { $q = $wpdb->prepare("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = %s ORDER BY `timestamp` DESC", $parent); } } else { if ($limit) { $q = $wpdb->prepare("SELECT * FROM `" . WPPA_ALBUMS . "` ORDER BY `timestamp` DESC LIMIT %d", $limit); } else { $q = "SELECT * FROM `" . WPPA_ALBUMS . "` ORDER BY `timestamp` DESC"; } } $albs = $wpdb->get_results($q, ARRAY_A); wppa_dbg_q('Q-main-3'); wppa_cache_album('add', $albs); if (is_array($albs)) { foreach (array_keys($albs) as $key) { $albs[$key] = $albs[$key]['id']; } } $id = implode('.', $albs); } } break; case '#topten': $temp = explode(',', wppa('start_album')); $id = isset($temp[1]) ? $temp[1] : '0'; wppa('topten_count', isset($temp[2]) ? $temp[2] : wppa_opt('topten_count')); wppa('is_topten', true); if (wppa('is_cover')) { wppa_dbg_msg('A topten album has no cover. ' . wppa('start_album'), 'red', 'force'); wppa_reset_occurrance(); return; // Give up this occurence } break; case '#lasten': $temp = explode(',', wppa('start_album')); $id = isset($temp[1]) ? $temp[1] : '0'; wppa('lasten_count', isset($temp[2]) ? $temp[2] : wppa_opt('lasten_count')); wppa('is_lasten', true); if (wppa('is_cover')) { wppa_dbg_msg('A lasten album has no cover. ' . wppa('start_album'), 'red', 'force'); wppa_reset_occurrance(); return; // Give up this occurence } break; case '#comten': $temp = explode(',', wppa('start_album')); $id = isset($temp[1]) ? $temp[1] : '0'; wppa('comten_count', isset($temp[2]) ? $temp[2] : wppa_opt('comten_count')); wppa('is_comten', true); if (wppa('is_cover')) { wppa_dbg_msg('A comten album has no cover. ' . wppa('start_album'), 'red', 'force'); wppa_reset_occurrance(); return; // Give up this occurence } break; case '#featen': $temp = explode(',', wppa('start_album')); $id = isset($temp[1]) ? $temp[1] : '0'; wppa('featen_count', isset($temp[2]) ? $temp[2] : wppa_opt('featen_count')); wppa('is_featen', true); if (wppa('is_cover')) { wppa_dbg_msg('A featen album has no cover. ' . wppa('start_album'), 'red', 'force'); wppa_reset_occurrance(); return; // Give up this occurence } break; case '#related': $temp = explode(',', wppa('start_album')); $type = isset($temp[1]) ? $temp[1] : 'tags'; // tags is default type wppa('related_count', isset($temp[2]) ? $temp[2] : wppa_opt('related_count')); wppa('is_related', $type); $data = wppa_get_related_data(); if ($type == 'tags') { wppa('is_tag', $data); } if ($type == 'desc') { wppa('src', true); wppa('searchstring', str_replace(';', ',', $data)); wppa('photos_only', true); } wppa('photos_only', true); $id = '0'; break; case '#tags': wppa('is_tag', wppa_sanitize_tags(substr(wppa('start_album'), 6), true)); $id = '0'; wppa('photos_only', true); break; case '#cat': $temp = explode(',', wppa('start_album')); $cat = isset($temp[1]) ? $temp[1] : ''; $cat = trim(wppa_sanitize_tags($cat), ','); wppa('is_cat', $cat); if (!$cat) { wppa_dbg_msg('Missing cat #cat album spec: ' . wppa('start_album'), 'red', 'force'); wppa_reset_occurrance(); return; // Forget this occurrance } $albs = $wpdb->get_results("SELECT * FROM `" . WPPA_ALBUMS . "`", ARRAY_A); wppa_dbg_q('Q-main-4'); wppa_cache_album('add', $albs); $id = ''; if ($albs) { foreach ($albs as $alb) { $temp = explode(',', $alb['cats']); if (in_array($cat, $temp)) { $id .= $alb['id'] . '.'; } } } $id = rtrim($id, '.'); break; case '#owner': $temp = explode(',', wppa('start_album')); $owner = isset($temp[1]) ? $temp[1] : ''; if ($owner == '#me') { if (is_user_logged_in()) { $owner = wppa_get_user(); } else { // User not logged in, ignore shortcode wppa_reset_occurrance(); return; // Forget this occurrance } } if (!$owner) { wppa_dbg_msg('Missing owner in #owner album spec: ' . wppa('start_album'), 'red', 'force'); wppa_reset_occurrance(); return; // Forget this occurrance } $parent = isset($temp[2]) ? wppa_album_name_to_number($temp[2]) : '0'; if ($parent === false) { return; } if (!$parent) { $parent = '-1.0'; } if ($parent) { // Valid parent spec $parent_arr = explode('.', wppa_expand_enum($parent)); $id = wppa_alb_to_enum_children($parent); // Verify all albums are owned by $owner and are directly under a parent album $id = wppa_expand_enum($id); $albs = explode('.', $id); if ($albs) { foreach (array_keys($albs) as $idx) { if (wppa_get_album_item($albs[$idx], 'owner') != $owner || !in_array(wppa_get_album_item($albs[$idx], 'a_parent'), $parent_arr)) { unset($albs[$idx]); } } } $id = implode('.', $albs); if (!$id) { $id = '-9'; // Force nothing found // wppa_reset_occurrance(); // return; // No children found } } wppa('is_owner', $owner); break; case '#upldr': $temp = explode(',', wppa('start_album')); $owner = isset($temp[1]) ? $temp[1] : ''; if ($owner == '#me') { if (is_user_logged_in()) { $owner = wppa_get_user(); } else { // User not logged in, ignore shortcode wppa_reset_occurrance(); return; // Forget this occurrance } } if (!$owner) { wppa_dbg_msg('Missing owner in #upldr album spec: ' . wppa('start_album'), 'red', 'force'); wppa_reset_occurrance(); return; // Forget this occurrance } $parent = isset($temp[2]) ? wppa_album_name_to_number($temp[2]) : '0'; if ($parent === false) { return; } // parent specified but not a valid value if ($parent) { // Valid parent spec $id = wppa_alb_to_enum_children(wppa_expand_enum($parent)); if (!$id) { wppa_reset_occurrance(); return; // No children found } } else { // No parent spec $id = '0'; } wppa('is_upldr', $owner); wppa('photos_only', true); break; case '#all': $id = '-2'; break; default: wppa_dbg_msg('Unrecognized album keyword found: ' . wppa('start_album'), 'red', 'force'); wppa_reset_occurrance(); return; // Forget this occurrance } wppa('start_album', $id); } } // See if the album id is a name and convert it if possible wppa('start_album', wppa_album_name_to_number(wppa('start_album'))); if (wppa('start_album') === false) { wppa_reset_occurrance(); return; } // Also for parents wppa('last_albums_parent', wppa_album_name_to_number(wppa('last_albums_parent'))); if (wppa('last_albums_parent') === false) { wppa_reset_occurrance(); return; } // Check if album is valid if (strpos(wppa('start_album'), '.') !== false) { // Album may be enum if (!wppa_series_to_array(wppa('start_album'))) { // Syntax error wppa_reset_occurrance(); return; } } elseif (wppa('start_album') && !is_numeric(wppa('start_album'))) { wppa_stx_err('Unrecognized Album identification found: ' . wppa('start_album')); wppa_reset_occurrance(); return; // Forget this occurrance } elseif (wppa('start_album') > '0') { // -2 is #all if (!wppa_album_exists(wppa('start_album'))) { wppa_stx_err('Album does not exist: ' . wppa('start_album')); wppa_reset_occurrance(); return; // Forget this occurrance } } // See if the photo id is a keyword and convert it if possible if (wppa('single_photo') && !is_numeric(wppa('single_photo'))) { if (substr(wppa('single_photo'), 0, 1) == '#') { // Keyword switch (wppa('single_photo')) { case '#potd': // Photo of the day $t = wppa_get_potd(); if (is_array($t)) { $id = $t['id']; } else { $id = '0'; } break; case '#last': // Last upload $id = wppa_get_youngest_photo_id(); break; default: wppa_dbg_msg('Unrecognized photo keyword found: ' . wppa('single_photo'), 'red', 'force'); wppa_reset_occurrance(); return; // Forget this occurrance } wppa('single_photo', $id); } } // See if the photo id is a name and convert it if possible if (wppa('single_photo') && !is_numeric(wppa('single_photo'))) { if (substr(wppa('single_photo'), 0, 1) == '$') { // Name $id = wppa_get_photo_id_by_name(substr(wppa('single_photo'), 1)); if ($id > '0') { wppa('single_photo', $id); } else { wppa_dbg_msg('Photo name not found: ' . wppa('single_photo'), 'red', 'force'); wppa_reset_occurrance(); return; // Forget this occurrance } } } // Size and align if (is_numeric($size)) { wppa('fullsize', $size); } elseif ($size == 'auto') { wppa('auto_colwidth', true); } if ($align == 'left' || $align == 'center' || $align == 'right') { wppa('align', $align); } // Empty related shortcode? if (wppa('is_related')) { $thumbs = wppa_get_thumbs(); if (empty($thumbs)) { wppa_errorbox(__('No related photos found.', 'wp-photo-album-plus')); $result = wppa('out'); wppa_reset_occurrance(); // Forget this occurrance return $result; } } // Subsearch or rootsearch? if (wppa('occur') == '1' && $wppa_session['has_searchbox'] && !wppa('in_widget')) { // Is it a search now? if (wppa('src')) { // Is the subsearch box checked? wppa('is_subsearch', wppa_get_get('subsearch') || wppa_get_post('subsearch')); // Is the rootsearch box checked? wppa('is_rootsearch', wppa_get_get('rootsearch') || wppa_get_post('rootsearch')); // No rootsearch, forget previous root if (!wppa('is_rootsearch')) { $wppa_session['search_root'] = '0'; wppa_save_session(); } } else { // Find new potential searchroot if (isset($_REQUEST['wppa-searchroot'])) { wppa('start_album', strval(intval($_REQUEST['wppa-searchroot']))); } // Update session with new searchroot $wppa_session['search_root'] = wppa('start_album'); wppa_save_session(); } // Update searchroot in search boxes $rt = $wppa_session['search_root']; if (!$rt) { $rt = '0'; } // must be non-empty string wppa_add('src_script', 'jQuery(document).ready(function(){wppaUpdateSearchRoot( \'' . esc_js(wppa_display_root($rt)) . '\', ' . $rt . ' )});'); // If not search forget previous results if (!wppa('src')) { $wppa_session['use_searchstring'] = ''; $wppa_session['display_searchstring'] = ''; wppa_save_session(); wppa_add('src_script', "\n" . 'jQuery(document).ready(function(){wppaClearSubsearch()});'); } else { // Enable subbox wppa_add('src_script', 'jQuery(document).ready(function(){wppaEnableSubsearch()});'); } } // Is it url? if (wppa('is_url')) { if (wppa_photo_exists(wppa('single_photo'))) { wppa_out(wppa_get_hires_url(wppa('single_photo'))); } else { wppa_dbg_msg(sprintf('Photo %s not found', wppa('single_photo')), 'red', 'force'); } } elseif (wppa('is_stereobox')) { wppa_stereo_box(); } elseif (wppa('is_searchbox')) { wppa_search_box('', wppa('may_sub'), wppa('may_root')); } elseif (wppa('is_superviewbox')) { wppa_superview_box(wppa('start_album')); } elseif (wppa('is_multitagbox')) { wppa_multitag_box(wppa('tagcols'), wppa('taglist')); } elseif (wppa('is_tagcloudbox')) { wppa_tagcloud_box(wppa('taglist'), wppa_opt('tagcloud_min'), wppa_opt('tagcloud_max')); } elseif (wppa('is_upload')) { wppa_upload_box(); } elseif (wppa('is_supersearch')) { wppa_supersearch_box(); } elseif (wppa('is_mphoto') == '1') { if (wppa('is_autopage')) { wppa_auto_page_links('top'); } wppa_mphoto(); if (wppa('is_autopage')) { wppa_auto_page_links('bottom'); } } elseif (wppa_page('oneofone')) { if (wppa('is_autopage')) { wppa_auto_page_links('top'); } wppa_sphoto(); if (wppa('is_autopage')) { wppa_auto_page_links('bottom'); } } elseif (wppa('is_calendar')) { wppa_calendar_box(); } else { if (function_exists('wppa_theme')) { if (wppa('is_autopage')) { wppa_auto_page_links('top'); } wppa_theme(); // Call the theme module if (wppa('is_autopage')) { wppa_auto_page_links('bottom'); } } else { wppa_out('<span style="color:red">ERROR: Missing function wppa_theme(), check the installation of WPPA+. Remove customized wppa_theme.php</span>'); } global $wppa_version; $expected_version = '6-3-14-000'; if ($wppa_version != $expected_version) { wppa_dbg_msg('WARNING: customized wppa-theme.php is out of rev. Expected version: ' . $expected_version . ' found: ' . $wppa_version, 'red'); } } // Done $out = str_replace('w#location', wppa('geo'), wppa('out')); // Reset wppa_reset_occurrance(); return $out; }