All times are UTC - 6 hours   |  Page 1 of 1

Dion Designs

Quote button

Quote button

Posted: November 3rd 2013, 4:56pm
by Daniel
Ok I know that I've done it before but I forgot how I did it :(

In one of my themes I was able to put a quote button in and it worked :) Now I went to put that button into a different theme (This is for wordpress) and I'm getting

It looks like that we are having issues here, do you have permission to comment on this post?

My javascript file, please note that it has some of the changes needed for it to work on the new theme:

Code: Select all
function jsEncode(str){

// ugly hack
str = " " + str;

var aStr = str.split(''), i = aStr.length, aRet = [];

while (--i) {
var iC = aStr[i].charCodeAt();

if (iC < 65 || iC > 127 || (iC>90 && iC<97)) {
aRet.push('&#'+iC+';');
} else {
aRet.push(aStr[i]);
}
}

return aRet.reverse().join('');

}

function quote(postid, author, commentarea, commentID, mce) {
try {
// If you don't want quotes begin with "<author>:", uncomment the next line
//author = null;

// begin code
var posttext = '';

if (window.getSelection){
posttext = window.getSelection();
}

else if (document.getSelection){
posttext = document.getSelection();
}

else if (document.selection){
posttext = document.selection.createRange().text;
}

else {
return true;
}

if (posttext=='') { // quoting entire comment

// quoteing the entire thing
var selection = false;
var commentID = commentID.split("comment-")[1];

// quote entire comment as html
var theQuote = "q-"+commentID;
//var theQuote = "comment-"+commentID;
var posttext = document.getElementById(theQuote).innerHTML;

// remove nested divs
var posttext = posttext.replace(/<div(.*?)>((.|\n)*?)(<\/div>)/ig, "");

// remove superfluous linebreaks
var posttext = posttext.replace(/\s\s/gm, "");

// do basic cleanups
var posttext = posttext.replace(/ /g, "");
var posttext = posttext.replace(/<p>/g, "\n");
var posttext = posttext.replace(/<\/\s*p>/g, "");
var posttext = posttext.replace(/<br>/g, "")

// remove nonbreaking space
var posttext = posttext.replace(/ /g, " ");

// remove nested spans
var posttext = posttext.replace(/<span(.*?)>((.|\n)*?)(<\/span>)/ig, "");

// remove nested quote links
var posttext = posttext.replace(/<a class="comment_quote_link"(.*?)>((.|\n)*?)(<\/a>)/ig, "");
}

// build quote
if (author) {

// prevent xss stuff
author = jsEncode(author);

var quote='\n<blockquote cite="comment-'+postid+'">\n\n<strong><a href="#comment-'+postid+'">'+unescape(author)+'</a></strong>: '+posttext+'</blockquote>\n';

} else {

var quote='\n<blockquote cite="comment-'+postid+'">\n\n'+posttext+'</blockquote>\n';

}

// send quoted content
if (mce == true) { // TinyMCE detected

//addQuoteMCE(comment,quote);
insertHTML(quote);
insertHTML("<p> </p>");

} else { // No TinyMCE detected

var comment=document.getElementById(commentarea);
addQuote(comment,quote);

}

return false;

} catch (e) {

alert("It looks like that we are having issues here, do you have permission to comment on this post?")

}
}

function addQuote(comment,quote){

/*
Derived from Alex King's JS Quicktags code (http://www.alexking.org/)
Released under LGPL license
*/

// IE support
if (document.selection) {
comment.focus();
sel = document.selection.createRange();
sel.text = quote;
comment.focus();
}

// Mozilla support

else if (comment.selectionStart || comment.selectionStart == '0') {
var startPos = comment.selectionStart;
var endPos = comment.selectionEnd;
var cursorPos = endPos;
var scrollTop = comment.scrollTop;
if (startPos != endPos) {

comment.value = comment.value.substring(0, startPos)
+ quote
+ comment.value.substring(endPos, comment.value.length);
cursorPos = startPos + quote.length

}

else {
comment.value = comment.value.substring(0, startPos)
+ quote
+ comment.value.substring(endPos, comment.value.length);
cursorPos = startPos + quote.length;

}

comment.focus();
comment.selectionStart = cursorPos;
comment.selectionEnd = cursorPos;
comment.scrollTop = scrollTop;

}

else {

comment.value += quote;

}

// If Live Preview Plugin is installed, refresh preview
try {
ReloadTextDiv();
}
catch ( e ) {
}
}


