6 Nov, 2008  |  Written by User ImageDan (Who am I?)  |  under Blog, Code Snippets, Tips and Tricks

I thought that i should touch quickly on recursion as it is something that is needed for the below tutorial on creating a conversion script for Wordpress to Joomla

Recursive functions, are functions that call upon themselves repeatedly, in the example in the previous post the function updateCategory is a recursive function

function updateCategory($category, $newParentID)
{
	global $db, $jb, $wp_prefix, $j_prefix;
	$children = $db->get_results("SELECT t.term_id as term_id, t.name as tname, t.slug as tslug, tt.description as description, tt.parent as parent FROM ".$wp_prefix."terms AS t INNER JOIN ".$wp_prefix."term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category') and parent=".$category."  ORDER BY t.name");
 
	foreach($children as $child) {
		updateCategory($child->term_id, $newParentID);
		//Check if we are insterting into 1.5 or 1.0.x
		if($j_version=='1.5') {
			//Insert the latest category 
			$jb->query("insert into ".$j_prefix."categories (title, alias, section, description, published) Values('".$child->tname."', '".$child->tslug."', '".$newParentID."', '".$child->description."', 1)");
		}
		else
		{
			$jb->query("insert into ".$j_prefix."categories (title, name, section, description, published) Values('".$child->tname."', '".$child->tslug."', '".$newParentID."', '".$child->description."', 1)");
 
		}
 
		//
		// Insert into our temp storage/reference table
		//
		$jb->query("insert into jos_wp_category_map (wp_cat_id, jos_cat_id, jos_sec_id) values(".$child->term_id.", ".$jb->insert_id.", ".$newParentID.")");
 
	}
 
}

This function uses a recordset of data from the database, it then goes through each of the categories, sub-categories and inserts them in the database in a new level to it’s previous position, the function then calls itself again to check if the current record has children records.

This is a classic example of why recursion is useful and whilst not perfect coding, it does show the usefulness when you need to run a function for deep levels of information and in particular when you do not know how deep you need to go.

So to re-iterate, a recursive function simply calls itself multiple times.

I hope this helps and I hope you find new useful ways to use this, once learning recursive functions, it adds a whole new level to your coding and can cut the amount of lines of code you need to write in half.

Rate this:
2.1
28 Oct, 2008  |  Written by User ImageDan (Who am I?)  |  under Blog, Conversions, Tips and Tricks, Tutorials

I wanted to just reach out to let you know the second part of the script and tutorial on converting from Wordpress to Joomla is in the works, I am only managing about 5 minutes a day working on it but am at the stage where I am writing the major parts of the code.

Whilst it seems fairly simple to write a category importer, Joomla and Wordpress manage categories in very different ways. Wordpress also allows for an infinite level of categories, whilst Joomla restricts you to Section and dingle category hierarchy. This presents a fairly complex set of problems and it means a lot of work in order to sort out and create a new structure that still makes some sense and holds true when we move to Joomla.

On the surface it isn’t a complex problem but as the developer we have made some pretty harsh decisions on behalf of the people that will be using the script to convert their systems, it also means that we have to do some lateral thinking about how we are going to progrematically take something that may be a hierarchy of “foo >> Bar >> doe >> Ray” into something like “Foo >> Ray” or “doe >> Ray” essentially we cant make everyone happy and we are going to have to make some people happy and others unhappy. I plan on writing a switch into the converter also, that allows a site administrator to say they want it to work so that any parent, no matter it’s place in the hierarchy becomes a section as well as staying a child, this allowing for everyone brings drama of it’s own though!

Stay tuned
Dan

Rate this:
2.1

As always there are far more than one way to skin a cat, you will notice this when you come to set up a development environment for PHP on your local machine or server.

Once again I will be focusing this tutorial on Windows environments, because to a large extent if you already have Linux on one of your boxes, setting up a local PHP test environment is just a small series of steps built into the environment.

If you plan to start learning PHP the setting up a local environment is essential, it will save you time uploading to a host and provides you an environment to test everything without harming anything you have in production.

