aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
blob: ef18254a4166f5a58976522dd8b270bad5ab8ae0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
 * poche, a read it later open source system
 *
 * @category   poche
 * @author     Nicolas LÅ“uillet <support@inthepoche.com>
 * @copyright  2013
 * @license    http://www.wtfpl.net/ see COPYING file
 */

include dirname(__FILE__).'/inc/config.php';

$action = (isset ($_GET['action'])) ? htmlspecialchars($_GET['action']) : '';
$view   = (isset ($_GET['view'])) ? htmlspecialchars($_GET['view']) : '';
$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());
}

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