Skip to content

Commit cce2d0e

Browse files
author
peejeh
committed
Initial import
0 parents  commit cce2d0e

File tree

6 files changed

+820
-0
lines changed

6 files changed

+820
-0
lines changed

html.php

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
/**
4+
* PHP REST SQL HTML renderer class
5+
* This class renders the REST response data as HTML.
6+
*/
7+
class PHPRestSQLRenderer {
8+
9+
/**
10+
* @var PHPRestSQL PHPRestSQL
11+
*/
12+
var $PHPRestSQL;
13+
14+
/**
15+
* Constructor. Takes an output array and calls the appropriate handler.
16+
* @param PHPRestSQL PHPRestSQL
17+
*/
18+
function render($PHPRestSQL) {
19+
$this->PHPRestSQL = $PHPRestSQL;
20+
if (isset($PHPRestSQL->output['database'])) {
21+
$this->database();
22+
} elseif (isset($PHPRestSQL->output['table'])) {
23+
$this->table();
24+
} elseif (isset($PHPRestSQL->output['row'])) {
25+
$this->row();
26+
}
27+
}
28+
29+
/**
30+
* Output the top level table listing.
31+
*/
32+
function database() {
33+
header('Content-Type: text/html');
34+
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">';
35+
echo '<html>';
36+
echo '<head>';
37+
echo '<title>PHP REST SQL : Database "'.htmlspecialchars($this->PHPRestSQL->config['database']['database']).'"</title>';
38+
echo '</head>';
39+
echo '<body>';
40+
echo '<h1>Tables in database "'.htmlspecialchars($this->PHPRestSQL->config['database']['database']).'"</h1>';
41+
echo '<ul>';
42+
foreach ($this->PHPRestSQL->output['database'] as $table) {
43+
echo '<li><a href="'.htmlspecialchars($table['xlink']).'">'.htmlspecialchars($table['value']).'</a></li>';
44+
}
45+
echo '</ul>';
46+
echo '</body>';
47+
echo '</html>';
48+
}
49+
50+
/**
51+
* Output the rows within a table.
52+
*/
53+
function table() {
54+
header('Content-Type: text/html');
55+
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">';
56+
echo '<html>';
57+
echo '<head>';
58+
echo '<title>PHP REST SQL : Table "'.htmlspecialchars($this->PHPRestSQL->table).'"</title>';
59+
echo '</head>';
60+
echo '<body>';
61+
echo '<h1>Records in table "'.htmlspecialchars($this->PHPRestSQL->table).'"</h1>';
62+
echo '<ul>';
63+
foreach ($this->PHPRestSQL->output['table'] as $row) {
64+
echo '<li><a href="'.htmlspecialchars($row['xlink']).'">'.htmlspecialchars($row['value']).'</a></li>';
65+
}
66+
echo '</ul>';
67+
echo '</body>';
68+
echo '</html>';
69+
}
70+
71+
/**
72+
* Output the entry in a table row.
73+
*/
74+
function row() {
75+
header('Content-Type: text/html');
76+
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">';
77+
echo '<html>';
78+
echo '<head>';
79+
echo '<title>PHP REST SQL : Record #'.htmlspecialchars(join('/', $this->PHPRestSQL->uid)).'</title>';
80+
echo '</head>';
81+
echo '<body>';
82+
echo '<h1>Record #'.htmlspecialchars(join('/', $this->PHPRestSQL->uid)).'</h1>';
83+
echo '<table>';
84+
foreach ($this->PHPRestSQL->output['row'] as $field) {
85+
echo '<tr><th>'.htmlspecialchars($field['field']).'</th><td>';
86+
if (isset($field['xlink'])) {
87+
echo '<a href="'.htmlspecialchars($field['xlink']).'">'.htmlspecialchars($field['value']).'</a>';
88+
} else {
89+
echo htmlspecialchars($field['value']);
90+
}
91+
echo '</td></tr>';
92+
}
93+
echo '</table>';
94+
echo '</body>';
95+
echo '</html>';
96+
}
97+
98+
}

index.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
require_once('phprestsql.php');
4+
5+
$PHPRestSQL =& new PHPRestSQL();
6+
$PHPRestSQL->exec();
7+
8+
/*
9+
echo '<pre>';
10+
var_dump($PHPRestSQL->output);
11+
//*/
12+
13+
?>

phprestsql.ini

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[settings]
2+
baseURL = "/PHPRestSQL/?"
3+
4+
[database]
5+
type = "mysql"
6+
server = "localhost"
7+
database = "phprestsql"
8+
;username = "root"
9+
;password = ""
10+
foreignKeyPostfix = "_uid"
11+
12+
[renderers]
13+
text/xml = xml.php
14+
text/plain = plain.php
15+
text/html = html.php

0 commit comments

Comments
 (0)