aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
Diffstat (limited to 'index.php')
-rwxr-xr-xindex.php80
1 files changed, 43 insertions, 37 deletions
diff --git a/index.php b/index.php
index 8e04fa3e..ba70b29c 100755
--- a/index.php
+++ b/index.php
@@ -1485,51 +1485,57 @@ function renderPage()
1485 $url->cleanup(); 1485 $url->cleanup();
1486 1486
1487 $link_is_new = false; 1487 $link_is_new = false;
1488 $link = $LINKSDB->getLinkFromUrl($url); // Check if URL is not already in database (in this case, we will edit the existing link) 1488 // Check if URL is not already in database (in this case, we will edit the existing link)
1489 $link = $LINKSDB->getLinkFromUrl((string)$url);
1489 if (!$link) 1490 if (!$link)
1490 { 1491 {
1491 $link_is_new = true; // This is a new link 1492 $link_is_new = true;
1492 $linkdate = strval(date('Ymd_His')); 1493 $linkdate = strval(date('Ymd_His'));
1493 $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet). 1494 // Get title if it was provided in URL (by the bookmarklet).
1494 $description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that] 1495 $title = (empty($_GET['title']) ? '' : $_GET['title'] );
1495 $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL 1496 // Get description if it was provided in URL (by the bookmarklet). [Bronco added that]
1496 $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL 1497 $description = (empty($_GET['description']) ? '' : $_GET['description']);
1497 if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url; 1498 $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] );
1499 $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0);
1498 // If this is an HTTP link, we try go get the page to extract the title (otherwise we will to straight to the edit form.) 1500 // If this is an HTTP link, we try go get the page to extract the title (otherwise we will to straight to the edit form.)
1499 if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http') 1501 if (empty($title) && $url->getScheme() == 'http') {
1500 {
1501 list($status,$headers,$data) = getHTTP($url,4); // Short timeout to keep the application responsive. 1502 list($status,$headers,$data) = getHTTP($url,4); // Short timeout to keep the application responsive.
1502 // FIXME: Decode charset according to specified in either 1) HTTP response headers or 2) <head> in html 1503 // FIXME: Decode charset according to specified in either 1) HTTP response headers or 2) <head> in html
1503 if (strpos($status,'200 OK')!==false) 1504 if (strpos($status,'200 OK')!==false) {
1504 { 1505 // Look for charset in html header.
1505 // Look for charset in html header. 1506 preg_match('#<meta .*charset=.*>#Usi', $data, $meta);
1506 preg_match('#<meta .*charset=.*>#Usi', $data, $meta); 1507
1507 1508 // If found, extract encoding.
1508 // If found, extract encoding. 1509 if (!empty($meta[0])) {
1509 if (!empty($meta[0])) 1510 // Get encoding specified in header.
1510 { 1511 preg_match('#charset="?(.*)"#si', $meta[0], $enc);
1511 // Get encoding specified in header. 1512 // If charset not found, use utf-8.
1512 preg_match('#charset="?(.*)"#si', $meta[0], $enc); 1513 $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8';
1513 // If charset not found, use utf-8. 1514 }
1514 $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8'; 1515 else {
1515 } 1516 $html_charset = 'utf-8';
1516 else { $html_charset = 'utf-8'; } 1517 }
1517 1518
1518 // Extract title 1519 // Extract title
1519 $title = html_extract_title($data); 1520 $title = html_extract_title($data);
1520 if (!empty($title)) 1521 if (!empty($title)) {
1521 { 1522 // Re-encode title in utf-8 if necessary.
1522 // Re-encode title in utf-8 if necessary. 1523 $title = ($html_charset == 'iso-8859-1') ? utf8_encode($title) : $title;
1523 $title = ($html_charset == 'iso-8859-1') ? utf8_encode($title) : $title; 1524 }
1524 } 1525 }
1525 }
1526 } 1526 }
1527 if ($url=='') // In case of empty URL, this is just a text (with a link that points to itself) 1527 if ($url == '') {
1528 { 1528 $url = '?' . smallHash($linkdate);
1529 $url='?'.smallHash($linkdate); 1529 $title = 'Note: ';
1530 $title='Note: ';
1531 } 1530 }
1532 $link = array('linkdate'=>$linkdate,'title'=>$title,'url'=>$url,'description'=>$description,'tags'=>$tags,'private'=>$private); 1531 $link = array(
1532 'linkdate' => $linkdate,
1533 'title' => $title,
1534 'url' => (string)$url,
1535 'description' => $description,
1536 'tags' => $tags,
1537 'private' => $private
1538 );
1533 } 1539 }
1534 1540
1535 $PAGE = new pageBuilder; 1541 $PAGE = new pageBuilder;