Beispiel #1
0
 /**
  * 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;
 }
Beispiel #2
0
 /**
  * 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
  *
  */
 public 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 = self::GetInfo($trash_index);
         if ($title_info === false) {
             continue;
         }
         $new_title = \gp\admin\Tools::CheckPostedNewPage($title_info['title'], $message);
         if (!$new_title) {
             continue;
         }
         //make sure the page_file exists
         if (!\gp\tool\Files::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 = \gp\tool::NewFileIndex();
             $gp_index[$new_title] = $index;
         }
         // move the trash file to the /_pages directory if needed
         $new_file = \gp\tool\Files::PageFile($new_title);
         if (!\gp\tool\Files::Exists($new_file)) {
             if (!\gp\tool\Files::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;
         self::RestoreFile($new_title, $new_file, $title_info);
     }
     $titles = $restored;
     return $new_menu;
 }
Beispiel #3
0
 /**
  * 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;
 }