Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.
Please upgrade here. These earlier versions are no longer being updated and have security issues.

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:

"themes/my_theme/views/discussion/index.tpl"

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 'Name).'" href="'.Url('/profile/'.$User->UserID.'/'.urlencode($User->Name)).'"'.$CssClass.'>'
.Img($PhotoUrl, array('alt' => urlencode($User->Name)))
.'
'; } 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.

Cheers

Comments

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

    library/vendors/SmartyPlugins/modifier.changebasename.php

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

    You use it like this:



    image
    {$comment.InsertName}


    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.

    Cheers
Sign In or Register to comment.