If you already have IIS installed on your system then installing PHP is a fairly simple process of downloading the PHP installation from http://www.php.net. However if you don’t have IIS running, don’t know how or don’t want to set it up then the best option and the one I use personally is to download and install a LAMP (WAMP for us since we are running on Windows) bundle and install that. The benefit of doing so, means that you have MYSQL, PHP and usually a stack of other useful server apps installe dall in one go, and you can manage it through the applications control panel.

Continue Reading ->

When you start to learn PHP programming you will need to first start with an editor to write your code with and there are plenty of them out there for you to choose from and use. There is no editor that is right for everyone and it comes down to a matter of preference and in most cases what you first started learning withm is what you tend to stick with, it just becomes familiar and easy, but I always encourage expanding on what you have and trying new things.

In this tutorial/Review I am going to list some of the most commondly used PHP editor tools and some information about them. Hopefully any new coders can then try out some of them and decide on what is best for them.

Edit Plus

http://www.editplus.com/
Personally this is the editor that I use the most, out of a desire for change and a completely freeware application I have tried changing but always find myself relying on this brilliant application.

I first started out coding ASP in Edit Plus, so was more than use to it’s workflows and styles, so that when I transitioned to learning PHP I was able to adapt fairly easily with Edit Plus.

There are a stack of features in the application that I wont go through, I will let the creators of the application do that for you, However some of the things that I found incredibly useful when learning and still use to this day is the “ClipText” feature.

The ClipText allows you to either load a predefined list, add to an existing or create your own, this allows you to simply double click an item from the list which will insert the related code directly into the code you are editing at the current cursor location. When learning this feature is incredible because it lets you essentially set up a list of repetitive snippets of code, to save time and effort.

I used this mostly for database connections and functions that I have created. I can quickly click on “DB Connection” from my list and then fill in the connection details and I am away, saves several lines of typing code and a lot of time across a large project.

The syntax highlighting is again very easy to understand and follow and you can also edit or add your own syntax highlighting or download other people’s set from the Edit Plus website.

The application is free to use for 30-days and then can be bought for a small fee after that, and I advise in purchasing it as it is a fantastic application, and the authors have done a great job.

NotePad++

http://notepad-plus.sourceforge.net/uk/site.htm
First of all NotePad++ is completely freeware which is the first advantage that the application has over EditPlus. I have recently started using NotePad++ more and more, it offers a further flexibility over Edit Plus and shares many of the same features. This means that in general it is a win over Edit Plus.

There are some code quirks to it and it doesn’t always handle spacing in some documents as well as other applications (Think Windows notepad) However this is only on the odd occassion and over all it handles things very well.

The one feature I find myself very attracted to in Notepad++ is the collapsable routines. This feature, if you have indented your code correctly (otherwise sometimes it guesses a little) will automatically create a tree style + next to your IF and other routine statements within you code. This is extremely useful when trying to find end points of these routines and in general for making your work area tidier as you code.

Again it has many other features but I am only touching on the most obvious and useful. If you are just learning to code I would highly reccomend this as your editor, as it will be easier than transitioning at a later date, and it offers a lot for new coders and developers.

Continue Reading ->

21 Sep, 2008  |  Written by User ImageDan (Who am I?)  |  under Tips and Tricks, Tutorials

When developing sites and creating scripts you quickly learn that there are processes that you do time and time again, and you often end up re-inventing the wheel. Even to this day I tend to rewrite code that I or someone else has written before me.

I am however learning to rely on the work of others more and more. As such I have over the years come across a some great tools and classes which I rely heavily upon to do my work and code my scripts.

I will try to share these with you in a set of tutorials for new users and detail why I use them vs other scripts that are out there and that I have tried. I plan on providing tutorials for new coders to help them build a library to use going forward and am hoping to find alternatives to the classes and tools I use to expand my own libraries through suggestions of you, the readers.

stay tuned as I build and release these over the next few weeks

Rate this:
1.8