Skip to content

Commit

Permalink
#1 добавлен шаблон sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
Ichinya committed Feb 6, 2021
1 parent 78c4a53 commit 7da10b5
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 13 deletions.
22 changes: 18 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
die();
}
$config = require_once('config.inc.php');
$currentVersion = "1.2.0";
$currentVersion = "1.3.0";

spl_autoload_register(function ($class) {
$file = 'libs/'.$class . '.php';
$file = 'libs/' . $class . '.php';
if (is_file($file)) {
/** @noinspection PhpIncludeInspection */
require_once $file;
Expand Down Expand Up @@ -51,14 +51,28 @@
$rssTemplate = isset($_GET['template']) ? $_GET['template'] : $config['defaultTemplate'];
$rss = new cRSS($rssTemplate);

if (isset($_GET['page'])) {
if (isset($_GET['page']) || isset($_GET['template'])) {
// формируем страницу rss
if (empty($_GET['page'])) {
$_GET['page'] = 0;
}
$listPages = $list->getPageList($_GET['page'], $rss->getMaxCount());
$lenta = $rss->generateRSS($listPages);
echo($lenta);
} else {
// формируем список rss
$countPage = ceil($list->countPageDB() / $rss->getMaxCount());

$fileParams = glob("rss_templates/*.default_params.php");
$rssListTemplate = [];
foreach ($fileParams as $fileParam) {
$nameRss = preg_replace(['#rss_templates/#', '#\.default_params.php#'], '', $fileParam);
$currentRss = new cRSS($nameRss);
$rssListTemplate[$nameRss] = [
'rss' => $currentRss,
'maxCount' => $currentRss->getMaxCount()
];
}

ob_start();
include('templates/index.php');
$html = ob_get_contents();
Expand Down
2 changes: 1 addition & 1 deletion libs/cRSS.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct($template)
exit('шаблон не найден');
}
/** @noinspection PhpIncludeInspection */
$this->params = require_once($paramsFile);
$this->params = require($paramsFile);
return true;
}

Expand Down
9 changes: 9 additions & 0 deletions rss_templates/sitemap.default_params.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
return [
// максимальное количество элементов в ленте
'maxCount' => 50000,

// параметры
'changefreq' => 'monthly',
'priority' => '0.8'
];
12 changes: 12 additions & 0 deletions rss_templates/sitemap.item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/** @var array $data */
/** @var cPage $page */
$page = $data['page'];
$params = $data['config'];
?>
<url>
<loc><?= $page->url; ?></loc>
<lastmod><?= date('Y-m-H', strtotime($page->updateAt)); ?></lastmod>
<changefreq><?= $params['changefreq']; ?></changefreq>
<priority><?= $params['priority']; ?></priority>
</url>
7 changes: 7 additions & 0 deletions rss_templates/sitemap.rss.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
/** @var array $data */
$config = $data['config'];
echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php echo implode('', $data['items']); ?>
</urlset>
26 changes: 18 additions & 8 deletions templates/index.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php
/** @var string $currentVersion */
/** @var string $rssTemplate */
/** @var array $rssListTemplate */
/** @var array $config */
/** @var int $countPage */
/** @var cPageList $list */
?>
<!doctype html>
<html lang="ru">
Expand All @@ -12,21 +14,29 @@
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="shortcut icon" href="./templates/favicon.png">
<title>Яндекс Турбо для MediWiki</title>
<title>Яндекс Турбо для MediaWiki</title>
</head>
<body>
<h1>Яндекс Турбо для MediWiki</h1>
<h1>Яндекс Турбо для MediaWiki</h1>
<div>версия <?= $currentVersion; ?></div>

<h2>Список доступных лент</h2>
<ol>
<?php
for ($i = 0; $i < $countPage; $i++) {
$strTemplate = ($config['defaultTemplate'] == $rssTemplate) ? '' : "template={$rssTemplate}&";
$str = "http://{$config['here']}?{$strTemplate}page={$i}";
?>
<li><a href="<?= $str; ?>"><?= $str; ?></a></li>
<?php

foreach ($rssListTemplate as $rssName => $rss) {

$maxCount = ($rssListTemplate[$rssName]['maxCount']);

$countPage = ceil($list->countPageDB() / $maxCount);
for ($i = 0; $i < $countPage; $i++) {
$url['template'] = ($config['defaultTemplate'] == $rssName) ? null : "{$rssName}";
$url['page'] = ($i == 0 && $url['template'] != '') ? null : "{$i}";
$str = "http://{$config['here']}?" . http_build_query($url);
?>
<li><a href="<?= $str; ?>"><?= $str; ?></a></li>
<?php
}
}
?>
</ol>
Expand Down

0 comments on commit 7da10b5

Please sign in to comment.