├── .github └── workflows │ ├── moodle-plugin-ci.yml │ └── moodle-release.yml ├── CHANGES.md ├── COPYING.txt ├── README.md ├── UPGRADE.md ├── classes ├── admin_setting_staticpagestoredfile.php ├── event │ └── staticpage_viewed.php └── privacy │ └── provider.php ├── db ├── access.php └── upgrade.php ├── lang └── en │ └── local_staticpage.php ├── lib.php ├── locallib.php ├── settings.php ├── settings_pagelist.php ├── tests ├── behat │ └── local_staticpage.feature └── fixtures │ ├── example.html │ ├── iframetest.html │ └── nonadmin.html ├── version.php └── view.php /.github/workflows/moodle-plugin-ci.yml: -------------------------------------------------------------------------------- 1 | name: Moodle Plugin CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | runs-on: ubuntu-22.04 8 | 9 | services: 10 | postgres: 11 | image: postgres:14 12 | env: 13 | POSTGRES_USER: 'postgres' 14 | POSTGRES_HOST_AUTH_METHOD: 'trust' 15 | ports: 16 | - 5432:5432 17 | options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3 18 | 19 | mariadb: 20 | image: mariadb:10 21 | env: 22 | MYSQL_USER: 'root' 23 | MYSQL_ALLOW_EMPTY_PASSWORD: "true" 24 | MYSQL_CHARACTER_SET_SERVER: "utf8mb4" 25 | MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci" 26 | ports: 27 | - 3306:3306 28 | options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3 29 | 30 | strategy: 31 | fail-fast: false 32 | matrix: 33 | php: ['8.2', '8.3', '8.4'] 34 | moodle-branch: ['MOODLE_500_STABLE'] 35 | database: [pgsql, mariadb] 36 | 37 | steps: 38 | - name: Check out repository code 39 | uses: actions/checkout@v4 40 | with: 41 | path: plugin 42 | 43 | - name: Setup PHP ${{ matrix.php }} 44 | uses: shivammathur/setup-php@v2 45 | with: 46 | php-version: ${{ matrix.php }} 47 | extensions: ${{ matrix.extensions }} 48 | ini-values: max_input_vars=5000 49 | coverage: none 50 | 51 | - name: Initialise moodle-plugin-ci 52 | run: | 53 | composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^4 54 | echo $(cd ci/bin; pwd) >> $GITHUB_PATH 55 | echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH 56 | sudo locale-gen en_AU.UTF-8 57 | echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV 58 | 59 | - name: Install moodle-plugin-ci 60 | run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1 61 | env: 62 | DB: ${{ matrix.database }} 63 | MOODLE_BRANCH: ${{ matrix.moodle-branch }} 64 | 65 | - name: PHP Lint 66 | if: ${{ !cancelled() }} 67 | run: moodle-plugin-ci phplint 68 | 69 | - name: PHP Mess Detector 70 | continue-on-error: true # This step will show errors but will not fail 71 | if: ${{ !cancelled() }} 72 | run: moodle-plugin-ci phpmd 73 | 74 | - name: Moodle Code Checker 75 | if: ${{ !cancelled() }} 76 | run: moodle-plugin-ci phpcs --max-warnings 0 77 | 78 | - name: Moodle PHPDoc Checker 79 | if: ${{ !cancelled() }} 80 | run: moodle-plugin-ci phpdoc --max-warnings 0 81 | 82 | - name: Validating 83 | if: ${{ !cancelled() }} 84 | run: moodle-plugin-ci validate 85 | 86 | - name: Check upgrade savepoints 87 | if: ${{ !cancelled() }} 88 | run: moodle-plugin-ci savepoints 89 | 90 | - name: Mustache Lint 91 | if: ${{ !cancelled() }} 92 | run: moodle-plugin-ci mustache 93 | 94 | - name: Grunt 95 | if: ${{ !cancelled() }} 96 | run: moodle-plugin-ci grunt --max-lint-warnings 0 97 | 98 | - name: PHPUnit tests 99 | if: ${{ !cancelled() }} 100 | run: moodle-plugin-ci phpunit --fail-on-warning 101 | 102 | - name: Behat features 103 | id: behat 104 | if: ${{ !cancelled() }} 105 | run: moodle-plugin-ci behat --profile chrome 106 | 107 | - name: Upload Behat Faildump 108 | if: ${{ failure() && steps.behat.outcome == 'failure' }} 109 | uses: actions/upload-artifact@v4 110 | with: 111 | name: Behat Faildump (${{ join(matrix.*, ', ') }}) 112 | path: ${{ github.workspace }}/moodledata/behat_dump 113 | retention-days: 7 114 | if-no-files-found: ignore 115 | 116 | - name: Mark cancelled jobs as failed. 117 | if: ${{ cancelled() }} 118 | run: exit 1 119 | -------------------------------------------------------------------------------- /.github/workflows/moodle-release.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Whenever a new tag starting with "v" is pushed, add the tagged version 3 | # to the Moodle Plugins directory at https://moodle.org/plugins 4 | # 5 | # revision: 2021070201 6 | # 7 | name: Releasing in the Plugins directory 8 | 9 | on: 10 | push: 11 | tags: 12 | - v* 13 | 14 | workflow_dispatch: 15 | inputs: 16 | tag: 17 | description: 'Tag to be released' 18 | required: true 19 | 20 | defaults: 21 | run: 22 | shell: bash 23 | 24 | jobs: 25 | release-at-moodle-org: 26 | runs-on: ubuntu-latest 27 | env: 28 | PLUGIN: local_staticpage 29 | CURL: curl -s 30 | ENDPOINT: https://moodle.org/webservice/rest/server.php 31 | TOKEN: ${{ secrets.MOODLE_ORG_TOKEN }} 32 | FUNCTION: local_plugins_add_version 33 | 34 | steps: 35 | - name: Call the service function 36 | id: add-version 37 | run: | 38 | if [[ ! -z "${{ github.event.inputs.tag }}" ]]; then 39 | TAGNAME="${{ github.event.inputs.tag }}" 40 | elif [[ $GITHUB_REF = refs/tags/* ]]; then 41 | TAGNAME="${GITHUB_REF##*/}" 42 | fi 43 | if [[ -z "${TAGNAME}" ]]; then 44 | echo "No tag name has been provided!" 45 | exit 1 46 | fi 47 | ZIPURL="https://api.github.com/repos/${{ github.repository }}/zipball/${TAGNAME}" 48 | RESPONSE=$(${CURL} ${ENDPOINT} --data-urlencode "wstoken=${TOKEN}" \ 49 | --data-urlencode "wsfunction=${FUNCTION}" \ 50 | --data-urlencode "moodlewsrestformat=json" \ 51 | --data-urlencode "frankenstyle=${PLUGIN}" \ 52 | --data-urlencode "zipurl=${ZIPURL}" \ 53 | --data-urlencode "vcssystem=git" \ 54 | --data-urlencode "vcsrepositoryurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" \ 55 | --data-urlencode "vcstag=${TAGNAME}" \ 56 | --data-urlencode "changelogurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commits/${TAGNAME}" \ 57 | --data-urlencode "altdownloadurl=${ZIPURL}") 58 | echo "response=${RESPONSE}" >> $GITHUB_OUTPUT 59 | 60 | - name: Evaluate the response 61 | id: evaluate-response 62 | env: 63 | RESPONSE: ${{ steps.add-version.outputs.response }} 64 | run: | 65 | jq <<< ${RESPONSE} 66 | jq --exit-status ".id" <<< ${RESPONSE} > /dev/null 67 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | moodle-local_staticpage 2 | ======================= 3 | 4 | Changes 5 | ------- 6 | 7 | ### v5.0-r1 8 | 9 | * 2025-04-14 - Prepare compatibility for Moodle 5.0. 10 | 11 | ### v4.5-r2 12 | 13 | * 2025-05-06 - Tests: Fix Behat failures due to MDL-67683, resolves #76 14 | 15 | ### v4.5-r1 16 | 17 | * 2024-10-14 - Upgrade: Adopt changes from MDL-82183 and use new \core\output\html_writer 18 | * 2024-10-14 - Upgrade: Adopt changes from MDL-81960 and use new \core\url class 19 | * 2024-10-14 - Upgrade: Adopt changes from MDL-81818 to remove old bootstrap classes 20 | * 2024-10-07 - Prepare compatibility for Moodle 4.5. 21 | 22 | ### v4.4-r1 23 | 24 | * 2024-08-24 - Development: Rename master branch to main, please update your clones. 25 | * 2024-08-20 - Upgrade: Update Bootstrap classes for Moodle 4.4. 26 | * 2024-08-20 - Prepare compatibility for Moodle 4.4. 27 | 28 | ### v4.3-r2 29 | 30 | * 2024-08-11 - Add section for scheduled tasks to README 31 | * 2024-08-11 - Updated Moodle Plugin CI to latest upstream recommendations 32 | * 2024-08-11 - Preserve tags in head of static page document by moving it to the Moodle element, credits to Peter Keijsers. 33 | * 2024-08-11 - Added static page view even, credits to Jeroen de Bruijn. 34 | * 2024-01-08 - Improve the installation and usage of language packs in Behat tests. 35 | 36 | ### v4.3-r1 37 | 38 | * 2023-10-20 - Prepare compatibility for Moodle 4.3. 39 | 40 | ### v4.2-r1 41 | 42 | * 2023-10-19 - Fix Behat tests which broke on Moodle 4.2. 43 | * 2023-09-01 - Prepare compatibility for Moodle 4.2. 44 | 45 | ### v4.1-r2 46 | 47 | * 2023-10-14 - Add automated release to moodle.org/plugins 48 | * 2023-10-14 - Make codechecker happy again 49 | * 2023-10-10 - Updated Moodle Plugin CI to latest upstream recommendations 50 | * 2023-04-30 - Tests: Updated Moodle Plugin CI to use PHP 8.1 and Postgres 13 from Moodle 4.1 on. 51 | 52 | ### v4.1-r1 53 | 54 | * 2023-01-21 - Prepare compatibility for Moodle 4.1. 55 | * 2022-11-28 - Updated Moodle Plugin CI to latest upstream recommendations 56 | 57 | ### v4.0-r1 58 | 59 | * 2022-07-12 - Improve lib.php, solves #62. 60 | * 2022-07-12 - Remove the 'documentnavbarsource' setting as static pages do not have a navbar anymore on Moodle 4.0. 61 | * 2022-07-12 - Fix Behat tests which broke with Moodle 4.0. 62 | * 2022-07-12 - Prepare compatibility for Moodle 4.0. 63 | 64 | ### v3.11-r3 65 | 66 | * 2022-07-11 - Bugfix: Static page was crippled if the HTML code did not contain a plain body tag, solves #64 and several older issues. 67 | * 2022-07-11 - Add links to README to the language pack, solves #61 68 | * 2022-07-10 - Add Visual checks section to UPGRADE.md 69 | 70 | ### v3.11-r2 71 | 72 | * 2022-06-26 - Make codechecker happy again 73 | * 2022-06-26 - Updated Moodle Plugin CI to latest upstream recommendations 74 | * 2022-06-26 - Add UPGRADE.md as internal upgrade documentation 75 | * 2022-06-26 - Update maintainers and copyrights in README.md. 76 | 77 | ### v3.11-r1 78 | 79 | * 2021-12-08 - Prepare compatibility for Moodle 3.11. 80 | 81 | ### v3.10-r2 82 | 83 | * 2021-08-28 - Feature: Add a body class which contains the page name of the static page shown 84 | * 2021-08-28 - Bugfix: Fix incorrect setting defaults when installing the plugin - Thanks to Davo Smith 85 | * 2021-08-28 - Replace the deprecated print_error() function with a Moodle exception 86 | * 2021-08-28 - Feature: Allow non-admins to manage static page documents by introducing the local/staticpage:managedocuments capability 87 | * 2021-02-05 - Move Moodle Plugin CI from Travis CI to Github actions 88 | 89 | ### v3.10-r1 90 | 91 | * 2021-01-09 - Change Bootstrap labels to badges to comply with Bootstrap 4 standards 92 | * 2021-01-09 - Fix a small language pack flaw for the admin setting page. 93 | * 2021-01-09 - Prepare compatibility for Moodle 3.10. 94 | * 2021-01-06 - Change in Moodle release support: 95 | For the time being, this plugin is maintained for the most recent LTS release of Moodle as well as the most recent major release of Moodle. 96 | Bugfixes are backported to the LTS release. However, new features and improvements are not necessarily backported to the LTS release. 97 | * 2021-01-06 - Improvement: Declare which major stable version of Moodle this plugin supports (see MDL-59562 for details). 98 | 99 | ### v3.9-r1 100 | 101 | * 2020-11-25 - Improvement: Improve require_once calls which require the plugin's library - Credits to Antoni Bertran. 102 | * 2020-11-25 - Prepare compatibility for Moodle 3.9. 103 | 104 | ### v3.8-r1 105 | 106 | * 2020-02-14 - Prepare compatibility for Moodle 3.8. 107 | * 2019-12-18 - Improved behat test for fileupload because MDL-60975 was fixed. 108 | PLEASE NOTE: For all scenarios to pass, the Moodle version 3.7.3+ (Build: 20191212) is needed. 109 | 110 | ### v3.7-r2 111 | 112 | * 2019-12-12 - Bugfix: List of static pages link broken when moodle is installed in subdirectory - Credits to wuzhuoqing. 113 | * 2019-10-24 - Improvement: Add @_file_upload tag to fix failing behat tests. 114 | 115 | ### v3.7-r1 116 | 117 | * 2019-09-27 - Added behat tests. 118 | * 2019-09-23 - Add admin setting to check availability on list of static pages or not - Credits to Arief Wibowo. 119 | * 2019-08-05 - Prepare compatibility for Moodle 3.7. 120 | 121 | ### v3.6-r1 122 | 123 | * 2019-01-22 - Check compatibility for Moodle 3.6, no functionality change. 124 | * 2018-12-05 - Changed travis.yml due to upstream changes. 125 | 126 | ### v3.5-r2 127 | 128 | * 2018-09-26 - Bugfix: Forcing apache rewrite wasn't possible for Moodle installations in subdirectories. 129 | 130 | ### v3.5-r1 131 | 132 | * 2018-06-29 - Check compatibility for Moodle 3.5, no functionality change. 133 | 134 | ### v3.4-r2 135 | 136 | * 2018-05-16 - Implement Privacy API. 137 | 138 | ### v3.4-r1 139 | 140 | * 2017-12-14 - Check compatibility for Moodle 3.4, no functionality change. 141 | * 2017-12-05 - Added Workaround to travis.yml for fixing Behat tests with TravisCI. 142 | 143 | ### v3.3-r1 144 | 145 | * 2017-11-23 - Check compatibility for Moodle 3.3, no functionality change. 146 | * 2017-11-08 - Updated travis.yml to use newer node version for fixing TravisCI error. 147 | 148 | ### v3.2-r9 149 | 150 | * 2017-09-22 - Bugfix: Boost seems not to process filters for our breadcrumb element anymore 151 | 152 | ### v3.2-r8 153 | 154 | * 2017-09-13 - Escape proposed HTML structure and Apache configuration in README 155 | * 2017-09-13 - Escape HTML code in language pack - Credits to Carson Tam 156 | 157 | ### v3.2-r7 158 | 159 | * 2017-05-29 - Add Travis CI support 160 | 161 | ### v3.2-r6 162 | 163 | * 2017-05-05 - Improve README.md 164 | * 2017-02-15 - Minor code improvement, no functionality change 165 | 166 | ### v3.2-r5 167 | 168 | * 2017-01-27 - Automatically rename htm files to html - Credits to Andrew Hancox 169 | 170 | ### v3.2-r4 171 | 172 | * 2017-01-12 - Move Changelog from README.md to CHANGES.md 173 | 174 | ### v3.2-r3 175 | 176 | * 2017-01-12 - Check compatibility for Moodle 3.2, no functionality change 177 | * 2017-01-12 - Re-add the list of available static pages 178 | * 2017-01-11 - Improve README 179 | 180 | ### v3.2-r2 181 | 182 | * Internal release 183 | 184 | ### v3.2-r1 185 | 186 | * Internal release 187 | 188 | ### v3.1-r2 189 | 190 | * 2016-07-21 - Move the plugin's settings page to Site Administration -> Static Pages because this is where it logically belongs to 191 | 192 | ### v3.1-r1 193 | 194 | * 2016-07-19 - Check compatibility for Moodle 3.1, no functionality change 195 | 196 | ### Changes before v3.1 197 | 198 | * 2016-05-09 - Add settings to control if filters are processed and if the HTML code is cleaned on a static page or not 199 | * 2016-04-07 - Add a setting to control if a static page should be shown to visitors or not 200 | * 2016-02-10 - Add a new filearea to save the document files within Moodle - This change might break backwards compatibility in some situations, please read the "Upgrading from previous versions" below 201 | * 2016-02-10 - Change plugin version and release scheme to the scheme promoted by moodle.org, no functionality change 202 | * 2016-01-25 - Improve RewriteRules in README, no functionality change - Credits to Daniel Ruf 203 | * 2016-01-01 - Check compatibility for Moodle 3.0, no functionality change 204 | * 2015-08-18 - Check compatibility for Moodle 2.9, no functionality change 205 | * 2015-01-23 - Check compatibility for Moodle 2.8, no functionality change 206 | * 2014-08-19 - Add possibility to use a `'; 119 | } 120 | 121 | // Extract link tags in head (if present) and insert into HTML head. 122 | if (!empty($staticdoc->getElementsByTagName('link'))) { 123 | $linknodes = $staticdoc->getElementsByTagName('link'); 124 | foreach ($linknodes as $linknode) { 125 | $CFG->additionalhtmlhead .= $staticdoc->saveHTML($linknode); 126 | } 127 | } 128 | 129 | // Set page title. 130 | if ($localstaticpageconfig->documenttitlesource == STATICPAGE_TITLE_H1) { 131 | $PAGE->set_title($firsth1); 132 | } else if ($localstaticpageconfig->documenttitlesource == STATICPAGE_TITLE_HEAD) { 133 | $PAGE->set_title($title); 134 | } else { 135 | $PAGE->set_title($title); 136 | } 137 | 138 | // Set page heading. 139 | if ($localstaticpageconfig->documentheadingsource == STATICPAGE_TITLE_H1) { 140 | $PAGE->set_heading($firsth1); 141 | } else if ($localstaticpageconfig->documentheadingsource == STATICPAGE_TITLE_H1) { 142 | $PAGE->set_heading($title); 143 | } else { 144 | $PAGE->set_heading($title); 145 | } 146 | 147 | echo $OUTPUT->header(); 148 | 149 | // Get body tag. 150 | $body = $staticdoc->getElementsByTagName('body')->item(0); 151 | 152 | // Get page content from body tag. 153 | $pagecontent = $staticdoc->saveHTML($body); 154 | 155 | // Print page content. 156 | if ($localstaticpageconfig->processfilters == STATICPAGE_PROCESSFILTERS_YES && 157 | $localstaticpageconfig->cleanhtml == STATICPAGE_CLEANHTML_YES) { 158 | echo format_text($pagecontent, FORMAT_HTML, ['trusted' => false, 'noclean' => false, 'filter' => true]); 159 | } else if ($localstaticpageconfig->processfilters == STATICPAGE_PROCESSFILTERS_YES && 160 | $localstaticpageconfig->cleanhtml == STATICPAGE_CLEANHTML_NO) { 161 | echo format_text($pagecontent, FORMAT_HTML, ['trusted' => true, 'noclean' => true, 'filter' => true]); 162 | } else if ($localstaticpageconfig->processfilters == STATICPAGE_PROCESSFILTERS_NO && 163 | $localstaticpageconfig->cleanhtml == STATICPAGE_CLEANHTML_YES) { 164 | echo format_text($pagecontent, FORMAT_HTML, ['trusted' => false, 'noclean' => false, 'filter' => false]); 165 | } else if ($localstaticpageconfig->processfilters == STATICPAGE_PROCESSFILTERS_NO && 166 | $localstaticpageconfig->cleanhtml == STATICPAGE_CLEANHTML_NO) { 167 | echo format_text($pagecontent, FORMAT_HTML, ['trusted' => true, 'noclean' => true, 'filter' => false]); 168 | } else { // This should not happen. 169 | echo $pagecontent; 170 | } 171 | 172 | // Log this view. 173 | $logevent = \local_staticpage\event\staticpage_viewed::create([ 174 | 'userid' => $USER->id, 175 | 'context' => $context, 176 | 'other' => [ 177 | 'title' => $title, 178 | 'page' => $page, 179 | ], 180 | ]); 181 | $logevent->trigger(); 182 | 183 | echo $OUTPUT->footer(); 184 | --------------------------------------------------------------------------------