Esempio n. 1
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;
 }