deprecatedlib.php 175 KB
Newer Older
1
2
<?php

3
4
// This file is part of Moodle - http://moodle.org/
//
5
6
7
8
9
10
11
12
13
// 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.
14
//
15
16
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17
18
19
20
21
22
23

/**
 * deprecatedlib.php - Old functions retained only for backward compatibility
 *
 * Old functions retained only for backward compatibility.  New code should not
 * use any of these functions.
 *
24
 * @package    core
25
 * @subpackage deprecated
26
27
 * @copyright  1999 onwards Martin Dougiamas  {@link http://moodle.com}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28
 * @deprecated
29
30
 */

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

33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* === Functions that needs to be kept longer in deprecated lib than normal time period === */

/**
 * Add an entry to the legacy log table.
 *
 * @deprecated since 2.7 use new events instead
 *
 * @param    int     $courseid  The course id
 * @param    string  $module  The module name  e.g. forum, journal, resource, course, user etc
 * @param    string  $action  'view', 'update', 'add' or 'delete', possibly followed by another word to clarify.
 * @param    string  $url     The file and parameters used to see the results of the action
 * @param    string  $info    Additional description information
 * @param    int     $cm      The course_module->id if there is one
 * @param    int|stdClass $user If log regards $user other than $USER
 * @return void
 */
function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user=0) {
    debugging('add_to_log() has been deprecated, please rewrite your code to the new events API', DEBUG_DEVELOPER);

    // This is a nasty hack that allows us to put all the legacy stuff into legacy storage,
    // this way we may move all the legacy settings there too.
    $manager = get_log_manager();
    if (method_exists($manager, 'legacy_add_to_log')) {
        $manager->legacy_add_to_log($courseid, $module, $action, $url, $info, $cm, $user);
    }
}

/**
 * Function to call all event handlers when triggering an event
 *
 * @deprecated since 2.6
 *
 * @param string $eventname name of the event
 * @param mixed $eventdata event data object
 * @return int number of failed events
 */
function events_trigger($eventname, $eventdata) {
    debugging('events_trigger() is deprecated, please use new events instead', DEBUG_DEVELOPER);
    return events_trigger_legacy($eventname, $eventdata);
}

/**
 * List all core subsystems and their location
 *
 * This is a whitelist of components that are part of the core and their
 * language strings are defined in /lang/en/<<subsystem>>.php. If a given
 * plugin is not listed here and it does not have proper plugintype prefix,
 * then it is considered as course activity module.
 *
 * The location is optionally dirroot relative path. NULL means there is no special
 * directory for this subsystem. If the location is set, the subsystem's
 * renderer.php is expected to be there.
 *
 * @deprecated since 2.6, use core_component::get_core_subsystems()
 *
 * @param bool $fullpaths false means relative paths from dirroot, use true for performance reasons
 * @return array of (string)name => (string|null)location
 */
