- Import - Import Netscape html bookmarks (as exported from Firefox, Chrome, Opera, delicious...)
- Export - Export Netscape html bookmarks (which can be imported in Firefox, Chrome, Opera, delicious...)
- Shaare link - Drag this link to your bookmarks toolbar (or right-click it and choose Bookmark This Link....). Then click "Shaare link" button in any page you want to share.
@@ -1196,8 +1199,7 @@ HTML;
if ($link['description']!='') echo '
'.htmlspecialchars($link['description'])."\n";
}
}
- echo '\n";
- exit;
+ exit;
}
// -------- User is uploading a file for import
@@ -1272,7 +1274,6 @@ 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)).
foreach(explode('
',$data) as $html) // explode is very fast
{
$link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0);
@@ -1283,19 +1284,42 @@ function importFile()
preg_match('!(.*?)!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
+ $raw_add_date=0;
foreach($matches as $m)
{
$attr=$m[1]; $value=$m[2];
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=='ADD_DATE') $raw_add_date=intval($value);
elseif ($attr=='PRIVATE') $link['private']=($value=='0'?0:1);
elseif ($attr=='TAGS') $link['tags']=html_entity_decode(str_replace(',',' ',$value),ENT_QUOTES,'UTF-8');
}
- if ($link['linkdate']!='' && $link['url']!='' && ($overwrite || empty($LINKSDB[$link['linkdate']])))
+ if ($link['url']!='')
{
if ($private==1) $link['private']=1;
- $LINKSDB[$link['linkdate']] = $link;
- $import_count++;
+ $dblink = $LINKSDB->getLinkFromUrl($link['url']); // See if the link is already in database.
+ if ($dblink==false)
+ { // Link not in database, let's import it...
+ if (empty($raw_add_date)) $raw_add_date=time(); // In case of shitty bookmark file with no ADD_DATE
+
+ // Make sure date/time is not already used by another link.
+ // (Some bookmark files have several different links with the same ADD_DATE)
+ // We increment date by 1 second until we find a date which is not used in db.
+ // (so that links that have the same date/time are more or less kept grouped by date, but do not conflict.)
+ while (!empty($LINKSDB[date('Ymd_His',$raw_add_date)])) { $raw_add_date++; }// Yes, I know it's ugly.
+ $link['linkdate']=date('Ymd_His',$raw_add_date);
+ $LINKSDB[$link['linkdate']] = $link;
+ $import_count++;
+ }
+ else // link already present in database.
+ {
+ if ($overwrite)
+ { // If overwrite is required, we import link data, except date/time.
+ $link['linkdate']=$dblink['linkdate'];
+ $LINKSDB[$link['linkdate']] = $link;
+ $import_count++;
+ }
+ }
+
}
}
}
@@ -1417,9 +1441,9 @@ function templateLinkList()
$classprivate = ($link['private']==0 ? $classLi : 'class="private"');
if (isLoggedIn())
{
- $actions=' ';
+ $actions=' ';
$actions.=' ';
+ $actions.='';
}
$tags='';
if ($link['tags']!='')
@@ -1520,16 +1544,16 @@ function thumbnail($url,$href=false)
|| $domain=='ted.com' || endsWith($domain,'.ted.com')
)
{
- if ($domain=='vimeo.com')
- { // Make sure this vimeo url points to a video (/xxx... where xxx is numeric)
- $path = parse_url($url,PHP_URL_PATH);
- if (!preg_match('!/\d+.+?!',$path)) return ''; // This is not a single video URL.
- }
- if ($domain=='ted.com' || endsWith($domain,'.ted.com'))
- { // Make sure this TED url points to a video (/talks/...)
- $path = parse_url($url,PHP_URL_PATH);
- if ("/talks/" !== substr($path,0,7)) return ''; // This is not a single video URL.
- }
+ if ($domain=='vimeo.com')
+ { // Make sure this vimeo url points to a video (/xxx... where xxx is numeric)
+ $path = parse_url($url,PHP_URL_PATH);
+ if (!preg_match('!/\d+.+?!',$path)) return ''; // This is not a single video URL.
+ }
+ if ($domain=='ted.com' || endsWith($domain,'.ted.com'))
+ { // Make sure this TED url points to a video (/talks/...)
+ $path = parse_url($url,PHP_URL_PATH);
+ if ("/talks/" !== substr($path,0,7)) return ''; // This is not a single video URL.
+ }
$sign = hash_hmac('sha256', $url, $GLOBALS['salt']); // We use the salt to sign data (it's random, secret, and specific to each installation)
return '';
}
@@ -1563,15 +1587,25 @@ function templatePage($data)
$newversion=checkUpdate();
if ($newversion!='') $newversion='
● Shaarli '.htmlspecialchars($newversion).' is available.
';
$linkcount = count($LINKSDB);
+
+ $feedurl=htmlspecialchars(serverUrl().$_SERVER['SCRIPT_NAME']);
+ $searchcrits=''; // Search criteria
+ if (!empty($_GET['searchtags'])) $searchcrits.='&searchtags='.$_GET['searchtags'];
+ elseif (!empty($_GET['searchterm'])) $searchcrits.='&searchterm='.$_GET['searchterm'];
+ $filtered_feed= ($searchcrits=='' ? '' : 'Filtered ');
+
$open='';
if ($GLOBALS['config']['OPEN_SHAARLI'])
{
- $menu=' ToolsAdd link';
+ $menu='ToolsAdd link';
$open='Open ';
}
else
- $menu=(isLoggedIn() ? ' LogoutToolsAdd link' : ' Login');
-
+ $menu=(isLoggedIn() ? 'LogoutToolsAdd link' : ' Login');
+ $menu='Home'.$menu.'RSS FeedATOM FeedTag cloudPicture wall';
+ # If we are in the bookmarklet popup, do not display menu.
+ if (!empty($_GET['source']) && $_GET['source']=='bookmarklet') $menu='';
+
foreach(array('pageheader','body','onload') as $k) // make sure all required fields exist (put an empty string if not).
{
if (!array_key_exists($k,$data)) $data[$k]='';
@@ -1592,15 +1626,12 @@ $(document).ready(function()
JS;
}
- $feedurl=htmlspecialchars(serverUrl().$_SERVER['SCRIPT_NAME']);
- $searchcrits=''; // Search criteria
- if (!empty($_GET['searchtags'])) $searchcrits.='&searchtags='.$_GET['searchtags'];
- elseif (!empty($_GET['searchterm'])) $searchcrits.='&searchterm='.$_GET['searchterm'];
- $filtered_feed= ($searchcrits=='' ? '' : 'Filtered ');
+
$version=shaarli_version;
$title = htmlspecialchars( $GLOBALS['title'] );
$pagetitle = htmlspecialchars( empty($GLOBALS['pagetitle']) ? $title : $GLOBALS['pagetitle'] );
+
echo <<
@@ -1609,19 +1640,19 @@ JS;
+
{$jsincludes}
{$newversion}
-