Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

using ChangeBasename with templates?

codegruntcodegrunt New
edited February 2011 in Vanilla 2.0 - 2.8
Howdy. I am currently working on a Smarty template for the discussion detail view:


I have hit an issue where the image name stored in the $CommentData array is not correct. After some digging, I see that the original "WriteComment()" function used by the inline PHP script generates the image link via the following function in "applications/vanilla/views/discussion/helper_functions.php":

if (!function_exists('UserPhoto')) { function UserPhoto($User, $CssClass = '') { $CssClass = $CssClass == '' ? '' : ' class="'.$CssClass.'"'; if ($User->Photo != '') { $IsFullPath = strtolower(substr($User->Photo, 0, 7)) == 'http://' || strtolower(substr($User->Photo, 0, 8)) == 'https://'; $PhotoUrl = ($IsFullPath) ? $User->Photo : 'uploads/'.ChangeBasename($User->Photo, 'n%s'); return '<a title="'.urlencode($User->Name).'" href="'.Url('/profile/'.$User->UserID.'/'.urlencode($User->Name)).'"'.$CssClass.'>' .Img($PhotoUrl, array('alt' => urlencode($User->Name))) .'</a>'; } else { return ''; } } }

ChangeBasename() is then used to (not sure why) prepend a "n" to the base file name.

My first question is what is the purpose of ChangeBasename() call here (i.e why is the image not accessed directly)?

Secondly, is there an existing way to call ChangeBasename() via a Smarty template or is the only option to add a plugin and hardcode in the "n%s" string as a parameter in the Smarty template:

{changebasename path=$comment.UserPhoto newbasename="n%s"}

I have to say that trying to fully template Vanilla is proving to be quite an adventure. . .the current Smarty support is far from complete.



  • Not sure if this is the best way to do this but it works. . .I have setup a modifier for Smarty that calls changebasename:


    function smarty_modifier_changebasename($Code, $Default = '') { return( ChangeBasename($Code, $Default) ); }

    You use it like this:

    <span class="Author"> <a title="{$comment.InsertName}" href="{link path="/profile"}/{$comment.InsertUserID}/{$comment.InsertName|format_url}"><img src="{link path="uploads"}/{$comment.InsertPhoto|changebasename:'n%s'}" alt="{$comment.InsertName}" /></a> <a href="{link path="/profile"}/{$comment.InsertUserID}/{$comment.InsertName|format_url}">{$comment.InsertName}</a> </span>

    If I hit too many more of these it may be quicker to write a single general purpose modifier which takes the name of the function as one of the arguments. Still, I do wish that Vanilla would pass the correct data to Smarty to begin with as this is a lot of hoop jumping to do something that should be straight forward.

Sign In or Register to comment.