Author Topic: [MOD] - Comment users sessions  (Read 8894 times)

0 Members and 1 Guest are viewing this topic.

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
[MOD] - Comment users sessions
« on: August 31, 2007, 03:04:52 AM »
Hi, I create MOD for comment users sessions. Each user visit image can see session in detail foreach image ID (live) if post comment (and all poster of each image ID where session active). 8)

If image active - show.
If image no active - no show.
If user invisible - show * (same includes/sessions.php file). No show for user (is admin).
If user no post comment, no see in comment session. If post 1st, start see. ;)
No HTML in PHP - all HTML template.

/* New - [08/31/2007]: There are currently . . . xxx add. */ ;)

Test: Mr_LovaLove

// Step 1

In details.php file,

find:

Code: [Select]
// Update Hits
if ($user_info['user_level'] != ADMIN) {
  $sql = "UPDATE ".IMAGES_TABLE."
          SET image_hits = image_hits + 1
          WHERE image_id = $image_id";
  $site_db->query($sql);
}

add after:

Code: [Select]
// MOD: Comment users sessions.
$comment_time_out = time() - 300;
$comment_guest_level_sessions_counter = 0;

$additional_sql = "";
$additional_sql_array = array();
if (isset($additional_user_fields) && is_array($additional_user_fields) && !empty($additional_user_fields)) {
    foreach ($additional_user_fields as $key => $val) {
        $additional_sql .= ", u." . $key;
        $additional_sql_array[] = $key;
    }
}

if (function_exists('get_comment_sessions_info') && $user_info['user_level'] == GUEST) {
    get_comment_sessions_info($site_sess->session_id, 'check_sessions_table');
}

if (function_exists('get_comment_sessions_info') && $user_info['user_level'] >= USER) {
    get_comment_sessions_info($user_info['user_id'], 'check_sessions_table');
}

$sql1 = "

SELECT s.session_user_id" . get_user_table_field(", u.", "user_name") . get_user_table_field(", u.", "user_level") . get_user_table_field(", u.", "user_invisible") . $additional_sql . "
FROM (" . COMMENTS_TABLE . " c, " . SESSIONS_TABLE . " s, " . COMMENTS_SESSIONS_TABLE . " ist)
LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = s.session_user_id)
WHERE ist.user_id = c.user_id AND c.user_id = s.session_user_id AND c.image_id = " . $image_id . " AND ist.comment_notify_microtime >= " . $comment_time_out . " AND s.session_user_id > '" . GUEST . "'
GROUP BY s.session_user_id
ORDER BY " . get_user_table_field("u.", "user_id") . " ASC, s.session_ip ASC";

$sessions_comment_result = $site_db->query($sql1);
$comment_num_rows = $site_db->get_numrows($sessions_comment_result);

if (isset($comment_num_rows) && $comment_num_rows > 0) {

$comment_sessions_template = "";

$comment_invisible_sessions_counter = 0;
$comment_registered_users_sessions_counter = 0;
while ($sessions_comment_row = $site_db->fetch_array($sessions_comment_result)) {
    if ($sessions_comment_row[$user_table_fields['user_invisible']] == 1) {
        $comment_invisible_sessions_counter++;
    }
    if ($sessions_comment_row[$user_table_fields['user_level']] >= USER) {
        $comment_registered_users_sessions_counter++;
    }
    $session_comment_user_id = $sessions_comment_row['session_user_id'];
    $session_comment_name = $sessions_comment_row[$user_table_fields['user_name']];
    $session_comment_invisible = $sessions_comment_row[$user_table_fields['user_invisible']];
    
    $site_template->register_vars(array(
    "session_comment_user_url" => $site_sess->url(ROOT_PATH . "member.php?action=showprofile&" . URL_USER_ID . "=" . $session_comment_user_id),
    "session_comment_user_id" => (int)$session_comment_user_id,
    "session_comment_name" => format_text(stripslashes($session_comment_name), 2),
    "session_comment_invisible" => ($session_comment_invisible == 1) ? 1 : 0,
    "invisible_comment_chars" => $lang['comments_notify_invisible_chars'],
    "need_separator" => (isset($comment_num_rows) && $comment_num_rows > 1) ? true : false
    ));
    
    if (isset($additional_sql_array) && is_array($additional_sql_array) && !empty($additional_sql_array)) {
        foreach ($additional_sql_array as $key => $val) {
            if ($val == $sessions_comment_row[$val]) {
                $site_template->register_vars($val, $sessions_comment_row[$val]);
            }
        }
    }
    $comment_sessions_template .= $site_template->parse_template("comment_sessions_content");
    
    }
    }
    
    $sql2 = "
    
    SELECT s.session_user_id" . $additional_sql . "
    FROM (" . COMMENTS_TABLE . " c, " . SESSIONS_TABLE . " s, " . COMMENTS_SESSIONS_TABLE . " ist)
    LEFT JOIN " . USERS_TABLE . " u ON (" . get_user_table_field("u.", "user_id") . " = s.session_user_id)
    WHERE ist.user_id = c.user_id AND c.user_id = s.session_user_id AND c.image_id = " . $image_id . " AND ist.comment_notify_microtime >= " . $comment_time_out . " AND s.session_user_id = '" . GUEST . "'
    GROUP BY s.session_ip";
    
    $sessions_guest_comment_result = $site_db->query($sql2);
    $sessions_guest_num_rows = $site_db->get_numrows($sessions_guest_comment_result);
    
    if (isset($sessions_guest_num_rows) && $sessions_guest_num_rows > 0) {
        while ($sessions_comment_guest_row = $site_db->fetch_array($sessions_guest_comment_result)) {
            $comment_guest_level_sessions_counter++;
        }
    }
    $total_comment_sessions = $comment_registered_users_sessions_counter + $comment_guest_level_sessions_counter;

