|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Aliresalat Smarty Rookie
Joined: 09 Feb 2014 Posts: 23 Location: Iran
|
Posted: Wed Jul 16, 2014 4:48 am Post subject: Where is the problem? ( Php question ) |
|
|
Please see the :
Code: |
{php}
/**
* Include the Services_Gravatar class.
*/
require_once 'Services/Gravatar.php';
$gravatar = new Services_Gravatar('{$comments[comment].email}', array(
'size' => 180,
'rating' => Services_Gravatar::RATING_G,
));
{/php}
{php} echo $gravatar->getHtml(array('title' => 'John Doe', 'alt' => 'John Doe avatar')) {/php}
<br>
<a href="{php} echo $gravatar->getURL() {/php}">{php} echo $gravatar->getURL() {/php}</a>
|
Where is the problem?
Into the wrong outlet and not shown why my Gravatar
Code should be ok, the problem is
$gravatar = new Services_Gravatar('{$comments[comment].email}', array(
see : {$comments[comment].email}
please help |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Wed Jul 16, 2014 9:25 am Post subject: |
|
|
That's because you are use Smarty Variables in PHP Code
Try this (not tested)
{php}
/**
* Include the Services_Gravatar class.
*/
require_once 'Services/Gravatar.php';
$comments = $this->getTemplateVars('comments');
$gravatar = new Services_Gravatar('$comments[comment].email', array(
'size' => 180,
'rating' => Services_Gravatar::RATING_G,
));
{/php}
IMPORTANT NOTICE (Smarty 3.x)
{php} tags are deprecated from Smarty, and should not be used. Put your PHP logic in PHP scripts or plugin functions instead. |
|
Back to top |
|
Aliresalat Smarty Rookie
Joined: 09 Feb 2014 Posts: 23 Location: Iran
|
Posted: Wed Jul 16, 2014 9:38 am Post subject: Fatal error |
|
|
Fatal error:
Call to undefined method HD getTemplateVars() in C:\xampp\htdocs\library\smarty\templates_c\%%F9^F99^F99E15C9%%show.photo.tpl.php on line 786
I am using Smarty-3.1.16 |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Wed Jul 16, 2014 9:48 am Post subject: |
|
|
must be the SMARTY Object. Is in your case "$this->" the SMARTY Object? |
|
Back to top |
|
Aliresalat Smarty Rookie
Joined: 09 Feb 2014 Posts: 23 Location: Iran
|
Posted: Wed Jul 16, 2014 10:08 am Post subject: |
|
|
Grizzly wrote: |
must be the SMARTY Object. Is in your case "$this->" the SMARTY Object? |
no
Now what should I do
If the problem is with Java
{/ literal}
{$ comments [comment]. email}
/ literal}
It was
Php But you should also do something else |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Wed Jul 16, 2014 10:50 am Post subject: |
|
|
Do you have the Smarty Object in your context (between {php}{/php} block)?
If you have it, replace "$this->" with your smarty object instance (i. e. $smarty->). If not, please add the object too your context
EDIT:
Please create a new File in the smarty plugins folder and name this file "function.gravatar.php"
put this code in the file:
Code: |
<?php
function smarty_function_gravatar($params, Smarty_Internal_Template $template)
{
$mail = isset($params["mail"]) ? $params["mail"] : null;
if($mail != null) {
require_once 'Services/Gravatar.php'; //CHANGE THIS PATH, IF NECESSARY
$gravatar = new Services_Gravatar($mail, array(
'size' => 180,
'rating' => Services_Gravatar::RATING_G,
));
echo $gravatar->getHtml(array('title' => 'John Doe', 'alt' => 'John Doe avatar')); //CHANGE THIS AND USE PARAMS (Like $params["name"]), IF NECESSARY
echo '<br />';
echo '<a href="'.$gravatar->getURL().'">'.$gravatar->getURL().'</a>';
}
}
?>
|
in the template take the following "call"
Code: | {gravatar mail=$comments[comment].email} |
|
|
Back to top |
|
Aliresalat Smarty Rookie
Joined: 09 Feb 2014 Posts: 23 Location: Iran
|
Posted: Wed Jul 16, 2014 12:11 pm Post subject: |
|
|
Grizzly wrote: | Do you have the Smarty Object in your context (between {php}{/php} block)?
If you have it, replace "$this->" with your smarty object instance (i. e. $smarty->). If not, please add the object too your context
EDIT:
Please create a new File in the smarty plugins folder and name this file "function.gravatar.php"
put this code in the file:
Code: |
<?php
function smarty_function_gravatar($params, Smarty_Internal_Template $template)
{
$mail = isset($params["mail"]) ? $params["mail"] : null;
if($mail != null) {
require_once 'Services/Gravatar.php'; //CHANGE THIS PATH, IF NECESSARY
$gravatar = new Services_Gravatar($mail, array(
'size' => 180,
'rating' => Services_Gravatar::RATING_G,
));
echo $gravatar->getHtml(array('title' => 'John Doe', 'alt' => 'John Doe avatar')); //CHANGE THIS AND USE PARAMS (Like $params["name"]), IF NECESSARY
echo '<br />';
echo '<a href="'.$gravatar->getURL().'">'.$gravatar->getURL().'</a>';
}
}
?>
|
in the template take the following "call"
Code: | {gravatar mail=$comments[comment].email} |
|
Thank you
Please look up the notice :
Catchable fatal error: Argument 2 passed to smarty_function_gravatar() must be an instance of Smarty_Internal_Template, instance of HD given, called in C:\xampp\htdocs\library\smarty\templates_c\%%F9^F99^F99E15C9%%show.photo.tpl.php on line 781 and defined in C:\xampp\htdocs\library\smarty\libs\plugins\function.gravatar.php on line 2 |
|
Back to top |
|
Aliresalat Smarty Rookie
Joined: 09 Feb 2014 Posts: 23 Location: Iran
|
Posted: Wed Jul 16, 2014 12:12 pm Post subject: Please look up the notice |
|
|
Grizzly wrote: | Do you have the Smarty Object in your context (between {php}{/php} block)?
If you have it, replace "$this->" with your smarty object instance (i. e. $smarty->). If not, please add the object too your context
EDIT:
Please create a new File in the smarty plugins folder and name this file "function.gravatar.php"
put this code in the file:
Code: |
<?php
function smarty_function_gravatar($params, Smarty_Internal_Template $template)
{
$mail = isset($params["mail"]) ? $params["mail"] : null;
if($mail != null) {
require_once 'Services/Gravatar.php'; //CHANGE THIS PATH, IF NECESSARY
$gravatar = new Services_Gravatar($mail, array(
'size' => 180,
'rating' => Services_Gravatar::RATING_G,
));
echo $gravatar->getHtml(array('title' => 'John Doe', 'alt' => 'John Doe avatar')); //CHANGE THIS AND USE PARAMS (Like $params["name"]), IF NECESSARY
echo '<br />';
echo '<a href="'.$gravatar->getURL().'">'.$gravatar->getURL().'</a>';
}
}
?>
|
in the template take the following "call"
Code: | {gravatar mail=$comments[comment].email} |
|
Thank you
Please look up the notice :
Catchable fatal error: Argument 2 passed to smarty_function_gravatar() must be an instance of Smarty_Internal_Template, instance of HD given, called in C:\xampp\htdocs\library\smarty\templates_c\%%F9^F99^F99E15C9%%show.photo.tpl.php on line 781 and defined in C:\xampp\htdocs\library\smarty\libs\plugins\function.gravatar.php on line 2 |
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Wed Jul 16, 2014 12:31 pm Post subject: |
|
|
Do you have a backend/code behind file with an instance of Smarty?
like this:
Code: |
<?php
require_once('Smarty.class.php');
$smarty = new Smarty();
$foo = null;
$smarty->assign('comments', $foo);
$smarty->display('myTemplate.tpl');
?>
|
The Error message means, that you don't have a instance of smarty.
How your .PHP-File and .TPL-File looks like? |
|
Back to top |
|
Aliresalat Smarty Rookie
Joined: 09 Feb 2014 Posts: 23 Location: Iran
|
Posted: Wed Jul 16, 2014 12:55 pm Post subject: Ali |
|
|
Code: |
<?php
include('includes/ALIRESALAT09359743850.Core.php');
///////////////////////////////////////////////////////////////////////////// FUNCTIONS /////////////////////////
function GetCategorylinks($categoryid){
global $siteicategories, $langs;
$sReturn = ' ' . $langs['nav'] . ' <a href="'.GetUrl('index.php', 'c', $categoryid).'">'.ShortTitle($siteicategories[$categoryid]['title'], 18).'</a>';
if($siteicategories[$categoryid]['parentid']){
$sReturn = GetCategorylinks($siteicategories[$categoryid]['parentid']) . $sReturn;
}
return $sReturn;
}
///////////////////////////////////////////////////////////////////////////// FUNCTIONS /////////////////////////
$action = ForceIncomingString('action');
$imageid = ForceIncomingInt('id');
$smarty = new ALIRESALAT09359743850;
$showimage = 1;
if($action == 'insertcomment' AND $userinfo['allowcomment'])
{
$username = ForceIncomingString('username');
$content = ShortTitle(ForceIncomingString('content'), 200);
$email = ShortTitle(ForceIncomingString('email'), 200);
$vvckey = ForceIncomingInt('vvckey');
$vvc = ForceIncomingString('vvc');
if(strlen($username) == 0){
$errors[] = $sys_langs['please_enter'].$langs['cauthor'];
}
if(strlen($content) == 0){
$errors[] = $sys_langs['please_enter'].$langs['comment'].$langs['content'];
}
if(strlen($email) == 1){
$errors[] = $sys_langs['please_enter'].$langs['email'];
}
if(!CheckVVC($vvckey, $vvc)){
$errors[] = $sys_langs['badvvc'];
}
if(isset($errors))
{
$comment = array('username' => $username, 'content' => $_POST['content']);
$errortitle = $langs['publish'].$langs['comment'].$sys_langs['error'];
}else{
$DB->query("INSERT INTO " . TABLE_PREFIX . "comments VALUES (NULL, '$imageid', '$userinfo[allowcommentshow]', '$username', '$content', '$email', '".time()."')");
if(!$userinfo['allowcommentshow'])
{
$successtitle = $sys_langs['thanksforcomment'];
$success = $sys_langs['needadmincheckc'];
}
}
}
if(!$userinfo['allowview']) {
$errors = $sys_langs['nopermissionviewbig'];
$errortitle = $langs['browse'].$langs['image'].$sys_langs['error'];
$showimage = 0;
}else{
$image = $DB->query_first("SELECT i.imageid, i.categoryid, i.userid, i.username, i.sale, i.path, i.filename, i.price, i.title, i.description, i.keywords, i.url, i.viewcount, i.downloadcount, i.created, c.watermarkpos, c.sorting FROM " . TABLE_PREFIX . "images i LEFT JOIN " . TABLE_PREFIX . "categories c ON (c.categoryid = i.categoryid) WHERE (i.usergroupids = 'all' OR i.usergroupids LIKE '%(".$userinfo['groupid'].")%') AND i.actived = 1 AND c.actived = 1 AND i.imageid = $imageid ");
if (!$image){
$errors = $sys_langs['noimage_or_nopermission'];
$errortitle = $langs['browse'].$langs['image'].$sys_langs['error'];
$showimage = 0;
}else{
if($action != 'insertcomment' AND !IsGet('p')){
$DB->query("UPDATE " . TABLE_PREFIX . "images SET viewcount = (viewcount + 1) WHERE imageid = '$imageid'");
}
$image['keycode'] = md5($image['filename'].WEBSITE_KEY);
$siteicategories = array();
$geticategories = $DB->query("SELECT categoryid, parentid, title FROM " . TABLE_PREFIX . "categories WHERE actived = 1 ORDER BY ordernum ASC");
while($icategory = $DB->getrow($geticategories)){
$siteicategories[$icategory['categoryid']] = $icategory;
}
$categorylinks = GetCategorylinks($image['categoryid']);
$image_path = BASEPATH.'MyWebsiteImages/'.$image['path'].'_'.WEBSITE_KEY.'/original/'.$image['filename'];
if (!file_exists($image_path)) {
$image_path = BASEPATH.'MyWebsiteImages/'.$image['path'].'_'.WEBSITE_KEY.'/760x760/'.$image['filename'];
}
$image_size = @getimagesize($image_path);
$image['width'] = $image_size[0];
$image['height'] = $image_size[1];
$image['filesize'] = DisplayFilesize(@filesize($image_path));
$smarty->assign('image', $image);
if($image['keywords']){
$smarty->assign('metakeywords', $image['keywords'] . ','.$mainsettings['siteKeywords']);
$smarty->assign('metadescription', $image['keywords'] . ',' .$mainsettings['siteMeta']);
}
if($image['sorting'] == 'tup') {
$prevorderbysql = " ORDER BY imageid DESC ";
$prevWhere = " imageid < '$imageid' ";
$nextorderbysql = " ORDER BY imageid ASC ";
$nextWhere = " imageid > '$imageid' ";
}else{
$prevorderbysql = " ORDER BY imageid ASC ";
$prevWhere = " imageid > '$imageid' ";
$nextorderbysql = " ORDER BY imageid DESC ";
$nextWhere = " imageid < '$imageid' ";
}
$previmage = $DB->query_first("SELECT imageid FROM " . TABLE_PREFIX . "images WHERE (usergroupids = 'all' OR usergroupids LIKE '%(".$userinfo['groupid'].")%') AND actived = 1 AND categoryid = '$image[categoryid]' AND ".$prevWhere.$prevorderbysql);
$nextimage = $DB->query_first("SELECT imageid FROM " . TABLE_PREFIX . "images WHERE (usergroupids = 'all' OR usergroupids LIKE '%(".$userinfo['groupid'].")%') AND actived = 1 AND categoryid = '$image[categoryid]' AND ".$nextWhere.$nextorderbysql);
$smarty->assign('previmageid', $previmage['imageid']);
$smarty->assign('nextimageid', $nextimage['imageid']);
if($image['userid']){
$user = $DB->query_first("SELECT userid, joindate, userfullname, usercompany, useraddress, userpostcode, usertel, userfax, useronline, userwebsite, avatar, magham, laghab, jensiyat, vtahol, tavalod, keshvar, ostan, shahr, dustm1, dustm2, dustm3, dustm4 FROM " . TABLE_PREFIX . "users WHERE activated = 1 and userid = '$image[userid]' ");
if ($user){
$smarty->assign('user', $user);
}
}
$page = ForceIncomingInt('p', 1);
$NumPerPage = 10;
$start = $NumPerPage * ($page-1);
$getcomments = $DB->query("SELECT * FROM " . TABLE_PREFIX . "comments WHERE actived = 1 AND imageid = '$imageid' ORDER BY commentid ASC LIMIT $start,$NumPerPage");
$maxrows = $DB->query_first("SELECT COUNT(commentid) AS value FROM " . TABLE_PREFIX . "comments WHERE actived = 1 AND imageid = '$imageid' ");
$comments = $DB->getrows($getcomments);
$totalpages = ceil($maxrows['value'] / $NumPerPage);
$smarty->assign('pagelist', Iif($totalpages>1, GetPageList('show.photo.php', $totalpages, $page, 20, 'id', $imageid), ''));
$smarty->assign('comments', $comments);
$smarty->assign('start', $start);
$smarty->assign('totalcomments', $maxrows['value']);
}
}
if($userinfo['allowcomment']){
header("Expires: Mon, 18 Jul 1988 01:08:08 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
$smarty->assign('vvckey', CreateVVC());
$smarty->assign('comment', $comment);
}
$smarty->assign('showimage', $showimage);
//if(!$mainsettings['siteAllowGuest']){
// $smarty->assign('loginforview', $sys_langs['loginforview']);
//}else{
$getimages = $DB->query("SELECT i.imageid, i.path, i.filename, i.title FROM " . TABLE_PREFIX . "images i LEFT JOIN " . TABLE_PREFIX . "categories c ON (c.categoryid = i.categoryid) WHERE (i.usergroupids = 'all' OR i.usergroupids LIKE '%(".$userinfo['groupid'].")%') AND i.actived = 1 AND c.actived = 1 ORDER BY rand() LIMIT 10");
$images = $DB->getrows($getimages);
$smarty->assign('images', $images);
//}
$pagenav = '<a href="'.GetUrl('index.php').'">'.$langs['home'].'</a>'
.$categorylinks
.Iif($image['imageid'], ' '.$langs['nav'].' <a href="'.GetUrl('show.photo.php', 'id', $image['imageid']).'">'.Iif($image['title'], ShortTitle($image['title'], 36), $langs['notitle'].$langs['image']).'</a>');
$smarty->assign('pagenav', $pagenav);
$smarty->assign('userinfo', $userinfo);
$smarty->assign('pagetitle', Iif($image['title'], $image['title'] . ' - ' ) .$mainsettings['siteTitle']);
$smarty->interPlay('show.photo.tpl');
?>
|
Code: |
{if $totalcomments}
{section name=comment loop=$comments}
<br><br>
{gravatar mail=$comments[comment].email} SEEEEEEEEEE
<div style="margin-top: 4px; padding: 4px; border: 1px solid rgb(488, 102, 291); background: none repeat scroll 0% 0% rgb(248, 248, 248);">
name : <span style="color: #ff0000;"> {$comments[comment].username} </span> date : <span style="color: #ff0000;">{$comments[comment].created|DisplayDate} </span>
</div>
<div class="number">{math equation="x + y" x=$smarty.section.comment.rownum y=$start}<sup>#</sup></div>
<div class="comment">
<div dir="rtl" class="info">
{$comments[comment].content|nl2br}
</div>
</div>
<hr>
</div>
{/section}
{$pagelist}
{else}
<div style="margin-top: 4px; padding: 7px; border: 4px solid rgb(788, 202, 211); background: none repeat scroll 0% 0% rgb(248, 248, 248);">
no com
</div>
{/if}
</td>
|
Change the code : function smarty_function_gravatar($params, $smarty, $template)
Error message :
Warning: Missing argument 3 for smarty_function_gravatar(), called in C:\xampp\htdocs\library\smarty\templates_c\%%F9^F99^F99E15C9%%show.photo.tpl.php on line 781 and defined in C:\xampp\htdocs\library\smarty\libs\plugins\function.gravatar.php on line 2 |
|
Back to top |
|
Aliresalat Smarty Rookie
Joined: 09 Feb 2014 Posts: 23 Location: Iran
|
Posted: Wed Jul 16, 2014 1:04 pm Post subject: After the change |
|
|
After the change code :
|
|
Back to top |
|
Grizzly Smarty Pro
Joined: 15 Apr 2011 Posts: 172 Location: Germany
|
Posted: Wed Jul 16, 2014 2:04 pm Post subject: |
|
|
This definition:
Code: | function smarty_function_gravatar($params, Smarty_Internal_Template $template) |
must be right. But I think your Object "smarty" is not a Instanceof Smarty. And that's why you get the error. |
|
Back to top |
|
Aliresalat Smarty Rookie
Joined: 09 Feb 2014 Posts: 23 Location: Iran
|
Posted: Wed Jul 16, 2014 2:19 pm Post subject: |
|
|
Grizzly wrote: | This definition:
Code: | function smarty_function_gravatar($params, Smarty_Internal_Template $template) |
must be right. But I think your Object "smarty" is not a Instanceof Smarty. And that's why you get the error. |
Again, changed
I did not notice User Photos are not displayed
see : function smarty_function_gravatar($params, &$smarty)
------------------
My friend is there another way that I can show the user's photo in the comments section? |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jul 16, 2014 2:31 pm Post subject: |
|
|
Note that in Smarty 3 the template object is passed to plugins, not the smarty object as in Smarty 2. You can still get the Smarty object.
Code: | $smarty = $template->smarty; |
Sorry, ich vergas das ich gerade im deutschen Forum bin..... |
|
Back to top |
|
Aliresalat Smarty Rookie
Joined: 09 Feb 2014 Posts: 23 Location: Iran
|
Posted: Wed Jul 16, 2014 2:45 pm Post subject: Thanks |
|
|
Thank you Grizzly |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|