Permalink
Browse files

Added file types to file extension array. Added fonts to array.

  • Loading branch information...
1 parent 1104e70 commit f0ae52e582705f0b14240be2b7e199e33a19c0e5 @mvied committed Mar 29, 2013
Showing with 37 additions and 23 deletions.
  1. +19 −1 lib/WordPressHTTPS.php
  2. +9 −6 lib/WordPressHTTPS/Module/Core.php
  3. +9 −16 lib/WordPressHTTPS/Module/Parser.php
@@ -50,10 +50,28 @@ class WordPressHTTPS extends Mvied_Plugin {
/**
* File extensions to be loaded securely.
+ * File type => Array of extensions
*
* @var array
*/
- protected $_file_extensions = array('jpg', 'jpeg', 'png', 'gif', 'css', 'js', 'ttf', 'otf');
+ protected $_file_extensions = array(
+ 'script' => array(
+ 'js'
+ ),
+ 'img' => array(
+ 'jpg',
+ 'jpeg',
+ 'png',
+ 'gif'
+ ),
+ 'style' => array(
+ 'css'
+ ),
+ 'font' => array(
+ 'ttf',
+ 'otf'
+ )
+ );
/**
* Default External SSL Host Mapping
@@ -296,12 +296,15 @@ public function secure_login( $force_ssl, $post_id = 0, $url = '' ) {
public function secure_element( $force_ssl, $post_id = 0, $url = '' ) {
if ( $url != '' && $this->getPlugin()->isUrlLocal($url) ) {
$filename = basename($url);
- foreach( $this->getPlugin()->getFileExtensions() as $extension ) {
- if ( preg_match('/\.' . $extension . '(\?|$)/', $filename) ) {
- if ( $this->getPlugin()->isSsl() ) {
- $force_ssl = true;
- } else {
- $force_ssl = false;
+ foreach( $this->getPlugin()->getFileExtensions() as $type => $extensions ) {
+ foreach( $extensions as $extension ) {
+ if ( preg_match('/\.' . $extension . '(\?|$)/', $filename) ) {
+ if ( $this->getPlugin()->isSsl() ) {
+ $force_ssl = true;
+ } else {
+ $force_ssl = false;
+ }
+ break 2;
}
}
}
@@ -265,22 +265,15 @@ public function fixExtensions() {
$filename = basename($url);
$scheme = $matches[2][$i];
- foreach( $this->getPlugin()->getFileExtensions() as $extension ) {
- if ( $extension == 'js' ) {
- $type = 'script';
- } else if ( $extension == 'css' ) {
- $type = 'style';
- } else if ( in_array($extension, array('jpg', 'jpeg', 'png', 'gif')) ) {
- $type = 'img';
- } else {
- continue;
- }
-
- if ( preg_match('/\.' . $extension . '(\?|$)/', $filename) ) {
- if ( $this->getPlugin()->isSsl() && ( $this->getPlugin()->getSetting('ssl_host_diff') || ( !$this->getPlugin()->getSetting('ssl_host_diff') && strpos($url, 'http://') === 0 ) ) ) {
- $this->secureElement($url, $type);
- } else if ( !$this->getPlugin()->isSsl() && strpos($url, 'https://') === 0 && $this->getPlugin()->isUrlLocal($url) ) {
- $this->unsecureElement($url, $type);
+ foreach( $this->getPlugin()->getFileExtensions() as $type => $extensions ) {
+ foreach( $extensions as $extension ) {
+ if ( preg_match('/\.' . $extension . '(\?|$)/', $filename) ) {
+ if ( $this->getPlugin()->isSsl() && ( $this->getPlugin()->getSetting('ssl_host_diff') || ( !$this->getPlugin()->getSetting('ssl_host_diff') && strpos($url, 'http://') === 0 ) ) ) {
+ $this->secureElement($url, $type);
+ } else if ( !$this->getPlugin()->isSsl() && strpos($url, 'https://') === 0 && $this->getPlugin()->isUrlLocal($url) ) {
+ $this->unsecureElement($url, $type);
+ }
+ break 2;
}
}
}

0 comments on commit f0ae52e

Please sign in to comment.