function om_maximenu_import_submit in OM Maximenu 8
Same name and namespace in other branches
- 6 inc/om_maximenu.import.inc \om_maximenu_import_submit()
- 7 inc/om_maximenu.import.inc \om_maximenu_import_submit()
Import from existing menus
File
- inc/
om_maximenu.import.inc, line 118 - OM Maximenu Import
Code
function om_maximenu_import_submit($form, $form_state) {
global $_om_maximenu_variable;
$om_maximenu = $_om_maximenu_variable;
if (!empty($om_maximenu)) {
// check for existing imported menus
foreach ($om_maximenu as $menu_id => $content) {
$codes[] = $content['code'];
}
}
else {
$codes = array();
}
// New menu and links
// new ids relies on highest menu key id
// adding only 1 new blank menu
$menu_id = !empty($om_maximenu) ? max(array_keys($om_maximenu)) + 1 : 1;
$menus = $form_state['values']['om_import']['menus'];
$import = array();
foreach ($menus as $menu => $select) {
$mlid = $select['mlid'];
$menu_list = explode(',', $select['menu_list']);
if (is_numeric($mlid)) {
// getting existing menus
$link = db_query("SELECT link_title, has_children FROM {menu_links} WHERE mlid = :mlid", array(
':mlid' => $mlid,
))
->fetchObject();
if ($link->has_children) {
$result = db_query("SELECT mlid, plid, link_path, link_title, options, weight FROM {menu_links} WHERE hidden = 0 AND plid = :plid AND TRIM(link_title) > '' ORDER BY p1, p2, p3, p4, p5, p6, p7, p8, p9, plid, mlid, link_title ASC", array(
':plid' => $mlid,
));
}
else {
$result = db_query("SELECT mlid, link_path, link_title, options, weight FROM {menu_links} WHERE hidden = 0 AND mlid = :mlid", array(
':mlid' => $mlid,
));
}
$menu = strtolower(preg_replace('/ /', '-', $link->link_title));
$menu_title = $link->link_title;
}
elseif (is_string($mlid)) {
$result = db_query("SELECT mlid, plid, link_path, link_title, options, weight FROM {menu_links} WHERE hidden = 0 AND menu_name = :menu_name AND TRIM(link_title) > '' ORDER BY p1, p2, p3, p4, p5, p6, p7, p8, p9, plid, mlid, link_title ASC", array(
':menu_name' => $mlid,
));
$menu_title = ucwords(preg_replace('/-/', ' ', $menu));
}
else {
// do nothing
}
if (!empty($mlid) && !in_array($menu . '-imported', $codes) && !empty($menu_title)) {
$import = array(
'code' => $menu . '-imported',
'title' => $menu_title,
'action' => 'hover',
'skin' => 'bubble',
'tabbed' => '',
'output' => 'block',
);
$import['output'] = 'block';
$import['block_options'] = array(
'stacking' => 'horizontal',
'direction' => 'left',
'region' => '',
'weight' => 0,
'region' => '',
);
$import['menu_visibility'] = array(
'visibility' => 0,
'pages' => '',
);
// because we are handling the visibility, etc., we have to handle everything to synch with blocks settings
om_maximenu_update_blocks_db($menu_id, $import);
while ($record = $result
->fetchObject()) {
if (isset($record->link_title) && !empty($record->link_title) && in_array($record->mlid, $menu_list)) {
// this transforms paths with %
$path = menu_link_load($record->mlid);
//$path = menu_link_get_preferred($path['href']);
// this will get the path alias if available
$alias = drupal_get_path_alias($path['href']);
$path = $alias ? $alias : $path['href'];
$options = unserialize($record->options);
$import['links'][$record->mlid] = array(
'link_title' => $record->link_title,
'link_title_option' => 'title',
'path_icon' => '',
'icon_option' => 0,
'php_option' => 0,
//'path' => $record->link_path,
'path' => $path,
'weight' => $record->weight,
'id' => isset($options['attributes']['id']) ? $options['attributes']['id'] : '',
'class' => isset($options['attributes']['class']) ? $options['attributes']['class'] : '',
'rel' => isset($options['attributes']['rel']) ? $options['attributes']['rel'] : '',
'target' => isset($options['attributes']['target']) ? $options['attributes']['target'] : '_self',
'description' => isset($options['attributes']['title']) ? $options['attributes']['title'] : '',
'description_option' => 'hover',
'roles' => array(
1 => 0,
2 => 0,
),
'content' => '',
);
}
}
drupal_set_message(t($menu_title . ' has been imported.'));
$om_maximenu[$menu_id] = $import;
$menu_id++;
}
}
if (module_exists('taxonomy') && isset($form_state['values']['om_import']['vocabularies'])) {
global $_om_maximenu_existing_terms;
$terms = $_om_maximenu_existing_terms;
// taxonomy terms as menus
$vocabularies = $form_state['values']['om_import']['vocabularies'];
$import = array();
foreach ($vocabularies as $voc_id => $voc) {
$enabled = $voc['enabled'];
if ($enabled) {
$voc_list = $voc['voc_list'];
$voc_title = $voc_list[$voc_id];
$code = 'taxonomy-' . $voc_id;
if (!in_array($code . '-imported', $codes)) {
$import = array(
'code' => $code . '-imported',
'title' => $voc_title,
'action' => 'hover',
'skin' => 'bubble',
'output' => 'block',
);
$import['output'] = 'block';
$import['block_options'] = array(
'stacking' => 'horizontal',
'direction' => 'left',
'region' => '',
'weight' => 0,
'region' => '',
);
$import['menu_visibility'] = array(
'visibility' => 0,
'pages' => '',
);
// because we are handling the visibility, etc., we have to handle everything to synch with blocks settings
om_maximenu_update_blocks_db($voc_id, $import);
foreach ($terms[$voc_id] as $term_id => $term) {
$path = 'taxonomy/term/' . $term_id;
// this will get the path alias if available
$alias = drupal_get_path_alias($path);
$path = $alias ? $alias : $path;
$import['links'][$term_id] = array(
'link_title' => $term['term'],
'link_title_option' => 'title',
'path_icon' => '',
'icon_option' => 0,
'php_option' => 0,
'path' => $path,
'weight' => $term['weight'],
'id' => '',
'class' => '',
'rel' => '',
'target' => '_self',
'description' => $term['description'],
'description_option' => 'hover',
'roles' => array(
1 => 0,
2 => 0,
),
'content' => '',
);
}
}
drupal_set_message(t($voc_title . ' has been imported.'));
$om_maximenu[$menu_id] = $import;
$menu_id++;
}
}
}
// Save all settings in 1 variable
variable_set('om_maximenu', $om_maximenu);
}