X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=38958a79f199b1104acadf81fd7f4573df00c553;hb=e5aab50ac4b76a167fa1938e318e77e5c7e4c855;hp=c91ae23b4992f7e9f05a8241745eb83bbe7a2788;hpb=1099d8fcad1844599a365fc03506ca69d156609f;p=github%2Fshaarli%2FShaarli.git diff --git a/index.php b/index.php index c91ae23b..38958a79 100644 --- a/index.php +++ b/index.php @@ -32,6 +32,7 @@ $GLOBALS['config']['RAINTPL_TPL'] = 'tpl/' ; // Raintpl template directory (keep $GLOBALS['config']['UPDATECHECK_FILENAME'] = $GLOBALS['config']['DATADIR'].'/lastupdatecheck.txt'; // For updates check of Shaarli. $GLOBALS['config']['UPDATECHECK_INTERVAL'] = 86400 ; // Updates check frequency for Shaarli. 86400 seconds=24 hours // Note: You must have publisher.php in the same directory as Shaarli index.php +$GLOBALS['config']['ARCHIVE_ORG'] = false; // For each link, add a link to an archived version on archive.org // ----------------------------------------------------------------------------------------------- // You should not touch below (or at your own risks!) // Optional config file. @@ -336,7 +337,7 @@ function isLoggedIn() } // Force logout. -function logout() { if (isset($_SESSION)) { unset($_SESSION['uid']); unset($_SESSION['ip']); unset($_SESSION['username']); unset($_SESSION['privateonly']); } +function logout() { if (isset($_SESSION)) { unset($_SESSION['uid']); unset($_SESSION['ip']); unset($_SESSION['username']); unset($_SESSION['privateonly']); } setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH); } @@ -906,7 +907,7 @@ function showRSS() else $linksToDisplay = $LINKSDB; $nblinksToDisplay = 50; // Number of links to display. if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. - { + { $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; } @@ -981,7 +982,7 @@ function showATOM() else $linksToDisplay = $LINKSDB; $nblinksToDisplay = 50; // Number of links to display. if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. - { + { $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; } @@ -1266,7 +1267,25 @@ function renderPage() // Get previous URL (http_referer) and add the tag to the searchtags parameters in query. if (empty($_SERVER['HTTP_REFERER'])) { header('Location: ?searchtags='.urlencode($_GET['addtag'])); exit; } // In case browser does not send HTTP_REFERER parse_str(parse_url($_SERVER['HTTP_REFERER'],PHP_URL_QUERY), $params); - $params['searchtags'] = (empty($params['searchtags']) ? trim($_GET['addtag']) : trim($params['searchtags']).' '.trim($_GET['addtag'])); + + // Check if this tag is already in the search query and ignore it if it is. + // Each tag is always separated by a space + $current_tags = explode(' ', $params['searchtags']); + $addtag = true; + foreach ($current_tags as $value) { + if ($value === $_GET['addtag']) { + $addtag = false; + break; + } + } + // Append the tag if necessary + if (empty($params['searchtags'])) { + $params['searchtags'] = trim($_GET['addtag']); + } + else if ($addtag) { + $params['searchtags'] = trim($params['searchtags']).' '.trim($_GET['addtag']); + } + unset($params['page']); // We also remove page (keeping the same page has no sense, since the results are different) header('Location: ?'.http_build_query($params)); exit; @@ -1330,6 +1349,14 @@ function renderPage() header('Location: ?do=login&post='.urlencode($_GET['post']).(!empty($_GET['title'])?'&title='.urlencode($_GET['title']):'').(!empty($_GET['description'])?'&description='.urlencode($_GET['description']):'').(!empty($_GET['source'])?'&source='.urlencode($_GET['source']):'')); // Redirect to login page, then back to post link. exit; } + + // Same case as above except that user tried to access ?do=addlink without being logged in + // Note: passing empty parameters makes Shaarli generate default URLs and descriptions. + if (isset($_GET['do']) && $_GET['do'] === 'addlink') { + header('Location: ?do=login&post='); + exit; + } + $PAGE = new pageBuilder; buildLinkList($PAGE,$LINKSDB); // Compute list of links to display $PAGE->renderPage('linklist'); @@ -1557,7 +1584,7 @@ function renderPage() $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 + $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') @@ -1568,7 +1595,7 @@ function renderPage() { // Look for charset in html header. preg_match('##Usi', $data, $meta); - + // If found, extract encoding. if (!empty($meta[0])) { @@ -1578,7 +1605,7 @@ function renderPage() $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)) @@ -1892,13 +1919,13 @@ function computeThumbnail($url,$href=false) if ($domain=='youtube.com' || $domain=='www.youtube.com') { parse_str(parse_url($url,PHP_URL_QUERY), $params); // Extract video ID and get thumbnail - if (!empty($params['v'])) return array('src'=>'http://img.youtube.com/vi/'.$params['v'].'/default.jpg', + if (!empty($params['v'])) return array('src'=>'https://img.youtube.com/vi/'.$params['v'].'/default.jpg', 'href'=>$href,'width'=>'120','height'=>'90','alt'=>'YouTube thumbnail'); } if ($domain=='youtu.be') // Youtube short links { $path = parse_url($url,PHP_URL_PATH); - return array('src'=>'http://img.youtube.com/vi'.$path.'/default.jpg', + return array('src'=>'https://img.youtube.com/vi'.$path.'/default.jpg', 'href'=>$href,'width'=>'120','height'=>'90','alt'=>'YouTube thumbnail'); } if ($domain=='pix.toile-libre.org') // pix.toile-libre.org image hosting @@ -1912,18 +1939,18 @@ function computeThumbnail($url,$href=false) { $path = parse_url($url,PHP_URL_PATH); if (startsWith($path,'/a/')) return array(); // Thumbnails for albums are not available. - if (startsWith($path,'/r/')) return array('src'=>'http://i.imgur.com/'.basename($path).'s.jpg', + if (startsWith($path,'/r/')) return array('src'=>'https://i.imgur.com/'.basename($path).'s.jpg', 'href'=>$href,'width'=>'90','height'=>'90','alt'=>'imgur.com thumbnail'); - if (startsWith($path,'/gallery/')) return array('src'=>'http://i.imgur.com'.substr($path,8).'s.jpg', + if (startsWith($path,'/gallery/')) return array('src'=>'https://i.imgur.com'.substr($path,8).'s.jpg', 'href'=>$href,'width'=>'90','height'=>'90','alt'=>'imgur.com thumbnail'); - if (substr_count($path,'/')==1) return array('src'=>'http://i.imgur.com/'.substr($path,1).'s.jpg', + if (substr_count($path,'/')==1) return array('src'=>'https://i.imgur.com/'.substr($path,1).'s.jpg', 'href'=>$href,'width'=>'90','height'=>'90','alt'=>'imgur.com thumbnail'); } if ($domain=='i.imgur.com') { $pi = pathinfo(parse_url($url,PHP_URL_PATH)); - if (!empty($pi['filename'])) return array('src'=>'http://i.imgur.com/'.$pi['filename'].'s.jpg', + if (!empty($pi['filename'])) return array('src'=>'https://i.imgur.com/'.$pi['filename'].'s.jpg', 'href'=>$href,'width'=>'90','height'=>'90','alt'=>'imgur.com thumbnail'); } if ($domain=='dailymotion.com' || $domain=='www.dailymotion.com') @@ -2067,7 +2094,9 @@ function install() { // Step 2: Check if data in session is correct. echo '
Sessions do not seem to work correctly on your server.
'; echo 'Make sure the variable session.save_path is set correctly in your php config, and that you have write access to it.
'; - echo 'It currently points to '.session_save_path().'

