]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #1093 from ArthurHoaro/feature/theme-translation
authorArthurHoaro <arthur@hoa.ro>
Mon, 26 Mar 2018 18:26:10 +0000 (20:26 +0200)
committerGitHub <noreply@github.com>
Mon, 26 Mar 2018 18:26:10 +0000 (20:26 +0200)
Load theme translations files automatically

23 files changed:
.htaccess
CHANGELOG.md
Doxyfile
Makefile
README.md
application/FileUtils.php
application/LinkFilter.php
application/NetscapeBookmarkUtils.php
application/Updater.php
application/Url.php
application/api/controllers/History.php
application/api/controllers/Links.php
doc/md/Download-and-Installation.md
doc/md/Upgrade-and-migration.md
docker/alpine/Dockerfile.armhf.latest
docker/alpine/Dockerfile.armhf.master
docker/alpine/Dockerfile.latest
docker/alpine/Dockerfile.master
index.php
plugins/markdown/markdown.php
tests/Updater/UpdaterTest.php
tests/plugins/test/test.php
tpl/vintage/loginform.html

index 19dd72a805e7b3bd170c87aabb25ad4764ca179a..7ba4744b262af9c1ca97f617c4bb60d9510808e9 100644 (file)
--- a/.htaccess
+++ b/.htaccess
@@ -6,6 +6,10 @@ RewriteEngine On
 # Prevent accessing subdirectories not managed by SCM
 RewriteRule ^(.git|doxygen|vendor) - [F]
 
+# Forward the "Authorization" HTTP header
+RewriteCond %{HTTP:Authorization} ^(.*)
+RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
+
 # REST API
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
index 0e737d8cbbc4ef45c51a7d304c65c12c9eff5bec..3218f4d83a1dbcfe9b4885418cc001e3577fd72c 100644 (file)
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 
 ## [v0.10.0](https://github.com/shaarli/Shaarli/releases/tag/v0.10.0) - UNPUBLISHED
 
+
+## [v0.9.6](https://github.com/shaarli/Shaarli/releases/tag/v0.9.6) - 2018-03-25
+## Changed
+- htaccess: prevent accessing resources not managed by SCM
+- htaccess: always forward the 'Authorization' HTTP header
+
+
 ## [v0.9.5](https://github.com/shaarli/Shaarli/releases/tag/v0.9.5) - 2018-02-02
 ### Fixed
 - Fix a warning happening when `php-intl` is not installed on the system
index 9a596b539b7b59fe49fc99b090b002d42f31cf86..30f9556428457678228b9bde10a53e89cce6806e 100644 (file)
--- a/Doxyfile
+++ b/Doxyfile
@@ -804,6 +804,7 @@ RECURSIVE              = YES
 # run.
 
 EXCLUDE                = vendor \
+                         data \
                          tpl \
                          inc \
                          doc \
index d659d908e45aad561638d8f7617b30b3ed51c35a..5e3ae26d11d89ea243ecf0f86344f39f6f691a17 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -192,7 +192,7 @@ authors:
 ### generate Doxygen documentation
 doxygen: clean
        @rm -rf doxygen
-       @( cat Doxyfile ; echo "PROJECT_NUMBER=`git describe`" ) | doxygen -
+       @doxygen Doxyfile
 
 ### generate HTML documentation from Markdown pages with MkDocs
 htmldoc:
@@ -206,4 +206,4 @@ htmldoc:
 
 ### Generate Shaarli's translation compiled file (.mo)
 translate:
