| 54 | | $templates = array(); |
|---|
| 55 | | //set index to server id for easy retrieval |
|---|
| 56 | | foreach ($ret as $s) { |
|---|
| 57 | | //set index to id for easy retrieval |
|---|
| 58 | | $templates[$s['id']] = $s; |
|---|
| 59 | | |
|---|
| 60 | | //default name in one is missing |
|---|
| 61 | | if (!$templates[$s['id']]['name']) { |
|---|
| 62 | | $templates[$s['id']]['name'] = _('Template') . ' ' . $s['id']; |
|---|
| 63 | | } |
|---|
| 64 | | |
|---|
| 65 | | //add details if requested |
|---|
| | 55 | |
|---|
| | 56 | //get hooks from other modules |
|---|
| | 57 | $hook_temps = mod_func_iterator('hook_backup_get_template'); |
|---|
| | 58 | |
|---|
| | 59 | //sanatizes hooks and push them in to the stack |
|---|
| | 60 | foreach ($hook_temps as $mod => $template) { |
|---|
| | 61 | foreach ($template as $my => $temp) { |
|---|
| | 62 | $ret[] = backup_template_sanitize($temp, $mod); |
|---|
| | 63 | } |
|---|
| | 64 | |
|---|
| | 65 | } |
|---|
| | 66 | |
|---|
| | 67 | //sanatize/argument templates |
|---|
| | 68 | foreach ($ret as $temp) { |
|---|
| 67 | | $templates[$s['id']] = backup_get_template($s['id']); |
|---|
| 68 | | } |
|---|
| 69 | | } |
|---|
| 70 | | |
|---|
| | 70 | //backup_get_template() dose its own sanatization |
|---|
| | 71 | $templates[$temp['id']] = backup_get_template($temp['id']); |
|---|
| | 72 | } else { |
|---|
| | 73 | $templates[$temp['id']] = backup_template_sanitize($temp); |
|---|
| | 74 | } |
|---|
| | 75 | } |
|---|
| | 76 | |
|---|
| | 77 | //this ugliness is here pending requiring php-53 |
|---|
| | 78 | //to migrate, just copy the functions in place of the string of same name |
|---|
| | 79 | function _anon_func1($val) { |
|---|
| | 80 | return $val; |
|---|
| | 81 | } |
|---|
| | 82 | |
|---|
| | 83 | function _anon_func2($a, $b) { |
|---|
| | 84 | if ($a['name'] == $b['name']) { |
|---|
| | 85 | return 0; |
|---|
| | 86 | } else { |
|---|
| | 87 | return $a['name'] > $b['name'] ? 1 : -1; |
|---|
| | 88 | } |
|---|
| | 89 | } |
|---|
| | 90 | |
|---|
| | 91 | //remove any false values (templates that didnt pass sanitization) |
|---|
| | 92 | $templates = array_filter($templates, '_anon_func1'); |
|---|
| | 93 | |
|---|
| | 94 | //sort templaes based on template name |
|---|
| | 95 | uasort($templates, '_anon_func2'); |
|---|
| | 96 | |
|---|
| | 100 | //if the id is preceded by a module name, ask that module for the details |
|---|
| | 101 | if (strpos($id, '-') !== false) { |
|---|
| | 102 | |
|---|
| | 103 | //get data by breaking up backup id |
|---|
| | 104 | list($mod, $id) = explode('-', $id); |
|---|
| | 105 | |
|---|
| | 106 | //return template data if $mod's function exsists |
|---|
| | 107 | if (function_exists($mod . '_hook_backup_get_template')) { |
|---|
| | 108 | return backup_template_sanitize( |
|---|
| | 109 | call_user_func($mod . '_hook_backup_get_template', $id), |
|---|
| | 110 | $mod |
|---|
| | 111 | ); |
|---|
| | 112 | } |
|---|
| | 113 | |
|---|
| | 114 | } |
|---|
| | 115 | |
|---|
| | 320 | |
|---|
| | 321 | /** |
|---|
| | 322 | * |
|---|
| | 323 | * Sanatize a template and ensures it is in format we excpet |
|---|
| | 324 | * @pram array - a template |
|---|
| | 325 | * @pram string - module name, default to backup |
|---|
| | 326 | * |
|---|
| | 327 | * @returns mixed - the sanatized template or fals on error |
|---|
| | 328 | */ |
|---|
| | 329 | function backup_template_sanitize($temp, $mod = 'backup') { |
|---|
| | 330 | |
|---|
| | 331 | //backup's id's are just a number. Add the module name for consistancy with hooks |
|---|
| | 332 | //this can get a bit tricky - make sure we dotn already have a mod name set! |
|---|
| | 333 | if ($mod == 'backup' && strpos($temp['id'], '-') === false) { |
|---|
| | 334 | $temp['id'] = 'backup-' . $temp['id']; |
|---|
| | 335 | } |
|---|
| | 336 | $id = explode('-', $temp['id']); |
|---|
| | 337 | |
|---|
| | 338 | //ensure we have a name |
|---|
| | 339 | $temp['name'] = $temp['name'] ? $temp['name'] : $id[0] . ' ' . $id[1]; |
|---|
| | 340 | |
|---|
| | 341 | //hooked templates are ALWAYS immortal |
|---|
| | 342 | //partly as we dont have delete hooks, and partly because there is no |
|---|
| | 343 | //need for modules to create templates that are NOT hard coded |
|---|
| | 344 | if ($mod != 'backup') { |
|---|
| | 345 | $temp['immortal'] = 'true'; |
|---|
| | 346 | } |
|---|
| | 347 | |
|---|
| | 348 | //unserialize data |
|---|
| | 349 | if (!isset($temp['data'])) { |
|---|
| | 350 | $temp['data'] = array(); |
|---|
| | 351 | } elseif(is_string($temp['data'])) { |
|---|
| | 352 | $temp['data'] = unserialize($temp['data']); |
|---|
| | 353 | } |
|---|
| | 354 | |
|---|
| | 355 | return $temp; |
|---|
| | 356 | } |
|---|