Skip to content
This repository was archived by the owner on Jul 3, 2024. It is now read-only.

86byt93eq plugin setup #1

Merged
merged 18 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# .github/workflows/ci.yml
name: ci

on: [push, pull_request]

jobs:
test:
uses: catalyst/catalyst-moodle-workflows/.github/workflows/ci.yml@main
secrets:
# Required if you plan to publish (uncomment the below)
moodle_org_token: ${{ secrets.MOODLE_ORG_TOKEN }}
with:
#Grunt fails due to CSS styling needing an !important.
disable_phpunit: true
disable_release : true
release_branches: main
min_php : 8.1
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
# moodle-block_staticlink
# Moodle - block_staticlink

This block allows to modify a part of the url. For example:
https://abc.com/code=123
Only the [123] part will be allowed to be edited in the block by the user.

##### Features:

- Editing url

##### Tested in:

![Moodle41](https://img.shields.io/badge/moodle-4.1-green.svg)
![PHP8.1](https://img.shields.io/badge/PHP-8.1-brightgreen.svg?logo=php)

### Installation

1. Copy this plugin to the `block\staticlink` folder on the server
2. Login as administrator
3. Go to Site Administrator > Notification
4. Install the plugin

##### Requirements:

* Recommended Moodle version: **4.1 Moodle**
* Recommended PHP version: **8.1**
* Required Moodle version: **4.1 Moodle Workplace**
* Required PHP version: **8.1**

---
### Changelog

##### 4.1.0 (28.05.2024)
* Original release

---

##### Author:
* Nihaal Shaikh :: [Ldesign Media](https://ldesignmedia.nl/) - [[email protected]]([email protected])

<img src="https://ldesignmedia.nl/themes/ldesignmedia/assets/images/logo/logo.svg" alt="ldesignmedia" height="70px">
105 changes: 105 additions & 0 deletions block_staticlink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?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/>.

/**
* Form for editing Static Link block instances.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package block_staticlink
* @copyright 21/05/2024 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
* @author Nihaal Shaikh
*/
class block_staticlink extends block_base {

/**
* Init the block.
*/
public function init(): void {
$this->title = get_string('pluginname', 'block_staticlink');
}

/**
* Which page types this block may appear on.
*
* @return array
*/
public function applicable_formats(): array {
return ['course-view' => true];
}

/**
* This function is called on your subclass right after an instance is loaded
* Use this function to act on instance data just after it's loaded and before anything else is done
* For instance: if your block will have different title's depending on location (site, course, blog, etc)
*/
public function specialization(): void {
if (isset($this->config->title)) {
$this->title = $this->title = format_string($this->config->title, true, ['context' => $this->context]);
} else {
$this->title = get_string('newstaticlinkblock', 'block_staticlink');
}
}

/**
* Parent class version of this function simply returns NULL
* Get the content
*
* @return object
*/
public function get_content(): object {
global $CFG;

require_once($CFG->libdir . '/filelib.php');
if ($this->content !== null) {
return $this->content;
}

$filteropt = new stdClass;
$filteropt->overflowdiv = true;
$this->content = new stdClass;
$this->content->footer = '';
if (isset($this->config->text)) {
// Rewrite url.
$this->config->text = file_rewrite_pluginfile_urls(
$this->config->text,
'pluginfile.php',
$this->context->id,
'block_staticlink',
'content',
null
);
$this->content->text = get_string('staticlink', 'block_staticlink', $this->config->text);
} else {
$this->content->text = '';
}

unset($filteropt); // Memory footprint.

return $this->content;
}

/**
* The block should only be dockable when the title of the block is not empty
* and when parent allows docking.
*
* @return bool
*/
public function instance_can_be_docked(): bool {
return !empty($this->config->title) && parent::instance_can_be_docked();
}

}
53 changes: 53 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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/>.

/**
* Static Link block caps.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package block_staticlink
* @copyright 21/05/2024 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
* @author Nihaal Shaikh
*/

defined('MOODLE_INTERNAL') || die();

$capabilities = [

'block/staticlink:myaddinstance' => [
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => [
'user' => CAP_ALLOW,
],

'clonepermissionsfrom' => 'moodle/my:manageblocks',
],

'block/staticlink:addinstance' => [
'riskbitmask' => RISK_SPAM | RISK_XSS,

'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => [
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
],

'clonepermissionsfrom' => 'moodle/site:manageblocks',
],
];
84 changes: 84 additions & 0 deletions edit_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?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/>.

/**
* Form for editing Static Link block instances.
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package block_staticlink
* @copyright 21/05/2024 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
* @author Nihaal Shaikh
*/
class block_staticlink_edit_form extends block_edit_form {

/**
* Specific fields for block_staticlink
* @param object $mform the form being built.
*/
protected function specific_definition($mform): void {

// Fields for editing Static Link block title and contents.
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));

$mform->addElement('text', 'config_title', get_string('configtitle', 'block_staticlink'));
$mform->setType('config_title', PARAM_TEXT);

$mform->addElement('text', 'config_text', get_string('configcontent', 'block_staticlink'));
$mform->setType('config_text', PARAM_TEXT);
}

/**
* Load in existing data as form defaults. Usually new entry defaults are stored directly in
* form definition (new entry form); this function is used to load in data where values
* already exist and data is being edited (edit entry form).
*
* @param $defaults
*/
public function set_data($defaults): void {
$canedit = $this->block->user_can_edit();
$config = $this->block->config;

foreach (['title', 'text'] as $field) {
if (!$canedit && !empty($config->$field)) {
${$field} = $config->$field;
$defaults->{"config_$field"} = format_string(${$field}, true, $this->page->context);
unset($config->$field);
}
}

parent::set_data($defaults);

if (!isset($config)) {
$this->block->config = new stdClass();
}

if (isset($title) || isset($text)) {
$config->title = $title ?? $config->title;
$config->text = $text ?? $config->text;
}
}

/**
* Display the configuration form when block is being added to the page
*
* @return bool
*/
public static function display_form_when_adding(): bool {
return true;
}

}
35 changes: 35 additions & 0 deletions lang/en/block_staticlink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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/>.

/**
* Strings for component 'block_staticlink', language 'en'
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package block_staticlink
* @copyright 21/05/2024 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
* @author Nihaal Shaikh
*/

$string['configcontent'] = 'Content';
$string['configtitle'] = 'Static Link block title';
$string['html:addinstance'] = 'Add a new static link block';
$string['html:myaddinstance'] = 'Add a new static link block to Dashboard';
$string['newstaticlinkblock'] = '(new static link block)';
$string['pluginname'] = 'Static Link';
$string['search:content'] = 'Static Link block content';
$string['privacy:metadata:block'] = 'The Static Link block stores all of its data within the block subsystem.';
$string['staticlink'] = '<a href="https://bsl.nl/feedbackform?code={$a}">Enter</a>';
34 changes: 34 additions & 0 deletions version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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/>.

/**
* Version details
*
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @package block_staticlink
* @copyright 21/05/2024 Mfreak.nl | LdesignMedia.nl - Luuk Verhoeven
* @author Nihaal Shaikh
*/

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024052800;
$plugin->requires = 2022051300;
$plugin->supported = [400, 401];
$plugin->component = 'block_staticlink';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '4.1.0';
Loading