write function for plugins

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Izal

write function for plugins

Post by Izal »

I need to make my own plugin. I would do this in a UDT if it was practical but its not as it will need to be installed easily so it can be also removed easily and also I have a feature that requires the function to be in a file that is accessible to the function itself, eg it reads itself to do a check to thwart tampering.

The wiki talks about tags but not how you write the plugins, searching for writing plugins mainly points to the UDT tag writing.

I have been hacking away at plugins to see how they are written and have managed to get an empty container on the server which does not break or cause problems with site operation.
Izal

Re: write function for plugins

Post by Izal »

Really, no information exists on how you go about writing a compatible plug in....!

I have as stated been hacking away at one and would like to know why when its uploaded it breaks the tag menu in the admin side of things.

Theirs no errors, when I try the script out in my regular space and plug in some data to it, the thing outputs something, regardless of if its functioning as it is meant to, the thing output data. I guessed at the params[] array is parameters passed to the function and that &smarty is a reference to the smarty template engine.

The question remains as to why the function breaks the CMS... Do you run checks on them, do I need to register the plugin in the CMS somewhere?

I have tried the wiki, why you have it is a mystery as it has yet to tell me anything of use. Have you guys got any plans for updating it or adding useful information to it, I mean beyond descriptions and use of tags like being able to write your own plugin and I do not mean the UDT's either.
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: write function for plugins

Post by jmcgin51 »

if you're writing a tag or module, it's expected that you understand PHP and Smarty, and are familiar with the CMSMS API.  If you understand these items, writing a tag/module is just a matter of putting them all together.

If you can provide some sample code, you may get more help.

And the wiki is open to all users to add/edit/expand, so when you figure out the answer to your question, I'm sure you'll take the time to improve the wiki for the next person in your situation.
Izal

Re: write function for plugins

Post by Izal »

TBH that is a pretty unreasonable train of though when you consider that to learn you need information and to expect an individual to have prior knowledge is just not an attainable goal.

All I want to do is to get the current page URL, other items of information like what are the variables available to the function in the CMS, how do you post to the CMS using the CMS to processes to process the form or supplied data / request.

If I want to write a tag like {mytag dosomething} then how to I get the "dosomething" part of the tag? the params array appaers to be an associative array, what help is available to grab single non named entities? is it a simple case of params[0...[1...[2] etc or does some other method exist?

I already have tried a writing a function but I notice that the CMSMS does somethings that under normal PHP would not happen. A tag like {mytag start} that is meant to insert a marker with opening DIV, I find that the div is automatically closed when it shouldn't.

So I need to know information like how can that operation be surppresed?

When I examined the output of a line of code in the page output, I can see that this closing tag has been inserted, it does not form part of the template nor part of the plugin.

So information is all I need, I have no code to show other than

Code: Select all

function smarty_cms_function_mytag($params, &$smarty)
{
if( $params['start']=="START") return "<!-- MyTag START --><div id='DivID'>";
if( $params['stop']=="STOP") return "</div><!-- MyTag STOP -->";
return ""; // return nothing if no match to a tag
}
What I want to do is have tag elements that do not need a name reference.

So... if you have any pointers, I would genuinely appreciate the input.
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: write function for plugins

Post by Jos »

Maybe cmsms needs the other two functions also:

Code: Select all

function smarty_cms_help_function_mytag() {
  echo 'help';
}
and

Code: Select all

function smarty_cms_about_function_mytag() {
  echo 'about';
}
Just guessing...  8)
Last edited by Jos on Sun Feb 07, 2010 6:10 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: write function for plugins

Post by calguy1000 »

Have you read the smarty manual?  I bet not... it is REQUIRED READING!
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Izal

Re: write function for plugins

Post by Izal »

calguy1000 wrote: Have you read the smarty manual?  I bet not... it is REQUIRED READING!
THIS... Is what I am on about, WHERE..! Well now I know the name of the manual, I have looked online I find the smarty site. Unfortunately its not telling me anything about the PHP code or variables that I can access in the CMS like a search for the $gCms variable returns a blank page, its all smarty stuff, not what I need ATM.

I take it that this is what you use to get the page URL?

Code: Select all

 global $gCms;
    $hm =& $gCms->GetHierarchyManager();
    $page_content_id = $gCms->variables['content_id'];
    $curnode =& $hm->getNodeById($page_content_id);
    $curcontent =& $curnode->GetContent();
    $url = urlencode($curcontent->GetURL()); // url of current page
What other elements are available in the $gCms variable and how do I access them, easily, I hate OO at the best of times, reminds me of *ptr;

@JOS, lol, yeah they exist but I didn't include them because its obvious that they are meant to be in it also....
Jos
Support Guru
Support Guru
Posts: 4019
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: write function for plugins

Post by Jos »

Think Calguy means you should start reading here: http://www.smarty.net/manual/en/plugins.php (after you get the hang of the general smarty stuff)
Izal

Re: write function for plugins

Post by Izal »

Thanks,

a little light reading for bedtime.....
Post Reply

Return to “Developers Discussion”