Skip to content

Commit

Permalink
Merge pull request #98 from vuthao/develop
Browse files Browse the repository at this point in the history
News: fix Take over the editor of the post
  • Loading branch information
hoaquynhtim99 committed Apr 9, 2017
2 parents e6af81e + e582eaf commit 3865bbd
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 124 deletions.
2 changes: 2 additions & 0 deletions assets/js/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ function createfolder() {
//Tạo lại ảnh thumb
function recreatethumb() {
$("div#recreatethumb").dialog("open")
$("#recreatethumb_ok").show();
$("#recreatethumb_loading").html(LANG.recreatethumb_note);
}

// Xoa thu muc
Expand Down
1 change: 1 addition & 0 deletions includes/language/en/admin_upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
$lang_module['deletefolder'] = 'Delete Folder';
$lang_module['createfolder'] = 'Create Folder';
$lang_module['recreatethumb'] = 'Recreate thumb images';
$lang_module['recreatethumb_note'] = 'Note: This function will erase all the thumbs under the folder, both sub-folders and recreate the thumb image according to the new configuration. This process can take a long time, you can not close the browser';
$lang_module['rename_newname'] = 'New name:';
$lang_module['rename_noname'] = 'You not enter a new file name';
$lang_module['rename_error_folder'] = 'Error: System can not rename folder';
Expand Down
1 change: 1 addition & 0 deletions includes/language/fr/admin_upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
$lang_module['deletefolder'] = 'Supprimer le répertoire';
$lang_module['createfolder'] = 'Créer un répertoire';
$lang_module['recreatethumb'] = 'Régénérer pouce image';
$lang_module['recreatethumb_note'] = 'Remarque: Cette fonction efface tous les pouces sous le dossier, les deux sous-dossiers et recréer l\'image du pouce en fonction de la nouvelle configuration. Ce processus peut prendre beaucoup de temps, vous ne pouvez pas fermer le navigateur';
$lang_module['rename_newname'] = 'Nouveau nom';
$lang_module['rename_noname'] = 'Vous n\'avez pas encore nommé le fichier';
$lang_module['rename_error_folder'] = 'Erreur: Le système ne peut pas changer le nom du dossier';
Expand Down
92 changes: 60 additions & 32 deletions modules/news/admin/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@

//kiểm tra xem đang sửa có bị cướp quyền hay không, cập nhật thêm thời gian chỉnh sửa
if ($nv_Request->isset_request('id', 'post') and $nv_Request->isset_request('check_edit', 'post')) {
$id = $nv_Request->get_int('id', 'post', 0);

$return = 'NO_'. $lang_module['not_edit_by_admin'];
$_query = $db->query( 'SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_tmp
WHERE id =' . $id .' AND admin_id=' . $admin_info['admin_id'] );
if ($row_tmp = $_query->fetch()) {
$db->query('UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_tmp SET
time_late=' . NV_CURRENTTIME . ',ip=' . $db->quote($admin_info['last_ip']) . '
WHERE id=' . $id);
$return = 'OK_';
}
die($return);
$id = $nv_Request->get_int('id', 'post', 0);
$return = 'OK_';

$_query = $db->query('SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_tmp WHERE id =' . $id);
if ($row_tmp = $_query->fetch()) {
if ($row_tmp['admin_id'] == $admin_info['admin_id']) {
$db->query('UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_tmp SET time_late=' . NV_CURRENTTIME . ', ip=' . $db->quote($admin_info['last_ip']) . ' WHERE id=' . $id);
$return = 'OK_' . $id;
} else {
$_username = $db->query('SELECT username FROM ' . NV_USERS_GLOBALTABLE . ' WHERE userid =' . $row_tmp['admin_id'])->fetchColumn();
$return = 'ERROR_' . sprintf($lang_module['dulicate_edit_takeover'], $_username, date('H:i d/m/Y', $row_tmp['time_edit']));
}
}
die($return);
}

if (defined('NV_EDITOR')) {
Expand Down Expand Up @@ -254,19 +256,6 @@
if (empty($module_config[$module_name]['htmlhometext'])) {
$rowcontent['hometext'] = strip_tags($rowcontent['hometext'], 'br');
}

//lưu thông tin người đang sửa
$_query = $db->query( 'SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_tmp
WHERE id =' . $rowcontent['id'] );
if ($row_tmp = $_query->fetch()) {
$db->query('UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_tmp SET
time_late=' . NV_CURRENTTIME . ',ip=' . $db->quote($admin_info['last_ip']) . '
WHERE id=' . $rowcontent['id']);

} else {
$db->query('INSERT INTO ' . NV_PREFIXLANG . '_' . $module_data . '_tmp (id, admin_id, time_edit, time_late, ip)
VALUES (' . $rowcontent['id'] . ',' . $admin_info['admin_id'] . ',' . NV_CURRENTTIME . ',' . NV_CURRENTTIME . ',' . $db->quote($admin_info['last_ip']) . ')');
}
}

$array_cat_add_content = $array_cat_pub_content = $array_cat_edit_content = $array_censor_content = array();
Expand Down Expand Up @@ -305,7 +294,6 @@
if ($check_censor_content) {
//Nguoi kiem duyet


$array_censor_content[] = $catid_i;
}

Expand Down Expand Up @@ -798,9 +786,9 @@
$nukeVietElasticSearh = new NukeViet\ElasticSearch\Functions($module_config[$module_name]['elas_host'], $module_config[$module_name]['elas_port'], $module_config[$module_name]['elas_index']);
$result_search = $nukeVietElasticSearh->update_data(NV_PREFIXLANG . '_' . $module_data . '_rows', $rowcontent['id'], $rowcontent);
}
// sau khi sửa, tiến hành xóa bản ghi lưu trạng thái sửa trong csdl
$db->exec('DELETE FROM ' . NV_PREFIXLANG . '_' . $module_data . '_tmp WHERE id = ' . $rowcontent['id']);
// sau khi sửa, tiến hành xóa bản ghi lưu trạng thái sửa trong csdl
$db->exec('DELETE FROM ' . NV_PREFIXLANG . '_' . $module_data . '_tmp WHERE id = ' . $rowcontent['id']);
} else {
$error[] = $lang_module['errorsave'];
}
Expand Down Expand Up @@ -909,6 +897,42 @@
redriect($msg1, $msg2, $url, $module_data . '_detail', 'back');
}
$id_block_content = $id_block_content_post;
} elseif ($rowcontent['id'] > 0) {
// Lưu thông tin người đang sửa
$_query = $db->query('SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_tmp
WHERE id =' . $rowcontent['id']);
if ($row_tmp = $_query->fetch()) {
if ($row_tmp['admin_id'] == $admin_info['admin_id']) {
// Cập nhật thời gian sửa cuối
$db->query('UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_tmp SET time_late=' . NV_CURRENTTIME . ',ip=' . $db->quote($admin_info['last_ip']) . ' WHERE id=' . $rowcontent['id']);
} elseif ($row_tmp['time_late'] < NV_CURRENTTIME - 300) {
//Cho phép sửa nếu người đang sửa 5 phút không thao tác đến
$db->query('UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_tmp SET admin_id=' . $admin_info['admin_id'] . ', time_late=' . NV_CURRENTTIME . ',ip=' . $db->quote($admin_info['last_ip']) . ' WHERE id=' . $rowcontent['id']);
} else {
// Thông báo không có quyền sửa.
$_username = $db->query('SELECT username FROM ' . NV_USERS_GLOBALTABLE . ' WHERE userid =' . $row_tmp['admin_id'])->fetchColumn();
$_authors_lev = $db->query('SELECT lev FROM ' . NV_AUTHORS_GLOBALTABLE . ' WHERE admin_id =' . $row_tmp['admin_id'])->fetchColumn();
if ($admin_info['level'] < $_authors_lev) {
$takeover = md5($rowcontent['id'] . '_takeover_' . NV_CHECK_SESSION);
if ($takeover == $nv_Request->get_title('takeover', 'get', '')) {
$db->query('UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_tmp SET admin_id=' . $admin_info['admin_id'] . ', time_late=' . NV_CURRENTTIME . ',ip=' . $db->quote($admin_info['last_ip']) . ' WHERE id=' . $rowcontent['id']);
Header('Location: ' . NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $op . '&id=' . $rowcontent['id'] . '&rand=' . nv_genpass());
die();
}
$contents = sprintf($lang_module['dulicate_edit_admin'], $rowcontent['title'], $_username, date('H:i d/m/Y', $row_tmp['time_edit']));
$contents .= '<br><a type="button" class="btn btn-danger" href="' . NV_BASE_ADMINURL . 'index.php?' . NV_LANG_VARIABLE . '=' . NV_LANG_DATA . '&' . NV_NAME_VARIABLE . '=' . $module_name . '&' . NV_OP_VARIABLE . '=' . $op . '&id=' . $rowcontent['id'] . '&takeover=' . $takeover . '">' . $lang_module['dulicate_takeover'] . '</a>';
} else {
$contents = sprintf($lang_module['dulicate_edit'], $rowcontent['title'], $_username, date('H:i d/m/Y', $row_tmp['time_edit']));
}

include NV_ROOTDIR . '/includes/header.php';
echo nv_admin_theme('<br><br><br><h2 class="text-center">' . $contents . '</h2>');
include NV_ROOTDIR . '/includes/footer.php';
}
} else {
$db->query('INSERT INTO ' . NV_PREFIXLANG . '_' . $module_data . '_tmp (id, admin_id, time_edit, time_late, ip)
VALUES (' . $rowcontent['id'] . ',' . $admin_info['admin_id'] . ',' . NV_CURRENTTIME . ',' . NV_CURRENTTIME . ',' . $db->quote($admin_info['last_ip']) . ')');
}
}

if (!empty($module_config[$module_name]['htmlhometext'])) {
Expand Down Expand Up @@ -1150,6 +1174,11 @@
$xtpl->parse('main.error');
}

$status_save = true;
if ($rowcontent['id'] > 0) {
$op = '';
}

//Gioi hoan quyen
if ($rowcontent['status'] == 1 and $rowcontent['id'] > 0) {
$xtpl->parse('main.status_save');
Expand Down Expand Up @@ -1205,9 +1234,8 @@
$xtpl->parse('main');
$contents .= $xtpl->text('main');

if ($rowcontent['id'] > 0) {
$op = '';
}
$my_footer .= '<script type="text/javascript">timer_check_takeover = setTimeout(function() {nv_timer_check_takeover(' . $rowcontent['id'] . ');}, 30000);</script>';

include NV_ROOTDIR . '/includes/header.php';
echo nv_admin_theme($contents);
include NV_ROOTDIR . '/includes/footer.php';
40 changes: 0 additions & 40 deletions modules/news/admin/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,6 @@
die('Stop!!!');
}

//kiểm tra xem có người sửa hay chưa, và quyền sửa có dc cướp quyền hay không
if ($nv_Request->isset_request('id', 'post') and $nv_Request->isset_request('check_edit', 'post')) {
$id = $nv_Request->get_int('id', 'post', 0);
$time = NV_CURRENTTIME - 300;// thời gian sửa:5p

$_query = $db->query( 'SELECT * FROM ' . NV_PREFIXLANG . '_' . $module_data . '_tmp
WHERE id =' . $id );
if ($row_tmp = $_query->fetch()) {
if ($row_tmp['time_late'] > $time) { // đang trong thời gian sửa
$array_admin = array();
$query_admin = $db->query( 'SELECT admin_id, lev FROM ' . NV_AUTHORS_GLOBALTABLE );
while ($_tmp = $query_admin->fetch()) {
$array_admin[$_tmp['admin_id']] = $_tmp;
}

if ($array_admin[$admin_info['admin_id']]['lev'] == 1 or $array_admin[$admin_info['admin_id']]['lev'] < $array_admin[$row_tmp['admin_id']]['lev']) {
$return = 'NO_' . $lang_module['dulicate_edit'];
} else {
$return = 'ERR_' . $lang_module['error_edit'];
}
} else {// không trong khoảng thời gian sửa
$return = 'EDIT_';
}
} else {
$return = 'OK_';
}

die($return);
}

//chiếm quyền sửa bài viết
if ($nv_Request->isset_request('id', 'post') and $nv_Request->isset_request('get_edit', 'post')) {
$id = $nv_Request->get_int('id', 'post', 0);

$db->query('UPDATE ' . NV_PREFIXLANG . '_' . $module_data . '_tmp SET
admin_id=' . $admin_info['admin_id'] .',time_late=' . NV_CURRENTTIME . ',ip=' . $db->quote($admin_info['last_ip']) . '
WHERE id=' . $id);
die('OK');
}

$page_title = $lang_module['content_list'];
$stype = $nv_Request->get_string('stype', 'get', '-');
$sstatus = $nv_Request->get_int('sstatus', 'get', -1);
Expand Down
7 changes: 6 additions & 1 deletion modules/news/language/admin_en.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,9 @@
$lang_module['fbinsartmgs_102'] = 'Error: Your article has attributes for tags. To select this article as an instant article, remove them from the tab or tick the box to automatically convert your posts into instant posts. Note: at system conversion will automatically remove components that do not support or replace them with other appropriate components.';
$lang_module['error_edit'] = 'Posts are moderated moderators. You can not edit next.';
$lang_module['dulicate_edit'] = 'Posts are moderated moderators. Do you want to take over this administration?';
$lang_module['not_edit_by_admin'] = 'You have been hijacked to edit this post. Your changes can not be saved to the system, please copy again to avoid losing your changes.';
$lang_module['not_edit_by_admin'] = 'You have been hijacked to edit this post. Your changes can not be saved to the system, please copy again to avoid losing your changes.';

$lang_module['dulicate_edit'] = 'The article <b>%s </b> is being edited by the account <b>%s</b> at %s. You may not edit this post until it is complete.';
$lang_module['dulicate_edit_admin'] = 'The article <b>%s </b> is being edited by the account <b>%s</b> at %s. Do you want to <b>Take over the editor of the post</b>?';
$lang_module['dulicate_takeover'] = 'Take over the editor of the post';
$lang_module['dulicate_edit_takeover'] = 'You have been take over by this account %s at %s. Your changes can not be saved to the system, please copy again to avoid losing your changes.';
8 changes: 5 additions & 3 deletions modules/news/language/admin_fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@
$lang_module['fbinsartmgs_100'] = 'Erreur: Les articles avec les balises HTML: <strong />%s ne sont pas pris en charge par les postes immédiatement. Pour sélectionner cet article comme article s\'il vous plaît les enlever immédiatement, remplacé par le support de carte ou cocher la case convertit automatiquement des articles dans l\'article habituellement instantané. Remarque: lors de la conversion du système laissera automatiquement le composant ne prend pas en charge ou les remplacer par d\'autres ingrédients appropriés';
$lang_module['fbinsartmgs_101'] = 'Erreur: L\'sans contenu';
$lang_module['fbinsartmgs_102'] = 'Erreur: Votre article a des attributs pour les balises. Pour sélectionner cet article comme l\'article les retirer immédiatement de la carte ou cocher la case convertit automatiquement des articles dans l\'article habituellement instantané. Remarque: lors de la conversion du système laissera automatiquement le composant ne prend pas en charge ou les remplacer par d\'autres ingrédients appropriés';
$lang_module['error_edit'] = 'Gestion des entrées sont modifiées. Vous ne pouvez pas modifier une ligne.';
$lang_module['dulicate_edit'] = 'Gestion des entrées sont modifiées. Vous voulez prendre le contrôle de cette administration.';
$lang_module['not_edit_by_admin'] = 'Vous avez modifier cet article compromettez. Vos modifications ne peuvent pas être enregistrés dans le système, copiez le contenu pour éviter de perdre des changements.';

$lang_module['dulicate_edit'] = 'L\'article <b>%s </b> est édité par le compte <b>%s </b> à %s. Vous ne pouvez pas modifier cette publication jusqu\'à ce qu\'elle soit terminée.';
$lang_module['dulicate_edit_admin'] = 'L\'article <b>%s</b> est édité par le compte <b>%s</b> à %s. Voulez-vous <b> Prendre en charge l\'éditeur de la publication </b>?';
$lang_module['dulicate_takeover'] = 'Prendre en charge l\'éditeur de la publication';
$lang_module['dulicate_edit_takeover'] = 'Vous avez été pris en charge par ce compte %s à %s. Vos modifications ne peuvent pas être sauvegardées dans le système, copiez-les à nouveau pour éviter de perdre vos modifications.';
7 changes: 4 additions & 3 deletions modules/news/language/admin_vi.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
$lang_module['fbinsartmgs_101'] = 'Lỗi: Bài viết không có nội dung';
$lang_module['fbinsartmgs_102'] = 'Lỗi: Bài viết của bạn có các thuộc tính cho các thẻ. Để chọn bài viết này làm bài viết tức thời hãy loại bỏ chúng khỏi thẻ hoặc tích chọn vào ô tự động chuyển đổi bài viết thường thành bài viết tức thời. Lưu ý: lúc chuyển đổi hệ thống sẽ tự động bỏ đi các thành phần không hỗ trợ hoặc thay thế chúng bằng các thành phần khác thích hợp';

$lang_module['error_edit'] = 'Bài viết đang có quản trị chỉnh sửa. Bạn không thể chỉnh sửa tiếp.';
$lang_module['dulicate_edit'] = 'Bài viết đang có quản trị chỉnh sửa. Bạn có muốn chiếm quyền của quản trị này không.';
$lang_module['not_edit_by_admin'] = 'Bạn đã bị chiếm quyền chỉnh sửa bài viết này. Những thay đổi của bạn không thể lưu vào hệ thống, hãy sao chép lại để tránh mất nội dung đã thay đổi.';
$lang_module['dulicate_edit'] = 'Bài viết <b>%s</b> đang được sửa bởi tài khoản <b>%s</b> lúc %s. Bạn không được sửa bài viết này đến khi người đó sửa xong.';
$lang_module['dulicate_edit_admin'] = 'Bài viết <b>%s</b> đang được sửa bởi tài khoản <b>%s</b> lúc %s. Bạn có muốn <b>chiếm quyền sửa bài viết</b> này không ?';
$lang_module['dulicate_takeover'] = 'Chiếm quyền sửa bài viết';
$lang_module['dulicate_edit_takeover'] = 'Bạn đã bị chiếm quyền chỉnh sửa bài viết này bởi tài khoản %s lúc %s. Những thay đổi của bạn không thể lưu vào hệ thống, hãy sao chép lại để tránh mất nội dung đã thay đổi.';
17 changes: 17 additions & 0 deletions themes/admin_default/js/news_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,21 @@ function nv_add_element( idElment, key, value ){
var html = "<span title=\"" + value + "\" class=\"uiToken removable\" ondblclick=\"$(this).remove();\">" + value + "<input type=\"hidden\" value=\"" + key + "\" name=\"" + idElment + "[]\" autocomplete=\"off\"><a onclick=\"$(this).parent().remove();\" href=\"javascript:void(0);\" class=\"remove uiCloseButton uiCloseButtonSmall\"></a></span>";
$("#" + idElment).append( html );
return false;
}

var timer_check_takeover = '';
function nv_timer_check_takeover(id) {
clearTimeout(timer_check_takeover);
$.post(script_name + '?' + nv_name_variable + '=' + nv_module_name + '&' + nv_fc_variable + '=content&nocache=' + new Date().getTime(), 'id='+id+'&check_edit=1', function(res) {
res = res.split("_");
if (res[0] != 'OK') {// thông báo bị chiếm quyền sửa
alert(res[1]);
$('.submit-post').remove();
} else {
timer_check_takeover = setTimeout(function() {
nv_timer_check_takeover(id);
}, 30000);
}
});
return false;
}
19 changes: 0 additions & 19 deletions themes/admin_default/modules/news/content.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,6 @@ $("#idtitle").change(function() {
get_alias();
});
<!-- END: getalias -->
$(document).ready(function() {
var id='{rowcontent.id}';
if (id != 0) {
check_edit();
}
});
var check_edit = function() {
$.post(script_name + '?' + nv_name_variable + '=' + nv_module_name + '&' + nv_fc_variable + '=content&nocache=' + new Date().getTime(), 'id={rowcontent.id}&check_edit=1', function(res) {
res = res.split("_");
if (res[0] != 'OK') {// thông báo bị chiếm quyền sửa
alert(res[1]);
$('.submit-post').remove();
} else {
setTimeout(check_edit, 60000);//1 phút cập nhật đang sửa
}
});
return false;
};
//]]>
</script>
<script type="text/javascript" src="{NV_BASE_SITEURL}{NV_ASSETS_DIR}/js/select2/select2.min.js"></script>
Expand Down
Loading

0 comments on commit 3865bbd

Please sign in to comment.