aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2016-04-12 23:48:00 +0200
committerVirtualTam <virtualtam@flibidi.net>2016-04-12 23:48:00 +0200
commit9f400b0dad68b82d65692bd6ab6190f6a787fa89 (patch)
tree7abb6d242fc551b33b1d5b9f066fdabf4ef64c4d /index.php
parent745304c842e6e1234aac41a3f1c496c4522f32c5 (diff)
parentcd5327bee83f3e9467d786752bbd447963b941f7 (diff)
downloadShaarli-9f400b0dad68b82d65692bd6ab6190f6a787fa89.tar.gz
Shaarli-9f400b0dad68b82d65692bd6ab6190f6a787fa89.tar.zst
Shaarli-9f400b0dad68b82d65692bd6ab6190f6a787fa89.zip
Merge pull request #538 from virtualtam/fix/bookmark-export
Refactor Netscape bookmark exporting
Diffstat (limited to 'index.php')
-rw-r--r--index.php57
1 files changed, 25 insertions, 32 deletions
diff --git a/index.php b/index.php
index d3369a2d..456d93c2 100644
--- a/index.php
+++ b/index.php
@@ -161,6 +161,7 @@ require_once 'application/HttpUtils.php';
161require_once 'application/LinkDB.php'; 161require_once 'application/LinkDB.php';
162require_once 'application/LinkFilter.php'; 162require_once 'application/LinkFilter.php';
163require_once 'application/LinkUtils.php'; 163require_once 'application/LinkUtils.php';
164require_once 'application/NetscapeBookmarkUtils.php';
164require_once 'application/TimeZone.php'; 165require_once 'application/TimeZone.php';
165require_once 'application/Url.php'; 166require_once 'application/Url.php';
166require_once 'application/Utils.php'; 167require_once 'application/Utils.php';
@@ -1584,44 +1585,36 @@ function renderPage()
1584 } 1585 }
1585 1586
1586 // -------- Export as Netscape Bookmarks HTML file. 1587 // -------- Export as Netscape Bookmarks HTML file.
1587 if ($targetPage == Router::$PAGE_EXPORT) 1588 if ($targetPage == Router::$PAGE_EXPORT) {
1588 { 1589 if (empty($_GET['selection'])) {
1589 if (empty($_GET['what']))
1590 {
1591 $PAGE->assign('linkcount',count($LINKSDB)); 1590 $PAGE->assign('linkcount',count($LINKSDB));
1592 $PAGE->renderPage('export'); 1591 $PAGE->renderPage('export');
1593 exit; 1592 exit;
1594 } 1593 }
1595 $exportWhat=$_GET['what'];
1596 if (!array_intersect(array('all','public','private'),array($exportWhat))) die('What are you trying to export???');
1597 1594
1598 header('Content-Type: text/html; charset=utf-8'); 1595 // export as bookmarks_(all|private|public)_YYYYmmdd_HHMMSS.html
1599 header('Content-disposition: attachment; filename=bookmarks_'.$exportWhat.'_'.strval(date('Ymd_His')).'.html'); 1596 $selection = $_GET['selection'];
1600 $currentdate=date('Y/m/d H:i:s'); 1597 try {
1601 echo <<<HTML 1598 $PAGE->assign(
1602<!DOCTYPE NETSCAPE-Bookmark-file-1> 1599 'links',
1603<!-- This is an automatically generated file. 1600 NetscapeBookmarkUtils::filterAndFormat($LINKSDB, $selection)
1604 It will be read and overwritten. 1601 );
1605 DO NOT EDIT! --> 1602 } catch (Exception $exc) {
1606<!-- Shaarli {$exportWhat} bookmarks export on {$currentdate} --> 1603 header('Content-Type: text/plain; charset=utf-8');
1607<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> 1604 echo $exc->getMessage();
1608<TITLE>Bookmarks</TITLE> 1605 exit;
1609<H1>Bookmarks</H1>
1610HTML;
1611 foreach($LINKSDB as $link)
1612 {
1613 if ($exportWhat=='all' ||
1614 ($exportWhat=='private' && $link['private']!=0) ||
1615 ($exportWhat=='public' && $link['private']==0))
1616 {
1617 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
1618 echo '<DT><A HREF="'.$link['url'].'" ADD_DATE="'.$date->getTimestamp().'" PRIVATE="'.$link['private'].'"';
1619 if ($link['tags']!='') echo ' TAGS="'.str_replace(' ',',',$link['tags']).'"';
1620 echo '>'.$link['title']."</A>\n";
1621 if ($link['description']!='') echo '<DD>'.$link['description']."\n";
1622 }
1623 } 1606 }
1624 exit; 1607 $now = new DateTime();
1608 header('Content-Type: text/html; charset=utf-8');
1609 header(
1610 'Content-disposition: attachment; filename=bookmarks_'
1611 .$selection.'_'.$now->format(LinkDB::LINK_DATE_FORMAT).'.html'
1612 );
1613 $PAGE->assign('date', $now->format(DateTime::RFC822));
1614 $PAGE->assign('eol', PHP_EOL);
1615 $PAGE->assign('selection', $selection);
1616 $PAGE->renderPage('export.bookmarks');
1617 exit;
1625 } 1618 }
1626 1619
1627 // -------- User is uploading a file for import 1620 // -------- User is uploading a file for import