Skip to content

Commit

Permalink
Merge pull request #4 from Ichinya/feature/3
Browse files Browse the repository at this point in the history
#3 исправлена ошибка
  • Loading branch information
Ichinya authored May 14, 2021
2 parents 1c537fa + fdc1fb6 commit d01951c
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 27 deletions.
11 changes: 7 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
die();
}
$config = require_once('config.inc.php');
$currentVersion = "1.3.0";
$currentVersion = "1.3.1";

spl_autoload_register(function ($class) {
$file = 'libs/' . $class . '.php';
Expand All @@ -14,6 +14,7 @@
}
});

$notify = [];
// формируем список всех страниц
$list = new cPageList($config);
// модуль парсинга страниц
Expand Down Expand Up @@ -43,12 +44,15 @@
cUpdate::sendNotify($config['email']);
}

$list->getPages();
if (false === $list->getPages()) {
$notify['warning'][] = 'Нет доступа к API или в wiki не найдено страниц';
}
// проверяем все страницы
$parse->updateCache($list->listPage);
// заполняем пустые ссылки (при первом запуске формируются в кэше статьи без ссылок)
$parse->fillingURL();
// модуль формирования RSS
$rssTemplate = isset($_GET['template']) ? $_GET['template'] : $config['defaultTemplate'];
$rssTemplate = $_GET['template'] ?? $config['defaultTemplate'];
$rss = new cRSS($rssTemplate);

if (isset($_GET['page']) || isset($_GET['template'])) {
Expand All @@ -61,7 +65,6 @@
echo($lenta);
} else {
// формируем список rss

$fileParams = glob("rss_templates/*.default_params.php");
$rssListTemplate = [];
foreach ($fileParams as $fileParam) {
Expand Down
6 changes: 5 additions & 1 deletion libs/cContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ protected function getContent(array $params): array
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output, true);
$ret = json_decode($output, true);
if (empty($ret)) {
$ret = [];
}
return $ret;
}