// End of MOD: Comments users sessions.

Find:

Code: [Select]
"lang_file_size" => $lang['file_size'],  

add after:

Code: [Select]
// MOD: Comment users sessions.
  "lang_comment_notify_sessions_title" => $lang['comments_notify_sessions_title'],  
  "lang_comment_notify_current_sessions_title" => $lang['comments_notify_current_sessions_title'],
  "comment_sessions_template" => (isset($comment_sessions_template)) ? trim($comment_sessions_template) : "",    
  "sessions_comment_no_content_msg" => (isset($sessions_comment_no_content_msg)) ? $sessions_comment_no_content_msg : "",
  "total_invisible_comment_sessions" => (isset($comment_invisible_sessions_counter)) ? preg_replace("/" . $site_template->start . "invisible_count" . $site_template->end . "/siU", (int)$comment_invisible_sessions_counter, $lang['comments_notify_invisible_count']) : preg_replace("/" . $site_template->start . "invisible_count" . $site_template->end . "/siU", 0, $lang['comments_notify_invisible_count']),
  "total_registered_users_comment_sessions" => (isset($comment_registered_users_sessions_counter)) ? preg_replace("/" . $site_template->start . "registered_users_count" . $site_template->end . "/siU", (int)$comment_registered_users_sessions_counter, $lang['comments_notify_registered_users_count']) : preg_replace("/" . $site_template->start . "registered_users_count" . $site_template->end . "/siU", 0, $lang['comments_notify_registered_users_count']),
  "total_guest_level_comment_sessions" => (isset($comment_guest_level_sessions_counter)) ? preg_replace("/" . $site_template->start . "guest_level_count" . $site_template->end . "/siU", (int)$comment_guest_level_sessions_counter, $lang['comments_notify_guest_level_count']) : preg_replace("/" . $site_template->start . "guest_level_count" . $site_template->end . "/siU", 0, $lang['comments_notify_guest_level_count']),
  "total_comment_sessions" => (isset($total_comment_sessions)) ? (int)$total_comment_sessions : false,
  // End of MOD: Comment users sessions.

// Step 2

In lang/english/main.php file,

add top ?>:

Code: [Select]
// MOD: Comments sessions.
//-----------------------------------------------------
//--- Comments sessions -------------------------------
//-----------------------------------------------------
$lang['comments_notify_count'] = "Total: {count}";
$lang['comments_notify_sessions_title'] = "Currently active comment users: ";
$lang['comments_notify_no_sessions_content'] = "No comment users sessions found.";
$lang['comments_notify_invisible_chars'] = "*";
$lang['comments_notify_current_sessions_title'] = "There are currently ";
$lang['comments_notify_registered_users_count'] = "<b>{registered_users_count}</b> registered user(s) ";
$lang['comments_notify_invisible_count'] = "({invisible_count} among them invisible) ";
$lang['comments_notify_guest_level_count'] = "and <b>{guest_level_count}</b> guest(s) online.";

// Step 3

In templates/your_template, create: comment_sessions_content.html .

Add:

Code: [Select]
{if is_admin}{if session_comment_invisible}<a href="{session_comment_user_url}"><b>{session_comment_name}</b></a>{invisible_comment_chars}{if need_separator}, {endif need_separator}&nbsp;{endif session_comment_invisible}{endif is_admin}
{if user_loggedin}{ifnot session_comment_invisible}<a href="{session_comment_user_url}"><b>{session_comment_name}</b></a>{if need_separator}, {endif need_separator}&nbsp;{endifnot session_comment_invisible}{endif user_loggedin}

// Step 4

In templates/your_template/details.html file,

find:

