Skip to content

Commit

Permalink
Add URL_STRIP_EXTENSION constant (#2)
Browse files Browse the repository at this point in the history
This small update allows users to remove the file extension from
the resulting URL, as requested. This is useful for instances using
a rewrite rule in order to automatically find the corresponsing file.

Be careful, as the filename generator only checks against existing
files of the same extension. It is therefore possible to have two files
with the exact same name, as long as they have a different extension.

Version bumped to 2.3.0
  • Loading branch information
Xenthys committed Apr 2, 2019
1 parent 150596d commit 3983d90
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion sharexen.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
// Example: ['Mario', 'Toad'] (sorry Luigi)
define('ADMINS', []);

// Strip file extensions from generated URLs
// This is only useful if you have a rewrite rule
define('URL_STRIP_EXTENSION', false);

// Log requests to Discord using a webhook
// If you do not know what this is about, please ignore
// It is not recommended to set this if your API is heavily used
Expand Down Expand Up @@ -180,6 +184,16 @@ function check_constants()
'Invalid ADMINS constant, must be an array.');
}

if (!defined('URL_STRIP_EXTENSION'))
{
define('URL_STRIP_EXTENSION', false);
}
if (gettype(URL_STRIP_EXTENSION) !== 'boolean')
{
error_die($data, 500, 'invalid_server_configuration',
'Invalid URL_STRIP_EXTENSION constant, must be a boolean.');
}

if (!defined('DISCORD_WEBHOOK_URL'))
{
define('DISCORD_WEBHOOK_URL', '');
Expand Down Expand Up @@ -466,6 +480,11 @@ function generate_all_urls(&$data, $deletion = true)

$data['url'] = "$protocol$domain$sub$name";

if (URL_STRIP_EXTENSION)
{
$data['url'] = preg_replace('/\.[^.]+$/', '', $data['url']);
}

if (!$deletion)
{
return;
Expand Down Expand Up @@ -741,7 +760,7 @@ function info_endpoint(&$data)
}
}

define('VERSION', '2.2.1');
define('VERSION', '2.3.0');
define('SOURCE', 'https://github.com/Xenthys/ShareXen');

$data = [
Expand Down

0 comments on commit 3983d90

Please sign in to comment.