You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.8 KiB
JavaScript

'use strict';
3 years ago
const meta = require.main.require('./src/meta');
const user = require.main.require('./src/user');
const translator = require.main.require('./src/translator');
const controllers = require('./lib/controllers');
3 years ago
const library = module.exports;
3 years ago
library.init = async function (params) {
const { router, middleware } = params;
const routeHelpers = require.main.require('./src/routes/helpers');
routeHelpers.setupAdminPageRoute(router, '/admin/plugins/persona', middleware, [], controllers.renderAdminPage);
routeHelpers.setupPageRoute(router, '/user/:userslug/theme', middleware, [
middleware.exposeUid,
middleware.ensureLoggedIn,
middleware.canViewUsers,
middleware.checkAccountPermissions,
], controllers.renderThemeSettings);
};
3 years ago
library.addAdminNavigation = async function (header) {
header.plugins.push({
route: '/plugins/persona',
icon: 'fa-paint-brush',
3 years ago
name: 'Persona Theme',
});
3 years ago
return header;
};
library.addProfileItem = async (data) => {
data.links.push({
id: 'theme',
route: 'theme',
icon: 'fa-paint-brush',
name: await translator.translate('[[persona:settings.title]]'),
visibility: {
self: true,
other: false,
moderator: false,
globalMod: false,
admin: false,
},
});
return data;
};
3 years ago
library.defineWidgetAreas = async function (areas) {
const locations = ['header', 'sidebar', 'footer'];
const templates = [
'categories.tpl', 'category.tpl', 'topic.tpl', 'users.tpl',
3 years ago
'unread.tpl', 'recent.tpl', 'popular.tpl', 'top.tpl', 'tags.tpl', 'tag.tpl',
'login.tpl', 'register.tpl',
];
function capitalizeFirst(str) {
3 years ago
return str.charAt(0).toUpperCase() + str.slice(1);
}
3 years ago
templates.forEach((template) => {
locations.forEach((location) => {
areas.push({
3 years ago
name: `${capitalizeFirst(template.split('.')[0])} ${capitalizeFirst(location)}`,
template: template,
location: location,
});
});
});
9 years ago
areas = areas.concat([
{
3 years ago
name: 'Account Header',
template: 'account/profile.tpl',
location: 'header',
},
9 years ago
]);
3 years ago
return areas;
9 years ago
};
3 years ago
library.getThemeConfig = async function (config) {
4 years ago
const settings = await meta.settings.get('persona');
config.hideSubCategories = settings.hideSubCategories === 'on';
config.hideCategoryLastPost = settings.hideCategoryLastPost === 'on';
config.enableQuickReply = settings.enableQuickReply === 'on';
return config;
};
library.addUserToTopic = async function (hookData) {
const settings = await meta.settings.get('persona');
if (settings.enableQuickReply === 'on') {
if (hookData.req.user) {
const userData = await user.getUserData(hookData.req.user.uid);
hookData.templateData.loggedInUser = userData;
} else {
3 years ago
hookData.templateData.loggedInUser = {
uid: 0,
username: '[[global:guest]]',
picture: user.getDefaultAvatar(),
'icon:text': '?',
'icon:bgColor': '#aaa',
};
}
}
return hookData;
};
8 years ago
module.exports = library;