....................................../////.===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/tag/classes/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/formation/tag/classes/area.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 core_tag_area for managing tag areas
 *
 * @package   core_tag
 * @copyright 2015 Marina Glancy
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

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

/**
 * Class to manage tag areas
 *
 * @package   core_tag
 * @copyright 2015 Marina Glancy
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class core_tag_area {

    /**
     * Returns the list of areas indexed by itemtype and component
     *
     * @param int $tagcollid return only areas in this tag collection
     * @param bool $enabledonly return only enabled tag areas
     * @return array itemtype=>component=>tagarea object
     */
    public static function get_areas($tagcollid = null, $enabledonly = false) {
        global $DB;
        $cache = cache::make('core', 'tags');
        if (($itemtypes = $cache->get('tag_area')) === false) {
            $colls = core_tag_collection::get_collections();
            $defaultcoll = reset($colls);
            $itemtypes = array();
            $areas = $DB->get_records('tag_area', array(), 'component,itemtype');
            foreach ($areas as $area) {
                if ($colls[$area->tagcollid]->component) {
                    $area->locked = true;
                }
                $itemtypes[$area->itemtype][$area->component] = $area;
            }
            $cache->set('tag_area', $itemtypes);
        }
        if ($tagcollid || $enabledonly) {
            $rv = array();
            foreach ($itemtypes as $itemtype => $it) {
                foreach ($it as $component => $v) {
                    if (($v->tagcollid == $tagcollid || !$tagcollid) && (!$enabledonly || $v->enabled)) {
                        $rv[$itemtype][$component] = $v;
                    }
                }
            }
            return $rv;
        }
        return $itemtypes;
    }

    /**
     * Retrieves info about one tag area
     *
     * @param int $tagareaid
     * @return stdClass
     */
    public static function get_by_id($tagareaid) {
        $tagareas = self::get_areas();
        foreach ($tagareas as $itemtype => $it) {
            foreach ($it as $component => $v) {
                if ($v->id == $tagareaid) {
                    return $v;
                }
            }
        }
        return null;
    }

    /**
     * Returns the display name for this area
     *
     * @param string $component
     * @param string $itemtype
     * @return lang_string
     */
    public static function display_name($component, $itemtype) {
        $identifier = 'tagarea_' . clean_param($itemtype, PARAM_STRINGID);
        if ($component === 'core') {
            $component = 'tag';
        }
        return new lang_string($identifier, $component);
    }

    /**
     * Returns whether the tag area is enabled
     *
     * @param string $component component responsible for tagging
     * @param string $itemtype what is being tagged, for example, 'post', 'course', 'user', etc.
     * @return bool|null
     */
    public static function is_enabled($component, $itemtype) {
        global $CFG;
        if (empty($CFG->usetags)) {
            return false;
        }
        $itemtypes = self::get_areas();
        if (isset($itemtypes[$itemtype][$component])) {
            return $itemtypes[$itemtype][$component]->enabled ? true : false;
        }
        return null;
    }

    /**
     * Checks if the tag area allows items to be tagged in multiple different contexts.
     *
     * If true then it indicates that not all tag instance contexts must match the
     * context of the item they are tagging. If false then all tag instance should
     * match the context of the item they are tagging.
     *
     * Example use case for multi-context tagging:
     * A question that exists in a course category context may be used by multiple
     * child courses. The question tag area can allow tag instances to be created in
     * multiple contexts which allows the tag API to tag the question at the course
     * category context and then seperately in each of the child course contexts.
     *
     * @param string $component component responsible for tagging
     * @param string $itemtype what is being tagged, for example, 'post', 'course', 'user', etc.
     * @return bool
     */
    public static function allows_tagging_in_multiple_contexts($component, $itemtype) {
        $itemtypes = self::get_areas();
        if (isset($itemtypes[$itemtype][$component])) {
            $config = $itemtypes[$itemtype][$component];
            return isset($config->multiplecontexts) ? $config->multiplecontexts : false;
        }
        return false;
    }

    /**
     * Returns the id of the tag collection that should be used for storing tags of this itemtype
     *
     * @param string $component component responsible for tagging
     * @param string $itemtype what is being tagged, for example, 'post', 'course', 'user', etc.
     * @return int
     */
    public static function get_collection($component, $itemtype) {
        $itemtypes = self::get_areas();
        if (array_key_exists($itemtype, $itemtypes)) {
            if (!array_key_exists($component, $itemtypes[$itemtype])) {
                $component = key($itemtypes[$itemtype]);
            }
            return $itemtypes[$itemtype][$component]->tagcollid;
        }
        return core_tag_collection::get_default();
    }

    /**
     * Returns wether this tag area should display or not standard tags when user edits it.
     *
     * @param string $component component responsible for tagging
     * @param string $itemtype what is being tagged, for example, 'post', 'course', 'user', etc.
     * @return int
     */
    public static function get_showstandard($component, $itemtype) {
        $itemtypes = self::get_areas();
        if (array_key_exists($itemtype, $itemtypes)) {
            if (!array_key_exists($component, $itemtypes[$itemtype])) {
                $component = key($itemtypes[$itemtype]);
            }
            return $itemtypes[$itemtype][$component]->showstandard;
        }
        return core_tag_tag::BOTH_STANDARD_AND_NOT;
    }

    /**
     * Returns all tag areas and collections that are currently cached in DB for this component
     *
     * @param string $componentname
     * @return array first element is the list of areas and the second list of collections
     */
    protected static function get_definitions_for_component($componentname) {
        global $DB;
        list($a, $b) = core_component::normalize_component($componentname);
        $component = $b ? ($a . '_' . $b) : $a;
        $sql = 'component = :component';
        $params = array('component' => $component);
        if ($component === 'core') {
            $sql .= ' OR component LIKE :coreprefix';
            $params['coreprefix'] = 'core_%';
        }
        $fields = $DB->sql_concat_join("':'", array('itemtype', 'component'));
        $existingareas = $DB->get_records_sql(
                "SELECT $fields AS returnkey, a.* FROM {tag_area} a WHERE $sql", $params);
        $fields = $DB->sql_concat_join("':'", array('name', 'component'));
        $existingcolls = $DB->get_records_sql(
                "SELECT $fields AS returnkey, t.* FROM {tag_coll} t WHERE $sql", $params);
        return array($existingareas, $existingcolls);

    }

    /**
     * Completely delete a tag area and all instances inside it
     *
     * @param stdClass $record
     */
    protected static function delete($record) {
        global $DB;

        core_tag_tag::delete_instances($record->component, $record->itemtype);

        $DB->delete_records('tag_area',
                array('itemtype' => $record->itemtype,
                    'component' => $record->component));

        // Reset cache.
        cache::make('core', 'tags')->delete('tag_area');
    }

    /**
     * Create a new tag area
     *
     * @param stdClass $record
     */
    protected static function create($record) {
        global $DB;
        if (empty($record->tagcollid)) {
            $record->tagcollid = core_tag_collection::get_default();
        }
        $DB->insert_record('tag_area', array('component' => $record->component,
            'itemtype' => $record->itemtype,
            'tagcollid' => $record->tagcollid,
            'callback' => $record->callback,
            'callbackfile' => $record->callbackfile,
            'showstandard' => isset($record->showstandard) ? $record->showstandard : core_tag_tag::BOTH_STANDARD_AND_NOT,
            'multiplecontexts' => isset($record->multiplecontexts) ? $record->multiplecontexts : 0));

        // Reset cache.
        cache::make('core', 'tags')->delete('tag_area');
    }

    /**
     * Update the tag area
     *
     * @param stdClass $existing current record from DB table tag_area
     * @param array|stdClass $data fields that need updating
     */
    public static function update($existing, $data) {
        global $DB;
        $data = array_intersect_key((array)$data,
                array('enabled' => 1, 'tagcollid' => 1,
                    'callback' => 1, 'callbackfile' => 1, 'showstandard' => 1,
                    'multiplecontexts' => 1));
        foreach ($data as $key => $value) {
            if ($existing->$key == $value) {
                unset($data[$key]);
            }
        }
        if (!$data) {
            return;
        }

        if (!empty($data['tagcollid'])) {
            self::move_tags($existing->component, $existing->itemtype, $data['tagcollid']);
        }

        $data['id'] = $existing->id;
        $DB->update_record('tag_area', $data);

        // Reset cache.
        cache::make('core', 'tags')->delete('tag_area');
    }

    /**
     * Update the database to contain a list of tagged areas for a component.
     * The list of tagged areas is read from [plugindir]/db/tag.php
     *
     * @param string $componentname - The frankenstyle component name.
     */
    public static function reset_definitions_for_component($componentname) {
        global $DB;
        $dir = core_component::get_component_directory($componentname);
        $file = $dir . '/db/tag.php';
        $tagareas = null;
        if (file_exists($file)) {
            require_once($file);
        }

        list($a, $b) = core_component::normalize_component($componentname);
        $component = $b ? ($a . '_' . $b) : $a;

        list($existingareas, $existingcolls) = self::get_definitions_for_component($componentname);

        $itemtypes = array();
        $collections = array();
        $needcleanup = false;
        if ($tagareas) {
            foreach ($tagareas as $tagarea) {
                $record = (object)$tagarea;
                if ($component !== 'core' || empty($record->component)) {
                    if (isset($record->component) && $record->component !== $component) {
                        debugging("Item type {$record->itemtype} has illegal component {$record->component}", DEBUG_DEVELOPER);
                    }
                    $record->component = $component;
                }
                unset($record->tagcollid);
                if (!empty($record->collection)) {
                    // Create collection if it does not exist, or update 'searchable' and/or 'customurl' if needed.
                    $key = $record->collection . ':' . $record->component;
                    $collectiondata = array_intersect_key((array)$record,
                            array('component' => 1, 'searchable' => 1, 'customurl' => 1));
                    $collectiondata['name'] = $record->collection;
                    if (!array_key_exists($key, $existingcolls)) {
                        $existingcolls[$key] = core_tag_collection::create($collectiondata);
                    } else {
                        core_tag_collection::update($existingcolls[$key], $collectiondata);
                    }
                    $record->tagcollid = $existingcolls[$key]->id;
                    $collections[$key] = $existingcolls[$key];
                    unset($record->collection);
                }
                unset($record->searchable);
                unset($record->customurl);
                if (!isset($record->callback)) {
                    $record->callback = null;
                }
                if (!isset($record->callbackfile)) {
                    $record->callbackfile = null;
                }
                if (!isset($record->multiplecontexts)) {
                    $record->multiplecontexts = false;
                }
                $itemtypes[$record->itemtype . ':' . $record->component] = $record;
            }
        }
        $todeletearea = array_diff_key($existingareas, $itemtypes);
        $todeletecoll = array_diff_key($existingcolls, $collections);

        // Delete tag areas that are no longer needed.
        foreach ($todeletearea as $key => $record) {
            self::delete($record);
        }

        // Update tag areas if changed.
        $toupdatearea = array_intersect_key($existingareas, $itemtypes);
        foreach ($toupdatearea as $key => $tagarea) {
            if (!isset($itemtypes[$key]->tagcollid)) {
                foreach ($todeletecoll as $tagcoll) {
                    if ($tagcoll->id == $tagarea->tagcollid) {
                        $itemtypes[$key]->tagcollid = core_tag_collection::get_default();
                    }
                }
            }
            unset($itemtypes[$key]->showstandard); // Do not override value that was already changed by admin with the default.
            self::update($tagarea, $itemtypes[$key]);
        }

        // Create new tag areas.
        $toaddarea = array_diff_key($itemtypes, $existingareas);
        foreach ($toaddarea as $record) {
            self::create($record);
        }

        // Delete tag collections that are no longer needed.
        foreach ($todeletecoll as $key => $tagcoll) {
            core_tag_collection::delete($tagcoll);
        }
    }

    /**
     * Deletes all tag areas, collections and instances associated with the plugin.
     *
     * @param string $pluginname
     */
    public static function uninstall($pluginname) {
        global $DB;

        list($a, $b) = core_component::normalize_component($pluginname);
        if (empty($b) || $a === 'core') {
            throw new coding_exception('Core component can not be uninstalled');
        }
        $component = $a . '_' . $b;

        core_tag_tag::delete_instances($component);

        $DB->delete_records('tag_area', array('component' => $component));
        $DB->delete_records('tag_coll', array('component' => $component));
        cache::make('core', 'tags')->delete_many(array('tag_area', 'tag_coll'));
    }

    /**
     * Moves existing tags associated with an item type to another tag collection
     *
     * @param string $component
     * @param string $itemtype
     * @param int $tagcollid
     */
    public static function move_tags($component, $itemtype, $tagcollid) {
        global $DB;
        $params = array('itemtype1' => $itemtype, 'component1' => $component,
            'itemtype2' => $itemtype, 'component2' => $component,
            'tagcollid1' => $tagcollid, 'tagcollid2' => $tagcollid);

        // Find all collections that need to be cleaned later.
        $sql = "SELECT DISTINCT t.tagcollid " .
            "FROM {tag_instance} ti " .
            "JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1 " .
            "WHERE ti.itemtype = :itemtype2 AND ti.component = :component2 ";
        $cleanupcollections = $DB->get_fieldset_sql($sql, $params);

        // Find all tags that are related to the tags being moved and make sure they are present in the target tagcoll.
        // This query is a little complicated because Oracle does not allow to run SELECT DISTINCT on CLOB fields.
        $sql = "SELECT name, rawname, description, descriptionformat, userid, isstandard, flag, timemodified ".
                "FROM {tag} WHERE id IN ".
                "(SELECT r.id ".
                "FROM {tag_instance} ti ". // Instances that need moving.
                "JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1 ". // Tags that need moving.
                "JOIN {tag_instance} tr ON tr.itemtype = 'tag' and tr.component = 'core' AND tr.itemid = t.id ".
                "JOIN {tag} r ON r.id = tr.tagid ". // Tags related to the tags that need moving.
                "LEFT JOIN {tag} re ON re.name = r.name AND re.tagcollid = :tagcollid2 ". // Existing tags in the target tagcoll with the same name as related tags.
                "WHERE ti.itemtype = :itemtype2 AND ti.component = :component2 ".
                "    AND re.id IS NULL)"; // We need related tags that ARE NOT present in the target tagcoll.
        $result = $DB->get_records_sql($sql, $params);
        foreach ($result as $tag) {
            $tag->tagcollid = $tagcollid;
            $tag->id = $DB->insert_record('tag', $tag);
            \core\event\tag_created::create_from_tag($tag);
        }

        // Find all tags that need moving and have related tags, remember their related tags.
        $sql = "SELECT t.name AS tagname, r.rawname AS relatedtag ".
                "FROM {tag_instance} ti ". // Instances that need moving.
                "JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1 ". // Tags that need moving.
                "JOIN {tag_instance} tr ON t.id = tr.tagid AND tr.itemtype = 'tag' and tr.component = 'core' ".
                "JOIN {tag} r ON r.id = tr.itemid ". // Tags related to the tags that need moving.
                "WHERE ti.itemtype = :itemtype2 AND ti.component = :component2 ".
                "ORDER BY t.id, tr.ordering ";
        $relatedtags = array();
        $result = $DB->get_recordset_sql($sql, $params);
        foreach ($result as $record) {
            $relatedtags[$record->tagname][] = $record->relatedtag;
        }
        $result->close();

        // Find all tags that are used for this itemtype/component and are not present in the target tag collection.
        // This query is a little complicated because Oracle does not allow to run SELECT DISTINCT on CLOB fields.
        $sql = "SELECT id, name, rawname, description, descriptionformat, userid, isstandard, flag, timemodified
                FROM {tag} WHERE id IN
                (SELECT t.id
                FROM {tag_instance} ti
                JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1
                LEFT JOIN {tag} tt ON tt.name = t.name AND tt.tagcollid = :tagcollid2
                WHERE ti.itemtype = :itemtype2 AND ti.component = :component2
                    AND tt.id IS NULL)";
        $movedtags = array(); // Keep track of moved tags so we don't hit DB index violation.
        $result = $DB->get_records_sql($sql, $params);
        foreach ($result as $tag) {
            $originaltagid = $tag->id;
            if (array_key_exists($tag->name, $movedtags)) {
                // Case of corrupted data when the same tag was in several collections.
                $tag->id = $movedtags[$tag->name];
            } else {
                // Copy the tag into the new collection.
                unset($tag->id);
                $tag->tagcollid = $tagcollid;
                $tag->id = $DB->insert_record('tag', $tag);
                \core\event\tag_created::create_from_tag($tag);
                $movedtags[$tag->name] = $tag->id;
            }
            $DB->execute("UPDATE {tag_instance} SET tagid = ? WHERE tagid = ? AND itemtype = ? AND component = ?",
                    array($tag->id, $originaltagid, $itemtype, $component));
        }

        // Find all tags that are used for this itemtype/component and are already present in the target tag collection.
        $sql = "SELECT DISTINCT t.id, tt.id AS targettagid
                FROM {tag_instance} ti
                JOIN {tag} t ON t.id = ti.tagid AND t.tagcollid <> :tagcollid1
                JOIN {tag} tt ON tt.name = t.name AND tt.tagcollid = :tagcollid2
                WHERE ti.itemtype = :itemtype2 AND ti.component = :component2";
        $result = $DB->get_records_sql($sql, $params);
        foreach ($result as $tag) {
            $DB->execute("UPDATE {tag_instance} SET tagid = ? WHERE tagid = ? AND itemtype = ? AND component = ?",
                    array($tag->targettagid, $tag->id, $itemtype, $component));
        }

        // Add related tags to the moved tags.
        if ($relatedtags) {
            $tags = core_tag_tag::get_by_name_bulk($tagcollid, array_keys($relatedtags));
            foreach ($tags as $tag) {
                $tag->add_related_tags($relatedtags[$tag->name]);
            }
        }

        if ($cleanupcollections) {
            core_tag_collection::cleanup_unused_tags($cleanupcollections);
        }

        // Reset caches.
        cache::make('core', 'tags')->delete('tag_area');
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit