summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoel Stein2011-03-14 20:40:18 (GMT)
committerJoel Stein2011-03-14 20:40:18 (GMT)
commitb1fcdb62a65869e003e279e6a2d8b261ed232879 (patch)
tree0728084a36d24eb0aaf1977b6d98f8e864a607bc
parent2109ae51b362cee9c02aad85bb565a3c68d1ae8b (diff)
D7 upgrade.7.x-1.1
-rw-r--r--skin.admin.inc27
-rwxr-xr-xskin.info3
-rwxr-xr-xskin.module119
3 files changed, 55 insertions, 94 deletions
diff --git a/skin.admin.inc b/skin.admin.inc
index 83ad62b..9c328c6 100644
--- a/skin.admin.inc
+++ b/skin.admin.inc
@@ -3,7 +3,7 @@
/**
* Settings form.
*/
-function skin_settings_form() {
+function skin_settings_form($form, &$form_state) {
$form['skin_paths'] = array(
'#title' => t('Skin paths'),
'#type' => 'textarea',
@@ -13,7 +13,7 @@ function skin_settings_form() {
$form['skin_save'] = array(
'#type' => 'radios',
'#title' => t('CSS and Javascript'),
- '#description' => t('Optimized CSS and Javascript files are frequently deleted, which could break your skin. You can save an additional copy of these files, so they persist until the next time you build your skin. These files are saved in the "skin" directory within your <a href="@files_url">file system path</a>. You can also adjust your optimization settings on the <a href="@performance_url">performance page</a>.', array('@files_url' => 'admin/settings/file-system', '@performance_url' => url('admin/settings/performance'))),
+ '#description' => t('Optimized CSS and Javascript files are frequently deleted, which could break your skin. You can save an additional copy of these files, so they persist until the next time you build your skin. These files are saved in the "skin" directory within your <a href="@files_url">file system path</a>. You can also adjust your optimization settings on the <a href="@performance_url">performance page</a>.', array('@files_url' => 'admin/config/file-system', '@performance_url' => url('admin/config/development/performance'))),
'#options' => array(
0 => "Don't save any files",
1 => "Save a copy of optimized CSS and JS files",
@@ -35,27 +35,6 @@ function skin_settings_form() {
*/
function skin_settings_form_submit($form, &$form_state) {
if ($form_state['values']['skin_clear_cache']) {
- _skin_recursive_delete(file_create_path('skin'));
- }
-}
-
-/**
- * Recursive delete function.
- */
-function _skin_recursive_delete($path) {
- if (is_file($path) or is_link($path)) {
- unlink($path);
- }
- else if (is_dir($path)) {
- $d = dir($path);
- while (($entry = $d->read()) !== FALSE) {
- if ($entry == '.' or $entry == '..') {
- continue;
- }
- $entry_path = $path .'/'. $entry;
- _skin_recursive_delete($entry_path);
- }
- $d->close();
- rmdir($path);
+ file_unmanaged_delete_recursive('public://skin');
}
}
diff --git a/skin.info b/skin.info
index 78ef360..8e9b260 100755
--- a/skin.info
+++ b/skin.info
@@ -1,3 +1,4 @@
name = Skin
description = Turns your theme into a flexible, offsite skin.
-core = 6.x
+core = 7.x
+configure = admin/config/skin \ No newline at end of file
diff --git a/skin.module b/skin.module
index 6820bf5..339e933 100755
--- a/skin.module
+++ b/skin.module
@@ -1,17 +1,21 @@
<?php
/**
- * Implementation of hook_perm().
+ * Implements hook_permission().
*/
-function skin_perm() {
- return array('administer skin paths');
+function skin_permission() {
+ return array(
+ 'administer skin paths' => array(
+ 'title' => t('administer skin paths'),
+ ),
+ );
}
/**
- * Implementation of hook_menu().
+ * Implements hook_menu().
*/
function skin_menu() {
- $items['admin/settings/skin'] = array(
+ $items['admin/config/content/skin'] = array(
'title' => 'Skin settings',
'description' => 'Settings for the Skin module.',
'page callback' => 'drupal_get_form',
@@ -23,92 +27,69 @@ function skin_menu() {
}
/**
- * Implementation of hook_help().
+ * Implements 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();
+ case 'admin/config/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_exit().
+ * Implements 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());
+ global $base_url;
+ global $base_path;
+ $data = ob_get_clean();
+ // Converts all CSS and JS paths to absolute, optionally saving a copy in
+ // the skin folder.
+ print preg_replace_callback('/"((' . preg_quote($base_url, '/') . '?' . preg_quote($base_path, '/') . ')([^"]+\.(css|js))(\?[^"]+)?)"/', '_skin_replace_callback', $data);
}
}
/**
* Manipulates the rendered HTML.
+ *
+ * $matches[0] - entire match (including quotes)
+ * $matches[1] - entire url (no quotes)
+ * $matches[2] - base url and base path (http://example.com/)
+ * $matches[3] - path to css/js file (modules/system/system.base.css)
+ * $matches[4] - extension (css or js)
+ * $matches[5] - query string (empty for optimized files)
*/
function _skin_replace_callback($matches) {
- $filepath_minus_query = preg_replace('/\?.*/', '', $matches[1]);
- $info = pathinfo($filepath_minus_query);
-
$save = variable_get('skin_save', 1);
+ $uri = $matches[3];
+ $skin_uri = 'public://skin/' . $matches[3];
+ $optimized = empty($matches[5]);
- // 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'];
- // Optimized CSS files have resolved imports and prefixed paths.
- // Un-optimized JS files don't need to be resolved.
- if ($optimized or $info['extension'] == 'js') {
- $contents = file_get_contents($filepath_minus_query);
- }
- // Unoptimized CSS files need to resolve imports and prefix paths.
- // See drupal_build_css_cache().
- else {
- $contents = drupal_load_stylesheet($filepath_minus_query);
- $base = base_path() . dirname($filepath_minus_query) .'/';
- _drupal_build_css_path(NULL, $base);
- $contents = preg_replace_callback('/url\([\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\)/i', '_drupal_build_css_path', $contents);
- }
- if (!file_save_data($contents, $filename, FILE_EXISTS_REPLACE)) {
- unset($filename);
- }
+ // Save the CSS/JS file.
+ if ($save == 2 || ($save == 1 && $optimized)) {
+ // Save file in directory resembling its original location.
+ if (file_prepare_directory(dirname($skin_uri), FILE_CREATE_DIRECTORY)) {
+ // Optimized CSS files have resolved imports and prefixed paths.
+ // Unoptimized JS files don't need to be resolved.
+ if ($optimized || $matches[4] == 'js') {
+ $contents = file_get_contents($matches[3]);
+ }
+ // Unoptimized CSS files need to resolve imports and prefix paths.
+ // See drupal_build_css_cache().
+ else {
+ $contents = drupal_load_stylesheet($matches[3]);
+ $base = $matches[2] . dirname($matches[3]);
+ _drupal_build_css_path(NULL, $base);
+ $contents = preg_replace_callback('/url\([\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\)/i', '_drupal_build_css_path', $contents);
+ }
+ if (file_save_data($contents, $skin_uri, FILE_EXISTS_REPLACE)) {
+ $uri = $skin_uri;
}
}
}
- // 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 .'"';
+ // Return URL.
+ return '"' . file_create_url($uri) . '"';
}