Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: onijin on May 10, 2006, 01:07:17 PM

Title: Special *annoying* message for members with 0 posts
Post by: onijin on May 10, 2006, 01:07:17 PM
Hi, my forums are plagued with lurkers, and I'm trying to put a stop to it.  So what I'm trying to do, is members with a post count of zero, have a message that is constantly  "reminding" them they have yet to post.  And have it disappear after the first post.

I've been messing with some codes, but can't seem to get the right combination.  I used:


// Have they posted yet?
{
if ($context['user']['posts'] = 0)

echo '

<tr>
<td colspan="2" width="100%" align="left" valign="top" class="windowbg2">
<span style="font-size: 100%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '

</span>!&nbsp;&nbsp;<br />You have never posted in the forums before! Make your first post today and say hello to our community in our <a href=/forum/index.php?board=48.0>Introductions</a> board.<br /><br /> Why not start with your first post today and become an active part of our community.  We are waiting for you!
</td>
</tr>';
}



in index.template.php
and the message is shown regardless of post count. obviously "if ($context['user']['posts'] = 0)" is wrong.  Any advice would be appreciated.  ^_^
Title: Re: Special *annoying* message for members with 0 posts
Post by: ruzster on May 10, 2006, 03:34:21 PM

if ($user_info['posts'] = 0)
 
                echo '
 
                               <tr>
                                    <td colspan="2" width="100%" align="left" valign="top" class="windowbg2">
                                         <span style="font-size: 100%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '
                                         
                </span>!&nbsp;&nbsp;<br />You have never posted in the forums before! Make your first post today and say hello to our community in our <a href=/forum/index.php?board=48.0>Introductions</a> board.<br /><br /> Why not start with your first post today and become an active part of our community.  We are waiting for you!
                                    </td>                         
                               </tr>';


Don't forget to add $user_info to your globals.
Title: Re: Special *annoying* message for members with 0 posts
Post by: onijin on May 10, 2006, 03:46:55 PM
looks promising.  When my host comes back up, test it out, and let you know if it worked.  ~thanx~ ruz
Title: Re: Special *annoying* message for members with 0 posts
Post by: winrules on May 10, 2006, 03:51:51 PM
also you need to use a double ==
Title: Re: Special *annoying* message for members with 0 posts
Post by: Harzem on May 10, 2006, 03:52:30 PM
if ($context['user']['posts'] = 0)

should be

if ($context['user']['posts'] == 0)

just a bit php experience ;)

edit: winrules, just 39 seconds faster than me :P
Title: Re: Special *annoying* message for members with 0 posts
Post by: onijin on May 10, 2006, 04:11:08 PM
hmm... I even tried the double...


i tried

= 0
== 0
< 1

but =&== didn't show the message at all. (when post count was 0 on a new account)

< 1 however did... but didn't go away after the first post.
Title: Re: Special *annoying* message for members with 0 posts
Post by: onijin on May 10, 2006, 05:04:03 PM
okay.

Added the $user_info to the global and used    if ($user_info['user']['posts'] == 0)

that gave me a parse error.

removed the global, changed it to   if ($context['user']['posts'] == 0)

and the message comes up.  0 posts and it's there.  However, after posting, still wont go away.
Title: Re: Special *annoying* message for members with 0 posts
Post by: Harzem on May 10, 2006, 05:34:13 PM
Probably you coded the global declaration line incorrectly. Can you post that line?
Title: Re: Special *annoying* message for members with 0 posts
Post by: onijin on May 10, 2006, 05:38:19 PM
   global $context, $settings, $options, $scripturl, $txt, $modSettings, $user_info;
Title: Re: Special *annoying* message for members with 0 posts
Post by: Harzem on May 10, 2006, 05:39:34 PM
Use

if ($user_info['posts'] == 0)
Title: Re: Special *annoying* message for members with 0 posts
Post by: onijin on May 10, 2006, 05:43:11 PM
omg.  That worked.

LoL~!


sweeet~!  thanx guys~!   ^_^
Title: Re: Special *annoying* message for members with 0 posts
Post by: Harzem on May 10, 2006, 05:59:53 PM
Have a nice forum with thousands of members :)
Title: Re: Special *annoying* message for members with 0 posts
Post by: onijin on May 10, 2006, 06:01:17 PM
heh~!

thanks...

Kinda hard to get members

{insert shameless plug here}
Title: Re: Special *annoying* message for members with 0 posts
Post by: Red-Omni on July 10, 2006, 09:09:53 AM
hey how can i get my hands on that mod/code ??

i need it for my forums as well , as i have the same issue with people joining and then not posting .
Title: Re: Special *annoying* message for members with 0 posts
Post by: Alan S on July 10, 2006, 09:23:56 AM
yea me too! could some one post the full working code to it and where do you post it in the index.template.php?
Title: Re: Special *annoying* message for members with 0 posts
Post by: Alan S on July 10, 2006, 05:00:48 PM
Figured it out , so for anyone who wants it* ,

Index.template.php

Search For

global $context, $settings, $options, $scripturl, $txt, $modSettings;

Replace With

global $context, $settings, $options, $scripturl, $txt, $modSettings, $user_info;

Find

<div align="center" style="width: 90%; margin-left: auto; margin-right: auto; margin-top:10px; border: 0px solid;" class="middletext">
', $settings['custom_global_html'], '
</div>';


Add After

// Have they posted yet?
{
                     if ($user_info['posts'] == 0)

echo '

<tr>
<td colspan="2" width="100%" align="left" valign="top" class="windowbg2">
<span style="font-size: 100%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '

</span>!&nbsp;&nbsp;<br />REPLACE THIS TEXT WITH YOUR MESSAGE , HTML IS ALLOWED<br /><br />
</td>
</tr>';
}



I think this should be moved to the tips & tricks section , its fairly handy


*Code may change depending on theme , i used the index.template.php from the Dilbert MC theme
Title: Re: Special *annoying* message for members with 0 posts
Post by: onijin on July 10, 2006, 07:00:42 PM
actually... someone [Ruzster] made a mod (i've been using that).  Doesn't seem like it was approved for distrobution tho.  Works really well!  I like it.
Title: Re: Special *annoying* message for members with 0 posts
Post by: ruzster on July 10, 2006, 08:23:07 PM
http://mods.simplemachines.org/index.php?mod=340 (http://mods.simplemachines.org/index.php?mod=340)

It's been approved... Finally.
Title: Re: Special *annoying* message for members with 0 posts
Post by: Alan S on July 11, 2006, 11:21:01 AM
dammit ! lol , i spent the best part of 9 hours figuring it out!!!!!!!!! ah well.................at least i leart something....................
Title: Re: Special *annoying* message for members with 0 posts
Post by: ^DooM^ on July 12, 2006, 08:44:46 AM
Hi All,

I wonder if you can help me out. I am trying to do something similar to this on my forum except instead of displaying an annoying message if you dont post I want to ban a user if inactive for X number of days.

I have setup all the database settings i need and added the options in the admin panel etc. What I can't get my head around is how I can check the user has been offline for X Days.

In this annoying display message mods case it checks when they login. If in my case they login their X days inactive will be reset and will never be true. I thought about adding a manual button to loop through every user and check / add the ban but I would like this to be automated so I can set it and forget it. The other way I thought of doing it is run the check when I login but that seems like an ugly hack to me.

I have just thought of another way of doing this as I typed. By adding a small php script that I can run via crontab. Would this be a good way of doing what I need or is there a better way my tiny mind hasn't thought of.

Any help would be appreciated.

Kind regards,

Jon.