Code: [Select]
{if allow_comments}
<a name="comments"></a>
<br />

add after:

Code: [Select]
 
{if is_admin}<! -- Comment users sessions -- >{endif is_admin}
 {if comment_allow_read}  
<table width="100%" border="0" cellpadding="0" cellspacing="0">
                          <tr>
                            <td valign="top" class="head1">&nbsp;{lang_comment_notify_sessions_title} {total_comment_sessions}</td>
 </tr>
   </table>
 <table width="100%" border="0" cellpadding="0" cellspacing="0">
 <tr>  
   <td class="row1">&nbsp;{lang_comment_notify_current_sessions_title} {total_registered_users_comment_sessions} {total_invisible_comment_sessions} {total_guest_level_comment_sessions}</td>
 </tr>
    </table>
 <table width="100%" border="0" cellpadding="0" cellspacing="0">
 <tr>
  {if comment_sessions_template}<td width="100%" class="row1" />&nbsp;{comment_sessions_template}</td>{endif comment_sessions_template}
  {if sessions_comment_no_content_msg}{if allow_image_read}<td width="100%" class="row1" align="center" /><b>{sessions_comment_no_content_msg}</b></td>{endif allow_image_read}{endif sessions_comment_no_content_msg}
 </tr>  
                        </table>  
         {endif comment_allow_read}
 <br />
 {if is_admin}<! -- End of comment users sessions -- >{endif is_admin}

// Step 5

In includes/functions.php file,

add top ?>:

Code: [Select]
// MOD: Comment sessions user.
function get_comment_sessions_info($user_id = -1, $status = "") {
    global $site_db, $session_info, $image_id, $user_table_fields, $table_prefix;    

    if (!isset($user_id) || $user_id == -1) {
        return;
    }    

    if (!isset($status) || $status == "") {
        return;
    }    

    if (isset($user_id) && $user_id > 0) {
        $user_id = preg_replace("/[^0-9]+/i", "", $user_id);

        if ($user_row = get_user_info($user_id)) {
            if ($user_id != $user_row[$user_table_fields['user_id']]) {
                return;
            }
            unset ($user_row);
        }
        $status = preg_replace("/[^A-Za-z0-9\_]+/i", "", $status);

        

        $date = date('Y-m-d');
        $time = date('H:i:s');
        $microtime = time();        

        switch($status) {            

            case 'check_sessions_table' :            

            if (!defined('COMMENTS_SESSIONS_TABLE')) {                
                define('COMMENTS_SESSIONS_TABLE', $table_prefix . "comments_sessions");
            }              

                $sql = "              

                CREATE TABLE IF NOT EXISTS " . COMMENTS_SESSIONS_TABLE . " (
                field_id INT(11) NOT NULL AUTO_INCREMENT,
                user_id VARCHAR(32) NOT NULL DEFAULT '0',
                image_id INT(11) NOT NULL DEFAULT '0',
                comment_notify_date VARCHAR(48) NOT NULL DEFAULT '0000-00-00',
                comment_notify_time VARCHAR(48) NOT NULL DEFAULT '00:00:00',
                comment_notify_microtime VARCHAR(255) NOT NULL DEFAULT '0',
                comment_notify_ip VARCHAR(48) NOT NULL DEFAULT '0.0.0.0',
                PRIMARY KEY (field_id)
                ) TYPE=MyISAM;              

                ";              

                $result = $site_db->query($sql);

                $sql = "SELECT user_id, image_id FROM " . COMMENTS_SESSIONS_TABLE . " WHERE user_id = " . $user_id . " AND image_id = " . $image_id;
                $result = $site_db->query($sql);
                $num_rows = $site_db->get_numrows($result);
                
                if (isset($num_rows) && $num_rows <= 0) {
                    
                    $comment_sessions_ip = $session_info['session_ip'];

                    $sql1 = "                  

                    INSERT INTO " . COMMENTS_SESSIONS_TABLE . "
                    (field_id, user_id, image_id, comment_notify_date, comment_notify_time, comment_notify_microtime, comment_notify_ip)
                    VALUES (NULL, '" . $user_id . "', '" . $image_id . "', '" . $date . "', '" . $time . "', '" . $microtime . "', '" . $comment_sessions_ip . "')

                    ";                  

                    $result = $site_db->query($sql1);                    
                }
                
                $get_sessions_microtime = $microtime - 300;
                
                if (isset($num_rows) && $num_rows > 0) {                    
                        $site_db->query("DELETE FROM " . COMMENTS_SESSIONS_TABLE . " WHERE comment_notify_microtime < " . $get_sessions_microtime);
                        //$site_db->query("UPDATE " . COMMENTS_SESSIONS_TABLE . " SET comment_notify_microtime = '" . $microtime . "', image_id = '" . $image_id . "' WHERE user_id = '" . $user_id . "'");
                }
                
                return $user_id;
                break;        
        }
    }
}
// End of MOD: Comment sessions user.

