diff options
author | redmatrix <redmatrix@redmatrix.me> | 2015-09-08 17:51:48 -0700 |
---|---|---|
committer | redmatrix <redmatrix@redmatrix.me> | 2015-09-08 17:52:39 -0700 |
commit | 75d521d42affbafa34e87752deeb1961367de1d5 (patch) | |
tree | ae068699ab0372837d35f73146745accb6f0ce2d /include/import.php | |
parent | c6bdf7e891f3c0b49a1e9c40622e05aef590e2b6 (diff) | |
download | volse-hubzilla-75d521d42affbafa34e87752deeb1961367de1d5.tar.gz volse-hubzilla-75d521d42affbafa34e87752deeb1961367de1d5.tar.bz2 volse-hubzilla-75d521d42affbafa34e87752deeb1961367de1d5.zip |
menu import and sync
Diffstat (limited to 'include/import.php')
-rw-r--r-- | include/import.php | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/include/import.php b/include/import.php index 616ee4987..7b2f574d9 100644 --- a/include/import.php +++ b/include/import.php @@ -1,5 +1,6 @@ <?php +require_once('include/menu.php'); function import_channel($channel) { @@ -616,7 +617,130 @@ function sync_events($channel,$events) { } +function import_menus($channel,$menus) { + if($channel && $menus) { + foreach($menus as $menu) { + $m = array(); + $m['menu_channel_id'] = $channel['channel_id']; + $m['menu_name'] = $menu['pagetitle']; + $m['menu_desc'] = $menu['desc']; + if($menu['created']) + $m['menu_created'] = datetime_convert($menu['created']); + if($menu['edited']) + $m['menu_edited'] = datetime_convert($menu['edited']); + + $m['menu_flags'] = 0; + if($menu['flags']) { + if(in_array('bookmark',$menu['flags'])) + $m['menu_flags'] |= MENU_BOOKMARK; + if(in_array('system',$menu['flags'])) + $m['menu_flags'] |= MENU_SYSTEM; + + } + + $menu_id = menu_create($m); + + if($menu_id) { + if(is_array($menu['items'])) { + foreach($menu['items'] as $it) { + $mitem = array(); + + $mitem['mitem_link'] = str_replace('[baseurl]',z_root(),$it['link']); + $mitem['mitem_desc'] = escape_tags($it['desc']); + $mitem['mitem_order'] = intval($it['order']); + if(is_array($it['flags'])) { + $mitem['mitem_flags'] = 0; + if(in_array('zid',$it['flags'])) + $mitem['mitem_flags'] |= MENU_ITEM_ZID; + if(in_array('new-window',$it['flags'])) + $mitem['mitem_flags'] |= MENU_ITEM_NEWWIN; + if(in_array('chatroom',$it['flags'])) + $mitem['mitem_flags'] |= MENU_ITEM_CHATROOM; + } + menu_add_item($menu_id,$channel['channel_id'],$mitem); + } + } + } + } + } +} + + +function sync_menus($channel,$menus) { + + if($channel && $menus) { + foreach($menus as $menu) { + $m = array(); + $m['menu_channel_id'] = $channel['channel_id']; + $m['menu_name'] = $menu['pagetitle']; + $m['menu_desc'] = $menu['desc']; + if($menu['created']) + $m['menu_created'] = datetime_convert($menu['created']); + if($menu['edited']) + $m['menu_edited'] = datetime_convert($menu['edited']); + + $m['menu_flags'] = 0; + if($menu['flags']) { + if(in_array('bookmark',$menu['flags'])) + $m['menu_flags'] |= MENU_BOOKMARK; + if(in_array('system',$menu['flags'])) + $m['menu_flags'] |= MENU_SYSTEM; + + } + + $editing = false; + $r = q("select * from menu where menu_name = '%s' and menu_channel_id = %d limit 1", + dbesc($m['menu_name']), + intval($channel['channel_id']) + ); + if($r) { + if($r[0]['menu_edited'] >= $m['menu_edited']) + continue; + if($menu['menu_deleted']) { + menu_delete_id($r[0]['menu_id'],$channel['channel_id']); + continue; + } + $menu_id = $r[0]['menu_id']; + $x = menu_edit($m); + if(! $x) + continue; + $editing = true; + } + if(! $editing) { + $menu_id = menu_create($m); + } + if($menu_id) { + if($editing) { + // don't try syncing - just delete all the entries and start over + q("delete from menu_item where mitem_menu_id = %d", + intval($menu_id) + ); + } + + if(is_array($menu['items'])) { + foreach($menu['items'] as $it) { + $mitem = array(); + + $mitem['mitem_link'] = str_replace('[baseurl]',z_root(),$it['link']); + $mitem['mitem_desc'] = escape_tags($it['desc']); + $mitem['mitem_order'] = intval($it['order']); + if(is_array($it['flags'])) { + $mitem['mitem_flags'] = 0; + if(in_array('zid',$it['flags'])) + $mitem['mitem_flags'] |= MENU_ITEM_ZID; + if(in_array('new-window',$it['flags'])) + $mitem['mitem_flags'] |= MENU_ITEM_NEWWIN; + if(in_array('chatroom',$it['flags'])) + $mitem['mitem_flags'] |= MENU_ITEM_CHATROOM; + } + menu_add_item($menu_id,$channel['channel_id'],$mitem); + } + } + } + } + } +} |