4images Forum & Community

4images Issues / Ausgaben => Discussion & Troubleshooting => Topic started by: NoBob on June 10, 2003, 12:38:44 AM

Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 10, 2003, 12:38:44 AM
Thought I'd pass on some info about solving an UNEXPECTED T-STRING ERROR message I got on my gallery home page.

The story:

I set up the templates and changed the look of the site, added the categories and then ftd'd the images into the numbered folders. Then I started to 'check new images' and add them. While I began by hitting the 'Go to the gallery home page' each time I added them, after a while I  just added them and moved onto the next category. To my horror I got an 'UNEXPECTED T-STRING ERROR in...template.php(133)...when I next checked the home page. Luckily I still had a previous gallery window open that showed the categories and I could move around the site - but not the home page. Eventually I found that the last pictures I'd added to a category called 'Nice's old port' were giving the T-STRING ERROR as well. So I deleted the category and tried again. Still the same problem. So, I changed the name of the category to 'Nice old port' and everything worked - works - okay. To cut an already long story short, it seems as if an 's was the problem. Hope this helps someone. My advice - don't close an old gallery window until the updated one appears okay. And back up soon and often.

Best, NoBob.
Title: UNEXPECTED T-STRING error resolved
Post by: V@no on June 10, 2003, 12:54:03 AM
Just to check your theory, I created new category with name 'Nice's old port', uploaded new images, went to index.php and....nothing happend, no error messages. Not sure why u got that error.
Title: Tested it again
Post by: NoBob on June 10, 2003, 01:05:02 AM
I just changed the category name back to 'Nice's old port' and got 'Parse error: parse error, unexpected T_STRING in /usr/local/psa/home/vhosts/rtwtravel.com/httpdocs/gallery/includes/template.php(133) : eval()'d code on line 190' on the home page. Got rid of the 's again and everything is fine. The results: www.rtwtravel.com/gallery/index.php

Best, NoBob.
Title: UNEXPECTED T-STRING error resolved
Post by: omp on June 11, 2003, 06:58:33 AM
The actual cause of this error is having a ' in the name.  The php code does not know how to handle the ' and it tra-la-las it up.  I have this same issue anytime someone uploads a image and puts a ' in the title of the image.  Only mod iv'e installed is the user upload limit/time limit mod.
Title: Thanks for that
Post by: NoBob on June 11, 2003, 08:05:03 AM
Hi omp,

Yeah, I thought of going back and trying different variations - with just an apostrophe, just a space and an s, etc - to see if it was really both the ' and the s that were causing the problem, but didn't get time. You've answered that for me. Thanks.

NoBob.
Title: UNEXPECTED T-STRING error resolved
Post by: V@no on June 11, 2003, 12:17:08 PM
did u guys remove htmlspecialchars(...); from the code? if u didnt then this error just shouldt happend, 4images uses this function that convers all quotes into " - into HTML codes.
personaly I've never had this problem, even though I have categorie, images and users with single quotes in the name.
And the only problem I had was when I installed first version of Slide show mod. but that's different story.
Title: Nope
Post by: NoBob on June 11, 2003, 12:23:15 PM
Nope, not me - well, don't think so, anyway. Could you tell me where htmlspecialchars(...); is?

Best, NoBob.
Title: Re: Nope
Post by: V@no on June 11, 2003, 12:24:56 PM
Quote from: NoBob
Nope, not me - well, don't think so, anyway. Could you tell me where htmlspecialchars(...); is?

Best, NoBob.

everywhere ;)
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 11, 2003, 12:35:45 PM
Okay, I give up. I've just looked for htmlspecialchars in three templates (header, home and details) and the index.php file. If it's everywhere, then it's cloaked somehow.

Best, NoBob.
Title: UNEXPECTED T-STRING error resolved
Post by: Chris on June 11, 2003, 03:02:40 PM
It's mostly used in the php files found in the includes directories.  There are many more php files than index.php
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 11, 2003, 03:45:13 PM
I'm certain I haven't deleted that code - not knowingly anyway. I've carefully changed bits of code in header, home, details, searchbox, index, click_incl, just to change the look, but that's it.

