Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Camo Image Proxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WP Plugins
Camo Image Proxy
Commits
e6c5b324
Commit
e6c5b324
authored
7 years ago
by
Erick Hitter
Browse files
Options
Downloads
Patches
Plain Diff
Camouflage attachment URLs
parent
ddafdc42
Branches
Branches containing commit
No related tags found
3 merge requests
!6
add linting
,
!5
WIP: Add JUnit reporting
,
!4
WIP: Initial release
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
camo-image-proxy.php
+3
-1
3 additions, 1 deletion
camo-image-proxy.php
inc/class-rewrite-urls.php
+38
-0
38 additions, 0 deletions
inc/class-rewrite-urls.php
inc/class-url.php
+10
-2
10 additions, 2 deletions
inc/class-url.php
with
51 additions
and
3 deletions
camo-image-proxy.php
+
3
−
1
View file @
e6c5b324
...
@@ -34,7 +34,7 @@ require_once PLUGIN_PATH . '/inc/class-options-page.php';
...
@@ -34,7 +34,7 @@ require_once PLUGIN_PATH . '/inc/class-options-page.php';
/**
/**
* URL Building
* URL Building
*/
*/
require_once
PLUGIN_PATH
.
'/inc/class-url
s
.php'
;
require_once
PLUGIN_PATH
.
'/inc/class-url.php'
;
/**
/**
* Rewrite WordPress-generated URLs
* Rewrite WordPress-generated URLs
...
@@ -60,5 +60,7 @@ function init() {
...
@@ -60,5 +60,7 @@ function init() {
if
(
is_admin
()
)
{
if
(
is_admin
()
)
{
Options_Page
::
instance
();
Options_Page
::
instance
();
}
}
Rewrite_URLs
::
instance
();
}
}
add_action
(
'init'
,
__NAMESPACE__
.
'\init'
);
add_action
(
'init'
,
__NAMESPACE__
.
'\init'
);
This diff is collapsed.
Click to expand it.
inc/class-rewrite-urls.php
+
38
−
0
View file @
e6c5b324
<?php
/**
* Force Core's image functions to use Camo
*
* @package Camo_Image_Proxy
*/
namespace
Camo_Image_Proxy
;
/**
* Class Rewrite_URLs
*/
class
Rewrite_URLs
{
use
Singleton
;
/**
* Hooks
*/
public
function
setup
()
{
add_filter
(
'wp_get_attachment_image_src'
,
[
$this
,
'encode_image'
]
);
}
/**
* Camouflage attachment URL
*
* @param array $image Image data.
* @return array
*/
public
function
encode_image
(
array
$image
)
:
array
{
$url
=
URL
::
instance
()
->
encode
(
$image
[
0
]
);
if
(
is_string
(
$url
)
)
{
$image
[
0
]
=
$url
;
}
return
$image
;
}
}
This diff is collapsed.
Click to expand it.
inc/class-url
s
.php
→
inc/class-url.php
+
10
−
2
View file @
e6c5b324
...
@@ -25,7 +25,7 @@ class URL {
...
@@ -25,7 +25,7 @@ class URL {
$can_rewrite
=
true
;
$can_rewrite
=
true
;
// Validate host.
// Validate host.
if
(
$this
->
is_valid_url
(
$host
)
)
{
if
(
!
$this
->
is_valid_url
(
$host
)
)
{
$can_rewrite
=
false
;
$can_rewrite
=
false
;
}
}
...
@@ -75,6 +75,14 @@ class URL {
...
@@ -75,6 +75,14 @@ class URL {
* @return bool
* @return bool
*/
*/
private
function
is_valid_url
(
string
$url
)
:
bool
{
private
function
is_valid_url
(
string
$url
)
:
bool
{
return
empty
(
$url
)
||
(
!
filter_var
(
$url
,
FILTER_VALIDATE_URL
)
&&
!
filter_var
(
$url
,
FILTER_VALIDATE_IP
)
);
if
(
empty
(
$url
)
)
{
return
false
;
}
if
(
false
===
filter_var
(
$url
,
FILTER_VALIDATE_URL
)
&&
false
===
filter_var
(
$url
,
FILTER_VALIDATE_IP
)
)
{
return
false
;
}
return
true
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment