aboutsummaryrefslogtreecommitdiff
path: root/app/Controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controllers')
-rw-r--r--app/Controllers/authController.php4
-rwxr-xr-xapp/Controllers/feedController.php4
-rw-r--r--app/Controllers/importExportController.php6
-rw-r--r--app/Controllers/updateController.php159
4 files changed, 124 insertions, 49 deletions
diff --git a/app/Controllers/authController.php b/app/Controllers/authController.php
index 9decba431..1398e4e49 100644
--- a/app/Controllers/authController.php
+++ b/app/Controllers/authController.php
@@ -113,6 +113,10 @@ class FreshRSS_auth_Controller extends Minz_ActionController {
$file_mtime = @filemtime(PUBLIC_PATH . '/scripts/bcrypt.min.js');
Minz_View::appendScript(Minz_Url::display('/scripts/bcrypt.min.js?' . $file_mtime));
+ $conf = Minz_Configuration::get('system');
+ $limits = $conf->limits;
+ $this->view->cookie_days = round($limits['cookie_duration'] / 86400, 1);
+
if (Minz_Request::isPost()) {
$nonce = Minz_Session::param('nonce');
$username = Minz_Request::param('username', '');
diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php
index c4115584a..f71f26a4e 100755
--- a/app/Controllers/feedController.php
+++ b/app/Controllers/feedController.php
@@ -27,6 +27,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
public static function addFeed($url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '') {
+ FreshRSS_UserDAO::touch();
@set_time_limit(300);
$catDAO = new FreshRSS_CategoryDAO();
@@ -484,6 +485,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
if ($feed_id <= 0 || $feed_name == '') {
return false;
}
+ FreshRSS_UserDAO::touch();
$feedDAO = FreshRSS_Factory::createFeedDao();
return $feedDAO->updateFeed($feed_id, array('name' => $feed_name));
}
@@ -492,6 +494,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
if ($feed_id <= 0 || ($cat_id <= 0 && $new_cat_name == '')) {
return false;
}
+ FreshRSS_UserDAO::touch();
$catDAO = new FreshRSS_CategoryDAO();
if ($cat_id > 0) {
@@ -540,6 +543,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
public static function deleteFeed($feed_id) {
+ FreshRSS_UserDAO::touch();
$feedDAO = FreshRSS_Factory::createFeedDao();
if ($feedDAO->deleteFeed($feed_id)) {
// TODO: Delete old favicon
diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php
index 3ba91a243..6ae89defb 100644
--- a/app/Controllers/importExportController.php
+++ b/app/Controllers/importExportController.php
@@ -531,6 +531,8 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
$this->entryDAO = FreshRSS_Factory::createEntryDao($username);
$this->feedDAO = FreshRSS_Factory::createFeedDao($username);
+ $this->entryDAO->disableBuffering();
+
if ($export_feeds === true) {
//All feeds
$export_feeds = $this->feedDAO->listFeedsIds();
@@ -641,13 +643,13 @@ class FreshRSS_importExport_Controller extends Minz_ActionController {
$this->view->list_title = _t('sub.import_export.starred_list');
$this->view->type = 'starred';
$unread_fav = $this->entryDAO->countUnreadReadFavorites();
- $this->view->entries = $this->entryDAO->listWhere(
+ $this->view->entriesRaw = $this->entryDAO->listWhereRaw(
's', '', FreshRSS_Entry::STATE_ALL, 'ASC', $unread_fav['all']
);
} elseif ($type === 'feed' && $feed != null) {
$this->view->list_title = _t('sub.import_export.feed_list', $feed->name());
$this->view->type = 'feed/' . $feed->id();
- $this->view->entries = $this->entryDAO->listWhere(
+ $this->view->entriesRaw = $this->entryDAO->listWhereRaw(
'f', $feed->id(), FreshRSS_Entry::STATE_ALL, 'ASC',
$maxFeedEntries
);
diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php
index 64c984b04..8f939dbdb 100644
--- a/app/Controllers/updateController.php
+++ b/app/Controllers/updateController.php
@@ -2,6 +2,45 @@
class FreshRSS_update_Controller extends Minz_ActionController {
+ public static function isGit() {
+ return is_dir(FRESHRSS_PATH . '/.git/');
+ }
+
+ public static function hasGitUpdate() {
+ $cwd = getcwd();
+ chdir(FRESHRSS_PATH);
+ $output = array();
+ try {
+ exec('git fetch', $output, $return);
+ if ($return == 0) {
+ exec('git status -sb --porcelain remote', $output, $return);
+ } else {
+ $line = is_array($output) ? implode('; ', $output) : '' . $output;
+ Minz_Log::warning('git fetch warning:' . $line);
+ }
+ } catch (Exception $e) {
+ Minz_Log::warning('git fetch error:' . $e->getMessage());
+ }
+ chdir($cwd);
+ $line = is_array($output) ? implode('; ', $output) : '' . $output;
+ return strpos($line, '[behind') !== false;
+ }
+
+ public static function gitPull() {
+ $cwd = getcwd();
+ chdir(FRESHRSS_PATH);
+ $output = array();
+ $return = 1;
+ try {
+ exec('git pull --ff-only', $output, $return);
+ } catch (Exception $e) {
+ Minz_Log::warning('git pull error:' . $e->getMessage());
+ }
+ chdir($cwd);
+ $line = is_array($output) ? implode('; ', $output) : '' . $output;
+ return $return == 0 ? true : 'Git error: ' . $line;
+ }
+
public function firstAction() {
if (!FreshRSS_Auth::hasAccess('admin')) {
Minz_Error::error(403);
@@ -20,7 +59,7 @@ class FreshRSS_update_Controller extends Minz_ActionController {
public function indexAction() {
Minz_View::prependTitle(_t('admin.update.title') . ' ยท ');
- if (file_exists(UPDATE_FILENAME) && !is_writable(FRESHRSS_PATH)) {
+ if (!is_writable(FRESHRSS_PATH)) {
$this->view->message = array(
'status' => 'bad',
'title' => _t('gen.short.damn'),
@@ -53,49 +92,65 @@ class FreshRSS_update_Controller extends Minz_ActionController {
return;
}
- $auto_update_url = FreshRSS_Context::$system_conf->auto_update_url . '?v=' . FRESHRSS_VERSION;
- $c = curl_init($auto_update_url);
- curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
- curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
- $result = curl_exec($c);
- $c_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
- $c_error = curl_error($c);
- curl_close($c);
-
- if ($c_status !== 200) {
- Minz_Log::warning(
- 'Error during update (HTTP code ' . $c_status . '): ' . $c_error
- );
+ $script = '';
+ $version = '';
- $this->view->message = array(
- 'status' => 'bad',
- 'title' => _t('gen.short.damn'),
- 'body' => _t('feedback.update.server_not_found', $auto_update_url)
- );
- return;
- }
-
- $res_array = explode("\n", $result, 2);
- $status = $res_array[0];
- if (strpos($status, 'UPDATE') !== 0) {
- $this->view->message = array(
- 'status' => 'bad',
- 'title' => _t('gen.short.damn'),
- 'body' => _t('feedback.update.none')
- );
+ if (self::isGit()) {
+ if (self::hasGitUpdate()) {
+ $version = 'git';
+ } else {
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('gen.short.damn'),
+ 'body' => _t('feedback.update.none')
+ );
+ @touch(join_path(DATA_PATH, 'last_update.txt'));
+ return;
+ }
+ } else {
+ $auto_update_url = FreshRSS_Context::$system_conf->auto_update_url . '?v=' . FRESHRSS_VERSION;
+ Minz_Log::debug('HTTP GET ' . $auto_update_url);
+ $c = curl_init($auto_update_url);
+ curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
+ curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
+ $result = curl_exec($c);
+ $c_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
+ $c_error = curl_error($c);
+ curl_close($c);
+
+ if ($c_status !== 200) {
+ Minz_Log::warning(
+ 'Error during update (HTTP code ' . $c_status . '): ' . $c_error
+ );
+
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('gen.short.damn'),
+ 'body' => _t('feedback.update.server_not_found', $auto_update_url)
+ );
+ return;
+ }
- @touch(join_path(DATA_PATH, 'last_update.txt'));
+ $res_array = explode("\n", $result, 2);
+ $status = $res_array[0];
+ if (strpos($status, 'UPDATE') !== 0) {
+ $this->view->message = array(
+ 'status' => 'bad',
+ 'title' => _t('gen.short.damn'),
+ 'body' => _t('feedback.update.none')
+ );
+ @touch(join_path(DATA_PATH, 'last_update.txt'));
+ return;
+ }
- return;
+ $script = $res_array[1];
+ $version = explode(' ', $status, 2);
+ $version = $version[1];
}
- $script = $res_array[1];
if (file_put_contents(UPDATE_FILENAME, $script) !== false) {
- $version = explode(' ', $status, 2);
- $version = $version[1];
@file_put_contents(join_path(DATA_PATH, 'last_update.txt'), $version);
-
Minz_Request::forward(array('c' => 'update'), true);
} else {
$this->view->message = array(
@@ -111,10 +166,13 @@ class FreshRSS_update_Controller extends Minz_ActionController {
Minz_Request::forward(array('c' => 'update'), true);
}
- require(UPDATE_FILENAME);
-
if (Minz_Request::param('post_conf', false)) {
- $res = do_post_update();
+ if (self::isGit()) {
+ $res = !self::hasGitUpdate();
+ } else {
+ require(UPDATE_FILENAME);
+ $res = do_post_update();
+ }
Minz_ExtensionManager::callHook('post_update');
@@ -126,14 +184,21 @@ class FreshRSS_update_Controller extends Minz_ActionController {
Minz_Request::bad(_t('feedback.update.error', $res),
array('c' => 'update', 'a' => 'index'));
}
- }
-
- if (Minz_Request::isPost()) {
- save_info_update();
- }
+ } else {
+ $res = false;
- if (!need_info_update()) {
- $res = apply_update();
+ if (self::isGit()) {
+ $res = self::gitPull();
+ } else {
+ if (Minz_Request::isPost()) {
+ save_info_update();
+ }
+ if (!need_info_update()) {
+ $res = apply_update();
+ } else {
+ return;
+ }
+ }
if ($res === true) {
Minz_Request::forward(array(