aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Poche.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche/Poche.class.php')
-rwxr-xr-xinc/poche/Poche.class.php73
1 files changed, 37 insertions, 36 deletions
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index a662f695..90fbcb2d 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -828,7 +828,7 @@ class Poche
828 define('IMPORT_LIMIT', 5); 828 define('IMPORT_LIMIT', 5);
829 } 829 }
830 if (!defined('IMPORT_DELAY')) { 830 if (!defined('IMPORT_DELAY')) {
831 define('IMPORT_DELAY', 5); 831 define('IMPORT_DELAY', 5);
832 } 832 }
833 833
834 if ( isset($_FILES['file']) ) { 834 if ( isset($_FILES['file']) ) {
@@ -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 }
@@ -866,16 +866,16 @@ class Poche
866 $data[] = $record; 866 $data[] = $record;
867 foreach ($record as $record2) { 867 foreach ($record as $record2) {
868 if (is_array($record2)) { 868 if (is_array($record2)) {
869 $data[] = $record2; 869 $data[] = $record2;
870 } 870 }
871 } 871 }
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,16 +883,17 @@ 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
891 } 891 }
892 } 892 }
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 }
@@ -919,17 +920,17 @@ class Poche
919 $purifier = new HTMLPurifier($config); 920 $purifier = new HTMLPurifier($config);
920 921
921 foreach ($items as $item) { 922 foreach ($items as $item) {
922 $url = new Url(base64_encode($item['url'])); 923 $url = new Url(base64_encode($item['url']));
923 $content = Tools::getPageContent($url); 924 $content = Tools::getPageContent($url);
924 925
925 $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled')); 926 $title = (($content['rss']['channel']['item']['title'] != '') ? $content['rss']['channel']['item']['title'] : _('Untitled'));
926 $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined')); 927 $body = (($content['rss']['channel']['item']['description'] != '') ? $content['rss']['channel']['item']['description'] : _('Undefined'));
927 928
928 //clean content to prevent xss attack 929 //clean content to prevent xss attack
929 $title = $purifier->purify($title); 930 $title = $purifier->purify($title);
930 $body = $purifier->purify($body); 931 $body = $purifier->purify($body);
931 932
932 $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId()); 933 $this->store->updateContentAndTitle($item['id'], $title, $body, $this->user->getId());
933 } 934 }
934 935
935 } 936 }
@@ -944,8 +945,8 @@ class Poche
944 */ 945 */
945 public function export() 946 public function export()
946 { 947 {
947 $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json"; 948 $filename = "wallabag-export-".$this->user->getId()."-".date("Y-m-d").".json";
948 header('Content-Disposition: attachment; filename='.$filename); 949 header('Content-Disposition: attachment; filename='.$filename);
949 950
950 $entries = $this->store->retrieveAll($this->user->getId()); 951 $entries = $this->store->retrieveAll($this->user->getId());
951 echo $this->tpl->render('export.twig', array( 952 echo $this->tpl->render('export.twig', array(
@@ -978,13 +979,13 @@ class Poche
978 public function generateToken() 979 public function generateToken()
979 { 980 {
980 if (ini_get('open_basedir') === '') { 981 if (ini_get('open_basedir') === '') {
981 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 982 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
982 echo 'This is a server using Windows!'; 983 echo 'This is a server using Windows!';
983 // alternative to /dev/urandom for Windows 984 // alternative to /dev/urandom for Windows
984 $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); 985 $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);
985 } else { 986 } else {
986 $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15); 987 $token = substr(base64_encode(file_get_contents('/dev/urandom', false, null, 0, 20)), 0, 15);
987 } 988 }
988 } 989 }
989 else { 990 else {
990 $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20); 991 $token = substr(base64_encode(uniqid(mt_rand(), true)), 0, 20);