1
shank
Need help with a simple Smarty insert
  • 2005/12/21 1:37

  • shank

  • Not too shy to talk

  • Posts: 144

  • Since: 2004/8/17


I need to make a smarty insert that assigns the value of a cookie to a varible. What I am doing is working on a popup window for new private messages. This is what I did so far:

When a user logs in and has new messages they get a popup that tells them how many. this popup also sets a cookie named 'pms' with a value of $msgcount.

I have made a smarty insert that checks if they have unread messages and assigns the number of unread messages to $msgcount. and I was thinking I could make another one that would check for the cookie and assign the value to $cookie then in my theme I could do this:

<{if $xoops_isuser}><{insert name="pms"}><{insert name="cookie"}><{/if}>
<{if 
$msgcount $cookie}>
<
body onLoad="javascript: poponload()"><{else}><body><{/if}>


What I need help with apparently is the insert.cookie.php file for the plugins folder.

I tried this:
<?
function 
smarty_insert_cookie()
{
$cookie=$_COOKIE['pms'];
}
?>
and it didn't work.

Help me out here. I know this is simple.

Thanks,
Steve
s l s h a n k l e @ b e l l s o u t h . n e t

2
AAINC
Re: Need help with a simple Smarty insert
  • 2005/12/21 2:35

  • AAINC

  • Not too shy to talk

  • Posts: 121

  • Since: 2003/10/18



3
AAINC
Re: Need help with a simple Smarty insert
  • 2005/12/21 2:38

  • AAINC

  • Not too shy to talk

  • Posts: 121

  • Since: 2003/10/18


Quote:

AAINC wrote:
This still works.


Create a php file and name it ex_assign.php

ex_assign.php
<?php
// $Id$
// FILE        ::    ex_assign.php
// AUTHOR    ::    Ryuji AMANO <info@joetsu.info>
// WEB        ::    Ryu's Planning <http://ryus.joetsu.info/>
//

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')));
    
$this->assign("ex_new_messages"$pm_handler->getCount($criteria));
}

if ( 
is_object($xoopsModule) ) {
    
$this->assign('ex_moduledir'$xoopsModule->getVar('dirname'));
}

?>


Put ex-assign.php inside the THEME folder.

Now call ex_assign.php into theme by placing the below code right after the body statement in the theme.html.
<{include_php file="$xoops_rootpath/themes/YOUR_THEME_NAME_HERE/ex_assign.php"}>


Now place the below code where you want the message alert to go inside the theme.html
<{if $ex_new_messages 1}>
<
a href="<{$xoops_url}>/viewpmsg.php">Private Messages</a>
<{/if}>
<{if 
$ex_new_messages 0}>
<{if 
$smarty.server.SCRIPT_NAME == "/index.php"}>
<
script language="javascript" type="text/javascript">
<!--
msg="<b>Hello! <{$xoops_uname}></b><br />You have <span style='color:#ff0000; font-weight: bold;'><{$ex_new_messages}></span> new Message(s)";
openwin (msg)
function 
openwin(message) {
open("""message""width=250,height=150,toolbar=no,scrollbars=yes,resizable=yes");
w.focus();
w.document.open();
w.document.write("<html><head></head><meta http-equiv='content-type' content='text/html; charset=<{$xoops_charset}>' /><title>You've Got Messages</title><body><br><br><center>");
w.document.write(message);
w.document.write("<br /><br /><a href="javascript:window.opener.location='<{$xoops_url}>/viewpmsg.php';window.close();">");
w.document.write("View</a>");
w.document.write("</center></body></html>");
w.document.close();
}
// -->
</script>
<{/if}>
<
a  href="<{$xoops_url}>/viewpmsg.php">
<
span style="color:#ff6600;"><{$ex_new_messages}>-Message(s)
</
span></a>
<{/if}>


With this you not only have a Red link saying how many new messages you have, when you return to front page a popup tells you also. If no new messages it just says "Private Message, linking to the inbox.

I am sure someone could clean up and update, but this works in XOOPS 2 XOOPS 2.2 and XOOPS 2.2.3a.

4
shank
Re: Need help with a simple Smarty insert
  • 2005/12/21 3:21

  • shank

  • Not too shy to talk

  • Posts: 144

  • Since: 2004/8/17


Yeah, but I don't want it to pop up everytime someone goes to the index page. I want it to pop up only if they recieve a new message while they are online on any page, or the first time they log in.

Everything works, and the cookie is set. I just need to assign the cookie value to a varible that can be called in the theme file then compare that varible to $msgcount.

Thanks anyway.
s l s h a n k l e @ b e l l s o u t h . n e t

5
shank
Re: Need help with a simple Smarty insert
  • 2005/12/21 3:31

  • shank

  • Not too shy to talk

  • Posts: 144

  • Since: 2004/8/17


Nevermind, I figured it out.
This
<?
function 
smarty_insert_cookie()
{
$cookie=$_COOKIE['pms'];
}
?>


Should've been this
<?
function 
smarty_insert_cookie()
{
$cookie=$_COOKIE['pms'];
$GLOBALS['xoopsTpl']->assign('cookie'$cookie);
}
?>
s l s h a n k l e @ b e l l s o u t h . n e t

6
Dave_L
Re: Need help with a simple Smarty insert
  • 2005/12/21 9:21

  • Dave_L

  • XOOPS is my life!

  • Posts: 2277

  • Since: 2003/11/7


There's also a built-in Smarty tag for accessing cookies:
http://smarty.php.net/manual/en/language.variables.smarty.php

So this should also too: <{$smarty.cookies.pms}>

Login

Who's Online

130 user(s) are online (92 user(s) are browsing Support Forums)


Members: 0


Guests: 130


more...

Donat-O-Meter

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

Latest GitHub Commits