// Step 6

In includes/constants.php file,

find:

Code: [Select]
define('COMMENTS_TABLE', $table_prefix.'comments');

add after:

Code: [Select]
define('COMMENTS_SESSIONS_TABLE', $table_prefix.'comments_sessions');

// Step 7 (09/09/2007)

In includes/sessions.php file,

find:

Quote
$this->current_time = time();

add before:

Code: [Select]
$this->current_date = date('Y-m-d');
$this->current_clocktime = date('H:i:s');

Find:

Quote
function logout($user_id) {
    global $site_db;
    $sql = "DELETE FROM ".SESSIONS_TABLE."
            WHERE session_id = '".addslashes($this->session_id)."' OR session_user_id = " . $user_id;
    $site_db->query($sql);
  
    $this->set_cookie_data("userpass", "", 0);
    $this->set_cookie_data("userid", GUEST);

    $this->session_info = array();

    return true;
  }

replace:

Code: [Select]
function logout($user_id) {
    global $site_db;
    $sql = "DELETE FROM ".SESSIONS_TABLE."
            WHERE session_id = '".addslashes($this->session_id)."' OR session_user_id = " . $user_id;
    $site_db->query($sql);    
    $sql = "DELETE FROM " . COMMENTS_SESSIONS_TABLE . "
            WHERE user_id = '" . addslashes($this->session_id) ."' OR user_id = " . $user_id;
    $site_db->query($sql);
    
    $this->set_cookie_data("userpass", "", 0);
    $this->set_cookie_data("userid", GUEST);

    $this->session_info = array();

    return true;
  }

Find:

Quote
function update_session() {
    global $site_db;

replace:

Code: [Select]
function update_session() {
    global $site_db, $image_id, $url;

Find:

Quote
$this->session_info['session_lastaction'] = $this->current_time;
$this->session_info['session_location'] = $this->user_location;
$this->session_info['session_ip'] = $this->user_ip;

add after:

Code: [Select]
if (preg_match("/details.php/", $url)) {
    
    $sql = "REPLACE INTO " . COMMENTS_SESSIONS_TABLE . "
            (field_id, user_id, image_id, comment_notify_date, comment_notify_time, comment_notify_microtime)
            VALUES (NULL, '" . addslashes($this->session_id) . "', '" . $image_id . "', '" . $this->current_date . "', '" . $this->current_clocktime . "', $this->current_time)
            
           ";
    $site_db->query($sql);
    
}

Find:

Quote
if ($this->user_info['user_id'] != GUEST) {
      $sql = "UPDATE ".USERS_TABLE."
              SET ".get_user_table_field("", "user_lastaction")." = $this->current_time, ".get_user_table_field("", "user_location")." = '$this->user_location'
              WHERE ".get_user_table_field("", "user_id")." = ".$this->user_info['user_id'];
      $site_db->query($sql);            
}

replace:

Code: [Select]
if ($this->user_info['user_id'] != GUEST) {
      $sql = "UPDATE ".USERS_TABLE."
              SET ".get_user_table_field("", "user_lastaction")." = $this->current_time, ".get_user_table_field("", "user_location")." = '$this->user_location'
              WHERE ".get_user_table_field("", "user_id")." = ".$this->user_info['user_id'];
      $site_db->query($sql);          
      $sql2 = "DELETE FROM " . COMMENTS_SESSIONS_TABLE . " WHERE user_id = '" . GUEST . "' AND comment_notify_ip = '" . $this->user_ip . "'";
      $site_db->query($sql2);      
}

Go details (is active for image) and see. ;)

(For fix - reset table).
« Last Edit: February 18, 2011, 01:56:44 PM by thunderstrike »
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Loda

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
    • Fotosucht Schweiz
Re: [MOD] - Comment users sessions
« Reply #1 on: August 31, 2007, 02:54:30 PM »
hi.. thanks..
realy testing?
i miss any code in the detail html..

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [MOD] - Comment users sessions
« Reply #2 on: August 31, 2007, 03:41:17 PM »
I forget step 4.  :mrgreen:
Thank for posting.

/* Fix */

- Step 1 fix (09/09/2007 (REV 5))
- Step 2 fix
- Step 3 fix (09/08/2007)
- Step 4 fix (09/08/2007)
- Step 5 fix (09/09/2007 (REV 1))

/* New step */

- Step 7 (09/09/2007 (REV 3))
« Last Edit: September 09, 2007, 05:36:24 PM by thunderstrike »
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Re: [MOD] - Comment users sessions
« Reply #3 on: September 08, 2007, 11:19:25 PM »
All finish. 8)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?