Пример #1
0
function wppa_add_wppa_on_page()
{
    global $wppa_first_id;
    // Feature enabled?
    if (!wppa_switch('js_css_optional')) {
        return;
    }
    // Init
    $pages = wppa_index_string_to_array(get_option('wppa_on_pages_list'));
    $ID = get_the_ID();
    $doit = false;
    // Check for the current ID
    if ($ID) {
        if (!in_array($ID, $pages)) {
            $pages[] = $ID;
            $doit = true;
        }
    }
    // Check for the first encountered ID that may not need wppa. Mark it as it is now the first post on a page, but posts further on the page will going to need it
    if ($wppa_first_id) {
        if (!in_array($wppa_first_id, $pages)) {
            $pages[] = $wppa_first_id;
            $doit = true;
        }
    }
    if ($doit) {
        sort($pages, SORT_NUMERIC);
        update_option('wppa_on_pages_list', wppa_index_array_to_string($pages));
        echo '<script type="text/javascript" >document.location.reload(true);</script>';
    }
}
function wppa_index_quick_remove($type, $id)
{
    global $wpdb;
    if ($type == 'album') {
        $album = wppa_cache_album($id);
        $words = stripslashes($album['name']) . ' ' . stripslashes($album['description']) . ' ' . $album['cats'];
        $words = wppa_index_raw_to_words($words);
        foreach ($words as $word) {
            $indexline = $wpdb->get_row("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` = '" . $word . "'", ARRAY_A);
            $array = wppa_index_string_to_array($indexline['albums']);
            foreach (array_keys($array) as $k) {
                if ($array[$k] == $id) {
                    unset($array[$k]);
                    $string = wppa_index_array_to_string($array);
                    if ($string || $indexline['photos']) {
                        $wpdb->query("UPDATE `" . WPPA_INDEX . "` SET `albums` = '" . $string . "' WHERE `id` = " . $indexline['id']);
                    } else {
                        $wpdb->query("DELETE FROM `" . WPPA_INDEX . "` WHERE `id` = " . $indexline['id']);
                    }
                }
            }
        }
    } elseif ($type == 'photo') {
        $thumb = wppa_cache_thumb($id);
        // Find the raw text
        $words = stripslashes($thumb['name']) . ' ' . $thumb['filename'] . ' ' . stripslashes($thumb['description']) . ' ' . $thumb['tags'];
        $coms = $wpdb->get_results($wpdb->prepare("SELECT `comment` FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s AND `status` = 'approved'", $thumb['id']), ARRAY_A);
        if ($coms) {
            foreach ($coms as $com) {
                $words .= ' ' . stripslashes($com['comment']);
            }
        }
        $words = wppa_index_raw_to_words($words, 'noskips');
        foreach ($words as $word) {
            $indexline = $wpdb->get_row("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` = '" . $word . "'", ARRAY_A);
            $array = wppa_index_string_to_array($indexline['photos']);
            foreach (array_keys($array) as $k) {
                if ($array[$k] == $id) {
                    unset($array[$k]);
                    $string = wppa_index_array_to_string($array);
                    if ($string || $indexline['albums']) {
                        $wpdb->query("UPDATE `" . WPPA_INDEX . "` SET `photos` = '" . $string . "' WHERE `id` = " . $indexline['id']);
                    } else {
                        $wpdb->query("DELETE FROM `" . WPPA_INDEX . "` WHERE `id` = " . $indexline['id']);
                    }
                }
            }
        }
    }
}
Пример #3
0
function wppa_do_maintenance_popup($slug)
{
    global $wpdb;
    global $thumb;
    $result = '';
    switch ($slug) {
        case 'wppa_list_index':
            $start = get_option('wppa_list_index_display_start', '');
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_INDEX . "`");
            $indexes = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` >= %s ORDER BY `slug` LIMIT 1000", $start), ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of Searcheable words <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($indexes) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th><span style="float:left;" >Word</span></th>
							<th style="max-width:400px;" ><span style="float:left;" >Albums</span></th>
							<th><span style="float:left;" >Photos</span></th>
						</tr>
						<tr><td colspan="3"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($indexes as $index) {
                    $result .= '
						<tr>
							<td>' . $index['slug'] . '</td>
							<td style="max-width:400px; word-wrap: break-word;" >' . $index['albums'] . '</td>
							<td>' . $index['photos'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no index items.', 'wppa');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_errorlog':
            $filename = WPPA_CONTENT_PATH . '/wppa-depot/admin/error.log';
            $result .= '
				<h2>List of WPPA+ error messages <small>( Newest first )</small></h2>
				<div style="float:left; clear:both; width:100%; overflow:auto; word-wrap:none; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if (!($file = @fopen($filename, 'r'))) {
                $result .= __('There are no error log messages', 'wppa');
            } else {
                $size = filesize($filename);
                $data = fread($file, $size);
                $messages = explode("\n", $data);
                $count = count($messages);
                $idx = $count - '2';
                while ($idx >= '0') {
                    $msg = $messages[$idx];
                    $msg = htmlspecialchars(strip_tags($msg));
                    // Security fix
                    $result .= $msg . '<br />';
                    $idx--;
                }
            }
            $result .= '
				</div><div style="clear:both;"></div>
				';
            break;
        case 'wppa_list_rating':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_RATING . "`");
            $ratings = $wpdb->get_results("SELECT * FROM `" . WPPA_RATING . "` ORDER BY `timestamp` DESC LIMIT 1000", ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of recent ratings <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($ratings) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Timestamp</th>
							<th>Date/time</th>
							<th>Status</th>
							<th>User</th>
							<th>Value</th>
							<th>Photo id</th>
							<th></th>
							<th># ratings</th>
							<th>Average</th>
						</tr>
						<tr><td colspan="10"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($ratings as $rating) {
                    wppa_cache_thumb($rating['photo']);
                    $result .= '
						<tr>
							<td>' . $rating['id'] . '</td>
							<td>' . $rating['timestamp'] . '</td>
							<td>' . ($rating['timestamp'] ? wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $rating['timestamp']) : 'pre-historic') . '</td>
							<td>' . $rating['status'] . '</td>
							<td>' . $rating['user'] . '</td>
							<td>' . $rating['value'] . '</td>
							<td>' . $rating['photo'] . '</td>
							<td style="width:250px; text-align:center;"><img src="' . wppa_get_thumb_url($rating['photo']) . '" 
								style="height: 40px;" 
								onmouseover="jQuery(this).stop().animate({height:this.naturalHeight}, 200);"
								onmouseout="jQuery(this).stop().animate({height:\'40px\'}, 200);" /></td>
							<td>' . $thumb['rating_count'] . '</td>
							<td>' . $thumb['mean_rating'] . '</td>
						</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no ratings', 'wppa');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        case 'wppa_list_session':
            $total = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_SESSION . "` WHERE `status` = 'valid'");
            $sessions = $wpdb->get_results("SELECT * FROM `" . WPPA_SESSION . "` WHERE `status` = 'valid' ORDER BY `id` DESC LIMIT 1000", ARRAY_A);
            $result .= '
			<style>td, th { border-right: 1px solid darkgray; } </style>
			<h2>List of active sessions <small>( Max 1000 entries of total ' . $total . ' )</small></h2>
			<div style="float:left; clear:both; width:100%; overflow:auto; background-color:#f1f1f1; border:1px solid #ddd;" >';
            if ($sessions) {
                $result .= '
				<table>
					<thead>
						<tr>
							<th>Id</th>
							<th>Session id</th>
							<th>User</th>
							<th>Rs</th>
							<th>Started</th>
							<th>Count</th>
							<th>Page</th>
							<th>Ajax</th>
							<th>Albums viewed</th>
							<th>Photos viewed</th>
							<th>Search string</th>
							<th>root</th>
							<th>sub</th>
							<th>Superview</th>
						</tr>
						<tr><td colspan="14"><hr /></td></tr>
					</thead>
					<tbody>';
                foreach ($sessions as $session) {
                    $data = unserialize($session['data']);
                    $result .= '
							<tr>
								<td>' . $session['id'] . '</td>
								<td>' . $session['session'] . '</td>
								<td>' . $session['user'] . '</td>
								<td>' . $data['randseed'] . '</td>
								<td style="text-wrap:none;" >' . wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $session['timestamp']) . '</td>
								<td>' . $session['count'] . '</td>
								<td>' . (isset($data['page']) ? $data['page'] : '') . '</td>
								<td>' . (isset($data['ajax']) ? $data['ajax'] : '') . '</td>
								<td>' . (isset($data['album']) ? wppa_index_array_to_string(array_keys($data['album'])) : '') . '</td>
								<td>' . (isset($data['photo']) ? wppa_index_array_to_string(array_keys($data['photo'])) : '') . '</td>
								<td>' . (isset($data['use_searchstring']) ? $data['use_searchstring'] : '') . '</td>
								<td style="text-wrap:unrestricted; max-width:300px;" >' . (isset($data['search_root']) ? $data['search_root'] . ' ' : '') . (isset($data['rootbox']) ? $data['rootbox'] ? 'on' : 'off' : '') . '</td>
								<td>' . (isset($data['subbox']) ? $data['subbox'] ? 'Y' : 'N' : '') . '</td>
								<td>' . (isset($data['superalbum']) ? $data['superalbum'] . ' ' : '') . (isset($data['superview']) ? $data['superview'] : '') . '</td>
							</tr>';
                }
                $result .= '
					</tbody>
				</table>';
            } else {
                $result .= __('There are no active sessions', 'wppa');
            }
            $result .= '
				</div><div style="clear:both;"></div>';
            break;
        default:
            $result = 'Error: Unimplemented slug: ' . $slug . ' in wppa_do_maintenance_popup()';
    }
    return $result;
}
Пример #4
0
function wppa_compress_enum($enum)
{
    $result = $enum;
    if (strpos($enum, '.') !== false) {
        $result = explode('.', $enum);
        sort($result, SORT_NUMERIC);
        $old = '-99';
        foreach (array_keys($result) as $key) {
            // Remove dups
            if ($result[$key] == $old) {
                unset($result[$key]);
            } else {
                $old = $result[$key];
            }
        }
        $result = wppa_index_array_to_string($result);
        $result = str_replace(',', '.', $result);
    }
    $result = trim($result, '.');
    return $result;
}