Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
ac8b85cb
Commit
ac8b85cb
authored
Feb 19, 2018
by
pupi1985
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use JSON in admin AJAX calls
parent
1a9496fd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
215 additions
and
36 deletions
+215
-36
qa-admin.js
qa-content/qa-admin.js
+12
-9
qa-global.js
qa-content/qa-global.js
+20
-11
click-admin.php
qa-include/ajax/click-admin.php
+26
-6
admin.php
qa-include/app/admin.php
+152
-6
qa-lang-admin.php
qa-include/lang/qa-lang-admin.php
+4
-3
admin-approve.php
qa-include/pages/admin/admin-approve.php
+1
-1
No files found.
qa-content/qa-admin.js
View file @
ac8b85cb
...
@@ -120,15 +120,18 @@ function qa_admin_click(target)
...
@@ -120,15 +120,18 @@ function qa_admin_click(target)
params
.
code
=
target
.
form
.
elements
.
code
.
value
;
params
.
code
=
target
.
form
.
elements
.
code
.
value
;
qa_ajax_post
(
'click_admin'
,
params
,
qa_ajax_post
(
'click_admin'
,
params
,
function
(
lines
)
{
function
(
response
)
{
if
(
lines
[
0
]
==
'1'
)
if
(
response
.
hideEntitySelector
!==
null
)
{
qa_conceal
(
document
.
getElementById
(
'p'
+
p
[
1
]),
'admin'
);
qa_conceal
(
document
.
getElementById
(
'p'
+
params
.
entityid
),
'admin'
);
else
if
(
lines
[
0
]
==
'0'
)
{
$
(
'.qa-nav-sub-counter-'
+
response
.
hideEntitySelector
).
text
(
response
.
entityCount
);
alert
(
lines
[
1
]);
}
qa_hide_waiting
(
target
);
}
else
if
(
response
.
result
!==
'success'
)
{
qa_ajax_error
();
alert
(
response
.
error
.
message
);
}
}
qa_hide_waiting
(
target
);
},
1
);
);
qa_show_waiting_after
(
target
,
false
);
qa_show_waiting_after
(
target
,
false
);
...
...
qa-content/qa-global.js
View file @
ac8b85cb
...
@@ -152,22 +152,31 @@ function qa_favorite_click(elem)
...
@@ -152,22 +152,31 @@ function qa_favorite_click(elem)
return
false
;
return
false
;
}
}
function
qa_ajax_post
(
operation
,
params
,
callback
)
function
qa_ajax_post
(
operation
,
params
,
callback
,
version
)
{
{
$
.
extend
(
params
,
{
qa
:
'ajax'
,
qa_operation
:
operation
,
qa_root
:
qa_root
,
qa_request
:
qa_request
});
if
(
typeof
(
version
)
===
'undefined'
)
{
version
=
0
;
}
$
.
post
(
qa_root
,
params
,
function
(
response
)
{
$
.
extend
(
params
,
{
qa
:
'ajax'
,
qa_operation
:
operation
,
qa_root
:
qa_root
,
qa_request
:
qa_request
,
version
:
version
});
var
header
=
'QA_AJAX_RESPONSE'
;
var
headerpos
=
response
.
indexOf
(
header
);
if
(
headerpos
>=
0
)
$
.
post
(
qa_root
,
params
,
function
(
response
)
{
callback
(
response
.
substr
(
headerpos
+
header
.
length
).
replace
(
/^
\s
+/
,
''
).
split
(
"
\
n"
));
if
(
version
===
0
)
{
else
var
header
=
'QA_AJAX_RESPONSE'
;
callback
([]
);
var
headerpos
=
response
.
indexOf
(
header
);
},
'text'
).
fail
(
function
(
jqXHR
)
{
if
(
headerpos
>=
0
)
callback
(
response
.
substr
(
headerpos
+
header
.
length
).
replace
(
/^
\s
+/
,
''
).
split
(
"
\
n"
));
else
callback
([]);
}
else
{
callback
(
response
);
}
},
version
===
0
?
'text'
:
'json'
).
fail
(
function
(
jqXHR
)
{
if
(
jqXHR
.
readyState
>
0
)
if
(
jqXHR
.
readyState
>
0
)
callback
([])
qa_ajax_error
();
});
});
}
}
...
...
qa-include/ajax/click-admin.php
View file @
ac8b85cb
...
@@ -26,10 +26,30 @@ require_once QA_INCLUDE_DIR . 'app/cookies.php';
...
@@ -26,10 +26,30 @@ require_once QA_INCLUDE_DIR . 'app/cookies.php';
$entityid
=
qa_post_text
(
'entityid'
);
$entityid
=
qa_post_text
(
'entityid'
);
$action
=
qa_post_text
(
'action'
);
$action
=
qa_post_text
(
'action'
);
$version
=
(
int
)
qa_post_text
(
'version'
);
switch
(
$version
)
{
case
1
:
if
(
!
qa_check_form_security_code
(
'admin/click'
,
qa_post_text
(
'code'
)))
{
$response
=
array
(
'result'
=>
'error'
,
'error'
=>
array
(
'message'
=>
qa_lang
(
'misc/form_security_reload'
),
),
);
}
else
{
$response
=
qa_admin_single_click_array
(
$entityid
,
$action
);
}
echo
json_encode
(
$response
);
break
;
default
:
// prior version
if
(
!
qa_check_form_security_code
(
'admin/click'
,
qa_post_text
(
'code'
)))
echo
"QA_AJAX_RESPONSE
\n
0
\n
"
.
qa_lang
(
'misc/form_security_reload'
);
elseif
(
qa_admin_single_click
(
$entityid
,
$action
))
echo
"QA_AJAX_RESPONSE
\n
1
\n
"
;
else
echo
"QA_AJAX_RESPONSE
\n
0
\n
"
.
qa_lang
(
'main/general_error'
);
}
if
(
!
qa_check_form_security_code
(
'admin/click'
,
qa_post_text
(
'code'
)))
echo
"QA_AJAX_RESPONSE
\n
0
\n
"
.
qa_lang
(
'misc/form_security_reload'
);
elseif
(
qa_admin_single_click
(
$entityid
,
$action
))
// permission check happens in here
echo
"QA_AJAX_RESPONSE
\n
1
\n
"
;
else
echo
"QA_AJAX_RESPONSE
\n
0
\n
"
.
qa_lang
(
'main/general_error'
);
qa-include/app/admin.php
View file @
ac8b85cb
...
@@ -374,19 +374,19 @@ function qa_admin_sub_navigation()
...
@@ -374,19 +374,19 @@ function qa_admin_sub_navigation()
}
}
if
(
!
qa_user_maximum_permit_error
(
'permit_moderate'
))
{
if
(
!
qa_user_maximum_permit_error
(
'permit_moderate'
))
{
$count
=
qa_user_permit_error
(
'permit_moderate'
)
?
null
:
qa_opt
(
'cache_queuedcount'
);
// if only in some categories don't show cached count
$count
=
qa_user_permit_error
(
'permit_moderate'
)
?
0
:
(
int
)
qa_opt
(
'cache_queuedcount'
);
// if only in some categories don't show cached count
$navigation
[
'admin/moderate'
]
=
array
(
$navigation
[
'admin/moderate'
]
=
array
(
'label'
=>
qa_lang_html
(
'admin/moderate_title'
)
.
(
$count
?
(
' ('
.
$count
.
')'
)
:
'
'
),
'label'
=>
qa_lang_html
_sub
(
'admin/moderate_title'
,
'<span class="qa-nav-sub-counter-moderate">'
.
qa_html
(
qa_format_number
(
$count
))
.
'</span>
'
),
'url'
=>
qa_path_html
(
'admin/moderate'
),
'url'
=>
qa_path_html
(
'admin/moderate'
),
);
);
}
}
if
(
qa_opt
(
'flagging_of_posts'
)
&&
!
qa_user_maximum_permit_error
(
'permit_hide_show'
))
{
if
(
qa_opt
(
'flagging_of_posts'
)
&&
!
qa_user_maximum_permit_error
(
'permit_hide_show'
))
{
$count
=
qa_user_permit_error
(
'permit_hide_show'
)
?
null
:
qa_opt
(
'cache_flaggedcount'
);
// if only in some categories don't show cached count
$count
=
qa_user_permit_error
(
'permit_hide_show'
)
?
0
:
(
int
)
qa_opt
(
'cache_flaggedcount'
);
// if only in some categories don't show cached count
$navigation
[
'admin/flagged'
]
=
array
(
$navigation
[
'admin/flagged'
]
=
array
(
'label'
=>
qa_lang_html
(
'admin/flagged_title'
)
.
(
$count
?
(
' ('
.
$count
.
')'
)
:
'
'
),
'label'
=>
qa_lang_html
_sub
(
'admin/flagged_title'
,
'<span class="qa-nav-sub-counter-flagged">'
.
qa_html
(
qa_format_number
(
$count
))
.
'</span>
'
),
'url'
=>
qa_path_html
(
'admin/flagged'
),
'url'
=>
qa_path_html
(
'admin/flagged'
),
);
);
}
}
...
@@ -399,10 +399,10 @@ function qa_admin_sub_navigation()
...
@@ -399,10 +399,10 @@ function qa_admin_sub_navigation()
}
}
if
(
!
QA_FINAL_EXTERNAL_USERS
&&
qa_opt
(
'moderate_users'
)
&&
$level
>=
QA_USER_LEVEL_MODERATOR
)
{
if
(
!
QA_FINAL_EXTERNAL_USERS
&&
qa_opt
(
'moderate_users'
)
&&
$level
>=
QA_USER_LEVEL_MODERATOR
)
{
$count
=
qa_opt
(
'cache_uapprovecount'
);
$count
=
(
int
)
qa_opt
(
'cache_uapprovecount'
);
$navigation
[
'admin/approve'
]
=
array
(
$navigation
[
'admin/approve'
]
=
array
(
'label'
=>
qa_lang_html
(
'admin/approve_users_title'
)
.
(
$count
?
(
' ('
.
$count
.
')'
)
:
'
'
),
'label'
=>
qa_lang_html
_sub
(
'admin/approve_users_title'
,
'<span class="qa-nav-sub-counter-approve">'
.
qa_html
(
qa_format_number
(
$count
))
.
'</span>
'
),
'url'
=>
qa_path_html
(
'admin/approve'
),
'url'
=>
qa_path_html
(
'admin/approve'
),
);
);
}
}
...
@@ -582,6 +582,152 @@ function qa_admin_single_click($entityid, $action)
...
@@ -582,6 +582,152 @@ function qa_admin_single_click($entityid, $action)
/**
/**
* Returns true if admin (hidden/flagged/approve/moderate) page $action performed on $entityid is permitted by the
* logged in user and was processed successfully
* @param $entityid
* @param $action
* @return array
*/
function
qa_admin_single_click_array
(
$entityid
,
$action
)
{
$userid
=
qa_get_logged_in_userid
();
$response
=
array
();
if
(
!
QA_FINAL_EXTERNAL_USERS
&&
(
$action
===
'userapprove'
||
$action
===
'userblock'
))
{
// approve/block moderated users
require_once
QA_INCLUDE_DIR
.
'db/selects.php'
;
$useraccount
=
qa_db_select_with_pending
(
qa_db_user_account_selectspec
(
$entityid
,
true
));
if
(
isset
(
$useraccount
)
&&
qa_get_logged_in_level
()
>=
QA_USER_LEVEL_MODERATOR
)
{
switch
(
$action
)
{
case
'userapprove'
:
$response
[
'entityCount'
]
=
(
int
)
qa_opt
(
'cache_uapprovecount'
);
if
(
$useraccount
[
'level'
]
>=
QA_USER_LEVEL_APPROVED
)
{
// don't demote higher level users
$response
[
'result'
]
=
'error'
;
$response
[
'error'
][
'type'
]
=
'user-already-approved'
;
$response
[
'error'
][
'message'
]
=
qa_lang_html
(
'main/general_error'
);
$response
[
'hideEntitySelector'
]
=
null
;
}
else
{
require_once
QA_INCLUDE_DIR
.
'app/users-edit.php'
;
qa_set_user_level
(
$useraccount
[
'userid'
],
$useraccount
[
'handle'
],
QA_USER_LEVEL_APPROVED
,
$useraccount
[
'level'
]);
$response
[
'result'
]
=
'success'
;
$response
[
'entityCount'
]
=
max
(
$response
[
'entityCount'
]
-
1
,
0
);
$response
[
'hideEntitySelector'
]
=
'approve'
;
}
break
;
case
'userblock'
:
require_once
QA_INCLUDE_DIR
.
'app/users-edit.php'
;
qa_set_user_blocked
(
$useraccount
[
'userid'
],
$useraccount
[
'handle'
],
true
);
$response
[
'result'
]
=
'success'
;
$response
[
'entityCount'
]
=
max
((
int
)
qa_opt
(
'cache_uapprovecount'
)
-
1
,
0
);
$response
[
'hideEntitySelector'
]
=
'approve'
;
break
;
default
:
}
}
}
else
{
// something to do with a post
require_once
QA_INCLUDE_DIR
.
'app/posts.php'
;
$post
=
qa_post_get_full
(
$entityid
);
if
(
isset
(
$post
))
{
$queued
=
(
substr
(
$post
[
'type'
],
1
)
==
'_QUEUED'
);
switch
(
$action
)
{
case
'approve'
:
case
'reject'
:
$response
[
'entityCount'
]
=
(
int
)
qa_opt
(
'cache_queuedcount'
);
if
(
!
$queued
)
{
$response
[
'result'
]
=
'error'
;
$response
[
'error'
][
'type'
]
=
'post-not-queued'
;
$response
[
'error'
][
'message'
]
=
qa_lang_html
(
'main/general_error'
);
$response
[
'entityCount'
]
=
max
(
$response
[
'entityCount'
]
-
1
,
0
);
$response
[
'hideEntitySelector'
]
=
'moderate'
;
}
elseif
(
qa_user_post_permit_error
(
'permit_moderate'
,
$post
)
!==
false
)
{
$response
[
'result'
]
=
'error'
;
$response
[
'error'
][
'type'
]
=
'no-permission'
;
$response
[
'error'
][
'message'
]
=
qa_lang_html
(
'users/no_permission'
);
$response
[
'hideEntitySelector'
]
=
null
;
}
else
{
$postStatus
=
$action
===
'approve'
?
QA_POST_STATUS_NORMAL
:
QA_POST_STATUS_HIDDEN
;
// 'reject'
qa_post_set_status
(
$entityid
,
$postStatus
,
$userid
);
$response
[
'result'
]
=
'success'
;
$response
[
'entityCount'
]
=
max
(
$response
[
'entityCount'
]
-
1
,
0
);
$response
[
'hideEntitySelector'
]
=
'moderate'
;
}
break
;
case
'reshow'
:
case
'delete'
:
if
(
!
$post
[
'hidden'
])
{
$response
[
'result'
]
=
'error'
;
$response
[
'error'
][
'type'
]
=
'post-not-hidden'
;
$response
[
'error'
][
'message'
]
=
qa_lang_html
(
'main/general_error'
);
$response
[
'hideEntitySelector'
]
=
'hidden'
;
}
elseif
(
qa_user_post_permit_error
(
'permit_hide_show'
,
$post
)
!==
false
)
{
$response
[
'result'
]
=
'error'
;
$response
[
'error'
][
'type'
]
=
'no-permission'
;
$response
[
'error'
][
'message'
]
=
qa_lang_html
(
'users/no_permission'
);
$response
[
'hideEntitySelector'
]
=
null
;
}
else
{
if
(
$action
===
'reshow'
)
{
qa_post_set_status
(
$entityid
,
QA_POST_STATUS_NORMAL
,
$userid
);
}
else
{
// 'delete'
qa_post_delete
(
$entityid
);
}
$response
[
'result'
]
=
'success'
;
$response
[
'hideEntitySelector'
]
=
'hidden'
;
}
break
;
case
'hide'
:
case
'clearflags'
:
$response
[
'entityCount'
]
=
(
int
)
qa_opt
(
'cache_flaggedcount'
);
if
(
$action
===
'hide'
&&
$queued
)
{
$response
[
'result'
]
=
'error'
;
$response
[
'error'
][
'type'
]
=
'post-queued'
;
$response
[
'error'
][
'message'
]
=
qa_lang_html
(
'main/general_error'
);
$response
[
'entityCount'
]
=
max
(
$response
[
'entityCount'
]
-
1
,
0
);
$response
[
'hideEntitySelector'
]
=
'flagged'
;
}
elseif
(
qa_user_post_permit_error
(
'permit_hide_show'
,
$post
)
!==
false
)
{
$response
[
'result'
]
=
'error'
;
$response
[
'error'
][
'type'
]
=
'no-permission'
;
$response
[
'error'
][
'message'
]
=
qa_lang_html
(
'users/no_permission'
);
$response
[
'hideEntitySelector'
]
=
null
;
}
else
{
if
(
$action
===
'hide'
)
{
qa_post_set_status
(
$entityid
,
QA_POST_STATUS_HIDDEN
,
$userid
);
}
else
{
// 'clearflags'
require_once
QA_INCLUDE_DIR
.
'app/votes.php'
;
qa_flags_clear_all
(
$post
,
$userid
,
qa_get_logged_in_handle
(),
null
);
}
$response
[
'result'
]
=
'success'
;
$response
[
'entityCount'
]
=
max
(
$response
[
'entityCount'
]
-
1
,
0
);
$response
[
'hideEntitySelector'
]
=
'flagged'
;
}
break
;
default
:
}
}
}
return
$response
;
}
/**
* Checks for a POSTed click on an admin (hidden/flagged/approve/moderate) page, and refresh the page if processed successfully (non Ajax)
* Checks for a POSTed click on an admin (hidden/flagged/approve/moderate) page, and refresh the page if processed successfully (non Ajax)
*/
*/
function
qa_admin_check_clicks
()
function
qa_admin_check_clicks
()
...
...
qa-include/lang/qa-lang-admin.php
View file @
ac8b85cb
...
@@ -37,7 +37,7 @@ return array(
...
@@ -37,7 +37,7 @@ return array(
'after_x'
=>
'After "^"'
,
'after_x'
=>
'After "^"'
,
'after_x_tab'
=>
'After "^" tab'
,
'after_x_tab'
=>
'After "^" tab'
,
'approve_user_popup'
=>
'Approve user'
,
'approve_user_popup'
=>
'Approve user'
,
'approve_users_title'
=>
'Approve users'
,
'approve_users_title'
=>
'Approve users
(^)
'
,
'basic_editor'
=>
'Basic Editor'
,
'basic_editor'
=>
'Basic Editor'
,
'before_main_menu'
=>
'Before tabs at top'
,
'before_main_menu'
=>
'Before tabs at top'
,
'blobs_directory_error'
=>
'The directory ^ defined as QA_BLOBS_DIRECTORY is not writable by the web server.'
,
'blobs_directory_error'
=>
'The directory ^ defined as QA_BLOBS_DIRECTORY is not writable by the web server.'
,
...
@@ -121,7 +121,7 @@ return array(
...
@@ -121,7 +121,7 @@ return array(
'field_single_line'
=>
'Single line of text'
,
'field_single_line'
=>
'Single line of text'
,
'field_type'
=>
'Content type:'
,
'field_type'
=>
'Content type:'
,
'first'
=>
'First'
,
'first'
=>
'First'
,
'flagged_title'
=>
'Flagged'
,
'flagged_title'
=>
'Flagged
(^)
'
,
'form_security_expired'
=>
'Form security code expired - please try again'
,
'form_security_expired'
=>
'Form security code expired - please try again'
,
'from_anon'
=>
'From anonymous:'
,
'from_anon'
=>
'From anonymous:'
,
'from_users'
=>
'From users:'
,
'from_users'
=>
'From users:'
,
...
@@ -145,7 +145,7 @@ return array(
...
@@ -145,7 +145,7 @@ return array(
'maintenance_admin_only'
=>
'Your site is in ^1maintenance^2 and is currently inaccessible to regular users.'
,
'maintenance_admin_only'
=>
'Your site is in ^1maintenance^2 and is currently inaccessible to regular users.'
,
'maximum_x'
=>
' (max ^)'
,
'maximum_x'
=>
' (max ^)'
,
'memcached_error'
=>
'Memcached error: ^'
,
'memcached_error'
=>
'Memcached error: ^'
,
'moderate_title'
=>
'Moderate'
,
'moderate_title'
=>
'Moderate
(^)
'
,
'module_x_database_init'
=>
'The ^1 ^2 module requires some ^3database initialization^4.'
,
'module_x_database_init'
=>
'The ^1 ^2 module requires some ^3database initialization^4.'
,
'most_flagged_title'
=>
'Flagged content'
,
'most_flagged_title'
=>
'Flagged content'
,
'mysql_version'
=>
'MySQL version:'
,
'mysql_version'
=>
'MySQL version:'
,
...
@@ -215,6 +215,7 @@ return array(
...
@@ -215,6 +215,7 @@ return array(
'recalc_stop'
=>
'Stop recalculating'
,
'recalc_stop'
=>
'Stop recalculating'
,
'recent_approve_title'
=>
'Recent content waiting for approval'
,
'recent_approve_title'
=>
'Recent content waiting for approval'
,
'recent_hidden_title'
=>
'Recent hidden content'
,
'recent_hidden_title'
=>
'Recent hidden content'
,
'recent_users_title'
=>
'Recent users waiting for approval'
,
'recount_posts'
=>
'Recount posts'
,
'recount_posts'
=>
'Recount posts'
,
'recount_posts_as_recounted'
=>
'Recounted answers and hotness for ^1 of ^2 posts...'
,
'recount_posts_as_recounted'
=>
'Recounted answers and hotness for ^1 of ^2 posts...'
,
'recount_posts_complete'
=>
'All posts were successfully recounted.'
,
'recount_posts_complete'
=>
'All posts were successfully recounted.'
,
...
...
qa-include/pages/admin/admin-approve.php
View file @
ac8b85cb
...
@@ -60,7 +60,7 @@ $pageerror = qa_admin_check_clicks();
...
@@ -60,7 +60,7 @@ $pageerror = qa_admin_check_clicks();
$qa_content
=
qa_content_prepare
();
$qa_content
=
qa_content_prepare
();
$qa_content
[
'title'
]
=
qa_lang_html
(
'admin/
approve
_users_title'
);
$qa_content
[
'title'
]
=
qa_lang_html
(
'admin/
recent
_users_title'
);
$qa_content
[
'error'
]
=
isset
(
$pageerror
)
?
$pageerror
:
qa_admin_page_error
();
$qa_content
[
'error'
]
=
isset
(
$pageerror
)
?
$pageerror
:
qa_admin_page_error
();
$qa_content
[
'message_list'
]
=
array
(
$qa_content
[
'message_list'
]
=
array
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment