Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plugins bot
moodle-plugins-snapshots
Commits
220a90c5
Commit
220a90c5
authored
Dec 19, 2007
by
skodak
Browse files
MDL-11561 admin tree improvements and bugfixing
parent
a5feb176
Changes
110
Hide whitespace changes
Inline
Side-by-side
admin/auth.php
View file @
220a90c5
...
...
@@ -11,7 +11,10 @@ require_once('../config.php');
require_once
(
$CFG
->
libdir
.
'/adminlib.php'
);
require_once
(
$CFG
->
libdir
.
'/tablelib.php'
);
admin_externalpage_setup
(
'userauthentication'
);
require_login
();
require_capability
(
'moodle/site:config'
,
get_context_instance
(
CONTEXT_SYSTEM
));
$returnurl
=
"
$CFG->wwwroot
/
$CFG->admin
/settings.php?section=manageauths"
;
$action
=
optional_param
(
'action'
,
''
,
PARAM_ACTION
);
$auth
=
optional_param
(
'auth'
,
''
,
PARAM_SAFEDIR
);
...
...
@@ -19,13 +22,6 @@ $auth = optional_param('auth', '', PARAM_SAFEDIR);
// get currently installed and enabled auth plugins
$authsavailable
=
get_list_of_plugins
(
'auth'
);
//revert auth_plugins_enabled
if
(
isset
(
$CFG
->
auth_plugins_enabled
))
{
set_config
(
'auth'
,
$CFG
->
auth_plugins_enabled
);
delete_records
(
'config'
,
'name'
,
'auth_plugins_enabled'
);
unset
(
$CFG
->
auth_plugins_enabled
);
}
get_enabled_auth_plugins
(
true
);
// fix the list of enabled auths
if
(
empty
(
$CFG
->
auth
))
{
$authsenabled
=
array
();
...
...
@@ -33,45 +29,18 @@ if (empty($CFG->auth)) {
$authsenabled
=
explode
(
','
,
$CFG
->
auth
);
}
if
(
!
isset
(
$CFG
->
registerauth
))
{
set_config
(
'registerauth'
,
''
);
}
if
(
!
isset
(
$CFG
->
auth_instructions
))
{
set_config
(
'auth_instructions'
,
''
);
}
if
(
!
empty
(
$auth
)
and
!
exists_auth_plugin
(
$auth
))
{
error
(
get_string
(
'pluginnotinstalled'
,
'auth'
,
$auth
),
$url
);
}
////////////////////////////////////////////////////////////////////////////////
// process actions
$status
=
''
;
if
(
!
confirm_sesskey
())
{
redirect
(
$returnurl
);
}
switch
(
$action
)
{
case
'save'
:
if
(
data_submitted
()
and
confirm_sesskey
())
{
// save settings
set_config
(
'guestloginbutton'
,
required_param
(
'guestloginbutton'
,
PARAM_BOOL
));
set_config
(
'alternateloginurl'
,
stripslashes
(
trim
(
required_param
(
'alternateloginurl'
,
PARAM_RAW
))));
set_config
(
'forgottenpasswordurl'
,
stripslashes
(
trim
(
required_param
(
'forgottenpasswordurl'
,
PARAM_RAW
))));
set_config
(
'registerauth'
,
required_param
(
'register'
,
PARAM_SAFEDIR
));
set_config
(
'auth_instructions'
,
stripslashes
(
trim
(
required_param
(
'auth_instructions'
,
PARAM_RAW
))));
// enable registerauth in $CFG->auth if needed
if
(
!
empty
(
$CFG
->
registerauth
)
and
!
in_array
(
$CFG
->
registerauth
,
$authsenabled
))
{
$authsenabled
[]
=
$CFG
->
registerauth
;
set_config
(
'auth'
,
implode
(
','
,
$authsenabled
));
}
$status
=
get_string
(
'changessaved'
);
}
break
;
case
'disable'
:
// remove from enabled list
$key
=
array_search
(
$auth
,
$authsenabled
);
...
...
@@ -128,198 +97,6 @@ switch ($action) {
break
;
}
// display strings
$txt
=
get_strings
(
array
(
'authenticationplugins'
,
'users'
,
'administration'
,
'settings'
,
'edit'
,
'name'
,
'enable'
,
'disable'
,
'up'
,
'down'
,
'none'
));
$txt
->
updown
=
"
$txt->up
/
$txt->down
"
;
// construct the display array, with enabled auth plugins at the top, in order
$displayauths
=
array
();
$registrationauths
=
array
();
$registrationauths
[
''
]
=
$txt
->
disable
;
foreach
(
$authsenabled
as
$auth
)
{
$authplugin
=
get_auth_plugin
(
$auth
);
/// Get the auth title (from core or own auth lang files)
$authtitle
=
get_string
(
"auth_
{
$auth
}
title"
,
"auth"
);
if
(
$authtitle
==
"[[auth_
{
$auth
}
title]]"
)
{
$authtitle
=
get_string
(
"auth_
{
$auth
}
title"
,
"auth_
{
$auth
}
"
);
}
/// Apply titles
$displayauths
[
$auth
]
=
$authtitle
;
if
(
$authplugin
->
can_signup
())
{
$registrationauths
[
$auth
]
=
$authtitle
;
}
}
foreach
(
$authsavailable
as
$auth
)
{
if
(
array_key_exists
(
$auth
,
$displayauths
))
{
continue
;
//already in the list
}
$authplugin
=
get_auth_plugin
(
$auth
);
/// Get the auth title (from core or own auth lang files)
$authtitle
=
get_string
(
"auth_
{
$auth
}
title"
,
"auth"
);
if
(
$authtitle
==
"[[auth_
{
$auth
}
title]]"
)
{
$authtitle
=
get_string
(
"auth_
{
$auth
}
title"
,
"auth_
{
$auth
}
"
);
}
/// Apply titles
$displayauths
[
$auth
]
=
$authtitle
;
if
(
$authplugin
->
can_signup
())
{
$registrationauths
[
$auth
]
=
$authtitle
;
}
}
// build the display table
$table
=
new
flexible_table
(
'auth_admin_table'
);
$table
->
define_columns
(
array
(
'name'
,
'enable'
,
'order'
,
'settings'
));
$table
->
define_headers
(
array
(
$txt
->
name
,
$txt
->
enable
,
$txt
->
updown
,
$txt
->
settings
));
$table
->
define_baseurl
(
"
{
$CFG
->
wwwroot
}
/
{
$CFG
->
admin
}
/auth.php"
);
$table
->
set_attribute
(
'id'
,
'blocks'
);
$table
->
set_attribute
(
'class'
,
'generaltable generalbox boxaligncenter boxwidthwide'
);
$table
->
setup
();
//add always enabled plugins first
$displayname
=
"<span>"
.
$displayauths
[
'manual'
]
.
"</span>"
;
$settings
=
"<a href=
\"
auth_config.php?sesskey=
{
$USER
->
sesskey
}
&auth=manual
\"
>
{
$txt
->
settings
}
</a>"
;
$table
->
add_data
(
array
(
$displayname
,
''
,
''
,
$settings
));
$displayname
=
"<span>"
.
$displayauths
[
'nologin'
]
.
"</span>"
;
$settings
=
"<a href=
\"
auth_config.php?sesskey=
{
$USER
->
sesskey
}
&auth=nologin
\"
>
{
$txt
->
settings
}
</a>"
;
$table
->
add_data
(
array
(
$displayname
,
''
,
''
,
$settings
));
// iterate through auth plugins and add to the display table
$updowncount
=
1
;
$authcount
=
count
(
$authsenabled
);
$url
=
"auth.php?sesskey="
.
sesskey
();
foreach
(
$displayauths
as
$auth
=>
$name
)
{
if
(
$auth
==
'manual'
or
$auth
==
'nologin'
)
{
continue
;
}
// hide/show link
if
(
in_array
(
$auth
,
$authsenabled
))
{
$hideshow
=
"<a href=
\"
$url
&action=disable&auth=
$auth
\"
>"
;
$hideshow
.
=
"<img src=
\"
{
$CFG
->
pixpath
}
/i/hide.gif
\"
class=
\"
icon
\"
alt=
\"
disable
\"
/></a>"
;
// $hideshow = "<a href=\"$url&action=disable&auth=$auth\"><input type=\"checkbox\" checked /></a>";
$enabled
=
true
;
$displayname
=
"<span>
$name
</span>"
;
}
else
{
$hideshow
=
"<a href=
\"
$url
&action=enable&auth=
$auth
\"
>"
;
$hideshow
.
=
"<img src=
\"
{
$CFG
->
pixpath
}
/i/show.gif
\"
class=
\"
icon
\"
alt=
\"
enable
\"
/></a>"
;
// $hideshow = "<a href=\"$url&action=enable&auth=$auth\"><input type=\"checkbox\" /></a>";
$enabled
=
false
;
$displayname
=
"<span class=
\"
dimmed_text
\"
>
$name
</span>"
;
}
// up/down link (only if auth is enabled)
$updown
=
''
;
if
(
$enabled
)
{
if
(
$updowncount
>
1
)
{
$updown
.
=
"<a href=
\"
$url
&action=up&auth=
$auth
\"
>"
;
$updown
.
=
"<img src=
\"
{
$CFG
->
pixpath
}
/t/up.gif
\"
alt=
\"
up
\"
/></a> "
;
}
else
{
$updown
.
=
"<img src=
\"
{
$CFG
->
pixpath
}
/spacer.gif
\"
class=
\"
icon
\"
alt=
\"\"
/> "
;
}
if
(
$updowncount
<
$authcount
)
{
$updown
.
=
"<a href=
\"
$url
&action=down&auth=
$auth
\"
>"
;
$updown
.
=
"<img src=
\"
{
$CFG
->
pixpath
}
/t/down.gif
\"
alt=
\"
down
\"
/></a>"
;
}
else
{
$updown
.
=
"<img src=
\"
{
$CFG
->
pixpath
}
/spacer.gif
\"
class=
\"
icon
\"
alt=
\"\"
/>"
;
}
++
$updowncount
;
}
// settings link
$settings
=
"<a href=
\"
auth_config.php?sesskey=
{
$USER
->
sesskey
}
&auth=
$auth
\"
>
{
$txt
->
settings
}
</a>"
;
// add a row to the table
$table
->
add_data
(
array
(
$displayname
,
$hideshow
,
$updown
,
$settings
));
}
// output form
admin_externalpage_print_header
();
//print stus messages
if
(
$status
!==
''
)
{
notify
(
$status
,
'notifysuccess'
);
}
print_simple_box
(
get_string
(
'configauthenticationplugins'
,
'admin'
),
'center'
,
'700'
);
$table
->
print_html
();
////////////////////////////////////////////////////////////////////////////////
$guestoptions
=
array
();
$guestoptions
[
0
]
=
get_string
(
"hide"
);
$guestoptions
[
1
]
=
get_string
(
"show"
);
echo
'<hr />'
;
echo
'<form '
.
$CFG
->
frametarget
.
' id="adminsettings" method="post" action="auth.php">'
;
echo
'<div class="settingsform clearfix">'
;
print_heading
(
get_string
(
'auth_common_settings'
,
'auth'
));
echo
'<input type="hidden" name="sesskey" value="'
.
sesskey
()
.
'" />'
;
echo
'<input type="hidden" name="action" value="save" />'
;
echo
'<fieldset>'
;
##echo '<table cellspacing="0" cellpadding="5" border="0" style="margin-left:auto;margin-right:auto">';
// User self registration
echo
'<div class="form-item" id="admin-register">'
;
echo
'<label for = "menuregister">'
.
get_string
(
"selfregistration"
,
"auth"
);
echo
'<span class="form-shortname">registerauth</span>'
;
echo
'</label>'
;
choose_from_menu
(
$registrationauths
,
"register"
,
$CFG
->
registerauth
,
""
);
echo
'<div class="description">'
.
get_string
(
"selfregistration_help"
,
"auth"
)
.
'</div>'
;
echo
'</div>'
;
// Login as guest button enabled
echo
'<div class="form-item" id="admin-guestloginbutton">'
;
echo
'<label for = "menuguestloginbutton">'
.
get_string
(
"guestloginbutton"
,
"auth"
);
echo
'<span class="form-shortname">guestloginbutton</span>'
;
echo
'</label>'
;
choose_from_menu
(
$guestoptions
,
"guestloginbutton"
,
$CFG
->
guestloginbutton
,
""
);
echo
'<div class="description">'
.
get_string
(
"showguestlogin"
,
"auth"
)
.
'</div>'
;
echo
'</div>'
;
/// An alternate url for the login form. It means we can use login forms that are integrated
/// into non-moodle pages
echo
'<div class="form-item" id="admin-alternateloginurl">'
;
echo
'<label for = "alternateloginurl">'
.
get_string
(
"alternateloginurl"
,
"auth"
);
echo
'<span class="form-shortname">alternateloginurl</span>'
;
echo
'</label>'
;
echo
'<input type="text" size="60" name="alternateloginurl" id="alternateloginurl" value="'
.
s
(
$CFG
->
alternateloginurl
)
.
"
\"
/>
\n
"
;
echo
'<div class="description">'
.
get_string
(
"alternatelogin"
,
"auth"
,
htmlspecialchars
(
$CFG
->
wwwroot
.
'/login/index.php'
))
.
'</div>'
;
echo
'</div>'
;
/// An alternate url for lost passwords. It means we can use external lost password
/// recovery for all users. Effectively disables built-in processes!!!
echo
'<div class="form-item" id="admin-forgottenpasswordurl">'
;
echo
'<label for = "forgottenpasswordurl">'
.
get_string
(
"forgottenpasswordurl"
,
"auth"
);
echo
'<span class="form-shortname">forgottenpasswordurl</span>'
;
echo
'</label>'
;
echo
'<input type="text" size="60" name="forgottenpasswordurl" id="forgottenpasswordurl" value="'
.
s
(
$CFG
->
forgottenpasswordurl
)
.
"
\"
/>
\n
"
;
echo
'<div class="description">'
.
get_string
(
"forgottenpassword"
,
"auth"
)
.
'</div>'
;
echo
'</div>'
;
/// Instructions about login/password
/// to be showed to users
echo
'<div class="form-item" id="admin-auth_instructions">'
;
echo
'<label for = "auth_instructions">'
.
get_string
(
"instructions"
,
"auth"
);
echo
'<span class="form-shortname">auth_instructions</span>'
;
echo
'</label>'
;
echo
'<textarea cols="30" rows="4" name="auth_instructions" id="auth_instructions">'
.
s
(
$CFG
->
auth_instructions
)
.
"</textarea>
\n
"
;
echo
'<div class="description">'
.
get_string
(
"authinstructions"
,
"auth"
)
.
'</div>'
;
echo
'</div>'
;
echo
'</fieldset>'
;
////////////////////////////////////////////////////////////////////////////////
echo
'<div class="form-buttons"><input class="form-submit" type="submit" value="'
.
get_string
(
'savechanges'
,
'admin'
)
.
'" /></div>'
;
echo
'</div>'
;
echo
'</form>'
;
admin_externalpage_print_footer
();
redirect
(
$returnurl
);
?>
admin/auth_config.php
View file @
220a90c5
...
...
@@ -6,18 +6,17 @@
require_once
'../config.php'
;
require_once
$CFG
->
libdir
.
'/adminlib.php'
;
admin_externalpage_setup
(
'userauthentication'
);
$auth
=
required_param
(
'auth'
,
PARAM_SAFEDIR
);
admin_externalpage_setup
(
'authsetting'
.
$auth
);
$authplugin
=
get_auth_plugin
(
$auth
);
$err
=
array
();
// save configuration changes
if
(
$frm
=
data_submitted
())
{
if
(
!
confirm_sesskey
())
{
error
(
get_string
(
'confirmsesskeybad'
,
'error'
));
}
$returnurl
=
"
$CFG->wwwroot
/
$CFG->admin
/settings.php?section=manageauths"
;
// save configuration changes
if
(
$frm
=
data_submitted
()
and
confirm_sesskey
())
{
$frm
=
stripslashes_recursive
(
$frm
);
$authplugin
->
validate_form
(
$frm
,
$err
);
...
...
@@ -37,7 +36,7 @@ if ($frm = data_submitted()) {
}
}
}
redirect
(
"auth.php"
);
redirect
(
$returnurl
);
exit
;
}
}
else
{
...
...
admin/block.php
View file @
220a90c5
...
...
@@ -6,14 +6,14 @@
require_once
(
$CFG
->
libdir
.
'/adminlib.php'
);
require_once
(
$CFG
->
libdir
.
'/blocklib.php'
);
admin_externalpage_setup
(
'manageblocks'
);
$blockid
=
required_param
(
'block'
,
PARAM_INT
);
if
(
(
$blockrecord
=
blocks_get_record
(
$blockid
))
===
false
)
{
if
(
!
$blockrecord
=
blocks_get_record
(
$blockid
))
{
error
(
'This block does not exist'
);
}
admin_externalpage_setup
(
'blocksetting'
.
$blockrecord
->
name
);
$block
=
block_instance
(
$blockrecord
->
name
);
if
(
$block
===
false
)
{
error
(
'Problem in instantiating block object'
);
...
...
@@ -50,11 +50,6 @@
$strmanageblocks
=
get_string
(
'manageblocks'
);
$strblockname
=
$block
->
get_title
();
// $CFG->pagepath is used to generate the body and id attributes for the body tag
// of the page. It is also used to generate the link to the Moodle Docs for this view.
$CFG
->
pagepath
=
'block/'
.
$block
->
name
()
.
'/config'
;
admin_externalpage_print_header
();
print_heading
(
$strblockname
);
...
...
@@ -70,6 +65,6 @@
echo
'</p>'
;
$block
->
config_print
();
echo
'</form>'
;
admin_externalpage_
print_footer
();
print_footer
();
?>
admin/blocks.php
View file @
220a90c5
...
...
@@ -29,10 +29,6 @@
$strmultiple
=
get_string
(
'blockmultiple'
,
'admin'
);
$strshowblockcourse
=
get_string
(
'showblockcourse'
);
admin_externalpage_print_header
();
print_heading
(
$strmanageblocks
);
/// If data submitted, then process and store.
if
(
!
empty
(
$hide
)
&&
confirm_sesskey
())
{
...
...
@@ -40,6 +36,7 @@
error
(
"Block doesn't exist!"
);
}
set_field
(
'block'
,
'visible'
,
'0'
,
'id'
,
$block
->
id
);
// Hide block
admin_get_root
(
true
,
false
);
// settings not required - only pages
}
if
(
!
empty
(
$show
)
&&
confirm_sesskey
()
)
{
...
...
@@ -47,6 +44,7 @@
error
(
"Block doesn't exist!"
);
}
set_field
(
'block'
,
'visible'
,
'1'
,
'id'
,
$block
->
id
);
// Show block
admin_get_root
(
true
,
false
);
// settings not required - only pages
}
if
(
!
empty
(
$multiple
)
&&
confirm_sesskey
())
{
...
...
@@ -55,9 +53,12 @@
}
$block
->
multiple
=
!
$block
->
multiple
;
update_record
(
'block'
,
$block
);
admin_get_root
(
true
,
false
);
// settings not required - only pages
}
if
(
!
empty
(
$delete
)
&&
confirm_sesskey
())
{
admin_externalpage_print_header
();
print_heading
(
$strmanageblocks
);
if
(
!
$block
=
blocks_get_record
(
$delete
))
{
error
(
"Block doesn't exist!"
);
...
...
@@ -130,6 +131,9 @@
}
}
admin_externalpage_print_header
();
print_heading
(
$strmanageblocks
);
/// Main display starts here
/// Get and sort the existing blocks
...
...
@@ -174,21 +178,26 @@
foreach
(
$blockbyname
as
$blockname
=>
$blockid
)
{
$blockobject
=
$blockobjects
[
$blockid
];
$block
=
$blocks
[
$blockid
];
$delete
=
'<a href="blocks.php?delete='
.
$blockid
.
'&sesskey='
.
$USER
->
sesskey
.
'">'
.
$strdelete
.
'</a>'
;
$settings
=
''
;
// By default, no configuration
if
(
$blockobject
->
has_config
())
{
$settings
=
'<a href="block.php?block='
.
$blockid
.
'">'
.
$strsettings
.
'</a>'
;
if
(
$blockobject
->
has_config
())
{
if
(
file_exists
(
$CFG
->
dirroot
.
'/blocks/'
.
$block
->
name
.
'/settings.php'
))
{
$settings
=
'<a href="'
.
$CFG
->
wwwroot
.
'/'
.
$CFG
->
admin
.
'/settings.php?section=blocksetting'
.
$block
->
name
.
'">'
.
$strsettings
.
'</a>'
;
}
else
{
$settings
=
'<a href="block.php?block='
.
$blockid
.
'">'
.
$strsettings
.
'</a>'
;
}
}
// MDL-11167, blocks can be placed on mymoodle, or the blogs page
// and it should not show up on course search page
$totalcount
=
count_records
(
'block_instance'
,
'blockid'
,
$blockid
);
$count
=
count_records_sql
(
'SELECT COUNT(*)
FROM '
.
$CFG
->
prefix
.
'block_instance
$count
=
count_records_sql
(
'SELECT COUNT(*)
FROM '
.
$CFG
->
prefix
.
'block_instance
WHERE blockid = '
.
$blockid
.
' AND
pagetype = \'course-view\''
);
...
...
admin/filter.php
View file @
220a90c5
...
...
@@ -6,20 +6,18 @@
require_once
(
$CFG
->
libdir
.
'/adminlib.php'
);
require_once
(
$CFG
->
libdir
.
'/tablelib.php'
);
admin_externalpage_setup
(
'managefilters'
);
// get parameters
$param
=
new
Object
;
$param
->
filter
=
required_param
(
'filter'
,
PARAM_PATH
);
$param
->
submit
=
optional_param
(
'submit'
,
0
,
PARAM_BOOL
);
$param
->
reset
=
optional_param
(
'reset'
,
0
,
PARAM_BOOL
);
$filterfull
=
required_param
(
'filter'
,
PARAM_PATH
);
$forcereset
=
optional_param
(
'reset'
,
0
,
PARAM_BOOL
);
$filtername
=
substr
(
$filterfull
,
strpos
(
$filterfull
,
'/'
)
+
1
)
;
$filtername
=
substr
(
$param
->
filter
,
strpos
(
$param
->
filter
,
'/'
)
+
1
)
;
admin_externalpage_setup
(
'filtersetting'
.
str_replace
(
'/'
,
''
,
$filterfull
));
$returnurl
=
"
$CFG->wwwroot
/
$CFG->admin
/settings.php?section=managefilters"
;
// $CFG->pagepath is used to generate the body and id attributes for the body tag
// of the page. It is also used to generate the link to the Moodle Docs for this view.
$CFG
->
pagepath
=
'filter/'
.
$filtername
.
'/config'
;
// get translated strings for use on page
$txt
=
new
Object
;
...
...
@@ -32,12 +30,7 @@
//======================
// if reset pressed let filter config page handle it
$forcereset
=
false
;
if
(
!
empty
(
$param
->
reset
))
{
$forcereset
=
true
;
}
else
if
(
$config
=
data_submitted
())
{
if
(
$config
=
data_submitted
()
and
!
$forcereset
)
{
// check session key
if
(
!
confirm_sesskey
())
{
...
...
@@ -61,7 +54,7 @@
set_config
(
$name
,
stripslashes
(
$value
));
}
}
redirect
(
"
$CFG->wwwroot
/
$CFG->admin
/filters.php"
);
redirect
(
$returnurl
);
exit
;
}
...
...
@@ -79,11 +72,11 @@
print_simple_box_start
(
"center"
,
''
);
?>
<form
action=
"filter.php?filter=
<?php
echo
urlencode
(
$
param
->
filter
);
?>
"
method=
"post"
>
<form
action=
"filter.php?filter=
<?php
echo
urlencode
(
$filter
full
);
?>
"
method=
"post"
>
<div
style=
"text-align: center"
>
<input
type=
"hidden"
name=
"sesskey"
value=
"
<?php
echo
sesskey
();
?>
"
/>
<?php
include
"
$CFG->dirroot
/
$
param->
filter
/filterconfig.html"
;
?>
<?php
include
"
$CFG->dirroot
/
$filter
full
/filterconfig.html"
;
?>
<input
type=
"submit"
name=
"submit"
value=
"
<?php
print_string
(
'savechanges'
);
?>
"
/>
<input
type=
"submit"
name=
"reset"
value=
"
<?php
echo
print_string
(
'resettodefaults'
);
?>
"
/>
...
...
admin/filters.php
View file @
220a90c5
<?php
// $Id$
// filters.php
// Edit list of available text filters
require_once
(
'../config.php'
);
require_once
(
$CFG
->
libdir
.
'/adminlib.php'
);
require_once
(
$CFG
->
libdir
.
'/tablelib.php'
);
// defines
define
(
'FILTER_TABLE'
,
'filter_administration_table'
);
$action
=
optional_param
(
'action'
,
''
,
PARAM_ACTION
);
$filterpath
=
optional_param
(
'filterpath'
,
''
,
PARAM_PATH
);
admin_externalpage_setup
(
'managefilters'
);
require_login
();
require_capability
(
'moodle/site:config'
,
get_context_instance
(
CONTEXT_SYSTEM
));
// get values from page
$params
=
new
object
();
$params
->
action
=
optional_param
(
'action'
,
''
,
PARAM_ACTION
);
$params
->
filterpath
=
optional_param
(
'filterpath'
,
''
,
PARAM_PATH
);
$params
->
cachetext
=
optional_param
(
'cachetext'
,
0
,
PARAM_INT
);
$params
->
filterall
=
optional_param
(
'filterall'
,
0
,
PARAM_BOOL
);
$params
->
filteruploadedfiles
=
optional_param
(
'filteruploadedfiles'
,
0
,
PARAM_INT
);
$params
->
filtermatchoneperpage
=
optional_param
(
'filtermatchoneperpage'
,
0
,
PARAM_BOOL
);
$params
->
filtermatchonepertext
=
optional_param
(
'filtermatchonepertext'
,
0
,
PARAM_BOOL
);
$returnurl
=
"
$CFG->wwwroot
/
$CFG->admin
/settings.php?section=managefilters"
;
// some basic information
$url
=
'filters.php'
;
$myurl
=
"
$url
?sesskey="
.
sesskey
();
$img
=
"
$CFG->pixpath
/t"
;
// get translated strings for use on page
$txt
=
new
object
();
$txt
->
managefilters
=
get_string
(
'managefilters'
);
$txt
->
administration
=
get_string
(
'administration'
);
$txt
->
configuration
=
get_string
(
'configuration'
);
$txt
->
name
=
get_string
(
'name'
);
$txt
->
hide
=
get_string
(
'hide'
);
$txt
->
show
=
get_string
(
'show'
);
$txt
->
hideshow
=
"
$txt->hide
/
$txt->show
"
;
$txt
->
settings
=
get_string
(
'settings'
);
$txt
->
up
=
get_string
(
'up'
);
$txt
->
down
=
get_string
(
'down'
);
$txt
->
updown
=
"
$txt->up
/
$txt->down
"
;
$txt
->
cachetext
=
get_string
(
'cachetext'
,
'admin'
);
$txt
->
configcachetext
=
get_string
(
'configcachetext'
,
'admin'
);
$txt
->
filteruploadedfiles
=
get_string
(
'filteruploadedfiles'
,
'admin'
);
$txt
->
configfilteruploadedfiles
=
get_string
(
'configfilteruploadedfiles'
,
'admin'
);
$txt
->
filterall
=
get_string
(
'filterall'
,
'admin'
);
$txt
->
filtermatchoneperpage
=
get_string
(
'filtermatchoneperpage'
,
'admin'
);
$txt
->
filtermatchonepertext
=
get_string
(
'filtermatchonepertext'
,
'admin'
);
$txt
->
configfilterall
=
get_string
(
'configfilterall'
,
'admin'
);
$txt
->
configfiltermatchoneperpage
=
get_string
(
'configfiltermatchoneperpage'
,
'admin'
);
$txt
->
configfiltermatchonepertext
=
get_string
(
'configfiltermatchonepertext'
,
'admin'
);
$txt
->
cachecontrols
=
get_string
(
'cachecontrols'
);
$txt
->
yes
=
get_string
(
'yes'
);
$txt
->
no
=
get_string
(
'no'
);
$txt
->
none
=
get_string
(
'none'
);
$txt
->
allfiles
=
get_string
(
'allfiles'
);
$txt
->
htmlfilesonly
=
get_string
(
'htmlfilesonly'
);
if
(
!
confirm_sesskey
())
{
redirect
(
$returnurl
);
}
// get a list of possible filters (and translate name if possible)
// note filters can be in the dedicated filters area OR in their
// associated modules
// get a list of installed filters
$installedfilters
=
array
();
$filtersettings
=
array
();
$filterlocations
=
array
(
'mod'
,
'filter'
);
foreach
(
$filterlocations
as
$filterlocation
)
{
$plugins
=
get_list_of_plugins
(
$filterlocation
);
foreach
(
$plugins
as
$plugin
)
{
$pluginpath
=
"
$CFG->dirroot
/
$filterlocation
/
$plugin
/filter.php"
;
$settingspath
=
"
$CFG->dirroot
/
$filterlocation
/
$plugin
/filterconfig.html"
;
if
(
is_readable
(
$pluginpath
))
{
$name
=
trim
(
get_string
(
"filtername"
,
$plugin
));
if
(
empty
(
$name
)
or
(
$name
==
'[[filtername]]'
))
{
$name
=
ucfirst
(
$plugin
);
}
$installedfilters
[
"
$filterlocation
/
$plugin
"
]
=
$name
;
if
(
is_readable
(
$settingspath
))
{
$filtersettings
[]
=
"
$filterlocation
/
$plugin
"
;
}
$installedfilters
[
"
$filterlocation
/
$plugin
"
]
=
"
$filterlocation
/
$plugin
"
;
}
}
}
// get all the currently selected filters
if
(
!
empty
(
$CFG
->
textfilters
))
{
$oldactivefilters
=
explode
(
','
,
$CFG
->
textfilters
);
$oldactivefilters
=
array_unique
(
$oldactivefilters
);
$activefilters
=
explode
(
','
,
$CFG
->
textfilters
);
}
else
{
$oldactivefilters
=
array
();
}
// take this opportunity to clean up filters
$activefilters
=
array
();
foreach
(
$oldactivefilters
as
$oldactivefilter
)
{
if
(
!
empty
(
$oldactivefilter
)
and
array_key_exists
(
$oldactivefilter
,
$installedfilters
))
{
$activefilters
[]
=
$oldactivefilter
;
}
$activefilters
=
array
();
}
//======================
// Process Actions
//======================
if
(
$params
->
action
==
""
)
{
// store cleaned active filers in db
set_config
(
'textfilters'
,
implode
(
','
,
$activefilters
));
}
elseif
((
$params
->
action
==
"hide"
)
and
confirm_sesskey
())
{
$key
=
array_search
(
$params
->
filterpath
,
$activefilters
);
switch
(
$action
)
{
case
'hide'
:
$key
=
array_search
(
$filterpath
,
$activefilters
);
// check filterpath is valid
if
(
$key
===
false
)
{
// ignore it - doubleclick??