You are here

function _optimizely_valid_paths in Optimizely 7.2

Same name and namespace in other branches
  1. 7.3 optimizely.admin.inc \_optimizely_valid_paths()

_optimizely_valid_paths()

Validate the target paths with drupal_lookup_path.

@parm $target_paths An array of the paths to validate. @parm $include Boolean, TRUE if the paths are included or FALSE for exclude paths

Return value

Boolean of TRUE if the paths are valid or a string of the path that failed.

2 calls to _optimizely_valid_paths()
optimizely_add_update_form_validate in ./optimizely.admin.inc
Validate form submissions from optimizely_add_update_form().
optimizely_ajax_enable in ./optimizely.admin.inc
AJAX callback for click event on project enable checkbox.

File

./optimizely.admin.inc, line 937
Admin page callback for the Optimizely module.

Code

function _optimizely_valid_paths($project_paths) {

  // Validate entered paths to confirm the paths exist on the website
  foreach ($project_paths as $project_path) {

    // Check for site wide wildcard
    if (strpos($project_path, '*') === 0) {
      if (count($project_paths) == 1) {
        return TRUE;
      }
      else {
        return $project_path;
      }
    }
    elseif (strpos($project_path, '*') !== FALSE) {
      $project_wildpath = substr($project_path, 0, -2);
      if (!drupal_valid_path($project_wildpath, TRUE)) {

        // Look for entries in url_aias
        $query = db_query("SELECT * FROM {url_alias} WHERE\n          source LIKE :project_wildpath OR alias LIKE :project_wildpath", array(
          ':project_wildpath' => $project_wildpath . '%',
        ));
        $project_wildpath_match = $query
          ->rowCount();

        // No matches found for wildcard path
        if (!$project_wildpath_match) {
          return $project_path;
        }
      }
    }
    elseif (strpos($project_path, '?') !== FALSE) {

      // Look for entries in menu_router
      $project_parmpath = substr($project_path, 0, strpos($project_path, '?'));

      // Look for entry in url_alias table
      if (drupal_lookup_path('alias', $project_parmpath) === FALSE && drupal_lookup_path('source', $project_parmpath) === FALSE && drupal_valid_path($project_parmpath, TRUE) === FALSE) {
        return $project_path;
      }
    }
    elseif (drupal_valid_path($project_path, TRUE) === FALSE) {

      // Look for entry in url_alias table
      if (drupal_lookup_path('alias', $project_path) === FALSE && drupal_lookup_path('source', $project_path) === FALSE) {
        return $project_path;
      }
    }
  }
  return TRUE;
}