A blog on IT, PHP, ASP.NET, MVC Frameworks, Shopping Carts, IDEs, etc
Welcome to my blog on PHP, ASP.NET, MVC Frameworks, Shopping Carts, IDEs and IT in General. Recently I have spent quite a lot of time research many IT related topics and often couldn't find all the info I was looking for in one place, so I decided to finally create a blog to aggregate and share the info to make other people's research a little bit easier (and add my 2c worth of course).
I’ve spent a fair bit of time looking for a decent HTML Editor control for a variety of platforms… The platforms on which I needed a decent HTML Editor included Visual Basic 6, .NET Windows Forms and now .NET WPF. The problem is there is no decent native HTML Editor control for any of these, but what’s worse is there aren’t any good third party controls either, so the only option is really to create your own.
Firstly I needed a HTML Editor for VB6. The option that most people seem to suggest is to use the DHTMLEdit OCX which has now been retired but can still be deployed and then call various methods on it to do the editing. You can do something similar with the MSHTML control, but once again it’s quite ugly. I spent some time searching for a better control and found nBit HTML Editor ActiveX Control but after using it for some time found that it produces SUPER UGLY non standards compliant HTML (i.e. 90s style). Given that my content is going onto an XHTML page that is not an option. The control is quite nice in terms of function, but is quite restrictive in what you can do and the ugly HTML is a deal breaker. I didn’t really want to spend heaps of time on implementing all the buttons in DHTMLEdit or the MSHTML by calling execCommand. A frequently referred to post for implementing a Windows Forms HTML Editor was also not of much use as it is very basic and doesn’t fit my needs. Another post on Code Project called WYSIWYG HTML Editor was also not of much use as it didn’t do it how I wanted it.
My initial idea before I began my search was to actually use a WebBrowser control with one of the well established OpenSource HTML Editors like TinyMCE, CKEditor or FCKEditor (now superseded by CKEditor), so I thought I’d see what I can find. I found an article on CodeProject again where someone has implemented TinyMCE HTML Editor in .NET WindowsForms which was pretty close to what i was looking for. I did a bit more searching and also found a blog post where a fella has done the same with FCKEditor, titled TinyMCE HTML Editor running in Windows Forms and another one called FCKEditor HTML Editor Running on Desktop. Between all these posts (and the sample code) I pretty much worked out that this is going to be by far the best way to do this. Some people on various forms and on StackOverflow had taken issue with using the WebBrowser Control in both Windows Forms and WPF as it’s just a wrapper for the COM WebBrowser and they would prefer a native control, but I say who cares, you just need something that works how you want it from a functional perspective and doesn’t take heaps and heaps of code.
I then did a bit more searching to find out how I can avoid any security issues coming up and found a post about WebBrowser in WPF. That showed how to avoid a warning by adding some code to the HTML page.
So putting all of this together I managed to easily implement a WYSIWYG HTML Editor on all of the platforms being VB6, Windows Forms and WPF. What you need to do is actually rather simple, with a few specialty tweaks for each platform:
- Download the WYSIWYG HTML Editor of your choice (i.e. TinyMCE, CKEditor, FCKEditor or some other) and put into your project directory
- Create a HTML file that will host the control. This file has the page that will be loaded in the WebBrowser and provides stuff like initialisation for the control as well as simple getter and setter methods. Make sure to add the stuff at the start of your file to stop the security warning coming up. (i.e. <!– saved from url=(0014)about:internet –>)
- Put a WebBrowser control in your window and in the Load (or Loaded) event use the Navigate function of the WebBrowser to open your file. You can also use the Source or Url Property in WPF and WindowsForms respectively.
- When you run the project your WebBrowser should show now.
- Next thing is to be able to get and set the contents.
- In WPF and WindowsForms you can just use InvokeScript to call the JavaScript methods created in Step 2 to get and set the content of the control. In VB6 the execScript method doesn’t work quite as well so can’t return a value. To work around that all you do is add a textarea in a hidden div and use the DOM to access that value and then have your getter and setter javascript methods which you call using execScript get and set the values from the textarea, which you interact with via the DOM using WebBrowser.Document.getElementById(‘htmlArea’).value.
That’s pretty much all you need to implement a fully functional HTML Editor. You can of course do stuff like implement a user control or a custom control in WPF and WindowsForms to reuse the web browser easily. You can pass in the configuration and so on from the code and you can even write out the HTML from the code so you don’t need the HTML file. Whichever way you do it is up to you, but this should certainly give you an idea of how to get the basics working, which is the critical part.
In the past I have extensively used ASP.NET and ASP.NET MVC in C#. In C# they are basically the only options and it would be rather crazy to try to come up with your own high-level web framework on top of C# and rightfully so. However when I moved over to be doing a lot of web development in PHP (see PHP for ASP.NET Developers which I blogged about before) things were not so rosy. PHP is a great scripting language, many things are very simple to do and well geared towards web development. However, a bad (and a good in some way) thing about PHP is that it’s a very low level language and doesn’t provide many of the higher-level framework nicities that is provided with ASP.NET and ASP.NET MVC straight out of the box. By nicities I mean things like structured request routing and handling (with hooks/events), page lifecycle, MVC separation, configuration management (e.g. web.config), logging and so on. It is also a fact that many PHP developers and participants in open-source projects are not professional programmers with an IT or software engineering degree. What all of this has lead to is A LOT OF HORRIBLE ARCHITECTURE AND CODE. Having looked through the source code of many many open source PHP projects, there is only a very very small handful that I would say are very well architected. In some cases there is no architecture at all, in other cases there is some attempt at architecture but it’s not particularly good and in other cases things are over-architected to the point that making even a small change, let alone a complex change becomes extremely difficult. For many users of these open-source projects this of course doesn’t matter as they don’t ever have to look at the code, but for anyone looking to make serious changes this is quite a problem indeed. The best architected open-source applications I’ve seen are OpenCart (has it’s architectural flaws, but not too bad), being a Shopping Cart application, and Drupal (being a CMS). Some people may say Drupal is not well architected because it’s not PHP5 Object Oriented code, but I don’t think you need to have PHP5 or OO for an application be well architected. For example in C you can structure your application well, or you can structure it poorly and same goes for PHP. You don’t have to use the latest technology to structure it well. Sure there are obviously certain performance factors that come into play when you have load lots and lots of modules just to see if they’re enabled, but such is life when you’re building a configurable system. Other applications in those classes of applications are not very well architected at all. Here’s a non-exhaustive list:
Shopping Carts
- PrestaShop – Pretty ugly architecture, poor file structure, doesn’t use MVC (poor form for a modern application), un-necessary use of Smarty for templating, all the admin code output using echoing directly out of modules instead of using MVC pattern, etc.
- osCommerce – No programming standards, mix of code and markup, terrible code re-use, and just plain ugly bad design.
- ZenCart – TERRIBLE design rooted in osCommerce that’s almost impossible to change if you try to make serious modifications as you have to change way too many files.
- Magento – Over-architected to the point of obscrurity (not unexpected given it is based on Zend Framework) which impacts performance and requires lots and lots of caching.
- Commercial Carts – This includes CSCart, X-Cart, etc – There is some attempt at decent architecture but often it still comes up short.
CMS / Blogs
- Joomla – Over-architected MVC design and terrible rigid structure and security model.
- Wordpress – Horrible mix of PHP and HTML, although workable to some degree, it is far from well architected.
- ModX – Ok-ish architecture but also rather ugly when you look at the code.
Now when it comes to frameworks, which is more the subject of this post, things don’t change much. Most of the frameworks are also poorly designed and structured with their design patterns firmly rooted in PHP4. This includes CodeIgniter, Kohana, DooPHP and pretty much every other framework I’ve looked at with the exception of Yii and Zend and perhaps Symfony and a few others (see Choosing the Best PHP Framework). Ultimately after much research I’ve found Yii and Zend to be by far the best structured (with Zend over-engineered). What I have found is that Yii Framework is by far the closest thing there is to .NET so I’m finding that any application that I’m looking to write even if it’s a console application is well handled by Yii, even if it’s because it has a decent architecture (which I can’t fault). I’m finding that even for little PHP scripts without a user interface and simple web applications it’s easier and better for me to use Yii Framework even just because of the database access and configuration capabilities that it provides and of course the structured design. I do find that it is still lacking a few things that are general framework classes (e.g. HttpClient, Application File System) rather than anything specific to do with web development).
Choosing a PHP framework is not an easy task, especially if you have relatively little experience in PHP to know what makes a good framework or and what doesn’t, but choosing the right PHP framework for the job is absolutely critical in the long term as choosing the wrong PHP framework can lead to a number of negatives, such as longer development time, need for more experienced staff who may be hard to find and of course performance problems. Unluckily (or perhaps luckily) when it comes to PHP there is such a plethora of PHP MVC Frameworks that it’s damn hard to actually boil them down to the final choice. With ASP.NET for example it’s quite easy (although it’s gotten a little more complicated lately), previously there was only ASP.NET but now there’s also ASP.NET MVC, which is very different development paradigm and has it’s own catches. However, one thing with .NET is that you need to choose how you’re going to do your data access, etc, but with most PHP Frameworks there is usually only one or two ways and they tend to do the job quite well. So, now with this brief introduction, here’s the thoughts on Yii Framework (1.1.5) vs Zend Framework (1.11.0) vs Code Igniter (1.7.2).
Read more…
I’m currently at the start of developing a fairly sizable project in .NET using C# with WPF. As this is going to be quite a large project I thought it would be prudent to spend a bit of time upfront to organise it into some sort of a sensible structure which will see us through into the future, so that we don’t have to change it half way because things get too messy. So I set out to find the appropriate solution structure for a WPF project. A bit of googling turned up a few posts such as Recommended WPF Project Structure discussion on StackOverflow and WPF Project Structure by Dr. WPF, but neither gave a difinitive answers or detailed Pros and Cons of any particular structure. So taking what I’ve read and my own experience my analysis is as follows…
Read more…
ASP.NET is very nice to use for developing web applications but also comes with a few cons. The biggest drawbacks of ASP.NET (including ASP.NET MVC) are that it’s more expensive to host than PHP (and you can’t use certain programming concepts if you want to host on shared servers because they require full trust) and you pretty much need to use Visual Studio to do the development (although you could use the Express edition if you’re doing something basic).
Because of these drawbacks some people (like myself) have looked at other options (of which PHP is one). In the recent years PHP has matured into a pretty decent OO programming language, but raw PHP is still very low level and doesn’t give you much guidance or have much of a framework for implementing your applications. This of course requires you to be far more skilled in PHP and application architecture in general and would take much more time. Having a good IDE is also improtant for productivity.
Luckily there is a very nice solution to this problem.
- Use an IDE – There are two mature (and FREE) IDEs you can use to develop PHP. They are Eclipse PDT and NetBeans. NetBeans kind of comes with everything there (e.g. SVN and Mercurial support), but I still find that Eclipse PDT is the better option, especially if you’re doing much deployment via FTP (with the Aptana Plug-In). Eclipse PDT also has much better SVN support than NetBeans when you add the Subclipse or Subversive plugins.
- Use a PHP Framework – There are far too many PHP frameworks around, and sadly most are not up to scratch or what one would be used to coming from the ASP.NET environment. However, there are two awesome frameworks which have a good combination of performance, good architecture and are most similar to ASP.NET. They are Yii Framework and Zend Framework. Yii Framework seems to have borrowed may concepts from ASP.NET and is an absolute pleasure to use. It even solves problems which are still a bit of a pain in ASP.NET (e.g. paging in lists). It is also significantly faster than Zend Framework and hence is my preferred choice. Zend Framework is more feature rich than Yii Framework, but it has a degree of complexity and doesn’t perform all that well in shared hosting environments. If you want to use some Zend Framework features with Yii you can easily do so, so you can get the best of both worlds.
That’s pretty much it… By combining those two concepts you can do pretty much the same thing in PHP as you can in ASP.NET without the associated expense.
Well, I’ve just spent the last 10 minutes doing an online quote for Youi insurance and what a waste of time this has been… The insurance with Youi has come in at MORE THAN DOUBLE what I currently pay with AAMI. Perhaps it might work out well for someone who only uses their car on the weekend but it doesn’t work out all that well for me, even though I drive against the traffic each day. So, Youi or not Youi, it’s still an insurance company and it doesn’t ask anywhere near as many questions as you’d think from their ads about how you use your car. Then again their actuarial models would be pretty nasty if they did ask more questions.
I’ve done a lot of research into email marketing providers as I needed to find a new one for our business. I searched far and wide and basically these are my findings…
Read more…
We’ve got quite a few projects on the go at work and it’s become quite difficult to remember all the projects, the tasks needed in each project and more important making sure that the team is working on what they should be working, so I set out to find a better solution than just using Excel. The result was Web2Project. This is how I came to that choice…
Read more…
So, you might have received a Don’t Count on It Wooden Puzzle Money Box from Crestcom or from someone else and wondering how to open it. The box of course most likely has money in it or something else of value that you probably want to get out. The easiest way to open the box is just to break it. Well if you’re a practical person that’s the best way to do it. That’s the way that I did it, not so much to get the $5, but as I was interested in how it works rather than getting the money out or keeping the box in one piece.
Well, the way it works is as follows:
There are two end pieces that have magnets glued into them. Then, the main frame has holes which are about one inch long and inside those holes are little metal rods about half an inch long. The way the box locks is by putting the metal rods into the holes then sliding the cover on and turning the box so that the metal rods slide inside the holes and make contact with the magnets at which stage they attach to the magnets. Once you know the actual construction it’s quite easy to work out ways of how to open the Don’t Count On It Wooden Puzzle Money Box.
I came up with the following ways:
1. The way I broke the box was to twist the end bit sideways (i.e. No in the direction of the slide). The end bit just popped out. This is the easy way but it kinda breaks the box slightly as it usually creates a crack along the joint between the 3 main bits that make up the main part of the box.
2. The best and proper way is to grab the box and tap it with a hard sharp blow on the floor (with one of the ends at the bottom) and then just slide the top end off. The basic idea here is that the intertia and the sudden stopping of the frame will make the rods separate from the magnets and fall into the holes. You might not get it the first time, but I believe that’s the PROPER way to open the box. Something to remember here as well is that only one of the sides has the magnets, so if you try like 10 times with one side and have no luck, try with the other side. I recommend doing this on a carpet if you don’t want to damage the box.
3. Use strong magnets to separate the metal rods from the little magnets inside the end. As nice as this sounds not everyone has a magnet lying around… In fact thats’ the way that I tried to open it initially, but didn’t have a strong enough magnet laying around, and doubt you would too.
4. Try to use some really sharp instrument to slide the rod away from the magnet via the tiny gap between the end and the main bit… This is a real pain in the ass and I tried this way also before opening the box using method 1.
I’ll also try to create some photos and videos and post them on YouTube for anyone interested.
WOW… I just did some comparisons between what Google Analytics reports in terms of traffic as well as e-commerce sales numbers and Google Analytics is just terrible. One would think it’s the best thing since sliced bread as it gives you all these ways to look at data, but when both the traffic and sales are out by HUGE numbers, you really change your mind. I really don’t know how on earth I would ever trust Google Analytics again when the difference is like 25% (and I’m talking sales here). That’s an absolutely massive difference and throws out your ratios completely. My recommendation for anyone considering using Google Analytics is DONT, unless you’re ok with completely wrong data being presented and you making decisions based on this data. If you want proper analysis you should use some tool that analyses your server logs, not a javascript based tool.