Beispiel #1
0
 protected function SaveSection($i, $arg, &$unused_sections)
 {
     global $langmessage;
     $section_types = \gp\tool\Output\Sections::GetTypes();
     $section_attrs = array('gp_label', 'gp_color', 'gp_collapse');
     // moved / copied sections
     if (ctype_digit($arg)) {
         $arg = (int) $arg;
         if (!isset($this->file_sections[$arg])) {
             msg($langmessage['OOPS'] . ' (Invalid Section Number)');
             return false;
         }
         unset($unused_sections[$arg]);
         $new_section = $this->file_sections[$arg];
         $new_section['attributes'] = array();
         // otherwise, new sections
     } else {
         if (!isset($section_types[$arg])) {
             msg($langmessage['OOPS'] . ' (Unknown Type: ' . $arg . ')');
             return false;
         }
         $new_section = \gp\tool\Editing::DefaultContent($arg);
     }
     // attributes
     $this->PostedAttributes($new_section, $i);
     // wrapper section 'contains_sections'
     if ($new_section['type'] == 'wrapper_section') {
         $new_section['contains_sections'] = isset($_POST['contains_sections']) ? $_POST['contains_sections'][$i] : '0';
     }
     // section attributes
     foreach ($section_attrs as $attr) {
         unset($new_section[$attr]);
         if (!empty($_POST[$attr][$i])) {
             $new_section[$attr] = $_POST[$attr][$i];
         }
     }
     return $new_section;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 /**
  * Create a new extra content section
  *
  */
 public function NewSection()
 {
     global $langmessage, $gpAdmin;
     $title = \gp\tool\Editing::CleanTitle($_REQUEST['new_title']);
     if (empty($title)) {
         message($langmessage['OOPS'] . ' (Invalid Title)');
         return false;
     }
     $file = $this->folder . '/' . $title . '/page.php';
     $section = \gp\tool\Editing::DefaultContent($_POST['type']);
     $section['created'] = time();
     $section['created_by'] = $gpAdmin['username'];
     $sections = array($section);
     if (!\gp\tool\Files::SaveData($file, 'file_sections', $sections)) {
         message($langmessage['OOPS'] . ' (Not Saved)');
         return false;
     }
     message($langmessage['SAVED']);
     $this->areas[$title] = $title;
 }
Beispiel #4
0
 /**
  * Return the name of the cleansed extra area name, create file if it doesn't already exist
  *
  */
 public function NewExtraArea()
 {
     global $langmessage, $dataDir;
     $title = \gp\tool\Editing::CleanTitle($_REQUEST['extra_area']);
     if (empty($title)) {
         message($langmessage['OOPS']);
         return false;
     }
     $data = \gp\tool\Editing::DefaultContent($_POST['type']);
     $file = $dataDir . '/data/_extra/' . $title . '.php';
     if (\gp\tool\Files::Exists($file)) {
         return $title;
     }
     if (!\gp\tool\Files::SaveData($file, 'extra_content', $data)) {
         message($langmessage['OOPS']);
         return false;
     }
     return $title;
 }