function red_item_new(&$a, $type) { if (api_user() === false) { logger('api_red_item_new: no user'); return false; } logger('api_red_item_new: REQUEST ' . print_r($_REQUEST, true)); logger('api_red_item_new: 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; $_REQUEST['profile_uid'] = api_user(); 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_upload.php'; $media = wall_upload_post($a); if (strlen($media) > 0) { $_REQUEST['body'] .= "\n\n" . $media; } } require_once 'mod/item.php'; $x = item_post($a); json_return_and_die($x); }
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['body'] = urldecode(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 { $_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); }
function api_media_upload(&$a, $type) { if (api_user() === false) { logger('no user'); return false; } $user_info = api_get_user($a); if (!x($_FILES, 'media')) { // Output error return false; } $media = wall_upload_post($a, false); if (!$media) { // Output error return false; } $returndata = array(); $returndata["media_id"] = $media["id"]; $returndata["media_id_string"] = (string) $media["id"]; $returndata["size"] = $media["size"]; $returndata["image"] = array("w" => $media["width"], "h" => $media["height"], "image_type" => $media["type"]); logger("Media uploaded: " . print_r($returndata, true), LOGGER_DEBUG); return array("media" => $returndata); }
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); }