Initial commit

This commit is contained in:
kjodle 2017-12-18 21:12:29 -05:00
parent fbe68decfd
commit 6f67b16c0f
4 changed files with 69 additions and 0 deletions

View File

@ -1,2 +1,27 @@
# d12-moodle-shortcodes # d12-moodle-shortcodes
A filter that adds WordPress-like shortcodes to Moodle A filter that adds WordPress-like shortcodes to Moodle
## What this filter does
This filter allows you to use a shortcode, such as `[wi]` to dynamically add content to Moodle blocks and activities.
## How to install this filter
1. Upload the entire directory to the `moodle/filter` directory.
1. Make sure the plugin directory and enclosed files have the same permissions as other filters. (Use their permission scheme as a reference.)
1. Go to Site Administration >> Notifications and upgrade your database.
1. Go to Site Administration >> Plugins >> Filters >> Manage Filters and activate the plugin.
## How to use this filter
This filter is preset to use `[wi]` to add `<div class="wi">`, and `[/wi]` to add `</div>`.
You will need to go to the custom CSS area of your theme and define a style for `.wi` css class.
## How to adapt this filter
This filter uses the php function `str_replace` to replace the shortcode with your desired text. The basic formula is
str_replace (
'text to replace',
'text to replace it with',
$string_to_replace_text_in
)
Both `text to replace` and `text to replace it with` will accept arrays, so you can define a lot of shortcodes in a single function. I have not yet tested performance when adding many shortcodes.

11
filter.php Executable file
View File

@ -0,0 +1,11 @@
<?php
class filter_d12shortcodes extends moodle_text_filter {
public function filter($text, array $options = array()) {
return str_replace(
array('[wi]', '[/wi]'),
array('<div class="wi">', '</div>'),
$text
);
}
}

View File

@ -0,0 +1,3 @@
<?php
$string['filtername'] = 'd12 Shortcodes';

30
version.php Executable file
View File

@ -0,0 +1,30 @@
<?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
*
* @package filter
* @subpackage censor
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016051500; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2016050500; // Requires this Moodle version
$plugin->component = 'filter_d12shortcodes'; // Full name of the plugin (used for diagnostics)