From: VirtualTam Date: Mon, 31 Aug 2015 18:31:41 +0000 (+0200) Subject: Merge pull request #326 from ArthurHoaro/bug-url X-Git-Tag: v0.5.2~1 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=6211c498f6e0bdc6d86152e9777bcc75955a5ec4;hp=-c;p=github%2Fshaarli%2FShaarli.git Merge pull request #326 from ArthurHoaro/bug-url Fixes #325 - Shaarli does not recognize saved links --- 6211c498f6e0bdc6d86152e9777bcc75955a5ec4 diff --combined index.php index a093a283,9c3f7c1b..f4c7e781 --- a/index.php +++ b/index.php @@@ -43,6 -43,19 +43,6 @@@ define('shaarli_version','0.5.1') // http://server.com/x/shaarli --> /shaarli/ define('WEB_PATH', substr($_SERVER["REQUEST_URI"], 0, 1+strrpos($_SERVER["REQUEST_URI"], '/', 0))); -// Force cookie path (but do not change lifetime) -$cookie=session_get_cookie_params(); -$cookiedir = ''; if(dirname($_SERVER['SCRIPT_NAME'])!='/') $cookiedir=dirname($_SERVER["SCRIPT_NAME"]).'/'; -session_set_cookie_params($cookie['lifetime'],$cookiedir,$_SERVER['SERVER_NAME']); // Set default cookie expiration and path. - -// Set session parameters on server side. -define('INACTIVITY_TIMEOUT',3600); // (in seconds). If the user does not access any page within this time, his/her session is considered expired. -ini_set('session.use_cookies', 1); // Use cookies to store session. -ini_set('session.use_only_cookies', 1); // Force cookies for session (phpsessionID forbidden in URL). -ini_set('session.use_trans_sid', false); // Prevent PHP form using sessionID in URL if cookies are disabled. -session_name('shaarli'); -if (session_id() == '') session_start(); // Start session if needed (Some server auto-start sessions). - // PHP Settings ini_set('max_input_time','60'); // High execution time in case of problematic imports/exports. ini_set('memory_limit', '128M'); // Try to set max upload file size and read (May not work on some hosts). @@@ -74,34 -87,6 +74,34 @@@ try exit; } +// Force cookie path (but do not change lifetime) +$cookie = session_get_cookie_params(); +$cookiedir = ''; +if (dirname($_SERVER['SCRIPT_NAME']) != '/') { + $cookiedir = dirname($_SERVER["SCRIPT_NAME"]).'/'; +} +// Set default cookie expiration and path. +session_set_cookie_params($cookie['lifetime'], $cookiedir, $_SERVER['SERVER_NAME']); +// Set session parameters on server side. +// If the user does not access any page within this time, his/her session is considered expired. +define('INACTIVITY_TIMEOUT', 3600); // in seconds. +// Use cookies to store session. +ini_set('session.use_cookies', 1); +// Force cookies for session (phpsessionID forbidden in URL). +ini_set('session.use_only_cookies', 1); +// Prevent PHP form using sessionID in URL if cookies are disabled. +ini_set('session.use_trans_sid', false); + +// Regenerate session id if invalid or not defined in cookie. +if (isset($_COOKIE['shaarli']) && !is_session_id_valid($_COOKIE['shaarli'])) { + $_COOKIE['shaarli'] = uniqid(); +} +session_name('shaarli'); +// Start session if needed (Some server auto-start sessions). +if (session_id() == '') { + session_start(); +} + include "inc/rain.tpl.class.php"; //include Rain TPL raintpl::$tpl_dir = $GLOBALS['config']['RAINTPL_TPL']; // template directory raintpl::$cache_dir = $GLOBALS['config']['RAINTPL_TMP']; // cache directory @@@ -1500,51 -1485,57 +1500,57 @@@ function renderPage( $url->cleanup(); $link_is_new = false; - $link = $LINKSDB->getLinkFromUrl($url); // Check if URL is not already in database (in this case, we will edit the existing link) + // Check if URL is not already in database (in this case, we will edit the existing link) + $link = $LINKSDB->getLinkFromUrl((string)$url); if (!$link) { - $link_is_new = true; // This is a new link + $link_is_new = true; $linkdate = strval(date('Ymd_His')); - $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet). - $description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that] - $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL - $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL - if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url; - // 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.) - if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http') - { + // Get title if it was provided in URL (by the bookmarklet). + $title = (empty($_GET['title']) ? '' : $_GET['title'] ); + // Get description if it was provided in URL (by the bookmarklet). [Bronco added that] + $description = (empty($_GET['description']) ? '' : $_GET['description']); + $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); + $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); + // 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.) + if (empty($title) && strpos($url->getScheme(), 'http') !== false) { list($status,$headers,$data) = getHTTP($url,4); // Short timeout to keep the application responsive. // FIXME: Decode charset according to specified in either 1) HTTP response headers or 2) in html - if (strpos($status,'200 OK')!==false) - { - // Look for charset in html header. - preg_match('##Usi', $data, $meta); - - // If found, extract encoding. - if (!empty($meta[0])) - { - // Get encoding specified in header. - preg_match('#charset="?(.*)"#si', $meta[0], $enc); - // If charset not found, use utf-8. - $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8'; - } - else { $html_charset = 'utf-8'; } - - // Extract title - $title = html_extract_title($data); - if (!empty($title)) - { - // Re-encode title in utf-8 if necessary. - $title = ($html_charset == 'iso-8859-1') ? utf8_encode($title) : $title; - } - } + if (strpos($status,'200 OK')!==false) { + // Look for charset in html header. + preg_match('##Usi', $data, $meta); + + // If found, extract encoding. + if (!empty($meta[0])) { + // Get encoding specified in header. + preg_match('#charset="?(.*)"#si', $meta[0], $enc); + // If charset not found, use utf-8. + $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8'; + } + else { + $html_charset = 'utf-8'; + } + + // Extract title + $title = html_extract_title($data); + if (!empty($title)) { + // Re-encode title in utf-8 if necessary. + $title = ($html_charset == 'iso-8859-1') ? utf8_encode($title) : $title; + } + } } - if ($url=='') // In case of empty URL, this is just a text (with a link that points to itself) - { - $url='?'.smallHash($linkdate); - $title='Note: '; + if ($url == '') { + $url = '?' . smallHash($linkdate); + $title = 'Note: '; } - $link = array('linkdate'=>$linkdate,'title'=>$title,'url'=>$url,'description'=>$description,'tags'=>$tags,'private'=>$private); + $link = array( + 'linkdate' => $linkdate, + 'title' => $title, + 'url' => (string)$url, + 'description' => $description, + 'tags' => $tags, + 'private' => $private + ); } $PAGE = new pageBuilder;