xoops forums

3lr0n

Not too shy to talk
Posted on: 2009/12/5 9:49
3lr0n
3lr0n (Show more)
Not too shy to talk
Posts: 167
Since: 2004/3/13
#1

smarty global variables

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?

3lr0n

Not too shy to talk
Posted on: 2009/12/6 19:57
3lr0n
3lr0n (Show more)
Not too shy to talk
Posts: 167
Since: 2004/3/13
#2

Re: smarty global variables

anyone can help me?

trabis

Core Developer
Posted on: 2009/12/6 22:26
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#3

Re: smarty global variables

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.

3lr0n

Not too shy to talk
Posted on: 2009/12/6 22:49
3lr0n
3lr0n (Show more)
Not too shy to talk
Posts: 167
Since: 2004/3/13
#4

Re: smarty global variables

it works.. (as usual)

thanks trabis

Anonymous

Posted on: 2009/12/7 2:30
Anonymous
Anonymous (Show more)
Posts: 0
Since:
#5

Re: smarty global variables

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

trabis

Core Developer
Posted on: 2009/12/7 11:15
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#6

Re: smarty global variables

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:
<?php
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:

global $xoopsUser, $xoopsModule;
if (is_object($xoopsUser)) {
$pm_handler =& xoops_gethandler('privmessage');

$criteria = new CriteriaCompo(new Criteria('read_msg', 0));
$criteria->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 Panel</a> | <a href="<{$xoops_url}>/admin.php">Admin Panel</a> | <a href="<{$xoops_url}>/user.php?op=logout">Log Out</a>
    <{elseif 
$xoops_isuser}>
    <
a href="<{$xoops_url}>/user.php">User Panel</a> | <a href="<{$xoops_url}>/user.php?op=logout">Log Out</a>
    <{else}>
    <
a href="<{$xoops_url}>/register.php">Register Now</a> | <a href="<{$xoops_url}>/user.php">Log in</a> | <a href="<{$xoops_url}>/user.php#lost">Lost Password</a>
    <{/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>

trabis

Core Developer
Posted on: 2009/12/7 11:26
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#7

Re: smarty global variables

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:
<?php
global $xoTheme;
$xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js');
?>

Anonymous

Posted on: 2009/12/7 19:17
Anonymous
Anonymous (Show more)
Posts: 0
Since:
#8

Re: smarty global variables

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 ?

trabis

Core Developer
Posted on: 2009/12/7 19:24
trabis
trabis (Show more)
Core Developer
Posts: 2268
Since: 2006/9/1 1
#9

Re: smarty global variables

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.