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
41f86fe8
Commit
41f86fe8
authored
Jan 16, 2019
by
Scott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Controller: Admin pages
parent
9bb4effd
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
100 additions
and
87 deletions
+100
-87
page.php
qa-include/app/page.php
+4
-2
Points.php
qa-src/Controllers/Admin/Points.php
+46
-41
Stats.php
qa-src/Controllers/Admin/Stats.php
+50
-44
No files found.
qa-include/app/page.php
View file @
41f86fe8
...
@@ -421,9 +421,7 @@ function qa_page_routing()
...
@@ -421,9 +421,7 @@ function qa_page_routing()
'admin/moderate'
=>
'pages/admin/admin-moderate.php'
,
'admin/moderate'
=>
'pages/admin/admin-moderate.php'
,
'admin/pages'
=>
'pages/admin/admin-pages.php'
,
'admin/pages'
=>
'pages/admin/admin-pages.php'
,
'admin/plugins'
=>
'pages/admin/admin-plugins.php'
,
'admin/plugins'
=>
'pages/admin/admin-plugins.php'
,
'admin/points'
=>
'pages/admin/admin-points.php'
,
'admin/recalc'
=>
'pages/admin/admin-recalc.php'
,
'admin/recalc'
=>
'pages/admin/admin-recalc.php'
,
'admin/stats'
=>
'pages/admin/admin-stats.php'
,
'admin/userfields'
=>
'pages/admin/admin-userfields.php'
,
'admin/userfields'
=>
'pages/admin/admin-userfields.php'
,
'admin/usertitles'
=>
'pages/admin/admin-usertitles.php'
,
'admin/usertitles'
=>
'pages/admin/admin-usertitles.php'
,
'answers/'
=>
'pages/answers.php'
,
'answers/'
=>
'pages/answers.php'
,
...
@@ -476,6 +474,10 @@ function qa_routing_config()
...
@@ -476,6 +474,10 @@ function qa_routing_config()
$router
->
addRoute
(
'ip'
,
'get'
,
'ip/{str}'
,
'\Q2A\Controllers\User\Ip'
,
'address'
);
$router
->
addRoute
(
'ip'
,
'get'
,
'ip/{str}'
,
'\Q2A\Controllers\User\Ip'
,
'address'
);
$router
->
addRoute
(
'ip'
,
'post'
,
'ip/{str}'
,
'\Q2A\Controllers\User\Ip'
,
'address'
);
$router
->
addRoute
(
'ip'
,
'post'
,
'ip/{str}'
,
'\Q2A\Controllers\User\Ip'
,
'address'
);
$router
->
addRoute
(
'admin-stats'
,
'get'
,
'admin/stats'
,
'\Q2A\Controllers\Admin\Stats'
,
'index'
);
$router
->
addRoute
(
'admin-points'
,
'get'
,
'admin/points'
,
'\Q2A\Controllers\Admin\Points'
,
'index'
);
$router
->
addRoute
(
'admin-points'
,
'post'
,
'admin/points'
,
'\Q2A\Controllers\Admin\Points'
,
'index'
);
}
}
...
...
qa-
include/pages/admin/admin-p
oints.php
→
qa-
src/Controllers/Admin/P
oints.php
View file @
41f86fe8
...
@@ -3,9 +3,6 @@
...
@@ -3,9 +3,6 @@
Question2Answer by Gideon Greenspan and contributors
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
http://www.question2answer.org/
Description: Controller for admin page for settings about user points
This program is free software; you can redistribute it and/or
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
as published by the Free Software Foundation; either version 2
...
@@ -19,38 +16,44 @@
...
@@ -19,38 +16,44 @@
More about this license: http://www.question2answer.org/license.php
More about this license: http://www.question2answer.org/license.php
*/
*/
if
(
!
defined
(
'QA_VERSION'
))
{
// don't allow this page to be requested directly from browser
namespace
Q2A\Controllers\Admin
;
header
(
'Location: ../../../'
);
exit
;
}
require_once
QA_INCLUDE_DIR
.
'db/recalc.php'
;
use
Q2A\Auth\NoPermissionException
;
require_once
QA_INCLUDE_DIR
.
'db/points.php'
;
use
Q2A\Middleware\Auth\MinimumUserLevel
;
require_once
QA_INCLUDE_DIR
.
'app/options.php'
;
require_once
QA_INCLUDE_DIR
.
'app/admin.php'
;
require_once
QA_INCLUDE_DIR
.
'util/sort.php'
;
/**
* Controller for admin page for settings about user points
*/
class
Points
extends
\Q2A\Controllers\BaseController
{
public
function
__construct
()
{
require_once
QA_INCLUDE_DIR
.
'db/recalc.php'
;
require_once
QA_INCLUDE_DIR
.
'db/points.php'
;
require_once
QA_INCLUDE_DIR
.
'app/options.php'
;
require_once
QA_INCLUDE_DIR
.
'app/admin.php'
;
require_once
QA_INCLUDE_DIR
.
'util/sort.php'
;
// Check admin privileges
parent
::
__construct
();
if
(
!
qa_admin_check_privileges
(
$qa_content
))
{
return
$qa_content
;
}
$this
->
addMiddleware
(
new
MinimumUserLevel
(
QA_USER_LEVEL_ADMIN
));
}
// Process user actions
public
function
index
()
{
// Process user actions
$securityexpired
=
false
;
$securityexpired
=
false
;
$recalculate
=
false
;
$recalculate
=
false
;
$optionnames
=
qa_db_points_option_names
();
$optionnames
=
qa_db_points_option_names
();
if
(
qa_clicked
(
'doshowdefaults'
))
{
if
(
qa_clicked
(
'doshowdefaults'
))
{
$options
=
array
();
$options
=
array
();
foreach
(
$optionnames
as
$optionname
)
{
foreach
(
$optionnames
as
$optionname
)
{
$options
[
$optionname
]
=
qa_default_option
(
$optionname
);
$options
[
$optionname
]
=
qa_default_option
(
$optionname
);
}
}
}
else
{
}
else
{
if
(
qa_clicked
(
'dosaverecalc'
))
{
if
(
qa_clicked
(
'dosaverecalc'
))
{
if
(
!
qa_check_form_security_code
(
'admin/points'
,
qa_post_text
(
'code'
)))
{
if
(
!
qa_check_form_security_code
(
'admin/points'
,
qa_post_text
(
'code'
)))
{
$securityexpired
=
true
;
$securityexpired
=
true
;
...
@@ -68,17 +71,17 @@ if (qa_clicked('doshowdefaults')) {
...
@@ -68,17 +71,17 @@ if (qa_clicked('doshowdefaults')) {
}
}
$options
=
qa_get_options
(
$optionnames
);
$options
=
qa_get_options
(
$optionnames
);
}
}
// Prepare content for theme
// Prepare content for theme
$qa_content
=
qa_content_prepare
();
$qa_content
=
qa_content_prepare
();
$qa_content
[
'title'
]
=
qa_lang_html
(
'admin/admin_title'
)
.
' - '
.
qa_lang_html
(
'admin/points_title'
);
$qa_content
[
'title'
]
=
qa_lang_html
(
'admin/admin_title'
)
.
' - '
.
qa_lang_html
(
'admin/points_title'
);
$qa_content
[
'error'
]
=
$securityexpired
?
qa_lang_html
(
'admin/form_security_expired'
)
:
qa_admin_page_error
();
$qa_content
[
'error'
]
=
$securityexpired
?
qa_lang_html
(
'admin/form_security_expired'
)
:
qa_admin_page_error
();
$qa_content
[
'form'
]
=
array
(
$qa_content
[
'form'
]
=
array
(
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'" name="points_form" onsubmit="document.forms.points_form.has_js.value=1; return true;"'
,
'tags'
=>
'method="post" action="'
.
qa_self_html
()
.
'" name="points_form" onsubmit="document.forms.points_form.has_js.value=1; return true;"'
,
'style'
=>
'wide'
,
'style'
=>
'wide'
,
...
@@ -95,17 +98,17 @@ $qa_content['form'] = array(
...
@@ -95,17 +98,17 @@ $qa_content['form'] = array(
'has_js'
=>
'0'
,
'has_js'
=>
'0'
,
'code'
=>
qa_get_form_security_code
(
'admin/points'
),
'code'
=>
qa_get_form_security_code
(
'admin/points'
),
),
),
);
);
if
(
qa_clicked
(
'doshowdefaults'
))
{
if
(
qa_clicked
(
'doshowdefaults'
))
{
$qa_content
[
'form'
][
'ok'
]
=
qa_lang_html
(
'admin/points_defaults_shown'
);
$qa_content
[
'form'
][
'ok'
]
=
qa_lang_html
(
'admin/points_defaults_shown'
);
$qa_content
[
'form'
][
'buttons'
][
'cancel'
]
=
array
(
$qa_content
[
'form'
][
'buttons'
][
'cancel'
]
=
array
(
'tags'
=>
'name="docancel"'
,
'tags'
=>
'name="docancel"'
,
'label'
=>
qa_lang_html
(
'main/cancel_button'
),
'label'
=>
qa_lang_html
(
'main/cancel_button'
),
);
);
}
else
{
}
else
{
if
(
$recalculate
)
{
if
(
$recalculate
)
{
$qa_content
[
'form'
][
'ok'
]
=
'<span id="recalc_ok"></span>'
;
$qa_content
[
'form'
][
'ok'
]
=
'<span id="recalc_ok"></span>'
;
$qa_content
[
'form'
][
'hidden'
][
'code_recalc'
]
=
qa_get_form_security_code
(
'admin/recalc'
);
$qa_content
[
'form'
][
'hidden'
][
'code_recalc'
]
=
qa_get_form_security_code
(
'admin/recalc'
);
...
@@ -122,10 +125,10 @@ if (qa_clicked('doshowdefaults')) {
...
@@ -122,10 +125,10 @@ if (qa_clicked('doshowdefaults')) {
'tags'
=>
'name="doshowdefaults"'
,
'tags'
=>
'name="doshowdefaults"'
,
'label'
=>
qa_lang_html
(
'admin/show_defaults_button'
),
'label'
=>
qa_lang_html
(
'admin/show_defaults_button'
),
);
);
}
}
foreach
(
$optionnames
as
$optionname
)
{
foreach
(
$optionnames
as
$optionname
)
{
$optionfield
=
array
(
$optionfield
=
array
(
'label'
=>
qa_lang_html
(
'options/'
.
$optionname
),
'label'
=>
qa_lang_html
(
'options/'
.
$optionname
),
'tags'
=>
'name="option_'
.
$optionname
.
'"'
,
'tags'
=>
'name="option_'
.
$optionname
.
'"'
,
...
@@ -170,15 +173,17 @@ foreach ($optionnames as $optionname) {
...
@@ -170,15 +173,17 @@ foreach ($optionnames as $optionname) {
$optionfield
[
'prefix'
]
=
'<span style="width:1em; display:inline-block; display:-moz-inline-stack;">'
.
$prefix
.
'</span>'
;
$optionfield
[
'prefix'
]
=
'<span style="width:1em; display:inline-block; display:-moz-inline-stack;">'
.
$prefix
.
'</span>'
;
$qa_content
[
'form'
][
'fields'
][
$optionname
]
=
$optionfield
;
$qa_content
[
'form'
][
'fields'
][
$optionname
]
=
$optionfield
;
}
}
qa_array_insert
(
$qa_content
[
'form'
][
'fields'
],
'points_post_a'
,
array
(
'blank0'
=>
array
(
'type'
=>
'blank'
)));
qa_array_insert
(
$qa_content
[
'form'
][
'fields'
],
'points_post_a'
,
array
(
'blank0'
=>
array
(
'type'
=>
'blank'
)));
qa_array_insert
(
$qa_content
[
'form'
][
'fields'
],
'points_per_c_voted_up'
,
array
(
'blank1'
=>
array
(
'type'
=>
'blank'
)));
qa_array_insert
(
$qa_content
[
'form'
][
'fields'
],
'points_per_c_voted_up'
,
array
(
'blank1'
=>
array
(
'type'
=>
'blank'
)));
qa_array_insert
(
$qa_content
[
'form'
][
'fields'
],
'points_vote_up_q'
,
array
(
'blank2'
=>
array
(
'type'
=>
'blank'
)));
qa_array_insert
(
$qa_content
[
'form'
][
'fields'
],
'points_vote_up_q'
,
array
(
'blank2'
=>
array
(
'type'
=>
'blank'
)));
qa_array_insert
(
$qa_content
[
'form'
][
'fields'
],
'points_multiple'
,
array
(
'blank3'
=>
array
(
'type'
=>
'blank'
)));
qa_array_insert
(
$qa_content
[
'form'
][
'fields'
],
'points_multiple'
,
array
(
'blank3'
=>
array
(
'type'
=>
'blank'
)));
$qa_content
[
'navigation'
][
'sub'
]
=
qa_admin_sub_navigation
();
$qa_content
[
'navigation'
][
'sub'
]
=
qa_admin_sub_navigation
();
return
$qa_content
;
return
$qa_content
;
}
}
qa-
include/pages/admin/admin-s
tats.php
→
qa-
src/Controllers/Admin/S
tats.php
View file @
41f86fe8
...
@@ -3,9 +3,6 @@
...
@@ -3,9 +3,6 @@
Question2Answer by Gideon Greenspan and contributors
Question2Answer by Gideon Greenspan and contributors
http://www.question2answer.org/
http://www.question2answer.org/
Description: Controller for admin page showing usage statistics and clean-up buttons
This program is free software; you can redistribute it and/or
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
as published by the Free Software Foundation; either version 2
...
@@ -19,45 +16,52 @@
...
@@ -19,45 +16,52 @@
More about this license: http://www.question2answer.org/license.php
More about this license: http://www.question2answer.org/license.php
*/
*/
if
(
!
defined
(
'QA_VERSION'
))
{
// don't allow this page to be requested directly from browser
namespace
Q2A\Controllers\Admin
;
header
(
'Location: ../../../'
);
exit
;
}
require_once
QA_INCLUDE_DIR
.
'db/recalc.php'
;
require_once
QA_INCLUDE_DIR
.
'app/admin.php'
;
require_once
QA_INCLUDE_DIR
.
'db/admin.php'
;
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
use
Q2A\Auth\NoPermissionException
;
use
Q2A\Middleware\Auth\MinimumUserLevel
;
// Check admin privileges (do late to allow one DB query)
/**
* Controller for admin page showing usage statistics and clean-up buttons
*/
class
Stats
extends
\Q2A\Controllers\BaseController
{
public
function
__construct
()
{
require_once
QA_INCLUDE_DIR
.
'db/recalc.php'
;
require_once
QA_INCLUDE_DIR
.
'app/admin.php'
;
require_once
QA_INCLUDE_DIR
.
'db/admin.php'
;
require_once
QA_INCLUDE_DIR
.
'app/format.php'
;
if
(
!
qa_admin_check_privileges
(
$qa_content
))
parent
::
__construct
();
return
$qa_content
;
$this
->
addMiddleware
(
new
MinimumUserLevel
(
QA_USER_LEVEL_ADMIN
));
}
// Get the information to display
public
function
index
()
{
// Get the information to display
$qcount
=
(
int
)
qa_opt
(
'cache_qcount'
);
$qcount
=
(
int
)
qa_opt
(
'cache_qcount'
);
$qcount_anon
=
qa_db_count_posts
(
'Q'
,
false
);
$qcount_anon
=
qa_db_count_posts
(
'Q'
,
false
);
$qcount_unans
=
(
int
)
qa_opt
(
'cache_unaqcount'
);
$qcount_unans
=
(
int
)
qa_opt
(
'cache_unaqcount'
);
$acount
=
(
int
)
qa_opt
(
'cache_acount'
);
$acount
=
(
int
)
qa_opt
(
'cache_acount'
);
$acount_anon
=
qa_db_count_posts
(
'A'
,
false
);
$acount_anon
=
qa_db_count_posts
(
'A'
,
false
);
$ccount
=
(
int
)
qa_opt
(
'cache_ccount'
);
$ccount
=
(
int
)
qa_opt
(
'cache_ccount'
);
$ccount_anon
=
qa_db_count_posts
(
'C'
,
false
);
$ccount_anon
=
qa_db_count_posts
(
'C'
,
false
);
// Prepare content for theme
// Prepare content for theme
$qa_content
=
qa_content_prepare
();
$qa_content
=
qa_content_prepare
();
$qa_content
[
'title'
]
=
qa_lang_html
(
'admin/admin_title'
)
.
' - '
.
qa_lang_html
(
'admin/stats_title'
);
$qa_content
[
'title'
]
=
qa_lang_html
(
'admin/admin_title'
)
.
' - '
.
qa_lang_html
(
'admin/stats_title'
);
$qa_content
[
'error'
]
=
qa_admin_page_error
();
$qa_content
[
'error'
]
=
qa_admin_page_error
();
$qa_content
[
'form'
]
=
array
(
$qa_content
[
'form'
]
=
array
(
'style'
=>
'wide'
,
'style'
=>
'wide'
,
'fields'
=>
array
(
'fields'
=>
array
(
...
@@ -191,19 +195,19 @@ $qa_content['form'] = array(
...
@@ -191,19 +195,19 @@ $qa_content['form'] = array(
'value'
=>
qa_html
(
qa_format_number
(
qa_db_count_active_users
(
'uservotes'
))),
'value'
=>
qa_html
(
qa_format_number
(
qa_db_count_active_users
(
'uservotes'
))),
),
),
),
),
);
);
if
(
QA_FINAL_EXTERNAL_USERS
)
if
(
QA_FINAL_EXTERNAL_USERS
)
unset
(
$qa_content
[
'form'
][
'fields'
][
'users'
]);
unset
(
$qa_content
[
'form'
][
'fields'
][
'users'
]);
else
else
unset
(
$qa_content
[
'form'
][
'fields'
][
'users_active'
]);
unset
(
$qa_content
[
'form'
][
'fields'
][
'users_active'
]);
foreach
(
$qa_content
[
'form'
][
'fields'
]
as
$index
=>
$field
)
{
foreach
(
$qa_content
[
'form'
][
'fields'
]
as
$index
=>
$field
)
{
if
(
empty
(
$field
[
'type'
]))
if
(
empty
(
$field
[
'type'
]))
$qa_content
[
'form'
][
'fields'
][
$index
][
'type'
]
=
'static'
;
$qa_content
[
'form'
][
'fields'
][
$index
][
'type'
]
=
'static'
;
}
}
$qa_content
[
'form_2'
]
=
array
(
$qa_content
[
'form_2'
]
=
array
(
'tags'
=>
'method="post" action="'
.
qa_path_html
(
'admin/recalc'
)
.
'"'
,
'tags'
=>
'method="post" action="'
.
qa_path_html
(
'admin/recalc'
)
.
'"'
,
'title'
=>
qa_lang_html
(
'admin/database_cleanup'
),
'title'
=>
qa_lang_html
(
'admin/database_cleanup'
),
...
@@ -251,12 +255,12 @@ $qa_content['form_2'] = array(
...
@@ -251,12 +255,12 @@ $qa_content['form_2'] = array(
'hidden'
=>
array
(
'hidden'
=>
array
(
'code'
=>
qa_get_form_security_code
(
'admin/recalc'
),
'code'
=>
qa_get_form_security_code
(
'admin/recalc'
),
),
),
);
);
if
(
!
qa_using_categories
())
if
(
!
qa_using_categories
())
unset
(
$qa_content
[
'form_2'
][
'buttons'
][
'recalc_categories'
]);
unset
(
$qa_content
[
'form_2'
][
'buttons'
][
'recalc_categories'
]);
if
(
defined
(
'QA_BLOBS_DIRECTORY'
))
{
if
(
defined
(
'QA_BLOBS_DIRECTORY'
))
{
if
(
qa_db_has_blobs_in_db
())
{
if
(
qa_db_has_blobs_in_db
())
{
$qa_content
[
'form_2'
][
'buttons'
][
'blobs_to_disk'
]
=
array
(
$qa_content
[
'form_2'
][
'buttons'
][
'blobs_to_disk'
]
=
array
(
'label'
=>
qa_lang_html
(
'admin/blobs_to_disk'
),
'label'
=>
qa_lang_html
(
'admin/blobs_to_disk'
),
...
@@ -272,17 +276,19 @@ if (defined('QA_BLOBS_DIRECTORY')) {
...
@@ -272,17 +276,19 @@ if (defined('QA_BLOBS_DIRECTORY')) {
'note'
=>
'<span id="blobs_to_db_note">'
.
qa_lang_html
(
'admin/blobs_to_db_note'
)
.
'</span>'
,
'note'
=>
'<span id="blobs_to_db_note">'
.
qa_lang_html
(
'admin/blobs_to_db_note'
)
.
'</span>'
,
);
);
}
}
}
}
$qa_content
[
'script_rel'
][]
=
'qa-content/qa-admin.js?'
.
QA_VERSION
;
$qa_content
[
'script_rel'
][]
=
'qa-content/qa-admin.js?'
.
QA_VERSION
;
$qa_content
[
'script_var'
][
'qa_warning_recalc'
]
=
qa_lang
(
'admin/stop_recalc_warning'
);
$qa_content
[
'script_var'
][
'qa_warning_recalc'
]
=
qa_lang
(
'admin/stop_recalc_warning'
);
$qa_content
[
'script_onloads'
][]
=
array
(
$qa_content
[
'script_onloads'
][]
=
array
(
"qa_version_check('https://raw.githubusercontent.com/q2a/question2answer/master/VERSION.txt', "
.
qa_js
(
qa_html
(
QA_VERSION
),
true
)
.
", 'q2a-version', true);"
"qa_version_check('https://raw.githubusercontent.com/q2a/question2answer/master/VERSION.txt', "
.
qa_js
(
qa_html
(
QA_VERSION
),
true
)
.
", 'q2a-version', true);"
);
);
$qa_content
[
'navigation'
][
'sub'
]
=
qa_admin_sub_navigation
();
$qa_content
[
'navigation'
][
'sub'
]
=
qa_admin_sub_navigation
();
return
$qa_content
;
return
$qa_content
;
}
}
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