Page 1 of 1

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

Posted: Fri Mar 30, 2007 5:53 am
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 

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

Posted: Tue Apr 10, 2007 3:26 pm
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

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

Posted: Sat Apr 28, 2007 11:33 pm
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";
}
}

?>


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

Posted: Sun Apr 29, 2007 11:57 am
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

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

Posted: Mon Apr 30, 2007 12:39 am
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.