PageRenderTime 62ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/deprecatedlib.php

https://bitbucket.org/kudutest1/moodlegit
PHP | 1518 lines | 659 code | 170 blank | 689 comment | 119 complexity | 5c0cfc61fdebe8cbaa6433843b865c21 MD5 | raw file
  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. * deprecatedlib.php - Old functions retained only for backward compatibility
  18. *
  19. * Old functions retained only for backward compatibility. New code should not
  20. * use any of these functions.
  21. *
  22. * @package core
  23. * @subpackage deprecated
  24. * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
  25. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26. * @deprecated
  27. */
  28. defined('MOODLE_INTERNAL') || die();
  29. /**
  30. * Hack to find out the GD version by parsing phpinfo output
  31. *
  32. * @return int GD version (1, 2, or 0)
  33. */
  34. function check_gd_version() {
  35. // TODO: delete function in Moodle 2.7
  36. debugging('check_gd_version() is deprecated, GD extension is always available now');
  37. $gdversion = 0;
  38. if (function_exists('gd_info')){
  39. $gd_info = gd_info();
  40. if (substr_count($gd_info['GD Version'], '2.')) {
  41. $gdversion = 2;
  42. } else if (substr_count($gd_info['GD Version'], '1.')) {
  43. $gdversion = 1;
  44. }
  45. } else {
  46. ob_start();
  47. phpinfo(INFO_MODULES);
  48. $phpinfo = ob_get_contents();
  49. ob_end_clean();
  50. $phpinfo = explode("\n", $phpinfo);
  51. foreach ($phpinfo as $text) {
  52. $parts = explode('</td>', $text);
  53. foreach ($parts as $key => $val) {
  54. $parts[$key] = trim(strip_tags($val));
  55. }
  56. if ($parts[0] == 'GD Version') {
  57. if (substr_count($parts[1], '2.0')) {
  58. $parts[1] = '2.0';
  59. }
  60. $gdversion = intval($parts[1]);
  61. }
  62. }
  63. }
  64. return $gdversion; // 1, 2 or 0
  65. }
  66. /**
  67. * Not used any more, the account lockout handling is now
  68. * part of authenticate_user_login().
  69. * @deprecated
  70. */
  71. function update_login_count() {
  72. // TODO: delete function in Moodle 2.6
  73. debugging('update_login_count() is deprecated, all calls need to be removed');
  74. }
  75. /**
  76. * Not used any more, replaced by proper account lockout.
  77. * @deprecated
  78. */
  79. function reset_login_count() {
  80. // TODO: delete function in Moodle 2.6
  81. debugging('reset_login_count() is deprecated, all calls need to be removed');
  82. }
  83. /**
  84. * Unsupported session id rewriting.
  85. * @deprecated
  86. * @param string $buffer
  87. */
  88. function sid_ob_rewrite($buffer) {
  89. throw new coding_exception('$CFG->usesid support was removed completely and can not be used.');
  90. }
  91. /**
  92. * Insert or update log display entry. Entry may already exist.
  93. * $module, $action must be unique
  94. * @deprecated
  95. *
  96. * @param string $module
  97. * @param string $action
  98. * @param string $mtable
  99. * @param string $field
  100. * @return void
  101. *
  102. */
  103. function update_log_display_entry($module, $action, $mtable, $field) {
  104. global $DB;
  105. debugging('The update_log_display_entry() is deprecated, please use db/log.php description file instead.');
  106. }
  107. /**
  108. * Given some text in HTML format, this function will pass it
  109. * through any filters that have been configured for this context.
  110. *
  111. * @deprecated use the text formatting in a standard way instead,
  112. * this was abused mostly for embedding of attachments
  113. *
  114. * @param string $text The text to be passed through format filters
  115. * @param int $courseid The current course.
  116. * @return string the filtered string.
  117. */
  118. function filter_text($text, $courseid = NULL) {
  119. global $CFG, $COURSE;
  120. if (!$courseid) {
  121. $courseid = $COURSE->id;
  122. }
  123. if (!$context = context_course::instance($courseid, IGNORE_MISSING)) {
  124. return $text;
  125. }
  126. return filter_manager::instance()->filter_text($text, $context);
  127. }
  128. /**
  129. * This function indicates that current page requires the https
  130. * when $CFG->loginhttps enabled.
  131. *
  132. * By using this function properly, we can ensure 100% https-ized pages
  133. * at our entire discretion (login, forgot_password, change_password)
  134. * @deprecated use $PAGE->https_required() instead
  135. */
  136. function httpsrequired() {
  137. global $PAGE;
  138. $PAGE->https_required();
  139. }
  140. /**
  141. * Given a physical path to a file, returns the URL through which it can be reached in Moodle.
  142. *
  143. * @deprecated use moodle_url factory methods instead
  144. *
  145. * @param string $path Physical path to a file
  146. * @param array $options associative array of GET variables to append to the URL
  147. * @param string $type (questionfile|rssfile|httpscoursefile|coursefile)
  148. * @return string URL to file
  149. */
  150. function get_file_url($path, $options=null, $type='coursefile') {
  151. global $CFG;
  152. $path = str_replace('//', '/', $path);
  153. $path = trim($path, '/'); // no leading and trailing slashes
  154. // type of file
  155. switch ($type) {
  156. case 'questionfile':
  157. $url = $CFG->wwwroot."/question/exportfile.php";
  158. break;
  159. case 'rssfile':
  160. $url = $CFG->wwwroot."/rss/file.php";
  161. break;
  162. case 'httpscoursefile':
  163. $url = $CFG->httpswwwroot."/file.php";
  164. break;
  165. case 'coursefile':
  166. default:
  167. $url = $CFG->wwwroot."/file.php";
  168. }
  169. if ($CFG->slasharguments) {
  170. $parts = explode('/', $path);
  171. foreach ($parts as $key => $part) {
  172. /// anchor dash character should not be encoded
  173. $subparts = explode('#', $part);
  174. $subparts = array_map('rawurlencode', $subparts);
  175. $parts[$key] = implode('#', $subparts);
  176. }
  177. $path = implode('/', $parts);
  178. $ffurl = $url.'/'.$path;
  179. $separator = '?';
  180. } else {
  181. $path = rawurlencode('/'.$path);
  182. $ffurl = $url.'?file='.$path;
  183. $separator = '&amp;';
  184. }
  185. if ($options) {
  186. foreach ($options as $name=>$value) {
  187. $ffurl = $ffurl.$separator.$name.'='.$value;
  188. $separator = '&amp;';
  189. }
  190. }
  191. return $ffurl;
  192. }
  193. /**
  194. * If there has been an error uploading a file, print the appropriate error message
  195. * Numerical constants used as constant definitions not added until PHP version 4.2.0
  196. * @deprecated removed - use new file api
  197. */
  198. function print_file_upload_error($filearray = '', $returnerror = false) {
  199. throw new coding_exception('print_file_upload_error() can not be used any more, please use new file API');
  200. }
  201. /**
  202. * Handy function for resolving file conflicts
  203. * @deprecated removed - use new file api
  204. */
  205. function resolve_filename_collisions($destination,$files,$format='%s_%d.%s') {
  206. throw new coding_exception('resolve_filename_collisions() can not be used any more, please use new file API');
  207. }
  208. /**
  209. * Checks a file name for any conflicts
  210. * @deprecated removed - use new file api
  211. */
  212. function check_potential_filename($destination,$filename,$files) {
  213. throw new coding_exception('check_potential_filename() can not be used any more, please use new file API');
  214. }
  215. /**
  216. * This function prints out a number of upload form elements.
  217. * @deprecated removed - use new file api
  218. */
  219. function upload_print_form_fragment($numfiles=1, $names=null, $descriptions=null, $uselabels=false, $labelnames=null, $coursebytes=0, $modbytes=0, $return=false) {
  220. throw new coding_exception('upload_print_form_fragment() can not be used any more, please use new file API');
  221. }
  222. /**
  223. * Return the authentication plugin title
  224. *
  225. * @param string $authtype plugin type
  226. * @return string
  227. */
  228. function auth_get_plugin_title($authtype) {
  229. debugging('Function auth_get_plugin_title() is deprecated, please use standard get_string("pluginname", "auth_'.$authtype.'")!');
  230. return get_string('pluginname', "auth_{$authtype}");
  231. }
  232. /**
  233. * Enrol someone without using the default role in a course
  234. * @deprecated
  235. */
  236. function enrol_into_course($course, $user, $enrol) {
  237. error('Function enrol_into_course() was removed, please use new enrol plugins instead!');
  238. }
  239. /**
  240. * Returns a role object that is the default role for new enrolments in a given course
  241. *
  242. * @deprecated
  243. * @param object $course
  244. * @return object returns a role or NULL if none set
  245. */
  246. function get_default_course_role($course) {
  247. debugging('Function get_default_course_role() is deprecated, please use individual enrol plugin settings instead!');
  248. $student = get_archetype_roles('student');
  249. $student = reset($student);
  250. return $student;
  251. }
  252. /**
  253. * Extremely slow enrolled courses query.
  254. * @deprecated
  255. */
  256. function get_my_courses($userid, $sort='visible DESC,sortorder ASC', $fields=NULL, $doanything=false,$limit=0) {
  257. error('Function get_my_courses() was removed, please use new enrol_get_my_courses() or enrol_get_users_courses()!');
  258. }
  259. /**
  260. * Was returning list of translations, use new string_manager instead
  261. *
  262. * @deprecated
  263. * @param bool $refreshcache force refreshing of lang cache
  264. * @param bool $returnall ignore langlist, return all languages available
  265. * @return array An associative array with contents in the form of LanguageCode => LanguageName
  266. */
  267. function get_list_of_languages($refreshcache=false, $returnall=false) {
  268. debugging('get_list_of_languages() is deprecated, please use get_string_manager()->get_list_of_translations() instead.');
  269. if ($refreshcache) {
  270. get_string_manager()->reset_caches();
  271. }
  272. return get_string_manager()->get_list_of_translations($returnall);
  273. }
  274. /**
  275. * Returns a list of currencies in the current language
  276. * @deprecated
  277. * @return array
  278. */
  279. function get_list_of_currencies() {
  280. debugging('get_list_of_currencies() is deprecated, please use get_string_manager()->get_list_of_currencies() instead.');
  281. return get_string_manager()->get_list_of_currencies();
  282. }
  283. /**
  284. * Returns a list of all enabled country names in the current translation
  285. * @deprecated
  286. * @return array two-letter country code => translated name.
  287. */
  288. function get_list_of_countries() {
  289. debugging('get_list_of_countries() is deprecated, please use get_string_manager()->get_list_of_countries() instead.');
  290. return get_string_manager()->get_list_of_countries(false);
  291. }
  292. /**
  293. * @deprecated
  294. */
  295. function isteacher() {
  296. error('Function isteacher() was removed, please use capabilities instead!');
  297. }
  298. /**
  299. * @deprecated
  300. */
  301. function isteacherinanycourse() {
  302. throw new coding_Exception('Function isteacherinanycourse() was removed, please use capabilities instead!');
  303. }
  304. /**
  305. * @deprecated
  306. */
  307. function get_guest() {
  308. throw new coding_Exception('Function get_guest() was removed, please use capabilities instead!');
  309. }
  310. /**
  311. * @deprecated
  312. */
  313. function isguest() {
  314. throw new coding_Exception('Function isguest() was removed, please use capabilities instead!');
  315. }
  316. /**
  317. * @deprecated
  318. */
  319. function get_teacher() {
  320. throw new coding_Exception('Function get_teacher() was removed, please use capabilities instead!');
  321. }
  322. /**
  323. * Return all course participant for a given course
  324. *
  325. * @deprecated
  326. * @param integer $courseid
  327. * @return array of user
  328. */
  329. function get_course_participants($courseid) {
  330. return get_enrolled_users(context_course::instance($courseid));
  331. }
  332. /**
  333. * Return true if the user is a participant for a given course
  334. *
  335. * @deprecated
  336. * @param integer $userid
  337. * @param integer $courseid
  338. * @return boolean
  339. */
  340. function is_course_participant($userid, $courseid) {
  341. return is_enrolled(context_course::instance($courseid), $userid);
  342. }
  343. /**
  344. * Searches logs to find all enrolments since a certain date
  345. *
  346. * used to print recent activity
  347. *
  348. * @todo MDL-36993 this function is still used in block_recent_activity, deprecate properly
  349. * @global object
  350. * @uses CONTEXT_COURSE
  351. * @param int $courseid The course in question.
  352. * @param int $timestart The date to check forward of
  353. * @return object|false {@link $USER} records or false if error.
  354. */
  355. function get_recent_enrolments($courseid, $timestart) {
  356. global $DB;
  357. $context = context_course::instance($courseid);
  358. $sql = "SELECT u.id, u.firstname, u.lastname, MAX(l.time)
  359. FROM {user} u, {role_assignments} ra, {log} l
  360. WHERE l.time > ?
  361. AND l.course = ?
  362. AND l.module = 'course'
  363. AND l.action = 'enrol'
  364. AND ".$DB->sql_cast_char2int('l.info')." = u.id
  365. AND u.id = ra.userid
  366. AND ra.contextid ".get_related_contexts_string($context)."
  367. GROUP BY u.id, u.firstname, u.lastname
  368. ORDER BY MAX(l.time) ASC";
  369. $params = array($timestart, $courseid);
  370. return $DB->get_records_sql($sql, $params);
  371. }
  372. /**
  373. * Turn the ctx* fields in an objectlike record into a context subobject
  374. * This allows us to SELECT from major tables JOINing with
  375. * context at no cost, saving a ton of context lookups...
  376. *
  377. * Use context_instance_preload() instead.
  378. *
  379. * @deprecated since 2.0
  380. * @param object $rec
  381. * @return object
  382. */
  383. function make_context_subobj($rec) {
  384. throw new coding_Exception('make_context_subobj() was removed, use new context preloading');
  385. }
  386. /**
  387. * Do some basic, quick checks to see whether $rec->context looks like a valid context object.
  388. *
  389. * Use context_instance_preload() instead.
  390. *
  391. * @deprecated since 2.0
  392. * @param object $rec a think that has a context, for example a course,
  393. * course category, course modules, etc.
  394. * @param int $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
  395. * @return bool whether $rec->context looks like the correct context object
  396. * for this thing.
  397. */
  398. function is_context_subobj_valid($rec, $contextlevel) {
  399. throw new coding_Exception('is_context_subobj_valid() was removed, use new context preloading');
  400. }
  401. /**
  402. * Ensure that $rec->context is present and correct before you continue
  403. *
  404. * When you have a record (for example a $category, $course, $user or $cm that may,
  405. * or may not, have come from a place that does make_context_subobj, you can use
  406. * this method to ensure that $rec->context is present and correct before you continue.
  407. *
  408. * Use context_instance_preload() instead.
  409. *
  410. * @deprecated since 2.0
  411. * @param object $rec a thing that has an associated context.
  412. * @param integer $contextlevel the type of thing $rec is, one of the CONTEXT_... constants.
  413. */
  414. function ensure_context_subobj_present(&$rec, $contextlevel) {
  415. throw new coding_Exception('ensure_context_subobj_present() was removed, use new context preloading');
  416. }
  417. ########### FROM weblib.php ##########################################################################
  418. /**
  419. * Print a message in a standard themed box.
  420. * This old function used to implement boxes using tables. Now it uses a DIV, but the old
  421. * parameters remain. If possible, $align, $width and $color should not be defined at all.
  422. * Preferably just use print_box() in weblib.php
  423. *
  424. * @deprecated
  425. * @param string $message The message to display
  426. * @param string $align alignment of the box, not the text (default center, left, right).
  427. * @param string $width width of the box, including units %, for example '100%'.
  428. * @param string $color background colour of the box, for example '#eee'.
  429. * @param int $padding padding in pixels, specified without units.
  430. * @param string $class space-separated class names.
  431. * @param string $id space-separated id names.
  432. * @param boolean $return return as string or just print it
  433. * @return string|void Depending on $return
  434. */
  435. function print_simple_box($message, $align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
  436. $output = '';
  437. $output .= print_simple_box_start($align, $width, $color, $padding, $class, $id, true);
  438. $output .= $message;
  439. $output .= print_simple_box_end(true);
  440. if ($return) {
  441. return $output;
  442. } else {
  443. echo $output;
  444. }
  445. }
  446. /**
  447. * This old function used to implement boxes using tables. Now it uses a DIV, but the old
  448. * parameters remain. If possible, $align, $width and $color should not be defined at all.
  449. * Even better, please use print_box_start() in weblib.php
  450. *
  451. * @param string $align alignment of the box, not the text (default center, left, right). DEPRECATED
  452. * @param string $width width of the box, including % units, for example '100%'. DEPRECATED
  453. * @param string $color background colour of the box, for example '#eee'. DEPRECATED
  454. * @param int $padding padding in pixels, specified without units. OBSOLETE
  455. * @param string $class space-separated class names.
  456. * @param string $id space-separated id names.
  457. * @param boolean $return return as string or just print it
  458. * @return string|void Depending on $return
  459. */
  460. function print_simple_box_start($align='', $width='', $color='', $padding=5, $class='generalbox', $id='', $return=false) {
  461. debugging('print_simple_box(_start/_end) is deprecated. Please use $OUTPUT->box(_start/_end) instead', DEBUG_DEVELOPER);
  462. $output = '';
  463. $divclasses = 'box '.$class.' '.$class.'content';
  464. $divstyles = '';
  465. if ($align) {
  466. $divclasses .= ' boxalign'.$align; // Implement alignment using a class
  467. }
  468. if ($width) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
  469. if (substr($width, -1, 1) == '%') { // Width is a % value
  470. $width = (int) substr($width, 0, -1); // Extract just the number
  471. if ($width < 40) {
  472. $divclasses .= ' boxwidthnarrow'; // Approx 30% depending on theme
  473. } else if ($width > 60) {
  474. $divclasses .= ' boxwidthwide'; // Approx 80% depending on theme
  475. } else {
  476. $divclasses .= ' boxwidthnormal'; // Approx 50% depending on theme
  477. }
  478. } else {
  479. $divstyles .= ' width:'.$width.';'; // Last resort
  480. }
  481. }
  482. if ($color) { // Hopefully we can eliminate these in calls to this function (inline styles are bad)
  483. $divstyles .= ' background:'.$color.';';
  484. }
  485. if ($divstyles) {
  486. $divstyles = ' style="'.$divstyles.'"';
  487. }
  488. if ($id) {
  489. $id = ' id="'.$id.'"';
  490. }
  491. $output .= '<div'.$id.$divstyles.' class="'.$divclasses.'">';
  492. if ($return) {
  493. return $output;
  494. } else {
  495. echo $output;
  496. }
  497. }
  498. /**
  499. * Print the end portion of a standard themed box.
  500. * Preferably just use print_box_end() in weblib.php
  501. *
  502. * @param boolean $return return as string or just print it
  503. * @return string|void Depending on $return
  504. */
  505. function print_simple_box_end($return=false) {
  506. $output = '</div>';
  507. if ($return) {
  508. return $output;
  509. } else {
  510. echo $output;
  511. }
  512. }
  513. /**
  514. * Given some text this function converted any URLs it found into HTML links
  515. *
  516. * This core function has been replaced with filter_urltolink since Moodle 2.0
  517. *
  518. * @param string $text Passed in by reference. The string to be searched for urls.
  519. */
  520. function convert_urls_into_links($text) {
  521. debugging('convert_urls_into_links() has been deprecated and replaced by a new filter');
  522. }
  523. /**
  524. * Used to be called from help.php to inject a list of smilies into the
  525. * emoticons help file.
  526. *
  527. * @return string HTML
  528. */
  529. function get_emoticons_list_for_help_file() {
  530. debugging('get_emoticons_list_for_help_file() has been deprecated, see the new emoticon_manager API');
  531. return '';
  532. }
  533. /**
  534. * Was used to replace all known smileys in the text with image equivalents
  535. *
  536. * This core function has been replaced with filter_emoticon since Moodle 2.0
  537. */
  538. function replace_smilies(&$text) {
  539. debugging('replace_smilies() has been deprecated and replaced with the new filter_emoticon');
  540. }
  541. /**
  542. * deprecated - use clean_param($string, PARAM_FILE); instead
  543. * Check for bad characters ?
  544. *
  545. * @todo Finish documenting this function - more detail needed in description as well as details on arguments
  546. *
  547. * @param string $string ?
  548. * @param int $allowdots ?
  549. * @return bool
  550. */
  551. function detect_munged_arguments($string, $allowdots=1) {
  552. if (substr_count($string, '..') > $allowdots) { // Sometimes we allow dots in references
  553. return true;
  554. }
  555. if (preg_match('/[\|\`]/', $string)) { // check for other bad characters
  556. return true;
  557. }
  558. if (empty($string) or $string == '/') {
  559. return true;
  560. }
  561. return false;
  562. }
  563. /**
  564. * Unzip one zip file to a destination dir
  565. * Both parameters must be FULL paths
  566. * If destination isn't specified, it will be the
  567. * SAME directory where the zip file resides.
  568. *
  569. * @global object
  570. * @param string $zipfile The zip file to unzip
  571. * @param string $destination The location to unzip to
  572. * @param bool $showstatus_ignored Unused
  573. */
  574. function unzip_file($zipfile, $destination = '', $showstatus_ignored = true) {
  575. global $CFG;
  576. //Extract everything from zipfile
  577. $path_parts = pathinfo(cleardoubleslashes($zipfile));
  578. $zippath = $path_parts["dirname"]; //The path of the zip file
  579. $zipfilename = $path_parts["basename"]; //The name of the zip file
  580. $extension = $path_parts["extension"]; //The extension of the file
  581. //If no file, error
  582. if (empty($zipfilename)) {
  583. return false;
  584. }
  585. //If no extension, error
  586. if (empty($extension)) {
  587. return false;
  588. }
  589. //Clear $zipfile
  590. $zipfile = cleardoubleslashes($zipfile);
  591. //Check zipfile exists
  592. if (!file_exists($zipfile)) {
  593. return false;
  594. }
  595. //If no destination, passed let's go with the same directory
  596. if (empty($destination)) {
  597. $destination = $zippath;
  598. }
  599. //Clear $destination
  600. $destpath = rtrim(cleardoubleslashes($destination), "/");
  601. //Check destination path exists
  602. if (!is_dir($destpath)) {
  603. return false;
  604. }
  605. $packer = get_file_packer('application/zip');
  606. $result = $packer->extract_to_pathname($zipfile, $destpath);
  607. if ($result === false) {
  608. return false;
  609. }
  610. foreach ($result as $status) {
  611. if ($status !== true) {
  612. return false;
  613. }
  614. }
  615. return true;
  616. }
  617. /**
  618. * Zip an array of files/dirs to a destination zip file
  619. * Both parameters must be FULL paths to the files/dirs
  620. *
  621. * @global object
  622. * @param array $originalfiles Files to zip
  623. * @param string $destination The destination path
  624. * @return bool Outcome
  625. */
  626. function zip_files ($originalfiles, $destination) {
  627. global $CFG;
  628. //Extract everything from destination
  629. $path_parts = pathinfo(cleardoubleslashes($destination));
  630. $destpath = $path_parts["dirname"]; //The path of the zip file
  631. $destfilename = $path_parts["basename"]; //The name of the zip file
  632. $extension = $path_parts["extension"]; //The extension of the file
  633. //If no file, error
  634. if (empty($destfilename)) {
  635. return false;
  636. }
  637. //If no extension, add it
  638. if (empty($extension)) {
  639. $extension = 'zip';
  640. $destfilename = $destfilename.'.'.$extension;
  641. }
  642. //Check destination path exists
  643. if (!is_dir($destpath)) {
  644. return false;
  645. }
  646. //Check destination path is writable. TODO!!
  647. //Clean destination filename
  648. $destfilename = clean_filename($destfilename);
  649. //Now check and prepare every file
  650. $files = array();
  651. $origpath = NULL;
  652. foreach ($originalfiles as $file) { //Iterate over each file
  653. //Check for every file
  654. $tempfile = cleardoubleslashes($file); // no doubleslashes!
  655. //Calculate the base path for all files if it isn't set
  656. if ($origpath === NULL) {
  657. $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/");
  658. }
  659. //See if the file is readable
  660. if (!is_readable($tempfile)) { //Is readable
  661. continue;
  662. }
  663. //See if the file/dir is in the same directory than the rest
  664. if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) {
  665. continue;
  666. }
  667. //Add the file to the array
  668. $files[] = $tempfile;
  669. }
  670. $zipfiles = array();
  671. $start = strlen($origpath)+1;
  672. foreach($files as $file) {
  673. $zipfiles[substr($file, $start)] = $file;
  674. }
  675. $packer = get_file_packer('application/zip');
  676. return $packer->archive_to_pathname($zipfiles, $destpath . '/' . $destfilename);
  677. }
  678. /////////////////////////////////////////////////////////////
  679. /// Old functions not used anymore - candidates for removal
  680. /////////////////////////////////////////////////////////////
  681. /** various deprecated groups function **/
  682. /**
  683. * Get the IDs for the user's groups in the given course.
  684. *
  685. * @global object
  686. * @param int $courseid The course being examined - the 'course' table id field.
  687. * @return array|bool An _array_ of groupids, or false
  688. * (Was return $groupids[0] - consequences!)
  689. */
  690. function mygroupid($courseid) {
  691. global $USER;
  692. if ($groups = groups_get_all_groups($courseid, $USER->id)) {
  693. return array_keys($groups);
  694. } else {
  695. return false;
  696. }
  697. }
  698. /**
  699. * Returns the current group mode for a given course or activity module
  700. *
  701. * Could be false, SEPARATEGROUPS or VISIBLEGROUPS (<-- Martin)
  702. *
  703. * @param object $course Course Object
  704. * @param object $cm Course Manager Object
  705. * @return mixed $course->groupmode
  706. */
  707. function groupmode($course, $cm=null) {
  708. if (isset($cm->groupmode) && empty($course->groupmodeforce)) {
  709. return $cm->groupmode;
  710. }
  711. return $course->groupmode;
  712. }
  713. /**
  714. * Sets the current group in the session variable
  715. * When $SESSION->currentgroup[$courseid] is set to 0 it means, show all groups.
  716. * Sets currentgroup[$courseid] in the session variable appropriately.
  717. * Does not do any permission checking.
  718. *
  719. * @global object
  720. * @param int $courseid The course being examined - relates to id field in
  721. * 'course' table.
  722. * @param int $groupid The group being examined.
  723. * @return int Current group id which was set by this function
  724. */
  725. function set_current_group($courseid, $groupid) {
  726. global $SESSION;
  727. return $SESSION->currentgroup[$courseid] = $groupid;
  728. }
  729. /**
  730. * Gets the current group - either from the session variable or from the database.
  731. *
  732. * @global object
  733. * @param int $courseid The course being examined - relates to id field in
  734. * 'course' table.
  735. * @param bool $full If true, the return value is a full record object.
  736. * If false, just the id of the record.
  737. * @return int|bool
  738. */
  739. function get_current_group($courseid, $full = false) {
  740. global $SESSION;
  741. if (isset($SESSION->currentgroup[$courseid])) {
  742. if ($full) {
  743. return groups_get_group($SESSION->currentgroup[$courseid]);
  744. } else {
  745. return $SESSION->currentgroup[$courseid];
  746. }
  747. }
  748. $mygroupid = mygroupid($courseid);
  749. if (is_array($mygroupid)) {
  750. $mygroupid = array_shift($mygroupid);
  751. set_current_group($courseid, $mygroupid);
  752. if ($full) {
  753. return groups_get_group($mygroupid);
  754. } else {
  755. return $mygroupid;
  756. }
  757. }
  758. if ($full) {
  759. return false;
  760. } else {
  761. return 0;
  762. }
  763. }
  764. /**
  765. * Inndicates fatal error. This function was originally printing the
  766. * error message directly, since 2.0 it is throwing exception instead.
  767. * The error printing is handled in default exception handler.
  768. *
  769. * Old method, don't call directly in new code - use print_error instead.
  770. *
  771. * @param string $message The message to display to the user about the error.
  772. * @param string $link The url where the user will be prompted to continue. If no url is provided the user will be directed to the site index page.
  773. * @return void, always throws moodle_exception
  774. */
  775. function error($message, $link='') {
  776. throw new moodle_exception('notlocalisederrormessage', 'error', $link, $message, 'error() is a deprecated function, please call print_error() instead of error()');
  777. }
  778. //////////////////////////
  779. /// removed functions ////
  780. //////////////////////////
  781. /**
  782. * @deprecated
  783. * @param mixed $name
  784. * @param mixed $editorhidebuttons
  785. * @param mixed $id
  786. * @return void Throws an error and does nothing
  787. */
  788. function use_html_editor($name='', $editorhidebuttons='', $id='') {
  789. error('use_html_editor() not available anymore');
  790. }
  791. /**
  792. * The old method that was used to include JavaScript libraries.
  793. * Please use $PAGE->requires->js_module() instead.
  794. *
  795. * @param mixed $lib The library or libraries to load (a string or array of strings)
  796. * There are three way to specify the library:
  797. * 1. a shorname like 'yui_yahoo'. This translates into a call to $PAGE->requires->yui2_lib('yahoo');
  798. * 2. the path to the library relative to wwwroot, for example 'lib/javascript-static.js'
  799. * 3. (legacy) a full URL like $CFG->wwwroot . '/lib/javascript-static.js'.
  800. * 2. and 3. lead to a call $PAGE->requires->js('/lib/javascript-static.js').
  801. */
  802. function require_js($lib) {
  803. throw new coding_exception('require_js() was removed, use new JS api');
  804. }
  805. /**
  806. * Makes an upload directory for a particular module.
  807. *
  808. * This function has been deprecated by the file API changes in Moodle 2.0.
  809. *
  810. * @deprecated
  811. * @param int $courseid The id of the course in question - maps to id field of 'course' table.
  812. * @return string|false Returns full path to directory if successful, false if not
  813. */
  814. function make_mod_upload_directory($courseid) {
  815. throw new coding_exception('make_mod_upload_directory has been deprecated by the file API changes in Moodle 2.0.');
  816. }
  817. /**
  818. * Used to be used for setting up the theme. No longer used by core code, and
  819. * should not have been used elsewhere.
  820. *
  821. * The theme is now automatically initialised before it is first used. If you really need
  822. * to force this to happen, just reference $PAGE->theme.
  823. *
  824. * To force a particular theme on a particular page, you can use $PAGE->force_theme(...).
  825. * However, I can't think of any valid reason to do that outside the theme selector UI.
  826. *
  827. * @deprecated
  828. * @param string $theme The theme to use defaults to current theme
  829. * @param array $params An array of parameters to use
  830. */
  831. function theme_setup($theme = '', $params=NULL) {
  832. throw new coding_exception('The function theme_setup is no longer required, and should no longer be used. ' .
  833. 'The current theme gets initialised automatically before it is first used.');
  834. }
  835. /**
  836. * @deprecated use $PAGE->theme->name instead.
  837. * @return string the name of the current theme.
  838. */
  839. function current_theme() {
  840. global $PAGE;
  841. // TODO, uncomment this once we have eliminated all references to current_theme in core code.
  842. // debugging('current_theme is deprecated, use $PAGE->theme->name instead', DEBUG_DEVELOPER);
  843. return $PAGE->theme->name;
  844. }
  845. /**
  846. * Prints some red text using echo
  847. *
  848. * @deprecated
  849. * @param string $error The text to be displayed in red
  850. */
  851. function formerr($error) {
  852. debugging('formerr() has been deprecated. Please change your code to use $OUTPUT->error_text($string).');
  853. global $OUTPUT;
  854. echo $OUTPUT->error_text($error);
  855. }
  856. /**
  857. * Return the markup for the destination of the 'Skip to main content' links.
  858. * Accessibility improvement for keyboard-only users.
  859. *
  860. * Used in course formats, /index.php and /course/index.php
  861. *
  862. * @deprecated use $OUTPUT->skip_link_target() in instead.
  863. * @return string HTML element.
  864. */
  865. function skip_main_destination() {
  866. global $OUTPUT;
  867. return $OUTPUT->skip_link_target();
  868. }
  869. /**
  870. * Prints a string in a specified size (retained for backward compatibility)
  871. *
  872. * @deprecated
  873. * @param string $text The text to be displayed
  874. * @param int $size The size to set the font for text display.
  875. * @param bool $return If set to true output is returned rather than echoed Default false
  876. * @return string|void String if return is true
  877. */
  878. function print_headline($text, $size=2, $return=false) {
  879. global $OUTPUT;
  880. debugging('print_headline() has been deprecated. Please change your code to use $OUTPUT->heading().');
  881. $output = $OUTPUT->heading($text, $size);
  882. if ($return) {
  883. return $output;
  884. } else {
  885. echo $output;
  886. }
  887. }
  888. /**
  889. * Prints text in a format for use in headings.
  890. *
  891. * @deprecated
  892. * @param string $text The text to be displayed
  893. * @param string $deprecated No longer used. (Use to do alignment.)
  894. * @param int $size The size to set the font for text display.
  895. * @param string $class
  896. * @param bool $return If set to true output is returned rather than echoed, default false
  897. * @param string $id The id to use in the element
  898. * @return string|void String if return=true nothing otherwise
  899. */
  900. function print_heading($text, $deprecated = '', $size = 2, $class = 'main', $return = false, $id = '') {
  901. global $OUTPUT;
  902. debugging('print_heading() has been deprecated. Please change your code to use $OUTPUT->heading().');
  903. if (!empty($deprecated)) {
  904. debugging('Use of deprecated align attribute of print_heading. ' .
  905. 'Please do not specify styling in PHP code like that.', DEBUG_DEVELOPER);
  906. }
  907. $output = $OUTPUT->heading($text, $size, $class, $id);
  908. if ($return) {
  909. return $output;
  910. } else {
  911. echo $output;
  912. }
  913. }
  914. /**
  915. * Output a standard heading block
  916. *
  917. * @deprecated
  918. * @param string $heading The text to write into the heading
  919. * @param string $class An additional Class Attr to use for the heading
  920. * @param bool $return If set to true output is returned rather than echoed, default false
  921. * @return string|void HTML String if return=true nothing otherwise
  922. */
  923. function print_heading_block($heading, $class='', $return=false) {
  924. global $OUTPUT;
  925. debugging('print_heading_with_block() has been deprecated. Please change your code to use $OUTPUT->heading().');
  926. $output = $OUTPUT->heading($heading, 2, 'headingblock header ' . renderer_base::prepare_classes($class));
  927. if ($return) {
  928. return $output;
  929. } else {
  930. echo $output;
  931. }
  932. }
  933. /**
  934. * Print a message in a standard themed box.
  935. * Replaces print_simple_box (see deprecatedlib.php)
  936. *
  937. * @deprecated
  938. * @param string $message, the content of the box
  939. * @param string $classes, space-separated class names.
  940. * @param string $ids
  941. * @param boolean $return, return as string or just print it
  942. * @return string|void mixed string or void
  943. */
  944. function print_box($message, $classes='generalbox', $ids='', $return=false) {
  945. global $OUTPUT;
  946. debugging('print_box() has been deprecated. Please change your code to use $OUTPUT->box().');
  947. $output = $OUTPUT->box($message, $classes, $ids);
  948. if ($return) {
  949. return $output;
  950. } else {
  951. echo $output;
  952. }
  953. }
  954. /**
  955. * Starts a box using divs
  956. * Replaces print_simple_box_start (see deprecatedlib.php)
  957. *
  958. * @deprecated
  959. * @param string $classes, space-separated class names.
  960. * @param string $ids
  961. * @param boolean $return, return as string or just print it
  962. * @return string|void string or void
  963. */
  964. function print_box_start($classes='generalbox', $ids='', $return=false) {
  965. global $OUTPUT;
  966. debugging('print_box_start() has been deprecated. Please change your code to use $OUTPUT->box_start().');
  967. $output = $OUTPUT->box_start($classes, $ids);
  968. if ($return) {
  969. return $output;
  970. } else {
  971. echo $output;
  972. }
  973. }
  974. /**
  975. * Simple function to end a box (see above)
  976. * Replaces print_simple_box_end (see deprecatedlib.php)
  977. *
  978. * @deprecated
  979. * @param boolean $return, return as string or just print it
  980. * @return string|void Depending on value of return
  981. */
  982. function print_box_end($return=false) {
  983. global $OUTPUT;
  984. debugging('print_box_end() has been deprecated. Please change your code to use $OUTPUT->box_end().');
  985. $output = $OUTPUT->box_end();
  986. if ($return) {
  987. return $output;
  988. } else {
  989. echo $output;
  990. }
  991. }
  992. /**
  993. * Print a message in a standard themed container.
  994. *
  995. * @deprecated
  996. * @param string $message, the content of the container
  997. * @param boolean $clearfix clear both sides
  998. * @param string $classes, space-separated class names.
  999. * @param string $idbase
  1000. * @param boolean $return, return as string or just print it
  1001. * @return string|void Depending on value of $return
  1002. */
  1003. function print_container($message, $clearfix=false, $classes='', $idbase='', $return=false) {
  1004. global $OUTPUT;
  1005. if ($clearfix) {
  1006. $classes .= ' clearfix';
  1007. }
  1008. $output = $OUTPUT->container($message, $classes, $idbase);
  1009. if ($return) {
  1010. return $output;
  1011. } else {
  1012. echo $output;
  1013. }
  1014. }
  1015. /**
  1016. * Starts a container using divs
  1017. *
  1018. * @deprecated
  1019. * @param boolean $clearfix clear both sides
  1020. * @param string $classes, space-separated class names.
  1021. * @param string $idbase
  1022. * @param boolean $return, return as string or just print it
  1023. * @return string|void Based on value of $return
  1024. */
  1025. function print_container_start($clearfix=false, $classes='', $idbase='', $return=false) {
  1026. global $OUTPUT;
  1027. if ($clearfix) {
  1028. $classes .= ' clearfix';
  1029. }
  1030. $output = $OUTPUT->container_start($classes, $idbase);
  1031. if ($return) {
  1032. return $output;
  1033. } else {
  1034. echo $output;
  1035. }
  1036. }
  1037. /**
  1038. * Deprecated, now handled automatically in themes
  1039. */
  1040. function check_theme_arrows() {
  1041. debugging('check_theme_arrows() has been deprecated, do not use it anymore, it is now automatic.');
  1042. }
  1043. /**
  1044. * Simple function to end a container (see above)
  1045. *
  1046. * @deprecated
  1047. * @param boolean $return, return as string or just print it
  1048. * @return string|void Based on $return
  1049. */
  1050. function print_container_end($return=false) {
  1051. global $OUTPUT;
  1052. $output = $OUTPUT->container_end();
  1053. if ($return) {
  1054. return $output;
  1055. } else {
  1056. echo $output;
  1057. }
  1058. }
  1059. /**
  1060. * Print a bold message in an optional color.
  1061. *
  1062. * @deprecated use $OUTPUT->notification instead.
  1063. * @param string $message The message to print out
  1064. * @param string $style Optional style to display message text in
  1065. * @param string $align Alignment option
  1066. * @param bool $return whether to return an output string or echo now
  1067. * @return string|bool Depending on $result
  1068. */
  1069. function notify($message, $classes = 'notifyproblem', $align = 'center', $return = false) {
  1070. global $OUTPUT;
  1071. if ($classes == 'green') {
  1072. debugging('Use of deprecated class name "green" in notify. Please change to "notifysuccess".', DEBUG_DEVELOPER);
  1073. $classes = 'notifysuccess'; // Backward compatible with old color system
  1074. }
  1075. $output = $OUTPUT->notification($message, $classes);
  1076. if ($return) {
  1077. return $output;
  1078. } else {
  1079. echo $output;
  1080. }
  1081. }
  1082. /**
  1083. * Print a continue button that goes to a particular URL.
  1084. *
  1085. * @deprecated since Moodle 2.0
  1086. *
  1087. * @param string $link The url to create a link to.
  1088. * @param bool $return If set to true output is returned rather than echoed, default false
  1089. * @return string|void HTML String if return=true nothing otherwise
  1090. */
  1091. function print_continue($link, $return = false) {
  1092. global $CFG, $OUTPUT;
  1093. if ($link == '') {
  1094. if (!empty($_SERVER['HTTP_REFERER'])) {
  1095. $link = $_SERVER['HTTP_REFERER'];
  1096. $link = str_replace('&', '&amp;', $link); // make it valid XHTML
  1097. } else {
  1098. $link = $CFG->wwwroot .'/';
  1099. }
  1100. }
  1101. $output = $OUTPUT->continue_button($link);
  1102. if ($return) {
  1103. return $output;
  1104. } else {
  1105. echo $output;
  1106. }
  1107. }
  1108. /**
  1109. * Print a standard header
  1110. *
  1111. * @param string $title Appears at the top of the window
  1112. * @param string $heading Appears at the top of the page
  1113. * @param string $navigation Array of $navlinks arrays (keys: name, link, type) for use as breadcrumbs links
  1114. * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
  1115. * @param string $meta Meta tags to be added to the header
  1116. * @param boolean $cache Should this page be cacheable?
  1117. * @param string $button HTML code for a button (usually for module editing)
  1118. * @param string $menu HTML code for a popup menu
  1119. * @param boolean $usexml use XML for this page
  1120. * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
  1121. * @param bool $return If true, return the visible elements of the header instead of echoing them.
  1122. * @return string|void If return=true then string else void
  1123. */
  1124. function print_header($title='', $heading='', $navigation='', $focus='',
  1125. $meta='', $cache=true, $button='&nbsp;', $menu=null,
  1126. $usexml=false, $bodytags='', $return=false) {
  1127. global $PAGE, $OUTPUT;
  1128. $PAGE->set_title($title);
  1129. $PAGE->set_heading($heading);
  1130. $PAGE->set_cacheable($cache);
  1131. if ($button == '') {
  1132. $button = '&nbsp;';
  1133. }
  1134. $PAGE->set_button($button);
  1135. $PAGE->set_headingmenu($menu);
  1136. // TODO $menu
  1137. if ($meta) {
  1138. throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
  1139. 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
  1140. }
  1141. if ($usexml) {
  1142. throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
  1143. }
  1144. if ($bodytags) {
  1145. throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
  1146. }
  1147. $output = $OUTPUT->header();
  1148. if ($return) {
  1149. return $output;
  1150. } else {
  1151. echo $output;
  1152. }
  1153. }
  1154. /**
  1155. * This version of print_header is simpler because the course name does not have to be
  1156. * provided explicitly in the strings. It can be used on the site page as in courses
  1157. * Eventually all print_header could be replaced by print_header_simple
  1158. *
  1159. * @deprecated since Moodle 2.0
  1160. * @param string $title Appears at the top of the window
  1161. * @param string $heading Appears at the top of the page
  1162. * @param string $navigation Premade navigation string (for use as breadcrumbs links)
  1163. * @param string $focus Indicates form element to get cursor focus on load eg inputform.password
  1164. * @param string $meta Meta tags to be added to the header
  1165. * @param boolean $cache Should this page be cacheable?
  1166. * @param string $button HTML code for a button (usually for module editing)
  1167. * @param string $menu HTML code for a popup menu
  1168. * @param boolean $usexml use XML for this page
  1169. * @param string $bodytags This text will be included verbatim in the <body> tag (useful for onload() etc)
  1170. * @param bool $return If true, return the visible elements of the header instead of echoing them.
  1171. * @return string|void If $return=true the return string else nothing
  1172. */
  1173. function print_header_simple($title='', $heading='', $navigation='', $focus='', $meta='',
  1174. $cache=true, $button='&nbsp;', $menu='', $usexml=false, $bodytags='', $return=false) {
  1175. global $COURSE, $CFG, $PAGE, $OUTPUT;
  1176. if ($meta) {
  1177. throw new coding_exception('The $meta parameter to print_header is no longer supported. '.
  1178. 'You should be able to do everything you want with $PAGE->requires and other such mechanisms.');
  1179. }
  1180. if ($usexml) {
  1181. throw new coding_exception('The $usexml parameter to print_header is no longer supported.');
  1182. }
  1183. if ($bodytags) {
  1184. throw new coding_exception('The $bodytags parameter to print_header is no longer supported.');
  1185. }
  1186. $PAGE->set_title($title);
  1187. $PAGE->set_heading($heading);
  1188. $PAGE->set_cacheable(true);
  1189. $PAGE->set_button($button);
  1190. $output = $OUTPUT->header();
  1191. if ($return) {
  1192. return $output;
  1193. } else {
  1194. echo $output;
  1195. }
  1196. }
  1197. function print_footer($course = NULL, $usercourse = NULL, $return = false) {
  1198. global $PAGE, $OUTPUT;
  1199. debugging('print_footer() has been deprecated. Please change your code to use $OUTPUT->footer().');
  1200. // TODO check arguments.
  1201. if (is_string($course)) {
  1202. debugging("Magic values like 'home', 'empty' passed to print_footer no longer have any effect. " .
  1203. 'To achieve a similar effect, call $PAGE->set_pagelayout before you call print_header.', DEBUG_DEVELOPER);
  1204. } else if (!empty($course->id) && $course->id != $PAGE->course->id) {
  1205. throw new coding_exception('The $course object you passed to print_footer does not match $PAGE->course.');
  1206. }
  1207. if (!is_null($usercourse)) {
  1208. debugging('The second parameter ($usercourse) to print_footer is no longer supported. ' .
  1209. '(I did not think it was being used anywhere.)', DEBUG_DEVELOPER);
  1210. }
  1211. $output = $OUTPUT->footer();
  1212. if ($return) {
  1213. return $output;
  1214. } else {
  1215. echo $output;
  1216. }
  1217. }
  1218. /**
  1219. * Returns text to be displayed to the user which reflects their login status
  1220. *
  1221. * @global object
  1222. * @global object
  1223. * @global object
  1224. * @global object
  1225. * @uses CONTEXT_COURSE
  1226. * @param course $course {@link $COURSE} object containing course information
  1227. * @param user $user {@link $USER} object containing user information
  1228. * @return string HTML
  1229. */
  1230. function user_login_string($course='ignored', $user='ignored') {
  1231. debugging('user_login_info() has been deprecated. User login info is now handled via themes layouts.');
  1232. return '';
  1233. }
  1234. /**
  1235. * Prints a nice side block with an optional header. The content can either
  1236. * be a block of HTML or a list of text with optional icons.
  1237. *
  1238. * @todo Finish documenting this function. Show example of various attributes, etc.
  1239. *
  1240. * @static int $block_id Increments for each call to the function
  1241. * @param string $heading HTML for the heading. Can include full HTML or just
  1242. * plain text - plain text will automatically be enclosed in the appropriate
  1243. * heading tags.
  1244. * @param string $content HTML for the content
  1245. * @param array $list an alternative to $content, it you want a list of things with optional icons.
  1246. * @param array $icons optional icons for the things in $list.
  1247. * @param string $footer Extra HTML content that gets output at the end, inside a &lt;div class="footer">
  1248. * @param array $attributes an array of attribute => value pairs that are put on the
  1249. * outer div of this block. If there is a class attribute ' block' gets appended to it. If there isn't
  1250. * already a class, class='block' is used.
  1251. * @param string $title Plain text title, as embedded in the $heading.
  1252. * @deprecated
  1253. */
  1254. function print_side_block($heading='', $content='', $list=NULL, $icons=NULL, $footer='', $attributes = array(), $title='') {
  1255. global $OUTPUT;
  1256. // We don't use $heading, becuse it often contains HTML that we don't want.
  1257. // However, sometimes $title is not set, but $heading is.
  1258. if (empty($title)) {
  1259. $title = strip_tags($heading);
  1260. }
  1261. // Render list contents to HTML if required.
  1262. if (empty($content) && $list) {
  1263. $content = $OUTPUT->list_block_contents($icons, $list);
  1264. }
  1265. $bc = new block_contents();
  1266. $bc->content = $content;
  1267. $bc->footer = $footer;
  1268. $bc->title = $title;
  1269. if (isset($attributes['id'])) {
  1270. $bc->id = $attributes['id'];
  1271. unset($attributes['id']);
  1272. }
  1273. $bc->attributes = $attributes;
  1274. echo $OUTPUT->block($bc, BLOCK_POS_LEFT); // POS LEFT may be wrong, but no way to get a better guess here.
  1275. }
  1276. /**
  1277. * Starts a nice side block with an optional header.
  1278. *
  1279. * @todo Finish documenting this function
  1280. *
  1281. * @global object
  1282. * @global object
  1283. * @param string $heading HTML for the heading. Can include full HTML or just
  1284. * plain text - plain text will automatically be enclosed in the appropriate
  1285. * heading tags.
  1286. * @param array $attributes HTML attributes to apply if possible
  1287. * @deprecated
  1288. */
  1289. function print_side_block_start($heading='', $attributes = array()) {
  1290. throw new coding_exception('print_side_block_start has been deprecated. Please change your code to use $OUTPUT->block().');
  1291. }
  1292. /**
  1293. * Print table ending tags for a side block box.
  1294. *
  1295. * @global object
  1296. * @global object
  1297. * @param array $attributes HTML attributes to apply if possible [id]
  1298. * @param string $title
  1299. * @deprecated
  1300. */
  1301. function print_side_block_end($attributes = array(), $title='') {
  1302. throw new coding_exception('print_side_block_end has been deprecated. Please change your code to use $OUTPUT->block().');
  1303. }
  1304. /**
  1305. * This was used by old code to see whether a block region had anything in it,
  1306. * and hence wether that region should be printed.
  1307. *
  1308. * We don't ever want old code to print blocks, so we now always return false.
  1309. * The function only exists to avoid fatal errors in old code.
  1310. *
  1311. * @deprecated since Moodle 2.0. always returns false.
  1312. *
  1313. * @param object $blockmanager
  1314. * @param string $region
  1315. * @return bool
  1316. */
  1317. function blocks_have_content(&$blockmanager, $region) {
  1318. debugging('The function blocks_have_content should no longer be used. Blocks are now printed by the theme.');
  1319. return false;
  1320. }
  1321. /**
  1322. * This was used by old code to print the blocks in a region.
  1323. *
  1324. * We don't ever want old code to print blocks, so this is now a no-op.
  1325. * The function only exists to avoid fatal errors in old code.
  1326. *
  1327. * @deprecated since Moodle 2.0. does nothing.
  1328. *
  1329. * @param object $page
  1330. * @param object $blockmanager
  1331. * @param string $region
  1332. */
  1333. function blocks_print_group($page, $blockmanager, $region) {
  1334. debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
  1335. }
  1336. /**
  1337. * This used to be the old entry point for anyone that wants to use blocks.
  1338. * Since we don't want people people dealing with blocks this way any more,
  1339. * just return a suitable empty array.
  1340. *
  1341. * @deprecated since Moodle 2.0.
  1342. *
  1343. * @param object $page
  1344. * @return array
  1345. */
  1346. function blocks_setup(&$page, $pinned = BLOCKS_PINNED_FALSE) {
  1347. debugging('The function blocks_print_group should no longer be used. Blocks are now printed by the theme.');
  1348. return array(BLOCK_POS_LEFT => array(),