diff options
-rw-r--r-- | .gitattributes | 31 | ||||
-rw-r--r-- | application/Url.php | 12 | ||||
-rw-r--r-- | docker/.htaccess | 2 | ||||
-rw-r--r-- | docker/development/Dockerfile | 28 | ||||
-rw-r--r-- | docker/development/IMAGE.md | 10 | ||||
-rw-r--r-- | docker/development/nginx.conf | 64 | ||||
-rw-r--r-- | docker/development/supervised.conf | 13 | ||||
-rw-r--r-- | docker/production/Dockerfile | 20 | ||||
-rw-r--r-- | docker/production/IMAGE.md | 5 | ||||
-rw-r--r-- | docker/production/nginx.conf | 56 | ||||
-rw-r--r-- | docker/production/stable/Dockerfile | 20 | ||||
-rw-r--r-- | docker/production/stable/IMAGE.md | 5 | ||||
-rw-r--r-- | docker/production/stable/nginx.conf | 56 | ||||
-rw-r--r-- | docker/production/stable/supervised.conf | 13 | ||||
-rw-r--r-- | docker/production/supervised.conf | 13 | ||||
-rw-r--r-- | index.php | 18 | ||||
-rw-r--r-- | plugins/wallabag/README.md | 25 | ||||
-rw-r--r-- | plugins/wallabag/WallabagInstance.php | 71 | ||||
-rw-r--r-- | plugins/wallabag/config.php.dist | 3 | ||||
-rw-r--r-- | plugins/wallabag/wallabag.html | 2 | ||||
-rw-r--r-- | plugins/wallabag/wallabag.php | 17 | ||||
-rw-r--r-- | tests/Url/UrlTest.php | 11 | ||||
-rw-r--r-- | tests/plugins/PluginWallabagTest.php | 4 | ||||
-rw-r--r-- | tests/plugins/WallabagInstanceTest.php | 60 |
24 files changed, 539 insertions, 20 deletions
diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..aaf6a39e --- /dev/null +++ b/.gitattributes | |||
@@ -0,0 +1,31 @@ | |||
1 | # Set default behavior | ||
2 | * text=auto eol=lf | ||
3 | |||
4 | # Ensure sources are processed | ||
5 | *.conf text | ||
6 | *.css text | ||
7 | *.html text diff=html | ||
8 | *.js text | ||
9 | *.md text | ||
10 | *.php text diff=php | ||
11 | Dockerfile text | ||
12 | |||
13 | # Do not alter images nor minified scripts | ||
14 | *.ico binary | ||
15 | *.jpg binary | ||
16 | *.png binary | ||
17 | *.min.css binary | ||
18 | *.min.js binary | ||
19 | |||
20 | # Exclude from Git archives | ||
21 | .gitattributes export-ignore | ||
22 | .gitignore export-ignore | ||
23 | .travis.yml export-ignore | ||
24 | composer.json export-ignore | ||
25 | doc/**/*.json export-ignore | ||
26 | doc/**/*.md export-ignore | ||
27 | docker/ export-ignore | ||
28 | Doxyfile export-ignore | ||
29 | Makefile export-ignore | ||
30 | phpunit.xml export-ignore | ||
31 | tests/ export-ignore | ||
diff --git a/application/Url.php b/application/Url.php index af43b457..d80c9c58 100644 --- a/application/Url.php +++ b/application/Url.php | |||
@@ -52,6 +52,18 @@ function get_url_scheme($url) | |||
52 | } | 52 | } |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Adds a trailing slash at the end of URL if necessary. | ||
56 | * | ||
57 | * @param string $url URL to check/edit. | ||
58 | * | ||
59 | * @return string $url URL with a end trailing slash. | ||
60 | */ | ||
61 | function add_trailing_slash($url) | ||
62 | { | ||
63 | return $url . (!endsWith($url, '/') ? '/' : ''); | ||
64 | } | ||
65 | |||
66 | /** | ||
55 | * URL representation and cleanup utilities | 67 | * URL representation and cleanup utilities |
56 | * | 68 | * |
57 | * Form | 69 | * Form |
diff --git a/docker/.htaccess b/docker/.htaccess new file mode 100644 index 00000000..b584d98c --- /dev/null +++ b/docker/.htaccess | |||
@@ -0,0 +1,2 @@ | |||
1 | Allow from none | ||
2 | Deny from all | ||
diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile new file mode 100644 index 00000000..2ed59b89 --- /dev/null +++ b/docker/development/Dockerfile | |||
@@ -0,0 +1,28 @@ | |||
1 | FROM debian:jessie | ||
2 | MAINTAINER Shaarli Community | ||
3 | |||
4 | RUN apt-get update \ | ||
5 | && apt-get install -y \ | ||
6 | nginx-light php5-fpm php5-gd supervisor \ | ||
7 | git nano | ||
8 | |||
9 | ADD https://getcomposer.org/composer.phar /usr/local/bin/composer | ||
10 | RUN chmod 755 /usr/local/bin/composer | ||
11 | |||
12 | COPY nginx.conf /etc/nginx/nginx.conf | ||
13 | COPY supervised.conf /etc/supervisor/conf.d/supervised.conf | ||
14 | RUN echo "<?php phpinfo(); ?>" > /var/www/index.php | ||
15 | |||
16 | WORKDIR /var/www | ||
17 | RUN rm -rf html \ | ||
18 | && git clone https://github.com/shaarli/Shaarli.git shaarli \ | ||
19 | && chown -R www-data:www-data . | ||
20 | |||
21 | WORKDIR /var/www/shaarli | ||
22 | RUN composer install | ||
23 | |||
24 | VOLUME /var/www/shaarli/data | ||
25 | |||
26 | EXPOSE 80 | ||
27 | |||
28 | CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"] | ||
diff --git a/docker/development/IMAGE.md b/docker/development/IMAGE.md new file mode 100644 index 00000000..e2ff0f0e --- /dev/null +++ b/docker/development/IMAGE.md | |||
@@ -0,0 +1,10 @@ | |||
1 | ## shaarli:dev | ||
2 | - [Debian 8 Jessie](https://hub.docker.com/_/debian/) | ||
3 | - [PHP5-FPM](http://php-fpm.org/) | ||
4 | - [Nginx](http://nginx.org/) | ||
5 | - [Shaarli](https://github.com/shaarli/Shaarli) | ||
6 | |||
7 | ### Development tools | ||
8 | - [composer](https://getcomposer.org/) | ||
9 | - [git](http://git-scm.com/) | ||
10 | - [nano](http://www.nano-editor.org/) | ||
diff --git a/docker/development/nginx.conf b/docker/development/nginx.conf new file mode 100644 index 00000000..cda09b56 --- /dev/null +++ b/docker/development/nginx.conf | |||
@@ -0,0 +1,64 @@ | |||
1 | user www-data www-data; | ||
2 | daemon off; | ||
3 | worker_processes 4; | ||
4 | |||
5 | events { | ||
6 | worker_connections 768; | ||
7 | } | ||
8 | |||
9 | http { | ||
10 | include mime.types; | ||
11 | default_type application/octet-stream; | ||
12 | keepalive_timeout 20; | ||
13 | |||
14 | index index.html index.php; | ||
15 | |||
16 | server { | ||
17 | listen 80; | ||
18 | root /var/www/shaarli; | ||
19 | |||
20 | access_log /var/log/nginx/shaarli.access.log; | ||
21 | error_log /var/log/nginx/shaarli.error.log; | ||
22 | |||
23 | location /phpinfo/ { | ||
24 | # add a PHP info page for convenience | ||
25 | fastcgi_pass unix:/var/run/php5-fpm.sock; | ||
26 | fastcgi_index index.php; | ||
27 | fastcgi_param SCRIPT_FILENAME /var/www/index.php; | ||
28 | include fastcgi_params; | ||
29 | } | ||
30 | |||
31 | location ~ /\. { | ||
32 | # deny access to dotfiles | ||
33 | access_log off; | ||
34 | log_not_found off; | ||
35 | deny all; | ||
36 | } | ||
37 | |||
38 | location ~ ~$ { | ||
39 | # deny access to temp editor files, e.g. "script.php~" | ||
40 | access_log off; | ||
41 | log_not_found off; | ||
42 | deny all; | ||
43 | } | ||
44 | |||
45 | location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { | ||
46 | # cache static assets | ||
47 | expires max; | ||
48 | add_header Pragma public; | ||
49 | add_header Cache-Control "public, must-revalidate, proxy-revalidate"; | ||
50 | } | ||
51 | |||
52 | location ~ (index)\.php$ { | ||
53 | # filter and proxy PHP requests to PHP-FPM | ||
54 | fastcgi_pass unix:/var/run/php5-fpm.sock; | ||
55 | fastcgi_index index.php; | ||
56 | include fastcgi.conf; | ||
57 | } | ||
58 | |||
59 | location ~ \.php$ { | ||
60 | # deny access to all other PHP scripts | ||
61 | deny all; | ||
62 | } | ||
63 | } | ||
64 | } | ||
diff --git a/docker/development/supervised.conf b/docker/development/supervised.conf new file mode 100644 index 00000000..5acd9795 --- /dev/null +++ b/docker/development/supervised.conf | |||
@@ -0,0 +1,13 @@ | |||
1 | [program:php5-fpm] | ||
2 | command=/usr/sbin/php5-fpm -F | ||
3 | priority=5 | ||
4 | autostart=true | ||
5 | autorestart=true | ||
6 | |||
7 | [program:nginx] | ||
8 | command=/usr/sbin/nginx | ||
9 | priority=10 | ||
10 | autostart=true | ||
11 | autorestart=true | ||
12 | stdout_events_enabled=true | ||
13 | stderr_events_enabled=true | ||
diff --git a/docker/production/Dockerfile b/docker/production/Dockerfile new file mode 100644 index 00000000..3db4eb56 --- /dev/null +++ b/docker/production/Dockerfile | |||
@@ -0,0 +1,20 @@ | |||
1 | FROM debian:jessie | ||
2 | MAINTAINER Shaarli Community | ||
3 | |||
4 | RUN apt-get update \ | ||
5 | && apt-get install -y curl nginx-light php5-fpm php5-gd supervisor | ||
6 | |||
7 | COPY nginx.conf /etc/nginx/nginx.conf | ||
8 | COPY supervised.conf /etc/supervisor/conf.d/supervised.conf | ||
9 | |||
10 | WORKDIR /var/www | ||
11 | RUN rm -rf html \ | ||
12 | && curl -L https://github.com/shaarli/Shaarli/archive/master.tar.gz | tar xvzf - \ | ||
13 | && mv Shaarli-master shaarli \ | ||
14 | && chown -R www-data:www-data shaarli | ||
15 | |||
16 | VOLUME /var/www/shaarli/data | ||
17 | |||
18 | EXPOSE 80 | ||
19 | |||
20 | CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"] | ||
diff --git a/docker/production/IMAGE.md b/docker/production/IMAGE.md new file mode 100644 index 00000000..6f827b35 --- /dev/null +++ b/docker/production/IMAGE.md | |||
@@ -0,0 +1,5 @@ | |||
1 | ## shaarli:latest | ||
2 | - [Debian 8 Jessie](https://hub.docker.com/_/debian/) | ||
3 | - [PHP5-FPM](http://php-fpm.org/) | ||
4 | - [Nginx](http://nginx.org/) | ||
5 | - [Shaarli](https://github.com/shaarli/Shaarli) | ||
diff --git a/docker/production/nginx.conf b/docker/production/nginx.conf new file mode 100644 index 00000000..e23c4587 --- /dev/null +++ b/docker/production/nginx.conf | |||
@@ -0,0 +1,56 @@ | |||
1 | user www-data www-data; | ||
2 | daemon off; | ||
3 | worker_processes 4; | ||
4 | |||
5 | events { | ||
6 | worker_connections 768; | ||
7 | } | ||
8 | |||
9 | http { | ||
10 | include mime.types; | ||
11 | default_type application/octet-stream; | ||
12 | keepalive_timeout 20; | ||
13 | |||
14 | index index.html index.php; | ||
15 | |||
16 | server { | ||
17 | listen 80; | ||
18 | root /var/www/shaarli; | ||
19 | |||
20 | access_log /var/log/nginx/shaarli.access.log; | ||
21 | error_log /var/log/nginx/shaarli.error.log; | ||
22 | |||
23 | location ~ /\. { | ||
24 | # deny access to dotfiles | ||
25 | access_log off; | ||
26 | log_not_found off; | ||
27 | deny all; | ||
28 | } | ||
29 | |||
30 | location ~ ~$ { | ||
31 | # deny access to temp editor files, e.g. "script.php~" | ||
32 | access_log off; | ||
33 | log_not_found off; | ||
34 | deny all; | ||
35 | } | ||
36 | |||
37 | location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { | ||
38 | # cache static assets | ||
39 | expires max; | ||
40 | add_header Pragma public; | ||
41 | add_header Cache-Control "public, must-revalidate, proxy-revalidate"; | ||
42 | } | ||
43 | |||
44 | location ~ (index)\.php$ { | ||
45 | # filter and proxy PHP requests to PHP-FPM | ||
46 | fastcgi_pass unix:/var/run/php5-fpm.sock; | ||
47 | fastcgi_index index.php; | ||
48 | include fastcgi.conf; | ||
49 | } | ||
50 | |||
51 | location ~ \.php$ { | ||
52 | # deny access to all other PHP scripts | ||
53 | deny all; | ||
54 | } | ||
55 | } | ||
56 | } | ||
diff --git a/docker/production/stable/Dockerfile b/docker/production/stable/Dockerfile new file mode 100644 index 00000000..2bb3948c --- /dev/null +++ b/docker/production/stable/Dockerfile | |||
@@ -0,0 +1,20 @@ | |||
1 | FROM debian:jessie | ||
2 | MAINTAINER Shaarli Community | ||
3 | |||
4 | RUN apt-get update \ | ||
5 | && apt-get install -y curl nginx-light php5-fpm php5-gd supervisor | ||
6 | |||
7 | COPY nginx.conf /etc/nginx/nginx.conf | ||
8 | COPY supervised.conf /etc/supervisor/conf.d/supervised.conf | ||
9 | |||
10 | WORKDIR /var/www | ||
11 | RUN rm -rf html \ | ||
12 | && curl -L https://github.com/shaarli/Shaarli/archive/stable.tar.gz | tar xvzf - \ | ||
13 | && mv Shaarli-stable shaarli \ | ||
14 | && chown -R www-data:www-data shaarli | ||
15 | |||
16 | VOLUME /var/www/shaarli/data | ||
17 | |||
18 | EXPOSE 80 | ||
19 | |||
20 | CMD ["/usr/bin/supervisord", "-n", "-c", "/etc/supervisor/supervisord.conf"] | ||
diff --git a/docker/production/stable/IMAGE.md b/docker/production/stable/IMAGE.md new file mode 100644 index 00000000..d85b1d7a --- /dev/null +++ b/docker/production/stable/IMAGE.md | |||
@@ -0,0 +1,5 @@ | |||
1 | ## shaarli:stable | ||
2 | - [Debian 8 Jessie](https://hub.docker.com/_/debian/) | ||
3 | - [PHP5-FPM](http://php-fpm.org/) | ||
4 | - [Nginx](http://nginx.org/) | ||
5 | - [Shaarli (stable)](https://github.com/shaarli/Shaarli/tree/stable) | ||
diff --git a/docker/production/stable/nginx.conf b/docker/production/stable/nginx.conf new file mode 100644 index 00000000..e23c4587 --- /dev/null +++ b/docker/production/stable/nginx.conf | |||
@@ -0,0 +1,56 @@ | |||
1 | user www-data www-data; | ||
2 | daemon off; | ||
3 | worker_processes 4; | ||
4 | |||
5 | events { | ||
6 | worker_connections 768; | ||
7 | } | ||
8 | |||
9 | http { | ||
10 | include mime.types; | ||
11 | default_type application/octet-stream; | ||
12 | keepalive_timeout 20; | ||
13 | |||
14 | index index.html index.php; | ||
15 | |||
16 | server { | ||
17 | listen 80; | ||
18 | root /var/www/shaarli; | ||
19 | |||
20 | access_log /var/log/nginx/shaarli.access.log; | ||
21 | error_log /var/log/nginx/shaarli.error.log; | ||
22 | |||
23 | location ~ /\. { | ||
24 | # deny access to dotfiles | ||
25 | access_log off; | ||
26 | log_not_found off; | ||
27 | deny all; | ||
28 | } | ||
29 | |||
30 | location ~ ~$ { | ||
31 | # deny access to temp editor files, e.g. "script.php~" | ||
32 | access_log off; | ||
33 | log_not_found off; | ||
34 | deny all; | ||
35 | } | ||
36 | |||
37 | location ~* \.(?:ico|css|js|gif|jpe?g|png)$ { | ||
38 | # cache static assets | ||
39 | expires max; | ||
40 | add_header Pragma public; | ||
41 | add_header Cache-Control "public, must-revalidate, proxy-revalidate"; | ||
42 | } | ||
43 | |||
44 | location ~ (index)\.php$ { | ||
45 | # filter and proxy PHP requests to PHP-FPM | ||
46 | fastcgi_pass unix:/var/run/php5-fpm.sock; | ||
47 | fastcgi_index index.php; | ||
48 | include fastcgi.conf; | ||
49 | } | ||
50 | |||
51 | location ~ \.php$ { | ||
52 | # deny access to all other PHP scripts | ||
53 | deny all; | ||
54 | } | ||
55 | } | ||
56 | } | ||
diff --git a/docker/production/stable/supervised.conf b/docker/production/stable/supervised.conf new file mode 100644 index 00000000..5acd9795 --- /dev/null +++ b/docker/production/stable/supervised.conf | |||
@@ -0,0 +1,13 @@ | |||
1 | [program:php5-fpm] | ||
2 | command=/usr/sbin/php5-fpm -F | ||
3 | priority=5 | ||
4 | autostart=true | ||
5 | autorestart=true | ||
6 | |||
7 | [program:nginx] | ||
8 | command=/usr/sbin/nginx | ||
9 | priority=10 | ||
10 | autostart=true | ||
11 | autorestart=true | ||
12 | stdout_events_enabled=true | ||
13 | stderr_events_enabled=true | ||
diff --git a/docker/production/supervised.conf b/docker/production/supervised.conf new file mode 100644 index 00000000..5acd9795 --- /dev/null +++ b/docker/production/supervised.conf | |||
@@ -0,0 +1,13 @@ | |||
1 | [program:php5-fpm] | ||
2 | command=/usr/sbin/php5-fpm -F | ||
3 | priority=5 | ||
4 | autostart=true | ||
5 | autorestart=true | ||
6 | |||
7 | [program:nginx] | ||
8 | command=/usr/sbin/nginx | ||
9 | priority=10 | ||
10 | autostart=true | ||
11 | autorestart=true | ||
12 | stdout_events_enabled=true | ||
13 | stderr_events_enabled=true | ||
@@ -1470,19 +1470,20 @@ function renderPage() | |||
1470 | // -------- User wants to rename a tag or delete it | 1470 | // -------- User wants to rename a tag or delete it |
1471 | if ($targetPage == Router::$PAGE_CHANGETAG) | 1471 | if ($targetPage == Router::$PAGE_CHANGETAG) |
1472 | { | 1472 | { |
1473 | if (empty($_POST['fromtag'])) | 1473 | if (empty($_POST['fromtag']) || (empty($_POST['totag']) && isset($_POST['renametag']))) { |
1474 | { | 1474 | $PAGE->assign('linkcount', count($LINKSDB)); |
1475 | $PAGE->assign('linkcount',count($LINKSDB)); | 1475 | $PAGE->assign('token', getToken()); |
1476 | $PAGE->assign('token',getToken()); | ||
1477 | $PAGE->assign('tags', $LINKSDB->allTags()); | 1476 | $PAGE->assign('tags', $LINKSDB->allTags()); |
1478 | $PAGE->renderPage('changetag'); | 1477 | $PAGE->renderPage('changetag'); |
1479 | exit; | 1478 | exit; |
1480 | } | 1479 | } |
1481 | if (!tokenOk($_POST['token'])) die('Wrong token.'); | 1480 | |
1481 | if (!tokenOk($_POST['token'])) { | ||
1482 | die('Wrong token.'); | ||
1483 | } | ||
1482 | 1484 | ||
1483 | // Delete a tag: | 1485 | // Delete a tag: |
1484 | if (!empty($_POST['deletetag']) && !empty($_POST['fromtag'])) | 1486 | if (isset($_POST['deletetag']) && !empty($_POST['fromtag'])) { |
1485 | { | ||
1486 | $needle=trim($_POST['fromtag']); | 1487 | $needle=trim($_POST['fromtag']); |
1487 | // True for case-sensitive tag search. | 1488 | // True for case-sensitive tag search. |
1488 | $linksToAlter = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $needle, true); | 1489 | $linksToAlter = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $needle, true); |
@@ -1499,8 +1500,7 @@ function renderPage() | |||
1499 | } | 1500 | } |
1500 | 1501 | ||
1501 | // Rename a tag: | 1502 | // Rename a tag: |
1502 | if (!empty($_POST['renametag']) && !empty($_POST['fromtag']) && !empty($_POST['totag'])) | 1503 | if (isset($_POST['renametag']) && !empty($_POST['fromtag']) && !empty($_POST['totag'])) { |
1503 | { | ||
1504 | $needle=trim($_POST['fromtag']); | 1504 | $needle=trim($_POST['fromtag']); |
1505 | // True for case-sensitive tag search. | 1505 | // True for case-sensitive tag search. |
1506 | $linksToAlter = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $needle, true); | 1506 | $linksToAlter = $LINKSDB->filter(LinkFilter::$FILTER_TAG, $needle, true); |
diff --git a/plugins/wallabag/README.md b/plugins/wallabag/README.md index 08e0d44a..5bc35be1 100644 --- a/plugins/wallabag/README.md +++ b/plugins/wallabag/README.md | |||
@@ -2,7 +2,8 @@ | |||
2 | 2 | ||
3 | For each link in your Shaarli, adds a button to save the target page in your [wallabag](https://www.wallabag.org/). | 3 | For each link in your Shaarli, adds a button to save the target page in your [wallabag](https://www.wallabag.org/). |
4 | 4 | ||
5 | ### Installation/configuration | 5 | ### Installation |
6 | |||
6 | Clone this repository inside your `tpl/plugins/` directory, or download the archive and unpack it there. | 7 | Clone this repository inside your `tpl/plugins/` directory, or download the archive and unpack it there. |
7 | The directory structure should look like: | 8 | The directory structure should look like: |
8 | 9 | ||
@@ -11,19 +12,31 @@ The directory structure should look like: | |||
11 | └── plugins | 12 | └── plugins |
12 |   └── wallabag | 13 |   └── wallabag |
13 |   ├── README.md | 14 |   ├── README.md |
15 | ├── config.php.dist | ||
14 |   ├── wallabag.html | 16 |   ├── wallabag.html |
17 |   ├── wallabag.php | ||
15 |   └── wallabag.png | 18 |   └── wallabag.png |
16 | ``` | 19 | ``` |
17 | 20 | ||
18 | To enable the plugin, add `'wallabag'` to your list of enabled plugins in `data/options.php` (`PLUGINS` array) | 21 | To enable the plugin, add `'wallabag'` to your list of enabled plugins in `data/options.php` (`PLUGINS` array). |
19 | . This should look like: | 22 | This should look like: |
20 | 23 | ||
21 | ``` | 24 | ``` |
22 | $GLOBALS['config']['PLUGINS'] = array('qrcode', 'any_other_plugin', 'wallabag') | 25 | $GLOBALS['config']['PLUGINS'] = array('qrcode', 'any_other_plugin', 'wallabag') |
23 | ``` | 26 | ``` |
24 | 27 | ||
25 | Then, set the `WALLABAG_URL` variable in `data/options.php` pointing to your wallabag URL. Example: | 28 | ### Configuration |
29 | |||
30 | Copy `config.php.dist` into `config.php` and setup your instance. | ||
26 | 31 | ||
32 | *Wallabag instance URL* | ||
27 | ``` | 33 | ``` |
28 | $GLOBALS['config']['WALLABAG_URL'] = 'http://demo.wallabag.org' ; //Base URL of your wallabag installation | 34 | $GLOBALS['config']['WALLABAG_URL'] = 'http://v2.wallabag.org' ; |
29 | ``` \ No newline at end of file | 35 | ``` |
36 | |||
37 | *Wallabag version*: either `1` (for 1.x) or `2` (for 2.x) | ||
38 | ``` | ||
39 | $GLOBALS['config']['WALLABAG_VERSION'] = 2; | ||
40 | ``` | ||
41 | |||
42 | > Note: these settings can also be set in `data/config.php`. \ No newline at end of file | ||
diff --git a/plugins/wallabag/WallabagInstance.php b/plugins/wallabag/WallabagInstance.php new file mode 100644 index 00000000..87352e66 --- /dev/null +++ b/plugins/wallabag/WallabagInstance.php | |||
@@ -0,0 +1,71 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * Class WallabagInstance. | ||
5 | */ | ||
6 | class WallabagInstance | ||
7 | { | ||
8 | /** | ||
9 | * @var array Static reference to differrent WB API versions. | ||
10 | * - key: version ID, must match plugin settings. | ||
11 | * - value: version name. | ||
12 | */ | ||
13 | private static $wallabagVersions = array( | ||
14 | 1 => '1.x', | ||
15 | 2 => '2.x', | ||
16 | ); | ||
17 | |||
18 | /** | ||
19 | * @var array Static reference to WB endpoint according to the API version. | ||
20 | * - key: version name. | ||
21 | * - value: endpoint. | ||
22 | */ | ||
23 | private static $wallabagEndpoints = array( | ||
24 | '1.x' => '?plainurl=', | ||
25 | '2.x' => 'bookmarklet?url=', | ||
26 | ); | ||
27 | |||
28 | /** | ||
29 | * @var string Wallabag user instance URL. | ||
30 | */ | ||
31 | private $instanceUrl; | ||
32 | |||
33 | /** | ||
34 | * @var string Wallabag user instance API version. | ||
35 | */ | ||
36 | private $apiVersion; | ||
37 | |||
38 | function __construct($instance, $version) | ||
39 | { | ||
40 | if ($this->isVersionAllowed($version)) { | ||
41 | $this->apiVersion = self::$wallabagVersions[$version]; | ||
42 | } else { | ||
43 | // Default API version: 1.x. | ||
44 | $this->apiVersion = self::$wallabagVersions[1]; | ||
45 | } | ||
46 | |||
47 | $this->instanceUrl = add_trailing_slash($instance); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * Build the Wallabag URL to reach from instance URL and API version endpoint. | ||
52 | * | ||
53 | * @return string wallabag url. | ||
54 | */ | ||
55 | public function getWallabagUrl() | ||
56 | { | ||
57 | return $this->instanceUrl . self::$wallabagEndpoints[$this->apiVersion]; | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * Checks version configuration. | ||
62 | * | ||
63 | * @param mixed $version given version ID. | ||
64 | * | ||
65 | * @return bool true if it's valid, false otherwise. | ||
66 | */ | ||
67 | private function isVersionAllowed($version) | ||
68 | { | ||
69 | return isset(self::$wallabagVersions[$version]); | ||
70 | } | ||
71 | } | ||
diff --git a/plugins/wallabag/config.php.dist b/plugins/wallabag/config.php.dist index 7cf0d303..a602708f 100644 --- a/plugins/wallabag/config.php.dist +++ b/plugins/wallabag/config.php.dist | |||
@@ -1,3 +1,4 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | $GLOBALS['plugins']['WALLABAG_URL'] = 'https://demo.wallabag.org/'; \ No newline at end of file | 3 | $GLOBALS['plugins']['WALLABAG_URL'] = 'https://demo.wallabag.org'; |
4 | $GLOBALS['plugins']['WALLABAG_VERSION'] = 1; \ No newline at end of file | ||
diff --git a/plugins/wallabag/wallabag.html b/plugins/wallabag/wallabag.html index ddcf8126..d0382adc 100644 --- a/plugins/wallabag/wallabag.html +++ b/plugins/wallabag/wallabag.html | |||
@@ -1 +1 @@ | |||
<span><a href="%s/?plainurl=%s" target="_blank"><img width="13" height="13" src="%s/wallabag/wallabag.png" title="Save to wallabag" /></a></span> | <span><a href="%s%s" target="_blank"><img width="13" height="13" src="%s/wallabag/wallabag.png" title="Save to wallabag" /></a></span> | ||
diff --git a/plugins/wallabag/wallabag.php b/plugins/wallabag/wallabag.php index 37969c97..e3c399a9 100644 --- a/plugins/wallabag/wallabag.php +++ b/plugins/wallabag/wallabag.php | |||
@@ -4,6 +4,8 @@ | |||
4 | * Plugin Wallabag. | 4 | * Plugin Wallabag. |
5 | */ | 5 | */ |
6 | 6 | ||
7 | require_once 'WallabagInstance.php'; | ||
8 | |||
7 | // don't raise unnecessary warnings | 9 | // don't raise unnecessary warnings |
8 | if (is_file(PluginManager::$PLUGINS_PATH . '/wallabag/config.php')) { | 10 | if (is_file(PluginManager::$PLUGINS_PATH . '/wallabag/config.php')) { |
9 | include PluginManager::$PLUGINS_PATH . '/wallabag/config.php'; | 11 | include PluginManager::$PLUGINS_PATH . '/wallabag/config.php'; |
@@ -28,12 +30,23 @@ function hook_wallabag_render_linklist($data) | |||
28 | return $data; | 30 | return $data; |
29 | } | 31 | } |
30 | 32 | ||
31 | $wallabag_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html'); | 33 | $version = isset($GLOBALS['plugins']['WALLABAG_VERSION']) |
34 | ? $GLOBALS['plugins']['WALLABAG_VERSION'] | ||
35 | : ''; | ||
36 | $wallabagInstance = new WallabagInstance($GLOBALS['plugins']['WALLABAG_URL'], $version); | ||
37 | |||
38 | $wallabagHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/wallabag/wallabag.html'); | ||
32 | 39 | ||
33 | foreach ($data['links'] as &$value) { | 40 | foreach ($data['links'] as &$value) { |
34 | $wallabag = sprintf($wallabag_html, $GLOBALS['plugins']['WALLABAG_URL'], $value['url'], PluginManager::$PLUGINS_PATH); | 41 | $wallabag = sprintf( |
42 | $wallabagHtml, | ||
43 | $wallabagInstance->getWallabagUrl(), | ||
44 | urlencode($value['url']), | ||
45 | PluginManager::$PLUGINS_PATH | ||
46 | ); | ||
35 | $value['link_plugin'][] = $wallabag; | 47 | $value['link_plugin'][] = $wallabag; |
36 | } | 48 | } |
37 | 49 | ||
38 | return $data; | 50 | return $data; |
39 | } | 51 | } |
52 | |||
diff --git a/tests/Url/UrlTest.php b/tests/Url/UrlTest.php index e498d79e..af6daaa4 100644 --- a/tests/Url/UrlTest.php +++ b/tests/Url/UrlTest.php | |||
@@ -145,4 +145,15 @@ class UrlTest extends PHPUnit_Framework_TestCase | |||
145 | $url = new Url('git://domain.tld/push?pull=clone#checkout'); | 145 | $url = new Url('git://domain.tld/push?pull=clone#checkout'); |
146 | $this->assertEquals('git', $url->getScheme()); | 146 | $this->assertEquals('git', $url->getScheme()); |
147 | } | 147 | } |
148 | |||
149 | /** | ||
150 | * Test add trailing slash. | ||
151 | */ | ||
152 | function testAddTrailingSlash() | ||
153 | { | ||
154 | $strOn = 'http://randomstr.com/test/'; | ||
155 | $strOff = 'http://randomstr.com/test'; | ||
156 | $this->assertEquals($strOn, add_trailing_slash($strOn)); | ||
157 | $this->assertEquals($strOn, add_trailing_slash($strOff)); | ||
158 | } | ||
148 | } | 159 | } |
diff --git a/tests/plugins/PluginWallabagTest.php b/tests/plugins/PluginWallabagTest.php index 7cc83f4f..5d3a60e0 100644 --- a/tests/plugins/PluginWallabagTest.php +++ b/tests/plugins/PluginWallabagTest.php | |||
@@ -44,6 +44,8 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase | |||
44 | 44 | ||
45 | // plugin data | 45 | // plugin data |
46 | $this->assertEquals(1, count($link['link_plugin'])); | 46 | $this->assertEquals(1, count($link['link_plugin'])); |
47 | $this->assertNotFalse(strpos($link['link_plugin'][0], $str)); | 47 | $this->assertNotFalse(strpos($link['link_plugin'][0], urlencode($str))); |
48 | $this->assertNotFalse(strpos($link['link_plugin'][0], $GLOBALS['plugins']['WALLABAG_URL'])); | ||
48 | } | 49 | } |
49 | } | 50 | } |
51 | |||
diff --git a/tests/plugins/WallabagInstanceTest.php b/tests/plugins/WallabagInstanceTest.php new file mode 100644 index 00000000..7c14c1df --- /dev/null +++ b/tests/plugins/WallabagInstanceTest.php | |||
@@ -0,0 +1,60 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'plugins/wallabag/WallabagInstance.php'; | ||
4 | |||
5 | /** | ||
6 | * Class WallabagInstanceTest | ||
7 | */ | ||
8 | class WallabagInstanceTest extends PHPUnit_Framework_TestCase | ||
9 | { | ||
10 | /** | ||
11 | * @var string wallabag url. | ||
12 | */ | ||
13 | private $instance; | ||
14 | |||
15 | /** | ||
16 | * Reset plugin path | ||
17 | */ | ||
18 | function setUp() | ||
19 | { | ||
20 | $this->instance = 'http://some.url'; | ||
21 | } | ||
22 | |||
23 | /** | ||
24 | * Test WallabagInstance with API V1. | ||
25 | */ | ||
26 | function testWallabagInstanceV1() | ||
27 | { | ||
28 | $instance = new WallabagInstance($this->instance, 1); | ||
29 | $expected = $this->instance . '/?plainurl='; | ||
30 | $result = $instance->getWallabagUrl(); | ||
31 | $this->assertEquals($expected, $result); | ||
32 | } | ||
33 | |||
34 | /** | ||
35 | * Test WallabagInstance with API V2. | ||
36 | */ | ||
37 | function testWallabagInstanceV2() | ||
38 | { | ||
39 | $instance = new WallabagInstance($this->instance, 2); | ||
40 | $expected = $this->instance . '/bookmarklet?url='; | ||
41 | $result = $instance->getWallabagUrl(); | ||
42 | $this->assertEquals($expected, $result); | ||
43 | } | ||
44 | |||
45 | /** | ||
46 | * Test WallabagInstance with an invalid API version. | ||
47 | */ | ||
48 | function testWallabagInstanceInvalidVersion() | ||
49 | { | ||
50 | $instance = new WallabagInstance($this->instance, false); | ||
51 | $expected = $this->instance . '/?plainurl='; | ||
52 | $result = $instance->getWallabagUrl(); | ||
53 | $this->assertEquals($expected, $result); | ||
54 | |||
55 | $instance = new WallabagInstance($this->instance, 3); | ||
56 | $expected = $this->instance . '/?plainurl='; | ||
57 | $result = $instance->getWallabagUrl(); | ||
58 | $this->assertEquals($expected, $result); | ||
59 | } | ||
60 | } | ||