#1611 tiki-edit_templates.php path problem

HEAD_(CVS)
closed-fixed
mose
PHP Error (166)
5
2004-09-08
2004-08-17
Tsan-Kuang Lee
No

The path for *.tpl to be edited is always wrong for me.
Almost all *.tpl calling tiki-edit_templates.php gives
a parameter of "template=templates/xxxx.tpl"

Therefore, in the following code:

tiki-edit_templates.php (line 42)

if (isset($tikidomain) and
is_file($smarty->template_dir.'/'.$tikidomain.'/'.$style_base.'/'.$_REQUEST["template"]))
{
$fp =
fopen($smarty->template_dir.'/'.$tikidomain.'/'.$style_base.'/'.$_REQUEST["template"],
"w");
} elseif (isset($tikidomain) and
is_dir($smarty->template_dir.'/'.$tikidomain)) {
$fp =
fopen($smarty->template_dir.'/'.$tikidomain.'/'.$_REQUEST["template"],
"w");
} elseif (isset($tikidomain) and
is_file($smarty->template_dir.'/'.$style_base.'/'.$_REQUEST["template"]))
{
$fp =
fopen($smarty->template_dir.'/'.$style_base.'/'.$_REQUEST["template"],
"w");
} else {
$fp =
fopen($smarty->template_dir.$_REQUEST["template"], "w");
==================

$smarty->template_dir and $_REQUEST["template"] will
both contain "templates/". In most cases, we'll have
"templates/templates/xxx.tpl" which obviously doesn't
exist.

The other problem is $style_base does not contain
"styles/". Therefore, it would give
templates/tikidomain/default/templates/xxx.tpl

setup_smarty.php seems to have a neater way to deal
with the similiar situation:

setup_smarty.php (line 43)

if (isset($style) && isset($style_base)) {
if ($tikidomain and
file_exists("templates/$tikidomain/styles/$style_base/".$params['smarty_include_tpl_file']))
{
$params['smarty_include_tpl_file'] =
"$tikidomain/styles/$style_base/".$params['smarty_include_tpl_file'];
} elseif ($tikidomain and
file_exists("templates/$tikidomain/".$params['smarty_include_tpl_file']))
{
$params['smarty_include_tpl_file'] =
"$tikidomain/".$params['smarty_include_tpl_file'];
} elseif
(file_exists("templates/styles/$style_base/".$params['smarty_include_tpl_file']))
{
$params['smarty_include_tpl_file'] =
"styles/$style_base/".$params['smarty_include_tpl_file'];
}
}
return parent::_smarty_include($params);
===========================

Discussion

  • Tsan-Kuang Lee
    Tsan-Kuang Lee
    2004-08-17

    • milestone: 316039 --> HEAD_(CVS)
     
  • Tsan-Kuang Lee
    Tsan-Kuang Lee
    2004-08-18

    Logged In: YES
    user_id=1085659

    It's the version (the HEAD) I got from CVS.

     
  • Logged In: YES
    user_id=738765

    I understand this, I was asking if you are using the
    Multi-Tiki feature.

     
  • Tsan-Kuang Lee
    Tsan-Kuang Lee
    2004-08-18

    Logged In: YES
    user_id=1085659

    Sorry for my misunderstanding. No, I'm not using Multi-Tiki
    feature. (I don't even know there's such a thing, or do you
    mean the virtual domain thing? -- I don't use it either.)

    If you are getting the right path, we are probably taking
    about different versions. From the code I quoted in the
    original mail, the path would turn out wrong. Any idea?

     
  • Logged In: YES
    user_id=738765

    I have the same code at line 43, so we must be talking about
    the same version.
    As you can see, all the elseifs (and the if) have
    if (isset($tikidomain))
    If $tikidoman is set, this means you are using MultiTiki.
    If it it not set then the path is determined by the else
    clause :
    $fp = fopen($smarty->template_dir.$_REQUEST["template"], "w");

    So only the code at line 50 should be relevant.

    Since you were able to read those lines, you should be able
    to do some basic debugging, such as adding "echo "else
    clause entered";" to the else clause. This will tell you
    what clause is executed.

    After looking at the code, you're talking about an
    irrelevant part. The code you're dealing with if from line
    87 to 114 :
    // Get templates from the templates directory
    $files = array();
    $h = opendir($smarty->template_dir);
    while (($file = readdir($h)) !== false) {
    if (substr($file,-4,4) == '.tpl') {
    $files[] = $file;
    }
    }
    closedir ($h);

    $h = opendir($smarty->template_dir."modules/");
    while (($file = readdir($h)) !== false) {
    if (substr($file,-4,4) == '.tpl') {
    $files[] = "modules/" . $file;
    }
    }
    closedir ($h);

    $h = opendir($smarty->template_dir."mail/");
    while (($file = readdir($h)) !== false) {
    if (substr($file,-4,4) == '.tpl') {
    $files[] = "mail/" . $file;
    }
    }
    closedir ($h);

    sort ($files);
    $smarty->assign('files', $files);

    If you have the same code I can't see how you would get such
    a problem :/

    Since you are reporting this to be a PHP error bug, please
    mention the error so that another victim can find this bug
    using search.

     
  • Tsan-Kuang Lee
    Tsan-Kuang Lee
    2004-08-19

    Logged In: YES
    user_id=1085659

    Thanks a lot for reading into the code. You are right -- I
    should have included the error to make things clear:

    When I enter "Forum Admin" and click on "edit template", I got:

    Warning: fopen(templates/templates/tiki-admin_forums.tpl):
    failed to open stream: No such file or directory in /(my
    directory)/tikiwiki/tiki-edit_templates.php on line 74

    I did insert some echo before I submit this problem, and in
    my case, it's the last else clause got excuted.

    Also, I'm sorry that I wasn't specific enough -- I found the
    section of "save" (line 41-60) and the section of "template"
    (line 62-83) are similar, so I sloppily said line 41 while
    my case is really about line 62.

     
  • Tsan-Kuang Lee
    Tsan-Kuang Lee
    2004-08-19

    Logged In: YES
    user_id=1085659

    After reading the lines you reffered me to (line 87-114), I
    realize we are talking about different functions. You mean
    the page of editting all the templates; I mean the pages
    with the "edit template" icon.

    Now the problem is clearly the in *.tpl files -- they should
    have template=xxx.tpl instead of template=templates/xxx.tpl
    . (I wasn't sure whether to change all the *.tpl or the
    tkik-edit_templates.php but now it's clear.)

    Maybe it'll make me more clear by this:
    grep "template=templates/" templates/*

    Take tiki-admin_forums.tpl for example, line 12 gives
    "template=templates/tiki-admin_forums.tpl" and cause the
    problem I mentioned.

    This set of templates are the default files, so I think
    maybe this should be fixed (if I'm right about the
    problem/solution).

     
  • Logged In: YES
    user_id=738765

    Thanks for your perseverence with that bug.
    I confirm this error when editing templates with
    "templates/" in the link for 1.9+.
    This is now fixed in BRANCH-1-9 and should be ported to HEAD
    next merge.

    There is also a problem specific to HEAD : Warning:
    fopen(templates///tiki-galleries.tpl): failed to open
    stream: Permission denied in
    /var/www/tiki/HEAD/tiki-edit_templates.php on line 46

    This problem brings us back to the code you originally
    submitted. If I put some debug stuff there, I realize that
    the else clause is not entered. If I put "echo
    ($tikidomain=='') ? 'y' : 'n';" , I get "y", so $tikidomain
    is set for me, yet I don't remember doing anything to use
    MultiTiki.
    We need to know if that's just for me as this would produce
    important problems. Can you whether put that code anywhere
    in your Tiki and report the result? Alternatively, try
    editing a template FROM THE EDIT TEMPLATES PAGE and tell us
    if you get the above error or if it works.

    Thanks again.

     
    • status: open --> open-accepted
     
  • Tsan-Kuang Lee
    Tsan-Kuang Lee
    2004-08-21

    Logged In: YES
    user_id=1085659

    Thank YOU for the hard work.

    If you have
    echo ($tikidomain=='') ? 'y' : 'n';
    and you get 'y'; it means $tikidomain is empty and you are
    NOT using tikidomain, right?

    I tested it again: in my case, it's the last "else" section
    got excuted.

    I also reported a second bug in the oroginal post. I think
    there should be "styles/" before each $style_base.

     
  • Logged In: YES
    user_id=738765

    if (isset($tikidomain)) will evaluate to true if $tikidomain==''
    An non-set variable is different from a variable assigned to
    an empty string.
    I tested on someone else's HEAD Tiki and Edit Templates
    worked, so I may have done something wrong which is causing
    me this problem.

    It would be a great help for me to know how $tikidomain is set.

     
  • mose
    mose
    2004-09-08

    • assigned_to: nobody --> mose
    • status: open-accepted --> closed-fixed
     
  • mose
    mose
    2004-09-08

    Logged In: YES
    user_id=8021

    should be fixed in 1.9rc3