The link that I used

Code: Select all
   <ul class="profile-icons"> <li class="quote-icon">
<a href="javascript:void(null)" title="quote" onmousedown="quote('<?php comment_ID(); ?>', null, 'comment','div-comment-<?php comment_ID(); ?>', false);try { addComment.moveForm('div-comment-<?php comment_ID(); ?>', '<?php comment_ID(); ?>', 'respond', '1'); } catch(e) {}; return false;"><span>(Quote)</span></a>
</li></ul>


Now it work just fine on the original theme so I must be forgetting to change something.

Final theme html with button (one with issue)

Code: Select all
                <h2><a href="{U_TOPIC}" rel="bookmark" title="{TOPIC_SUBJECT}">{TOPIC_SUBJECT}</a></h2>

<!-- IF PAGINATION or TOTAL_POSTS -->
<div class="topic-actions">
<div class="pagination">
{TOTAL_POSTS}
<!-- IF PAGE_NUMBER --><!-- IF PAGINATION --> • {PAGE_NUMBER} • <span>{PAGINATION}</span><!-- ELSE --> • {PAGE_NUMBER}<!-- ENDIF --><!-- ENDIF -->
</div>
</div>
<!-- ENDIF -->

<!-- BEGIN postrow -->
<div class="post<!-- IF postrow.S_FIRST_ROW --> bg3<!-- ELSE --><!-- IF postrow.S_ROW_COUNT is odd --> bg2<!-- ELSE --> bg1<!-- ENDIF --><!-- ENDIF --><!-- IF (postrow.S_POST_UNAPPROVED or postrow.S_POST_REPORTED or postrow.S_POST_TRASHED) --> reported<!-- ENDIF -->" id="<!-- IF postrow.S_COMMENT -->comment-{postrow.POST_ID}<!-- ELSE -->post-{postrow.POST_ID}<!-- ENDIF -->">
<div class="inner"><span class="corners-top"><span></span></span>
<div class="postbody<!-- IF DYNAMIC_SIDEBAR and postrow.S_FIRST_ROW--> postbodyfull<!-- ELSEIF not postrow.S_FIRST_ROW --> postbodyfull<!-- ENDIF -->">
<!-- IF not S_IS_BOT -->
<ul class="profile-icons"> <li class="quote-icon">
<a href="javascript:void(null)" title="quote" onmousedown="quote('{postrow.POST_ID}', null, 'comment','comment-{postrow.POST_ID}', false);try { addComment.moveForm('comment-{postrow.POST_ID}', '{postrow.POST_ID}', 'respond', '1'); } catch(e) {}; return false;"><span>(Quote)</span></a>
</li></ul>
<!-- IF postrow.S_POST_ACTIONS and (postrow.U_POST_EDIT or postrow.U_POST_DELETE or postrow.U_POST_TRASH or postrow.U_POST_SPAM or postrow.U_POST_UNSPAM or postrow.U_POST_APPROVE or postrow.U_POST_UNAPPROVE) -->
<ul class="profile-icons">
<!-- IF postrow.U_POST_EDIT --><li class="edit-icon"><a href="{postrow.U_POST_EDIT}" title="{L_WP_COMMENT_EDIT_EXPLAIN}"><span>{L_WP_COMMENT_EDIT}</span></a></li><!-- ENDIF -->
<!-- IF postrow.U_POST_DELETE --><li class="delete-icon"><a href="{postrow.U_POST_DELETE}" title="{L_WP_COMMENT_DELETE_EXPLAIN}"><span>{L_WP_COMMENT_DELETE}</span></a></li><!-- ENDIF -->
<!-- IF postrow.U_POST_TRASH --><li class="{TRASH_IMG_CLASS}"><a href="{postrow.U_POST_TRASH}" title="{L_WP_COMMENT_TRASH_EXPLAIN}"><span>{L_WP_COMMENT_TRASH}</span></a></li><!-- ENDIF -->
<!-- IF postrow.U_POST_UNTRASH --><li class="{UNTRASH_IMG_CLASS}"><a href="{postrow.U_POST_UNTRASH}" title="{L_WP_COMMENT_UNTRASH_EXPLAIN}"><span>{L_WP_COMMENT_UNTRASH}</span></a></li><!-- ENDIF -->
<!-- IF postrow.U_POST_SPAM --><li class="{SPAM_IMG_CLASS}"><a href="{postrow.U_POST_SPAM}" title="{L_WP_COMMENT_SPAM_EXPLAIN}"><span>{L_WP_COMMENT_SPAM}</span></a></li><!-- ENDIF -->
<!-- IF postrow.U_POST_UNSPAM --><li class="{UNSPAM_IMG_CLASS}"><a href="{postrow.U_POST_UNSPAM}" title="{L_WP_COMMENT_UNSPAM_EXPLAIN}"><span>{L_WP_COMMENT_UNSPAM}</span></a></li><!-- ENDIF -->
<!-- IF postrow.U_POST_APPROVE --><li class="{APPROVE_IMG_CLASS}"><a href="{postrow.U_POST_APPROVE}" title="{L_WP_COMMENT_APPROVE_EXPLAIN}"><span>{L_WP_COMMENT_APPROVE}</span></a></li><!-- ENDIF -->
<!-- IF postrow.U_POST_UNAPPROVE --><li class="{UNAPPROVE_IMG_CLASS}"><a href="{postrow.U_POST_UNAPPROVE}" title="{L_WP_COMMENT_UNAPPROVE_EXPLAIN}"><span>{L_WP_COMMENT_UNAPPROVE}</span></a></li><!-- ENDIF -->
</ul>
<!-- ENDIF -->
<!-- ENDIF -->

