Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
namespace tool_mobile;
18
 
19
use html_writer;
20
 
21
/**
22
 * Allows plugins to add any elements to the footer.
23
 *
24
 * @package    tool_mobile
25
 * @copyright  2024 Andrew Lyons <andrew@nicols.co.uk>
26
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
class hook_callbacks {
29
    /**
30
     * Callback to add head elements.
31
     *
32
     * @param \core\hook\output\before_standard_head_html_generation $hook
33
     */
34
    public static function before_standard_head_html_generation(
35
        \core\hook\output\before_standard_head_html_generation $hook,
36
    ): void {
37
        global $CFG, $PAGE;
38
        // Smart App Banners meta tag is only displayed if mobile services are enabled and configured.
39
        if (!empty($CFG->enablemobilewebservice)) {
40
            $mobilesettings = get_config('tool_mobile');
41
            if (!empty($mobilesettings->enablesmartappbanners)) {
42
                if (!empty($mobilesettings->iosappid)) {
43
                    $hook->add_html(
44
                        '<meta name="apple-itunes-app" content="app-id=' . s($mobilesettings->iosappid) . ', ' .
45
                            'app-argument=' . $PAGE->url->out() . '"/>'
46
                    );
47
                }
48
 
49
                if (!empty($mobilesettings->androidappid)) {
50
                    $mobilemanifesturl = "$CFG->wwwroot/$CFG->admin/tool/mobile/mobile.webmanifest.php";
51
                    $hook->add_html('<link rel="manifest" href="' . $mobilemanifesturl . '" />');
52
                }
53
            }
54
        }
55
    }
56
 
57
    /**
58
     * Callback to add head elements.
59
     *
60
     * @param \core\hook\output\before_standard_footer_html_generation $hook
61
     */
62
    public static function before_standard_footer_html_generation(
63
        \core\hook\output\before_standard_footer_html_generation $hook,
64
    ): void {
65
        global $CFG;
66
 
67
        require_once(__DIR__ . '/../lib.php');
68
 
69
        if (empty($CFG->enablemobilewebservice)) {
70
            return;
71
        }
72
 
73
        $url = tool_mobile_create_app_download_url();
74
        if (empty($url)) {
75
            return;
76
        }
77
        $hook->add_html(
1441 ariadna 78
            html_writer::div(
79
                html_writer::link($url, get_string('getmoodleonyourmobile', 'tool_mobile'), ['class' => 'mobilelink']),
80
            ),
1 efrain 81
        );
82
    }
83
 
84
    /**
85
     * Callback to recover $SESSION->wantsurl.
86
     *
87
     * @param \core_user\hook\after_login_completed $hook
88
     */
89
    public static function after_login_completed(
90
        \core_user\hook\after_login_completed $hook,
91
    ): void {
92
        global $SESSION, $CFG;
93
 
94
        // Check if the user is doing a mobile app launch, if that's the case, ensure $SESSION->wantsurl is correctly set.
95
        if (!NO_MOODLE_COOKIES && !empty($_COOKIE['tool_mobile_launch'])) {
96
            if (empty($SESSION->wantsurl) || strpos($SESSION->wantsurl, '/tool/mobile/launch.php') === false) {
97
                $params = json_decode($_COOKIE['tool_mobile_launch'], true);
98
                $SESSION->wantsurl = (new \moodle_url("/$CFG->admin/tool/mobile/launch.php", $params))->out(false);
99
            }
100
        }
101
    }
102
}