aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2018-12-03 00:08:04 +0100
committerVirtualTam <virtualtam@flibidi.net>2019-01-12 22:47:48 +0100
commitdfc650aa239d3a2c028d0ba13132ce75b4f4c0b4 (patch)
tree4b3f54ecfe27e57fd5d32f3543f688c545588aab
parentf3d2f257946e2a3c8791c1ba99b379acbe934fec (diff)
downloadShaarli-dfc650aa239d3a2c028d0ba13132ce75b4f4c0b4.tar.gz
Shaarli-dfc650aa239d3a2c028d0ba13132ce75b4f4c0b4.tar.zst
Shaarli-dfc650aa239d3a2c028d0ba13132ce75b4f4c0b4.zip
namespacing: \Shaarli\Feed\{Cache,CachedPage,FeedBuilder}
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
-rw-r--r--application/feed/Cache.php (renamed from application/Cache.php)0
-rw-r--r--application/feed/CachedPage.php (renamed from application/CachedPage.php)4
-rw-r--r--application/feed/FeedBuilder.php (renamed from application/FeedBuilder.php)37
-rw-r--r--composer.json1
-rw-r--r--index.php8
-rw-r--r--plugins/pubsubhubbub/pubsubhubbub.php1
-rw-r--r--tests/LinkDBTest.php4
-rw-r--r--tests/feed/CacheTest.php (renamed from tests/CacheTest.php)23
-rw-r--r--tests/feed/CachedPageTest.php (renamed from tests/CachedPageTest.php)9
-rw-r--r--tests/feed/FeedBuilderTest.php (renamed from tests/FeedBuilderTest.php)11
10 files changed, 54 insertions, 44 deletions
diff --git a/application/Cache.php b/application/feed/Cache.php
index e5d43e61..e5d43e61 100644
--- a/application/Cache.php
+++ b/application/feed/Cache.php
diff --git a/application/CachedPage.php b/application/feed/CachedPage.php
index e11cc52d..1c51ac73 100644
--- a/application/CachedPage.php
+++ b/application/feed/CachedPage.php
@@ -1,4 +1,6 @@
1<?php 1<?php
2
3namespace Shaarli\Feed;
2/** 4/**
3 * Simple cache system, mainly for the RSS/ATOM feeds 5 * Simple cache system, mainly for the RSS/ATOM feeds
4 */ 6 */
@@ -24,7 +26,7 @@ class CachedPage
24 { 26 {
25 // TODO: check write access to the cache directory 27 // TODO: check write access to the cache directory
26 $this->cacheDir = $cacheDir; 28 $this->cacheDir = $cacheDir;
27 $this->filename = $this->cacheDir.'/'.sha1($url).'.cache'; 29 $this->filename = $this->cacheDir . '/' . sha1($url) . '.cache';
28 $this->shouldBeCached = $shouldBeCached; 30 $this->shouldBeCached = $shouldBeCached;
29 } 31 }
30 32
diff --git a/application/FeedBuilder.php b/application/feed/FeedBuilder.php
index 73fafcbe..dcfd2c89 100644
--- a/application/FeedBuilder.php
+++ b/application/feed/FeedBuilder.php
@@ -1,4 +1,8 @@
1<?php 1<?php
2namespace Shaarli\Feed;
3
4use DateTime;
5use LinkDB;
2 6
3/** 7/**
4 * FeedBuilder class. 8 * FeedBuilder class.
@@ -38,12 +42,12 @@ class FeedBuilder
38 protected $feedType; 42 protected $feedType;
39 43
40 /** 44 /**
41 * @var array $_SERVER. 45 * @var array $_SERVER
42 */ 46 */
43 protected $serverInfo; 47 protected $serverInfo;
44 48
45 /** 49 /**
46 * @var array $_GET. 50 * @var array $_GET
47 */ 51 */
48 protected $userInput; 52 protected $userInput;
49 53
@@ -75,10 +79,10 @@ class FeedBuilder
75 /** 79 /**
76 * Feed constructor. 80 * Feed constructor.
77 * 81 *
78 * @param LinkDB $linkDB LinkDB instance. 82 * @param LinkDB $linkDB LinkDB instance.
79 * @param string $feedType Type of feed. 83 * @param string $feedType Type of feed.
80 * @param array $serverInfo $_SERVER. 84 * @param array $serverInfo $_SERVER.
81 * @param array $userInput $_GET. 85 * @param array $userInput $_GET.
82 * @param boolean $isLoggedIn True if the user is currently logged in, false otherwise. 86 * @param boolean $isLoggedIn True if the user is currently logged in, false otherwise.
83 */ 87 */
84 public function __construct($linkDB, $feedType, $serverInfo, $userInput, $isLoggedIn) 88 public function __construct($linkDB, $feedType, $serverInfo, $userInput, $isLoggedIn)
@@ -124,7 +128,7 @@ class FeedBuilder
124 $data['show_dates'] = !$this->hideDates || $this->isLoggedIn; 128 $data['show_dates'] = !$this->hideDates || $this->isLoggedIn;
125 // Remove leading slash from REQUEST_URI. 129 // Remove leading slash from REQUEST_URI.
126 $data['self_link'] = escape(server_url($this->serverInfo)) 130 $data['self_link'] = escape(server_url($this->serverInfo))
127 . escape($this->serverInfo['REQUEST_URI']); 131 . escape($this->serverInfo['REQUEST_URI']);
128 $data['index_url'] = $pageaddr; 132 $data['index_url'] = $pageaddr;
129 $data['usepermalinks'] = $this->usePermalinks === true; 133 $data['usepermalinks'] = $this->usePermalinks === true;
130 $data['links'] = $linkDisplayed; 134 $data['links'] = $linkDisplayed;
@@ -142,18 +146,18 @@ class FeedBuilder
142 */ 146 */
143 protected function buildItem($link, $pageaddr) 147 protected function buildItem($link, $pageaddr)
144 { 148 {
145 $link['guid'] = $pageaddr .'?'. $link['shorturl']; 149 $link['guid'] = $pageaddr . '?' . $link['shorturl'];
146 // Check for both signs of a note: starting with ? and 7 chars long. 150 // Check for both signs of a note: starting with ? and 7 chars long.
147 if ($link['url'][0] === '?' && strlen($link['url']) === 7) { 151 if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
148 $link['url'] = $pageaddr . $link['url']; 152 $link['url'] = $pageaddr . $link['url'];
149 } 153 }
150 if ($this->usePermalinks === true) { 154 if ($this->usePermalinks === true) {
151 $permalink = '<a href="'. $link['url'] .'" title="'. t('Direct link') .'">'. t('Direct link') .'</a>'; 155 $permalink = '<a href="' . $link['url'] . '" title="' . t('Direct link') . '">' . t('Direct link') . '</a>';
152 } else { 156 } else {
153 $permalink = '<a href="'. $link['guid'] .'" title="'. t('Permalink') .'">'. t('Permalink') .'</a>'; 157 $permalink = '<a href="' . $link['guid'] . '" title="' . t('Permalink') . '">' . t('Permalink') . '</a>';
154 } 158 }
155 $link['description'] = format_description($link['description'], '', false, $pageaddr); 159 $link['description'] = format_description($link['description'], '', false, $pageaddr);
156 $link['description'] .= PHP_EOL .'<br>&#8212; '. $permalink; 160 $link['description'] .= PHP_EOL . '<br>&#8212; ' . $permalink;
157 161
158 $pubDate = $link['created']; 162 $pubDate = $link['created'];
159 $link['pub_iso_date'] = $this->getIsoDate($pubDate); 163 $link['pub_iso_date'] = $this->getIsoDate($pubDate);
@@ -164,7 +168,6 @@ class FeedBuilder
164 $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM); 168 $link['up_iso_date'] = $this->getIsoDate($upDate, DateTime::ATOM);
165 } else { 169 } else {
166 $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM); 170 $link['up_iso_date'] = $this->getIsoDate($pubDate, DateTime::ATOM);
167 ;
168 } 171 }
169 172
170 // Save the more recent item. 173 // Save the more recent item.
@@ -223,11 +226,11 @@ class FeedBuilder
223 public function getTypeLanguage() 226 public function getTypeLanguage()
224 { 227 {
225 // Use the locale do define the language, if available. 228 // Use the locale do define the language, if available.
226 if (! empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) { 229 if (!empty($this->locale) && preg_match('/^\w{2}[_\-]\w{2}/', $this->locale)) {
227 $length = ($this->feedType == self::$FEED_RSS) ? 5 : 2; 230 $length = ($this->feedType === self::$FEED_RSS) ? 5 : 2;
228 return str_replace('_', '-', substr($this->locale, 0, $length)); 231 return str_replace('_', '-', substr($this->locale, 0, $length));
229 } 232 }
230 return ($this->feedType == self::$FEED_RSS) ? 'en-en' : 'en'; 233 return ($this->feedType === self::$FEED_RSS) ? 'en-en' : 'en';
231 } 234 }
232 235
233 /** 236 /**
@@ -287,7 +290,7 @@ class FeedBuilder
287 } 290 }
288 291
289 $intNb = intval($this->userInput['nb']); 292 $intNb = intval($this->userInput['nb']);
290 if (! is_int($intNb) || $intNb == 0) { 293 if (!is_int($intNb) || $intNb == 0) {
291 return self::$DEFAULT_NB_LINKS; 294 return self::$DEFAULT_NB_LINKS;
292 } 295 }
293 296
diff --git a/composer.json b/composer.json
index 027203f4..7c9cbf3d 100644
--- a/composer.json
+++ b/composer.json
@@ -37,6 +37,7 @@
37 "Shaarli\\Config\\": "application/config/", 37 "Shaarli\\Config\\": "application/config/",
38 "Shaarli\\Config\\Exception\\": "application/config/exception", 38 "Shaarli\\Config\\Exception\\": "application/config/exception",
39 "Shaarli\\Exceptions\\": "application/exceptions", 39 "Shaarli\\Exceptions\\": "application/exceptions",
40 "Shaarli\\Feed\\": "application/feed",
40 "Shaarli\\Security\\": "application/security" 41 "Shaarli\\Security\\": "application/security"
41 } 42 }
42 } 43 }
diff --git a/index.php b/index.php
index cc41d80c..6d1ae3fc 100644
--- a/index.php
+++ b/index.php
@@ -57,10 +57,8 @@ require_once __DIR__ . '/vendor/autoload.php';
57 57
58// Shaarli library 58// Shaarli library
59require_once 'application/ApplicationUtils.php'; 59require_once 'application/ApplicationUtils.php';
60require_once 'application/Cache.php';
61require_once 'application/CachedPage.php';
62require_once 'application/config/ConfigPlugin.php'; 60require_once 'application/config/ConfigPlugin.php';
63require_once 'application/FeedBuilder.php'; 61require_once 'application/feed/Cache.php';
64require_once 'application/FileUtils.php'; 62require_once 'application/FileUtils.php';
65require_once 'application/History.php'; 63require_once 'application/History.php';
66require_once 'application/HttpUtils.php'; 64require_once 'application/HttpUtils.php';
@@ -76,7 +74,9 @@ require_once 'application/PluginManager.php';
76require_once 'application/Router.php'; 74require_once 'application/Router.php';
77require_once 'application/Updater.php'; 75require_once 'application/Updater.php';
78use \Shaarli\Config\ConfigManager; 76use \Shaarli\Config\ConfigManager;
79use Shaarli\History; 77use \Shaarli\Feed\CachedPage;
78use \Shaarli\Feed\FeedBuilder;
79use \Shaarli\History;
80use \Shaarli\Languages; 80use \Shaarli\Languages;
81use \Shaarli\Security\LoginManager; 81use \Shaarli\Security\LoginManager;
82use \Shaarli\Security\SessionManager; 82use \Shaarli\Security\SessionManager;
diff --git a/plugins/pubsubhubbub/pubsubhubbub.php b/plugins/pubsubhubbub/pubsubhubbub.php
index 9f0342a3..1872af8a 100644
--- a/plugins/pubsubhubbub/pubsubhubbub.php
+++ b/plugins/pubsubhubbub/pubsubhubbub.php
@@ -11,6 +11,7 @@
11 11
12use pubsubhubbub\publisher\Publisher; 12use pubsubhubbub\publisher\Publisher;
13use Shaarli\Config\ConfigManager; 13use Shaarli\Config\ConfigManager;
14use Shaarli\Feed\FeedBuilder;
14 15
15/** 16/**
16 * Plugin init function - set the hub to the default appspot one. 17 * Plugin init function - set the hub to the default appspot one.
diff --git a/tests/LinkDBTest.php b/tests/LinkDBTest.php
index 9b2f35e6..737a2247 100644
--- a/tests/LinkDBTest.php
+++ b/tests/LinkDBTest.php
@@ -3,9 +3,7 @@
3 * Link datastore tests 3 * Link datastore tests
4 */ 4 */
5 5
6use Shaarli\Exceptions\IOException; 6require_once 'application/feed/Cache.php';
7
8require_once 'application/Cache.php';
9require_once 'application/FileUtils.php'; 7require_once 'application/FileUtils.php';
10require_once 'application/LinkDB.php'; 8require_once 'application/LinkDB.php';
11require_once 'application/Utils.php'; 9require_once 'application/Utils.php';
diff --git a/tests/CacheTest.php b/tests/feed/CacheTest.php
index f60fad91..c0a9f26f 100644
--- a/tests/CacheTest.php
+++ b/tests/feed/CacheTest.php
@@ -2,16 +2,17 @@
2/** 2/**
3 * Cache tests 3 * Cache tests
4 */ 4 */
5namespace Shaarli\Feed;
5 6
6// required to access $_SESSION array 7// required to access $_SESSION array
7session_start(); 8session_start();
8 9
9require_once 'application/Cache.php'; 10require_once 'application/feed/Cache.php';
10 11
11/** 12/**
12 * Unitary tests for cached pages 13 * Unitary tests for cached pages
13 */ 14 */
14class CacheTest extends PHPUnit_Framework_TestCase 15class CacheTest extends \PHPUnit\Framework\TestCase
15{ 16{
16 // test cache directory 17 // test cache directory
17 protected static $testCacheDir = 'sandbox/dummycache'; 18 protected static $testCacheDir = 'sandbox/dummycache';
@@ -25,16 +26,16 @@ class CacheTest extends PHPUnit_Framework_TestCase
25 */ 26 */
26 public function setUp() 27 public function setUp()
27 { 28 {
28 if (! is_dir(self::$testCacheDir)) { 29 if (!is_dir(self::$testCacheDir)) {
29 mkdir(self::$testCacheDir); 30 mkdir(self::$testCacheDir);
30 } else { 31 } else {
31 array_map('unlink', glob(self::$testCacheDir.'/*')); 32 array_map('unlink', glob(self::$testCacheDir . '/*'));
32 } 33 }
33 34
34 foreach (self::$pages as $page) { 35 foreach (self::$pages as $page) {
35 file_put_contents(self::$testCacheDir.'/'.$page.'.cache', $page); 36 file_put_contents(self::$testCacheDir . '/' . $page . '.cache', $page);
36 } 37 }
37 file_put_contents(self::$testCacheDir.'/intru.der', 'ShouldNotBeThere'); 38 file_put_contents(self::$testCacheDir . '/intru.der', 'ShouldNotBeThere');
38 } 39 }
39 40
40 /** 41 /**
@@ -42,7 +43,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
42 */ 43 */
43 public function tearDown() 44 public function tearDown()
44 { 45 {
45 array_map('unlink', glob(self::$testCacheDir.'/*')); 46 array_map('unlink', glob(self::$testCacheDir . '/*'));
46 rmdir(self::$testCacheDir); 47 rmdir(self::$testCacheDir);
47 } 48 }
48 49
@@ -53,10 +54,10 @@ class CacheTest extends PHPUnit_Framework_TestCase
53 { 54 {
54 purgeCachedPages(self::$testCacheDir); 55 purgeCachedPages(self::$testCacheDir);
55 foreach (self::$pages as $page) { 56 foreach (self::$pages as $page) {
56 $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); 57 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
57 } 58 }
58 59
59 $this->assertFileExists(self::$testCacheDir.'/intru.der'); 60 $this->assertFileExists(self::$testCacheDir . '/intru.der');
60 } 61 }
61 62
62 /** 63 /**
@@ -68,7 +69,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
68 ini_set('error_log', '/dev/null'); 69 ini_set('error_log', '/dev/null');
69 $this->assertEquals( 70 $this->assertEquals(
70 'Cannot purge sandbox/dummycache_missing: no directory', 71 'Cannot purge sandbox/dummycache_missing: no directory',
71 purgeCachedPages(self::$testCacheDir.'_missing') 72 purgeCachedPages(self::$testCacheDir . '_missing')
72 ); 73 );
73 ini_set('error_log', $oldlog); 74 ini_set('error_log', $oldlog);
74 } 75 }
@@ -83,7 +84,7 @@ class CacheTest extends PHPUnit_Framework_TestCase
83 84
84 invalidateCaches(self::$testCacheDir); 85 invalidateCaches(self::$testCacheDir);
85 foreach (self::$pages as $page) { 86 foreach (self::$pages as $page) {
86 $this->assertFileNotExists(self::$testCacheDir.'/'.$page.'.cache'); 87 $this->assertFileNotExists(self::$testCacheDir . '/' . $page . '.cache');
87 } 88 }
88 89
89 $this->assertArrayNotHasKey('tags', $_SESSION); 90 $this->assertArrayNotHasKey('tags', $_SESSION);
diff --git a/tests/CachedPageTest.php b/tests/feed/CachedPageTest.php
index 51565cd6..0bcc1442 100644
--- a/tests/CachedPageTest.php
+++ b/tests/feed/CachedPageTest.php
@@ -2,13 +2,12 @@
2/** 2/**
3 * PageCache tests 3 * PageCache tests
4 */ 4 */
5 5namespace Shaarli\Feed;
6require_once 'application/CachedPage.php';
7 6
8/** 7/**
9 * Unitary tests for cached pages 8 * Unitary tests for cached pages
10 */ 9 */
11class CachedPageTest extends PHPUnit_Framework_TestCase 10class CachedPageTest extends \PHPUnit\Framework\TestCase
12{ 11{
13 // test cache directory 12 // test cache directory
14 protected static $testCacheDir = 'sandbox/pagecache'; 13 protected static $testCacheDir = 'sandbox/pagecache';
@@ -20,10 +19,10 @@ class CachedPageTest extends PHPUnit_Framework_TestCase
20 */ 19 */
21 public static function setUpBeforeClass() 20 public static function setUpBeforeClass()
22 { 21 {
23 if (! is_dir(self::$testCacheDir)) { 22 if (!is_dir(self::$testCacheDir)) {
24 mkdir(self::$testCacheDir); 23 mkdir(self::$testCacheDir);
25 } 24 }
26 self::$filename = self::$testCacheDir.'/'.sha1(self::$url).'.cache'; 25 self::$filename = self::$testCacheDir . '/' . sha1(self::$url) . '.cache';
27 } 26 }
28 27
29 /** 28 /**
diff --git a/tests/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index 4ca58e5a..1fdbc60e 100644
--- a/tests/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -1,6 +1,11 @@
1<?php 1<?php
2 2
3require_once 'application/FeedBuilder.php'; 3namespace Shaarli\Feed;
4
5use DateTime;
6use LinkDB;
7use ReferenceLinkDB;
8
4require_once 'application/LinkDB.php'; 9require_once 'application/LinkDB.php';
5 10
6/** 11/**
@@ -8,7 +13,7 @@ require_once 'application/LinkDB.php';
8 * 13 *
9 * Unit tests for FeedBuilder. 14 * Unit tests for FeedBuilder.
10 */ 15 */
11class FeedBuilderTest extends PHPUnit_Framework_TestCase 16class FeedBuilderTest extends \PHPUnit\Framework\TestCase
12{ 17{
13 /** 18 /**
14 * @var string locale Basque (Spain). 19 * @var string locale Basque (Spain).
@@ -90,7 +95,7 @@ class FeedBuilderTest extends PHPUnit_Framework_TestCase
90 $this->assertEquals('http://host.tld/?WDWyig', $link['url']); 95 $this->assertEquals('http://host.tld/?WDWyig', $link['url']);
91 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']); 96 $this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
92 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']); 97 $pub = DateTime::createFromFormat(DateTime::RSS, $link['pub_iso_date']);
93 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']); 98 $up = DateTime::createFromFormat(DateTime::ATOM, $link['up_iso_date']);
94 $this->assertEquals($pub, $up); 99 $this->assertEquals($pub, $up);
95 $this->assertContains('Stallman has a beard', $link['description']); 100 $this->assertContains('Stallman has a beard', $link['description']);
96 $this->assertContains('Permalink', $link['description']); 101 $this->assertContains('Permalink', $link['description']);