Hello

July 30, 2010, 05:22:04 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?
Login with username, password and session length
What sNews Is: - sNews is a simple, basic, customizable CMS tool suitable for developers with beginner-to-advanced PHP skills. It is also useful to have a good working knowledge of how to work with, set up and manage MySQL databases. sNews is not - geared towards the end-user who knows little or nothing about building and developing PHP-MySQL based websites.
News: Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.
 
   Home   Help Search Login Register  
Pages: [1] 2 3
  Print  
Author Topic: [MOD] Function use in articles (snews1.6)  (Read 10197 times)
philmoz
High flyer
Administrator
ULTIMATE member
******

Karma: 150
Posts: 1836



WWW
« 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

Take offs are optional, landings are mandatory, unless you get into space, then you have other issues.
danfascia
Newbie
*

Karma: 0
Posts: 10


« 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
Administrator
ULTIMATE member
******

Karma: 150
Posts: 1836



WWW
« 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

Take offs are optional, landings are mandatory, unless you get into space, then you have other issues.
Sven
ULTIMATE member
******

Karma: 72
Posts: 1816


Chasing MY bugs!


WWW
« 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?
Logged

Patric Ahlqvist
Nobodys perfect, but Im pretty effing close
Administrator
ULTIMATE member
******

Karma: 64
Posts: 4903


“I'm a self-made man and worships my creator.”


WWW
« 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 Wink
Logged

My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs
philmoz
High flyer
Administrator
ULTIMATE member
******

Karma: 150
Posts: 1836



WWW
« Reply #5 on: September 13, 2007, 10:13:54 AM »

eh-hem  Embarrassed

ok, I've corrected the instructions...  Roll Eyes
Logged

Take offs are optional, landings are mandatory, unless you get into space, then you have other issues.
Sven
ULTIMATE member
******

Karma: 72
Posts: 1816


Chasing MY bugs!


WWW
« Reply #6 on: September 13, 2007, 10:54:15 AM »

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

Fred K (agentsmith)
sNews Dude
ULTIMATE member
*****

Karma: 92
Posts: 2256


da- dadadaaaa


« 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? Cool
Logged

ki11
Newbie
*

Karma: 1
Posts: 11


« Reply #8 on: November 06, 2007, 04:29:39 AM »

Great one!

But you forgot one little thing:

Code:
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
Administrator
ULTIMATE member
******

Karma: 150
Posts: 1836



WWW
« 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

Take offs are optional, landings are mandatory, unless you get into space, then you have other issues.
codetwist
Hero Member
*****

Karma: 50
Posts: 955


« Reply #10 on: November 06, 2007, 07:47:48 AM »

@philmoz : He is saying about little thing ... namely, 'title' aka 'parameters' Wink They are missing in Your js code.
Logged
philmoz
High flyer
Administrator
ULTIMATE member
******

Karma: 150
Posts: 1836



WWW
« 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

Take offs are optional, landings are mandatory, unless you get into space, then you have other issues.
ki11
Newbie
*

Karma: 1
Posts: 11


« 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
Administrator
ULTIMATE member
******

Karma: 150
Posts: 1836



WWW
« 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

Take offs are optional, landings are mandatory, unless you get into space, then you have other issues.
codetwist
Hero Member
*****

Karma: 50
Posts: 955


« 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 Wink So, Your code should be ok  Grin
Logged
Pages: [1] 2 3
  Print  
 
Jump to:  

English Steel 1.6 © Saxon North Technologies
Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!