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 | |
parent | c6bdf7e891f3c0b49a1e9c40622e05aef590e2b6 (diff) | |
download | volse-hubzilla-75d521d42affbafa34e87752deeb1961367de1d5.tar.gz volse-hubzilla-75d521d42affbafa34e87752deeb1961367de1d5.tar.bz2 volse-hubzilla-75d521d42affbafa34e87752deeb1961367de1d5.zip |
menu import and sync
-rw-r--r-- | include/Import/import_diaspora.php | 5 | ||||
-rw-r--r-- | include/identity.php | 11 | ||||
-rw-r--r-- | include/import.php | 124 | ||||
-rw-r--r-- | include/menu.php | 13 | ||||
-rw-r--r-- | include/zot.php | 3 | ||||
-rw-r--r-- | mod/import.php | 3 | ||||
-rw-r--r-- | mod/menu.php | 8 | ||||
-rw-r--r-- | mod/mitem.php | 3 |
8 files changed, 167 insertions, 3 deletions
diff --git a/include/Import/import_diaspora.php b/include/Import/import_diaspora.php index fca9fa4f2..a0f473b50 100644 --- a/include/Import/import_diaspora.php +++ b/include/Import/import_diaspora.php @@ -57,6 +57,10 @@ function import_diaspora($data) { $channel_id = $c['channel']['channel_id']; + // Hubzilla only: Turn on the Diaspora protocol so that follow requests will be sent. + + set_pconfig($channel_id,'system','diaspora_allowed','1'); + // todo - add auto follow settings, (and strip exif in hubzilla) $location = escape_tags($data['user']['profile']['location']); @@ -70,7 +74,6 @@ function import_diaspora($data) { ); if($data['user']['profile']['nsfw']) { - // fixme for hubzilla which doesn't use pageflags any more q("update channel set channel_pageflags = (channel_pageflags | %d) where channel_id = %d", intval(PAGE_ADULT), intval($channel_id) diff --git a/include/identity.php b/include/identity.php index 211832d51..f68b1fe4a 100644 --- a/include/identity.php +++ b/include/identity.php @@ -5,6 +5,7 @@ require_once('include/zot.php'); require_once('include/crypto.php'); +require_once('include/menu.php'); /** @@ -595,6 +596,16 @@ function identity_basic_export($channel_id, $items = false) { foreach($r as $rr) $ret['event_item'][] = encode_item($rr,true); } + + $x = menu_list($channel_id); + if($x) { + $ret['menu'] = array(); + for($y = 0; $y < count($x); $y ++) { + $m = menu_fetch($x[$y]['menu_name'],$channel_id,$ret['channel']['channel_hash']); + if($m) + $ret['menu'][] = menu_element($m); + } + } if(! $items) 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); + } + } + } + } + } +} diff --git a/include/menu.php b/include/menu.php index 7ed931a59..32d8630a6 100644 --- a/include/menu.php +++ b/include/menu.php @@ -6,7 +6,7 @@ require_once('include/bbcode.php'); function menu_fetch($name,$uid,$observer_xchan) { - $sql_options = permissions_sql($uid); + $sql_options = permissions_sql($uid,$observer_xchan); $r = q("select * from menu where menu_channel_id = %d and menu_name = '%s' limit 1", intval($uid), @@ -388,3 +388,14 @@ function menu_del_item($menu_id,$uid,$item_id) { return $r; } +function menu_sync_packet($uid,$observer_hash,$menu_id,$delete = false) { + $r = menu_fetch_id($menu_id,$uid); + if($r) { + $m = menu_fetch($r[0]['menu_name'],$uid,$observer_hash); + if($m) { + if($delete) + $m['menu_delete'] = 1; + build_sync_packet($uid,array('menu' => array(menu_element($m)))); + } + } +} diff --git a/include/zot.php b/include/zot.php index 285668209..9fac4d40e 100644 --- a/include/zot.php +++ b/include/zot.php @@ -2896,6 +2896,9 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) { if(array_key_exists('item_id',$arr) && $arr['item_id']) sync_items($channel,$arr['item_id']); + if(array_key_exists('menu',$arr) && $arr['menu']) + sync_menus($channel,$arr['menu']); + if(array_key_exists('channel',$arr) && is_array($arr['channel']) && count($arr['channel'])) { if(array_key_exists('channel_page_flags',$arr['channel']) && intval($arr['channel']['channel_pageflags'])) { $arr['channel']['channel_removed'] = (($arr['channel']['channel_pageflags'] & 0x8000) ? 1 : 0); diff --git a/mod/import.php b/mod/import.php index 27c2094c3..0e43d2444 100644 --- a/mod/import.php +++ b/mod/import.php @@ -443,6 +443,9 @@ function import_post(&$a) { if(is_array($data['event_item'])) import_items($channel,$data['event_item']); + + if(is_array($data['menu'])) + import_menus($channel,$data['menu']); $saved_notification_flags = notifications_off($channel['channel_id']); diff --git a/mod/menu.php b/mod/menu.php index 7763c4ed1..bfc45adef 100644 --- a/mod/menu.php +++ b/mod/menu.php @@ -37,6 +37,7 @@ function menu_post(&$a) { $_REQUEST['menu_id'] = intval(argv(1)); $r = menu_edit($_REQUEST); if($r) { + menu_sync_packet($uid,get_observer_hash(),$menu_id); //info( t('Menu updated.') . EOL); goaway(z_root() . '/mitem/' . $menu_id . (($a->is_sys) ? '?f=&sys=1' : '')); } @@ -45,7 +46,9 @@ function menu_post(&$a) { } else { $r = menu_create($_REQUEST); - if($r) { + if($r) { + menu_sync_packet($uid,get_observer_hash(),$r); + //info( t('Menu created.') . EOL); goaway(z_root() . '/mitem/' . $r . (($a->is_sys) ? '?f=&sys=1' : '')); } @@ -56,6 +59,8 @@ function menu_post(&$a) { } + + function menu_content(&$a) { $uid = local_channel(); @@ -121,6 +126,7 @@ function menu_content(&$a) { if(intval(argv(1))) { if(argc() == 3 && argv(2) == 'drop') { + menu_sync_packet($uid,get_observer_hash(),intval(argv(1)),true); $r = menu_delete_id(intval(argv(1)),$uid); if(!$r) notice( t('Menu could not be deleted.'). EOL); diff --git a/mod/mitem.php b/mod/mitem.php index 0fadd1548..0c3f83bdd 100644 --- a/mod/mitem.php +++ b/mod/mitem.php @@ -64,6 +64,7 @@ function mitem_post(&$a) { $_REQUEST['mitem_id'] = $mitem_id; $r = menu_edit_item($_REQUEST['menu_id'],$uid,$_REQUEST); if($r) { + menu_sync_packet($uid,get_observer_hash(),$_REQUEST['menu_id']); //info( t('Menu element updated.') . EOL); goaway(z_root() . '/mitem/' . $_REQUEST['menu_id'] . (($a->is_sys) ? '?f=&sys=1' : '')); } @@ -74,6 +75,7 @@ function mitem_post(&$a) { else { $r = menu_add_item($_REQUEST['menu_id'],$uid,$_REQUEST); if($r) { + menu_sync_packet($uid,get_observer_hash(),$_REQUEST['menu_id']); //info( t('Menu element added.') . EOL); if($_REQUEST['submit']) { goaway(z_root() . '/menu' . (($a->is_sys) ? '?f=&sys=1' : '')); @@ -203,6 +205,7 @@ function mitem_content(&$a) { if(argc() == 4 && argv(3) == 'drop') { $r = menu_del_item($mitem['mitem_menu_id'], $uid, intval(argv(2))); + menu_sync_packet($uid,get_observer_hash(),$mitem['mitem_menu_id']); if($r) info( t('Menu item deleted.') . EOL); else |