function get_core_subsystems($fullpaths = false) {
    global $CFG;

    // NOTE: do not add any other debugging here, keep forever.

    $subsystems = core_component::get_core_subsystems();

    if ($fullpaths) {
        return $subsystems;
    }

    debugging('Short paths are deprecated when using get_core_subsystems(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);

    $dlength = strlen($CFG->dirroot);

    foreach ($subsystems as $k => $v) {
        if ($v === null) {
            continue;
        }
        $subsystems[$k] = substr($v, $dlength+1);
    }

    return $subsystems;
}

/**
 * Lists all plugin types.
 *
 * @deprecated since 2.6, use core_component::get_plugin_types()
 *
 * @param bool $fullpaths false means relative paths from dirroot
 * @return array Array of strings - name=>location
 */
function get_plugin_types($fullpaths = true) {
    global $CFG;

    // NOTE: do not add any other debugging here, keep forever.

    $types = core_component::get_plugin_types();

    if ($fullpaths) {
        return $types;
    }

    debugging('Short paths are deprecated when using get_plugin_types(), please fix the code to use fullpaths instead.', DEBUG_DEVELOPER);

    $dlength = strlen($CFG->dirroot);

    foreach ($types as $k => $v) {
        if ($k === 'theme') {
            $types[$k] = 'theme';
            continue;
        }
        $types[$k] = substr($v, $dlength+1);
    }

    return $types;
}

/**
 * Use when listing real plugins of one type.
 *
 * @deprecated since 2.6, use core_component::get_plugin_list()
 *
 * @param string $plugintype type of plugin
 * @return array name=>fulllocation pairs of plugins of given type
 */
function get_plugin_list($plugintype) {

    // NOTE: do not add any other debugging here, keep forever.

    if ($plugintype === '') {
        $plugintype = 'mod';
    }

    return core_component::get_plugin_list($plugintype);
}

/**
 * Get a list of all the plugins of a given type that define a certain class
 * in a certain file. The plugin component names and class names are returned.
 *
 * @deprecated since 2.6, use core_component::get_plugin_list_with_class()
 *
 * @param string $plugintype the type of plugin, e.g. 'mod' or 'report'.
 * @param string $class the part of the name of the class after the
 *      frankenstyle prefix. e.g 'thing' if you are looking for classes with
 *      names like report_courselist_thing. If you are looking for classes with
 *      the same name as the plugin name (e.g. qtype_multichoice) then pass ''.
 * @param string $file the name of file within the plugin that defines the class.
 * @return array with frankenstyle plugin names as keys (e.g. 'report_courselist', 'mod_forum')
 *      and the class names as values (e.g. 'report_courselist_thing', 'qtype_multichoice').
 */
function get_plugin_list_with_class($plugintype, $class, $file) {

    // NOTE: do not add any other debugging here, keep forever.

    return core_component::get_plugin_list_with_class($plugintype, $class, $file);
}

/**
 * Returns the exact absolute path to plugin directory.
 *
 * @deprecated since 2.6, use core_component::get_plugin_directory()
 *
 * @param string $plugintype type of plugin
 * @param string $name name of the plugin
 * @return string full path to plugin directory; NULL if not found
 */
function get_plugin_directory($plugintype, $name) {

    // NOTE: do not add any other debugging here, keep forever.

    if ($plugintype === '') {
        $plugintype = 'mod';
    }

    return core_component::get_plugin_directory($plugintype, $name);
}

/**
 * Normalize the component name using the "frankenstyle" names.
 *
 * @deprecated since 2.6, use core_component::normalize_component()
 *
 * @param string $component
 * @return array as (string)$type => (string)$plugin
 */
function normalize_component($component) {

    // NOTE: do not add any other debugging here, keep forever.

    return core_component::normalize_component($component);
}

/**
 * Return exact absolute path to a plugin directory.
 *
 * @deprecated since 2.6, use core_component::normalize_component()
 *
 * @param string $component name such as 'moodle', 'mod_forum'
 * @return string full path to component directory; NULL if not found
 */
function get_component_directory($component) {

    // NOTE: do not add any other debugging here, keep forever.

    return core_component::get_component_directory($component);
}

/**
 * Get the context instance as an object. This function will create the
 * context instance if it does not exist yet.
 *
 * @deprecated since 2.2, use context_course::instance() or other relevant class instead
 * @todo This will be deleted in Moodle 2.8, refer MDL-34472
 * @param integer $contextlevel The context level, for example CONTEXT_COURSE, or CONTEXT_MODULE.
 * @param integer $instance The instance id. For $level = CONTEXT_COURSE, this would be $course->id,
 *      for $level = CONTEXT_MODULE, this would be $cm->id. And so on. Defaults to 0
 * @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
 *      MUST_EXIST means throw exception if no record or multiple records found
 * @return context The context object.
 */
function get_context_instance($contextlevel, $instance = 0, $strictness = IGNORE_MISSING) {

    debugging('get_context_instance() is deprecated, please use context_xxxx::instance() instead.', DEBUG_DEVELOPER);

    $instances = (array)$instance;
    $contexts = array();

    $classname = context_helper::get_class_for_level($contextlevel);

    // we do not load multiple contexts any more, PAGE should be responsible for any preloading
    foreach ($instances as $inst) {
        $contexts[$inst] = $classname::instance($inst, $strictness);
    }

    if (is_array($instance)) {
        return $contexts;
    } else {
        return $contexts[$instance];
    }
}
/* === End of long term deprecated api list === */

276
277
278
279
280
281
282
/**
 * Adds a file upload to the log table so that clam can resolve the filename to the user later if necessary
 *
 * @deprecated since 2.7 - use new file picker instead
 *
 */
function clam_log_upload($newfilepath, $course=null, $nourl=false) {
283
    throw new coding_exception('clam_log_upload() can not be used any more, please use file picker instead');
284
285
286
287
288
289
290
291
292
}

/**
 * This function logs to error_log and to the log table that an infected file has been found and what's happened to it.
 *
 * @deprecated since 2.7 - use new file picker instead
 *
 */
function clam_log_infected($oldfilepath='', $newfilepath='', $userid=0) {
293
    throw new coding_exception('clam_log_infected() can not be used any more, please use file picker instead');
294
295
296
297
298
299
300
301
302
}

/**
 * Some of the modules allow moving attachments (glossary), in which case we need to hunt down an original log and change the path.
 *
 * @deprecated since 2.7 - use new file picker instead
 *
 */
function clam_change_log($oldpath, $newpath, $update=true) {
303
    throw new coding_exception('clam_change_log() can not be used any more, please use file picker instead');
304
305
306
307
308
309
310
311
312
}

/**
 * Replaces the given file with a string.
 *
 * @deprecated since 2.7 - infected files are now deleted in file picker
 *
 */
function clam_replace_infected_file($file) {
313
    throw new coding_exception('clam_replace_infected_file() can not be used any more, please use file picker instead');
314
315
}

316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/**
 * Deals with an infected file - either moves it to a quarantinedir
 * (specified in CFG->quarantinedir) or deletes it.
 *
 * If moving it fails, it deletes it.
 *
 * @deprecated since 2.7
 */
function clam_handle_infected_file($file, $userid=0, $basiconly=false) {
    throw new coding_exception('clam_handle_infected_file() can not be used any more, please use file picker instead');
}

/**
 * If $CFG->runclamonupload is set, we scan a given file. (called from {@link preprocess_files()})
 *
 * @deprecated since 2.7
 */
function clam_scan_moodle_file(&$file, $course) {
    throw new coding_exception('clam_scan_moodle_file() can not be used any more, please use file picker instead');
}


338
339
340
341
342
343
344
345
346
347
348
/**
 * Checks whether the password compatibility library will work with the current
 * version of PHP. This cannot be done using PHP version numbers since the fix
 * has been backported to earlier versions in some distributions.
 *
 * See https://github.com/ircmaxell/password_compat/issues/10 for more details.
 *
 * @deprecated since 2.7 PHP 5.4.x should be always compatible.
 *
 */
function password_compat_not_supported() {
349
    throw new coding_exception('Do not use password_compat_not_supported() - bcrypt is now always available');
350
351
}

352
353
354
355
356
357
/**
 * Factory method that was returning moodle_session object.
 *
 * @deprecated since 2.6
 */
function session_get_instance() {
358
    throw new coding_exception('session_get_instance() is removed, use \core\session\manager instead');
359
360
361
362
363
364
365
366
}

/**
 * Returns true if legacy session used.
 *
 * @deprecated since 2.6
 */
function session_is_legacy() {
367
    throw new coding_exception('session_is_legacy() is removed, do not use any more');
368
369
370
371
372
373
374
375
}

/**
 * Terminates all sessions, auth hooks are not executed.
 *
 * @deprecated since 2.6
 */
function session_kill_all() {
376
    throw new coding_exception('session_kill_all() is removed, use \core\session\manager::kill_all_sessions() instead');
377
378
379
380
381
382
383
384
}

/**
 * Mark session as accessed, prevents timeouts.
 *
 * @deprecated since 2.6
 */
function session_touch($sid) {
385
    throw new coding_exception('session_touch() is removed, use \core\session\manager::touch_session() instead');
386
387
388
389
390
391
392
393
}

/**
 * Terminates one sessions, auth hooks are not executed.
 *
 * @deprecated since 2.6
 */
function session_kill($sid) {
394
    throw new coding_exception('session_kill() is removed, use \core\session\manager::kill_session() instead');
395
396
397
398
399
400
401
402
}

/**
 * Terminates all sessions of one user, auth hooks are not executed.
 *
 * @deprecated since 2.6
 */
function session_kill_user($userid) {
403
    throw new coding_exception('session_kill_user() is removed, use \core\session\manager::kill_user_sessions() instead');
404
405
406
407
408
409
410
411
412
413
}

/**
 * Setup $USER object - called during login, loginas, etc.
 *
 * Call sync_user_enrolments() manually after log-in, or log-in-as.
 *
 * @deprecated since 2.6
 */
function session_set_user($user) {
414
    throw new coding_exception('session_set_user() is removed, use \core\session\manager::set_user() instead');
415
416
417
418
419
420
421
}

/**
 * Is current $USER logged-in-as somebody else?
 * @deprecated since 2.6
 */
function session_is_loggedinas() {
422
    throw new coding_exception('session_is_loggedinas() is removed, use \core\session\manager::is_loggedinas() instead');
423
424
425
426
427
428
429
}

/**
 * Returns the $USER object ignoring current login-as session
 * @deprecated since 2.6
 */
function session_get_realuser() {
430
    throw new coding_exception('session_get_realuser() is removed, use \core\session\manager::get_realuser() instead');
431
432
433
434
435
436
437
}

/**
 * Login as another user - no security checks here.
 * @deprecated since 2.6
 */
function session_loginas($userid, $context) {
438
    throw new coding_exception('session_loginas() is removed, use \core\session\manager::loginas() instead');
439
440
}

441
442
443
444
445
446
/**
 * Minify JavaScript files.
 *
 * @deprecated since 2.6
 */
function js_minify($files) {
447
    throw new coding_exception('js_minify() is removed, use core_minify::js_files() or core_minify::js() instead.');
448
449
450
451
452
453
454
455
}

/**
 * Minify CSS files.
 *
 * @deprecated since 2.6
 */
function css_minify_css($files) {
456
    throw new coding_exception('css_minify_css() is removed, use core_minify::css_files() or core_minify::css() instead.');
457
458
}

459
460
// === Deprecated before 2.6.0 ===

461
462
/**
 * Hack to find out the GD version by parsing phpinfo output
463
464
 *
 * @deprecated
465
466
 */
function check_gd_version() {
467
    throw new coding_exception('check_gd_version() is removed, GD extension is always available now');
468
469
}

470
471
472
473
474
475
/**
 * Not used any more, the account lockout handling is now
 * part of authenticate_user_login().
 * @deprecated
 */
function update_login_count() {
476
    throw new coding_exception('update_login_count() is removed, all calls need to be removed');
477
478
479
480
481
482
483
}

/**
 * Not used any more, replaced by proper account lockout.
 * @deprecated
 */
function reset_login_count() {
484
    throw new coding_exception('reset_login_count() is removed, all calls need to be removed');
485
486
}

487
488
489
490
491
/**
 * @deprecated
 */
function update_log_display_entry($module, $action, $mtable, $field) {

492
    throw new coding_exception('The update_log_display_entry() is removed, please use db/log.php description file instead.');
493
494
}

495
/**
496
 * @deprecated use the text formatting in a standard way instead (http://docs.moodle.org/dev/Output_functions)
497
498
499
 *             this was abused mostly for embedding of attachments
 */
function filter_text($text, $courseid = NULL) {
500
    throw new coding_exception('filter_text() can not be used anymore, use format_text(), format_string() etc instead.');
501
502
}

503
504
505
506
/**
 * @deprecated use $PAGE->https_required() instead
 */
function httpsrequired() {
507
    throw new coding_exception('httpsrequired() can not be used any more use $PAGE->https_required() instead.');
508
509
}

Petr Skoda's avatar
Petr Skoda committed
510
511
512
/**
 * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
 *
513
514
515
 * @deprecated since 3.1 - replacement legacy file API methods can be found on the moodle_url class, for example:
 * The moodle_url::make_legacyfile_url() method can be used to generate a legacy course file url. To generate
 * course module file.php url the moodle_url::make_file_url() should be used.
Petr Skoda's avatar
Petr Skoda committed
516
517
518
519
520
521
522
 *
 * @param string $path Physical path to a file
 * @param array $options associative array of GET variables to append to the URL
 * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
 * @return string URL to file
 */
function get_file_url($path, $options=null, $type='coursefile') {
523
    debugging('Function get_file_url() is deprecated, please use moodle_url factory methods instead.', DEBUG_DEVELOPER);
524
    global $CFG;
Petr Skoda's avatar
Petr Skoda committed
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571

    $path = str_replace('//', '/', $path);
    $path = trim($path, '/'); // no leading and trailing slashes

    // type of file
    switch ($type) {
       case 'questionfile':
            $url = $CFG->wwwroot."/question/exportfile.php";
            break;
       case 'rssfile':
            $url = $CFG->wwwroot."/rss/file.php";
            break;
        case 'httpscoursefile':
            $url = $CFG->httpswwwroot."/file.php";
            break;
         case 'coursefile':
        default:
            $url = $CFG->wwwroot."/file.php";
    }

    if ($CFG->slasharguments) {
        $parts = explode('/', $path);
        foreach ($parts as $key => $part) {
        /// anchor dash character should not be encoded
            $subparts = explode('#', $part);
            $subparts = array_map('rawurlencode', $subparts);
            $parts[$key] = implode('#', $subparts);
        }
        $path  = implode('/', $parts);
        $ffurl = $url.'/'.$path;
        $separator = '?';
    } else {
        $path = rawurlencode('/'.$path);
        $ffurl = $url.'?file='.$path;
        $separator = '&amp;';
    }

    if ($options) {
        foreach ($options as $name=>$value) {
            $ffurl = $ffurl.$separator.$name.'='.$value;
            $separator = '&amp;';
        }
    }

    return $ffurl;
}

572
/**
573
 * @deprecated use get_enrolled_users($context) instead.
574
 */
575
function get_course_participants($courseid) {
576
    throw new coding_exception('get_course_participants() can not be used any more, use get_enrolled_users() instead.');
577
578
579
}

/**
580
 * @deprecated use is_enrolled($context, $userid) instead.
581
 */
582
function is_course_participant($userid, $courseid) {
583
    throw new coding_exception('is_course_participant() can not be used any more, use is_enrolled() instead.');
584
585
586
}

/**
587
 * @deprecated
588
589
 */
function get_recent_enrolments($courseid, $timestart) {
590
    throw new coding_exception('get_recent_enrolments() is removed as it returned inaccurate results.');
591
592
}

593
/**
594
 * @deprecated use clean_param($string, PARAM_FILE) instead.
595
596
 */
function detect_munged_arguments($string, $allowdots=1) {
597
    throw new coding_exception('detect_munged_arguments() can not be used any more, please use clean_param(,PARAM_FILE) instead.');
598
599
}

600

601
602
603
604
605
/**
 * Unzip one zip file to a destination dir
 * Both parameters must be FULL paths
 * If destination isn't specified, it will be the
 * SAME directory where the zip file resides.
606
607
608
609
610
 *
 * @global object
 * @param string $zipfile The zip file to unzip
 * @param string $destination The location to unzip to
 * @param bool $showstatus_ignored Unused
611
 * @deprecated since 2.0 MDL-15919
612
613
 */
function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
614
615
    debugging(__FUNCTION__ . '() is deprecated. '
            . 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER);
616

617
    // Extract everything from zipfile.
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
    $path_parts = pathinfo(cleardoubleslashes($zipfile));
    $zippath = $path_parts["dirname"];       //The path of the zip file
    $zipfilename = $path_parts["basename"];  //The name of the zip file
    $extension = $path_parts["extension"];    //The extension of the file

    //If no file, error
    if (empty($zipfilename)) {
        return false;
    }

    //If no extension, error
    if (empty($extension)) {
        return false;
    }

    //Clear $zipfile
    $zipfile = cleardoubleslashes($zipfile);

    //Check zipfile exists
    if (!file_exists($zipfile)) {
        return false;
    }

    //If no destination, passed let's go with the same directory
    if (empty($destination)) {
        $destination = $zippath;
    }

    //Clear $destination
    $destpath = rtrim(cleardoubleslashes($destination), "/");

    //Check destination path exists
    if (!is_dir($destpath)) {
        return false;
    }

654
655
656
    $packer = get_file_packer('application/zip');

    $result = $packer->extract_to_pathname($zipfile, $destpath);
657
658
659
660
661
662
663
664
665
666
667
668
669
670

    if ($result === false) {
        return false;
    }

    foreach ($result as $status) {
        if ($status !== true) {
            return false;
        }
    }

    return true;
}