<!-- IF postrow.S_COMMENT -->
<p class="author">
<!-- IF postrow.POSTER_AVATAR -->{postrow.POSTER_AVATAR}<br /><!-- ENDIF -->
<!-- IF S_IS_BOT -->{postrow.MINI_POST_IMG}<!-- ELSE --><a href="{postrow.U_MINI_POST}">{postrow.MINI_POST_IMG}</a><!-- ENDIF -->
{L_POST_BY_AUTHOR} <strong>{postrow.POST_AUTHOR_FULL}</strong> » {postrow.POST_DATE}
</p>
<!-- ELSE -->
<h3 class="first"><a href="{postrow.U_MINI_POST}">{postrow.MINI_POST_IMG}</a>{postrow.POST_SUBJECT}</h3>
<!-- ENDIF -->

<!-- IF postrow.S_POST_UNAPPROVED or postrow.S_POST_REPORTED or postrow.S_POST_TRASHED -->
<p class="rules">
<!-- IF postrow.S_POST_UNAPPROVED -->{REPORTED_IMG} <strong>{L_WP_COMMENT_UNAPPROVED}</strong><br /><!-- ENDIF -->
<!-- IF postrow.S_POST_REPORTED -->{REPORTED_IMG} <strong>{L_WP_COMMENT_REPORTED_NOTE}</strong><!-- ENDIF -->
<!-- IF postrow.S_POST_TRASHED -->{REPORTED_IMG} <strong>{L_WP_COMMENT_UNTRASHED_NOTE}</strong><!-- ENDIF -->
</p>
<!-- ENDIF -->

<div class="entry content">{postrow.MESSAGE}</div>

