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

Re: User Defined Tag upgrade to latest Smarty

Post by Curious2 »

Folks,
I had a few UDTs which stopped working when upgrading CMSMS from 1.8 to 2.2.
Velden
memberlist.php?mode=viewprofile&u=61031
was able to help me out. His rate was acceptable, and his knowledge, and ability to help, and quality and amount of support provided were superb!
I used to be active on the forum 10 years ago, back then there were developers all over the forum. Now I can't trust any leechers here with few forum posts. Yeah sure everyone claims to know PHP these days, but what do they know of CMSMS and Smarty and CMSMS-related knowlege and experience???????
Velden is super! Besides being a good programmer, he is also a CMSMS dev, so he has superb knowledge of CMSMS internals. In my case, Smarty statements obviously changed from 1.8 to 2.2.
All working now!
If Velden is too busy or your request is outside of his specialty (whatever that is... maybe he knows everything???), you can also request help from CMSMS team:
https://www.cmsmadesimple.org/support/hire-a-dev

Unfortunately, too much changed since CMSMS 1.8. A whole bunch of things break on upgrade, and worse yet, a number of extensions/modules are long obsolete due to not being maintained for CMSMS 2.2 and recent PHP versions.
At this point, doing a CMSMS upgrade without a developer is waaay too risky. DO NOT attempt an upgrade without having multiple tested backups in place (file-copy to another folder name, tar archive, etc. Database export. Etc). And then DO NOT upgrade a production website. Clone its folder structure and database, and upgrade the clone (aka "development server"). Only when you are happy with results would you EVER touch live production website! (Alternatively, leave old version as-is as a backup, and just re-point your domain name to the upgraded "developmental" folder, assuming there were no content additions to your website between the two).

This is a minor duplicate of another post. That's intentional. I gave this upgrade several attempts before realizing I need to pay a developer...
User avatar
Rolf
Dev Team Member
Dev Team Member
Posts: 7826
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: User Defined Tag upgrade to latest Smarty

Post by Rolf »

I have an old UDT that showed a listing of pages that are "children" to current page (in terms of navigation)
No need for a UDT, this does the trick in any page:

Code: Select all

{Navigator childrenof=$page_alias}
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Post Reply

Return to “Developers Discussion”