Beispiel #1
0
 /**
  * Toggle the visibility of a page given by $index
  *
  */
 static function Toggle($index, $visibility = '')
 {
     global $gp_titles, $langmessage;
     if (!isset($gp_titles[$index])) {
         msg($langmessage['OOPS'] . ' (Invalid Request)');
         return false;
     }
     if ($visibility == 'private') {
         $gp_titles[$index]['vis'] = 'private';
     } else {
         unset($gp_titles[$index]['vis']);
     }
     return \gp\admin\Tools::SavePagesPHP(true);
 }
Beispiel #2
0
 /**
  * Update the gp_index, gp_titles and menus so that special pages can be renamed
  *
  */
 function Upgrade_234()
 {
     global $gp_index, $gp_titles, $gp_menu, $config, $dataDir;
     $special_indexes = array();
     $new_index = array();
     $new_titles = array();
     foreach ($gp_index as $title => $index) {
         $info = $gp_titles[$index];
         $type = \gp\tool::SpecialOrAdmin($title);
         if ($type === 'special') {
             $special_indexes[$index] = strtolower($title);
             $index = strtolower($title);
             $info['type'] = 'special';
             //some older versions didn't maintain this value well
         }
         $new_index[$title] = $index;
         $new_titles[$index] = $info;
     }
     $gp_titles = $new_titles;
     $gp_index = $new_index;
     //update gp_menu
     $gp_menu = $this->FixMenu($gp_menu, $special_indexes);
     //save pages
     if (!\gp\admin\Tools::SavePagesPHP()) {
         return;
     }
     $config['gpversion'] = '2.3.4';
     \gp\admin\Tools::SaveConfig();
     //update alt menus
     if (isset($config['menus']) && is_array($config['menus'])) {
         foreach ($config['menus'] as $key => $value) {
             $menu_file = $dataDir . '/data/_menus/' . $key . '.php';
             if (\gp\tool\Files::Exists($menu_file)) {
                 $menu = \gp\tool\Output::GetMenuArray($key);
                 $menu = $this->FixMenu($menu, $special_indexes);
                 \gp\tool\Files::SaveData($menu_file, 'menu', $menu);
             }
         }
     }
 }
Beispiel #3
0
 public function NewDrag()
 {
     global $langmessage, $gp_index, $gp_titles;
     $this->page->ajaxReplace = array();
     //get the title of the gallery that was moved
     $dragging = $_POST['title'];
     if (!isset($this->galleries[$dragging])) {
         message($langmessage['OOPS'] . ' (Title not in gallery list)');
         return false;
     }
     $index = $gp_index[$dragging];
     $info = $this->galleries[$dragging];
     unset($this->galleries[$dragging]);
     //set visibility
     if (isset($_POST['active'])) {
         $info['visibility'] = 'show';
         unset($gp_titles[$index]['vis']);
     } else {
         $info['visibility'] = 'hide';
     }
     //place before the element represented by $_POST['next'] if it's set
     if (isset($_POST['next'])) {
         $next = $_POST['next'];
         if (!isset($this->galleries[$next])) {
             message($langmessage['OOPS'] . ' (Next not found)');
             return false;
         }
         if (!\gp\tool\Files::ArrayInsert($next, $dragging, $info, $this->galleries)) {
             message($langmessage['OOPS'] . ' (Insert Failed)');
             return false;
         }
         //place at the end
     } else {
         $this->galleries[$dragging] = $info;
     }
     //save it
     if (!self::SaveIndex($this->galleries)) {
         message($langmessage['OOPS'] . ' (Not Saved)');
         return false;
     }
     if (!\gp\admin\Tools::SavePagesPHP(true)) {
         return false;
     }
 }
Beispiel #4
0
 /**
  * Remove files from the trash by restoring them to $gp_titles and $gp_index
  *
  */
 public function RestoreDeleted()
 {
     global $langmessage, $gp_titles, $gp_index;
     if (empty($_POST['titles']) || !is_array($_POST['titles'])) {
         message($langmessage['OOPS'] . ' (No Titles)');
         return;
     }
     $titles = $_POST['titles'];
     self::RestoreTitles($titles);
     if (!$titles) {
         message($langmessage['OOPS'] . ' (R1)');
         return false;
     }
     if (!\gp\admin\Tools::SavePagesPHP(true)) {
         return false;
     }
     self::ModTrashData(null, $titles);
     $show_titles = array();
     foreach ($titles as $trash_index => $info) {
         $show_titles[] = \gp\tool::Link($info['title'], $info['title']);
         unset($this->trash_files[$trash_index]);
     }
     $title_string = implode(', ', $show_titles);
     $link = \gp\tool::GetUrl('Admin/Menu');
     $message = sprintf($langmessage['file_restored'], $title_string, $link);
     message($message);
 }
Beispiel #5
0
 /**
  * Save pages
  *
  * @param array $titles
  * @return bool
  */
 protected function SaveNew($titles)
 {
     global $langmessage;
     //menu modification
     if (isset($_POST['insert_where']) && isset($_POST['insert_how'])) {
         if (!$this->MenuInsert($titles, $_POST['insert_where'], $_POST['insert_how'])) {
             msg($langmessage['OOPS'] . ' (Insert Failed)');
             return false;
         }
         if (!$this->SaveMenu(true)) {
             msg($langmessage['OOPS'] . ' (Menu Not Saved)');
             return false;
         }
         return true;
     }
     if (!\gp\admin\Tools::SavePagesPHP(true)) {
         return false;
     }
     return true;
 }