Click to try again.
'; + echo 'It currently points to '.session_save_path().'
'; + echo 'Check that the hostname used to access Shaarli contains a dot. On some browsers, accessing your server via a hostname like \'localhost\' or any custom hostname without a dot causes cookie storage to fail. We recommend accessing your server via it\'s IP address or Fully Qualified Domain Name.
'; + echo '
Click to try again.'; die; } if (!isset($_SESSION['session_tested'])) @@ -2138,13 +2167,13 @@ function templateTZform($ptz=false) $continent=substr($tz,0,$spos); $city=substr($tz,$spos+1); $continents[$continent]=1; if (!isset($cities[$continent])) $cities[$continent]=''; - $cities[$continent].=''; + $cities[$continent].=''; } } $continents_html = ''; $continents = array_keys($continents); foreach($continents as $continent) - $continents_html.=''; + $continents_html.=''; $cities_html = $cities[$pcontinent]; $timezone_form = "Continent: "; $timezone_form .= "    City:
"; @@ -2354,7 +2383,7 @@ function genThumbnail() // This is more complex: we have to perform a HTTP request, then parse the result. // Maybe we should deport this to JavaScript ? Example: http://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo/4285098#4285098 $vid = substr(parse_url($url,PHP_URL_PATH),1); - list($httpstatus,$headers,$data) = getHTTP('http://vimeo.com/api/v2/video/'.htmlspecialchars($vid).'.php',5); + list($httpstatus,$headers,$data) = getHTTP('https://vimeo.com/api/v2/video/'.htmlspecialchars($vid).'.php',5); if (strpos($httpstatus,'200 OK')!==false) { $t = unserialize($data);