PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.16
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.16
1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 All 180 releases
disco / vendor / inpsyde / assets / inc / functions.php

functions.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.16, at vendor/inpsyde/assets/inc/functions.php

89 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php # -*- coding: utf-8 -*-
2 /*
3 * This file is part of the Assets package.
4 *
5 * (c) Inpsyde GmbH
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 namespace Inpsyde\Assets;
12
13 // Exit early in case multiple Composer autoloaders try to include this file.
14 if (function_exists(__NAMESPACE__.'\\assetSuffix')) {
15 return;
16 }
17
18 /**
19 * Returns ".min" if SCRIPT_DEBUG is false.
20 *
21 * @return string
22 */
23 function assetSuffix(): string
24 {
25 return defined('SCRIPT_DEBUG') && SCRIPT_DEBUG
26 ? ''
27 : '.min';
28 }
29
30 /**
31 * Adding the assetSuffix() before file extension to the given file.
32 *
33 * @param string $file
34 *
35 * @return string
36 * @example before: my-script.js | after: my-script.min.js
37 *
38 */
39 function withAssetSuffix(string $file): string
40 {
41 $suffix = assetSuffix();
42 $extension = '.'.pathinfo($file, PATHINFO_EXTENSION);
43
44 return str_replace(
45 $extension,
46 $suffix.$extension,
47 $file
48 );
49 }
50
51 /**
52 * Symlinks a folder inside the web-root for Assets, which are outside of the web-root
53 * and returns a link to that folder.
54 *
55 * @param string $originDir
56 * @param string $name
57 *
58 * @return string|null
59 */
60 function symlinkedAssetFolder(string $originDir, string $name): ?string
61 {
62 // we're using realpath here, otherwise the comparisment with
63 // readlink will not work.
64 $originDir = realpath($originDir);
65
66 $folderName = '/~inpsyde-assets/';
67 $rootPath = WP_CONTENT_DIR.$folderName;
68 $rootUrl = WP_CONTENT_URL.$folderName;
69 if (! is_dir($rootPath) && ! wp_mkdir_p($rootPath)) {
70 return null;
71 }
72
73 $targetDir = $rootPath.$name;
74 $targetUrl = trailingslashit($rootUrl.$name);
75
76 if (is_link($targetDir)) {
77 if (readlink($targetDir) === $originDir) {
78 return $targetUrl;
79 }
80 unlink($targetDir);
81 }
82
83 if (! symlink($originDir, $targetDir)) {
84 return null;
85 }
86
87 return $targetUrl;
88 }
89