Archive for December, 2010

PHP PEAR HTML_Template_IT Eats Dollar Signs

Wednesday, December 29th, 2010

Sigh.  We discovered a bug in our recently reworked tools.perceptus.ca (“PWT”) site.

We have a simple, custom, partial MVC system that runs a few of our smaller websites.  That system uses the PEAR HTML_Template_IT package to do the final template rendering. We ported PWT to our MVC to make future site changes much easier.

A week after going live with the changes, we found a baffling bug.  The tools were eating the dollar sign and dollar amounts (but not the decimals) from the input text. E.g. “$103.00” would get returned as “.00”.  Not good.

Apparently, HTML_Template_IT defaults to processing all text with regex.  Not cool.

There might be a historical reason for this, but for new users, this has got to be confusing. Plus, this is NOT mentioned in the intro documentation: http://pear.php.net/manual/en/package.html.html-template-it.intro.php

We’re not the only ones caught by this: http://pear.php.net/bugs/bug.php?id=50.

The fix is to initialize and set the use_preg option, like this:

$tpl = new HTML_Template_IT(‘./’,array(‘use_preg’=>true));

I have glanced at the package pages, and while this behavior is  documented it is buried quite deeply in the documentation.

This also explains a typo we had years ago on a static page that had the text like $5 in it.  That time, we just changed the copy to read 5 dollars and got on with life.

 

A Web Based Adding Machine

Monday, December 13th, 2010

We have Perceptus’ Web Tools at the top of mind lately.  We’ve created another new tool, our minimal web based adding machine.

Have you ever had a half-hazardly formatted list of numbers to add up (maybe from an email?) and you didn’t want to do this:

  • open up Excel (or other spreadsheet program)
  • create a new file
  • paste the values
  • tidy them up so that they are  recognized  as numbers
  • create the SUM() function

Well, we have, and now we have created a tool to save us, and hopefully you, some time.

Visit our new web based adding machine tool and try pasting in a set of numbers like this:

10
-7.8
8 000
(92)
30.1

And be impressed when you get results like this:

Add Running Total
+0 0
+10 10
-7.8 2.2
+8000 8002.2
-92 7910.2
+30.1 7940.3

Impressed?  Did you notice that it handles negative numbers in (brackets) magically?  Or how about that awkward space in “8 000”?  We’re pretty proud of ourselves – even if you’re not impressed.

Comments and feedback is always appreciated!

 

Clean Up a Column of Mixed Date Formats Tool

Sunday, December 12th, 2010

A few times a year, a client of our will need our help in cleaning up a manually populated Excel file that has a couple of date columns. Invariably, there is a hodge-podge of date entries, such as 2010-10-05;  june 10, 2010; or 8/4/2008.  We’ve finally made a tool to fix up the bulk of this so that Excel will detect it properly as a date value.

Perceptus introduces the  Clean and convert a column of dates in Excel Numbers Wizard, on the Perceptus Web Tools mini-site.

We hope this tool saves some people besides ourselves some time.

 

Google Chrome Built-in PDF Viewer Incompatibility with IFRAME and a Workaround

Saturday, December 11th, 2010

With the recent automatic upgrade of Google Chrome to version 8, Google made their built in PDF viewer the default viewer *.  I.e. there is now no need to separately download Adobe Reader or Adobe Flash Player to browse the web with Google Chrome.

Generally, I like this addition to Google Chrome; however, it caused some work for us.  Our web based bingo card generator, print-bingo.com, is highly dependent on PDF’s.  That’s the sole reason why our bingo cards are dead-easy to print out by the hundreds.  Unfortunately, Chrome’s built-in PDF renderer does not display PDFs that are in an IFRAME tag properly.

For the last few days, this is what users of print-bingo.com would see after generating 5 pages of bingo cards on print-bingo.com:

 

Broken PDF rendering in an IFRAME in Google Chrome 8 - screenshot from print-bingo.com

Broken PDF rendering in an IFRAME in Google Chrome 8 - screenshot from print-bingo.com

Chrome tries to scale the parent page to fit everything in… and it fails badly.

We were not able to get things working 100% the way we would like, but we have a workable situation now.

The basic steps that we had to take:

  • Change from IFRAME to OBJECT tag.  For whatever reason, this fixes the zooming issue.  And it was quite simple.  In our case, there wasn’t much difference between the two HTML tags.
  • Unfortunately, we can’t find a way to get Chrome to print the contents of the object tag without printing the rest of the page (though, perhaps using CSS  might work).
  • Instead, we added some bold warning text that gives Chrome users instructions to use the manual download links. We use a little function to identify Chrome users – the two key lines of code are: 
    $u_agent = $_SERVER[‘HTTP_USER_AGENT’]; 
    if(preg_match(‘/Chrome/i’,$u_agent)) { $ub = “Chrome”; }

So, we ended up with a workaround.  We sincerely hope that Google will add the missing interface elements that will make things just work, but until then, we are doing some other site improvements as we prepare to bump up the price of Premium Access to $12 in 2011.

* If you want to go back to using Adobe Reader in Google Chrome, you can turn off the  built-in viewer by going to the special address about:plugins and change Chrome PDF Viewer to Disable.  Of course, website owners should not depend on end-users to do this just to visit your site!