Beispiel #6
0
 /**
  * Handle renaming a page based on POSTed data
  *
  */
 public static function RenameFile($title)
 {
     global $langmessage, $page, $gp_index, $gp_titles;
     $page->ajaxReplace = array();
     //change the title
     $title = self::RenameFileWorker($title);
     if ($title === false) {
         return false;
     }
     if (!isset($gp_index[$title])) {
         msg($langmessage['OOPS']);
         return false;
     }
     $id = $gp_index[$title];
     $title_info =& $gp_titles[$id];
     //change the label
     $title_info['label'] = \gp\admin\Tools::PostedLabel($_POST['new_label']);
     if (isset($title_info['lang_index'])) {
         unset($title_info['lang_index']);
     }
     //browser_title, keywords, description
     self::SetInfo($title_info, 'browser_title');
     self::SetInfo($title_info, 'keywords');
     self::SetInfo($title_info, 'description');
     self::SetRobots($title_info);
     //same as auto-generated?
     $auto_browser_title = strip_tags($title_info['label']);
     if (isset($title_info['browser_title']) && $title_info['browser_title'] == $auto_browser_title) {
         unset($title_info['browser_title']);
     }
     if (!\gp\admin\Tools::SavePagesPHP(true, true)) {
         return false;
     }
     return $title;
 }
Beispiel #7
0
 /**
  * Recalculate the file_type string for this file
  * Updates $this->meta_data and $gp_titles
  *
  */
 public function ResetFileTypes()
 {
     global $gp_titles;
     $new_types = array();
     foreach ($this->file_sections as $section) {
         $new_types[] = $section['type'];
     }
     $new_types = array_unique($new_types);
     $new_types = array_diff($new_types, array(''));
     sort($new_types);
     $new_types = implode(',', $new_types);
     $this->meta_data['file_type'] = $new_types;
     if (!isset($gp_titles[$this->gp_index])) {
         return;
     }
     $gp_titles[$this->gp_index]['type'] = $new_types;
     \gp\admin\Tools::SavePagesPHP();
 }
Beispiel #8
0
 public function SaveMenu($menu_and_pages = false)
 {
     global $dataDir;
     if ($this->is_main_menu) {
         return \gp\admin\Tools::SavePagesPHP();
     }
     if (is_null($this->curr_menu_array)) {
         return false;
     }
     if ($menu_and_pages && !\gp\admin\Tools::SavePagesPHP()) {
         return false;
     }
     $menu_file = $dataDir . '/data/_menus/' . $this->curr_menu_id . '.php';
     return \gp\tool\Files::SaveData($menu_file, 'menu', $this->curr_menu_array);
 }
Beispiel #9
0
 /**
  * Update layout information if needed
  *
  */
 public static function LayoutInfo()
 {
     global $page, $gpLayouts, $get_all_gadgets_called;
     if (!\gp\tool\Output::$template_included) {
         return;
     }
     if (\gp\tool::RequestType() != 'template') {
         return;
     }
     $layout = $page->gpLayout;
     if (!isset($gpLayouts[$layout])) {
         return;
     }
     $layout_info =& $gpLayouts[$layout];
     //template.php file not modified
     $template_file = realpath($page->theme_dir . '/template.php');
     $template_mod = filemtime($template_file);
     if (isset($layout_info['template_mod']) && $layout_info['template_mod'] >= $template_mod) {
         return;
     }
     $contents = ob_get_contents();
     //charset
     if (strpos($contents, 'charset=') !== false) {
         return;
     }
     //get just the head of the buffer to see if we need to add charset
     $pos = strpos($contents, '</head');
     unset($layout_info['doctype']);
     if ($pos > 0) {
         $head = substr($contents, 0, $pos);
         $layout_info['doctype'] = self::DoctypeMeta($head);
     }
     $layout_info['all_gadgets'] = $get_all_gadgets_called;
     //save
     $layout_info['template_mod'] = $template_mod;
     \gp\admin\Tools::SavePagesPHP();
 }
Beispiel #10
0
 /**
  * Assign a layout to the $title. Child pages without a layout assigned will inherit this setting
  * @param string $title
  */
 public function SetLayout()
 {
     global $gp_index, $gp_titles, $langmessage, $gpLayouts;
     $index = $_POST['index'];
     $title = \gp\tool::IndexToTitle($index);
     if (!$title) {
         msg($langmessage['OOPS']);
         return;
     }
     $this->title = $title;
     $layout = $_POST['layout'];
     if (!isset($gpLayouts[$layout])) {
         msg($langmessage['OOPS']);
         return;
     }
     if (!\gp\tool::verify_nonce('use_' . $layout)) {
         msg($langmessage['OOPS']);
         return;
     }
     //unset, then reset if needed
     unset($gp_titles[$index]['gpLayout']);
     $currentLayout = \gp\Page::OrConfig($index, 'gpLayout');
     if ($currentLayout != $layout) {
         $gp_titles[$index]['gpLayout'] = $layout;
     }
     return \gp\admin\Tools::SavePagesPHP(true, true);
 }
Beispiel #11
0
 /**
  * Save the gpLayouts data
  *
  */
 protected function SaveLayouts($notify_user = true)
 {
     global $gpLayouts;
     if (\gp\admin\Tools::SavePagesPHP($notify_user, $notify_user)) {
         return true;
     }
     if (is_array($this->gpLayouts_before)) {
         $gpLayouts = $this->gpLayouts_before;
     }
     return false;
 }