User Defined Tag upgrade to latest Smarty

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
Curious2
New Member
New Member
Posts: 5
Joined: Mon Nov 02, 2020 8:27 pm

User Defined Tag upgrade to latest Smarty

Post by Curious2 »

Hello,
This was also posted under Help Wanted. I am fine with either paid work or suggestions from others.
I have an old UDT that showed a listing of pages that are "children" to current page (in terms of navigation). It worked fine for CMSMS 1.5 or older I believe, does not work with latest CMSMS due to Smarty changes. I have never understood Smarty much... I already tried reading posts around that time, I have faint ideas, but I am afraid to change something I don't understand well... Here is code that needs to be updated:

Code: Select all

global $gCms;
$manager =& $gCms->GetHierarchyManager();
$thisPage = $gCms->variables['page_name'];
$currentNode = &$manager->sureGetNodeByAlias($thisPage);

$nodes = $currentNode->getChildren();

if ($currentNode->hasChildren()) {
  echo '<ul class="sectionlinks">';
  foreach ($nodes as $node) {
     $content= $node->getContent();
     $url = $content->GetURL();
    if ($url == "#") { /* section header has no link by default */
      $url = "index.php?page=".$content->Alias();
    }
    echo "<li><a href=\"".$url."\">".$content->MenuText()."</a> </li>";

  }
  echo "</ul>";
}
Running CMSMS Version 2.2.10
Curious2
New Member
New Member
Posts: 5
Joined: Mon Nov 02, 2020 8:27 pm

Re: User Defined Tag upgrade to latest Smarty

Post by Curious2 »

Code: Select all

global $gCms;
becomes

Code: Select all

$gCms = cmsms();

Code: Select all

$gCms->variables['page_name']
becomes
???

Where do I go for a CMSMS-specific Smarty manual on such functions, and their listing? Because I tried here:
https://apidoc.cmsmadesimple.org/
But I don't see anything with a few searches that seems to be the replacement for this.
Last edited by Curious2 on Mon Nov 02, 2020 9:37 pm, edited 1 time in total.
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1076
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: User Defined Tag upgrade to latest Smarty

Post by DIGI3 »

I know it's not really an answer to your question, but couldn't you accomplish this with Navigator? If not, CGSimpleSmarty also has a method: cgsimple::get_children([$alias][,$showinactive])
Not getting the answer you need? CMSMS support options
Curious2
New Member
New Member
Posts: 5
Joined: Mon Nov 02, 2020 8:27 pm

Re: User Defined Tag upgrade to latest Smarty

Post by Curious2 »

DIGI3 wrote: Tue Nov 03, 2020 3:56 pm I know it's not really an answer to your question, but couldn't you accomplish this with Navigator? If not, CGSimpleSmarty also has a method: cgsimple::get_children([$alias][,$showinactive])
Thanks @DIGI3! I will try this!
Well, main point was to upgrade this properly because this is not the only utility that relied on Smarty that I had. I have a few.
Another utility that I have shows as a number, total number of articles/pages I have on my website. Is there also a simple equivalent of that?

Where do I go to access cgsimple API documentation?

Some of other UDTs that were running on 1.12.2:

Number of pages on website UDT:

Code: Select all

	$db = cmsms()->GetDB();
		
$query = "SELECT count(content_id) FROM ".cms_db_prefix()."content WHERE active=1";
	$dbresult = $db->Execute($query);

	$row = $dbresult->FetchRow();
        return($row['count(content_id)']);

Last created articles (selectable as to how many are shown) returned / displayed UDT:

Code: Select all

	$db = cmsms()->GetDB();

	if(empty($params['number']))
		$number = 20;
	else
		$number = $params['number'];
		
	if(empty($params['format']))
		$format = "d. M Y";
	else
		$format = $params['format'];

	
	$query = "SELECT * FROM ".cms_db_prefix()."content WHERE active=1 ORDER BY create_date DESC LIMIT 0,".$number;
	$dbresult = $db->Execute($query);

	$ret = "";
	while ($dbresult && $row = $dbresult->FetchRow())
	{
		$ret .= date($format,$db->UnixTimeStamp($row['create_date']));
		$ret .= "&nbsp;<a href=\"index.php/".$row['content_alias']."\" target=\"_self\">".$row['content_name']."</a><br />";
	}

	return $ret;
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1076
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: User Defined Tag upgrade to latest Smarty

Post by DIGI3 »

The documentation for CGSS is in the module's help, there's no specific API documentation as far as I know though. Easiest way to access a module's help page is to click on 'help' next to it in Module Manager.

I'll leave it up to someone else to help with your UDT's, that's not my strong suit.
Not getting the answer you need? CMSMS support options
Post Reply

Return to “Developers Discussion”