'use strict'; (function (exports) { /* globals define, utils, config */ // export the class if we are in a Node-like system. if (typeof module === 'object' && module.exports === exports) { exports = module.exports/* = SemVer*/; } var helpers = exports; helpers.displayMenuItem = function (data, index) { var item = data.navigation[index]; if (!item) { return false; } var properties = item.properties; var loggedIn = data.config ? data.config.loggedIn : false; if (properties) { if ((properties.loggedIn && !loggedIn) || (properties.globalMod && !data.isGlobalMod && !data.isAdmin) || (properties.adminOnly && !data.isAdmin) || (properties.searchInstalled && !data.searchEnabled)) { return false; } } if (item.route.match('/users') && data.privateUserInfo && !loggedIn) { return false; } if (item.route.match('/tags') && data.privateTagListing && !loggedIn) { return false; } return true; }; helpers.buildMetaTag = function (tag) { var name = tag.name ? 'name="' + tag.name + '" ' : ''; var property = tag.property ? 'property="' + tag.property + '" ' : ''; var content = tag.content ? 'content="' + tag.content.replace(/\n/g, ' ') + '" ' : ''; return '\n\t'; }; helpers.buildLinkTag = function (tag) { var link = tag.link ? 'link="' + tag.link + '" ' : ''; var rel = tag.rel ? 'rel="' + tag.rel + '" ' : ''; var type = tag.type ? 'type="' + tag.type + '" ' : ''; var href = tag.href ? 'href="' + tag.href + '" ' : ''; var sizes = tag.sizes ? 'sizes="' + tag.sizes + '" ' : ''; return '\n\t'; }; helpers.stringify = function (obj) { // Turns the incoming object into a JSON string return JSON.stringify(obj).replace(/&/gm, '&').replace(//gm, '>').replace(/"/g, '"'); }; helpers.escape = function (str) { if (typeof utils !== 'undefined') { return utils.escapeHTML(str); } return require('../utils').escapeHTML(str); }; helpers.stripTags = function (str) { if (typeof window !== 'undefined' && window.S) { return window.S(String(str)).stripTags().s; } var S = require('string'); return S(String(str)).stripTags().s; }; helpers.generateCategoryBackground = function (category) { if (!category) { return ''; } var style = []; if (category.bgColor) { style.push('background-color: ' + category.bgColor); } if (category.color) { style.push('color: ' + category.color); } if (category.backgroundImage) { style.push('background-image: url(' + category.backgroundImage + ')'); if (category.imageClass) { style.push('background-size: ' + category.imageClass); } } return style.join('; ') + ';'; }; helpers.generateChildrenCategories = function (category) { var html = ''; var relative_path = (typeof config !== 'undefined' ? config.relative_path : require('nconf').get('relative_path')); if (!category || !category.children || !category.children.length) { return html; } category.children.forEach(function (child) { if (child) { var link = child.link ? child.link : (relative_path + '/category/' + child.slug); html += '' + '' + '' + '' + '' + child.name + ' '; } }); html = html ? ('' + html + '') : html; return html; }; helpers.generateTopicClass = function (topic) { var style = []; if (topic.locked) { style.push('locked'); } if (topic.pinned) { style.push('pinned'); } if (topic.deleted) { style.push('deleted'); } if (topic.unread) { style.push('unread'); } return style.join(' '); }; helpers.displayUserSearch = function (data, allowGuestUserSearching) { return data.loggedIn || allowGuestUserSearching === 'true'; }; // Groups helpers helpers.membershipBtn = function (groupObj) { if (groupObj.isMember && groupObj.name !== 'administrators') { return ''; } if (groupObj.isPending && groupObj.name !== 'administrators') { return ''; } else if (groupObj.isInvited) { return ''; } else if (!groupObj.disableJoinRequests && groupObj.name !== 'administrators') { return ''; } return ''; }; helpers.spawnPrivilegeStates = function (member, privileges) { var states = []; for (var priv in privileges) { if (privileges.hasOwnProperty(priv)) { states.push({ name: priv, state: privileges[priv], }); } } return states.map(function (priv) { return '