* // Returns the help text in artefact/blog/lang/[lang]/help/forms/editpost.draft.html
* get_help_icon('artefact', 'blog', 'editpost', 'draft');
* // Returns the help text in artefact/internal/lang/[lang]/help/pages/index.html
* get_help_icon('artefact', 'internal', '', '', 'index');
*
*
* @param string $plugintype the type of plugin to find help text for
* @param string $pluginname the name of the plugin to find help text for
* @param string $form the ID of the form this help icon is connected to
* @param string $element the ID of the form element this help icon is connected to
* @param string $page the page this help icon describes
* @param string $section the section this help icon describes
* @param string $title the title/label of the element this help icon is connected to
*
* @return string HTML with help icon element
*/
function get_help_icon($plugintype, $pluginname, $form, $element, $page='', $section='', $title=null) {
global $THEME;
if ($title) {
$content = get_string('helpfor', 'mahara', $title);
}
else {
$content = get_string('Help');
}
return ' '. $content . '';
}
function pieform_get_help(Pieform $form, $element) {
$plugintype = isset($element['helpplugintype']) ? $element['helpplugintype'] : $form->get_property('plugintype');
$pluginname = isset($element['helppluginname']) ? $element['helppluginname'] : $form->get_property('pluginname');
$formname = isset($element['helpformname']) ? $element['helpformname'] : $form->get_name();
return get_help_icon($plugintype, $pluginname, $formname, $element['name'], '', '', (isset($element['title']) ? $element['title'] : null));
}
/**
* Is this a page in the admin area?
*
* @return bool
*/
function in_admin_section() {
return defined('ADMIN') || defined('INSTITUTIONALADMIN') || defined('STAFF') || defined('INSTITUTIONALSTAFF') || defined('INADMINMENU');
}
/**
* Returns the entries in the standard admin menu
*
* See the function find_menu_children() in lib/web.php
* for a description of the expected array structure.
*
* @return $adminnav a data structure containing the admin navigation
*/
function admin_nav() {
$menu = array(
'adminhome' => array(
'path' => 'adminhome',
'url' => 'admin/index.php',
'title' => get_string('adminhome', 'admin'),
'weight' => 10,
'accesskey' => 'a',
),
'adminhome/home' => array(
'path' => 'adminhome/home',
'url' => 'admin/index.php',
'title' => get_string('overview'),
'weight' => 10,
),
'adminhome/registersite' => array(
'path' => 'adminhome/registersite',
'url' => 'admin/registersite.php',
'title' => get_string('register'),
'weight' => 20,
),
'configsite' => array(
'path' => 'configsite',
'url' => 'admin/site/options.php',
'title' => get_string('configsite', 'admin'),
'weight' => 20,
'accesskey' => 's',
),
'configsite/siteoptions' => array(
'path' => 'configsite/siteoptions',
'url' => 'admin/site/options.php',
'title' => get_string('siteoptions', 'admin'),
'weight' => 10,
),
'configsite/sitepages' => array(
'path' => 'configsite/sitepages',
'url' => 'admin/site/pages.php',
'title' => get_string('staticpages', 'admin'),
'weight' => 20
),
'configsite/sitemenu' => array(
'path' => 'configsite/sitemenu',
'url' => 'admin/site/menu.php',
'title' => get_string('menus', 'admin'),
'weight' => 30,
),
'configsite/networking' => array(
'path' => 'configsite/networking',
'url' => 'admin/site/networking.php',
'title' => get_string('networking', 'admin'),
'weight' => 40,
),
'configsite/sitelicenses' => array(
'path' => 'configsite/sitelicenses',
'url' => 'admin/site/licenses.php',
'title' => get_string('sitelicenses', 'admin'),
'weight' => 45,
),
'configsite/siteviews' => array(
'path' => 'configsite/siteviews',
'url' => 'admin/site/views.php',
'title' => get_string('Viewscollections', 'view'),
'weight' => 50,
),
'configsite/share' => array(
'path' => 'configsite/share',
'url' => 'admin/site/shareviews.php',
'title' => get_string('share', 'view'),
'weight' => 70,
),
'configsite/sitefiles' => array(
'path' => 'configsite/sitefiles',
'url' => 'artefact/file/sitefiles.php',
'title' => get_string('Files', 'artefact.file'),
'weight' => 80,
),
'configsite/cookieconsent' => array(
'path' => 'configsite/cookieconsent',
'url' => 'admin/site/cookieconsent.php',
'title' => get_string('cookieconsent', 'cookieconsent'),
'weight' => 90,
),
'configusers' => array(
'path' => 'configusers',
'url' => 'admin/users/search.php',
'title' => get_string('users'),
'weight' => 30,
'accesskey' => 'u',
),
'configusers/usersearch' => array(
'path' => 'configusers/usersearch',
'url' => 'admin/users/search.php',
'title' => get_string('usersearch', 'admin'),
'weight' => 10,
),
'configusers/suspendedusers' => array(
'path' => 'configusers/suspendedusers',
'url' => 'admin/users/suspended.php',
'title' => get_string('suspendeduserstitle', 'admin'),
'weight' => 15,
),
'configusers/staffusers' => array(
'path' => 'configusers/staffusers',
'url' => 'admin/users/staff.php',
'title' => get_string('sitestaff', 'admin'),
'weight' => 20,
),
'configusers/adminusers' => array(
'path' => 'configusers/adminusers',
'url' => 'admin/users/admins.php',
'title' => get_string('siteadmins', 'admin'),
'weight' => 30,
),
'configusers/exportqueue' => array(
'path' => 'configusers/exportqueue',
'url' => 'admin/users/exportqueue.php',
'title' => get_string('exportqueue', 'admin'),
'weight' => 35,
),
'configusers/adduser' => array(
'path' => 'configusers/adduser',
'url' => 'admin/users/add.php',
'title' => get_string('adduser', 'admin'),
'weight' => 40,
),
'configusers/uploadcsv' => array(
'path' => 'configusers/uploadcsv',
'url' => 'admin/users/uploadcsv.php',
'title' => get_string('uploadcsv', 'admin'),
'weight' => 50,
),
'managegroups' => array(
'path' => 'managegroups',
'url' => 'admin/groups/groups.php',
'title' => get_string('groups', 'admin'),
'accessibletitle' => get_string('administergroups', 'admin'),
'weight' => 40,
'accesskey' => 'r',
),
'managegroups/groups' => array(
'path' => 'managegroups/groups',
'url' => 'admin/groups/groups.php',
'title' => get_string('administergroups', 'admin'),
'weight' => 10,
),
'managegroups/categories' => array(
'path' => 'managegroups/categories',
'url' => 'admin/groups/groupcategories.php',
'title' => get_string('groupcategories', 'admin'),
'weight' => 20,
),
'managegroups/archives' => array(
'path' => 'managegroups/archives',
'url' => 'admin/groups/archives.php',
'title' => get_string('archivedsubmissions', 'admin'),
'weight' => 25,
),
'managegroups/uploadcsv' => array(
'path' => 'managegroups/uploadcsv',
'url' => 'admin/groups/uploadcsv.php',
'title' => get_string('uploadgroupcsv', 'admin'),
'weight' => 30,
),
'managegroups/uploadmemberscsv' => array(
'path' => 'managegroups/uploadmemberscsv',
'url' => 'admin/groups/uploadmemberscsv.php',
'title' => get_string('uploadgroupmemberscsv', 'admin'),
'weight' => 40,
),
'manageinstitutions' => array(
'path' => 'manageinstitutions',
'url' => 'admin/users/institutions.php',
'title' => get_string('Institutions', 'admin'),
'weight' => 50,
'accesskey' => 'i',
),
'manageinstitutions/institutions' => array(
'path' => 'manageinstitutions/institutions',
'url' => 'admin/users/institutions.php',
'title' => get_string('settings', 'admin'),
'weight' => 10,
),
'manageinstitutions/sitepages' => array(
'path' => 'manageinstitutions/sitepages',
'url' => 'admin/users/institutionpages.php',
'title' => get_string('staticpages', 'admin'),
'weight' => 15
),
'manageinstitutions/institutionusers' => array(
'path' => 'manageinstitutions/institutionusers',
'url' => 'admin/users/institutionusers.php',
'title' => get_string('Members', 'admin'),
'weight' => 20,
),
'manageinstitutions/institutionstaff' => array(
'path' => 'manageinstitutions/institutionstaff',
'url' => 'admin/users/institutionstaff.php',
'title' => get_string('Staff', 'admin'),
'weight' => 30,
),
'manageinstitutions/institutionadmins' => array(
'path' => 'manageinstitutions/institutionadmins',
'url' => 'admin/users/institutionadmins.php',
'title' => get_string('Admins', 'admin'),
'weight' => 40,
),
'manageinstitutions/adminnotifications' => array(
'path' => 'manageinstitutions/adminnotifications',
'url' => 'admin/users/notifications.php',
'title' => get_string('adminnotifications', 'admin'),
'weight' => 50,
),
'manageinstitutions/progressbar' => array(
'path' => 'manageinstitutions/progressbar',
'url' => 'admin/users/progressbar.php',
'title' => get_string('progressbar', 'admin'),
'weight' => 55,
),
'manageinstitutions/institutionviews' => array(
'path' => 'manageinstitutions/institutionviews',
'url' => 'view/institutionviews.php',
'title' => get_string('Viewscollections', 'view'),
'weight' => 60,
),
'manageinstitutions/share' => array(
'path' => 'manageinstitutions/share',
'url' => 'view/institutionshare.php',
'title' => get_string('share', 'view'),
'weight' => 80,
),
'manageinstitutions/institutionfiles' => array(
'path' => 'manageinstitutions/institutionfiles',
'url' => 'artefact/file/institutionfiles.php',
'title' => get_string('Files', 'artefact.file'),
'weight' => 90,
),
'manageinstitutions/pendingregistrations' => array(
'path' => 'manageinstitutions/pendingregistrations',
'url' => 'admin/users/pendingregistrations.php',
'title' => get_string('pendingregistrations', 'admin'),
'weight' => 100,
),
'reports' => array(
'path' => 'reports',
'url' => 'admin/users/statistics.php',
'title' => get_string('reports', 'statistics'),
'weight' => 60,
),
'configextensions' => array(
'path' => 'configextensions',
'url' => 'admin/extensions/plugins.php',
'title' => get_string('Extensions', 'admin'),
'weight' => 70,
'accesskey' => 'e',
),
'configextensions/pluginadmin' => array(
'path' => 'configextensions/pluginadmin',
'url' => 'admin/extensions/plugins.php',
'title' => get_string('pluginadmin', 'admin'),
'weight' => 10,
),
'configextensions/filters' => array(
'path' => 'configextensions/filters',
'url' => 'admin/extensions/filter.php',
'title' => get_string('htmlfilters', 'admin'),
'weight' => 20,
),
'configextensions/iframesites' => array(
'path' => 'configextensions/iframesites',
'url' => 'admin/extensions/iframesites.php',
'title' => get_string('allowediframesites', 'admin'),
'weight' => 30,
),
'configextensions/cleanurls' => array(
'path' => 'configextensions/cleanurls',
'url' => 'admin/extensions/cleanurls.php',
'title' => get_string('cleanurls', 'admin'),
'weight' => 40,
),
);
// Add the menu items for skins, if that feature is enabled
if (get_config('skins')) {
$menu['configsite/siteskins'] = array(
'path' => 'configsite/siteskins',
'url' => 'admin/site/skins.php',
'title' => get_string('siteskinmenu', 'skin'),
'weight' => 75,
);
$menu['configsite/sitefonts'] = array(
'path' => 'configsite/sitefonts',
'url' => 'admin/site/fonts.php',
'title' => get_string('sitefontsmenu', 'skin'),
'weight' => 76,
);
}
// enable plugins to augment the admin menu structure
foreach (array('artefact', 'interaction', 'module', 'auth') as $plugintype) {
if ($plugins = plugins_installed($plugintype)) {
foreach ($plugins as &$plugin) {
if (safe_require_plugin($plugintype, $plugin->name)) {
$plugin_menu = call_static_method(generate_class_name($plugintype,$plugin->name), 'admin_menu_items');
$menu = array_merge($menu, $plugin_menu);
}
}
}
}
return $menu;
}
/**
* Returns the entries in the standard institutional admin menu
*
* See the function find_menu_children() in lib/web.php
* for a description of the expected array structure.
*
* @return $adminnav a data structure containing the admin navigation
*/
function institutional_admin_nav() {
global $USER;
$ret = array(
'configusers' => array(
'path' => 'configusers',
'url' => 'admin/users/search.php',
'title' => get_string('users'),
'weight' => 10,
'accesskey' => 'u',
),
'configusers/usersearch' => array(
'path' => 'configusers/usersearch',
'url' => 'admin/users/search.php',
'title' => get_string('usersearch', 'admin'),
'weight' => 10,
),
'configusers/suspendedusers' => array(
'path' => 'configusers/suspendedusers',
'url' => 'admin/users/suspended.php',
'title' => get_string('suspendeduserstitle', 'admin'),
'weight' => 20,
),
'configusers/exportqueue' => array(
'path' => 'configusers/exportqueue',
'url' => 'admin/users/exportqueue.php',
'title' => get_string('exportqueue', 'admin'),
'weight' => 25,
),
'configusers/adduser' => array(
'path' => 'configusers/adduser',
'url' => 'admin/users/add.php',
'title' => get_string('adduser', 'admin'),
'weight' => 30,
),
'configusers/uploadcsv' => array(
'path' => 'configusers/uploadcsv',
'url' => 'admin/users/uploadcsv.php',
'title' => get_string('uploadcsv', 'admin'),
'weight' => 40,
),
'managegroups' => array(
'path' => 'managegroups',
'url' => 'admin/groups/uploadcsv.php',
'title' => get_string('groups', 'admin'),
'accessibletitle' => get_string('administergroups', 'admin'),
'weight' => 20,
'accesskey' => 'g',
),
'managegroups/archives' => array(
'path' => 'managegroups/archives',
'url' => 'admin/groups/archives.php',
'title' => get_string('archivedsubmissions', 'admin'),
'weight' => 5,
),
'managegroups/uploadcsv' => array(
'path' => 'managegroups/uploadcsv',
'url' => 'admin/groups/uploadcsv.php',
'title' => get_string('uploadgroupcsv', 'admin'),
'weight' => 10,
),
'managegroups/uploadmemberscsv' => array(
'path' => 'managegroups/uploadmemberscsv',
'url' => 'admin/groups/uploadmemberscsv.php',
'title' => get_string('uploadgroupmemberscsv', 'admin'),
'weight' => 20,
),
'manageinstitutions' => array(
'path' => 'manageinstitutions',
'url' => 'admin/users/institutions.php',
'title' => get_string('Institutions', 'admin'),
'weight' => 30,
'accesskey' => 'i',
),
'manageinstitutions/institutions' => array(
'path' => 'manageinstitutions/institutions',
'url' => 'admin/users/institutions.php',
'title' => get_string('settings'),
'weight' => 10,
),
'manageinstitutions/sitepages' => array(
'path' => 'manageinstitutions/sitepages',
'url' => 'admin/users/institutionpages.php',
'title' => get_string('staticpages', 'admin'),
'weight' => 15
),
'manageinstitutions/institutionusers' => array(
'path' => 'manageinstitutions/institutionusers',
'url' => 'admin/users/institutionusers.php',
'title' => get_string('Members', 'admin'),
'weight' => 20,
),
'manageinstitutions/institutionstaff' => array(
'path' => 'manageinstitutions/institutionstaff',
'url' => 'admin/users/institutionstaff.php',
'title' => get_string('Staff', 'admin'),
'weight' => 30,
),
'manageinstitutions/institutionadmins' => array(
'path' => 'manageinstitutions/institutionadmins',
'url' => 'admin/users/institutionadmins.php',
'title' => get_string('Admins', 'admin'),
'weight' => 40,
),
'manageinstitutions/adminnotifications' => array(
'path' => 'manageinstitutions/adminnotifications',
'url' => 'admin/users/notifications.php',
'title' => get_string('adminnotifications', 'admin'),
'weight' => 50,
),
'manageinstitutions/institutionviews' => array(
'path' => 'manageinstitutions/institutionviews',
'url' => 'view/institutionviews.php',
'title' => get_string('Viewscollections', 'view'),
'weight' => 60,
),
'manageinstitutions/share' => array(
'path' => 'manageinstitutions/share',
'url' => 'view/institutionshare.php',
'title' => get_string('share', 'view'),
'weight' => 80,
),
'manageinstitutions/institutionfiles' => array(
'path' => 'manageinstitutions/institutionfiles',
'url' => 'artefact/file/institutionfiles.php',
'title' => get_string('Files', 'artefact.file'),
'weight' => 90,
),
'manageinstitutions/pendingregistrations' => array(
'path' => 'manageinstitutions/pendingregistrations',
'url' => 'admin/users/pendingregistrations.php',
'title' => get_string('pendingregistrations', 'admin'),
'weight' => 100,
),
'reports' => array(
'path' => 'reports',
'url' => 'admin/users/statistics.php',
'title' => get_string('reports', 'statistics'),
'weight' => 40,
),
);
// enable plugins to augment the institution admin menu structure
foreach (array('artefact', 'interaction', 'module', 'auth') as $plugintype) {
if ($plugins = plugins_installed($plugintype)) {
foreach ($plugins as &$plugin) {
if (safe_require_plugin($plugintype, $plugin->name)) {
$plugin_menu = call_static_method(generate_class_name($plugintype,$plugin->name), 'institution_menu_items');
$ret = array_merge($ret, $plugin_menu);
}
}
}
}
return $ret;
}
/**
* Returns the entries in the staff menu
*
* See the function find_menu_children() in lib/web.php
* for a description of the expected array structure.
*
* @return a data structure containing the staff navigation
*/
function staff_nav() {
$menu = array(
'usersearch' => array(
'path' => 'usersearch',
'url' => 'admin/users/search.php',
'title' => get_string('usersearch', 'admin'),
'weight' => 10,
'accesskey' => 'u',
),
'reports' => array(
'path' => 'reports',
'url' => 'admin/users/statistics.php',
'title' => get_string('reports', 'statistics'),
'weight' => 30,
'accesskey' => 'i',
),
);
// enable plugins to augment the institution staff menu structure
foreach (array('artefact', 'interaction', 'module', 'auth') as $plugintype) {
if ($plugins = plugins_installed($plugintype)) {
foreach ($plugins as &$plugin) {
if (safe_require_plugin($plugintype, $plugin->name)) {
$plugin_menu = call_static_method(generate_class_name($plugintype,$plugin->name), 'institution_staff_menu_items');
$menu = array_merge($menu, $plugin_menu);
}
}
}
}
return $menu;
}
/**
* Returns the entries in the institutional staff menu
*
* See the function find_menu_children() in lib/web.php
* for a description of the expected array structure.
*
* @return a data structure containing the institutional staff navigation
*/
function institutional_staff_nav() {
return array(
'usersearch' => array(
'path' => 'usersearch',
'url' => 'admin/users/search.php',
'title' => get_string('usersearch', 'admin'),
'weight' => 10,
'accesskey' => 'u',
),
'reports' => array(
'path' => 'reports',
'url' => 'admin/users/statistics.php',
'title' => get_string('reports', 'statistics'),
'weight' => 20,
'accesskey' => 'i',
),
);
}
/**
* Returns the entries in the standard user menu
*
* See the function find_menu_children() in lib/web.php
* for a description of the expected array structure.
*
* @return $standardnav a data structure containing the standard navigation
*/
function mahara_standard_nav() {
global $SESSION;
$exportenabled = (plugins_installed('export') && !$SESSION->get('handheld_device')) ? TRUE : FALSE;
$importenabled = (plugins_installed('import') && !$SESSION->get('handheld_device')) ? TRUE : FALSE;
$menu = array(
'home' => array(
'path' => 'home',
'url' => '',
'title' => get_string('dashboard', 'view'),
'weight' => 10,
'accesskey' => 'd',
),
'content' => array(
'path' => 'content',
'url' => 'artefact/internal/index.php', // @todo possibly do path aliasing and dispatch?
'title' => get_string('Content'),
'weight' => 20,
'accesskey' => 'c',
),
'myportfolio' => array(
'path' => 'myportfolio',
'url' => 'view/index.php',
'title' => get_string('myportfolio'),
'weight' => 30,
'accesskey' => 'p',
),
'myportfolio/views' => array(
'path' => 'myportfolio/views',
'url' => 'view/index.php',
'title' => get_string('Viewscollections', 'view'),
'weight' => 10,
),
'myportfolio/share' => array(
'path' => 'myportfolio/share',
'url' => 'view/share.php',
'title' => get_string('sharedbyme', 'view'),
'weight' => 30,
),
'myportfolio/sharedviews' => array(
'path' => 'myportfolio/sharedviews',
'url' => 'view/sharedviews.php',
'title' => get_string('sharedwithme', 'view'),
'weight' => 60,
),
'myportfolio/export' => array(
'path' => 'myportfolio/export',
'url' => 'export/index.php',
'title' => get_string('Export', 'export'),
'weight' => 70,
'ignore' => !$exportenabled,
),
'myportfolio/import' => array(
'path' => 'myportfolio/import',
'url' => 'import/index.php',
'title' => get_string('Import', 'import'),
'weight' => 80,
'ignore' => !$importenabled,
),
'groups' => array(
'path' => 'groups',
'url' => 'group/mygroups.php',
'title' => get_string('groups'),
'weight' => 40,
'accesskey' => 'g',
),
'groups/mygroups' => array(
'path' => 'groups/mygroups',
'url' => 'group/mygroups.php',
'title' => get_string('mygroups'),
'weight' => 10,
),
'groups/find' => array(
'path' => 'groups/find',
'url' => 'group/find.php',
'title' => get_string('findgroups'),
'weight' => 20,
),
'groups/myfriends' => array(
'path' => 'groups/myfriends',
'url' => 'user/myfriends.php',
'title' => get_string('myfriends'),
'weight' => 30,
),
'groups/findfriends' => array(
'path' => 'groups/findfriends',
'url' => 'user/find.php',
'title' => get_string('findpeople'),
'weight' => 40,
),
'groups/institutionmembership' => array(
'path' => 'groups/institutions',
'url' => 'account/institutions.php',
'title' => get_string('institutionmembership'),
'weight' => 50,
),
);
if (can_use_skins()) {
$menu['myportfolio/skins'] = array(
'path' => 'myportfolio/skins',
'url' => 'skin/index.php',
'title' => get_string('myskins', 'skin'),
'weight' => 65,
);
}
return $menu;
}
/**
* Builds a data structure representing the menu for Mahara.
*
* @return array
*/
function main_nav($type = null) {
global $USER;
$language = current_language();
$cachemenu = false;
// Get the first institution
$institution = $USER->get_primary_institution();
$menutype = '';
if ($type == 'adminnav') {
global $USER, $SESSION;
if ($USER->get('admin')) {
$menutype = 'admin_nav';
if (!($cachemenu = get_config_institution($institution, $menutype . '_' . $language))) {
$menu = admin_nav();
}
}
else if ($USER->get('staff')) {
$menutype = 'staff_nav';
if (!($cachemenu = get_config_institution($institution, $menutype . '_' . $language))) {
$menu = staff_nav();
}
}
else if ($USER->is_institutional_admin()) {
$menutype = 'instadmin_nav';
if (!($cachemenu = get_config_institution($institution, $menutype . '_' . $language))) {
$menu = institutional_admin_nav();
}
}
else {
$menutype = 'inststaff_nav';
if (!($cachemenu = get_config_institution($institution, $menutype . '_' . $language))) {
$menu = institutional_staff_nav();
}
}
}
else {
// Build the menu structure for the site
$menutype = 'standard_nav';
if (!($cachemenu = get_config_institution($institution, $menutype . '_' . $language))) {
$menu = mahara_standard_nav();
}
}
if ($cachemenu) {
$menu = json_decode($cachemenu, true);
}
else {
$menu = array_filter($menu, create_function('$a', 'return empty($a["ignore"]);'));
// enable plugins to augment the menu structure
foreach (array('artefact', 'interaction', 'module', 'auth') as $plugintype) {
if ($plugins = plugins_installed($plugintype)) {
foreach ($plugins as &$plugin) {
if (safe_require_plugin($plugintype, $plugin->name)) {
$plugin_menu = call_static_method(generate_class_name($plugintype,$plugin->name), 'menu_items');
$menu = array_merge($menu, $plugin_menu);
}
}
}
}
set_config_institution($institution, $menutype . '_' . $language, json_encode($menu));
}
// local_main_nav_update allows sites to customise the menu by munging the $menu array.
// as there is no internal way to know if the local_main_nav array has changed we keep it outside the cached menu
if (function_exists('local_main_nav_update')) {
local_main_nav_update($menu);
}
$menu_structure = find_menu_children($menu, '');
return $menu_structure;
}
/**
* Clear the cached menu so that the next visit to the site will recreate the cache.
*
* @param string $institution Optional institution name if we only want to delete cache from a certain institution
*/
function clear_menu_cache($institution = null) {
if ($institution) {
try {
delete_records_sql("DELETE FROM {institution_config} WHERE field LIKE '%/_nav/_%' ESCAPE '/' AND institution = ?", array($institution));
}
catch (SQLException $e) {
// Institution_config table may not exist on install/upgrade at this point
}
}
else {
try {
delete_records_sql("DELETE FROM {institution_config} WHERE field LIKE '%/_nav/_%' ESCAPE '/'", array());
}
catch (SQLException $e) {
// Institution_config table may not exist on install/upgrade at this point
}
}
}
function right_nav() {
global $USER, $THEME;
safe_require('notification', 'internal');
$unread = $USER->get('unread');
$menu = array(
'settings' => array(
'path' => 'settings',
'url' => 'account/index.php',
'title' => get_string('settings'),
'alt' => '',
'weight' => 10,
'iconclass' => 'cogs'
),
'inbox' => array(
'path' => 'inbox',
'url' => 'account/activity/index.php',
'title' => get_string('inbox'),
'alt' => get_string('inbox'),
'count' => $unread,
'countclass' => 'unreadmessagecount',
'linkid' => 'mail',
'weight' => 20,
'iconclass' => 'envelope'
),
'settings/account' => array(
'path' => 'settings/account',
'url' => 'account/index.php',
'title' => get_config('dropdownmenu') ? get_string('general') : get_string('account'),
'weight' => 10,
'iconclass' => 'user'
),
'settings/notifications' => array(
'path' => 'settings/notifications',
'url' => 'account/activity/preferences/index.php',
'title' => get_string('notifications'),
'weight' => 30,
'iconclass' => 'flag'
),
);
// enable plugins to augment the menu structure
foreach (array('artefact', 'interaction', 'module') as $plugintype) {
if ($plugins = plugins_installed($plugintype)) {
foreach ($plugins as &$plugin) {
if (safe_require_plugin($plugintype, $plugin->name)) {
$plugin_nav_menu = call_static_method(generate_class_name($plugintype, $plugin->name),
'right_nav_menu_items');
$menu = array_merge($menu, $plugin_nav_menu);
}
}
}
}
// local_right_nav_update allows sites to customise the menu by munging the $menu array.
if (function_exists('local_right_nav_update')) {
local_right_nav_update($menu);
}
$menu_structure = find_menu_children($menu, '');
return $menu_structure;
}
function footer_menu($all=false) {
$wwwroot = get_config('wwwroot');
$menu = array(
'termsandconditions' => array(
'url' => $wwwroot . 'terms.php',
'title' => get_string('termsandconditions'),
),
'privacystatement' => array(
'url' => $wwwroot . 'privacy.php',
'title' => get_string('privacystatement'),
),
'about' => array(
'url' => $wwwroot . 'about.php',
'title' => get_string('about'),
),
'contactus' => array(
'url' => $wwwroot . 'contact.php',
'title' => get_string('contactus'),
),
);
if ($all) {
return $menu;
}
if ($enabled = get_config('footerlinks')) {
$enabled = unserialize($enabled);
foreach ($menu as $k => $v) {
if (!in_array($k, $enabled)) {
unset($menu[$k]);
}
}
}
if ($customlinks = get_config('footercustomlinks')) {
$customlinks = unserialize($customlinks);
foreach ($customlinks as $k => $v) {
if (!empty($menu[$k])) {
$menu[$k]['url'] = $v;
}
}
}
return $menu;
}
/**
* Given a menu structure and a path, returns a data structure representing all
* of the child menu items of the path, and removes those items from the menu
* structure
*
* The menu structure should be an array. Each item in the array should be
* a sub-array representing one of the nodes in the menu.
*
* The keys of each menu node are as follows:
* path: Where the link sits in the menu. E.g. 'myporfolio/myplugin'
* parent: (optional) The parent path - use if tertiary level menu
* url: The URL to the page, relative to wwwroot. E.g. 'artefact/myplugin/'
* title: Translated text to use for the text of the link. E.g. get_string('myplugin', 'artefact.myplugin')
* weight: Where in the menu the item should be inserted. Larger number are to the right.
*
* Used by main_nav()
*/
function find_menu_children(&$menu, $path) {
global $SELECTEDSUBNAV;
$result = array();
if (!$menu) {
return array();
}
foreach ($menu as $key => $item) {
$item['selected'] = defined('MENUITEM')
&& ($item['path'] == MENUITEM
|| ($item['path'] . '/' == substr(MENUITEM, 0, strlen($item['path'])+1))
|| (!empty($item['parent']) && $item['parent'] == MENUITEM));
if (
($path == '' && $item['path'] == '') ||
($item['path'] != '' && substr($item['path'], 0, strlen($path)) == $path && !preg_match('%/%', substr($item['path'], strlen($path) + 1)))) {
$result[] = $item;
unset($menu[$key]);
}
}
if ($menu) {
foreach ($result as &$item) {
$item['submenu'] = find_menu_children($menu, $item['path']);
if ($item['selected']) {
$SELECTEDSUBNAV = $item['submenu'];
}
}
}
uasort($result, 'menu_sort_items');
return $result;
}
/**
* Comparison function for sorting menu items
*/
function menu_sort_items(&$a, &$b) {
!isset($a['weight']) && $a['weight'] = 0;
!isset($b['weight']) && $b['weight'] = 0;
return $a['weight'] > $b['weight'];
}
/**
* Site-level sidebar menu (list of links)
* There is no admin files table yet so just get the urls.
* @return $menu a data structure containing the site menu
*/
function site_menu() {
global $USER;
$menu = array();
if ($menuitems = get_records_array('site_menu','public',(int) !$USER->is_logged_in(),'displayorder')) {
foreach ($menuitems as $i) {
if ($i->url) {
$safeurl = sanitize_url($i->url);
if ($safeurl != '') {
$menu[] = array('name' => $i->title,
'link' => $safeurl);
}
}
else if ($i->file) {
$menu[] = array('name' => $i->title,
'link' => get_config('wwwroot') . 'artefact/file/download.php?file=' . $i->file);
}
}
}
return $menu;
}
/**
* Returns the list of site content pages
* @return array of names
*/
function site_content_pages() {
return array('about', 'home', 'loggedouthome', 'termsandconditions');
}
/**
* Returns the list of site versioned content pages
* @return array of names
*/
function site_content_version_pages() {
return array('privacy');
}
function get_site_page_content($pagename) {
global $USER;
$institution = $USER->sitepages_institutionname_by_theme($pagename);
// try to get the content for this institution and if it fails try to get default site information
// first check to see if the db upgrade has been run so the institution column exists
if (get_config('version') >= '2014010801') {
if ($pagedata = get_record('site_content', 'name', $pagename, 'institution', $institution)) {
return $pagedata->content;
}
else if ($defaultpagedata = get_record('site_content', 'name', $pagename, 'institution', 'mahara')) {
return $defaultpagedata->content;
}
return get_string('sitecontentnotfound', 'mahara', get_string($pagename, $institution));
}
else {
if ($pagedata = get_record('site_content', 'name', $pagename)) {
return $pagedata->content;
}
}
return get_string('sitecontentnotfound', 'mahara', get_string($pagename));
}
/**
* Redirects the browser to a new location. The path to redirect to can take
* two forms:
*
* - http[something]: will redirect the user to that exact URL
* - /[something]: will redirect to WWWROOT/[something]
*
* Any other form is illegal and will cause an error.
*
* @param string $location The location to redirect the user to. Defaults to
* the application home page.
*/
function redirect($location='/') {
$file = $line = null;
if (headers_sent($file, $line)) {
throw new SystemException("Headers already sent when redirect() was called (output started in $file on line $line");
}
if (substr($location, 0, 4) != 'http') {
if (substr($location, 0, 1) != '/') {
throw new SystemException('redirect() should be called with either'
. ' /[something] for local redirects or http[something] for'
. ' absolute redirects');
}
$location = get_config('wwwroot') . substr($location, 1);
}
header('HTTP/1.1 303 See Other');
header('Location:' . $location);
perf_to_log();
exit;
}
/**
* Returns a string, HTML escaped
*
* @param string $text The text to escape
* @return string The text, HTML escaped
*/
function hsc ($text) {
return htmlspecialchars($text, ENT_COMPAT, 'UTF-8');
}
/**
* Builds the pieform for the search field in the page header
*/
function header_search_form() {
$plugin = get_config('searchplugin');
safe_require('search', $plugin);
return call_static_method(
generate_class_name('search', $plugin),
'header_search_form'
);
}
/**
* Returns the name of the current script, WITH the querystring portion.
* this function is necessary because PHP_SELF and REQUEST_URI and SCRIPT_NAME
* return different things depending on a lot of things like your OS, Web
* server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.)
* NOTE: This function returns false if the global variables needed are not set.
*
* @return string
*/
function get_script_path() {
if (!empty($_SERVER['REQUEST_URI'])) {
return $_SERVER['REQUEST_URI'];
} else if (!empty($_SERVER['PHP_SELF'])) {
if (!empty($_SERVER['QUERY_STRING'])) {
return $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
}
return $_SERVER['PHP_SELF'];
} else if (!empty($_SERVER['SCRIPT_NAME'])) {
if (!empty($_SERVER['QUERY_STRING'])) {
return $_SERVER['SCRIPT_NAME'] .'?'. $_SERVER['QUERY_STRING'];
}
return $_SERVER['SCRIPT_NAME'];
} else if (!empty($_SERVER['URL'])) { // May help IIS (not well tested)
if (!empty($_SERVER['QUERY_STRING'])) {
return $_SERVER['URL'] .'?'. $_SERVER['QUERY_STRING'];
}
return $_SERVER['URL'];
}
else {
log_warn('Warning: Could not find any of these web server variables: $REQUEST_URI, $PHP_SELF, $SCRIPT_NAME or $URL');
return false;
}
}
/**
* Get the requested servername in preference to the host in the configured
* wwwroot. Usually the same unless some parts of the site are at subdomains.
*
* @return string
*/
function get_requested_host_name() {
global $CFG;
$hostname = false;
if (false === $hostname && !empty($_SERVER['SERVER_NAME'])) {
$hostname = $_SERVER['SERVER_NAME'];
}
if (false === $hostname && !empty($_ENV['SERVER_NAME'])) {
$hostname = $_ENV['SERVER_NAME'];
}
if (false === $hostname && !empty($_SERVER['HTTP_HOST'])) {
$hostname = $_SERVER['HTTP_HOST'];
}
if (false === $hostname && !empty($_ENV['HTTP_HOST'])) {
$hostname = $_ENV['HTTP_HOST'];
}
if (false === $hostname && !empty($CFG->wwwroot)) {
$url = parse_url($CFG->wwwroot);
if (!empty($url['host'])) {
$hostname = $url['host'];
}
}
if (false === $hostname) {
log_warn('Warning: could not find the name of this server!');
return false;
}
else {
$hostname = strtolower($hostname);
// Because the hostname can be user provided data (from the HTTP request), we
// should whitelist it.
if (!preg_match(
'/^([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])(\\.([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9]))*$/',
$hostname
)
) {
log_warn('Warning: invalid hostname found in get_requested_host_name.');
return false;
}
return $hostname;
}
}
/**
* Like {@link get_script_path()} but returns a full URL
* @see get_script_path()
* @return string
*/
function get_full_script_path() {
global $CFG;
if (!empty($CFG->wwwroot)) {
$url = parse_url($CFG->wwwroot);
}
if (!$hostname = get_requested_host_name()) {
return false;
}
if (!empty($url['port'])) {
$hostname .= ':'.$url['port'];
} else if (!empty($_SERVER['SERVER_PORT'])) {
// SSL proxy could be on a random port and we don't want it to appear in URL.
if (get_config('sslproxy')) {
$_SERVER['SERVER_PORT'] = '443';
}
if ($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
$hostname .= ':'.$_SERVER['SERVER_PORT'];
}
}
if (isset($_SERVER['HTTPS'])) {
$protocol = ($_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
}
else if (isset($_SERVER['SERVER_PORT'])) { # Apache2 does not export $_SERVER['HTTPS']
$protocol = ($_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';
}
else {
$protocol = 'http://';
}
$url_prefix = $protocol.$hostname;
return $url_prefix . get_script_path();
}
/**
* Like {@link get_script_path()} but returns a URI relative to WWWROOT
* @see get_script_path()
* @return string
*/
function get_relative_script_path() {
$maharadir = get_mahara_install_subdirectory();
// $maharadir always has a trailing '/'
return substr(get_script_path(), strlen($maharadir) - 1);
}
/**
* Get query string from url
*
* Takes in a URL and returns the querystring portion
* or returns $_SERVER['QUERY_STRING']) if set
*
* @param string $url the url which may have a query string attached
* @return string
*/
function get_querystring($url = null) {
if (!empty($url) && $commapos = strpos($url, '?')) {
return substr($url, $commapos + 1);
}
else if (!empty($_SERVER['QUERY_STRING'])) {
return $_SERVER['QUERY_STRING'];
}
else {
return '';
}
}
/**
* Remove query string from url
*
* Takes in a URL and returns it without the querystring portion
*
* @param string $url the url which may have a query string attached
* @return string
*/
function strip_querystring($url) {
if ($commapos = strpos($url, '?')) {
return substr($url, 0, $commapos);
}
else {
return $url;
}
}
function has_page_help() {
$pt = defined('SECTION_PLUGINTYPE') ? SECTION_PLUGINTYPE : null;
$pn = defined('SECTION_PLUGINNAME') ? SECTION_PLUGINNAME : null;
$sp = defined('SECTION_PAGE') ? SECTION_PAGE : null;
if (empty($pt) || ($pt != 'core' && empty($pn))) {
// we can't have a plugin type but no plugin name
return false;
}
if (in_array($pt, plugin_types())) {
$pagehelp = get_config('docroot') . $pt . '/' . $pn . '/lang/en.utf8/help/pages/' . $sp . '.html';
}
else {
$pagehelp = get_config('docroot') . 'lang/en.utf8/help/pages/' . $pn . '/' . $sp . '.html';
}
if (is_readable($pagehelp)) {
return array($sp, get_help_icon($pt, $pn, '', '', $sp));
}
return false;
}
//
// Cleaning/formatting functions
//
/**
* Given some plain text, adds the appropriate HTML to it to make it appear in
* an HTML document with the same formatting
*
* This includes escaping entities, replacing newlines etc. It is not
* particularly intelligent about paragraphs, it just adds . * * This version is appropriate for use on HTML. See str_shorten_text() for use * on text strings. * * @param string $str The string to shorten * @param int $maxlen The maximum length the new string should be (default 100) * @param bool $truncate If true, cut the string at the end rather than in the middle (default false) * @param bool $newlines If false, cut off after the first newline (default true) * @param bool $usenl2br if false, only do HTML-escapes (default true) * @return string */ function str_shorten_html($str, $maxlen=100, $truncate=false, $newlines=true, $usenl2br=true) { if (empty($str)) { return $str; } if (!$newlines) { $nextbreak = strpos($str, '
$str = $str[0] . str_replace('
$maxlen) { $str = mb_substr($str, 0, $maxlen-3, 'UTF-8') . '...'; } if (mb_strlen($str, 'UTF-8') > $maxlen) { $str = mb_substr($str, 0, floor($maxlen / 2) - 1, 'UTF-8') . '...' . mb_substr($str, -(floor($maxlen / 2) - 2), mb_strlen($str, 'UTF-8'), 'UTF-8'); } } else { if ($truncate && strlen($str) > $maxlen) { $str = substr($str, 0, $maxlen-3) . '...'; } if (strlen($str) > $maxlen) { $str = substr($str, 0, floor($maxlen / 2) - 1) . '...' . substr($str, -(floor($maxlen / 2) - 2), strlen($str)); } } $str = hsc($str); if ($usenl2br) { $str = nl2br($str); } // this should be ok, because the string gets checked before going into the database $str = str_replace('&', '&', $str); return $str; } /** * Takes a string and a length, and ensures that the string is no longer than * this length, by putting '...' in it somewhere. * * This version is appropriate for use on plain text. See str_shorten_html() * for use on HTML strings. * * @param string $str The string to shorten * @param int $maxlen The maximum length the new string should be (default 100) * @param bool $truncate If true, cut the string at the end rather than in the middle (default false) * @return string */ function str_shorten_text($str, $maxlen=100, $truncate=false) { if (function_exists('mb_substr')) { if (mb_strlen($str, 'UTF-8') > $maxlen) { if ($truncate) { return mb_substr($str, 0, $maxlen - 3, 'UTF-8') . '...'; } return mb_substr($str, 0, floor($maxlen / 2) - 1, 'UTF-8') . '...' . mb_substr($str, -(floor($maxlen / 2) - 2), mb_strlen($str, 'UTF-8'), 'UTF-8'); } return $str; } if (strlen($str) > $maxlen) { if ($truncate) { return substr($str, 0, $maxlen - 3) . '...'; } return substr($str, 0, floor($maxlen / 2) - 1) . '...' . substr($str, -(floor($maxlen / 2) - 2)); } return $str; } /** * Builds pagination links for HTML display. * * The pagination is quite configurable, but at the same time gives a consistent * look and feel to all pagination. * * This function takes one array that contains the options to configure the * pagination. Required options include: * * - url: The base URL to use for all links (it should not contain special characters) * - count: The total number of results to paginate for * - setlimit: toggle variable for enabling/disabling limit dropbox, default value = false * - limit: How many to show per page * - offset: At which result to start showing results * * Optional options include: * * - id: The ID of the div enclosing the pagination * - class: The class of the div enclosing the pagination * - offsetname: The name of the offset parameter in the url * - firsttext: The text to use for the 'first page' link * - previoustext: The text to use for the 'previous page' link * - nexttext: The text to use for the 'next page' link * - lasttext: The text to use for the 'last page' link * - numbersincludefirstlast: Whether the page numbering should include links * for the first and last pages * - numbersincludeprevnext: The number of pagelinks, adjacent the the current page, * to include per side * - jumplinks: The maximum number of page jump links to have between first- and current-, and current- and last page * - resultcounttextsingular: The text to use for 'result' * - resultcounttextplural: The text to use for 'results' * - limittext: The text to use for the limitoption, e.g. "Max items per page" or "Page size" * * Optional options to support javascript pagination include: * * - datatable: The ID of the table whose TBODY's rows will be replaced with the * resulting rows * - jsonscript: The script to make a json request to in order to retrieve * both the new rows and the new pagination. See js/artefactchooser.json.php * for an example. Note that the paginator javascript library is NOT * automatically included just because you call this function, so make sure * that your smarty() call hooks it in. * * @param array $params Options for the pagination */ function build_pagination($params) { $limitoptions = array(1, 10, 20, 50, 100, 500); // Bail if the required attributes are not present $required = array('url', 'count', 'limit', 'offset'); foreach ($required as $option) { if (!isset($params[$option])) { throw new ParameterException('You must supply option "' . $option . '" to build_pagination'); } } if (isset($params['setlimit']) && $params['setlimit']) { if (!in_array($params['limit'], $limitoptions)) { $params['limit'] = 10; } if (!isset($params['limittext'])) { $params['limittext'] = get_string('maxitemsperpage1'); } } else { $params['setlimit'] = false; } // Work out default values for parameters if (!isset($params['id'])) { $params['id'] = substr(md5(microtime()), 0, 4); } $params['offsetname'] = (isset($params['offsetname'])) ? $params['offsetname'] : 'offset'; if (isset($params['forceoffset']) && !is_null($params['forceoffset'])) { $params['offset'] = (int) $params['forceoffset']; } else if (!isset($params['offset'])) { $params['offset'] = param_integer($params['offsetname'], 0); } // Correct for odd offsets if ($params['limit']) { $params['offset'] -= $params['offset'] % $params['limit']; } $params['firsttext'] = (isset($params['firsttext'])) ? $params['firsttext'] : get_string('first'); $params['previoustext'] = (isset($params['previoustext'])) ? $params['previoustext'] : get_string('previous'); $params['nexttext'] = (isset($params['nexttext'])) ? $params['nexttext'] : get_string('next'); $params['lasttext'] = (isset($params['lasttext'])) ? $params['lasttext'] : get_string('last'); $params['resultcounttextsingular'] = (isset($params['resultcounttextsingular'])) ? $params['resultcounttextsingular'] : get_string('result'); $params['resultcounttextplural'] = (isset($params['resultcounttextplural'])) ? $params['resultcounttextplural'] : get_string('results'); if (!isset($params['numbersincludefirstlast'])) { $params['numbersincludefirstlast'] = true; } if (!isset($params['numbersincludeprevnext'])) { $params['numbersincludeprevnext'] = 1; } else { $params['numbersincludeprevnext'] = (int) $params['numbersincludeprevnext']; } if (!isset($params['extradata'])) { $params['extradata'] = null; } // Begin building the output $output = '