Here is the code i want to add to the form, Im guessing as i go along.. and thinking aloud.. and documenting as i go..
Is there anything i am missing? i haven't tried this yet as i don't have a test server i can access at the moment
to load the script i add to the top of form.php
Code:
<script type="text/javascript" src="jscolor/jscolor.js"></script>
to display the button i want next to the comment box, and update the color in of text in the text box i added id="cmtx_comment" to line 1050 in form.php to make it this:
Code:
<textarea id="cmtx_comment" name="cmtx_comment" class="cmtx_field cmtx_textarea_field cmtx_comment_field" title="<?php echo CMTX_TITLE_COMMENT; ?>" placeholder="<?php echo CMTX_PLACEHOLDER_COMMENT; ?>" maxlength="<?php echo cmtx_setting('comment_maximum_characters'); ?>" onkeyup="cmtx_text_counter()" onkeydown="cmtx_text_counter()"><?php echo $cmtx_default_comment; ?></textarea>
And add the color picker with image to the next line:
Code:
<input type="image" img src="color.png" width="32" height="32" onclick="document.getElementById('color').color.showPicker();" onchange="document.getElementById('cmtx_comment').style.color = '#'+this.color"value="00eeff" class="color {pickerOnfocus:false, pickerClosable:true, pickerFaceColor:'transparent',pickerFace:3,pickerBorder:0,pickerInsetColor:'black'}" id="color">
<div style="clear: left;"></div>
so clicking the palette icon will display the color picker, when the close button is clicked on the picker the onchange will update the text in the textbox with the new color
I then need the value in 'color' sanitized and stored in the comment table in the color column
in app/processor.php i will add some checks:
Code:
if (!isset($_POST['color'])) { //if color not submitted
$_POST['color'] = "00eeff"; //set it with default value
}
$cmtx_color = trim($_POST['color']); //remove any space at beginning and end
if (!empty($cmtx_color)) { //if color value is set
cmtx_is_injected($cmtx_color); //check for injection attempt
if (!ctype_xdigit($color) || !strlen($color) == 6){ // only 6 hexidecimal numbers is valid for this field
$cmtx_color = "00eeff"; //set default color if anything different
}
$cmtx_color = cmtx_sanitize($cmtx_color, true, true); //sanitize color
} else {
$cmtx_color = "00eeff"; //set default if empty
}
and add it to the databse by adding it in at line 510
Code:
cmtx_db_query("INSERT INTO `" . $cmtx_mysql_table_prefix . "comments` (`name`, `email`, `website`, `town`, `country`, `rating`, `reply_to`, `comment`, `reply`, `ip_address`, `page_id`, `is_approved`, `approval_reasoning`, `is_admin`, `is_sent`, `sent_to`, `likes`, `dislikes`, `is_sticky`, `is_locked`, `is_verified`, `dated`, `color`) VALUES ('$cmtx_name', '$cmtx_email', '$cmtx_website', '$cmtx_town', '$cmtx_country', '$cmtx_rating', '$cmtx_reply_to', '$cmtx_comment', '', '$cmtx_ip_address', '$cmtx_page_id', 0, '$cmtx_approve_reason', '$cmtx_is_admin', 0, 0, 0, 0, 0, 0, 0, NOW(), '$cmtx_color')");
Now, to get it to display in the comments section i will make a few changes in include\functions\comments.php
to get the color from the database and send to the function add , $comments['color'] to lines 51 and 79 to make this
Code:
echo cmtx_generate_comment (false, $alternate, $comments['id'], $comments['name'], $comments['email'], $comments['website'], $comments['town'], $comments['country'], $comments['rating'], $comments['reply_to'], $comments['comment'], $comments['reply'], $comments['is_admin'], $comments['likes'], $comments['dislikes'], $comments['is_sticky'], $comments['is_locked'], $comments['dated'], $comments['color']);
line 161 add , $color to make this
Code:
function cmtx_generate_comment($is_preview, $alternate, $id, $name, $email, $website, $town, $country, $rating, $reply_to, $comment, $reply, $is_admin, $likes, $dislikes, $is_sticky, $is_locked, $dated, $color) { //generate comment
To display the text in the desired color, change line 315 to this
Code:
$cmtx_box .= '<span style="color:#' . $color . '">' . $comment . '</span>';
and for completeness lines 308 and 312 respectively
Code:
$cmtx_box .= '<span style="color:#' . $color . '">' . $comment_less . '</span>';
$cmtx_box .= '<span style="color:#' . $color . '">' . $comment . '</span>';
I think that's all i need, ill update as i get a chance to test. I hope someone finds this useful!