671
672
673
/**
 * Zip an array of files/dirs to a destination zip file
 * Both parameters must be FULL paths to the files/dirs
674
675
676
677
678
 *
 * @global object
 * @param array $originalfiles Files to zip
 * @param string $destination The destination path
 * @return bool Outcome
679
680
 *
 * @deprecated since 2.0 MDL-15919
681
 */
682
683
684
function zip_files($originalfiles, $destination) {
    debugging(__FUNCTION__ . '() is deprecated. '
            . 'Please use the application/zip file_packer implementation instead.', DEBUG_DEVELOPER);
685

686
    // Extract everything from destination.
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
    $path_parts = pathinfo(cleardoubleslashes($destination));
    $destpath = $path_parts["dirname"];       //The path of the zip file
    $destfilename = $path_parts["basename"];  //The name of the zip file
    $extension = $path_parts["extension"];    //The extension of the file

    //If no file, error
    if (empty($destfilename)) {
        return false;
    }

    //If no extension, add it
    if (empty($extension)) {
        $extension = 'zip';
        $destfilename = $destfilename.'.'.$extension;
    }

    //Check destination path exists
    if (!is_dir($destpath)) {
        return false;
    }

    //Check destination path is writable. TODO!!

    //Clean destination filename
    $destfilename = clean_filename($destfilename);

    //Now check and prepare every file
    $files = array();
    $origpath = NULL;

    foreach ($originalfiles as $file) {  //Iterate over each file
        //Check for every file
        $tempfile = cleardoubleslashes($file); // no doubleslashes!
        //Calculate the base path for all files if it isn't set
        if ($origpath === NULL) {
            $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
        }
        //See if the file is readable
        if (!is_readable($tempfile)) {  //Is readable
            continue;
        }
        //See if the file/dir is in the same directory than the rest
        if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
            continue;
        }
        //Add the file to the array
        $files[] = $tempfile;
    }

    $zipfiles = array();
    $start = strlen($origpath)+1;
    foreach($files as $file) {
        $zipfiles[substr($file, $start)] = $file;
    }

