PDA

View Full Version : Adding a time limit to a code



JRR
02-21-2015, 03:57 PM
I use this code in my headers that stops members from deleting their posts except for staff, is there a way to put a time delay in it? For instance if a member makes a post and within 5 minutes of making the post wants to delete it they can but after that they will not be able to delete it at all.

The code:


<script type="text/javascript">
$(document).ready(function(){
if(!proboards.data('user').is_staff){
$('.options_menu li').each(function(){
if($(this).html().indexOf('Delete Post') != -1)
$(this).remove();
});
}
});
</script>

jscheuer1
02-21-2015, 07:17 PM
Generally that sort of thing is (can be) set in a forum's configuration. So, please double check that you cannot already take care of that in the config.

Now, that said, we can easily delay execution of the code in your post. But that won't distinguish between a user returning to a page where they previously made a post perhaps hours or days ago versus a page where they have just now made a post. You might have a way to do that though (use the above code on a normal page, use the new timed code on the page a user lands on after making a new post). If you can control that, then just add a timeout for the code you wish to delay:


<script type="text/javascript">
$(document).ready(function(){
if(!proboards.data('user').is_staff){
setTimeout(function(){
$('.options_menu li').each(function(){
if($(this).html().indexOf('Delete Post') != -1)
$(this).remove();
});
}, 5 * 60 * 1000); // 5 minutes
}
});
</script>

But - what about a user who makes a new post, does something else on the forum for 3 minutes, and then comes back and wants to delete their post? With this code, there's no way we can tell they still have time left, or how much time they have left.

If there's a place on the page that says when the post was made that can be read accurate to the minute (preferably second, but minute will roughly do) at least while the post is 6 minutes or less old, we could read that and remove the delete option if the post is older than five minutes, and set the timer for the rest of them relative to how much time is left until the age will be five minutes. But to do that, I would need to see the page.

On one of your other pages I see things like:

5 hours ago

and:

Jan 20, 2014 at 10:39pm

showing the age of individual posts. How accurate is that and what does it show during the posts first 6 minutes of existence?

JRR
02-22-2015, 06:09 AM
Ok John with the other thread we've got going I haven't had time to come back to this one. First of all they don't have the configuration on a timed delete thing because they defend the post deleting by members vigorously and even though they don't try to stop forum owners from removing the delete post function they don't support it either.

Now the question you had about 5 hours ago and the dates and time are their timestamps and on PB forums as soon as one posts the first mention of time after a post is "a few seconds ago" then it counts in one minute intervals as in "one minute ago" up to 60 minutes in which it changes to "one Hour ago" and then to the daily count and so on.

But on my forums I have a footer code that puts the timestamp readings to exact time and date like listed here:

http://scooterdoc.proboards.com/


Here is the code it's a monster:


<script type="text/javascript">

/* Replace elapsed time with specific time (Sept 15, 2013) */
$(function(){
var a = 0, timeID = null, ac = arguments.callee, abbr = this.jquery? this : (this.ownerDocument ? $(this) : $('abbr.time'))
for(; a < $.livequery.queries.length; a++){
if($.livequery.queries[a].selector == "abbr.time" && "function" == typeof $.livequery.queries[a].fn && $.livequery.queries[a].fn.toString().indexOf("non_mod_date") != -1)
{
timeID = $.livequery.queries[a]/*.id*/; $.livequery.stop(timeID.id);break;
}
}
//$('abbr.time')
abbr.each(function () {
var time = $(this).addClass('modified_time').removeClass('time'), raw_date = new Date(parseInt(time.data("timestamp"),10));
if($(this).hasClass('recent_time') && !/yesterday/i.test($(this).text())){
time = time.removeClass('recent_time');
var today = raw_date.getDate() == (new Date()).getDate()?"today":"yesterday",
user_date = ['M d, yy', 'd M, yy'][proboards.data("time_style") || 0];
time.replaceWith(
$(this).clone(true).addClass('recent_time')
.html(
'<span class="'+today+'">'+today+' </span>'
+ '<span class="at">at</span> <span class="at-time">' +
(proboards.data('military_time') ? $.formatTime('HH:mm', raw_date) : $.formatTime('h:mmp', raw_date))
+'</span>'
)
);
}else if(/yesterday/i.test($(this).text())){
time.replaceWith(
$(this).clone(true)
.html(
'<span class="yesterday">yesterday </span><span class="at">at </span><span class="at-time">'
+ $(this).text().split("at ")[1]
+'</span>'
)
)
}else{
if(time.text().indexOf(" at ")== -1)
time.text($.datepicker.formatDate((proboards.data('time_style') ? 'd M yy' : 'M d, yy'), raw_date) + ' at ' + $.formatTime((proboards.data('military_time') ? 'HH:mm' : 'h:mmp'), raw_date))
time.replaceWith(function(){
for(var dt = time.text().split(" at")[0], a = dt.split(/,?\s+/), b=0, c = $('<span></span>'); b<a.length; b++){
if((d = a[b].match(/^(\d+)$/))){
if(d[1].length == 4)
c.append('<span class="year">'+a[b]+' </span>').addClass("year_"+a[b]);
else
c.append('<span class="day">'+a[b]+' </span>').addClass("day_"+a[b])
}else{
c.append('<span class="month">'+a[b]+' </span>').addClass("month_"+a[b])
}
}
c.append('<span class="at">at </span>').append('<span class="at-time">' + time.text().split(" at ")[1] + '</span>')
return time.clone(true).html('').append(c)
})
}

})
$('abbr.modified_time').addClass('time'); //re-enable livequery treatment
if(!ac.func){
ac.func = function(){
$.livequery.run(timeID.id);
ac();
}
}
if(!ac.shoutbox){ ac.shoutbox = $('.shoutbox_messages')
.on('shoutbox_update.has-payload', function(event,data){
if(data.shout.length){
data.shout.each(function(){
var time = $('abbr.time',this)
timeID.fn.call(time);
ac.call(time.addClass('recent_time'));
})
}
})}
if($.inArray(ac.func, proboards.events.afterSearch) == -1){ proboards.on("afterSearch", ac.func); }
})

</script>



I'm confused about what you asked here?



Now, that said, we can easily delay execution of the code in your post. But that won't distinguish between a user returning to a page where they previously made a post perhaps hours or days ago versus a page where they have just now made a post. You might have a way to do that though (use the above code on a normal page, use the new timed code on the page a user lands on after making a new post). If you can control that, then just add a timeout for the code you wish to delay:

JRR
02-23-2015, 06:48 PM
Oh another thing John the code you put the timer in would need the staff portion removed wouldn't it? With the old code the delete button is still there to use for staff only.

JRR
04-09-2015, 03:05 PM
Would still like to make this work if possible. Thanks

jscheuer1
04-11-2015, 04:12 PM
Yeah, sorry. We were working together a little while back and I got busy with a lot on non-forum things. I'm back for now. Of the two things we were working on, this one seems easier, so let's see what we can do. As I remember, the page actually contains text that tells us how old each post is, right? If so, all we need to do is trap that text (set some variable equal to it or gain a reference to it in some way) compare it against all possible values/wordings it could have and determine how old the post is on that basis. Armed with that knowledge, the code could then either hide or allow to be seen the edit button. It will not work for non-javascript enabled users. I'm going to go back over the previous posts here and see if I still have enough to go on in making the general idea I just explained here work for this specific case.

jscheuer1
04-11-2015, 05:15 PM
OK, let's try this out. First get rid of:


<script type="text/javascript">
$(document).ready(function(){
if(!proboards.data('user').is_staff){
$('.options_menu li').each(function(){
if($(this).html().indexOf('Delete Post') != -1)
$(this).remove();
});
}
});
</script>

Then add the highlighted to the existing function for the time display:


<script type="text/javascript">

/* Replace elapsed time with specific time (Sept 15, 2013) */
$(function(){
var a = 0, timeID = null, ac = arguments.callee, abbr = this.jquery? this : (this.ownerDocument ? $(this) : $('abbr.time'))
for(; a < $.livequery.queries.length; a++){
if($.livequery.queries[a].selector == "abbr.time" && "function" == typeof $.livequery.queries[a].fn && $.livequery.queries[a].fn.toString().indexOf("non_mod_date") != -1)
{
timeID = $.livequery.queries[a]/*.id*/; $.livequery.stop(timeID.id);break;
}
}
//$('abbr.time')
abbr.each(function () {
var time = $(this).addClass('modified_time').removeClass('time'), raw_date = new Date(parseInt(time.data("timestamp"),10));
if(!proboards.data('user').is_staff){
var elapsed = new Date().getTime() - raw_date.getTime();
if(elapsed > 5 * 60 * 1000){
$(this).parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(){
if($(this).html().indexOf('Delete Post') != -1)
$(this).remove();
});
}
}
if($(this).hasClass('recent_time') && !/yesterday/i.test($(this).text())){
time = time.removeClass('recent_time');
var today = raw_date.getDate() == (new Date()).getDate()?"today":"yesterday",
user_date = ['M d, yy', 'd M, yy'][proboards.data("time_style") || 0];
time.replaceWith(
$(this).clone(true).addClass('recent_time')
.html(
'<span class="'+today+'">'+today+' </span>'
+ '<span class="at">at</span> <span class="at-time">' +
(proboards.data('military_time') ? $.formatTime('HH:mm', raw_date) : $.formatTime('h:mmp', raw_date))
+'</span>'
)
);
}else if(/yesterday/i.test($(this).text())){
time.replaceWith(
$(this).clone(true)
.html(
'<span class="yesterday">yesterday </span><span class="at">at </span><span class="at-time">'
+ $(this).text().split("at ")[1]
+'</span>'
)
)
}else{
if(time.text().indexOf(" at ")== -1)
time.text($.datepicker.formatDate((proboards.data('time_style') ? 'd M yy' : 'M d, yy'), raw_date) + ' at ' + $.formatTime((proboards.data('military_time') ? 'HH:mm' : 'h:mmp'), raw_date))
time.replaceWith(function(){
for(var dt = time.text().split(" at")[0], a = dt.split(/,?\s+/), b=0, c = $('<span></span>'); b<a.length; b++){
if((d = a[b].match(/^(\d+)$/))){
if(d[1].length == 4)
c.append('<span class="year">'+a[b]+' </span>').addClass("year_"+a[b]);
else
c.append('<span class="day">'+a[b]+' </span>').addClass("day_"+a[b])
}else{
c.append('<span class="month">'+a[b]+' </span>').addClass("month_"+a[b])
}
}
c.append('<span class="at">at </span>').append('<span class="at-time">' + time.text().split(" at ")[1] + '</span>')
return time.clone(true).html('').append(c)
})
}

})
$('abbr.modified_time').addClass('time'); //re-enable livequery treatment
if(!ac.func){
ac.func = function(){
$.livequery.run(timeID.id);
ac();
}
}
if(!ac.shoutbox){ ac.shoutbox = $('.shoutbox_messages')
.on('shoutbox_update.has-payload', function(event,data){
if(data.shout.length){
data.shout.each(function(){
var time = $('abbr.time',this)
timeID.fn.call(time);
ac.call(time.addClass('recent_time'));
})
}
})}
if($.inArray(ac.func, proboards.events.afterSearch) == -1){ proboards.on("afterSearch", ac.func); }
})

