Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: asmith on October 22, 2008, 02:25:39 AM

Title: $context[\\\'current_action\\\'] and logged time
Post by: asmith on October 22, 2008, 02:25:39 AM
hey guys

I have non-forum pages, SSI.php included.

I've checked if someone is visitign page x.html , the forum says he is viewing the index board of the site.
How can i make it so that the forum says he is visiting x.html ?

I played a little with $context['current_action'] on the x.html , before and after including SSI ,But has no success.


same with total time logged. When the user is in the x.html page, he total time logged won't increase, How can i achieve that too?

Thanks

SMF 1.1.6
Title: Re: $context['current_action'] and logged time
Post by: asmith on October 24, 2008, 05:39:03 AM
*bump*
Title: Re: $context['current_action'] and logged time
Post by: [SiNaN] on October 24, 2008, 11:54:13 AM
To make forum to count the SSI page as online too, add this code after you include SSI.php:

writeLog();

To make forum to recognize where you are, add this code before you include SSI.php:

$_GET['action'] = 'my_page';

Then add this at the end of your Who.template.php file:

$txt['whoall_my_page] = 'He\'s viewing my page.';
Title: Re: $context['current_action'] and logged time
Post by: asmith on October 24, 2008, 12:41:53 PM
Thanks for replying man,  I got the members visiting pages right.

But total time logged still doesn't work.

I added writeLog(); after SSI being included, and stayed in some pages for like 2-3 mins , and refreshed, still no change, any idea?
Title: Re: $context['current_action'] and logged time
Post by: [SiNaN] on October 25, 2008, 04:43:12 AM
I see, total time online won't increase if you are using SSI.

Subs.php

Find:

if (SMF != 'SSI' && !empty($user_info['last_login']) && $user_info['last_login'] < time() - 60)

Replace:

if (!empty($user_info['last_login']) && $user_info['last_login'] < time() - 60)

Do not forget this edit, you may need to take it back for upgrades.
Title: Re: $context['current_action'] and logged time
Post by: asmith on October 25, 2008, 08:34:18 AM
it worked! I cannot believe it :D

Thanks man, Don't know how to thank you, Thanks A TON!
Title: Re: $context[\'current_action\'] and logged time
Post by: Deprecated on October 25, 2008, 09:18:36 AM
Great advice Sinan! I've copied notes from this topic and I'm sure I'm going to need it before long. :)
Title: Re: $context[\'current_action\'] and logged time
Post by: virtualxtc on October 25, 2008, 06:53:49 PM
Quote from: [SiNaN] on October 24, 2008, 11:54:13 AM
To make forum to count the SSI page as online too, add this code after you include SSI.php:

writeLog();

To make forum to recognize where you are, add this code before you include SSI.php:

$_GET['action'] = 'my_page';

Then add this at the end of your Who.template.php file:

$txt['whoall_my_page] = 'He\'s viewing my page.';


Just wondering if this script is good for use in SMF V2?
Title: Re: $context[\'current_action\'] and logged time
Post by: [SiNaN] on October 26, 2008, 04:00:54 AM
It should be.
Title: Re: $context[\\\'current_action\\\'] and logged time
Post by: asmith on October 28, 2008, 06:38:45 AM
seems I got a problem with "who's online"  .

my non forum files work like this :

index.php?file=file1 

so I have $_GET['file'] .
I've tested it, it works WHEN there's no $_GET variable set, meaning when I'm on my home page where there's no $_GET variable it works,

BUT when i'm in the index.php?file=file1 , it says I'm on index of forum page which means it kinda has been disabled.

What's wrong with it?
Title: Re: $context['current_action'] and logged time
Post by: asmith on October 29, 2008, 01:28:05 PM
*bump*
Title: Re: $context['current_action'] and logged time
Post by: [SiNaN] on November 01, 2008, 09:18:58 AM
Would having a single action for all SSI pages work for you?
Title: Re: $context['current_action'] and logged time
Post by: asmith on November 01, 2008, 09:56:59 AM
unfortunately no. 
I have a lot of SSI pages. That their $_GET['action'] are all different.

What should I ? I'll go down that road, just tell me :)
Title: Re: $context['current_action'] and logged time
Post by: [SiNaN] on November 04, 2008, 07:39:37 AM
Well, let's try this.

Subs.php

Find:

function writeLog($force = false)

Replace:

function writeLog($force = false, $ssi_action = null)

Find:

$serialized = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);

Replace:

$serialized = $_GET + array('USER_AGENT' => $_SERVER['HTTP_USER_AGENT']);
if (!empty($ssi_action))
$serialized['action'] = $ssi_action;


Then in your SSI included file, use writeLog(false, 'action_you_want_to_be_save'); instead of just writeLog();. Example: writeLog(false, 'my_page);
Title: Re: $context['current_action'] and logged time
Post by: asmith on November 04, 2008, 01:47:05 PM
It worked ! FINALLY ! I don't know what to say :D

just to sum it up for others :

do exactly as [SiNaN] said. but remember the  $_GET['action'] = 'my_page'; and the $txt['whoall_my_pages'] = 'He\'s viewing the page';

must be in their places still.

[SiNaN], Dont' know how to thank you. It was driving me crazy!
Thanks!

P.S  (I promise it is the last one :D ) If a page has its own variable,for example , 
we are both visiting  "edit" page and you are editing "A" team stat, I'm editing "B" team stat. something like the way forum do wit topics .

I want it to say : SiNaN is editing "A" team stat.
                           Asmith is editing "B" team stat.

how should I pass "A" or "B" to $txt variable? something to do with those %s  ?
Title: Re: $context['current_action'] and logged time
Post by: [SiNaN] on November 22, 2008, 12:21:13 PM
This might work:

Who.php

Find:

// An action any old fellow can look at. (if ['whoall_' . $action] exists, we know everyone can see it.)

Replace:

elseif (substr($actions['action'], 0, 8) == 'my_page_')
$data[$k] = sprintf($txt['whoall_my_page'], substr($actions['action'], 8));
// An action any old fellow can look at. (if ['whoall_' . $action] exists, we know everyone can see it.)


Then you text string will be:

$txt['whoall_my_page'] = 'Editing "%s" team stats.';

When you set the action in SSI, set you should set it as; my_page_{team_name}

Example:

$_GET['action'] = 'my_page_A';

If you want to change 'my_page' part, you should modify the codes accordingly.
Title: Re: $context['current_action'] and logged time
Post by: asmith on November 22, 2008, 01:23:32 PM
:) Got nothing to say!

You're awsome!
btw congrats on your new nick, finally got rid of 'Extremely Depressed' ?  ;)
Title: Re: $context['current_action'] and logged time
Post by: [SiNaN] on November 22, 2008, 01:28:25 PM
Well, not really; trying to get along with it. :P

Glad that I could help and thanks. ;)
Title: Re: $context[\\\'current_action\\\'] and logged time
Post by: asmith on December 19, 2008, 10:44:01 AM
Came up with a new question :D lol this thread can never get closed !

emm does this thing we did to other pages, has any effect on "who's viewing this page" ?
You know when viewing a topic on the top it is written "asmith and 4 guests are viewing this topic" (If this option is turned on in admin of course)

How can I put it on my non-forum pages?   
I think the changes we did has something to do with this.

any idea?
Title: Re: $context[\\\'current_action\\\'] and logged time
Post by: [SiNaN] on December 23, 2008, 08:00:13 AM
You mean this causes a problem with that function? I don't think so.
Title: Re: $context[\\\'current_action\\\'] and logged time
Post by: asmith on December 24, 2008, 02:48:25 PM
No, it is working perfect.

I mean, this thing we can make it on in admin page that it show which people are watching a topic. for example it says on the top of the topic :    Blue Dream, Asmith and 4 guests are viewing this  topic.

I thought maybe I could put such thing on my non-forum pages. Is there a function for that ?  If not maybe I can do it by writing an script with logs table?
I'm checking with you if there's a better way with smf functions, rather than I write an script myself in eahc page, checking the data in logs table.
Title: Re: $context[\\\'current_action\\\'] and logged time
Post by: [SiNaN] on December 26, 2008, 09:06:47 AM
Yeah, you can do that. You can cheat from SMF. Look for "// Nosey, nosey - who's viewing this topic?" line and the block under it, in MessadIndex.php file. You will see the codes to fetch who's viewing.
Title: Re: $context[\\\'current_action\\\'] and logged time
Post by: spartacussing on January 18, 2010, 11:44:25 AM
WARNING!!

After beating my head for a few days  (which made a surprising change, I can tell you!) I found out my problem!

I tried to add some custom actions to the who's online thing, but found they were not showing up!

I found with some trial and error, that if I set the action to something that was already in the who.english.... file, that THOSE actions were reflected in the who's online, and then...

:( grrr.... YOU HAVE TO CLEAR THE CACHE!!!!!

index.php?action=admin;area=maintain;sa=routine;activity=cleancache