PageRenderTime 67ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/mplayer/backuplib.php

https://github.com/ewout/moodle-atpusp
PHP | 252 lines | 181 code | 35 blank | 36 comment | 23 complexity | a801a69968f9089a278d264dbf4611c6 MD5 | raw file
  1. <?php //$Id: backuplib.php,v 1.7 2007/04/22 22:07:03 stronk7 Exp $
  2. //This php script contains all the stuff to backup/restore
  3. //mplayer mods
  4. //This is the "graphical" structure of the mplayer mod:
  5. //
  6. // mplayer
  7. // (CL,pk->id,files)
  8. //
  9. // Meaning: pk->primary key field of the table
  10. // fk->foreign key to link with parent
  11. // nt->nested field (recursive data)
  12. // CL->course level info
  13. // UL->user level info
  14. // files->table may have files)
  15. //
  16. //-----------------------------------------------------------
  17. //This function executes all the backup procedure about this mod
  18. function mplayer_backup_mods($bf,$preferences) {
  19. global $CFG;
  20. $status = true;
  21. ////Iterate over mplayer table
  22. $mplayers = get_records ("mplayer","course",$preferences->backup_course,"id");
  23. if ($mplayers) {
  24. foreach ($mplayers as $mplayer) {
  25. if (backup_mod_selected($preferences,'mplayer',$mplayer->id)) {
  26. $status = mplayer_backup_one_mod($bf,$preferences,$mplayer);
  27. }
  28. }
  29. }
  30. return $status;
  31. }
  32. function mplayer_backup_one_mod($bf,$preferences,$mplayer) {
  33. global $CFG;
  34. if (is_numeric($mplayer)) {
  35. $mplayer = get_record('mplayer','id',$mplayer);
  36. }
  37. $status = true;
  38. //Start mod
  39. fwrite ($bf,start_tag("MOD",3,true));
  40. //Print assignment data
  41. fwrite ($bf,full_tag("ID",4,false,$mplayer->id));
  42. fwrite ($bf,full_tag("MODTYPE",4,false,"mplayer"));
  43. fwrite ($bf,full_tag("NAME",4,false,$mplayer->name));
  44. fwrite ($bf,full_tag("INTRO",4,false,$mplayer->intro));
  45. fwrite ($bf,full_tag("INTROFORMAT",4,false,$mplayer->introformat));
  46. fwrite ($bf,full_tag("TIMECREATED",4,false,$mplayer->timecreated));
  47. fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$mplayer->timemodified));
  48. fwrite ($bf,full_tag("CONFIGXML",4,false,$mplayer->configxml));
  49. fwrite ($bf,full_tag("AUTHOR",4,false,$mplayer->author));
  50. fwrite ($bf,full_tag("MPLAYERDATE",4,false,$mplayer->mplayerdate));
  51. fwrite ($bf,full_tag("DESCRIPTION",4,false,$mplayer->description));
  52. fwrite ($bf,full_tag("INFOBOXCOLOR",4,false,$mplayer->infoboxcolor));
  53. fwrite ($bf,full_tag("INFOBOXPOSITION",4,false,$mplayer->infoboxposition));
  54. fwrite ($bf,full_tag("INFOBOXSIZE",4,false,$mplayer->infoboxsize));
  55. fwrite ($bf,full_tag("DURATION",4,false,$mplayer->duration));
  56. fwrite ($bf,full_tag("MPLAYERFILE",4,false,$mplayer->mplayerfile));
  57. fwrite ($bf,full_tag("HDBITRATE",4,false,$mplayer->hdbitrate));
  58. fwrite ($bf,full_tag("HDFILE",4,false,$mplayer->hdfile));
  59. fwrite ($bf,full_tag("HDFULLSCREEN",4,false,$mplayer->hdfullscreen));
  60. fwrite ($bf,full_tag("HDSATE",4,false,$mplayer->hdstate));
  61. fwrite ($bf,full_tag("LIVESTREAMFILE",4,false,$mplayer->livestreamfile));
  62. fwrite ($bf,full_tag("LIVESTREAMIMAGE",4,false,$mplayer->livestreamimage));
  63. fwrite ($bf,full_tag("LIVESTREAMINTERVAL",4,false,$mplayer->livestreaminterval));
  64. fwrite ($bf,full_tag("LIVESTREAMMESSAGE",4,false,$mplayer->livestreammessage));
  65. fwrite ($bf,full_tag("LIVESTREAMSTREAMER",4,false,$mplayer->livestreamstreamer));
  66. fwrite ($bf,full_tag("LIVESTREAMTAGS",4,false,$mplayer->livestreamtags));
  67. fwrite ($bf,full_tag("IMAGE",4,false,$mplayer->image));
  68. fwrite ($bf,full_tag("AUDIODESCRIPTIONFILE",4,false,$mplayer->audiodescriptionfile));
  69. fwrite ($bf,full_tag("AUDIODESCRIPTIONSTATE",4,false,$mplayer->audiodescriptionstate));
  70. fwrite ($bf,full_tag("AUDIODESCRIPTIONVOLUME",4,false,$mplayer->audiodescriptionvolume));
  71. fwrite ($bf,full_tag("MPLAYERSTART",4,false,$mplayer->mplayerstart));
  72. fwrite ($bf,full_tag("TAGS",4,false,$mplayer->tags));
  73. fwrite ($bf,full_tag("TITLE",4,false,$mplayer->title));
  74. fwrite ($bf,full_tag("TYPE",4,false,$mplayer->type));
  75. fwrite ($bf,full_tag("BACKCOLOR",4,false,$mplayer->backcolor));
  76. fwrite ($bf,full_tag("FRONTCOLOR",4,false,$mplayer->frontcolor));
  77. fwrite ($bf,full_tag("LIGHTCOLOR",4,false,$mplayer->lightcolor));
  78. fwrite ($bf,full_tag("SCREENCOLOR",4,false,$mplayer->screencolor));
  79. fwrite ($bf,full_tag("CONTROLBAR",4,false,$mplayer->controlbar));
  80. fwrite ($bf,full_tag("SMOOTHING",4,false,$mplayer->smoothing));
  81. fwrite ($bf,full_tag("HEIGHT",4,false,$mplayer->height));
  82. fwrite ($bf,full_tag("PLAYLIST",4,false,$mplayer->playlist));
  83. fwrite ($bf,full_tag("PLAYLISTSIZE",4,false,$mplayer->playlistsize));
  84. fwrite ($bf,full_tag("SKIN",4,false,$mplayer->skin));
  85. fwrite ($bf,full_tag("WIDTH",4,false,$mplayer->width));
  86. fwrite ($bf,full_tag("AUTOSTART",4,false,$mplayer->autostart));
  87. fwrite ($bf,full_tag("BUFFERLENGTH",4,false,$mplayer->bufferlength));
  88. fwrite ($bf,full_tag("FULLSCREEN",4,false,$mplayer->fullscreen));
  89. fwrite ($bf,full_tag("ICONS",4,false,$mplayer->icons));
  90. fwrite ($bf,full_tag("ITEM",4,false,$mplayer->item));
  91. fwrite ($bf,full_tag("LOGOBOXALIGN",4,false,$mplayer->logoboxalign));
  92. fwrite ($bf,full_tag("LOGOBOXFILE",4,false,$mplayer->logoboxfile));
  93. fwrite ($bf,full_tag("LOGOBOXLINK",4,false,$mplayer->logoboxlink));
  94. fwrite ($bf,full_tag("LOGOBOXMARGIN",4,false,$mplayer->logoboxmargin));
  95. fwrite ($bf,full_tag("LOGOBOXPOSITION",4,false,$mplayer->logoboxposition));
  96. fwrite ($bf,full_tag("LOGOFILE",4,false,$mplayer->logofile));
  97. fwrite ($bf,full_tag("LOGOLINK",4,false,$mplayer->logolink));
  98. fwrite ($bf,full_tag("LOGOHIDE",4,false,$mplayer->logohide));
  99. fwrite ($bf,full_tag("LOGOPOSITION",4,false,$mplayer->logoposition));
  100. fwrite ($bf,full_tag("MUTE",4,false,$mplayer->mute));
  101. fwrite ($bf,full_tag("QUALITY",4,false,$mplayer->quality));
  102. fwrite ($bf,full_tag("MPLAYERREPEAT",4,false,$mplayer->mplayerrepeat));
  103. fwrite ($bf,full_tag("RESIZING",4,false,$mplayer->resizing));
  104. fwrite ($bf,full_tag("SHUFFLE",4,false,$mplayer->shuffle));
  105. fwrite ($bf,full_tag("STATE",4,false,$mplayer->state));
  106. fwrite ($bf,full_tag("STRETCHING",4,false,$mplayer->stretching));
  107. fwrite ($bf,full_tag("VOLUME",4,false,$mplayer->volume));
  108. fwrite ($bf,full_tag("PLUGINS",4,false,$mplayer->plugins));
  109. fwrite ($bf,full_tag("STREAMER",4,false,$mplayer->streamer));
  110. fwrite ($bf,full_tag("TRACECALL",4,false,$mplayer->tracecall));
  111. fwrite ($bf,full_tag("CAPTIONSBACK",4,false,$mplayer->captionsback));
  112. fwrite ($bf,full_tag("CAPTIONSFILE",4,false,$mplayer->captionsfile));
  113. fwrite ($bf,full_tag("CAPTIONSFONTSIZE",4,false,$mplayer->captionsfontsize));
  114. fwrite ($bf,full_tag("CAPTIONSSTATE",4,false,$mplayer->captionsstate));
  115. fwrite ($bf,full_tag("FPVERSION",4,false,$mplayer->fpversion));
  116. fwrite ($bf,full_tag("NOTES",4,false,$mplayer->notes));
  117. fwrite ($bf,full_tag("METAVIEWERPOSITION",4,false,$mplayer->metaviewerposition));
  118. fwrite ($bf,full_tag("METAVIEWERSIZE",4,false,$mplayer->metaviewersize));
  119. fwrite ($bf,full_tag("SEARCHBARCOLOR",4,false,$mplayer->searchbarcolor));
  120. fwrite ($bf,full_tag("SEARCHBARLABEL",4,false,$mplayer->searchbarlabel));
  121. fwrite ($bf,full_tag("SEARCHBARPOSITION",4,false,$mplayer->searchbarposition));
  122. fwrite ($bf,full_tag("SEARCHBARSCRIPT",4,false,$mplayer->searchbarscript));
  123. fwrite ($bf,full_tag("SNAPSHOTBITMAP",4,false,$mplayer->snapshotbitmap));
  124. fwrite ($bf,full_tag("SNAPSHOTSCRIPT",4,false,$mplayer->snapshotscript));
  125. //End mod
  126. $status = fwrite ($bf,end_tag("MOD",3,true));
  127. if ($status) {
  128. // backup files for this mplayer.
  129. $status = mplayer_backup_files($bf,$preferences,$mplayer);
  130. }
  131. return $status;
  132. }
  133. ////Return an array of info (name,value)
  134. function mplayer_check_backup_mods($course,$user_data=false,$backup_unique_code,$instances=null) {
  135. if (!empty($instances) && is_array($instances) && count($instances)) {
  136. $info = array();
  137. foreach ($instances as $id => $instance) {
  138. $info += mplayer_check_backup_mods_instances($instance,$backup_unique_code);
  139. }
  140. return $info;
  141. }
  142. //First the course data
  143. $info[0][0] = get_string("modulenameplural","mplayer");
  144. if ($ids = mplayer_ids ($course)) {
  145. $info[0][1] = count($ids);
  146. } else {
  147. $info[0][1] = 0;
  148. }
  149. return $info;
  150. }
  151. ////Return an array of info (name,value)
  152. function mplayer_check_backup_mods_instances($instance,$backup_unique_code) {
  153. //First the course data
  154. $info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>';
  155. $info[$instance->id.'0'][1] = '';
  156. return $info;
  157. }
  158. //Return a content encoded to support interactivities linking. Every module
  159. //should have its own. They are called automatically from the backup procedure.
  160. function mplayer_encode_content_links ($content,$preferences) {
  161. global $CFG;
  162. $base = preg_quote($CFG->wwwroot,"/");
  163. //Link to the list of mplayers
  164. $buscar="/(".$base."\/mod\/mplayer\/index.php\?id\=)([0-9]+)/";
  165. $result= preg_replace($buscar,'$@MPLAYERINDEX*$2@$',$content);
  166. //Link to mplayer view by moduleid
  167. $buscar="/(".$base."\/mod\/mplayer\/view.php\?id\=)([0-9]+)/";
  168. $result= preg_replace($buscar,'$@MPLAYERVIEWBYID*$2@$',$result);
  169. //Link to mplayer view by mplayerid
  170. $buscar="/(".$base."\/mod\/mplayer\/view.php\?r\=)([0-9]+)/";
  171. $result= preg_replace($buscar,'$@MPLAYERVIEWBYR*$2@$',$result);
  172. return $result;
  173. }
  174. // INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
  175. //Returns an array of mplayers id
  176. function mplayer_ids ($course) {
  177. global $CFG;
  178. return get_records_sql ("SELECT a.id, a.course
  179. FROM {$CFG->prefix}mplayer a
  180. WHERE a.course = '$course'");
  181. }
  182. function mplayer_backup_files($bf,$preferences,$mplayer) {
  183. global $CFG;
  184. $status = true;
  185. if (!file_exists($CFG->dataroot.'/'.$preferences->backup_course.'/'.$mplayer->mplayerfile)) {
  186. return true ; // doesn't exist but we don't want to halt the entire process so still return true.
  187. }
  188. $status = $status && check_and_create_course_files_dir($preferences->backup_unique_code);
  189. // if this is somewhere deeply nested we need to do all the structure stuff first.....
  190. $bits = explode('/',$mplayer->mplayerfile);
  191. $newbit = '';
  192. for ($i = 0; $i< count($bits)-1; $i++) {
  193. $newbit .= $bits[$i].'/';
  194. $status = $status && check_dir_exists($CFG->dataroot.'/temp/backup/'.$preferences->backup_unique_code.'/course_files/'.$newbit,true);
  195. }
  196. if ($mplayer->mplayerfile === '') {
  197. $status = $status && backup_copy_course_files($preferences); // copy while ignoring backupdata and moddata!!!
  198. } else if (strpos($mplayer->mplayerfile, 'backupdata') === 0 or strpos($mplayer->mplayerfile, $CFG->moddata) === 0) {
  199. // no copying - these directories must not be shared anyway!
  200. } else {
  201. $status = $status && backup_copy_file($CFG->dataroot."/".$preferences->backup_course."/".$mplayer->mplayerfile,
  202. $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/course_files/".$mplayer->mplayerfile);
  203. }
  204. // now, just in case we check moddata ( going forwards, mplayers should use this )
  205. $status = $status && check_and_create_moddata_dir($preferences->backup_unique_code);
  206. $status = $status && check_dir_exists($CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/".$CFG->moddata."/mplayer/",true);
  207. if ($status) {
  208. //Only if it exists !! Thanks to Daniel Miksik.
  209. $instanceid = $mplayer->id;
  210. if (is_dir($CFG->dataroot."/".$preferences->backup_course."/".$CFG->moddata."/mplayer/".$instanceid)) {
  211. $status = backup_copy_file($CFG->dataroot."/".$preferences->backup_course."/".$CFG->moddata."/mplayer/".$instanceid,
  212. $CFG->dataroot."/temp/backup/".$preferences->backup_unique_code."/moddata/mplayer/".$instanceid);
  213. }
  214. }
  215. return $status;
  216. }
  217. ?>