Skip to content

Commit

Permalink
#1060, #1485, #1486
Browse files Browse the repository at this point in the history
  • Loading branch information
God Mod committed Mar 12, 2016
1 parent 59c4fdb commit 877fbcd
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 65 deletions.
116 changes: 116 additions & 0 deletions admin/settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php
/* Project: EQdkp-Plus
* Package: Guildbanker Plugin
* Link: http://eqdkp-plus.eu
*
* Copyright (C) 2006-2015 EQdkp-Plus Developer Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

// EQdkp required files/vars
define('EQDKP_INC', true);
define('IN_ADMIN', true);
define('PLUGIN', 'chat');

$eqdkp_root_path = './../../../';
include_once($eqdkp_root_path.'common.php');

class chatAdminSettings extends page_generic {
/**
* Constructor
*/
public function __construct(){
// plugin installed?
if (!$this->pm->check('chat', PLUGIN_INSTALLED))
message_die($this->user->lang('chat_not_installed'));

$handler = array(
'save' => array('process' => 'save', 'csrf' => true, 'check' => 'a_chat_settings'),
);
parent::__construct('a_chat_settings', $handler);

$this->process();
}

private $arrData = false;

public function save(){
$objForm = register('form', array('chat_settings'));
$objForm->langPrefix = 'chat_';
$objForm->validate = true;
$objForm->add_fieldsets($this->fields());
$arrValues = $objForm->return_values();

if($objForm->error){
$this->arrData = $arrValues;
}else{
// update configuration
$this->config->set($arrValues, '', 'chat');
// Success message - Message, Title
$messages[] = array($this->user->lang('save_suc'), $this->user->lang('settings'));
$this->display($messages);
}
}

private function fields(){
$arrFields = array(
'ajax' => array(
'reload_chat' => array(
'type' => 'spinner',
'default' => 5,
),
'reload_onlinelist' => array(
'type' => 'spinner',
'default' => 5,
),
),
);
return $arrFields;
}

public function display($messages=array()){
// -- Messages ------------------------------------------------------------
if ($messages){
foreach($messages as $val)
$this->core->message($val[0], $val[1], 'green');
}

// get the saved data
$arrValues = $this->config->get_config('chat');
if ($this->arrData !== false) $arrValues = $this->arrData;

// -- Template ------------------------------------------------------------
// initialize form class
$objForm = register('form', array('chat_settings'));
$objForm->reset_fields();
$objForm->lang_prefix = 'chat_';
$objForm->validate = true;
$objForm->use_fieldsets = true;
$objForm->add_fieldsets($this->fields());

// Output the form, pass values in
$objForm->output($arrValues);

$this->core->set_vars(array(
'page_title' => $this->user->lang('chat').' '.$this->user->lang('settings'),
'template_path' => $this->pm->get_data('chat', 'template_path'),
'template_file' => 'admin/manage_settings.html',
'display' => true
));
}

}
registry::register('chatAdminSettings');
?>
32 changes: 32 additions & 0 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ public function __construct(){
'userlist' => array('process' => 'get_userlist'),
'openConversation' => array('process' => 'openConversation'),
'closeConversation' => array('process' => 'closeConversation'),
'minConversation' => array('process' => 'minConversation'),
'maxConversation' => array('process' => 'maxConversation'),
'loadOpenConversations' => array('process' => 'loadOpenConversations'),
'save' => array('process' => 'saveMessage'),
'delete' => array('process' => 'deleteMessage'),
'markRead' => array('process' => 'markRead'),
'checkNew' => array('process' => 'checkNew'),
'getUser' => array('process' => 'getUser'),
Expand Down Expand Up @@ -105,6 +108,34 @@ public function closeConversation(){
}
}

public function minConversation(){
if ($this->in->get('key') != ""){
$this->pdh->put("chat_open_conversations", "minConversation", array($this->in->get('key'), $this->user->id));
$this->pdh->process_hook_queue();
}
}

public function maxConversation(){
if ($this->in->get('key') != ""){
$this->pdh->put("chat_open_conversations", "maxConversation", array($this->in->get('key'), $this->user->id));
$this->pdh->process_hook_queue();
}
}

