Mika Tuupola

Technology guy with passion for advertising.

  • weblog
  • projects
  • cv

Php

Logging API for Frog Dashboard

18 May 2009

Dashboard plugin for Frog CMS now provides simple API for other developers to log their events. Whenever you want to log something to dashboard just trigger a log event. Include your message as parameter.

Observer::notify('log_event', 'Something was done by :username.');

In your message you can include string :username to log the user name.

Continue reading

Mephisto Style Asset Management for Frog CMS

23 December 2008

One of the things I like about Mephisto is the asset management. Especially the way how you insert image URLs by dragging thumbnail from sidebar to content area. Frog CMS lacked easy way for inserting images (or any other files). Obvious thing to do was implement Mephisto style asset management as a plugin.

It is not one to one copy on how Mephisto does it. Instead of tagging assets you can categorize them by uploading to different folders. There is also extra pulldown to select which assets to show in sidebar while editing.

Plugin depends on Image Resize and jQuery plugins to work. Full installation instructions on project page.

Send Emails from Frog CMS

28 November 2008

I needed a mailer backend which can handle complicated forms with any number of arbitary form fields. I also needed to be able to fully control the layout of sent emails. Something similar as oldie but goldie cgiemail.

Here comes Email Template plugin for Frog CMS.

It provides new page type called named Email template. You can POST your forms to this page type. Page contains the layout of the mail including the headers. Template then parses POST:ed data and sends the email.

To: Somebody <somebody@example.com>
From: <?php print $_POST['name'] ?> <<?php print $_POST['email'] ?>>
Subject: Frog Mail

1. Contact info

Name.............: <?php print $_POST['name'] ?> 
Company..........: <?php print $_POST['company'] ?> 
Email............: <?php print $_POST['email'] ?> 

2. Message

<?php print $_POST['message'] ?>

--
Sent by <?php print $_SERVER['REMOTE_ADDR'] ?>

Plugin assumes your PHP mail() function works properly. Currently it only supports plain text emails. Download and installation instructions at the project page. All feedback welcome.

Ultrafast Frog With Funky Cache

21 November 2008

Funky caching is technique popularized by PHP.net site. It was first mentioned by Rasmus Lerdorf in 2002 PHPCon slides (page 25). Content is cached as static file on the first access. All following requests are served using the cached static file. Editing a page will automatically expire cached files. Page is then re-cached on the next hit.

Frog CMS is PHP port of Rails based Radiant CMS. Radiant is great but there is always the hosting problem. Even with mod_rails existing it is still easier to get quality PHP hosting. Both Frog and Radiant are the only CMS’es I can say I like. Expression Engine I can live with. Edicy looks really promising. Everything else I rather not touch.

Continue reading

Introduction to Marker Clustering With Google Maps

04 November 2008

Static Maps API has URL length limit of around 2048 characters. You can hit this limit quickly when adding lot of markers. You can keep URL short by clustering markers together.

Square Based Clustering

Clustering is usually done by dividing map to squares. Square size depends on map zoom level. Markers inside a square are then grouped into cluster. This technique has some limitations. Look at the following image.

Two markers are close to each other. In fact they are so close they are overlapping. Both markers are also the only marker inside their square. Because markers are in separate square they wont be clustered.

Continue reading

Simple Zoom and Pan Controls With Static Maps

24 October 2008

Most of the code from previous Static Maps experiments is now put into one clean package. Previously I showed you how to work with markers and bounds. Now we go forward and add zoom and pan controls. It takes only few lines of code. If you just started reading the series check the theory how it works. As a bonus lets add infowindows / bubbles too.

Note! Image above is just a screenshot. You can test final result in the demo.

Create Map and Some Markers

Start by creating new map object and set the size. We also need to give our API key. Markers are positioned on map using location object. Location can be latitude and longitude represented by Google_Maps_Coordinate object. Location can also be map x and y represented by Google_Maps_Point object.

Continue reading

Simple Static Maps With PHP

10 October 2008

Lately I have been playing with Google Static Maps API a lot. Writing the same things again and again is tedious job. I decided to put the code together as one clean extendable package. Writing object oriented interface for generating URL is trivial. Real meat is having working zoom and pan controls on static map with just 9 lines of code (demo now includes also clickable markers and infowindows).

Code is still alpha quality. API might change any time. But here is a quick walkthrough of current features. We will build the map you see above step by step.

Continue reading

Debugging PHP With Firebug

08 February 2007

Logging PHP and JavaScript errors to same window makes debugging easier. It also might be the cure to cancer and bring world peace. In general…

In a recent PHP + JavaScript project I realized how annoying it is to have debug information in more than one place. For PHP I use PEAR::Log package. Log is written to file. For JavaScript I use Firebug. Log is written to Firebug console. When something goes wrong you must switch between browser and terminal windows.

There must be a better way. I like both PEAR::Log and Firebug. Obvious thing was to combine them. Result is Firebug handler for PEAR::Log. It can currently be found only in CVS. Hopefully be handler will be included in next release of PEAR:Log package.

