first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,100 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package theme_boost
* @copyright 2016 Ryan Wyllie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* @package theme_boost
* @copyright 2016 Ryan Wyllie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class theme_boost_admin_settingspage_tabs extends admin_settingpage {
/** @var The tabs */
protected $tabs = array();
/**
* Add a tab.
*
* @param admin_settingpage $tab A tab.
*/
public function add_tab(admin_settingpage $tab) {
foreach ($tab->settings as $setting) {
$this->settings->{$setting->name} = $setting;
}
$this->tabs[] = $tab;
return true;
}
public function add($tab) {
return $this->add_tab($tab);
}
/**
* Get tabs.
*
* @return array
*/
public function get_tabs() {
return $this->tabs;
}
/**
* Generate the HTML output.
*
* @return string
*/
public function output_html() {
global $OUTPUT;
$activetab = optional_param('activetab', '', PARAM_TEXT);
$context = array('tabs' => array());
$havesetactive = false;
foreach ($this->get_tabs() as $tab) {
$active = false;
// Default to first tab it not told otherwise.
if (empty($activetab) && !$havesetactive) {
$active = true;
$havesetactive = true;
} else if ($activetab === $tab->name) {
$active = true;
}
$context['tabs'][] = array(
'name' => $tab->name,
'displayname' => $tab->visiblename,
'html' => $tab->output_html(),
'active' => $active,
);
}
if (empty($context['tabs'])) {
return '';
}
return $OUTPUT->render_from_template('theme_boost/admin_setting_tabs', $context);
}
}
+252
View File
@@ -0,0 +1,252 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Autoprefixer.
*
* This autoprefixer has been developed to satisfy the basic needs of the
* theme Boost when working with Bootstrap 4 alpha. We do not recommend
* that this tool is shared, nor used outside of this theme.
*
* @package theme_boost
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace theme_boost;
defined('MOODLE_INTERNAL') || die();
use Sabberworm\CSS\CSSList\CSSList;
use Sabberworm\CSS\CSSList\Document;
use Sabberworm\CSS\CSSList\KeyFrame;
use Sabberworm\CSS\OutputFormat;
use Sabberworm\CSS\Parser;
use Sabberworm\CSS\Property\AtRule;
use Sabberworm\CSS\Property\Selector;
use Sabberworm\CSS\Rule\Rule;
use Sabberworm\CSS\RuleSet\AtRuleSet;
use Sabberworm\CSS\RuleSet\DeclarationBlock;
use Sabberworm\CSS\RuleSet\RuleSet;
use Sabberworm\CSS\Settings;
use Sabberworm\CSS\Value\CSSFunction;
use Sabberworm\CSS\Value\CSSString;
use Sabberworm\CSS\Value\PrimitiveValue;
use Sabberworm\CSS\Value\RuleValueList;
use Sabberworm\CSS\Value\Size;
use Sabberworm\CSS\Value\ValueList;
/**
* Autoprefixer class.
*
* Very basic implementation covering simple needs for Bootstrap 4.
*
* @package theme_boost
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class autoprefixer {
/** @var object The CSS tree. */
protected $tree;
/** @var string Pseudo classes regex. */
protected $pseudosregex;
/** @var array At rules prefixes. */
protected static $atrules = [
'keyframes' => ['-webkit-', '-o-']
];
/** @var array Pseudo classes prefixes. */
protected static $pseudos = [
'::placeholder' => ['::-webkit-input-placeholder', '::-moz-placeholder', ':-ms-input-placeholder']
];
/** @var array Rule properties prefixes. */
protected static $rules = [
'animation' => ['-webkit-'],
'appearance' => ['-webkit-', '-moz-'],
'backface-visibility' => ['-webkit-'],
'box-sizing' => ['-webkit-'],
'box-shadow' => ['-webkit-'],
'background-clip' => ['-webkit-'],
'background-size' => ['-webkit-'],
'box-shadow' => ['-webkit-'],
'column-count' => ['-webkit-', '-moz-'],
'column-gap' => ['-webkit-', '-moz-'],
'perspective' => ['-webkit-'],
'touch-action' => ['-ms-'],
'transform' => ['-webkit-', '-moz-', '-ms-', '-o-'],
'transition' => ['-webkit-', '-o-'],
'transition-timing-function' => ['-webkit-', '-o-'],
'transition-duration' => ['-webkit-', '-o-'],
'transition-property' => ['-webkit-', '-o-'],
'user-select' => ['-webkit-', '-moz-', '-ms-'],
];
/**
* Constructor.
*
* @param Document $tree The CSS tree.
*/
public function __construct(Document $tree) {
debugging('theme_boost\autoprefixer() is deprecated. Required prefixes for Bootstrap ' .
'are now in theme/boost/scss/moodle/prefixes.scss', DEBUG_DEVELOPER);
$this->tree = $tree;
$pseudos = array_map(function($pseudo) {
return '(' . preg_quote($pseudo) . ')';
}, array_keys(self::$pseudos));
$this->pseudosregex = '(' . implode('|', $pseudos) . ')';
}
/**
* Manipulate an array of rules to adapt their values.
*
* @param array $rules The rules.
* @return New array of rules.
*/
protected function manipulateRuleValues(array $rules) {
$finalrules = [];
foreach ($rules as $rule) {
$property = $rule->getRule();
$value = $rule->getValue();
if ($property === 'position' && $value === 'sticky') {
$newrule = clone $rule;
$newrule->setValue('-webkit-sticky');
$finalrules[] = $newrule;
} else if ($property === 'background-image' &&
$value instanceof CSSFunction &&
$value->getName() === 'linear-gradient') {
foreach (['-webkit-', '-o-'] as $prefix) {
$newfunction = clone $value;
$newfunction->setName($prefix . $value->getName());
$newrule = clone $rule;
$newrule->setValue($newfunction);
$finalrules[] = $newrule;
}
}
$finalrules[] = $rule;
}
return $finalrules;
}
/**
* Prefix all the things!
*/
public function prefix() {
$this->processBlock($this->tree);
}
/**
* Process block.
*
* @param object $block A block.
* @param object $parent The parent of the block.
*/
protected function processBlock($block) {
foreach ($block->getContents() as $node) {
if ($node instanceof AtRule) {
$name = $node->atRuleName();
if (isset(self::$atrules[$name])) {
foreach (self::$atrules[$name] as $prefix) {
$newname = $prefix . $name;
$newnode = clone $node;
if ($node instanceof KeyFrame) {
$newnode->setVendorKeyFrame($newname);
$block->insert($newnode, $node);
} else {
debugging('Unhandled atRule prefixing.', DEBUG_DEVELOPER);
}
}
}
}
if ($node instanceof CSSList) {
$this->processBlock($node);
} else if ($node instanceof RuleSet) {
$this->processDeclaration($node, $block);
}
}
}
/**
* Process declaration.
*
* @param object $node The declaration block.
* @param object $parent The parent.
*/
protected function processDeclaration($node, $parent) {
$rules = [];
foreach ($node->getRules() as $key => $rule) {
$name = $rule->getRule();
$seen[$name] = true;
if (!isset(self::$rules[$name])) {
$rules[] = $rule;
continue;
}
foreach (self::$rules[$name] as $prefix) {
$newname = $prefix . $name;
if (isset($seen[$newname])) {
continue;
}
$newrule = clone $rule;
$newrule->setRule($newname);
$rules[] = $newrule;
}
$rules[] = $rule;
}
$node->setRules($this->manipulateRuleValues($rules));
if ($node instanceof DeclarationBlock) {
$selectors = $node->getSelectors();
foreach ($selectors as $key => $selector) {
$matches = [];
if (preg_match($this->pseudosregex, $selector->getSelector(), $matches)) {
$newnode = clone $node;
foreach (self::$pseudos[$matches[1]] as $newpseudo) {
$newselector = new Selector(str_replace($matches[1], $newpseudo, $selector->getSelector()));
$selectors[$key] = $newselector;
$newnode = clone $node;
$newnode->setSelectors($selectors);
$parent->insert($newnode, $node);
}
// We're only expecting one affected pseudo class per block.
break;
}
}
}
}
}
+341
View File
@@ -0,0 +1,341 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace theme_boost;
use core\navigation\views\view;
use navigation_node;
use moodle_url;
use action_link;
use lang_string;
/**
* Creates a navbar for boost that allows easy control of the navbar items.
*
* @package theme_boost
* @copyright 2021 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class boostnavbar implements \renderable {
/** @var array The individual items of the navbar. */
protected $items = [];
/** @var moodle_page The current moodle page. */
protected $page;
/**
* Takes a navbar object and picks the necessary parts for display.
*
* @param \moodle_page $page The current moodle page.
*/
public function __construct(\moodle_page $page) {
$this->page = $page;
foreach ($this->page->navbar->get_items() as $item) {
$this->items[] = $item;
}
$this->prepare_nodes_for_boost();
}
/**
* Prepares the navigation nodes for use with boost.
*/
protected function prepare_nodes_for_boost(): void {
global $PAGE;
// Remove the navbar nodes that already exist in the primary navigation menu.
$this->remove_items_that_exist_in_navigation($PAGE->primarynav);
// Defines whether section items with an action should be removed by default.
$removesections = true;
if ($this->page->context->contextlevel == CONTEXT_COURSECAT) {
// Remove the 'Permissions' navbar node in the Check permissions page.
if ($this->page->pagetype === 'admin-roles-check') {
$this->remove('permissions');
}
}
if ($this->page->context->contextlevel == CONTEXT_COURSE) {
// Remove any duplicate navbar nodes.
$this->remove_duplicate_items();
// Remove 'My courses' and 'Courses' if we are in the course context.
$this->remove('mycourses');
$this->remove('courses');
// Remove the course category breadcrumb nodes.
foreach ($this->items as $key => $item) {
// Remove if it is a course category breadcrumb node.
$this->remove($item->key, \breadcrumb_navigation_node::TYPE_CATEGORY);
}
// Remove the course breadcrumb node.
if (!str_starts_with($this->page->pagetype, 'course-view-section-')) {
$this->remove($this->page->course->id, \breadcrumb_navigation_node::TYPE_COURSE);
}
// Remove the navbar nodes that already exist in the secondary navigation menu.
$this->remove_items_that_exist_in_navigation($PAGE->secondarynav);
switch ($this->page->pagetype) {
case 'group-groupings':
case 'group-grouping':
case 'group-overview':
case 'group-assign':
// Remove the 'Groups' navbar node in the Groupings, Grouping, group Overview and Assign pages.
$this->remove('groups');
case 'backup-backup':
case 'backup-restorefile':
case 'backup-copy':
case 'course-reset':
// Remove the 'Import' navbar node in the Backup, Restore, Copy course and Reset pages.
$this->remove('import');
case 'course-user':
$this->remove('mygrades');
$this->remove('grades');
}
}
// Remove 'My courses' if we are in the module context.
if ($this->page->context->contextlevel == CONTEXT_MODULE) {
$this->remove('mycourses');
$this->remove('courses');
// Remove the course category breadcrumb nodes.
foreach ($this->items as $key => $item) {
// Remove if it is a course category breadcrumb node.
$this->remove($item->key, \breadcrumb_navigation_node::TYPE_CATEGORY);
}
$courseformat = course_get_format($this->page->course);
$removesections = $courseformat->can_sections_be_removed_from_navigation();
if ($removesections) {
// If the course sections are removed, we need to add the anchor of current section to the Course.
$coursenode = $this->get_item($this->page->course->id);
if (!is_null($coursenode) && $this->page->cm->sectionnum !== null) {
$coursenode->action = course_get_format($this->page->course)->get_view_url($this->page->cm->sectionnum);
}
}
}
if ($this->page->context->contextlevel == CONTEXT_SYSTEM) {
// Remove the navbar nodes that already exist in the secondary navigation menu.
$this->remove_items_that_exist_in_navigation($PAGE->secondarynav);
}
// Set the designated one path for courses.
$mycoursesnode = $this->get_item('mycourses');
if (!is_null($mycoursesnode)) {
$url = new \moodle_url('/my/courses.php');
$mycoursesnode->action = $url;
$mycoursesnode->text = get_string('mycourses');
}
$this->remove_no_link_items($removesections);
// Don't display the navbar if there is only one item. Apparently this is bad UX design.
if ($this->item_count() <= 1) {
$this->clear_items();
return;
}
// Make sure that the last item is not a link. Not sure if this is always a good idea.
$this->remove_last_item_action();
}
/**
* Get all the boostnavbaritem elements.
*
* @return boostnavbaritem[] Boost navbar items.
*/
public function get_items(): array {
return $this->items;
}
/**
* Removes all navigation items out of this boost navbar
*/
protected function clear_items(): void {
$this->items = [];
}
/**
* Retrieve a single navbar item.
*
* @param string|int $key The identifier of the navbar item to return.
* @return \breadcrumb_navigation_node|null The navbar item.
*/
protected function get_item($key): ?\breadcrumb_navigation_node {
foreach ($this->items as $item) {
if ($key === $item->key) {
return $item;
}
}
return null;
}
/**
* Counts all of the navbar items.
*
* @return int How many navbar items there are.
*/
protected function item_count(): int {
return count($this->items);
}
/**
* Remove a boostnavbaritem from the boost navbar.
*
* @param string|int $itemkey An identifier for the boostnavbaritem
* @param int|null $itemtype An additional type identifier for the boostnavbaritem (optional)
*/
protected function remove($itemkey, ?int $itemtype = null): void {
$itemfound = false;
foreach ($this->items as $key => $item) {
if ($item->key === $itemkey) {
// If a type identifier is also specified, check whether the type of the breadcrumb item matches the
// specified type. Skip if types to not match.
if (!is_null($itemtype) && $item->type !== $itemtype) {
continue;
}
unset($this->items[$key]);
$itemfound = true;
break;
}
}
if (!$itemfound) {
return;
}
$itemcount = $this->item_count();
if ($itemcount <= 0) {
return;
}
$this->items = array_values($this->items);
// Set the last item to last item if it is not.
$lastitem = $this->items[$itemcount - 1];
if (!$lastitem->is_last()) {
$lastitem->set_last(true);
}
}
/**
* Removes the action from the last item of the boostnavbaritem.
*/
protected function remove_last_item_action(): void {
$item = end($this->items);
$item->action = null;
reset($this->items);
}
/**
* Returns the second last navbar item. This is for use in the mobile view where we are showing just the second
* last item in the breadcrumb navbar.
*
* @return breakcrumb_navigation_node|null The second last navigation node.
*/
public function get_penultimate_item(): ?\breadcrumb_navigation_node {
$number = $this->item_count() - 2;
return ($number >= 0) ? $this->items[$number] : null;
}
/**
* Remove items that have no actions associated with them and optionally remove items that are sections.
*
* The only exception is the last item in the list which may not have a link but needs to be displayed.
*
* @param bool $removesections Whether section items should be also removed (only applies when they have an action)
*/
protected function remove_no_link_items(bool $removesections = true): void {
foreach ($this->items as $key => $value) {
if (!$value->is_last() &&
(!$value->has_action() || ($value->type == \navigation_node::TYPE_SECTION && $removesections))) {
unset($this->items[$key]);
}
}
$this->items = array_values($this->items);
}
/**
* Remove breadcrumb items that already exist in a given navigation view.
*
* This method removes the breadcrumb items that have a text => action match in a given navigation view
* (primary or secondary).
*
* @param view $navigationview The navigation view object.
*/
protected function remove_items_that_exist_in_navigation(view $navigationview): void {
// Loop through the navigation view items and create a 'text' => 'action' array which will be later used
// to compare whether any of the breadcrumb items matches these pairs.
$navigationviewitems = [];
foreach ($navigationview->children as $child) {
list($childtext, $childaction) = $this->get_node_text_and_action($child);
if ($childaction) {
$navigationviewitems[$childtext] = $childaction;
}
}
// Loop through the breadcrumb items and if the item's 'text' and 'action' values matches with any of the
// existing navigation view items, remove it from the breadcrumbs.
foreach ($this->items as $item) {
list($itemtext, $itemaction) = $this->get_node_text_and_action($item);
if ($itemaction) {
if (array_key_exists($itemtext, $navigationviewitems) &&
$navigationviewitems[$itemtext] === $itemaction) {
$this->remove($item->key);
}
}
}
}
/**
* Remove duplicate breadcrumb items.
*
* This method looks for breadcrumb items that have identical text and action values and removes the first item.
*/
protected function remove_duplicate_items(): void {
$taken = [];
// Reverse the order of the items before filtering so that the first occurrence is removed instead of the last.
$filtereditems = array_values(array_filter(array_reverse($this->items), function($item) use (&$taken) {
list($itemtext, $itemaction) = $this->get_node_text_and_action($item);
if ($itemaction) {
if (array_key_exists($itemtext, $taken) && $taken[$itemtext] === $itemaction) {
return false;
}
$taken[$itemtext] = $itemaction;
}
return true;
}));
// Reverse back the order.
$this->items = array_reverse($filtereditems);
}
/**
* Helper function that returns an array of the text and the outputted action url (if exists) for a given
* navigation node.
*
* @param navigation_node $node The navigation node object.
* @return array
*/
protected function get_node_text_and_action(navigation_node $node): array {
$text = $node->text instanceof lang_string ? $node->text->out() : $node->text;
$action = null;
if ($node->has_action()) {
if ($node->action instanceof moodle_url) {
$action = $node->action->out();
} else if ($node->action instanceof action_link) {
$action = $node->action->url->out();
} else {
$action = $node->action;
}
}
return [$text, $action];
}
}
@@ -0,0 +1,254 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace theme_boost\output;
use moodle_url;
use html_writer;
use get_string;
defined('MOODLE_INTERNAL') || die;
/**
* Renderers to align Moodle's HTML with that expected by Bootstrap
*
* @package theme_boost
* @copyright 2012 Bas Brands, www.basbrands.nl
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_renderer extends \core_renderer {
/**
* Returns HTML to display a "Turn editing on/off" button in a form.
*
* @param moodle_url $url The URL + params to send through when clicking the button
* @param string $method
* @return string HTML the button
*/
public function edit_button(moodle_url $url, string $method = 'post') {
if ($this->page->theme->haseditswitch) {
return;
}
$url->param('sesskey', sesskey());
if ($this->page->user_is_editing()) {
$url->param('edit', 'off');
$editstring = get_string('turneditingoff');
} else {
$url->param('edit', 'on');
$editstring = get_string('turneditingon');
}
$button = new \single_button($url, $editstring, $method, \single_button::BUTTON_PRIMARY);
return $this->render_single_button($button);
}
/**
* Renders the "breadcrumb" for all pages in boost.
*
* @return string the HTML for the navbar.
*/
public function navbar(): string {
$newnav = new \theme_boost\boostnavbar($this->page);
return $this->render_from_template('core/navbar', $newnav);
}
/**
* Renders the context header for the page.
*
* @param array $headerinfo Heading information.
* @param int $headinglevel What 'h' level to make the heading.
* @return string A rendered context header.
*/
public function context_header($headerinfo = null, $headinglevel = 1): string {
global $DB, $USER, $CFG;
require_once($CFG->dirroot . '/user/lib.php');
$context = $this->page->context;
$heading = null;
$imagedata = null;
$userbuttons = null;
// Make sure to use the heading if it has been set.
if (isset($headerinfo['heading'])) {
$heading = $headerinfo['heading'];
} else {
$heading = $this->page->heading;
}
// The user context currently has images and buttons. Other contexts may follow.
if ((isset($headerinfo['user']) || $context->contextlevel == CONTEXT_USER) && $this->page->pagetype !== 'my-index') {
if (isset($headerinfo['user'])) {
$user = $headerinfo['user'];
} else {
// Look up the user information if it is not supplied.
$user = $DB->get_record('user', array('id' => $context->instanceid));
}
// If the user context is set, then use that for capability checks.
if (isset($headerinfo['usercontext'])) {
$context = $headerinfo['usercontext'];
}
// Only provide user information if the user is the current user, or a user which the current user can view.
// When checking user_can_view_profile(), either:
// If the page context is course, check the course context (from the page object) or;
// If page context is NOT course, then check across all courses.
$course = ($this->page->context->contextlevel == CONTEXT_COURSE) ? $this->page->course : null;
if (user_can_view_profile($user, $course)) {
// Use the user's full name if the heading isn't set.
if (empty($heading)) {
$heading = fullname($user);
}
$imagedata = $this->user_picture($user, array('size' => 100));
// Check to see if we should be displaying a message button.
if (!empty($CFG->messaging) && has_capability('moodle/site:sendmessage', $context)) {
$userbuttons = array(
'messages' => array(
'buttontype' => 'message',
'title' => get_string('message', 'message'),
'url' => new moodle_url('/message/index.php', array('id' => $user->id)),
'image' => 'message',
'linkattributes' => \core_message\helper::messageuser_link_params($user->id),
'page' => $this->page
)
);
if ($USER->id != $user->id) {
$iscontact = \core_message\api::is_contact($USER->id, $user->id);
$isrequested = \core_message\api::get_contact_requests_between_users($USER->id, $user->id);
$contacturlaction = '';
$linkattributes = \core_message\helper::togglecontact_link_params(
$user,
$iscontact,
true,
!empty($isrequested),
);
// If the user is not a contact.
if (!$iscontact) {
if ($isrequested) {
// We just need the first request.
$requests = array_shift($isrequested);
if ($requests->userid == $USER->id) {
// If the user has requested to be a contact.
$contacttitle = 'contactrequestsent';
} else {
// If the user has been requested to be a contact.
$contacttitle = 'waitingforcontactaccept';
}
$linkattributes = array_merge($linkattributes, [
'class' => 'disabled',
'tabindex' => '-1',
]);
} else {
// If the user is not a contact and has not requested to be a contact.
$contacttitle = 'addtoyourcontacts';
$contacturlaction = 'addcontact';
}
$contactimage = 'addcontact';
} else {
// If the user is a contact.
$contacttitle = 'removefromyourcontacts';
$contacturlaction = 'removecontact';
$contactimage = 'removecontact';
}
$userbuttons['togglecontact'] = array(
'buttontype' => 'togglecontact',
'title' => get_string($contacttitle, 'message'),
'url' => new moodle_url('/message/index.php', array(
'user1' => $USER->id,
'user2' => $user->id,
$contacturlaction => $user->id,
'sesskey' => sesskey())
),
'image' => $contactimage,
'linkattributes' => $linkattributes,
'page' => $this->page
);
}
$this->page->requires->string_for_js('changesmadereallygoaway', 'moodle');
}
} else {
$heading = null;
}
}
$prefix = null;
if ($context->contextlevel == CONTEXT_MODULE) {
if ($this->page->course->format === 'singleactivity') {
$heading = format_string($this->page->course->fullname, true, ['context' => $context]);
} else {
$heading = $this->page->cm->get_formatted_name();
$iconurl = $this->page->cm->get_icon_url();
$iconclass = $iconurl->get_param('filtericon') ? '' : 'nofilter';
$iconattrs = [
'class' => "icon activityicon $iconclass",
'aria-hidden' => 'true'
];
$imagedata = html_writer::img($iconurl->out(false), '', $iconattrs);
$purposeclass = plugin_supports('mod', $this->page->activityname, FEATURE_MOD_PURPOSE);
$purposeclass .= ' activityiconcontainer icon-size-6';
$purposeclass .= ' modicon_' . $this->page->activityname;
$isbranded = component_callback('mod_' . $this->page->activityname, 'is_branded', [], false);
$imagedata = html_writer::tag('div', $imagedata, ['class' => $purposeclass . ($isbranded ? ' isbranded' : '')]);
if (!empty($USER->editing)) {
$prefix = get_string('modulename', $this->page->activityname);
}
}
}
// Return the heading wrapped in an sr-only element so it is only visible to screen-readers.
if (!empty($this->page->layout_options['nocontextheader'])) {
return html_writer::div($heading, 'sr-only');
}
$contextheader = new \context_header($heading, $headinglevel, $imagedata, $userbuttons, $prefix);
return $this->render($contextheader);
}
/**
* See if this is the first view of the current cm in the session if it has fake blocks.
*
* (We track up to 100 cms so as not to overflow the session.)
* This is done for drawer regions containing fake blocks so we can show blocks automatically.
*
* @return boolean true if the page has fakeblocks and this is the first visit.
*/
public function firstview_fakeblocks(): bool {
global $SESSION;
$firstview = false;
if ($this->page->cm) {
if (!$this->page->blocks->region_has_fakeblocks('side-pre')) {
return false;
}
if (!property_exists($SESSION, 'firstview_fakeblocks')) {
$SESSION->firstview_fakeblocks = [];
}
if (array_key_exists($this->page->cm->id, $SESSION->firstview_fakeblocks)) {
$firstview = false;
} else {
$SESSION->firstview_fakeblocks[$this->page->cm->id] = true;
$firstview = true;
if (count($SESSION->firstview_fakeblocks) > 100) {
array_shift($SESSION->firstview_fakeblocks);
}
}
}
return $firstview;
}
}
+98
View File
@@ -0,0 +1,98 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for theme_boost.
*
* @package theme_boost
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace theme_boost\privacy;
use \core_privacy\local\metadata\collection;
defined('MOODLE_INTERNAL') || die();
/**
* The boost theme stores a user preference data.
*
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
// This plugin has data.
\core_privacy\local\metadata\provider,
// This plugin has some sitewide user preferences to export.
\core_privacy\local\request\user_preference_provider {
/** The user preferences for the course index. */
const DRAWER_OPEN_INDEX = 'drawer-open-index';
/** The user preferences for the blocks drawer. */
const DRAWER_OPEN_BLOCK = 'drawer-open-block';
/**
* Returns meta data about this system.
*
* @param collection $items The initialised item collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $items): collection {
$items->add_user_preference(self::DRAWER_OPEN_INDEX, 'privacy:metadata:preference:draweropenindex');
$items->add_user_preference(self::DRAWER_OPEN_BLOCK, 'privacy:metadata:preference:draweropenblock');
return $items;
}
/**
* Store all user preferences for the plugin.
*
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
$draweropenindexpref = get_user_preferences(self::DRAWER_OPEN_INDEX, null, $userid);
if (isset($draweropenindexpref)) {
$preferencestring = get_string('privacy:drawerindexclosed', 'theme_boost');
if ($draweropenindexpref == 1) {
$preferencestring = get_string('privacy:drawerindexopen', 'theme_boost');
}
\core_privacy\local\request\writer::export_user_preference(
'theme_boost',
self::DRAWER_OPEN_INDEX,
$draweropenindexpref,
$preferencestring
);
}
$draweropenblockpref = get_user_preferences(self::DRAWER_OPEN_BLOCK, null, $userid);
if (isset($draweropenblockpref)) {
$preferencestring = get_string('privacy:drawerblockclosed', 'theme_boost');
if ($draweropenblockpref == 1) {
$preferencestring = get_string('privacy:drawerblockopen', 'theme_boost');
}
\core_privacy\local\request\writer::export_user_preference(
'theme_boost',
self::DRAWER_OPEN_BLOCK,
$draweropenblockpref,
$preferencestring
);
}
}
}