]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
twig implementation
authorNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Sun, 4 Aug 2013 20:35:08 +0000 (22:35 +0200)
committerNicolas Lœuillet <nicolas.loeuillet@gmail.com>
Sun, 4 Aug 2013 20:35:08 +0000 (22:35 +0200)
README.md
inc/poche/Poche.class.php
inc/poche/Tools.class.php
index.php
tpl/_footer.twig
tpl/config.twig
tpl/export.twig
tpl/js/poche.js
tpl/login.twig

index b44e7d368a5b1e734ba1f5c943257054495d7bd0..09f48b17f600a99ba139d818dd49259d580bc085 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
 # poche
-Abandon Pocket, Instapaper and other Readability service : adopt poche. It is the same, but it is open source.
+Abandon Pocket, Instapaper and other Readability service : adopt poche. It is the same, but it is open source. Moreover, you can migrate from Pocket & Readability.
 
 ![poche](http://inthepoche.com/img/logo.png)
 
@@ -11,23 +11,23 @@ To get news from poche, [follow us on twitter](http://twitter.com/getpoche) or [
 
 [![flattr](http://api.flattr.com/button/flattr-badge-large.png)](http://flattr.com/thing/1265480/poche-a-read-it-later-open-source-system)
 
-## Usage
-You can easily add a "poched" page with the bookmarklet.
-
-poche save the entire content of a poched links : text and pictures are stored on your server.
-
-You can :
-* read a page in a comfortable reading view
-* archive a link
-* put a link in favorite
-* delete a link
-
 ## Requirements & installation
 You have to install [sqlite for php](http://www.php.net/manual/en/book.sqlite.php) on your server.
 
+[PHP cURL](http://www.php.net/manual/en/book.curl.php) & [tidy_parse_string](http://www.php.net/manual/en/tidy.parsestring.php) are recommended.
+
 Get the [latest version](https://github.com/inthepoche/poche) of poche on github. Unzip it and upload it on your server. poche must have write access on assets, cache and db directories.
 
-That's all, **poche works** !
+Install composer in your project : 
+```bash
+curl -s http://getcomposer.org/installer | php
+```
+Install via composer : 
+```bash
+php composer.phar install
+```
+
+That's all, you can use poche ! 
 
 ## Security
 You **have** to protect your db/poche.sqlite file. Modify the virtual host of your website to add this condition :
@@ -46,12 +46,11 @@ location ~ /(db) {
 }
 ```
 
-## Import from Pocket
-
-If you want to import your Pocket datas, [export them here](https://getpocket.com/export). Put the HTML file in your poche directory, execute import.php file locally by following instructions. Be careful, the script can take a very long time.
+## Usage
+See the documentation on our website : [inthepoche.com](http://inthepoche.com).
 
 ## License
 Copyright © 2010-2013 Nicolas Lœuillet <nicolas@loeuillet.org>
 This work is free. You can redistribute it and/or modify it under the
 terms of the Do What The Fuck You Want To Public License, Version 2,
-as published by Sam Hocevar. See the COPYING file for more details.
+as published by Sam Hocevar. See the COPYING file for more details.
\ No newline at end of file
index 9e407d41dd62209931de410c3c6dd01b18329993..5c3eda8065b27f75c6b9e535cfea54ff9e45c0fa 100644 (file)
@@ -118,8 +118,6 @@ class Poche
                 $this->store->archiveById($id);
                 Tools::logm('archive link #' . $id);
                 break;
-            case 'import':
-                break;
             default:
                 break;
         }
@@ -131,18 +129,6 @@ class Poche
 
         switch ($view)
         {
-            case 'install':
-                Tools::logm('install mode');
-                break;
-            case 'import';
-                Tools::logm('import mode');
-                break;
-            case 'export':
-                $entries = $this->store->retrieveAll();
-                // $tpl->assign('export', Tools::renderJson($entries));
-                // $tpl->draw('export');
-                Tools::logm('export view');
-                break;
             case 'config':
                 Tools::logm('config view');
                 break;
@@ -224,59 +210,80 @@ class Poche
         Tools::redirect();
     }
 
-    public function import($from)
+    private function importFromInstapaper()
     {
-        if ($from == 'pocket') {
-            $html = new simple_html_dom();
-            $html->load_file('./ril_export.html');
+        Tools::logm('import from instapaper completed');
+        Tools::redirect();
+    }
 
-            $read = 0;
-            $errors = array();
-            foreach($html->find('ul') as $ul)
+    private function importFromPocket()
+    {
+        $html = new simple_html_dom();
+        $html->load_file('./ril_export.html');
+
+        $read = 0;
+        $errors = array();
+        foreach($html->find('ul') as $ul)
+        {
+            foreach($ul->find('li') as $li)
             {
-                foreach($ul->find('li') as $li)
-                {
-                    $a = $li->find('a');
-                    $url = new Url($a[0]->href);
-                    $this->action('add', $url);
-                    if ($read == '1') {
-                        $last_id = $this->store->lastInsertId();
-                        $sql_update = "UPDATE entries SET is_read=~is_read WHERE id=?";
-                        $params_update = array($last_id);
-                        $query_update = $this->store->prepare($sql_update);
-                        $query_update->execute($params_update);
-                    }
+                $a = $li->find('a');
+                $url = new Url(base64_encode($a[0]->href));
+                $this->action('add', $url);
+                if ($read == '1') {
+                    $last_id = $this->store->getLastId();
+                    $this->store->archiveById($last_id);
                 }
-                # Pocket génère un fichier HTML avec deux <ul>
-                # Le premier concerne les éléments non lus
-                # Le second concerne les éléments archivés
-                $read = 1;
             }
-            logm('import from pocket completed');
-            Tools::redirect();
+            # Pocket génère un fichier HTML avec deux <ul>
+            # Le premier concerne les éléments non lus
+            # Le second concerne les éléments archivés
+            $read = 1;
         }
-        else if ($from == 'readability') {
-            # TODO finaliser tout ça ici
-            $str_data = file_get_contents("readability");
-            $data = json_decode($str_data,true);
+        Tools::logm('import from pocket completed');
+        Tools::redirect();
+    }
 
-            foreach ($data as $key => $value) {
-                $url = '';
-                foreach ($value as $key2 => $value2) {
-                    if ($key2 == 'article__url') {
-                        $url = new Url($value2);
-                    }
+    private function importFromReadability()
+    {
+        # TODO finaliser tout ça ici
+        # noms des variables + gestion des articles lus
+        $str_data = file_get_contents("./readability");
+        $data = json_decode($str_data,true);
+
+        foreach ($data as $key => $value) {
+            $url = '';
+            foreach ($value as $key2 => $value2) {
+                if ($key2 == 'article__url') {
+                    $url = new Url(base64_encode($value2));
                 }
-                if ($url != '')
-                    action_to_do('add', $url);
             }
-            logm('import from Readability completed');
-            Tools::redirect();
+            if ($url->isCorrect())
+                $this->action('add', $url);
         }
+        Tools::logm('import from Readability completed');
+        Tools::redirect();
     }
 
-    public function export()
+    public function import($from)
     {
+        if ($from == 'pocket') {
+            $this->importFromPocket();
+        }
+        else if ($from == 'readability') {
+            $this->importFromReadability();
+        }
+        else if ($from == 'instapaper') {
+            $this->importFromInstapaper();
+        }
+    }
 
+    public function export()
+    {
+        $entries = $this->store->retrieveAll();
+        echo $this->tpl->render('export.twig', array(
+            'export' => Tools::renderJson($entries),
+        ));
+        Tools::logm('export view');
     }
 }
\ No newline at end of file
index c277035febdcb0b972d8c69f880a37b4141c3663..1ff4ba55c90680790d9b9819e9d7dee23d672476 100644 (file)
@@ -205,4 +205,9 @@ class Tools
     {
         return sha1($string . SALT);
     }
+
+    public static function checkVar($var)
+    {
+        return ((isset ($_REQUEST["$var"])) ? htmlentities($_REQUEST["$var"]) : '');
+    }
 }
\ No newline at end of file
index 1554c0a65501c2333c3d58eb0710f0d11c5b3c24..381b8ccc89105d48fa71b773b439f2a7a740ad66 100644 (file)
--- a/index.php
+++ b/index.php
 
 include dirname(__FILE__).'/inc/poche/config.inc.php';
 
-# XSRF protection with token
-// if (!empty($_POST)) {
-//     if (!Session::isToken($_POST['token'])) {
-//         die(_('Wrong token'));
-//         // TODO remettre le test
-//     }
-//     unset($_SESSION['tokens']);
-// }
+#XSRF protection with token
+if (!empty($_POST)) {
+    if (!Session::isToken($_POST['token'])) {
+        die(_('Wrong token'));
+        // TODO remettre le test
+    }
+    unset($_SESSION['tokens']);
+}
 
 $referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
+$view = Tools::checkVar('view');
+$action = Tools::checkVar('action');
+$id = Tools::checkVar('id');
+$_SESSION['sort'] = Tools::checkVar('sort');
+$url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
 
 if (isset($_GET['login'])) {
     # hello you
@@ -36,15 +41,9 @@ elseif (isset($_GET['config'])) {
 elseif (isset($_GET['import'])) {
     $poche->import($_GET['from']);
 }
-
-# Aaaaaaand action !
-$view = (isset ($_REQUEST['view'])) ? htmlentities($_REQUEST['view']) : 'home';
-$full_head = (isset ($_REQUEST['full_head'])) ? htmlentities($_REQUEST['full_head']) : 'yes';
-$action = (isset ($_REQUEST['action'])) ? htmlentities($_REQUEST['action']) : '';
-$_SESSION['sort'] = (isset ($_REQUEST['sort'])) ? htmlentities($_REQUEST['sort']) : 'id';
-$id = (isset ($_REQUEST['id'])) ? htmlspecialchars($_REQUEST['id']) : '';
-
-$url = new Url((isset ($_GET['url'])) ? $_GET['url'] : '');
+elseif (isset($_GET['export'])) {
+    $poche->export();
+}
 
 $tpl_vars = array(
     'referer' => $referer,
@@ -64,4 +63,5 @@ else {
     $tpl_file = 'login.twig';
 }
 
+# Aaaaaaand action !
 echo $poche->tpl->render($tpl_file, $tpl_vars);
\ No newline at end of file
index 59b58fa5270786e521ab3cad43347fd14c346046..b1d7b8d4d3a3ba449da21e164f9f7c9432de7d49 100644 (file)
@@ -1,3 +1,3 @@
         <footer class="mr2 mt3 smaller">
-            <p>powered by <a href="http://inthepoche.com">poche</a></p>
+            <p>{% trans "powered by" %} <a href="http://inthepoche.com">poche</a></p>
         </footer>
\ No newline at end of file
index 9a51e5668705f9786b846f578fbb88e4a9c6ecf8..c18806bc6765c572db5c9a857947c16f3637bb28 100644 (file)
                 <p>{% trans "Please execute the import script locally, it can take a very long time." %}</p>
                 <p>{% trans "More infos in the official doc:" %} <a href="http://inthepoche.com/?pages/Documentation">inthepoche.com</a></p>
                 <p><ul>
-                <li><a href="/?import&from=pocket">{% trans "import from Pocket" %}</a> (you must have a "ril_export.html" file on your server)</li>
-                <li><a href="/?import&from=readability">{% trans "import from Readability" %}</a>  (you must have a "readability" file on your server)</li>
+                <li><a href="./?import&from=pocket">{% trans "import from Pocket" %}</a> (you must have a "ril_export.html" file on your server)</li>
+                <li><a href="./?import&from=readability">{% trans "import from Readability" %}</a>  (you must have a "readability" file on your server)</li>
                 </ul></p>
 
                 <h2>{% trans "Export your poche datas" %}</h2>
-                <p><a href="?view=export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your poche datas." %}</p>
+                <p><a href="./?export" target="_blank">{% trans "Click here" %}</a> {% trans "to export your poche datas." %}</p>
             </div>
 {% endblock %}
\ No newline at end of file
index d22d05fc9b21ec121415e85ed7db235167ee8848..4adb95402af726c82db2c425bd6cba33ef588af7 100644 (file)
@@ -1 +1 @@
-export {$export}
\ No newline at end of file
+{{ export }}
\ No newline at end of file
index 97d9911dccbe3fff59ddccf8aed2a8dfb125c815..b4eac11c17f0d1488c6590c3853cc416bd59e227 100644 (file)
@@ -23,7 +23,7 @@ function toggle_archive(element, id, view_article) {
 }
 
 function sort_links(view, sort) {
-    $.get('index.php', { view: view, sort: sort, full_head: 'no' }, function(data) {
+    $.get('index.php', { view: view, sort: sort }, function(data) {
       $('#content').html(data);
     });
 }
index 70c2190c8d2d18a7caaba58f74a8658e3adf237d..c3028795b0f12a5742fc9507d18b5a7d8bf5dd2b 100644 (file)
@@ -16,9 +16,9 @@
                                                <input class="col" type="password" id="password" name="password" placeholder="Password" tabindex="2" {% if demo == 1 %}value="poche"{% endif %} />
                                        </div>
                                        <div class="row">
-                                               <label class="col w150p">{% trans "Stay signed in" %}</label>
+                                               <label class="col w150p" for="longlastingsession">{% trans "Stay signed in" %}</label>
                                                <div class="col">
-                                                       <input type="checkbox" name="longlastingsession" tabindex="3">
+                                                       <input type="checkbox" id="longlastingsession" name="longlastingsession" tabindex="3">
                                                        <small class="inbl">{% trans "(Do not check on public computers)" %}</small>
                                                </div>
                                        </div>