Category: Web Development

Build a Basic Authorize.net Payment Form

By blobaugh, March 10, 2010 7:44 pm

Zac Vineyard wrote a great tutorial on building a basic Authorize.net payment for and connecting to their payment gateway. Zac used some of my code and was kind enough to reference me for it, and since he wrote such a clean tutorial I see no need to write my own (used my code anywho!).

Check his out!

Build a Basic Authorize.net Payment Form

PHP: A new kind of template engine

By blobaugh, February 21, 2010 12:09 am

I have been developing a custom Content Management System (CMS) for Blam Designs and though there are several really good templating engines out there for PHP (such as Smarty) I find them usually bulky. Then there is also the need to learn the templating language as well. Though the templating languages are simple, it is one more thing for a designer to worry about knowing that pulls them away from their designs.

With that in mind I set out to find or create a new kind of templating system that works in a way similar to the JavaScript DOM, but works with PHP. The beauty of this sort of a system lies in the fact that a designer can create a layout with all the filler content and dummy text they can imagine and they do not have to remove any of it, or add any special template tags before uploading their snazzy layout to a web server. Simply add a normal HTML id attribute to whatever it is the designer wants to place content in and the template engine will automagically take care of the rest for you!

For example:

 
<div id="content">Lorem ipsum solet dolomar</div>
 

Might be replaced with:

 
<div id="content">Hello World! I am some content</div>
 

Sounds pretty cool doesn't it? I wound up creating my own PHP classes to handle this for me. I ran across a library called PHP Simple HTML DOM Parser (SHDP) which does all the heavy lifting for me. My class it basically a wrapper object that makes it easier to deal with the SHDP, in addition to providing some extra functionality. Using my class it is possible to replace the entire contents of a tag (such as <title>), replace by the element id (such as <span id="myid">), or through the use of "special" tags. The "special" tags I call special because they do not fit inside the rest of the template paradigm. A special tag works in much the same manner as a tag from a normal template system like Smarty would. Tags are created using curly braces and look similar to {{my_tag}}. I needed to keep these in in the case that some special piece of code needs to be dynamically added to the template, but is not an HTML tag or id. This happens with things such as file paths.

Though I may not be fully done tweaking the new template engine it is fully operational and I am going to provide a few code example and a download of my class with SHDP packaged with it. Eventually I would like to setup a new site dedicated to this template engine, and would like to fully re-write SHDP so that the template system is one complete unit, not relying on any external libraries.

HTML File:

 
<html>
<head>
	<title>Template Engine Demo</title>
	<meta name="author" content="Ben Lobaugh">
</head>
<body>
<div id="contents" style="border: 1px dashed #000000">
This is inside the contents div
</div>
<div id="d2" style="margin-top: 20px; border: 1px solid #000000">
This is inside the d2 div
</div>
 
{{special_tag}}
</body>
</html>
 

Replace the contents of a tag:

$t->setTag('title', 'This is a new title');

Replace the contents of an element by id:

$t->setById('contents', 'Hello World! I am new content');

Append the contents of an element by id:

$t->setById('d2', ' I am appended content', 'a');

Set a special tag

$t->setSpecialTag('special_tag', 'I am special!');

Final Output:

 
<html>
<head>
	<title>This is a new title</title>
	<meta name="author" content="Ben Lobaugh">
</head>
<body>
<div id="contents" style="border: 1px dashed #000000">Hello World! I am new content</div>
<div id="d2" style="margin-top: 20px; border: 1px solid #000000">
This is inside the d2 div
 I am appended content</div>
 
I am special!
</body>
</html>
 

Please be sure to template_engine_demo the template engine to see all the working examples.

If you use this template engine on your site please drop me a comment below.

Enjoy :D

New Website Launch: Integrity Excavation and Rock Products

comments Comments Off
By blobaugh, February 6, 2010 3:53 pm

A friend of mine recently took a course on HTML web design and after completing her class she developed a website for Integrity Excavation and Rock Products. As a first site she did a great job. Go check it out.

Integrity Excavation and Rock Products

jQuery: Oh How I Love Thee

