]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
découpage des vues dans plusieurs fichiers tpl
authornicosomb <nicolas@loeuillet.org>
Mon, 15 Apr 2013 07:38:41 +0000 (09:38 +0200)
committernicosomb <nicolas@loeuillet.org>
Mon, 15 Apr 2013 07:38:41 +0000 (09:38 +0200)
inc/config.php
inc/functions.php
index.php
tpl/footer.html
tpl/head.html [new file with mode: 0644]
tpl/home.html [new file with mode: 0644]
tpl/js.html [new file with mode: 0644]
tpl/view.html [new file with mode: 0755]
view.php

index f9a4701ee7867c9fd3ec309c31d36578a9d60876..6d8be9ee9d6f3f1eba8cb511a054a6ddee23ac65 100644 (file)
@@ -13,4 +13,14 @@ include 'db.php';
 include 'functions.php';
 require_once 'Readability.php';
 require_once 'Encoding.php';
+require_once 'rain.tpl.class.php';
+
+$db = new db(DB_PATH);
+
+raintpl::$tpl_dir   = './tpl/';
+raintpl::$cache_dir = './cache/';
+raintpl::$base_url  = get_poche_url();
+raintpl::configure('path_replace', false);
+raintpl::configure('debug', false);
+$tpl = new raintpl();
 ?>
\ No newline at end of file
index 0b9eb93697f291150e21d2669b6e05d30946f9cf..ffd400ef3ecd811646d4dc437bbdbe7787a40433 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * Permet de générer l'URL de poche pour le bookmarklet
  */
-function url()
+function get_poche_url()
 {
     $protocol = "http";
     if(isset($_SERVER['HTTPS'])) {
@@ -15,29 +15,6 @@ function url()
     return $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 }
 
-/**
- * Génération de la page "vue d'un article"
- */
-function generate_page($entry)
-{
-    raintpl::$tpl_dir = './tpl/';
-    raintpl::$cache_dir = "./cache/";
-    raintpl::$base_url = url();
-    raintpl::configure( 'path_replace', false );
-    raintpl::configure('debug', false);
-
-    $tpl = new raintpl();
-
-    $tpl->assign("id", $entry['id']);
-    $tpl->assign("url", $entry['url']);
-    $tpl->assign("title", $entry['title']);
-    $tpl->assign("content", $entry['content']);
-    $tpl->assign("is_fav", $entry['is_fav']);
-    $tpl->assign("is_read", $entry['is_read']);
-
-    $tpl->draw( "index");
-}
-
 // function define to retrieve url content
 function get_external_file($url, $timeout)
 {
@@ -111,6 +88,9 @@ function get_external_file($url, $timeout)
     }
 }
 
+/**
+ * Préparation de l'URL avec récupération du contenu avant insertion en base
+ */
 function prepare_url($url)
 {
     $parametres = array();
index 8c695cd333c8cc5590a3503c8ddb0ceef7d2d68e..ef18254a4166f5a58976522dd8b270bad5ab8ae0 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -9,7 +9,6 @@
  */
 
 include dirname(__FILE__).'/inc/config.php';
-$db = new db(DB_PATH);
 
 $action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : '';
 $view   = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : '';
@@ -19,15 +18,12 @@ $url    = (isset ($_GET['url'])) ? $_GET['url'] : '';
 switch ($action)
 {
     case 'add':
-
         if ($url == '')
             continue;
 
         $parametres_url = prepare_url($url);
-
-        $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)';
+        $sql_action     = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)';
         $params_action  = array($url, $parametres_url['title'], $parametres_url['content']);
-
         break;
     case 'delete':
         $sql_action     = "DELETE FROM entries WHERE id=?";
@@ -80,79 +76,9 @@ catch (Exception $e)
     die('view query error : '.$e->getMessage());
 }
 