Best, NoBob.
words&pictures (http://www.rtwtravel.com)
Title: UNEXPECTED T-STRING error resolved
Post by: JoePCFX on June 12, 2003, 09:46:23 AM
I just got this error a few minutes ago for the first time. I had a ' in 2 album's descriptions. Got rid of them, and it works now. I've ALWAYS had the ' in there with no problem, so why is it all the sudden messing up?

I've never touched php templates, and the htmlspecialchar is all there.
Title: UNEXPECTED T-STRING error resolved
Post by: JoePCFX on June 13, 2003, 01:44:25 AM
bump
Title: UNEXPECTED T-STRING error resolved
Post by: www.girls-on-bikes.com on June 13, 2003, 06:05:04 AM
Just my .02 where it don't belong.

I've noticed some templates (template writers) change up code, including htmlspecialchars(...); (i.e. removing it)

I have a feeling this is where this problem originated.
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 13, 2003, 02:21:26 PM
I was careful not to put an apostrophe in a category's name, but then this morning I put one in the description, and got the same parse error. Will I never be able to use an apostrophe again? I haven't touched any special characters code. Would really like to find the solution to this problem.

www.girls-on-bikes.com, would you mind explaining what you mean about code writers? Which templates have you noticed getting affected?

Thanks.
Best, NoBob.
words&pictures (http://www.rtwtravel.com)
Title: UNEXPECTED T-STRING error resolved
Post by: V@no on June 13, 2003, 02:41:58 PM
maybe for now, untill someone figures this out, try use ' instead of '
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 13, 2003, 05:29:17 PM
Don't get it. If I put &apos, for example, "didn&apost do it", then it appears as just that on the public page. Sorry, I've missed something I think. Could you explain, please?

Best, NoBob.
words&pictures (http://www.rtwtravel.com)
Title: UNEXPECTED T-STRING error resolved
Post by: Chris on June 13, 2003, 05:39:17 PM
You missed the semicolon.  Try:
Code: [Select]
didn't do it
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 13, 2003, 06:04:55 PM
Oops. But tried that too now. On the public page it just says "didn't do it".

I'm putting this in the Edit categories section, where it says "Description
HTML allowed." I'm changing this in the right place, yeah?

Best, NoBob.

words&pictures (http://www.rtwtravel.com)
Title: UNEXPECTED T-STRING error resolved
Post by: www.girls-on-bikes.com on June 13, 2003, 06:27:22 PM
I've noticed that the template I use from www.vierstra.com has slightly different code that from the original.
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 13, 2003, 06:32:52 PM
Me too. 4bare.

NoBob.
words&pictures (http://www.rtwtravel.com)
Title: UNEXPECTED T-STRING error resolved
Post by: JoePCFX on June 13, 2003, 10:11:59 PM
Yeah, I'm using his 4_no_rand template for my design. But I searched the default templates and I cant find htmlspecialchars either.
Title: UNEXPECTED T-STRING error resolved
Post by: www.girls-on-bikes.com on June 13, 2003, 10:14:32 PM
The php command htmlspecialchars would be located in the php files, not the html template files.  I'm at work so I can't check to give you an example of where they are located, but I know it's in a lot of the php files.
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 14, 2003, 12:42:56 AM
Well,

The error I got mentions this code, which starts at line 133 in includes/template.php:  

   eval($code);
    }
    else {
      $code = preg_replace("/<\[\?|%](php|=)+( \r\n)*(.*)[\?|%]>/siU", "", $template);
      echo $code;
    }
  }

  function exec_php_code($code) {
    $code = str_replace('\\', '\\\\', $code);
    $code = str_replace('\'', '\\\'', $code);
    $new_lines = array();
    $is_code = 0;
    $lines = explode("\n", $code);
    foreach ($lines as $line) {
      //$line = trim($line);
      if (preg_match('/<[\?|%](php|=)+/', $line, $regs)) {
        $line = preg_replace('/<[\?|%](php|=)?/i', '', $line);
        $line = ((!empty($regs[1]) && $regs[1] == "=") ? "echo " : "").$line;
        $is_code = 1;
      }
      if ($is_code) {
        $line = str_replace ('\\\'', '\'', $line);
        $line = str_replace ('\\\\', '\\', $line);
        if (preg_match('/[\?|%]>/', $line)) {
          $line = preg_replace('/[\?|%]>/', '', $line);
          $is_code = 0;
        }
      }
      else {
        $line = 'echo \''.$line.'\'."\\n";';
      }
      $new_lines[] = $line;
    }
    return implode("\n", $new_lines);
  }

  function clean_template($template) {
    $search_array = array(
      "/".$this->start."[^ \t\r\n".$this->end."]+".$this->end."/",
      "/".$this->start."if[ \t\r\n]+[^ \t\r\n".$this->end."]+".$this->end."/",
      "/".$this->start."endif[ \t\r\n]+[^ \t\r\n".$this->end."]+".$this->end."/",
      "/&#36;([0-9])/",
      "/&#92;([0-9])/"
    );
    $replace_array = array(
      "",
      "",
      "",
      '$\1',
      '\\\1'
    );
    $template = preg_replace($search_array, $replace_array, $template);
    return $template;
  }

  function error($errmsg, $halt = 0) {
    if (!$this->no_error) {
      echo "<br /><font color='#FF0000'><b>Template Error</b></font>: ".$errmsg."<br />";
      if ($halt) {
        exit;
      }
    }
  }
} // end of class
?>

This is just semi-colons and curly brackets to me, but maybe someone can see something. I found htmlspecialchars in other php files, but it's not in this php file.

NoBob.
Title: UNEXPECTED T-STRING error resolved
Post by: www.girls-on-bikes.com on June 14, 2003, 03:19:39 AM
The error your getting isn't in "that" file, it's in the file that's being passed to template, which is a .html file, which has an apostrophe.

Just so you can compare, here is my template.php from 133 on:
Code: [Select]
eval($code);
    }
    else {
      $code = preg_replace("/<\[\?|%](php|=)+( \r\n)*(.*)[\?|%]>/siU", "", $template);
      echo $code;
    }
  }

  function exec_php_code($code) {
    $code = str_replace('\\', '\\\\', $code);
    $code = str_replace('\'', '\\\'', $code);
    $new_lines = array();
    $is_code = 0;
    $lines = explode("\n", $code);
    foreach ($lines as $line) {
      //$line = trim($line);
      if (preg_match('/<[\?|%](php|=)+/', $line, $regs)) {
        $line = preg_replace('/<[\?|%](php|=)?/i', '', $line);
        $line = ((!empty($regs[1]) && $regs[1] == "=") ? "echo " : "").$line;
        $is_code = 1;
      }
      if ($is_code) {
        $line = str_replace ('\\\'', '\'', $line);
        $line = str_replace ('\\\\', '\\', $line);
        if (preg_match('/[\?|%]>/', $line)) {
          $line = preg_replace('/[\?|%]>/', '', $line);
          $is_code = 0;
        }
      }
      else {
        $line = 'echo \''.$line.'\'."\\n";';
      }
      $new_lines[] = $line;
    }
    return implode("\n", $new_lines);
  }

  function clean_template($template) {
    $search_array = array(
      "/".$this->start."[^ \t\r\n".$this->end."]+".$this->end."/",
      "/".$this->start."if[ \t\r\n]+[^ \t\r\n".$this->end."]+".$this->end."/",
      "/".$this->start."endif[ \t\r\n]+[^ \t\r\n".$this->end."]+".$this->end."/",
      "/&#36;([0-9])/",
      "/&#92;([0-9])/"
    );
    $replace_array = array(
      "",
      "",
      "",
      '$\1',
      '\\\1'
    );
    $template = preg_replace($search_array, $replace_array, $template);
    return $template;
  }

  function error($errmsg, $halt = 0) {
    if (!$this->no_error) {
      echo "<br /><font color='#FF0000'><b>Template Error</b></font>: ".$errmsg."<br />";
      if ($halt) {
        exit;
      }
    }
  }
} // end of class
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 14, 2003, 09:30:41 AM
Just to check, the wrong code is in the html file that's being passed to template.php?

