Moodle插件:检查管理员+在管理中添加指向插件的链接

问题描述 投票:0回答:1

我是Moodle插件开发的新手,正在尝试创建一个显示向管理员显示页面的插件,在这里我可以在php代码上添加我的代码。

简而言之,我希望插件完成的工作已经在我上传到moodle根的标准php文件中实现。从这里您可以调用文件,例如yourdomain.co.uk/moodlelocation/myfile.php,它将按预期运行。

此问题是不安全的,因为任何人都可以加载myfile.php并依次运行页面上的脚本。这也意味着使用此脚本的任何其他人(完成后将免费获得)将通过FTP进入其托管服务器,并将两个php文件上传到他们的moodle安装中。

由于此,我认为一个插件(一个非常基础的插件)可能是最好的解决方案。然后,他们可以通过“站点管理”将页面加载到管理员中。例如站点管理>开发> MyPlugin。我假设我也可以将插件的主页限制为仅管理员(??)。

因此,我可以创建一个php页面,使我的脚本摇摆不定,但我需要将其制作为插件。

我读了一些书,我认为“本地”插件是最简单的方法(??)。

我设法使用local / webguides / inex.php中的以下内容启动并运行了本地插件:

<?php

// Standard config file and local library.

require_once(__DIR__ . '/../../config.php');

// Setting up the page.

$PAGE->set_context(context_system::instance());

$PAGE->set_pagelayout('standard');

$PAGE->set_title("webguides");

$PAGE->set_heading("webguides");

$PAGE->set_url(new moodle_url('/local/webguides/index.php'));

// Ouput the page header.

echo $OUTPUT->header();

echo 'MY php CODE here etc';

?>

这很好,但是有两个问题:

  1. 任何人都可以通过http://domain/local/webguides/index.php访问它
  2. 站点管理中没有指向它的链接(因此用户需要在其中键入URL)。

任何人都可以阐明我如何实现上述两个步骤吗?

提前感谢

ps.s。理想情况下,我希望将插件保留在尽可能少的文件中,因此,如果可以将所需的代码添加到local / webguides / index.php文件中,则将是首选。

php moodle
1个回答
0
投票

您需要创建一个功能,然后在显示页面之前需要该功能。

首先,请看local/readme.txt-这提供了本地插件所需文件的概述。

或阅读https://docs.moodle.org/dev/Local_plugins中的文档

也请查看现有的本地插件,以便您了解它们的创建方式-https://moodle.org/plugins/?q=type:local

您至少需要]

local/webguides/db/access.php - this will have the capability
local/webguides/lang/en/local_webguides.php
local/webguides/version.php

加上索引文件

local/webguides/index.php

db/access.php文件中有类似

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

$capabilities = array(

    'local/webguides:view' => array(
        'captype' => 'read',
        'contextlevel' => CONTEXT_SYSTEM,
        'archetypes' => array(
        ),
    ),

);

您可能还需要'riskbitmask' => RISK_XXX,具体取决于代码中是否存在任何风险。例如RISK_CONFIGRISK_PERSONAL

lang/en/local_webguides.php中有类似

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

$string['pluginname'] = 'Webguides';
$string['webguides:view'] = 'Able to view webguids';

version.php中有类似

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

$plugin->version   = 2020051901;        // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires  = 2015051109;        // Requires this Moodle version.
$plugin->component = 'local_webguides'; // Full name of the plugin (used for diagnostics).

用您使用的Moodle版本替换2015051109-这将在根文件夹的version.php中。

然后在index.php文件中的顶部附近使用它。

require_capability('local/webguides:view', context_system::instance());

因此,只有具有此功能的用户才能访问该页面。

© www.soinside.com 2019 - 2024. All rights reserved.