Skip to content

Commit

Permalink
sitemap update
Browse files Browse the repository at this point in the history
  • Loading branch information
khembikram committed Apr 20, 2024
1 parent 03e4ce6 commit e7a2b6e
Show file tree
Hide file tree
Showing 16 changed files with 2,702 additions and 76 deletions.
6 changes: 3 additions & 3 deletions app/Config/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class Database extends Config
public array $default = [
'DSN' => '',
'hostname' => 'localhost',
'username' => '',
'password' => '',
'database' => '',
'username' => 'database_user01',
'password' => 'xyz1245',
'database' => 'bbf',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => false,
Expand Down
3 changes: 3 additions & 0 deletions app/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
* @var RouteCollection $routes
*/
$routes->get('/', 'Home::index');
$routes->get('articles', 'Articles::index');
$routes->get('sitemap', 'Sitemap::index');
$routes->get('web-service/get-social-media-info', 'WebService::get_social_media_info');
21 changes: 21 additions & 0 deletions app/Controllers/Articles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Controllers;

class Articles extends BaseController
{
public function index()
{

// $db = db_connect();

$data = [
["Title" => "One", "content" => "The first"],
["Title" => "Two", "content" => "Some content"]
];

return view("Articles/index", [
"articles" => $data
]);
}
}
11 changes: 11 additions & 0 deletions app/Controllers/Header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php


namespace App\Controllers;

class Header extends BaseController
{
public function index(){
return "Header/index";
}
}
2 changes: 1 addition & 1 deletion app/Controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class Home extends BaseController
{
public function index(): string
{
return view('welcome_message');
return view("Home/index");
}
}
44 changes: 44 additions & 0 deletions app/Controllers/Sitemap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace App\Controllers;

class Sitemap extends BaseController
{
public function index()
{
$db = db_connect();

$sqlQueries = array(
"SELECT CONCAT('https://bestbizfinder.com/broker/', broker_id, '/', company, '/', address) AS url, 'monthly' AS changefreq, 0.8 AS priority FROM broker_details",
);

$xmlContent = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
$xmlContent .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;

foreach ($sqlQueries as $sqlQuery) {
$result = $db->query($sqlQuery);

if ($result->getResult()) {
$rows = $result->getResultArray();

if (count($rows) > 0) {
foreach ($rows as $row) {
$xmlContent .= '<url>' . PHP_EOL;
$xmlContent .= '<loc>' . htmlspecialchars($row['url']) . '</loc>' . PHP_EOL;
$xmlContent .= '<changefreq>' . htmlspecialchars($row['changefreq']) . '</changefreq>' . PHP_EOL;
$xmlContent .= '<priority>' . htmlspecialchars($row['priority']) . '</priority>' . PHP_EOL;
$xmlContent .= '</url>' . PHP_EOL;
}
}
} else {
echo "No results found";
}
}

$xmlContent .= '</urlset>' . PHP_EOL;

header('Content-Type: application/xml');

echo $xmlContent;
}
}
29 changes: 29 additions & 0 deletions app/Controllers/WebService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Controllers;

use CodeIgniter\Controller;

class WebService extends Controller {

protected $config;
public function __construct() {

try {
$this->config = config('Env');
} catch (Exception $e) {
log_message('error', 'Failed to load environment variables: ' . $e->getMessage());
die('An error occurred while retrieving configuration.');
}
}

public function get_social_media_info() {

$facebookUrl = env('FACEBOOK_PAGE_URL', '');
$twitterUrl = env('TWITTER_PAGE_URL', '');

if (empty($facebookUrl) || empty($twitterUrl)) {
die('Social media URLs are not configured.');
}
}
}
14 changes: 14 additions & 0 deletions app/Views/Articles/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?= $this->extend("layouts/defaults") ?>
<?= $this->section("title") ?>Article<?= $this->endSection() ?>

<?= $this->section("content") ?>

<h1>Articles</h1>

<?php foreach ($articles as $article): ?>
<article>
<h2><?= $article["Title"] ?></h2>
<p><?= $article["content"] ?></p>
</article>
<?php endforeach; ?>
<?= $this->endSection() ?>
7 changes: 7 additions & 0 deletions app/Views/Home/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?= $this->extend("layouts/defaults") ?>
<?= $this->section("title") ?>Home<?= $this->endSection() ?>

<?= $this->section("content") ?>
<h1>Welcome</h1>

<?= $this->endSection() ?>
16 changes: 16 additions & 0 deletions app/Views/Sitemap/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?= $this->extend("layouts/defaults") ?>
<?= $this->section("title") ?>Sitemap<?= $this->endSection() ?>

<?= $this->section("content") ?>
<?= '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($urls as $url): ?>
<url>
<loc><?= htmlspecialchars($url['url']) ?></loc>
<changefreq><?= htmlspecialchars($url['changefreq']) ?></changefreq>
<priority><?= htmlspecialchars($url['priority']) ?></priority>
</url>
<?php endforeach; ?>
</urlset>
</pre>
<?= $this->endSection() ?>
7 changes: 7 additions & 0 deletions app/Views/header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?= $title ?></title>
</head>
<body>
12 changes: 12 additions & 0 deletions app/Views/layouts/defaults.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title><?= $this->renderSection("title") ?></title>
</head>
<body>

<?= $this->renderSection("content") ?>

</body>
</html>
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
},
"require": {
"php": "^8.1",
"codeigniter4/framework": "^4.0"
"codeigniter4/framework": "^4.0",
"vlucas/phpdotenv": "^5.6"
},
"require-dev": {
"fakerphp/faker": "^1.9",
Expand Down
Loading

0 comments on commit e7a2b6e

Please sign in to comment.