summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Stein2010-10-28 18:44:49 (GMT)
committerJoel Stein2010-10-28 18:44:49 (GMT)
commitd70385e6dd7362a74c4695f243f377bb99b1c81c (patch)
tree35e051a9f2517926231cb69f8a1b5345935de1f4
parentcac2a88196c5d092052c40604119861b1d956f4b (diff)
#950626 by toomanypets: Fixed bug which occurred when viewing cached pages.6.x-1.2
-rwxr-xr-xskin.module203
1 files changed, 103 insertions, 100 deletions
diff --git a/skin.module b/skin.module
index 3f1c965..a1d1bc9 100755
--- a/skin.module
+++ b/skin.module
@@ -1,100 +1,103 @@
-<?php
-// $Id$
-
-/**
- * Implementation of hook_perm().
- */
-function skin_perm() {
- return array('administer skin paths');
-}
-
-/**
- * Implementation of hook_menu().
- */
-function skin_menu() {
- $items['admin/settings/skin'] = array(
- 'title' => 'Skin settings',
- 'description' => 'Settings for the Skin module.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('skin_settings_form'),
- 'access arguments' => array('administer skin paths'),
- 'file' => 'skin.admin.inc',
- );
- return $items;
-}
-
-/**
- * Implementation of hook_help().
- */
-function skin_help($path, $arg) {
- switch ($path) {
- case 'admin/settings/skin':
- return '<p>'. t('This module makes it easy to create a "skin" of your theme. Define your paths below, visit your skinned pages, and view the source to save your skinned HTML.') .'</p>';
- }
-}
-
-/**
- * Implementation of hook_init().
- */
-function skin_init() {
- $skin = drupal_match_path(drupal_get_path_alias($_GET['q']), variable_get('skin_paths', ''));
-
- // If viewing a "skin" page, capture the output so we can manipulate it in
- // skin_exit().
- if ($skin) {
- ob_start();
- }
-}
-
-/**
- * Implementation of hook_exit().
- */
-function skin_exit() {
- $skin = drupal_match_path(drupal_get_path_alias($_GET['q']), variable_get('skin_paths', ''));
-
- // On skin page; grab the output and manipulate it.
- if ($skin) {
- print preg_replace_callback('/"\/([^"]+)?"/', '_skin_replace_callback', ob_get_clean());
- }
-}
-
-/**
- * Manipulates the rendered HTML.
- */
-function _skin_replace_callback($matches) {
- $filepath_minus_query = preg_replace('/\?.*/', '', $matches[1]);
- $info = pathinfo($filepath_minus_query);
-
- $save = variable_get('skin_save', 1);
-
- // If we're interested in saving CSS or JS files...
- if ($save > 0 and in_array($info['extension'], array('css', 'js'))) {
-
- // Figure out if this is an optimized file.
- $optimized = in_array(substr(str_replace(file_directory_path(), '', $filepath_minus_query), 0, 4), array('/css', '/js/'));
-
- // Saving...
- if ($save == 2 or ($save == 1 and $optimized)) {
-
- // Save file in directory resembling its original location.
- $skin_path = file_create_path('skin') . (!$optimized ? '/'. dirname($filepath_minus_query) : '');
- if (file_check_directory($skin_path, FILE_CREATE_DIRECTORY) or mkdir($skin_path, 0755, TRUE)) {
- $filename = $skin_path .'/'. $info['filename'] .'.'. $info['extension'];
- $contents = file_get_contents($filepath_minus_query);
- if (!file_save_data($contents, $filename, FILE_EXISTS_REPLACE)) {
- unset($filename);
- }
- }
- }
- }
-
- // If filename was not made, then we are not saving.
- if (!isset($filename)) {
- $filename = $matches[1];
- }
-
- // Convert URL to absolute.
- global $base_url;
- global $base_path;
- return '"'. $base_url . $base_path . $filename .'"';
-}
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_perm().
+ */
+function skin_perm() {
+ return array('administer skin paths');
+}
+
+/**
+ * Implementation of hook_menu().
+ */
+function skin_menu() {
+ $items['admin/settings/skin'] = array(
+ 'title' => 'Skin settings',
+ 'description' => 'Settings for the Skin module.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('skin_settings_form'),
+ 'access arguments' => array('administer skin paths'),
+ 'file' => 'skin.admin.inc',
+ );
+ return $items;
+}
+
+/**
+ * Implementation of hook_help().
+ */
+function skin_help($path, $arg) {
+ switch ($path) {
+ case 'admin/settings/skin':
+ return '<p>'. t('This module makes it easy to create a "skin" of your theme. Define your paths below, visit your skinned pages, and view the source to save your skinned HTML.') .'</p>';
+ }
+}
+
+/**
+ * Implementation of hook_boot().
+ */
+function skin_boot() {
+ // Bootstrap the "path" phase, so we can match the path (because if we're
+ // viewing a cached page, these functions won't have been defined yet).
+ drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);
+
+ // Viewing a "skin" page.
+ if (drupal_match_path(drupal_get_path_alias($_GET['q']), variable_get('skin_paths', ''))) {
+ // Bootstrap the rest of Drupal, so we have access to the "file_" functions
+ // in _skin_replace_callback.
+ drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+ // Capture the output so we can manipulate it in skin_exit().
+ ob_start();
+ }
+}
+
+/**
+ * Implementation of hook_exit().
+ */
+function skin_exit() {
+ // On skin page; grab the output and manipulate it.
+ if (drupal_match_path(drupal_get_path_alias($_GET['q']), variable_get('skin_paths', ''))) {
+ print preg_replace_callback('/"\/([^"]+)?"/', '_skin_replace_callback', ob_get_clean());
+ }
+}
+
+/**
+ * Manipulates the rendered HTML.
+ */
+function _skin_replace_callback($matches) {
+ $filepath_minus_query = preg_replace('/\?.*/', '', $matches[1]);
+ $info = pathinfo($filepath_minus_query);
+
+ $save = variable_get('skin_save', 1);
+
+ // If we're interested in saving CSS or JS files...
+ if ($save > 0 and in_array($info['extension'], array('css', 'js'))) {
+
+ // Figure out if this is an optimized file.
+ $optimized = in_array(substr(str_replace(file_directory_path(), '', $filepath_minus_query), 0, 4), array('/css', '/js/'));
+
+ // Saving...
+ if ($save == 2 or ($save == 1 and $optimized)) {
+
+ // Save file in directory resembling its original location.
+ $skin_path = file_create_path('skin') . (!$optimized ? '/'. dirname($filepath_minus_query) : '');
+ if (file_check_directory($skin_path, FILE_CREATE_DIRECTORY) or mkdir($skin_path, 0755, TRUE)) {
+ $filename = $skin_path .'/'. $info['filename'] .'.'. $info['extension'];
+ $contents = file_get_contents($filepath_minus_query);
+ if (!file_save_data($contents, $filename, FILE_EXISTS_REPLACE)) {
+ unset($filename);
+ }
+ }
+ }
+ }
+
+ // If filename was not made, then we are not saving.
+ if (!isset($filename)) {
+ $filename = $matches[1];
+ }
+
+ // Convert URL to absolute.
+ global $base_url;
+ global $base_path;
+ return '"'. $base_url . $base_path . $filename .'"';
+}