Example PHP usage below.

 $log = &Log::singleton('firebug', '', 'PHP',
                        array('buffering' => true),
                        PEAR_LOG_DEBUG); 
 $log->log('Debug lorem ipsum.',             PEAR_LOG_DEBUG);
 $log->log('Info wisi enim ad minim veniam', PEAR_LOG_INFO);
 $log->log('Warning est usus legentis in',   PEAR_LOG_WARNING);
 $log->log('Error est notare quam',          PEAR_LOG_ERR);

If you have Firebug installed, enable it and check Log Firebug test page. You can also redirect all PHP errors to Firebug console.

UPDATE 20070208: You might want to check FirePHP which provides different approach. FirePHP is Firefox extension built on top of Firebug. It modifies request headers to include Accept: text/firephp. Debug data is sent back using text/firephp section of multipart/mixed HTTP response. Using FirePHP is more complicated but at the same time it can provide you with more flexibility.

Valentine Day Cards With jQuery and PHP

07 February 2007

We just finished latest joint project with finnish EGO. Result is Valentine’s Day card campaign for the main newspaper in Finland. Users choose between six prefined picture frames. Upload best picture of themselves (photoshopped or not). Write a nice poem to their loved one. After the masterpiece is finished they can send the card immedietly or at chosen time.

Typical way of working in advertising world is not most pleasant. Insane deadlines. Clients doing last minute changes. With these things in mind, you can not spend too much time coding basic things. With jQuery we were able to concentrate on needed features:

  • Photo should be zoomed with magnifying glass icons.
  • Photo should be panned by dragging it with mouse.
  • Greeting text should be previewed live while typing.
  • No Flash.

Campaign site also uses date picker plugin by Kelvin Luck

IP Address to Country Code Conversion

08 September 2006

Having been almost one year in my TODO list I finally updated the documentation section of I18N_IP2Country.

ISO 3166 Country Code PHP Class

18 March 2006

Old code gets updated because I am bored. I do not feel drinking and I have not found any pinball machines in Tallinn yet.

I18N_ISO_3166 is an old class which I have neglected for a while. Quick look on ISO website shows some updates I have missed. Yugoslavia has been removed. �land Islands and Serbia Montenegro has been added. I also shortened the official names of countries. There was no point including The Republic of after every other country.

Ford Henry Cars

23 January 2006

!/~tuupola/oldimages/22.gif (Henry Ford)! First joint Internet project between our Tallinn and Helsinki offices went just live.

Henry badge is a guarantee that the used car is sold by an official Ford dealer and it was throughoutly checked by Ford engineer. Ford Henry website itself is a visual way to browse used cars which have the Henry badge.

The car data is fetched from Netwheels database – a company which hosts most of carsale dealer data in Finland. The logic itself is built around DB_DataContainer, PHPSavant, Cache_Lite and PEAR::DB. And yes, it validates.

I18N_IP2Country - IP Address to Country Code Conversion

18 September 2005

Provides methods for retrieveing country name or ISO 3166 country code based on ip address, ie. ip to country conversion.

Continue reading

I'm back, this time armed with Textpattern

17 September 2005

Since there will be some changes in my life which I wanted to document (you know, so I will remember them later) it became mandatory that I ditch my old homebrewn system and change something easier to use. This way I won’t have the excuse of it’s so complicated for not writing. I looked into several different softwares…

WordPress: Everyone uses it, written in PHP – the language of my choice. But it just does not feel elegant. If it does not feel right it just does not feel right.

Typo: Propably the most hip blogging system at the moment. Written using Ruby on Rails. Utilises AJAX in several places. The downside? Installation, definetily installation. It was like compiling PHP in 2002 – trial and error. In the end I just could not make it work properly with ~username/ style URLs. Then I gave up.

Serendipity: Written by several of the best PHP developers on earth. The code itself is superior but what Serenpidity really needs is a couple of designer guys and a user interface specialist onboard with the developer team.

Texpattern: This is what I finally chose to use main reason being usage of Textile for post formatting. Textile together with somewhat different aproach to admin interface gives Textpattern an elegant overall feeling. The permalink style is similar to my old permalinks so I will not loose my google status. It is not all good though. The template system is a bit awkward and the PHP code itself is really not my style. But hey! It Works™ and I don’t have to maintain the code.

Persistence Layer For PHP5

17 October 2004

The latest releace candidate of DB_DataContainer now supports also PHP5. Official release will follow shortly if no bugs are found. Also to those who might be interested a port to PDO is under its way. The class will be called PDO_DataContainer.

While browsing through similar projects I found out something that I haven’t noticed before. Propel uses the same approach of having just one save() method instead of separate insert() and update() methods to persist the object into the database. I never understood the reason of having different method call for INSERT and UPDATE which is what most of the persistence layers and alike have. If the object has primary key set you know you have to do an UPDATE. If primary key is not set you know you have to do and INSERT.

Daniel Convissor Speaks PEAR::DB

24 June 2004

