1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-27 11:22:17 -05:00

découpage des vues dans plusieurs fichiers tpl

This commit is contained in:
nicosomb 2013-04-15 09:38:41 +02:00
parent 3e188a7c8d
commit 8046748b42
9 changed files with 132 additions and 113 deletions

View 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();
?>

View File

@ -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();

View File

@ -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 (?, ?, ?)';
$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');

View File

@ -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>

18
tpl/head.html Normal file
View File

@ -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>

33
tpl/home.html Normal file
View File

@ -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>

22
tpl/js.html Normal file
View File

@ -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}

29
tpl/view.html Executable file
View File

@ -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>

View File

@ -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');