miniflux-legacy/app/models/config.php

238 lines
5.9 KiB
PHP
Raw Permalink Normal View History

<?php
2016-08-25 03:17:58 +02:00
namespace Miniflux\Model\Config;
2016-08-25 03:17:58 +02:00
use Miniflux\Helper;
use Miniflux\Model;
2014-10-30 02:28:23 +01:00
use DirectoryIterator;
use Miniflux\Session\SessionStorage;
2014-02-08 20:13:14 +01:00
use PicoDb\Database;
2014-05-20 20:20:27 +02: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);
}
function is_language_rtl()
{
$languages = array(
'ar_AR'
);
return in_array(Helper\config('language'), $languages);
}
function get_languages()
{
2014-10-30 02:28:23 +01:00
return array(
'ar_AR' => 'عربي',
'cs_CZ' => 'Čeština',
'de_DE' => 'Deutsch',
'en_US' => 'English',
'es_ES' => 'Español',
'fr_FR' => 'Français',
2017-02-21 15:22:47 +01:00
'hu_HU' => 'Magyar',
'it_IT' => 'Italiano',
'ja_JP' => '日本語',
2017-11-02 05:09:32 +01:00
'pl_PL' => 'Polski',
'pt_BR' => 'Português',
2017-12-06 16:36:51 +01:00
'zh_CN' => '简体中文',
'zh_TW' => '繁體中文',
'sr_RS' => 'српски',
'sr_RS@latin' => 'srpski',
'ru_RU' => 'Русский',
'tr_TR' => 'Türkçe',
);
}
function get_themes()
{
$themes = array(
'original' => t('Default')
);
if (file_exists(THEME_DIRECTORY)) {
2014-10-30 02:28:23 +01:00
$dir = new DirectoryIterator(THEME_DIRECTORY);
foreach ($dir as $fileinfo) {
if (! $fileinfo->isDot() && $fileinfo->isDir()) {
$themes[$dir->getFilename()] = ucfirst($dir->getFilename());
}
}
}
return $themes;
}
function get_sorting_directions()
{
return array(
'asc' => t('Older items first'),
'desc' => t('Most recent first'),
);
}
function get_display_mode()
{
2016-04-18 01:44:45 +02:00
return array(
'titles' => t('Titles'),
2016-04-18 01:44:45 +02:00
'summaries' => t('Summaries'),
'full' => t('Full contents'),
2016-04-18 01:44:45 +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'),
'full' => t('Full contents'),
2016-04-18 01:44:45 +02:00
);
2016-02-27 20:21:18 +01:00
}
function get_autoflush_read_options()
{
return array(
'0' => t('Never'),
'-1' => t('Immediately'),
'1' => t('After %d day', 1),
'5' => t('After %d day', 5),
'15' => t('After %d day', 15),
'30' => t('After %d day', 30),
);
}
function get_autoflush_unread_options()
{
return array(
'0' => t('Never'),
'15' => t('After %d day', 15),
'30' => t('After %d day', 30),
'45' => t('After %d day', 45),
'60' => t('After %d day', 60),
);
}
function get_paging_options()
{
return array(
10 => 10,
20 => 20,
30 => 30,
50 => 50,
100 => 100,
150 => 150,
200 => 200,
250 => 250,
);
}
function get_nothing_to_read_redirections()
{
return array(
'feeds' => t('Subscriptions'),
'history' => t('History'),
'bookmarks' => t('Bookmarks'),
'nowhere' => t('Do not redirect me'),
);
}
function get_default_values()
{
return array(
'language' => 'en_US',
'timezone' => 'UTC',
'theme' => 'original',
'autoflush' => READING_REMOVE_READ_ITEMS,
'autoflush_unread' => READING_REMOVE_UNREAD_ITEMS,
'frontend_updatecheck_interval' => READING_FRONTEND_UPDATECHECK_INTERVAL,
'favicons' => READING_FAVICONS,
'nocontent' => READING_NOCONTENT,
'image_proxy' => 0,
'original_marks_read' => READING_ORIGINAL_MARKS_READ,
'instapaper_enabled' => 0,
'pinboard_enabled' => 0,
'pinboard_tags' => 'miniflux',
'items_per_page' => READING_ITEMS_PER_PAGE,
'items_display_mode' => READING_DISPLAY_MODE,
'items_sorting_direction' => READING_SORTING_DIRECTION,
'redirect_nothing_to_read' => READING_NOTHING_READ_REDIRECT,
'item_title_link' => READING_ITEM_TITLE_LINK,
);
}
function get_all($user_id)
{
$settings = Database::getInstance('db')
->hashtable(TABLE)
->eq('user_id', $user_id)
->getAll('key', 'value');
if (empty($settings)) {
save_defaults($user_id);
$settings = Database::getInstance('db')
->hashtable(TABLE)
->eq('user_id', $user_id)
->getAll('key', 'value');
}
return $settings;
}
function save_defaults($user_id)
{
return save($user_id, get_default_values());
}
function save($user_id, array $values)
{
$db = Database::getInstance('db');
$results = array();
$db->startTransaction();
if (isset($values['nocontent']) && (bool) $values['nocontent']) {
$db
->table(Model\Item\TABLE)
->eq('user_id', $user_id)
->update(array('content' => ''));
}
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
}
if (in_array(false, $results, true)) {
$db->cancelTransaction();
return false;
}
2014-12-24 16:47:24 +01:00
$db->closeTransaction();
SessionStorage::getInstance()->flushConfig();
return true;
}