';
return html;
}
},
growth : function(stats)
{
// If free account
if ( stats.stats_acc_id == 0 )
{
var html = ''+
'
'+
'
Due to resource limitations we are unable to offer detailed statistics for free plans. For in-depth statistics please upgrade to one of our great value paid plans.
';
return html;
},
addTwitterStream : function(title,button,streamId)
{
var icon = '';
var autoPollOnly = false;
var sel = 'selected';
var auto_poll = '';
var pi = 2;
if ( streamId !== undefined )
{
auto_poll = tm.twitter.loadedStreams[streamId].auto_poll==1?'checked':'';
pi = tm.twitter.loadedStreams[streamId].poll_interval;
switch(tm.twitter.loadedStreams[streamId].type)
{
case 'new-followers':;
case 'new-listings':;
case 'folks-i-follow':;
case 'tweets-at-me':;
case 'retweets-of-me':;
case 'dms-and-ats':;
case 'my-tweets':;
icon = ' ';
autoPollOnly = true;
break;
case 'dms-sent-to-me':;
case 'dms-sent-by-me':;
icon = ' ';
autoPollOnly = true;
break;
default:;
title = 'Edit Twitter Stream';
icon = ' ';
break;
}
}
var myListsHtml = '';
if ( tm.twitter.myLists !== false )
{
myListsHtml += '';
for ( i in tm.twitter.myLists )
{
myListsHtml += '';
}
}
var html = ''+
'
';
return html;
},
'group' : function(tweetId)
{
var html = ''+
'
'+
''+
''+
''+
''+
''+
''+
''+
''+
''+
'
';
return html;
}
},
makeFeedScheduleDropDown : function(storyId)
{
var html = ''+
'
'+
''+
''+
'
';
return html;
},
scheduleByTime : function(storyId)
{
var d = new Date();
var h = d.getHours();
var m = d.getMinutes();
var p = 'pm';
var sel = 'selected';
if ( h < 12 ) p = 'am';
// Makes sure hour is 0 padded & string
if ( h == 0 ) h = 12;
else if ( h > 12 ) h = h - 12;
// Rounds minutes to nearest 5 (and pads)
m = Math.round(parseInt(m)/5)*5
var html = ''+
'
'+
'Day: '+
' Time: '+
''+
''+
'
'+
' '+
(
storyId !== undefined
?
' '
:
' '
)+
'
'+
'
';
return html;
},
reScheduleByTime : function(storyId, hours, minutes, month, day, $year)
{
// I am just duplicating the function above "scheduleByTime" just to save time and move forward.
var d = new Date();
var h = hours;
var m = minutes;
var p = 'pm';
var sel = 'selected';
if ( h < 12 ) p = 'am';
// Makes sure hour is 0 padded & string
if ( h == 0 ) h = 12;
else if ( h > 12 ) h = h - 12;
// Rounds minutes to nearest 5 (and pads)
m = Math.round(parseInt(m)/5)*5
var html = ''+
'
'+
'Day: '+
' Time: '+
''+
''+
'
'+
' '+
(
storyId !== undefined
?
' '
:
' '
)+
'
'+
'
';
return html;
},
settings :
{
home : function()
{
var html = ''+
'
'+
'
'+
'
'+
'
';
return html;
},
listInfo : function(listInfo)
{
var html = ''+
'
Hint: Hover over left hand column names for a tool tip explaining each item.
'+
'
';
return html;
},
editList : function(listInfo)
{
var html = ''+
'
'+
'
Edit List/Group
'+
'
'+
'
Name:
'+
'
Mode:
'+
'
'+
' '+
'
'+
'
'+
'
Description:
'+
'
'+
''+
'
'+
'
'+
'
'+
'
'+
''+
'
'+
'
'+
'
'+
'
';
return html;
},
newList : function()
{
var html = ''+
'
'+
'
Create New List/Group
'+
'
'+
'
Name:
'+
'
Mode:
'+
'
'+
' '+
'
'+
'
'+
'
Description:
'+
'
'+
''+
'
'+
'
'+
'
'+
'
'+
''+
'
'+
'
'+
'
'+
'
';
return html;
},
manageLists : function()
{
// tm.twitter.myLists =
// [
// '@justinvincent/buds',
// '@justinvincent/tweetminers',
// ];
var myListsHtml = '';
if ( tm.twitter.myLists !== false )
{
for ( i in tm.twitter.myLists )
{
myListsHtml += '
'+tm.twitter.myLists[i]+'
';
}
}
var html = ''+
'
'+
'
My Lists/Groups
'+
'
Click a list to view info.
'+
' '+
'
'+
'
'+
myListsHtml+
'
'+
'
'+
'
'+
'
'+
'
';
return html;
},
info : function()
{
var set = tm.settings.loadedSettings;
var html = ''+
'
Settings are unique to each Twitter account. The current settings apply to @'+tm.accounts.loadedAccounts[tm.accounts.selectedAccount].login+'. Please select a setting on the left to edit.
'+
'
';
return html;
},
timezone : function()
{
var set = tm.settings.loadedSettings;
var html = ''+
'
Important! By selecting the above checkboxes you are NOT turning on/off which service you post to. You ARE selecting which checkboxes will be selected by default when you open a new Tweet dialog.
'+
'
Important! You will be able to post to one (or more) of the above services with each Tweet. You can select where to post on a Tweet by Tweet basis. The above list is for information only and to allow you to specify defaults.
'+
'
'+
'
'+
' '+
' '+
'
'
)+
'
';
return html;
},
bitly : function()
{
var set = tm.settings.loadedSettings;
var html = ''+
'
'+
'
Bit.ly (Short URLs)
'+
'
'+
' '+
' '+
'
'+
'
'+
'
Bit.ly login
'+
'
'+
'
'+
'
Bit.ly API Key
'+
'
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
';
return html;
},
newFollowers : function()
{
var set = tm.settings.loadedSettings;
if ( set.auto_dm_message == null )
{
set.auto_dm_message = 'Thanks for the follow';
}
var html = ''+
'
'+
'
New Follower Automation
'+
'
'+
' '+
' '+
'
'+
'
'+
' '+
' '+
'
'+
'
'+
''+
'
'+
'
Dynamic Fields
'+
'
'+
'You can use the following dynamic fields in your message:'+
'
'+
'
{FIRST_NAME} - Will be replaced with the users first name
'+
'
{LAST_NAME} - Will be replaced with the users last name
'+
'
'+
'
'+
'
'+
' '+
'
'+
'
';
return html;
},
rollingSchedule : function()
{
var set = tm.settings.loadedSettings;
var html = ''+
'
'+
'
Rolling Schedule
'+
'
'+
'Post Tweets every minutes'+
'
'+
'
'+
' '+
' to minutes'+
'
'+
'
'+
'
Post Tweets on the following days:
'+
'
'+
' '+
' '+
' '+
' '+
' '+
' '+
' '+
'
'+
'
'+
'
'+
' '+
'
'+
'
'+
tm.templates.settings.timeWindowFineTune()+
'
'+
'
'+
' '+
'
'+
'
'+
' '+
'
'+
'
'
return html;
},
timeWindowFineTune : function()
{
var s = tm.settings.loadedSettings;
// Need to translate this!!
var days = ['mon','tue','wed','thu','fri','sat','sun'];
var html = '
';
for ( i in days )
{
html += tm.templates.settings.hoursLine
(
days[i],
'tw_'+days[i]+'_on',
s['tw_'+days[i]+'_on'],
'tw_'+days[i]+'_from',
s['tw_'+days[i]+'_from'],
'tw_'+days[i]+'_from_ampm',
s['tw_'+days[i]+'_from_ampm'],
'tw_'+days[i]+'_to',
s['tw_'+days[i]+'_to'],
'tw_'+days[i]+'_to_ampm',
s['tw_'+days[i]+'_to_ampm']
);
}
html += '
';
return html;
},
hoursLine : function(day,cbId,cbState,fromId,fromVal,fromAmpmId,fromAmpmVal,toId,toVal,toAmpmId,toAmpmVal)
{
var html = ''+
'
';
return html;
},
pleaseRead : function()
{
var html = ''+
'
'+
'Important:'+
'
'+
'
Please leave Pluggio open for Friend Finder to work at optimum levels.
'+
'
Please click Follow/Discard for latest suggestions before closing your browser.
'+
'
Pluggio will make a maximum of '+tm.friendFinder.cron.maxSuggestions+' suggestions per account (until Follow or Discard is clicked on those suggestions).
'+
'
With good keywords Pluggio will make about 1000 suggestions (across all accounts) in a 24 hour period.
'+
'
If you are not getting any suggestions make sure that "Other Settings > My current follower-to-friend ratio" is set correctly
'+
'
'+
'
';
return html;
},
activityLog : function()
{
var html = ''+
'
';
}
return html;
},
customSigSetup : function()
{
var html = ''+
'
'+
'customSigSetup'+
'
';
return html;
}
},
pingFm :
{
checkBoxes : function()
{
var html = '';
var s = tm.accounts.loadedAccounts[tm.accounts.selectedAccount].pingFm;
// This builds services
for ( service in s.services )
{
html += ''+
''+
''+
''+
' ';
}
return html;
},
tweetCheckBoxes : function()
{
var html = '
';
var pingFm = tm.accounts.loadedAccounts[tm.accounts.selectedAccount].pingFm;
if ( pingFm !== undefined )
{
if ( pingFm === false || pingFm.services === false )
{
html += ''+
''+
''+
''+
' '+
'
Please add a twitter account (left panel) to get started.
'
);
return;
}
$("#feeds .list").html('
');
// Send to the server and try to create the account
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-feeds'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// If there are no configured twitter accounts
if ( response.feeds == false )
{
$("#feeds .list").html
(
'
To add a feed click the + sign above
'
);
$("#feed-content").addClass('hide');
return;
}
$("#feeds .list").html('');
tm.feeds.numFeeds=0;
// if there ARE feeds
for ( i in response.feeds )
{
if ( i == 0 && tm.feeds.curFeedId[tm.accounts.selectedAccount] === undefined )
{
tm.feeds.curFeedId[tm.accounts.selectedAccount] = response.feeds[i]['feed_id'];
}
// Store loaded feeds for future use in other dialogs etc.
tm.feeds.loadedFeeds[response.feeds[i]['feed_id']] = response.feeds[i];
// Insert item into the list
$("#feeds .list").append
(
tm.templates.feedListItem
(
response.feeds[i]['type'],
response.feeds[i]['name'],
response.feeds[i]['feed_id'],
response.feeds[i]['url_or_search']
)
);
tm.feeds.numFeeds++;
}
$("#feeds .list").sortable('destroy');
$("#feeds .list").sortable
({
stop: function(event, ui)
{
// This gets feedList[]=1&feedList[]=2&feedList[]=3 ready to send to server
tm.feeds.saveOrder($("#feeds .list").sortable('serialize'));
}
});
tm.feeds.selectFeed(tm.feeds.curFeedId[tm.accounts.selectedAccount]);
}
}
);
},
savingOrder : false,
saveOrder : function(feedIds)
{
if ( tm.curView != 'rss' )
{
return;
}
tm.feeds.savingOrder = true;
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'feedIds' : feedIds,
'action' : 'ajax/save-order-feeds'
},
function(response)
{
tm.feeds.savingOrder = false;
if (response.error != 'OK')
{
alert(response.error);
}
}
);
},
openModalAdd : function()
{
if ( tm.accounts.selectedAccount === false )
{
alert("Please add a Twitter account (See the left hand panel on this screen)");
return;
}
if ( tm.feeds.numFeeds >= tm.maxFeeds )
{
if ( _useFreeTrial )
{
alert('If you would like to add more than '+tm.maxFeeds+' feeds please signup to our '+_numTrialDays+' day free trial. No payment required. Cancel any time!');
}
else
{
alert('If you would like to add more than '+tm.maxFeeds+' feeds please signup and try Pluggio for 60 days risk free! Cancel any time!');
}
return;
}
tm.feeds.isNewFeed = true;
var pos = $('#feed-plus-sign').offset();
tm.tools.makeModal(tm.templates.addFeed('Add Feed','Add'),'callout-tl', 305, pos.left-16, pos.top-2);
tm.tools.textFocus('#feed-name');
},
changeInputType : function()
{
switch ( $('#feed-type').val() )
{
case 'rss':;
$('#feed-icon').attr({'src':'/template/gfx/rss.png'});
$('#feed-input-title').text('Location:');
break;
case 'blog':;
$('#feed-icon').attr({'src':'/template/gfx/blog.png'});
$('#feed-input-title').text('Keyword:');
break;
case 'news':;
$('#feed-icon').attr({'src':'/template/gfx/news.png'});
$('#feed-input-title').text('Keyword:');
break;
break;
}
},
unHighlightFeeds : function()
{
$("#feeds .list .list-item").removeClass('selected');
},
highlightFeed : function(feedId)
{
$('#feedList_'+feedId).addClass('selected');
},
selectFeed : function(feedId)
{
if ( tm.feeds.savingOrder )
{
return;
}
tm.feeds.curFeedId[tm.accounts.selectedAccount] = feedId;
tm.feeds.unHighlightFeeds();
tm.feeds.highlightFeed(feedId);
// do it (as long as modal isnt open)
if ( $('#feed-popup').length == 0)
{
tm.feeds.getFeed(feedId);
}
},
openModalEdit : function(feedId)
{
tm.feeds.isNewFeed = false;
// Id the popup will be below the fold
var pos = $('#feedList_' + feedId + ' img').offset();
if ( 180 + pos.top >= $(window).height() )
{
tm.tools.makeModal(tm.templates.addFeed('Edit Feed','Save',feedId),'callout-bl', 305, pos.left-16, pos.top-175);
}
else
{
tm.tools.makeModal(tm.templates.addFeed('Edit Feed','Save',feedId),'callout-tl', 305, pos.left-16, pos.top-2);
}
$('#feed-input').val(tm.feeds.loadedFeeds[feedId]['url_or_search']);
$('#feed-type').val(tm.feeds.loadedFeeds[feedId]['type']);
$('#feed-name').val(tm.feeds.loadedFeeds[feedId]['name']);
$("select#automation_is_on").val(tm.feeds.loadedFeeds[feedId]['automation_is_on']);
$("select#automation_check_every_n_hours").val(tm.feeds.loadedFeeds[feedId]['automation_check_every_n_hours']);
$("select#automation_post_max_per_poll").val(tm.feeds.loadedFeeds[feedId]['automation_post_max_per_poll']);
$('#automation_post_to_rolling').attr('checked', (tm.feeds.loadedFeeds[feedId]['automation_post_to_rolling'] == 1 ? true : false) );
$('#automation_postpend_after_link').attr('checked', (tm.feeds.loadedFeeds[feedId]['automation_postpend_after_link'] == 1 ? true : false) );
$('#force_refresh').attr('checked', (tm.feeds.loadedFeeds[feedId]['force_refresh'] == 1 ? true : false) );
$('#tweet_prepend').val(tm.feeds.loadedFeeds[feedId]['tweet_prepend']);
$('#tweet_postpend').val(tm.feeds.loadedFeeds[feedId]['tweet_postpend']);
$('#tweet_find_replace').val(tm.feeds.loadedFeeds[feedId]['tweet_find_replace']);
$('#automation_post_order').val(tm.feeds.loadedFeeds[feedId]['automation_post_order']);
// This sets the service checkboxes as checked
var sendTo = tm.feeds.loadedFeeds[feedId]['automation_send_posts_to'];
if ( sendTo && sendTo.indexOf(',') > -1 )
{
$('.automation .post-targets input[type=checkbox]').attr('checked',false);
var targets = sendTo.split(',');
for ( i in targets )
{
if ( targets[i] == '' ) continue;
$('.automation #service_'+targets[i]).attr('checked',true);
}
}
tm.feeds.changeInputType();
tm.tools.textFocus('#feed-name');
},
deleteFeed : function(feedId)
{
var name = $('#feed-name').val();
tm.prompt('Sure you want to delete '+name+'?','tm.feeds.doDeleteFeed('+feedId+')');
},
doDeleteFeed : function (feedId)
{
// Send to the server and try to create the account
tm.ajax
(
{
'feedId' : feedId,
'action' : 'ajax/delete-feed'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.tools.closeModal();
tm.tools.closeModal();
tm.feeds.curFeedId[tm.accounts.selectedAccount] = undefined;
tm.feeds.getFeeds();
}
}
);
},
doStarClick : function(storyId)
{
// Mark as not interesting
if ( tm.keyDown == 17 )
{
tm.feeds.markAsNotInteresting(storyId);
}
// Add story to flag feed
else
{
tm.feeds.flagStory(storyId);
}
},
markAsNotInteresting : function(storyId)
{
if ( $('#feedItem'+storyId).hasClass('not-interested') )
{
$('#feedItem'+storyId).removeClass('not-interested');
}
else
{
$('#feedItem'+storyId).addClass('not-interested');
}
setTimeout(function()
{
tm.ajax
(
{
'storyId' : storyId,
'action' : 'ajax/hide-story'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
}
);
},100);
},
flagStory : function(storyId)
{
// Build icon path for alternate bolean state
var iconPath = tm.templates.flaggedIconPath($('#star'+storyId).attr('isFlagged'));
// Apply the new path
$('#star'+storyId).attr({'src':iconPath,'origSrc':iconPath});
// if in the flagged view then remove the item (if it's a remove)
if ( tm.curView == 'flagged' && $('#star'+storyId).attr('isFlagged') == 1 )
{
$('#feedItem'+storyId).remove();
}
setTimeout(function()
{
// Now flag this item
tm.ajax
(
{
'storyId' : storyId,
'action' : 'ajax/flag-story'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( tm.curView == 'flagged' && $("#feed-content .list").text() == '' )
{
tm.nav.go(tm.curView);
return;
}
// Change the isFLagged state so toggle works correctly next time
$('#star'+storyId).attr({'isFlagged': response.isFlagged});
}
}
);
},100);
},
instantTweet : function(storyId)
{
if ( tm.accounts.selectedAccount === false )
{
alert('Please add a Twitter account (See the left hand panel on this screen)');
return;
}
// Build icon path for alternate bolean state
var iconPath = '/template/gfx/bubble-tick.png';
// Apply the new path
$('#bubble'+storyId).attr({'src':iconPath,'origSrc':iconPath});
setTimeout(function()
{
// Now tweet this item
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'storyId' : storyId,
'action' : 'ajax/instant-tweet',
'postTo' : tm.settings.pingFm.getSelectedServices()
},
function(response)
{
if ( response.isInstant == 0 )
{
// Build icon path for alternate bolean state
var iconPath = '/template/gfx/bubble-grey.png';
// Apply the new path
$('#bubble'+storyId).attr({'src':iconPath,'origSrc':iconPath});
}
if (response.error != 'OK')
{
alert(response.error);
}
}
);
}
,100);
},
currentEditUrl : '',
currentEditTweet : '',
openEditTweet : function(storyId)
{
if ( tm.accounts.selectedAccount === false )
{
alert('Please add a Twitter account (See the left hand panel on this screen)');
return;
}
var position = $('#pencil'+storyId).position();
tm.tools.makeModal(tm.templates.feedsTweetDialog(storyId),'callout-bl', 385);
$('#tweet').val('Loading...');
tm.ajax
(
{
'storyId' : storyId,
'action' : 'ajax/get-short-url'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.feeds.currentEditUrl = response.stdUrl;
tm.feeds.currentEditTweet = $('#title'+storyId).text();
$('#tweet').val(tm.feeds.currentEditTweet);
tm.feeds.checkChars();
}
}
);
},
showFindReplaceHelp : function()
{
alert('To find and replace use the == sign. Put the term you want to find on the left, and the replace term on the right. For example:
find this==replace with this
You may enter multiple find and replace rules using one per line. They will be processed in order of appearance.');
},
saveFeedAndClearCache : function(reason)
{
if ( reason == 'automation' )
{
tm.prompt('This will clear the cache and force all current stories returned by the feed to be (re)posted. (Usually the last 10 stories).','tm.feeds.saveFeedAndClearCacheDo()');
}
else if ( reason == 'alter-tweet-text' )
{
tm.prompt('This will clear the feed cache and reapply your new text rules
IMPORTANT! If automation is switched on this will force recently posted stories to be re-posted','tm.feeds.saveFeedAndClearCacheDo()');
}
},
saveFeedAndClearCacheDo : function()
{
tm.tools.closeModal();
tm.feeds.addFeed('saveFeedAndClearCache');
},
checkChars : function()
{
if ( tm.feeds.curTweetTab == 'linkTab' )
{
$('#chars-left').text('');
tm.feeds.currentEditUrl = $('#tweet').val();
}
else
{
setTimeout(function()
{
if ( $('#tweet').length > 0 )
{
var charsLeft = 140 - $('#tweet').val().length;
$('#chars-left').html(charsLeft);
if ( charsLeft >= 0 )
{
$('#chars-left').addClass('enough-chars');
$('#chars-left').removeClass('not-enough-chars');
}
else
{
$('#chars-left').addClass('not-enough-chars');
$('#chars-left').removeClass('enough-chars');
}
tm.feeds.currentEditTweet = $('#tweet').val();
}
},100);
}
},
editStory : function(storyId,editAndTweet)
{
tm.feeds.checkChars();
if ( tm.feeds.currentEditTweet.length > 140 )
{
alert('Tweet Too Long!');
return;
}
// Build icon path for alternate bolean state
if ( editAndTweet !== undefined )
{
var iconPath = '/template/gfx/pencil-tick.png';
var loadingMsg = 'Saving & Tweeting...';
}
else
{
var iconPath = '/template/gfx/pencil-hover.png';
var loadingMsg = 'Saving & Tweeting...';
}
// Apply the new path
$('#pencil'+storyId).attr({'src':iconPath,'origSrc':iconPath});
var editVal = $('#tweet').val();
$('#tweet').val(loadingMsg);
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'editAndTweet' : editAndTweet !== undefined ? true : false,
'storyId' : storyId,
'editVal' : tm.feeds.currentEditTweet,
'action' : 'ajax/edit-story'
},
function(response)
{
if (response.error != 'OK')
{
$('#tweet').val(editVal);
alert(response.error);
}
else
{
$('#title'+storyId+' a').text(unescape(response.editVal));
tm.tools.closeModal();
}
}
);
},
editAndTweetStory : function(storyId)
{
tm.feeds.editStory(storyId,true)
},
curTweetTab : '',
switchTweetTab : function (divObj)
{
tm.feeds.curTweetTab = divObj.id;
$('#tweet-bubble-feeds .tabs div').removeClass('selected');
$(divObj).addClass('selected');
if ( tm.feeds.curTweetTab == 'linkTab' )
{
$('#tweet').val(tm.feeds.currentEditUrl);
$('#editTweetButtons').addClass('hide');
$('#editLinkButtons').removeClass('hide');
}
else
{
$('#tweet').val(tm.feeds.currentEditTweet);
$('#editTweetButtons').removeClass('hide');
$('#editLinkButtons').addClass('hide');
}
tm.feeds.checkChars();
},
editLink : function(storyId)
{
tm.feeds.checkChars();
tm.ajax
(
{
'storyId' : storyId,
'newLink' : tm.feeds.currentEditUrl,
'action' : 'ajax/edit-link'
},
function(response)
{
if (response.error != 'OK')
{
$('#tweet').val(tm.feeds.currentEditUrl);
alert(response.error);
}
else
{
$('#link'+storyId).attr({'href':tm.feeds.currentEditUrl});
tm.feeds.currentEditTweet = unescape(response.tweet) + ' ' + response.shortUrl;
alert('Link updated Successfully');
}
}
);
},
markStoryAsVisited : function (storyId,url)
{
$('#title'+storyId).addClass('is-read');
setTimeout(function()
{
// Now flag this item
tm.ajax
(
{
'storyId' : storyId,
'action' : 'ajax/flag-as-read'
},
function(response)
{
}
);
},100);
},
showScheduleDropDown : function (storyId,imgObj)
{
// If ctrl key is beign clicked, add to rolling schedule
if ( tm.keyDown == 17 || tm.keyDown == 224 )
{
tm.feeds.addToRollingSchedule(storyId);
return;
}
var pos = $(imgObj).offset();
tm.tools.makeModal(tm.templates.makeFeedScheduleDropDown(storyId),'schedule-drop-down-outer',73,pos.left-10,pos.top-46,0);
// This binds a close modal action to the overlay
$('#overlay'+tm.curModal).bind("mouseover", function(e){tm.tools.closeModal();});
},
addToRollingSchedule : function(storyId,postAt)
{
if ( tm.accounts.selectedAccount === false )
{
alert('Please add a Twitter account (See the left hand panel on this screen)');
return;
}
tm.tools.closeModal();
// Build icon path for alternate bolean state
var iconPath = '/template/gfx/clock-'+(postAt===undefined?'hover-rolling':'hover')+'.png';
// Apply the new path
$('#schedule'+storyId).attr({'src':iconPath,'origSrc':iconPath});
setTimeout(function()
{
// Now tweet this item
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'storyId' : storyId,
'action' : 'ajax/schedule-from-feed',
'postAt' : postAt === undefined ? 0 : postAt,
'postTo' : tm.settings.pingFm.getSelectedServices()
},
function(response)
{
if ( response.isScheduled == 0 )
{
// Build icon path for alternate bolean state
var iconPath = '/template/gfx/clock-grey.png';
// Apply the new path
$('#schedule'+storyId).attr({'src':iconPath,'origSrc':iconPath});
}
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( tm.hiddenHints[5] === undefined )
{
// ctrl + click clock instant add to rolling
setTimeout("tm.hint(5)",500);
}
else if ( tm.hiddenHints[7] === undefined )
{
// ctrl + click star to grey out from schedule
setTimeout("tm.hint(7)",500);
}
}
}
);
}
,100);
},
openScheduleByTime : function(storyId)
{
tm.tools.closeModal();
var pos = $('#schedule'+storyId).offset();
tm.tools.makeModal(tm.templates.scheduleByTime(storyId),'callout-tl', 360,pos.left-14,pos.top,0);
$('#datepicker').datepicker
({
changeMonth: true,
changeYear: true,
showOn: 'both',
buttonImage: '/template/gfx/calender.png',
buttonImageOnly: true
});
},
addToTimedSchedule : function(storyId)
{
var postAt = $('#datepicker').val()+' '+$('#hour').val()+':'+$('#minute').val()+' '+$('#ampm').val();
$('#datepicker').datepicker('destroy');
tm.feeds.addToRollingSchedule(storyId,postAt);
}
};
tm.flagged =
{
gettingFlagged : false,
loadedItems : [],
toggleView : function()
{
// Switch to text view
if ( tm.curView == 'flagged' )
{
tm.nav.go('flaggedText');
}
// Switch to standard view
else
{
tm.nav.go('flagged');
}
},
getFlagged : function()
{
if ( tm.feeds.gettingFlagged === true )
{
return;
}
tm.feeds.gettingFlagged = true;
tm.feeds.resetFeedContent();
$("#feed-content").removeClass('hide');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-flagged'
},
function(response)
{
tm.feeds.gettingFlagged = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// Reset the list
$("#feed-content .list").html('');
$("#feed-content .title-bar .title").html
(
''+
' '+
''+response.numItems+' Items Of Interest '+
'(List View)'
);
// If there are no feed results
if ( response.stories === false )
{
$("#feed-content .list").html(tm.templates.nothingFlagged());
return;
}
// if there ARE results
for ( i in response.stories )
{
response.stories[i].alt = ( i % 2 == 0 ? '' : 'alt') ;
$("#feed-content .list").append
(
tm.templates.feedContentItem(response.stories[i])
);
}
$("#hint-bar").html(tm.templates.feedHintBar());
}
}
);
},100);
},
getFlaggedTextView : function()
{
if ( tm.feeds.gettingFlagged === true )
{
return;
}
tm.feeds.gettingFlagged = true;
tm.feeds.resetFeedContent();
$("#feed-content").removeClass('hide');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-flagged'
},
function(response)
{
tm.feeds.gettingFlagged = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
// Reset the list
$("#feed-content .list").html('');
$("#feed-content .title-bar .title").html
(
''+
' '+
''+response.numItems+' Items Of Interest '+
'(Text View)'
);
// If there are no feed results
if ( response.stories === false )
{
$("#feed-content .list").html(tm.templates.nothingFlagged());
return;
}
// Put this div in order to format the text view
$("#feed-content .list").append('');
// if there ARE results
for ( i in response.stories )
{
$("#textarea").val
(
$("#textarea").val()+
unescape(response.stories[i].title)+' '+response.stories[i].short_url+'\n\n'
);
}
}
}
);
},100);
}
};
tm.friendFinder =
{
amGetting : false,
loadedUsers : {},
loadedSettings : {},
maxStubbsUsed : {},
selectedOption : false,
init : function()
{
tm.friendFinder.showNav('recommendedFriends');
tm.friendFinder.selectOption('suggestedFriends');
// Set the nav to display the current counts
tm.friendFinder.followCount(0);
tm.friendFinder.unfollowCount(0);
},
setTitle : function(optionId)
{
var actionLink = '';
if ( optionId == 'suggestedPurges' && parseInt(tm.accounts.loadedAccounts[tm.accounts.selectedAccount].purge_suggest_count) > 0 )
{
actionLink = ' (Un-follow All)';
}
$("#feed-content .title-bar .title").html
(
tm.templates.friendFinder.titles[optionId]
+actionLink
);
},
selectOption : function(optionId)
{
if ( tm.friendFinder.amGetting === true )
{
return;
}
tm.friendFinder.amGetting = true;
tm.friendFinder.unHighlightOptions();
tm.friendFinder.highlightOption(optionId);
tm.feeds.resetFeedContent();
tm.friendFinder.setTitle(optionId);
tm.friendFinder.selectedOption = optionId;
switch(optionId)
{
default:;
case 'suggestedFriends':
tm.friendFinder.getSuggestedFriends();
break;
case 'suggestedPurges':
tm.friendFinder.getSuggestedPurges();
break;
case 'keywordsLocations':
tm.friendFinder.getKeywordsLocations();
break;
case 'generalSettings':
tm.friendFinder.getGeneralSettings();
break;
case 'pleaseRead':
tm.friendFinder.pleaseRead();
break;
case 'activityLog':
tm.friendFinder.getActivityLog();
break;
}
},
pleaseRead : function()
{
tm.friendFinder.amGetting = false;
$("#feed-content .list").html
(
tm.templates.friendFinder.pleaseRead()
);
},
getSuggestions : function(suggestionType)
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-get-suggested-'+suggestionType
},
function(response)
{
tm.friendFinder.amGetting = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( suggestionType == 'friend' && response.followLimitIsHit === true )
{
$("#feed-content .list").html
(
'
'+
'
Oops
'+
'
Twitter has told us they will not allow @' + tm.accounts.loadedAccounts[tm.accounts.selectedAccount].login + ' to follow any more users just now (we will try again in '+response.followLimitReleaseIn+' hours).
'+
'
For more information please see this page on Twitter.
');
return;
}
$('#activity-log .scroller').html('');
for ( i in response.activity )
{
$('#activity-log .scroller').append
(
'
'+
'
'+
response.activity[i].creation_date+
'
'+
response.activity[i].log+
'
'
);
}
}
}
);
},100);
},
showNav : function(navOption)
{
$("#feeds .list").html
(
tm.templates.friendFinder.navOptions()
);
tm.friendFinder.highlightOption(navOption);
},
highlightOption : function(optionId)
{
$('#'+optionId).addClass('selected');
},
unHighlightOptions : function()
{
$("#feeds .list .list-item").removeClass('selected');
},
currentlyEditingFilter : false,
openEditFilter : function(filterId,event)
{
$('.auto-add-filter-list .scroller tr').removeClass('editing-row');
$('#filterRow'+filterId).addClass('editing-row');
tm.friendFinder.currentlyEditingFilter = filterId;
$('#ff-save-button').val('Save Changes');
var keyword = tm.friendFinder.loadedFilters[filterId].keyword;
var myLocation = tm.friendFinder.loadedFilters[filterId].location;
var range = tm.friendFinder.loadedFilters[filterId].distance;
var type = tm.friendFinder.loadedFilters[filterId].auto_add_type;
var isActive = tm.friendFinder.loadedFilters[filterId].is_active;
$('#auto-add-is-active').attr('checked', isActive==1?true:false);
$("#auto-add-range").val(range);
$("#auto-add-type").val(type);
if ( keyword != '' )
{
tm.tools.cleardFields['auto-add-keyword'] = 'is-cleared';
$('#auto-add-keyword').removeClass('fade');
$('#auto-add-keyword').val(keyword);
}
if ( myLocation != '' )
{
tm.tools.cleardFields['auto-add-location'] = 'is-cleared';
$('#auto-add-location').removeClass('fade');
$('#auto-add-location').val(myLocation);
}
},
addFilter : function(event)
{
if ( ! tm.canUseBitly )
{
var count = 0;
for (var k in tm.friendFinder.loadedFilters) ++count;
if ( count >= 5 && tm.friendFinder.currentlyEditingFilter == false )
{
if ( _useFreeTrial )
{
alert('To add more Keywords please signup to our '+_numTrialDays+' day free trial. No payment required. Cancel any time!');
}
else
{
alert('To add more Keywords please signupand try Pluggio for 60 days risk free! Cancel any time!');
}
}
}
if ( ! tm.tools.isFormTrigger(event) )
{
return;
}
var keyword = tm.getVal('auto-add-keyword');
if ( keyword == 'e.g. fly fishing' )
keyword = '';
var myLocation = tm.getVal('auto-add-location');
if ( myLocation == 'zip or place' )
myLocation = '';
var addType = tm.getVal('auto-add-type');
if ( ! tm.friendFinder.validateFilterForm(addType,keyword,myLocation) )
{
return;
}
var origHtml = $('#auto-add-filters').html();
$('#auto-add-filters').html('
');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-add-keyword-location',
'keyword' : keyword,
'location' : myLocation,
'type' : addType,
'isActive' : tm.getVal('auto-add-is-active'),
'range' : tm.getVal('auto-add-range'),
'editFilterId' : tm.friendFinder.currentlyEditingFilter
},
function(response)
{
if (response.error != 'OK')
{
$('#auto-add-filters').html(origHtml);
alert(response.error);
}
else
{
tm.friendFinder.selectOption('keywordsLocations');
tm.friendFinder.cron.loadAllSettings();
}
}
);
},100);
},
validateFilterForm : function(addType,keyword,myLocation)
{
var error = false;
switch(addType)
{
case 'bio':
case 'tweet':
if ( keyword == '' )
error = 'Please enter a keyword';
break;
case 'location':
if ( myLocation == '' )
error = 'Please enter a location';
break;
}
if ( error )
{
alert(error);
return false;
}
return true;
},
deleteFilter : function(filterId,event)
{
tm.prompt('Sure you want to delete this item?','tm.friendFinder.doDeleteFilter('+filterId+')');
},
doDeleteFilter : function(filterId)
{
tm.tools.closeModal();
alert('Deleting item...');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-delete-filter',
'filterId' : filterId
},
function(response)
{
tm.tools.closeModal();
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.friendFinder.selectOption('keywordsLocations');
tm.friendFinder.cron.loadAllSettings();
}
}
);
},100);
},
saveGeneralSettings : function()
{
var parms = {};
var fields =
[
'auto_prune_after_n_days',
// 'auto_prune_if_no_tweet_in_n_days',
'targets_max_days_since_tweet',
'targets_acc_min_days_old',
'targets_max_followers',
'targets_max_friends',
'targets_min_friends',
'targets_min_followers',
'my_min_f_to_f_ratio',
'targets_min_f_to_f_ratio',
'targets_max_f_to_f_ratio',
'auto_add_is_active',
'auto_prune_is_active',
'language_filter',
// 'send_notification_email_friend',
'send_notification_email_purge'
];
// Remove the error status of a field
for ( i in fields )
{
parms[fields[i]] = tm.getVal(fields[i]);
$('#'+fields[i]).removeClass('errorField');
}
/*
* Error testing
*/
var error = false;
var errorField = '';
var rangeTests =
[
['my_min_f_to_f_ratio',0,500],
['auto_prune_after_n_days',1,365],
// ['auto_prune_if_no_tweet_in_n_days',30,365],
['targets_min_f_to_f_ratio',1,500],
['targets_max_f_to_f_ratio',1,500],
['targets_min_friends',1,500],
['targets_max_friends',1,1000000],
['targets_min_followers',1,500],
['targets_max_followers',1,1000000],
['targets_acc_min_days_old',1,365],
['targets_max_days_since_tweet',1,365]
];
// Test that all numerical fields fall within required ranges
for ( i in rangeTests )
{
if ( isNaN(parseInt(parms[rangeTests[i][0]])) || ( parseInt(parms[rangeTests[i][0]]) < rangeTests[i][1] || parseInt(parms[rangeTests[i][0]]) > rangeTests[i][2] ) )
{
errorField = rangeTests[i][0];
error = "Value must be between "+rangeTests[i][1]+" - "+rangeTests[i][2];
break;
}
}
// Check that the between fields lower value is lower!
if ( error == false )
{
var rangeTests =
[
['targets_min_f_to_f_ratio','targets_max_f_to_f_ratio'],
['targets_min_friends','targets_max_friends'],
['targets_min_followers','targets_max_followers'],
];
for ( i in rangeTests )
{
if ( parseInt(parms[rangeTests[i][0]]) >= parseInt(parms[rangeTests[i][1]]) )
{
errorField = rangeTests[i][0];
error = "Value must be smaller than upper range ";
break;
}
}
}
// If error then mark the field as red and popup a notice
if ( error )
{
// Add error status to a field
$('#'+errorField).addClass('errorField');
alert(error);
return;
}
alert('Saving Settings...');
parms['twitAccId'] = tm.accounts.selectedAccount;
parms['action'] = 'ajax/ff-save-general-settings';
setTimeout(function()
{
tm.ajax
(
// big parms obj!
parms,
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
setTimeout(function(){tm.tools.closeModal();},500);
tm.friendFinder.cron.loadAllSettings();
}
}
);
},100);
},
followCount : function(bumpUpDown)
{
if ( bumpUpDown === undefined )
{
bumpUpDown = 0;
}
var fc = tm.friendFinder.cron.suggestionCount[tm.accounts.selectedAccount] + parseInt(bumpUpDown);
var uc = parseInt(tm.accounts.loadedAccounts[tm.accounts.selectedAccount].purge_suggest_count) ;
tm.accounts.loadedAccounts[tm.accounts.selectedAccount].friend_suggest_count = fc;
if ( fc > 0 )
{
$('.follow-count').html(''+fc+'');
}
else
{
$('.follow-count').html('');
}
if ( fc+uc > 0 )
{
$('#new-suggestions').html(''+(fc+uc)+'');
}
else
{
$('#new-suggestions').html('');
}
// This updates the left nav
for ( var twitAccId in tm.accounts.loadedAccounts )
{
var alertCount = tm.friendFinder.cron.suggestionCount[twitAccId] + parseInt(tm.accounts.loadedAccounts[twitAccId].purge_suggest_count);
if ( alertCount > 0 && twitAccId != tm.accounts.selectedAccount )
{
if ( $('#leftNav'+twitAccId+' .alert').length == 0 )
{
$('#leftNav'+twitAccId).append(''+alertCount+'');
}
else
{
$('#leftNav'+twitAccId+' .alert').text(alertCount);
}
}
else
{
$('#leftNav'+twitAccId+' .alert').remove();
}
}
},
unfollowCount : function(bumpUpDown)
{
var uc = parseInt(tm.accounts.loadedAccounts[tm.accounts.selectedAccount].purge_suggest_count) + parseInt(bumpUpDown);
tm.accounts.loadedAccounts[tm.accounts.selectedAccount].purge_suggest_count = uc;
if ( uc > 0 )
$('.unfollow-count').html(''+uc+'');
else
$('.unfollow-count').html('');
},
followAll : function()
{
var twitAccId = tm.accounts.selectedAccount;
tm.feeds.resetFeedContent(true);
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : twitAccId,
'action' : 'ajax/ff-follow-all'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.friendFinder.cron.suggestionCount[twitAccId]=0;
tm.friendFinder.followCount(0);
tm.friendFinder.renderBlankScreen();
}
}
);
},100);
},
unfollowAll : function()
{
tm.feeds.resetFeedContent(true);
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ff-unfollow-all'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.friendFinder.selectOption('suggestedPurges');
tm.accounts.loadedAccounts[tm.accounts.selectedAccount]['purge_suggest_count'] = 0;
tm.friendFinder.unfollowCount(0);
}
}
);
},100);
},
ffAction : function(twitUid,theAction)
{
var twitAccId = tm.accounts.selectedAccount;
if ( theAction == 'follow' || theAction == 'follow-discard' )
{
tm.friendFinder.cron.suggestionCount[twitAccId]--;
tm.friendFinder.followCount(0);
if ( tm.friendFinder.cron.suggestionCount[twitAccId] == 0 )
{
tm.friendFinder.renderBlankScreen();
}
// Remove the pause on processing stubs for this account
if ( tm.friendFinder.maxStubbsUsed[tm.friendFinder.cron.curTwitAccId] !== undefined )
{
delete tm.friendFinder.maxStubbsUsed[tm.friendFinder.cron.curTwitAccId];
}
}
else if ( theAction == 'unfollow' || theAction == 'unfollow-discard' )
{
tm.friendFinder.unfollowCount(-1);
}
$('#ffFollow'+twitUid).remove();
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : twitAccId,
'screenName' : tm.friendFinder.loadedUsers[twitUid].screen_name,
'action' : 'ajax/ff-'+theAction
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
if ( $(".ff-item").length == 0 )
{
if ( theAction == 'follow' || theAction == 'follow-discard' )
{
//tm.friendFinder.selectOption('suggestedFriends');
// Do nothing. All done instantly above
;
}
else if ( theAction == 'unfollow' || theAction == 'unfollow-discard' )
{
tm.friendFinder.selectOption('suggestedPurges');
}
}
}
);
},100);
}
};
tm.friendFinder.cron =
{
maxSuggestions : 100,
isRunning : false,
activeFilter : {},
suggestionCount : {},
stacks :
{
searchResults : {},
processed : {} // don't do this again
},
counts :
{
totalResults : 0,
discarded: 0,
suggested: 0
},
timeouts :
{
// 5 minute = 5*60*1000
filterStackPolls : 30*1000, // 30 seconds (note using search API)
suggestionStackPolls : 40*1000, // 30 seconds
reloadSettingsPolls : 15*60*1000 // 15 minutes
},
locks : {},
init : function()
{
var date = new Date;
tm.friendFinder.cron.startTime = date.getTime();
tm.friendFinder.cron.isRunning = true;
tm.fflog('system> Initialized');
$('#ff-activity').draggable({ handle: '.title' });
setInterval(tm.friendFinder.cron.processFilterStack, tm.friendFinder.cron.timeouts.filterStackPolls);
setInterval(tm.friendFinder.cron.processSuggestionStack, tm.friendFinder.cron.timeouts.suggestionStackPolls);
setInterval(tm.friendFinder.cron.loadAllSettings, tm.friendFinder.cron.timeouts.reloadSettingsPolls);
tm.friendFinder.cron.loadAllSettings();
},
processSuggestionStack : function()
{
tm.trace('* Start: processSuggestionStack()');
var numToProcess = tm.tools.count(tm.friendFinder.cron.stacks.searchResults);
$('#ff-activity .stats .in-queue i').text(numToProcess);
if ( numToProcess > 0 )
{
tm.trace('* '+numToProcess+' suggestions to process');
var stackId = false;
var randStackEntry = Math.floor(Math.random() * ((numToProcess-1) - 0 + 1) + 0);
tm.trace('* randStackEntry: '+randStackEntry);
// Pick one off the stack
var i = 0;
for ( var curStackId in tm.friendFinder.cron.stacks.searchResults )
{
if ( i == randStackEntry )
{
stackId = curStackId;
break;
}
i++;
}
tm.trace('* stackId: '+stackId);
var twitUid = tm.friendFinder.cron.stacks.searchResults[stackId].twitUid;
var twitAccId = tm.friendFinder.cron.stacks.searchResults[stackId].twitAccId;
var screenName = tm.friendFinder.cron.stacks.searchResults[stackId].screenName;
var keyword = tm.friendFinder.cron.stacks.searchResults[stackId].keyword;
var kw_location = tm.friendFinder.cron.stacks.searchResults[stackId].kw_location;
var kw_distance = tm.friendFinder.cron.stacks.searchResults[stackId].kw_distance;
var filterId = tm.friendFinder.cron.stacks.searchResults[stackId].filterId;
delete(tm.friendFinder.cron.stacks.searchResults[stackId]);
tm.trace('* Processing: '+twitAccId+'/'+twitUid);
var logStr = ''+tm.accounts.loadedAccounts[twitAccId].login+'>@'+screenName+' ';
// Move onto processed stack
tm.friendFinder.cron.stacks.processed[stackId] = true;
/*
* Now. Process this mo-fo!
*/
$.twitter.users.show
(
twitUid,
function(data)
{
var settings = tm.friendFinder.loadedSettings[twitAccId];
// What is the follower ratio?
var follower_ratio = 0;
if ( data.followers_count > 0 && data.friends_count > 0 )
{
follower_ratio = Math.round((data.followers_count / data.friends_count)*100);
}
var date = new Date;
var now = date.getTime()
// When was the most recent tweet?
var lastTweetTooLongAgo = false;
if ( data.status!==undefined )
{
var lastTweetParsed = ''+data.status.created_at.replace(/ \d+:\d+:\d+ (\+|-)\d+/,'');
tm.trace('lastTweetParsed: '+lastTweetParsed);
var lastTweet = new Date.parse(lastTweetParsed);
tm.trace(lastTweet);
var minTweetMs = now - (settings.targets_max_days_since_tweet*(((1000*60)*60)*24));
lastTweetTooLongAgo = lastTweet.getTime() < minTweetMs;
}
// When was the account created?
var createdAtParsed = ''+data.created_at.replace(/ \d+:\d+:\d+ (\+|-)\d+/,'');
tm.trace('createdAtParsed: '+createdAtParsed);
var createdAt = new Date.parse(createdAtParsed);
tm.trace(createdAt);
var minCreatedMs = now - (settings.targets_acc_min_days_old*(((1000*60)*60)*24));
var discarded = false;
if ( ! ( createdAt.getTime() < minCreatedMs ) )
{
tm.fflog(logStr+' account too young');
tm.trace('* Discarded: account too young');
tm.trace('* createdAt: '+createdAt.toString());
discarded = true;
}
else if ( data.statuses_count == 0 )
{
tm.fflog(logStr+' never tweeted');
tm.trace('* Discarded: never tweeted');
tm.trace(data);
discarded = true;
}
else if ( lastTweetTooLongAgo )
{
tm.fflog(logStr+' too long since last tweet');
tm.trace('* Discarded: To long since last tweet');
tm.trace('* lastTweet: '+lastTweet.toString());
discarded = true;
}
else if ( ! ( data.friends_count >= parseInt(settings.targets_min_friends) && data.friends_count <= parseInt(settings.targets_max_friends) ) )
{
tm.fflog(logStr+' following too many/few');
tm.trace('* Discarded: bad friends_count');
tm.trace('** friends_count: '+data.friends_count);
tm.trace('** targets_min_friends: '+settings.targets_min_friends);
tm.trace('** targets_max_friends: '+settings.targets_max_friends);
discarded = true;
}
else if ( ! ( data.followers_count >= parseInt(settings.targets_min_followers) && data.followers_count <= parseInt(settings.targets_max_followers) ) )
{
tm.fflog(logStr+' got too many/few followers');
tm.trace('* Discarded: bad followers_count');
tm.trace('** followers_count: '+data.followers_count);
tm.trace('** targets_min_followers: '+settings.targets_min_followers);
tm.trace('** targets_max_followers: '+settings.targets_max_followers);
discarded = true;
}
else if ( ! ( follower_ratio >= parseInt(settings.targets_min_f_to_f_ratio) && follower_ratio <= parseInt(settings.targets_max_f_to_f_ratio) ) )
{
tm.fflog(logStr+' bad follower ratio');
tm.trace('* Discarded: bad follower_ratio');
tm.trace('** follower_ratio: '+follower_ratio);
tm.trace('** targets_min_f_to_f_ratio: '+settings.targets_min_f_to_f_ratio);
tm.trace('** targets_max_f_to_f_ratio: '+settings.targets_max_f_to_f_ratio);
discarded = true;
}
if ( discarded )
{
tm.friendFinder.cron.counts.discarded++;
$('#ff-activity .stats .discarded i').text(tm.friendFinder.cron.counts.discarded);
return;
}
else
{
tm.trace('* If the server says OK then we can add this to the real suggestion stack');
tm.ajax
(
{
'twitAccId' : twitAccId,
'action' : 'ajax/ff-test-suggestion',
'twitUid' : twitUid,
'screenName' : screenName,
'filterId' : filterId
},
function(response)
{
if ( response.error != 'OK' )
{
alert(response.error)
return;
}
else if ( response.isGoodSuggestion == true )
{
tm.trace('Server says: YES');
tm.friendFinder.cron.suggestionCount[twitAccId]++;
tm.fflog(logStr+' good suggestion');
tm.friendFinder.cron.counts.suggested++;
$('#ff-activity .stats .suggested i').text(tm.friendFinder.cron.counts.suggested);
var suggestion =
{
id : twitUid,
screen_name : data.screen_name,
profile_image_url : data.profile_image_url,
location : data.location,
description : data.description,
url : data.url!==null?data.url:'',
followers_count : data.followers_count,
friends_count : data.friends_count,
ff_percent : follower_ratio,
statuses_count : data.statuses_count,
keyword : keyword,
kw_location : kw_location,
kw_distance : kw_distance
};
// Now update the suggestion count for this
tm.friendFinder.followCount();
// If we are in Friend Finder screen and Suggestions is selected
// then pop this to the top bottom the screen
if ( tm.accounts.selectedAccount == twitAccId && tm.curView == 'friendFinder' && tm.friendFinder.selectedOption == 'suggestedFriends' )
{
tm.friendFinder.loadedUsers[suggestion.id] = suggestion;
if ( $("#feed-content .list .hint").length > 0 )
{
$("#feed-content .list").html('');
}
tm.friendFinder.setTitle('suggestedFriends');
$("#feed-content .list").append
(
tm.templates.friendFinder.suggestionContentItem(suggestion,'friend')
);
}
}
else
{
tm.fflog(logStr+' already following/discarded');
tm.friendFinder.cron.counts.discarded++;
$('#ff-activity .stats .discarded i').text(tm.friendFinder.cron.counts.discarded);
tm.trace('Server says: NO');
}
}
);
}
}
); // $.twitter.users.show
}
},
showRunningTime : function()
{
var date = new Date;
var elapsedMinutes = (date.getTime() - tm.friendFinder.cron.startTime)/(1000*60);
var elapsedHours = 0;
var labelText = 'Running: ';
// Minutes
var elapsedText = (Math.round(elapsedMinutes*10)/10) + ' minute';
if ( elapsedMinutes > 1 ) elapsedText += 's';
if ( elapsedMinutes < 1 )
{
elapsedText = 'Less than 1 minute';
}
// Hours
else if ( elapsedMinutes > 60 )
{
elapsedHours = Math.round((elapsedMinutes/60)*10)/10;
elapsedText = elapsedHours + ' hour';
if ( elapsedHours > 1 ) elapsedText += 's';
}
// Days
if ( elapsedMinutes > 60 && elapsedHours > 24 )
{
elapsedDays = Math.round((elapsedHours/24)*10)/10;
elapsedText = elapsedDays + ' day';
if ( elapsedDays > 1 ) elapsedText += 's';
}
$('#ff-activity .clock').text(labelText+elapsedText);
},
processFilterStack : function()
{
// Only process if settings are loaded
if ( tm.friendFinder.cron.loadedFilters && tm.friendFinder.cron.loadedSettings && tm.friendFinder.cron.locks.canProcessFilters )
{
var numResultsToProcess = tm.tools.count(tm.friendFinder.cron.stacks.searchResults);
if ( numResultsToProcess >= 2500 )
{
return;
}
tm.trace('+ In process filter');
tm.friendFinder.cron.locks.canProcessFilters = false;
tm.friendFinder.cron.activeFilter = tm.friendFinder.cron.shuffleAndGetNextFilter();
var filter = tm.friendFinder.cron.activeFilter;
tm.trace('Got filter:');
tm.trace(filter);
var parms =
{
rpp:25
};
tm.trace('filter.keyword = '+filter.keyword);
if ( filter.valid_location == 1)
{
parms['geocode'] = filter.latitude+','+filter.longitude+','+filter.distance+'mi';
tm.trace('geocode = '+parms['geocode']);
}
if ( tm.friendFinder.loadedSettings[filter.twit_acc_id].language_filter != 'any' )
{
parms['lang'] = tm.friendFinder.loadedSettings[filter.twit_acc_id].language_filter;
}
tm.trace('filter.twit_acc_id: '+filter.twit_acc_id);
tm.trace('tm.friendFinder.cron.suggestionCount[filter.twit_acc_id]: '+tm.friendFinder.cron.suggestionCount[filter.twit_acc_id]);
tm.trace('tm.friendFinder.cron.maxSuggestions: '+tm.friendFinder.cron.maxSuggestions);
if ( tm.friendFinder.cron.suggestionCount[filter.twit_acc_id] <= tm.friendFinder.cron.maxSuggestions )
{
$.twitter.search(filter.keyword,tm.friendFinder.cron.popResultsToSuggestionStack,parms);
}
tm.friendFinder.cron.locks.canProcessFilters = true;
}
},
shuffleAndGetNextFilter : function()
{
// Pick random entry from one stack and move to other stack
var numInStack = tm.tools.count(tm.friendFinder.cron.stacks.filters[tm.friendFinder.cron.activeFilterStack]);
tm.trace('+ '+numInStack+' filters left in active stack');
var stackId = false;
var randStackEntry = Math.floor(Math.random() * ((numInStack-1) - 0 + 1) + 0);
tm.trace('+ randStackEntry: '+randStackEntry);
// Pick one off the stack
var i = 0;
for ( var curStackId in tm.friendFinder.cron.stacks.filters[tm.friendFinder.cron.activeFilterStack] )
{
if ( i == randStackEntry )
{
stackId = curStackId;
break;
}
i++;
}
tm.trace('+ stackId: '+stackId);
// Get this filter
var filter = tm.friendFinder.cron.stacks.filters[tm.friendFinder.cron.activeFilterStack][stackId];
// Delete from stack
delete(tm.friendFinder.cron.stacks.filters[tm.friendFinder.cron.activeFilterStack][stackId]);
// Move to other stack
tm.friendFinder.cron.stacks.filters[tm.friendFinder.cron.activeFilterStack=='a'?'b':'a'][stackId] = filter;
// If all filters moved from this stack then set active stack to other stack
if ( numInStack == 1 )
{
tm.friendFinder.cron.activeFilterStack = tm.friendFinder.cron.activeFilterStack=='a'?'b':'a';
}
return filter;
},
loadAllFilters : function()
{
tm.ajax
(
{
'action' : 'ajax/ff-load-all-filters'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else if ( response.allFilters !== false )
{
var alreadyReportedIt = {};
for ( var i in response.allFilters )
{
var twitAccId = response.allFilters[i].twit_acc_id;
var myRatio = tm.friendFinder.loadedSettings[twitAccId].my_ratio;
var minRatio = tm.friendFinder.loadedSettings[twitAccId].my_min_f_to_f_ratio;
var keyword = response.allFilters[i].keyword;
if ( myRatio < minRatio )
{
if ( alreadyReportedIt[twitAccId] === undefined )
{
tm.fflog('system> Not processing @'+tm.accounts.loadedAccounts[twitAccId].login+'. Follower ratio '+myRatio+'% is to low. See "Other Settings" to change.');
alreadyReportedIt[twitAccId] = true;
}
delete(response.allFilters[i]);
}
if ( tm.friendFinder.loadedSettings[twitAccId].follow_limit_is_hit == '1' )
{
delete(response.allFilters[i]);
}
}
var numActiveFilters = tm.tools.count(response.allFilters)
if ( numActiveFilters > 0 )
{
tm.friendFinder.cron.stacks.filters.a = response.allFilters;
tm.fflog('system> Loaded '+tm.tools.count(response.allFilters)+' filters');
tm.friendFinder.cron.loadedFilters = true;
}
else
{
tm.friendFinder.cron.loadedFilters = false;
tm.fflog('system> No active Friend Finder keywords found. Activity stopped.');
}
for ( var twitAccId in tm.friendFinder.loadedSettings )
{
if ( tm.friendFinder.loadedSettings[twitAccId].follow_limit_is_hit == '1' )
{
tm.fflog('system> WARNING! Twitter will not allow @' + tm.accounts.loadedAccounts[twitAccId].login + ' to follow any more users today. Following will be re-instated in '+tm.friendFinder.loadedSettings[twitAccId].follow_limit_release_in+' hours');
}
}
}
else
{
tm.friendFinder.cron.loadedFilters = false;
tm.fflog('system> No active Friend Finder keywords found. Activity stopped.');
}
}
);
},
loadAllSettings : function()
{
tm.friendFinder.cron.loadedFilters = false;
tm.friendFinder.cron.loadedSettings = false;
tm.friendFinder.cron.activeFilterStack = 'a';
tm.friendFinder.cron.stacks.filters = {a :{},b:{}};
tm.friendFinder.cron.locks.canProcessFilters = true;
tm.friendFinder.cron.stacks.searchResults = {};
tm.ajax
(
{
'action' : 'ajax/ff-load-all-settings'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else if ( response.allSettings !== false )
{
tm.friendFinder.loadedSettings = response.allSettings;
var logStr = '';
for ( var twitAccId in tm.friendFinder.loadedSettings )
{
if ( tm.accounts.loadedAccounts[twitAccId] === undefined )
{
tm.fflog('system> Missing account '+twitAccId);
continue;
}
if ( tm.friendFinder.cron.suggestionCount[twitAccId] === undefined )
{
tm.friendFinder.cron.suggestionCount[twitAccId]=0;
}
logStr += ' @' + tm.accounts.loadedAccounts[twitAccId].login + ' ';
}
tm.fflog('system> Loaded settings for'+logStr);
tm.friendFinder.cron.loadedSettings = true;
setTimeout(function()
{
tm.friendFinder.cron.loadAllFilters();
},250);
}
else
{
tm.friendFinder.cron.loadedSettings = false;
tm.fflog('system> No active Friend Finder accounts found. Activity stopped.');
}
}
);
},
popResultsToSuggestionStack : function(data)
{
tm.trace('In popResultsToSuggestionStack');
var filter = tm.friendFinder.cron.activeFilter;
if ( data.results === undefined || data.results[0] === undefined )
{
tm.fflog(''+tm.accounts.loadedAccounts[filter.twit_acc_id].login+'> No results for keyword '+ filter.keyword + ' (bad keyword?)');
return;
}
tm.trace('Number of results: ' + data.results.length);
var popped = 0;
var noPopped = 0;
for ( var i in data.results )
{
var stackId = filter.twit_acc_id+'-'+data.results[i].from_user_id_str;
// This needs to be added to a queue along with the twitAccountId it was associated with
if ( tm.friendFinder.cron.stacks.searchResults[stackId] === undefined && tm.friendFinder.cron.stacks.processed[stackId] === undefined )
{
popped+=1;
tm.friendFinder.cron.stacks.searchResults[stackId] =
{
twitAccId : filter.twit_acc_id,
twitUid : data.results[i].from_user_id_str,
screenName : data.results[i].from_user,
keyword : filter.keyword,
kw_location : filter.location,
kw_distance : filter.distance,
filterId : filter.filter_id
};
}
else
{
noPopped+=1;
}
}
if ( popped > 0 )
{
tm.friendFinder.cron.counts.totalResults += popped;
tm.fflog(''+tm.accounts.loadedAccounts[filter.twit_acc_id].login+'> Found '+ popped +' results for keyword '+ filter.keyword + '');
}
tm.trace('Popped: '+popped+', NO-Popped: '+noPopped);
}
};
tm.twitter =
{
loadedStreams : [],
gettingTweets : false,
streamInfo : [],
curStreamId : [],
loadedUsernames : {},
loadedTweets : {},
lastTweetId : {},
lastSearchPollTweetId : {},
replyToId : false,
directMessageTo : false,
isNewStream : false,
curStreamType: false,
curStreamArgs: false,
amLoadingExtraContent: false,
reachedStreamEnd : false,
streamExists : {},
myLists : false,
tempHiddenStreamItems : [],
origStreamHtml : '',
editingStreamId : false,
nextCursor : '',
streamTitles :
{
'folks-i-follow' : 'Home',
'tweets-at-me' : "@mentions",
'retweets-of-me' : 'ReTweets Of Me',
'dms-and-ats' : "DM's & @'s",
'my-tweets' : 'Tweets I Posted',
'dms-sent-to-me' : 'Direct Mesages (Inbox)',
'dms-sent-by-me' : 'Direct Mesages (Outbox)',
'search' : '',
'favorites' : 'Favorites',
'new-followers' : 'New Followers',
'new-listings' : 'New Listings (Twitter Lists I\'ve Been Added To)'
},
makeStreamTitle : function(streamType,arg1)
{
switch(streamType)
{
case 'search':
var title = tm.twitter.streamTitles[streamType]
var stream = tm.twitter.loadedStreams[tm.twitter.getCurStreamId()];
if ( arg1 != '' )
{
title += ' ' + arg1 + '';
}
if ( stream.geo_distance != 0 )
{
if ( arg1 != '' )
{
title += ' near ';
}
title += ' ' + stream.geo_location + ' ('+stream.geo_distance+'mi) » ';
}
return title;
case 'tweets-at-me':
return 'Tweets Mentioning @'+tm.accounts.loadedAccounts[tm.accounts.selectedAccount].login;
case 'retweets-of-me':
return 'ReTweets of Me';
case 'get-user-timeline':
case 'them-and-me':
return tm.twitter.userTimelineTitleBar(arg1);
case 'group':
return 'Recent tweets'+' @'+arg1;
// In most cases just get it from the titles array
default:
return tm.twitter.streamTitles[streamType];
}
},
userTimelineTitleBar : function(screenName)
{
var html =
'@'+screenName+': '+
'Public Tweets / '+
'Them & Me';
return html;
},
setContentTitle : function(title)
{
$("#feed-content .title-bar .title").html
(
''+
''+
(
tm.twitter.streamExists[tm.twitter.curStreamType+tm.twitter.curStreamArgs] === undefined
?
' '
:
''
)+
' '+
''+
title+
''
);
if ( tm.twitter.autoRefreshHandle !== false )
{
$('#auto-refresh').attr({checked:true});
}
},
// If it's a search no we need to poll twitter directly rather than send to the server
pollTweetsSearch : function(streamId,search)
{
// console.log('debug: pollTweetsSearch -- streamId: '+streamId+' -- search: '+search);
var maxId = tm.twitter.lastSearchPollTweetId[streamId];
var parms = {rpp:20};
// Add in geo-location stuff if required
var stream = tm.twitter.loadedStreams[streamId];
if ( stream.geo_distance != 0 )
{
parms.geocode = stream.geo_latitude+','+stream.geo_longitude+','+stream.geo_distance+'mi';
}
$.twitter.search
(
search,
function(data)
{
if ( maxId !== undefined && maxId != data.max_id_str )
{
// console.log('debug: There was something new: '+data.max_id_str);
var numNew = 0;
for ( var i in data.results )
{
numNew++;
if ( data.results[i].id_str == maxId )
{
break;
}
}
if ( numNew > 0 && ! $('#streamList_'+streamId).hasClass('selected') )
{
var numText = numNew<20?numNew:'20+';
$('#sCount'+streamId).text(numText);
$('#sCount'+streamId).removeClass('hide');
$('
'+numText+' new in '+tm.twitter.loadedStreams[streamId].name+'
').toaster();
var folderId = tm.twitter.loadedStreams[streamId].parent_id;
// If this new item was found inside a closed folder
if ( folderId != 0 && tm.twitter.loadedStreams[folderId].is_closed == 1 )
{
$('#sCount'+folderId).text('NEW');
$('#sCount'+folderId).removeClass('hide');
}
}
}
else if ( maxId == data.max_id_str )
{
// console.log('debug: IDs were the exact same: '+ data.max_id_str);
}
else
{
// console.log('debug: First time load: '+ data.max_id_str);
}
tm.twitter.lastSearchPollTweetId[streamId] = data.max_id_str;
//console.dir(data);
},
parms
);
},
pollTweets : function(streamId,streamType,arg1)
{
// Don't poll tweets if this stream is currently being viewed
if ( tm.twitter.curStreamId == streamId )
{
return;
}
// If a rouge poll is happenign because of switching acounts
if ( tm.twitter.loadedStreams[streamId] === undefined )
{
tm.tools.stopPoll(streamId);
return;
}
// If it's a search no we need to poll twitter directly rather than send to the server
if ( streamType == 'search' )
{
tm.twitter.pollTweetsSearch(streamId,arg1);
return;
}
tm.ajax
(
{
'streamType' : streamType,
'arg1' : arg1 !== undefined && arg1 != false ? arg1 : false,
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/poll-tweets'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
if ( response.isNewTweets == true )
{
$('#sCount'+streamId).text(response.numTweets);
$('#sCount'+streamId).removeClass('hide');
$('
'+response.numTweets+' new in '+tm.twitter.loadedStreams[streamId].name+'
').toaster();
}
else
{
$('#sCount'+streamId).addClass('hide');
}
var folderId = tm.twitter.loadedStreams[streamId].parent_id;
// If this new item was found inside a closed folder
if ( folderId != 0 && tm.twitter.loadedStreams[folderId].is_closed == 1 )
{
if ( response.isNewTweets == true )
{
$('#sCount'+folderId).text('NEW');
$('#sCount'+folderId).removeClass('hide');
}
}
}
}
);
},
jQuery :
{
search : function(query,maxId)
{
var parms = {rpp:20};
if ( maxId !== undefined )
{
parms.max_id = maxId;
}
else
{
tm.twitter.loadedTweets = {};
}
// Add in geo-location stuff if required
var streamId = tm.twitter.getCurStreamId();
var stream = tm.twitter.loadedStreams[streamId];
if ( stream.geo_distance != 0 )
{
parms.geocode = stream.geo_latitude+','+stream.geo_longitude+','+stream.geo_distance+'mi';
}
$.twitter.search(query,tm.twitter.jQuery.doSearchResponse,parms);
},
doSearchResponse : function(data)
{
var tweetIdx = 0;
var tweets = [];
var iBackwards = data.results.length;
for ( var i in data.results )
{
// This stops it from adding duplicate tweets when scrolling back
if ( tm.twitter.loadedTweets[data.results[i].id] === undefined )
{
tweets[tweetIdx] = tm.twitter.jQuery.formatSearchTweet(data.results[i]);
tweetIdx++;
}
}
var response =
{
error : 'OK',
stream : tweets
};
tm.twitter.doGetTweetsResponse
(
tm.twitter.curStreamType,
tm.twitter.curStreamArgs,
tm.twitter.curMaxId,
undefined,
response
);
},
formatSearchTweet : function(tweet)
{
// This removes all the gunk in source
var source = tweet.source.replace(/\<\;a.*\"\;\>\;/gi, '');
source = source.replace('</a>','');
var newTweet =
{
'tweet_type' : 'search',
'date' : prettyDate(tweet.created_at),
'tweet_id' : tweet.id+'',
'tweet' : tm.twitter.jQuery.formatTweetText(tweet.text),
'tweet_text' : tweet.text,
'source' : source,
'user_id' : tweet.from_user_id,
'username' : tweet.from_user,
'realname' : '',
'thumb' : tweet.profile_image_url,
'followers' : 0,
'following' : 0,
'im_following' : 0,
'in_reply_to_status_id' : 0,
'in_reply_to_user_id' : 0,
'to_user_id' : 0,
'to_username' : '',
'to_realname' : '',
'to_thumb' : '',
'to_followers' : 0,
'to_following' : 0,
'f_ratio' : false
};
tm.twitter.curMaxId = tweet.id;
return newTweet;
},
formatTweetText : function(tweet)
{
var words = tweet.split(' ');
var newTweet = '';
for ( var i in words )
{
words[i] = words[i].replace(/(\w+:\/\/[^\s]+)/g,'$1');
words[i] = words[i].replace(/^(\@|\.\@)([A-Za-z0-9_]+)/g,'$1$2');
words[i] = words[i].replace(/^(\#[A-Za-z0-9_-]+)/g,'$1');
newTweet += words[i] + ' ';
}
return newTweet;
}
},
getTweets : function(streamType,arg1,lastTweetId,autoRefresh)
{
if ( tm.feeds.gettingTweets === true )
{
return;
}
tm.twitter.curStreamType = streamType;
tm.twitter.curStreamArgs = arg1;
tm.twitter.curLastTweetId = lastTweetId;
tm.feeds.gettingTweets = true;
tm.nav.setView('twitter');
$("#feed-content").removeClass('hide');
// If we are NOT getting extra tweets from same stream
if ( lastTweetId === undefined )
{
tm.twitter.reachedStreamEnd = false;
tm.feeds.resetFeedContent();
tm.twitter.setContentTitle('Loading...');
}
else
{
// Let the user know we are loading more stuff
$("#feed-content .list").append('
'
);
}
}
);
},100);
}
},
// Note!! This function is called 5 lines above (when the user clicks a link)
helloWorld : function(showError)
{
tm.ajax
(
{
// Specify the location of the ajax script to use
'action' : 'ajax/hello-world',
// Send some arbitary input to the script
'showError' : showError!==undefined?true:false
},
function(response)
{
// response.error will ALWAYS be returned. If not 'OK' then display string
if (response.error != 'OK')
{
alert(response.error);
}
// If no error then work on the good data that was sent back
// it can be response.ANYTHING (it is set on the backend)
else
{
alert(response.myHelloMessage);
}
}
);
},
pingFm :
{
loadSettingsScreen : function()
{
$('#cur-setting').html('
');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ping-fm-get-settings'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.accounts.loadedAccounts[tm.accounts.selectedAccount].pingFm = response.settings;
tm.settings.selectSetting('pingFm');
$('#post-to-panel .scroller').html(tm.templates.pingFm.tweetCheckBoxes());
}
}
);
},100);
},
connect : function()
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'apiKey' : $('#api-key').val(),
'action' : 'ajax/ping-fm-connect'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.settings.pingFm.loadSettingsScreen();
}
}
);
},100);
},
getSelectedServices : function(rootSelector)
{
var s = tm.accounts.loadedAccounts[tm.accounts.selectedAccount].pingFm;
var selectedServices = '';
// Because side panel and root is open at same time
if ( rootSelector === undefined )
{
if ( $('#settings').length > 0 )
{
rootSelector = '#settings';
}
else if ( $('#tweet-bubble').length > 0 )
{
rootSelector = '#tweet-bubble';
}
else if ( $('#post-to-panel').length > 0 )
{
rootSelector = '#post-to-panel';
}
}
rootSelector += ' ';
if ( s === false )
{
selectedServices = 'twitter,';
}
// If there is a dialog with checkboxes then get from that.
else if ( $(rootSelector+'#service_twitter').length > 0 )
{
// Work out which services have been selected as default
for ( service in s.services )
{
if ( $(rootSelector+'#service_'+service).is(':checked') )
{
selectedServices += service + ',';
}
}
}
// If not then take the value from memory
else
{
for ( service in s.services )
{
if ( s.services[service]['selected'] == true )
{
selectedServices += service + ',';
}
}
}
return selectedServices;
},
saveSettings : function()
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'defaultServices' : tm.settings.pingFm.getSelectedServices('#settings'),
'action' : 'ajax/ping-fm-save-settings'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.settings.pingFm.loadSettingsScreen();
}
}
);
},100);
},
unConnect : function()
{
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/ping-fm-unconnect'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.settings.pingFm.loadSettingsScreen();
}
}
);
},100);
}
},
showNav : function(navOption)
{
$("#feeds .list").html
(
tm.templates.settingsNavOptions()
);
tm.settings.highlightOption(navOption);
},
highlightOption : function(optionId)
{
$('#'+optionId).addClass('selected');
},
unHighlightOptions : function()
{
$("#feeds .list .list-item").removeClass('selected');
},
showFineTuneTimes : function()
{
if ( $('#fine-tune-times').hasClass('hide') )
{
$('#fine-tune-times').removeClass('hide');
}
else
{
$('#fine-tune-times').addClass('hide');
}
},
getSettings : function(navOption)
{
if ( tm.settings.gettingSettings === true )
{
return;
}
if ( tm.twitter.myLists === false )
{
tm.twitter.getMyLists();
}
if ( navOption === undefined )
{
navOption = tm.settings.selectedOption;
}
else
{
tm.settings.selectedOption = navOption;
}
tm.settings.showNav(navOption);
tm.settings.gettingSettings = true;
tm.feeds.resetFeedContent();
$("#feed-content").removeClass('hide');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/get-settings'
},
function(response)
{
tm.settings.gettingSettings = false;
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.settings.loadedSettings = response.settings;
// Reset the list
$("#feed-content .list").html('');
$("#feed-content .title-bar .title").html
(
'@'+tm.accounts.loadedAccounts[tm.accounts.selectedAccount].login+' Settings '
);
// Open the settings home
$("#feed-content .list").html
(
tm.templates.settings.home()
);
tm.settings.selectSetting('info');
}
}
);
},100);
},
selectSetting : function(settingTemplate)
{
if ( settingTemplate == 'bitly' && ! tm.canUseBitly )
{
if ( _useFreeTrial )
{
alert('If you would like to use your own bit.ly account when creating short links please signup to our '+_numTrialDays+' day free trial. No payment required. Cancel any time!');
}
else
{
alert('If you would like to use your own bit.ly account when creating short links please signup and try Pluggio for 60 days risk free! Cancel any time!');
}
return;
}
if ( settingTemplate == 'newFollowers' && tm.isFree )
{
alert('If you would like to auto-follow and auto-dm "new followers" please signup and try Pluggio for 60 days risk free! Cancel any time!');
return;
}
$("#cur-setting").html
(
tm.templates.settings[settingTemplate]()
);
if ( settingTemplate == 'rollingSchedule' )
{
tm.settings.setRollingFadeState();
$('#is_randomized_rolling').bind('click',function(){tm.settings.setRollingFadeState();});
}
},
setRollingFadeState : function()
{
if ( ! $('#is_randomized_rolling').attr('checked') )
{
$('.randomize').addClass('fade');
$('.randomize input').addClass('fade');
$('.post-every').removeClass('fade');
$('.post-every input').removeClass('fade');
}
else
{
$('.post-every').addClass('fade');
$('.post-every input').addClass('fade');
$('.randomize').removeClass('fade');
$('.randomize input').removeClass('fade');
}
},
saveBitly : function()
{
alert('Saving...');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'bitlyLogin' : $('#bitly-login').val(),
'bitlyApiKey' : $('#bitly-api-key').val(),
'useMyBitly' : $('#use-my-bitly').attr('checked'),
'action' : 'ajax/save-bitly'
},
function(response)
{
if (response.error != 'OK')
{
tm.tools.closeModal();
alert(response.error);
}
else
{
tm.tools.closeModal();
alert('Bit.ly settings saved successfully');
tm.settings.getSettings();
}
}
);
},100);
},
saveNewFollowers : function()
{
alert('Saving...');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'auto_dm_message' : $('#auto_dm_message').val(),
'auto_follow_new_followers' : $('#auto_follow_new_followers').attr('checked'),
'auto_dm_new_followers' : $('#auto_dm_new_followers').attr('checked'),
'action' : 'ajax/settings-save-new-followers'
},
function(response)
{
if (response.error != 'OK')
{
tm.tools.closeModal();
alert(response.error);
}
else
{
tm.tools.closeModal();
alert('Settings saved successfully');
tm.settings.getSettings();
}
}
);
},100);
},
saveRolling : function()
{
alert('Saving...');
var parms =
{
'twitAccId' : tm.accounts.selectedAccount,
'action' : 'ajax/save-rolling-prefs',
'post_every_n_mins' : $('#post-every').val(),
'rolling_pause' : $('#rolling_pause').attr('checked'),
'is_randomized_rolling' : $('#is_randomized_rolling:checked').attr('checked'),
'rolling_rand_min' : $('#rolling_rand_min').val(),
'rolling_rand_max' : $('#rolling_rand_max').val()
};
var days = ['mon','tue','wed','thu','fri','sat','sun'];
for ( i in days )
{
parms['rolling_'+days[i]] = $('#rolling_'+days[i]).attr('checked');
parms['tw_'+days[i]+'_on'] = $('#tw_'+days[i]+'_on').attr('checked');
parms['tw_'+days[i]+'_from'] = $('#tw_'+days[i]+'_from').val();
parms['tw_'+days[i]+'_from_ampm'] = $('#tw_'+days[i]+'_from_ampm').val();
parms['tw_'+days[i]+'_to'] = $('#tw_'+days[i]+'_to').val();
parms['tw_'+days[i]+'_to_ampm'] = $('#tw_'+days[i]+'_to_ampm').val();
}
setTimeout(function()
{
tm.ajax
(
parms,
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.tools.closeModal();
alert('Rolling Schedule Saved Successfully');
tm.settings.getSettings();
}
}
);
},100);
},
saveTimeZone : function()
{
alert('Saving...');
setTimeout(function()
{
tm.ajax
(
{
'twitAccId' : tm.accounts.selectedAccount,
'timezone' : $('#timezone').val(),
'action' : 'ajax/save-tz-prefs'
},
function(response)
{
if (response.error != 'OK')
{
alert(response.error);
}
else
{
tm.tools.closeModal();
alert('Timezone Saved Successfully');
tm.settings.getSettings();
}
}
);
},100);
}
};
tm.hints =
{
1 : "Power Hint To delete a Twitter account click the to the left of the account name",
2 : "Power Hint To edit or delete a Feed, hover over (//) until it turns into then click the ",
3 : "Power Hint To edit or delete a Stream, hover over (/) until it turns into then click the ",
4 : "Re: the DM's & @'s stream. Twitter allows 150 API calls per hour. The DM's & @'s stream uses 2 calls per view. Call limits are shown in the lower left hand corner.",
5 : "Power Hint To instantly add an item to the rolling schedule (with only one click) hold down CTRL (Command on Macs) and click on (click again to un-schedule)",
6 :"Power Hint You can easily schedule Tweets for future posting by clicking OR (bottom right)",
7 : "Power Hint You can mark a story as dealt with by holding down CTRL and clicking this will strike out the story.",
8 : "Tweet Scheduled Successfully",
9 : "Message Sent Successfully",
10 : "Tweet Posted Successfully",
11 : "Power Hint Pluggio can check for new messages every N minutes - per stream.
Click the icon next to a stream (i.e. \"Direct Inbox\") to turn this feature on.