1
3lr0n
smarty global variables
  • 2009/12/5 9:49

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


Hello, I need to make use of loged user avatar and was planning to set a smarty global variable with this (<{$xoops_avatar}>), but cant find where this vbles are declarated. Any help on finding?

2
3lr0n
Re: smarty global variables
  • 2009/12/6 19:57

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


anyone can help me?

3
trabis
Re: smarty global variables
  • 2009/12/6 22:26

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


class/theme.php line 268
if (isset($GLOBALS['xoopsUser']) && is_object($GLOBALS['xoopsUser'])) {
            
$this->template->assign(array(
                
'xoops_avatar' => $GLOBALS['xoopsUser']->getVar('user_avatar'),//add this
                
'xoops_isuser' => true ,
                
'xoops_userid' => $GLOBALS['xoopsUser']->getVar('uid'),
                
'xoops_uname' => $GLOBALS['xoopsUser']->getVar('uname'),
                
'xoops_name' => $GLOBALS['xoopsUser']->getVar('name'),
                
'xoops_isadmin' => $GLOBALS['xoopsUserIsAdmin']));
        } else {
            
$this->template->assign(array(
                
'xoops_isuser' => false,
                
'xoops_isadmin' => false));
        }

this will return the avatar file name so don't forget to refer to folder uploads in your img tag.

4
3lr0n
Re: smarty global variables
  • 2009/12/6 22:49

  • 3lr0n

  • Not too shy to talk

  • Posts: 167

  • Since: 2004/3/13


it works.. (as usual)

thanks trabis

5
Anonymous
Re: smarty global variables
  • 2009/12/7 2:30

  • Anonymous

  • Posts: 0

  • Since:


How to add it inside <{php}> tags in theme.html w/o modify class/theme.php ?

6
trabis
Re: smarty global variables
  • 2009/12/7 11:15

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


I would paste this line in top of the theme:
<{include_php file="file:$xoops_rootpath/themes/mytheme/extension.php"}>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
Then create the extension.php file inside the mytheme folder with the content:
if (isset($GLOBALS['xoopsUser']) && is_object($GLOBALS['xoopsUser'])) {
    
$this->assign('xoops_avatar' => $GLOBALS['xoopsUser']->getVar('user_avatar'));
        }
?>
Here is one example of an extension.php file for creating mainmenu and submenus (Credits to Ryuji AMANO): Quote:
add(new Criteria('to_userid', $xoopsUser->getVar('uid'))); $message = $pm_handler->getCount($criteria); $message =1; if ($message > 0) $message = "".$message.""; $this->assign("ex_new_messages", $message)); } if ( is_object($xoopsModule) ) { $this->assign('ex_moduledir', $xoopsModule->getVar('dirname')); } require_once XOOPS_ROOT_PATH."/modules/system/blocks/system_blocks.php"; $mainmenu = b_system_main_show(); foreach($mainmenu["modules"] as $module){ if (count($module["sublinks"]) > 0 ){ $mainmenu["sublinks"] = $module["sublinks"]; } } $this->assign("ex_mainmenu", $mainmenu); $this->assign("mymodules", $mainmenu["modules"]); global $xoopsRequestUri; if ( is_object($xoopsModule) ) { $this->assign('ex_moduledir', $xoopsModule->getVar('dirname')); $this->assign('ex_modulename', $xoopsModule->getVar('name')); if( count($xoopsModule->subLink()) > 0 ) { $replacedUri = preg_replace("/\/modules\/".$xoopsModule->getVar('dirname')."\/(.*)$/i", "$1", $xoopsRequestUri); foreach( $xoopsModule->subLink() as $sublink ) { if( $sublink['url'] == $replacedUri ) { $this->assign('ex_sublinkname', $sublink['name']); } } } } ?>
(I'm using quote because 'code' breaks the reg expression) And html code for it:
<div id="row1"
  <
div id="siteName"
    <
h1><{$xoops_sitename}>h1
  div
  <
div id="utility"
    <{if 
$xoops_isadmin}>
    <
a href="<{$xoops_url}>/user.php">User Panela> | <a href="<{$xoops_url}>/admin.php">Admin Panela> | <a href="<{$xoops_url}>/user.php?op=logout">Log Outa>
    <{elseif 
$xoops_isuser}>
    <
a href="<{$xoops_url}>/user.php">User Panela> | <a href="<{$xoops_url}>/user.php?op=logout">Log Outa>
    <{else}>
    <
a href="<{$xoops_url}>/register.php">Register Nowa> | <a href="<{$xoops_url}>/user.php">Log ina> | <a href="<{$xoops_url}>/user.php#lost">Lost Passworda>
    <{/if}>
  div
div>

<
div id="row2">
    <
img alt="" src="<{$xoops_imageurl}>images/gblnav_left.gif" height="32" width="4" id="gnl" /> <img alt="" src="<{$xoops_imageurl}>images/glbnav_right.gif" height="32" width="4" id="gnr" /> 
    <
div id="globalLink"
    <
a href="<{$xoops_url}>/" id="gl1" class="glink">
      
Home
      
a>
    <{foreach 
item=module from=$mymodules}>
    <
a href="<{$xoops_url}>/modules/<{$module.directory}>/" class="glink"><{$module.name}>a>
    <{/foreach}>
    div>
    <
form id="search_nav" action="<{$xoops_url}>/search.php" method="get"
      <
input type="text" name="query" size="16" onfocus="this.value=''" value="Enter keywords" /><input type="hidden" name="action" value="results" /><input type="submit" value="Go" />
    form
div>

<
div id="row3">
  <
img alt="" src="<{$xoops_imageurl}>images/tl_curve_white.gif" height="6" width="6" id="tl" /> <img alt="" src="<{$xoops_imageurl}>images/tr_curve_white.gif" height="6" width="6" id="tr" /> 
  <
div id="breadCrumb"
    <{foreach 
item=sublink from=$ex_mainmenu.sublinks}>
    <
a href="<{$sublink.url}>"><{$sublink.name}>a> |
    <{/foreach}>
    &
nbsp;
  div
  <
div id="pageName"
    <
h2><{$xoops_pagetitle}>h2
  div
div>

7
trabis
Re: smarty global variables
  • 2009/12/7 11:26

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Btw, if you are looking for adding javascipt files into your theme like jquery or others, the above option should be used. Js or css files should not be hardcoded in theme, they should be set from core so we can check for duplications. Use this inside extensions.php to include js:
global $xoTheme;
$xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
?>

8
Anonymous
Re: smarty global variables
  • 2009/12/7 19:17

  • Anonymous

  • Posts: 0

  • Since:


Thanks trabis,

I'm using php tags in theme.html file:

<{php}>
GLOBAL 
$xoopsUser;
$avatar $xoopsUser->getVar('user_avatar');
$GLOBALS['xoopsTpl']->assign('avatar'$avatar);
<{/
php}>


then use <{$avatar}> in image src.

is it valid ?

9
trabis
Re: smarty global variables
  • 2009/12/7 19:24

  • trabis

  • Core Developer

  • Posts: 2269

  • Since: 2006/9/1 1


Quote:
Mowaffaq wrote: Thanks trabis, I'm using php tags in theme.html file:
<{php}>
GLOBAL 
$xoopsUser;
$avatar $xoopsUser->getVar('user_avatar');
$GLOBALS['xoopsTpl']->assign('avatar'$avatar);
<{/
php}>
then use <{$avatar}> in image src. is it valid ?
I think it is, just do a check to see if $xoopsUser is an object.

Login

Who's Online

289 user(s) are online (162 user(s) are browsing Support Forums)


Members: 0


Guests: 289


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits