Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Pages: [1] 2 3

Author Topic: [MOD] Function use in articles (snews1.6)  (Read 28862 times)

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] Function use in articles (snews1.6)
« on: May 18, 2007, 03:00:58 am »

Function use in articles ver 1.00

This mod will allow the insertion of functions found in snews.php, directly into your articles when using the editor in admin.
This mod will allow the submission of any parameters that the original function requires

Locate //FILE INCLUSION
place the following just after
$fulltext = substr($text, 0, $shorten);
Quote from: function include()
/*article function*/
    $ins = strpos($fulltext, '[/func]');
    if ($ins > 0) {
        $text = str_replace('[func]', '|&|', $fulltext);
        $text = str_replace('[/func]', '|&|', $text);
        $text = explode('|&|', $text);$num=count($text)-1;$i=1;
        while ($i <= $num) {
        $func = explode(':|:',$text[$i]);
        ob_start();
        $returned = call_user_func_array($func[0],explode(',',$func[1]));
        $text[$i]= ob_get_clean();
        if (empty($text[$i])){$text[$i]=$returned;}
         $i=$i+2;
        }
        $fulltext = implode($text);
    }
/*end article function*/
locate
// basic html textarea editor
and directly after case 'break': start = '[break]'; end = ''; break;
add
Quote from: JS textarea editor
case 'func':// adding function insertion
   url = prompt("<?php echo l('function'); ?>", '');// function name no brackets
   title = prompt("<?php echo l('parameters'); ?>", ""); //params, seperated by comma.
   start = url !=null ? '[func]'+url+':|:' : ''; // start
   end = '[\/func]';// and end tag
   break;
To add the button in the editor,
place the following in //ARTICLES FORM
(possibly just after echo html_input('button', 'include', ...)
Quote from: form_articles() for editor button
echo html_input('button', 'func', '', 'Function', '', 'button', 'onclick="tag(\'func\')"', '', '', '', '', '', '', '', '');
then place the following in language function
Quote from: language
$l['function']='Function Name - no brackets.';
$l['parameters']='Parameters - if more than one required, separate with a comma. Do not use quotes for empty parameters.';
« Last Edit: September 13, 2007, 10:12:51 am by philmoz »
Logged
Of all the things I have lost, it is my mind that I miss the most.

danfascia

  • Newbie
  • *
  • Karma: 0
  • Posts: 10
[MOD] Function use in articles (snews1.6)
« Reply #1 on: June 12, 2007, 05:53:46 pm »

@philmoz

I like this plugin as I see it having a lot of potential. At the moment all I'm using it for is placing a recent articles link in the article body itself but I'm keen to see if it's possible to create more dynamic content with it.

Can you access any php function, so that an include() could be called for example?

I wonder if you would also mind explaining the syntax as I find the :|: a little confusing
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] Function use in articles (snews1.6)
« Reply #2 on: June 13, 2007, 01:25:22 pm »

Quote from: danfascia
@philmoz

I like this plugin as I see it having a lot of potential. At the moment all I'm using it for is placing a recent articles link in the article body itself but I'm keen to see if it's possible to create more dynamic content with it.

Can you access any php function, so that an include() could be called for example?

I wonder if you would also mind explaining the syntax as I find the :|: a little confusing
ok, syntax first... These could be anything but--

'|&|'  -- is used by snews in the include function anyway, so I used it in this. It is used when breaking the $text up, to seperate out where the function is inserted.
 ':|:'  -- This one I have the javascript inserting to seperate the name from the parameters.

Yes it could be done differently, and probably more efficiently, but hey... I like exploding things :D

The only functions you can access, are the ones defined in sNews.php. to add in an include(), simply use the include button in editor to include your file.
Logged
Of all the things I have lost, it is my mind that I miss the most.

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] Function use in articles (snews1.6)
« Reply #3 on: September 13, 2007, 08:57:20 am »