</script>

Browser and/or server caches may need to be cleared and/or the page refreshed to see changes. If there are problems, please leave the code in place so I can diagnose the problem. Also, if there's a problem, please describe it in as much detail as possible.

JRR
04-12-2015, 12:50 PM
OK John I have this in place here:

http://scootproftest.freeforums.net/thread/1/welcome-new-forum?page=2&scrollTo=127

I made a post as a regular member on that thread as 008 twice and in both instances the "delete post" button disappeared in 5 minutes after posting, brilliant! You have posted there too so would you post once to confirm this? BTW to see the "delete post" button click on the gear icon in the top right corner of the posting window, take note of the time you made the post and you will have the delete post button for 5 minutes, as soon as the 6 minute has passed it disappeared for me. But as staff the button remains as it should.

Oh so as not to be guessing what part does one change to change the time limit settings? I tried this is IE11 if you have chrome could you check it in that browser?

jscheuer1
04-12-2015, 04:57 PM
OK, 'works' in Chrome. But I'm not satisfied because two situations are not yet covered. If you post and just wait with the page sitting there for 10 minutes or whatever, the delete button is still there. Or if you refresh and 5 minutes haven't passed yet and just let it sit there, the delete button remains until time is up AND you refresh. It's only if you refresh the page and 5 minutes have passed that the delete button goes away.

Since the page initially reloads just after posting, these are really the same problem. So I've rewritten to take care of this. Changes/additions highlighted, also included the time allowed as a variable near the top in case you want to change it:


<script type="text/javascript">

/* Replace elapsed time with specific time (Sept 15, 2013) */
$(function(){
var howlongallowed = 5 * 60 * 1000; //5 minutes in milliseconds
function keepwatch($del, raw_time){
if(new Date().getTime() - raw_time > howlongallowed){
$del.remove();
return;
} else {
setTimeout(function(){keepwatch($del, raw_time);}, 300);
}
}

var a = 0, timeID = null, ac = arguments.callee, abbr = this.jquery? this : (this.ownerDocument ? $(this) : $('abbr.time'))
for(; a < $.livequery.queries.length; a++){
if($.livequery.queries[a].selector == "abbr.time" && "function" == typeof $.livequery.queries[a].fn && $.livequery.queries[a].fn.toString().indexOf("non_mod_date") != -1)
{
timeID = $.livequery.queries[a]/*.id*/; $.livequery.stop(timeID.id);break;
}
}
//$('abbr.time')
abbr.each(function () {
var time = $(this).addClass('modified_time').removeClass('time'), raw_date = new Date(parseInt(time.data("timestamp"),10));
if(!proboards.data('user').is_staff){
var $del;
$(this).parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') != -1){
$del = $(del);
return false;
}
});
if($del){keepwatch($del, raw_date.getTime());}
}
if($(this).hasClass('recent_time') && !/yesterday/i.test($(this).text())){
time = time.removeClass('recent_time');
var today = raw_date.getDate() == (new Date()).getDate()?"today":"yesterday",
user_date = ['M d, yy', 'd M, yy'][proboards.data("time_style") || 0];
time.replaceWith(
$(this).clone(true).addClass('recent_time')
.html(
'<span class="'+today+'">'+today+' </span>'
+ '<span class="at">at</span> <span class="at-time">' +
(proboards.data('military_time') ? $.formatTime('HH:mm', raw_date) : $.formatTime('h:mmp', raw_date))
+'</span>'
)
);
}else if(/yesterday/i.test($(this).text())){
time.replaceWith(
$(this).clone(true)
.html(
'<span class="yesterday">yesterday </span><span class="at">at </span><span class="at-time">'
+ $(this).text().split("at ")[1]
+'</span>'
)
)
}else{
if(time.text().indexOf(" at ")== -1)
time.text($.datepicker.formatDate((proboards.data('time_style') ? 'd M yy' : 'M d, yy'), raw_date) + ' at ' + $.formatTime((proboards.data('military_time') ? 'HH:mm' : 'h:mmp'), raw_date))
time.replaceWith(function(){
for(var dt = time.text().split(" at")[0], a = dt.split(/,?\s+/), b=0, c = $('<span></span>'); b<a.length; b++){
if((d = a[b].match(/^(\d+)$/))){
if(d[1].length == 4)
c.append('<span class="year">'+a[b]+' </span>').addClass("year_"+a[b]);
else
c.append('<span class="day">'+a[b]+' </span>').addClass("day_"+a[b])
}else{
c.append('<span class="month">'+a[b]+' </span>').addClass("month_"+a[b])
}
}
c.append('<span class="at">at </span>').append('<span class="at-time">' + time.text().split(" at ")[1] + '</span>')
return time.clone(true).html('').append(c)
})
}

})
$('abbr.modified_time').addClass('time'); //re-enable livequery treatment
if(!ac.func){
ac.func = function(){
$.livequery.run(timeID.id);
ac();
}
}
if(!ac.shoutbox){ ac.shoutbox = $('.shoutbox_messages')
.on('shoutbox_update.has-payload', function(event,data){
if(data.shout.length){
data.shout.each(function(){
var time = $('abbr.time',this)
timeID.fn.call(time);
ac.call(time.addClass('recent_time'));
})
}
})}
if($.inArray(ac.func, proboards.events.afterSearch) == -1){ proboards.on("afterSearch", ac.func); }
})

</script>

JRR
04-12-2015, 09:44 PM
Ok John it's working nicely still in IE11 and FF, checked both of those. Also I'm a little confused?


I see

var howlongallowed = 5 * 60 * 1000; //5 minutes in milliseconds


Is 5 here the place where the time limit can be changed?

jscheuer1
04-12-2015, 11:24 PM
var howlongallowed = 5 * 60 * 1000; //5 minutes in milliseconds

The green is a comment. The red is the actual value. Time in javascript is always in milliseconds unless converted/extracted from a value or time object in different units.

What is often done, and what I do here is multiply to get milliseconds and use them in a native comparison later. You want minutes (5 minutes). I take (red section) 5 * (times) 60, so now it's seconds, then * (times) 1000, so now it's milliseconds - all ready to go for use in the native comparison in the keepwatch function. That way it doesn't have to be converted each time it's used. If you wanted 6 minutes, you would do:


var howlongallowed = 6 * 60 * 1000;

Hope that explains it. If not, ask another question.



Oh, and this now works to my satisfaction, keeping track of a current post and even if the page is not reloaded, removing the delete button after the post is 5 minutes old.

JRR
04-12-2015, 11:56 PM
Awesome John! Will ask about the other project on the other thread. Thanks!

JRR
04-13-2015, 05:19 PM
John I actually do have another question? This is working brilliantly and I have another function that is a issue sometimes and it's the "Edit Post" button. I can remove it or make it where only staff can use it but putting it on a time delay would also be a nice option.

It is in the templates like other button functions and looks like this:



<div class="controls">
$[post.quote_button]
$[post.edit_button]
$[post.likes.button]
$[post.select_options]
</div>


Like I said I can just delete that button code or I can use this to leave it for staff to use:




{if $[current_user.is_staff]}
$[post.edit_button]
{/if}


Could the other code that BTW goes in the Global Header be changed to use for the Edit Post button?

jscheuer1
04-14-2015, 03:28 AM
Probably. I would need to know the text or (preferably) class of the edit button and the time limit you want for it. If that class is 'edit-button' (looks that way) and 5 minutes is the time again, we would need to only change this part a little:


if(!proboards.data('user').is_staff){
var $del;
$(this).parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') != -1){
$del = $(del);
return false;
}
});
if($del){keepwatch($del, raw_date.getTime());}
}

to:


if(!proboards.data('user').is_staff){
var raw_time = raw_date.getTime(), $del, $edit = $(this).parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') != -1){
$del = $(del);
return false;
}
}).end().find('.edit-button');
if($del){keepwatch($del, raw_time);}
if($edit.length){keepwatch($edit, raw_time);}
}

One thing to think about with this and the delete button though. Say a staff person posts and right away a non-staff person loads the page. Won't the non-staff person be able to edit or delete the staff person's post until 5 minutes have past? If so, a fix would be comparing the username to the owner of the posts as part of the looping process. Is there an easy way to get the username and/or the owner of the post from pcb?

jscheuer1
04-14-2015, 04:37 AM
If you can do this:



{if $[current_user.is_staff]}
$[post.edit_button]
{/if}

Why couldn't you do something like that with the delete button?

But since we no longer want that, could you do something like (syntax is probably wrong, but I think you get the idea):


{if $[current_user.is_staff] or $[current_user == $current_poster]}
$[post.edit_button]
{/if}

But even without that, this should work:


if(!proboards.data('user').is_staff){
var postid = $(this).parents('.content').prev('.left-panel').find('a').eq(0).attr('href'), $del,
removenow = proboards.data('user').id != postid.substring(postid.lastIndexOf('/') + 1), raw_time = raw_date.getTime(),
$edit = $(this).parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') != -1){
$del = $(del);
return false;
}
}).end().find('.edit-button');
if($del && removenow){$del.remove(); $edit.remove();}
else if($del || $edit.length){
if($del){keepwatch($del, raw_time);}
if($edit.length){keepwatch($edit, raw_time);}
}
}


