Archive for July, 2005

Bitwise Operators

4 Comments

So today after an interesting discussion with Kieran, one of the other MyBB developers, about showing different notices to users and such (such as if their private messaging quota is used) I suggested we use a bitfield/bitwise system for storing which “notices” the user still has visible (and hasn’t dismissed). Not knowing much about how bitwise works in PHP apart from how it’s calculated using binary I set out to do some experiementation and find out the end results.

Along with everything in PHP, bitwise operators are easy to grasp and can easily be used in IF statements to check the value of a “bit field”. Take a look at the following code:

<?php
$notices['can_view'] = 1;
$notices['can_post_threads'] = 2;
$notices['can_post_replies'] = 4;
$notices['can_edit'] = 8;

$testers[1] = 1;
$testers[2] = 5;
$testers[3] = 9;
$testers[4] = 14;

foreach($testers as $key => $tester)
{
    echo "$key";
    foreach($notices as $key => $notice)
    {
        if($tester & $notice)
        {
            echo " - $key";
        }
    }
    echo "<br />";
}
?>

Now thise code will print out the following:
1 - can_view
2 - can_view - can_post_replies
3 - can_view - can_edit
4 - can_post_threads - can_post_replies - can_edit

So basically we can store a lot of data (be it preferences, yes/no options, permissions) in the one column in the database and variable in PHP and just perform if()’s to see if a certain value is in the field. (or an option is selected in a users profile).

For example, using the above code the following code would calculate if a user ($tester[1]) had the can_edit permission:

if($tester[1] & $notices['can_edit'])
{
    echo "This user can edit";
}
else
{
    echo "This user cannot edit";
}

The other interesting this is that this would also allow users to easily and effectively add their own “user options” or “permissions” to MyBB without having to modify the database by adding a new column to store the data – in fact using bitwise operators would reduce the size of the database all together.

I can see many useful places this can be implemented in to MyBB:

  • The permissions system for user groups and forums
  • User options (such as if they want to receive email notification to threads)
  • Forum settings (such as is open, can use BB code)
  • Basically any other options which can have a yes/no or on/off value

Chances are we’ll end up moving to a system like this for MyBB for storing these preferences and permissions, but instead of running in to it we’ll research it some more and find out the best possible ways of implementing it.

(Someone sent me an email saying I should write more about PHP/MyBB here :P )

July 27th, 2005 4 Comments

Take Some Initiative?

6 Comments

I’m curious as to what she meant. I have some idea but I don’t want to be wrong and assume something again. I want things back how they were.

Forever and Always

(Image © Ky, 21st March 2004)

Of course, nobody here will understand anything about this image. It’s something of significance to me. Maybe it has some hidden words?

July 24th, 2005 6 Comments

Docking boxes

These docking boxes look fairly interesting and although it’s been possible for years, movable and dockable items seem to becoming more popular along with the implementation of AJAX to provide full customisation of a page to a visitor whilst saving their preferences for their next visit. Must see how this can be used in MyBB.

July 18th, 2005 0 Comments

Getting Beyond a Joke..

8 Comments

Comment Spam

This is since Saturday.

Okay, so two things are happening here.. I have a huge list in my keywords blacklist (meaning they should be sent directly to the spam section) however none of them are being marked as spam, they’re all being sent to the moderation queue (unapproved commenters require their comments to be moderated), and secondly: I’m getting the absolute hell spammed out of me.

I think it’s time to go back to using a Spam Karma or Spam Words, even though they used to chew up legitimate comments.

Maybe i’ll create a WordPress plugin which will automatically ban IP’s of spammers using htaccess (even though they’re mostly zombie computers) and redirect any of their requests to the comment file to a spammer page.

It’s getting annoying because for some reason the blacklist isn’t working as it should be – even though it is set up properly and keywords in the comments are in the blacklist. Anyone got any ideas? :-/

July 12th, 2005 8 Comments

So..

3 Comments

Alot’s happened recently and I haven’t really felt like wiritng here because of some other things that have happened and are happening in my life at the moment (which sort of affect everything) but here we are..

  • I went back to my High School to help them with their musical production, Grease, because on the opening night when I went it was absolutely shocking. So you could say I saved the show. Hehe.. Though I did have lots of fun whilst doing it.
  • As per my previous post, I finished my TAFE course. To my disappointment TAFE don’t give High Distinctions in anything, though i’m happy to say I got Distinctions in every module. Go me.. Hehe
  • I purchased a dedicated server for both SurfiOnline and MyBB (more so MyBB). This means that I can finally have some freedom in how things are setup and I don’t have to put up with the slow speeds of shared hosting and crappy uptime.
    • Right now i’ve setup Subversion to allow us to develop MyBB as a group alot easier with code management. I’ve also setup trac as a project manager which has an interface to subversion.
    • I’ve moved over several subdomains of both mybboard.com and surfionline.com to the new server however I haven’t moved anything major as of yet because I still need to test mail, as well as create name servers and fiddle around with DNS (uck.).
  • On Sunday (this last Sunday) I bought a new laptop to replace the one Harvey Norman lost (they will be paying for half of this machine). It is a Toshiba F10 (sorry Michelle, still not ready for a Powerbook ;) ). It cost $4,000 and came with a Canon MFP390 printer.
    • Intel Centrino M 2.0 Ghz processor
    • 1 GB DDR RAM (2x 512mb)
    • 100 GB Hard Disk Drive
    • 128mb Nvidia GeForce 5700 Go Video Card
    • 15.4″ Super Bright Widescreen LCD (And it is very bright with two lamps – looks awesome)
    • Built in TV Tuner (With Svideo/Component/Ant Inputs)
    • Remote Control
    • 100 MB LAN / 802.11g Wifi / Bluetooth
    • Harman/Kardon Speakers (These sound excellent)
    • Plus other stuff
    • Runs Windows XP Media Center Edition

I’ll try to update again soon, if i’m feeling more like it..

July 6th, 2005 3 Comments