742
    $packer = get_file_packer('application/zip');
743

744
    return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
745
746
}

747
/**
748
 * @deprecated use groups_get_all_groups() instead.
749
750
 */
function mygroupid($courseid) {
751
    throw new coding_exception('mygroupid() can not be used any more, please use groups_get_all_groups() instead.');
752
753
754
755
756
}


/**
 * Returns the current group mode for a given course or activity module
757
 *
758
 * Could be false, SEPARATEGROUPS or VISIBLEGROUPS    (<-- Martin)
759
 *
760
761
762
 * @deprecated since Moodle 2.0 MDL-14617 - please do not use this function any more.
 * @todo MDL-50273 This will be deleted in Moodle 3.2.
 *
763
764
765
 * @param object $course Course Object
 * @param object $cm Course Manager Object
 * @return mixed $course->groupmode
766
767
768
 */
function groupmode($course, $cm=null) {

769
    debugging('groupmode() is deprecated, please use groups_get_* instead', DEBUG_DEVELOPER);
770
771
772
773
774
775
    if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
        return $cm->groupmode;
    }
    return $course->groupmode;
}

776
777
778
779
780
/**
 * Sets the current group in the session variable
 * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
 * Sets currentgroup[$courseid] in the session variable appropriately.
 * Does not do any permission checking.
781
 *
782
783
784
 * @deprecated Since year 2006 - please do not use this function any more.
 * @todo MDL-50273 This will be deleted in Moodle 3.2.
 *
785
 * @global object
786
 * @global object
787
788
789
790
791
792
793
 * @param int $courseid The course being examined - relates to id field in
 * 'course' table.
 * @param int $groupid The group being examined.
 * @return int Current group id which was set by this function
 */
