diff options
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 102 |
1 files changed, 46 insertions, 56 deletions
@@ -100,6 +100,7 @@ $GLOBALS['config']['ENABLE_LOCALCACHE'] = true; | |||
100 | $GLOBALS['config']['UPDATECHECK_BRANCH'] = 'stable'; | 100 | $GLOBALS['config']['UPDATECHECK_BRANCH'] = 'stable'; |
101 | $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400; | 101 | $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400; |
102 | 102 | ||
103 | $GLOBALS['config']['REDIRECTOR_URLENCODE'] = true; | ||
103 | 104 | ||
104 | /* | 105 | /* |
105 | * Plugin configuration | 106 | * Plugin configuration |
@@ -160,6 +161,7 @@ require_once 'application/HttpUtils.php'; | |||
160 | require_once 'application/LinkDB.php'; | 161 | require_once 'application/LinkDB.php'; |
161 | require_once 'application/LinkFilter.php'; | 162 | require_once 'application/LinkFilter.php'; |
162 | require_once 'application/LinkUtils.php'; | 163 | require_once 'application/LinkUtils.php'; |
164 | require_once 'application/NetscapeBookmarkUtils.php'; | ||
163 | require_once 'application/TimeZone.php'; | 165 | require_once 'application/TimeZone.php'; |
164 | require_once 'application/Url.php'; | 166 | require_once 'application/Url.php'; |
165 | require_once 'application/Utils.php'; | 167 | require_once 'application/Utils.php'; |
@@ -706,7 +708,8 @@ function showDailyRSS() { | |||
706 | $GLOBALS['config']['DATASTORE'], | 708 | $GLOBALS['config']['DATASTORE'], |
707 | isLoggedIn(), | 709 | isLoggedIn(), |
708 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'], | 710 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'], |
709 | $GLOBALS['redirector'] | 711 | $GLOBALS['redirector'], |
712 | $GLOBALS['config']['REDIRECTOR_URLENCODE'] | ||
710 | ); | 713 | ); |
711 | 714 | ||
712 | /* Some Shaarlies may have very few links, so we need to look | 715 | /* Some Shaarlies may have very few links, so we need to look |
@@ -791,16 +794,10 @@ function showDailyRSS() { | |||
791 | * Show the 'Daily' page. | 794 | * Show the 'Daily' page. |
792 | * | 795 | * |
793 | * @param PageBuilder $pageBuilder Template engine wrapper. | 796 | * @param PageBuilder $pageBuilder Template engine wrapper. |
797 | * @param LinkDB $LINKSDB LinkDB instance. | ||
794 | */ | 798 | */ |
795 | function showDaily($pageBuilder) | 799 | function showDaily($pageBuilder, $LINKSDB) |
796 | { | 800 | { |
797 | $LINKSDB = new LinkDB( | ||
798 | $GLOBALS['config']['DATASTORE'], | ||
799 | isLoggedIn(), | ||
800 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'], | ||
801 | $GLOBALS['redirector'] | ||
802 | ); | ||
803 | |||
804 | $day=Date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD. | 801 | $day=Date('Ymd',strtotime('-1 day')); // Yesterday, in format YYYYMMDD. |
805 | if (isset($_GET['day'])) $day=$_GET['day']; | 802 | if (isset($_GET['day'])) $day=$_GET['day']; |
806 | 803 | ||
@@ -892,7 +889,8 @@ function renderPage() | |||
892 | $GLOBALS['config']['DATASTORE'], | 889 | $GLOBALS['config']['DATASTORE'], |
893 | isLoggedIn(), | 890 | isLoggedIn(), |
894 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'], | 891 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'], |
895 | $GLOBALS['redirector'] | 892 | $GLOBALS['redirector'], |
893 | $GLOBALS['config']['REDIRECTOR_URLENCODE'] | ||
896 | ); | 894 | ); |
897 | 895 | ||
898 | $updater = new Updater( | 896 | $updater = new Updater( |
@@ -1015,11 +1013,16 @@ function renderPage() | |||
1015 | return strcasecmp($a, $b); | 1013 | return strcasecmp($a, $b); |
1016 | }); | 1014 | }); |
1017 | 1015 | ||
1018 | $tagList=array(); | 1016 | $tagList = array(); |
1019 | foreach($tags as $key=>$value) | 1017 | foreach($tags as $key => $value) { |
1020 | // Tag font size scaling: default 15 and 30 logarithm bases affect scaling, 22 and 6 are arbitrary font sizes for max and min sizes. | 1018 | // Tag font size scaling: |
1021 | { | 1019 | // default 15 and 30 logarithm bases affect scaling, |
1022 | $tagList[$key] = array('count'=>$value,'size'=>log($value, 15) / log($maxcount, 30) * (22-6) + 6); | 1020 | // 22 and 6 are arbitrary font sizes for max and min sizes. |
1021 | $size = log($value, 15) / log($maxcount, 30) * 2.2 + 0.8; | ||
1022 | $tagList[$key] = array( | ||
1023 | 'count' => $value, | ||
1024 | 'size' => number_format($size, 2, '.', ''), | ||
1025 | ); | ||
1023 | } | 1026 | } |
1024 | 1027 | ||
1025 | $data = array( | 1028 | $data = array( |
@@ -1038,7 +1041,7 @@ function renderPage() | |||
1038 | 1041 | ||
1039 | // Daily page. | 1042 | // Daily page. |
1040 | if ($targetPage == Router::$PAGE_DAILY) { | 1043 | if ($targetPage == Router::$PAGE_DAILY) { |
1041 | showDaily($PAGE); | 1044 | showDaily($PAGE, $LINKSDB); |
1042 | } | 1045 | } |
1043 | 1046 | ||
1044 | // ATOM and RSS feed. | 1047 | // ATOM and RSS feed. |
@@ -1584,44 +1587,36 @@ function renderPage() | |||
1584 | } | 1587 | } |
1585 | 1588 | ||
1586 | // -------- Export as Netscape Bookmarks HTML file. | 1589 | // -------- Export as Netscape Bookmarks HTML file. |
1587 | if ($targetPage == Router::$PAGE_EXPORT) | 1590 | if ($targetPage == Router::$PAGE_EXPORT) { |
1588 | { | 1591 | if (empty($_GET['selection'])) { |
1589 | if (empty($_GET['what'])) | ||
1590 | { | ||
1591 | $PAGE->assign('linkcount',count($LINKSDB)); | 1592 | $PAGE->assign('linkcount',count($LINKSDB)); |
1592 | $PAGE->renderPage('export'); | 1593 | $PAGE->renderPage('export'); |
1593 | exit; | 1594 | exit; |
1594 | } | 1595 | } |
1595 | $exportWhat=$_GET['what']; | ||
1596 | if (!array_intersect(array('all','public','private'),array($exportWhat))) die('What are you trying to export???'); | ||
1597 | 1596 | ||
1598 | header('Content-Type: text/html; charset=utf-8'); | 1597 | // export as bookmarks_(all|private|public)_YYYYmmdd_HHMMSS.html |
1599 | header('Content-disposition: attachment; filename=bookmarks_'.$exportWhat.'_'.strval(date('Ymd_His')).'.html'); | 1598 | $selection = $_GET['selection']; |
1600 | $currentdate=date('Y/m/d H:i:s'); | 1599 | try { |
1601 | echo <<<HTML | 1600 | $PAGE->assign( |
1602 | <!DOCTYPE NETSCAPE-Bookmark-file-1> | 1601 | 'links', |
1603 | <!-- This is an automatically generated file. | 1602 | NetscapeBookmarkUtils::filterAndFormat($LINKSDB, $selection) |
1604 | It will be read and overwritten. | 1603 | ); |
1605 | DO NOT EDIT! --> | 1604 | } catch (Exception $exc) { |
1606 | <!-- Shaarli {$exportWhat} bookmarks export on {$currentdate} --> | 1605 | header('Content-Type: text/plain; charset=utf-8'); |
1607 | <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> | 1606 | echo $exc->getMessage(); |
1608 | <TITLE>Bookmarks</TITLE> | 1607 | exit; |
1609 | <H1>Bookmarks</H1> | ||
1610 | HTML; | ||
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 | } | 1608 | } |
1624 | exit; | 1609 | $now = new DateTime(); |
1610 | header('Content-Type: text/html; charset=utf-8'); | ||
1611 | header( | ||
1612 | 'Content-disposition: attachment; filename=bookmarks_' | ||
1613 | .$selection.'_'.$now->format(LinkDB::LINK_DATE_FORMAT).'.html' | ||
1614 | ); | ||
1615 | $PAGE->assign('date', $now->format(DateTime::RFC822)); | ||
1616 | $PAGE->assign('eol', PHP_EOL); | ||
1617 | $PAGE->assign('selection', $selection); | ||
1618 | $PAGE->renderPage('export.bookmarks'); | ||
1619 | exit; | ||
1625 | } | 1620 | } |
1626 | 1621 | ||
1627 | // -------- User is uploading a file for import | 1622 | // -------- User is uploading a file for import |
@@ -1635,7 +1630,7 @@ HTML; | |||
1635 | exit; | 1630 | exit; |
1636 | } | 1631 | } |
1637 | if (!tokenOk($_POST['token'])) die('Wrong token.'); | 1632 | if (!tokenOk($_POST['token'])) die('Wrong token.'); |
1638 | importFile(); | 1633 | importFile($LINKSDB); |
1639 | exit; | 1634 | exit; |
1640 | } | 1635 | } |
1641 | 1636 | ||
@@ -1704,15 +1699,10 @@ HTML; | |||
1704 | 1699 | ||
1705 | // ----------------------------------------------------------------------------------------------- | 1700 | // ----------------------------------------------------------------------------------------------- |
1706 | // Process the import file form. | 1701 | // Process the import file form. |
1707 | function importFile() | 1702 | function importFile($LINKSDB) |
1708 | { | 1703 | { |
1709 | if (!isLoggedIn()) { die('Not allowed.'); } | 1704 | if (!isLoggedIn()) { die('Not allowed.'); } |
1710 | $LINKSDB = new LinkDB( | 1705 | |
1711 | $GLOBALS['config']['DATASTORE'], | ||
1712 | isLoggedIn(), | ||
1713 | $GLOBALS['config']['HIDE_PUBLIC_LINKS'], | ||
1714 | $GLOBALS['redirector'] | ||
1715 | ); | ||
1716 | $filename=$_FILES['filetoupload']['name']; | 1706 | $filename=$_FILES['filetoupload']['name']; |
1717 | $filesize=$_FILES['filetoupload']['size']; | 1707 | $filesize=$_FILES['filetoupload']['size']; |
1718 | $data=file_get_contents($_FILES['filetoupload']['tmp_name']); | 1708 | $data=file_get_contents($_FILES['filetoupload']['tmp_name']); |