News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Custom action for redirect board

Started by HunterP, April 08, 2018, 05:55:34 AM

Previous topic - Next topic

HunterP

Dear SMF coders,

On my forum, I'm using the redirect board for one specific purpose and would like to attach a custom action on that redirect, so this action becomes visible on Who Is Online.

Any suggestions maybe? Just something basic like "This user has been redirected" will help me a lot :)

(using SMF 2.0.15)

Doug Heffernan

It is a little unclear to me what you are asking. Can you post a couple of screenshots?

HunterP


Sorry, ok, let me try to clarify. When creating a new board, you can define it as 'redirect', so you will be send to a different URL. When checking Who Is Online, that user will be shown as viewing the previous board. I would like to see the redirect shown as action, in the Who.language file I would like to have something linke :

$txt['whoall_redirect'] = 'User has been redirected';

Any idea if that is possible?

Doug Heffernan

Quote from: HunterP on April 08, 2018, 09:06:45 AM

Sorry, ok, let me try to clarify. When creating a new board, you can define it as 'redirect', so you will be send to a different URL. When checking Who Is Online, that user will be shown as viewing the previous board. I would like to see the redirect shown as action, in the Who.language file I would like to have something linke :

$txt['whoall_redirect'] = 'User has been redirected';

Any idea if that is possible?

Yes, that can work if you want to change only the text at the online list for that particular action.

HunterP


Well, there is no existing action for this. That's my question, can this be modified into an action? The redirect just diverts to a different site, it performs no action from SMF point of view.

Doug Heffernan

Quote from: HunterP on April 08, 2018, 09:27:19 AM

Well, there is no existing action for this. That's my question, can this be modified into an action? The redirect just diverts to a different site, it performs no action from SMF point of view.

I thought that you wanted to change the text only for the online list. Anyway, whatever you are looking for to achieve can be done with custom coding.

Kindred

If the user is viewing a url with the custom action= statement and that action is defined in the action index in who.php, then th user will be shown performing that action.
The only way the user would not be shown as doing that action is if the action was not defined.

So, your issue is not the redirect, your issue is defining the custom action in the array.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

HunterP

Quote from: Kindred on April 08, 2018, 11:11:11 AM
If the user is viewing a url with the custom action= statement and that action is defined in the action index in who.php, then th user will be shown performing that action.
The only way the user would not be shown as doing that action is if the action was not defined.

So, your issue is not the redirect, your issue is defining the custom action in the array.

I think the issue is still not clear. I don't have any action defined, this is default SMF redirect. I would like to know how the redirect can become visible in the Who is Online list?

Illori

i know i have seen before people "viewing" the SMF Online Manual board here, i think that is the only way to know that the user is viewing the redirect board. i am not sure there is really any other way to know they are being redirected.

HunterP


The redirect is performed via MessageIndex :

// If this is a redirection board head off.
if ($board_info['redirect'])
{
   $smcFunc['db_query']('', '
      UPDATE {db_prefix}boards
      SET num_posts = num_posts + 1
      WHERE id_board = {int:current_board}',
      array(
         'current_board' => $board,
      )
   );
   redirectexit($board_info['redirect']);
}

I was hoping there might be a way to set the current action for that user, without performing the action.
The only thing that actually has to be performed is the last line. Is the last action stored DB-wise?

HunterP

Ok, found out that this is logged in the log_online table, in the url column. At the point of the redirect, there is no action present in 'url'. Now, I would like to fetch the url for this user, add the action and update the table. So far, it's not working yet. Without modifying the string, I just fetch it and UPDATE it. Am I doing something wrong? I get a server error :

$request = $smcFunc['db_query']('', '
SELECT url
FROM {db_prefix}log_online
WHERE id_member = {int:current_member}
LIMIT 1',
array(
'current_member' => $user_info['id'],
)
);
$url = $smcFunc['db_fetch_assoc']($request);
$smcFunc['db_free_result']($request);