function set_current_group($courseid, $groupid) {
    global $SESSION;
794
795

    debugging('set_current_group() is deprecated, please use $SESSION->currentgroup[$courseid] instead', DEBUG_DEVELOPER);
796
797
798
    return $SESSION->currentgroup[$courseid] = $groupid;
}

799
/**
800
 * Gets the current group - either from the session variable or from the database.
801
 *
802
803
804
 * @deprecated Since year 2006 - please do not use this function any more.
 * @todo MDL-50273 This will be deleted in Moodle 3.2.
 *
805
 * @global object
806
 * @param int $courseid The course being examined - relates to id field in
807
 * 'course' table.
808
 * @param bool $full If true, the return value is a full record object.
809
 * If false, just the id of the record.
810
 * @return int|bool
811
812
813
814
 */
function get_current_group($courseid, $full = false) {
    global $SESSION;

815
    debugging('get_current_group() is deprecated, please use groups_get_* instead', DEBUG_DEVELOPER);
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
    if (isset($SESSION->currentgroup[$courseid])) {
        if ($full) {
            return groups_get_group($SESSION->currentgroup[$courseid]);
        } else {
            return $SESSION->currentgroup[$courseid];
        }
    }

    $mygroupid = mygroupid($courseid);
    if (is_array($mygroupid)) {
        $mygroupid = array_shift($mygroupid);
        set_current_group($courseid, $mygroupid);
        if ($full) {
            return groups_get_group($mygroupid);
        } else {
            return $mygroupid;
        }
    }

    if ($full) {
        return false;
    } else {
        return 0;
    }
}

