function sm_get_pages($sort, $order, $limit = false)
{
    global $wpdb, $table_name, $user_excludes_table;
    $sm_settings = get_option('sm_settings');
    $filter = sm_get('filter');
    $sql = 'SELECT
				COUNT(t1.id) AS hits
				, t1.url
			FROM
				' . $table_name . ' t1
				' . (!$sm_settings->view_robot_hits ? ' LEFT JOIN ' . $user_excludes_table . ' t2 ON (t1.ip_address = t2.ip_address)' : '') . '
			WHERE 1 ' . ($filter ? 'AND url LIKE "%' . $filter . '%"' : '') . (!$sm_settings->view_robot_hits ? ' AND t2.id IS NULL ' : '') . '
			GROUP BY t1.url
			ORDER BY ' . $sort . ' ' . $order;
    if ($limit) {
        $sql .= ' LIMIT ' . $limit;
    }
    return $wpdb->get_results($sql);
}
<?php

echo '<div class="wrap" id="poststuff">';
if ($url = sm_get('url')) {
    $url = base64_decode($url);
    echo '<form method="POST">';
    echo sm_start_box('Session Manager - URL stats: ' . sm_shorten_url($url));
    sm_hits_by_page($url);
    echo sm_end_box();
    echo '</form>';
} else {
    if ($session_id = sm_get('session_id')) {
        echo '<form method="POST">';
        echo sm_start_box('Session Manager - Individual session stats: ' . sm_real_name($session_id, sm_get_user_by_session($session_id)));
        sm_show_session_stats($session_id);
        echo sm_end_box();
        echo '</form>';
    } else {
        if (sm_post('exclude_pages_button')) {
            sm_save_excluded_pages();
        } else {
            if (sm_post('delete_pagedata')) {
                sm_delete_pagedata();
            }
        }
        echo sm_start_box('Session Manager - Filter Controls');
        sm_render_filters('by_page');
        echo sm_end_box();
        echo '<form method="POST">';
        echo sm_start_box('Stats by page');
        sm_show_by_page();
Example #3
0
/**
 * Marca el post como que alguien lo esta leyendo
 * @param string $mypost post
 * @return void
 */
function sm_store_session_data($mypost)
{
    get_currentuserinfo();
    global $wpdb, $table_name, $current_user, $excludes_table, $user_excludes_table;
    $track = true;
    $url = $_SERVER['REQUEST_URI'];
    $sm_settings = get_option('sm_settings');
    $track_admin = $sm_settings->track_admin;
    $name = $wpdb->prefix . 'user_level';
    $user_level = $current_user->{$name};
    $user_id = (int) $current_user->id;
    if (!isset($_SESSION)) {
        session_start();
    }
    $session_id = session_id();
    $sql = 'SELECT COUNT(id)
			FROM ' . $excludes_table . '
			WHERE filename = "' . mysql_real_escape_string($url) . '"';
    $sql2 = 'SELECT COUNT(id)
			FROM ' . $user_excludes_table . '
			WHERE
				session_id = "' . $session_id . '"
				OR ip_address = "' . $_SERVER['REMOTE_ADDR'] . '"';
    if ($user_id) {
        $sql2 .= ' OR user_id = "' . $user_id . '"';
    }
    if ($wpdb->get_var($sql)) {
        //If the current page is in the list of excluded pages (eg: robots.txt, xmlrpc.php, favicon.ico)
        $track = false;
    } else {
        if ($wpdb->get_var($sql2)) {
            //If the current user/session is in the excludes table then don't track
            $track = false;
        } else {
            //Check for the admin area of the site
            if (strpos($url, 'wp-admin')) {
                //If track admin is set on the settings page
                if (!$track_admin) {
                    $track = false;
                } else {
                    //Check for the existence of the page argument in the querystring
                    if ($page = sm_get('page')) {
                        //If it mentions sm_ then don't log it
                        if (stripos($page, 'sm_') !== false) {
                            $track = false;
                            //we dont want to track hits to the session data pages.
                        }
                    }
                }
            }
        }
    }
    if ($track) {
        $sql = 'INSERT INTO ' . $table_name . ' (user_id, session_id, url, ip_address, user_agent, unixtime)
				VALUES (
					' . $user_id . '
					, "' . $session_id . '"
					, "' . $mypost . '"
					, "' . $_SERVER['REMOTE_ADDR'] . '"
					, "' . $_SERVER['HTTP_USER_AGENT'] . '"
					, UNIX_TIMESTAMP()
				)';
        $wpdb->query($sql);
        if ($user_id > 0) {
            $sql = 'UPDATE ' . $table_name . '
					SET user_id = ' . $user_id . '
					WHERE session_id = "' . $session_id . '"';
            $wpdb->query($sql);
        }
    }
}