svivian / q2a-chat-room Goto Github PK
View Code? Open in Web Editor NEWChat room plugin for Question2Answer
Chat room plugin for Question2Answer
Seemed to be having problems setting the url for the chat. I followed the instructing to the letter. Chat is in the root/plugins/chat folder I used the url mysite.net/chat
I followed your first step
Download and extract the files to your plugins folder (e.g. qa-plugins/chat).
But i cant find the Plugin name in Admin section
Go to Admin > Plugin and click the link to set up the database tables. ?? why !?
To convert image links to tag, just do the following in qa-chat.js:
After:
$('#qa-chat-list').prepend($msg);
$msg.slideDown('fast');
add line:
parse_url_to_img();
below function qa_chat_add_message( post )
add function:
// parse img-URL to img tag
function parse_url_to_img() {
$('.qa-chat-item-data a').each( function() {
var regexr = "(https?:\/\/.*\.(?:png|jp?g|gif))";
if( $(this).attr('href').match(regexr) != null ) {
$(this).empty();
$(this).append("<img src='" + $(this).attr('href') + "' />");
}
});
}
Need to extract the various messages to language files.
Add to qa-chat.js:
/* YOUTUBE thumbnail */
$.extend({
jYoutube: function( url, size ){
if(url === null){ return ""; }
size = (size === null) ? "big" : size;
var vid;
var results;
results = url.match("[\\?&]v=([^&#]*)");
vid = ( results === null ) ? url : results[1];
if(size == "small"){
return "http://img.youtube.com/vi/"+vid+"/2.jpg";
}else {
return "http://img.youtube.com/vi/"+vid+"/0.jpg";
}
}
});
add after:
$('#qa-chat-list').prepend($msg);
$msg.slideDown('fast');
the line:
add_youtube_thumbnail();
and also add these functions:
// add youtube-URL to thumbnail img
function add_youtube_thumbnail() {
$('.qa-chat-item-data a').each( function() {
if( ytVidId($(this).attr('href')) && !$(this).find('img').length) {
var ytThumbnail = $.jYoutube('http://www.youtube.com/watch?v='+ytVidId($(this).attr('href')), 'big'); // or 'small'
$(this).prepend("<img src='" + ytThumbnail + "' /><br />Video: ");
}
});
}
function ytVidId(url) {
var p = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
return (url.match(p)) ? RegExp.$1 : false;
}
Where is the option that delete entries in chat room and how can I limit the number of entries showing in chat room?
Hi Scott,
I am digging deeper into your work, very nice coding.
Issue I am stuck now: I would like to display the chat history even for anonymous users.
What I tried in qa-chat.php:
before line: $qa_content['error'] = qa_insert_login_links((...
I added: $qa_content['custom_form'] = '<ul id="qa-chat-list"></ul>';
from line: if ( $lastid !== null ) {
I added:
if ( $lastid !== null ) {
$isAnonymous = false;`
if ( !$this->user_perms_view() ) {
// return;
$isAnonymous = true;
}
and line: $this->update_activity( $lastid==0 );
I enclosed with (to prevent mysql error due to activity update):
if(!$isAnonymous) {
$this->update_activity( $lastid==0 );
}
But it is not working!
Could you help me please :)
A plugin for Question2Answer that allows users to live-chat. Original source by Scott, extended by q2apro.
Added features:
number of new messages in tab title
sound notification
clear chat button for each user
parsing/embed of youtube and soundcloud links
weekly chat history email to admin
manual chat history triggered by admin
no link showing for database tables @svivian
I implemented a counter that shows the number of new chat messages in the page title, i.e. in the tab of the browser is is displaying: "(2) Chat - My Forum"
Code you need:
// add a message to the list
function qa_chat_add_message( post )
{
var $ex_post = $( '#qa-chat-id-'+post.postid );
if ( $ex_post.length == 0 )
{
var $msg = $( Tmpl.message( post ) );
$('.qa-chat-item-when', $msg).timeago();
$('#qa-chat-list').prepend($msg);
$msg.slideDown('fast');
// write count of new chat messages in page title, do not regard if post is not by user himself
if(!userPostsMessage) {
var rowCount = $('ul#qa-chat-list li:visible').length - userPostsCount;
if(startEventsVisible) { rowCount -= startEventsCount - userPostsCount; }
$('title').text('('+rowCount+') '+ pagetitle);
}
}
/*if ( $('.qa-chat-item').length > 80 )
$('.qa-chat-item:nth-child(n+81)').remove();
*/
}
var startEventsVisible = true;
var startEventsCount = 0;
var firstLoad = true;
var pagetitle = 'Mathe-Chat - Gute-Mathe-Fragen';
var userPostsMessage = false;
var userPostsCount = 0;
// fetch all new messages
function qa_chat_fetch_messages()
{
$.ajax({
type: 'post',
data: { ajax_get_messages: lastid },
success: function(response) {
var lines = response.split("\n");
if ( lines[0] != 'QA_AJAX_RESPONSE' || lines[1] == 0 )
return false;
cUser.id = lines[1];
var posts = $.parseJSON( lines[2] ).reverse();
for ( var i in posts ) {
qa_chat_add_message( posts[i] );
lastid = posts[i].postid;
}
// update active users
if ( lines[3] ) {
var users = $.parseJSON( lines[3] );
qa_chat_update_users( users );
}
if(firstLoad) {
startEventsCount = $('ul#qa-chat-list li:visible').length;
$('title').text('(0) '+ pagetitle);
firstLoad = false;
}
}
});
// adding a message to the chat
$('#qa-chat-form').submit( function() {
var message = $('#message').val();
if ( message.length == 0 )
return false;
$('#qa-chat-form input').attr({ disabled: 'disabled' });
$.ajax({
type: 'post',
data: { ajax_add_message: message, ajax_add_lastid: '0' },
success: function(response) {
$('#qa-chat-form input').removeAttr('disabled');
$('#message').val('').focus();
var lines = response.split("\n");
if ( lines[0] != 'QA_AJAX_RESPONSE' ) {
alert("There was a server error, please try again in a few minutes");
return false;
}
if ( lines[1] == 0 ) {
alert("Error: "+lines[2]);
return false;
}
userPostsMessage = true;
userPostsCount++;
var post = $.parseJSON( lines[2] );
qa_chat_add_message( post );
userPostsMessage = false;
cUser.idle = false;
}
});
return false;
} );
Error with Mysql 8:
PHP Question2Answer MySQL query error 1364: Field 'lastposted' doesn't have a default value - Query: INSERT INTO qa_chat_users (userid, lastpolled) VALUES (36509, NOW()) ON DUPLICATE KEY UPDATE lastpolled=NOW()
Suggested fix: Give a default value NOW() to lastposted.
Nothing is deleted yet.
My chat room is not at forum.learningwithexperts,ml/chat
I got one user calling another one 'stupid' within the chat.
That's why I like to add a chat filter to ******* blank out such words.
How/where would I implement the filter?
The words list can be within the chat.php file, no extra mysql entry necessary.
Inherit censorship list from Admin > Posting
Hi Scott, could you tell me what your reason is to use GMT instead of server time (date())?
From qa-chat.php:
// create dates for database
$now = time();
$this->dates = array(
'posted' => gmdate( 'Y-m-d H:i:s', $now ),
'posted_utc' => gmdate( 'Y-m-d\TH:i:s\Z', $now ),
);
Most chats are from top to bottom, chat field in the end of the page.
Would be great to have this feature/option with this chat plugin as well.
Good example by stackoverflow (CSS-fixed to bottom): https://chat.stackoverflow.com/rooms/110313/haskell-and-other-functional-languages
Hi,
it's is possbile to add a multi room with privileges, than we can switch the room including history
Ex: Multi Room change on same windows
Room User (reading only) : view by all
Room Members confirmed (Read and post) view by members, moderateur / admin
Room Moderator/Admin : (Read, post, delete, history, ban) view by moderateur / admin
Thank you
Very nice plugin
I would like to see an option for admin only to "edit" or "delete" a post.
Scenario: I wrote something in chat and wanted to change it later on. It is a waste of time to go to phpmyadmin each time!
Any idea for a quick and clean implementation? Ajax? Extra div?
Hi Scott, I started using your chat plugin. Nice work! Congratulations.
Could you implement the avatar img to display it front-end in online users list and/or for each user name on the left?
Thanks,
Kai
Currently only usernames show in chat and in sidebar but many users recognize each other with their avatars so it would be good if user avatars are shown.
I know this feature is already been requested before but there is no update on that feature so I thought to make a new issue for this.
For polling frequency, idle timeouts, number of messages displayed, etc.
Hi Scott, what has to be changed to allow anonymous participating in chat as well?
Basically, I am not sure if this is a good idea because of misuse, but would like to know.
Thanks.
Well, users complained that when opening links they lose the chat...
That's why I suggest changing line:
return qa_html_convert_urls($msg);
to:
return qa_html_convert_urls($msg,true);
which will open all posted links in a new window.
I want to show the chat bubble in left and right(for me)
I'm only asking for just add the class to chat item which is send by me. I can do the rest css work by my self.
also can you change the order of the elements like order: name, message, time instead of name, time, message.
thank you
I searched all the plugin's code but cannot find it.
Where do you parse a link like https://github.com/svivian/
to <a href="https://github.com/svivian/">https://github.com/svivian/</a>
as it is done now.
I would like to add a target="_blank"
.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.