aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rw-r--r--index.php56
1 files changed, 23 insertions, 33 deletions
diff --git a/index.php b/index.php
index 05f06452..fdbdfaa2 100644
--- a/index.php
+++ b/index.php
@@ -566,21 +566,17 @@ function showDailyRSS($conf) {
566 /* Some Shaarlies may have very few links, so we need to look 566 /* Some Shaarlies may have very few links, so we need to look
567 back in time until we have enough days ($nb_of_days). 567 back in time until we have enough days ($nb_of_days).
568 */ 568 */
569 $ids = array();
570 foreach ($LINKSDB as $id => $value) {
571 $ids[] = $id;
572 }
573 $nb_of_days = 7; // We take 7 days. 569 $nb_of_days = 7; // We take 7 days.
574 $today = date('Ymd'); 570 $today = date('Ymd');
575 $days = array(); 571 $days = array();
576 572
577 foreach ($ids as $id) { 573 foreach ($LINKSDB as $link) {
578 $day = $LINKSDB[$id]['created']->format('Ymd'); // Extract day (without time) 574 $day = $link['created']->format('Ymd'); // Extract day (without time)
579 if (strcmp($day, $today) < 0) { 575 if (strcmp($day, $today) < 0) {
580 if (empty($days[$day])) { 576 if (empty($days[$day])) {
581 $days[$day] = array(); 577 $days[$day] = array();
582 } 578 }
583 $days[$day][] = $id; 579 $days[$day][] = $link;
584 } 580 }
585 581
586 if (count($days) > $nb_of_days) { 582 if (count($days) > $nb_of_days) {
@@ -600,23 +596,18 @@ function showDailyRSS($conf) {
600 echo '<copyright>'. $pageaddr .'</copyright>'. PHP_EOL; 596 echo '<copyright>'. $pageaddr .'</copyright>'. PHP_EOL;
601 597
602 // For each day. 598 // For each day.
603 foreach ($days as $day => $ids) { 599 foreach ($days as $day => $links) {
604 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000'); 600 $dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
605 $absurl = escape(index_url($_SERVER).'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page. 601 $absurl = escape(index_url($_SERVER).'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
606 602
607 // Build the HTML body of this RSS entry.
608 $links = array();
609
610 // We pre-format some fields for proper output. 603 // We pre-format some fields for proper output.
611 foreach ($ids as $id) { 604 foreach ($links as &$link) {
612 $l = $LINKSDB[$id]; 605 $link['formatedDescription'] = format_description($link['description'], $conf->get('redirector.url'));
613 $l['formatedDescription'] = format_description($l['description'], $conf->get('redirector.url')); 606 $link['thumbnail'] = thumbnail($conf, $link['url']);
614 $l['thumbnail'] = thumbnail($conf, $l['url']); 607 $link['timestamp'] = $link['created']->getTimestamp();
615 $l['timestamp'] = $l['created']->getTimestamp(); 608 if (startsWith($link['url'], '?')) {
616 if (startsWith($l['url'], '?')) { 609 $link['url'] = index_url($_SERVER) . $link['url']; // make permalink URL absolute
617 $l['url'] = index_url($_SERVER) . $l['url']; // make permalink URL absolute
618 } 610 }
619 $links[$id] = $l;
620 } 611 }
621 612
622 // Then build the HTML for this day: 613 // Then build the HTML for this day:
@@ -675,7 +666,6 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
675 666
676 $taglist = explode(' ',$link['tags']); 667 $taglist = explode(' ',$link['tags']);
677 uasort($taglist, 'strcasecmp'); 668 uasort($taglist, 'strcasecmp');
678 $linksToDisplay[$key]['shorturl'] = smallHash($link['created']->format('Ymd_His'));
679 $linksToDisplay[$key]['taglist']=$taglist; 669 $linksToDisplay[$key]['taglist']=$taglist;
680 $linksToDisplay[$key]['formatedDescription'] = format_description($link['description'], $conf->get('redirector.url')); 670 $linksToDisplay[$key]['formatedDescription'] = format_description($link['description'], $conf->get('redirector.url'));
681 $linksToDisplay[$key]['thumbnail'] = thumbnail($conf, $link['url']); 671 $linksToDisplay[$key]['thumbnail'] = thumbnail($conf, $link['url']);
@@ -829,7 +819,7 @@ function renderPage($conf, $pluginManager)
829 // Get only links which have a thumbnail. 819 // Get only links which have a thumbnail.
830 foreach($links as $link) 820 foreach($links as $link)
831 { 821 {
832 $permalink='?'.escape(smallHash($link['created']->format('Ymd_His'))); 822 $permalink='?'.$link['shorturl'];
833 $thumb=lazyThumbnail($conf, $link['url'],$permalink); 823 $thumb=lazyThumbnail($conf, $link['url'],$permalink);
834 if ($thumb!='') // Only output links which have a thumbnail. 824 if ($thumb!='') // Only output links which have a thumbnail.
835 { 825 {
@@ -1249,7 +1239,7 @@ function renderPage($conf, $pluginManager)
1249 } 1239 }
1250 1240
1251 // lf_id should only be present if the link exists. 1241 // lf_id should only be present if the link exists.
1252 $id = !empty($_POST['lf_id']) ? (int) escape($_POST['lf_id']) : $LINKSDB->getNextId(); 1242 $id = !empty($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : $LINKSDB->getNextId();
1253 // Linkdate is kept here to: 1243 // Linkdate is kept here to:
1254 // - use the same permalink for notes as they're displayed when creating them 1244 // - use the same permalink for notes as they're displayed when creating them
1255 // - let users hack creation date of their posts 1245 // - let users hack creation date of their posts
@@ -1257,11 +1247,11 @@ function renderPage($conf, $pluginManager)
1257 $linkdate = escape($_POST['lf_linkdate']); 1247 $linkdate = escape($_POST['lf_linkdate']);
1258 if (isset($LINKSDB[$id])) { 1248 if (isset($LINKSDB[$id])) {
1259 // Edit 1249 // Edit
1260 $created = DateTime::createFromFormat('Ymd_His', $linkdate); 1250 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
1261 $updated = new DateTime(); 1251 $updated = new DateTime();
1262 } else { 1252 } else {
1263 // New link 1253 // New link
1264 $created = DateTime::createFromFormat('Ymd_His', $linkdate); 1254 $created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
1265 $updated = null; 1255 $updated = null;
1266 } 1256 }
1267 1257
@@ -1288,7 +1278,8 @@ function renderPage($conf, $pluginManager)
1288 'private' => (isset($_POST['lf_private']) ? 1 : 0), 1278 'private' => (isset($_POST['lf_private']) ? 1 : 0),
1289 'created' => $created, 1279 'created' => $created,
1290 'updated' => $updated, 1280 'updated' => $updated,
1291 'tags' => str_replace(',', ' ', $tags) 1281 'tags' => str_replace(',', ' ', $tags),
1282 'shorturl' => link_small_hash($created, $id),
1292 ); 1283 );
1293 1284
1294 // If title is empty, use the URL as title. 1285 // If title is empty, use the URL as title.
@@ -1311,7 +1302,7 @@ function renderPage($conf, $pluginManager)
1311 $returnurl = !empty($_POST['returnurl']) ? $_POST['returnurl'] : '?'; 1302 $returnurl = !empty($_POST['returnurl']) ? $_POST['returnurl'] : '?';
1312 $location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link')); 1303 $location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link'));
1313 // Scroll to the link which has been edited. 1304 // Scroll to the link which has been edited.
1314 $location .= '#' . smallHash($created->format('Ymd_His')); 1305 $location .= '#' . $link['shorturl'];
1315 // After saving the link, redirect to the page the user was on. 1306 // After saving the link, redirect to the page the user was on.
1316 header('Location: '. $location); 1307 header('Location: '. $location);
1317 exit; 1308 exit;
@@ -1325,7 +1316,7 @@ function renderPage($conf, $pluginManager)
1325 $link = $LINKSDB[(int) escape($_POST['lf_id'])]; 1316 $link = $LINKSDB[(int) escape($_POST['lf_id'])];
1326 $returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' ); 1317 $returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' );
1327 // Scroll to the link which has been edited. 1318 // Scroll to the link which has been edited.
1328 $returnurl .= '#'.smallHash($link['created']->format('Ymd_His')); 1319 $returnurl .= '#'. $link['shorturl'];
1329 $returnurl = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link')); 1320 $returnurl = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link'));
1330 header('Location: '.$returnurl); // After canceling, redirect to the page the user was on. 1321 header('Location: '.$returnurl); // After canceling, redirect to the page the user was on.
1331 exit; 1322 exit;
@@ -1341,7 +1332,7 @@ function renderPage($conf, $pluginManager)
1341 // - we are protected from XSRF by the token. 1332 // - we are protected from XSRF by the token.
1342 1333
1343 // FIXME! We keep `lf_linkdate` for consistency before a proper API. To be removed. 1334 // FIXME! We keep `lf_linkdate` for consistency before a proper API. To be removed.
1344 $id = isset($_POST['lf_id']) ? (int) escape($_POST['lf_id']) : (int) escape($_POST['lf_linkdate']); 1335 $id = isset($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : intval(escape($_POST['lf_linkdate']));
1345 1336
1346 $pluginManager->executeHooks('delete_link', $LINKSDB[$id]); 1337 $pluginManager->executeHooks('delete_link', $LINKSDB[$id]);
1347 1338
@@ -1387,7 +1378,7 @@ function renderPage($conf, $pluginManager)
1387 $id = (int) escape($_GET['edit_link']); 1378 $id = (int) escape($_GET['edit_link']);
1388 $link = $LINKSDB[$id]; // Read database 1379 $link = $LINKSDB[$id]; // Read database
1389 if (!$link) { header('Location: ?'); exit; } // Link not found in database. 1380 if (!$link) { header('Location: ?'); exit; } // Link not found in database.
1390 $link['linkdate'] = $link['created']->format('Ymd_His'); 1381 $link['linkdate'] = $link['created']->format(LinkDB::LINK_DATE_FORMAT);
1391 $data = array( 1382 $data = array(
1392 'link' => $link, 1383 'link' => $link,
1393 'link_is_new' => false, 1384 'link_is_new' => false,
@@ -1414,7 +1405,7 @@ function renderPage($conf, $pluginManager)
1414 if (! $link) 1405 if (! $link)
1415 { 1406 {
1416 $link_is_new = true; 1407 $link_is_new = true;
1417 $linkdate = strval(date('Ymd_His')); 1408 $linkdate = strval(date(LinkDB::LINK_DATE_FORMAT));
1418 // Get title if it was provided in URL (by the bookmarklet). 1409 // Get title if it was provided in URL (by the bookmarklet).
1419 $title = empty($_GET['title']) ? '' : escape($_GET['title']); 1410 $title = empty($_GET['title']) ? '' : escape($_GET['title']);
1420 // Get description if it was provided in URL (by the bookmarklet). [Bronco added that] 1411 // Get description if it was provided in URL (by the bookmarklet). [Bronco added that]
@@ -1438,7 +1429,7 @@ function renderPage($conf, $pluginManager)
1438 } 1429 }
1439 1430
1440 if ($url == '') { 1431 if ($url == '') {
1441 $url = '?' . smallHash($linkdate); 1432 $url = '?' . smallHash($linkdate . $LINKSDB->getNextId());
1442 $title = 'Note: '; 1433 $title = 'Note: ';
1443 } 1434 }
1444 $url = escape($url); 1435 $url = escape($url);
@@ -1453,7 +1444,7 @@ function renderPage($conf, $pluginManager)
1453 'private' => $private 1444 'private' => $private
1454 ); 1445 );
1455 } else { 1446 } else {
1456 $link['linkdate'] = $link['created']->format('Ymd_His'); 1447 $link['linkdate'] = $link['created']->format(LinkDB::LINK_DATE_FORMAT);
1457 } 1448 }
1458 1449
1459 $data = array( 1450 $data = array(
@@ -1668,7 +1659,6 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
1668 $taglist = explode(' ', $link['tags']); 1659 $taglist = explode(' ', $link['tags']);
1669 uasort($taglist, 'strcasecmp'); 1660 uasort($taglist, 'strcasecmp');
1670 $link['taglist'] = $taglist; 1661 $link['taglist'] = $taglist;
1671 $link['shorturl'] = smallHash($link['created']->format('Ymd_His'));
1672 // Check for both signs of a note: starting with ? and 7 chars long. 1662 // Check for both signs of a note: starting with ? and 7 chars long.
1673 if ($link['url'][0] === '?' && 1663 if ($link['url'][0] === '?' &&
1674 strlen($link['url']) === 7) { 1664 strlen($link['url']) === 7) {