? .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.22 diff -u -r1.22 cdn.admin.inc --- cdn.admin.inc 6 Oct 2010 20:43:23 -0000 1.22 +++ cdn.admin.inc 14 Oct 2010 20:52:19 -0000 @@ -55,6 +55,45 @@ '#process' => array('ctools_dependent_process'), '#dependency' => array('radio:' . CDN_STATUS_VARIABLE => array(CDN_TESTING, CDN_ENABLED)), ); + + $form['cdn_pages_settings'] = array( + '#type' => 'fieldset', + '#title' => t('What pages to enable CDN on'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + + $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'] = array('#type' => 'value', '#value' => CDN_PHP_VIS_VALUE); + $form['cdn_visibility_settings']['cdn_pages'] = 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'] = array( + '#type' => 'radios', + '#title' => t('Add tracking to specific pages'), + '#options' => $visibility_options, + '#default_value' => $visibility, + ); + $form['cdn_visibility_settings']['cdn_pages'] = 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.57 diff -u -r1.57 cdn.module --- cdn.module 6 Oct 2010 22:20:28 -0000 1.57 +++ cdn.module 14 Oct 2010 20:52:19 -0000 @@ -15,6 +15,8 @@ define('CDN_PERM_ACCESS_STATS', 'access per-page statistics'); define('CDN_PERM_ACCESS_TESTING', 'access files on CDN when in testing mode'); define('CDN_PERM_TOUCH', 'touch files'); +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'); @@ -24,6 +26,9 @@ define('CDN_STATS_VARIABLE', 'cdn_stats'); define('CDN_DRUPAL_ROOT_VARIABLE', 'cdn_drupal_root'); define('CDN_HTTPS_SUPPORT_VARIABLE', 'cdn_https_support'); +define('CDN_VISIBILITY_VARIABLE', 'cdn_visibility'); +define('CDN_PAGES_VARIABLE', 'cdn_pages'); + // Variables for exceptions. define('CDN_EXCEPTION_PATH_BLACKLIST_VARIABLE', 'cdn_exception_path_blacklist'); @@ -76,6 +81,12 @@ return; } + // If the current Drupal path (not the file path) matches the + // visibility settings, return immediately. + if (!_cdn_visibility_pages()) { + return; + } + // If the current path matches one of the blacklisted paths, return // immediately, except when the current path also matches one of the // whitelisted paths. @@ -201,7 +212,7 @@ * Implementation of hook_perm(). */ function cdn_perm() { - return array(CDN_PERM_ACCESS_STATS, CDN_PERM_ACCESS_TESTING, CDN_PERM_TOUCH); + return array(CDN_PERM_ACCESS_STATS, CDN_PERM_ACCESS_TESTING, CDN_PERM_TOUCH, CDN_PERM_PHP_VISIBILITY); } /** @@ -594,3 +605,35 @@ return $db; } + +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', 0); + $pages = variable_get('cdn_pages', ''); + + // 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; +}