It's just that you are better off doing as much as possible on the server side, otherwise folks will be able to get over by turning javascript off.

JRR
04-14-2015, 07:45 PM
Ok John sorry I haven't got back. Put the code changes in, delete button still works like it should. If a member posts it disappears on the time setting which is 5 minutes. The delete post button is always there for staff, just as it should be.

Now on the edit post is where we have issues. The edit button is there for staff as it should be but if you login as a regular member it's gone, all fine but the hope is the edit button will be there if you make a post and then disappear after the time limit, this is not the case. BTW the Edit Button is located next to the Quote Button.

I left the code in place awaiting your instructions. In this case we have to have the Edit button appear upon a members post then disappear after the allotted time limit.

jscheuer1
04-15-2015, 02:17 AM
Well, the edit button isn't there most likely because you haven't changed:


{if $[current_user.is_staff]}
$[post.edit_button]
{/if}

to:


$[post.edit_button]


Either that, or you had some javascript that was removing it that you didn't mention/don't know about and that's still there. Or maybe there's some other setting that prevents the edit button for non-staff.

Reason I say is that there's no way my code can make an edit button where none is, and it will not remove one that is there until the time is up and only for non-staff. I'll poke around for other javascript on the page, but it might be external. You check the server side code I mentioned at the top of this post to see it it's been changed to allow the button for non-staff.

JRR
04-15-2015, 03:40 AM
Arrrrrgh! I forgot about the code I put in the templates removing the edit button except for staff! I removed that and the edit button is back for someone to use for the time limit specified. I made a post, made sure the Edit and Delete Post buttons still worked correctly inside the 5 minute time frame I set it for and then waited for 5 minutes, they both disappeared!,

All is great, sorry John for the screw up,Thanks!

jscheuer1
04-15-2015, 02:53 PM
OK, so it's working. I've discovered I can edit my own post at any time though if I know the post number which can be found in at least three ways. Easiest way is to just hover the quote button for that post, it has the post number in its href which will then appear in the status for the browser. Once you have the post number you simply navigate to:

/post/146/edit

Where the first / is the root of the domain and 146 is the post number. I tried this with two other posts (one admin, one by another non-staff account) but both times I got a page that told me I didn't have permission to edit this post. So I guess the harm is minimal, and I'm not sure whether or not this would still be possible even if we had not allowed the edit button for 5 minutes, though I could check if you were to revert it to how it was - with the edit button never showing. Also this means we do not have to worry about non-staffers being able to edit others posts if they happen upon the page before the time limit is up for that post, because it likely will not have a button, and even if it did, there would not be permission to edit even if that button were used.

JRR
04-15-2015, 07:02 PM
I knew about the numbered post edit thing you mentioned as others have discovered it with a plugin that someone made that is supposed to hide it also. I'm a little confused? You said make it where it doesn't appear at all say with this code that I forgot to remove?


{if $[current_user.is_staff]}
$[post.edit_button]
{/if}


If that's the case I will put it back because I think I understand what you're getting at? If that code keeps the edit from appearing when you put your cursor over the quote button, then maybe it can be used to work with the code you just made?

jscheuer1
04-16-2015, 01:24 PM
That's not what I said. The post number is almost everywhere. If you go to your most recent (or go to any of your) post(s) in a thread via an internal board search or anything like that, it's even in the addressbar. And I think nothing will stop it from being in the quote url unless you remove the quote button. But then it can always be found in the proboards.data('proboards.post') object (which is in the source code of the served page and in the page's javascript environment if queried for by the browsers's developer's console) if nowhere else.

What I said was that if you eliminate the edit button on the server side, there's a chance - only a chance, that using a link pasted into the addressbar to edit your post won't work. Eliminating the edit button via javascript will not - cannot, because the proboards code has no awareness that the button isn't there. If you take it away on the server side, then it might know not to allow it via the url either.

All I was proposing was a test of that. I was suggesting that you reinstate the server side code that eliminates the edit button and then see if the url edit trick still works. If the url edit trick still works, then there's nothing to be gained by taking away the edit button on the server side.


Regardless, we are only talking about users being able to edit their own posts, and only fairly savvy ones at that, so I wouldn't worry about it too much.

It's also possible that even removing the button via javascript, we could somehow use javascript to tell proboards not to allow the url trick after that either, but that might not be possible. I'll poke around some more and see if that seems promising or not. But if removing the button on the server side doesn't take away the trick, javascript probably cannot do it either.

Oddly, the delete button isn't subject to the same kind of trick. It's click event is assigned via javascript and cannot be easily spoofed once the element is removed. It might be prudent to unbind the element though, as the event can still be triggered until the page is refreshed.

jscheuer1
04-17-2015, 03:07 AM
You might want to look at and/or test this as well if you haven't already:

https://www.proboards.com/library/plugins/item/318

I'd be interested if the url editing trick works with it or not.

JRR
04-17-2015, 03:01 PM
John I know I read a thread somewhere where a member was complaining about the URL edit trick being functional with the plugin and I'll follow up on that to verify it one way or another.

I'll also put the code back in on my test forum that removes the edit button to see if it can be used with the URL still also. I would if it's possible like to be able to eliminate all possibilities of editing after the time limit.


Edit: The Edit Post button removal code is in place so you can see what is going on.

jscheuer1
04-17-2015, 05:41 PM
I just tested, the trick works on both old and new posts. To disable it, one would have to do something on the server side. A complex mod-rewrite might work with the timer and non-staff. edit could be disabled for all with a simple mod-rewrite. These both require server side code like PHP (which I sort of know how to do this with) or asp or other (non of which I'm all that familiar with). I'll have to look at the edit page itself to see if there's a way to disable it using javascript.

jscheuer1
04-17-2015, 06:04 PM
We can get the original post time from the edit page and determine if the user is non staff, if the page is an edit page, how old the post is and if it's too old, give an alert that the post is older than - whatever (5 mins in this case) and that they have to contact an admin now to change it, once the alert dissapears, we can have javascript return them to the previous page, or perhaps better (if I can work this out) to the post that they were trying to edit. This will take some time to work out, but I think it's doable. I also want to check if the edit page works with javascript disabled - I think it won't, but wanna be sure. No it does - just checked - so whatever I do with javascript, a person could turn it off, use the edit trick and edit their own post at any time.

JRR
04-17-2015, 09:55 PM
It would still be a step to discourage them from doing so. There is another possibility of editing the posts for people using that plugin and folks were mad about it and gave up on the plugin. One can hit their name and go to their profile page, when doing so you have a listing of recent posts and recent threads which both are by the member themselves. With the plugin you can edit your post by going here, with the code you have built this is not possible, it removes the edit/delete button there as well a very big improvement.

jscheuer1
04-18-2015, 04:14 AM
I agree if the goal is to limit it as much as possible that making the edit trick not work at least for javascript enabled browsers would be good. It really shouldn't be that hard to write. I already have it figured out, I just have to do it. Maybe a little later tonight, or at some point over the weekend for sure. It's a shame this functionality isn't built into proboards. It is with at least some other forums.

That said, I doubt too many people are going to both know the url edit trick and realize that with this modification I'm going to write that they can still use it without javascript.

One thing to consider though is how we handle the rejection. I think an alert will be more of a clue that it's javascript based than we would want. I think it might be possible to replace the editor with a message right on the edit page that says (or something like) - "You don't have permission to edit this post, as the time limit for that has expired. Please contact a staff member or the Admin for assistance." As long as we could do that before they see the editor (could be tricky to time that, but I have an idea), that would make make it look and feel more like a server side thing, which would make them less inclined to think about turning off javascript to get around it.

jscheuer1
04-18-2015, 03:36 PM
OK, I worked this out last night but didn't have time to post it and explain what to do with it.

First make sure you enable the edit button again on the server side.

Then put this stylesheet in the head of the page (it can go in the template for all pages as long as all of those pages also get the script that follows):


<style type="text/css">
.subject, .subject_input, .editor, .tagholder, .edit_reason {display: none;}
</style>

If possible, the above styles can go in the head of a template that's only for the editor page (the page where actual edits are made), but it can go in all pages that also have this script, which replaces the entire script for the date format changes and modifications to it that we already made (I will try to highlight changes, but it's best to replace the entire thing, in case I missed something with the highlighter, or you do in copying it):


<script type="text/javascript">

/* Replace elapsed time with specific time (Sept 15, 2013) */
/* Note: - set .subject, .subject_input, .editor, .tagholder, and .edit_reason (dispnoneditels) to display: none; in the stylesheet */
$(function(){
var howlongallowed = 300000; /* 5 times 60 times 1000, (5 minutes = 300000 milliseconds) */
var editexpiredmsg = "You don't have permission to edit this post, the time limit for that has expired. If you want help, please contact a staff member or the Admin for assistance.";
var dispnoneditels = '.subject, .subject_input, .editor, .tagholder, .edit_reason';
var dispexcept = '.editor.bbcode-editor';
if(window.location.href.indexOf('/post/edit/') > -1 && !proboards.data('user').is_staff){
var elapsed = new Date().getTime() - pcboards.data('page').created_on * 1000;
if(elapsed > howlongallowed){
$('.editor').replaceWith('<div class="container error">\n<div class="title-bar">\n<h2>Oops, there was an error!</h2>\n</div>'+
'<div class="content pad-all cap-bottom auto-overflow">\n' + editexpiredmsg + '\n</div>');
} else {
$(dispnoneditels).not(dispexcept).css({display: 'block'});
}
} else {
$(dispnoneditels).not(dispexcept).css({display: 'block'});
}
function keepwatch($del, raw_time, unbind){
if(new Date().getTime() - raw_time > howlongallowed){
if(unbind === true){
$('a', $del).off();
}
$del.remove();
return;
} else {
setTimeout(function(){keepwatch($del, raw_time, unbind);}, 300);
}
}

var a = 0, timeID = null, ac = arguments.callee, abbr = this.jquery? this : (this.ownerDocument ? $(this) : $('abbr.time'))
for(; a < $.livequery.queries.length; a++){
if($.livequery.queries[a].selector == "abbr.time" && "function" == typeof $.livequery.queries[a].fn && $.livequery.queries[a].fn.toString().indexOf("non_mod_date") != -1)
{
timeID = $.livequery.queries[a]/*.id*/; $.livequery.stop(timeID.id);break;
}
}
//$('abbr.time')
abbr.each(function () {
var time = $(this).addClass('modified_time').removeClass('time'), raw_date = new Date(parseInt(time.data("timestamp"),10));
if(!proboards.data('user').is_staff){
var raw_time = raw_date.getTime(), $del, $edit = $(this).parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') != -1){
$del = $(del);
return false;
}
}).end().find('.edit-button');
if($del){keepwatch($del, raw_time, true);}
if($edit.length){keepwatch($edit, raw_time);}
}
if($(this).hasClass('recent_time') && !/yesterday/i.test($(this).text())){
time = time.removeClass('recent_time');
var today = raw_date.getDate() == (new Date()).getDate()?"today":"yesterday",
user_date = ['M d, yy', 'd M, yy'][proboards.data("time_style") || 0];
time.replaceWith(
$(this).clone(true).addClass('recent_time')
.html(
'<span class="'+today+'">'+today+' </span>'
+ '<span class="at">at</span> <span class="at-time">' +
(proboards.data('military_time') ? $.formatTime('HH:mm', raw_date) : $.formatTime('h:mmp', raw_date))
+'</span>'
)
);
}else if(/yesterday/i.test($(this).text())){
time.replaceWith(
$(this).clone(true)
.html(
'<span class="yesterday">yesterday </span><span class="at">at </span><span class="at-time">'
+ $(this).text().split("at ")[1]
+'</span>'
)
)
}else{
if(time.text().indexOf(" at ")== -1)
time.text($.datepicker.formatDate((proboards.data('time_style') ? 'd M yy' : 'M d, yy'), raw_date) + ' at ' + $.formatTime((proboards.data('military_time') ? 'HH:mm' : 'h:mmp'), raw_date))
time.replaceWith(function(){
for(var dt = time.text().split(" at")[0], a = dt.split(/,?\s+/), b=0, c = $('<span></span>'); b<a.length; b++){
if((d = a[b].match(/^(\d+)$/))){
if(d[1].length == 4)
c.append('<span class="year">'+a[b]+' </span>').addClass("year_"+a[b]);
else
c.append('<span class="day">'+a[b]+' </span>').addClass("day_"+a[b])
}else{
c.append('<span class="month">'+a[b]+' </span>').addClass("month_"+a[b])
}
}
c.append('<span class="at">at </span>').append('<span class="at-time">' + time.text().split(" at ")[1] + '</span>')
return time.clone(true).html('').append(c)
})
}

})
$('abbr.modified_time').addClass('time'); //re-enable livequery treatment
if(!ac.func){
ac.func = function(){
$.livequery.run(timeID.id);
ac();
}
}
if(!ac.shoutbox){ ac.shoutbox = $('.shoutbox_messages')
.on('shoutbox_update.has-payload', function(event,data){
if(data.shout.length){
data.shout.each(function(){
var time = $('abbr.time',this)
timeID.fn.call(time);
ac.call(time.addClass('recent_time'));
})
}
})}
if($.inArray(ac.func, proboards.events.afterSearch) == -1){ proboards.on("afterSearch", ac.func); }
})

