....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 41.207.40.59  /  Your IP : 216.73.216.58
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux srv-prod 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User : www-data ( 33)
PHP Version : 8.3.26
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/formation/lib/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/formation/lib/classes/filetypes.php
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Class to manage the custom filetypes list that is stored in a config variable.
 *
 * @package core
 * @copyright 2014 The Open University
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

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

require_once($CFG->libdir . '/filelib.php');

/**
 * Class to manage the custom filetypes list that is stored in a config variable.
 *
 * @copyright 2014 The Open University
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
abstract class core_filetypes {
    /** @var array Cached MIME types for current request */
    protected static $cachedtypes;

    /**
     * Gets default MIME types that are included as standard.
     *
     * Note: Use the function get_mimetypes_array to access this data including
     * any customisations the user might have made.
     *
     * @return array Default (pre-installed) MIME type information
     */
    protected static function get_default_types() {
        return array(
            'xxx' => array('type' => 'document/unknown', 'icon' => 'unknown'),
            '3gp' => array('type' => 'video/quicktime', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'),
            '7z' => array('type' => 'application/x-7z-compressed', 'icon' => 'archive',
                    'groups' => array('archive'), 'string' => 'archive'),
            'aac' => array('type' => 'audio/aac', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'),
                    'string' => 'audio'),
            'accdb' => array('type' => 'application/msaccess', 'icon' => 'database'),
            'ai' => array('type' => 'application/postscript', 'icon' => 'eps', 'groups' => array('image'), 'string' => 'image'),
            'aif' => array('type' => 'audio/x-aiff', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'),
            'aiff' => array('type' => 'audio/x-aiff', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'),
            'aifc' => array('type' => 'audio/x-aiff', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'),
            'applescript' => array('type' => 'text/plain', 'icon' => 'text'),
            'asc' => array('type' => 'text/plain', 'icon' => 'sourcecode'),
            'asm' => array('type' => 'text/plain', 'icon' => 'sourcecode'),
            'au' => array('type' => 'audio/au', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'),
            'avi' => array('type' => 'video/x-ms-wm', 'icon' => 'video',
                    'groups' => array('video', 'web_video'), 'string' => 'video'),
            'bmp' => array('type' => 'image/bmp', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'),
            'c' => array('type' => 'text/plain', 'icon' => 'sourcecode'),
            'cct' => array('type' => 'shockwave/director', 'icon' => 'flash'),
            'cpp' => array('type' => 'text/plain', 'icon' => 'sourcecode'),
            'cs' => array('type' => 'application/x-csh', 'icon' => 'sourcecode'),
            'css' => array('type' => 'text/css', 'icon' => 'json', 'groups' => array('web_file')),
            'csv' => array('type' => 'text/csv', 'icon' => 'spreadsheet', 'groups' => array('spreadsheet')),
            'dv' => array('type' => 'video/x-dv', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'),
            'dmg' => array('type' => 'application/octet-stream', 'icon' => 'unknown'),

            'doc' => array('type' => 'application/msword', 'icon' => 'document', 'groups' => array('document')),
            'bdoc' => array('type' => 'application/x-digidoc', 'icon' => 'document', 'groups' => array('archive')),
            'cdoc' => array('type' => 'application/x-digidoc', 'icon' => 'document', 'groups' => array('archive')),
            'ddoc' => array('type' => 'application/x-digidoc', 'icon' => 'document', 'groups' => array('archive')),
            'docx' => array('type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                    'icon' => 'document', 'groups' => array('document')),
            'docm' => array('type' => 'application/vnd.ms-word.document.macroEnabled.12', 'icon' => 'document'),
            'dotx' => array('type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
                    'icon' => 'document'),
            'dotm' => array('type' => 'application/vnd.ms-word.template.macroEnabled.12', 'icon' => 'document'),

            'dcr' => array('type' => 'application/x-director', 'icon' => 'flash'),
            'dif' => array('type' => 'video/x-dv', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'),
            'dir' => array('type' => 'application/x-director', 'icon' => 'flash'),
            'dxr' => array('type' => 'application/x-director', 'icon' => 'flash'),
            'eps' => array('type' => 'application/postscript', 'icon' => 'eps'),
            'epub' => array('type' => 'application/epub+zip', 'icon' => 'epub', 'groups' => array('document')),
            'fdf' => array('type' => 'application/vnd.fdf', 'icon' => 'pdf'),
            'flac' => array('type' => 'audio/flac', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'),
                    'string' => 'audio'),
            'flv' => array('type' => 'video/x-flv', 'icon' => 'flash',
                    'groups' => array('video', 'web_video'), 'string' => 'video'),
            'f4v' => array('type' => 'video/mp4', 'icon' => 'flash', 'groups' => array('video', 'web_video'), 'string' => 'video'),
            'fmp4' => array('type' => 'video/mp4', 'icon' => 'video', 'groups' => array('html_video', 'video', 'web_video'),
                    'string' => 'video'),
            'gallery' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'),
            'galleryitem' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'),
            'gallerycollection' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'),
            'gdraw' => array('type' => 'application/vnd.google-apps.drawing', 'icon' => 'image', 'groups' => array('image')),
            'gdoc' => array('type' => 'application/vnd.google-apps.document', 'icon' => 'document', 'groups' => array('document')),
            'gsheet' => array('type' => 'application/vnd.google-apps.spreadsheet', 'icon' => 'spreadsheet',
                    'groups' => array('spreadsheet')),
            'gslides' => array('type' => 'application/vnd.google-apps.presentation', 'icon' => 'powerpoint',
                    'groups' => array('presentation')),
            'gif' => array('type' => 'image/gif', 'icon' => 'gif', 'groups' => array('image', 'web_image', 'optimised_image'),
                'string' => 'image'),
            'gtar' => array('type' => 'application/x-gtar', 'icon' => 'archive',
                    'groups' => array('archive'), 'string' => 'archive'),
            'tgz' => array('type' => 'application/g-zip', 'icon' => 'archive', 'groups' => array('archive'), 'string' => 'archive'),
            'gz' => array('type' => 'application/g-zip', 'icon' => 'archive', 'groups' => array('archive'), 'string' => 'archive'),
            'gzip' => array('type' => 'application/g-zip', 'icon' => 'archive',
                    'groups' => array('archive'), 'string' => 'archive'),
            'h' => array('type' => 'text/plain', 'icon' => 'sourcecode'),
            'h5p' => array('type' => 'application/zip.h5p', 'icon' => 'h5p', 'string' => 'archive'),
            'hpp' => array('type' => 'text/plain', 'icon' => 'sourcecode'),
            'hqx' => array('type' => 'application/mac-binhex40', 'icon' => 'archive',
                    'groups' => array('archive'), 'string' => 'archive'),
            'htc' => array('type' => 'text/x-component', 'icon' => 'markup'),
            'html' => array('type' => 'text/html', 'icon' => 'markup', 'groups' => array('web_file')),
            'xhtml' => array('type' => 'application/xhtml+xml', 'icon' => 'markup', 'groups' => array('web_file')),
            'htm' => array('type' => 'text/html', 'icon' => 'markup', 'groups' => array('web_file')),
            'ico' => array('type' => 'image/vnd.microsoft.icon', 'icon' => 'image',
                    'groups' => array('image'), 'string' => 'image'),
            'ics' => array('type' => 'text/calendar', 'icon' => 'text'),
            'imscc' => array('type' => 'application/zip', 'icon' => 'archive', 'string' => 'archive'),
            'isf' => array('type' => 'application/inspiration', 'icon' => 'isf'),
            'ist' => array('type' => 'application/inspiration.template', 'icon' => 'isf'),
            'java' => array('type' => 'text/plain', 'icon' => 'sourcecode'),
            'jar' => array('type' => 'application/java-archive', 'icon' => 'archive'),
            'jcb' => array('type' => 'text/xml', 'icon' => 'markup'),
            'jcl' => array('type' => 'text/xml', 'icon' => 'markup'),
            'jcw' => array('type' => 'text/xml', 'icon' => 'markup'),
            'jmt' => array('type' => 'text/xml', 'icon' => 'markup'),
            'jmx' => array('type' => 'text/xml', 'icon' => 'markup'),
            'jnlp' => array('type' => 'application/x-java-jnlp-file', 'icon' => 'markup'),
            'jpe' => array('type' => 'image/jpeg', 'icon' => 'image', 'groups' => array('image', 'web_image', 'optimised_image'),
                'string' => 'image'),
            'jpeg' => array('type' => 'image/jpeg', 'icon' => 'image', 'groups' => array('image', 'web_image', 'optimised_image'),
                'string' => 'image'),
            'jpg' => array('type' => 'image/jpeg', 'icon' => 'image', 'groups' => array('image', 'web_image', 'optimised_image'),
                'string' => 'image'),
            'jqz' => array('type' => 'text/xml', 'icon' => 'markup'),
            'js' => array('type' => 'application/x-javascript', 'icon' => 'text', 'groups' => array('web_file')),
            'json' => array('type' => 'application/json', 'icon' => 'json'),
            'latex' => array('type' => 'application/x-latex', 'icon' => 'text'),
            'm' => array('type' => 'text/plain', 'icon' => 'sourcecode'),
            'mbz' => array('type' => 'application/vnd.moodle.backup', 'icon' => 'moodle'),
            'mdb' => array('type' => 'application/x-msaccess', 'icon' => 'database'),
            'mht' => array('type' => 'message/rfc822', 'icon' => 'archive'),
            'mhtml' => array('type' => 'message/rfc822', 'icon' => 'archive'),
            'mov' => array('type' => 'video/quicktime', 'icon' => 'video',
                    'groups' => array('video', 'web_video', 'html_video'), 'string' => 'video'),
            'movie' => array('type' => 'video/x-sgi-movie', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'),
            'mw' => array('type' => 'application/maple', 'icon' => 'math'),
            'mws' => array('type' => 'application/maple', 'icon' => 'math'),
            'm3u' => array('type' => 'audio/x-mpegurl', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'),
            'm3u8' => array('type' => 'application/x-mpegURL', 'icon' => 'video', 'groups' => array('media_source')),
            'mp3' => array('type' => 'audio/mp3', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'),
                    'string' => 'audio'),
            'mp4' => array('type' => 'video/mp4', 'icon' => 'video', 'groups' => array('html_video', 'video', 'web_video'),
                    'string' => 'video'),
            'm4v' => array('type' => 'video/mp4', 'icon' => 'video', 'groups' => array('html_video', 'video', 'web_video'),
                    'string' => 'video'),
            'm4a' => array('type' => 'audio/mp4', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'),
                    'string' => 'audio'),
            'mpeg' => array('type' => 'video/mpeg', 'icon' => 'video', 'groups' => array('video', 'web_video'),
                    'string' => 'video'),
            'mpd' => array('type' => 'application/dash+xml', 'icon' => 'video', 'groups' => array('media_source')),
            'mpe' => array('type' => 'video/mpeg', 'icon' => 'video', 'groups' => array('video', 'web_video'),
                    'string' => 'video'),
            'mpg' => array('type' => 'video/mpeg', 'icon' => 'video', 'groups' => array('video', 'web_video'),
                    'string' => 'video'),
            'mpr' => array('type' => 'application/vnd.moodle.profiling', 'icon' => 'moodle'),

            'nbk' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'),
            'notebook' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'),

            'odt' => array('type' => 'application/vnd.oasis.opendocument.text', 'icon' => 'writer', 'groups' => array('document')),
            'ott' => array('type' => 'application/vnd.oasis.opendocument.text-template',
                    'icon' => 'writer', 'groups' => array('document')),
            'oth' => array('type' => 'application/vnd.oasis.opendocument.text-web', 'icon' => 'oth', 'groups' => array('document')),
            'odm' => array('type' => 'application/vnd.oasis.opendocument.text-master', 'icon' => 'writer'),
            'odg' => array('type' => 'application/vnd.oasis.opendocument.graphics', 'icon' => 'draw'),
            'otg' => array('type' => 'application/vnd.oasis.opendocument.graphics-template', 'icon' => 'draw'),
            'odp' => array('type' => 'application/vnd.oasis.opendocument.presentation', 'icon' => 'impress',
                    'groups' => array('presentation')),
            'otp' => array('type' => 'application/vnd.oasis.opendocument.presentation-template', 'icon' => 'impress',
                    'groups' => array('presentation')),
            'ods' => array('type' => 'application/vnd.oasis.opendocument.spreadsheet',
                    'icon' => 'calc', 'groups' => array('spreadsheet')),
            'ots' => array('type' => 'application/vnd.oasis.opendocument.spreadsheet-template',
                    'icon' => 'calc', 'groups' => array('spreadsheet')),
            'odc' => array('type' => 'application/vnd.oasis.opendocument.chart', 'icon' => 'chart'),
            'odf' => array('type' => 'application/vnd.oasis.opendocument.formula', 'icon' => 'math'),
            'odb' => array('type' => 'application/vnd.oasis.opendocument.database', 'icon' => 'database'),
            'odi' => array('type' => 'application/vnd.oasis.opendocument.image', 'icon' => 'draw'),
            'oga' => array('type' => 'audio/ogg', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'),
                    'string' => 'audio'),
            'ogg' => array('type' => 'audio/ogg', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'),
                    'string' => 'audio'),
            'ogv' => array('type' => 'video/ogg', 'icon' => 'video', 'groups' => array('html_video', 'video', 'web_video'),
                    'string' => 'video'),

            'pct' => array('type' => 'image/pict', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'),
            'pdf' => array('type' => 'application/pdf', 'icon' => 'pdf', 'groups' => array('document')),
            'php' => array('type' => 'text/plain', 'icon' => 'sourcecode'),
            'pic' => array('type' => 'image/pict', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'),
            'pict' => array('type' => 'image/pict', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'),
            'png' => array('type' => 'image/png', 'icon' => 'image', 'groups' => array('image', 'web_image', 'optimised_image'),
                'string' => 'image'),
            'pps' => array('type' => 'application/vnd.ms-powerpoint', 'icon' => 'powerpoint', 'groups' => array('presentation')),
            'ppt' => array('type' => 'application/vnd.ms-powerpoint', 'icon' => 'powerpoint', 'groups' => array('presentation')),
            'pptx' => array('type' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
                    'icon' => 'powerpoint', 'groups' => array('presentation')),
            'pptm' => array('type' => 'application/vnd.ms-powerpoint.presentation.macroEnabled.12', 'icon' => 'powerpoint',
                    'groups' => array('presentation')),
            'potx' => array('type' => 'application/vnd.openxmlformats-officedocument.presentationml.template',
                    'icon' => 'powerpoint', 'groups' => array('presentation')),
            'potm' => array('type' => 'application/vnd.ms-powerpoint.template.macroEnabled.12', 'icon' => 'powerpoint',
                    'groups' => array('presentation')),
            'ppam' => array('type' => 'application/vnd.ms-powerpoint.addin.macroEnabled.12', 'icon' => 'powerpoint',
                    'groups' => array('presentation')),
            'ppsx' => array('type' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
                    'icon' => 'powerpoint', 'groups' => array('presentation')),
            'ppsm' => array('type' => 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12', 'icon' => 'powerpoint',
                    'groups' => array('presentation')),
            'ps' => array('type' => 'application/postscript', 'icon' => 'pdf'),
            'psd' => array('type' => 'image/vnd.adobe.photoshop', 'icon' => 'psd'),
            'pub' => array('type' => 'application/x-mspublisher', 'icon' => 'publisher', 'groups' => array('presentation')),

            'qt' => array('type' => 'video/quicktime', 'icon' => 'video',
                    'groups' => array('video', 'web_video'), 'string' => 'video'),
            'ra' => array('type' => 'audio/x-realaudio-plugin', 'icon' => 'audio',
                    'groups' => array('audio', 'web_audio'), 'string' => 'audio'),
            'ram' => array('type' => 'audio/x-pn-realaudio-plugin', 'icon' => 'audio',
                    'groups' => array('audio'), 'string' => 'audio'),
            'rar' => array('type' => 'application/x-rar-compressed', 'icon' => 'archive',
                    'groups' => array('archive'), 'string' => 'archive'),
            'rhb' => array('type' => 'text/xml', 'icon' => 'markup'),
            'rm' => array('type' => 'audio/x-pn-realaudio-plugin', 'icon' => 'audio',
                    'groups' => array('audio'), 'string' => 'audio'),
            'rmvb' => array('type' => 'application/vnd.rn-realmedia-vbr', 'icon' => 'video',
                    'groups' => array('video'), 'string' => 'video'),
            'rtf' => array('type' => 'text/rtf', 'icon' => 'text', 'groups' => array('document')),
            'rtx' => array('type' => 'text/richtext', 'icon' => 'text'),
            'rv' => array('type' => 'audio/x-pn-realaudio-plugin', 'icon' => 'audio',
                    'groups' => array('video'), 'string' => 'video'),
            'scss' => array('type' => 'text/x-scss', 'icon' => 'json', 'groups' => array('web_file')),
            'sh' => array('type' => 'application/x-sh', 'icon' => 'sourcecode'),
            'sit' => array('type' => 'application/x-stuffit', 'icon' => 'archive',
                    'groups' => array('archive'), 'string' => 'archive'),
            'smi' => array('type' => 'application/smil', 'icon' => 'text'),
            'smil' => array('type' => 'application/smil', 'icon' => 'text'),
            'sqt' => array('type' => 'text/xml', 'icon' => 'markup'),
            'svg' => array('type' => 'image/svg+xml', 'icon' => 'image',
                    'groups' => array('image', 'web_image'), 'string' => 'image'),
            'svgz' => array('type' => 'image/svg+xml', 'icon' => 'image',
                    'groups' => array('image', 'web_image'), 'string' => 'image'),
            'swa' => array('type' => 'application/x-director', 'icon' => 'flash'),
            'swf' => array('type' => 'application/x-shockwave-flash', 'icon' => 'flash'),
            'swfl' => array('type' => 'application/x-shockwave-flash', 'icon' => 'flash'),

            'sxw' => array('type' => 'application/vnd.sun.xml.writer', 'icon' => 'writer'),
            'stw' => array('type' => 'application/vnd.sun.xml.writer.template', 'icon' => 'writer'),
            'sxc' => array('type' => 'application/vnd.sun.xml.calc', 'icon' => 'calc'),
            'stc' => array('type' => 'application/vnd.sun.xml.calc.template', 'icon' => 'calc'),
            'sxd' => array('type' => 'application/vnd.sun.xml.draw', 'icon' => 'draw'),
            'std' => array('type' => 'application/vnd.sun.xml.draw.template', 'icon' => 'draw'),
            'sxi' => array('type' => 'application/vnd.sun.xml.impress', 'icon' => 'impress', 'groups' => array('presentation')),
            'sti' => array('type' => 'application/vnd.sun.xml.impress.template', 'icon' => 'impress',
                    'groups' => array('presentation')),
            'sxg' => array('type' => 'application/vnd.sun.xml.writer.global', 'icon' => 'writer'),
            'sxm' => array('type' => 'application/vnd.sun.xml.math', 'icon' => 'math'),

            'tar' => array('type' => 'application/x-tar', 'icon' => 'archive', 'groups' => array('archive'), 'string' => 'archive'),
            'tif' => array('type' => 'image/tiff', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'),
            'tiff' => array('type' => 'image/tiff', 'icon' => 'image', 'groups' => array('image'), 'string' => 'image'),
            'tex' => array('type' => 'application/x-tex', 'icon' => 'text'),
            'texi' => array('type' => 'application/x-texinfo', 'icon' => 'text'),
            'texinfo' => array('type' => 'application/x-texinfo', 'icon' => 'text'),
            'ts' => array('type' => 'video/MP2T', 'icon' => 'video', 'groups' => array('video', 'web_video'),
                    'string' => 'video'),
            'tsv' => array('type' => 'text/tab-separated-values', 'icon' => 'text'),
            'txt' => array('type' => 'text/plain', 'icon' => 'text', 'defaulticon' => true),
            'vtt' => array('type' => 'text/vtt', 'icon' => 'text', 'groups' => array('html_track')),
            'wav' => array('type' => 'audio/wav', 'icon' => 'audio', 'groups' => array('audio', 'html_audio', 'web_audio'),
                    'string' => 'audio'),
            'webm' => array('type' => 'video/webm', 'icon' => 'video', 'groups' => array('html_video', 'video', 'web_video'),
                    'string' => 'video'),
            'wmv' => array('type' => 'video/x-ms-wmv', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'),
            'asf' => array('type' => 'video/x-ms-asf', 'icon' => 'video', 'groups' => array('video'), 'string' => 'video'),
            'wma' => array('type' => 'audio/x-ms-wma', 'icon' => 'audio', 'groups' => array('audio'), 'string' => 'audio'),

            'xbk' => array('type' => 'application/x-smarttech-notebook', 'icon' => 'archive'),
            'xdp' => array('type' => 'application/vnd.adobe.xdp+xml', 'icon' => 'pdf'),
            'xfd' => array('type' => 'application/vnd.xfdl', 'icon' => 'pdf'),
            'xfdf' => array('type' => 'application/vnd.adobe.xfdf', 'icon' => 'pdf'),

            'xls' => array('type' => 'application/vnd.ms-excel', 'icon' => 'spreadsheet', 'groups' => array('spreadsheet')),
            'xlsx' => array('type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'icon' => 'spreadsheet',
                'groups' => array('spreadsheet')),
            'xlsm' => array('type' => 'application/vnd.ms-excel.sheet.macroEnabled.12',
                    'icon' => 'spreadsheet', 'groups' => array('spreadsheet')),
            'xltx' => array('type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
                    'icon' => 'spreadsheet'),
            'xltm' => array('type' => 'application/vnd.ms-excel.template.macroEnabled.12', 'icon' => 'spreadsheet'),
            'xlsb' => array('type' => 'application/vnd.ms-excel.sheet.binary.macroEnabled.12', 'icon' => 'spreadsheet'),
            'xlam' => array('type' => 'application/vnd.ms-excel.addin.macroEnabled.12', 'icon' => 'spreadsheet'),

            'xml' => array('type' => 'application/xml', 'icon' => 'markup'),
            'xsl' => array('type' => 'text/xml', 'icon' => 'markup'),

            'yaml' => array('type' => 'application/yaml', 'icon' => 'markup'),
            'yml' => array('type' => 'application/yaml', 'icon' => 'markup'),

            'zip' => array('type' => 'application/zip', 'icon' => 'archive', 'groups' => array('archive'), 'string' => 'archive')
        );
    }

    /**
     * Given a mimetype - return a valid file extension for it.
     *
     * @param $mimetype string
     * @return string|bool False if the mimetype was not known, a string indicating a valid file extension otherwise. It may not
     *                     be the only valid file extension - just the first one found.
     */
    public static function get_file_extension($mimetype) {
        $types = self::get_types();
        foreach ($types as $extension => $info) {
            if ($info['type'] == $mimetype) {
                return $extension;
            }
        }
        return false;
    }

    /**
     * Gets all the current types.
     *
     * @return array Associative array from extension to array of data about type
     */
    public static function &get_types() {
        // If it was already done in this request, use cache.
        if (self::$cachedtypes) {
            return self::$cachedtypes;
        }

        // Get defaults.
        $mimetypes = self::get_default_types();

        // Get custom file types.
        $custom = self::get_custom_types();

        // Check value is an array.
        if (!is_array($custom)) {
            debugging('Invalid $CFG->customfiletypes (not array)', DEBUG_DEVELOPER);
            $custom = array();
        }

        foreach ($custom as $customentry) {
            // Each entry is a stdClass object similar to the array values above.
            if (empty($customentry->extension)) {
                debugging('Invalid $CFG->customfiletypes entry (extension field required)',
                        DEBUG_DEVELOPER);
                continue;
            }

            // To delete a standard entry, set 'deleted' to true.
            if (!empty($customentry->deleted)) {
                unset($mimetypes[$customentry->extension]);
                continue;
            }

            // Check required fields.
            if (empty($customentry->type) || empty($customentry->icon)) {
                debugging('Invalid $CFG->customfiletypes entry ' . $customentry->extension .
                        ' (type and icon fields required)', DEBUG_DEVELOPER);
                continue;
            }

            // Build result array.
            $result = array('type' => $customentry->type, 'icon' => $customentry->icon);
            if (!empty($customentry->groups)) {
                if (!is_array($customentry->groups)) {
                    debugging('Invalid $CFG->customfiletypes entry ' . $customentry->extension .
                            ' (groups field not array)', DEBUG_DEVELOPER);
                    continue;
                }
                $result['groups'] = $customentry->groups;
            }
            if (!empty($customentry->string)) {
                if (!is_string($customentry->string)) {
                    debugging('Invalid $CFG->customfiletypes entry ' . $customentry->extension .
                            ' (string field not string)', DEBUG_DEVELOPER);
                    continue;
                }
                $result['string'] = $customentry->string;
            }
            if (!empty($customentry->defaulticon)) {
                if (!is_bool($customentry->defaulticon)) {
                    debugging('Invalid $CFG->customfiletypes entry ' . $customentry->extension .
                            ' (defaulticon field not bool)', DEBUG_DEVELOPER);
                    continue;
                }
                $result['defaulticon'] = $customentry->defaulticon;
            }
            if (!empty($customentry->customdescription)) {
                if (!is_string($customentry->customdescription)) {
                    debugging('Invalid $CFG->customfiletypes entry ' . $customentry->extension .
                            ' (customdescription field not string)', DEBUG_DEVELOPER);
                    continue;
                }
                // As the name suggests, this field is used only for custom entries.
                $result['customdescription'] = $customentry->customdescription;
            }

            // Track whether it is a custom filetype or a modified existing
            // filetype.
            if (array_key_exists($customentry->extension, $mimetypes)) {
                $result['modified'] = true;
            } else {
                $result['custom'] = true;
            }

            // Add result array to list.
            $mimetypes[$customentry->extension] = $result;
        }

        self::$cachedtypes = $mimetypes;
        return self::$cachedtypes;
    }

    /**
     * Gets custom types from config variable, after decoding the JSON if required.
     *
     * @return array Array of custom types (empty array if none)
     */
    protected static function get_custom_types() {
        global $CFG;
        if (!empty($CFG->customfiletypes)) {
            if (is_array($CFG->customfiletypes)) {
                // You can define this as an array in config.php...
                return $CFG->customfiletypes;
            } else {
                // Or as a JSON string in the config table.
                return json_decode($CFG->customfiletypes);
            }
        } else {
            return array();
        }
    }

    /**
     * Sets the custom types into config variable, encoding into JSON.
     *
     * @param array $types Array of custom types
     * @throws coding_exception If the custom types are fixed in config.php.
     */
    protected static function set_custom_types(array $types) {
        global $CFG;
        // Check the setting hasn't been forced.
        if (array_key_exists('customfiletypes', $CFG->config_php_settings)) {
            throw new coding_exception('Cannot set custom filetypes because they ' .
                    'are defined in config.php');
        }
        if (empty($types)) {
            unset_config('customfiletypes');
        } else {
            set_config('customfiletypes', json_encode(array_values($types)));
        }

        // Clear the cached type list.
        self::reset_caches();
    }

    /**
     * Clears the type cache. This is not needed in normal use as the
     * set_custom_types function automatically clears the cache. Intended for
     * use in unit tests.
     */
    public static function reset_caches() {
        self::$cachedtypes = null;
    }

    /**
     * Gets the default types that have been deleted. Returns an array containing
     * the defaults of all those types.
     *
     * @return array Array (same format as get_mimetypes_array)
     */
    public static function get_deleted_types() {
        $defaults = self::get_default_types();
        $deleted = array();
        foreach (self::get_custom_types() as $customentry) {
            if (!empty($customentry->deleted)) {
                $deleted[$customentry->extension] = $defaults[$customentry->extension];
            }
        }
        return $deleted;
    }

    /**
     * Adds a new entry to the list of custom filetypes.
     *
     * @param string $extension File extension without dot, e.g. 'doc'
     * @param string $mimetype MIME type e.g. 'application/msword'
     * @param string $coreicon Core icon to use e.g. 'document'
     * @param array $groups Array of group strings that this type belongs to
     * @param string $corestring Custom lang string name in mimetypes.php
     * @param string $customdescription Custom description (plain text/multilang)
     * @param bool $defaulticon True if this should be the default icon for the type
     * @throws coding_exception If the extension already exists, or otherwise invalid
     */
    public static function add_type($extension, $mimetype, $coreicon,
            array $groups = array(), $corestring = '', $customdescription = '',
            $defaulticon = false) {
        // Check for blank extensions or incorrectly including the dot.
        $extension = (string)$extension;
        if ($extension === '' || $extension[0] === '.') {
            throw new coding_exception('Invalid extension .' . $extension);
        }

        // Check extension not already used.
        $mimetypes = get_mimetypes_array();
        if (array_key_exists($extension, $mimetypes)) {
            throw new coding_exception('Extension ' . $extension . ' already exists');
        }

        // For default icon, check there isn't already something with default icon
        // set for that MIME type.
        if ($defaulticon) {
            foreach ($mimetypes as $type) {
                if ($type['type'] === $mimetype && !empty($type['defaulticon'])) {
                    throw new coding_exception('MIME type ' . $mimetype .
                            ' already has a default icon set');
                }
            }
        }

        // Get existing custom filetype list.
        $customs = self::get_custom_types();

        // Check if there's a 'deleted' entry for the extension, if so then get
        // rid of it.
        foreach ($customs as $key => $custom) {
            if ($custom->extension === $extension) {
                unset($customs[$key]);
            }
        }

        // Set up config record for new type.
        $newtype = self::create_config_record($extension, $mimetype, $coreicon, $groups,
                $corestring, $customdescription, $defaulticon);

        // See if there's a default value with this extension.
        $needsadding = true;
        $defaults = self::get_default_types();
        if (array_key_exists($extension, $defaults)) {
            // If it has the same values, we don't need to add it.
            $defaultvalue = $defaults[$extension];
            $modified = (array)$newtype;
            unset($modified['extension']);
            ksort($defaultvalue);
            ksort($modified);
            if ($modified === $defaultvalue) {
                $needsadding = false;
            }
        }

        // Add to array and set in config.
        if ($needsadding) {
            $customs[] = $newtype;
        }
        self::set_custom_types($customs);
    }

    /**
     * Updates an entry in the list of filetypes in config.
     *
     * @param string $extension File extension without dot, e.g. 'doc'
     * @param string $newextension New file extension (same if not changing)
     * @param string $mimetype MIME type e.g. 'application/msword'
     * @param string $coreicon Core icon to use e.g. 'document'
     * @param array $groups Array of group strings that this type belongs to
     * @param string $corestring Custom lang string name in mimetypes.php
     * @param string $customdescription Custom description (plain text/multilang)
     * @param bool $defaulticon True if this should be the default icon for the type
     * @throws coding_exception If the new extension already exists, or otherwise invalid
     */
    public static function update_type($extension, $newextension, $mimetype, $coreicon,
            array $groups = array(), $corestring = '', $customdescription = '',
            $defaulticon = false) {

        // Extension must exist.
        $extension = (string)$extension;
        $mimetypes = get_mimetypes_array();
        if (!array_key_exists($extension, $mimetypes)) {
            throw new coding_exception('Extension ' . $extension . ' not found');
        }

        // If there's a new extension then this must not exist.
        $newextension = (string)$newextension;
        if ($newextension !== $extension) {
            if ($newextension === '' || $newextension[0] === '.') {
                throw new coding_exception('Invalid extension .' . $newextension);
            }
            if (array_key_exists($newextension, $mimetypes)) {
                throw new coding_exception('Extension ' . $newextension . ' already exists');
            }
        }

        // For default icon, check there isn't already something with default icon
        // set for that MIME type (unless it's this).
        if ($defaulticon) {
            foreach ($mimetypes as $ext => $type) {
                if ($ext !== $extension && $type['type'] === $mimetype &&
                        !empty($type['defaulticon'])) {
                    throw new coding_exception('MIME type ' . $mimetype .
                            ' already has a default icon set');
                }
            }
        }

        // Delete the old extension and then add the new one (may be same). This
        // will correctly handle cases when a default type is involved.
        self::delete_type($extension);
        self::add_type($newextension, $mimetype, $coreicon, $groups, $corestring,
                $customdescription, $defaulticon);
    }

    /**
     * Deletes a file type from the config list (or, for a standard one, marks it
     * as deleted).
     *
     * @param string $extension File extension without dot, e.g. 'doc'
     * @throws coding_exception If the extension does not exist, or otherwise invalid
     */
    public static function delete_type($extension) {
        // Extension must exist.
        $mimetypes = get_mimetypes_array();
        if (!array_key_exists($extension, $mimetypes)) {
            throw new coding_exception('Extension ' . $extension . ' not found');
        }

        // Get existing custom filetype list.
        $customs = self::get_custom_types();

        // Remove any entries for this extension.
        foreach ($customs as $key => $custom) {
            if ($custom->extension === $extension && empty($custom->deleted)) {
                unset($customs[$key]);
            }
        }

        // If it was a standard entry (doesn't have 'custom' set) then add a
        // deleted marker.
        if (empty($mimetypes[$extension]['custom'])) {
            $customs[] = (object)array('extension' => $extension, 'deleted' => true);
        }

        // Save and reset cache.
        self::set_custom_types($customs);
    }

    /**
     * Reverts a file type to the default. May only be called on types that have
     * default values. This will undelete the type if necessary or set its values.
     * If the type is already at default values, does nothing.
     *
     * @param string $extension File extension without dot, e.g. 'doc'
     * @return bool True if anything was changed, false if it was already default
     * @throws coding_exception If the extension is not a default type.
     */
    public static function revert_type_to_default($extension) {
        $extension = (string)$extension;

        // Check it actually is a default type.
        $defaults = self::get_default_types();
        if (!array_key_exists($extension, $defaults)) {
            throw new coding_exception('Extension ' . $extension . ' is not a default type');
        }

        // Loop through all the custom settings.
        $changed = false;
        $customs = self::get_custom_types();
        foreach ($customs as $key => $customentry) {
            if ($customentry->extension === $extension) {
                unset($customs[$key]);
                $changed = true;
            }
        }

        // Save changes if any.
        if ($changed) {
            self::set_custom_types($customs);
        }
        return $changed;
    }

    /**
     * Converts function parameters into a record for storing in the JSON value.
     *
     * @param string $extension File extension without dot, e.g. 'doc'
     * @param string $mimetype MIME type e.g. 'application/msword'
     * @param string $coreicon Core icon to use e.g. 'document'
     * @param array $groups Array of group strings that this type belongs to
     * @param string $corestring Custom lang string name in mimetypes.php
     * @param string $customdescription Custom description (plain text/multilang)
     * @param bool $defaulticon True if this should be the default icon for the type
     * @return stdClass Record matching the parameters
     */
    protected static function create_config_record($extension, $mimetype,
            $coreicon, array $groups, $corestring, $customdescription, $defaulticon) {
        // Construct new entry.
        $newentry = (object)array('extension' => (string)$extension, 'type' => (string)$mimetype,
                'icon' => (string)$coreicon);
        if ($groups) {
            if (!is_array($groups)) {
                throw new coding_exception('Groups must be an array');
            }
            foreach ($groups as $group) {
                if (!is_string($group)) {
                    throw new coding_exception('Groups must be an array of strings');
                }
            }
            $newentry->groups = $groups;
        }
        if ($corestring) {
            $newentry->string = (string)$corestring;
        }
        if ($customdescription) {
            $newentry->customdescription = (string)$customdescription;
        }
        if ($defaulticon) {
            $newentry->defaulticon = true;
        }
        return $newentry;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit