]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | /** | |
3 | * poche, a read it later open source system | |
4 | * | |
5 | * @category poche | |
6 | * @author Nicolas Lœuillet <support@inthepoche.com> | |
7 | * @copyright 2013 | |
8 | * @license http://www.wtfpl.net/ see COPYING file | |
9 | */ | |
10 | ||
11 | set_time_limit(0); | |
12 | ||
13 | include dirname(__FILE__).'/inc/config.php'; | |
14 | include dirname(__FILE__).'/inc/simple_html_dom.php'; | |
15 | ||
16 | if (!isset($_GET['start'])) { | |
17 | echo ' | |
18 | Please execute the import script locally, it can take a very long time. <br /><br /> | |
19 | Please choose between Pocket & Readabilty : | |
20 | <br /><a href="import.php?start=pocket">Bye bye Pocket, let\'s go !</a> | |
21 | <br /><a href="import.php?start=readability">Bye bye Readability, let\'s go !</a>'; | |
22 | } | |
23 | else { | |
24 | if ($_GET['start'] == 'pocket') { | |
25 | $html = new simple_html_dom(); | |
26 | $html->load_file('ril_export.html'); | |
27 | ||
28 | $read = 0; | |
29 | $errors = array(); | |
30 | foreach($html->find('ul') as $ul) | |
31 | { | |
32 | foreach($ul->find('li') as $li) | |
33 | { | |
34 | $a = $li->find('a'); | |
35 | $url = $a[0]->href; | |
36 | ||
37 | action_to_do('add', $url); | |
38 | if ($read == '1') { | |
39 | $last_id = $db->getHandle()->lastInsertId(); | |
40 | $sql_update = "UPDATE entries SET is_read=~is_read WHERE id=?"; | |
41 | $params_update = array($last_id); | |
42 | $query_update = $db->getHandle()->prepare($sql_update); | |
43 | $query_update->execute($params_update); | |
44 | } | |
45 | } | |
46 | # Pocket génère un fichier HTML avec deux <ul> | |
47 | # Le premier concerne les éléments non lus | |
48 | # Le second concerne les éléments archivés | |
49 | $read = 1; | |
50 | } | |
51 | ||
52 | echo 'Import from Pocket completed. <a href="index.php">Welcome to #poche !</a>'; | |
53 | logm('import from pocket completed'); | |
54 | } | |
55 | else if ($_GET['start'] == 'readability') { | |
56 | $str_data = file_get_contents("readability"); | |
57 | $data = json_decode($str_data,true); | |
58 | ||
59 | foreach ($data as $key => $value) { | |
60 | $url = ''; | |
61 | foreach ($value as $key2 => $value2) { | |
62 | if ($key2 == 'article__url') { | |
63 | $url = $value2; | |
64 | } | |
65 | } | |
66 | if ($url != '') | |
67 | action_to_do('add', $url); | |
68 | } | |
69 | ||
70 | echo 'Import from Readability completed. <a href="index.php">Welcome to #poche !</a>'; | |
71 | logm('import from Readability completed'); | |
72 | } | |
73 | else { | |
74 | echo 'Error with the import. <a href="index.php">Welcome to #poche !</a>'; | |
75 | logm('error with the import'); | |
76 | } | |
77 | } |