</script>

JRR
04-19-2015, 02:43 PM
Ok John sorry so late in answering, have a softball tournament this weekend with my granddaughter. I put the code in exactly like you put here and we can still edit a post through the back door URL link like this last post of mine. http://scootproftest.freeforums.net/post/164/edit .

On the style sheet code one has to remove the style tags when you put it in the CSS or you get a Syntax Error. But you would put the code in like this:





.subject, .subject_input, .editor, .tagholder, .edit_reason {display: none;}



I did put it in the template area where the Edit Post button is also with the style tags included which you would do and it made no difference either?

PB also does this sometimes, instead of "display none" they use "block" like this:



.subject, .subject_input, .editor, .tagholder, .edit_reason {display: block;}



No luck with that either?


Everything is still working correctly as far as the buttons disappearing and such but we can still get in the back door. I've got you last code in as requested and will wait your instructions.

jscheuer1
04-19-2015, 03:06 PM
That's OK, softball sounds more important to me.

I made a typo in the javascript code and I have some other tweaks I want to work out. Also, the style is important. We do not want display block, that means you see it, like a block of wood, not like 'block this from view'. Weird I know, but it's to distinguish it from 'inline' and others, which get laid out differently. We want display: none; which is completely unseen. The elements I want to do this to have changed. but when the time comes, we will need to get the rules into style. The style section doesn't absolutely have to go in the head, it can go in the body, as long as it comes before the elements it makes unseen. Here's the new style, and it's true that you should not use the style tags if you are putting it in an existing style section or stylesheet, but if it's going by itself into the head or body, it needs the style tags:


<style type="text/css">
#nav-tree li, .container.new-area.wysiwyg-area, .container.posts.summary {display: none;}
#nav-tree li:first-child {display: inline-block;}
</style>

See if you can do that. You know you will have succeeded if you cannot see anything of use for editing on the edit page. I'll have the typo fix for the javascript and the tweaks ready soon. What we are doing is hiding everything for editing, then bringing it back into view via javascript for staff at all times and for users whose posts haven't timed out. For those who have timed out, we are going to replace it with an error message.

jscheuer1
04-19-2015, 03:34 PM
OK, here's the fixed and tweaked javascript code. I was actually able to test it for most errors in the console. So, as long as we can get our style in there, we should be golden:


<script type="text/javascript">

/* Replace elapsed time with specific time (Sept 15, 2013) */
/* Note: - set #nav-tree li, .container.new-area.wysiwyg-area, .container.posts.summary to display: none; in the stylesheet */
/* Set #nav-tree li:first-child to display: inline-block; in the stylesheet */
$(function(){
var howlongallowed = 300000; /* 5 times 60 times 1000, (5 minutes = 300000 milliseconds) */
var editexpiredmsg = "You don't have permission to edit this post, the time limit for that has expired. If you want help, please contact a staff member or the Admin for assistance.";
var dispnoneditels = '.container.new-area.wysiwyg-area, .container.posts.summary';
var dispinbl = '#nav-tree li';
if(/\/post\/\d+\/edit$/.test(window.location.href) && !proboards.data('user').is_staff){
var elapsed = new Date().getTime() - proboards.data('page').post.created_on * 1000;
if(elapsed > howlongallowed){
$('.container.new-area.wysiwyg-area').replaceWith('<div class="container error">\n<div class="title-bar">\n<h2>Oops, there was an error!</h2>\n</div>'+
'<div class="content pad-all cap-bottom auto-overflow">\n' + editexpiredmsg + '\n</div>');
document.title = "Oops, there was an error! | Forum";
} else {
$(dispnoneditels).css({display: 'block'});
$(dispinbl).css({display: 'inline-block'});
}
} else {
$(dispnoneditels).css({display: 'block'});
$(dispinbl).css({display: 'inline-block'});
}
function keepwatch($del, raw_time, unbind){
if(new Date().getTime() - raw_time > howlongallowed){
if(unbind === true){
$('a', $del).off();
}
$del.remove();
return;
} else {
setTimeout(function(){keepwatch($del, raw_time, unbind);}, 300);
}
}

var a = 0, timeID = null, ac = arguments.callee, abbr = this.jquery? this : (this.ownerDocument ? $(this) : $('abbr.time'))
for(; a < $.livequery.queries.length; a++){
if($.livequery.queries[a].selector == "abbr.time" && "function" == typeof $.livequery.queries[a].fn && $.livequery.queries[a].fn.toString().indexOf("non_mod_date") != -1)
{
timeID = $.livequery.queries[a]/*.id*/; $.livequery.stop(timeID.id);break;
}
}
//$('abbr.time')
abbr.each(function () {
var time = $(this).addClass('modified_time').removeClass('time'), raw_date = new Date(parseInt(time.data("timestamp"),10));
if(!proboards.data('user').is_staff){
var raw_time = raw_date.getTime(), $del, $edit = $(this).parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') != -1){
$del = $(del);
return false;
}
}).end().find('.edit-button');
if($del){keepwatch($del, raw_time, true);}
if($edit.length){keepwatch($edit, raw_time);}
}
if($(this).hasClass('recent_time') && !/yesterday/i.test($(this).text())){
time = time.removeClass('recent_time');
var today = raw_date.getDate() == (new Date()).getDate()?"today":"yesterday",
user_date = ['M d, yy', 'd M, yy'][proboards.data("time_style") || 0];
time.replaceWith(
$(this).clone(true).addClass('recent_time')
.html(
'<span class="'+today+'">'+today+' </span>'
+ '<span class="at">at</span> <span class="at-time">' +
(proboards.data('military_time') ? $.formatTime('HH:mm', raw_date) : $.formatTime('h:mmp', raw_date))
+'</span>'
)
);
}else if(/yesterday/i.test($(this).text())){
time.replaceWith(
$(this).clone(true)
.html(
'<span class="yesterday">yesterday </span><span class="at">at </span><span class="at-time">'
+ $(this).text().split("at ")[1]
+'</span>'
)
)
}else{
if(time.text().indexOf(" at ")== -1)
time.text($.datepicker.formatDate((proboards.data('time_style') ? 'd M yy' : 'M d, yy'), raw_date) + ' at ' + $.formatTime((proboards.data('military_time') ? 'HH:mm' : 'h:mmp'), raw_date))
time.replaceWith(function(){
for(var dt = time.text().split(" at")[0], a = dt.split(/,?\s+/), b=0, c = $('<span></span>'); b<a.length; b++){
if((d = a[b].match(/^(\d+)$/))){
if(d[1].length == 4)
c.append('<span class="year">'+a[b]+' </span>').addClass("year_"+a[b]);
else
c.append('<span class="day">'+a[b]+' </span>').addClass("day_"+a[b])
}else{
c.append('<span class="month">'+a[b]+' </span>').addClass("month_"+a[b])
}
}
c.append('<span class="at">at </span>').append('<span class="at-time">' + time.text().split(" at ")[1] + '</span>')
return time.clone(true).html('').append(c)
})
}

})
$('abbr.modified_time').addClass('time'); //re-enable livequery treatment
if(!ac.func){
ac.func = function(){
$.livequery.run(timeID.id);
ac();
}
}
if(!ac.shoutbox){ ac.shoutbox = $('.shoutbox_messages')
.on('shoutbox_update.has-payload', function(event,data){
if(data.shout.length){
data.shout.each(function(){
var time = $('abbr.time',this)
timeID.fn.call(time);
ac.call(time.addClass('recent_time'));
})
}
})}
if($.inArray(ac.func, proboards.events.afterSearch) == -1){ proboards.on("afterSearch", ac.func); }
})

