|
1 | 1 | <?php |
| 2 | + |
2 | 3 | namespace Gwa\Wordpress; |
3 | 4 |
|
4 | 5 | /** |
|
12 | 13 | * @license MIT |
13 | 14 | */ |
14 | 15 |
|
| 16 | +use Gwa\Wordpress\MockeryWpBridge\Traits\WpBridgeTrait; |
| 17 | + |
15 | 18 | /** |
16 | 19 | * AbstractResolver. |
17 | 20 | * |
18 | 21 | * @author Daniel Bannert |
19 | 22 | */ |
20 | 23 | abstract class AbstractResolver |
21 | 24 | { |
| 25 | + use WpBridgeTrait; |
| 26 | + |
22 | 27 | /** |
23 | 28 | * Folder path to wordpress, with trailing slash. |
24 | 29 | * |
@@ -75,15 +80,65 @@ public function fixNetworkAdminUrlFilter($path = '', $scheme = 'admin') |
75 | 80 | return preg_replace($wordpressUrl, $multiSiteUrl, $path, 1); |
76 | 81 | } |
77 | 82 |
|
| 83 | + /** |
| 84 | + * Fix double backslashes in app folder. |
| 85 | + * |
| 86 | + * @param string |
| 87 | + */ |
| 88 | + public function fixWpDoubleSlashFilter($urls) |
| 89 | + { |
| 90 | + foreach ($urls as &$url) { |
| 91 | + if ($url) { |
| 92 | + $url = str_replace('//app', '/app', $url); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + return $urls; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Fixes the protocol in urls. Replaces leading double slashes // |
| 101 | + * with the full protocol; https or http depending on context. |
| 102 | + * |
| 103 | + * @param string |
| 104 | + * |
| 105 | + * @return array |
| 106 | + */ |
| 107 | + public function fixWpProtocolFilter($urls) |
| 108 | + { |
| 109 | + $protocol = $this->getSiteProtocol(); |
| 110 | + |
| 111 | + foreach ($urls as $k => &$v) { |
| 112 | + if ((strpos($k, 'url') !== false) && (substr($v, 0, 2) === '//')) { |
| 113 | + $v = $protocol.ltrim($v, '//'); |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + return $urls; |
| 118 | + } |
| 119 | + |
| 120 | + /** |
| 121 | + * Get the correct protocol. |
| 122 | + * |
| 123 | + * @return string |
| 124 | + */ |
| 125 | + protected function getSiteProtocol() |
| 126 | + { |
| 127 | + return $this->getWpBridge()->isSsl() ? 'https://' : 'http://'; |
| 128 | + } |
| 129 | + |
78 | 130 | /** |
79 | 131 | * Init all filter. |
80 | 132 | */ |
81 | 133 | public function init() |
82 | 134 | { |
83 | | - add_filter('network_admin_url', [$this, 'fixNetworkAdminUrlFilter'], 10, 2); |
| 135 | + $this->getWpBridge()->addFilter('network_admin_url', [$this, 'fixNetworkAdminUrlFilter'], 10, 2); |
| 136 | + |
| 137 | + $this->getWpBridge()->addFilter('script_loader_src', [$this, 'fixStyleScriptPathFilter'], 10, 2); |
| 138 | + $this->getWpBridge()->addFilter('style_loader_src', [$this, 'fixStyleScriptPathFilter'], 10, 2); |
84 | 139 |
|
85 | | - add_filter('script_loader_src', [$this, 'fixStyleScriptPathFilter'], 10, 2); |
86 | | - add_filter('style_loader_src', [$this, 'fixStyleScriptPathFilter'], 10, 2); |
| 140 | + $this->getWpBridge()->addFilter('upload_dir', [$this, 'fixWpDoubleSlashFilter'], 10, 1); |
| 141 | + $this->getWpBridge()->addFilter('upload_dir', [$this, 'fixWpProtocolFilter'], 10, 1); |
87 | 142 | } |
88 | 143 |
|
89 | 144 | /** |
|
0 commit comments