X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=5a18529d93ab68837560d1cb927fcbc131ff2bb7;hb=a066befba547c5b5a56b945883eda6bf32030697;hp=d6b40dcc2e8e8f0dcb12c331c765174cf227f0f1;hpb=0360f7197aac062eb2fecf95969658ca56068deb;p=friendica.git diff --git a/include/text.php b/include/text.php index d6b40dcc2e..5a18529d93 100644 --- a/include/text.php +++ b/include/text.php @@ -12,17 +12,17 @@ use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; +use Friendica\Core\Protocol; use Friendica\Core\System; -use Friendica\Database\DBM; +use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\Event; use Friendica\Model\Item; -use Friendica\Model\Profile; use Friendica\Render\FriendicaSmarty; use Friendica\Util\DateTimeFormat; use Friendica\Util\Map; +use Friendica\Util\Proxy as ProxyUtils; -require_once "mod/proxy.php"; require_once "include/conversation.php"; /** @@ -42,7 +42,7 @@ function replace_macros($s, $r) { // pass $baseurl to all templates $r['$baseurl'] = System::baseUrl(); - $t = $a->template_engine(); + $t = $a->getTemplateEngine(); try { $output = $t->replaceMacros($s, $r); } catch (Exception $e) { @@ -50,7 +50,7 @@ function replace_macros($s, $r) { killme(); } - $a->save_timestamp($stamp1, "rendering"); + $a->saveTimestamp($stamp1, "rendering"); return $output; } @@ -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 * @@ -553,7 +473,7 @@ function get_markup_template($s, $root = '') { $stamp1 = microtime(true); $a = get_app(); - $t = $a->template_engine(); + $t = $a->getTemplateEngine(); try { $template = $t->getTemplateFile($s, $root); } catch (Exception $e) { @@ -561,7 +481,7 @@ function get_markup_template($s, $root = '') { killme(); } - $a->save_timestamp($stamp1, "file"); + $a->saveTimestamp($stamp1, "file"); return $template; } @@ -593,32 +513,24 @@ $LOGGER_LEVELS = []; * @brief Logs the given message at the given log level * * log levels: - * LOGGER_NORMAL (default) + * LOGGER_WARNING + * LOGGER_INFO (default) * LOGGER_TRACE * LOGGER_DEBUG * LOGGER_DATA * LOGGER_ALL * - * @global App $a * @global array $LOGGER_LEVELS * @param string $msg * @param int $level */ -function logger($msg, $level = 0) { +function logger($msg, $level = LOGGER_INFO) { $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 @@ -662,7 +574,7 @@ function logger($msg, $level = 0) { $stamp1 = microtime(true); @file_put_contents($logfile, $logline, FILE_APPEND); - $a->save_timestamp($stamp1, "file"); + $a->saveTimestamp($stamp1, "file"); } /** @@ -672,29 +584,20 @@ function logger($msg, $level = 0) { * personally without background noise * * log levels: - * LOGGER_NORMAL (default) + * LOGGER_WARNING + * LOGGER_INFO (default) * LOGGER_TRACE * LOGGER_DEBUG * LOGGER_DATA * LOGGER_ALL * - * @global App $a * @global array $LOGGER_LEVELS * @param string $msg * @param int $level */ - -function dlogger($msg, $level = 0) { +function dlogger($msg, $level = LOGGER_INFO) { $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; @@ -716,7 +619,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(); @@ -731,7 +634,7 @@ function dlogger($msg, $level = 0) { $stamp1 = microtime(true); @file_put_contents($logfile, $logline, FILE_APPEND); - $a->save_timestamp($stamp1, "file"); + $a->saveTimestamp($stamp1, "file"); } @@ -853,11 +756,11 @@ function contact_block() { AND NOT `pending` AND NOT `hidden` AND NOT `archive` AND `network` IN ('%s', '%s', '%s')", intval($a->profile['uid']), - dbesc(NETWORK_DFRN), - dbesc(NETWORK_OSTATUS), - dbesc(NETWORK_DIASPORA) + DBA::escape(Protocol::DFRN), + DBA::escape(Protocol::OSTATUS), + DBA::escape(Protocol::DIASPORA) ); - if (DBM::is_result($r)) { + if (DBA::isResult($r)) { $total = intval($r[0]['total']); } if (!$total) { @@ -871,20 +774,20 @@ function contact_block() { AND `network` IN ('%s', '%s', '%s') ORDER BY RAND() LIMIT %d", intval($a->profile['uid']), - dbesc(NETWORK_DFRN), - dbesc(NETWORK_OSTATUS), - dbesc(NETWORK_DIASPORA), + DBA::escape(Protocol::DFRN), + DBA::escape(Protocol::OSTATUS), + DBA::escape(Protocol::DIASPORA), intval($shown) ); - if (DBM::is_result($r)) { + if (DBA::isResult($r)) { $contacts = []; foreach ($r AS $contact) { $contacts[] = $contact["id"]; } $r = q("SELECT `id`, `uid`, `addr`, `url`, `name`, `thumb`, `network` FROM `contact` WHERE `id` IN (%s)", - dbesc(implode(",", $contacts))); + DBA::escape(implode(",", $contacts))); - if (DBM::is_result($r)) { + if (DBA::isResult($r)) { $contacts = L10n::tt('%d Contact', '%d Contacts', $total); $micropro = []; foreach ($r as $rr) { @@ -956,7 +859,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { '$click' => defaults($contact, 'click', ''), '$class' => $class, '$url' => $url, - '$photo' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB), + '$photo' => ProxyUtils::proxifyUrl($contact['thumb'], false, ProxyUtils::SIZE_THUMB), '$name' => $contact['name'], 'title' => $contact['name'] . ' [' . $contact['addr'] . ']', '$parkle' => $sparkle, @@ -1137,7 +1040,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'] == Protocol::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']); } @@ -1173,6 +1076,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; @@ -1282,9 +1191,6 @@ function prepare_body(array &$item, $attach = false, $is_preview = false) $a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), [ '$baseurl' => System::baseUrl(), ]); - $a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), [ - '$baseurl' => System::baseUrl(), - ]); } $url_parts = explode('/', $the_url); @@ -1508,7 +1414,7 @@ function get_plink($item) { ]; if (x($item, 'plink')) { - $ret["href"] = $a->remove_baseurl($item['plink']); + $ret["href"] = $a->removeBaseURL($item['plink']); $ret["title"] = L10n::t('link to source'); } @@ -1550,26 +1456,6 @@ function return_bytes($size_str) { } } - -/** - * @return string - */ -function generate_user_guid() { - $found = true; - do { - $guid = System::createGUID(32); - $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1", - dbesc($guid) - ); - if (!DBM::is_result($x)) { - $found = false; - } - } while ($found == true); - - return $guid; -} - - /** * @param string $s * @param boolean $strip_padding @@ -1751,7 +1637,7 @@ function file_tag_file_query($table,$s,$type = 'file') { } else { $str = preg_quote('<' . str_replace('%', '%%', file_tag_encode($s)) . '>'); } - return " AND " . (($table) ? dbesc($table) . '.' : '') . "file regexp '" . dbesc($str) . "' "; + return " AND " . (($table) ? DBA::escape($table) . '.' : '') . "file regexp '" . DBA::escape($str) . "' "; } // ex. given music,video return