}
// Needed to match the correct template in a module that uses a different theme than the user/site/default
- $theme = Strings::sanitizeFilePathItem($_GET['theme'] ?? null);
+ $theme = Strings::sanitizeFilePathItem($_GET['theme'] ?? '');
if ($theme && is_file("view/theme/$theme/config.php")) {
$a->setCurrentTheme($theme);
}
/**
* Lists plugins
*
- * @return int Return code of this command
- *
+ * @return int|bool Return code of this command, false on error (?)
* @throws \Exception
*/
private function list()
* Enables an addon
*
* @return int Return code of this command
- *
* @throws \Exception
*/
- private function enable()
+ private function enable(): int
{
$addonname = $this->getArgument(1);
* Disables an addon
*
* @return int Return code of this command
- *
* @throws \Exception
*/
- private function disable()
+ private function disable(): int
{
$addonname = $this->getArgument(1);
* @return void
* @throws \Exception
*/
- public static function uninstall($addon)
+ public static function uninstall(string $addon)
{
$addon = Strings::sanitizeFilePathItem($addon);
* @return bool
* @throws \Exception
*/
- public static function install($addon)
+ public static function install(string $addon): bool
{
$addon = Strings::sanitizeFilePathItem($addon);
/**
* reload all updated addons
+ *
+ * @return void
*/
public static function reload()
{
* @return array with the addon information
* @throws \Exception
*/
- public static function getInfo($addon)
+ public static function getInfo(string $addon): array
{
$addon = Strings::sanitizeFilePathItem($addon);
* @param string $addon
* @return boolean
*/
- public static function isEnabled($addon)
+ public static function isEnabled(string $addon): bool
{
return in_array($addon, self::$addons);
}
*
* @return array
*/
- public static function getEnabledList()
+ public static function getEnabledList(): array
{
return self::$addons;
}
* @return array
* @throws \Exception
*/
- public static function getVisibleList()
+ public static function getVisibleList(): array
{
$visible_addons = [];
$stmt = DBA::select('addon', ['name'], ['hidden' => false, 'installed' => true]);
/**
* Load hooks
+ *
+ * @return void
*/
public static function loadHooks()
{
* @param string $hook
* @param string $file
* @param string $function
+ * @return void
*/
- public static function add($hook, $file, $function)
+ public static function add(string $hook, string $file, string $function)
{
if (!array_key_exists($hook, self::$hooks)) {
self::$hooks[$hook] = [];
* @return mixed|bool
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function register($hook, $file, $function, $priority = 0)
+ public static function register(string $hook, string $file, string $function, int $priority = 0)
{
$file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
* @return boolean
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function unregister($hook, $file, $function)
+ public static function unregister(string $hook, string $file, string $function): bool
{
$relative_file = str_replace(DI::app()->getBasePath() . DIRECTORY_SEPARATOR, '', $file);
self::delete($condition);
$condition = ['hook' => $hook, 'file' => $relative_file, 'function' => $function];
- $result = self::delete($condition);
- return $result;
+
+ return self::delete($condition);
}
/**
* @param string $name Name of the hook
* @return array
*/
- public static function getByName($name)
+ public static function getByName(string $name): array
{
$return = [];
* @param integer $priority of the hook
* @param string $name of the hook to call
* @param mixed $data to transmit to the callback handler
+ * @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function fork($priority, $name, $data = null)
+ public static function fork(int $priority, string $name, $data = null)
{
if (array_key_exists($name, self::$hooks)) {
foreach (self::$hooks[$name] as $hook) {
*
* @param string $name of the hook to call
* @param string|array &$data to transmit to the callback handler
+ * @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function callAll($name, &$data = null)
+ public static function callAll(string $name, &$data = null)
{
if (array_key_exists($name, self::$hooks)) {
foreach (self::$hooks[$name] as $hook) {
* @param string $name of the hook to call
* @param array $hook Hook data
* @param string|array &$data to transmit to the callback handler
+ * @return void
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function callSingle(App $a, $name, $hook, &$data = null)
+ public static function callSingle(App $a, string $name, array $hook, &$data = null)
{
// Don't run a theme's hook if the user isn't using the theme
if (strpos($hook[0], 'view/theme/') !== false && strpos($hook[0], 'view/theme/' . $a->getCurrentTheme()) === false) {
* @param string $name Name of the addon
* @return boolean
*/
- public static function isAddonApp($name)
+ public static function isAddonApp(string $name): bool
{
$name = Strings::sanitizeFilePathItem($name);
* @return bool
* @throws \Exception
*/
- public static function delete(array $condition)
+ public static function delete(array $condition): bool
{
$result = DBA::delete('hook', $condition);
* @return bool
* @throws \Exception
*/
- private static function insert(array $condition)
+ private static function insert(array $condition): bool
{
$result = DBA::insert('hook', $condition);
private function setLangFromSession(IHandleSessions $session)
{
if ($session->get('language') !== $this->lang) {
- $this->loadTranslationTable($session->get('language'));
+ $this->loadTranslationTable($session->get('language') ?? $this->lang);
}
}
* Uses an App object shim since all the strings files refer to $a->strings
*
* @param string $lang language code to load
- *
+ * @return void
* @throws \Exception
*/
- private function loadTranslationTable($lang)
+ private function loadTranslationTable(string $lang)
{
$lang = Strings::sanitizeFilePathItem($lang);
*
* @return string The two-letter language code
*/
- public static function detectLanguage(array $server, array $get, string $sysLang = self::DEFAULT)
+ public static function detectLanguage(array $server, array $get, string $sysLang = self::DEFAULT): string
{
$lang_variable = $server['HTTP_ACCEPT_LANGUAGE'] ?? null;
*
* @return string
*/
- public function t($s, ...$vars)
+ public function t(array $s, ...$vars): string
{
if (empty($s)) {
return '';
* @return string
* @throws \Exception
*/
- public function tt(string $singular, string $plural, int $count)
+ public function tt(string $singular, string $plural, int $count): string
{
$s = null;
*
* @return bool
*/
- private function stringPluralSelectDefault($n)
+ private function stringPluralSelectDefault(int $n): bool
{
return $n != 1;
}
*
* @return array
*/
- public static function getAvailableLanguages()
+ public static function getAvailableLanguages(): array
{
$langs = [];
$strings_file_paths = glob('view/lang/*/strings.php');
* Translate days and months names.
*
* @param string $s String with day or month name.
- *
* @return string Translated string.
*/
- public function getDay($s)
+ public function getDay(string $s): string
{
$ret = str_replace(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
[$this->t('Monday'), $this->t('Tuesday'), $this->t('Wednesday'), $this->t('Thursday'), $this->t('Friday'), $this->t('Saturday'), $this->t('Sunday')],
* Translate short days and months names.
*
* @param string $s String with short day or month name.
- *
* @return string Translated string.
*/
- public function getDayShort($s)
+ public function getDayShort(string $s): string
{
$ret = str_replace(['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
[$this->t('Mon'), $this->t('Tue'), $this->t('Wed'), $this->t('Thu'), $this->t('Fri'), $this->t('Sat'), $this->t('Sun')],
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @hook poke_verbs pokes array
*/
- public function getPokeVerbs()
+ public function getPokeVerbs(): array
{
// index is present tense verb
// value is array containing past tense verb, translation of present, translation of past
* @return static A new L10n instance
* @throws \Exception
*/
- public function withLang(string $lang)
+ public function withLang(string $lang): L10n
{
// Don't create a new instance for same language
if ($lang === $this->lang) {
*/
class Theme
{
- public static function getAllowedList()
+ public static function getAllowedList(): array
{
$allowed_themes_str = DI::config()->get('system', 'allowed_themes');
$allowed_themes_raw = explode(',', str_replace(' ', '', $allowed_themes_str));
* @param string $theme the name of the theme
* @return array
*/
- public static function getInfo($theme)
+ public static function getInfo(string $theme): array
{
$theme = Strings::sanitizeFilePathItem($theme);
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- public static function getScreenshot($theme)
+ public static function getScreenshot(string $theme): string
{
$theme = Strings::sanitizeFilePathItem($theme);
return DI::baseUrl() . '/images/blank.png';
}
- public static function uninstall($theme)
+ /**
+ * Uninstalls given theme name
+ *
+ * @param string $theme Name of theme
+ * @return bool true on success
+ */
+ public static function uninstall(string $theme)
{
$theme = Strings::sanitizeFilePathItem($theme);
if ($key !== false) {
unset($allowed_themes[$key]);
Theme::setAllowedList($allowed_themes);
+ return true;
}
+ return false;
}
- public static function install($theme)
+ /**
+ * Installs given theme name
+ *
+ * @param string $theme Name of theme
+ * @return bool true on success
+ */
+ public static function install(string $theme): bool
{
$theme = Strings::sanitizeFilePathItem($theme);
* @return string Path to the file or empty string if the file isn't found
* @throws \Exception
*/
- public static function getPathForFile($file)
+ public static function getPathForFile(string $file): string
{
$a = DI::app();
* Provide a sane default if nothing is chosen or the specified theme does not exist.
*
* @param string $theme Theme name
- *
* @return string
*/
- public static function getStylesheetPath($theme)
+ public static function getStylesheetPath(string $theme): string
{
$theme = Strings::sanitizeFilePathItem($theme);
/**
* Returns the path of the provided theme
*
- * @param $theme
+ * @param string $theme Theme name
* @return string|null
*/
- public static function getConfigFile($theme)
+ public static function getConfigFile(string $theme)
{
$theme = Strings::sanitizeFilePathItem($theme);
/**
* Returns the background color of the provided theme if available.
*
- * @param string $theme
+ * @param string $theme Theme name
* @param int|null $uid Current logged-in user id
* @return string|null
*/
- public static function getBackgroundColor(string $theme, $uid = null)
+ public static function getBackgroundColor(string $theme, int $uid = null)
{
$theme = Strings::sanitizeFilePathItem($theme);