842
843
844
845
/**
 * @deprecated Since Moodle 2.8
 */
function groups_filter_users_by_course_module_visible($cm, $users) {
846
    throw new coding_exception('groups_filter_users_by_course_module_visible() is removed. ' .
847
848
            'Replace with a call to \core_availability\info_module::filter_user_list(), ' .
            'which does basically the same thing but includes other restrictions such ' .
849
            'as profile restrictions.');
850
851
852
853
854
855
}

/**
 * @deprecated Since Moodle 2.8
 */
function groups_course_module_visible($cm, $userid=null) {
856
857
    throw new coding_exception('groups_course_module_visible() is removed, use $cm->uservisible to decide whether the current
        user can ' . 'access an activity.', DEBUG_DEVELOPER);
858
}
859

860
/**
861
 * @deprecated since 2.0
862
 */
863
function error($message, $link='') {
864
    throw new coding_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a removed, please call
865
            print_error() instead of error()');
866
}
867
868


869
870
871
872
/**
 * @deprecated use $PAGE->theme->name instead.
 */
function current_theme() {
873
    throw new coding_exception('current_theme() can not be used any more, please use $PAGE->theme->name instead');
874
875
}

876
877
878
879
/**
 * @deprecated
 */
function formerr($error) {
880
    throw new coding_exception('formerr() is removed. Please change your code to use $OUTPUT->error_text($string).');
881
882
}

883
884
885
886
/**
 * @deprecated use $OUTPUT->skip_link_target() in instead.
 */
function skip_main_destination() {
887
    throw new coding_exception('skip_main_destination() can not be used any more, please use $OUTPUT->skip_link_target() instead.');
888
889
890
}

/**
891
 * @deprecated use $OUTPUT->container() instead.
892
893
 */
function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
894
    throw new coding_exception('print_container() can not be used any more. Please use $OUTPUT->container() instead.');
895
896
897
}