By blobaugh, November 16, 2009 5:03 pm

I started using jQuery last week and I am finding it to be a great library so far. It is very easy to interact with elements on the page in fun and creative ways.

As a sample, I have been working with the Northwest Nazarene University web team and they wanted to develop a simple wizard they can put on any page that will help prospective students find the degree they are interested in. I decided to tackle that task. At first I was looking at slide show sample, then one of the other developers showed me the beauty of .load(), which allows me to load into any arbitrary element the contents of any file or web address. After playing with .load() and the event handlers for an hour I figured out a way to implement what they wanted. It took me maybe 4 hours going from ground zero of no knowledge on the subject to implementing a working system complete with calls to a backend PHP file that gets the contents for the wizard from the database. jQuery is really neat, I highly encourage other web developers to check it out. A working sample may be found here or on NNU's website.

Here is the jQuery code I used. Try not to be too critical, I am positive there has to be a better way of doing this. I still am learning the vast amount of options available to me in jQuery.

 
<script type="text/javascript">
 
$(document).ready(function() {
	$('#programs').load('programs.php', {}, function() { // Load the degree options
           $('.choice').bind('click', function() { // Load the school in that degree
	        $('.choice').bind('click', function() { // Load the list of degrees
						$('#programs').load($(this).attr('href'), {}, function () {
							$('.choice').bind('click', function() {
								$('#programs').load($(this).attr('href'), {}, function () { // Load a degree
					                        });
							});
					});
				});			
		 });
	});
 });
</script>
 

New Website Launch: Lewis County Chaplaincy

By blobaugh, August 17, 2009 8:54 pm

Launch another website this week. This one is for the Lewis County Chaplaincy, a group that serves the needs of emergency services personnel as well as people throughout the community in need.

Check out the Lewis County Chaplaincy website.

PHP: Fatal error: Trying to clone an uncloneable object of class mysqli

comments Comments Off
By blobaugh, July 18, 2009 11:20 am

I was working on a report for a client when I discovered this rather odd error: Fatal error: Trying to clone an uncloneable object of class mysqli. I am still not sure what caused this error, but there does seem to be a quick fix for it.

ini_set('zend.ze1_compatibility_mode', 0);

Here is what the PHP manual has to say about zend.ze1_compatibility_mode:

Name  - zend.ze1_compatibility_mode
Default - "0"
Changeable -  	PHP_INI_ALL
Changelog -  	Available since PHP 5.0.0. Removed in PHP 5.3.0

Enable compatibility mode with Zend Engine 1 (PHP 4). It affects the cloning, casting (objects with no properties cast to
FALSE or 0), and comparing of objects. In this mode, objects are passed by value instead of reference by default.

I hope that helps someone out there.

PHP: __call Magic

By blobaugh, July 10, 2009 8:24 am

Lastnight as I was researching how to build a plugin system for a cms I am working on I ran across several implementations using the __call method. I had not used it before myself, but after doing a little googling I devised a test. It really is quite simple and can be a powerhouse in your applications.

First, what is this __call thing even for? Remember those classes you built? Then remember how you were doing something else and forgot you had not yet created a method in the class to handle it and your application blew up? That is where __call comes to the rescue! Whenever a method in your class is called that does not exist PHP automagically sends the request to the __call() method. If __call exists then PHP assumes it knows how to take care of the missing method. If it does not exist is when things get hairy, fatal errors get thrown, the application blows up, and you loose your job cause one of the company execs got a phone call while in Hawaii. Oops, consider using __call in any of your important objects :D

Let's start with an example of the calling code:

$Car = new Car();
$Car-&gt;ZoomZoom(120);
$Car-&gt;Fly('Super Jets');

I am using a Car for this example. Most cars can go pretty fast, but currently there are no cars that can fly. Normally calling Fly() would cause a fatal error right? Not this time.

Take a look at the Car class:

class Car {
 
        // Constructor
        public function __construct() {
                echo "Your car has arrived";
        }
 
        // Let's roll! How fast?
        public function ZoomZoom($Speed) {
                echo "And we're off at an amazing $Speed! Hope you're buckled!";
        }
 
