Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: drewactual on January 14, 2019, 08:33:47 AM

Title: injecting code on targeted posts?
Post by: drewactual on January 14, 2019, 08:33:47 AM
I've been using the script below in 2.0.15 with much success for the past year or so.  In addition to assigning different functions/items to BOARDS, I'd like to be able to do the same thing with POSTS... is it possible w/o using 'pretty urls' (if the script would even recognize pretty urls for this use anyway)?

if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '1' )  || ( isset($board) && $board == '1' )) { echo '~whatever I'm injecting on board 1~'; }

      elseif(( isset($_REQUEST['
board']) && $_REQUEST['board'] == '2' ) || ( isset($board) && $board == '2' )) {echo '~whatever I'm injecting on board 2~'; }

      elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '3' ) || ( isset($board) && $board == '3' )) {echo '~whatever I'm injecting on board 3~</div>';}

      elseif(( isset($_REQUEST['
board']) && $_REQUEST['board'] == '4' ) || ( isset($board) && $board == '4' )) { echo '~whatever I'm injecting on board 4~'; }

else {  echo 
'~whatever I'm injecting or not injecting on a non-identified board~'; }

I'd 'like' to use the same injects on messages (from display.index) so the parent(board)/child(message) have the same inject.... I realize this can be done with individual theses for each board, but I'd rather have one file to keep up with instead of having to adjust each 'theme' every time I want to implement a change. 

is this possible?

as always, thanks in advance!!!
Title: Re: injecting code on targeted posts?
Post by: vii on January 19, 2019, 09:29:12 AM
You could always put some code in Display.php - prepareDisplayContext(), right after

$message['body'] = parse_bbc($message['body'], $message['smileys_enabled'], $message['id_msg']);

to check the message ID and add your code to $message['body'] if it matches. Just have it call a function in the file you want to keep everything in.