? .svn ? cdn.visibility.patch.2.txt ? cdn.visibility.patch.txt ? patches/.svn Index: cdn.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cdn/cdn.admin.inc,v retrieving revision 1.1 diff -u -r1.1 cdn.admin.inc --- cdn.admin.inc 1 Jul 2009 11:35:31 -0000 1.1 +++ cdn.admin.inc 14 Oct 2010 20:45:20 -0000 @@ -65,6 +65,42 @@ ), '#default_value' => variable_get(CDN_STATS_VARIABLE, CDN_DISABLED), ); + + $form['cdn_visibility_settings'] = array( + '#type' => 'fieldset', + '#title' => t('What pages to enable CDN on'), + ); + + $access = user_access(CDN_PERM_PHP_VISIBILITY); + $pages = variable_get(CDN_PAGES_VARIABLE, ''); + $visibility = variable_get(CDN_VISIBILITY_VARIABLE, 1); + + if ($visibility == CDN_PHP_VIS_VALUE && !$access) { + // User is not allowed to change visibility PHP code + $form['cdn_visibility_settings'][CDN_VISIBILITY_VARIABLE] = array('#type' => 'value', '#value' => CDN_PHP_VIS_VALUE); + $form['cdn_visibility_settings'][CDN_PAGES_VARIABLE] = array('#type' => 'value', '#value' => $pages); + $form['cdn_visibility_settings']['#description'] = t("You don't have the required permissions to change these setting."); + } else { + $visibility_options = array(t('Add to every page except the listed pages.'), t('Add to the listed pages only.')); + $visibility_description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')); + if ($access) { + $visibility_options[] = t('Add if the following PHP code returns TRUE (PHP-mode, experts only).'); + $visibility_description .= ' '. t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '')); + } + $form['cdn_visibility_settings'][CDN_VISIBILITY_VARIABLE] = array( + '#type' => 'radios', + '#title' => t('Add tracking to specific pages'), + '#options' => $visibility_options, + '#default_value' => $visibility, + ); + $form['cdn_visibility_settings'][CDN_PAGES_VARIABLE] = array( + '#type' => 'textarea', + '#title' => t('Pages'), + '#default_value' => $pages, + '#description' => $visibility_description, + '#wysiwyg' => FALSE, + ); + } return system_settings_form($form); } Index: cdn.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/cdn/cdn.module,v retrieving revision 1.25 diff -u -r1.25 cdn.module --- cdn.module 1 Jul 2009 19:36:50 -0000 1.25 +++ cdn.module 14 Oct 2010 20:45:20 -0000 @@ -14,6 +14,8 @@ // Permissions. define('CDN_PERM_ACCESS_STATS', 'access per-page statistics'); define('CDN_PERM_ACCESS_DEBUG', 'access files on CDN when in debug mode'); +define('CDN_PERM_PHP_VISIBILITY', 'use PHP for CDN visibility'); +define('CDN_PHP_VIS_VALUE', 2); // Variables and values. define('CDN_MODE_VARIABLE', 'cdn_mode'); @@ -22,6 +24,9 @@ define('CDN_STATUS_VARIABLE', 'cdn_status'); define('CDN_STATS_VARIABLE', 'cdn_stats'); define('CDN_DRUPAL_ROOT_VARIABLE', 'cdn_drupal_root'); +define('CDN_VISIBILITY_VARIABLE', 'cdn_visibility'); +define('CDN_PAGES_VARIABLE', 'cdn_pages'); + // Variables for basic mode. define('CDN_BASIC_URL_VARIABLE', 'cdn_basic_url'); @@ -50,7 +55,7 @@ require_once(drupal_get_path('module', 'cdn') . '/cdn.stats.inc'); } - if ($status == CDN_ENABLED || ($status == CDN_DEBUG && user_access(CDN_PERM_ACCESS_DEBUG))) { + if ($status == CDN_ENABLED || ($status == CDN_DEBUG && user_access(CDN_PERM_ACCESS_DEBUG) && _cdn_visibility_pages())) { if ($stats) { $start = microtime(); } @@ -136,7 +141,7 @@ * Implementation of hook_perm(). */ function cdn_perm() { - return array(CDN_PERM_ACCESS_STATS, CDN_PERM_ACCESS_DEBUG); + return array(CDN_PERM_ACCESS_STATS, CDN_PERM_ACCESS_DEBUG, CDN_PERM_PHP_VISIBILITY); } /** @@ -435,3 +440,40 @@ return $db; } + +/** + * Based on visibility setting this function returns TRUE if the CDN URLs should + * be rewritten on the current page and otherwise FALSE. + */ +function _cdn_visibility_pages() { + static $page_match; + // Cache visibility setting in hook_init for hook_footer. + if (!isset($page_match)) { + $visibility = variable_get(CDN_VISIBILITY_VARIABLE, 0); + $pages = variable_get(CDN_PAGES_VARIABLE, ''); + + + + // Match path if necessary. + if (!empty($pages)) { + if ($visibility < 2) { + $path = drupal_get_path_alias($_GET['q']); + // Compare with the internal and path alias (if any). + $page_match = drupal_match_path($path, $pages); + if ($path != $_GET['q']) { + $page_match = $page_match || drupal_match_path($_GET['q'], $pages); + } + // When $visibility has a value of 0, the block is displayed on + // all pages except those listed in $pages. When set to 1, it + // is displayed only on those pages listed in $pages. + $page_match = !($visibility xor $page_match); + } + else { + $page_match = drupal_eval($pages); + } + } else { + $page_match = ($visibility == 0); + } + } + return $page_match; +}