44|--------------------------------------------------------------------------
55| BasicPHP Functions Library
66|--------------------------------------------------------------------------
7- |
8- | These are core functions necessary to run the nano-framework:
97|
10- | 1. url_path() - retrieves the URL path substring separated by '/'
11- | 2. route_rpc() - JSON-RPC v2.0 compatibility layer
12- | 3. route_auto() - automatic routing of URL path to Class and method
13- | 4. route_class() - routes URL path request to Controllers
14- | 5. view() - passes data and renders the View
15- | 6. pdo_conn() - PHP Data Objects (PDO) database connection
16- | 7. api_response() - handles API response
17- | 8. api_call() - handles API call
18- | 9. firewall() - web application firewall
19- | 10. force_ssl() - force application to use SSL
20- | 11. esc() - uses htmlspecialchars() to prevent XSS
21- | 12. csrf_token() - uses sessions to create per request CSRF token
22- | 13. encrypt() - encrypt data using AES-CBC-HMAC
23- | 14. decrypt() - decrypt data using AES-CBC-HMAC
8+ | url_path() - retrieves the URL path substring separated by '/'
9+ | homepage() - render hompage
10+ | error404() - Handle Error 404 - Page Not Found - Invalid URI
11+ | route_rpc() - JSON-RPC v2.0 compatibility layer
12+ | route_auto() - automatic routing of URL path to Class and method
13+ | route_class() - routes URL path request to Controllers
14+ | view() - passes data and renders the View
15+ | pdo_conn() - PHP Data Objects (PDO) database connection
16+ | api_response() - handles API response
17+ | api_call() - handles API call
18+ | firewall() - web application firewall
19+ | force_ssl() - force application to use SSL
20+ | esc() - uses htmlspecialchars() to prevent XSS
21+ | csrf_token() - uses sessions to create per request CSRF token
22+ | encrypt() - encrypt data using AES-CBC-HMAC
23+ | decrypt() - decrypt data using AES-CBC-HMAC
2424|
2525*/
2626
@@ -47,13 +47,45 @@ function url_path($order)
4747
4848}
4949
50+ /**
51+ * Render Homepage
52+ */
53+
54+ function homepage ()
55+ {
56+
57+ if ( empty (url_path (1 )) ) {
58+ list ($ class , $ method ) = explode ('@ ' , HOME_PAGE );
59+ $ object = new $ class ();
60+ return $ object ->$ method ();
61+ }
62+
63+ }
64+
65+ /**
66+ * Handle Error 404 - Page Not Found - Invalid URI
67+ * A valid page has $valid_page set to TRUE.
68+ */
69+
70+ function error404 ()
71+ {
72+
73+ if ( ! isset ($ valid_page ) || $ valid_page !== TRUE ) {
74+ header ($ _SERVER ["SERVER_PROTOCOL " ]." 404 Not Found " );
75+ exit ();
76+ }
77+
78+ }
79+
5080/**
5181 * JSON-RPC v2.0 Compatibility Layer with 'method' member as 'class.method'
5282 */
5383
5484function route_rpc ()
5585{
5686
87+ $ valid_page = TRUE ; // Set page as valid
88+
5789 // Check if HTTP request method is 'POST', if there is POSTed data, and the POSTed data is in JSON format.
5890 if ($ _SERVER ['REQUEST_METHOD ' ] == 'POST ' && file_get_contents ('php://input ' ) !== FALSE && json_decode ( file_get_contents ('php://input ' ), TRUE ) !== NULL ) {
5991
@@ -88,6 +120,8 @@ function route_rpc()
88120function route_auto ()
89121{
90122
123+ $ valid_page = TRUE ; // Set page as valid
124+
91125 if (url_path (1 ) !== FALSE ) { $ class = ucfirst (url_path (1 )) . CONTROLLER_SUFFIX ; }
92126 if (url_path (2 ) !== FALSE ) { $ method = lcfirst (url_path (2 )); } else { $ method = METHOD_DEFAULT ; }
93127
@@ -116,6 +150,8 @@ function route_auto()
116150function route_class ($ http_method , $ path , $ class_method )
117151{
118152
153+ $ valid_page = TRUE ; // Set page as valid
154+
119155 if ($ _SERVER ['REQUEST_METHOD ' ] == $ http_method ) {
120156
121157 // Convert '/' and wilcards (:num) and (:any) to RegEx
0 commit comments