More security/sanitizing fixes
--- a/common.inc.php
+++ b/common.inc.php
@@ -5,7 +5,9 @@
$googleMapsAPIkey="ABQIAAAA95XYXN0cki3Yj_Sb71CFvBTPaLd08ONybQDjcH_VdYtHHLgZvRTw2INzI_m17_IoOUqH3RNNmlTk1Q";
$otpAPIurl = 'http://localhost:8080/opentripplanner-api-webapp/';
$owaSiteID = 'fe5b819fa8c424a99ff0764d955d23f3';
-if (isDebug()) error_reporting(E_ALL ^ E_NOTICE);
+//$debugOkay = Array("session","json","phperror","other");
+$debugOkay = Array("session","json","phperror");
+if (isDebug("phperror")) error_reporting(E_ALL ^ E_NOTICE);
// SELECT array_to_string(array(SELECT REPLACE(name_2006, ',', '\,') as name FROM suburbs order by name), ',')
$suburbs = explode(",","Acton,Ainslie,Amaroo,Aranda,Banks,Barton,Belconnen,Bonner,Bonython,Braddon,Bruce,Calwell,Campbell,Chapman,Charnwood,Chifley,Chisholm,City,Conder,Cook,Curtin,Deakin,Dickson,Downer,Duffy,Dunlop,Evatt,Fadden,Farrer,Fisher,Florey,Flynn,Forrest,Franklin,Fraser,Fyshwick,Garran,Gilmore,Giralang,Gordon,Gowrie,Greenway,Griffith,Gungahlin,Hackett,Hall,Harrison,Hawker,Higgins,Holder,Holt,Hughes,Hume,Isaacs,Isabella Plains,Kaleen,Kambah,Kingston,Latham,Lawson,Lyneham,Lyons,Macarthur,Macgregor,Macquarie,Mawson,McKellar,Melba,Mitchell,Monash,Narrabundah,Ngunnawal,Nicholls,Oaks Estate,O'Connor,O'Malley,Oxley,Page,Palmerston,Parkes,Pearce,Phillip,Pialligo,Red Hill,Reid,Richardson,Rivett,Russell,Scullin,Spence,Stirling,Symonston,Tharwa,Theodore,Torrens,Turner,Wanniassa,Waramanga,Watson,Weetangera,Weston,Yarralumla");
@@ -21,8 +23,8 @@
if (isset($_REQUEST['geolocate'])) {
$geocoded = false;
if (isset($_REQUEST['lat']) && isset($_REQUEST['lon'])) {
- $_SESSION['lat'] = $_REQUEST['lat'];
- $_SESSION['lon'] = $_REQUEST['lon'];
+ $_SESSION['lat'] = filter_var($_REQUEST['lat'],FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
+ $_SESSION['lon'] = filter_var($_REQUEST['lon'],FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
} else {
$contents = geocode(filter_var($_REQUEST['geolocate'],FILTER_SANITIZE_URL),true);
if (isset($contents[0]->centroid)) {
@@ -53,9 +55,10 @@
}
}
debug(print_r($_SESSION,true));
-function isDebug()
-{
- return $_SERVER['SERVER_NAME'] == "10.0.1.154" || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1" || !$_SERVER['SERVER_NAME'];
+function isDebug($debugReason = "other")
+{
+ global $debugOkay;
+ return in_array($debugReason,$debugOkay,false) && $_SERVER['SERVER_NAME'] == "10.0.1.154" || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1" || !$_SERVER['SERVER_NAME'];
}
function isMetricsOn()
@@ -63,8 +66,8 @@
return !isDebug();
}
-function debug($msg) {
- if (isDebug()) echo "\n<!-- ".date(DATE_RFC822)."\n $msg -->\n";
+function debug($msg, $debugReason = "other") {
+ if (isDebug($debugReason)) echo "\n<!-- ".date(DATE_RFC822)."\n $msg -->\n";
}
function isFastDevice() {
$ua = $_SERVER['HTTP_USER_AGENT'];
@@ -243,7 +246,15 @@
return $f;
}
-function staticmap($mapPoints, $zoom = 0, $markerImage = "iconb")
+function curPageURL() {
+$isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on");
+$port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443")));
+$port = ($port) ? ':'.$_SERVER["SERVER_PORT"] : '';
+$url = ($isHTTPS ? 'https://' : 'http://').$_SERVER["SERVER_NAME"].$port.dirname($_SERVER['PHP_SELF'])."/";
+return $url;
+}
+
+function staticmap($mapPoints, $zoom = 0, $markerImage = "iconb", $collapsible = true)
{
$width = 300;
$height = 300;
@@ -267,7 +278,7 @@
if (sizeof($mapPoints) === 1) {
if ($zoom == 0) $zoom = 14;
$markers .= "{$mapPoints[0][0]},{$mapPoints[0][1]},$markerimage";
- $center = "{$mapPoints[0][0]},{$mapPoints[0][1]}";
+ $center = "{$mapPoints[0][0]},{$mapPoints[0][1]}";
} else {
foreach ($mapPoints as $index => $mapPoint) {
$markers .= $mapPoint[0].",".$mapPoint[1].",".$markerImage.($index+1);
@@ -289,9 +300,9 @@
$center = $totalLat/sizeof($mapPoints).",".$totalLon/sizeof($mapPoints);
}
$output = "";
- if(basename($_SERVER['PHP_SELF']) != "tripPlanner.php") $output .= '<div data-role="collapsible" data-collapsed="true"><h3>Open Map...</h3>';
- $output .= '<center><img src="staticmaplite/staticmap.php?center='.$center.'&zoom='.$zoom.'&size='.$width.'x'.$height.'&maptype=mapnik&markers='.$markers.'" width='.$width.' height='.$height.'></center>';
- if(basename($_SERVER['PHP_SELF']) != "tripPlanner.php") $output .= '</div>';
+ if ($collapsible) $output .= '<div data-role="collapsible" data-collapsed="true"><h3>Open Map...</h3>';
+ $output .= '<center><img src="'.curPageURL().'staticmaplite/staticmap.php?center='.$center.'&zoom='.$zoom.'&size='.$width.'x'.$height.'&maptype=mapnik&markers='.$markers.'" width='.$width.' height='.$height.'></center>';
+ if ($collapsible) $output .= '</div>';
return $output;
}
@@ -497,5 +508,7 @@
</form>
</div></div>';
}
+
+
?>
--- a/layar_api.php
+++ b/layar_api.php
@@ -6,10 +6,14 @@
$max_page = 10;
$max_results = 50;
-$page_start = 0+$_REQUEST['pageKey'];
-$page_end = $max_page+$_REQUEST['pageKey'];
+$page_start = 0+filter_var($_REQUEST['pageKey'],FILTER_SANITIZE_NUMBER_INT);
+$page_end = $max_page+filter_var($_REQUEST['pageKey'],FILTER_SANITIZE_NUMBER_INT);
-$url = $APIurl."/json/neareststops?lat={$_REQUEST['lat']}&lon={$_REQUEST['lon']}&limit=50";
+$lat = filter_var($_REQUEST['lat'],FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
+$lon = filter_var($_REQUEST['lon'],FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
+if (isset($_REQUEST['radius'])) $radius = filter_var($_REQUEST['radius'],FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
+
+$url = $APIurl."/json/neareststops?lat=$lat&lon=$lon&limit=50";
$contents = json_decode(getPage($url));
debug(print_r($contents,true));
$stopNum = 0;
@@ -24,7 +28,7 @@
$hotspot['lat'] = floor($row[2]*1000000);
$hotspot['lon'] = floor($row[3]*1000000);
$hotspot['distance'] = distance($row[2], $row[3], $_REQUEST['lat'], $_REQUEST['lon']);
- if (!isset($_REQUEST['radius']) || $hotspot['distance'] < $_REQUEST['radius']) {
+ if (!isset($_REQUEST['radius']) || $hotspot['distance'] < $radius) {
$hotspot['actions'] = Array(Array("label" => 'View more trips/information', 'uri' => 'http://bus.lambdacomplex.org/'.'stop.php?stopid='.$row[0]));
$url = $APIurl."/json/stoptrips?stop=".$row[0]."&time=".midnight_seconds()."&service_period=".service_period()."&limit=4&time_range=".str(90*60);
$trips = json_decode(getPage($url));
--- a/schedule_viewer.py
+++ b/schedule_viewer.py
@@ -421,6 +421,18 @@
if s.stop_id.lower() == query:
return StopToTuple(s)
return []
+ def handle_json_GET_stoproutes(self, params):
+ """Given a stop_id return all routes to visit the stop."""
+ schedule = self.server.schedule
+ stop = schedule.GetStop(params.get('stop', None))
+ service_period = params.get('service_period', None)
+ trips = stop.GetTrips(schedule)
+ result = {}
+ for trip in trips:
+ route = schedule.GetRoute(trip.route_id)
+ if not trip.route_id in result:
+ result[trip.route_id] = (route.route_id, route.route_short_name, route.route_long_name, trip.trip_id)
+ return result
def handle_json_GET_stopalltrips(self, params):
"""Given a stop_id return all trips to visit the stop."""
--- /dev/null
+++ b/stop.pdf.php
@@ -1,1 +1,186 @@
+<?php
+include('common.inc.php');
+$stopid = filter_var($_REQUEST['stopid'],FILTER_SANITIZE_NUMBER_INT);
+$url = $APIurl."/json/stop?stop_id=".$stopid;
+$stop = json_decode(getPage($url));
+$html .= '<div data-role="content" class="ui-content" role="main"><p>'.staticmap(Array(0 => Array($stop[2],$stop[3])), 0,"iconb", false).'</p>';
+$html .= ' <ul data-role="listview" data-inset="true">';
+$url = $APIurl."/json/stoptrips?stop=".$stopid."&time=".midnight_seconds()."&service_period=".service_period();
+$trips = json_decode(getPage($url));
+debug(print_r($trips,true));
+foreach ($trips as $row)
+{
+$html .= '<li>';
+$html .= '<h3><a href="trip.php?stopid='.$stopid.'&tripid='.$row[1][0].'">'.$row[1][1];
+if (isFastDevice()) {
+ $viaPoints = viaPointNames($row[1][0],$stopid);
+ if ($viaPoints != "") $html .= '<br><small>Via: '.$viaPoints.'</small> </a></h3>';
+}
+$html .= '<p class="ui-li-aside"><strong>'.midnight_seconds_to_time($row[0]).'</strong></p>';
+$html .= '</li>';
+}
+if (sizeof($trips) == 0) $html .= "<li> <center>No trips in the near future.</center> </li>";
+$html .= '</ul></div>';
+require_once('tcpdf/config/lang/eng.php');
+require_once('tcpdf/tcpdf.php');
+
+// create new PDF document
+class Custom_TCPDF extends TCPDF {
+ var $QRCodeURL;
+
+ function set_QRCodeURL ($url) {
+ $this->QRCodeURL = $url;
+ }
+
+/**
+ * This method is used to render the page header.
+ * It is automatically called by AddPage() and could be overwritten in your own inherited class.
+ * @public
+ */
+ public function Header() {
+ if ($this->header_xobjid < 0) {
+ // start a new XObject Template
+ $this->header_xobjid = $this->startTemplate($this->w, $this->tMargin+10);
+ $headerfont = $this->getHeaderFont();
+ $headerdata = $this->getHeaderData();
+ $this->y = $this->header_margin;
+ if ($this->rtl) {
+ $this->x = $this->w - $this->original_rMargin;
+ } else {
+ $this->x = $this->original_lMargin-10;
+ }
+ if (isset($this->QRCodeURL)) {
+// QRCODE,H : QR-CODE Best error correction
+$style = array(
+ 'border' => 1,
+ 'padding' => 0,
+ 'fgcolor' => array(0,0,0),
+ 'bgcolor' => false, //array(255,255,255)
+ 'module_width' => 1, // width of a single module in points
+ 'module_height' => 1 // height of a single module in points
+);
+$this->write2DBarcode($this->QRCodeURL, 'QRCODE,H', '', '', 25, 25, $style, 'T');
+$imgy = 50+20;
+ } elseif (($headerdata['logo']) AND ($headerdata['logo'] != K_BLANK_IMAGE)) {
+ $imgtype = $this->getImageFileType(K_PATH_IMAGES.$headerdata['logo']);
+ if (($imgtype == 'eps') OR ($imgtype == 'ai')) {
+ $this->ImageEps(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
+ } elseif ($imgtype == 'svg') {
+ $this->ImageSVG(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
+ } else {
+ $this->Image(K_PATH_IMAGES.$headerdata['logo'], '', '', $headerdata['logo_width']);
+ }
+ $imgy = $this->getImageRBY();
+ } else {
+ $imgy = $this->y;
+ }
+ $cell_height = round(($this->cell_height_ratio * $headerfont[2]) / $this->k, 2);
+ // set starting margin for text data cell
+ if ($this->getRTL()) {
+ $header_x = $this->original_rMargin + ($headerdata['logo_width'] * 1.1);
+ } else {
+ $header_x = $this->original_lMargin + ($headerdata['logo_width'] * 1.1);
+ }
+ $cw = $this->w - $this->original_lMargin - $this->original_rMargin - ($headerdata['logo_width'] * 1.1);
+ $this->SetTextColor(0, 0, 0);
+ // header title
+ $this->SetFont($headerfont[0], 'B', $headerfont[2] + 1);
+ $this->SetX($header_x);
+ $this->Cell($cw, $cell_height, $headerdata['title'], 0, 1, '', 0, '', 0);
+ // header string
+ $this->SetFont($headerfont[0], $headerfont[1], $headerfont[2]);
+ $this->SetX($header_x);
+ $this->MultiCell($cw, $cell_height, $headerdata['string'], 0, '', 0, 1, '', '', true, 0, false);
+ // print an ending header line
+ //$this->SetLineStyle(array('width' => 0.85 / $this->k, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
+ //$this->SetY((2.835 / $this->k) + max($imgy, $this->y));
+ if ($this->rtl) {
+ $this->SetX($this->original_rMargin);
+ } else {
+ $this->SetX($this->original_lMargin);
+ }
+ //$this->Cell(($this->w - $this->original_lMargin - $this->original_rMargin), 0, '', 'T', 0, 'C');
+ $this->endTemplate();
+ }
+ // print header template
+ $x = 0;
+ $dx = 0;
+ if ($this->booklet AND (($this->page % 2) == 0)) {
+ // adjust margins for booklet mode
+ $dx = ($this->original_lMargin - $this->original_rMargin);
+ }
+ if ($this->rtl) {
+ $x = $this->w + $dx;
+ } else {
+ $x = 0 + $dx;
+ }
+ $this->printTemplate($this->header_xobjid, $x, 0, 0, 0, '', '', false);
+ }
+
+
+}
+$pdf = new Custom_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
+
+// set document information
+$pdf->SetCreator(PDF_CREATOR);
+$pdf->SetAuthor('bus.lambdacomplex.org');
+$pdf->SetTitle($stop[1]);
+
+// set default header data
+$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $stop[1] . " Timetable", "Some description of customization like Weekdays, 9am-10am");
+$pdf->set_QRCodeURL(curPageURL()."stop.php?stopid=".$_REQUEST['stopid']);
+
+// set header and footer fonts
+$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
+$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
+
+// set default monospaced font
+$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
+
+//set margins
+$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
+$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
+$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
+
+//set auto page breaks
+$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
+
+//set image scale factor
+$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
+
+//set some language-dependent strings
+$pdf->setLanguageArray($l);
+
+// ---------------------------------------------------------
+
+// set default font subsetting mode
+$pdf->setFontSubsetting(true);
+
+// Set font
+// dejavusans is a UTF-8 Unicode font, if you only need to
+// print standard ASCII chars, you can use core fonts like
+// helvetica or times to reduce file size.
+$pdf->SetFont('helvetica', '', 14, '', true);
+
+// Add a page
+// This method has several options, check the source code documentation for more information.
+$pdf->AddPage();
+
+
+// Print text using writeHTMLCell()
+$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
+
+
+
+// ---------------------------------------------------------
+
+// Close and output PDF document
+// This method has several options, check the source code documentation for more information.
+$pdf->Output('example_001.pdf', 'I');
+
+//============================================================+
+// END OF FILE
+//============================================================+
+?>
+
--- a/stop.php
+++ b/stop.php
@@ -1,6 +1,7 @@
<?php
include('common.inc.php');
-$url = $APIurl."/json/stop?stop_id=".$_REQUEST['stopid'];
+$stopid = filter_var($_REQUEST['stopid'],FILTER_SANITIZE_NUMBER_INT);
+$url = $APIurl."/json/stop?stop_id=".$stopid;
$stop = json_decode(getPage($url));
include_header($stop[1],"stop");
@@ -14,22 +15,22 @@
// Set the Event Type, in this case a "video_play"
$event->setEventType('view_stop');
// Set a property
-$event->set('stop_id',$_REQUEST['stopid']);
+$event->set('stop_id',$stopid);
// Track the event
$owa->trackEvent($event);
}
timePlaceSettings();
echo '<div data-role="content" class="ui-content" role="main"><p>'.staticmap(Array(0 => Array($stop[2],$stop[3]))).'</p>';
echo ' <ul data-role="listview" data-inset="true">';
-$url = $APIurl."/json/stoptrips?stop=".$_REQUEST['stopid']."&time=".midnight_seconds()."&service_period=".service_period();
+$url = $APIurl."/json/stoptrips?stop=".$stopid."&time=".midnight_seconds()."&service_period=".service_period();
$trips = json_decode(getPage($url));
debug(print_r($trips,true));
foreach ($trips as $row)
{
echo '<li>';
-echo '<h3><a href="trip.php?stopid='.$_REQUEST['stopid'].'&tripid='.$row[1][0].'">'.$row[1][1];
+echo '<h3><a href="trip.php?stopid='.$stopid.'&tripid='.$row[1][0].'">'.$row[1][1];
if (isFastDevice()) {
- $viaPoints = viaPointNames($row[1][0],$_REQUEST['stopid']);
+ $viaPoints = viaPointNames($row[1][0],$stopid);
if ($viaPoints != "") echo '<br><small>Via: '.$viaPoints.'</small> </a></h3>';
}
echo '<p class="ui-li-aside"><strong>'.midnight_seconds_to_time($row[0]).'</strong></p>';
--- a/stopList.php
+++ b/stopList.php
@@ -36,8 +36,9 @@
navbar();
timePlaceSettings(true);
} else if ($_REQUEST['suburb']) {
- $url = $APIurl."/json/stopzonesearch?q=".filter_var($_REQUEST['suburb'], FILTER_SANITIZE_STRING);
-include_header("Stops in ".ucwords(filter_var($_REQUEST['suburb'], FILTER_SANITIZE_STRING)),"stopList");
+ $suburb = filter_var($_REQUEST['suburb'], FILTER_SANITIZE_STRING);
+ $url = $APIurl."/json/stopzonesearch?q=".$suburb;
+include_header("Stops in ".ucwords($suburb),"stopList");
if (isMetricsOn()) {
// Create a new Instance of the tracker
$owa = new owa_php($config);
@@ -48,7 +49,7 @@
// Set the Event Type, in this case a "video_play"
$event->setEventType('view_stop_list_suburb');
// Set a property
-$event->set('stop_list_suburb',$_REQUEST['suburb']);
+$event->set('stop_list_suburb',$suburb);
// Track the event
$owa->trackEvent($event);
}
--- /dev/null
+++ b/tcpdf/2dbarcodes.php
@@ -1,1 +1,173 @@
+<?php
+//============================================================+
+// File name : 2dbarcodes.php
+// Version : 1.0.007
+// Begin : 2009-04-07
+// Last Update : 2010-12-16
+// Author : Nicola Asuni - Tecnick.com S.r.l - Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
+// License : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
+// -------------------------------------------------------------------
+// Copyright (C) 2009-2010 Nicola Asuni - Tecnick.com S.r.l.
+//
+// This file is part of TCPDF software library.
+//
+// TCPDF is free software: you can redistribute it and/or modify it
+// under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// TCPDF is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+// See the GNU Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with TCPDF. If not, see <http://www.gnu.org/licenses/>.
+//
+// See LICENSE.TXT file for more information.
+// -------------------------------------------------------------------
+//
+// Description : PHP class to creates array representations for
+// 2D barcodes to be used with TCPDF.
+//
+//============================================================+
+/**
+ * @file
+ * PHP class to creates array representations for 2D barcodes to be used with TCPDF.
+ * @package com.tecnick.tcpdf
+ * @author Nicola Asuni
+ * @version 1.0.007
+ */
+
+/**
+ * @class TCPDF2DBarcode
+ * PHP class to creates array representations for 2D barcodes to be used with TCPDF (http://www.tcpdf.org).
+ * @package com.tecnick.tcpdf
+ * @version 1.0.007
+ * @author Nicola Asuni
+ */
+class TCPDF2DBarcode {
+
+ /**
+ * Array representation of barcode.
+ * @protected
+ */
+ protected $barcode_array = false;
+
+ /**
+ * This is the class constructor.
+ * Return an array representations for 2D barcodes:<ul>
+ * <li>$arrcode['code'] code to be printed on text label</li>
+ * <li>$arrcode['num_rows'] required number of rows</li>
+ * <li>$arrcode['num_cols'] required number of columns</li>
+ * <li>$arrcode['bcode'][$r][$c] value of the cell is $r row and $c column (0 = transparent, 1 = black)</li></ul>
+ * @param $code (string) code to print
+ * @param $type (string) type of barcode: <ul><li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>QRCODE : QR-CODE Low error correction</li><li>QRCODE,L : QR-CODE Low error correction</li><li>QRCODE,M : QR-CODE Medium error correction</li><li>QRCODE,Q : QR-CODE Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li><li>PDF417 : PDF417 (ISO/IEC 15438:2006)</li><li>PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".</li></ul>
+ */
+ public function __construct($code, $type) {
+ $this->setBarcode($code, $type);
+ }
+
+ /**
+ * Return an array representations of barcode.
+ * @return array
+ */
+ public function getBarcodeArray() {
+ return $this->barcode_array;
+ }
+
+ /**
+ * Set the barcode.
+ * @param $code (string) code to print
+ * @param $type (string) type of barcode: <ul><li>RAW: raw mode - comma-separad list of array rows</li><li>RAW2: raw mode - array rows are surrounded by square parenthesis.</li><li>QRCODE : QR-CODE Low error correction</li><li>QRCODE,L : QR-CODE Low error correction</li><li>QRCODE,M : QR-CODE Medium error correction</li><li>QRCODE,Q : QR-CODE Better error correction</li><li>QRCODE,H : QR-CODE Best error correction</li><li>PDF417 : PDF417 (ISO/IEC 15438:2006)</li><li>PDF417,a,e,t,s,f,o0,o1,o2,o3,o4,o5,o6 : PDF417 with parameters: a = aspect ratio (width/height); e = error correction level (0-8); t = total number of macro segments; s = macro segment index (0-99998); f = file ID; o0 = File Name (text); o1 = Segment Count (numeric); o2 = Time Stamp (numeric); o3 = Sender (text); o4 = Addressee (text); o5 = File Size (numeric); o6 = Checksum (numeric). NOTES: Parameters t, s and f are required for a Macro Control Block, all other parametrs are optional. To use a comma character ',' on text options, replace it with the character 255: "\xff".</li></ul>
+ * @return array
+ */
+ public function setBarcode($code, $type) {
+ $mode = explode(',', $type);
+ $qrtype = strtoupper($mode[0]);
+ switch ($qrtype) {
+ case 'QRCODE': { // QR-CODE
+ require_once(dirname(__FILE__).'/qrcode.php');
+ if (!isset($mode[1]) OR (!in_array($mode[1],array('L','M','Q','H')))) {
+ $mode[1] = 'L'; // Ddefault: Low error correction
+ }
+ $qrcode = new QRcode($code, strtoupper($mode[1]));
+ $this->barcode_array = $qrcode->getBarcodeArray();
+ break;
+ }
+ case 'PDF417': { // PDF417 (ISO/IEC 15438:2006)
+ require_once(dirname(__FILE__).'/pdf417.php');
+ if (!isset($mode[1]) OR ($mode[1] === '')) {
+ $aspectratio = 2; // default aspect ratio (width / height)
+ } else {
+ $aspectratio = floatval($mode[1]);
+ }
+ if (!isset($mode[2]) OR ($mode[2] === '')) {
+ $ecl = -1; // default error correction level (auto)
+ } else {
+ $ecl = intval($mode[2]);
+ }
+ // set macro block
+ $macro = array();
+ if (isset($mode[3]) AND ($mode[3] !== '') AND isset($mode[4]) AND ($mode[4] !== '') AND isset($mode[5]) AND ($mode[5] !== '')) {
+ $macro['segment_total'] = intval($mode[3]);
+ $macro['segment_index'] = intval($mode[4]);
+ $macro['file_id'] = strtr($mode[5], "\xff", ',');
+ for ($i = 0; $i < 7; ++$i) {
+ $o = $i + 6;
+ if (isset($mode[$o]) AND ($mode[$o] !== '')) {
+ // add option
+ $macro['option_'.$i] = strtr($mode[$o], "\xff", ',');
+ }
+ }
+ }
+ $qrcode = new PDF417($code, $ecl, $aspectratio, $macro);
+ $this->barcode_array = $qrcode->getBarcodeArray();
+ break;
+ }
+ case 'RAW':
+ case 'RAW2': { // RAW MODE
+ // remove spaces
+ $code = preg_replace('/[\s]*/si', '', $code);
+ if (strlen($code) < 3) {
+ break;
+ }
+ if ($qrtype == 'RAW') {
+ // comma-separated rows
+ $rows = explode(',', $code);
+ } else { // RAW2
+ // rows enclosed in square parentheses
+ $code = substr($code, 1, -1);
+ $rows = explode('][', $code);
+ }
+ $this->barcode_array['num_rows'] = count($rows);
+ $this->barcode_array['num_cols'] = strlen($rows[0]);
+ $this->barcode_array['bcode'] = array();
+ foreach ($rows as $r) {
+ $this->barcode_array['bcode'][] = str_split($r, 1);
+ }
+ break;
+ }
+ case 'TEST': { // TEST MODE
+ $this->barcode_array['num_rows'] = 5;
+ $this->barcode_array['num_cols'] = 15;
+ $this->barcode_array['bcode'] = array(
+ array(1,1,1,0,1,1,1,0,1,1,1,0,1,1,1),
+ array(0,1,0,0,1,0,0,0,1,0,0,0,0,1,0),
+ array(0,1,0,0,1,1,0,0,1,1,1,0,0,1,0),
+ array(0,1,0,0,1,0,0,0,0,0,1,0,0,1,0),
+ array(0,1,0,0,1,1,1,0,1,1,1,0,0,1,0));
+ break;
+ }
+ default: {
+ $this->barcode_array = false;
+ }
+ }
+ }
+} // end of class
+
+//============================================================+
+// END OF FILE
+//============================================================+
+
--- /dev/null
+++ b/tcpdf/CHANGELOG.TXT
@@ -1,1 +1,1957 @@
-
+5.9.059 (2011-02-27)
+ - Default Header() method was improved to reduce document size.
+
+5.9.058 (2011-02-25)
+ - Image() method was improved to cache images with transparency layers (thanks to Korneliusz Jarzębski for reporting this problem).
+
+5.9.057 (2011-02-24)
+ - A problem with image caching system was fixed (thanks to Korneliusz Jarzębski for reporting this problem).
+
+5.9.056 (2011-02-22)
+ - A bug on fixHTMLCode() method was fixed.
+ - Automatic line break for HTML was fixed.
+
+5.9.055 (2011-02-17)
+ - Another bug related to HTML table page break was fixed.
+
+5.9.054 (2011-02-16)
+ - A bug related to HTML table page break was fixed.
+
+5.9.053 (2011-02-16)
+ - Support for HTMl attribute display="none" was added.
+
+5.9.052 (2011-02-15)
+ - A bug related to HTML automatic newlines was fixed.
+
+5.9.051 (2011-02-12)
+ - "Commas at beginning of new lines" problem was fixed.
+
+5.9.050 (2011-02-11)
+ - Bug #3177606 "SVG Bar chart error" was fixed.
+
+5.9.049 (2011-02-03)
+ - Bug #3170777 "TCPDF creates a new page after a single line in writeHTML" was fixed.
+
+5.9.048 (2011-02-02)
+ - No changes. Just released to override previous release that was not uploaded correctly.
+
+5.9.047 (2011-01-28)
+ - Bug #3167115 "PDF error in <table> (example 48)" was fixed (was introduced in 5.8.046).
+
+5.9.046 (2011-01-18)
+ - PDF view/print layers are now automatically turned off if not used (see setVisibility() method).
+
+5.9.045 (2011-01-17)
+ - HTML list support were improved.
+
+5.9.044 (2011-01-15)
+ - Bug #3158422 "writeHTMLCell Loop" was fixed.
+ - Some HTML image alignment problems were fixed.
+
+5.9.043 (2011-01-14)
+ - Bug #3158178 "PHP Notice" was fixed.
+ - Bug #3158193 "Endless loop in writeHTML" was fixed.
+ - Bug #3157764 "SVG Pie chart incorrectly rendered2".
+
+5.9.042 (2011-01-14)
+ - Some problems of the PHP4 version were fixed.
+
+5.9.041 (2011-01-13)
+ - A problem with SVG elliptical arc path was fixed (ref. bug #3156574).
+ - A problem related to font weight on HTML table headers was fixed.
+
+5.9.040 (2011-01-12)
+ - A bug related to empty pages after table was fixed.
+
+5.9.039 (2011-01-12)
+ - Bug item #3155759 "openssl_random_pseudo_bytes() slow under Windows" was fixed.
+
+5.9.038 (2011-01-11)
+ - Minor bugs were fixed.
+
+5.9.037 (2011-01-09)
+ - An alignment problem for HTML texts was fixed.
+
+5.9.036 (2011-01-07)
+ - A bug related to HTML tables on header was fixed.
+
+5.9.035 (2011-01-03)
+ - A problem related to HTML table border alignment was fixed.
+ - Bug #2996366 "FastCGI and Header Problems" was fixed.
+
+5.9.034 (2010-12-19)
+ - DejaVu and GNU Free fonts were updated.
+
+5.9.033 (2010-12-18)
+ - Source code documetnation was improved.
+
+5.9.032 (2010-12-18)
+ - Default font stretching and spacing values are now inherited by HTML methods.
+
+5.9.031 (2010-12-16)
+ - Source code documentation errors were fixed.
+
+5.9.030 (2010-12-16)
+ - Several source code documentation errors were fixed.
+ - Source code style was changed for Doxygen.
+ - Source code documentation was moved online to http://www.tcpdf.org
+
+5.9.029 (2010-12-04)
+ - The $fitbox parameter on Image() method was extended to specify image alignment inside the box (check the example n. 9).
+
+5.9.028 (2010-12-03)
+ - Font utils makefont.php and makeallttffonts.php were updated.
+
+5.9.027 (2010-12-01)
+ - Spot Colors are now better integrated with HTML mode.
+ - Method SetDocInfoUnicode() was added to turn on/off Unicode mode for document information dictionary (meta tags) - check the example n. 19.
+
+5.9.026 (2010-12-01)
+ - A problem with mixed text directions on HTML was fixed.
+
+5.9.025 (2010-12-01)
+ - The AddSpotColor() now automatically fills the spotcolor array (defined on spotcolors.php file).
+
+5.9.024 (2010-11-30)
+ - Bug item #3123612 "SVG not use gradientTransform in percentage mode" was fixed.
+
+5.9.023 (2010-11-25)
+ - A potential bug on SVG transcoder was fixed.
+
+5.9.022 (2010-11-21)
+ - Method ImageEPS includes support for EPS/AI Spot colors.
+ - Method ImageEPS includes a new parameter $fixoutvals to remove values outside the bounding box.
+
+5.9.021 (2010-11-20)
+ - Support for custom bullet points images was added (check the example n.6)
+ - Examples n. 6 and 61 were update (check the comments inside).
+
+5.9.020 (2010-11-19)
+ - A problem related to additional page when using multicolumn mode was fixed.
+
+5.9.019 (2010-11-19)
+ - An SVG bug was fixed.