function _pages_restriction_set_next_page_path in Pages Restriction Access 7
Update page on cache so it can be retrieved later.
Parameters
string $next_page_path: String with path to set on database.
File
- includes/
pages_restriction.helpers.inc, line 14 - Contains the helpers functions for the Pages Restriction.
Code
function _pages_restriction_set_next_page_path($next_page_path) {
global $language;
$lang_name = $language->language;
$current_site_languages = language_list('enabled');
$path_alias = drupal_lookup_path('alias', $next_page_path);
if ($path_alias == FALSE) {
$path_alias = $next_page_path;
}
$translated_path = _pages_restriction_get_translated_path($path_alias);
if (strpos($translated_path, $lang_name . "/") !== FALSE) {
$translated_path = str_replace($lang_name . "/", "", $translated_path);
}
$next_translated_path = array();
if (count($current_site_languages[1]) >= 2 || array_key_exists($lang_name, $current_site_languages[1]) && $lang_name != 'en') {
$rules = explode(PHP_EOL, variable_get('pages_restriction_rules'));
$thank_you_id = explode("/", $next_page_path);
foreach ($rules as $key => $rule) {
$pages = explode("|", $rule);
foreach ($pages as $page) {
$page = preg_replace('/\\/%/', '', $page);
if ($translated_path == $page) {
$pages[1] = preg_replace('/\\/%/', '', $pages[1]);
$next_translated_path[$key] = $pages[1];
if (!empty($thank_you_id[1])) {
$next_translated_path[$key] = $pages[1] . "/" . $thank_you_id[1];
}
$next_translated_path[$key] = preg_replace("/\r|\n/", "", $next_translated_path[$key]);
break;
}
}
}
}
foreach ($next_translated_path as $key => $path) {
if ($path_alias === $path) {
$path_key = $key;
break;
}
if (!array_search($path_alias, $next_translated_path)) {
$path_alias = current($next_translated_path);
}
}
if ($path_key !== NULL) {
$path_alias = $next_translated_path[$path_key];
}
$rules = _pages_restriction_get_rules_by_path($path_alias);
foreach ($rules as $key => $rule) {
if (!isset($_SESSION['pages_restriction_id_session_' . $key])) {
// Start a custom session and define the useful information.
$session_id = uuid_generate();
_pages_restriction_debug_info(t('Session @session started on path @next_page_path'), array(
'@session' => $session_id,
'@next_page_path' => $next_page_path,
));
$_SESSION['pages_restriction_id_session_' . $key] = $session_id;
}
// Define Array containing cached data.
$data = array(
'id_session' => $_SESSION['pages_restriction_id_session_' . $key],
'next_page_path' => $next_translated_path[$path_key] != $path_alias ? $path_alias : $next_translated_path[$path_key],
'restrict_rules' => $key,
);
// Insert data to cache table.
if (!is_null($data)) {
db_merge('cache_pages_restriction')
->key(array(
'id_session' => $_SESSION['pages_restriction_id_session_' . $key],
'restrict_rules' => $key,
))
->fields($data)
->execute();
}
}
}