</script>

jscheuer1
04-19-2015, 04:20 PM
If you're still having trouble with the style, see:

https://www.proboards.com/admin-guide/themes-styles/styles-css

Use the "Style Sheet tab on the top of the page. This tab will give you direct access to the forum's style sheet" as described on that page to add the styles:


#nav-tree li, .container.new-area.wysiwyg-area, .container.posts.summary {display: none;}
#nav-tree li:first-child {display: inline-block;}

to the end of the actual stylesheet.

JRR
04-20-2015, 01:29 AM
Works like a charm John and the permission message comes up just as planned, no more back door editing! BTW we came out second at the tournament! Thanks!

jscheuer1
04-20-2015, 03:39 AM
Great! Looks good here too. There's a plus and a minus with this method as regards javascript disabled browsers. On the plus side, folks without javascript will not be able to edit posts past deadlines unless they also use something like the browser's developer's console to change the css for the page. On the minus side - they (even if they are staff) won't be able to edit any posts without that and may have other problems/inconveniences with the forum that they wouldn't have already had, though they would have had plenty of problems/inconveniences with the board even without this mod. We can try adding a noscript only stylesheet directly to the body to make it so they can edit, but then they will be able to edit at any time again - their own posts only unless they are staff. As long as all staff have javascript, this shouldn't be a huge problem. Try the test forum with javascript disabled to see how bad it might be.

One other thing for now. In the script, in the comment section I still had a typo. Being a comment, it doesn't effect the code, but since it's an instruction, it should be fixed. I fixed it in my last post with the full script code. But here's the correction as well so you can change your copy if you like. This (at the beginning):


/* Replace elapsed time with specific time (Sept 15, 2013) */
/* Note: - set .nav-tree li, .container.new-area.wysiwyg-area, .container.posts.summary to display: none; in the stylesheet */
/* Set #nav-tree li:first-child to display: inline-block; in the stylesheet */

should be:


/* Replace elapsed time with specific time (Sept 15, 2013) */
/* Note: - set #nav-tree li, .container.new-area.wysiwyg-area, .container.posts.summary to display: none; in the stylesheet */
/* Set #nav-tree li:first-child to display: inline-block; in the stylesheet */



I spoke too soon. One more tweak to get it to look more like the actual error page, replace (fairly near the top in the script we've been using for this):


$('#scrollerbutton').remove();

with:


document.title = "Oops, there was an error! | Forum";

JRR
04-20-2015, 12:21 PM
OK John a update, made the tweaks and all is working fine but when we use the URL back door line this is the message we get:

Oops, there was an error! You don't have permission to edit this post.

instead of:

Oops, there was an error! You don't have permission to edit this post, the time limit for that has expired. If you want help, please contact a staff member or the Admin for assistance.


It's no big deal. I'm wondering if it is just that message is too long?

Also I've got a lady that wants to use this code badly and she uses Opera and says it doesn't work? I told her to join my test forum and see if it does with Opera because it's possible she has other coding that could interfere? I'll get back on that one, I know nothing about Opera?

jscheuer1
04-20-2015, 03:05 PM
What happens is, if you have no permission to edit because it's not your post, you get the shorter message, the board already did that. In fact, I took the look and feel of that page and tried to make what one sees when one tries to edit one's own post past the time limit be almost the same. I pretty much succeeded I think. I did add the longer message though, so that someone would know they could get help if it was really important to edit their post - like if there was a link there they later realized they shouldn't have used or something.

The only thing I'm concerned about now is how it looks on a slightly more customized board, say on SCOOTER PROFESSOR, the word FORUM in the document title (usually shown on the current tab or while hovering the page's tab in the browser, and in the browser's history listings) is replaced by SCOOTER PROFESSOR, so it should also be in our made up edit/error page's title. Just thinking about this, I already know how to do that, and will publish it here in a moment. Other customizations should scale through, as they are already in the template (custom names, terms, images on the page itself), stylesheet (colors, backgrounds, and fonts - I used the same classes as a real error page), or any embellishments added by javascript in the template - they would also carry through. I also made the code a little more efficient, here's the latest:


<script type="text/javascript">

/* Replace elapsed time with specific time (Sept 15, 2013) */
/* Note: - set #nav-tree li, .container.new-area.wysiwyg-area, .container.posts.summary to display: none; in the stylesheet */
/* Set #nav-tree li:first-child to display: inline-block; in the stylesheet */
$(function(){
var howlongallowed = 300000; /* 5 times 60 times 1000, (5 minutes = 300000 milliseconds) */
var errortitle = "Oops, there was an error!"
var editexpiredmsg = "You don't have permission to edit this post, the time limit for that has expired. If you want help, please contact a staff member or the Admin for assistance.";
var dispnoneditels = '.container.new-area.wysiwyg-area, .container.posts.summary';
var dispinbl = '#nav-tree li';
if(/\/post\/\d+\/edit$/.test(window.location.href) && !proboards.data('user').is_staff &&
new Date().getTime() - proboards.data('page').post.created_on * 1000 > howlongallowed){
$('.container.new-area.wysiwyg-area').replaceWith('<div class="container error">\n<div class="title-bar">\n<h2>' + errortitle + '</h2>\n</div>'+
'<div class="content pad-all cap-bottom auto-overflow">\n' + editexpiredmsg + '\n</div>');
document.title = errortitle + " |" + document.title.split('|').pop();
} else {
$(dispnoneditels).css({display: 'block'});
$(dispinbl).css({display: 'inline-block'});
}
function keepwatch($del, raw_time, unbind){
if(new Date().getTime() - raw_time > howlongallowed){
if(unbind === true){
$('a', $del).off();
}
$del.remove();
return;
} else {
setTimeout(function(){keepwatch($del, raw_time, unbind);}, 300);
}
}

var a = 0, timeID = null, ac = arguments.callee, abbr = this.jquery? this : (this.ownerDocument ? $(this) : $('abbr.time'))
for(; a < $.livequery.queries.length; a++){
if($.livequery.queries[a].selector == "abbr.time" && "function" == typeof $.livequery.queries[a].fn && $.livequery.queries[a].fn.toString().indexOf("non_mod_date") != -1)
{
timeID = $.livequery.queries[a]/*.id*/; $.livequery.stop(timeID.id);break;
}
}
//$('abbr.time')
abbr.each(function () {
var time = $(this).addClass('modified_time').removeClass('time'), raw_date = new Date(parseInt(time.data("timestamp"),10));
if(!proboards.data('user').is_staff){
var raw_time = raw_date.getTime(), $del, $edit = $(this).parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') > -1){
$del = $(del);
return false;
}
}).end().find('.edit-button');
if($del){keepwatch($del, raw_time, true);}
if($edit.length){keepwatch($edit, raw_time);}
}
if($(this).hasClass('recent_time') && !/yesterday/i.test($(this).text())){
time = time.removeClass('recent_time');
var today = raw_date.getDate() == (new Date()).getDate()?"today":"yesterday",
user_date = ['M d, yy', 'd M, yy'][proboards.data("time_style") || 0];
time.replaceWith(
$(this).clone(true).addClass('recent_time')
.html(
'<span class="'+today+'">'+today+' </span>'
+ '<span class="at">at</span> <span class="at-time">' +
(proboards.data('military_time') ? $.formatTime('HH:mm', raw_date) : $.formatTime('h:mmp', raw_date))
+'</span>'
)
);
}else if(/yesterday/i.test($(this).text())){
time.replaceWith(
$(this).clone(true)
.html(
'<span class="yesterday">yesterday </span><span class="at">at </span><span class="at-time">'
+ $(this).text().split("at ")[1]
+'</span>'
)
)
}else{
if(time.text().indexOf(" at ")== -1)
time.text($.datepicker.formatDate((proboards.data('time_style') ? 'd M yy' : 'M d, yy'), raw_date) + ' at ' + $.formatTime((proboards.data('military_time') ? 'HH:mm' : 'h:mmp'), raw_date))
time.replaceWith(function(){
for(var dt = time.text().split(" at")[0], a = dt.split(/,?\s+/), b=0, c = $('<span></span>'); b<a.length; b++){
if((d = a[b].match(/^(\d+)$/))){
if(d[1].length == 4)
c.append('<span class="year">'+a[b]+' </span>').addClass("year_"+a[b]);
else
c.append('<span class="day">'+a[b]+' </span>').addClass("day_"+a[b])
}else{
c.append('<span class="month">'+a[b]+' </span>').addClass("month_"+a[b])
}
}
c.append('<span class="at">at </span>').append('<span class="at-time">' + time.text().split(" at ")[1] + '</span>')
return time.clone(true).html('').append(c)
})
}

})
$('abbr.modified_time').addClass('time'); //re-enable livequery treatment
if(!ac.func){
ac.func = function(){
$.livequery.run(timeID.id);
ac();
}
}
if(!ac.shoutbox){ ac.shoutbox = $('.shoutbox_messages')
.on('shoutbox_update.has-payload', function(event,data){
if(data.shout.length){
data.shout.each(function(){
var time = $('abbr.time',this)
timeID.fn.call(time);
ac.call(time.addClass('recent_time'));
})
}
})}
if($.inArray(ac.func, proboards.events.afterSearch) == -1){ proboards.on("afterSearch", ac.func); }
})

</script>

JRR
04-20-2015, 09:36 PM
I'll put it in Scooter Professor and see how it does along on my test forum. BTW the person using Opera worked out their browser issues and all is fine with them.


Ok John I just tested it on the test forum and when I tried to edit it with the URL link with my post number I still got the short message?

http://scootproftest.freeforums.net/post/176/edit

I didn't get your longer message tell me to get with the admin and such?

Update. I installed this on Scooter Professor and it works like a charm. I took it back out as I'm not ready to use it yet. But when trying to edit my own post I just like on the test forum still get the short message? Other than that' it's perfect.

