function kwresearch_parse_menu_item in Keyword Research 7
Same name and namespace in other branches
- 6 kwresearch.module \kwresearch_parse_menu_item()
@todo Please document this function.
See also
1 call to kwresearch_parse_menu_item()
- kwresearch_construct_pathnid_obj in ./
kwresearch.module - Creates an object with nid and path attributes based on if pid is a nid or path. Also validates that the path is valid.
File
- ./
kwresearch.module, line 1563
Code
function kwresearch_parse_menu_item(&$item, &$msgs = array()) {
if (!is_array($item)) {
$item = array(
'link_path' => $item,
);
}
// remove base_path if found
$regex = '/^' . str_replace('/', '\\/', base_path()) . '/';
$item['link_path'] = preg_replace($regex, '', $item['link_path']);
$item['external'] = 0;
$normal_path = drupal_get_normal_path($item['link_path']);
if ($item['link_path'] != $normal_path) {
$msgs[] = array(
'message' => t('Keyword Research stores system paths only, but will use the URL alias in links. %link_path has been stored as %normal_path', array(
'%link_path' => $item['link_path'],
'%normal_path' => $normal_path,
)),
'status' => 'status',
);
$item['link_path'] = $normal_path;
}
if (!url_is_external($item['link_path'])) {
$parsed_link = parse_url($item['link_path']);
if (isset($parsed_link['query'])) {
$item['options']['query'] = $parsed_link['query'];
}
else {
// Use unset() rather than setting to empty string
// to avoid redundant serialized data being stored.
unset($item['options']['query']);
}
if (isset($parsed_link['fragment'])) {
$item['options']['fragment'] = $parsed_link['fragment'];
}
else {
unset($item['options']['fragment']);
}
if ($item['link_path'] != $parsed_link['path']) {
$item['link_path'] = $parsed_link['path'];
}
list($n, $nid, $e) = explode('/', $normal_path);
if ($n == 'node' && is_numeric($nid)) {
$item['nid'] = (int) $nid;
}
}
else {
$item['external'] = 1;
}
if (!trim($item['link_path']) || !drupal_valid_path(preg_replace($regex, '', $item['link_path']))) {
$msgs[] = array(
'message' => t("The path '@link_path' is either invalid or you do not have access to it.", array(
'@link_path' => $item['link_path'],
)),
'status' => 'error',
'element' => 'link_path',
);
return FALSE;
}
return $item;
}