I see this
 $site_template->register_vars(array(
  "categories" => get_categories($cat_id),
  "cat_name" => htmlspecialchars($cat_cache[$cat_id]['cat_name']),
  "cat_description" => $cat_cache[$cat_id]['cat_description'],

in categories.php.

Anyone who wrote this gallery have any more ideas?

NoBob.
words&pictures (http://www.rtwtravel.com)
Title: UNEXPECTED T-STRING error resolved
Post by: www.girls-on-bikes.com on June 14, 2003, 08:21:20 PM
Here is my entire show categories section in categories.php (that's what you were having trouble with, right?  When it displays the category text):

Code: [Select]
//-----------------------------------------------------
//--- Show Categories ---------------------------------
//-----------------------------------------------------
if (!check_permission("auth_upload", $cat_id)) {
  $upload_url = "";
  $upload_button = "<img src=\"".get_gallery_image("upload_off.gif")."\" border=\"0\" alt=\"\" />";
}
else {
  $upload_url = $site_sess->url(ROOT_PATH."member.php?action=uploadform&amp;".URL_CAT_ID."=".$cat_id);
  $upload_button = "<a href=\"".$upload_url."\"><img src=\"".get_gallery_image("upload.gif")."\" border=\"0\" alt=\"\" /></a>";
}

$random_cat_image = (defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0) ? "" : get_random_image($cat_id);
$site_template->register_vars(array(
  "categories" => get_categories($cat_id),
  "cat_name" => htmlspecialchars($cat_cache[$cat_id]['cat_name']),
  "cat_description" => $cat_cache[$cat_id]['cat_description'],
  "cat_hits" => $cat_cache[$cat_id]['cat_hits'],
  "upload_url" => $upload_url,
  "upload_button" => $upload_button,
  "random_cat_image" => $random_cat_image
));

unset($random_cat_image);
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 16, 2003, 05:32:53 PM
I've reached a dead end here. I was hoping that someone in the know would see something in the code we've posted. It seems like we're now the only ones interested in solving this problem.

NoBob.
Title: UNEXPECTED T-STRING error resolved
Post by: V@no on June 16, 2003, 09:59:52 PM
Quote from: NoBob
It seems like we're now the only ones interested in solving this problem.

not many people have this problem, maybe u are the only people who actualy have this problem...
it might be related to PHP configuration (just curious, is "Magick quotes" turned on at your host? can u see it in phpinfo() ?
Title: UNEXPECTED T-STRING error resolved
Post by: JoePCFX on June 16, 2003, 11:43:41 PM
For me magic quotes are enabled: I get this in phpinfo:

magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off

Quote
The php command htmlspecialchars would be located in the php files, not the html template files. I'm at work so I can't check to give you an example of where they are located, but I know it's in a lot of the php files.


So if thats the case, why are we getting this error if we havent modified (well I havent) the .php files if they arent in the templates? If the templates dont have anything to do with this issue how is it messing up for some of us?

Looks like I gotta work on a whole new template if I cant fix it because I really worked hard on the style I based off 4_no_rand.
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 17, 2003, 07:24:21 AM
V@no,

I've got

magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off

NoBob.
Title: UNEXPECTED T-STRING error resolved
Post by: V@no on June 17, 2003, 10:53:12 AM
magic_quotes changes anything...just tryed myself..
but if u use default template, do u get same error message? (lets go from here ;))
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 17, 2003, 10:16:09 PM
Just tried the default template and everything works okay.

I get these errors when using 4bare.

"Nice's old port" as category name. Error on home page:
Parse error: parse error, unexpected T_STRING in /usr/local/psa/home/vhosts/rtwtravel.com/httpdocs/gallery/includes/template.php(133) : eval()'d code on line 208


"Nice's old port" is in the description. When arrive at the category page through clickstream from home page, this is the error:
Parse error: parse error, unexpected T_STRING in /usr/local/psa/home/vhosts/rtwtravel.com/httpdocs/gallery/includes/template.php(133) : eval()'d code on line 95

When the apostrphe is in both the category name and the description, the error is:
Parse error: parse error, unexpected T_STRING in /usr/local/psa/home/vhosts/rtwtravel.com/httpdocs/gallery/includes/template.php(133) : eval()'d code on line 208

NoBob.
Title: UNEXPECTED T-STRING error resolved
Post by: www.girls-on-bikes.com on June 17, 2003, 10:37:35 PM
That pretty much proves it right there, a lot of these templates are modified, and as you can see, they don't deal with special characters well.
Kind of a bummer :(
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 17, 2003, 10:51:00 PM
There must be a solution.

NoBob.
Title: UNEXPECTED T-STRING error resolved
Post by: www.girls-on-bikes.com on June 17, 2003, 10:53:19 PM
There is, pinpoint exactly which file is causing the error, and re-write the way that file deals with htmlspecialchars.

It's not easy if you don't know PHP well, but that is the basic solution.
Title: UNEXPECTED T-STRING error resolved
Post by: V@no on June 17, 2003, 11:51:05 PM
Quote from: NoBob
Just tried the default template and everything works okay.

if there is something wrong with the template, then I'd first compare it with default, for {...} tags, and maybe syntaxis.
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 18, 2003, 12:01:57 PM
Does it matter that there are a mix of single and double quotes in 4bare's categories.html template?

<?php
 $cl = '{clickstream}';
 $uti = "{url_top_images}";
 $lti = "{lang_top_images}";
 $uni = "{url_new_images}";
 $lni = "{lang_new_images}";
 require "{template_url}/incl/click_incl.php";
 ?>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">

<?php
$cn = '{cat_name}';
$cd = '{cat_description}';
$ch = '{cat_hits}';
require "{template_url}/incl/cat_incl.php";


NoBob
Title: UNEXPECTED T-STRING error resolved
Post by: V@no on June 18, 2003, 12:34:46 PM
I think so, because when {...} tags get replaced by its value, its also strip slashes, so in your case u'll get:
Code: [Select]
$cd = 'Nice's old port';and that gives error message.
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 18, 2003, 12:53:50 PM
I tried replacing the single quotes around {cat_name} and {cat_description} with doubles, but that just generated error messages too. Anyway to re-write it?

NoBob
Title: UNEXPECTED T-STRING error resolved
Post by: V@no on June 18, 2003, 02:09:37 PM
first off all, this is not a right way to do anything in the templates...
but anyway, then try find something like:
Quote
"cat_description" => $some_variable_name

and replace it with:
Quote
"cat_description" => htmlspecialchars($some_variable_name)
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 18, 2003, 07:00:12 PM
Good, good, good, we're halfway there...In categories.php, I made the changes to cat_description and now I can use an apostrophe in the description. But htmlspecialchars has always been there after cat_name, and I still get an error if I use an apostrophe in the category name. How's that work for you JoePCFX? You were having problems with descriptions.

Code now:
"cat_name" => htmlspecialchars($cat_cache[$cat_id]['cat_name']),
  "cat_description" => htmlspecialchars($cat_cache[$cat_id]['cat_description']),

NoBob.
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 19, 2003, 05:59:15 PM
bump
Title: UNEXPECTED T-STRING error resolved
Post by: JoePCFX on June 20, 2003, 11:39:53 PM
Nothing works here, using 4_no_rand yet. Maybe Im just appying the code wrong though.
Title: UNEXPECTED T-STRING error resolved
Post by: www.girls-on-bikes.com on June 20, 2003, 11:52:28 PM
This may be a shot in the dark, but what if you try putting the HTML code version of the apostrophy where you enter in the category name, for example:

Quote
Blah Blah Don&#39;t


May be worth a try, but it doesn't solve the underlying problem.
Title: UNEXPECTED T-STRING error resolved
Post by: NoBob on June 21, 2003, 02:04:29 PM
That's clever! It works. Thank you.

Used "Nice&#39;s old port" in the category description and it comes up on the public page as "Nice's old port", with no error message.
 (http://www.rtwtravel.com/gallery) When you go back to Edit Categories, though, you have to remember to put in &#39; again, otherwise you'll get another error. It also seems to have an adverse effect on css no text decoration script on the page. Best to have a separate style sheet uploaded.

http://www.rtwtravel.com/gallery/

Thanks. But you're right, it still doesn't solve the underlying problem.

Best, NoBob
Title: Oh well
Post by: comicart on June 30, 2003, 10:45:21 PM
Too bad. Vierstra.com has some nice templates. I even use one on one of my sites. But another site I have needs to have apostrophes in the Category names.

Any other template makers have this problem or is it just the ones at Vierstra.com?

Terry