menu import and sync
This commit is contained in:
parent
c6bdf7e891
commit
75d521d42a
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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']);
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user