summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-02-01 14:38:59 +0100
committeremkael <emkael@tlen.pl>2019-02-01 14:38:59 +0100
commit28a1c14bf82d9d0a8311f8f18746d0b4cd821314 (patch)
tree6525acc4811fdf026489831a9339b79819ff7475
parentc4283763618a8e382dba7e70b06e1d3a908cd6c2 (diff)
Weaponizing cache files
-rw-r--r--_cron/check-empty-cache-files1
-rw-r--r--_cron/fb-cache-files2
-rwxr-xr-xbin/refresh-fb-cache.php34
-rw-r--r--providers/Facebook.php21
4 files changed, 48 insertions, 10 deletions
diff --git a/_cron/check-empty-cache-files b/_cron/check-empty-cache-files
deleted file mode 100644
index 41a5938..0000000
--- a/_cron/check-empty-cache-files
+++ /dev/null
@@ -1 +0,0 @@
-10 * * * * find $SITEPATH/cache -size 6c
diff --git a/_cron/fb-cache-files b/_cron/fb-cache-files
new file mode 100644
index 0000000..c6b2cb1
--- /dev/null
+++ b/_cron/fb-cache-files
@@ -0,0 +1,2 @@
+*/10 * * * * $SITEPATH/bin/refresh-fb-cache.php
+10 * * * * find $SITEPATH/cache -size 6c
diff --git a/bin/refresh-fb-cache.php b/bin/refresh-fb-cache.php
new file mode 100755
index 0000000..35c7822
--- /dev/null
+++ b/bin/refresh-fb-cache.php
@@ -0,0 +1,34 @@
+#!/usr/bin/env php
+<?php
+
+$BASEPATH = dirname(__FILE__);
+chdir($BASEPATH);
+
+require_once('../providers/Facebook.php');
+
+$cacheFiles = glob('../cache/facebook.*');
+
+$fileToFetch = NULL;
+$oldestCache = PHP_INT_MAX;
+
+foreach ($cacheFiles as $file) {
+ if (!preg_match('/\.Piwoteka$/', $file)) {
+ $cacheTime = filemtime($file);
+ if ($cacheTime < $oldestCache) {
+ $oldestCache = $cacheTime;
+ $fileToFetch = explode('.', $file);
+ $fileToFetch = $fileToFetch[count($fileToFetch)-1];
+ }
+ }
+}
+
+$filesToFetch = ['Piwoteka', $fileToFetch];
+
+foreach ($filesToFetch as $feed) {
+ $provider = new \Providers\Facebook($feed, ['force' => TRUE]);
+ if (!$provider->get()) {
+ throw new \Exception(sprintf('Feed %s failed to fetch!', $feed));
+ }
+}
+
+?>
diff --git a/providers/Facebook.php b/providers/Facebook.php
index e2afef6..2126189 100644
--- a/providers/Facebook.php
+++ b/providers/Facebook.php
@@ -7,7 +7,17 @@ require_once('Item.php');
class Facebook extends \Providers\HtmlFeed {
- protected $_cacheTimeout = '5 minutes';
+ protected $_cacheTimeout = '300 years';
+
+ public function __construct($feed, $options) {
+ parent::__construct($feed, $options);
+ if (isset($this->_options['dump'])) {
+ $this->_options['force'] = TRUE;
+ }
+ if (isset($this->_options['force'])) {
+ $this->_cacheTimeout = '1 second';
+ }
+ }
protected function _getCachePath() {
return '../cache/facebook.%s';
@@ -18,14 +28,7 @@ class Facebook extends \Providers\HtmlFeed {
}
protected function __getUserAgent() {
- return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0';
- }
-
- protected function _getItems() {
- if (isset($this->_options['dump'])) {
- $this->_cacheTimeout = '1 second';
- }
- return parent::_getItems();
+ return 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0.1';
}
protected function _parseFeedContent($tree) {