/**
898
 * @deprecated use $OUTPUT->container_start() instead.
899
900
 */
function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
901
    throw new coding_exception('print_container_start() can not be used any more. Please use $OUTPUT->container_start() instead.');
902
903
904
}

/**
905
 * @deprecated use $OUTPUT->container_end() instead.
906
907
 */
function print_container_end($return=false) {
908
    throw new coding_exception('print_container_end() can not be used any more. Please use $OUTPUT->container_end() instead.');
909
910
911
912
913
}

/**
 * Print a bold message in an optional color.
 *
914
 * @deprecated since Moodle 2.0 MDL-19077 - use $OUTPUT->notification instead.
915
 * @todo MDL-50469 This will be deleted in Moodle 3.3.
916
 * @param string $message The message to print out
917
 * @param string $classes Optional style to display message text in
918
919
 * @param string $align Alignment option
 * @param bool $return whether to return an output string or echo now
920
 * @return string|bool Depending on $result
921
 */
922
function notify($message, $classes = 'error', $align = 'center', $return = false) {
923
924
    global $OUTPUT;

925
926
    debugging('notify() is deprecated, please use $OUTPUT->notification() instead', DEBUG_DEVELOPER);

927
    if ($classes == 'green') {
928
929
        debugging('Use of deprecated class name "green" in notify. Please change to "success".', DEBUG_DEVELOPER);
        $classes = 'success'; // Backward compatible with old color system.
930
931
932
933
934
935
936
937
938
939
940
    }

    $output = $OUTPUT->notification($message, $classes);
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}