-       @find inc/languages/ -name shaarli.po -execdir msgfmt shaarli.po -o shaarli.mo \;
\ No newline at end of file
+       @find inc/languages/ -name shaarli.po -execdir msgfmt shaarli.po -o shaarli.mo \;
index 106384d8475773b1a44a8a9ac73ade8825a5e051..df9018b6b488639761254bc0cc9e484c2377b86b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -9,7 +9,7 @@ _It is designed to be personal (single-user), fast and handy._
 [![](https://img.shields.io/badge/stable-v0.8.6-blue.svg)](https://github.com/shaarli/Shaarli/releases/tag/v0.8.6)
 [![](https://img.shields.io/travis/shaarli/Shaarli/stable.svg?label=stable)](https://travis-ci.org/shaarli/Shaarli)
 &bull;
-[![](https://img.shields.io/badge/latest-v0.9.5-blue.svg)](https://github.com/shaarli/Shaarli/releases/tag/v0.9.5)
+[![](https://img.shields.io/badge/latest-v0.9.6-blue.svg)](https://github.com/shaarli/Shaarli/releases/tag/v0.9.6)
 [![](https://img.shields.io/travis/shaarli/Shaarli/latest.svg?label=latest)](https://travis-ci.org/shaarli/Shaarli)
 &bull;
 [![](https://img.shields.io/badge/master-v0.10.x-blue.svg)](https://github.com/shaarli/Shaarli)
index 918cb83b3c66cbc5aee40a0c704f1010aa339c1e..b89ea12bcc26cb7e67b09eaa60f11abf9b0c552a 100644 (file)
@@ -37,7 +37,7 @@ class FileUtils
         if (is_file($file) && !is_writeable($file)) {
             // The datastore exists but is not writeable
             throw new IOException($file);
-        } else if (!is_file($file) && !is_writeable(dirname($file))) {
+        } elseif (!is_file($file) && !is_writeable(dirname($file))) {
             // The datastore does not exist and its parent directory is not writeable
             throw new IOException(dirname($file));
         }
index 12376e27dc3aefe540960afbb0c194ec6ad55c16..e52239b84c89f4c1b387b02dd399e3c25e4bf23a 100644 (file)
@@ -117,7 +117,7 @@ class LinkFilter
         foreach ($this->links as $key => $value) {
             if ($value['private'] && $visibility === 'private') {
                 $out[$key] = $value;
-            } else if (! $value['private'] && $visibility === 'public') {
+            } elseif (! $value['private'] && $visibility === 'public') {
                 $out[$key] = $value;
             }
         }
@@ -210,7 +210,7 @@ class LinkFilter
             if ($visibility !== 'all') {
                 if (! $link['private'] && $visibility === 'private') {
                     continue;
-                } else if ($link['private'] && $visibility === 'public') {
+                } elseif ($link['private'] && $visibility === 'public') {
                     continue;
                 }
             }
@@ -337,7 +337,7 @@ class LinkFilter
             if ($visibility !== 'all') {
                 if (! $link['private'] && $visibility === 'private') {
                     continue;
-                } else if ($link['private'] && $visibility === 'public') {
+                } elseif ($link['private'] && $visibility === 'public') {
                     continue;
                 }
             }
@@ -380,7 +380,7 @@ class LinkFilter
             if ($visibility !== 'all') {
                 if (! $link['private'] && $visibility === 'private') {
                     continue;
-                } else if ($link['private'] && $visibility === 'public') {
+                } elseif ($link['private'] && $visibility === 'public') {
                     continue;
                 }
             }
index 2aa2da3b379958b2378e57d24467cf0cac50db5a..b4d16d00bb991e2e9b031a2bb9f5c1d352030176 100644 (file)
@@ -154,10 +154,10 @@ class NetscapeBookmarkUtils
             if (empty($post['privacy']) || $post['privacy'] == 'default') {
                 // use value from the imported file
                 $private = $bkm['pub'] == '1' ? 0 : 1;
-            } else if ($post['privacy'] == 'private') {
+            } elseif ($post['privacy'] == 'private') {
                 // all imported links are private
                 $private = 1;
-            } else if ($post['privacy'] == 'public') {
+            } elseif ($post['privacy'] == 'public') {
                 // all imported links are public
                 $private = 0;
             }
index f07e76978f170f7c8839f399c9d9c93e319d6384..dece2c020d297fdf13bf8773b76cb37895328025 100644 (file)
@@ -457,6 +457,32 @@ class Updater
         }
         return true;
     }
+
+    /**
+     * Add download size and timeout to the configuration file
+     *
+     * @return bool true if the update is successful, false otherwise.
+     */
+    public function updateMethodDownloadSizeAndTimeoutConf()
+    {
+        if ($this->conf->exists('general.download_max_size')
+            && $this->conf->exists('general.download_timeout')
+        ) {
+            return true;
+        }
+
+        if (! $this->conf->exists('general.download_max_size')) {
+            $this->conf->set('general.download_max_size', 1024*1024*4);
+        }
+
+        if (! $this->conf->exists('general.download_timeout')) {
+            $this->conf->set('general.download_timeout', 30);
+        }
+
+        $this->conf->write($this->isLoggedIn);
+
+        return true;
+    }
 }
 
 /**
index 21c17eccaa25644c72134795570cff816e2dad8d..6b9870f0c1bb468ebafd67e2d71123411f598a0c 100644 (file)
@@ -81,7 +81,7 @@ function whitelist_protocols($url, $protocols)
     // Protocol not allowed: we remove it and replace it with http
     if ($protocol === 1 && ! in_array($match[1], $protocols)) {
         $url = str_replace($match[0], 'http://', $url);
-    } else if ($protocol !== 1) {
+    } elseif ($protocol !== 1) {
         $url = 'http://' . $url;
     }
     return $url;
index 2ff9deaf24d98f4fb1f43356184fdd69996c223a..5cc453bfadd1decd5649d5cceab43ab342140b53 100644 (file)
@@ -36,7 +36,7 @@ class History extends ApiController
         if (empty($offset)) {
             $offset = 0;
         }
-        else if (ctype_digit($offset)) {
+        elseif (ctype_digit($offset)) {
             $offset = (int) $offset;
         } else {
             throw new ApiBadParametersException('Invalid offset');
@@ -46,7 +46,7 @@ class History extends ApiController
         $limit = $request->getParam('limit');
         if (empty($limit)) {
             $limit = count($history);
-        } else if (ctype_digit($limit)) {
+        } elseif (ctype_digit($limit)) {
             $limit = (int) $limit;
         } else {
             throw new ApiBadParametersException('Invalid limit');
index eb78dd266608d8690a033bf56b78c234514bd1ae..3a9c03553a30fbe5247e48a2a6c30eb4f34e7b51 100644 (file)
@@ -59,9 +59,9 @@ class Links extends ApiController
         $limit = $request->getParam('limit');
         if (empty($limit)) {
             $limit = self::$DEFAULT_LIMIT;
-        } else if (ctype_digit($limit)) {
+        } elseif (ctype_digit($limit)) {
             $limit = intval($limit);
-        } else if ($limit === 'all') {
+        } elseif ($limit === 'all') {
             $limit = count($links);
         } else {
             throw new ApiBadParametersException('Invalid limit');
index 0fdbd27de59ab5b184b3c9812cb1479d6ab40e76..05f0c8f2db3d5fe6bcddf32ab5d6c40c15eece6a 100644 (file)
@@ -25,11 +25,11 @@ Using one of the following methods:
 
 In most cases, you should download the latest Shaarli release from the [releases](https://github.com/shaarli/Shaarli/releases) page. **Download our *shaarli-full* archive** to include dependencies.
 
-The current latest released version is `v0.9.3`
+The current latest released version is `v0.9.6`
 
 ```bash
-$ wget https://github.com/shaarli/Shaarli/releases/download/v0.9.3/shaarli-v0.9.3-full.zip
-$ unzip shaarli-v0.9.3-full.zip
+$ wget https://github.com/shaarli/Shaarli/releases/download/v0.9.6/shaarli-v0.9.6-full.zip
+$ unzip shaarli-v0.9.6-full.zip
 $ mv Shaarli /path/to/shaarli/
 ```
 
index f666be751034c9b6d6e2f842c89435892b92e7dc..ac24ff34053c64e818ead7df366bb2b9968e75ac 100644 (file)
@@ -3,7 +3,7 @@
 ### Note your current version
 
 If anything goes wrong, it's important for us to know which version you're upgrading from.
-The current version is present in the `version.php` file.
+The current version is present in the `shaarli_version.php` file.
 
 ### Backup your data
 
index c923834abb9871ae70135af61b50cabefcf998ee..824a192633bbb7c2fb78d682644900c97805e8eb 100644 (file)
@@ -37,7 +37,9 @@ RUN curl -L https://github.com/shaarli/Shaarli/archive/latest.tar.gz | tar xzf -
     && cd shaarli \
     && composer --prefer-dist --no-dev install \
     && rm -rf ~/.composer \
-    && chown -R nginx:nginx .
+    && chown -R nginx:nginx . \
+    && ln -sf /dev/stdout /var/log/nginx/shaarli.access.log \
+    && ln -sf /dev/stderr /var/log/nginx/shaarli.error.log
 
 VOLUME /var/www/shaarli/data
 
index 7f1bdf85a19c7e663253d2262d9615e5bc041533..6c89adc3b9f734828f9e47257d4d1cea2a36c089 100644 (file)
@@ -37,7 +37,9 @@ RUN curl -L https://github.com/shaarli/Shaarli/archive/master.tar.gz | tar xzf -
     && cd shaarli \
     && composer --prefer-dist --no-dev install \
     && rm -rf ~/.composer \
-    && chown -R nginx:nginx .
+    && chown -R nginx:nginx . \
+    && ln -sf /dev/stdout /var/log/nginx/shaarli.access.log \
+    && ln -sf /dev/stderr /var/log/nginx/shaarli.error.log
 
 VOLUME /var/www/shaarli/data
 
index e9015c13c39b7b2d490843aa02088e2b9c723be4..755d87517c1ec8c1ae156bccedbd30ffb6b555be 100644 (file)
@@ -42,7 +42,12 @@ RUN rm -rf /etc/php7/php-fpm.d/www.conf \
 WORKDIR /var/www
 COPY --from=composer /app/shaarli shaarli
 
+RUN chown -R nginx:nginx . \
+    && ln -sf /dev/stdout /var/log/nginx/shaarli.access.log \
+    && ln -sf /dev/stderr /var/log/nginx/shaarli.error.log
+
 VOLUME /var/www/shaarli/data
+
 EXPOSE 80
 
 ENTRYPOINT ["/bin/s6-svscan", "/etc/services.d"]
index 9cb4dec49565d34337051088e43e0fcffed98b3d..0472947f54d90854b9966185daaf9da7d341df73 100644 (file)
@@ -42,7 +42,10 @@ RUN rm -rf /etc/php7/php-fpm.d/www.conf \
 WORKDIR /var/www
 COPY --from=composer /app/shaarli shaarli
 
-RUN chown -R nginx:nginx .
+RUN chown -R nginx:nginx . \
+    && ln -sf /dev/stdout /var/log/nginx/shaarli.access.log \
+    && ln -sf /dev/stderr /var/log/nginx/shaarli.error.log
+
 VOLUME /var/www/shaarli/data
 
 EXPOSE 80
index bd34c0cd05aeab499d26fc8b650218544adf53b1..dbc2bb3b2f37336f06de4c9d1287c15bd059dad0 100644 (file)
--- a/index.php
+++ b/index.php
@@ -887,7 +887,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
         if (empty($params['searchtags'])) {
             $params['searchtags'] = trim($_GET['addtag']);
         }
-        else if ($addtag) {
+        elseif ($addtag) {
             $params['searchtags'] = trim($params['searchtags']).' '.trim($_GET['addtag']);
         }
 
@@ -953,7 +953,7 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
             } else {
                 unset($_SESSION['visibility']);
             }
-        } else if ($_GET['visibility'] === 'public') {
+        } elseif ($_GET['visibility'] === 'public') {
             if (empty($_SESSION['visibility']) || $_SESSION['visibility'] !== 'public') {
                 // See only public links
                 $_SESSION['visibility'] = 'public';
@@ -1093,7 +1093,6 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
             $conf->set('general.title', escape($_POST['title']));
             $conf->set('general.header_link', escape($_POST['titleLink']));
             $conf->set('resource.theme', escape($_POST['theme']));
-            $conf->set('redirector.url', escape($_POST['redirector']));
             $conf->set('security.session_protection_disabled', !empty($_POST['disablesessionprotection']));
             $conf->set('privacy.default_private_links', !empty($_POST['privateLinkByDefault']));
             $conf->set('feed.rss_permalinks', !empty($_POST['enableRssPermalinks']));
@@ -1126,7 +1125,6 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
             $PAGE->assign('title', $conf->get('general.title'));
             $PAGE->assign('theme', $conf->get('resource.theme'));
             $PAGE->assign('theme_available', ThemeUtils::getThemes($conf->get('resource.raintpl_tpl')));
-            $PAGE->assign('redirector', $conf->get('redirector.url'));
             list($continents, $cities) = generateTimeZoneData(
                 timezone_identifiers_list(),
                 $conf->get('general.timezone')
@@ -1376,7 +1374,12 @@ function renderPage($conf, $pluginManager, $LINKSDB, $history, $sessionManager,
             if (empty($title) && strpos(get_url_scheme($url), 'http') !== false) {
                 // Short timeout to keep the application responsive
                 // The callback will fill $charset and $title with data from the downloaded page.
-                get_http_response($url, 25, 4194304, get_curl_download_callback($charset, $title));
+                get_http_response(
+                    $url,
+                    $conf->get('general.download_max_size', 4194304),
+                    $conf->get('general.download_timeout', 30),
+                    get_curl_download_callback($charset, $title)
+                );
                 if (! empty($title) && strtolower($charset) != 'utf-8') {
                     $title = mb_convert_encoding($title, 'utf-8', $charset);
                 }
index 6b4aabf3ae8ad6798ab40bb12ba8b499c7b13609..2f24e4172b1d3c66ca1eb0f1a9bf66ed4ecde606 100644 (file)
@@ -288,7 +288,7 @@ function sanitize_html($description)
             $description);
     }
     $description = preg_replace(
-        '#(<[^>]+)on[a-z]*="?[^ "]*"?#is',
+        '#(<[^>]+\s)on[a-z]*="?[^ "]*"?#is',
         '$1',
         $description);
     return $description;
index fed175df531bd5a336c25efd87d1fd51081ca99c..94e3c7d307c4bb46f1e45d8cf523852ee3b7ba88 100644 (file)
@@ -620,4 +620,68 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
         $this->assertTrue($updater->updateMethodAtomDefault());
         $this->assertTrue($this->conf->get('feed.show_atom'));
     }
+
+    /**
+     * Test updateMethodDownloadSizeAndTimeoutConf, it should be set if none is already defined.
+     */
+    public function testUpdateMethodDownloadSizeAndTimeoutConf()
+    {
+        $sandboxConf = 'sandbox/config';
+        copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
+        $this->conf = new ConfigManager($sandboxConf);
+        $updater = new Updater([], [], $this->conf, true);
+        $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
+        $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
+        $this->assertEquals(30, $this->conf->get('general.download_timeout'));
+
+        $this->conf = new ConfigManager($sandboxConf);
+        $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
+        $this->assertEquals(30, $this->conf->get('general.download_timeout'));
+    }
+
+    /**
+     * Test updateMethodDownloadSizeAndTimeoutConf, it shouldn't be set if it is already defined.
+     */
+    public function testUpdateMethodDownloadSizeAndTimeoutConfIgnore()
+    {
+        $sandboxConf = 'sandbox/config';
+        copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
+        $this->conf = new ConfigManager($sandboxConf);
+        $this->conf->set('general.download_max_size', 38);
+        $this->conf->set('general.download_timeout', 70);
+        $updater = new Updater([], [], $this->conf, true);
+        $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
+        $this->assertEquals(38, $this->conf->get('general.download_max_size'));
+        $this->assertEquals(70, $this->conf->get('general.download_timeout'));
+    }
+
+    /**
+     * Test updateMethodDownloadSizeAndTimeoutConf, only the maz size should be set here.
+     */
+    public function testUpdateMethodDownloadSizeAndTimeoutConfOnlySize()
+    {
+        $sandboxConf = 'sandbox/config';
+        copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
+        $this->conf = new ConfigManager($sandboxConf);
+        $this->conf->set('general.download_max_size', 38);
+        $updater = new Updater([], [], $this->conf, true);
+        $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
+        $this->assertEquals(38, $this->conf->get('general.download_max_size'));
+        $this->assertEquals(30, $this->conf->get('general.download_timeout'));
+    }
+
+    /**
+     * Test updateMethodDownloadSizeAndTimeoutConf, only the time out should be set here.
+     */
+    public function testUpdateMethodDownloadSizeAndTimeoutConfOnlyTimeout()
+    {
+        $sandboxConf = 'sandbox/config';
+        copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
+        $this->conf = new ConfigManager($sandboxConf);
+        $this->conf->set('general.download_timeout', 3);
+        $updater = new Updater([], [], $this->conf, true);
+        $this->assertTrue($updater->updateMethodDownloadSizeAndTimeoutConf());
+        $this->assertEquals(4194304, $this->conf->get('general.download_max_size'));
+        $this->assertEquals(3, $this->conf->get('general.download_timeout'));
+    }
 }
index 3d750c902195dc2a0d3bfdf13687a0c2c5bc3eba..2aaf51223e326e108451b0ba77b026db7828b6d0 100644 (file)
@@ -11,7 +11,7 @@ function hook_test_random($data)
 {
     if (isset($data['_PAGE_']) && $data['_PAGE_'] == 'test') {
         $data[1] = 'page test';
-    } else if (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) {
+    } elseif (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) {
         $data[1] = 'loggedin';
     } else {
         $data[1] = $data[0];
index 2c9b710e8cc344af87f94aa6d5bce55b0ba37523..0f7d6387e8ec07e2dfc93b16afc23dfdc203c7c0 100644 (file)
@@ -13,7 +13,7 @@
   {include="page.header"}
 
   <div id="headerform">
-    {if="!ban_canLogin($conf)"}
+    {if="!$user_can_login"}
       You have been banned from login after too many failed attempts. Try later.
     {else}
       <form method="post" name="loginform">