]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Fix tests (#5400)
[friendica.git] / include / text.php
index 0066e188145deb1c11d8158433162a08df28c419..6aa0c9d2dd43208e33464c913d79253b5a04cf4c 100644 (file)
@@ -462,86 +462,6 @@ function perms2str($p) {
        return $ret;
 }
 
-/**
- * @deprecated
- * wrapper to load a view template, checking for alternate
- * languages before falling back to the default
- *
- * @global string $lang
- * @global App $a
- * @param string $s view name
- * @return string
- */
-function load_view_file($s) {
-       global $lang, $a;
-       if (!isset($lang)) {
-               $lang = 'en';
-       }
-       $b = basename($s);
-       $d = dirname($s);
-       if (file_exists("$d/$lang/$b")) {
-               $stamp1 = microtime(true);
-               $content = file_get_contents("$d/$lang/$b");
-               $a->save_timestamp($stamp1, "file");
-               return $content;
-       }
-
-       $theme = $a->getCurrentTheme();
-
-       if (file_exists("$d/theme/$theme/$b")) {
-               $stamp1 = microtime(true);
-               $content = file_get_contents("$d/theme/$theme/$b");
-               $a->save_timestamp($stamp1, "file");
-               return $content;
-       }
-
-       $stamp1 = microtime(true);
-       $content = file_get_contents($s);
-       $a->save_timestamp($stamp1, "file");
-       return $content;
-}
-
-
-/**
- * load a view template, checking for alternate
- * languages before falling back to the default
- *
- * @global string $lang
- * @param string $s view path
- * @return string
- */
-function get_intltext_template($s) {
-       global $lang;
-
-       $a = get_app();
-       $engine = '';
-       if ($a->theme['template_engine'] === 'smarty3') {
-               $engine = "/smarty3";
-       }
-
-       if (!isset($lang)) {
-               $lang = 'en';
-       }
-
-       if (file_exists("view/lang/$lang$engine/$s")) {
-               $stamp1 = microtime(true);
-               $content = file_get_contents("view/lang/$lang$engine/$s");
-               $a->save_timestamp($stamp1, "file");
-               return $content;
-       } elseif (file_exists("view/lang/en$engine/$s")) {
-               $stamp1 = microtime(true);
-               $content = file_get_contents("view/lang/en$engine/$s");
-               $a->save_timestamp($stamp1, "file");
-               return $content;
-       } else {
-               $stamp1 = microtime(true);
-               $content = file_get_contents("view$engine/$s");
-               $a->save_timestamp($stamp1, "file");
-               return $content;
-       }
-}
-
-
 /**
  * load template $s
  *
@@ -599,7 +519,6 @@ $LOGGER_LEVELS = [];
  * LOGGER_DATA
  * LOGGER_ALL
  *
- * @global App $a
  * @global array $LOGGER_LEVELS
  * @param string $msg
  * @param int $level
@@ -608,17 +527,9 @@ function logger($msg, $level = 0) {
        $a = get_app();
        global $LOGGER_LEVELS;
 
-       // turn off logger in install mode
-       if (
-               $a->mode == App::MODE_INSTALL
-               || !dba::$connected
-       ) {
-               return;
-       }
-
-       $debugging = Config::get('system','debugging');
-       $logfile   = Config::get('system','logfile');
-       $loglevel = intval(Config::get('system','loglevel'));
+       $debugging = Config::get('system', 'debugging');
+       $logfile   = Config::get('system', 'logfile');
+       $loglevel = intval(Config::get('system', 'loglevel'));
 
        if (
                !$debugging
@@ -643,13 +554,20 @@ function logger($msg, $level = 0) {
        }
 
        $callers = debug_backtrace();
+
+       if (count($callers) > 1) {
+               $function = $callers[1]['function'];
+       } else {
+               $function = '';
+       }
+
        $logline = sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n",
                        DateTimeFormat::utcNow(DateTimeFormat::ATOM),
                        $process_id,
                        $LOGGER_LEVELS[$level],
                        basename($callers[0]['file']),
                        $callers[0]['line'],
-                       $callers[1]['function'],
+                       $function,
                        $msg
                );
 
@@ -671,23 +589,13 @@ function logger($msg, $level = 0) {
  * LOGGER_DATA
  * LOGGER_ALL
  *
- * @global App $a
  * @global array $LOGGER_LEVELS
  * @param string $msg
  * @param int $level
  */
-
 function dlogger($msg, $level = 0) {
        $a = get_app();
 
-       // turn off logger in install mode
-       if (
-               $a->mode == App::MODE_INSTALL
-               || !dba::$connected
-       ) {
-               return;
-       }
-
        $logfile = Config::get('system', 'dlogfile');
        if (!$logfile) {
                return;
@@ -709,7 +617,7 @@ function dlogger($msg, $level = 0) {
        $process_id = session_id();
 
        if ($process_id == '') {
-               $process_id = get_app()->process_id;
+               $process_id = $a->process_id;
        }
 
        $callers = debug_backtrace();
@@ -1130,7 +1038,7 @@ function redir_private_images($a, &$item)
                                continue;
                        }
 
-                       if ((local_user() == $item['uid']) && ($item['private'] != 0) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
+                       if ((local_user() == $item['uid']) && ($item['private'] == 1) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
                                $img_url = 'redir?f=1&quiet=1&url=' . urlencode($mtch[1]) . '&conurl=' . urlencode($item['author-link']);
                                $item['body'] = str_replace($mtch[0], '[img]' . $img_url . '[/img]', $item['body']);
                        }
@@ -1166,6 +1074,12 @@ function put_item_in_cache(&$item, $update = false)
                $item["rendered-html"] = prepare_text($item["body"]);
                $item["rendered-hash"] = hash("md5", $item["body"]);
 
+               $hook_data = ['item' => $item, 'rendered-html' => $item['rendered-html'], 'rendered-hash' => $item['rendered-hash']];
+               Addon::callHooks('put_item_in_cache', $hook_data);
+               $item['rendered-html'] = $hook_data['rendered-html'];
+               $item['rendered-hash'] = $hook_data['rendered-hash'];
+               unset($hook_data);
+
                // Force an update if the generated values differ from the existing ones
                if ($rendered_hash != $item["rendered-hash"]) {
                        $update = true;
@@ -1280,7 +1194,8 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
                                ]);
                        }
 
-                       $id = end(explode('/', $the_url));
+                       $url_parts = explode('/', $the_url);
+                       $id = end($url_parts);
                        $as .= replace_macros(get_markup_template('video_top.tpl'), [
                                '$video' => [
                                        'id'     => $id,
@@ -1549,7 +1464,7 @@ function return_bytes($size_str) {
 function generate_user_guid() {
        $found = true;
        do {
-               $guid = get_guid(32);
+               $guid = System::createGUID(32);
                $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1",
                        dbesc($guid)
                );
@@ -1710,11 +1625,11 @@ function reltoabs($text, $base) {
  * @return string
  */
 function item_post_type($item) {
-       if (intval($item['event-id'])) {
+       if (!empty($item['event-id'])) {
                return L10n::t('event');
-       } elseif (strlen($item['resource-id'])) {
+       } elseif (!empty($item['resource-id'])) {
                return L10n::t('photo');
-       } elseif (strlen($item['verb']) && $item['verb'] !== ACTIVITY_POST) {
+       } elseif (!empty($item['verb']) && $item['verb'] !== ACTIVITY_POST) {
                return L10n::t('activity');
        } elseif ($item['id'] != $item['parent']) {
                return L10n::t('comment');