function bookmark_add($channel, $sender, $taxonomy, $private, $opts = null) { $menu_id = 0; $menu_name = ''; $ischat = false; if (is_array($opts)) { $menu_id = x($opts, 'menu_id') ? intval($opts['menu_id']) : 0; $menu_name = x($opts, 'menu_name') ? escape_tags($opts['menu_name']) : ''; $ischat = x($opts, 'ischat') ? intval($opts['ischat']) : 0; } $iarr = array(); $channel_id = $channel['channel_id']; if ($private) { $iarr['contact_allow'] = array($channel['channel_hash']); } $iarr['mitem_link'] = $taxonomy['url']; $iarr['mitem_desc'] = $taxonomy['term']; $iarr['mitem_flags'] = $ischat ? MENU_ITEM_CHATROOM : 0; require_once 'include/hubloc.php'; $zrl = is_matrix_url($taxonomy['url']); if ($zrl) { $iarr['mitem_flags'] |= MENU_ITEM_ZID; } $arr = array(); if (!$menu_name) { $arr['menu_name'] = substr($sender['xchan_hash'], 0, 16) . ' ' . $sender['xchan_name']; $arr['menu_desc'] = sprintf(t('%1$s\'s bookmarks'), $sender['xchan_name']); } else { $arr['menu_name'] = $arr['menu_desc'] = $menu_name; } $arr['menu_flags'] = $sender['xchan_hash'] === $channel['channel_hash'] ? MENU_BOOKMARK : MENU_SYSTEM | MENU_BOOKMARK; $arr['menu_channel_id'] = $channel_id; if (!$menu_id) { $x = menu_list($arr['menu_channel_id'], $arr['menu_name'], $arr['menu_flags']); if ($x) { $menu_id = $x[0]['menu_id']; } else { $menu_id = menu_create($arr); } } if (!$menu_id) { logger('bookmark_add: unable to create menu ' . $arr['menu_name']); return; } logger('add_bookmark: menu_id ' . $menu_id); $r = q("select * from menu_item where mitem_link = '%s' and mitem_menu_id = %d and mitem_channel_id = %d limit 1", dbesc($iarr['mitem_link']), intval($menu_id), intval($channel_id)); if ($r) { logger('add_bookmark: duplicate menu entry', LOGGER_DEBUG); } if (!$r) { $r = menu_add_item($menu_id, $channel_id, $iarr); } return $r; }
function mitem_post(&$a) { $uid = local_channel(); if ($a->is_sys && is_site_admin()) { $sys = get_sys_channel(); $uid = intval($sys['channel_id']); } if (!$uid) { return; } if (!$a->data['menu']) { return; } if (!$_REQUEST['mitem_desc'] || !$_REQUEST['mitem_link']) { notice(t('Unable to create element.') . EOL); return; } $_REQUEST['mitem_channel_id'] = $uid; $_REQUEST['menu_id'] = $a->data['menu']['menu_id']; $_REQUEST['mitem_flags'] = 0; if ($_REQUEST['usezid']) { $_REQUEST['mitem_flags'] |= MENU_ITEM_ZID; } if ($_REQUEST['newwin']) { $_REQUEST['mitem_flags'] |= MENU_ITEM_NEWWIN; } $mitem_id = argc() > 2 ? intval(argv(2)) : 0; if ($mitem_id) { $_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' : '')); } else { notice(t('Unable to update menu element.') . EOL); } } 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' : '')); } if ($_REQUEST['submit-more']) { goaway(z_root() . '/mitem/' . $_REQUEST['menu_id'] . '?f=&display=block' . ($a->is_sys ? '&sys=1' : '')); } } else { notice(t('Unable to add menu element.') . EOL); } } }
function mitem_post(&$a) { $uid = local_channel(); if ($a->is_sys && is_site_admin()) { $sys = get_sys_channel(); $uid = intval($sys['channel_id']); } if (!$uid) { return; } if (!$a->data['menu']) { return; } $channel = $a->get_channel(); $_REQUEST['mitem_channel_id'] = $uid; $_REQUEST['menu_id'] = $a->data['menu']['menu_id']; $_REQUEST['mitem_flags'] = 0; if ($_REQUEST['usezid']) { $_REQUEST['mitem_flags'] |= MENU_ITEM_ZID; } if ($_REQUEST['newwin']) { $_REQUEST['mitem_flags'] |= MENU_ITEM_NEWWIN; } $mitem_id = argc() > 2 ? intval(argv(2)) : 0; if ($mitem_id) { $_REQUEST['mitem_id'] = $mitem_id; $r = menu_edit_item($_REQUEST['menu_id'], $uid, $_REQUEST); if ($r) { info(t('Menu element updated.') . EOL); goaway(z_root() . '/mitem/' . $_REQUEST['menu_id'] . ($a->is_sys ? '?f=&sys=1' : '')); } else { notice(t('Unable to update menu element.') . EOL); } } else { $r = menu_add_item($_REQUEST['menu_id'], $uid, $_REQUEST); if ($r) { info(t('Menu element added.') . EOL); goaway(z_root() . '/mitem/' . $_REQUEST['menu_id'] . ($a->is_sys ? '?f=&sys=1' : '')); } else { notice(t('Unable to add menu element.') . EOL); } } }
function mitem_post(&$a) { if (!local_user()) { return; } if (!$a->data['menu']) { return; } $channel = $a->get_channel(); $_REQUEST['mitem_channel_id'] = local_user(); $_REQUEST['menu_id'] = $a->data['menu']['menu_id']; $_REQUEST['mitem_flags'] = 0; if ($_REQUEST['usezid']) { $_REQUEST['mitem_flags'] |= MENU_ITEM_ZID; } if ($_REQUEST['newwin']) { $_REQUEST['mitem_flags'] |= MENU_ITEM_NEWWIN; } $mitem_id = argc() > 2 ? intval(argv(2)) : 0; if ($mitem_id) { $_REQUEST['mitem_id'] = $mitem_id; $r = menu_edit_item($_REQUEST['menu_id'], local_user(), $_REQUEST); if ($r) { info(t('Menu element updated.') . EOL); goaway(z_root() . '/mitem/' . $_REQUEST['menu_id']); } else { notice(t('Unable to update menu element.') . EOL); } } else { $r = menu_add_item($_REQUEST['menu_id'], local_user(), $_REQUEST); if ($r) { info(t('Menu element added.') . EOL); goaway(z_root() . '/mitem/' . $_REQUEST['menu_id']); } else { notice(t('Unable to add menu element.') . EOL); } } }
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']; $m['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); } } } } } }
function impel_init(&$a) { $ret = array('success' => false); if (!local_channel()) { json_return_and_die($ret); } logger('impel: ' . print_r($_REQUEST, true), LOGGER_DATA); $elm = $_REQUEST['element']; $x = base64url_decode($elm); if (!$x) { json_return_and_die($ret); } $j = json_decode($x, true); if (!$j) { json_return_and_die($ret); } $channel = $a->get_channel(); $arr = array(); $is_menu = false; // a portable menu has its links rewritten with the local baseurl $portable_menu = false; switch ($j['type']) { case 'webpage': $arr['item_type'] = ITEM_TYPE_WEBPAGE; $namespace = 'WEBPAGE'; $installed_type = t('webpage'); break; case 'block': $arr['item_type'] = ITEM_TYPE_BLOCK; $namespace = 'BUILDBLOCK'; $installed_type = t('block'); break; case 'layout': $arr['item_type'] = ITEM_TYPE_PDL; $namespace = 'PDL'; $installed_type = t('layout'); break; case 'portable-menu': $portable_menu = true; // fall through // fall through case 'menu': $is_menu = true; $installed_type = t('menu'); break; default: logger('mod_impel: unrecognised element type' . print_r($j, true)); break; } if ($is_menu) { $m = array(); $m['menu_channel_id'] = local_channel(); $m['menu_name'] = $j['pagetitle']; $m['menu_desc'] = $j['desc']; if ($j['created']) { $m['menu_created'] = datetime_convert($j['created']); } if ($j['edited']) { $m['menu_edited'] = datetime_convert($j['edited']); } $m['menu_flags'] = 0; if ($j['flags']) { if (in_array('bookmark', $j['flags'])) { $m['menu_flags'] |= MENU_BOOKMARK; } if (in_array('system', $j['flags'])) { $m['menu_flags'] |= MENU_SYSTEM; } } $menu_id = menu_create($m); if ($menu_id) { if (is_array($j['items'])) { foreach ($j['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, local_channel(), $mitem); } if ($j['edited']) { $x = q("update menu set menu_edited = '%s' where menu_id = %d and menu_channel_id = %d", dbesc(datetime_convert('UTC', 'UTC', $j['edited'])), intval($menu_id), intval(local_channel())); } } $ret['success'] = true; } $x = $ret; } else { $arr['uid'] = local_channel(); $arr['aid'] = $channel['channel_account_id']; $arr['title'] = $j['title']; $arr['body'] = $j['body']; $arr['term'] = $j['term']; $arr['layout_mid'] = $j['layout_mid']; $arr['created'] = datetime_convert('UTC', 'UTC', $j['created']); $arr['edited'] = datetime_convert('UTC', 'UTC', $j['edited']); $arr['owner_xchan'] = get_observer_hash(); $arr['author_xchan'] = $j['author_xchan'] ? $j['author_xchan'] : get_observer_hash(); $arr['mimetype'] = $j['mimetype'] ? $j['mimetype'] : 'text/bbcode'; if (!$j['mid']) { $j['mid'] = item_message_id(); } $arr['mid'] = $arr['parent_mid'] = $j['mid']; if ($j['pagetitle']) { require_once 'library/urlify/URLify.php'; $pagetitle = strtolower(URLify::transliterate($j['pagetitle'])); } // Verify ability to use html or php!!! $execflag = false; if ($arr['mimetype'] === 'application/x-php') { $z = q("select account_id, account_roles, channel_pageflags from account left join channel on channel_account_id = account_id where channel_id = %d limit 1", intval(local_channel())); if ($z && ($z[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE || $z[0]['channel_pageflags'] & PAGE_ALLOWCODE)) { $execflag = true; } } $remote_id = 0; $z = q("select * from item_id where sid = '%s' and service = '%s' and uid = %d limit 1", dbesc($pagetitle), dbesc($namespace), intval(local_channel())); $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", dbesc($arr['mid']), intval(local_channel())); if ($z && $i) { $remote_id = $z[0]['id']; $arr['id'] = $i[0]['id']; // don't update if it has the same timestamp as the original if ($arr['edited'] > $i[0]['edited']) { $x = item_store_update($arr, $execflag); } } else { if ($i && intval($i[0]['item_deleted'])) { // was partially deleted already, finish it off q("delete from item where mid = '%s' and uid = %d", dbesc($arr['mid']), intval(local_channel())); } $x = item_store($arr, $execflag); } if ($x['success']) { $item_id = $x['item_id']; update_remote_id($channel, $item_id, $arr['item_type'], $pagetitle, $namespace, $remote_id, $arr['mid']); } } if ($x['success']) { $ret['success'] = true; info(sprintf(t('%s element installed'), $installed_type)); } else { notice(sprintf(t('%s element installation failed'), $installed_type)); } //??? should perhaps return ret? json_return_and_die(true); }