namespacing: \Shaarli\Feed\{Cache,CachedPage,FeedBuilder}
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
This commit is contained in:
parent
f3d2f25794
commit
dfc650aa23
10 changed files with 54 additions and 44 deletions
|
@ -1,4 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace Shaarli\Feed;
|
||||||
/**
|
/**
|
||||||
* Simple cache system, mainly for the RSS/ATOM feeds
|
* Simple cache system, mainly for the RSS/ATOM feeds
|
||||||
*/
|
*/
|
||||||
|
@ -24,7 +26,7 @@ public function __construct($cacheDir, $url, $shouldBeCached)
|
||||||
{
|
{
|
||||||
// TODO: check write access to the cache directory
|
// TODO: check write access to the cache directory
|
||||||
$this->cacheDir = $cacheDir;
|
$this->cacheDir = $cacheDir;
|
||||||
$this->filename = $this->cacheDir.'/'.sha1($url).'.cache';
|
$this->filename = $this->cacheDir . '/' . sha1($url) . '.cache';
|
||||||
$this->shouldBeCached = $shouldBeCached;
|
$this->shouldBeCached = $shouldBeCached;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
namespace Shaarli\Feed;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use LinkDB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FeedBuilder class.
|
* FeedBuilder class.
|
||||||
|
@ -38,12 +42,12 @@ class FeedBuilder
|
||||||
protected $feedType;
|
protected $feedType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array $_SERVER.
|
* @var array $_SERVER
|
||||||
*/
|
*/
|
||||||
protected $serverInfo;
|
protected $serverInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array $_GET.
|
* @var array $_GET
|
||||||
*/
|
*/
|
||||||
protected $userInput;
|
protected $userInput;
|
||||||
|
|
||||||
|
@ -142,18 +146,18 @@ public function buildData()
|
||||||
*/
|
*/
|
||||||
protected function buildItem($link, $pageaddr)
|
protected function buildItem($link, $pageaddr)
|
||||||
{
|
{
|
||||||
$link['guid'] = $pageaddr .'?'. $link['shorturl'];
|
$link['guid'] = $pageaddr . '?' . $link['shorturl'];
|
||||||
// Check for both signs of a note: starting with ? and 7 chars long.
|
// Check for both signs of a note: starting with ? and 7 chars long.
|
||||||
if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
|
if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
|
||||||
$link['url'] = $pageaddr . $link['url'];
|
$link['url'] = $pageaddr . $link['url'];
|
||||||
}
|
}
|
||||||
if ($this->usePermalinks === true) {
|
if ($this->usePermalinks === true) {
|
||||||
$permalink = '<a href="'. $link['url'] .'" title="'. t('Direct link') .'">'. t('Direct link') .'</a>';
|
$permalink = '<a href="' . $link['url'] . '" title="' . t('Direct link') . '">' . t('Direct link') . '</a>';
|
||||||
} else {
|
} else {
|
||||||
$permalink = '<a href="'. $link['guid'] .'" title="'. t('Permalink') .'">'. t('Permalink') .'</a>';
|
$permalink = '<a href="' . $link['guid'] . '" title="' . t('Permalink') . '">' . t('Permalink') . '</a>';
|
||||||
}
|
}
|
||||||
$link['description'] = format_description($link['description'], '', false, $pageaddr);
|
$link['description'] = format_description($link['description'], '', false, $pageaddr);
|
||||||
$link['description'] .= PHP_EOL .'<br>— '. $permalink;
|
$link['description'] .= PHP_EOL . '<br>— ' . $permalink;
|
||||||
|
|
||||||
$pubDate = $link['created'];
|
$pubDate = $link['created'];
|
||||||
$link['pub_iso_date'] = $this->getIsoDate($pubDate);
|
$link['pub_iso_date'] = $this->getIsoDate($pubDate);
|
||||||
|
@ -164,7 +168,6 @@ protected function buildItem($link, $pageaddr)
|
||||||
$link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM);
|
$link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM);
|
||||||
} else {
|
} else {
|
||||||
$link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);
|
$link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the more recent item.
|
// Save the more recent item.
|
||||||
|
@ -223,11 +226,11 @@ public function setLocale($locale)
|
||||||
public function getTypeLanguage()
|
public function getTypeLanguage()
|
||||||
{
|
{
|
||||||
// Use the locale do define the language, if available.
|
// Use the locale do define the language, if available.
|
||||||
if (! empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) {
|
if (!empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) {
|
||||||
$length = ($this->feedType == self::$FEED_RSS) ? 5 : 2;
|
$length = ($this->feedType === self::$FEED_RSS) ? 5 : 2;
|
||||||
return str_replace('_', '-', substr($this->locale, 0, $length));
|
return str_replace('_', '-', substr($this->locale, 0, $length));
|
||||||
}
|
}
|
||||||
return ($this->feedType == self::$FEED_RSS) ? 'en-en' : 'en';
|
return ($this->feedType === self::$FEED_RSS) ? 'en-en' : 'en';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -287,7 +290,7 @@ public function getNbLinks($max)
|
||||||
}
|
}
|
||||||
|
|
||||||
$intNb = intval($this->userInput['nb']);
|
$intNb = intval($this->userInput['nb']);
|
||||||
if (! is_int($intNb) || $intNb == 0) {
|
if (!is_int($intNb) || $intNb == 0) {
|
||||||
return self::$DEFAULT_NB_LINKS;
|
return self::$DEFAULT_NB_LINKS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
"Shaarli\\Config\\": "application/config/",
|
"Shaarli\\Config\\": "application/config/",
|
||||||
"Shaarli\\Config\\Exception\\": "application/config/exception",
|
"Shaarli\\Config\\Exception\\": "application/config/exception",
|
||||||
"Shaarli\\Exceptions\\": "application/exceptions",
|
"Shaarli\\Exceptions\\": "application/exceptions",
|
||||||
|
"Shaarli\\Feed\\": "application/feed",
|
||||||
"Shaarli\\Security\\": "application/security"
|
"Shaarli\\Security\\": "application/security"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,10 +57,8 @@
|
||||||
|
|
||||||
// Shaarli library
|
// Shaarli library
|
||||||
require_once 'application/ApplicationUtils.php';
|
require_once 'application/ApplicationUtils.php';
|
||||||
require_once 'application/Cache.php';
|
|
||||||
require_once 'application/CachedPage.php';
|
|
||||||
require_once 'application/config/ConfigPlugin.php';
|
require_once 'application/config/ConfigPlugin.php';
|
||||||
require_once 'application/FeedBuilder.php';
|
require_once 'application/feed/Cache.php';
|
||||||
require_once 'application/FileUtils.php';
|
require_once 'application/FileUtils.php';
|
||||||
require_once 'application/History.php';
|
require_once 'application/History.php';
|
||||||
require_once 'application/HttpUtils.php';
|
require_once 'application/HttpUtils.php';
|
||||||
|
@ -76,7 +74,9 @@
|
||||||
require_once 'application/Router.php';
|
require_once 'application/Router.php';
|
||||||
require_once 'application/Updater.php';
|
require_once 'application/Updater.php';
|
||||||
use \Shaarli\Config\ConfigManager;
|
use \Shaarli\Config\ConfigManager;
|
||||||
use Shaarli\History;
|
use \Shaarli\Feed\CachedPage;
|
||||||
|
use \Shaarli\Feed\FeedBuilder;
|
||||||
|
use \Shaarli\History;
|
||||||
use \Shaarli\Languages;
|
use \Shaarli\Languages;
|
||||||
use \Shaarli\Security\LoginManager;
|
use \Shaarli\Security\LoginManager;
|
||||||
use \Shaarli\Security\SessionManager;
|
use \Shaarli\Security\SessionManager;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
use pubsubhubbub\publisher\Publisher;
|
use pubsubhubbub\publisher\Publisher;
|
||||||
use Shaarli\Config\ConfigManager;
|
use Shaarli\Config\ConfigManager;
|
||||||
|
use Shaarli\Feed\FeedBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin init function - set the hub to the default appspot one.
|
* Plugin init function - set the hub to the default appspot one.
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
* Link datastore tests
|
* Link datastore tests
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Shaarli\Exceptions\IOException;
|
require_once 'application/feed/Cache.php';
|
||||||
|
|
||||||
require_once 'application/Cache.php';
|
|
||||||
require_once 'application/FileUtils.php';
|
require_once 'application/FileUtils.php';
|
||||||
require_once 'application/LinkDB.php';
|
require_once 'application/LinkDB.php';
|
||||||
require_once 'application/Utils.php';
|
require_once 'application/Utils.php';
|
||||||
|
|
|
@ -2,16 +2,17 @@
|
||||||
/**
|
/**
|
||||||
* Cache tests
|
* Cache tests
|
||||||
*/
|
*/
|
||||||
|
namespace Shaarli\Feed;
|
||||||
|
|
||||||
// required to access $_SESSION array
|
// required to access $_SESSION array
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
require_once 'application/Cache.php';
|
require_once 'application/feed/Cache.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for cached pages
|
* Unitary tests for cached pages
|
||||||
*/
|
*/
|
||||||
class CacheTest extends PHPUnit_Framework_TestCase
|
class CacheTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
// test cache directory
|
// test cache directory
|
||||||
protected static $testCacheDir = 'sandbox/dummycache';
|
protected static $testCacheDir = 'sandbox/dummycache';
|
||||||
|
@ -25,16 +26,16 @@ class CacheTest extends PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
if (! is_dir(self::$testCacheDir)) {
|
if (!is_dir(self::$testCacheDir)) {
|
||||||
mkdir(self::$testCacheDir);
|
mkdir(self::$testCacheDir);
|
||||||
} else {
|
} else {
|
||||||
array_map('unlink', glob(self::$testCacheDir.'/*'));
|
array_map('unlink', glob(self::$testCacheDir . '/*'));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (self::$pages as $page) {
|
foreach (self::$pages as $page) {
|
||||||
file_put_contents(self::$testCacheDir.'/'.$page.'.cache', $page);
|
file_put_contents(self::$testCacheDir . '/' . $page . '.cache', $page);
|
||||||
}
|
}
|
||||||
file_put_contents(self::$testCacheDir.'/intru.der', 'ShouldNotBeThere');
|
file_put_contents(self::$testCacheDir . '/intru.der', 'ShouldNotBeThere');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,7 +43,7 @@ public function setUp()
|
||||||
*/
|
*/
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
array_map('unlink', glob(self::$testCacheDir.'/*'));
|
array_map('unlink', glob(self::$testCacheDir . '/*'));
|
||||||
rmdir(self::$testCacheDir);
|
rmdir(self::$testCacheDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,10 +54,10 @@ public function testPurgeCachedPages()
|
||||||
{
|
{
|
||||||
purgeCachedPages(self::$testCacheDir);
|
purgeCachedPages(self::$testCacheDir);
|
||||||
foreach (self::$pages as $page) {
|
foreach (self::$pages as $page) {
|
||||||
$this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache');
|
$this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertFileExists(self::$testCacheDir.'/intru.der');
|
$this->assertFileExists(self::$testCacheDir . '/intru.der');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +69,7 @@ public function testPurgeCachedPagesMissingDir()
|
||||||
ini_set('error_log', '/dev/null');
|
ini_set('error_log', '/dev/null');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'Cannot purge sandbox/dummycache_missing: no directory',
|
'Cannot purge sandbox/dummycache_missing: no directory',
|
||||||
purgeCachedPages(self::$testCacheDir.'_missing')
|
purgeCachedPages(self::$testCacheDir . '_missing')
|
||||||
);
|
);
|
||||||
ini_set('error_log', $oldlog);
|
ini_set('error_log', $oldlog);
|
||||||
}
|
}
|
||||||
|
@ -83,7 +84,7 @@ public function testInvalidateCaches()
|
||||||
|
|
||||||
invalidateCaches(self::$testCacheDir);
|
invalidateCaches(self::$testCacheDir);
|
||||||
foreach (self::$pages as $page) {
|
foreach (self::$pages as $page) {
|
||||||
$this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache');
|
$this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertArrayNotHasKey('tags', $_SESSION);
|
$this->assertArrayNotHasKey('tags', $_SESSION);
|
|
@ -2,13 +2,12 @@
|
||||||
/**
|
/**
|
||||||
* PageCache tests
|
* PageCache tests
|
||||||
*/
|
*/
|
||||||
|
namespace Shaarli\Feed;
|
||||||
require_once 'application/CachedPage.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unitary tests for cached pages
|
* Unitary tests for cached pages
|
||||||
*/
|
*/
|
||||||
class CachedPageTest extends PHPUnit_Framework_TestCase
|
class CachedPageTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
// test cache directory
|
// test cache directory
|
||||||
protected static $testCacheDir = 'sandbox/pagecache';
|
protected static $testCacheDir = 'sandbox/pagecache';
|
||||||
|
@ -20,10 +19,10 @@ class CachedPageTest extends PHPUnit_Framework_TestCase
|
||||||
*/
|
*/
|
||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
if (! is_dir(self::$testCacheDir)) {
|
if (!is_dir(self::$testCacheDir)) {
|
||||||
mkdir(self::$testCacheDir);
|
mkdir(self::$testCacheDir);
|
||||||
}
|
}
|
||||||
self::$filename = self::$testCacheDir.'/'.sha1(self::$url).'.cache';
|
self::$filename = self::$testCacheDir . '/' . sha1(self::$url) . '.cache';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,6 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'application/FeedBuilder.php';
|
namespace Shaarli\Feed;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use LinkDB;
|
||||||
|
use ReferenceLinkDB;
|
||||||
|
|
||||||
require_once 'application/LinkDB.php';
|
require_once 'application/LinkDB.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* Unit tests for FeedBuilder.
|
* Unit tests for FeedBuilder.
|
||||||
*/
|
*/
|
||||||
class FeedBuilderTest extends PHPUnit_Framework_TestCase
|
class FeedBuilderTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var string locale Basque (Spain).
|
* @var string locale Basque (Spain).
|
Loading…
Reference in a new issue