]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #761 from ArthurHoaro/hotfix/referrer-warning
authorArthurHoaro <arthur@hoa.ro>
Mon, 16 Jan 2017 11:40:00 +0000 (12:40 +0100)
committerGitHub <noreply@github.com>
Mon, 16 Jan 2017 11:40:00 +0000 (12:40 +0100)
Prevent warning if HTTP_REFERER isn't set

1  2 
index.php

diff --combined index.php
index 8055a7b7bde78bfe06f290ce58ec0a647313ab57,f736fcf2fe203252aad4377612ee5ac973e9daa4..b27c83b600a8038c09d9d90d2ea3e4190d58d217
+++ b/index.php
@@@ -13,7 -13,7 +13,7 @@@
   *
   * Licence: http://www.opensource.org/licenses/zlib-license.php
   *
 - * Requires: PHP 5.3.x
 + * Requires: PHP 5.5.x
   */
  
  // Set 'UTC' as the default timezone if it is not defined in php.ini
@@@ -83,7 -83,7 +83,7 @@@ use \Shaarli\ThemeUtils
  
  // Ensure the PHP version is supported
  try {
 -    ApplicationUtils::checkPHPVersion('5.3', PHP_VERSION);
 +    ApplicationUtils::checkPHPVersion('5.5', PHP_VERSION);
  } catch(Exception $exc) {
      header('Content-Type: text/plain; charset=utf-8');
      echo $exc->getMessage();
@@@ -1012,7 -1012,12 +1012,12 @@@ function renderPage($conf, $pluginManag
              $_SESSION['LINKS_PER_PAGE']=abs(intval($_GET['linksperpage']));
          }
  
-         header('Location: '. generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('linksperpage')));
+         if (! empty($_SERVER['HTTP_REFERER'])) {
+             $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('linksperpage'));
+         } else {
+             $location = '?';
+         }
+         header('Location: '. $location);
          exit;
      }
  
              unset($_SESSION['privateonly']); // See all links
          }
  
-         header('Location: '. generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('privateonly')));
+         if (! empty($_SERVER['HTTP_REFERER'])) {
+             $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('privateonly'));
+         } else {
+             $location = '?';
+         }
+         header('Location: '. $location);
          exit;
      }
  
              $needle = trim($_POST['fromtag']);
              // True for case-sensitive tag search.
              $linksToAlter = $LINKSDB->filterSearch(array('searchtags' => $needle), true);
 -            foreach($linksToAlter as $key=>$value)
 -            {
 -                $tags = explode(' ',trim($value['tags']));
 -                $tags[array_search($needle,$tags)] = trim($_POST['totag']); // Replace tags value.
 -                $value['tags']=trim(implode(' ',$tags));
 -                $LINKSDB[$key]=$value;
 +            foreach($linksToAlter as $key=>$value) {
 +                $tags = preg_split('/\s+/', trim($value['tags']));
 +                // Replace tags value.
 +                $tags[array_search($needle, $tags)] = trim($_POST['totag']);
 +                $value['tags'] = implode(' ', array_unique($tags));
 +                $LINKSDB[$key] = $value;
              }
              $LINKSDB->save($conf->get('resource.page_cache')); // Save to disk.
 -            echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode($_POST['totag']).'\';</script>';
 +            echo '<script>alert("Tag was renamed in '.count($linksToAlter).' links.");document.location=\'?searchtags='.urlencode(escape($_POST['totag'])).'\';</script>';
              exit;
          }
      }
          ) {
              if (isset($_POST['returnurl'])) {
                  $location = $_POST['returnurl']; // Handle redirects given by the form
-             } else {
+             } else if (isset($_SERVER['HTTP_REFERER'])) {
                  $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('delete_link'));
              }
          }