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.

85 lines
2.2 KiB
JavaScript

'use strict';
3 years ago
const meta = require.main.require('./src/meta');
const user = require.main.require('./src/user');
3 years ago
const library = module.exports;
3 years ago
library.init = async function (params) {
const { app, middleware } = params;
app.get('/admin/plugins/persona', middleware.admin.buildHeader, renderAdmin);
app.get('/api/admin/plugins/persona', renderAdmin);
};
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;
};
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',
];
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;
};
3 years ago
function renderAdmin(req, res) {
res.render('admin/plugins/persona', {});
}
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;