Skip to content

Commit e7a2b6e

Browse files
committed
sitemap update
1 parent 03e4ce6 commit e7a2b6e

16 files changed

+2702
-76
lines changed

app/Config/Database.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class Database extends Config
2727
public array $default = [
2828
'DSN' => '',
2929
'hostname' => 'localhost',
30-
'username' => '',
31-
'password' => '',
32-
'database' => '',
30+
'username' => 'database_user01',
31+
'password' => 'xyz1245',
32+
'database' => 'bbf',
3333
'DBDriver' => 'MySQLi',
3434
'DBPrefix' => '',
3535
'pConnect' => false,

app/Config/Routes.php

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
* @var RouteCollection $routes
77
*/
88
$routes->get('/', 'Home::index');
9+
$routes->get('articles', 'Articles::index');
10+
$routes->get('sitemap', 'Sitemap::index');
11+
$routes->get('web-service/get-social-media-info', 'WebService::get_social_media_info');

app/Controllers/Articles.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
class Articles extends BaseController
6+
{
7+
public function index()
8+
{
9+
10+
// $db = db_connect();
11+
12+
$data = [
13+
["Title" => "One", "content" => "The first"],
14+
["Title" => "Two", "content" => "Some content"]
15+
];
16+
17+
return view("Articles/index", [
18+
"articles" => $data
19+
]);
20+
}
21+
}

app/Controllers/Header.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
4+
namespace App\Controllers;
5+
6+
class Header extends BaseController
7+
{
8+
public function index(){
9+
return "Header/index";
10+
}
11+
}

app/Controllers/Home.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ class Home extends BaseController
66
{
77
public function index(): string
88
{
9-
return view('welcome_message');
9+
return view("Home/index");
1010
}
1111
}

app/Controllers/Sitemap.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
class Sitemap extends BaseController
6+
{
7+
public function index()
8+
{
9+
$db = db_connect();
10+
11+
$sqlQueries = array(
12+
"SELECT CONCAT('https://bestbizfinder.com/broker/', broker_id, '/', company, '/', address) AS url, 'monthly' AS changefreq, 0.8 AS priority FROM broker_details",
13+
);
14+
15+
$xmlContent = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
16+
$xmlContent .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
17+
18+
foreach ($sqlQueries as $sqlQuery) {
19+
$result = $db->query($sqlQuery);
20+
21+
if ($result->getResult()) {
22+
$rows = $result->getResultArray();
23+
24+
if (count($rows) > 0) {
25+
foreach ($rows as $row) {
26+
$xmlContent .= '<url>' . PHP_EOL;
27+
$xmlContent .= '<loc>' . htmlspecialchars($row['url']) . '</loc>' . PHP_EOL;
28+
$xmlContent .= '<changefreq>' . htmlspecialchars($row['changefreq']) . '</changefreq>' . PHP_EOL;
29+
$xmlContent .= '<priority>' . htmlspecialchars($row['priority']) . '</priority>' . PHP_EOL;
30+
$xmlContent .= '</url>' . PHP_EOL;
31+
}
32+
}
33+
} else {
34+
echo "No results found";
35+
}
36+
}
37+
38+
$xmlContent .= '</urlset>' . PHP_EOL;
39+
40+
header('Content-Type: application/xml');
41+
42+
echo $xmlContent;
43+
}
44+
}

app/Controllers/WebService.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
use CodeIgniter\Controller;
6+
7+
class WebService extends Controller {
8+
9+
protected $config;
10+
public function __construct() {
11+
12+
try {
13+
$this->config = config('Env');
14+
} catch (Exception $e) {
15+
log_message('error', 'Failed to load environment variables: ' . $e->getMessage());
16+
die('An error occurred while retrieving configuration.');
17+
}
18+
}
19+
20+
public function get_social_media_info() {
21+
22+
$facebookUrl = env('FACEBOOK_PAGE_URL', '');
23+
$twitterUrl = env('TWITTER_PAGE_URL', '');
24+
25+
if (empty($facebookUrl) || empty($twitterUrl)) {
26+
die('Social media URLs are not configured.');
27+
}
28+
}
29+
}

app/Views/Articles/index.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?= $this->extend("layouts/defaults") ?>
2+
<?= $this->section("title") ?>Article<?= $this->endSection() ?>
3+
4+
<?= $this->section("content") ?>
5+
6+
<h1>Articles</h1>
7+
8+
<?php foreach ($articles as $article): ?>
9+
<article>
10+
<h2><?= $article["Title"] ?></h2>
11+
<p><?= $article["content"] ?></p>
12+
</article>
13+
<?php endforeach; ?>
14+
<?= $this->endSection() ?>

app/Views/Home/index.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?= $this->extend("layouts/defaults") ?>
2+
<?= $this->section("title") ?>Home<?= $this->endSection() ?>
3+
4+
<?= $this->section("content") ?>
5+
<h1>Welcome</h1>
6+
7+
<?= $this->endSection() ?>

app/Views/Sitemap/index.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?= $this->extend("layouts/defaults") ?>
2+
<?= $this->section("title") ?>Sitemap<?= $this->endSection() ?>
3+
4+
<?= $this->section("content") ?>
5+
<?= '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
6+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
7+
<?php foreach ($urls as $url): ?>
8+
<url>
9+
<loc><?= htmlspecialchars($url['url']) ?></loc>
10+
<changefreq><?= htmlspecialchars($url['changefreq']) ?></changefreq>
11+
<priority><?= htmlspecialchars($url['priority']) ?></priority>
12+
</url>
13+
<?php endforeach; ?>
14+
</urlset>
15+
</pre>
16+
<?= $this->endSection() ?>

app/Views/header.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title><?= $title ?></title>
6+
</head>
7+
<body>

app/Views/layouts/defaults.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title><?= $this->renderSection("title") ?></title>
6+
</head>
7+
<body>
8+
9+
<?= $this->renderSection("content") ?>
10+
11+
</body>
12+
</html>

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"require": {
1313
"php": "^8.1",
14-
"codeigniter4/framework": "^4.0"
14+
"codeigniter4/framework": "^4.0",
15+
"vlucas/phpdotenv": "^5.6"
1516
},
1617
"require-dev": {
1718
"fakerphp/faker": "^1.9",

0 commit comments

Comments
 (0)