Permalink
Browse files

Fix handle of missing .evocache files

  • Loading branch information...
1 parent 315ab5f commit e56fa49ff5dd5671fddd7e03d129d59b01465244 @yurabakhtin yurabakhtin committed Oct 28, 2016
Showing with 101 additions and 12 deletions.
  1. +9 −0 htsrv/getfile.php
  2. +1 −1 inc/files/model/_file.class.php
  3. +89 −0 inc/files/model/_file.funcs.php
  4. +2 −2 media/sample.htaccess
  5. +0 −9 skins/sample.htaccess
View
@@ -32,6 +32,15 @@
debug_die( 'Files module is disabled or missing!' );
}
+if( param( 'abspath', 'string', NULL ) !== NULL )
+{ // If absolute path is requested then try to decode it to root and relative path:
+ if( $decoded_data = get_root_path_by_abspath( $abspath ) )
+ { // Root and path are decoded, Use them:
+ set_param( 'root', $decoded_data['root'] );
+ set_param( 'path', $decoded_data['path'] );
+ }
+}
+
// We need this param early to check blog perms, if possible
param( 'root', 'string', true ); // the root directory from the dropdown box (user_X or blog_X; X is ID - 'user' for current user (default))
@@ -2206,7 +2206,7 @@ function get_thumb_url( $size_name = 'fit-80x80', $glue = '&', $size_x = 1 )
// Get the relative dirpath of this file to use in the url
$rdfp_dirname = dirname( $this->_rdfp_rel_path );
$rdfp_dirpath = ( $rdfp_dirname == '.' ) ? '' : $rdfp_dirname.'/';
- $url = $this->_FileRoot->ads_url.$rdfp_dirpath.$Settings->get( 'evocache_foldername' ).'/'.$this->_name.'/'.$this->get_thumb_name( $size_name, $size_x ).'?mtime='.$this->get_lastmod_ts().'&root='.$this->_FileRoot->ID.'&path='.$this->get_rdfp_rel_path();
+ $url = $this->_FileRoot->ads_url.$rdfp_dirpath.$Settings->get( 'evocache_foldername' ).'/'.$this->_name.'/'.$this->get_thumb_name( $size_name, $size_x ).'?mtime='.$this->get_lastmod_ts();
$url = str_replace( '\/', '', $url ); // Fix incorrect path
return $url;
}
@@ -2832,4 +2832,93 @@ function file_properties( root, path, file )
</script>
<?php
}
+
+
+/**
+ * Get root and relative file path by absolute path
+ *
+ * @param string Absolute path
+ * @return boolean|array FALSE - if root and path are not detected, Array with keys 'root' and 'path'
+ */
+function get_root_path_by_abspath( $abspath )
+{
+ if( empty( $abspath ) )
+ { // If absolute path is empty do NOT try to decode it:
+ return false;
+ }
+
+ load_class( 'files/model/_fileroot.class.php', 'FileRoot' );
+
+ $abspath = explode( DIRECTORY_SEPARATOR, $abspath );
+
+ switch( $abspath[0] )
+ {
+ case 'users':
+ // User media dir:
+ $UserCache = & get_UserCache();
+ if( $file_User = & $UserCache->get_by_login( $abspath[1] ) )
+ { // User is found by login:
+ $root = FileRoot::gen_ID( 'user', $file_User->ID );
+ $start_relpath = 2;
+ }
+ break;
+
+ case 'blogs':
+ // Collection media dir:
+ $BlogCache = & get_BlogCache();
+ if( $file_Blog = & $BlogCache->get_by_urlname( $abspath[1], false ) )
+ { // Blog is found by urlname:
+ $root = FileRoot::gen_ID( 'collection', $file_Blog->ID );
+ $start_relpath = 2;
+ }
+ break;
+
+ case 'shared':
+ // Shared media dir:
+ $root = FileRoot::gen_ID( 'shared', 0 );
+ $start_relpath = 2;
+ break;
+
+ case 'import':
+ // Import media dir:
+ $root = FileRoot::gen_ID( 'import', 0 );
+ $start_relpath = 1;
+ break;
+
+ case 'emailcampaign':
+ // Email campaign media dir:
+ $EmailCampaignCache = & get_EmailCampaignCache();
+ if( $file_EmailCampaign = & $EmailCampaignCache->get_by_ID( $abspath[1], false ) )
+ { // Email campaign is found by ID:
+ $root = FileRoot::gen_ID( 'emailcampaign', $file_EmailCampaign->ID );
+ $start_relpath = 1;
+ }
+ break;
+ }
+
+ if( ! empty( $root ) )
+ { // Get relative path only if root is detected:
+ $relpath = '';
+ $abspath_length = count( $abspath );
+ for( $f = $start_relpath; $f < $abspath_length - 1; $f++ )
+ {
+ if( $f == $abspath_length - 3 )
+ { // Skip this because it is a evocache folder:
+ continue;
+ }
+ $relpath .= $abspath[ $f ].( $f < $abspath_length - 2 ? DIRECTORY_SEPARATOR : '' );
+ }
+
+ if( ! empty( $relpath ) )
+ { // Return data only if they both are detected:
+ return array(
+ 'root' => $root,
+ 'path' => $relpath,
+ );
+ }
+ }
+
+ // Data are not found correctly:
+ return false;
+}
?>
@@ -8,6 +8,6 @@
# Redirect any _evocache file that does not exist to generate new by htsrv/getfile.php:
RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{QUERY_STRING} mtime=(\d+)&root=([a-z0-9_]+)&path=(.+)
- RewriteRule ^.+/[_\.]evocache/.+/([a-z0-9\-]+)\.[a-z]{3,4}$ /htsrv/getfile.php?mtime=%1&size=$1&root=%2&path=%3 [L]
+ RewriteCond %{QUERY_STRING} mtime=(\d+)
+ RewriteRule ^(.+/[_\.]evocache/.+/([a-z0-9\-]+)\.[a-z]{3,4})$ /htsrv/getfile.php?abspath=$1&size=$2&mtime=%1 [L]
</IfModule>
@@ -1,13 +1,4 @@
# We don't want any PHP execution in this folder! (Prevent direct invocation of PHP files)
<IfModule mod_php5.c>
php_flag engine off
-</IfModule>
-
-<IfModule mod_rewrite.c>
- RewriteEngine On
-
- # Redirect any _evocache file that does not exist to generate new by htsrv/getfile.php:
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{QUERY_STRING} mtime=(\d+)&root=([a-z0-9_]+)&path=(.+)
- RewriteRule ^.+/[_\.]evocache/.+/([a-z0-9\-]+)\.[a-z]{3,4}$ /htsrv/getfile.php?mtime=%1&size=$1&root=%2&path=%3 [L]
</IfModule>

0 comments on commit e56fa49

Please sign in to comment.