-?>
-<!DOCTYPE html>
-<!--[if lte IE 6]> <html class="no-js ie6 ie67 ie678" lang="en"> <![endif]-->
-<!--[if lte IE 7]> <html class="no-js ie7 ie67 ie678" lang="en"> <![endif]-->
-<!--[if IE 8]> <html class="no-js ie8 ie678" lang="en"> <![endif]-->
-<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
-<html>
-    <head>
-        <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
-        <meta charset="utf-8">
-        <meta http-equiv="X-UA-Compatible" content="IE=10">
-        <title>poche, a read it later open source system</title>
-        <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico" />
-        <link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/apple-touch-icon-144x144-precomposed.png">
-        <link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/apple-touch-icon-72x72-precomposed.png">
-        <link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-precomposed.png">
-        <link rel="stylesheet" href="css/knacss.css" media="all">
-        <link rel="stylesheet" href="css/style.css" media="all">
-    </head>
-    <body>
-        <header>
-            <h1><img src="img/logo.png" alt="logo poche" />poche</h1>
-        </header>
-        <div id="main">
-            <ul id="links">
-                <li><a href="index.php" <?php echo (($view == 'index') ? 'class="current"' : ''); ?>>home</a></li>
-                <li><a href="?view=fav" <?php echo (($view == 'fav') ? 'class="current"' : ''); ?>>favorites</a></li>
-                <li><a href="?view=archive" <?php echo (($view == 'archive') ? 'class="current"' : ''); ?>>archive</a></li>
-                <li><a style="cursor: move" title="i am a bookmarklet, use me !" href="javascript:(function(){var%20url%20=%20location.href;var%20title%20=%20document.title%20||%20url;window.open('<?php echo url()?>?action=add&url='%20+%20encodeURIComponent(url),'_self');})();">poche it !</a></li>
-            </ul>
-            <div id="content">
-                <?php
-                foreach ($entries as $entry)
-                {
-                    ?>
-                    <div id="entry-<?php echo $entry['id']; ?>" class="entrie mb2">
-                        <span class="content">
-                            <h2 class="h6-like">
-                                <a href="view.php?id=<?php echo $entry['id']; ?>"><?php echo $entry['title']; ?>
-                            </h2>
-                            <div class="tools">
-                                <a title="toggle mark as read" class="tool archive <?php echo ( ($entry['is_read'] == '0') ? 'archive-off' : '' ); ?>" onclick="toggle_archive(this, <?php echo $entry['id']; ?>)"><span></span></a>
-                                <a title="toggle favorite" class="tool fav <?php echo ( ($entry['is_fav'] == '0') ? 'fav-off' : '' ); ?>" onclick="toggle_favorite(this, <?php echo $entry['id']; ?>)"><span></span></a>
-                                <a href="?action=delete&id=<?php echo $entry['id']; ?>" title="toggle delete" onclick="return confirm('Are you sure?')" class="tool delete"><span></span></a>
-                            </div>
-                        </span>
-                    </div>
-                <?php
-                }
-                ?>
-            </div>
-        </div>
-        <footer class="mr2 mt3 smaller">
-            <p>powered by <a href="http://inthepoche.com">poche</a><br />follow us on <a href="https://twitter.com/getpoche" title="follow us on twitter">twitter</a></p>
-        </footer>
-        <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
-        <script type="text/javascript" src="js/jquery.masonry.min.js"></script>
-        <script type="text/javascript" src="js/poche.js"></script>
-        <script type="text/javascript">
-            $( window ).load( function()
-            {
-                var columns    = 3,
-                    setColumns = function() { columns = $( window ).width() > 640 ? 3 : $( window ).width() > 320 ? 2 : 1; };
-
-                setColumns();
-                $( window ).resize( setColumns );
-
-                $( '#content' ).masonry(
-                {
-                    itemSelector: '.entrie',
-                    columnWidth:  function( containerWidth ) { return containerWidth / columns; }
-                });
-            });
-        </script>
-    </body>
-</html>
+$tpl->assign('title', 'poche, a read it later open source system');
+$tpl->assign('view', $view);
+$tpl->assign('poche_url', get_poche_url());
+$tpl->assign('entries', $entries);
+$tpl->assign('load_all_js', 1);
+$tpl->draw('home');
\ No newline at end of file
index 3328a8a4e6f4c8c97e129b17d463dcdecbf9a9fc..d225acbe3827c62c463eb93983cb424d441b8cee 100755 (executable)
@@ -1,5 +1,3 @@
         <footer class="mr2 mt3 smaller">
             <p>powered by <a href="http://inthepoche.com">poche</a><br />follow us on <a href="https://twitter.com/getpoche" title="follow us on twitter">twitter</a></p>
