aboutsummaryrefslogtreecommitdiff
path: root/lib/lib_rss.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-15 14:17:00 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-15 14:17:00 +0100
commiteaf6c2c33e3c058bd6890c9fb30308b13727b19d (patch)
tree6a797374b348e5a42ddd5b8dc26079525f9194eb /lib/lib_rss.php
parentcaa274c75b6a7471f09f9c21057749c686e155fb (diff)
parent4c143426712f75fa04999f4e8b3c0b6900bf062d (diff)
Merge branch 'dev' into beta
Diffstat (limited to 'lib/lib_rss.php')
-rw-r--r--lib/lib_rss.php130
1 files changed, 120 insertions, 10 deletions
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 264c69d58..083e87745 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -15,6 +15,17 @@ if (!function_exists('json_encode')) {
}
}
+/**
+ * Build a directory path by concatenating a list of directory names.
+ *
+ * @param $path_parts a list of directory names
+ * @return a string corresponding to the final pathname
+ */
+function join_path() {
+ $path_parts = func_get_args();
+ return join(DIRECTORY_SEPARATOR, $path_parts);
+}
+
//<Auto-loading>
function classAutoloader($class) {
if (strpos($class, 'FreshRSS') === 0) {
@@ -108,7 +119,8 @@ function html_only_entity_decode($text) {
}
function customSimplePie() {
- $limits = Minz_Configuration::limits();
+ $system_conf = Minz_Configuration::get('system');
+ $limits = $system_conf->limits;
$simplePie = new SimplePie();
$simplePie->set_useragent(_t('gen.freshrss') . '/' . FRESHRSS_VERSION . ' (' . PHP_OS . '; ' . FRESHRSS_WEBSITE . ') ' . SIMPLEPIE_NAME . '/' . SIMPLEPIE_VERSION);
$simplePie->set_cache_location(CACHE_PATH);
@@ -205,21 +217,53 @@ function uSecString() {
function invalidateHttpCache() {
Minz_Session::_param('touch', uTimeString());
- return touch(LOG_PATH . '/' . Minz_Session::param('currentUser', '_') . '.log');
+ return touch(join_path(DATA_PATH, 'users', Minz_Session::param('currentUser', '_'), 'log.txt'));
}
-function usernameFromPath($userPath) {
- if (preg_match('%/([A-Za-z0-9]{1,16})_user\.php$%', $userPath, $matches)) {
- return $matches[1];
- } else {
- return '';
+function listUsers() {
+ $final_list = array();
+ $base_path = join_path(DATA_PATH, 'users');
+ $dir_list = array_values(array_diff(
+ scandir($base_path),
+ array('..', '.', '_')
+ ));
+
+ foreach ($dir_list as $file) {
+ if (is_dir(join_path($base_path, $file))) {
+ $final_list[] = $file;
+ }
}
+
+ return $final_list;
}
-function listUsers() {
- return array_map('usernameFromPath', glob(DATA_PATH . '/*_user.php'));
+
+/**
+ * Register and return the configuration for a given user.
+ *
+ * Note this function has been created to generate temporary configuration
+ * objects. If you need a long-time configuration, please don't use this function.
+ *
+ * @param $username the name of the user of which we want the configuration.
+ * @return a Minz_Configuration object, null if the configuration cannot be loaded.
+ */
+function get_user_configuration($username) {
+ $namespace = time() . '_user_' . $username;
+ try {
+ Minz_Configuration::register($namespace,
+ join_path(USERS_PATH, $username, 'config.php'),
+ join_path(USERS_PATH, '_', 'config.default.php'));
+ } catch (Minz_ConfigurationNamespaceException $e) {
+ // namespace already exists, do nothing.
+ } catch (Minz_FileNotExistException $e) {
+ Minz_Log::warning($e->getMessage());
+ return null;
+ }
+
+ return Minz_Configuration::get($namespace);
}
+
function httpAuthUser() {
return isset($_SERVER['REMOTE_USER']) ? $_SERVER['REMOTE_USER'] : '';
}
@@ -284,7 +328,7 @@ function check_install_files() {
return array(
'data' => DATA_PATH && is_writable(DATA_PATH),
'cache' => CACHE_PATH && is_writable(CACHE_PATH),
- 'logs' => LOG_PATH && is_writable(LOG_PATH),
+ 'users' => USERS_PATH && is_writable(USERS_PATH),
'favicons' => is_writable(DATA_PATH . '/favicons'),
'persona' => is_writable(DATA_PATH . '/persona'),
'tokens' => is_writable(DATA_PATH . '/tokens'),
@@ -319,3 +363,69 @@ function check_install_database() {
return $status;
}
+
+/**
+ * Remove a directory recursively.
+ *
+ * From http://php.net/rmdir#110489
+ *
+ * @param $dir the directory to remove
+ */
+function recursive_unlink($dir) {
+ if (!is_dir($dir)) {
+ return true;
+ }
+
+ $files = array_diff(scandir($dir), array('.', '..'));
+ foreach ($files as $filename) {
+ $filename = $dir . '/' . $filename;
+ if (is_dir($filename)) {
+ @chmod($filename, 0777);
+ recursive_unlink($filename);
+ } else {
+ unlink($filename);
+ }
+ }
+
+ return rmdir($dir);
+}
+
+
+/**
+ * Remove queries where $get is appearing.
+ * @param $get the get attribute which should be removed.
+ * @param $queries an array of queries.
+ * @return the same array whithout those where $get is appearing.
+ */
+function remove_query_by_get($get, $queries) {
+ $final_queries = array();
+ foreach ($queries as $key => $query) {
+ if (empty($query['get']) || $query['get'] !== $get) {
+ $final_queries[$key] = $query;
+ }
+ }
+ return $final_queries;
+}
+
+
+/**
+ * Add a value in an array and take care it is unique.
+ * @param $array the array in which we add the value.
+ * @param $value the value to add.
+ */
+function array_push_unique(&$array, $value) {
+ $found = array_search($value, $array) !== false;
+ if (!$found) {
+ $array[] = $value;
+ }
+}
+
+
+/**
+ * Remove a value from an array.
+ * @param $array the array from wich value is removed.
+ * @param $value the value to remove.
+ */
+function array_remove(&$array, $value) {
+ $array = array_diff($array, array($value));
+}