function wppa_encrypt_url($url)
{
    // Feature enabled?
    if (!wppa_switch('use_encrypted_links')) {
        return $url;
    }
    // Querystring present?
    if (strpos($url, '?') === false) {
        return $url;
    }
    // Has it & 's ?
    if (strpos($url, '&') === false) {
        $hasamp = false;
    } else {
        $hasamp = true;
    }
    // Disassemble url
    $temp = explode('?', $url);
    // Has it a querystring?
    if (count($temp) == '1') {
        return $url;
    }
    // Disassemble querystring
    $qarray = explode('&', str_replace('&', '&', $temp['1']));
    // Search and replace album and photo ids by crypts
    $i = 0;
    while ($i < count($qarray)) {
        $item = $qarray[$i];
        $t = explode('=', $item);
        if (isset($t['1'])) {
            switch ($t['0']) {
                case 'wppa-album':
                case 'album':
                    if (!$t['1']) {
                        $t['1'] = '0';
                    }
                    $t['1'] = wppa_encrypt_album($t['1']);
                    if ($t['1'] === false) {
                        wppa_dbg_msg('Error: Illegal album specification: ' . $item . ' (wppa_encrypt_url)', 'red', 'force');
                        exit;
                    }
                    break;
                case 'wppa-photo':
                case 'photo':
                    $t['1'] = wppa_encrypt_photo($t['1']);
                    if ($t['1'] === false) {
                        wppa_dbg_msg('Error: Illegal photo specification: ' . $item . ' (wppa_encrypt_url)', 'red', 'force');
                        exit;
                    }
                    break;
            }
        }
        $item = implode('=', $t);
        $qarray[$i] = $item;
        $i++;
    }
    // Re-assemble url
    $temp['1'] = implode('&', $qarray);
    $newurl = implode('?', $temp);
    if ($hasamp) {
        $newurl = str_replace('&', '&amp;', $newurl);
    }
    return $newurl;
}
function wppa_album_download_link($albumid)
{
    if (!wppa_switch('allow_download_album')) {
        return;
    }
    // Not enabled
    $result = '<div style="clear:both;" ></div>' . '<a' . ' onclick="wppaAjaxDownloadAlbum(' . wppa('mocc') . ', \'' . wppa_encrypt_album($albumid) . '\' );"' . ' style="cursor:pointer;"' . ' class="wppa-album-cover-link"' . ' title="' . esc_attr(__('Download', 'wp-photo-album-plus')) . '" ' . '>' . __('Download Album', 'wp-photo-album-plus') . '</a>' . '<img' . ' id="dwnspin-' . wppa('mocc') . '-' . wppa_encrypt_album($albumid) . '"' . ' src="' . wppa_get_imgdir() . 'spinner.gif"' . ' style="margin-left:6px; display:none;"' . ' alt="spin"' . ' />';
    wppa_out($result);
}