]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #979 from ArthurHoaro/feature/assets-cache-version
authorVirtualTam <virtualtam+github@flibidi.net>
Fri, 6 Oct 2017 12:32:07 +0000 (14:32 +0200)
committerGitHub <noreply@github.com>
Fri, 6 Oct 2017 12:32:07 +0000 (14:32 +0200)
 Add a version hash for asset loading to prevent browser's cache issue

1  2 
application/ApplicationUtils.php
index.php

index 123cc0b3e567ef531e4123dff6d31149d5f69ff5,20fec376faebddda7b040eb2b35a73e457396fd8..5643f4a09706f2bb5b867153ee09c3c4974d77c3
@@@ -168,15 -168,14 +168,15 @@@ class ApplicationUtil
      public static function checkResourcePermissions($conf)
      {
          $errors = array();
 +        $rainTplDir = rtrim($conf->get('resource.raintpl_tpl'), '/');
  
          // Check script and template directories are readable
          foreach (array(
              'application',
              'inc',
              'plugins',
 -            $conf->get('resource.raintpl_tpl'),
 -            $conf->get('resource.raintpl_tpl').'/'.$conf->get('resource.theme'),
 +            $rainTplDir,
 +            $rainTplDir.'/'.$conf->get('resource.theme'),
          ) as $path) {
              if (! is_readable(realpath($path))) {
                  $errors[] = '"'.$path.'" directory is not readable';
  
          return $errors;
      }
+     /**
+      * Returns a salted hash representing the current Shaarli version.
+      *
+      * Useful for assets browser cache.
+      *
+      * @param string $currentVersion of Shaarli
+      * @param string $salt           User personal salt, also used for the authentication
+      *
+      * @return string version hash
+      */
+     public static function getVersionHash($currentVersion, $salt)
+     {
+         return hash_hmac('sha256', $currentVersion, $salt);
+     }
  }
diff --combined index.php
index 43aab303c67f84c51fcf274cd478407af7fa7260,12ccceafe652a5bf3c2a119d1258b65485ca97f2..c2552ce8662ef48034c8f3c3f7bfd56039489a1d
+++ b/index.php
@@@ -88,7 -88,7 +88,7 @@@ try 
      exit;
  }
  
- define('shaarli_version', ApplicationUtils::getVersion(__DIR__ .'/'. ApplicationUtils::$VERSION_FILE));
+ define('SHAARLI_VERSION', ApplicationUtils::getVersion(__DIR__ .'/'. ApplicationUtils::$VERSION_FILE));
  
  // Force cookie path (but do not change lifetime)
  $cookie = session_get_cookie_params();
@@@ -1443,7 -1443,7 +1443,7 @@@ function renderPage($conf, $pluginManag
  
              if ($url == '') {
                  $url = '?' . smallHash($linkdate . $LINKSDB->getNextId());
 -                $title = 'Note: ';
 +                $title = $conf->get('general.default_note_title', 'Note: ');
              }
              $url = escape($url);
              $title = escape($title);