jscheuer1
04-21-2015, 12:20 AM
I'm not sure what to say about you getting the shorter message. I'm not getting it. I think it's either the browser or how you're logged in. I just tried your test page - I was a guest, so of course I got the shorter message. Even if I logged in, I would get the shorter message, because that's not my post. It's only when you are logged in, and you are not staff or admin, and it is your message, and it's beyond the allowed time - only then will you get the longer message. Now, it's possible that different browsers might do things in a different order and that somehow gives the shorter message in all cases. But I sort of doubt that.

Are you sure you were logged on as 008 when you tried to edit post 176?

jscheuer1
04-21-2015, 12:31 AM
Hmm, I just tried in Firefox, Opera, and IE (I had been testing all along in Chrome, and that was still working). In Firefox and Opera I get the longer message if I'm logged in and try to edit an older message of mine. In IE - I cannot log in. Even using my correct name and password - several attempts, I cannot log on using that browser - so of course I get the shorter message.

I had an idea the trouble in IE might be that I had cookies blocked. I did. So I unblocked them, then was able to log on. After that, I did get the longer message while trying to edit an older post of mine on the test board.

If you are still having problems, post a screen capture of the entire browser or at least so I can see the url and both the error message and the user name.

JRR
04-21-2015, 02:45 AM
Went and done the same thing John, checked for updates, cleared the cache, restarted my computer and all is well, error message came up just like it is supposed to! Man sometimes IE11 is tough! I can't thank you enough for all of your help!

JRR
04-22-2015, 12:48 AM
John I've had another request about this code. I've never used it but PB has a thing that some people really like and it's called a shoutbox and I enabled it just now on my test forum that you are a member of. It naturally has timestamps and in this case when you put your cursor over your post/shout the edit button appears and to the far right it has a X button which will delete the shout/post.

As I mentioned on the very first page I use the code made by a member at PB that changes the V5 military time format back to the old V4 format of specific time and day which is what you started working with.


But the changes you made which works great for the main forum doesn't work with the shoutbox? Is it possible that you can make it do so? Now here is a tidbit of info that I feel is very important for you to know. Originally the code didn't change the shoutbox time and the maker of that code fixed it where it would and here is a link with his post explaining why and the changes he made to make it work forum wide including the shoutbox.

http://support.proboards.com/thread/449282/show-specific-time?page=2



I have made some shouts on my test forum as a regular member 008 to see if the edit button and the delete X button have disappeared and they have not. I'll await your reply.

jscheuer1
04-22-2015, 01:24 AM
The conversion of the shoutbox time to specific time and day only occurs if the page is refreshed. Unless there's an aftershout function or something like that which we can use to refresh the page and/or convert the time as soon as the shout is made, we will not be able to be as complete with the shout edit and delete buttons as we are with the post ones. Even without that (a shout callback function), we are converting the shout's time the next and all subsequent times the page is refreshed and can at that point remove it's edit and delete buttons if time is expired or expires while the page is loaded. Do you know of a shout callback function? It would be a function that fires after a new shout appears on the page. It may be optional - currently empty or unused, or not even implemented, but available for/to use if desired, or it might be used for some things already and we could just add our purpose(s) to it.

If you know of such a function, let me know. In the meantime I will look for it myself as well as begin sketching out the code to track the age of shout edit and del buttons.

jscheuer1
04-22-2015, 01:49 AM
OK, there is a callback (actually some callbacks) available for the shoutbox code that are specific to the time code we are already using. Add this script to the page before the script we are currently using:


<script type="text/javascript">

$(function(){
var shoutbox_messages = $('.shoutbox_messages')
/* create custom shoutbox events
*
* most useful events would be "shoutbox_update" , "shoutbox_edit" and "shoutbox_add"
* eventHandler = function(event,dataObject)
* shout prop on dataObject would hold a jQuery array of last shout node if event had a payload
* args prop on dataObject would hold a reference to the arguments from the AJAX request itself
* all new shoutbox posts (since page load) is given class "shoutbox-new-post"
* all new shoutbox posts (since page load) is given a .data("shoutinfo") which is same as data param in handler
* events that carry a payload has namespace of "has-payload" else "empty"
* events that occur in the send phase gets a namespace of "ajaxSend" else "ajaxComplete"
*/
shoutbox_messages.bind('ajaxComplete ajaxSend', function(ev,jxhr,inf){
if(inf.url && /shoutbox\/(\w+)/.test(inf.url)){
var data = {"args":arguments, shout:$()}
inf.shoutEvent = RegExp.$1.replace(/\//g,"_");
inf.payload = $.parseJSON(jxhr.responseText)||{}
var shouts = $();
var cev = 'shoutbox_'+ inf.shoutEvent + "." + ev.type;
if((inf.payload.new_ids||[])[0]){
cev += ".has-payload";
var new_ids = $($.map(inf.payload.new_ids,function(e){return ".shoutbox-post-" + e + ' .details abbr.time';}).join(", "),this)
new_ids.each(function(i,e){
var shout = $(this).closest('.shoutbox-post'), user = $('.user-link', shout).eq(0);
if(shout.data("shoutinfo")) return;
shoutbox_last = +inf.payload.new_ids[inf.payload.new_ids.length-1];
data.shout = shout;
data.user = {
url:user.attr("href"),
name: proboards.escape_html(user.text()),
username:user.attr("title").substr(1),
group_ids: [String(user.attr('class').match(/(?:group-(\d+))/)[1])]
}
data.message = $('.message',shout).text();
data.user.id = data.user.url.split(/\//).pop();
shouts = shout.add(shouts);
shout.data("shoutinfo",data);
if(shouts.length == inf.payload.new_ids.length){
//new_ids.expire(arguments.callee);
shoutbox_messages.trigger(cev, data); //namespaced
shoutbox_messages.trigger(cev.split(/\./)[0], data); //no namespacing
}
}).closest('.shoutbox-post').addClass('shoutbox-new-post')
}else{ //no new shouts then append an "empty" namespace
shoutbox_messages.trigger(cev+".empty", data); //namespaced
shoutbox_messages.trigger(cev.split(/\./)[0], data); //no namespacing
}
}
})
})

</script>

Once that's in the template, there will be shoutbox callbacks that the code we already have will use when shouts are added and/or updated. Preliminary tests show these events might not be complete enough, but they are better than what we have at the moment. They might be better than I think because I can only add them after our current script at the moment. Once they are inserted before our current script, they may be even more effective. If not, I should be able to improve upon either their usefulness and/or the use that they are put to in order to achieve our purposes. First add the script as indicated and let me know it's there.

JRR
04-22-2015, 03:05 AM
Got the code added and you meant put this code in the footer right above the other code right?

JRR
04-22-2015, 03:28 AM
Made a shout and the edit and delete X have not disappeared? Will wait for your reply.

jscheuer1
04-22-2015, 01:36 PM
That code was not to remove the edit and deletes. It was part of the original time replacement code specifically for shoutbox. Without it, the job of removing the buttons in the same way we did for post would be a lot harder because our code wouldn't even fire when a shout was first made. Now it should, if so, I can just tweak it, if not, I will need to tweak what we just added or write new code.

JRR
04-22-2015, 03:33 PM
I just saw you doing tests and myself I'm still seeing the buttons. Yes I understood that this code is just a helper to the other code and doesn't remove anything itself. That's the way it worked with the specific time code of the author a PB. So it would seem that now that code has to be added to get rid of the shoutbox buttons?

jscheuer1
04-23-2015, 01:08 AM
Right, and now I'm ready to start actual testing of the code to time out the edit and delete buttons of the shouts. I have a hunch that we can get rid of the helper code and still get decent results. And I have some commented out code in this first trial that we will either want to bring back or get rid of depending upon what happens with this and possibly other tests. But at least I'm ready to give it a go. So we now have the two scripts in the template, the helper first, and the second is now the one we have been working on all along. For now only replace the second of these two, the one we have been working on all along, with this one (keep the helper script in front of it for now):


<script type="text/javascript">

/* Replace elapsed time with specific time (Sept 15, 2013) */
/* Note: - set #nav-tree li, .container.new-area.wysiwyg-area, .container.posts.summary to display: none; in the stylesheet */
/* Set #nav-tree li:first-child to display: inline-block; in the stylesheet */
$(function(){
var howlongallowed = 300000; /* 5 times 60 times 1000, (5 minutes = 300000 milliseconds) */
var errortitle = "Oops, there was an error!"
var editexpiredmsg = "You don't have permission to edit this post, the time limit for that has expired. If you want help, please contact a staff member or the Admin for assistance.";
var dispnoneditels = '.container.new-area.wysiwyg-area, .container.posts.summary';
var dispinbl = '#nav-tree li', boards = proboards, page = boards && typeof boards.data === 'function'? boards.data('page') : null, post, created;
if(/\/post\/\d+\/edit$/.test(window.location.href) && !proboards.data('user').is_staff && page &&
(post = page.post) && (created = post.created_on) && new Date().getTime() - created * 1000 > howlongallowed){
$('.container.new-area.wysiwyg-area').replaceWith('<div class="container error">\n<div class="title-bar">\n<h2>' + errortitle + '</h2>\n</div>'+
'<div class="content pad-all cap-bottom auto-overflow">\n' + editexpiredmsg + '\n</div>');
document.title = errortitle + " |" + document.title.split('|').pop();
} else {
$(dispnoneditels).css({display: 'block'});
$(dispinbl).css({display: 'inline-block'});
}
function keepwatch($del, raw_time, unbind){
if(new Date().getTime() - raw_time > howlongallowed){
if(unbind === true){
$('a', $del).off();
}
$del.remove();
return;
} else {
setTimeout(function(){keepwatch($del, raw_time, unbind);}, 300);
}
}

var a = 0, timeID = null, ac = arguments.callee, abbr = this.jquery? this : (this.ownerDocument ? $(this) : $('abbr.time'))
for(; a < $.livequery.queries.length; a++){
if($.livequery.queries[a].selector == "abbr.time" && "function" == typeof $.livequery.queries[a].fn && $.livequery.queries[a].fn.toString().indexOf("non_mod_date") != -1)
{
timeID = $.livequery.queries[a]/*.id*/; $.livequery.stop(timeID.id);break;
}
}
//$('abbr.time')
abbr.each(function () {
var time = $(this).addClass('modified_time').removeClass('time'), raw_date = new Date(parseInt(time.data("timestamp"),10));
if(!proboards.data('user').is_staff){
var raw_time = raw_date.getTime(), $del, $this = $(this), $edit, unbind;
if($this.parents('.shoutbox-post').length){
$edit = $this.prev('.shoutbox_edit_button');
$del = $this.parent().next('.shoutbox_delete_button');
} else {
$edit = $this.parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') > -1){
$del = $(del);
unbind = true
return false;
}
}).end().find('.edit-button');
}
if($del && $del.length){keepwatch($del, raw_time, unbind);}
if($edit.length){keepwatch($edit, raw_time);}
}
if($(this).hasClass('recent_time') && !/yesterday/i.test($(this).text())){
time = time.removeClass('recent_time');
var today = raw_date.getDate() == (new Date()).getDate()?"today":"yesterday",
user_date = ['M d, yy', 'd M, yy'][proboards.data("time_style") || 0];
time.replaceWith(
$(this).clone(true).addClass('recent_time')
.html(
'<span class="'+today+'">'+today+' </span>'
+ '<span class="at">at</span> <span class="at-time">' +
(proboards.data('military_time') ? $.formatTime('HH:mm', raw_date) : $.formatTime('h:mmp', raw_date))
+'</span>'
)
);
}else if(/yesterday/i.test($(this).text())){
time.replaceWith(
$(this).clone(true)
.html(
'<span class="yesterday">yesterday </span><span class="at">at </span><span class="at-time">'
+ $(this).text().split("at ")[1]
+'</span>'
)
)
}else{
if(time.text().indexOf(" at ")== -1)
time.text($.datepicker.formatDate((proboards.data('time_style') ? 'd M yy' : 'M d, yy'), raw_date) + ' at ' + $.formatTime((proboards.data('military_time') ? 'HH:mm' : 'h:mmp'), raw_date))
time.replaceWith(function(){
for(var dt = time.text().split(" at")[0], a = dt.split(/,?\s+/), b=0, c = $('<span></span>'); b<a.length; b++){
if((d = a[b].match(/^(\d+)$/))){
if(d[1].length == 4)
c.append('<span class="year">'+a[b]+' </span>').addClass("year_"+a[b]);
else
c.append('<span class="day">'+a[b]+' </span>').addClass("day_"+a[b])
}else{
c.append('<span class="month">'+a[b]+' </span>').addClass("month_"+a[b])
}
}
c.append('<span class="at">at </span>').append('<span class="at-time">' + time.text().split(" at ")[1] + '</span>')
return time.clone(true).html('').append(c)
})
}

})
$('abbr.modified_time').addClass('time'); //re-enable livequery treatment
if(!ac.func){
ac.func = function(){
$.livequery.run(timeID.id);
ac();
}
}
if(!ac.shoutbox){ ac.shoutbox = $('.shoutbox_messages')
.on('shoutbox_update.has-payload, shoutbox_add', function(event,data){/* console.log(event.type); */
if($('abbr.time', this).not('.modified_time').length){/* console.log('shoutbox: ' + $('abbr.time',this).length); */
/* setTimeout(function(){ */$('.shoutbox-post').each(function(){
var time = $('abbr.time',this)
if(!time.length){return true;}
timeID.fn.call(time);
ac.call(time);
});/* }, 100); */
}
})}
if($.inArray(ac.func, proboards.events.afterSearch) == -1){ proboards.on("afterSearch", ac.func); }
})

