示例#1
0
function thing_content(&$a)
{
    // @FIXME one problem with things is we can't share them unless we provide the channel in the url
    // so we can definitively lookup the owner.
    if (argc() == 2) {
        $r = q("select obj_channel from obj where obj_type = %d and obj_obj = '%s' limit 1", intval(TERM_OBJ_THING), dbesc(argv(1)));
        if ($r) {
            $sql_extra = permissions_sql($r[0]['obj_channel']);
        }
        $r = q("select * from obj where obj_type = %d and obj_obj = '%s' {$sql_extra} limit 1", intval(TERM_OBJ_THING), dbesc(argv(1)));
        if ($r) {
            return replace_macros(get_markup_template('show_thing.tpl'), array('$header' => t('Show Thing'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$canedit' => local_channel() && local_channel() == $r[0]['obj_channel'] ? true : false, '$thing' => $r[0]));
        } else {
            notice(t('item not found.') . EOL);
            return;
        }
    }
    $channel = App::get_channel();
    if (!(local_channel() && $channel)) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $acl = new Zotlabs\Access\AccessList($channel);
    $channel_acl = $acl->get();
    $lockstate = $acl->is_private() ? 'lock' : 'unlock';
    $thing_hash = '';
    if (argc() == 3 && argv(1) === 'edit') {
        $thing_hash = argv(2);
        $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1", intval(TERM_OBJ_THING), dbesc($thing_hash));
        if (!$r || $r[0]['obj_channel'] != local_channel()) {
            notice(t('Permission denied.') . EOL);
            return '';
        }
        $o .= replace_macros(get_markup_template('thing_edit.tpl'), array('$thing_hdr' => t('Edit Thing'), '$multiprof' => feature_enabled(local_channel(), 'multi_profiles'), '$profile_lbl' => t('Select a profile'), '$profile_select' => contact_profile_assign($r[0]['obj_page']), '$verb_lbl' => $channel['channel_name'], '$verb_select' => obj_verb_selector($r[0]['obj_verb']), '$activity' => array('activity', t('Post an activity'), true, t('Only sends to viewers of the applicable profile')), '$thing_hash' => $thing_hash, '$thing_lbl' => t('Name of thing e.g. something'), '$thething' => $r[0]['obj_term'], '$url_lbl' => t('URL of thing (optional)'), '$theurl' => $r[0]['obj_url'], '$img_lbl' => t('URL for photo of thing (optional)'), '$imgurl' => $r[0]['obj_imgurl'], '$permissions' => t('Permissions'), '$aclselect' => populate_acl($channel_acl, false), '$lockstate' => $lockstate, '$submit' => t('Submit')));
        return $o;
    }
    if (argc() == 3 && argv(1) === 'drop') {
        $thing_hash = argv(2);
        $r = q("select * from obj where obj_type = %d and obj_obj = '%s' limit 1", intval(TERM_OBJ_THING), dbesc($thing_hash));
        if (!$r || $r[0]['obj_channel'] != local_channel()) {
            notice(t('Permission denied.') . EOL);
            return '';
        }
        $x = q("delete from obj where obj_obj = '%s' and obj_type = %d and obj_channel = %d", dbesc($thing_hash), intval(TERM_OBJ_THING), intval(local_channel()));
        $r[0]['obj_deleted'] = 1;
        build_sync_packet(0, array('obj' => $r));
        return $o;
    }
    $o .= replace_macros(get_markup_template('thing_input.tpl'), array('$thing_hdr' => t('Add Thing to your Profile'), '$multiprof' => feature_enabled(local_channel(), 'multi_profiles'), '$profile_lbl' => t('Select a profile'), '$profile_select' => contact_profile_assign(''), '$verb_lbl' => $channel['channel_name'], '$activity' => array('activity', t('Post an activity'), array_key_exists('activity', $_REQUEST) ? $_REQUEST['activity'] : true, t('Only sends to viewers of the applicable profile')), '$verb_select' => obj_verb_selector(), '$thing_lbl' => t('Name of thing e.g. something'), '$url_lbl' => t('URL of thing (optional)'), '$img_lbl' => t('URL for photo of thing (optional)'), '$permissions' => t('Permissions'), '$aclselect' => populate_acl($channel_acl, false), '$lockstate' => $lockstate, '$submit' => t('Submit')));
    return $o;
}
示例#2
0
文件: thing.php 项目: redmatrix/red
function thing_content(&$a)
{
    if (argc() == 2) {
        $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", intval(TERM_OBJ_THING), dbesc(argv(1)));
        if ($r) {
            return replace_macros(get_markup_template('show_thing.tpl'), array('$header' => t('Show Thing'), '$edit' => t('Edit'), '$delete' => t('Delete'), '$canedit' => local_channel() && local_channel() == $r[0]['obj_channel'] ? true : false, '$thing' => $r[0]));
        } else {
            notice(t('item not found.') . EOL);
            return;
        }
    }
    $channel = $a->get_channel();
    if (!(local_channel() && $channel)) {
        notice(t('Permission denied.') . EOL);
        return;
    }
    $thing_hash = '';
    if (argc() == 3 && argv(1) === 'edit') {
        $thing_hash = argv(2);
        $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", intval(TERM_OBJ_THING), dbesc($thing_hash));
        if (!$r || $r[0]['obj_channel'] != local_channel()) {
            notice(t('Permission denied.') . EOL);
            return '';
        }
        $o .= replace_macros(get_markup_template('thing_edit.tpl'), array('$thing_hdr' => t('Edit Thing'), '$multiprof' => feature_enabled(local_channel(), 'multi_profiles'), '$profile_lbl' => t('Select a profile'), '$profile_select' => contact_profile_assign($r[0]['obj_page']), '$verb_lbl' => $channel['channel_name'], '$verb_select' => obj_verb_selector($r[0]['obj_verb']), '$activity' => array('activity', t('Post an activity'), true, t('Only sends to viewers of the applicable profile')), '$thing_hash' => $thing_hash, '$thing_lbl' => t('Name of thing e.g. something'), '$thething' => $r[0]['term'], '$url_lbl' => t('URL of thing (optional)'), '$theurl' => $r[0]['url'], '$img_lbl' => t('URL for photo of thing (optional)'), '$imgurl' => $r[0]['imgurl'], '$submit' => t('Submit')));
        return $o;
    }
    if (argc() == 3 && argv(1) === 'drop') {
        $thing_hash = argv(2);
        $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_type = %d and term_hash = '%s' limit 1", intval(TERM_OBJ_THING), dbesc($thing_hash));
        if (!$r || $r[0]['obj_channel'] != local_channel()) {
            notice(t('Permission denied.') . EOL);
            return '';
        }
        $x = q("delete from obj where obj_obj = '%s' and obj_type = %d and obj_channel = %d", dbesc($thing_hash), intval(TERM_OBJ_THING), intval(local_channel()));
        $x = q("delete from term where term_hash = '%s' and uid = %d", dbesc($thing_hash), intval(local_channel()));
        return $o;
    }
    $o .= replace_macros(get_markup_template('thing_input.tpl'), array('$thing_hdr' => t('Add Thing to your Profile'), '$multiprof' => feature_enabled(local_channel(), 'multi_profiles'), '$profile_lbl' => t('Select a profile'), '$profile_select' => contact_profile_assign(''), '$verb_lbl' => $channel['channel_name'], '$activity' => array('activity', t('Post an activity'), array_key_exists('activity', $_REQUEST) ? $_REQUEST['activity'] : true, t('Only sends to viewers of the applicable profile')), '$verb_select' => obj_verb_selector(), '$thing_lbl' => t('Name of thing e.g. something'), '$url_lbl' => t('URL of thing (optional)'), '$img_lbl' => t('URL for photo of thing (optional)'), '$submit' => t('Submit')));
    return $o;
}