function _optimizely_unique_paths in Optimizely 7.3
Same name and namespace in other branches
- 7.2 optimizely.admin.inc \_optimizely_unique_paths()
2 calls to _optimizely_unique_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 749
- Admin page callback for the Optimizely module.
Code
function _optimizely_unique_paths($target_paths, $target_oid = NULL) {
$target_paths = _optimizely_collect_alias($target_paths);
$duplicate_target_path = _optimizely_duplicate_check($target_paths);
if (!$duplicate_target_path) {
$query = db_select('optimizely', 'o', array(
'target' => 'slave',
))
->fields('o', array(
'oid',
'project_title',
'path',
))
->condition('o.enabled', 1, '=');
if ($target_oid != NULL) {
$query = $query
->condition('o.oid', $target_oid, '<>');
}
$projects = $query
->execute();
if ($query
->countQuery()
->execute()
->fetchField() == 0) {
return array(
TRUE,
NULL,
);
}
$all_project_paths = array();
foreach ($projects as $project) {
$project_paths = unserialize($project->path);
$all_project_paths = array_merge($all_project_paths, $project_paths);
}
$all_project_paths = _optimizely_collect_alias($all_project_paths);
$all_project_paths_string = implode("\n", $all_project_paths);
foreach ($target_paths as $target_path) {
if (strpos($target_path, '*') !== FALSE) {
if (strpos($target_path, '*') !== 0) {
$target_path = substr($target_path, 0, -2);
foreach ($all_project_paths as $all_project_path) {
if (strpos($all_project_path, $target_path) === 0 && $all_project_path != $target_path) {
return array(
$project->project_title,
$target_path,
);
}
}
}
elseif (strpos($target_path, '*') === 0 && (count($target_paths) > 1 || count($all_project_paths) > 0)) {
return array(
$project->project_title,
$target_path,
);
}
if (in_array('*', $all_project_paths)) {
return array(
$project->project_title,
$target_path,
);
}
}
elseif (strpos($target_path, '?') !== FALSE) {
$target_path = substr($target_path, 0, strpos($target_path, '?'));
}
if (drupal_match_path($target_path, $all_project_paths_string)) {
return array(
$project->project_title,
$target_path,
);
}
}
return array(
TRUE,
NULL,
);
}
else {
return array(
NULL,
$duplicate_target_path,
);
}
}