Phil, a dumber's question:
I can't locate this:
then in language function
Quote from: language
$l['function']='Function Name - no brackets.';
$l['parameters']='Parameters - if more than one required, separate with a comma. Do not use quotes for empty parameters.';
Where is it hidden?

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
Re: [MOD] Function use in articles (snews1.6)
« Reply #4 on: September 13, 2007, 09:02:11 am »

Sven, I think you'll have to put it in the snews.php then re-open it in order to find it... It's supposed to be inserted, mate ;)
Logged
"It's only dead fish that goes with the flow... "
Updated

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Re: [MOD] Function use in articles (snews1.6)
« Reply #5 on: September 13, 2007, 10:13:54 am »

eh-hem  :-[

ok, I've corrected the instructions...  ::)
Logged
Of all the things I have lost, it is my mind that I miss the most.

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] Function use in articles (snews1.6)
« Reply #6 on: September 13, 2007, 10:54:15 am »

 :-[
I sware (and I'm splittting on the floor) to never, never again, read a code when not awake.
Sorry to have disturbed pals.

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [MOD] Function use in articles (snews1.6)
« Reply #7 on: September 27, 2007, 08:00:01 pm »

I just have to say that I really like this mod. Really, really. Did I say that I like it? 8)
Logged

ki11

  • Newbie
  • *
  • Karma: 1
  • Posts: 11
Re: [MOD] Function use in articles (snews1.6)
« Reply #8 on: November 06, 2007, 04:29:39 am »

Great one!

But you forgot one little thing:

Code: [Select]
case 'func':// adding function insertion
   url = prompt("<?php echo l('function'); ?>", '');// function name no brackets
   title = prompt("<?php echo l('parameters'); ?>", ""); //params, seperated by comma.
   start = url !=null ? '[func]'+url+':|:'+title : ''; // start
   end = '[\/func]';// and end tag
   break;
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Re: [MOD] Function use in articles (snews1.6)
« Reply #9 on: November 06, 2007, 06:21:57 am »

um, I've been away for a bit.
I seem to be missing what you are saying...
Logged
Of all the things I have lost, it is my mind that I miss the most.

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Re: [MOD] Function use in articles (snews1.6)
« Reply #10 on: November 06, 2007, 07:47:48 am »

@philmoz : He is saying about little thing ... namely, 'title' aka 'parameters' ;) They are missing in Your js code.
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Re: [MOD] Function use in articles (snews1.6)
« Reply #11 on: November 06, 2007, 09:51:44 am »

They are??
I really am going screwy... so I will need this spelt out, as I still can't see what's wrong??
Logged
Of all the things I have lost, it is my mind that I miss the most.

ki11

  • Newbie
  • *
  • Karma: 1
  • Posts: 11
Re: [MOD] Function use in articles (snews1.6)
« Reply #12 on: November 06, 2007, 05:13:38 pm »

case 'func':// adding function insertion
   url = prompt("<?php echo l('function'); ?>", '');// function name no brackets
   title = prompt("<?php echo l('parameters'); ?>", ""); //params, seperated by comma.
   start = url !=null ? '[func]'+url+':|:'+title : ''; // start
   end = '[\/func]';// and end tag
   break;

You missed to add the parameters from the js as codetwist already mentioned. Nevertheless it's a really useful mod. Thank you for it.
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
Re: [MOD] Function use in articles (snews1.6)
« Reply #13 on: November 06, 2007, 09:58:55 pm »

hmmm, which raises the issue as to why I left it out...

for some reason, the parameters are repeated if I put in that title (param) tag in the js.
any suggestions as to why??
Logged
Of all the things I have lost, it is my mind that I miss the most.

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Re: [MOD] Function use in articles (snews1.6)
« Reply #14 on: November 07, 2007, 08:14:45 am »

@philmoz : Because 'title' is used later in code as well as 'start' and 'end' var-s ;) So, Your code should be ok  ;D
Logged
Pages: [1] 2 3