Ejemplo n.º 1
0
function api_statuses_update(&$a, $type)
{
    if (api_user() === false) {
        logger('api_statuses_update: no user');
        return false;
    }
    logger('api_statuses_update: REQUEST ' . print_r($_REQUEST, true));
    logger('api_statuses_update: FILES ' . print_r($_FILES, true));
    // set this so that the item_post() function is quiet and doesn't redirect or emit json
    $_REQUEST['api_source'] = true;
    $user_info = api_get_user($a);
    // convert $_POST array items to the form we use for web posts.
    // logger('api_post: ' . print_r($_POST,true));
    if (requestdata('htmlstatus')) {
        require_once 'library/HTMLPurifier.auto.php';
        require_once 'include/html2bbcode.php';
        $txt = requestdata('htmlstatus');
        if (strpos($txt, '<') !== false || strpos($txt, '>') !== false) {
            $txt = html2bb_video($txt);
            $config = HTMLPurifier_Config::createDefault();
            $config->set('Cache.DefinitionImpl', null);
            $purifier = new HTMLPurifier($config);
            $txt = $purifier->purify($txt);
        }
        $_REQUEST['body'] = html2bbcode($txt);
    } else {
        $_REQUEST['body'] = requestdata('status');
    }
    $parent = requestdata('in_reply_to_status_id');
    if (ctype_digit($parent)) {
        $_REQUEST['parent'] = $parent;
    } else {
        $_REQUEST['parent_mid'] = $parent;
    }
    if ($_REQUEST['namespace'] && $parent) {
        $x = q("select iid from item_id where service = '%s' and sid = '%s' limit 1", dbesc($_REQUEST['namespace']), dbesc($parent));
        if ($x) {
            $_REQUEST['parent'] = $x[0]['iid'];
        }
    }
    if (requestdata('lat') && requestdata('long')) {
        $_REQUEST['coord'] = sprintf("%s %s", requestdata('lat'), requestdata('long'));
    }
    $_REQUEST['profile_uid'] = api_user();
    if ($parent) {
        $_REQUEST['type'] = 'net-comment';
    } else {
        $_REQUEST['type'] = 'wall';
        if (x($_FILES, 'media')) {
            $_FILES['userfile'] = $_FILES['media'];
            // upload the image if we have one
            $_REQUEST['silent'] = '1';
            //tell wall_upload function to return img info instead of echo
            require_once 'mod/wall_attach.php';
            $media = wall_attach_post($a);
            if (strlen($media) > 0) {
                $_REQUEST['body'] .= "\n\n" . $media;
            }
        }
    }
    // call out normal post function
    require_once 'mod/item.php';
    item_post($a);
    // this should output the last post (the one we just posted).
    return api_status_show($a, $type);
}
Ejemplo n.º 2
0
function api_statuses_mediap(&$a, $type)
{
    if (api_user() === false) {
        logger('api_statuses_update: no user');
        return false;
    }
    $user_info = api_get_user($a);
    $_REQUEST['type'] = 'wall';
    $_REQUEST['profile_uid'] = api_user();
    $_REQUEST['api_source'] = true;
    $txt = requestdata('status');
    require_once 'library/HTMLPurifier.auto.php';
    require_once 'include/html2bbcode.php';
    if (strpos($txt, '<') !== false || strpos($txt, '>') !== false) {
        $txt = html2bb_video($txt);
        $config = HTMLPurifier_Config::createDefault();
        $config->set('Cache.DefinitionImpl', null);
        $purifier = new HTMLPurifier($config);
        $txt = $purifier->purify($txt);
    }
    $txt = html2bbcode($txt);
    $a->argv[1] = $user_info['screen_name'];
    $_REQUEST['silent'] = '1';
    //tell wall_upload function to return img info instead of echo
    require_once 'mod/wall_attach.php';
    $posted = wall_attach_post($a);
    //now that we have the img url in bbcode we can add it to the status and insert the wall item.
    $_REQUEST['body'] = $txt . "\n\n" . $posted;
    require_once 'mod/item.php';
    item_post($a);
    // this should output the last post (the one we just posted).
    return api_status_show($a, $type);
}