Developing 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
tvdbon

Developing Plugins

Post by tvdbon »

I've started using CMSMadeSimple today and I just love it. The pure simplicity of it, makes everything so much better. I just have one question:

I'd like to develop some plugins/modules for it. So far I discovered that the plugins are being kept in the modules folder and I even understand how the plugins work, but If I create a new module and I add it in the modules folder under a pluginname folder will the CMS automatically pick it up or must I set it up in a table on the mysql somewhere ? Sorry if the sounds incoherent.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: Developing Plugins

Post by Ted »

tvdbon wrote:I've started using CMSMadeSimple today and I just love it. The pure simplicity of it, makes everything so much better. I just have one question:

I'd like to develop some plugins/modules for it. So far I discovered that the plugins are being kept in the modules folder and I even understand how the plugins work, but If I create a new module and I add it in the modules folder under a pluginname folder will the CMS automatically pick it up or must I set it up in a table on the mysql somewhere ? Sorry if the sounds incoherent.
Hello,

Yeah. This is still in a little bit of flux, which is why we haven't really documented it yet.

Basically, there is a mixup of terms here.

Modules = Large chunks of functionality, many having databases, and lots of options or screens
User Defined Tags = One function to provide quick functionality (these will be able to be developed in the admin in 0.6) and isn't cached (like the {php} tag would do)
Plugins = modules + user tags

Real quick overview of how modules work:

CMS looks in the modules directory and all of it's subs for files named cmsmodule.php. If it finds one, it includes it. cmsmodule.php should then set all of it's callback functions. These functions can be defined anywhere, as long as cmsmodule.php includes them before registering the functions inside. The module will only be usable if it is registered as a module in the cmsmodule.php with cms_mapi_register_module function.

Hope that helps in the interim until we have some real docs or tutorials on how to build them.

wishy
tvdbon

Developing Plugins

Post by tvdbon »

After some more digging I found what you just told me, plugins and modules are def not the same. Ok, so I understand the modules part, but what about the plugins ? I found the plugins folder and the function.filename.php, will it find those automatically as well ?

Thanks for all the info so far.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Developing Plugins

Post by Ted »

tvdbon wrote:After some more digging I found what you just told me, plugins and modules are def not the same. Ok, so I understand the modules part, but what about the plugins ? I found the plugins folder and the function.filename.php, will it find those automatically as well ?

Thanks for all the info so far.
As long as the filename and the function(s) inside match the same naming scheme (function.{name}.php and smarty_cms_function_{name}), then they will be picked up automatically.

Obviously, the 0.6 change will make this process much easier.

wishy
iNSiPiD

Re: Developing Plugins

Post by iNSiPiD »

[edit] Let me rephrase all that...

I'm having trouble getting a post variable to stick when the form gets submitted to the same page.

Is this just a problem with my coding or does the CMS perhaps dump post variables when it returns to the same page?
Last edited by iNSiPiD on Fri Jun 03, 2005 4:59 am, edited 1 time in total.
iNSiPiD

Re: Developing Plugins

Post by iNSiPiD »

Woo-hoo! Done. Oddly enough the problem did lie with my coding and the  fact that I was re-using php3 code.

What a great and simple system for adding custom code.

For anyone who's interested in seeing it in action it can be found here.

http://d81314.i50.quadrahosting.com.au/ ... act-search

Ths plugin is a search engine of one of my other databases but I see no reason why the respective tables and columns couldn't be substituted for a CMSms search plugin. If only someone more familiar with it could have a go ... [nudge nudge, wink wink] ;)

