示例#1
0
function wppa_get_search_html($label = '', $sub = false, $rt = false)
{
    global $wppa_session;
    $wppa_session['has_searchbox'] = true;
    wppa_save_session();
    $page = wppa_get_the_landing_page('wppa_search_linkpage', __('Photo search results', 'wp-photo-album-plus'));
    $pagelink = wppa_dbg_url(get_page_link($page));
    $cansubsearch = $sub && $wppa_session['use_searchstring'];
    $value = $cansubsearch ? '' : wppa_test_for_search(true);
    $root = $wppa_session['search_root'];
    $rootboxset = $root ? '' : 'checked="checked" disabled="disabled"';
    $fontsize = wppa_in_widget() ? 'font-size: 9px;' : '';
    $mocc = wppa('mocc');
    if (!wppa_in_widget()) {
        $label = wppa_opt('search_toptext');
    }
    wppa_dbg_msg('Root=' . $root . ': ' . wppa_get_album_name($root));
    $result = '<form' . ' id="wppa_searchform_' . $mocc . '"' . ' action="' . $pagelink . '"' . ' method="post"' . ' class="widget_search"' . ' >' . '<div>' . $label . '<input' . ' type="text"' . ' class="wppa-search-input"' . ' style="width:60%;"' . ' name="wppa-searchstring"' . ' id="wppa_s-' . $mocc . '"' . ' value="' . $value . '"' . ' />' . '<input' . ' id="wppa_searchsubmit-' . $mocc . '"' . ' type="submit"' . ' name="wppa-search-submit"' . ' value="' . __('Search', 'wp-photo-album-plus') . '"' . ' onclick="if ( document.getElementById( \'wppa_s-' . $mocc . '\' ).value == \'\' ) return false;"' . ' />' . '<input' . ' type="hidden"' . ' name="wppa-searchroot"' . ' class="wppa-search-root-id"' . ' value="' . $root . '"' . ' />' . ($rt ? '<div style="clear:both" ></div>' . '<small class="wppa-search-root" style="margin:0;padding:4px 0 0;" >' . wppa_display_root($root) . '</small>' . '<div style="clear:both;' . $fontsize . '" >
					<input type="checkbox" name="wppa-rootsearch" class="wppa-rootbox" ' . $rootboxset . ' /> ' . wppa_opt('search_in_section') . '</div>' : '') . ($sub ? '<div style="clear:both" ></div>' . '<small class="wppa-display-searchstring" style="margin:0;padding:4px 0 0;" >' . $wppa_session['display_searchstring'] . '</small>' . '<div style="clear:both;' . $fontsize . '" >' . '<input' . ' type="checkbox"' . ' name="wppa-subsearch"' . ' class="wppa-search-sub-box"' . (empty($wppa_session['display_searchstring']) ? ' disabled="disabled"' : '') . ' onchange="wppaSubboxChange(this)"' . ' /> ' . wppa_opt('search_in_results') . '</div>' : '') . '</div>' . '</form>';
    return $result;
}
function wppa_get_search_html($label = '', $sub = false, $root = false)
{
    global $wppa_session;
    $page = wppa_get_the_landing_page('wppa_search_linkpage', __a('Photo search results'));
    $pagelink = wppa_dbg_url(get_page_link($page));
    $cansubsearch = $sub && isset($wppa_session['use_searchstring']) && $wppa_session['use_searchstring'];
    $subboxset = isset($wppa_session['subbox']) && $wppa_session['subbox'] ? 'checked="checked"' : '';
    $canrootsearch = $root;
    $rootboxset = isset($wppa_session['rootbox']) && $wppa_session['rootbox'] ? 'checked="checked"' : '';
    $value = $cansubsearch ? '' : wppa_test_for_search();
    $root = isset($wppa_session['search_root']) ? $wppa_session['search_root'] : '';
    $fontsize = wppa('in_widget') ? 'font-size: 9px;' : '';
    $mocc = wppa('mocc');
    wppa_dbg_msg('Root=' . $root . ': ' . wppa_get_album_name($root));
    $result = '
	<form' . ' id="wppa_searchform_' . $mocc . '"' . ' action="' . $pagelink . '"' . ' method="post"' . ' class="widget_search"' . ' >
		<div>' . $label . ($cansubsearch ? '<small>' . $wppa_session['display_searchstring'] . '<br /></small>' : '') . '<input' . ' type="text"' . ' class="wppa-search-input"' . ' style="width:60%;"' . ' name="wppa-searchstring"' . ' id="wppa_s-' . $mocc . '"' . ' value="' . $value . '"' . ' />' . '<input' . ' id="wppa_searchsubmit-' . $mocc . '"' . ' type="submit"' . ' name="wppa-search-submit"' . ' value="' . __a('Search') . '"' . ' onclick="if ( document.getElementById( \'wppa_s-' . $mocc . '\' ).value == \'\' ) return false;"' . ' />' . '<input' . ' type="hidden"' . ' name="wppa-searchroot"' . ' value="' . $root . '"' . ' />' . ($canrootsearch ? '<div style="' . $fontsize . '" >
					<input type="checkbox" name="wppa-rootsearch" ' . $rootboxset . ' /> ' . __a('Search in current section') . '</div>' : '') . ($cansubsearch ? '<div style="' . $fontsize . '" >
					<input type="checkbox" name="wppa-subsearch" ' . $subboxset . '/> ' . __a('Search in current results') . '</div>' : '') . '</div>
	</form>';
    return $result;
}
function wppa_initialize_runtime($force = false)
{
    global $wppa;
    global $wppa_opt;
    global $wppa_revno;
    global $wppa_api_version;
    global $wpdb;
    global $wppa_initruntimetime;
    global $wppa_defaults;
    $wppa_initruntimetime = -microtime(true);
    if ($force) {
        $wppa = false;
        // destroy existing arrays
        $wppa_opt = false;
        delete_option('wppa_cached_options');
    }
    if (is_array($wppa) && !$force) {
        return;
        // Done already
    }
    if (!is_array($wppa)) {
        $wppa = array('debug' => false, 'revno' => $wppa_revno, 'api_version' => $wppa_api_version, 'fullsize' => '', 'enlarge' => false, 'occur' => '0', 'mocc' => '0', 'widget_occur' => '0', 'in_widget' => false, 'is_cover' => '0', 'is_slide' => '0', 'is_slideonly' => '0', 'is_slideonlyf' => '0', 'is_filmonly' => '0', 'film_on' => '0', 'browse_on' => '0', 'name_on' => '0', 'desc_on' => '0', 'numbar_on' => '0', 'single_photo' => '', 'is_mphoto' => '0', 'start_album' => '', 'align' => '', 'src' => false, 'portrait_only' => false, 'in_widget_linkurl' => '', 'in_widget_linktitle' => '', 'in_widget_timeout' => '0', 'ss_widget_valign' => '', 'album_count' => '0', 'thumb_count' => '0', 'out' => '', 'auto_colwidth' => false, 'permalink' => '', 'rendering_enabled' => false, 'tabcount' => '0', 'comment_id' => '', 'comment_photo' => '0', 'comment_user' => '', 'comment_email' => '', 'comment_text' => '', 'no_default' => false, 'in_widget_frame_height' => '', 'in_widget_frame_width' => '', 'user_uploaded' => false, 'current_album' => '0', 'searchstring' => wppa_test_for_search(), 'searchresults' => '', 'any' => false, 'ajax' => false, 'error' => false, 'iptc' => false, 'exif' => false, 'is_topten' => false, 'topten_count' => '0', 'is_lasten' => false, 'lasten_count' => '0', 'is_featen' => false, 'featen_count' => '0', 'start_photo' => '0', 'is_single' => false, 'is_landing' => '0', 'is_comten' => false, 'comten_count' => '0', 'is_tag' => false, 'photos_only' => false, 'albums_only' => false, 'page' => '', 'geo' => '', 'continue' => '', 'is_upload' => false, 'ajax_import_files' => false, 'ajax_import_files_done' => false, 'ajax_import_files_error' => '', 'last_albums' => false, 'last_albums_parent' => '0', 'is_multitagbox' => false, 'is_tagcloudbox' => false, 'taglist' => '', 'tagcols' => '2', 'is_related' => false, 'related_count' => '0', 'is_owner' => '', 'is_upldr' => '', 'no_esc' => false, 'front_edit' => false, 'is_autopage' => false, 'is_cat' => false, 'bestof' => false, 'is_subsearch' => false, 'is_rootsearch' => false, 'is_superviewbox' => false, 'is_searchbox' => false, 'may_sub' => false, 'may_root' => false, 'links_no_page' => array('none', 'file', 'lightbox', 'lightboxsingle', 'fullpopup'), 'shortcode_content' => '', 'is_remote' => false, 'is_supersearch' => false, 'supersearch' => '', 'is_mobile' => wppa_is_mobile(), 'rel' => get_option('wppa_lightbox_name') == 'wppa' ? 'data-rel' : 'rel', 'lbtitle' => get_option('wppa_lightbox_name') == 'wppa' ? 'data-lbtitle' : 'title', 'alt' => 'even');
    }
    $wppa_opt = get_option('wppa_cached_options', false);
    if (!is_array($wppa_opt)) {
        wppa_set_defaults();
        $wppa_opt = $wppa_defaults;
        foreach (array_keys($wppa_opt) as $option) {
            $optval = get_option($option, 'nil');
            if ($optval !== 'nil') {
                $wppa_opt[$option] = $optval;
            }
        }
        update_option('wppa_cached_options', $wppa_opt);
    }
    if (isset($_GET['debug']) && wppa_switch('wppa_allow_debug')) {
        $key = $_GET['debug'] ? $_GET['debug'] : E_ALL;
        $wppa['debug'] = $key;
    }
    wppa_load_language();
    // Delete obsolete spam
    $spammaxage = wppa_opt('wppa_spam_maxage');
    if ($spammaxage != 'none') {
        $time = time();
        $obsolete = $time - $spammaxage;
        $iret = $wpdb->query($wpdb->prepare("DELETE FROM `" . WPPA_COMMENTS . "` WHERE `status` = 'spam' AND `timestamp` < %s", $obsolete));
        if ($iret) {
            wppa_update_option('wppa_spam_auto_delcount', get_option('wppa_spam_auto_delcount', '0') + $iret);
        }
    }
    // Create an album if required
    if (wppa_switch('wppa_grant_an_album') && wppa_switch('wppa_owner_only') && is_user_logged_in() && (current_user_can('wppa_upload') || wppa_switch('wppa_user_upload_on'))) {
        $owner = wppa_get_user('login');
        $user = wppa_get_user(wppa_opt('wppa_grant_name'));
        $albs = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `owner` = %s", $owner));
        if (!$albs) {
            // make an album for this user
            $name = $user;
            if (is_admin()) {
                $desc = __('Default photo album for', 'wppa') . ' ' . $user;
            } else {
                $desc = __a('Default photo album for') . ' ' . $user;
            }
            $parent = wppa_opt('wppa_grant_parent');
            $id = wppa_create_album_entry(array('name' => $name, 'description' => $desc, 'a_parent' => $parent));
            wppa_flush_treecounts($parent);
            wppa_index_add('album', $id);
        }
    }
    $wppa_initruntimetime += microtime(true);
}
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;
}
function wppa_session_start()
{
    global $wpdb;
    global $wppa_session;
    // If the session table does not yet exist on activation
    if (!wppa_table_exists(WPPA_SESSION)) {
        $wppa_session['id'] = '0';
        return false;
    }
    $lifetime = 3600;
    // Sessions expire after one hour
    $expire = time() - $lifetime;
    // Is session already started?
    $session = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_SESSION . "` WHERE `session` = %s AND `status` = 'valid' LIMIT 1", wppa_get_session_id()), ARRAY_A);
    // Started but expired?
    if ($session) {
        if ($session['timestamp'] < $expire) {
            $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_SESSION . "` SET `status` = 'expired' WHERE `id` = %s", $session['id']));
            $session = false;
        }
    }
    // Get data if valid session exists
    $data = $session ? $session['data'] : false;
    // No valid session exists, start new
    if ($data === false) {
        $iret = wppa_create_session_entry(array());
        if (!$iret) {
            // Failed, retry after 1 sec.
            sleep(1);
            $iret = wppa_create_session_entry(array());
            if (!$iret) {
                wppa_log('Err', 'Unable to create session for user ' . wppa_get_user());
                // Give up
                return false;
            } else {
                wppa_log('Obs', 'Session ' . $iret . ' created after 1 retry for user ' . wppa_get_user());
            }
        }
        $wppa_session = array();
        $wppa_session['page'] = '0';
        $wppa_session['ajax'] = '0';
        $wppa_session['id'] = $iret;
        $wppa_session['user'] = wppa_get_user();
    } else {
        $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_SESSION . "` SET `count` = %s WHERE `id` = %s", $session['count'] + '1', $session['id']));
        $data_arr = unserialize($data);
        if (is_array($data_arr)) {
            $wppa_session = $data_arr;
        } else {
            $wppa_session = array();
        }
    }
    // Get info for root and sub search
    if (isset($_REQUEST['wppa-search-submit'])) {
        $wppa_session['rootbox'] = wppa_get_get('rootsearch') || wppa_get_post('rootsearch');
        $wppa_session['subbox'] = wppa_get_get('subsearch') || wppa_get_post('subsearch');
        if ($wppa_session['subbox']) {
            if (isset($wppa_session['use_searchstring'])) {
                $t = explode(',', $wppa_session['use_searchstring']);
                foreach (array_keys($t) as $idx) {
                    $t[$idx] .= ' ' . wppa_test_for_search('at_session_start');
                    $t[$idx] = trim($t[$idx]);
                    $v = explode(' ', $t[$idx]);
                    $t[$idx] = implode(' ', array_unique($v));
                }
                $wppa_session['use_searchstring'] = ' ' . implode(',', array_unique($t));
            } else {
                $wppa_session['use_searchstring'] = wppa_test_for_search('at_session_start');
            }
        } else {
            $wppa_session['use_searchstring'] = wppa_test_for_search('at_session_start');
        }
        if (isset($wppa_session['use_searchstring'])) {
            $wppa_session['use_searchstring'] = trim($wppa_session['use_searchstring'], ' ,');
            $wppa_session['display_searchstring'] = str_replace(',', ' &#8746 ', str_replace(' ', ' &#8745 ', $wppa_session['use_searchstring']));
        }
    }
    // Add missing defaults
    $defaults = array('has_searchbox' => false, 'rootbox' => false, 'search_root' => '', 'subbox' => false, 'use_searchstring' => '', 'display_searchstring' => '', 'supersearch' => '', 'superview' => 'thumbs', 'superalbum' => '0', 'page' => '0', 'ajax' => '0', 'user' => '', 'id' => '0', 'uris' => array(), 'isrobot' => false);
    $wppa_session = wp_parse_args($wppa_session, $defaults);
    ksort($wppa_session);
    $wppa_session['page']++;
    if (isset($_SERVER['REQUEST_URI'])) {
        $wppa_session['uris'][] = date_i18n("g:i") . ' ' . $_SERVER['REQUEST_URI'];
        if (stripos($_SERVER['REQUEST_URI'], '/robots.txt') !== false) {
            $wppa_session['isrobot'] = true;
        }
    }
    wppa_save_session();
    return true;
}
function wppa_reset_occurrance()
{
    global $wppa;
    global $wppa_revno;
    global $wppa_api_version;
    global $thumbs;
    $thumbs = false;
    wppa_cache_thumb('invalidate');
    wppa_cache_album('invalidate');
    $mocc = isset($wppa['mocc']) ? $wppa['mocc'] : '0';
    $occ = isset($wppa['occur']) ? $wppa['occur'] : '0';
    $wocc = isset($wppa['widget_occur']) ? $wppa['widget_occur'] : '0';
    $rend = isset($wppa['rendering_enabled']) ? $wppa['rendering_enabled'] : false;
    $debug = isset($wppa['debug']) ? $wppa['debug'] : false;
    $wppa = array('debug' => $debug, 'revno' => $wppa_revno, 'api_version' => $wppa_api_version, 'fullsize' => '', 'enlarge' => false, 'occur' => $occ, 'mocc' => $mocc, 'widget_occur' => $wocc, 'in_widget' => false, 'is_cover' => '0', 'is_slide' => '0', 'is_slideonly' => '0', 'is_slideonlyf' => '0', 'is_filmonly' => '0', 'film_on' => '0', 'browse_on' => '0', 'name_on' => '0', 'desc_on' => '0', 'numbar_on' => '0', 'single_photo' => '', 'is_mphoto' => '0', 'is_xphoto' => '0', 'start_album' => '', 'align' => '', 'src' => false, 'portrait_only' => false, 'in_widget_linkurl' => '', 'in_widget_linktitle' => '', 'in_widget_timeout' => '0', 'ss_widget_valign' => '', 'album_count' => '0', 'thumb_count' => '0', 'out' => '', 'auto_colwidth' => false, 'permalink' => '', 'rendering_enabled' => $rend, 'tabcount' => '0', 'comment_id' => '', 'comment_photo' => '0', 'comment_user' => '', 'comment_email' => '', 'comment_text' => '', 'no_default' => false, 'in_widget_frame_height' => '', 'in_widget_frame_width' => '', 'current_album' => '0', 'searchstring' => wppa_test_for_search(), 'searchresults' => '', 'any' => false, 'ajax' => false, 'error' => false, 'iptc' => false, 'exif' => false, 'is_topten' => false, 'topten_count' => '0', 'is_lasten' => false, 'lasten_count' => '0', 'is_featen' => false, 'featen_count' => '0', 'start_photo' => '0', 'is_single' => false, 'is_landing' => '0', 'is_comten' => false, 'comten_count' => '0', 'is_tag' => false, 'photos_only' => false, 'albums_only' => false, 'medals_only' => false, 'page' => '', 'geo' => '', 'continue' => '', 'is_upload' => false, 'ajax_import_files' => false, 'ajax_import_files_done' => false, 'ajax_import_files_error' => '', 'last_albums' => false, 'last_albums_parent' => '0', 'is_multitagbox' => false, 'is_tagcloudbox' => false, 'taglist' => '', 'tagcols' => '2', 'is_related' => false, 'related_count' => '0', 'is_owner' => '', 'is_upldr' => '', 'no_esc' => false, 'front_edit' => false, 'is_autopage' => false, 'is_cat' => false, 'bestof' => false, 'is_subsearch' => false, 'is_rootsearch' => false, 'is_superviewbox' => false, 'is_searchbox' => false, 'may_sub' => false, 'may_root' => false, 'links_no_page' => array('none', 'file', 'lightbox', 'lightboxsingle', 'fullpopup'), 'shortcode_content' => '', 'is_remote' => false, 'is_supersearch' => false, 'supersearch' => '', 'is_mobile' => wppa_is_mobile(), 'rel' => get_option('wppa_lightbox_name') == 'wppa' ? 'data-rel' : 'rel', 'lbtitle' => get_option('wppa_lightbox_name') == 'wppa' ? 'data-lbtitle' : 'title', 'alt' => 'even', 'is_wppa_tree' => false, 'is_calendar' => false, 'calendar' => '', 'caldate' => '', 'calendarall' => false, 'reverse' => false, 'current_photo' => false, 'is_stereobox' => false, 'npages' => '', 'curpage' => '', 'ss_pag' => false, 'slideframewidth' => '', 'slideframeheight' => '', 'ajax_import_files_error' => '', 'src_script' => '', 'is_url' => false, 'is_inverse' => false, 'coverphoto_pos' => '', 'forceroot' => '', 'landingpage' => '', 'is_admins_choice' => false, 'admins_choice_users' => '', 'for_sm' => false, 'max_width' => false);
}
function wppa_session_start()
{
    global $wpdb;
    global $wppa_session;
    // If the session table does not yet exist on activation
    if (!wppa_table_exists(WPPA_SESSION)) {
        $wppa_session['id'] = '0';
        return false;
    }
    // Cleanup first
    $lifetime = 3600;
    // Sessions expire after one hour
    $savetime = 3600;
    // Save session data for 1 hour
    $expire = time() - $lifetime;
    $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_SESSION . "` SET `status` = 'expired' WHERE `timestamp` < %s", $expire));
    $purge = time() - $savetime;
    $wpdb->query($wpdb->prepare("DELETE FROM `" . WPPA_SESSION . "` WHERE `timestamp` < %s", $purge));
    // Is session already started?
    $session = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_SESSION . "` WHERE `session` = %s AND `status` = 'valid' LIMIT 1", wppa_get_session_id()), ARRAY_A);
    $data = $session ? $session['data'] : false;
    // Not started yet, setup session
    if ($data === false) {
        $iret = false;
        $tries = '0';
        while (!$iret && $tries < '10') {
            $iret = wppa_create_session_entry(array());
            if (!$iret) {
                sleep(1);
                $tries++;
            }
        }
        if ($tries > '3' && $iret) {
            wppa_log('Debug', 'It took ' . $tries . ' retries to start session ' . $iret);
        }
        if (!$iret) {
            wppa_log('Error', 'Unable to create session.');
            return false;
        }
        $wppa_session = array();
        $wppa_session['page'] = '0';
        $wppa_session['ajax'] = '0';
        $wppa_session['id'] = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . WPPA_SESSION . "` WHERE `session` = %s LIMIT 1", wppa_get_session_id()));
        $wppa_session['user'] = wppa_get_user();
    } else {
        $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_SESSION . "` SET `count` = %s WHERE `id` = %s", $session['count'] + '1', $session['id']));
        $data_arr = unserialize($data);
        if (is_array($data_arr)) {
            $wppa_session = $data_arr;
        } else {
            $wppa_session = array();
        }
    }
    // Get info for root and sub search
    if (isset($_REQUEST['wppa-search-submit'])) {
        $wppa_session['rootbox'] = wppa_get_get('rootsearch') || wppa_get_post('rootsearch');
        $wppa_session['subbox'] = wppa_get_get('subsearch') || wppa_get_post('subsearch');
        if ($wppa_session['subbox']) {
            if (isset($wppa_session['use_searchstring'])) {
                $t = explode(',', $wppa_session['use_searchstring']);
                foreach (array_keys($t) as $idx) {
                    $t[$idx] .= ' ' . wppa_test_for_search('at_session_start');
                    $t[$idx] = trim($t[$idx]);
                    $v = explode(' ', $t[$idx]);
                    $t[$idx] = implode(' ', array_unique($v));
                }
                $wppa_session['use_searchstring'] = ' ' . implode(',', array_unique($t));
            } else {
                $wppa_session['use_searchstring'] = wppa_test_for_search('at_session_start');
            }
        } else {
            $wppa_session['use_searchstring'] = wppa_test_for_search('at_session_start');
        }
        if (isset($wppa_session['use_searchstring'])) {
            $wppa_session['use_searchstring'] = trim($wppa_session['use_searchstring'], ' ,');
            $wppa_session['display_searchstring'] = str_replace(',', ' &#8746 ', str_replace(' ', ' &#8745 ', $wppa_session['use_searchstring']));
        }
    }
    // Add missing defaults
    $defaults = array('has_searchbox' => false, 'rootbox' => false, 'search_root' => '', 'subbox' => false, 'use_searchstring' => '', 'display_searchstring' => '', 'supersearch' => '', 'superview' => 'thumbs', 'superalbum' => '0', 'page' => '0', 'ajax' => '0', 'user' => '', 'id' => $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . WPPA_SESSION . "` WHERE `session` = %s LIMIT 1", wppa_get_session_id())));
    $wppa_session = wp_parse_args($wppa_session, $defaults);
    ksort($wppa_session);
    $wppa_session['page']++;
    wppa_save_session();
    return true;
}