PHP
February 28, 2012
Example OOP PHP Code
<?php abstract class pid_entity{ function details(){ global $r; $r['dbname'] = 'uebs'; $r['schema'] = 'pid'; if(!$this->id){ return false; } if(!$this->table){ return false; } $reply = just::sql(sprintf('select * from %s.%s where %s_id = %d',$r['schema'] , $this->table, $this->table, $this->id)); $this->details = $reply['first_row']; $this->row = $this->details; } function create(){ if(!$this->table){ return false; } global $r; $r['dbname'] = 'uebs'; $r['schema'] = 'pid'; $this->id = just::add($this->table); } function set(){ if(!$this->table){ return false; } global $r; $r['dbname'] = 'uebs'; $r['schema'] = 'pid'; if(!$this->id){ $this->create(); } $reply = just::update($this->table, $r, $this->id); $_SESSION['pid_set'] = $reply; $this->details(); $this->row = $this->details; return $reply['status']; } function annotate(){ global $r; $r['dbname'] = 'uebs'; $r['schema'] = 'pid'; $id = just::add('note'); $r[$this->table.'_id'] = $this->id; $reply = just::update('note', $r, $id); return $reply['status']; } function get_notes(){ global $r; $r['dbname'] = 'uebs'; $r['schema'] = 'pid'; $reply = just::sql(sprintf('select notes, to_timestamp(insert_date) as ts, insert_date from %s.note where expired_date is null and %s_id = %d order by insert_date desc', $r['schema'], $this->table, $this->id )); return $reply['rows']; } } interface pid_entity_if{ function details(); function create(); function set(); function add_child($object); function get_children(); function calculate_start(); function calculate_end(); function annotate(); function get_notes(); } class project extends pid_entity implements pid_entity_if{ public $id; public $title; public $percent_complete; public $start_date; public $end_date; public $children; public $table = 'project'; function __construct($key){ if($key > 0){ $this->id = $key; $this->details(); } } function add_child($object){} function get_children(){} function calculate_start(){} function calculate_end(){} } class phase extends project{ public $id; public $title; public $percent_complete; public $start_date; public $end_date; public $children; public $table = 'phase'; function __construct($phase_id){ parent::__construct($phase_id); } } class work_package extends project{ public $id; public $title; public $percent_complete; public $start_date; public $end_date; public $children; public $table = 'work_package'; function __construct($wp_id){ parent::__construct($wp_id); } } class deliverable extends project{ public $id; public $title; public $percent_complete; public $start_date; public $end_date; public $children; public $table = 'deliverable'; function __construct($del_id){ parent::__construct($del_id); } } /* End of /waf/classes/project_initiation.php */
DB Model:
drop table if exists pid.project; create table pid.project ( project_id serial unique not null, project_type_id integer null, name text null, purpose text null, background text null, assumptions text null, constraints text null, risks text null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (project_id) ); alter table pid.project drop project_type_id; drop table if exists pid.phase; create table pid.phase ( phase_id serial unique not null, phase_type_id integer null, project_id integer null, phase_sort decimal null, name text null, description text null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (phase_id) ); alter table pid.phase drop phase_type_id; drop table if exists pid.work_package; create table pid.work_package ( work_package_id serial unique not null, work_package_type_id integer null, phase_id integer null, dependent_on_package_id integer null, name text null, package_sort decimal null, description text null, start_date bigint null, length_days decimal null, completion_date bigint null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (work_package_id) ); alter table pid.work_package drop work_package_type_id; drop table if exists pid.staff; create table pid.staff ( staff_id serial unique not null, staff_type_id integer null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (staff_id) ); alter table pid.staff drop staff_type_id; drop table if exists pid.note; create table pid.note ( note_id serial unique not null, note_type_id integer null, project_id integer null, phase_id integer null, work_package_id integer null, notes text null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (note_id) ); alter table pid.note drop note_type_id; drop table if exists pid.deliverable; create table pid.deliverable ( deliverable_id serial unique not null, deliverable_type_id integer null, work_package_id integer null, name text null, delivery_date bigint null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (deliverable_id) ); alter table pid.deliverable drop deliverable_type_id; drop table if exists pid.work_package_status; create table pid.work_package_status ( work_package_status_id serial unique not null, work_package_status_type_id integer null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (work_package_status_id) ); drop table if exists pid.work_package_status_type; create table pid.work_package_status_type ( work_package_status_type_id serial unique not null, name text null, description text, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, non_deletable boolean not null default true, expired_date bigint null, primary key (work_package_status_type_id) ); drop table if exists pid.upload_file; create table pid.upload_file ( upload_file_id serial unique not null, upload_file_type_id integer null, project_id integer null, phase_id integer null, work_package_id integer null, file_name text null, file_mime_type text null, file_length bigint null, file_data bytea null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key (upload_file_id) ); alter table pid.upload_file drop upload_file_type_id; drop table if exists pid.project_staff_link; create table pid.project_staff_link ( project_staff_link_id serial unique not null, project_id integer null, staff_id integer null, insert_by integer null, insert_date bigint null, update_by integer null, update_date bigint null, expired_date bigint null, primary key(project_staff_link_id) );
Windows .ini file:
[schema] default = pid [table_list] project = 0 phase = 0 work_package = 0 staff = 0 note = 0 deliverable = 0 work_package_status = 1 upload_file = 0 [upload_file] project_id = integer phase_id = integer work_package_id = integer file_name = text file_mime_type = text file_length = bigint file_data = bytea [work_package_status] work_package_id [note] project_id = integer phase_id = integer work_package_id = integer notes = text [deliverable] work_package_id = integer name = text delivery_date = bigint [work_package] phase_id = integer dependent_on_package_id = integer name = text package_sort = decimal name = text description = text start_date = bigint length_days = decimal completion_date = bigint [project] name = text purpose = text background = text assumptions = text constraints = text risks = text [phase] project_id = integer phase_sort = decimal name = text description = text [staff] [link_tables] project:staff = 0 ;programme:course = 0
Posted by pj at 02:37 PM | Comments (0)
October 11, 2011
Student class needs to be adjusted
function get_hash_by_uun($uun){ return $this->get_hash_by_id($this->get_id_by_uun($uun)); } function get_id_by_uun($uun){ $m = (int) str_replace('s', '', $uun); $reply = just::sql(sprintf("select student_id from student_full where matriculation_number = %d", $m)); return $reply['first_row']['student_id']; } function get_uun_by_id($id){ $reply = just::sql( sprintf("select case when char_length(matriculation_number::varchar) = 5 then 's00'||matriculation_number when char_length(matriculation_number::varchar) = 6 then 's0'||matriculation_number else 's'||matriculation_number end as uun from student_full where student_id = %d", (int) $id) ); return $reply['first_row']['uun']; }
Posted by pj at 06:42 PM | Comments (0)
September 28, 2011
Symfony Framework
Posted by pj at 11:27 PM | Comments (0)
December 12, 2009
XML :: PEAR Packages
Posted by pj at 04:33 PM | Comments (0)
September 23, 2009
Code for detecting if it's BST
http://www.devscripts.net/browse/116.php
Posted by pj at 03:45 PM | Comments (0)
July 09, 2009
PEAR CSS Builder
Manual :: features and usage patterns
Posted by pj at 03:55 PM | Comments (0)
PEAR Calendar
Posted by pj at 03:48 PM | Comments (0)
Installing Spredsheet_Excel_Writer PEAR module
/opt/php/bin/pear install channel://pear.php.net/OLE-1.0.0RC1 /opt/php/bin/pear install channel://pear.php.net/Spreadsheet_Excel_Writer
Posted by pj at 12:01 PM | Comments (0)
July 02, 2009
Limonade Framework
Limonade - PHP micro-framework
Posted by pj at 10:06 PM | Comments (0)
May 16, 2009
Mac PHP Postgres Bundle
Posted by pj at 10:36 PM | Comments (0)
January 19, 2009
Using PHP and PGP
Kelv's Programming Area - How to use PGP / GnuPG with PHP
Posted by pj at 04:05 PM | Comments (0)
December 15, 2008
PHP / SWF graphing
Posted by pj at 11:05 AM | Comments (0)
October 16, 2008
iTunes XML Parser in PHP
Code Triangle :: iTunes XML Parser for PHP
Posted by pj at 03:21 PM | Comments (0)
July 28, 2008
Drupal on XAMPP
How to Install Drupal on an XAMPP installation | drupal.org
Posted by pj at 12:43 PM | Comments (0)
July 18, 2008
XML to JSON in PHP
Posted by pj at 02:59 PM | Comments (0)
July 16, 2008
The RDF API for PHP
Also and more usefully:
http://www4.wiwiss.fu-berlin.de/bizer/rdfapi/tests.html
Posted by pj at 01:37 PM | Comments (0)
July 15, 2008
Drupal DOES use PHPtal
PHPTAL theme engine | drupal.org
Posted by pj at 09:35 AM | Comments (0)
April 20, 2008
ONLamp.com -- Improve Your Build Process with Ant
Posted by pj at 08:05 PM | Comments (0)
November 12, 2007
Parsing mail messages with PHP
PHP: Mailparse Functions - Manual
Posted by pj at 08:27 PM | Comments (0)
June 18, 2007
PHP and SOAP article on ADC
Posted by pj at 02:58 PM | Comments (0)
April 26, 2007
Sending plain text and HTML version in the same email
Sending HTML/Plain text Emails - PHP
$boundary = "nextPart"; $headers = "FROM: [email]me@fromme.com[/email]\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: multipart/alternative; boundary = $boundary\r\n\r\n"; $headers .= "This is a MIME encoded message.\r\n\r\n"; //text version $headers .= "--$boundary\n Content-Type: text/plain; charset=ISO_8859-1\r\n Content-Transfer_Encoding: 7bit\r\n\r\n"; $headers .= "This is the plain version\r\n\r\n"; // html version $headers .= "--$boundary\r\n Content-Type: text/html; charset=ISO_8859-1\r\n Content-Transfer_Encoding: 7bit\r\n\r\n"; $headers .= "This is the HTML version"; mail("me@myemail.com", "An HTML Message", "", $headers);
Posted by pj at 10:58 AM | Comments (0)
April 18, 2007
PHP and MySQL and Unicode
Unicode Data with PHP 5 and MySQL 4.1
Posted by pj at 11:01 AM | Comments (0)
January 24, 2007
PHP HTTP functions list
Some really useful stuff in here I wasn't aware of:
Posted by pj at 12:31 PM
November 13, 2006
Applet for file uploading which gets around PHP file size limit
SourceForge.net: Open Discussion
Posted by pj at 11:50 AM | Comments (0)
September 24, 2006
Web site analysis in PHP
Posted by pj at 08:51 PM
August 11, 2006
Python interpreter embedded in PHP
Posted by pj at 10:03 AM | Comments (0)
August 06, 2006
New do_sql.php
I've rewritten my do_sql.php
code to work with the Pear DB library and refactored everything while I was at it:
<?php require "DB.php"; include("read_config.php"); function sql_doozer($db, $sql, $is_query, $debug){ if($debug == true){ print $sql; } # Set up the reply array (array) $reply; # Get our database connection details from the INI config file (array) $config = read_config($db.".ini"); if($debug == true) { print_r($config); } $conf = $config["connection_parameters"]; # Build the connection URL $db_url = $conf["type"]."://".$conf["user"].":".$conf["passwd"]. "@".$conf["host"]."/".$conf["db"]; if($debug == true){ print $db_url; } # Create our connection $connection = DB::Connect($db_url); if(DB::isError($connection)){ $reply["status"] = false; $reply["message"] = $connection->getMessage(); return($reply); } (array) $reply["rows"]; # Do the query $cursor = $connection->query($sql); if(DB::isError($cursor)){ $reply["status"] = false; $reply["message"] = $cursor->getMessage()." - ".$sql; return($reply); } $count = 0; # If this is an SQL query get the results back if($is_query == true){ $reply["num_of_rows"] = $cursor->numRows(); if(DB::isError($cursor)){ $reply["status"] = false; $reply["message"] = $cursor->getMessage(); return($reply); } while($this_row = $cursor->fetchRow(DB_FETCHMODE_ASSOC)){ if(DB::isError($this_row)){ $reply["status"] = false; $reply["message"] = $this_row->getMessage(); return($reply); } $reply["rows"][$count] = $this_row; $count++; } } if($debug == true){ print_r($reply["rows"]); } $reply["first_row"] = $reply["rows"][0]; $reply["status"] = true; $reply["message"] = "OK"; return($reply); } function is_query($sql){ # Check to see if our SQL is an insert or update statement $sql_list = explode(" ",$sql); if((strtolower($sql_list[0]) == "insert") or (strtolower($sql_list[0]) == "update") or (strtolower($sql_list[0]) == "create") or (strtolower($sql_list[0]) == "alter")){ return(false); } return(true); } function do_sql($db, $sql, $debug){ $is_query = is_query($sql); return(sql_doozer($db, $sql, $is_query, $debug)); } function do_sql_query($db, $sql, $debug){ return(sql_doozer($db, $sql, true, $debug)); } function do_sql_insert($db, $sql, $debug){ return(sql_doozer($db, $sql, false, $debug)); } function do_sql_update($db, $sql, $debug){ return(sql_doozer($db, $sql, false, $debug)); } ?>
Posted by pj at 03:32 PM | Comments (0)
July 31, 2006
Unit tests in PHP
ONLamp.com: Testing PHP Code with PHPUnit
Posted by pj at 10:14 PM
July 26, 2006
Bundle for Apache, PHP and MySQL
Posted by pj at 11:43 AM | Comments (0)
July 04, 2006
We love PHPTAL
PHPTAL :: Template Attribute Language for PHP
Posted by pj at 01:40 PM | Comments (0)
July 01, 2005
Securing DB authentication credentials in PHP
I want to use Windows .ini style files for DB configuration settings in PHP. This is an approach I already use in Python.
Because these files are going to contain usernames and passwords I can't have them in the webserver file system as they would be visible to the web. However, if they aren't where the webserver can see them then PHP won't open them while running in safe mode.
My solution is to use a local .htaccess
file with the following:
<Files ~ "\.ini$">
Order allow,deny
Deny from all
</Files>
Posted by pj at 12:54 PM
April 13, 2005
Merging multiple RSS feeds
Suzanne thought it would be a good idea if we could merge multiple news feeds from BIOME, HS&P and HEALTH-01 for our joint portal page.
Whilst unconvinced of the requirement for such a thing I have come up with the following:
- http://www.ltsn-01.ac.uk/static/merge_feeds.php
To get a text/xml
view of it in your browser use:
- http://www.ltsn-01.ac.uk/static/merge_feeds.php?debug=1
The script is as follows:
- http://www.ltsn-01.ac.uk/static/merge_feeds.txt
Merging multiple RSS feeds into one involves de-duping based on link URLs in items and interleaving items so that they appear next to items of the same age in the final feed.
The script pulls our news feed and the feed from a blog we're hosting and represents them. In theory it can handle as many feeds as you want.
But why? I hear you ask.. Errm.. still not sure? Suzanne?
As a side effect of all this work, I was determined to get the feed to validate on http://feedvalidator.org.
It doesn't like my image references so those are gone from the feed, then it was a matter of getting the right content-type (application/rss+xml
), stripping annoying Windows meta characters from the feed, making sure there are no duplicate URLs, and I've UTF-8 encoded the final output for good measure.
- http://www.ltsn-01.ac.uk/static/strip_ms_chars.txt
Basically all the problems we've had with the LOM XML stuff.
I've done this with the rest of our feeds too and they now validate.
Posted by pj at 04:58 PM
March 23, 2005
PHP4 Installer for Mac OS X
Marc Liyanage - Software - Mac OS X Packages - PHP
Posted by pj at 03:38 PM
February 09, 2005
An iCalendar view of our events database
I've spent today hacking together a PHP script to generate a view of our ltsn01_general.events
table.
http://www.ltsn-01.ac.uk/static/ltsn-01_events.ics.php
I've also written a cron job which uses curl
to get a snapshot of that output into a static .ics
file:
http://www.ltsn-01.ac.uk/static/ltsn-01_events.ics
I've successfully subscribed to this in iCal.
There is also a web view of this calendar here:
http://minnesota.ncl.ac.uk/calendar/
Posted by pj at 04:29 PM
December 10, 2004
Article about PEAR, Smarty and MySQL
ONLamp.com: Three-Tier Development with PHP 5
Posted by pj at 01:31 PM
December 02, 2004
This is quite sick - ZPT in PHP
circle.ch :: PHPTAL - PHP Template Attribute Language
http://phptal.sourceforge.net/
Posted by pj at 09:36 PM
November 24, 2004
Photo metadata
I've finished the cataloguing tool for my photo album and formalised how the RDF is represented for the album, each collection, associated events and event attendees and then person depictions in the images themselves.
This is done within the framework of the CC License and Work model to assign a CC license to everything aswell.
I've also set up an RSS feed of the latest catalogued pictures and then hacked Feed2JS so that it pics up the image thumbnails if they are in the feed:
Paul Hollands - Photo Album - RSS
Posted by pj at 10:14 AM
November 16, 2004
Script to generate just FOAF
I've added a PHP script that generates just my FOAF, as opposed to the FOAF and blog DC.
http://minnesota.ncl.ac.uk/foaf.rdf.php?email=p.j.hollands@ncl.ac.uk
Posted by pj at 05:02 PM
November 11, 2004
Changes to my photo album code
I finally installed my PHP photo album on minnesota with the latest version of PHP which has GD rolled into it. When I finally got the JPEG library compiled into it though, I was getting images with only 256 colours.
I amended the code as follows and now have better image quality than I do with the app running on my iBook with a more aged PHP:
#$img_src=imagecreatefromjpeg('yoursource.jpg'); #$img_dst=imagecreatetruecolor(20,20); #imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, 20, 20, 20, 20); #imagejpeg($img_dst, $g_dstfile, 100); #imagedestroy($img_dst); $original = imagecreatefromjpeg($url); $new = imagecreatetruecolor($width, $height); #$new = imagecreate($width, $height); imagecopyresampled($new, $original, 0,0,0,0, $width, $height, $size[0], $size[1]); #imagecopyresized($new, $original, 0,0,0,0, $width, $height, $size[0], $size[1]); Header("Content-type: image/jpeg"); if(is_null($gamma_off)){ imagegammacorrect($new, 1.0, 1.6); } imagejpeg($new, '', 100); #imagejpeg($new, '', 90); imagedestroy($new); imagedestroy($original);< http://minnesota.ncl.ac.uk/photo_collections.php >
I've also added CC license, DC and FOAF metadata to the scripts. See copyright.rdf.
Posted by pj at 11:40 AM
October 29, 2004
Article about MT and PHP includes
Looking to roll some common PHP into the headers of all my bogs.. This might be useful:
< http://www.elise.com/mt/archives/000484using_php_and_mt_includes.php >
Posted by pj at 05:58 PM
Magpie RSS parser for PHP
< http://magpierss.sourceforge.net/ >
Posted by pj at 03:36 PM