public function deleteMessage(){
if($this->in->get('msg', 0)){
//Get Message Details:
$intMessageID = $this->in->get('msg', 0);
$arrResult = $this->pdh->get('chat_messages', 'id', array($intMessageID));
if($arrResult){
$strChatID = $arrResult['conversation_key'];
if($strChatID == 'guildchat' && $this->user->check_auth('u_chat_mod_pub', false)){
$this->pdh->put('chat_messages', 'deleteMessage', array($intMessageID));
}
}
}
}

public function loadOpenConversations(){
header('Content-type: application/json; charset=UTF-8');
$arrOpen = $this->pdh->get('chat_open_conversations', 'openUserConversations', array($this->user->id));
Expand All @@ -115,6 +146,7 @@ public function loadOpenConversations(){
'key' => $val['conversation_key'],
'title' => $this->pdh->get('chat_conversations', 'title', array($val['conversation_key'])),
'count' => count($this->pdh->get('chat_conversations', 'user', array($val['conversation_key']))),
'minimized' => $val['minimized'],
);
}
}
Expand Down
7 changes: 3 additions & 4 deletions chat_plugin_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
class chat extends plugin_generic
{

public $version = '0.2.2';
public $version = '0.3.0';
public $build = '';
public $copyright = 'GodMod';
public $vstatus = 'Alpha';

protected static $apiLevel = 23;

Expand Down Expand Up @@ -69,6 +68,7 @@ public function __construct()
// ('a'/'u', Permission-Name, Enable? 'Y'/'N', Language string, array of user-group-ids that should have this permission)
// Groups: 1 = Guests, 2 = Super-Admin, 3 = Admin, 4 = Member
$this->add_permission('u', 'view', 'Y', $this->user->lang('chat_view'), array(2,3,4));
$this->add_permission('u', 'mod_pub', 'Y', $this->user->lang('chat_mod_pub'), array(2,3));
$this->add_permission('a', 'manage', 'N', $this->user->lang('manage'), array(2,3));
$this->add_permission('a', 'settings', 'N', $this->user->lang('menu_settings'), array(2,3));

Expand Down Expand Up @@ -148,8 +148,7 @@ private function gen_main_menu()
*/
private function gen_admin_menu()
{
return array();


$admin_menu = array (array(
'name' => $this->user->lang('chat'),
'icon' => 'fa-comments',
Expand Down
8 changes: 7 additions & 1 deletion hooks/chat_portal_hook.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ public function portal()
$this->tpl->js_file($this->root_path.'plugins/chat/includes/js/jquery.tokeninput.js');
$this->tpl->js_file($this->root_path.'plugins/chat/includes/js/chat.js');
$this->tpl->css_file($this->root_path.'plugins/chat/templates/base_template/chat.css');
$this->tpl->add_js("EQdkpChat.init();

//In Secods
$intReloadTime = ($this->config->get('reload_chat', 'chat')) ? $this->config->get('reload_chat', 'chat') : 5;
//In Minutes
$intReloadOnlineList = ($this->config->get('reload_onlinelist', 'chat')) ? $this->config->get('reload_onlinelist', 'chat') : 5;

$this->tpl->add_js("EQdkpChat.init(".$intReloadTime.", ".$intReloadOnlineList.", ".(($this->user->check_auth('u_chat_mod_pub', false)) ? 1 : 0).");
$('.chat-tooltip-trigger').on('click', function(event){
$('#chat-tooltip').show('fast');
$('.chatTooltipRemove').remove();
Expand Down
54 changes: 46 additions & 8 deletions includes/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var EQdkpChat = new function(){
var unreadChats = new Array();
var onlineUsers = new Array();
var mybreak = false;
var minimizeLock = false;
var blnIsPubMod = false;

var check_new_interval, onlinelist_interval;

Expand Down Expand Up @@ -65,15 +67,16 @@ var EQdkpChat = new function(){

this.loadOnlineList = loadOnlineList;

this.init = function () {

this.init = function (intReloadTime, intRelodOnlinelist, isPubMod) {
loadOnlineList();
loadOpenConversations();
$(document).ready(function(){
check_new_interval = window.setInterval("EQdkpChat.checkNew()", 5000);
onlinelist_interval = window.setInterval("EQdkpChat.loadOnlineList()", 1000*60*5);
check_new_interval = window.setInterval("EQdkpChat.checkNew()", 1000*intReloadTime); //Seconds
onlinelist_interval = window.setInterval("EQdkpChat.loadOnlineList()", 1000*60*intRelodOnlinelist); //Minutes
})

blnIsPubMod = isPubMod;

bindActions();

$(window).focus($.proxy(function() {
Expand Down Expand Up @@ -139,6 +142,16 @@ var EQdkpChat = new function(){
$.get(mmocms_root_path+ "plugins/chat/ajax.php"+mmocms_sid+"&closeConversation&key="+key);
}

this.minConversation = function (key){
$.get(mmocms_root_path+ "plugins/chat/ajax.php"+mmocms_sid+"&minConversation&key="+key);
minimizeConversation(key);
}

this.deleteMessage = function (messageID){
$("div[data-post-id=\'"+messageID+"\']").remove();
$.get(mmocms_root_path+ "plugins/chat/ajax.php"+mmocms_sid+"&delete&msg="+messageID);
}

this.markAsRead = markAsRead;

this.checkNew = checkNew;
Expand Down Expand Up @@ -265,8 +278,10 @@ var EQdkpChat = new function(){
} else {
var newpost = "";
}
var deleteIcon = (key == 'guildchat' && blnIsPubMod) ? '<span class="chatDeleteContainer"><i class="hand fa fa-times-circle icon-grey" onclick="EQdkpChat.deleteMessage('+v.id+')"></i></span>' : '';

if(v.user_id == mmocms_userid) { var mine = ' mine'; } else { var mine = ''; }
var html = '<div class="chatPost'+newpost+mine+'" data-post-id="'+v.id+'"><div class="chatAvatar" title="'+v.username+'"><a href="'+v.profile+'">'+v.avatar+'</a></div><div class="chatMsgContainer"><div class="chatUsername">'+v.username+'</div><div class="chatTime">'+v.date+'</div><div class="chatMessage">'+v.text+'</div></div><div class="clear"></div></div>';
var html = '<div class="chatPost'+newpost+mine+'" data-post-id="'+v.id+'"><div class="chatAvatar" title="'+v.username+'"><a href="'+v.profile+'">'+v.avatar+'</a></div><div class="chatMsgContainer"><div class="chatUsername">'+v.username+'</div><div class="chatTime">'+v.date+'</div><div class="chatMessage">'+deleteIcon+v.text+'</div></div><div class="clear"></div></div>';
$(".chatBigContainer .chatMessages-"+key).append(html);
}
});
Expand Down Expand Up @@ -330,6 +345,16 @@ var EQdkpChat = new function(){
function bindActions(){
$(".chatWindow").on("click", function(e){
focusWindow(this);

var parent = $(this).parent();
if(parent.hasClass('chatMinimized')){
var key = $(this).parent().attr("data-chat-id");

if(key != minimizeLock){
maximizeConversation(key);
}
}
minimizeLock = false;
});

$(".chatWindowHeader span").on("dblclick", function(e){
Expand Down Expand Up @@ -421,7 +446,7 @@ var EQdkpChat = new function(){
$.get(mmocms_root_path+ "plugins/chat/ajax.php"+mmocms_sid+"&loadOpenConversations", function(data){
unfocusAllWindows();
$.each(data, function(key, v){
openChatWindow(key, v.title, v.count);
openChatWindow(key, v.title, v.count, v.minimized);
$.post(mmocms_root_path+ "plugins/chat/ajax.php"+mmocms_sid+"&loadLatestMessages", { key: key}, function(data){
var unread = addMessages(key, data, 1);
$(".chat-"+key).removeAttr("data-opened");
Expand All @@ -436,7 +461,7 @@ var EQdkpChat = new function(){
});
}

function openChatWindow(key, title, count){
function openChatWindow(key, title, count, minimized){
if ($("#chatWindowList").find(".chat-"+key).length == 0){
var icon = "";

Expand All @@ -453,7 +478,9 @@ var EQdkpChat = new function(){
if(count > 2){
var leave = '<br /><a href="javascript:EQdkpChat.leaveConversation(\''+key+'\')"><i class="fa fa-user-times"></i> Leave Conversation</a>';
} else var leave = '';
var html = '<div class="chatWindowContainer chat-'+key+'" data-chat-id="'+key+'" data-user-count="'+count+'" data-opened="1"><div class="chatWindow"><div class="chatWindowHeader"><span>'+icon+title+'</span><i class="fa fa-times floatRight hand" onclick="EQdkpChat.closeConversation(\''+key+'\')" style="margin-right: -5px; margin-left: 5px;"></i><i class="fa fa-user-plus floatRight hand" onclick="EQdkpChat.addUser(\''+key+'\')"></i></div><div class="chatWindowAddUser" style="display:none;"><input type="text" class="demo-input-local" name="blah" /><button type="button" onclick="EQdkpChat.addUserSubmit(\''+key+'\');"><i class="fa fa-check"></i> Absenden</button><br />'+leave+'</div><div class="chatWindowContent"><span class="chatMessages-'+key+'"></span><div class="clear"></div></div><div class="chatInput"><textarea id="chatInput-'+key+'" class="chatInputSubmit" style="overflow: hidden; word-wrap: break-word; resize: none;"></textarea></div><div class="clear"></div><div class="chatLastMessage-'+key+'" style="display:none;">0</div><div class="chatLastMessageByMe-'+key+'" style="display:none;">0</div></div></div>';

var minClass = (minimized) ? ' chatMinimized' : '';
var html = '<div class="chatWindowContainer chat-'+key+minClass+'" data-chat-id="'+key+'" data-user-count="'+count+'" data-opened="1"><div class="chatWindow"><div class="chatWindowHeader"><span>'+icon+title+'</span><i class="fa fa-times floatRight hand" onclick="EQdkpChat.closeConversation(\''+key+'\')" style="margin-right: -5px; margin-left: 5px;"></i><i class="fa fa-angle-down floatRight hand chatMinConvIcon" onclick="EQdkpChat.minConversation(\''+key+'\')" style="margin-right: 0px; margin-left: 5px;"></i><i class="fa fa-user-plus floatRight hand" onclick="EQdkpChat.addUser(\''+key+'\')"></i></div><div class="chatWindowAddUser" style="display:none;"><input type="text" class="demo-input-local" name="blah" /><button type="button" onclick="EQdkpChat.addUserSubmit(\''+key+'\');"><i class="fa fa-check"></i> Absenden</button><br />'+leave+'</div><div class="chatWindowContent"><span class="chatMessages-'+key+'"></span><div class="clear"></div></div><div class="chatInput"><textarea id="chatInput-'+key+'" class="chatInputSubmit" style="overflow: hidden; word-wrap: break-word; resize: none;"></textarea></div><div class="clear"></div><div class="chatLastMessage-'+key+'" style="display:none;">0</div><div class="chatLastMessageByMe-'+key+'" style="display:none;">0</div></div></div>';
$("#chatWindowList").append(html);
}
}
Expand Down Expand Up @@ -485,4 +512,15 @@ var EQdkpChat = new function(){
var header = $(".chat-"+key+" .chatWindowHeader");
$(header).addClass('blinkingHeader');
}

function minimizeConversation(key){
minimizeLock = key;
$(".chat-"+key).addClass('chatMinimized');
$(".chat-"+key).removeAttr("data-opened");
}

function maximizeConversation(key){
$(".chat-"+key).removeClass('chatMinimized');
$.get(mmocms_root_path+ "plugins/chat/ajax.php"+mmocms_sid+"&maxConversation&key="+key);
}
};
Loading

0 comments on commit 877fbcd

Please sign in to comment.