Skip to content

Commit

Permalink
fixes of lang filtering & posts showning, of localization, especially…
Browse files Browse the repository at this point in the history
… for de,fr,ru,zh, option for autoupdating of TopTrends, UPD of SASS for nin
  • Loading branch information
Simon Grim committed Mar 27, 2015
1 parent 81111a7 commit e1fd570
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 144 deletions.
9 changes: 5 additions & 4 deletions js/interface_home.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ var InterfaceFunctions = function()
}

setTimeout(updateTrendingHashtags, 1000);
setInterval(updateTrendingHashtags, 120*1000); // FIXME should be an option for this
if ($.Options.getTopTrendsAutoUpdateOpt() === 'enable' && $.Options.getTopTrendsAutoUpdateTimerOpt() > 0)
setInterval(updateTrendingHashtags, $.Options.getTopTrendsAutoUpdateTimerOpt()*1000);
}
};

Expand All @@ -133,9 +134,9 @@ function updateTrendingHashtags() {
$('.toptrends-list').empty();
//console.log('hashtags trends: '+ret);
for( var i = 0; i < ret.length; i++ ) {
if ($.Options.getFilterLangForTopTrendsOpt())
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangForTopTrendsOpt())
var langFilterData = filterLang(ret[i]);
if (!$.Options.getFilterLangForTopTrendsOpt() || langFilterData['pass'] || $.Options.getFilterLangSimulateOpt()) {
if (typeof(langFilterData) === 'undefined' || langFilterData['pass'] || $.Options.getFilterLangSimulateOpt()) {
var $li = $('<li>');
var hashtagLinkTemplate = $('#hashtag-link-template').clone(true);

Expand All @@ -144,7 +145,7 @@ function updateTrendingHashtags() {
hashtagLinkTemplate.text('#'+ret[i]);

$li.append(hashtagLinkTemplate);
if ($.Options.getFilterLangSimulateOpt()) {
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangSimulateOpt()) {
if (typeof(langFilterData) !== 'undefined') {
$li.append(' <span class="langFilterSimData"><em>'+((langFilterData['pass']) ? polyglot.t('passed') : polyglot.t('blocked'))+'</em>: '+langFilterData['prob'][0].toString()+'</span>');
} else {
Expand Down
161 changes: 113 additions & 48 deletions js/interface_localization.js

Large diffs are not rendered by default.

71 changes: 40 additions & 31 deletions js/mobile_abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,44 +489,53 @@ var MAL = function()
jQuery.MAL = new MAL;

function filterLang(string) {
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangListOpt().length > 0) {
var langFilterAccuracy = $.Options.getFilterLangAccuracyOpt();
var langFilterList = $.Options.getFilterLangListOpt();
var langFilterMode = $.Options.getFilterLangOpt();

if (langFilterMode !== 'disable') {
var langFilterSubj = '';
var langFilterProb = [];
var langFilterPass = ($.Options.getFilterLangOpt() === 'whitelist') ? false : true;
var langFilterReason = polyglot.t('this doesnt contain that', {'this': polyglot.t($.Options.getFilterLangOpt()), 'that': polyglot.t('language of this')});

// before detection attempts we cut out any mentions and links, and replace _ with space
langFilterSubj = string.replace(/@\S\w*|https?:\/\/\S*/g, '').replace(/_+/g, ' ')
// replace zero-width word boundaries, such as between letters from different alphabets [or other symbols], with spaces
// FIXME not so good idea because 'Za pomocą białej listy' may turn into 'Za pomoc ą bia ł ej listy' for e.g.
// FIXME but first one was recognized as 'hrv' and second as 'pol' and you know it's 'pol' actually
.replace(/\b/g, ' ')
// cut out some more symbols
.replace(/[#\[\]\(\)\{\}\-\+\=\^\:\;\\\/]/g, '')
// clear unwanted spaces
.replace(/\s+/g, ' ').trim();

langFilterProb = franc.all(langFilterSubj, {'minLength': 2}); // FIXME minLength may become configurable option at some time
for (var i = 0; i < langFilterProb.length; i++) {
if (langFilterProb[i][1] > langFilterAccuracy) {
if (langFilterProb[i][0] === 'und') { // e.g. digits-only string will be detected as undefined and thereby will be allowed
langFilterPass = true;
langFilterReason = polyglot.t('its undefined language');
break;
} else if (langFilterList.indexOf(langFilterProb[i][0]) > -1) {
if ($.Options.getFilterLangOpt() === 'whitelist') {
var langFilterPass = true;
var langFilterReason = '';
var langFilterList = $.Options.getFilterLangListOpt();

if (langFilterList.length > 0) {
var langFilterAccuracy = $.Options.getFilterLangAccuracyOpt();
langFilterPass = (langFilterMode === 'whitelist') ? false : true;
langFilterReason = polyglot.t('this doesnt contain that', {'this': polyglot.t(langFilterMode), 'that': polyglot.t('language of this')});

// before detection attempts we cut out any mentions and links, and replace _ with space
langFilterSubj = string.replace(/@\S\w*|https?:\/\/\S*/g, '').replace(/_+/g, ' ')
// replace zero-width word boundaries, such as between letters from different alphabets [or other symbols], with spaces
// FIXME not so good idea because 'Za pomocą białej listy' may turn into 'Za pomoc ą bia ł ej listy' for e.g.
// FIXME but first one was recognized as 'hrv' and second as 'pol' and you know it's 'pol' actually
.replace(/\b/g, ' ')
// cut out some more symbols
.replace(/[#\[\]\(\)\{\}\-\+\=\^\:\;\\\/]/g, '')
// clear unwanted spaces
.replace(/\s+/g, ' ').trim();

langFilterProb = franc.all(langFilterSubj, {'minLength': 2}); // FIXME minLength may become configurable option at some time
for (var i = 0; i < langFilterProb.length; i++) {
if (langFilterProb[i][1] > langFilterAccuracy) {
if (langFilterProb[i][0] === 'und') { // e.g. digits-only string will be detected as undefined and thereby will be allowed
langFilterPass = true;
langFilterReason = polyglot.t('its this, whitelisted', {'this': '\''+langFilterProb[i][0]+'\''});
break;
} else {
langFilterPass = false;
langFilterReason = polyglot.t('its this, blacklisted', {'this': '\''+langFilterProb[i][0]+'\''});
langFilterReason = polyglot.t('its undefined language');
break;
} else if (langFilterList.indexOf(langFilterProb[i][0]) > -1) {
if (langFilterMode === 'whitelist') {
langFilterPass = true;
langFilterReason = polyglot.t('its this, whitelisted', {'this': '\''+langFilterProb[i][0]+'\''});
break;
} else {
langFilterPass = false;
langFilterReason = polyglot.t('its this, blacklisted', {'this': '\''+langFilterProb[i][0]+'\''});
break;
}
}
}
}
} else {
langFilterReason = polyglot.t('this is undefined', {'this': polyglot.t(langFilterMode)});
}

//console.log('langFilter | status: '+((langFilterPass === true) ? polyglot.t('passed') : polyglot.t('blocked'))+' | reason: '+langFilterReason+' | subject: \''+langFilterSubj+'\'');
Expand Down
62 changes: 47 additions & 15 deletions js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ var TwisterOptions = function()

this.setTestDesktopNotif = function() {
$('#testDesktopNotif').on('click', function() {
$.MAL.showDesktopNotif(false, polyglot.t('notify_desktop_test'), false,'twister_notification_test', false, false, function() { alert(polyglot.t('notify_desktop_perm_denied')) })
$.MAL.showDesktopNotif(false, polyglot.t('notify_desktop_test'), false,'twister_notification_test', false, false, function() { alert(polyglot.t('notify_desktop_perm_denied', {'this_domain': document.domain})) })
})
}

Expand Down Expand Up @@ -372,6 +372,36 @@ var TwisterOptions = function()
});
}

this.getTopTrendsAutoUpdateOpt = function() {
return this.getOption('TopTrendsAutoUpdate', 'enable');
}

this.setTopTrendsAutoUpdateOpt = function () {
function TopTrendsAutoUpdateCfg() {
if ($.Options.getTopTrendsAutoUpdateOpt() === 'enable') {
$('#TopTrendsAutoUpdateOpt')[0].style.display= 'inline';
} else {
$('#TopTrendsAutoUpdateOpt')[0].style.display= 'none';
}
}
$('#TopTrendsAutoUpdate').val(this.getTopTrendsAutoUpdateOpt());
TopTrendsAutoUpdateCfg();
$('#TopTrendsAutoUpdate').on('change', function() {
$.Options.setOption(this.id, this.value);
TopTrendsAutoUpdateCfg();
});
}

this.getTopTrendsAutoUpdateTimerOpt = function () {
return parseInt(this.getOption('TopTrendsAutoUpdateTimer', '120'));
}

this.setTopTrendsAutoUpdateTimerOpt = function () {
$('#TopTrendsAutoUpdateTimer')[0].value = this.getTopTrendsAutoUpdateTimerOpt().toString();

$('#TopTrendsAutoUpdateTimer').on('keyup', function () {setElemValNumeric(this, polyglot.t('second(s)'));});
}

this.getSplitPostsOpt = function (){
return $.Options.getOption('splitPosts', 'disable');
}
Expand Down Expand Up @@ -435,7 +465,7 @@ var TwisterOptions = function()
};

this.getFilterLangOpt = function() {
return $.Options.getOption('filterLang','disable');
return this.getOption('filterLang','disable');
}

this.setFilterLangOpt = function () {
Expand All @@ -455,7 +485,7 @@ var TwisterOptions = function()
}

this.getFilterLangListOpt = function () {
return $.Options.getOption('filterLangList', '').replace(/\s+/g, '').split(/\s*,\s*/);
return this.getOption('filterLangList', '').replace(/\s+/g, '').split(/\s*,\s*/);
}

this.setFilterLangListOpt = function () {
Expand All @@ -465,7 +495,7 @@ var TwisterOptions = function()
}

this.getFilterLangAccuracyOpt = function () {
return parseFloat($.Options.getOption('filterLangAccuracy', '0.82'));
return parseFloat(this.getOption('filterLangAccuracy', '0.82'));
}

this.setFilterLangAccuracyOpt = function () {
Expand All @@ -478,41 +508,41 @@ var TwisterOptions = function()
}

this.getFilterLangForPostboardOpt = function () {
return $.Options.getOption('filterLangForPostboard', true);
return this.getOption('filterLangForPostboard', true);
}

this.setFilterLangForPostboardOpt = function () {
$('#filterLangForPostboard').prop('checked', $.Options.getFilterLangForPostboardOpt());
$('#filterLangForPostboard').prop('checked', this.getFilterLangForPostboardOpt());

$('#filterLangForPostboard').on('click', function () {$.Options.setOption(this.id, this.checked);});
}

this.getFilterLangForSearchingOpt = function () {
return $.Options.getOption('filterLangForSearching', true);
return this.getOption('filterLangForSearching', true);
}

this.setFilterLangForSearchingOpt = function () {
$('#filterLangForSearching').prop('checked', $.Options.getFilterLangForSearchingOpt());
$('#filterLangForSearching').prop('checked', this.getFilterLangForSearchingOpt());

$('#filterLangForSearching').on('click', function () {$.Options.setOption(this.id, this.checked);});
}

this.getFilterLangForTopTrendsOpt = function () {
return $.Options.getOption('filterLangForTopTrends', true);
return this.getOption('filterLangForTopTrends', true);
}

this.setFilterLangForTopTrendsOpt = function () {
$('#filterLangForTopTrends').prop('checked', $.Options.getFilterLangForTopTrendsOpt());
$('#filterLangForTopTrends').prop('checked', this.getFilterLangForTopTrendsOpt());

$('#filterLangForTopTrends').on('click', function () {$.Options.setOption(this.id, this.checked);});
}

this.getFilterLangSimulateOpt = function () {
return $.Options.getOption('filterLangSimulate', false);
return this.getOption('filterLangSimulate', true);
}

this.setFilterLangSimulateOpt = function () {
$('#filterLangSimulate').prop('checked', $.Options.getFilterLangSimulateOpt());
$('#filterLangSimulate').prop('checked', this.getFilterLangSimulateOpt());

$('#filterLangSimulate').on('click', function () {$.Options.setOption(this.id, this.checked);});
}
Expand Down Expand Up @@ -561,6 +591,8 @@ var TwisterOptions = function()
this.setConvertFractionsOpt();
this.setUseProxyOpt();
this.setUseProxyForImgOnlyOpt();
this.setTopTrendsAutoUpdateOpt();
this.setTopTrendsAutoUpdateTimerOpt();
this.setSplitPostsOpt();
this.setHideRepliesOpt();
this.setHideCloseRTsHourOpt();
Expand All @@ -578,13 +610,13 @@ var TwisterOptions = function()

function setElemValNumeric(elem, mes) {
//var elem = $(elem_nm);
if (/^\d+$/.test(elem.value)) {
if (/^\d+$/.test(elem.value) && parseFloat(elem.value) > 0) {
elem.style.backgroundColor = '';
$.Options.setOption(elem.id, elem.value);
$(elem).next('span').text(mes);
} else {
elem.style.backgroundColor = '#f00';
$(elem).next('span').text(polyglot.t('only numbers are allowed!'));
$(elem).next('span').text(polyglot.t('only positive numbers!'));
}
};
}
Expand All @@ -597,7 +629,7 @@ function localizeLabels()
$("label[for=t-2]").text(polyglot.t("Theme"));
$("label[for=t-3]").text(polyglot.t("Notifications"));
$("label[for=t-4]").text(polyglot.t("Keys"));
$("label[for=t-5]").text(polyglot.t("Postboard"));
$("label[for=t-5]").text(polyglot.t("Appearance"));
$("label[for=t-6]").text(polyglot.t("Users"));
}

Expand Down
2 changes: 1 addition & 1 deletion js/twister_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function processHashtag(postboard, hashtag, data) {
if( !(key in _hashtagProcessedMap) ) {
_hashtagProcessedMap[key] = true;

if ($.Options.getFilterLangForSearchingOpt()) {
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangForSearchingOpt()) {
if (typeof(userpost['rt']) !== 'undefined') {
var msg = userpost['rt']['msg'];
} else {
Expand Down
9 changes: 7 additions & 2 deletions js/twister_formatpost.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,16 @@ function postToElem( post, kind, promoted ) {
if (typeof(promoted) !== 'undefined' && promoted) {
elem.find('.post-propagate').remove();
} else {
if ($.Options.getFilterLangSimulateOpt()) {
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangSimulateOpt()) {
// FIXME it's must be stuff from template actually
if (typeof(post['langFilter']) !== 'undefined') {
if (typeof(post['langFilter']['prob'][0]) !== 'undefined')
var mlm = ' // '+polyglot.t('Most possible language: this', {'this': '<em>'+post['langFilter']['prob'][0].toString()+'</em>'});
else
var mlm = '';

elem.append('<div class="langFilterSimData">'+polyglot.t('This post is treated by language filter', {'treated': '<em>'+((post['langFilter']['pass']) ? polyglot.t('passed') : polyglot.t('blocked'))+'</em>'})+'</div>');
elem.append('<div class="langFilterSimData">'+polyglot.t('Reason: this', {'this': '<em>'+post['langFilter']['reason']+'</em>'})+' // '+polyglot.t('Most possible language: this', {'this': '<em>'+post['langFilter']['prob'][0].toString()+'</em>'})+'</div>');
elem.append('<div class="langFilterSimData">'+polyglot.t('Reason: this', {'this': '<em>'+post['langFilter']['reason']+'</em>'})+mlm+'</div>');
} else {
elem.append('<div class="langFilterSimData">'+polyglot.t('This post is treated by language filter', {'treated': '<em>'+polyglot.t('not analyzed')+'</em>'})+'</div>');
}
Expand Down
22 changes: 5 additions & 17 deletions js/twister_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,12 @@ function showPosts(req, posts)
break;
}
}
if( j == streamItems.length ) {
// no older posts in stream, so post is to be inserted below
if( req.mode == "older" || req.mode == "latestFirstTime" ) {
// note: when filling gaps, the post must be discarded (not
// shown) since it can never be older than what we already
// have on timeline. this is a problem due to requesting from
// several users at the same time, as some older posts might
// be included to complete the <count> in getposts because
// other users may have already been excluded by since_id.
streamItemsParent.append( streamPost );
streamPostAppended = true;
}
}
}
if (!streamPostAppended)
streamItemsParent.append( streamPost );

if( streamPostAppended ) {
streamPost.show();
}
streamPostAppended = true;
streamPost.show();
req.reportProcessedPost(post["userpost"]["n"],post["userpost"]["k"], streamPostAppended);
}
}
Expand Down Expand Up @@ -390,7 +378,7 @@ function willBeHidden(post){
}
}

if ($.Options.getFilterLangForPostboardOpt()) {
if ($.Options.getFilterLangOpt() !== 'disable' && $.Options.getFilterLangForPostboardOpt()) {
post['langFilter'] = filterLang(msg);
if (!post['langFilter']['pass'] && !$.Options.getFilterLangSimulateOpt()) {
// TODO maybe we need a counter of posts blocked by language filter and even caching of them and button to show?
Expand Down

0 comments on commit e1fd570

Please sign in to comment.