Trackr 0.1 – jQuery based user interaction tracking (PHP/MySQL)

Trackr is a very simple, lightweight (well, if you’re already using jQuery) user interaction tracker. It’s not particularly robust and is only in a fairly simple form right now.

The back end is written in PHP using MySQL for storage, but could easily be implemented in other languages.

To log data, you simply add a call to Trackr.init() to the page load event, passing the desired options as the only parameter to the function.

There are a variety of options that can be specified and for more information please see the test page.

You can get it here (includes jQuery 1.3.2).

php-log: Process apache log files with PHP

I’ve recently had to quickly parse an Apache log file, to get basic usage statistics for a site over a month and wanted the ability to quickly process any general logs and store them in a MySQL table, so I’ve made a small package class.log.

Included in the package are:

  • class.log.php (the main class)
  • class.log.processor.php (an interface for a log processor, very basic!!)
  • class.log.output.php (a simple extension of the processor (outputs <p> tags with <span>s)
  • class.log.mysql.php (a simple mysql importer of the processed data)
  • parse.php (a simple implementation, bringing all the classes together)

The class is designed to use one line at a time from the log retrieved, and the regular expression specified in class.log.php can be modified to parse different types of logs as long as the matches array is also updated.

I’ve only used this for apache logs currently, which it managed quite well, I’m not sure if I’d use this script in an automated script, but I’ll leave that for you to decide.

As other scripts, this class is available under the Creative Commons Share Alike Attribution license.

Edit: Minor update, made class more generic and added more comments.

Download (3.7kB)

mod-framework: PHP, light and easy

I know there’s already infinite PHP framework out there, trying to be rails; and most of them are doing it really well, I just feel that none of them completely embrace the simplicity of convention over configuration, so I’m trying to build one that ticks all the boxes.

It’s pretty simple so far, and is only a few hundred KB, but I think it’s got some cool features, and maybe even potential.

Like the other stuff it’s under a Creative-Commons SA license and can be found at:

http://mod-framework.googlecode.com/.

Any opinions, suggestions, contributions would be gratefully received.

Current functionality:

Model-View-Controller system
MySQL support (using a modified version of the DB class from earlier)
script/server implementation in PHP
Helper association, so if you create a PageHelper class for your Pages controller all the functions will automatically be made ‘global’ (accessible view functionname() instead of Helper::functionname())
Includes mootools in the htdocs folder

The DB doesn’t work quite how I would have imagined it to (well, with PHP 5.3 it might… but I haven’t got it yet…) so currently any models are added to $GLOBALS[] so that for a Page model, $GLOBALS[‘Page’]->find_by_name(‘dom’), etc would work.

There’s probably some other stuff in there too…

DB

Here’s a little script I’ve wanted to make for a while, but have only just finally got the motivation to work on.

It’s a lightweight Database wrapper with functions similar to Ruby on Rails’ ActiveRecord.

When I discovered the __call() method I wanted to make my own version in PHP, so here it is!

It supports most basic functions, all based on the MySQL set of PHP functions, no other wrapper is required (PEAR etc.). There is not (yet?) any automatic mysql_real_escape_string or anything, although that could easily be added if required, my assumption is you’ve done that kind of thing already before passing anything to it.

$db = new DB('mysql://username:password@server:port/database');
$people = $db->table('people');
$companies = $db->table('companies');

$company = $company->find_by_name_like('%test%');

$person = $people->create(
  array(
    'name' => 'Dom',
    'company_id' => $company->id,
    'created_date' => date('Y-m-d H:i:s')
  )
);

$id = $people->lastId();
$dom = $people->find($id);

print $person->name;
// Dom

print $dom->name;
// Dom

$dom = $person;
$new_users = $person->find_by_created_date_before(date('Y-m-d H:i:s', strtotime('1 hour ago')));

foreach ($new_users as $user) {
  // loop through all the users with a create date more than 1 hour ago
  if (!$company->find($user->company_id)) {
    // and delete any that don't have a company associated with them
    $people->delete($user->id);
  }
}

It’s only a first draft, so any comments, questions or pointing out any typo’s in the code, (yeah, there are likely to be a few…) would be muchly appreciated.

This work is free under the Creative Commons Share Alike 2.0 license.

Download:

DB_0.1.tar.gz (4.84Kb)

Edit: Think next on my list is TextMate syntax highlighting and maybe the non-default template…