aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php65
1 files changed, 30 insertions, 35 deletions
diff --git a/index.php b/index.php
index 01122ebf..47bae6e8 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';
@@ -1522,7 +1523,7 @@ function renderPage()
1522 1523
1523 // -------- User want to post a new link: Display link edit form. 1524 // -------- User want to post a new link: Display link edit form.
1524 if (isset($_GET['post'])) { 1525 if (isset($_GET['post'])) {
1525 $url = cleanup_url(escape($_GET['post'])); 1526 $url = cleanup_url($_GET['post']);
1526 1527
1527 $link_is_new = false; 1528 $link_is_new = false;
1528 // Check if URL is not already in database (in this case, we will edit the existing link) 1529 // Check if URL is not already in database (in this case, we will edit the existing link)
@@ -1547,8 +1548,8 @@ function renderPage()
1547 // Extract title. 1548 // Extract title.
1548 $title = html_extract_title($content); 1549 $title = html_extract_title($content);
1549 // Re-encode title in utf-8 if necessary. 1550 // Re-encode title in utf-8 if necessary.
1550 if (! empty($title) && $charset != 'utf-8') { 1551 if (! empty($title) && strtolower($charset) != 'utf-8') {
1551 $title = mb_convert_encoding($title, $charset, 'utf-8'); 1552 $title = mb_convert_encoding($title, 'utf-8', $charset);
1552 } 1553 }
1553 } 1554 }
1554 } 1555 }
@@ -1557,6 +1558,8 @@ function renderPage()
1557 $url = '?' . smallHash($linkdate); 1558 $url = '?' . smallHash($linkdate);
1558 $title = 'Note: '; 1559 $title = 'Note: ';
1559 } 1560 }
1561 $url = escape($url);
1562 $title = escape($title);
1560 1563
1561 $link = array( 1564 $link = array(
1562 'linkdate' => $linkdate, 1565 'linkdate' => $linkdate,
@@ -1588,44 +1591,36 @@ function renderPage()
1588 } 1591 }
1589 1592
1590 // -------- Export as Netscape Bookmarks HTML file. 1593 // -------- Export as Netscape Bookmarks HTML file.
1591 if ($targetPage == Router::$PAGE_EXPORT) 1594 if ($targetPage == Router::$PAGE_EXPORT) {
1592 { 1595 if (empty($_GET['selection'])) {
1593 if (empty($_GET['what']))
1594 {
1595 $PAGE->assign('linkcount',count($LINKSDB)); 1596 $PAGE->assign('linkcount',count($LINKSDB));
1596 $PAGE->renderPage('export'); 1597 $PAGE->renderPage('export');
1597 exit; 1598 exit;
1598 } 1599 }
1599 $exportWhat=$_GET['what'];
1600 if (!array_intersect(array('all','public','private'),array($exportWhat))) die('What are you trying to export???');
1601 1600
1602 header('Content-Type: text/html; charset=utf-8'); 1601 // export as bookmarks_(all|private|public)_YYYYmmdd_HHMMSS.html
1603 header('Content-disposition: attachment; filename=bookmarks_'.$exportWhat.'_'.strval(date('Ymd_His')).'.html'); 1602 $selection = $_GET['selection'];
1604 $currentdate=date('Y/m/d H:i:s'); 1603 try {
1605 echo <<<HTML 1604 $PAGE->assign(
1606<!DOCTYPE NETSCAPE-Bookmark-file-1> 1605 'links',
1607<!-- This is an automatically generated file. 1606 NetscapeBookmarkUtils::filterAndFormat($LINKSDB, $selection)
1608 It will be read and overwritten. 1607 );
1609 DO NOT EDIT! --> 1608 } catch (Exception $exc) {
1610<!-- Shaarli {$exportWhat} bookmarks export on {$currentdate} --> 1609 header('Content-Type: text/plain; charset=utf-8');
1611<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> 1610 echo $exc->getMessage();
1612<TITLE>Bookmarks</TITLE> 1611 exit;
1613<H1>Bookmarks</H1>
1614HTML;
1615 foreach($LINKSDB as $link)
1616 {
1617 if ($exportWhat=='all' ||
1618 ($exportWhat=='private' && $link['private']!=0) ||
1619 ($exportWhat=='public' && $link['private']==0))
1620 {
1621 $date = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $link['linkdate']);
1622 echo '<DT><A HREF="'.$link['url'].'" ADD_DATE="'.$date->getTimestamp().'" PRIVATE="'.$link['private'].'"';
1623 if ($link['tags']!='') echo ' TAGS="'.str_replace(' ',',',$link['tags']).'"';
1624 echo '>'.$link['title']."</A>\n";
1625 if ($link['description']!='') echo '<DD>'.$link['description']."\n";
1626 }
1627 } 1612 }
1628 exit; 1613 $now = new DateTime();
1614 header('Content-Type: text/html; charset=utf-8');
1615 header(
1616 'Content-disposition: attachment; filename=bookmarks_'
1617 .$selection.'_'.$now->format(LinkDB::LINK_DATE_FORMAT).'.html'
1618 );
1619 $PAGE->assign('date', $now->format(DateTime::RFC822));
1620 $PAGE->assign('eol', PHP_EOL);
1621 $PAGE->assign('selection', $selection);
1622 $PAGE->renderPage('export.bookmarks');
1623 exit;
1629 } 1624 }
1630 1625
1631 // -------- User is uploading a file for import 1626 // -------- User is uploading a file for import