</script>

JRR
04-23-2015, 12:22 PM
You got it! Awesome! all buttons gone, in posts and shoutbox!

JRR
04-23-2015, 03:38 PM
John do you mind highlighting the changes you made in this code for me so I have a reference? Is the code now done to your satisfaction, a little confused about some of your shoutbox comments because it seemed you didn't quite like the results?

jscheuer1
04-23-2015, 04:09 PM
OK, it is working the way I want it to for removing the buttons. But, it's not changing the elapsed time with specific time on a new shout unless you edit the shout (or any editable shout shout I think) or refresh the page. I think that's because it clones previous shouts to get the basic look, then adds the user and new shout text, either that, or because the time code can't change a time that would read 'now'. Anyway, I have an idea.

What I want to do is get rid of the helper code, and change the script that we have been using to this:


<script type="text/javascript">

/* Replace elapsed time with specific time (Sept 15, 2013) */
/* Note: - set #nav-tree li, .container.new-area.wysiwyg-area, .container.posts.summary to display: none; in the stylesheet */
/* Set #nav-tree li:first-child to display: inline-block; in the stylesheet */
$(function(){
var howlongallowed = 300000; /* 5 times 60 times 1000, (5 minutes = 300000 milliseconds) */
var errortitle = "Oops, there was an error!"
var editexpiredmsg = "You don't have permission to edit this post, the time limit for that has expired. If you want help, please contact a staff member or the Admin for assistance.";
var dispnoneditels = '.container.new-area.wysiwyg-area, .container.posts.summary';
var dispinbl = '#nav-tree li', boards = proboards, page = boards && typeof boards.data === 'function'? boards.data('page') : null, post, created;
if(/\/post\/\d+\/edit$/.test(window.location.href) && !proboards.data('user').is_staff && page &&
(post = page.post) && (created = post.created_on) && new Date().getTime() - created * 1000 > howlongallowed){
$('.container.new-area.wysiwyg-area').replaceWith('<div class="container error">\n<div class="title-bar">\n<h2>' + errortitle + '</h2>\n</div>'+
'<div class="content pad-all cap-bottom auto-overflow">\n' + editexpiredmsg + '\n</div>');
document.title = errortitle + " |" + document.title.split('|').pop();
} else {
$(dispnoneditels).css({display: 'block'});
$(dispinbl).css({display: 'inline-block'});
}
function keepwatch($del, raw_time, unbind){
if(new Date().getTime() - raw_time > howlongallowed){
if(unbind === true){
$('a', $del).off();
}
$del.remove();
return;
} else {
setTimeout(function(){keepwatch($del, raw_time, unbind);}, 300);
}
}

var a = 0, timeID = null, ac = arguments.callee, abbr = this.jquery? this : (this.ownerDocument ? $(this) : $('abbr.time'))
for(; a < $.livequery.queries.length; a++){
if($.livequery.queries[a].selector == "abbr.time" && "function" == typeof $.livequery.queries[a].fn && $.livequery.queries[a].fn.toString().indexOf("non_mod_date") != -1)
{
timeID = $.livequery.queries[a]/*.id*/; $.livequery.stop(timeID.id);break;
}
}
//$('abbr.time')
abbr.each(function () {
var time = $(this).addClass('modified_time').removeClass('time'), raw_date = new Date(parseInt(time.data("timestamp"),10));
if(!proboards.data('user').is_staff){
var raw_time = raw_date.getTime(), $del, $this = $(this), $edit, unbind;
if($this.parents('.shoutbox-post').length){
$edit = $this.prev('.shoutbox_edit_button');
$del = $this.parent().next('.shoutbox_delete_button');
} else {
$edit = $this.parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') > -1){
$del = $(del);
unbind = true
return false;
}
}).end().find('.edit-button');
}
if($del && $del.length){keepwatch($del, raw_time, unbind);}
if($edit.length){keepwatch($edit, raw_time);}
}
if($(this).hasClass('recent_time') && !/yesterday/i.test($(this).text())){
time = time.removeClass('recent_time');
var today = raw_date.getDate() == (new Date()).getDate()?"today":"yesterday",
user_date = ['M d, yy', 'd M, yy'][proboards.data("time_style") || 0];
time.replaceWith(
$(this).clone(true).addClass('recent_time')
.html(
'<span class="'+today+'">'+today+' </span>'
+ '<span class="at">at</span> <span class="at-time">' +
(proboards.data('military_time') ? $.formatTime('HH:mm', raw_date) : $.formatTime('h:mmp', raw_date))
+'</span>'
)
);
}else if(/yesterday/i.test($(this).text())){
time.replaceWith(
$(this).clone(true)
.html(
'<span class="yesterday">yesterday </span><span class="at">at </span><span class="at-time">'
+ $(this).text().split("at ")[1]
+'</span>'
)
)
}else{
if(time.text().indexOf(" at ")== -1)
time.text($.datepicker.formatDate((proboards.data('time_style') ? 'd M yy' : 'M d, yy'), raw_date) + ' at ' + $.formatTime((proboards.data('military_time') ? 'HH:mm' : 'h:mmp'), raw_date))
time.replaceWith(function(){
for(var dt = time.text().split(" at")[0], a = dt.split(/,?\s+/), b=0, c = $('<span></span>'); b<a.length; b++){
if((d = a[b].match(/^(\d+)$/))){
if(d[1].length == 4)
c.append('<span class="year">'+a[b]+' </span>').addClass("year_"+a[b]);
else
c.append('<span class="day">'+a[b]+' </span>').addClass("day_"+a[b])
}else{
c.append('<span class="month">'+a[b]+' </span>').addClass("month_"+a[b])
}
}
c.append('<span class="at">at </span>').append('<span class="at-time">' + time.text().split(" at ")[1] + '</span>')
return time.clone(true).html('').append(c)
})
}

})
$('abbr.modified_time').addClass('time'); //re-enable livequery treatment
if(!ac.func){
ac.func = function(){
$.livequery.run(timeID.id);
ac();
}
}
function fixshoutboxtimes(){
if($('.shoutbox_messages').find('.year').length){
$('.shoutbox-post').each(function(){
var time = $('abbr.time',this)
if(!time.length){return true;}
timeID.fn.call(time);
ac.call(time);
});
}
}
if($('.shoutbox_messages').length && !$('.shoutbox_messages').data('running')){
setInterval(function(){fixshoutboxtimes();}, 300);
$('.shoutbox_messages').data('running', 'true');
}
if($.inArray(ac.func, proboards.events.afterSearch) == -1){ proboards.on("afterSearch", ac.func); }
})

</script>

JRR
04-23-2015, 04:21 PM
Got it in John

jscheuer1
04-23-2015, 04:39 PM
OK, that didn't work. Bring back the helper script, and change our script to:


<script type="text/javascript">

