- fix troncamento stringa , i TAG HTML non venivano chiusi. ora li ho tolti
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
DATABASE=test_PiuCheBuono
|
DATABASE=test_FreePlanet
|
||||||
UDB=paofreeplanet
|
UDB=paofreeplanet
|
||||||
PDB=mypassword@1A
|
PDB=mypassword@1A
|
||||||
SEND_EMAIL=0
|
SEND_EMAIL=0
|
||||||
SEND_EMAIL_ORDERS=1
|
SEND_EMAIL_ORDERS=1
|
||||||
PORT=3000
|
PORT=3000
|
||||||
appTelegram_TEST=["1","17"]
|
appTelegram_TEST=["1","13"]
|
||||||
appTelegram=["1","17"]
|
appTelegram=["1","13"]
|
||||||
DOMAIN=mongodb://localhost:27017/
|
DOMAIN=mongodb://localhost:27017/
|
||||||
AUTH_MONGODB=true
|
AUTH_MONGODB=true
|
||||||
MONGODB_USER=admin
|
MONGODB_USER=admin
|
||||||
|
|||||||
@@ -4240,29 +4240,35 @@ module.exports = {
|
|||||||
const myval = value.toString();
|
const myval = value.toString();
|
||||||
return myval.charAt(0).toUpperCase() + myval.slice(1);
|
return myval.charAt(0).toUpperCase() + myval.slice(1);
|
||||||
},
|
},
|
||||||
|
truncateString(str, maxLength) {
|
||||||
|
if (str.length > maxLength) {
|
||||||
|
return str.slice(0, maxLength) + '...';
|
||||||
|
} else {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
removeSpanAndDivTags(text) {
|
||||||
|
// Rimozione dei tag <span> e </span> dalla stringa di testo
|
||||||
|
const spanRegex = /<span[^>]*>|<\/span>/gi;
|
||||||
|
const cleanedText = text.replace(spanRegex, '');
|
||||||
|
|
||||||
|
// Rimozione dei tag <div> e </div> dalla stringa di testo
|
||||||
|
const divRegex = /<div[^>]*>|<\/div>/gi;
|
||||||
|
const finalText = cleanedText.replace(divRegex, '');
|
||||||
|
|
||||||
|
return finalText;
|
||||||
|
},
|
||||||
|
|
||||||
firstchars(value, numchars = 200, continua, link) {
|
firstchars(value, numchars = 200, continua, link) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let truncatedValue = value;
|
value = this.convertHTMLTagsForTelegram(value);
|
||||||
// Controllo se la lunghezza della stringa è maggiore di numchars
|
value = this.removeSpanAndDivTags(value);
|
||||||
if (value.length > numchars) {
|
truncatedValue = this.truncateString(value, numchars);
|
||||||
// Tronca la stringa alla lunghezza specificata, mantenendo i tag HTML
|
|
||||||
const tags = [];
|
|
||||||
let openTag = false;
|
|
||||||
for (let i = 0, count = 0; i < value.length && count < numchars; i++) {
|
|
||||||
if (value[i] === '<') {
|
|
||||||
openTag = true;
|
|
||||||
} else if (value[i] === '>') {
|
|
||||||
openTag = false;
|
|
||||||
}
|
|
||||||
if (!openTag) {
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
truncatedValue = value.substring(0, i + 1);
|
|
||||||
}
|
|
||||||
// Aggiungi il testo aggiuntivo per indicare il troncamento
|
// Aggiungi il testo aggiuntivo per indicare il troncamento
|
||||||
if (continua) {
|
if (continua) {
|
||||||
if (link) {
|
if (link) {
|
||||||
@@ -4273,13 +4279,42 @@ module.exports = {
|
|||||||
} else {
|
} else {
|
||||||
truncatedValue += ' ...';
|
truncatedValue += ' ...';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return truncatedValue;
|
return truncatedValue;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
convertHTMLTagsForTelegram(text) {
|
||||||
|
const htmlTagsMap = {
|
||||||
|
'<font': '<span',
|
||||||
|
'</font>': '</span>',
|
||||||
|
'<i>': '',
|
||||||
|
'</i>': '',
|
||||||
|
'<u>': '',
|
||||||
|
'</u>': '',
|
||||||
|
};
|
||||||
|
|
||||||
|
// Sostituzione dei tag HTML con quelli Markdown supportati da Telegram
|
||||||
|
let convertedText = text;
|
||||||
|
for (const htmlTag in htmlTagsMap) {
|
||||||
|
const regex = new RegExp(htmlTag, 'g');
|
||||||
|
convertedText = convertedText.replace(regex, htmlTagsMap[htmlTag]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return convertedText;
|
||||||
|
},
|
||||||
|
|
||||||
|
removeFontTags(text) {
|
||||||
|
// Rimozione dei tag <font> e </font> dalla stringa di testo
|
||||||
|
const regex = /<font[^>]*>|<\/font>/gi;
|
||||||
|
const cleanedText = text.replace(regex, '');
|
||||||
|
|
||||||
|
return cleanedText;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
removeAtChar(mystr) {
|
removeAtChar(mystr) {
|
||||||
if (mystr && mystr[0] === '@') {
|
if (mystr && mystr[0] === '@') {
|
||||||
return mystr = mystr.substring(1);
|
return mystr = mystr.substring(1);
|
||||||
@@ -4593,15 +4628,6 @@ module.exports = {
|
|||||||
contributo = myrec.contribstr;
|
contributo = myrec.contribstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nuovo) {
|
|
||||||
if (tablerec === shared_consts.TABLES_MYGOODS) {
|
|
||||||
newdescr = i18n.__('NEW_GOOD', userorig, mydescr);
|
|
||||||
} else if (tablerec === shared_consts.TABLES_MYSKILLS) {
|
|
||||||
newdescr = i18n.__('NEW_SERVICE', userorig, mydescr);
|
|
||||||
} else if (tablerec === shared_consts.TABLES_MYHOSPS) {
|
|
||||||
newdescr = i18n.__('NEW_HOSP', userorig, mydescr);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (tablerec === shared_consts.TABLES_MYGOODS) {
|
if (tablerec === shared_consts.TABLES_MYGOODS) {
|
||||||
newdescr = i18n.__('Good', userorig, mydescr);
|
newdescr = i18n.__('Good', userorig, mydescr);
|
||||||
} else if (tablerec === shared_consts.TABLES_MYSKILLS) {
|
} else if (tablerec === shared_consts.TABLES_MYSKILLS) {
|
||||||
@@ -4609,7 +4635,6 @@ module.exports = {
|
|||||||
} else if (tablerec === shared_consts.TABLES_MYHOSPS) {
|
} else if (tablerec === shared_consts.TABLES_MYHOSPS) {
|
||||||
newdescr = i18n.__('Hosp', userorig, mydescr);
|
newdescr = i18n.__('Hosp', userorig, mydescr);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
let cat = '';
|
let cat = '';
|
||||||
let status = '';
|
let status = '';
|
||||||
let online = false;
|
let online = false;
|
||||||
@@ -4644,7 +4669,9 @@ module.exports = {
|
|||||||
|
|
||||||
let note = this.convertHTMLTagsToText(myrec.note)
|
let note = this.convertHTMLTagsToText(myrec.note)
|
||||||
|
|
||||||
let descrcontent = this.firstchars(this.removeLastSpaceAndACapo(note), 175, true, url);
|
let descrcontent = this.firstchars(this.removeLastSpaceAndACapo(note), 400, true, url);
|
||||||
|
|
||||||
|
// descrcontent = '<span size="3"><b>Prova Pao</b> Ciaooo</span>';
|
||||||
|
|
||||||
if (descrcontent)
|
if (descrcontent)
|
||||||
out += this.addRowTelegram('📝', 'Descrizione ' + newdescr, descrcontent, true);
|
out += this.addRowTelegram('📝', 'Descrizione ' + newdescr, descrcontent, true);
|
||||||
@@ -4674,6 +4701,8 @@ module.exports = {
|
|||||||
|
|
||||||
out += this.addRowTelegram('', `👉🏻 Vedi Annuncio completo su RISO`, url, true, true);
|
out += this.addRowTelegram('', `👉🏻 Vedi Annuncio completo su RISO`, url, true, true);
|
||||||
|
|
||||||
|
console.log('out', out);
|
||||||
|
|
||||||
// out += i18n.__('ADDED_FROM', );
|
// out += i18n.__('ADDED_FROM', );
|
||||||
|
|
||||||
return { newdescr, newdescrtelegram: out }
|
return { newdescr, newdescrtelegram: out }
|
||||||
|
|||||||
Reference in New Issue
Block a user