Can NOT code PHP with User define tags nor use_smarty_php_tags = true

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
ortegaj

Can NOT code PHP with User define tags nor use_smarty_php_tags = true

Post by ortegaj »

User define tags  nor

Code: Select all

$config['use_smarty_php_tags'] = true;
are working

the folowing code works perfectly on a simple php file. 

But using it in UDT  or the {php}{/php} combo produces nothing and unpredictable results.

Code: Select all

function GetExt($name)
{
	$ext = strrchr($name, '.');
	if($ext !== false)
	{
           $ext = substr($ext, 1);
	}
	return $ext;
}


function showDir($folder, $allowed_extensions ) {
	$d = dir($folder);
	//echo "Handle: " . $d->handle . "<br/>\n";
	echo "<H2>Path: " . $d->path . "</H2><br/>\n";
	$x = 0;
	while (false !== ($entry = $d->read())) {
		if(is_file($entry)) {

		   //echo GetExt($entry)."<br/>\n";
		   if( in_array(GetExt($entry), $allowed_extensions) )  {
			$x++;
			echo  "<TR><TD>$x.</TD><TD><A HREF='$entry'>$entry</A></TD><TD>???</TD></TR>\n";
		   }
		}
	}
	$d->close();
}

$DIRROOT = "/home/user/www/blahblah";

$allowed_extensions = array("pdf","gif", "jpg", "jpeg");
echo  $DIRROOT.'<BR>';
$folder = $DIRROOT.'/test';
//echo $folder. '<BR>';
echo "<TABLE border=1>\n";
showDir($folder, $allowed_extensions);
echo  "</TABLE>\n";
Developer FAQ said:
You can use any valid php code in a user defined tag, including the "include" command to include external scripts.
and also
Change the "use_smarty_php_tags" setting to true. ... Now you can place php code into your page or template at will.
After changing some lines I tried not using my functions and not using the is_file and in_array functions calls...  it worked but not as i want which is to display only files with specific extensions of a given subdir.

What other option is there in CMSms for inserting php code?

CMSms molokai ->  linux env.  ->  hosted (safe mode ON)

I'm using PHP Version 5.2.1  and MySQL  4.1.21 on  Apache/1.3.37 
OlafNoehring
Forum Members
Forum Members
Posts: 78
Joined: Mon Oct 23, 2006 4:43 pm

Re: Can NOT code PHP with User define tags nor use_smarty_php_tags = true

Post by OlafNoehring »

Hi

same problem here

I am trying this:

{php}
  $GLOBALS['adl_count_params']=true;
  require_once '/srv/www/htdocs/xxxx/html/twatch_include/logger.php';
{/php}

but nothing happens. I also do not know if the variable is declared as it should be. Weird: The page creation dies not break. The page is fine but it really seems nothing happens. (TWATCH is a logging free tool: www.tracewatch.com )
I have no idea why the code does not work. Especially strange: On a different server it works fine! And when I create a php file like the following it works as well and does what it is supposed to do:
y

Trying this works fine:
{php}
  echo $_SERVER['PHP_SELF'];
{/php}

Olaf
palmatec
New Member
New Member
Posts: 4
Joined: Wed Mar 14, 2007 6:15 am

Re: Can NOT code PHP with User define tags nor use_smarty_php_tags = true

Post by palmatec »

Anyone find a solution to this issue? ???

I am having the same problem. Simple PHP is working, but all of the functions I need to show the site navigation are not working. (see script below)

Basically everything within is not working.

It works fine on my old server ( http://65.109.231.8/ )  but the new server doesn't display anything. (http://64.13.250.75.)

Smarty is set to 'true'

user-defined tags do not allow me to use this script.





$menu_text";
}
else
{
echo "$menu_text";
}
}

?>

Last edited by palmatec on Sun Apr 29, 2007 6:43 am, edited 1 time in total.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Can NOT code PHP with User define tags nor use_smarty_php_tags = true

Post by Dee »

@palmatec:
You're not supplying a valid $dblink in your code. Try re-using the existing ADOdb database connection.
Try this in a UDT:

Code: Select all

global $gCms;
$db = $gCms->GetDb();

$pageinfo = $gCms->variables['pageinfo'];
$alias = $pageinfo->content_alias;

?>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<?php
$query = "SELECT content_id,parent_id FROM cms_content WHERE content_alias='$alias'";
$result = $db->Execute($query);
$content = $result->fields;
$current_id = $content['content_id'];
$current_par = $content['parent_id'];

$query = "SELECT content_id,type,parent_id,menu_text,content_alias,active FROM cms_content WHERE parent_id = '-1' AND show_in_menu = '1' AND active = '1' ORDER BY hierarchy ASC";
$result = $db->Execute($query);

while ($result && $content = $result->FetchRow())
   {
      $content_id = $content['content_id'];
      $type = $content['type'];
      $parent_id = $content['parent_id'];
      $menu_text = $content['menu_text'];
      $content_alias = $content['content_alias'];

      if (($current_id == $content_id) || ($current_par == $content_id) || ($current_par == "13"))
         {
            $divID = "mainNavcurrent";
         }
      else
         {
            $divID = "mainNav";
         }
      if ($type == "link")
         {
            $querytype = "SELECT content FROM cms_content_props WHERE content_id = '$newContid'";
            $resulttype = $db->Execute($querytype);
            $newUrl = $resulttype->fields;
            $link = $newUrl['content'];
            echo   "<td id=\"$divID\"><a href=\"".$link."\"><nobr>$menu_text</nobr></a></td>";
         }
      else
         {
            echo   "<td id=\"$divID\"><a href=\"".$url."?page=$content_alias\"><nobr>$menu_text</nobr></a></td>";
         }
   }

?>
</tr>
</table>
<?php


Regards,
D
Last edited by Anonymous on Sun Apr 29, 2007 12:36 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Can NOT code PHP with User define tags nor use_smarty_php_tags = true

Post by calguy1000 »

OlafNoehring wrote: Hi

same problem here

I am trying this:

{php}
  $GLOBALS['adl_count_params']=true;
  require_once '/srv/www/htdocs/xxxx/html/twatch_include/logger.php';
{/php}

but nothing happens. I also do not know if the variable is declared as it should be. Weird: The page creation dies not break. The page is fine but it really seems nothing happens. (TWATCH is a logging free tool: www.tracewatch.com )
I have no idea why the code does not work. Especially strange: On a different server it works fine! And when I create a php file like the following it works as well and does what it is supposed to do:
y

Trying this works fine:
{php}
  echo $_SERVER['PHP_SELF'];
{/php}

Olaf
Your httpd error log should tell you what the problem is.  When including php scripts like this you really need to keep an eye on your php error logs  (and ensure that error reporting is turned on).  If you don't have access to this log, ask your provider for access to it, or a copy of the logs that are relevant to your site.
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.
Locked

Return to “CMSMS Core”