diff --git a/sources/core/src/Http.h b/sources/core/src/Http.h index 1d2f0bb..fd781c7 100644 --- a/sources/core/src/Http.h +++ b/sources/core/src/Http.h @@ -79,15 +79,18 @@ namespace http { data += std::to_string(response.status_code) + " "; data += response.status_message + "\n"; - for (auto &it: response.headers) - data += (it.first + ": " + it.second + "\n"); + bool first = true; + for (auto &it: response.headers) { + if (!first) data += "\n"; + data += (it.first + ": " + it.second); + if (first) first = false; + } data += headers_end_delimiter; + buffer.insert(buffer.end(), data.begin(), data.end()); if (!response.body.empty()) - data.insert(data.end(), response.body.begin(), response.body.end()); - - buffer.insert(buffer.end(), data.begin(), data.end()); + buffer.insert(buffer.end(), response.body.begin(), response.body.end()); } } diff --git a/sources/modules/php/dist/sample/content/404.phtml b/sources/modules/php/dist/sample/content/404.phtml new file mode 100644 index 0000000..70b9ea7 --- /dev/null +++ b/sources/modules/php/dist/sample/content/404.phtml @@ -0,0 +1 @@ +
404 - This page does not exist.
\ No newline at end of file diff --git a/sources/modules/php/dist/sample/content/about-us.phtml b/sources/modules/php/dist/sample/content/about-us.phtml new file mode 100644 index 0000000..a86d130 --- /dev/null +++ b/sources/modules/php/dist/sample/content/about-us.phtml @@ -0,0 +1,2 @@ +This is about page. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
+It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). diff --git a/sources/modules/php/dist/sample/content/contact.phtml b/sources/modules/php/dist/sample/content/contact.phtml new file mode 100644 index 0000000..fa7c350 --- /dev/null +++ b/sources/modules/php/dist/sample/content/contact.phtml @@ -0,0 +1,2 @@ +This is contact page. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
+It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). diff --git a/sources/modules/php/dist/sample/content/home.phtml b/sources/modules/php/dist/sample/content/home.phtml new file mode 100644 index 0000000..6868b92 --- /dev/null +++ b/sources/modules/php/dist/sample/content/home.phtml @@ -0,0 +1,2 @@ +This is home page.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
+It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). diff --git a/sources/modules/php/dist/sample/content/products.phtml b/sources/modules/php/dist/sample/content/products.phtml new file mode 100644 index 0000000..0af9d3d --- /dev/null +++ b/sources/modules/php/dist/sample/content/products.phtml @@ -0,0 +1,2 @@ +This is product page. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
+It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). diff --git a/sources/modules/php/dist/sample/includes/config.php b/sources/modules/php/dist/sample/includes/config.php new file mode 100644 index 0000000..ad25dc8 --- /dev/null +++ b/sources/modules/php/dist/sample/includes/config.php @@ -0,0 +1,26 @@ + 'Simple PHP Website', + 'site_url' => '', + 'pretty_uri' => false, + 'nav_menu' => [ + '' => 'Home', + 'about-us' => 'About Us', + 'products' => 'Products', + 'contact' => 'Contact', + ], + 'template_path' => 'template', + 'content_path' => 'content', + 'version' => 'v3.0', + ]; + + return isset($config[$key]) ? $config[$key] : null; +} diff --git a/sources/modules/php/dist/sample/includes/functions.php b/sources/modules/php/dist/sample/includes/functions.php new file mode 100644 index 0000000..73ee106 --- /dev/null +++ b/sources/modules/php/dist/sample/includes/functions.php @@ -0,0 +1,80 @@ + $name) { + $class = str_replace('page=', '', $_SERVER['QUERY_STRING']) == $uri ? ' active' : ''; + $url = config('site_url') . '/' . (config('pretty_uri') || $uri == '' ? '' : '?page=') . $uri; + + $nav_menu .= '' . $name . '' . $sep; + } + + echo trim($nav_menu, $sep); +} + +/** + * Displays page title. It takes the data from + * URL, it replaces the hyphens with spaces and + * it capitalizes the words. + */ +function page_title() +{ + $page = isset($_GET['page']) ? htmlspecialchars($_GET['page']) : 'Home'; + + echo ucwords(str_replace('-', ' ', $page)); +} + +/** + * Displays page content. It takes the data from + * the static pages inside the pages/ directory. + * When not found, display the 404 error page. + */ +function page_content() +{ + $page = isset($_GET['page']) ? $_GET['page'] : 'home'; + + $path = getcwd() . '/' . config('content_path') . '/' . $page . '.phtml'; + + if (! file_exists($path)) { + $path = getcwd() . '/' . config('content_path') . '/404.phtml'; + } + + echo file_get_contents($path); +} + +/** + * Starts everything and displays the template. + */ +function init() +{ + require config('template_path') . '/template.php'; +} diff --git a/sources/modules/php/dist/sample/index.php b/sources/modules/php/dist/sample/index.php index 248f226..8db9bd7 100644 --- a/sources/modules/php/dist/sample/index.php +++ b/sources/modules/php/dist/sample/index.php @@ -1,4 +1,10 @@ -