]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Merge pull request #4630 from MrPetovan/task/4629-move-executable-to-bin
[friendica.git] / include / api.php
index 67df83fe14da138f15c1d064b6de8ce620f53dba..eec713c5374744ae0b6ae8d8bc66f51221fcc09b 100644 (file)
@@ -10,6 +10,7 @@ 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\Config;
 use Friendica\Core\L10n;
@@ -40,13 +41,10 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\XML;
 
-require_once 'include/bbcode.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';
 
@@ -318,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
@@ -345,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);
@@ -1078,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?
 
@@ -1129,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');
@@ -2604,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']);
@@ -2632,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);
@@ -2650,7 +2666,7 @@ function api_convert_item($item)
                $statustext = substr($statustext, 0, 1000)."... \n".$item["plink"];
        }
 
-       $statushtml = bbcode(api_clean_attachments($body), false, false);
+       $statushtml = BBCode::convert(api_clean_attachments($body), false);
 
        // Workaround for clients with limited HTML parser functionality
        $search = ["<br>", "<blockquote>", "</blockquote>",
@@ -2664,7 +2680,7 @@ function api_convert_item($item)
        $statushtml = str_replace($search, $replace, $statushtml);
 
        if ($item['title'] != "") {
-               $statushtml = "<br><h4>" . bbcode($item['title']) . "</h4><br>" . $statushtml;
+               $statushtml = "<br><h4>" . BBCode::convert($item['title']) . "</h4><br>" . $statushtml;
        }
 
        do {
@@ -2682,7 +2698,7 @@ function api_convert_item($item)
 
        // feeds without body should contain the link
        if (($item['network'] == NETWORK_FEED) && (strlen($item['body']) == 0)) {
-               $statushtml .= bbcode($item['plink']);
+               $statushtml .= BBCode::convert($item['plink']);
        }
 
        $entities = api_get_entitities($statustext, $body);
@@ -3053,18 +3069,18 @@ function api_format_items_profiles($profile_row)
                'religion'         => $profile_row['religion'],
                'public_keywords'  => $profile_row['pub_keywords'],
                'private_keywords' => $profile_row['prv_keywords'],
-               'likes'            => bbcode(api_clean_plain_items($profile_row['likes'])    , false, false, 2, false),
-               'dislikes'         => bbcode(api_clean_plain_items($profile_row['dislikes']) , false, false, 2, false),
-               'about'            => bbcode(api_clean_plain_items($profile_row['about'])    , false, false, 2, false),
-               'music'            => bbcode(api_clean_plain_items($profile_row['music'])    , false, false, 2, false),
-               'book'             => bbcode(api_clean_plain_items($profile_row['book'])     , false, false, 2, false),
-               'tv'               => bbcode(api_clean_plain_items($profile_row['tv'])       , false, false, 2, false),
-               'film'             => bbcode(api_clean_plain_items($profile_row['film'])     , false, false, 2, false),
-               'interest'         => bbcode(api_clean_plain_items($profile_row['interest']) , false, false, 2, false),
-               'romance'          => bbcode(api_clean_plain_items($profile_row['romance'])  , false, false, 2, false),
-               'work'             => bbcode(api_clean_plain_items($profile_row['work'])     , false, false, 2, false),
-               'education'        => bbcode(api_clean_plain_items($profile_row['education']), false, false, 2, false),
-               'social_networks'  => bbcode(api_clean_plain_items($profile_row['contact'])  , false, false, 2, false),
+               'likes'            => BBCode::convert(api_clean_plain_items($profile_row['likes'])    , false, 2),
+               'dislikes'         => BBCode::convert(api_clean_plain_items($profile_row['dislikes']) , false, 2),
+               'about'            => BBCode::convert(api_clean_plain_items($profile_row['about'])    , false, 2),
+               'music'            => BBCode::convert(api_clean_plain_items($profile_row['music'])    , false, 2),
+               'book'             => BBCode::convert(api_clean_plain_items($profile_row['book'])     , false, 2),
+               'tv'               => BBCode::convert(api_clean_plain_items($profile_row['tv'])       , false, 2),
+               'film'             => BBCode::convert(api_clean_plain_items($profile_row['film'])     , false, 2),
+               'interest'         => BBCode::convert(api_clean_plain_items($profile_row['interest']) , false, 2),
+               'romance'          => BBCode::convert(api_clean_plain_items($profile_row['romance'])  , false, 2),
+               'work'             => BBCode::convert(api_clean_plain_items($profile_row['work'])     , false, 2),
+               'education'        => BBCode::convert(api_clean_plain_items($profile_row['education']), false, 2),
+               'social_networks'  => BBCode::convert(api_clean_plain_items($profile_row['contact'])  , false, 2),
                'homepage'         => $profile_row['homepage'],
                'users'            => null
        ];
@@ -4616,7 +4632,7 @@ function save_media_to_database($mediatype, $media, $type, $album, $allow_cid, $
        $height = $Image->getHeight();
 
        // create a new resource-id if not already provided
-       $hash = ($photo_id == null) ? photo_new_resource() : $photo_id;
+       $hash = ($photo_id == null) ? Photo::newResource() : $photo_id;
 
        if ($mediatype == "photo") {
                // upload normal image (scales 0, 1, 2)