-        </footer>
-        <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
-        <script type="text/javascript" src="js/poche.js"></script>
\ No newline at end of file
+        </footer>
\ No newline at end of file
diff --git a/tpl/head.html b/tpl/head.html
new file mode 100644 (file)
index 0000000..66150d8
--- /dev/null
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<!--[if lte IE 6]> <html class="no-js ie6 ie67 ie678" lang="en"> <![endif]-->
+<!--[if lte IE 7]> <html class="no-js ie7 ie67 ie678" lang="en"> <![endif]-->
+<!--[if IE 8]> <html class="no-js ie8 ie678" lang="en"> <![endif]-->
+<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
+<html>
+    <head>
+        <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
+        <meta charset="utf-8">
+        <meta http-equiv="X-UA-Compatible" content="IE=10">
+        <title>{$title}</title>
+        <link rel="shortcut icon" type="image/x-icon" href="./img/favicon.ico" />
+        <link rel="apple-touch-icon-precomposed" sizes="144x144" href="./img/apple-touch-icon-144x144-precomposed.png">
+        <link rel="apple-touch-icon-precomposed" sizes="72x72" href="./img/apple-touch-icon-72x72-precomposed.png">
+        <link rel="apple-touch-icon-precomposed" href="./img/apple-touch-icon-precomposed.png">
+        <link rel="stylesheet" href="./css/knacss.css" media="all">
+        <link rel="stylesheet" href="./css/style.css" media="all">
+    </head>
\ No newline at end of file
diff --git a/tpl/home.html b/tpl/home.html
new file mode 100644 (file)
index 0000000..70a35a7
--- /dev/null
@@ -0,0 +1,33 @@
+{include="head"}
+    <body>
+        <header>
+            <h1><img src="./img/logo.png" alt="logo poche" />poche</h1>
+        </header>
+        <div id="main">
+            <ul id="links">
+                <li><a href="index.php" {if="$view == 'index'"}class="current"{/if}>home</a></li>
+                <li><a href="?view=fav" {if="$view == 'fav'"}class="current"{/if}>favorites</a></li>
+                <li><a href="?view=archive" {if="$view == 'archive'"}class="current"{/if}>archive</a></li>
+                <li><a style="cursor: move" title="i am a bookmarklet, use me !" href="javascript:(function(){var%20url%20=%20location.href;var%20title%20=%20document.title%20||%20url;window.open('{$poche_url}?action=add&url='%20+%20encodeURIComponent(url),'_self');})();">poche it !</a></li>
+            </ul>
+            <div id="content">
+                {loop="entries"}
+                    <div id="entry-{$value.id}" class="entrie mb2">
+                        <span class="content">
+                            <h2 class="h6-like">
+                                <a href="view.php?id={$value.id}">{$value.title}</a>
+                            </h2>
+                            <div class="tools">
+                                <a title="toggle mark as read" class="tool archive {if="$value.is_read == '0'"}archive-off{/if}" onclick="toggle_archive(this, {$value.id})"><span></span></a>
+                                <a title="toggle favorite" class="tool fav {if="$value.is_fav == '0'"}fav-off{/if}" onclick="toggle_favorite(this, {$value.id})"><span></span></a>
+                                <a href="?action=delete&id={$value.id}" title="toggle delete" onclick="return confirm('Are you sure?')" class="tool delete"><span></span></a>
+                            </div>
+                        </span>
+                    </div>
+                {/loop}
+            </div>
+        </div>
+        {include="footer"}
+        {include="js"}
+    </body>
+</html>
diff --git a/tpl/js.html b/tpl/js.html
new file mode 100644 (file)
index 0000000..a02212b
--- /dev/null
@@ -0,0 +1,22 @@
+        <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
+        <script type="text/javascript" src="js/poche.js"></script>
+
+        {if="$load_all_js == '1'"}
+        <script type="text/javascript" src="js/jquery.masonry.min.js"></script>
+        <script type="text/javascript">
+            $( window ).load( function()
+            {
+                var columns    = 3,
+                    setColumns = function() { columns = $( window ).width() > 640 ? 3 : $( window ).width() > 320 ? 2 : 1; };
+
+                setColumns();
+                $( window ).resize( setColumns );
+
+                $( '#content' ).masonry(
+                {
+                    itemSelector: '.entrie',
+                    columnWidth:  function( containerWidth ) { return containerWidth / columns; }
+                });
+            });
+        </script>
+        {/if}
\ No newline at end of file
diff --git a/tpl/view.html b/tpl/view.html
new file mode 100755 (executable)
index 0000000..1e05788
--- /dev/null
@@ -0,0 +1,29 @@
+{include="head"}
+    <body class="article">
+        <div id="article" class="w600p">
+               <div class="backhome">
+                       <a href="index.php" title="back to home">&larr;</a>
+               </div>
+            <div class="tools">
+                <a title="toggle mark as read" class="tool archive {if="$is_read == 0"}archive-off{/if}" onclick="toggle_archive(this, {$id}, 1)"><span></span></a>
+                <a title="toggle favorite" class="tool fav  {if="$is_fav == 0"}fav-off{/if}" onclick="toggle_favorite(this, {$id})"><span></span></a>
+                <a href="index.php?action=delete&id={$id}" title="toggle delete" onclick="return confirm('Are you sure?')" class="tool delete"><span></span></a>
+            </div>
+            <header class="mbm">
+                <h1><a href="{$url}">{$title}</a></h1>
+                <div class="vieworiginal txtright small"><a href="{$url}" target="_blank" title="original : {$title}">view original</a></div>
+            </header>
+            <article>
+                <div id="readityourselfcontent">
+                    {$content}
+                </div>
+            </article>
+            <div class="vieworiginal txtright small"><a href="{$url}" target="_blank" title="original : {$title}">view original</a></div>
+            <div class="backhome">
+                <a href="index.php" title="back to home">&larr;</a>
+            </div>
+        </div>
+        {include="footer"}
+        {include="js"}
+    </body>
+</html>
index 75e6c3a9e2ef41a0acae103df368e0e29f246af7..0ee8957b92a201fff8cfdb799736f890aa136ce3 100755 (executable)
--- a/view.php
+++ b/view.php
@@ -8,11 +8,7 @@
  * @license    http://www.wtfpl.net/ see COPYING file
  */
 
-header('Content-type:text/html; charset=utf-8');
-
 include dirname(__FILE__).'/inc/config.php';
-require_once dirname(__FILE__).'/inc/rain.tpl.class.php';
-$db = new db(DB_PATH);
 
 if(isset($_GET['id']) && $_GET['id'] != '') {
 
@@ -32,7 +28,14 @@ if(isset($_GET['id']) && $_GET['id'] != '') {
     }
 
     if ($entry != NULL) {
-        generate_page($entry[0]);
+        $tpl->assign('id', $entry[0]['id']);
+        $tpl->assign('url', $entry[0]['url']);
+        $tpl->assign('title', $entry[0]['title']);
+        $tpl->assign('content', $entry[0]['content']);
+        $tpl->assign('is_fav', $entry[0]['is_fav']);
+        $tpl->assign('is_read', $entry[0]['is_read']);
+        $tpl->assign('load_all_js', 0);
+        $tpl->draw('view');
     }
     else {
         die('error in view call');