$smcFunc['db_query']('', '
UPDATE {db_prefix}log_online
SET log_time = {int:log_time}, url = {string:url}
WHERE id_member = {int:current_member}',
array(
'log_time' => time(),
'url' => $url,
'current_member' => $user_info['id'],
)
);

Kindred

I already told you -- the action has to be defined in the action array in who.php

you said that you have users performing a custom action...   
every call to action= should be logged already
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

HunterP

Quote from: Kindred on April 09, 2018, 07:11:03 AM
I already told you -- the action has to be defined in the action array in who.php

you said that you have users performing a custom action...   
every call to action= should be logged already

No; that is not the case.

There is no custom action. I want a default SMF function to be turned into an action. By default, SMF offers the option for redirect boards. It's not a board on the forum, it redirects to a different URL. That is a basic SMF feature. But, somewhere it seems logically, it does not trigger an action on the forum, so SMF cannot show it's status, other than "viewing this board" which was the last action logged for this user.

So once again; if the basis redirect option is used; I would like this to be turned into (it's not yet) a custom action, so Who Is Online can show who used one of the redirect boards.

I hope it's more clear now?

Kindred

You are using the wrong terms, which is why this seems confusing.

A custom action means a specific thing...  it means code specifically added to use th action array, hence the reference I was making to action=customaction

If you just want the redirect board to point to a separate url, outside of smf...  you will never get the log or the usersonline to track it...   it won't work. That only tracks actions inside of smf.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

HunterP


Sorry for the confusion, English is not my main language...

I understand what you mean, but is there no possibility to set an action just before leaving to the redirect site? Worst case (as I was trying), SELECTing this users status from log_online, fetch the current URL (which does not contain an action), and add this action=redirect?

When I check this url column in the DB, I see lines like :

a:3:{s:5:"board";i:150;s:10:"USER_AGENT";s:114:"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36";}

Can't I just UPDATE this url to :

a:4:{s:6:"action";s:8"redirect";s:5:"board";i:150;s:10:"USER_AGENT";s:114:"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36";}

The user will leave the forum and others will see "This user has been redirected" (for example).

But when I fetch this url, I can't manage to read it the same way as phpMyAdmin does. When I echo the string it just shows "Array". Maybe I'm just making a stupid mistake since this seems to be an array stored as a string, but how can I handle this information after selecting it from DB and modify/add? I already tried searching in the other source files but couldn't find anything similar...

Kindred

well, for one, that array is malformed. needs to be

s:8:"redirect", not s:8"redirect"

for two... is s8 even a defined argument in the array?
you left s5 as "board" which I don't think is valid either...
Basically, you are trying to do something that the system is not intended to do.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

HunterP


Sorry... The second line was my mistake, I added the extra arguments manually. The first line comes straight from DB. Or at least, that is what phpMyAdmin shows me.

It's pretty sure that 'hacking' this value is not the best thing to do, but more like a work around. If I don't break the format (so don't forget the : as in my example :) ) it shouldn't be an issue, or should it?

Leaves me still how to import the array into something readable, I didn't work that out yet...

Pipke

example:
if your action is called test (?action=test) otherwise replace the word test with your current action.

in Who.template.php

find

foreach ($context['members'] as $member)
{


replace with:

foreach ($context['members'] as $member)
{
if ($member['query']['action'] === 'test')
$member['action'] = 'testing testing';
"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

HunterP

Thanks for the reply, but once again; there is no action. That is the main problem. I'm trying to deal with a default SMF option which does not set an action I would like to force SMF to make it into an action.

Anyways, I won't rest until this is fixed :) No matter if I hack the code into something it's not intended to; I really don't care. For me it's nothing but the result that counts. I want to be able to see who is being redirected and the only thing I need to know is how to (correctly) edit the url column in log_online. If succeed on that, I'm done. It's just a string that needs to be modified, but in the end it's all about the format, making SMF able to deal with it.

Thanks so far. If anyone thinks (s)he can be able to help me; please :) In the meanwhile I will try and search outside this forum and will mark the topic as solved once I reached my goal ;)

Pipke

what is the redirect url being called? this could help.

"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Advertisement: