Simply Program

Simply programming - It’s a life style

Archive for the 'Programming' Category...

Filed under Programming, PHP

This is quite a unique little function. It came in handy when I had to check a "global" array holding all key elements already loaded.

CODE:
  1. $foo = array('test1'=>"This is test 1",
  2.  
  3. 'test2'=>"This is test 2");
  4.  
  5. $global_bar = array('test1'=>'yep its loaded');
  6.  
  7. foreach($foo as $fkey=>$f){
  8.  
  9. if(!array_key_exists($fkey, $global_bar)){
  10.  
  11. // not there - keep going.
  12.  
  13. }else{
  14.  
  15. // Yep its there.
  16.  
  17. }
  18.  
  19. }

Very simple example above - for more information check php.net: http://www.php.net/manual/en/function.array-key-exists.php

Comments (0) Posted by sp on Friday, April 18th, 2008

Filed under Programming, PHP

Well, here I was again doing a fast freelance job for a friend - He wanted a full functioning forum up and ready to go as fast as possible. I of course thought of the very nice free system - phpbb(http://phpbb.com). To make things interesting we had already put in place a custom made membership system, the phpbb forum would now have to integrate into our Registration and Login process seamlessly.

My first instinct was to go to the boards on PHPBB and do a quick search to find my solution - It turns out the solution is not fully laid out... Or atleast to me it didn't seem to be layed out.

So after about 30-45 minutes looking over threads and replies I decided to just look at how PHPBB initiated its sessions and cookies and go for it myself.

Here are my easy steps to accomplish this login / registration task (I have no error checking/hack prevention in place for my example, I don't want to do everything for you now :) )

STEP 1 - REGISTRATION

CODE:
  1. //Query to select the max number of users in the table
  2. $sql = "SELECT MAX(user_id) AS total FROM phpbb_users";
  3. $select=mysql_query($sql);
  4. $row=mysql_fetch_array($select);
  5.  
  6. //Taking the max number of records and adding 1 for the next user_id
  7. $user_id=$row['total']+1;
  8.  
  9. //Query to insert the basics into the users table.
  10. //NOTE - Take validation into your own hands, this is just an example.
  11. $sql = "INSERT INTO phpbb_users (user_id, username, user_regdate,
  12. user_password, user_email,user_active)
  13. VALUES ($user_id, '$username',".time().",'$password','$email','1')";
  14.  
  15. //Insert the user
  16. $insert=mysql_query($sql);
  17.  
  18. //Setup the users group so he/she has posting ability.
  19. //Why group_id=3?
  20. //On a basic PHPBB installation:
  21. // ID #1 = Visitor/Guest
  22. // ID #2 = Admin
  23. // ID #3 = Basic registered user
  24. //If you have a custom user group setup,
  25. //replace 3 with the id number.
  26. $group_id=3;
  27.  
  28. $sql = "INSERT INTO phpbb_user_group (user_id,
  29. group_id, user_pending)
  30. VALUES ($user_id, $group_id, 0)";
  31.  
  32. //Insert user into the correct group.
  33. $insert=mysql_query($sql);
  34.  
  35. //Add in your own registration for your own website here.

STEP 2 - LOGIN

CODE:
  1. //Place this on top of your login script
  2.  
  3. define("IN_LOGIN", true);
  4. define('IN_PHPBB', true);
  5.  
  6. //Be sure to update the root path to match your forum settings
  7. $phpbb_root_path = './forum/';
  8. include($phpbb_root_path . 'extension.inc');
  9. include($phpbb_root_path . 'common.'.$phpEx);

While checking for the username/password within your own system (and succeeding) enter these few lines of code.

CODE:
  1. $select=mysql_query("SELECT * FROM phpbb_users WHERE username='".$username."'");
  2. $row=mysql_fetch_array($select);
  3. $userdata = session_pagestart($user_ip, PAGE_LOGIN);
  4. $session_id = session_begin($row['user_id'],
  5. $user_ip, PAGE_INDEX, FALSE, $autologin, '0');

The above peace of code will use PHPBB's own session handler to create the cookies / sessions needed to log the user into the forum - as well as your own system.

Enjoy!

Comments (0) Posted by sp on Tuesday, November 13th, 2007

Filed under Programming, AIR

Adobes Apollo project has been provided a new breath of life, which so conveniently is named AIR (Adobe Integrated Runtime). Yes, the AIR project is the same as Apollo just with a few new (advanced) features.

The key feature to Apollo/AIR is the runtime enviorment as it allows you to take your Javascript, HTML, Flash, or Flex application and turn it into a light desktop application.

Why do I say "light"? Frankly, the AIR runtime does not handle its resources and memory access very well - hence any large system seems clunky, and slow to response.

Now, what can a light application do? What is the Runtime useful for at this stage in the game?

Lets take a real world example - Pownce.com...
"You can access all of your Pownce notes just on our website or you can download a small program for your computer.

The software is available right now for Windows and Mac users and will be available for Linux soon too. It takes advantage of a new technology from Adobe called AIR, which is super useful."

Screenshot

View larger image

Yes... Pownce has created a very simple IM type application and integrated it to work directly with their website.

Now, however cool this might be - Is it really practical to have another system like this? I personally believe not, Pownce will not steal any facebookers just because they have a cool AIR application.

In my opinion the largest contribution this runtime offers is the ability to instantly update your users / members of new content on your website. Imagine your user having an instant notification sent right to their desktop when a user has posted a reply to their topic? Many of you will say... so... thats email? Not exactly, when it comes to automated responses email has some flaws.

Over all AIR is not fully operational, its real world examples and applications are more experiments / cool toys instead of practical applications.

I do however believe this will be quite revolutionary and will more then likely become an effective way to deliver fresh content to your users as well as communicate your users content with your website(Instant desktop updates without c++!).

More to come as I am now developing a few "Practical" applications for my employers.

RESOURCES

Adobe AIR
Adobe Showcase
O2Apps.com

Comments (0) Posted by sp on Sunday, November 11th, 2007

Filed under Programming, Javascript, CSS

Thank you google toolbar!!

Read more: http://www.htmldog.com/ptg/archives/000017.php

Fix: http://code.jenseng.com/google/

Enjoy ;)

Comments (0) Posted by sp on Sunday, October 28th, 2007

Filed under Programming, CSS / Design, CSS
CODE:
  1. A:active
  2. {
  3. outline: none;
  4. }
  5. A:focus
  6. {
  7. -moz-outline-style: none;
  8. }

Enjoy :)

Comments (0) Posted by sp on Sunday, October 28th, 2007

Filed under Programming, Hot or Not?

This morning right as I started working I noticed an interesting post on Digg... Manipulate images on the web?

Now, of course images can be manipulated on the web this wasn't the question; however, the way it was written made me check it out.

*Click* - FotoFlexer - *thinks: This seems like a whole lot of nothing*

FotoFlexer: FotoFlexer is the most powerful online digital photo editor in existence. (from the website)

Come to find out they use their own image manipulation system (meaning Adobes) to rotate, stretch, and attach basic filters. After a quick play with it I have to say it is not HOT, it only allows for basic manipulation and mediocre text tools. What's even worse is that you have to be registered with them to use it. If it is truly free then just let it be free :)

The system looks to be developed using Flex, that right there turns me off.

FotoFlexer: Not the coolest image manipulation system on the internet. 

Anyways - check it out and let me know what you think about it: http://fotoflexer.com

As for me... Back to photoshop :)

Comments (0) Posted by sp on Wednesday, August 29th, 2007

Filed under Programming, Make you smile

While testing our new administrative panel for the company I work for I stumbled upon an interesting "validation"... error?

Now... if you want to use an alert to question a users action within the system - be sure to give them at least two options :)

Click to view the screenshot

Comments (0) Posted by sp on Thursday, August 16th, 2007

Filed under Programming, Javascript

Planet Yazaar creates and maintains community-supported additions to the Yahoo User Interface (YUI) Library (Yahoo + Bazaar = Yazaar).

This is an interesting idea - I would like to see a bit better design and system though. Still something worth checking out! :)

Comments (0) Posted by sp on Saturday, May 26th, 2007

Filed under Programming, Javascript

We have a function - resizeAll()

Now, what does this function do?

Quite simple, if you read in my earlier post about the issue I found with YUI's animation class you would know what the purpose of this function does.

If you know NOTHING about what I speak, read my post here:
http://simplyprogram.com/yui-interesting-find/

Back to the function -- My initial test was to take one or many images and have them animate the EXACT SAME as the containing element. I am proud to say this has been accomplished!

So when we started this our code looked a little bit like this:

JavaScript:
  1. var attributes = {
  2. width: { to: 0 },
  3. height: { to: 0 },
  4. opacity: { to: 1 },
  5. fontSize: { from: 100, to: 0, unit: '%'}
  6. };
  7.  
  8. var anim = new YAHOO.util.Anim(itemObj,
  9. attributes, 1.0, YAHOO.util.Easing.backOut);
  10.  
  11. anim.animate();

With my new function in place our code looks like this:

JavaScript:
  1. var attributes = {
  2. width: { to: 0 },
  3. height: { to: 0 },
  4. opacity: { to: 1 },
  5. fontSize: { from: 100, to: 0, unit: '%'}
  6. };
  7.  
  8. var anim = new YAHOO.util.Anim(itemObj,
  9. attributes, 1.0,YAHOO.util.Easing.backOut);
  10.  
  11. anim.resizeAll();
  12. anim.animate();

Thats it - Simply place anim.resizeAll() within your code and ALL images will take on the same attributes and animation method as your containing element.

What is next for this function?

I am now working to make it pretty much any element you could possibly want to animate!

On the priority list:
1. Other Divs
2. Other font tags
3. OBJECT Codes (Includes Flash :D )
4. Forms
I think that should do it for now. :)

Until my next update!

Comments (0) Posted by sp on Wednesday, May 16th, 2007

Filed under Programming

New life is being breathed into ACJavascripts.com - No, I am not redesigning it again!

However, considering the numerous errors with the website I am re-doing certain aspects as well as adding new elements and scripts.

If you have a free moment stop on bye and check out the additions and updates - http://www.acjavascripts.com.

Comments (0) Posted by sp on Wednesday, May 16th, 2007