Exemplo 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);
}
Exemplo n.º 2
0
function api_statuses_update(&$a, $type)
{
    if (api_user() === false) {
        logger('api_statuses_update: no user');
        return false;
    }
    $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')) {
        $txt = requestdata('htmlstatus');
        if (strpos($txt, '<') !== false || strpos($txt, '>') !== false) {
            require_once 'library/HTMLPurifier.auto.php';
            $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');
    }
    $_REQUEST['title'] = requestdata('title');
    $parent = requestdata('in_reply_to_status_id');
    // Twidere sends "-1" if it is no reply ...
    if ($parent == -1) {
        $parent = "";
    }
    if (ctype_digit($parent)) {
        $_REQUEST['parent'] = $parent;
    } else {
        $_REQUEST['parent_uri'] = $parent;
    }
    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 {
        // Check for throttling (maximum posts per day, week and month)
        $throttle_day = get_config('system', 'throttle_limit_day');
        if ($throttle_day > 0) {
            $datefrom = date("Y-m-d H:i:s", time() - 24 * 60 * 60);
            $r = q("SELECT COUNT(*) AS `posts_day` FROM `item` WHERE `uid`=%d AND `wall`\n\t\t\t\t\tAND `created` > '%s' AND `id` = `parent`", intval(api_user()), dbesc($datefrom));
            if ($r) {
                $posts_day = $r[0]["posts_day"];
            } else {
                $posts_day = 0;
            }
            if ($posts_day > $throttle_day) {
                logger('Daily posting limit reached for user ' . api_user(), LOGGER_DEBUG);
                die(api_error($a, $type, sprintf(t("Daily posting limit of %d posts reached. The post was rejected."), $throttle_day)));
            }
        }
        $throttle_week = get_config('system', 'throttle_limit_week');
        if ($throttle_week > 0) {
            $datefrom = date("Y-m-d H:i:s", time() - 24 * 60 * 60 * 7);
            $r = q("SELECT COUNT(*) AS `posts_week` FROM `item` WHERE `uid`=%d AND `wall`\n\t\t\t\t\tAND `created` > '%s' AND `id` = `parent`", intval(api_user()), dbesc($datefrom));
            if ($r) {
                $posts_week = $r[0]["posts_week"];
            } else {
                $posts_week = 0;
            }
            if ($posts_week > $throttle_week) {
                logger('Weekly posting limit reached for user ' . api_user(), LOGGER_DEBUG);
                die(api_error($a, $type, sprintf(t("Weekly posting limit of %d posts reached. The post was rejected."), $throttle_week)));
            }
        }
        $throttle_month = get_config('system', 'throttle_limit_month');
        if ($throttle_month > 0) {
            $datefrom = date("Y-m-d H:i:s", time() - 24 * 60 * 60 * 30);
            $r = q("SELECT COUNT(*) AS `posts_month` FROM `item` WHERE `uid`=%d AND `wall`\n\t\t\t\t\tAND `created` > '%s' AND `id` = `parent`", intval(api_user()), dbesc($datefrom));
            if ($r) {
                $posts_month = $r[0]["posts_month"];
            } else {
                $posts_month = 0;
            }
            if ($posts_month > $throttle_month) {
                logger('Monthly posting limit reached for user ' . api_user(), LOGGER_DEBUG);
                die(api_error($a, $type, sprintf(t("Monthly posting limit of %d posts reached. The post was rejected."), $throttle_month)));
            }
        }
        $_REQUEST['type'] = 'wall';
    }
    if (x($_FILES, 'media')) {
        // upload the image if we have one
        $_REQUEST['hush'] = 'yeah';
        //tell wall_upload function to return img info instead of echo
        $media = wall_upload_post($a);
        if (strlen($media) > 0) {
            $_REQUEST['body'] .= "\n\n" . $media;
        }
    }
    // To-Do: Multiple IDs
    if (requestdata('media_ids')) {
        $r = q("SELECT `resource-id`, `scale`, `nickname`, `type` FROM `photo` INNER JOIN `user` ON `user`.`uid` = `photo`.`uid` WHERE `resource-id` IN (SELECT `resource-id` FROM `photo` WHERE `id` = %d) AND `scale` > 0 AND `photo`.`uid` = %d ORDER BY `photo`.`width` DESC LIMIT 1", intval(requestdata('media_ids')), api_user());
        if ($r) {
            $phototypes = Photo::supportedTypes();
            $ext = $phototypes[$r[0]['type']];
            $_REQUEST['body'] .= "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']';
            $_REQUEST['body'] .= '[img]' . $a->get_baseurl() . "/photo/" . $r[0]['resource-id'] . "-" . $r[0]['scale'] . "." . $ext . "[/img][/url]";
        }
    }
    // set this so that the item_post() function is quiet and doesn't redirect or emit json
    $_REQUEST['api_source'] = true;
    if (!x($_REQUEST, "source")) {
        $_REQUEST["source"] = api_source();
    }
    // call out normal post function
    item_post($a);
    // this should output the last post (the one we just posted).
    return api_status_show($a, $type);
}
Exemplo n.º 3
0
function api_statuses_update(&$a, $type)
{
    if (api_user() === false) {
        logger('api_statuses_update: no user');
        return false;
    }
    $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');
    }
    $_REQUEST['title'] = requestdata('title');
    $parent = requestdata('in_reply_to_status_id');
    if (ctype_digit($parent)) {
        $_REQUEST['parent'] = $parent;
    } else {
        $_REQUEST['parent_uri'] = $parent;
    }
    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 {
        //			logger("api_statuses_update: upload ".print_r($_FILES, true)." ".print_r($_POST, true)." ".print_r($_GET, true), LOGGER_DEBUG);
        //die("blubb");
        $_REQUEST['type'] = 'wall';
        if (x($_FILES, 'media')) {
            // upload the image if we have one
            $_REQUEST['hush'] = 'yeah';
            //tell wall_upload function to return img info instead of echo
            require_once 'mod/wall_upload.php';
            $media = wall_upload_post($a);
            if (strlen($media) > 0) {
                $_REQUEST['body'] .= "\n\n" . $media;
            }
        }
    }
    // set this so that the item_post() function is quiet and doesn't redirect or emit json
    $_REQUEST['api_source'] = true;
    // 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);
}
Exemplo n.º 4
0
function api_statuses_update(&$a, $type)
{
    if (local_user() === false) {
        return false;
    }
    $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);
            $_POST['body'] = html2bbcode($txt);
        }
    } else {
        $_POST['body'] = urldecode(requestdata('status'));
    }
    $parent = requestdata('in_reply_to_status_id');
    if (ctype_digit($parent)) {
        $_POST['parent'] = $parent;
    } else {
        $_POST['parent_uri'] = $parent;
    }
    if (requestdata('lat') && requestdata('long')) {
        $_POST['coord'] = sprintf("%s %s", requestdata('lat'), requestdata('long'));
    }
    $_POST['profile_uid'] = local_user();
    if (requestdata('parent')) {
        $_POST['type'] = 'net-comment';
    } else {
        $_POST['type'] = 'wall';
    }
    // set this so that the item_post() function is quiet and doesn't redirect or emit json
    $_POST['api_source'] = true;
    // 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);
}
Exemplo n.º 5
0
function api_statuses_update(&$a, $type)
{
    if (api_user() === false) {
        logger('api_statuses_update: no user');
        return false;
    }
    $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');
    }
    $_REQUEST['title'] = requestdata('title');
    $parent = requestdata('in_reply_to_status_id');
    if (ctype_digit($parent)) {
        $_REQUEST['parent'] = $parent;
    } else {
        $_REQUEST['parent_uri'] = $parent;
    }
    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 {
        // Check for throttling (maximum posts per day, week and month)
        $throttle_day = get_config('system', 'throttle_limit_day');
        if ($throttle_day > 0) {
            $datefrom = date("Y-m-d H:i:s", time() - 24 * 60 * 60);
            $r = q("SELECT COUNT(*) AS `posts_day` FROM `item` WHERE `uid`=%d AND `wall`\n\t\t\t\t\tAND `created` > '%s' AND `id` = `parent`", intval(api_user()), dbesc($datefrom));
            if ($r) {
                $posts_day = $r[0]["posts_day"];
            } else {
                $posts_day = 0;
            }
            if ($posts_day > $throttle_day) {
                logger('Daily posting limit reached for user ' . api_user(), LOGGER_DEBUG);
                die(api_error($a, $type, sprintf(t("Daily posting limit of %d posts reached. The post was rejected."), $throttle_day)));
            }
        }
        $throttle_week = get_config('system', 'throttle_limit_week');
        if ($throttle_week > 0) {
            $datefrom = date("Y-m-d H:i:s", time() - 24 * 60 * 60 * 7);
            $r = q("SELECT COUNT(*) AS `posts_week` FROM `item` WHERE `uid`=%d AND `wall`\n\t\t\t\t\tAND `created` > '%s' AND `id` = `parent`", intval(api_user()), dbesc($datefrom));
            if ($r) {
                $posts_week = $r[0]["posts_week"];
            } else {
                $posts_week = 0;
            }
            if ($posts_week > $throttle_week) {
                logger('Weekly posting limit reached for user ' . api_user(), LOGGER_DEBUG);
                die(api_error($a, $type, sprintf(t("Weekly posting limit of %d posts reached. The post was rejected."), $throttle_week)));
            }
        }
        $throttle_month = get_config('system', 'throttle_limit_month');
        if ($throttle_month > 0) {
            $datefrom = date("Y-m-d H:i:s", time() - 24 * 60 * 60 * 30);
            $r = q("SELECT COUNT(*) AS `posts_month` FROM `item` WHERE `uid`=%d AND `wall`\n\t\t\t\t\tAND `created` > '%s' AND `id` = `parent`", intval(api_user()), dbesc($datefrom));
            if ($r) {
                $posts_month = $r[0]["posts_month"];
            } else {
                $posts_month = 0;
            }
            if ($posts_month > $throttle_month) {
                logger('Monthly posting limit reached for user ' . api_user(), LOGGER_DEBUG);
                die(api_error($a, $type, sprintf(t("Monthly posting limit of %d posts reached. The post was rejected."), $throttle_month)));
            }
        }
        $_REQUEST['type'] = 'wall';
    }
    if (x($_FILES, 'media')) {
        // upload the image if we have one
        $_REQUEST['hush'] = 'yeah';
        //tell wall_upload function to return img info instead of echo
        require_once 'mod/wall_upload.php';
        $media = wall_upload_post($a);
        if (strlen($media) > 0) {
            $_REQUEST['body'] .= "\n\n" . $media;
        }
    }
    // set this so that the item_post() function is quiet and doesn't redirect or emit json
    $_REQUEST['api_source'] = true;
    if (!x($_REQUEST, "source")) {
        $_REQUEST["source"] = api_source();
    }
    // 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);
}