xoops forums

JamesSAEP

Just can't stay away
Posted on: 2005/6/23 17:04
JamesSAEP
JamesSAEP (Show more)
Just can't stay away
Posts: 732
Since: 2005/2/28
#1

Custom Block - code help

I'm trying to make a custom block that will display the "Inbox" when the user has messages. I've pasted the code below in the Content area and set it to PHP Script. I've tried php script, html, html autoformat and it doesn't display the "inbox." There are 4 messages in the inbox waiting to be viewed.
What else needs to be done for this to work?

<table cellspacing="0">
  <
tr>
    <
td id="usermenu">
      <{if 
$block.new_messages 0}>
        <
class="highlight" href="<{$xoops_url}>/viewpmsg.php"><{$block.lang_inbox}> (<span style="color:#ff0000; font-weight: bold;"><{$block.new_messages}></span>)</a>
      <{/if}>
    </
td>
  </
tr>
</
table>

Antoine

Friend of XOOPS
Posted on: 2005/6/23 17:19
Antoine
Antoine (Show more)
Friend of XOOPS
Posts: 112
Since: 2004/11/14
#2

Re: Custom Block - code help

Hmm if I understand this correctly you are trying to directly link block code from your theme file?

The most correct way to make a block is to first setup your own module and then making a block inside this module.

I cannot go into all the details for making modules but in this case you should create your own directory under the /modules dir and it should contain a file named xoops_version.php looking like this:

$modversion['name'] = <name>;
$modversion['version'] = <version>;
$modversion['description'] = <description>;
$modversion['author'] = <author>;
$modversion['credits'] = <credits>;
$modversion['help'] = <help>;
$modversion['license'] = <license>;
$modversion['official'] = 0;
$modversion['image'] = "images/<an optional image to display in admin section>";
$modversion['dirname'] = <name of dir under modules>;

$modversion['hasAdmin'] = 0;
$modversion['hasMain'] = 0;

$modversion['blocks'][1]['file'] = <block filename>;
$modversion['blocks'][1]['name'] = <block name>;
$
$modversion['blocks'][1]['description'] = <description>;
$modversion['blocks'][1]['show_func'] = <function to invole to show render the block>;
$modversion['blocks'][1]['template'] = <any template file you might be using to render the block>;


This will basically setup a module with one block and without and admin or main stuff and provides a basic framework to install your block into XOOPS and manage it's display through teh configuration tools.

How to setup the rest is a bit too much to get into. Best read up and have a look at the sample XOOPS module if that's still available.

JamesSAEP

Just can't stay away
Posted on: 2005/6/23 17:32
JamesSAEP
JamesSAEP (Show more)
Just can't stay away
Posts: 732
Since: 2005/2/28
#3

Re: Custom Block - code help

Thanks for the reply, Antoine.

Is creating a module necessary for just wanting to display one block of information? I thought it would be easier to just use Administration -> blocks -> Add a new block?

Antoine

Friend of XOOPS
Posted on: 2005/6/23 17:51
Antoine
Antoine (Show more)
Friend of XOOPS
Posts: 112
Since: 2004/11/14
#4

Re: Custom Block - code help

True if you want a block with semi-static content (though you can allways use the provided tags). The problem however is: where does the template get $blocks.new_messages assigned? If it isn't set Smarty will interpret it as false and therefore the link will never get rendered.

JamesSAEP

Just can't stay away
Posted on: 2005/6/23 17:58
JamesSAEP
JamesSAEP (Show more)
Just can't stay away
Posts: 732
Since: 2005/2/28
#5

Re: Custom Block - code help

Yesterday I started a thread on trying put the inbox into the theme.html file and Mith wrote Quote:
The code for checking whether the user has messages is not in the template, but in the block code (modules/system/system_blocks.php - the userinfo_show() function, I think it is called)

Is this what need to be referenced some how?

JamesSAEP

Just can't stay away
Posted on: 2005/6/23 22:04
JamesSAEP
JamesSAEP (Show more)
Just can't stay away
Posts: 732
Since: 2005/2/28
#6

Re: Custom Block - code help

bump -

Antoine

Friend of XOOPS
Posted on: 2005/6/24 11:43
Antoine
Antoine (Show more)
Friend of XOOPS
Posts: 112
Since: 2004/11/14
#7

Re: Custom Block - code help

That is one one the things that need to be referenced. But your "somehow" suggests that you don't know how.

Unfortunately this forum is not meant to give online courses on PHP programming. You have to have a decent grasp of PHP to make custom modules (and blocks) and be able to read and understand a lot of the sourcecode. Both the kernel and other core class code as the modules so that you can see what the structure is and how the core functionalities can be used.

I think I'd better and by saying that custom block coding is beyond the scope of the Beginner's forum. Good luck though.

JamesSAEP

Just can't stay away
Posted on: 2005/6/28 14:45
JamesSAEP
JamesSAEP (Show more)
Just can't stay away
Posts: 732
Since: 2005/2/28
#8

Re: Custom Block - code help

Quote:

Antoine wrote:
That is one one the things that need to be referenced. But your "somehow" suggests that you don't know how.


Correct, Antoine, I don't know. I wasn't sure if all that was needed was an include statement or something easy and changing the block to php script...

Thanks.

hsalazar

Just popping in
Posted on: 2005/6/28 16:13
hsalazar
hsalazar (Show more)
Just popping in
Posts: 78
Since: 2003/2/6 1
#9

Re: Custom Block - code help

Jamescne:

Try the following code:
global $xoopsUser;
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')));
$msgs $pm_handler->getCount($criteria);
}
$xoops_url XOOPS_URL
if (
$msgs 0) {
echo 
"<table cellspacing='0'><tr><td id='usermenu'><a class='highlight' href='$xoops_url/viewpmsg.php'>You have new messages (<span style='color:#ff0000; font-weight:
bold;'>"
.$msgs."</span>)</a></td></tr></table>";
}


How does this work? Here's a brief explanation.

First you need to determine if there's new private messages for the logged user. This won't work for anonymous users, since all the code is wrapped in an if statement that precludes it.

One line instantiates the private message handler. Then we create a mixed criteria that includes the actual user id and as far as I can see, the existence of non-read messages.

Then we assign to a variable the result of counting the non-read messages sent to the user. If this variable is larger than zero, that is, if there are non-read private messages addressed to the user, then we echo to the screen the table containing the count and the link to the private message page.

A couple of extra notes:

1) Don't include the opening and closing tags for PHP. They are already included.

2. Don't try to use Smarty variables. All blocks are rendered through a template that already exists, so you can only use general variables, as in the example above.

I hope this works.

Cheers

JamesSAEP

Just can't stay away
Posted on: 2005/6/28 16:27
JamesSAEP
JamesSAEP (Show more)
Just can't stay away
Posts: 732
Since: 2005/2/28
#10

Re: Custom Block - code help

hsalazar -

That worked and is exactly what I was after. Thanks for the explaination. I knew it didn't take writing a module to get what I was after.

Thanks again!!!!!!!!!!