Advertisement:

Author Topic: Where to put persistent code?  (Read 1458 times)

Offline BinkyM

  • Semi-Newbie
  • *
  • Posts: 49
  • Gender: Female
  • I've been running forums since 1987 (not a typo!).
    • @lilMMAsweetie on Twitter
    • Snarkish
Where to put persistent code?
« on: April 23, 2012, 05:55:58 PM »
Hi, SMF peeps:

I have a script I'd like to be available nearly all the time. Where's a good place to put it? I'm thinking in the file wherever the footer is kept. Is that a good place? I did some grepping of my SMF files and it appears that the footer happens in a file called index.template.php in my theme directory. Is that a good place to put a script I'd like to be persistent?

(I'm an SMF neophyte, so please excuse me if I come across like a boob.)

Thanks for a tip,

Binky

Online 4Kstore

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 3,453
  • Gender: Male
  • |-|Principito|-|
    • agustintari on Facebook
    • @agustintarifa on Twitter
    • SSIMPLE TEAM PAGE
Re: Where to put persistent code?
« Reply #1 on: April 23, 2012, 06:13:21 PM »
Hi binkyM, if the code is a function you can put in load.php o subs.php (in sources file), You can call the function from anywhere
If the code is a script you can add in index.template.php in the header section.

Maybe you can add more information and i can help better..
Bye!

Offline MrPhil

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,652
Re: Where to put persistent code?
« Reply #2 on: April 23, 2012, 07:53:04 PM »
Please clarify what this script is, and how you want it 'available'. Is it a standalone page or shell script, or is it code to be stuck inside some part of SMF (additional function on the page)? How are you thinking of invoking it -- as part of SMF or something completely on its own? If it's standalone, just give it a nonguessable name and stick it in your site root. If it's meant to interact with SMF in some way, or be embedded in it, we'll need to know a lot more about it.
Please do not PM me with support questions, unless I ask you to. Unsolicited PMs for support will be ignored. It's best to have questions and answers in public, so others can research a problem and learn about it without having to ask the question yet again. Thank you!
FAQs | SMF 1.1 fixes | Project ideas
-= From the ashes shall rise a sooty tern =-

Offline Labradoodle-360

  • Developer
  • SMF Super Hero
  • *
  • Posts: 11,470
  • Gender: Male
    • matthew.kerle on Facebook
    • @matthew_kerle on Twitter
Re: Where to put persistent code?
« Reply #3 on: April 24, 2012, 11:03:48 AM »
Yeah, we need to know more about "this script". SMF uses an MVC (Model-View-Controller) meaning source is separated from template.

The quality of the responses received is directly proportional to the quality of the question asked. | My Modifications

Offline BinkyM

  • Semi-Newbie
  • *
  • Posts: 49
  • Gender: Female
  • I've been running forums since 1987 (not a typo!).
    • @lilMMAsweetie on Twitter
    • Snarkish
Re: Where to put persistent code?
« Reply #4 on: April 28, 2012, 02:50:19 PM »
MrPhil and Labradoodle:

One script is an Amazon code snippet such that I can make reference to an Amazon product any time I want to. The other is VGlink code that links to a product when it finds a word in a post that's linkable and I can make some scratch if a user clicks the link).

Is 4kStore right that  load.php and subs.php are good places to stick that code? They look good at a cursory glance.

Binky

Offline Labradoodle-360

  • Developer
  • SMF Super Hero
  • *
  • Posts: 11,470
  • Gender: Male
    • matthew.kerle on Facebook
    • @matthew_kerle on Twitter
Re: Where to put persistent code?
« Reply #5 on: April 28, 2012, 03:51:42 PM »
Yeah, I typically place my code right below $context['insert_after_template'] = ''; or detectBrowser(); in Load.php, depending on what I'm needing to add.

If you need to add something to <head> you can add your code right after $context['html_headers'] = ''; or detectBrowser();, if you need to add something to the bottom of the actual body tag, you can add your script to $context['insert_after_template'] .= ''; (after it's primary definition).

The quality of the responses received is directly proportional to the quality of the question asked. | My Modifications

Offline BinkyM

  • Semi-Newbie
  • *
  • Posts: 49
  • Gender: Female
  • I've been running forums since 1987 (not a typo!).
    • @lilMMAsweetie on Twitter
    • Snarkish
Re: Where to put persistent code?
« Reply #6 on: April 28, 2012, 07:27:50 PM »
Okay, thanks, Doodle! Then I'm gonna go start making some money! (grin) Especially since I can't seem to put Amazon's crappy-ass iframes anywhere else. I'm gonna miss those; they've been a fair source of of income for seven years, so it's gonna be painful putting in text links instead. But we'll see how this goes. I appreciate your help, men!

Binky

Offline Labradoodle-360

  • Developer
  • SMF Super Hero
  • *
  • Posts: 11,470
  • Gender: Male
    • matthew.kerle on Facebook
    • @matthew_kerle on Twitter
Re: Where to put persistent code?
« Reply #7 on: April 29, 2012, 12:44:11 AM »
Not a problem, topic solved? Good luck :)

The quality of the responses received is directly proportional to the quality of the question asked. | My Modifications

Offline BinkyM

  • Semi-Newbie
  • *
  • Posts: 49
  • Gender: Female
  • I've been running forums since 1987 (not a typo!).
    • @lilMMAsweetie on Twitter
    • Snarkish
Re: Where to put persistent code?
« Reply #8 on: April 30, 2012, 11:39:09 AM »
Yes, topic solved! I'm a happy admin now!

Offline Labradoodle-360

  • Developer
  • SMF Super Hero
  • *
  • Posts: 11,470
  • Gender: Male
    • matthew.kerle on Facebook
    • @matthew_kerle on Twitter
Re: Where to put persistent code?
« Reply #9 on: April 30, 2012, 12:21:28 PM »
Glad to hear it :) Good luck!

The quality of the responses received is directly proportional to the quality of the question asked. | My Modifications