/**
Expand Down
28 changes: 13 additions & 15 deletions libs/cDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct()
}


static function createTablePage()
static function createTablePage(): bool
{
self::$count_query++;
$sql = "CREATE TABLE IF NOT EXISTS page (
Expand All @@ -61,7 +61,7 @@ static function createTablePage()
return self::$db->exec($sql);
}

static function createTableConfig()
static function createTableConfig(): bool
{
self::$count_query++;
$sql = "CREATE TABLE IF NOT EXISTS config (
Expand All @@ -74,9 +74,9 @@ static function createTableConfig()

/**
* получение параметров из БД
* @return array резульат в виде массива
* @return array результат в виде массива
*/
public function readConfigFromBD()
public function readConfigFromBD(): array
{
self::$count_query++;
$sql = "SELECT * FROM config ";
Expand All @@ -102,11 +102,11 @@ public function getConfig(string $name)

/**
* Запись или обновление параметра в БД
* @param string $name имя парамтра
* @param string $name имя параметра
* @param string $value значение параметра
* @return bool
*/
public function setConfig(string $name, string $value)
public function setConfig(string $name, string $value): bool
{
self::$count_query++;
if ($this->getConfig($name) === false || $this->getConfig($name) === null) {
Expand Down Expand Up @@ -136,7 +136,7 @@ public function getPageById(int $id)
return $query->execute()->fetchArray(SQLITE3_ASSOC);
}

public function getPageByIds(array $ids)
public function getPageByIds(array $ids): array
{
if (count($ids) == 0) {
return [];
Expand All @@ -152,7 +152,7 @@ public function getPageByIds(array $ids)
return $result;
}

public function getEmptyPagesId()
public function getEmptyPagesId(): array
{
self::$count_query++;
$sql = "SELECT id FROM page WHERE revid is null";
Expand All @@ -165,7 +165,7 @@ public function getEmptyPagesId()
return $result;
}

public function getEmptyUrl()
public function getEmptyUrl(): array
{
self::$count_query++;
$sql = "SELECT id FROM page WHERE url is null;";
Expand All @@ -191,7 +191,7 @@ public function getPageList(int $page, int $count):array
{
self::$count_query++;
$offset = $count * $page;
$sql = "SELECT * FROM page WHERE url not null ORDER BY updateAt ASC LIMIT {$count} OFFSET {$offset};";
$sql = "SELECT * FROM page WHERE url not null ORDER BY updateAt ASC LIMIT $count OFFSET $offset;";
$query = self::$db->query($sql);
self::$query[] = $sql;
$result = [];
Expand Down Expand Up @@ -252,12 +252,10 @@ private function clearText($text)
'&lt;' => '<',
'&gt;' => '>'
];
$text = str_replace(array_keys($replace), array_values($replace), $text);

return $text;
return str_replace(array_keys($replace), array_values($replace), $text);
}

public function updateCache(cPage $page)
public function updateCache(cPage $page): SQLite3Result
{
self::$count_query++;
if ($this->getPageById($page->id)) {
Expand All @@ -276,7 +274,7 @@ public function updateCache(cPage $page)
$query->bindValue(':text', $this->clearText($page->text));
$query->bindValue(':updateAt', $page->updateAt);
$query->bindValue(':categories', implode(',', $page->categories));
self::$query[] = (self::$getSQL) ? $query->getSQL(self::$getSQL) : "$sql {$page->id}";
self::$query[] = (self::$getSQL) ? $query->getSQL(self::$getSQL) : "$sql $page->id";
return $query->execute();
}

Expand Down
4 changes: 2 additions & 2 deletions libs/cPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class cPage
var $text;
public array $categories = [];
var $revid;
var $user;
var $url;
var string $user;
var string $url;

public function __construct($id, $title, $time)
{
Expand Down
3 changes: 3 additions & 0 deletions libs/cPageList.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public function init()
function getPages()
{
$list = $this->getContentAll($this->params);
if (empty($list)) {
return false;
}
foreach ($list as $item) {
$this->listPage[$item['pageid']] = new cPage(
$item['pageid'],
Expand Down
8 changes: 7 additions & 1 deletion libs/cUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function checkUpdate($version)

public static function sendNotify(string $mail = ''): bool
{
return mail($mail, 'Тема', 'Сообщение');
return mail($mail, 'Найдена новая версия плагина Яндекс.Турбо для движка mediawiki', 'Вышла новая версия плагина. Скачать можно по ссылке https://github.com/Ichinya/yandex_turbo_for_mediawiki');
}

/**
Expand Down Expand Up @@ -105,11 +105,17 @@ private static function checkGitVersion()
}


/**
* Запускаем обновление, в основном это обновления кэша, чтобы заново его не перестраивать и "не сбивать" даты
*/
private static function update()
{
self::update111to120();
}

/**
* Обновление с версии 1.1.1 до 1.2.0 - изменение в кэше символов
*/
private static function update111to120()
{
$replace = [
Expand Down
17 changes: 13 additions & 4 deletions templates/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/** @var array $config */
/** @var int $countPage */
/** @var cPageList $list */
/** @var array $notify */
?>
<!doctype html>
<html lang="ru">
Expand All @@ -20,6 +21,16 @@
<h1>Яндекс Турбо для MediaWiki</h1>
<div>версия <?= $currentVersion; ?></div>

<?php
if (!empty($notify['warning'])) {
foreach ($notify['warning'] as $warning): ?>
<div style="color: red; font-weight: 800;">
<p><b>!!!</b> <?= $warning; ?></p>
</div>
<?php endforeach;
}
?>

<h2>Список доступных лент</h2>
<ol>
<?php
Expand All @@ -42,13 +53,11 @@
</ol>

<?php
if (cUpdate::$needUpdateFromGit) {
?>
if (cUpdate::$needUpdateFromGit): ?>
<div>Есть новая версия на <a href="https://github.com/Ichinya/yandex_turbo_for_mediawiki" target="_blank">GitHub</a>,
рекомендуется обновить
</div>
<?php
}
<?php endif;


if (!isset($_GET['page']) && $config['debug']) {
Expand Down

1 comment on commit d01951c

@Ichinya
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a

Please sign in to comment.