In the latest edition of International PHP Magazine Daniel Convissor gives an overview of the new Features in the PEAR::DB 1.6.x releases. The article is called PEAR DB: Ripe for the Picking.

Two solid months of tilling the proverbial soil, committing over 500 bits of fertilizer and squishing 90 documented bugs — and countless undocumented ones — has brought PEAR’s most popular package to a new state of maturity. It is stable and fully tested on most of the supported DBMS’s. The new release focuses on portability, allowing you to write applications that can be used with a wide variety of database back-ends.

Savant - a No-Nonsense Templating Engine For PHP

05 May 2004

For years I have disliked all the templating engines for PHP. IMNSHO the whole concept of templating engines for PHP does not make sense. In order to have a flexible templating engine it must have a flexible scripting language. Why in earth you would want to write a scripting language parser with a scripting language such as PHP.

Friends don’t let friends use templating engines.

Today I found Savant. After spending a good hour reading the docs I started to realise it is a templating engine I could use. It has a no-nonsense aproach. It uses PHP as the template language, but still provides a nice interface to separate business-logic from display-logic (something I should pay more attention sometimes). As a promise to myself, I will investigate more on Savant. Perhaps first use vanavesi.com as a testbed and initial testing.

Because you still want to separate your business logic from your display logic.

Creating GIS Maps With PHP

09 March 2004


You just have to love Sebastian Bergmann’s
Image_GIS. With
few lines of code and free
geospatial
data
you are able to produce nice map of Finland. A bigger version
here.

Generating maps on demand can be a hard job as most often you don’t have the maps you need in digital form. But you can generate your own maps based on raw, digital data files which are available for free on the net.

The Image_GIS package provides a parser for the most common format for geographical data, the Arcinfo/E00 format as well as renderers to produce images using GD or Scalable Vector Graphics (SVG).

PHP 4.3.3 Released

26 August 2003

After four release candidates PHP 4.3.3 was finally released yesterday. This release contains a large number of bug fixes and PHP group strongly recommends that all users of PHP upgrade to this version.

PHP 4.3.3 contains, among others, following important fixes, additions and improvements:

  • Improved the engine to use POSIX/socket IO where feasible.
  • Fixed several potentially hazardous integer and buffer overflows.
  • Fixed corruption of multibyte character including 0×5c as second
    byte in multipart/form-data.
  • Fixed each() to be binary safe for keys.
  • Major improvements to the NSAPI SAPI.
  • Improvements to the IMAP extension.
  • Improvements to the InterBase extension.
  • Added DBA handler ‘inifile’ to support ini files.
  • Added long options into CLI & CGI (e.g. —version).
  • Added a new parameter to preg_match*() that can be used to specify
    the starting offset in the subject string to match from.
  • Upgraded the bundled Expat library to version 1.95.6
  • Upgraded the bundled PCRE library to version 4.3
  • Upgraded the bundled GD library to version GD 2.0.15
  • Over 100 various bug fixes!

Stable Persistence Layer

24 June 2003

After nine months of testing and developing DB_DataContainer was finally announced stable. The version number was bumbed up to 1.0.0. Being stable means API is frozen and backwards compatibility will be maintained with future releases. Thanks to everyone who have helped with suggestions and bugfixes.

PHP Meets Java Meets PHP

16 June 2003

It seems Zend teams with Sun to work with Java Specification requests initiative. Does this mean PHP will have Enterprise Compatible badge in it? ;)

Zend Technologies Ltd., the creator of the PHP scripting engine, and provider of solutions to Develop, Protect and Scale enterprise PHP applications, today announced their participation in a Java Specification Request (JSR) initiative with Sun Microsystems to create a standard method for accessing Java-based systems from scripting languages. The initiative is an important step in further strengthening PHP adoption by enterprises. Furthermore, it paves the way for standards-based middleware products that will provide scalable integration between PHP front-end web applications and Java business logic.

IP to Country PHP Class

02 June 2003

I18N_IP2Country is a quick PHP class to provide OOP interface to Ip To Country database. As usual installable with PEAR commandline installer. Check the examples for usage.

Clickpath Analysis

02 June 2003

Thanks to project at work which needed clickpath analysis I finally had time to play around with phpOpenTracker and GraphViz to create graphical clickpath maps. As a side product I made two real time maps out of my journal. Please note that they are rendered on the fly so loading them might take few seconds.

The first one All paths today renders one big map of all users clickpath combined. This is useful for determining different trends on navigating inside the site.

The second one Top paths today maps all the unique clickpaths on several different maps. These maps provide interesting information of single user behaviour.

If you need GraphViz binaries for Sparc Solaris you can find them here. Installs in /usr/local/.

ISO 3166 Country Codes

08 May 2003

Since I needed to be able to convert between different ISO 3166
standard country codes and retrieve correspoding country names
I wrote a small utility class in PHP. Not surprisinly it is named
I18N_ISO_3166 and as
usual is under revised BSD licence and
installable via PEAR
commandline installer.



@tuupola