<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Exception;
use Friendica\DI;
-use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Network\HTTPException\ServiceUnavailableException;
use Friendica\Render\TemplateEngine;
/**
* @param string $template
* @param array $vars
* @return string
- * @throws InternalServerErrorException
+ * @throws ServiceUnavailableException
*/
public static function replaceMacros(string $template, array $vars = [])
{
- $stamp1 = microtime(true);
+ DI::profiler()->startRecording('rendering');
// pass $baseurl to all templates if it isn't set
$vars = array_merge(['$baseurl' => DI::baseUrl()->get(), '$APP' => DI::app()], $vars);
$output = $t->replaceMacros($template, $vars);
} catch (Exception $e) {
DI::logger()->critical($e->getMessage(), ['template' => $template, 'vars' => $vars]);
- $message = is_site_admin() ?
+ $message = DI::app()->isSiteAdmin() ?
$e->getMessage() :
DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
- throw new InternalServerErrorException($message);
+ throw new ServiceUnavailableException($message);
}
- DI::profiler()->saveTimestamp($stamp1, "rendering");
+ DI::profiler()->stopRecording();
return $output;
}
* @param string $subDir Subdirectory (Optional)
*
* @return string template.
- * @throws InternalServerErrorException
+ * @throws ServiceUnavailableException
*/
public static function getMarkupTemplate($file, $subDir = '')
{
- $stamp1 = microtime(true);
+ DI::profiler()->startRecording('file');
$t = self::getTemplateEngine();
try {
$template = $t->getTemplateFile($file, $subDir);
} catch (Exception $e) {
DI::logger()->critical($e->getMessage(), ['file' => $file, 'subDir' => $subDir]);
- $message = is_site_admin() ?
+ $message = DI::app()->isSiteAdmin() ?
$e->getMessage() :
DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
- throw new InternalServerErrorException($message);
+ throw new ServiceUnavailableException($message);
}
- DI::profiler()->saveTimestamp($stamp1, "file");
+ DI::profiler()->stopRecording();
return $template;
}
* Register template engine class
*
* @param string $class
- * @throws InternalServerErrorException
+ * @throws ServiceUnavailableException
*/
public static function registerTemplateEngine($class)
{
} else {
$admin_message = DI::l10n()->t('template engine cannot be registered without a name.');
DI::logger()->critical($admin_message, ['class' => $class]);
- $message = is_site_admin() ?
+ $message = DI::app()->isSiteAdmin() ?
$admin_message :
DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
- throw new InternalServerErrorException($message);
+ throw new ServiceUnavailableException($message);
}
}
* or default
*
* @return TemplateEngine Template Engine instance
- * @throws InternalServerErrorException
+ * @throws ServiceUnavailableException
*/
public static function getTemplateEngine()
{
$admin_message = DI::l10n()->t('template engine is not registered!');
DI::logger()->critical($admin_message, ['template_engine' => $template_engine]);
- $message = is_site_admin() ?
+ $message = DI::app()->isSiteAdmin() ?
$admin_message :
DI::l10n()->t('Friendica can\'t display this page at the moment, please contact the administrator.');
- throw new InternalServerErrorException($message);
+ throw new ServiceUnavailableException($message);
}
/**