/**
941
 * @deprecated use $OUTPUT->continue_button() instead.
942
943
 */
function print_continue($link, $return = false) {
944
    throw new coding_exception('print_continue() can not be used any more. Please use $OUTPUT->continue_button() instead.');
945
946
947
}

/**
948
 * @deprecated use $PAGE methods instead.
949
950
 */
function print_header($title='', $heading='', $navigation='', $focus='',
951
                      $meta='', $cache=true, $button='&nbsp;', $menu=null,
952
953
                      $usexml=false, $bodytags='', $return=false) {

954
    throw new coding_exception('print_header() can not be used any more. Please use $PAGE methods instead.');
955
956
}

957
/**
958
 * @deprecated use $PAGE methods instead.
959
960
961
962
 */
function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
                       $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {

963
    throw new coding_exception('print_header_simple() can not be used any more. Please use $PAGE methods instead.');
964
965
}

966
/**
967
 * @deprecated use $OUTPUT->block() instead.
968
969
 */
function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
970
    throw new coding_exception('print_side_block() can not be used any more, please use $OUTPUT->block() instead.');
971
972
}

973
974
975
976
977
978
979
980
/**
 * Prints a basic textarea field.
 *
 * @deprecated since Moodle 2.0
 *
 * When using this function, you should
 *
 * @global object
981
 * @param bool $unused No longer used.
982
983
984
985
986
987
988
989
990
991
992
 * @param int $rows Number of rows to display  (minimum of 10 when $height is non-null)
 * @param int $cols Number of columns to display (minimum of 65 when $width is non-null)
 * @param null $width (Deprecated) Width of the element; if a value is passed, the minimum value for $cols will be 65. Value is otherwise ignored.
 * @param null $height (Deprecated) Height of the element; if a value is passe, the minimum value for $rows will be 10. Value is otherwise ignored.
 * @param string $name Name to use for the textarea element.
 * @param string $value Initial content to display in the textarea.
 * @param int $obsolete deprecated
 * @param bool $return If false, will output string. If true, will return string value.
 * @param string $id CSS ID to add to the textarea element.
 * @return string|void depending on the value of $return
 */
993
function print_textarea($unused, $rows, $cols, $width, $height, $name, $value='', $obsolete=0, $return=false, $id='') {
994
995
996
    /// $width and height are legacy fields and no longer used as pixels like they used to be.
    /// However, you can set them to zero to override the mincols and minrows values below.

997
998
    // Disabling because there is not yet a viable $OUTPUT option for cases when mforms can't be used
    // debugging('print_textarea() has been deprecated. You should be using mforms and the editor element.');
999
1000

    global $CFG;
For faster browsing, not all history is shown. View entire blame