mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-23 09:31:04 +00:00
factorisation code
This commit is contained in:
parent
8046748b42
commit
263d6c6756
4 changed files with 111 additions and 77 deletions
|
@ -22,5 +22,4 @@ raintpl::$cache_dir = './cache/';
|
|||
raintpl::$base_url = get_poche_url();
|
||||
raintpl::configure('path_replace', false);
|
||||
raintpl::configure('debug', false);
|
||||
$tpl = new raintpl();
|
||||
?>
|
||||
$tpl = new raintpl();
|
|
@ -120,4 +120,108 @@ function prepare_url($url)
|
|||
$parametres['content'] = $r->articleContent->innerHTML;
|
||||
|
||||
return $parametres;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appel d'une action (mark as fav, archive, delete)
|
||||
*/
|
||||
function action_to_do($action, $id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
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=?";
|
||||
$params_action = array($id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
# action query
|
||||
if (isset($sql_action))
|
||||
{
|
||||
$query = $db->getHandle()->prepare($sql_action);
|
||||
$query->execute($params_action);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
die('action query error : '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Détermine quels liens afficher : home, fav ou archives
|
||||
*/
|
||||
function display_view($view)
|
||||
{
|
||||
global $db;
|
||||
|
||||
switch ($view)
|
||||
{
|
||||
case 'archive':
|
||||
$sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
|
||||
$params = array(-1);
|
||||
break;
|
||||
case 'fav' :
|
||||
$sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc";
|
||||
$params = array(-1);
|
||||
break;
|
||||
default:
|
||||
$sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
|
||||
$params = array(0);
|
||||
break;
|
||||
}
|
||||
|
||||
# view query
|
||||
try
|
||||
{
|
||||
$query = $db->getHandle()->prepare($sql);
|
||||
$query->execute($params);
|
||||
$entries = $query->fetchAll();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
die('view query error : '.$e->getMessage());
|
||||
}
|
||||
|
||||
return $entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère un article en fonction d'un ID
|
||||
*/
|
||||
function get_article($id)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$entry = NULL;
|
||||
$sql = "SELECT * FROM entries WHERE id=?";
|
||||
$params = array(intval($id));
|
||||
|
||||
# view article query
|
||||
try
|
||||
{
|
||||
$query = $db->getHandle()->prepare($sql);
|
||||
$query->execute($params);
|
||||
$entry = $query->fetchAll();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
die('query error : '.$e->getMessage());
|
||||
}
|
||||
|
||||
return $entry;
|
||||
}
|
64
index.php
64
index.php
|
@ -11,70 +11,12 @@
|
|||
include dirname(__FILE__).'/inc/config.php';
|
||||
|
||||
$action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : '';
|
||||
$view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : '';
|
||||
$view = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : 'index';
|
||||
$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : '';
|
||||
$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=?";
|
||||
$params_action = array($id);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
# action query
|
||||
if (isset($sql_action))
|
||||
{
|
||||
$query = $db->getHandle()->prepare($sql_action);
|
||||
$query->execute($params_action);
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
die('action query error : '.$e->getMessage());
|
||||
}
|
||||
|
||||
switch ($view)
|
||||
{
|
||||
case 'archive':
|
||||
$sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
|
||||
$params = array(-1);
|
||||
break;
|
||||
case 'fav' :
|
||||
$sql = "SELECT * FROM entries WHERE is_fav=? ORDER BY id desc";
|
||||
$params = array(-1);
|
||||
break;
|
||||
default:
|
||||
$sql = "SELECT * FROM entries WHERE is_read=? ORDER BY id desc";
|
||||
$params = array(0);
|
||||
$view = 'index';
|
||||
break;
|
||||
}
|
||||
|
||||
# view query
|
||||
try
|
||||
{
|
||||
$query = $db->getHandle()->prepare($sql);
|
||||
$query->execute($params);
|
||||
$entries = $query->fetchAll();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
die('view query error : '.$e->getMessage());
|
||||
}
|
||||
action_to_do($action, $id);
|
||||
$entries = display_view($view);
|
||||
|
||||
$tpl->assign('title', 'poche, a read it later open source system');
|
||||
$tpl->assign('view', $view);
|
||||
|
|
17
view.php
17
view.php
|
@ -10,22 +10,11 @@
|
|||
|
||||
include dirname(__FILE__).'/inc/config.php';
|
||||
|
||||
if(isset($_GET['id']) && $_GET['id'] != '') {
|
||||
$id = (isset ($_GET['id'])) ? htmlspecialchars($_GET['id']) : '';
|
||||
|
||||
$sql = "SELECT * FROM entries WHERE id=?";
|
||||
$params = array(intval($_GET['id']));
|
||||
if(!empty($id)) {
|
||||
|
||||
# view article query
|
||||
try
|
||||
{
|
||||
$query = $db->getHandle()->prepare($sql);
|
||||
$query->execute($params);
|
||||
$entry = $query->fetchAll();
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
die('query error : '.$e->getMessage());
|
||||
}
|
||||
$entry = get_article($id);
|
||||
|
||||
if ($entry != NULL) {
|
||||
$tpl->assign('id', $entry[0]['id']);
|
||||
|
|
Loading…
Reference in a new issue