Expression Engine

Over the past two months I have been working on a web site called Get Safe Online with a company called Grasp Digital which I am currently contracted to 3 days a week, it is a government backed web site aimed at making people more a where of the dangers online. For this site I had been asked to use the CMS Expression Engine. Having never used this CMS before I through myself into learning the in’s and out’s.

My first impression was why would one buy a CMS of this nature when there are so many other better solutions out there. Once you get under the hood of this CMS there are some good bit’s and some very frustrating bit’s.

Lets start with the good bits. Firstly if you are looking for a content rich site much like www.bbc.co.uk then expression engine is your CMS, after all Expression Engine claim that the BBC are using there CMS. With the CMS you can quickly get a site up and running displaying articles. For a designer/developer the syntax is very human readable and from what I have seen this is Expression Engines market. As a developer I have found this most frustrating.

This moves me on to the frustrating bits. Expression Engines use of categories is a little convoluted it took me a while to get my head around this and the way it works with the articles. I found a great guy on you tub DaBrook that went through the whole process of creating an Expression Engine site, but he didn’t explain the relationship, he had used a category as if it was just another article. There was no digression into the subject.

With Expression Engine you can have category groups and then multiple categories in that group. You then have to assign the category group to a channel. In the beginning what I misunderstood was when that has been done you can create your articles and assign them to one or more categories. Now in something like WordPress or Joomla this is already done or in fact you only have one category group which is automatically assigned to your articles. At this point I was lost in the wilderness.

After much playing around it twigged. For very big sites you need this for instance with the BBC they would categorize there categories. This is important for the fact that you can have the same category name in multiple category groups.

So that gives us a background into the workings of categories, but I still had a problem with the fact that the site needs to be dynamic. The other frustrating part about Expression Engine is how it handles pages. For Expression Engine to serve a page it needs a template group and this template group can be made up of other template group pages and what is called snippets, pieces of code doing specific tasks kind of like programmable functions.

Most other CMS’s, you create a one template to serve many pages, Expression Engine is almost old skol and backward with it’s template mark-up. There are ways and means which allow for dynamic content in my next post regarding Expression Engine I will explain in more detail.

One last frustrating part of Expression Engine is when using categories to for instance create a navigation menu and a nested one at that, there was no out of the box solution to create one. I thought I am pay for a license for this surly  there should be provision for creating a menu using categories. Well there is one but you have no say in how it is created. To create a menu I had to create a custom plugin please see below the plugin.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Menu{
	public $return_data = "";
	public function __construct(){

		$this->EE = &get_instance();

                $site_url = $this->EE->config->config['site_url'];
                $index_page = $this->EE->config->config["site_index"];
                $this->EE->db->where('parent_id',0);
                $this->EE->db->where('cat_name !=','News');
                $this->EE->db->where('group_id',1);
                $this->EE->db->order_by('cat_order');
                $segment = $this->EE->TMPL->fetch_param('segment');

		$query = $this->EE->db->get('exp_categories');
               $this->return_data = "<ul id='mega-menu-tut' class='main-navigation menu'>";
               $i=1;
                foreach($query->result_array() as $row)
                {
                    if(preg_match('/&/',$row['cat_name'])){
                        $start = 1;
                        $title = '';
                    }else{
                        $start = 0;
                        $title = '';
                    }
                    $titleOld = explode(' ',$row['cat_name']);
                    for($i=0;$i<sizeof($titleOld);$i++){
                        if($i==$start){
                            $title .= $titleOld[$i]."<br class='iphone' />";
                        }else{
                            $title .= $titleOld[$i]." ";
                        }
                    }
                    $path =$site_url.$index_page.'/'.$row["cat_url_title"];
                    if($segment == $row["cat_url_title"]){
                     $this->return_data .='<li class="menu-0'.$i.'"><a href="'.$path.'" class="current">'.$title.'</a>';
                    }else{
                    $this->return_data .= '<li class="menu-0'.$i.'"><a href="'.$path.'">'.$title.'</a>';
                    }
                    $this->EE->db->where('parent_id',$row['cat_id']);
                    $this->EE->db->where('cat_name !=','News');
                    $this->EE->db->where('group_id',1);
                    $this->EE->db->order_by('cat_order');

                    $query1 = $this->EE->db->get('exp_categories');
                    if(is_object($query1)){
                        $this->return_data .=  "<ul>";
                        foreach($query1->result_array() as $child)
                        {
                            $path =$site_url.$index_page.'/'.$row["cat_url_title"].'/'.$child['cat_url_title'].'/';
                            $this->return_data .= '<li ><a href="'.$path.'">'.$child['cat_name'].'</a>';
                            $this->EE->db->where('parent_id',$child['cat_id']);
                            $this->EE->db->where('cat_name !=','News');
                            $this->EE->db->where('group_id',1);
                            $this->EE->db->order_by('cat_order');

                            $query2 = $this->EE->db->get('exp_categories');
                            if(is_object($query2)){
                                $this->return_data .=  "<ul>";
                                foreach($query2->result_array() as $sub_child)
                                {
                                    $path =$site_url.$index_page.'/'.$row["cat_url_title"].'/'.$child['cat_url_title'].'/'.$sub_child['cat_url_title'].'/';
                                    $this->return_data .= '<li ><a href="'.$path.'">'.$sub_child['cat_name'].'</a>';
                                }
                                $this->return_data .= "</ul>";
                            }

                            $this->return_data .= "</li>";
                        }
                        $this->return_data .=  "</ul>";
                    }

                    $this->return_data .= "</li>";
                    $i++;
                }
                $this->return_data .=  "</ul>";
	}
}
?>

