MDL-53777 tool_mobile: Move mobile settings to the admin tool
[moodle.git] / admin / tool / mobile / classes / api.php
CommitLineData
b2478ed0
JL
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Class for Moodle Mobile tools.
19 *
20 * @package tool_mobile
21 * @copyright 2016 Juan Leyva
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @since Moodle 3.1
24 */
25namespace tool_mobile;
26
27use core_component;
28use core_plugin_manager;
0002056f 29use context_system;
b2478ed0
JL
30
31/**
32 * API exposed by tool_mobile
33 *
34 * @copyright 2016 Juan Leyva
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36 * @since Moodle 3.1
37 */
38class api {
39
40 /**
41 * Returns a list of Moodle plugins supporting the mobile app.
42 *
43 * @return array an array of objects containing the plugin information
44 */
45 public static function get_plugins_supporting_mobile() {
46 global $CFG;
47 require_once($CFG->libdir . '/adminlib.php');
48
49 $pluginsinfo = [];
50 $plugintypes = core_component::get_plugin_types();
51
52 foreach ($plugintypes as $plugintype => $unused) {
53 // We need to include files here.
54 $pluginswithfile = core_component::get_plugin_list_with_file($plugintype, 'db' . DIRECTORY_SEPARATOR . 'mobile.php');
55 foreach ($pluginswithfile as $plugin => $notused) {
56 $path = core_component::get_plugin_directory($plugintype, $plugin);
57 $component = $plugintype . '_' . $plugin;
58 $version = get_component_version($component);
59
60 require_once("$path/db/mobile.php");
61 foreach ($addons as $addonname => $addoninfo) {
62 $plugininfo = array(
63 'component' => $component,
64 'version' => $version,
65 'addon' => $addonname,
b4baee42 66 'dependencies' => !empty($addoninfo['dependencies']) ? $addoninfo['dependencies'] : array(),
b2478ed0
JL
67 'fileurl' => '',
68 'filehash' => '',
69 'filesize' => 0
70 );
71
72 // All the mobile packages must be under the plugin mobile directory.
73 $package = $path . DIRECTORY_SEPARATOR . 'mobile' . DIRECTORY_SEPARATOR . $addonname . '.zip';
74 if (file_exists($package)) {
75 $plugininfo['fileurl'] = $CFG->wwwroot . '' . str_replace($CFG->dirroot, '', $package);
76 $plugininfo['filehash'] = sha1_file($package);
77 $plugininfo['filesize'] = filesize($package);
78 }
79 $pluginsinfo[] = $plugininfo;
80 }
81 }
82 }
83 return $pluginsinfo;
84 }
85
0002056f
JL
86 /**
87 * Returns a list of the site public settings, those not requiring authentication.
88 *
89 * @return array with the settings and warnings
90 */
91 public static function get_site_public_settings() {
92 global $CFG, $SITE, $PAGE;
93
94 $context = context_system::instance();
95 // We need this to make work the format text functions.
96 $PAGE->set_context($context);
97
98 $settings = array(
99 'wwwroot' => $CFG->wwwroot,
100 'httpswwwroot' => $CFG->httpswwwroot,
101 'sitename' => external_format_string($SITE->fullname, $context->id, true),
102 'guestlogin' => $CFG->guestloginbutton,
103 'rememberusername' => $CFG->rememberusername,
104 'authloginviaemail' => $CFG->authloginviaemail,
105 'registerauth' => $CFG->registerauth,
106 'forgottenpasswordurl' => $CFG->forgottenpasswordurl,
107 'authinstructions' => format_text($CFG->auth_instructions),
108 'authnoneenabled' => (int) is_enabled_auth('none'),
109 'enablewebservices' => $CFG->enablewebservices,
110 'enablemobilewebservice' => $CFG->enablemobilewebservice,
111 'maintenanceenabled' => $CFG->maintenance_enabled,
112 'maintenancemessage' => format_text($CFG->maintenance_message),
113 );
114 return $settings;
115 }
116
b2478ed0 117}