php-pushover, a PHP class for sending push notifications to iOS & Android

So I’ve been using Notifo for a while now and I must say, lovely service. Unfortunately, they will be closing down..

In my quest for a new push notification provider, I stumbled upon Pushover.
Pushover is by far the only service that can deliver (free) push notifications to both iOS and Android platforms, with a simple API, and a lot of cool options. Even authentication is very easy (not like Prowl). Have a look at their api docs.

Here’s the php class I wrote for Pushover:
https://github.com/kryap/php-pushover/blob/master/Pushover.php

And here’s how you use it:

<?php 
include('Pushover.php');
 
$push = new Pushover();
$push->setToken('app token goes here');
$push->setUser('user token goes here');
 
$push->setTitle('Hey Chris');
$push->setMessage('Hello world! ' .time());
$push->setUrl('http://chris.schalenborgh.be/blog/');
$push->setUrlTitle('cool php blog');
 
$push->setDevice('iPhone');
$push->setPriority(0);
$push->setTimestamp(time());
$push->setDebug(false);
 
$go = $push->send();
?>

Good luck! And let me know which cool projects you used this for! 🙂

Opencart send fax on order

In some cases, it’s useful to fax your orders to the store as soon as an order is placed. Now many people will think this is very hard, but in fact, it’s very easy to accomplish this. Thank god for API’s!

Browse your Opencart folder and go to /catalog/model/checkout/order.php, line 370 (after the following code), and add your fax code. If you put the code here, you can reuse the default HTML mail Opencart will send to your client (which includes all the order info).

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/mail/order.tpl')) {
	$html = $template->fetch($this->config->get('config_template') . '/template/mail/order.tpl');
} else {
	$html = $template->fetch('default/template/mail/order.tpl');
}

I’d like to use Interfax since they provide a very easy PHP API. Only 1 requirement, you’ll need SOAP. Now add this code:

/* START: SEND FAX */
 
	/**************** Settings begin **************/
 
	$username = ''; // Enter your Interfax username here
	$password = ''; // Enter your Interfax password here
	$faxnumber = ''; // Enter your designated fax number here in the format +[country code][area code][fax number], for example: +12125554874
	$texttofax = $html; // Enter your fax contents here
	$filetype = 'HTML'; // If $texttofax is regular text, enter TXT here. If $texttofax is HTML enter HTML here
 
	/**************** Settings end ****************/
 
	$client = new SoapClient("http://ws.interfax.net/dfs.asmx?wsdl");
 
	$params->Username  = $username;
	$params->Password  = $password;
	$params->FaxNumber = $faxnumber;
	$params->Data      = $texttofax;
	$params->FileType  = $filetype;
 
	$faxResult = $client->SendCharFax($params);
 
/* END: SEND FAX */

Et voila. The email sent to your client for notification will also automaticly be faxed to the given fax number.

Minifying your Zend Framework views

When your website is getting alot of traffic, you’ll eventually reach the point where you want to tune things (or good habits). Next to backend and frontend caching, checking your expiry headers, optimizing images, … you can also minify your application’s output. Minifying or ‘minification’ is ‘the process of removing all unnecessary characters from source code, without changing its functionality‘.

Now keep in mind, it’s always better to load your CSS from an external stylesheet, this way it can get cached + you can use a very cool tool called http://code.google.com/p/minify/ . This leaves us with all the other code, your website’s HTML.

Using view output filters in Zend, it’s fairly easy to minify all your html/javascript/css output. In this blog post I’ll show you how to get things up and running. We’ll be using the same open source Minify library (http://code.google.com/p/minify/source/browse/#svn%2Ftrunk%2Fmin%2Flib)

Create a new view output helper (more about this):

<?php
require_once 'Zend/Filter/Interface.php';
require_once 'Minify/HTML.php';
require_once 'Minify/CSS.php';
require_once 'JSMin.php';
 
class My_View_Filter_Minify implements Zend_Filter_Interface
{
    public function filter($value) 
    {
    	return Minify_HTML::minify($value, array(
    	    'cssMinifier' => array('Minify_CSS', 'minify'),
            'jsMinifier' => array('JSMin', 'minify')
    	));
    }
}

Next and final step is letting our project know we want to use this new filter globally, so add the following code in your bootstrap:

public function _initMinifyHTML()
{
    $this->bootstrap('view');
    $view = $this->getResource('view');
    $view->addFilterPath('My/View/Filter', 'My_View_Filter');
    $view->setFilter('Minify');		
}

PHPBenelux Conference 2012

So last weekend I went to my first #phpbnl12 conference in Edegem, Antwerp, and I must say. This was one of the best conferences I’ve attended so far! Great talks, great people, open bar every night, bbq, kinect, free bowling, belgian beer, am I missing something?

Anyway here’s a list of the talks: http://conference.phpbenelux.eu/2012/talks/ , and the by now famous after movie: