2013-12-23 03:25:54 +01:00
|
|
|
<?php
|
|
|
|
|
2016-08-25 03:17:58 +02:00
|
|
|
namespace Miniflux\Model\Config;
|
2013-12-23 03:25:54 +01:00
|
|
|
|
2016-08-25 03:17:58 +02:00
|
|
|
use Miniflux\Helper;
|
2016-12-26 15:44:53 +01:00
|
|
|
use Miniflux\Model;
|
2014-10-30 02:28:23 +01:00
|
|
|
use DirectoryIterator;
|
2016-12-26 15:44:53 +01:00
|
|
|
use Miniflux\Session\SessionStorage;
|
2014-02-08 20:13:14 +01:00
|
|
|
use PicoDb\Database;
|
2014-05-20 20:20:27 +02:00
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
const TABLE = 'user_settings';
|
2014-05-20 20:20:27 +02:00
|
|
|
|
|
|
|
function get_iframe_whitelist()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'http://www.youtube.com',
|
|
|
|
'https://www.youtube.com',
|
|
|
|
'http://player.vimeo.com',
|
|
|
|
'https://player.vimeo.com',
|
|
|
|
'http://www.dailymotion.com',
|
|
|
|
'https://www.dailymotion.com',
|
|
|
|
);
|
|
|
|
}
|
2014-03-30 21:59:26 +02:00
|
|
|
|
2014-02-26 01:03:46 +01:00
|
|
|
function get_timezones()
|
|
|
|
{
|
2014-10-30 02:28:23 +01:00
|
|
|
$timezones = timezone_identifiers_list();
|
2014-02-26 01:03:46 +01:00
|
|
|
return array_combine(array_values($timezones), $timezones);
|
|
|
|
}
|
|
|
|
|
2015-03-20 23:53:15 +01:00
|
|
|
function is_language_rtl()
|
|
|
|
{
|
|
|
|
$languages = array(
|
|
|
|
'ar_AR'
|
|
|
|
);
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
return in_array(Helper\config('language'), $languages);
|
2015-03-20 23:53:15 +01:00
|
|
|
}
|
|
|
|
|
2013-12-23 03:25:54 +01:00
|
|
|
function get_languages()
|
|
|
|
{
|
2014-10-30 02:28:23 +01:00
|
|
|
return array(
|
2016-12-26 15:44:53 +01:00
|
|
|
'ar_AR' => 'عربي',
|
|
|
|
'cs_CZ' => 'Čeština',
|
|
|
|
'de_DE' => 'Deutsch',
|
|
|
|
'en_US' => 'English',
|
|
|
|
'es_ES' => 'Español',
|
|
|
|
'fr_FR' => 'Français',
|
|
|
|
'it_IT' => 'Italiano',
|
|
|
|
'ja_JP' => '日本語',
|
|
|
|
'pt_BR' => 'Português',
|
|
|
|
'zh_CN' => '简体中国',
|
|
|
|
'sr_RS' => 'српски',
|
2015-03-20 23:53:15 +01:00
|
|
|
'sr_RS@latin' => 'srpski',
|
2016-12-26 15:44:53 +01:00
|
|
|
'ru_RU' => 'Русский',
|
|
|
|
'tr_TR' => 'Türkçe',
|
2013-12-23 03:25:54 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_themes()
|
|
|
|
{
|
|
|
|
$themes = array(
|
2014-11-14 18:48:27 +01:00
|
|
|
'original' => t('Default')
|
2013-12-23 03:25:54 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (file_exists(THEME_DIRECTORY)) {
|
2014-10-30 02:28:23 +01:00
|
|
|
$dir = new DirectoryIterator(THEME_DIRECTORY);
|
2013-12-23 03:25:54 +01:00
|
|
|
|
|
|
|
foreach ($dir as $fileinfo) {
|
|
|
|
if (! $fileinfo->isDot() && $fileinfo->isDir()) {
|
|
|
|
$themes[$dir->getFilename()] = ucfirst($dir->getFilename());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $themes;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_sorting_directions()
|
|
|
|
{
|
|
|
|
return array(
|
2016-12-26 15:44:53 +01:00
|
|
|
'asc' => t('Older items first'),
|
2013-12-23 03:25:54 +01:00
|
|
|
'desc' => t('Most recent first'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-05-29 16:57:23 +02:00
|
|
|
function get_display_mode()
|
|
|
|
{
|
2016-04-18 01:44:45 +02:00
|
|
|
return array(
|
2016-12-26 15:44:53 +01:00
|
|
|
'titles' => t('Titles'),
|
2016-04-18 01:44:45 +02:00
|
|
|
'summaries' => t('Summaries'),
|
2016-12-26 15:44:53 +01:00
|
|
|
'full' => t('Full contents'),
|
2016-04-18 01:44:45 +02:00
|
|
|
);
|
2014-05-29 16:57:23 +02:00
|
|
|
}
|
|
|
|
|
2016-02-27 20:21:18 +01:00
|
|
|
function get_item_title_link()
|
|
|
|
{
|
2016-04-18 01:44:45 +02:00
|
|
|
return array(
|
|
|
|
'original' => t('Original'),
|
2016-12-26 15:44:53 +01:00
|
|
|
'full' => t('Full contents'),
|
2016-04-18 01:44:45 +02:00
|
|
|
);
|
2016-02-27 20:21:18 +01:00
|
|
|
}
|
|
|
|
|
2014-12-16 02:38:35 +01:00
|
|
|
function get_autoflush_read_options()
|
2013-12-23 03:25:54 +01:00
|
|
|
{
|
|
|
|
return array(
|
2016-12-26 15:44:53 +01:00
|
|
|
'0' => t('Never'),
|
2013-12-23 03:25:54 +01:00
|
|
|
'-1' => t('Immediately'),
|
2016-12-26 15:44:53 +01:00
|
|
|
'1' => t('After %d day', 1),
|
|
|
|
'5' => t('After %d day', 5),
|
2015-01-30 19:45:23 +01:00
|
|
|
'15' => t('After %d day', 15),
|
2016-12-26 15:44:53 +01:00
|
|
|
'30' => t('After %d day', 30),
|
2013-12-23 03:25:54 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-12-16 02:38:35 +01:00
|
|
|
function get_autoflush_unread_options()
|
|
|
|
{
|
|
|
|
return array(
|
2016-12-26 15:44:53 +01:00
|
|
|
'0' => t('Never'),
|
2015-01-30 19:45:23 +01:00
|
|
|
'15' => t('After %d day', 15),
|
|
|
|
'30' => t('After %d day', 30),
|
|
|
|
'45' => t('After %d day', 45),
|
|
|
|
'60' => t('After %d day', 60),
|
2014-12-16 02:38:35 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-12-23 03:25:54 +01:00
|
|
|
function get_paging_options()
|
|
|
|
{
|
|
|
|
return array(
|
2016-12-26 15:44:53 +01:00
|
|
|
10 => 10,
|
|
|
|
20 => 20,
|
|
|
|
30 => 30,
|
|
|
|
50 => 50,
|
2013-12-23 03:25:54 +01:00
|
|
|
100 => 100,
|
|
|
|
150 => 150,
|
|
|
|
200 => 200,
|
|
|
|
250 => 250,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-12-23 19:33:16 +01:00
|
|
|
function get_nothing_to_read_redirections()
|
|
|
|
{
|
|
|
|
return array(
|
2016-12-26 15:44:53 +01:00
|
|
|
'feeds' => t('Subscriptions'),
|
|
|
|
'history' => t('History'),
|
2014-11-14 18:48:27 +01:00
|
|
|
'bookmarks' => t('Bookmarks'),
|
2013-12-23 19:33:16 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
function get_default_values()
|
2013-12-23 03:25:54 +01:00
|
|
|
{
|
2016-12-26 15:44:53 +01:00
|
|
|
return array(
|
|
|
|
'language' => 'en_US',
|
|
|
|
'timezone' => 'UTC',
|
|
|
|
'theme' => 'original',
|
|
|
|
'autoflush' => 15,
|
|
|
|
'autoflush_unread' => 45,
|
|
|
|
'frontend_updatecheck_interval' => 10,
|
|
|
|
'favicons' => 1,
|
|
|
|
'nocontent' => 0,
|
|
|
|
'image_proxy' => 0,
|
|
|
|
'original_marks_read' => 1,
|
|
|
|
'instapaper_enabled' => 0,
|
|
|
|
'pinboard_enabled' => 0,
|
|
|
|
'pinboard_tags' => 'miniflux',
|
|
|
|
'items_per_page' => 100,
|
|
|
|
'items_display_mode' => 'summaries',
|
|
|
|
'items_sorting_direction' => 'desc',
|
|
|
|
'redirect_nothing_to_read' => 'feeds',
|
|
|
|
'item_title_link' => 'full',
|
2013-12-23 03:25:54 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
function get_all($user_id)
|
2013-12-23 03:25:54 +01:00
|
|
|
{
|
2016-12-26 15:44:53 +01:00
|
|
|
$settings = Database::getInstance('db')
|
|
|
|
->hashtable(TABLE)
|
|
|
|
->eq('user_id', $user_id)
|
|
|
|
->getAll('key', 'value');
|
2013-12-23 03:25:54 +01:00
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
if (empty($settings)) {
|
|
|
|
save_defaults($user_id);
|
|
|
|
$settings = Database::getInstance('db')
|
|
|
|
->hashtable(TABLE)
|
|
|
|
->eq('user_id', $user_id)
|
|
|
|
->getAll('key', 'value');
|
2013-12-23 03:25:54 +01:00
|
|
|
}
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
return $settings;
|
2013-12-23 03:25:54 +01:00
|
|
|
}
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
function save_defaults($user_id)
|
2013-12-23 03:25:54 +01:00
|
|
|
{
|
2016-12-26 15:44:53 +01:00
|
|
|
return save($user_id, get_default_values());
|
2013-12-23 03:25:54 +01:00
|
|
|
}
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
function save($user_id, array $values)
|
2013-12-23 03:25:54 +01:00
|
|
|
{
|
2016-12-26 15:44:53 +01:00
|
|
|
$db = Database::getInstance('db');
|
|
|
|
$results = array();
|
|
|
|
$db->startTransaction();
|
2013-12-23 03:25:54 +01:00
|
|
|
|
|
|
|
if (isset($values['nocontent']) && (bool) $values['nocontent']) {
|
2016-12-26 15:44:53 +01:00
|
|
|
$db
|
|
|
|
->table(Model\Item\TABLE)
|
|
|
|
->eq('user_id', $user_id)
|
|
|
|
->update(array('content' => ''));
|
2013-12-23 03:25:54 +01:00
|
|
|
}
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
foreach ($values as $key => $value) {
|
|
|
|
if ($db->table(TABLE)->eq('user_id', $user_id)->eq('key', $key)->exists()) {
|
|
|
|
$results[] = $db->table(TABLE)
|
|
|
|
->eq('user_id', $user_id)
|
|
|
|
->eq('key', $key)
|
|
|
|
->update(array('value' => $value));
|
|
|
|
} else {
|
|
|
|
$results[] = $db->table(TABLE)->insert(array(
|
|
|
|
'key' => $key,
|
|
|
|
'value' => $value,
|
|
|
|
'user_id' => $user_id,
|
|
|
|
));
|
|
|
|
}
|
2014-12-24 16:47:24 +01:00
|
|
|
}
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
if (in_array(false, $results, true)) {
|
|
|
|
$db->cancelTransaction();
|
|
|
|
return false;
|
|
|
|
}
|
2014-12-24 16:47:24 +01:00
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
$db->closeTransaction();
|
|
|
|
SessionStorage::getInstance()->flushConfig();
|
|
|
|
return true;
|
2013-12-23 03:25:54 +01:00
|
|
|
}
|