        /*
         * This is a magic function.
         * This function gets called when a method that does
         * not exist in this class is called. Once inside this
         * method you are free to deal with it however you
         * would like
         */
        public function __call($Function, $Args) {
                $Args = implode(', ', $Args);
                echo "I can't $Function you idiot! Especially with $Args! Hoser";
        }
}

Note the two arguments. They do not have to be called that, but it will help you remember what they are in 6 months.

Here is the output:

Your car has arrived
And we're off at an amazing 120! Hope you're buckled!
I can't Fly you idiot! Especially with Super Jets! Hoser

Pretty simple eh? I hope you realize the potentially huge impact the use of this magic method could have on your application. Heck, if nothing else use it with a logger to log errors.

Cheers,

Website Redesign: Enchanted with Nature

By blobaugh, July 5, 2009 10:33 pm

I hadn't intended on redoing any websites tonight, but while I was talking with maddslacker of my Linux group he mentioned that he did not like how his mother-in-law's site looked. He sent me a link and I made a couple suggestions, then I saved the page with Firefox and did a little editing to show him what I was talking about. Soon I had redone almost the entire layout. Since it is a simple two page static site it did not take very long at all.

Here is the original look

Seeing that there was potential for a good layout already I simply moved the content to the middle, put a border around it, then made the background gray. The font size for the testimonials continued to scream at me, distracting from the page so I made the text smaller, then thought a rotator would tidy the look up. After looking at the rest of the page I realized I could move some other elements around to provide a contrast between the content the visitor should see, and the additional info needed to make the site useful.

By this point I had completely changed the look and maddslacker liked what he saw. Even though it started out as an example of what could be done to improve it, I wound up simply redoing the entire site.

Here is the fresh new layout

Another site successfully and satisfactorally designed.

Visit the Enchanted with Nature website!

Crazy NULLs in MySQL

By blobaugh, May 27, 2009 2:40 pm

The topic of MySQL and NULLs came up in my IRC room today. It turns out that MySQL tends to handle NULLs in a rather wonky way at times. Personally, I usually do not like allowing NULLs, and the only time they are ever present would be in a RIGHT or LEFT JOIN that had missing information. There are many people out there, however, that do use NULLs, and love them. I am not knocking the use of NULLs in any way, but before you sit down and use NULLs again be sure you take some time and study this bit of trivia one of the guys in the IRC showed us.

 mysql&gt; SELECT if(NULL=NULL,"yep","nope");
+----------------------------+
 | if(NULL=NULL,"yep","nope") |
 +----------------------------+
| nope                       |
 +----------------------------+

If you think this is strange behavior you are right. According to the MySQL manual on control flow the correct response should be 'yep'.

Automatically Resize an IFrame From It’s Content

By blobaugh, May 23, 2009 7:47 am

I recently had a situation with a client where I needed to use an iframe to pull content from a bulletin board into their main site template. Setting up the iframe was the easy part, then I noticed that the content would auto size the width, but it would not autosize the height. As I wanted this iframe to look like it was part of the page, not an iframe, I started googling. There are lots of "solutions" out there to make the iframe automatically resize the height, but I did not find one that actually worked how I wanted it. The closest I came to finding what I was looking for was creating a div around the iframe, and with javascript get the content of the iframe and replace the content of the div. This actually works out really well, until you clicked a link inside the iframe and it broke out of the iframe. So I did some looking at javascript methods and I came up with a pretty good solution myself. You can use this to automatically resize your height, and still use the links inside the iframe. It looks like the iframe is part of your actual page, and nobody is the wiser.

 
function resizeIFrame() {
     var myIFrame = document.getElementById('YourIframeName');
     myIFrame.height = myIFrame.contentWindow.document.body.scrollHeight + 10;
}
 

Be sure to change the name of the iframe you are trying to get. Here is an example of the HTML I used.

 
<iframe onload="resizeIFrame();" id="YourIframeName" src="content_for_your_iframe" frameborder="no" width="100%" scrolling="no">
 

Be sure to set the id and content of your iframe and you are set!

Theme by Blam Designs
Based on Themocracy