Documents and Documentation (beta 1) #23
|
@ -2,7 +2,7 @@
|
|||
|
||||
/** The current Feed Reader Central version */
|
||||
|
||||
use BitBadger\PDODocument\Configuration;
|
||||
use BitBadger\PDODocument\{AutoId, Configuration};
|
||||
use FeedReaderCentral\Data;
|
||||
|
||||
const FRC_VERSION = '1.0.0-beta1';
|
||||
|
@ -27,6 +27,7 @@ require __DIR__ . '/vendor/autoload.php';
|
|||
require 'user-config.php';
|
||||
|
||||
Configuration::$pdoDSN = 'sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'data', DATABASE_NAME]);
|
||||
Configuration::$autoId = AutoId::Number;
|
||||
Data::ensureDb();
|
||||
|
||||
/** @var string The date the world wide web was created */
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
"name": "bit-badger/feed-reader-central",
|
||||
"minimum-stability": "dev",
|
||||
"require": {
|
||||
"php": ">=8.2",
|
||||
"bit-badger/pdo-document": "^1",
|
||||
"ext-curl": "*",
|
||||
"ext-dom": "*",
|
||||
|
|
11
src/composer.lock
generated
11
src/composer.lock
generated
|
@ -4,20 +4,20 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "f074a197e429ac24507becc14e0d99c3",
|
||||
"content-hash": "4f0add59e384feb6787acf3685c9e031",
|
||||
"packages": [
|
||||
{
|
||||
"name": "bit-badger/pdo-document",
|
||||
"version": "v1.0.0-alpha1",
|
||||
"version": "v1.0.0-alpha2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://git.bitbadger.solutions/bit-badger/pdo-document",
|
||||
"reference": "f784f3e52cc1e4691fa347eefc82a2e4587c7f38"
|
||||
"reference": "330e27218756df8b93081a17dead8aaec789b071"
|
||||
},
|
||||
"require": {
|
||||
"ext-pdo": "*",
|
||||
"netresearch/jsonmapper": "^4",
|
||||
"php": ">=8.3"
|
||||
"php": ">=8.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^11"
|
||||
|
@ -54,7 +54,7 @@
|
|||
"rss": "https://git.bitbadger.solutions/bit-badger/pdo-document.rss",
|
||||
"source": "https://git.bitbadger.solutions/bit-badger/pdo-document"
|
||||
},
|
||||
"time": "2024-06-08T23:58:45+00:00"
|
||||
"time": "2024-06-11T11:07:56+00:00"
|
||||
},
|
||||
{
|
||||
"name": "netresearch/jsonmapper",
|
||||
|
@ -115,6 +115,7 @@
|
|||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": ">=8.2",
|
||||
"ext-curl": "*",
|
||||
"ext-dom": "*",
|
||||
"ext-pdo": "*",
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace FeedReaderCentral;
|
||||
|
||||
use BitBadger\PDODocument\{
|
||||
Configuration, Custom, DocumentException, DocumentList, Exists, Field, Find, Parameters, Patch, Query
|
||||
Configuration, Custom, Document, DocumentException, DocumentList, Exists, Field, Find, Parameters, Patch, Query
|
||||
};
|
||||
use DateTimeInterface;
|
||||
|
||||
|
@ -15,16 +15,16 @@ class Feed
|
|||
// ***** CONSTANTS *****
|
||||
|
||||
/** @var int Do not purge items */
|
||||
public const int PURGE_NONE = 0;
|
||||
public const PURGE_NONE = 0;
|
||||
|
||||
/** @var int Purge all read items (will not purge unread items) */
|
||||
public const int PURGE_READ = 1;
|
||||
public const PURGE_READ = 1;
|
||||
|
||||
/** @var int Purge items older than the specified number of days */
|
||||
public const int PURGE_BY_DAYS = 2;
|
||||
public const PURGE_BY_DAYS = 2;
|
||||
|
||||
/** @var int Purge items in number greater than the specified number of items to keep */
|
||||
public const int PURGE_BY_COUNT = 3;
|
||||
public const PURGE_BY_COUNT = 3;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -187,10 +187,7 @@ class Feed
|
|||
return ['error' => "Already subscribed to feed $feed->url"];
|
||||
}
|
||||
|
||||
Custom::nonQuery(<<<'SQL'
|
||||
INSERT INTO feed (data)
|
||||
VALUES (json_set(:data, '$.id', (SELECT coalesce(max(data->>'id'), 0) + 1 FROM feed)))
|
||||
SQL, Parameters::json(':data', self::fromParsed($feed)));
|
||||
Document::insert(Table::FEED, self::fromParsed($feed));
|
||||
|
||||
$doc = Find::firstByFields(Table::FEED, $fields, static::class);
|
||||
if (!$doc) return ['error' => 'Could not retrieve inserted feed'];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use BitBadger\PDODocument\{Custom, DocumentException, Parameters, Patch};
|
||||
use BitBadger\PDODocument\{Document, DocumentException, Patch};
|
||||
|
||||
/**
|
||||
* An item from a feed
|
||||
|
@ -57,17 +57,14 @@ class Item
|
|||
*/
|
||||
public static function add(int $feedId, ParsedItem $parsed): void
|
||||
{
|
||||
Custom::nonQuery(<<<'SQL'
|
||||
INSERT INTO item (data)
|
||||
VALUES (json_set(:data, '$.id', (SELECT coalesce(max(data->>'id'), 0) + 1 FROM item)))
|
||||
SQL, Parameters::json(':data', new static(
|
||||
feed_id: $feedId,
|
||||
title: $parsed->title,
|
||||
item_guid: $parsed->guid,
|
||||
item_link: $parsed->link,
|
||||
published_on: $parsed->publishedOn,
|
||||
updated_on: $parsed->updatedOn,
|
||||
content: $parsed->content)));
|
||||
Document::insert(Table::ITEM, new static(
|
||||
feed_id: $feedId,
|
||||
title: $parsed->title,
|
||||
item_guid: $parsed->guid,
|
||||
item_link: $parsed->link,
|
||||
published_on: $parsed->publishedOn,
|
||||
updated_on: $parsed->updatedOn,
|
||||
content: $parsed->content));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,11 +11,11 @@ use BitBadger\PDODocument\Mapper\{DocumentMapper, ExistsMapper};
|
|||
class ItemWithFeed extends Item
|
||||
{
|
||||
/** @var string The body of the `FROM` clause to join item and feed */
|
||||
public const string FROM_WITH_JOIN = Table::ITEM . ' INNER JOIN ' . Table::FEED
|
||||
public const FROM_WITH_JOIN = Table::ITEM . ' INNER JOIN ' . Table::FEED
|
||||
. ' ON ' . Table::ITEM . ".data->>'feed_id' = " . Table::FEED . ".data->>'id'";
|
||||
|
||||
/** @var string The `SELECT` clause to add the feed as a property to the item's document */
|
||||
public const string SELECT_WITH_FEED =
|
||||
public const SELECT_WITH_FEED =
|
||||
'SELECT json_set(' . Table::ITEM . ".data, '$.feed', json(" . Table::FEED . '.data)) AS data FROM '
|
||||
. self::FROM_WITH_JOIN;
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@ namespace FeedReaderCentral;
|
|||
class Key {
|
||||
|
||||
/** @var string The $_SESSION key for the current user's e-mail address */
|
||||
public const string USER_EMAIL = 'FRC_USER_EMAIL';
|
||||
public const USER_EMAIL = 'FRC_USER_EMAIL';
|
||||
|
||||
/** @var string The $_SESSION key for the current user's ID */
|
||||
public const string USER_ID = 'FRC_USER_ID';
|
||||
public const USER_ID = 'FRC_USER_ID';
|
||||
|
||||
/** @var string The $_REQUEST key for the array of user messages to display */
|
||||
public const string USER_MSG = 'FRC_USER_MSG';
|
||||
public const USER_MSG = 'FRC_USER_MSG';
|
||||
}
|
||||
|
|
|
@ -22,16 +22,16 @@ class ParsedFeed
|
|||
public array $items = [];
|
||||
|
||||
/** @var string The XML namespace for Atom feeds */
|
||||
public const string ATOM_NS = 'http://www.w3.org/2005/Atom';
|
||||
public const ATOM_NS = 'http://www.w3.org/2005/Atom';
|
||||
|
||||
/** @var string The XML namespace for the `<content:encoded>` tag that allows HTML content in a feed */
|
||||
public const string CONTENT_NS = 'http://purl.org/rss/1.0/modules/content/';
|
||||
public const CONTENT_NS = 'http://purl.org/rss/1.0/modules/content/';
|
||||
|
||||
/** @var string The XML namespace for XHTML */
|
||||
public const string XHTML_NS = 'http://www.w3.org/1999/xhtml';
|
||||
public const XHTML_NS = 'http://www.w3.org/1999/xhtml';
|
||||
|
||||
/** @var string The user agent for Feed Reader Central's refresh requests */
|
||||
private const string USER_AGENT =
|
||||
private const USER_AGENT =
|
||||
'FeedReaderCentral/' . FRC_VERSION . ' +https://bitbadger.solutions/open-source/feed-reader-central';
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use BitBadger\PDODocument\DocumentException;
|
||||
use BitBadger\PDODocument\Field;
|
||||
use BitBadger\PDODocument\Patch;
|
||||
use BitBadger\PDODocument\{DocumentException, Field, Patch};
|
||||
|
||||
/**
|
||||
* Security functions
|
||||
|
@ -12,22 +10,22 @@ use BitBadger\PDODocument\Patch;
|
|||
class Security
|
||||
{
|
||||
/** @var int Run as a single user requiring no password */
|
||||
public const int SINGLE_USER = 0;
|
||||
public const SINGLE_USER = 0;
|
||||
|
||||
/** @var int Run as a single user requiring a password */
|
||||
public const int SINGLE_USER_WITH_PASSWORD = 1;
|
||||
public const SINGLE_USER_WITH_PASSWORD = 1;
|
||||
|
||||
/** @var int Require users to provide e-mail address and password */
|
||||
public const int MULTI_USER = 2;
|
||||
public const MULTI_USER = 2;
|
||||
|
||||
/** @var string The e-mail address for the single user */
|
||||
public const string SINGLE_USER_EMAIL = 'solouser@example.com';
|
||||
public const SINGLE_USER_EMAIL = 'solouser@example.com';
|
||||
|
||||
/** @var string The password for the single user with no password */
|
||||
public const string SINGLE_USER_PASSWORD = 'no-password-required';
|
||||
public const SINGLE_USER_PASSWORD = 'no-password-required';
|
||||
|
||||
/** @var string The password algorithm to use for our passwords */
|
||||
public const string PW_ALGORITHM = PASSWORD_DEFAULT;
|
||||
public const PW_ALGORITHM = PASSWORD_DEFAULT;
|
||||
|
||||
/**
|
||||
* Verify a user's password
|
||||
|
|
|
@ -8,11 +8,11 @@ namespace FeedReaderCentral;
|
|||
class Table
|
||||
{
|
||||
/** @var string The user table */
|
||||
public const string USER = 'frc_user';
|
||||
public const USER = 'frc_user';
|
||||
|
||||
/** @var string The feed table */
|
||||
public const string FEED = 'feed';
|
||||
public const FEED = 'feed';
|
||||
|
||||
/** @var string The item table */
|
||||
public const string ITEM = 'item';
|
||||
public const ITEM = 'item';
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace FeedReaderCentral;
|
||||
|
||||
use BitBadger\PDODocument\{Custom, DocumentException, Field, Find, Parameters, Query};
|
||||
use BitBadger\PDODocument\{Custom, Document, DocumentException, Field, Find, Parameters, Query};
|
||||
use BitBadger\PDODocument\Mapper\ExistsMapper;
|
||||
|
||||
/**
|
||||
|
@ -40,10 +40,7 @@ class User
|
|||
*/
|
||||
public static function add(string $email, string $password): void
|
||||
{
|
||||
Custom::nonQuery(<<<'SQL'
|
||||
INSERT INTO user (data)
|
||||
VALUES (json_set(:data, '$.id', (SELECT coalesce(max(data->>'id'), 0) + 1 FROM user)))
|
||||
SQL, Parameters::json(':data', new User(email: $email, password: $password)));
|
||||
Document::insert(Table::USER, new User(email: $email, password: $password));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user