diff options
-rwxr-xr-x | inc/poche/Poche.class.php | 113 |
1 files changed, 56 insertions, 57 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index a7bee65d..613377c6 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -844,18 +844,18 @@ class Poche | |||
844 | $read = 0; | 844 | $read = 0; |
845 | foreach (array('ol','ul') as $list) { | 845 | foreach (array('ol','ul') as $list) { |
846 | foreach ($html->find($list) as $ul) { | 846 | foreach ($html->find($list) as $ul) { |
847 | foreach ($ul->find('li') as $li) { | 847 | foreach ($ul->find('li') as $li) { |
848 | $tmpEntry = array(); | 848 | $tmpEntry = array(); |
849 | $a = $li->find('a'); | 849 | $a = $li->find('a'); |
850 | $tmpEntry['url'] = $a[0]->href; | 850 | $tmpEntry['url'] = $a[0]->href; |
851 | $tmpEntry['tags'] = $a[0]->tags; | 851 | $tmpEntry['tags'] = $a[0]->tags; |
852 | $tmpEntry['is_read'] = $read; | 852 | $tmpEntry['is_read'] = $read; |
853 | if ($tmpEntry['url']) { | 853 | if ($tmpEntry['url']) { |
854 | $data[] = $tmpEntry; | 854 | $data[] = $tmpEntry; |
855 | } | 855 | } |
856 | } | 856 | } |
857 | # the second <ol/ul> is for read links | 857 | # the second <ol/ul> is for read links |
858 | $read = ((sizeof($data) && $read)?0:1); | 858 | $read = ((sizeof($data) && $read)?0:1); |
859 | } | 859 | } |
860 | } | 860 | } |
861 | } | 861 | } |
@@ -872,10 +872,10 @@ class Poche | |||
872 | } | 872 | } |
873 | } | 873 | } |
874 | 874 | ||
875 | $i = 0; //counter for articles inserted | 875 | $urlsInserted = array(); //urls of articles inserted |
876 | foreach ($data as $record) { | 876 | foreach ($data as $record) { |
877 | $url = trim( isset($record['article__url']) ? $record['article__url'] : (isset($record['url']) ? $record['url'] : '') ); | 877 | $url = trim( isset($record['article__url']) ? $record['article__url'] : (isset($record['url']) ? $record['url'] : '') ); |
878 | if ( $url ) { | 878 | if ( $url and !in_array($url, $urlsInserted) ) { |
879 | $title = (isset($record['title']) ? $record['title'] : _('Untitled - Import - ').'</a> <a href="./?import">'._('click to finish import').'</a><a>'); | 879 | $title = (isset($record['title']) ? $record['title'] : _('Untitled - Import - ').'</a> <a href="./?import">'._('click to finish import').'</a><a>'); |
880 | $body = (isset($record['content']) ? $record['content'] : ''); | 880 | $body = (isset($record['content']) ? $record['content'] : ''); |
881 | $isRead = (isset($record['is_read']) ? intval($record['is_read']) : (isset($record['archive'])?intval($record['archive']):0)); | 881 | $isRead = (isset($record['is_read']) ? intval($record['is_read']) : (isset($record['archive'])?intval($record['archive']):0)); |
@@ -883,8 +883,8 @@ class Poche | |||
883 | //insert new record | 883 | //insert new record |
884 | $id = $this->store->add($url, $title, $body, $this->user->getId(), $isFavorite, $isRead); | 884 | $id = $this->store->add($url, $title, $body, $this->user->getId(), $isFavorite, $isRead); |
885 | if ( $id ) { | 885 | if ( $id ) { |
886 | //increment no of records inserted | 886 | $urlsInserted[] = $url; //add |
887 | $i++; | 887 | |
888 | if ( isset($record['tags']) && trim($record['tags']) ) { | 888 | if ( isset($record['tags']) && trim($record['tags']) ) { |
889 | //@TODO: set tags | 889 | //@TODO: set tags |
890 | 890 | ||
@@ -893,6 +893,7 @@ class Poche | |||
893 | } | 893 | } |
894 | } | 894 | } |
895 | 895 | ||
896 | $i = sizeof($urlsInserted); | ||
896 | if ( $i > 0 ) { | 897 | if ( $i > 0 ) { |
897 | $this->messages->add('s', _('Articles inserted: ').$i._('. Please note, that some may be marked as "read".')); | 898 | $this->messages->add('s', _('Articles inserted: ').$i._('. Please note, that some may be marked as "read".')); |
898 | } | 899 | } |
@@ -942,16 +943,15 @@ class Poche | |||
942 | * export poche entries in json | 943 | * export poche entries in json |
943 | * @return json all poche entries | 944 | * @return json all poche entries |
944 | */ | 945 | */ |
945 | public function export() | 946 | public function export() { |
946 | { | 947 | $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; |
947 | $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; | 948 | header('Content-Disposition: attachment; filename='.$filename); |
948 | header('Content-Disposition: attachment; filename='.$filename); | 949 | |
949 | 950 | $entries = $this->store->retrieveAll($this->user->getId()); | |
950 | $entries = $this->store->retrieveAll($this->user->getId()); | 951 | echo $this->tpl->render('export.twig', array( |
951 | echo $this->tpl->render('export.twig', array( | 952 | 'export' => Tools::renderJson($entries), |
952 | 'export' => Tools::renderJson($entries), | 953 | )); |
953 | )); | 954 | Tools::logm('export view'); |
954 | Tools::logm('export view'); | ||
955 | } | 955 | } |
956 | 956 | ||
957 | /** | 957 | /** |
@@ -959,43 +959,42 @@ class Poche | |||
959 | * @param string $which 'prod' or 'dev' | 959 | * @param string $which 'prod' or 'dev' |
960 | * @return string latest $which version | 960 | * @return string latest $which version |
961 | */ | 961 | */ |
962 | private function getPocheVersion($which = 'prod') | 962 | private function getPocheVersion($which = 'prod') { |
963 | { | 963 | $cache_file = CACHE . '/' . $which; |
964 | $cache_file = CACHE . '/' . $which; | 964 | $check_time = time(); |
965 | $check_time = time(); | 965 | |
966 | 966 | # checks if the cached version file exists | |
967 | # checks if the cached version file exists | 967 | if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { |
968 | if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 86400 ))) { | 968 | $version = file_get_contents($cache_file); |
969 | $version = file_get_contents($cache_file); | 969 | $check_time = filemtime($cache_file); |
970 | $check_time = filemtime($cache_file); | 970 | } else { |
971 | } else { | 971 | $version = file_get_contents('http://static.wallabag.org/versions/' . $which); |
972 | $version = file_get_contents('http://static.wallabag.org/versions/' . $which); | 972 | file_put_contents($cache_file, $version, LOCK_EX); |
973 | file_put_contents($cache_file, $version, LOCK_EX); | 973 | } |
974 | } | 974 | return array($version, $check_time); |
975 | return array($version, $check_time); | ||
976 | } | 975 | } |
977 | 976 | ||
978 | public function generateToken() | 977 | public function generateToken() |
979 | { | 978 | { |
980 | if (ini_get('open_basedir') === '') { | 979 | if (ini_get('open_basedir') === '') { |
981 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { | 980 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
982 | echo 'This is a server using Windows!'; | 981 | echo 'This is a server using Windows!'; |
983 | // alternative to /dev/urandom for Windows | 982 | // alternative to /dev/urandom for Windows |
984 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); | 983 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); |
985 | } else { | 984 | } else { |
986 | $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); | 985 | $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); |
987 | } | ||
988 | } | ||
989 | else { | ||
990 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); | ||
991 | } | 986 | } |
987 | } | ||
988 | else { | ||
989 | $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); | ||
990 | } | ||
992 | 991 | ||
993 | $token = str_replace('+', '', $token); | 992 | $token = str_replace('+', '', $token); |
994 | $this->store->updateUserConfig($this->user->getId(), 'token', $token); | 993 | $this->store->updateUserConfig($this->user->getId(), 'token', $token); |
995 | $currentConfig = $_SESSION['poche_user']->config; | 994 | $currentConfig = $_SESSION['poche_user']->config; |
996 | $currentConfig['token'] = $token; | 995 | $currentConfig['token'] = $token; |
997 | $_SESSION['poche_user']->setConfig($currentConfig); | 996 | $_SESSION['poche_user']->setConfig($currentConfig); |
998 | Tools::redirect(); | 997 | Tools::redirect(); |
999 | } | 998 | } |
1000 | 999 | ||
1001 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home') | 1000 | public function generateFeeds($token, $user_id, $tag_id, $type = 'home') |