Calling this plugin is really quite easy in the template group you write {exp:menu segment=”{segment_1}”} the segment parameter was for checking if the user was on segment one and if so add a class to the anchor link to make it sticky i.e give it a colour.

Posted in Expression Engine | Tagged , , , , | 3 Comments

PHP London 2012

On Friday 25th February PHP London held a conference, the main theme of the conference was collaboration and integration. It seems to me that there is ether a lack of raw talent or that business execs are now noticing that they need to expand there development team, but more collaboration to a project does not exactly mean quicker turn around.

When I was working at Askmerlin the business would often give the 8 strong development team individual tasks to do. Each developer would go away and implement the task in there own way. The problem with this was developing a system that is meant to be integrated also means that the development process and development team also needs to be integrated.

One way I went about solving this was to create a process that would make the team more integrated using tools such as subversion, hudson, bugzilla and phing.

The team was already using subversion but in a manor that still resembled using ftp the only saving grace was that subversion held an account of who was checking in and out the code.

To develop with the team was already using Netbeans as the IDE (Integrated Development Environment) and using subversion check in and out the project files through Netbeans. I wanted a way to track bugs and give the teams tasks that could be check off by each developer, and bugzilla was the best tool for this as it hooked into Netbeans with ease. The project is backed by the mozilla team who make firefox.

The next step was to now create a testing environment that could be staggered in two stages 1. test server 2. production test server.

The test server setup with hudson and using phing for deployment would poll the subversion trunk repository every 10 minutes allowing the development team to test there code on a server that was setup in the same way the live servers were. Once the testing phase was complete the trunk would be moved to a branch and then applied to the production test server to iron out bugs the development team would then check out this branch to fix the bugs that were entered into bugzilla and fed down to the developers using Netbeans.

The final phase would be taging the branch and deploying to the live servers using hudson and phing. Phing would copy the files to the server using ssh after hudson had checked out the tag.

There was only one problem with this the business would always skip the testing phase and bug fixing phase and deploy straight to live servers and then wonder why there are so many bugs.

From the conference I picked up that there are now some tools that create graphs and it is now possible to monitor when the software is deployed how many bugs were reported at each phase. If I had those tools before explaining to the business would have been so much easier.

I mentioned that there may not be raw talent this was a question that was asked to the panel clearly this person was not a developer however there is a fine line between being a developer and being business aware. What I have noticed is there are a number of creative houses who try to build a development department and can not see eye to eye on a number of things one being how long it takes to develop a software application. In this area things are being to change with the fact that there are a number of frameworks out there.

But the biggest problem is scaling a development team I found it most interesting that the PHP London sees this too.

Posted in development | 4 Comments

Codeigniter Form Validation

Using codeigniter and the form validation library, was a breeze when using my formValidation jQuery plugin. With the plugin all I need to worry about is getting the validation parameters of codeigniter correct and then return the error data if there is any. Below shows an example of error code to send back to the formValidation plugin.

