/** * Restore $titles and return array with menu information * @param array $titles An array of titles to be restored. After completion, it will contain only the titles that were prepared successfully * @return array A list of restored titles that can be used for menu insertion * */ function RestoreTitles(&$titles) { global $dataDir, $gp_index, $gp_titles; $new_menu = array(); $new_titles = array(); foreach ($titles as $title => $empty) { $new_title = admin_tools::CheckPostedNewPage($title, $message); if (!$new_title) { //message($message); continue; } //add to $gp_index first for PageFile() $index = common::NewFileIndex(); $gp_index[$new_title] = $index; //get trash info about file $title_info = admin_trash::GetInfo($title); if ($title_info === false) { unset($gp_index[$new_title]); continue; } //make sure the trash file exists $trash_file = $dataDir . '/data/_trash/' . $title_info['file']; if (!file_exists($trash_file)) { unset($gp_index[$new_title]); continue; } //copy the trash file to the /_pages directory $new_file = gpFiles::PageFile($new_title); if (!copy($trash_file, $new_file)) { unset($gp_index[$new_title]); continue; } //add to $gp_titles $gp_titles[$index] = array(); $gp_titles[$index]['label'] = $title_info['label']; $gp_titles[$index]['type'] = $title_info['type']; $new_menu[$index] = array(); $new_titles[$new_title] = true; admin_trash::RestoreFile($new_title, $trash_file, $title_info); } $titles = $new_titles; return $new_menu; }
/** * Restore $titles and return array with menu information * @param array $titles An array of titles to be restored. After completion, it will contain only the titles that were prepared successfully * @return array A list of restored titles that can be used for menu insertion * */ static function RestoreTitles(&$titles) { global $dataDir, $gp_index, $gp_titles, $config; $new_menu = array(); $restored = array(); foreach ($titles as $trash_index) { //get trash info about file $title_info = admin_trash::GetInfo($trash_index); if ($title_info === false) { continue; } $new_title = admin_tools::CheckPostedNewPage($title_info['title'], $message); if (!$new_title) { continue; } //make sure the page_file exists if (!gpFiles::Exists($title_info['page_file'])) { continue; } //add to $gp_index before PageFile() if (isset($title_info['index'])) { $index = $title_info['index']; $gp_index[$new_title] = $index; } else { $index = common::NewFileIndex(); $gp_index[$new_title] = $index; } // move the trash file to the /_pages directory if needed $new_file = gpFiles::PageFile($new_title); if (!gpFiles::Exists($new_file)) { if (!gpFiles::Rename($title_info['page_file'], $new_file)) { unset($gp_index[$new_title]); continue; } } //add to $gp_titles $gp_titles[$index] = array(); $gp_titles[$index]['label'] = $title_info['label']; $gp_titles[$index]['type'] = $title_info['type']; $new_menu[$index] = array(); $restored[$trash_index] = $title_info; admin_trash::RestoreFile($new_title, $new_file, $title_info); } $titles = $restored; return $new_menu; }