X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fapi.php;h=2d41cb986a4e5706c42fa6205bc8926816ae4221;hb=bfc2bda9b606b424e4dfc1053af1ecea116fb1e2;hp=4edced2214eb6f21eb0c49508b691d1bf9d1ec3f;hpb=974539913caa1d56184d8bef70743c3be37e5b57;p=friendica.git
diff --git a/include/api.php b/include/api.php
index 4edced2214..2d41cb986a 100644
--- a/include/api.php
+++ b/include/api.php
@@ -5,24 +5,26 @@
* @file include/api.php
* @todo Automatically detect if incoming data is HTML or BBCode
*/
+
use Friendica\App;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
use Friendica\Content\Text\BBCode;
+use Friendica\Content\Text\HTML;
use Friendica\Core\Addon;
-use Friendica\Core\System;
use Friendica\Core\Config;
-use Friendica\Core\NotificationsManager;
use Friendica\Core\L10n;
+use Friendica\Core\NotificationsManager;
use Friendica\Core\PConfig;
+use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
+use Friendica\Model\Item;
use Friendica\Model\Mail;
use Friendica\Model\Photo;
use Friendica\Model\User;
-use Friendica\Model\Item;
use Friendica\Network\FKOAuth1;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\BadRequestException;
@@ -31,21 +33,18 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPException\MethodNotAllowedException;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Network\HTTPException\NotImplementedException;
-use Friendica\Network\HTTPException\UnauthorizedException;
use Friendica\Network\HTTPException\TooManyRequestsException;
+use Friendica\Network\HTTPException\UnauthorizedException;
use Friendica\Object\Image;
use Friendica\Protocol\Diaspora;
+use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
use Friendica\Util\XML;
-require_once 'include/bbcode.php';
-require_once 'include/datetime.php';
require_once 'include/conversation.php';
-require_once 'include/html2plain.php';
require_once 'mod/share.php';
require_once 'mod/item.php';
require_once 'include/security.php';
-require_once 'include/html2bbcode.php';
require_once 'mod/wall_upload.php';
require_once 'mod/proxy.php';
@@ -109,7 +108,7 @@ function api_source()
function api_date($str)
{
// Wed May 23 06:01:13 +0000 2007
- return datetime_convert('UTC', 'UTC', $str, "D M d H:i:s +0000 Y");
+ return DateTimeFormat::utc($str, "D M d H:i:s +0000 Y");
}
/**
@@ -317,12 +316,16 @@ function api_call(App $a)
/// @TODO round() really everywhere?
logger(
parse_url($a->query_string, PHP_URL_PATH) . ": " . sprintf(
- "Database: %s/%s, Network: %s, I/O: %s, Other: %s, Total: %s",
+ "Database: %s/%s, Cache %s/%s, Network: %s, I/O: %s, Other: %s, Total: %s",
round($a->performance["database"] - $a->performance["database_write"], 3),
round($a->performance["database_write"], 3),
+ round($a->performance["cache"], 3),
+ round($a->performance["cache_write"], 3),
round($a->performance["network"], 2),
round($a->performance["file"], 2),
- round($duration - ($a->performance["database"] + $a->performance["network"] + $a->performance["file"]), 2),
+ round($duration - ($a->performance["database"]
+ + $a->performance["cache"] + $a->performance["cache_write"]
+ + $a->performance["network"] + $a->performance["file"]), 2),
round($duration, 2)
),
LOGGER_DEBUG
@@ -344,6 +347,21 @@ function api_call(App $a)
}
}
+ $o = "Cache Read:\n";
+ foreach ($a->callstack["cache"] as $func => $time) {
+ $time = round($time, 3);
+ if ($time > 0) {
+ $o .= $func . ": " . $time . "\n";
+ }
+ }
+ $o .= "\nCache Write:\n";
+ foreach ($a->callstack["cache_write"] as $func => $time) {
+ $time = round($time, 3);
+ if ($time > 0) {
+ $o .= $func . ": " . $time . "\n";
+ }
+ }
+
$o .= "\nNetwork:\n";
foreach ($a->callstack["network"] as $func => $time) {
$time = round($time, 3);
@@ -458,7 +476,7 @@ function api_rss_extra(App $a, $arr, $user_info)
'self' => System::baseUrl() . "/" . $a->query_string,
'base' => System::baseUrl(),
'updated' => api_date(null),
- 'atom_updated' => datetime_convert('UTC', 'UTC', 'now', ATOM_TIME),
+ 'atom_updated' => DateTimeFormat::utcNow(DateTimeFormat::ATOM),
'language' => $user_info['language'],
'logo' => System::baseUrl() . "/images/friendica-32.png",
];
@@ -1077,7 +1095,7 @@ function api_statuses_mediap($type)
$purifier = new HTMLPurifier($config);
$txt = $purifier->purify($txt);
}
- $txt = html2bbcode($txt);
+ $txt = HTML::toBBCode($txt);
$a->argv[1]=$user_info['screen_name']; //should be set to username?
@@ -1128,7 +1146,7 @@ function api_statuses_update($type)
$purifier = new HTMLPurifier($config);
$txt = $purifier->purify($txt);
- $_REQUEST['body'] = html2bbcode($txt);
+ $_REQUEST['body'] = HTML::toBBCode($txt);
}
} else {
$_REQUEST['body'] = requestdata('status');
@@ -1160,7 +1178,7 @@ function api_statuses_update($type)
// Check for throttling (maximum posts per day, week and month)
$throttle_day = Config::get('system', 'throttle_limit_day');
if ($throttle_day > 0) {
- $datefrom = date("Y-m-d H:i:s", time() - 24*60*60);
+ $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
$r = q(
"SELECT COUNT(*) AS `posts_day` FROM `item` WHERE `uid`=%d AND `wall`
@@ -1184,7 +1202,7 @@ function api_statuses_update($type)
$throttle_week = Config::get('system', 'throttle_limit_week');
if ($throttle_week > 0) {
- $datefrom = date("Y-m-d H:i:s", time() - 24*60*60*7);
+ $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
$r = q(
"SELECT COUNT(*) AS `posts_week` FROM `item` WHERE `uid`=%d AND `wall`
@@ -1208,7 +1226,7 @@ function api_statuses_update($type)
$throttle_month = Config::get('system', 'throttle_limit_month');
if ($throttle_month > 0) {
- $datefrom = date("Y-m-d H:i:s", time() - 24*60*60*30);
+ $datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
$r = q(
"SELECT COUNT(*) AS `posts_month` FROM `item` WHERE `uid`=%d AND `wall`
@@ -1609,6 +1627,7 @@ api_register_func('api/users/lookup', 'api_users_lookup', true);
function api_search($type)
{
$data = [];
+ $sql_extra = '';
if (!x($_REQUEST, 'q')) {
throw new BadRequestException("q parameter is required.");
@@ -1790,6 +1809,7 @@ function api_statuses_public_timeline($type)
$conversation_id = (x($_REQUEST, 'conversation_id') ? $_REQUEST['conversation_id'] : 0);
$start = $page * $count;
+ $sql_extra = '';
if ($exclude_replies && !$conversation_id) {
if ($max_id > 0) {
@@ -2146,7 +2166,6 @@ function api_statuses_repeat($type)
WHERE `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
AND NOT `item`.`private` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
- $sql_extra
AND `item`.`id`=%d",
intval($id)
);
@@ -2217,7 +2236,7 @@ function api_statuses_destroy($type)
$ret = api_statuses_show($type);
- Item::delete($id);
+ Item::deleteById($id);
return $ret;
}
@@ -2266,8 +2285,10 @@ function api_statuses_mentions($type)
$myurl = substr($myurl, strpos($myurl, '://') + 3);
$myurl = str_replace('www.', '', $myurl);
+ $sql_extra = '';
+
if ($max_id > 0) {
- $sql_extra = ' AND `item`.`id` <= ' . intval($max_id);
+ $sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
}
$r = q(
@@ -2458,9 +2479,7 @@ function api_favorites_create_destroy($type)
throw new BadRequestException("Invalid action ".$action);
}
- $r = q("UPDATE item SET starred=%d WHERE id=%d AND uid=%d", $item[0]['starred'], $itemid, api_user());
-
- q("UPDATE thread SET starred=%d WHERE iid=%d AND uid=%d", $item[0]['starred'], $itemid, api_user());
+ $r = Item::update(['starred' => $item[0]['starred']], ['id' => $itemid]);
if ($r === false) {
throw new InternalServerErrorException("DB error");
@@ -2602,13 +2621,12 @@ function api_format_messages($item, $recipient, $sender)
if (x($_GET, 'getText')) {
$ret['title'] = $item['title'];
if ($_GET['getText'] == 'html') {
- $ret['text'] = bbcode($item['body'], false, false);
+ $ret['text'] = BBCode::convert($item['body'], false);
} elseif ($_GET['getText'] == 'plain') {
- //$ret['text'] = html2plain(bbcode($item['body'], false, false, true), 0);
- $ret['text'] = trim(html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 2, true), 0));
+ $ret['text'] = trim(HTML::toPlaintext(BBCode::convert(api_clean_plain_items($item['body']), false, 2, true), 0));
}
} else {
- $ret['text'] = $item['title'] . "\n" . html2plain(bbcode(api_clean_plain_items($item['body']), false, false, 2, true), 0);
+ $ret['text'] = $item['title'] . "\n" . HTML::toPlaintext(BBCode::convert(api_clean_plain_items($item['body']), false, 2, true), 0);
}
if (x($_GET, 'getUserObjects') && $_GET['getUserObjects'] == 'false') {
unset($ret['sender']);
@@ -2630,8 +2648,8 @@ function api_convert_item($item)
$attachments = api_get_attachments($body);
// Workaround for ostatus messages where the title is identically to the body
- $html = bbcode(api_clean_plain_items($body), false, false, 2, true);
- $statusbody = trim(html2plain($html, 0));
+ $html = BBCode::convert(api_clean_plain_items($body), false, 2, true);
+ $statusbody = trim(HTML::toPlaintext($html, 0));
// handle data: images
$statusbody = api_format_items_embeded_images($item, $statusbody);
@@ -2648,7 +2666,7 @@ function api_convert_item($item)
$statustext = substr($statustext, 0, 1000)."... \n".$item["plink"];
}
- $statushtml = trim(bbcode($body, false, false));
+ $statushtml = BBCode::convert(api_clean_attachments($body), false);
// Workaround for clients with limited HTML parser functionality
$search = ["
", "
", "", @@ -2662,7 +2680,7 @@ function api_convert_item($item) $statushtml = str_replace($search, $replace, $statushtml); if ($item['title'] != "") { - $statushtml = "