$this->form_validation->set_rules('firstname', 'Firstname', 'trim|required');
            $this->form_validation->set_rules('surname', 'Surname', 'trim|required');
            $this->form_validation->set_rules('companyname', 'Company Name', 'trim|required');
            $this->form_validation->set_rules('jobtitle', 'Job Title', 'trim|required');
            $this->form_validation->set_rules('country', 'Country', 'trim|required');
            $this->form_validation->set_rules('teleno', 'Telephone No', 'trim|required');
            //$this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required');
            $this->form_validation->set_rules('email', 'Email', 'valid_email');
            $this->form_validation->set_message('required', 'Please Enter');
            $this->form_validation->set_message('valid_email', 'Email address is invalid');
            $this->form_validation->set_message('isPhoneNo', 'Telephone Number is invalid');

            if ($this->form_validation->run() == FALSE){
                $this->form_validation->set_error_delimiters('', '');
                $data['saveSuccessful'] = false;
                for($i=0;$i                    if(form_error($formData[$i])){
                        $data['errors'][$n]['name'] = $formData[$i];
                        if(form_error($formData[$i]) == 'Email address is invalid'){
                            $data['errors'][$n]['message'] = form_error($formData[$i]);
                        }elseif(form_error($formData[$i]) == 'Telephone Number is invalid'){
                            $data['errors'][$n]['message'] = form_error($formData[$i]);
                        }else{
                            $data['errors'][$n]['message'] = form_error($formData[$i]).' '.$formData[$i];
                        }
                        $n++;
                    }
                }
            }else{
                // Do something with the data
            }
            echo json_encode($data);

When the data is returned to the plugin if it is in error then the form fields are highlighted and an indicator icon is displayed. If the user clicks on the icon they are presented with a dialog telling them what is wrong.

Posted in Codeigniter | 36 Comments

Lets Get Social….

I have now created a twitter account and all my blog posts get tweeted straight from WordPress. I have also added social media links to all my pages and blog posts using add this. So Lets Get Social I have created a Facebook page although still in development so likes will be welcome.

I will link my twitter account to Facebook so eventuly I will be able to post from WordPress and feed it in to Facebook.

Posted in Any Thing Go's | 40 Comments

CodeIgniter

I have been working on a project with Expression Engine and noticed it used CodeIgniter as its framework. With this in mind I used CodeIgniter on another project for a company called Seal Software. They required a admin area for adding downloadable pdf files that there customers could download. With the download they wanted to capture the users details and only allow the user to download the document three times.

CodeIgniter was perfect for this I created an admin area, user download form and emailed the link to the user. When the user click on the link the database was updated with in increment and the user was presented with a download pop up. To speed the form creation up I used my formValidation query plugin. The plugin speeds up the sending and error reporting up.

The admin area consisted of a stats page where Seal Software could see how many times a document was being downloaded and how many times each user had downloaded each file. The download button in the admin area allows Seal Software to add new documents to the system and in the actions menu, allows there web editor to generate a link to display on the main web site.

Posted in Codeigniter | 38 Comments

Joomla and Virtuemart

Having started freelancing my first project involves Joomla and the component Virtuemart. The task involved creating a theme for Virtuemart this post will outline my experiences with Virtuemart.

The theme was to create a Kit Designer which would allow the user to select things like tops and shorts then change the colours. For instance the tops would have different segments that could be coloured and much like a Photoshop file be layered one on top of the other. I managed to create this feature quite easily using the PHP GD library. However installing this into Virtuemart proved problematic and later down the line I realised that the site also had a products section and would require a template for that section also.

I soon realized that Virtuemart could only support one template so for the most part of the project I concentrated on creating the Kit Designer template. During this process I found out that Virtuemart was very badly written.

Having never seen or used Virtuemart before this project I found myself reverse engineering the Virtuemart and Joomla framework. On the one hand I have found out a lot about how the component has been put together on the other I have been tearing my hair out.

In basic form Virtuemart is made up in browse, product details, cart and checkout. So to start with you create categories of products , sub categories of categories which also have products. Ok good so far but what if u just want categories > sub categories > products to do this virtuemart requires u to assign a product to the root level category, if you do not then a message appears telling you that the category is empty. Without re-writting the core code this one I had to grin and bare and just assign one product to the root level category but not display it not ideal but a work around.

The first picture above illustrates the outcome so far. The next stage posed some new challenges for instance how to get virtuemart to allow the user to select all the required layers that would make up the kit. After much digging I found that there is a file that obtains the attribute items. Now for those not having seen virtuemart you can add product attributes and these can effect the price up or down but for this instance I used them to produce and Item selector. Calling the attribute Item and setting properties of that item I could then use this to produce the structure I required. The pictures above showing the shorts indicate this.

