menu encoding for sharing/exchange

This commit is contained in:
redmatrix 2015-05-27 21:09:21 -07:00
parent 2dd02cc166
commit 12c17f1265
2 changed files with 43 additions and 0 deletions

View File

@ -24,6 +24,45 @@ function menu_fetch($name,$uid,$observer_xchan) {
return null;
}
function menu_element($menu) {
$arr = array();
$arr['type'] = 'menu';
$arr['name'] = $menu['menu_name'];
$arr['desc'] = $menu['menu_desc'];
$arr['baseurl'] = z_root();
if($menu['menu_flags']) {
$arr['flags'] = array();
if($menu['menu_flags'] & MENU_BOOKMARK)
$arr['flags'][] = 'bookmark';
if($menu['menu_flags'] & MENU_SYSTEM)
$arr['flags'][] = 'system';
}
if($menu['items']) {
$arr['items'] = array();
foreach($menu['items'] as $it) {
$entry = array();
$entry['link'] = str_replace(z_root(),'[baseurl]',$it['mitem_link']);
$entry['desc'] = $it['mitem_desc'];
$entry['order'] = $it['mitem_order'];
if($it['mitem_flags']) {
$entry['flags'] = array();
if($it['mitem_flags'] & MENU_ITEM_ZID)
$entry['flags'][] = 'zid';
if($it['mitem_flags'] & MENU_ITEM_NEWWIN)
$entry['flags'][] = 'new-window';
if($it['mitem_flags'] & MENU_ITEM_CHATROOM)
$entry['flags'][] = 'chatroom';
}
$arr['items'][] = $entry;
}
}
return $arr;
}
function menu_render($menu, $class='', $edit = false, $var = '') {
if(! $menu)

View File

@ -78,6 +78,10 @@ function menu_content(&$a) {
$x = menu_list($uid);
if($x) {
for($y = 0; $y < count($x); $y ++) {
$m = menu_fetch($x[$y]['menu_name'],$uid,get_observer_hash());
if($m)
$x[$y]['element'] = '[element]' . base64url_encode(json_encode(menu_element($m))) . '[/element]';
$x[$y]['bookmark'] = (($x[$y]['menu_flags'] & MENU_BOOKMARK) ? true : false);
}
}