<!-- IF not postrow.S_COMMENT and ( postrow.POST_TAGS or postrow.POST_CATS or postrow.POST_EDIT or postrow.POST_COMENT or postrow.U_FOLLOW_FEED) -->
<div class="postmetadata alt notice">
{L_WP_AUTHOR_TITLE}: <strong>{postrow.POST_AUTHOR_FULL}</strong> » {postrow.POST_DATE}
<!-- IF postrow.POST_CATS --><br />{postrow.POST_CATS}<!-- ENDIF -->
<!-- IF postrow.POST_TAGS --><br />{postrow.POST_TAGS}<!-- ENDIF -->
<!-- IF postrow.XPOST_EDIT --><!-- IF postrow.POST_CATS --> | <!-- ELSE --><br /><!-- ENDIF --> <a class="post-edit-link" href="{postrow.U_POST_EDIT}" title="{L_EDIT_POST}">{L_EDIT_POST}</a><!-- ENDIF -->
<!-- IF postrow.U_FOLLOW_FEED --><br />{postrow.U_FOLLOW_FEED}<!-- ENDIF -->
<!-- IF postrow.U_YES_COMMENT_YES_PING --><br />{postrow.U_YES_COMMENT_YES_PING}<!-- ENDIF -->
<!-- IF postrow.U_NO_COMMENT_YES_PING --><br />{postrow.U_NO_COMMENT_YES_PING}<!-- ENDIF -->
<!-- IF postrow.U_YES_COMMENT_NO_PING --><br />{postrow.U_YES_COMMENT_NO_PING}<!-- ENDIF -->
<!-- IF postrow.U_NO_COMMENT_NO_PING --><br />{postrow.U_NO_COMMENT_NO_PING}<!-- ENDIF -->
</div>
<!-- ENDIF -->

<!-- IF postrow.SIGNATURE --><div id="sig-{postrow.POST_ID}" class="signature">{postrow.SIGNATURE}</div><!-- ENDIF -->

</div>
<!-- IF postrow.S_FIRST_ROW and not DYNAMIC_SIDEBAR -->
<!-- INCLUDE wordpress/author_body.html -->
<!-- ENDIF -->
<span class="corners-bottom"><span></span></span></div>
</div>

<!-- IF postrow.S_FIRST_ROW and POST_REPLIES --><br /><h4 id="comments">{POST_REPLIES}</h4><!-- ENDIF -->
<hr class="divider" />

<!-- END postrow -->

<!-- IF PREVIOUS_PAGE or NEXT_PAGE -->
<hr />
<div style="text-align: center;"><!-- IF PREVIOUS_PAGE -->{PREVIOUS_PAGE}<!-- ENDIF --><strong>{TOTAL_POSTS}</strong> • {PAGE_NUMBER}<!-- IF NEXT_PAGE -->{NEXT_PAGE}<!-- ENDIF --></div>
<!-- ENDIF -->

<hr />
<div class="topic-actions">
<!-- IF not S_IS_BOT and S_DISPLAY_REPLY_INFO -->
<div class="buttons">
<!-- IF S_IS_LOCKED -->
<div class="locked-icon"><a href="#" title="{L_TOPIC_LOCKED}"><span></span>{L_TOPIC_LOCKED_SHORT}{L_POST_REPLY}</a></div>
<!-- ELSE -->
<div class="reply-icon"><a id="reply-button" title="{L_POST_REPLY}"><span></span>{L_POST_REPLY}</a></div>
<!-- ENDIF -->
</div>
<!-- ENDIF -->

<!-- IF PAGINATION or TOTAL_POSTS -->
<div class="pagination">
{TOTAL_POSTS}
<!-- IF PAGE_NUMBER --><!-- IF PAGINATION --> • {PAGE_NUMBER} • <span>{PAGINATION}</span><!-- ELSE --> • {PAGE_NUMBER}<!-- ENDIF --><!-- ENDIF -->
</div>
<!-- ENDIF -->
</div>

<!-- IF not S_IS_BOT and not S_IS_LOCKED -->
<div id="respond">
<!-- INCLUDE wordpress/posting_body.html -->
</div>
<!-- ENDIF -->


If you want the original theme source code, you will find then here: http://themes.svn.wordpress.org/propress/2.9.5.2/

Thank-you :)

Quote button

Posted: November 3rd 2013, 8:35pm
by Dion
The comment ID (comment-{postrow.POST_ID}) is not defined in the theme HTML you provided. That would cause a JS error and generate the message you're receiving.

Quote button

Posted: November 4th 2013, 5:20am
by Daniel
I got it sorted out - I just got the original code out and started again and it worked the second time *slapped himself*