/* Replace elapsed time with specific time (Sept 15, 2013) */
/* Note: - set #nav-tree li, .container.new-area.wysiwyg-area, .container.posts.summary to display: none; in the stylesheet */
/* Set #nav-tree li:first-child to display: inline-block; in the stylesheet */
$(function(){
var howlongallowed = 300000; /* 5 times 60 times 1000, (5 minutes = 300000 milliseconds) */
var errortitle = "Oops, there was an error!"
var editexpiredmsg = "You don't have permission to edit this post, the time limit for that has expired. If you want help, please contact a staff member or the Admin for assistance.";
var dispnoneditels = '.container.new-area.wysiwyg-area, .container.posts.summary';
var dispinbl = '#nav-tree li', boards = proboards, page = boards && typeof boards.data === 'function'? boards.data('page') : null, post, created;
if(/\/post\/\d+\/edit$/.test(window.location.href) && !proboards.data('user').is_staff && page &&
(post = page.post) && (created = post.created_on) && new Date().getTime() - created * 1000 > howlongallowed){
$('.container.new-area.wysiwyg-area').replaceWith('<div class="container error">\n<div class="title-bar">\n<h2>' + errortitle + '</h2>\n</div>'+
'<div class="content pad-all cap-bottom auto-overflow">\n' + editexpiredmsg + '\n</div>');
document.title = errortitle + " |" + document.title.split('|').pop();
} else {
$(dispnoneditels).css({display: 'block'});
$(dispinbl).css({display: 'inline-block'});
}
function keepwatch($del, raw_time, unbind){
if(new Date().getTime() - raw_time > howlongallowed){
if(unbind === true){
$('a', $del).off();
}
$del.remove();
return;
} else {
setTimeout(function(){keepwatch($del, raw_time, unbind);}, 300);
}
}

var a = 0, timeID = null, ac = arguments.callee, abbr = this.jquery? this : (this.ownerDocument ? $(this) : $('abbr.time'))
for(; a < $.livequery.queries.length; a++){
if($.livequery.queries[a].selector == "abbr.time" && "function" == typeof $.livequery.queries[a].fn && $.livequery.queries[a].fn.toString().indexOf("non_mod_date") != -1)
{
timeID = $.livequery.queries[a]/*.id*/; $.livequery.stop(timeID.id);break;
}
}
//$('abbr.time')
abbr.each(function () {
var time = $(this).addClass('modified_time').removeClass('time'), raw_date = new Date(parseInt(time.data("timestamp"),10));
if(!proboards.data('user').is_staff){
var raw_time = raw_date.getTime(), $del, $this = $(this), $edit, unbind;
if($this.parents('.shoutbox-post').length){
$edit = $this.prev('.shoutbox_edit_button');
$del = $this.parent().next('.shoutbox_delete_button');
} else {
$edit = $this.parents('.info').eq(0).next('.controls').find('.options_menu li').each(function(i, del){
if($(del).html().indexOf('Delete Post') > -1){
$del = $(del);
unbind = true
return false;
}
}).end().find('.edit-button');
}
if($del && $del.length){keepwatch($del, raw_time, unbind);}
if($edit.length){keepwatch($edit, raw_time);}
}
if($(this).hasClass('recent_time') && !/yesterday/i.test($(this).text())){
time = time.removeClass('recent_time');
var today = raw_date.getDate() == (new Date()).getDate()?"today":"yesterday",
user_date = ['M d, yy', 'd M, yy'][proboards.data("time_style") || 0];
time.replaceWith(
$(this).clone(true).addClass('recent_time')
.html(
'<span class="'+today+'">'+today+' </span>'
+ '<span class="at">at</span> <span class="at-time">' +
(proboards.data('military_time') ? $.formatTime('HH:mm', raw_date) : $.formatTime('h:mmp', raw_date))
+'</span>'
)
);
}else if(/yesterday/i.test($(this).text())){
time.replaceWith(
$(this).clone(true)
.html(
'<span class="yesterday">yesterday </span><span class="at">at </span><span class="at-time">'
+ $(this).text().split("at ")[1]
+'</span>'
)
)
}else{
if(time.text().indexOf(" at ")== -1)
time.text($.datepicker.formatDate((proboards.data('time_style') ? 'd M yy' : 'M d, yy'), raw_date) + ' at ' + $.formatTime((proboards.data('military_time') ? 'HH:mm' : 'h:mmp'), raw_date))
time.replaceWith(function(){
for(var dt = time.text().split(" at")[0], a = dt.split(/,?\s+/), b=0, c = $('<span></span>'); b<a.length; b++){
if((d = a[b].match(/^(\d+)$/))){
if(d[1].length == 4)
c.append('<span class="year">'+a[b]+' </span>').addClass("year_"+a[b]);
else
c.append('<span class="day">'+a[b]+' </span>').addClass("day_"+a[b])
}else{
c.append('<span class="month">'+a[b]+' </span>').addClass("month_"+a[b])
}
}
c.append('<span class="at">at </span>').append('<span class="at-time">' + time.text().split(" at ")[1] + '</span>')
return time.clone(true).html('').append(c)
})
}

})
$('abbr.modified_time').addClass('time'); //re-enable livequery treatment
if(!ac.func){
ac.func = function(){
$.livequery.run(timeID.id);
ac();
}
}
function fixshoutboxtimes(log){/* if(log === true && window.console){console.log('fired fixboxes');} */
$('.shoutbox-post').each(function(){
var time = $('abbr.time',this)
if(!time.length){return true;}
timeID.fn.call(time);
ac.call(time);
});
if($('.shoutbox_messages').find('.year').length){
setTimeout(function(){fixshoutboxtimes(log);}, 300);
}
}
if(!ac.shoutbox){ ac.shoutbox = $('.shoutbox_messages')
.on('shoutbox_update.has-payload, shoutbox_add', function(event,data){
if(event.type === 'shoutbox_add' || $('abbr.time', this).not('.modified_time').length){
if(event.type === 'shoutbox_add'){
ac.shoutbox.on('shoutbox_update.followup', function(){
$('.shoutbox-post').each(function(){
if($('abbr.time', this).find('.year').length){/* if(window.console){console.log('shoutbox time followup');} */
fixshoutboxtimes(true);
ac.shoutbox.off('shoutbox_update.followup');
}
});
});
} else {fixshoutboxtimes();}
}
})}
if($.inArray(ac.func, proboards.events.afterSearch) == -1){ proboards.on("afterSearch", ac.func); }
})

</script>

JRR
04-23-2015, 04:58 PM
On my last post in the shout box I mentioned the little black dot and it's came back from a previous code you worked on for me that I'm hoping we can get finished?

http://www.dynamicdrive.com/forums/showthread.php?77994-Turn-simple-javascript-code-to-a-button

jscheuer1
04-23-2015, 06:58 PM
That dot was in the quick reply. We can probably get rid of the one in the shout in a similar way. Do you want a button? I think you should just get rid of it completely (even the image link and not add an image button) because it looks to me that images don't show up in shouts. Before I get on to that, I'd like to know what you want there.

Also, it looks like older shouts from 4/21 aren't getting updated as to time. Can you edit them as 008?

JRR
04-23-2015, 09:20 PM
I removed them John as the admin and we'll start fresh, I even added a admin post and I'll go back and add a 008 post. When I put the codes back in the date was 4/21 and some of our previous posts were before that so I'm figuring that had an effect on it.

No images are not allowed in the shoutbox and I don't want them either. That funny dot has appeared again in several places even though we made a template mod to hide it? I'll look the forum over and find all the places.

jscheuer1
04-24-2015, 12:48 AM
We only intentionally hid or got rid of (hid I think) the dot where it was appearing in the quick reply controls section where it was part of the default added HTML for the postimages plug-in/add-on whatever that was. Apparently that code sees the shoutbox as similar enough to the quick reply editor to add its dot and a link (I'm not sure if you see the link, I do in Chrome).

In that case, whether you see the image link or not, removing both the dot and the image link (if seen) there should be easy - just add this at the end of the stylesheet (like we did those other rules for overcoming the url edit bug):


.shoutbox_form.content-box div {display: none;}

Now, as to the older shouts not having the converted time. I'm beginning to think that the time conversion code only converts times that can be expressed sanely in terms of 'yesterday at' or 'today at'. In fact I'm pretty sure that's how it works. If not, it's limited to fairly recent posts/shouts - all/most others it leaves alone, as it would get confusing to have something like 'two weeks and 4 days ago at'. Or 'four score and seven years ago at'. ;)

However, I didn't take that into consideration when I wrote the code that we were so pleased with earlier today. It can probably still work, but it needs to also ignore that the standard time format exists for shouts older than two days while still removing buttons if needed, otherwise it could spawn one or more endless loops. Any one or two of these would be harmless in and of themselves, but - given enough of them, they could crash a browser, or at the very least make the page very sluggish. Like if there were 30 shouts older than 2 days and someone made a new one - zing! It would not be pretty.

So, when I get the chance I will update that. In the meantime, add the style I'm suggesting in this post. It should take care of that dot.

jscheuer1
04-24-2015, 01:38 AM
The script has become just a little too long to publish in the editor, so I'm attaching it (right click and save as, then open in a text editor and copy it):

5668

It fixes the potential looping problem without sacrificing the advantages we already had - I think. I cannot test it locally though (other than to know there are no obvious syntax errors), so substitute it for the one we have been using/working on mostly in this thread, put it after the helper script, replacing the main script there we've been messing with.

JRR
04-24-2015, 03:07 AM
Got it in John and already made a post. Black dot gone.

JRR
04-30-2015, 05:34 PM
John would like to confirm one thing. In setting the time limit if I wanted 1 hour I would change the 5 which is minutes to 60 minutes I'm sure so if I want 12 hours I set the number to 720 right?

jscheuer1
04-30-2015, 07:19 PM
That's the idea. However, in the finished code, I have:


var howlongallowed = 300000; /* 5 times 60 times 1000, (5 minutes = 300000 milliseconds) */

The red 300000 is what the code is using, it's the milliseconds. I'm saving time for the code by doing the math for it, unlike at first where I had the code do the math. The green stuff now is just a comment, an explanation of how I arrived at 300000, it's ignored by the code. So, using this method 12hrs would be 12 * 60 * 60 * 1000 or 43200000 milliseconds. Replace 300000 with 43200000 for 12 hours.

JRR
05-01-2015, 04:00 AM
Got it John! Thanks!