The complete code (which I'm sure could benefit from more revision) follows:

Code: Select all

<?php

function smarty_cms_function_abstracts($params, &$smarty) {

	$dsn = "###.###.###.##";
	$dbuser = "######";
	$dbpwd = "######";
	$databaseName="######";
	$conn = mysql_connect($dsn, $dbuser, $dbpwd);
	
	if(!$conn){
	echo("Unable to connect to database");
	}
	mysql_select_db($databaseName, $conn);
	
	if (!isset($_POST['confyear'])) {$confyear = date("2004");}
		else {$confyear = $_POST['confyear'];}
	
	$AbstractCountQry = "SELECT * FROM abstracts WHERE conf_year = $confyear";
	$CountRun = mysql_query($AbstractCountQry) or die ("Error in query: $AbstractCountQry " . mysql_error());
	$CountResult = mysql_num_rows($CountRun);

?>

<p><strong>Conference Abstracts Archive for:</strong> <? echo $confyear ?><br>
    <strong>Total abstracts found:</strong> <? echo $CountResult ?></p>

<form name="year" action="<? echo $_SERVER['PHP_SELF'].'?page=abstract-search' ?>" method="POST">
	<font face="Verdana, Arial" size="2">Change conference year:</font>
	<select name="confyear" onChange="submit();">
		<option value="" selected="selected"><? echo $confyear; ?></option>
	<?php
	$cyear = date("2004");
	$sqlquery = mysql_query("SELECT distinct (conf_year) as years FROM abstracts WHERE activity = 'active'", $conn) or die (mysql_error());
	$y= mysql_num_rows($sqlquery);
	
	// set the variable i to the first abstract year available
	$i= "2002";
	
	while($i<=$cyear) {
	  echo "<option value='$i'>$i</option>";
	  $i=$i+1; 
	}	
	?> 
	</select>
</form>

<form name=searchform action="<?php $_SERVER['PHP_SELF']; ?>" method=POST>
	<input type="hidden" name="confyear"  value= "<? echo $_REQUEST['confyear'] ?>" />
    <p>Select one of the search criteria below.</p>
	<p><input name=Radios type=RADIO value=1 checked />All Titles<br>
    <input name=Radios type=RADIO value=2 />By Author<br>
    <input name=Radios type=RADIO value=3 />By Title Content<br>
    <input name=Radios type=RADIO value=4 />By Abstract Content<br>
    <input name=Radios type=RADIO value=5 />By Day<br>
	<input name=Radios type=RADIO value=6 />By Institution/Organisation</p>

	<p>Keywords: <input type=textbox value='' size='40' name=MyBox style=BACKGROUND:'#FFFFCC' />
    <input type=HIDDEN name=doSearch value=doSearch />
    <input type=submit value=Search /></p>
</form>

<hr width='100%' align='center' size='1' color='#005CAB' noshade>

<?php

function performSearch() {
global $Radios, $MyBox, $selectFavorites, $confyear;

        $queryBase = "SELECT author, primary_author, title, bodytext, theme, institutes, focus, level, session_cat, abstractday, abstracttime FROM abstracts";
        $queryOrder = "ORDER BY abstractday, abstracttime , author, title";
        $queryCriteria = "";

       if( isset($Radios) )
          $strRadioValue = $Radios;
       else
          $strRadioValue = "";

       $strTextValue  = $MyBox;
       //Search by Author (keyword box)
       if( $strRadioValue == "2" && $strTextValue !="") {
          $queryCriteria = " WHERE  abstracts.conf_year = '$confyear' AND  abstracts.author LIKE '%$strTextValue%' OR abstracts.conf_year = '$confyear' AND  abstracts.primary_author LIKE '%$strTextValue%' ";
       }
       //Search by Organisation (keyword box)
       else if( $strRadioValue == "6" && $strTextValue !="") {
          $queryCriteria = " WHERE  abstracts.conf_year = '$confyear' AND  abstracts.institutes LIKE '%$strTextValue%'";
       }
       //Search by title (keyword box)
       else if ( $strRadioValue == "3" && $strTextValue !="" ) {
          $queryCriteria = " WHERE abstracts.conf_year = '$confyear' AND  abstracts.title LIKE '%$strTextValue%' ";
       }
      //Search by abtract content (keyword box)
       else if ( $strRadioValue == "4" && $strTextValue !="" ) {
          $queryCriteria = " WHERE abstracts.conf_year = '$confyear' AND  abstracts.bodytext LIKE '%$strTextValue%' ";
       }
         //Search by Day (keyword box)
       else if ( $strRadioValue == "5" && $strTextValue !="" ){
          $queryCriteria = " WHERE abstracts.conf_year = '$confyear' AND  abstracts.abstractday LIKE '%$strTextValue%' ";
       }
         //All titles with search string
       else if ( $strTextValue !="" ) {
          $queryCriteria = " WHERE abstracts.conf_year = '$confyear' AND abstracts.author LIKE '%$strTextValue%' OR abstracts.conf_year = '$confyear' AND abstracts.title LIKE '%$strTextValue%' ";
       }
         //All titles without search string
       else
       {
          $queryCriteria = " WHERE abstracts.conf_year = '$confyear' ";
       }
    
       //Execute real query   
       $strSqlQuery = $queryBase . $queryCriteria . $queryOrder;
       $result = mysql_query($strSqlQuery);
       displayResults($result);
}

function displayResults($result){
    $numRecords = mysql_num_rows($result);

	print "    <p><b>Search returned:</b> $numRecords result(s)</p>\n";
    print "    <table border=0 cellspacing=3 summary='Results of abstract search'>\n";

    while( $row = mysql_fetch_row($result))
    {
        $row[0] = stripslashes($row[0]);
        $row[1] = stripslashes($row[1]);
        print "        <tr>\n";
        print "            <td valign='top' width=60%><b>Author(s)   <font size=-1>[Primary Author: $row[1]]</font></b></td><td ALIGN='right' VALIGN='bottom' width=40%><font SIZE=-2>SESSION CATEGORY: <B>$row[7]</B></FONT></td></tr>\n";
        print "            <tr><td bgcolor='eeeeee' width=60%><font  SIZE=-1 COLOR='black'>$row[0]</font></td><td ALIGN='right'  width=40%><font SIZE=-2>PRESENTATION TYPE: <B>$row[8]</B></FONT></td>\n";
        print "        </tr>\n";
        print "        <tr>\n";
        print "            <td  valign='top'  width=60%><b>Title</b></td><td  ALIGN='right' VALIGN='top' width=40%><font SIZE=-2>DAY/TIME:<b>$row[9] $row[10]</b></FONT></td></tr>\n";
        print "          <tr><td colspan=3 bgcolor='#eeeeee' valign='top'  width=100%><font  SIZE=-1 COLOR='black'>$row[2]</font></td>\n";
        print "        </tr>\n";
        print "        <tr><td valign='top' width=50%><b>Theme</b></td><td valign='top' width=50%><b>Focus</b></td></tr>\n";
        print "        <tr><td valign='top'  bgcolor='#eeeeee' width=50%><font SIZE=-1>$row[4]</font></td><td valign='top'  bgcolor='eeeeee' width=50%><font SIZE=-1>$row[6]</font></td></tr>\n";
        print "        <tr><td colspan=2 valign='top'  width=100%><b>Institute(s)</b></td></tr>\n";
        print "        <tr><td  colspan=2 valign='top'  bgcolor='#eeeeee' width=65%><font  SIZE=-1>$row[5]</font></td></tr>\n";
        print "        <tr></tr>\n";
        print "        <tr>\n";
        print "             <td valign='top'  bgcolor='#FFFFCC' colspan=3 width=100%><font SIZE=-1>$row[3]</font></td>\n";
        print "        </tr>\n";
        print "        <tr height=1>\n";
        print "             <td colspan=3 height=1 width=100%><hr width='100%' align='center' size='1' color='#005CAB' noshade></td>\n";
        print "        </tr>\n";

  }   
    print "    </table>\n";
 }
 
 function displayPage() {

    // make connection to database 
    $connection = mysql_connect($dsn, $dbuser, $dbpwd);

//    displaySearchForm();
    
    global $doSearch;
    if( isset($doSearch) )
    {
        performSearch();
    }
	mysql_close();
 }


  displayPage();
}

function smarty_cms_help_function_abstracts() {
	?>
	<h3>What does this do?</h3>
	<p>It embeds the conference abstracts search engine in a page. Before it works you 
	need to make sure the Webmaster has populated the database with the abstract records.</p>

	<h3>How do I use it?</h3>
	<p>Just insert the tag <code>{abstracts}</code> into a new page.

	<h3>What parameters does it take?</h3>
	<p>Absolutely none.</p>
	<?php
}

function smarty_cms_about_function_abstracts() {
	?>
	<p>Author: Paul Noone {email address="webmaster@ashm.org.au" linkname="webmaster at ashm"} </p>
	<p>Version: 1.0</p>
	<p>Change History:<br/>
	None</p>
	<?php
}
?>
Post Reply

Return to “Developers Discussion”