/** * Perform a page copy * */ public function CopyPage() { global $gp_index, $gp_titles, $langmessage; $this->CacheSettings(); if (!isset($_POST['from_title'])) { msg($langmessage['OOPS'] . ' (Copy from not selected)'); if (isset($_POST['insert_how'])) { $this->InsertDialog($_POST['insert_how']); } else { $this->AddHidden(); } return false; } //existing page info $from_title = $_POST['from_title']; if (!isset($gp_index[$from_title])) { msg($langmessage['OOPS_TITLE']); return false; } $from_index = $gp_index[$from_title]; $info = $gp_titles[$from_index]; //check the new title $title = $_POST['title']; $title = \gp\admin\Tools::CheckPostedNewPage($title, $message); if ($title === false) { msg($message); return false; } //get the existing content $from_file = \gp\tool\Files::PageFile($from_title); $contents = file_get_contents($from_file); //add to $gp_index first! $index = \gp\tool::NewFileIndex(); $gp_index[$title] = $index; $file = \gp\tool\Files::PageFile($title); if (!\gp\tool\Files::Save($file, $contents)) { msg($langmessage['OOPS'] . ' (File not saved)'); return false; } //add to gp_titles $new_titles = array(); $new_titles[$index]['label'] = \gp\admin\Tools::PostedLabel($_POST['title']); $new_titles[$index]['type'] = $info['type']; $gp_titles += $new_titles; //add to menu $insert = array(); $insert[$index] = array(); if (!$this->SaveNew($insert)) { $this->RestoreSettings(); return false; } $this->HiddenSaved($index); return true; }
public function TrashRow($trash_index, $info, $show_orphaned = false) { global $langmessage; $class = ''; if (isset($info['orphaned'])) { $class = 'orphaned'; } //title echo '<tr class="' . $class . '"><td>'; echo '<label style="display:block;">'; echo '<input type="checkbox" name="titles[]" value="' . htmlspecialchars($trash_index) . '" />'; echo ' '; if (isset($info['orphaned'])) { echo '(Orphaned) '; } echo \gp\tool::Link('Admin/Trash/' . $trash_index, str_replace('_', ' ', $info['title'])); echo '</label>'; //time echo '</td><td>'; if (!empty($info['time'])) { $elapsed = \gp\admin\Tools::Elapsed(time() - $info['time']); echo sprintf($langmessage['_ago'], $elapsed); } echo '</td><td>'; if (isset($info['type'])) { $this->TitleTypes($info['type']); } echo '</td><td>'; if (\gp\admin\Tools::CheckPostedNewPage($info['title'], $msg)) { echo \gp\tool::Link('Admin/Trash', $langmessage['restore'], 'cmd=RestoreDeleted&titles[]=' . rawurlencode($trash_index), array('data-cmd' => 'postlink')); } else { echo '<span>' . $langmessage['restore'] . '</span>'; } echo ' '; echo \gp\tool::Link('Admin/Trash', $langmessage['delete'], 'cmd=DeleteFromTrash&titles[]=' . rawurlencode($trash_index), array('data-cmd' => 'postlink')); echo '</td></tr>'; }
/** * Create a new page from a user post * */ public static function CreateNew() { global $gp_index, $gp_titles, $langmessage, $gpAdmin; //check title $title = $_POST['title']; $title = \gp\admin\Tools::CheckPostedNewPage($title, $message); if ($title === false) { msg($message); return false; } //multiple section types $type = $_POST['content_type']; if (strpos($type, '{') === 0) { $types = json_decode($type, true); if ($types) { $types += array('wrapper_class' => 'gpRow'); $content = array(); //wrapper section $section = \gp\tool\Editing::DefaultContent('wrapper_section'); $section['contains_sections'] = count($types['types']); $section['attributes']['class'] = $types['wrapper_class']; $content[] = $section; //nested sections foreach ($types['types'] as $type) { if (strpos($type, '.')) { list($type, $class) = explode('.', $type, 2); } else { $class = ''; } $section = \gp\tool\Editing::DefaultContent($type); $section['attributes']['class'] .= ' ' . $class; $content[] = $section; } } //single section type } else { $content = \gp\tool\Editing::DefaultContent($type, $_POST['title']); if ($content['content'] === false) { return false; } } //add to $gp_index first! $index = \gp\tool::NewFileIndex(); $gp_index[$title] = $index; if (!\gp\tool\Files::NewTitle($title, $content, $type)) { msg($langmessage['OOPS'] . ' (cn1)'); unset($gp_index[$title]); return false; } //add to gp_titles $new_titles = array(); $new_titles[$index]['label'] = \gp\admin\Tools::PostedLabel($_POST['title']); $new_titles[$index]['type'] = $type; $gp_titles += $new_titles; //add to users editing if ($gpAdmin['editing'] != 'all') { $gpAdmin['editing'] = rtrim($gpAdmin['editing'], ',') . ',' . $index . ','; $users = \gp\tool\Files::Get('_site/users'); $users[$gpAdmin['username']]['editing'] = $gpAdmin['editing']; \gp\tool\Files::SaveData('_site/users', 'users', $users); } return $index; }