Archive for the ‘Coding’ category

TUPAS authentication service for Zend Framework

August 14th, 2010

TUPAS is authentication service used by finnish banks. I created Zend_Service for it. See project site for code and examples.

iMagickFX – image effects for the people

August 2nd, 2010

I just started new project called iMagickFX which adds possibility to add different effects to images easily.

Like so:

$im = new iMagickFx('example.jpg');
$im->fxCropResize(100, 100)->fxReflection('white', 0.9);

$im = new iMagickFx('example.jpg');
$im->fxCropResize(100, 100)->fxRoundCorners()->fxDropShadow();

Currently it contains only four effects. Reflection, drop shadow, greyscaling and resizing but more is coming!

imfx

XoNoiD CRM development stopped

July 28th, 2010

I’ve now stopped XoNoiD CRM development completely because lack of time and feedback from testers and users. Please be free to fork it for your own CRM projects.

Subversion logs to iCalendar format

April 2nd, 2010

I wanted to know when I’ve kept my vacations so I wrote small Python script to find out.

pysvnlog2ics parses SVN XML commit log and creates iCalendar .ics file from it. This resulted in many .ics files as in work I use one repository per project and over the years this count is in hundreds today. So I wrote another script – pyicalmerge which combines those .ics files to one big .ics file. Then I just uploaded that giant .ics file to Google Calendar and now I have all my commits in my calendar and can easily see the vacation gaps.

Minimal feedback form with ZF

October 4th, 2009

Here’s minimal feedback form example using Zend Framework 1.9.2 without MVC.

<?php
ignore_user_abort(true);
header("Content-Type: text/html; charset=utf-8")

error_reporting(E_ALL);
ini_set('display_errors', '1');

ini_set('magic_quotes_gpc', false);
ini_set('magic_quotes_runtime', false);

ini_set('default_charset', 'UTF-8');

ini_set('iconv.input_encoding', 'UTF-8');
ini_set('iconv.output_encoding', 'UTF-8');
ini_set('iconv.internal_encoding', 'UTF-8');

function stripinputslashes(&$input)
{
  if (is_array($input))
  {
    foreach ($input as $key => $value)
    {
      switch (gettype($value))
      {
        default: break;
        case 'string':
          $input[$key] = stripinputslashes($value);
        break;
      } // /switch
    } // /foreach
  } // /if
  else
  {
    switch (gettype($input))
    {
      default: break;
      case 'string':
        $input = stripslashes($input);
      break;
    } // /switch
  } // /else

  return true;
} // /function

if (version_compare(phpversion(), 6) === -1)
{
  if (function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc() === 1)
  {
    array_walk_recursive($_GET, 'stripinputslashes');
    array_walk_recursive($_REQUEST, 'stripinputslashes');

    if (isset($_POST))
    {
      array_walk_recursive($_POST, 'stripinputslashes');
    } // /if

  } // /if
} // /if

// Add library path
set_include_path(implode(PATH_SEPARATOR, array(
  realpath(dirname(__FILE__) . '/../library'),
  get_include_path(),
)));

// Enable autoloader
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

$view = new Zend_View();

$form = new Zend_Form();
$form->setView($view);
$form->setMethod(Zend_Form::METHOD_POST);
$form->setAction('/');

$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('OK');

$email = new Zend_Form_Element_Text('email');
$email->setRequired(true);
$email->setLabel('E-mail');
$email->addFilter('StringTrim');
$email->addFilter('StringToLower');
$email->addValidator('StringLength', false, array(7));
$email->addValidator(new Zend_Validate_EmailAddress(Zend_Validate_Hostname::ALLOW_DNS, true));

$txt = new Zend_Form_Element_Textarea('text');
$txt->setRequired(true);
$txt->addFilter('StringTrim');
$txt->addValidator('StringLength', false, array(3));

// Add fields to form
$form->addElement($email);
$form->addElement($txt);
$form->addElement($submit);

if (isset($_POST) && !empty($_POST))
{
  if ($form->isValid($_POST))
  {
    $values = $form->getValues();

    $m = new Zend_Mail('UTF-8');
    $m->setBodyText($values['text']);
    $m->setFrom($values['email']);
    $m->addTo('feedback@example.com');
    $m->setSubject('Feedback');
    $m->send();

    header("Location: /ok.php");
  }

}

// Output form to page
echo $form;

Page contains e-mail and free text field. E-mail address is checked against DNS. Form contents are send to feedback@example.com and given e-mail address is the sender. stripinputslashes kills all stupid slashes from _POST data.

Directory structure:

/home/foo/public_html/index.php (feedback form)
/home/foo/public_html/ok.php
/home/foo/library/Zend/ (ZF files)

ok.php contains something like “Thank you for giving feedback.”

Gozerbot and What is this file?

October 2nd, 2009

It’s been many years since I played with IRC bots. I’ve used eggdrop for something like 10+ years. Now I tried Gozerbot and coded plugin (source) to it which gets URLs from chat and then gives some information about them. It utilizes my other project – “what is this file?” which runs on top of Google App Engine. Everything is using Python.

First site using zfComicEngine!

September 26th, 2009

Finnish Pikselinviilaajat IT comic is now using zfComicEngine. It was previously running on my non-opensource and age old code. I coded simple converter which corrected all the old links in HTML etc with PHP’s DOM and XML Starlet.

ZFCE has many similarities to old Pikselinviilaajat comic publishing engine but of course it’s all been rewritten.

If you want to try out zfCE, please use my demo site. I’m also looking for some people with some graphical eye so that zfCE could have more default CSS files for new users.

I’m also planning for Flash support so that you could publish animations easily too.

New translations are also welcome. Currently supported languages are Finnish and English.

http://code.google.com/p/zfcomicengine/issues/detail?id=9