X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=babce3dca8f6aa5b380b1c11775cec37883af557;hb=9aadcdaefaceec86c0610499e48bc41273f5d26f;hp=520d7d30af41cfc17f721334279d7a15fabb3c7d;hpb=ef4275c50edad6de268d53214db37f071e227b34;p=github%2Fshaarli%2FShaarli.git diff --git a/index.php b/index.php index 520d7d30..babce3dc 100644 --- a/index.php +++ b/index.php @@ -1,5 +1,5 @@ getLinkFromUrl($url); // Check if URL is not already in database (in this case, we will edit the existing link) @@ -853,7 +858,8 @@ Import Netscape html bookmarks (as exported from Firefox/Chrome/Opera/delicious/
-  Import all links as private +  Import all links as private
+  Overwrite existing links HTML; @@ -884,6 +890,8 @@ function importFile() $filesize=$_FILES['filetoupload']['size']; $data=file_get_contents($_FILES['filetoupload']['tmp_name']); $private = (empty($_POST['private']) ? 0 : 1); // Should the links be imported as private ? + $overwrite = !empty($_POST['overwrite']) ; // Should the imported links overwrite existing ones ? + $import_count=0; // Sniff file type: $type='unknown'; @@ -895,35 +903,35 @@ function importFile() // This is a standard Netscape-style bookmark file. // This format is supported by all browsers (except IE, of course), also delicious, diigo and others. // I didn't want to use DOM... anyway, this is FAST (less than 1 second to import 7200 links (2.1 Mb html file)). - $before=count($LINKSDB); foreach(explode('
',$data) as $html) // explode is very fast { $link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0); $d = explode('
',$html); if (startswith($d[0],'(.*?)!i',$d[0],$matches); $link['title'] = (isset($matches[1]) ? trim($matches[1]) : ''); // Get title + $link['title'] = html_entity_decode($link['title'],ENT_QUOTES,'UTF-8'); preg_match_all('! ([A-Z_]+)=\"(.*?)"!i',$html,$matches,PREG_SET_ORDER); // Get all other attributes foreach($matches as $m) { $attr=$m[1]; $value=$m[2]; - if ($attr=='HREF') $link['url']=$value; + if ($attr=='HREF') $link['url']=html_entity_decode($value,ENT_QUOTES,'UTF-8'); elseif ($attr=='ADD_DATE') $link['linkdate']=date('Ymd_His',intval($value)); elseif ($attr=='PRIVATE') $link['private']=($value=='0'?0:1); - elseif ($attr=='TAGS') $link['tags']=str_replace(',',' ',$value); + elseif ($attr=='TAGS') $link['tags']=html_entity_decode(str_replace(',',' ',$value),ENT_QUOTES,'UTF-8'); } - if ($link['linkdate']!='' && $link['url']!='' && empty($LINKSDB[$link['linkdate']])) + if ($link['linkdate']!='' && $link['url']!='' && ($overwrite || empty($LINKSDB[$link['linkdate']]))) { if ($private==1) $link['private']=1; $LINKSDB[$link['linkdate']] = $link; + $import_count++; } } } - $import_count = count($LINKSDB)-$before; $LINKSDB->savedb(); invalidateCaches(); - echo ''; + echo ''; } else { @@ -1095,70 +1103,9 @@ JS; {$open}Shaarli - Let's shaare your links... - + + {$jsincludes} -