A very basic PHP syntax thing usually ignored by developers is that you can directly update current element from within the foreach loop.
Just precede value variable with & character and it will be assigned by reference:
$arr = array(1, 2, 3, 4); foreach ($arr as &$value) { $value = $value * 2; }
Read the rest of this entry »
Update notification for a commercial plug-in
WordPress CMS has a nice auto update feature that displays update notifications for outdated plug-ins and themes in admin panel. Once you got a notification you can go to Dashboard->Updates and install all updates with few clicks while WordPress will automatically download and extract archives, remove old versions and reactivate plug-ins for you.
The only problem is that it works for plug-ins published on wordpress.org which are open-source so it’s not an option for commercial plug-ins.
Luckily there is a very good solution to this problem: Upgrademe plug-in. Read the rest of this entry »
Unlike desktop applications which rarely use “skins”, web applications look ugly and unprofessional w/o a design template. However, building unique design for each project sometimes is just not affordable, especially for back-end, admin and other data analysis and management applications. At the other hand, if you look for free or commercial design templates available, you’ll find nothing but website templates which doesn’t have elements like cascading menus, dialog, grid, form elements and others usually required for an application user interface.
Sad but true, except this little thing: Admintasia 2.1. Powered with jQuery and jQuery IU it has all the elements you need to build rich professional user interfaces. Read the rest of this entry »
Recently I noticed that ON UPDATE CASCADE rule falis in MySQL on InnoDB tables if a foreign key references the same table, which is usual for tree-like data structured. At the same time ON DELETE CASCADE works fine.
This is not corresponding to SQL standard but it’s already stated in MySQL manual:
Deviation from SQL standards: If ON UPDATE CASCADE or ON UPDATE SET NULL recurses to update the same table it has previously updated during the cascade, it acts like RESTRICT
ON UPDATE CASCADE
ON UPDATE SET NULL
RESTRICT
It was also reported as a bug but rejected years ago. Read the rest of this entry »
After upgrading to jQuery 1.6+ you’ll find that code you used to enable/disable elements doesn’t work anymore:
//This is supposed to enable element(s) before jQuery 1.6: $("some-selector").attr("disabled", ""); //This is supposed to disable element(s) before jQuery 1.6: $("some-selector").attr("disabled", "disabled");
But now the code above doesn’t change anything. So what’s the problem?
Escaping from HTML is a very cool feature of PHP because it allows easily to inject portions of dynamic content into predefined HTML template. But when you come to HTML tags with many dynamic attributes and relatively complex logic beyond them, this cool feature turns into complete disaster. If you constantly develop view templates or web page scripts then you definitely know how many times you hated starting yet another “<?php echo…” just for another attribute value.
Right, even if you strongly pretend to write clean code, multiple dynamic attributes per HTML tag, variable styles or class sets usually result in total mess of HTML and PHP which is very hard to read. This usually happens with form elements or jQuery widgets that require a lot of data converted into HTML attributes, classes and styles. Read the rest of this entry »
Customers and users sometimes ask for an ability to save some reports from web applications to PDF files. It could be very tricky to write PDF directly but as far as you already have those reports on web pages you can add printable views of them and then ability to convert HTML/CSS of the pages to PDF, say with dompdf library. This way you can hit two targets: add printing of reports and PDF export. Dompdf is still in beta but at least it could work on shared hosting AFAIK.
But what if you need to export web pages with JavaScript canvas elements like Flot charts that are plotted on browser side only? All available solutions require installing executables which is usually problematic on shared hosting.
The solution is PDFmyURL.com/ which you can easily use as a web-service: send GET requests with URL of the page you want to export and get PDF file as a response. The service is based wkhtmltopdf. As you can see, it’s good enough to convert pages with Flot charts:
http://pdfmyurl.com/?url=http://people.iola.dk/olau/flot/examples/basic.html.
You can call the service from JavaScript on your pages or from server-side scripts via any HTTP client library like cURL. All wkhtmltopdf options are supported and could be passed as GET request parameters.
Their free service inserts very small watermark to each page which is usually not a problem. But of course you can upgrade to paid service to remove it.
If you need to get Google search result count for some query, using estimatedResultCount from Google AJAX Search API sounds like a winner. However, the number reported as estimatedResultCount doesn’t match the number displayed on regular search pages and could be different in many times. This is known issue since 2008 and it seems it will never be fixed.
So if you want more correct result count, the extract it from regular Google search page. Alternatively you can use Yahoo or Bing APIs as they report the same numbers to displayed on their regular search pages.
UPDATE: It was found that regular Google search pages display even more rough estimated result count than Google AJAX Search API. For example, query for "pumka.net" (w/ quotes) it reports "About 1,380 results" while only finds 284 pages. Bing reports 55 results while finds 50-52 and Yahoo reports 210 results while finds 55. So using Bing or Yahoo API for analysis of result counts is likely more accurate.
When I developed Windows desktop applications I was tied to ProEssentials library which was powerful yet expensive and had weird and very limiting API. Don’t want to say anything bad about ProEssentials developers but, OMG, their API contains hundreds of properties and functions you have to go through just to find few ones you really need. Not only do many of them have strange names, but they also do very strange things))). How do you like “ForceVerticalPoints” property? How in this World could points be vertical or horizontal? Well, it’s actually about point labels… Enough about that horror.
Thank to Flot library, charting for the Web made extremely easy yet powerful and extensible. Flot is jQuery plug-in which means you can use all power of jQuery for setting it up, passing data to it and reacting to its events. Moreover, chart plotting happens on the browser side which means your server isn’t slowed down by producing chart pictures. And this also means you can add interactive features to your chart like point tooltips, zooming, live AJAX updates or display options applied w/o page reload.
Recently we found that our Zend Framework based application was running into infinite loop and terminated by execution timeout on some hostings. The problem was found in Zend_Http_Client_Adapter_Socket class which uses stream_copy_to_stream if you configure Zend_Http_Client for writing data to stream.
The problem already was reported on ZF issue tracker but wasn’t fixed: http://framework.zend.com/issues/browse/ZF-9265. It seems that the cause is a bug in stream_copy_to_stream that was fixed at some point during PHP 5.2.x development.
But as we need to run our code on virtually any hosting we decided to work around this problem by replacing stream_copy_to_stream with fread and fwrite in Zend_Http_Client_Adapter_Socket code. Notice that Zend_Http_Client_Adapter_Curl is not affected by this problem as it uses internal code for writing to streams. Thus, switching to Zend_Http_Client_Adapter_Curl sounds as the easiest solution. We added automatic switching to it by checking if ‘curl_init’ function exists and if so we use Zend_Http_Client_Adapter_Curl as the adapter for Zend_Http_Client.