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