aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/DatabaseDAO.php41
-rw-r--r--app/Models/DatabaseDAOPGSQL.php37
-rw-r--r--app/Models/DatabaseDAOSQLite.php13
-rw-r--r--app/Models/Entry.php8
-rw-r--r--app/Models/EntryDAO.php22
-rw-r--r--app/Models/EntryDAOPGSQL.php11
-rw-r--r--app/Models/EntryDAOSQLite.php8
-rw-r--r--app/Models/Feed.php43
-rw-r--r--app/Models/LogDAO.php6
-rw-r--r--app/Models/Share.php31
10 files changed, 154 insertions, 66 deletions
diff --git a/app/Models/DatabaseDAO.php b/app/Models/DatabaseDAO.php
index 6ba5bca3e..f5469f2b7 100644
--- a/app/Models/DatabaseDAO.php
+++ b/app/Models/DatabaseDAO.php
@@ -80,4 +80,45 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
return $list;
}
+
+ public function size($all = false) {
+ $db = FreshRSS_Context::$system_conf->db;
+ $sql = 'SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema=?'; //MySQL
+ $values = array($db['base']);
+ if (!$all) {
+ $sql .= ' AND table_name LIKE ?';
+ $values[] = $this->prefix . '%';
+ }
+ $stm = $this->bd->prepare($sql);
+ $stm->execute($values);
+ $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
+ return $res[0];
+ }
+
+ public function optimize() {
+ $ok = true;
+
+ $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'entry`'; //MySQL
+ $stm = $this->bd->prepare($sql);
+ $ok &= $stm != false;
+ if ($stm) {
+ $ok &= $stm->execute();
+ }
+
+ $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'feed`'; //MySQL
+ $stm = $this->bd->prepare($sql);
+ $ok &= $stm != false;
+ if ($stm) {
+ $ok &= $stm->execute();
+ }
+
+ $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'category`'; //MySQL
+ $stm = $this->bd->prepare($sql);
+ $ok &= $stm != false;
+ if ($stm) {
+ $ok &= $stm->execute();
+ }
+
+ return $ok;
+ }
}
diff --git a/app/Models/DatabaseDAOPGSQL.php b/app/Models/DatabaseDAOPGSQL.php
index 2a18db970..1b3f7408d 100644
--- a/app/Models/DatabaseDAOPGSQL.php
+++ b/app/Models/DatabaseDAOPGSQL.php
@@ -40,4 +40,41 @@ class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAO {
'default' => $dao['default'],
);
}
+
+ public function size($all = true) {
+ $db = FreshRSS_Context::$system_conf->db;
+ $sql = 'SELECT pg_size_pretty(pg_database_size(?))';
+ $values = array($db['base']);
+ $stm = $this->bd->prepare($sql);
+ $stm->execute($values);
+ $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
+ return $res[0];
+ }
+
+ public function optimize() {
+ $ok = true;
+
+ $sql = 'VACUUM `' . $this->prefix . 'entry`';
+ $stm = $this->bd->prepare($sql);
+ $ok &= $stm != false;
+ if ($stm) {
+ $ok &= $stm->execute();
+ }
+
+ $sql = 'VACUUM `' . $this->prefix . 'feed`';
+ $stm = $this->bd->prepare($sql);
+ $ok &= $stm != false;
+ if ($stm) {
+ $ok &= $stm->execute();
+ }
+
+ $sql = 'VACUUM `' . $this->prefix . 'category`';
+ $stm = $this->bd->prepare($sql);
+ $ok &= $stm != false;
+ if ($stm) {
+ $ok &= $stm->execute();
+ }
+
+ return $ok;
+ }
}
diff --git a/app/Models/DatabaseDAOSQLite.php b/app/Models/DatabaseDAOSQLite.php
index 2e1df132e..d3aedb3c0 100644
--- a/app/Models/DatabaseDAOSQLite.php
+++ b/app/Models/DatabaseDAOSQLite.php
@@ -45,4 +45,17 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO {
'default' => $dao['dflt_value'],
);
}
+
+ public function size($all = false) {
+ return @filesize(join_path(DATA_PATH, 'users', $this->current_user, 'db.sqlite'));
+ }
+
+ public function optimize() {
+ $sql = 'VACUUM';
+ $stm = $this->bd->prepare($sql);
+ if ($stm) {
+ return $stm->execute();
+ }
+ return false;
+ }
}
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index df3d59bea..0ad3781e5 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -97,6 +97,14 @@ class FreshRSS_Entry extends Minz_Model {
return $this->hash;
}
+ public function _hash($value) {
+ $value = trim($value);
+ if (ctype_xdigit($value)) {
+ $this->hash = substr($value, 0, 32);
+ }
+ return $this->hash;
+ }
+
public function _id($value) {
$this->id = $value;
}
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index bebafe500..e8b6dcdae 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -885,28 +885,6 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
return array('all' => $all, 'unread' => $unread, 'read' => $all - $unread);
}
- public function optimizeTable() {
- $sql = 'OPTIMIZE TABLE `' . $this->prefix . 'entry`'; //MySQL
- $stm = $this->bd->prepare($sql);
- if ($stm) {
- return $stm->execute();
- }
- }
-
- public function size($all = false) {
- $db = FreshRSS_Context::$system_conf->db;
- $sql = 'SELECT SUM(data_length + index_length) FROM information_schema.TABLES WHERE table_schema=?'; //MySQL
- $values = array($db['base']);
- if (!$all) {
- $sql .= ' AND table_name LIKE ?';
- $values[] = $this->prefix . '%';
- }
- $stm = $this->bd->prepare($sql);
- $stm->execute($values);
- $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
- return $res[0];
- }
-
public static function daoToEntry($dao) {
$entry = new FreshRSS_Entry(
$dao['id_feed'],
diff --git a/app/Models/EntryDAOPGSQL.php b/app/Models/EntryDAOPGSQL.php
index 405774abf..f09fe8e75 100644
--- a/app/Models/EntryDAOPGSQL.php
+++ b/app/Models/EntryDAOPGSQL.php
@@ -46,15 +46,4 @@ END $$;';
}
return $result;
}
-
- public function size($all = true) {
- $db = FreshRSS_Context::$system_conf->db;
- $sql = 'SELECT pg_size_pretty(pg_database_size(?))';
- $values = array($db['base']);
- $stm = $this->bd->prepare($sql);
- $stm->execute($values);
- $res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
- return $res[0];
- }
-
}
diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php
index 8dad54322..0f57dc1ba 100644
--- a/app/Models/EntryDAOSQLite.php
+++ b/app/Models/EntryDAOSQLite.php
@@ -261,12 +261,4 @@ class FreshRSS_EntryDAOSQLite extends FreshRSS_EntryDAO {
}
return $affected;
}
-
- public function optimizeTable() {
- //TODO: Search for an equivalent in SQLite
- }
-
- public function size($all = false) {
- return @filesize(join_path(DATA_PATH, 'users', $this->current_user, 'db.sqlite'));
- }
}
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index d8fe03197..560f7415d 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -403,8 +403,7 @@ class FreshRSS_Feed extends Minz_Model {
if (!isset($hubJson['error']) || $hubJson['error'] !== (bool)$error) {
$hubJson['error'] = (bool)$error;
file_put_contents($hubFilename, json_encode($hubJson));
- file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t"
- . 'Set error to ' . ($error ? 1 : 0) . ' for ' . $url . "\n", FILE_APPEND);
+ Minz_Log::warning('Set error to ' . ($error ? 1 : 0) . ' for ' . $url, PSHB_LOG);
}
return false;
}
@@ -419,7 +418,7 @@ class FreshRSS_Feed extends Minz_Model {
if (!$hubJson || empty($hubJson['key']) || !ctype_xdigit($hubJson['key'])) {
$text = 'Invalid JSON for PubSubHubbub: ' . $this->url;
Minz_Log::warning($text);
- file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND);
+ Minz_Log::warning($text, PSHB_LOG);
return false;
}
if ((!empty($hubJson['lease_end'])) && ($hubJson['lease_end'] < (time() + (3600 * 23)))) { //TODO: Make a better policy
@@ -427,7 +426,7 @@ class FreshRSS_Feed extends Minz_Model {
. date('c', empty($hubJson['lease_end']) ? time() : $hubJson['lease_end'])
. ' and needs renewal: ' . $this->url;
Minz_Log::warning($text);
- file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND);
+ Minz_Log::warning($text, PSHB_LOG);
$key = $hubJson['key']; //To renew our lease
} elseif (((!empty($hubJson['error'])) || empty($hubJson['lease_end'])) &&
(empty($hubJson['lease_start']) || $hubJson['lease_start'] < time() - (3600 * 23))) { //Do not renew too often
@@ -445,7 +444,7 @@ class FreshRSS_Feed extends Minz_Model {
file_put_contents(PSHB_PATH . '/keys/' . $key . '.txt', base64url_encode($this->selfUrl));
$text = 'PubSubHubbub prepared for ' . $this->url;
Minz_Log::debug($text);
- file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" . $text . "\n", FILE_APPEND);
+ Minz_Log::debug($text, PSHB_LOG);
}
$currentUser = Minz_Session::param('currentUser');
if (FreshRSS_user_Controller::checkUsername($currentUser) && !file_exists($path . '/' . $currentUser . '.txt')) {
@@ -481,24 +480,28 @@ class FreshRSS_Feed extends Minz_Model {
}
$ch = curl_init();
curl_setopt_array($ch, array(
- CURLOPT_URL => $hubJson['hub'],
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_USERAGENT => 'FreshRSS/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ')',
- CURLOPT_POSTFIELDS => http_build_query(array(
- 'hub.verify' => 'sync',
- 'hub.mode' => $state ? 'subscribe' : 'unsubscribe',
- 'hub.topic' => $url,
- 'hub.callback' => $callbackUrl,
- ))
- )
- );
+ CURLOPT_URL => $hubJson['hub'],
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_POSTFIELDS => http_build_query(array(
+ 'hub.verify' => 'sync',
+ 'hub.mode' => $state ? 'subscribe' : 'unsubscribe',
+ 'hub.topic' => $url,
+ 'hub.callback' => $callbackUrl,
+ )),
+ CURLOPT_USERAGENT => FRESHRSS_USERAGENT,
+ CURLOPT_MAXREDIRS => 10,
+ ));
+ if (version_compare(PHP_VERSION, '5.6.0') >= 0 || ini_get('open_basedir') == '') {
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //Keep option separated for open_basedir PHP bug 65646
+ }
+ if (defined('CURLOPT_ENCODING')) {
+ curl_setopt($ch, CURLOPT_ENCODING, ''); //Enable all encodings
+ }
$response = curl_exec($ch);
$info = curl_getinfo($ch);
- file_put_contents(USERS_PATH . '/_/log_pshb.txt', date('c') . "\t" .
- 'PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url .
- ' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response . "\n", FILE_APPEND);
+ Minz_Log::warning('PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $url .
+ ' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response, PSHB_LOG);
if (substr($info['http_code'], 0, 1) == '2') {
return true;
diff --git a/app/Models/LogDAO.php b/app/Models/LogDAO.php
index ab258cd58..5bce466d5 100644
--- a/app/Models/LogDAO.php
+++ b/app/Models/LogDAO.php
@@ -22,9 +22,9 @@ class FreshRSS_LogDAO {
public static function truncate() {
file_put_contents(join_path(DATA_PATH, 'users', Minz_Session::param('currentUser', '_'), 'log.txt'), '');
if (FreshRSS_Auth::hasAccess('admin')) {
- file_put_contents(join_path(DATA_PATH, 'users', '_', 'log.txt'), '');
- file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_api.txt'), '');
- file_put_contents(join_path(DATA_PATH, 'users', '_', 'log_pshb.txt'), '');
+ file_put_contents(ADMIN_LOG, '');
+ file_put_contents(API_LOG, '');
+ file_put_contents(PSHB_LOG, '');
}
}
}
diff --git a/app/Models/Share.php b/app/Models/Share.php
index 86b1b9ed9..7378b30df 100644
--- a/app/Models/Share.php
+++ b/app/Models/Share.php
@@ -21,9 +21,11 @@ class FreshRSS_Share {
}
$help_url = isset($share_options['help']) ? $share_options['help'] : '';
+ $field = isset($share_options['field']) ? $share_options['field'] : null;
self::$list_sharing[$type] = new FreshRSS_Share(
$type, $share_options['url'], $share_options['transform'],
- $share_options['form'], $help_url
+ $share_options['form'], $help_url, $share_options['method'],
+ $field
);
}
@@ -76,6 +78,8 @@ class FreshRSS_Share {
private $base_url = null;
private $title = null;
private $link = null;
+ private $method = 'GET';
+ private $field;
/**
* Create a FreshRSS_Share object.
@@ -86,9 +90,10 @@ class FreshRSS_Share {
* is typically for a centralized service while "advanced" is for
* decentralized ones.
* @param $help_url is an optional url to give help on this option.
+ * @param $method defines the sharing method (GET or POST)
*/
private function __construct($type, $url_transform, $transform,
- $form_type, $help_url = '') {
+ $form_type, $help_url, $method, $field) {
$this->type = $type;
$this->name = _t('gen.share.' . $type);
$this->url_transform = $url_transform;
@@ -103,6 +108,11 @@ class FreshRSS_Share {
$form_type = 'simple';
}
$this->form_type = $form_type;
+ if (!in_array($method, array('GET', 'POST'))) {
+ $method = 'GET';
+ }
+ $this->method = $method;
+ $this->field = $field;
}
/**
@@ -116,6 +126,8 @@ class FreshRSS_Share {
'url' => 'base_url',
'title' => 'title',
'link' => 'link',
+ 'method' => 'method',
+ 'field' => 'field',
);
foreach ($options as $key => $value) {
@@ -133,6 +145,21 @@ class FreshRSS_Share {
}
/**
+ * Return the current method of the share option.
+ */
+ public function method() {
+ return $this->method;
+ }
+
+ /**
+ * Return the current field of the share option. It's null for shares
+ * using the GET method.
+ */
+ public function field() {
+ return $this->field;
+ }
+
+ /**
* Return the current form type of the share option.
*/
public function formType() {