With the items now displaying and producing the kit things are starting to shape up. Moving onto the next stages the cart and checkout I found somethings that were most annoying and one of the main reasons for creating this post.

Joomla’s template system works very well and gives the developer a lot of flexibility in creating components modules and plugins. What I found was quite amazing and a clear lack of understanding of how output buffers work. The following code is a snippet of the file checkout.index.php.

echo $theme->fetch( 'checkout/get_final_confirmation.tpl.php');
			$theme->set('basket_html', '');

The function fetch does the following action. With the template file that is passed in stops the output buffer, gets the contents of the template file and places it into a variable and then returns the variable. What I couldn’t understand is why would one  just echo out the data to the screen. This defeats the object of stopping the output buffer and allowing the developer to use the data that should be passed to the set function in his own template file.

To achieve what I have with this project I have had to stop the output buffer in some places completely and even kill the execution of code just to get what I need. With the proper use of the fetch function this would never be needed and data should be passed between template files with ease not difficulty. I had to create my own static class to dump the data in and transfer it around the templates. Not idea but it works.

Posted in development | Tagged , , , | 40 Comments

My Image Titles – Plugin now ready for packaging

The My Image Titles Plugin is now ready testing has finished. The plugin is installed on the site www.titanic705.co.uk. All the titles on the site are being produced with the plugin. I have been so busy of late I haven’t had a chance to create blog posts or create the documentation to release the plugin. This will happen I am creating the doc’s just not as quickly as I would like.

Posted in WordPress | 39 Comments

My Image Titles plugin is in testing

The My Title Image plugin is in the first phase of testing. So upon activation the database table is now being added the upload function is now working and the settings page is saving to the database.

This is my first plugin from scratch I have now got many more in the pipeline stay tuned for those. This at the moment is code named My Plugin as this is my first one which I have produced as soon as it is fully ready I will rename everything.

For saving to the database and uploading the font file, both actions use Ajax and the formValidation plugin which I have produced a while back. Because of the formValidation jQuery plugin producing this plugin for wordpress has been a breeze.

As the Upload Font File is a jQuery dialog the save button needed to be overridden. I once had to do this on another project for those who are interested this can be done in the following way.

dialogObj.dialog({
                    modal:true,
                    title:'Upload Font File',
                    buttons:{
                            'Cancel':function(){
                                    dialogObj.dialog('destroy');
                            },
                            'Save':function(){
                                var done = false;
                            $.each($('.ui-dialog-buttonpane').find('button'),function(k,v){
                                if($(v).text() == 'Save'){
                                   $(v).attr('id','save-but');
                                   done = true;
                                }
                            });
                            if(done){

                                    $('#myplugin-form2').formValidation({
                                    url:ajaxurl,
                                    butSaveId:'#save-but',
                                    dialogId:'#myplugin-dialog2',
                                    upLoadFile:true,
                                    debug:true,
                                    iframeId:'#myplugin-iframe',
                                    callBackSuccess:function(dialogObj,data){
                                        if(data.saveSuccessful == true){

                                        }
                                    }
                                });

                                setTimeout(function(){

                                        $('#save-but').trigger('click');
                                    },300);

                            }
                            }
                    }
            });

In this instance the formValidation plugin is doing something else once it has been called, which is to unbind the original click event on the save button and replace with the formValidation’s click event. If you are looking to do something else, just do that instead all you need to do is make sure you bind it this time to the id that you added this way you are targeting this button only.

Posted in WordPress | 31 Comments

Sweet……..

Ok so December has been a month to remember. After being put on Garden Leave from Askmerlin I have been looking at my next move. I have always thought about going freelance and doing contract work and as such I have been doing a lot of research. This site goes a long way to realizing that dream. There will be more posts regarding this matter but right now I am now freelancing and doing contract work.

I am now looking forward to 2012 with great expectation so for now everybody have a great Christmas and I will be back in the new year with many more updates. Thanks to all that have commented I really appreciate  it.

Posted in Any Thing Go's | 30 Comments

The Image Titles Plugin…

I have been grinding a way at this plugin which I have code named myplugin for the time being should be in the first phase of beta testing by the end of the week. I have the font files being uploaded and added to a database table. The next step is to populate a drop down list with the font files and allow the user to fill out the rest of the information like text color, background color, point size of the text, with and height of the output image.

I am very pleased with the progress of this plugin I am almost ready to start my next. Stay tuned for that one and the updates to this plugin.

Posted in WordPress | 26 Comments