Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed page title and content issue #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 44 additions & 23 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@
*/
function site_name()
{
echo config('name');
echo config('name');
}

/**
* Displays site url provided in config.
*/
function site_url()
{
echo config('site_url');
echo config('site_url');
}

/**
* Displays site version.
*/
function site_version()
{
echo config('version');
echo config('version');
}

/**
* Website navigation.
*/
function nav_menu($sep = ' | ')
{
$nav_menu = '';
$nav_items = config('nav_menu');
foreach ($nav_items as $uri => $name) {
$query_string = str_replace('page=', '', $_SERVER['QUERY_STRING'] ?? '');
$class = $query_string == $uri ? ' active' : '';
$url = config('site_url') . '/' . (config('pretty_uri') || $uri == '' ? '' : '?page=') . $uri;
// Add nav item to list. See the dot in front of equal sign (.=)
$nav_menu .= '<a href="' . $url . '" title="' . $name . '" class="item ' . $class . '">' . $name . '</a>' . $sep;
}

echo trim($nav_menu, $sep);
$nav_menu = '';
$nav_items = config('nav_menu');

foreach ($nav_items as $uri => $name) {
$query_string = str_replace('page=', '', $_SERVER['QUERY_STRING'] ?? '');
$class = $query_string == $uri ? ' active' : '';
$url = config('site_url') . '/' . (config('pretty_uri') || $uri == '' ? '' : '?page=') . $uri;

// Add nav item to list. See the dot in front of equal sign (.=)
$nav_menu .= '<a href="' . $url . '" title="' . $name . '" class="item ' . $class . '">' . $name . '</a>' . $sep;
}

echo trim($nav_menu, $sep);
}

/**
Expand All @@ -51,9 +51,18 @@ function nav_menu($sep = ' | ')
*/
function page_title()
{
if(config('pretty_uri')){
// Parse the URL path to extract the "page" parameter
$url_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$url_parts = explode('/', trim($url_path, '/'));

// The "page" will be the last part of the URL
$page = end($url_parts) !== '' ? end($url_parts) : 'Home';
} else {
$page = isset($_GET['page']) ? htmlspecialchars($_GET['page']) : 'Home';
}

echo ucwords(str_replace('-', ' ', $page));
echo ucwords(str_replace('-', ' ', $page));
}

/**
Expand All @@ -63,20 +72,32 @@ function page_title()
*/
function page_content()
{
if(config('pretty_uri')){
// Parse the URL path to extract the "page" parameter
$url_path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$url_parts = explode('/', trim($url_path, '/'));

// The "page" will be the last part of the URL
$page = end($url_parts) !== '' ? end($url_parts) : 'Home';


} else {
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
$path = getcwd() . '/' . config('content_path') . '/' . $page . '.phtml';
}

$path = getcwd() . '/' . config('content_path') . '/' . $page . '.phtml';

if (! file_exists($path)) {
$path = getcwd() . '/' . config('content_path') . '/404.phtml';
}
if (!file_exists($path)) {
$path = getcwd() . '/' . config('content_path') . '/404.phtml';
}

echo file_get_contents($path);
echo file_get_contents($path);
}

/**
* Starts everything and displays the template.
*/
function init()
{
require config('template_path') . '/template.php';
require config('template_path') . '/template.php';
}