2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2002 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Authors: Alan Knowles <alan@akbkhome.com> |
17 // +----------------------------------------------------------------------+
19 // $Id: Page.php,v 1.5 2003/02/22 01:52:50 alan Exp $
21 // A Base Page Class for use with HTML_Template_Flexy
22 // You could write one of these which used another template engine.
28 * The Base Page class - extend and override the methods to implement your own pages.
33 class HTML_FlexyFramework_JsonPage {
38 /* ---- Variables set by Page loader -------- */
43 * baseURL, that can be prefixed to URL's to ensure that they correctly relate to application
44 * (set by page loader)
50 * rootURL, the base installation directory - can be used to get images directories.
51 * (set by page loader)
58 * the full request string used by the getCacheID().
59 * (set by page loader)
63 var $request; // clean page request for page
65 * Authentication Check method
66 * Override this with a straight return for pages that do not require authentication
69 * a) redirects to login if authenticaiton fails
70 * b) checks to see if a isAdmin method exists on the auth object
71 * if it does see if the user is admin and let them in.
72 * otherwise access denied error is raised
77 * @return none or string redirection to another page.
89 * The default page handler
90 * by default relays to get(), or post() methods depending on the request.
92 * Override this if you do not handle get or post differently.
95 * @param string request, the remainder of the request not handled by the object.
97 * @return none|string none = handled, string = redirect to another page = eg. data/list
101 function start($request,$isRedirect=false,$args=array())
103 if (!$isRedirect && !empty($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "POST") {
104 return $this->post($request,$args);
106 return $this->get($request,$args);
110 * The get page handler
112 * Override this if you want to handle get requests
115 * @param string request, the remainder of the request not handled by the object.
117 * @return none|string none = handled, string = redirect to another page = eg. data/list
120 function get($request)
124 * The post page handler
126 * Override this if you want to handle get requests
129 * @param string request, the remainder of the request not handled by the object.
131 * @return none|string none = handled, string = redirect to another page = eg. data/list
134 function post($request)
139 function jerr($str, $errors=array()) // standard error reporting..
142 if (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE'])) {
143 header('Content-type: text/html');
144 echo "<HTML><HEAD></HEAD><BODY>";
145 echo json_encode(array(
148 'message' => $str, // compate with exeption / loadexception.
150 'errors' => $errors ? $errors : true, // used by forms to flag errors.
151 'authFailure' => !empty($errors['authFailure']),
153 echo "</BODY></HTML>";
156 header('Content-type: application/json');
157 echo json_encode(array(
161 'message' => $str, // compate with exeption / loadexception.
162 'errors' => $errors ? $errors : true, // used by forms to flag errors.
163 'authFailure' => !empty($errors['authFailure']),
172 if (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE'])) {
173 header('Content-type: text/html');
174 echo "<HTML><HEAD></HEAD><BODY>";
175 echo json_encode(array('success'=> true, 'data' => $str));
176 echo "</BODY></HTML>";
179 header('Content-type: application/json');
180 echo json_encode(array('success'=> true, 'data' => $str));
184 function jdata($ar,$total=false, $extra=array())
187 if ($total == false) {
190 $extra= $extra ? $extra : array();
191 header('Content-type: application/json');
192 echo json_enocde(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra);
203 * The master Output layer.
205 * compiles the template
206 * if no caching - just runs the template.
207 * otherwise stores it in the cache.
209 * you dont normally need to override this.
211 * called by the page loader.
219 $this->jerr("Output staged reached - you should output in get/post");