Skip to content

Commit 3f8baed

Browse files
committed
Add files
1 parent 8fb9dce commit 3f8baed

14 files changed

+215
-2
lines changed

Diff for: .DS_Store

10 KB
Binary file not shown.

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.idea
2+
.php_cs.cache

Diff for: .htaccess

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Options +FollowSymLinks
2+
RewriteEngine On
3+
4+
RewriteCond %{REQUEST_FILENAME} !-d
5+
RewriteCond %{REQUEST_FILENAME} !-f
6+
RewriteRule ^(.*)$ index.php?page=$1 [L]

Diff for: README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
# simple-php-website
2-
A simple and minimal website built with PHP.
1+
# Simple PHP-based website
2+
3+
This project is used in the GitHub documentation to guide users through the process of converting a project written on one language to another language - for example, from PHP to Python.
4+
5+
The repository is derived from the public GitHub repository [banago/simple-php-website](https://github.com/banago/simple-php-website).
6+
7+
## Installation
8+
9+
To generate the website output from this project:
10+
11+
1. Clone the project to your local computer.
12+
1. Install PHP on your computer.
13+
1. In a terminal, navigate to the project folder.
14+
1. Run `php -S localhost:8080`.
15+
1. In a web browser, go to http://localhost:8080.
16+
17+
## License
18+
19+
MIT

Diff for: content/404.phtml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>404 - This page does not exist.</p>

Diff for: content/about-us.phtml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>This is <b>about</b> 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.</p>
2+
<p>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).</p>

Diff for: content/contact.phtml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>This is <b>contact</b> 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.</p>
2+
<p>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).</p>

Diff for: content/home.phtml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>This is <b>home</b> 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.</p>
2+
<p>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).</p>

Diff for: content/products.phtml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<p>This is <b>product</b> 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.</p>
2+
<p>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).</p>

Diff for: includes/config.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* Used to store website configuration information.
5+
*
6+
* @var string or null
7+
*/
8+
function config($key = '')
9+
{
10+
$config = [
11+
'name' => 'Simple PHP Website',
12+
'site_url' => '',
13+
'pretty_uri' => false,
14+
'nav_menu' => [
15+
'' => 'Home',
16+
'about-us' => 'About Us',
17+
'products' => 'Products',
18+
'contact' => 'Contact',
19+
],
20+
'template_path' => 'template',
21+
'content_path' => 'content',
22+
'version' => 'v3.1',
23+
];
24+
25+
return isset($config[$key]) ? $config[$key] : null;
26+
}

Diff for: includes/functions.php

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
3+
/**
4+
* Displays site name.
5+
*/
6+
function site_name()
7+
{
8+
echo config('name');
9+
}
10+
11+
/**
12+
* Displays site url provided in config.
13+
*/
14+
function site_url()
15+
{
16+
echo config('site_url');
17+
}
18+
19+
/**
20+
* Displays site version.
21+
*/
22+
function site_version()
23+
{
24+
echo config('version');
25+
}
26+
27+
/**
28+
* Website navigation.
29+
*/
30+
function nav_menu($sep = ' | ')
31+
{
32+
$nav_menu = '';
33+
$nav_items = config('nav_menu');
34+
35+
foreach ($nav_items as $uri => $name) {
36+
$query_string = str_replace('page=', '', $_SERVER['QUERY_STRING'] ?? '');
37+
$class = $query_string == $uri ? ' active' : '';
38+
$url = config('site_url') . '/' . (config('pretty_uri') || $uri == '' ? '' : '?page=') . $uri;
39+
40+
// Add nav item to list. See the dot in front of equal sign (.=)
41+
$nav_menu .= '<a href="' . $url . '" title="' . $name . '" class="item ' . $class . '">' . $name . '</a>' . $sep;
42+
}
43+
44+
echo trim($nav_menu, $sep);
45+
}
46+
47+
/**
48+
* Displays page title. It takes the data from
49+
* URL, it replaces the hyphens with spaces and
50+
* it capitalizes the words.
51+
*/
52+
function page_title()
53+
{
54+
$page = isset($_GET['page']) ? htmlspecialchars($_GET['page']) : 'Home';
55+
56+
echo ucwords(str_replace('-', ' ', $page));
57+
}
58+
59+
/**
60+
* Displays page content. It takes the data from
61+
* the static pages inside the pages/ directory.
62+
* When not found, display the 404 error page.
63+
*/
64+
function page_content()
65+
{
66+
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
67+
$path = getcwd() . '/' . config('content_path') . '/' . $page . '.phtml';
68+
69+
if (! file_exists($path)) {
70+
$path = getcwd() . '/' . config('content_path') . '/404.phtml';
71+
}
72+
73+
echo file_get_contents($path);
74+
}
75+
76+
/**
77+
* Starts everything and displays the template.
78+
*/
79+
function init()
80+
{
81+
require config('template_path') . '/template.php';
82+
}

Diff for: index.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// Comment these lines to hide errors
4+
error_reporting(E_ALL);
5+
ini_set('display_errors', 1);
6+
7+
require 'includes/config.php';
8+
require 'includes/functions.php';
9+
10+
init();

Diff for: template/style.css

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
.wrap {
3+
padding: 25px;
4+
text-align: center;
5+
box-shadow: 0 4px 25px -4px #9da5ab;
6+
}
7+
article {
8+
padding: 25px 0;
9+
line-height: 150%;
10+
text-align: left;
11+
}
12+
13+
nav .item {
14+
text-decoration: none;
15+
}
16+
nav .active {
17+
border-bottom: 1px solid;
18+
}
19+
20+
@media only screen and (min-width: 768px) {
21+
article {
22+
padding: 40px;
23+
}
24+
.wrap {
25+
max-width: 750px;
26+
margin: 50px auto;
27+
padding: 30px 40px;
28+
}
29+
}
30+

Diff for: template/template.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta http-equiv="x-ua-compatible" content="ie=edge"/>
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
7+
<title><?php page_title(); ?> | <?php site_name(); ?></title>
8+
<link href="<?php site_url(); ?>/template/style.css" rel="stylesheet" type="text/css" />
9+
</head>
10+
<body>
11+
<div class="wrap">
12+
13+
<header>
14+
<h1><?php site_name(); ?></h1>
15+
<nav class="menu">
16+
<?php nav_menu(); ?>
17+
</nav>
18+
</header>
19+
20+
<article>
21+
<h2><?php page_title(); ?></h2>
22+
<?php page_content(); ?>
23+
</article>
24+
25+
<footer>
26+
<small>&copy;<?php echo date('Y'); ?> <?php site_name(); ?>.<br><?php site_version(); ?></small>
27+
</footer>
28+
29+
</div>
30+
</body>
31+
</html>

0 commit comments

Comments
 (0)