Ejemplo n.º 1
0
 /**
  * Create the files and folders
  *
  */
 function __construct()
 {
     // HHVM doesn't support writing with PHAR
     // https://github.com/facebook/hhvm/issues/4899
     if (defined('HHVM_VERSION')) {
         $this->types = array('zip');
     }
     $this->dir = sys_get_temp_dir() . '/test-' . rand(1, 10000000);
     foreach ($this->files as $name => $content) {
         $full = $this->dir . '/' . $name;
         \gp\tool\Files::Save($full, $content);
     }
 }
Ejemplo n.º 2
0
 public function SaveAddonData()
 {
     if (!isset($this->dataFile)) {
         trigger_error('dataFile not set');
         return;
     }
     $addonData = array();
     while (count($this->addonHistory) > 30) {
         array_shift($this->addonHistory);
     }
     $addonData['history'] = $this->addonHistory;
     $addonData['reviews'] = $this->addonReviews;
     return \gp\tool\Files::SaveData($this->dataFile, 'addonData', $addonData);
 }
Ejemplo n.º 3
0
 /**
  * Convert a .scss or .less files to .css and include it in the page
  *
  * @param mixed $scss_files A string or array of scss files
  * @param string $type
  * @return bool
  */
 public static function Cache($file_array, $type = 'scss')
 {
     global $dataDir;
     //generage the name of the css file from the modified times and content length of each imported file
     $file_array = (array) $file_array;
     $type = strtolower($type);
     $files_hash = \gp\tool::ArrayHash($file_array);
     $list_file = $dataDir . '/data/_cache/' . $type . '_' . $files_hash . '.list';
     if (file_exists($list_file)) {
         $list = explode("\n", file_get_contents($list_file));
         //pop the etag
         $etag = array_pop($list);
         // generate an etag if needed or if logged in
         if (\gp\tool::LoggedIn()) {
             $etag = \gp\tool::FilesEtag($list);
         }
         $compiled_name = $type . '_' . $files_hash . '_' . $etag . '.css';
         $compiled_file = '/data/_cache/' . $compiled_name;
         if (file_exists($dataDir . $compiled_file)) {
             return $compiled_file;
         }
     }
     if ($type == 'less') {
         $compiled = self::ParseLess($file_array);
     } else {
         $compiled = self::ParseScss($file_array);
     }
     if (!$compiled) {
         return false;
     }
     // generate the file name
     $etag = \gp\tool::FilesEtag($file_array);
     $compiled_name = $type . '_' . $files_hash . '_' . $etag . '.css';
     $compiled_file = '/data/_cache/' . $compiled_name;
     // save the cache
     // use the last line for the etag
     $list = $file_array;
     $list[] = $etag;
     $cache = implode("\n", $list);
     if (!\gp\tool\Files::Save($list_file, $cache)) {
         return false;
     }
     //save the css
     if (\gp\tool\Files::Save($dataDir . $compiled_file, $compiled)) {
         return $compiled_file;
     }
     return false;
 }
Ejemplo n.º 4
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);
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Check page files for orphaned data files
  *
  */
 protected function CheckPageFiles()
 {
     global $dataDir, $gp_index;
     $pages_dir = $dataDir . '/data/_pages';
     $all_files = \gp\tool\Files::ReadDir($pages_dir, 'php');
     foreach ($all_files as $key => $file) {
         $all_files[$key] = $pages_dir . '/' . $file . '.php';
     }
     $page_files = array();
     foreach ($gp_index as $slug => $index) {
         $page_files[] = \gp\tool\Files::PageFile($slug);
     }
     $diff = array_diff($all_files, $page_files);
     if (!count($diff)) {
         return;
     }
     echo '<h2>Orphaned Data Files</h2>';
     echo '<p>The following data files appear to be orphaned and are most likely no longer needed. Before completely removing these files, we recommend backing them up first.</p>';
     echo '<table class="bordered"><tr><th>File</th></tr>';
     foreach ($diff as $file) {
         echo '<tr><td>' . $file . '</td></tr>';
     }
     echo '</table>';
 }
Ejemplo n.º 6
0
 /**
  * Get the output formatting data for
  *
  */
 public function GetReplaceData($title, $layout_info, $menu_key, $menu_value = array())
 {
     global $langmessage, $gp_titles;
     $isSpecialLink = \gp\tool::SpecialOrAdmin($title);
     //get the data for this title
     $data = array('key' => $menu_key, 'url' => \gp\tool::GetUrl($title), 'title' => $title, 'special' => $isSpecialLink, 'has_layout' => !empty($gp_titles[$menu_key]['gpLayout']), 'layout_color' => $layout_info['color'], 'layout_label' => $layout_info['label'], 'types' => $gp_titles[$menu_key]['type'], 'opts' => '', 'size' => '', 'mtime' => '');
     if (isset($menu_value['level'])) {
         $data['level'] = $menu_value['level'];
     }
     if ($isSpecialLink === false) {
         $file = \gp\tool\Files::PageFile($title);
         $stats = @stat($file);
         if ($stats) {
             $data['size'] = \gp\admin\Tools::FormatBytes($stats['size']);
             $data['time'] = \gp\tool::date($langmessage['strftime_datetime'], $stats['mtime']);
         }
     }
     ob_start();
     \gp\tool\Plugins::Action('MenuPageOptions', array($title, $menu_key, $menu_value, $layout_info));
     $menu_options = ob_get_clean();
     if ($menu_options) {
         $data['opts'] = $menu_options;
     }
     return $data;
 }
Ejemplo n.º 7
0
 private static function RenameFileWorker($title)
 {
     global $langmessage, $dataDir, $gp_index;
     //use new_label or new_title
     if (isset($_POST['new_title'])) {
         $new_title = \gp\admin\Tools::PostedSlug($_POST['new_title']);
     } else {
         $new_title = \gp\admin\Tools::LabelToSlug($_POST['new_label']);
     }
     //title unchanged
     if ($new_title == $title) {
         return $title;
     }
     $special_file = false;
     if (\gp\tool::SpecialOrAdmin($title) !== false) {
         $special_file = true;
     }
     if (!\gp\admin\Tools::CheckTitle($new_title, $message)) {
         msg($message);
         return false;
     }
     $old_gp_index = $gp_index;
     //re-index: make the new title point to the same data index
     $old_file = \gp\tool\Files::PageFile($title);
     $file_index = $gp_index[$title];
     unset($gp_index[$title]);
     $gp_index[$new_title] = $file_index;
     //rename the php file
     if (!$special_file) {
         $new_file = \gp\tool\Files::PageFile($new_title);
         //if the file being renamed doesn't use the index naming convention, then we'll still need to rename it
         if ($new_file != $old_file) {
             $new_dir = dirname($new_file);
             $old_dir = dirname($old_file);
             if (!\gp\tool\Files::Rename($old_dir, $new_dir)) {
                 msg($langmessage['OOPS'] . ' (N3)');
                 $gp_index = $old_gp_index;
                 return false;
             }
         }
         //gallery rename
         \gp\special\Galleries::RenamedGallery($title, $new_title);
     }
     //create a 301 redirect
     if (isset($_POST['add_redirect']) && $_POST['add_redirect'] == 'add') {
         \gp\admin\Settings\Missing::AddRedirect($title, $new_title);
     }
     \gp\tool\Plugins::Action('RenameFileDone', array($file_index, $title, $new_title));
     return $new_title;
 }
Ejemplo n.º 8
0
 static function NewExtra($file, $content)
 {
     $extra_content = array('type' => 'text', 'content' => $content);
     return \gp\tool\Files::SaveData($file, 'extra_content', $extra_content);
 }
Ejemplo n.º 9
0
 /**
  * Clean old files and folders from the temporary folder
  * Delete after 36 hours (129600 seconds)
  *
  */
 public static function CleanTemp()
 {
     global $dataDir;
     $temp_folder = $dataDir . '/data/_temp';
     $files = \gp\tool\Files::ReadDir($temp_folder, false);
     foreach ($files as $file) {
         if ($file == 'index.html') {
             continue;
         }
         $full_path = $temp_folder . '/' . $file;
         $mtime = (int) filemtime($full_path);
         $diff = time() - $mtime;
         if ($diff < 129600) {
             continue;
         }
         \gp\tool\Files::RmAll($full_path);
     }
 }
Ejemplo n.º 10
0
 /**
  * View the contents of a trash file
  *
  */
 public function ViewTrashFile($trash_index)
 {
     global $dataDir, $langmessage, $trash_file;
     $title_info = self::GetInfo($trash_index);
     //delete / restore links
     echo '<div class="pull-right">';
     echo \gp\tool::Link('Admin/Trash', $langmessage['restore'], 'cmd=RestoreDeleted&titles[]=' . rawurlencode($trash_index), array('data-cmd' => 'cnreq', 'class' => 'gpsubmit'));
     echo ' &nbsp; ';
     echo \gp\tool::Link('Admin/Trash', $langmessage['delete'], 'cmd=DeleteFromTrash&titles[]=' . rawurlencode($trash_index), array('data-cmd' => 'cnreq', 'class' => 'gpsubmit'));
     echo '</div>';
     echo '<h2 class="hmargin">';
     echo \gp\tool::Link('Admin/Trash', $langmessage['trash']);
     echo ' &#187; ';
     echo htmlspecialchars($title_info['title']);
     echo '</h2>';
     echo '<hr>';
     //get file sections
     $file_sections = \gp\tool\Files::Get($title_info['page_file'], 'file_sections');
     if ($file_sections) {
         echo \gp\tool\Output\Sections::Render($file_sections, $title_info['title']);
     } else {
         echo '<p>This page no longer has any content</p>';
     }
 }
Ejemplo n.º 11
0
 /**
  * Save the posted data
  *
  */
 function SaveClasses()
 {
     global $langmessage;
     $classes = array();
     foreach ($_POST['class_names'] as $i => $class_names) {
         $class_names = trim($class_names);
         if (empty($class_names)) {
             continue;
         }
         $classes[] = array('names' => $class_names, 'desc' => $_POST['class_desc'][$i]);
     }
     if (\gp\tool\Files::SaveData('_config/classes', 'classes', $classes)) {
         msg($langmessage['SAVED']);
     } else {
         msg($langmessage['OOPS'] . ' (Not Saved)');
     }
 }
Ejemplo n.º 12
0
 /**
  * Download the source code
  *
  */
 function DownloadSource()
 {
     global $langmessage, $dataDir;
     $this->msg('Downloading version ' . $this->core_package['version'] . ' from ' . CMS_READABLE_DOMAIN . '.');
     /* for testing
      * $download = 'http://gpeasy.loc/x_gpEasy.zip';
      */
     $download = addon_browse_path . '/Special_gpEasy?cmd=download';
     $contents = \gp\tool\RemoteGet::Get_Successful($download);
     if (!$contents || empty($contents)) {
         $this->msg($langmessage['download_failed'] . '(1)');
         return false;
     }
     $this->msg($langmessage['package_downloaded']);
     $md5 = md5($contents);
     if ($md5 != $this->core_package['md5']) {
         $this->msg($langmessage['download_failed_md5'] . '<br/>Downloaded Checksum (' . $md5 . ') != Expected Checksum (' . $this->core_package['md5'] . ')');
         return false;
     }
     $this->msg($langmessage['download_verified']);
     //save contents
     $temp_file = $dataDir . \gp\tool\FileSystem::TempFile('/data/_temp/update', '.zip');
     if (!\gp\tool\Files::Save($temp_file, $contents)) {
         $this->msg($langmessage['download_failed'] . ' (2)');
         return false;
     }
     $this->core_package['file'] = $temp_file;
     return true;
 }
Ejemplo n.º 13
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;
 }
Ejemplo n.º 14
0
 public function GetUsers()
 {
     $this->users = \gp\tool\Files::Get('_site/users');
     //fix the editing value
     foreach ($this->users as $username => $userinfo) {
         $userinfo += array('granted' => '');
         \gp\admin\Tools::EditingValue($userinfo);
         $this->users[$username] = $userinfo;
     }
 }
Ejemplo n.º 15
0
 public function put_contents($file, $contents, $type = '')
 {
     if (!\gp\tool\Files::Save($file, $contents)) {
         return false;
     }
     //the core does not need to be world writable
     @chmod($file, FS_CHMOD_FILE);
     return true;
 }
Ejemplo n.º 16
0
 /**
  * Save Gallery Content
  *
  */
 public static function SectionFromPost_Gallery(&$section)
 {
     if (empty($_POST['images'])) {
         $section['content'] = '<ul class="gp_gallery"><li class="gp_to_remove"></li></ul>';
         return;
     }
     ob_start();
     echo '<ul class="gp_gallery">';
     foreach ($_POST['images'] as $i => $image) {
         $thumb_path = \gp\tool::ThumbnailPath($image);
         $caption = $_POST['captions'][$i];
         \gp\tool\Files::cleanText($caption);
         echo '<li>';
         echo '<a class="gallery_gallery" title="' . htmlspecialchars($caption) . '" data-arg="gallery_gallery" href="' . $image . '" data-cmd="gallery">';
         echo '<img src="' . $thumb_path . '" alt="" /></a>';
         echo '<div class="caption">';
         echo $caption;
         echo '</div>';
         echo '</li>';
     }
     echo '</ul>';
     $section['content'] = ob_get_clean();
     $section['images'] = $_POST['images'];
     $section['captions'] = $_POST['captions'];
 }
Ejemplo n.º 17
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;
 }
Ejemplo n.º 18
0
 public static function SaveIndex($galleries)
 {
     global $dataDir;
     $file = $dataDir . '/data/_site/galleries.php';
     return \gp\tool\Files::SaveData($file, 'galleries', $galleries);
 }
Ejemplo n.º 19
0
 /**
  * Get a list of available addons
  *
  */
 function GetAvailAddons()
 {
     global $dataDir;
     $addonPath = $dataDir . '/addons';
     if (!file_exists($addonPath)) {
         message('Warning: The /addons folder "<em>' . $addonPath . '</em>" does not exist on your server.');
         return array();
     }
     $installed_path = $dataDir . '/data/_addoncode';
     $folders = \gp\tool\Files::ReadDir($addonPath, 1);
     $versions = array();
     $avail = array();
     foreach ($folders as $value) {
         $fullPath = $addonPath . '/' . $value;
         $info = $this->GetAvailInstall($fullPath);
         if (!$info) {
             continue;
         }
         $info['upgrade_key'] = \gp\admin\Addon\Tools::UpgradePath($info);
         $avail[$value] = $info;
         if (isset($info['Addon_Version']) && isset($info['Addon_Unique_ID'])) {
             $id = $info['Addon_Unique_ID'];
             if (!isset($versions[$id])) {
                 $versions[$id] = $info['Addon_Version'];
             } elseif (version_compare($versions[$id], $info['Addon_Version'], '<')) {
                 $versions[$id] = $info['Addon_Version'];
                 continue;
             }
         }
         if (!$info['upgrade_key']) {
             $this->avail_count++;
         }
     }
     if (gp_unique_addons) {
         $avail = self::FilterUnique($avail, $versions);
     }
     return $avail;
 }
Ejemplo n.º 20
0
 /**
  * Remove unused code folders created by incomplete addon installations
  *
  */
 public function CleanInstallFolder()
 {
     if (!$this->remote_install) {
         return;
     }
     if (file_exists($this->source)) {
         \gp\tool\Files::RmAll($this->source);
     }
     if (file_exists($this->trash_path)) {
         \gp\tool\Files::RmAll($this->trash_path);
     }
 }
Ejemplo n.º 21
0
 /**
  * Return the data for the requested menu, return the main menu if the requested menu doesn't exist
  * @param string $id String identifying the requested menu
  * @return array menu data
  */
 public function GetMenuArray($id)
 {
     global $dataDir, $gp_menu;
     $menu_file = $dataDir . '/data/_menus/' . $id . '.php';
     if (empty($id) || !\gp\tool\Files::Exists($menu_file)) {
         return \gp\tool\Plugins::Filter('GetMenuArray', array($gp_menu));
     }
     $menu = \gp\tool\Files::Get('_menus/' . $id, 'menu');
     if (\gp\tool\Files::$last_version && version_compare(\gp\tool\Files::$last_version, '3.0b1', '<')) {
         $menu = $this->FixMenu($menu);
     }
     return \gp\tool\Plugins::Filter('GetMenuArray', array($menu));
 }
Ejemplo n.º 22
0
 /**
  * Get possible configuration values
  *
  */
 protected function getPossible()
 {
     global $dataDir, $langmessage;
     $possible = $this->variables;
     $langDir = $dataDir . '/include/thirdparty/ckeditor_34/lang';
     //ckeditor
     $possible['langeditor'] = \gp\tool\Files::readDir($langDir, 'js');
     unset($possible['langeditor']['_languages']);
     $possible['langeditor']['inherit'] = ' ' . $langmessage['default'];
     //want it to be the first in the list
     asort($possible['langeditor']);
     //recaptcha language
     $possible['recaptcha_language'] = array();
     $possible['recaptcha_language']['inherit'] = $langmessage['default'];
     $possible['recaptcha_language']['en'] = 'en';
     $possible['recaptcha_language']['nl'] = 'nl';
     $possible['recaptcha_language']['fr'] = 'fr';
     $possible['recaptcha_language']['de'] = 'de';
     $possible['recaptcha_language']['pt'] = 'pt';
     $possible['recaptcha_language']['ru'] = 'ru';
     $possible['recaptcha_language']['es'] = 'es';
     $possible['recaptcha_language']['tr'] = 'tr';
     //website language
     $possible['language'] = $this->GetPossibleLanguages();
     //tidy
     if (function_exists('tidy_parse_string')) {
         $possible['HTML_Tidy'] = array('off' => $langmessage['Off'], '' => $langmessage['On']);
     } else {
         $possible['HTML_Tidy'] = array('' => 'Unavailable');
     }
     //required email fields
     $possible['require_email'] = array('none' => 'None', '' => 'Subject &amp; Message', 'email' => 'Subject, Message &amp; Email');
     //see xoopsmultimailer.php
     $possible['mail_method'] = array('mail' => 'PHP mail()', 'sendmail' => 'sendmail', 'smtp' => 'smtp', 'smtpauth' => 'SMTPAuth');
     //CDN
     foreach (\gp\tool\Output\Combine::$scripts as $key => $script_info) {
         if (!isset($script_info['cdn'])) {
             continue;
         }
         $config_key = 'cdn_' . $key;
         if (!array_key_exists($config_key, $possible)) {
             continue;
         }
         $opts = array_keys($script_info['cdn']);
         $possible[$config_key] = array_combine($opts, $opts);
         array_unshift($possible[$config_key], $langmessage['None']);
     }
     gpSettingsOverride('configuration', $possible);
     return $possible;
 }
Ejemplo n.º 23
0
 /**
  * Include the content of a normal page
  * @param string $requested The name of the page to include
  *
  */
 static function IncludePage($requested)
 {
     global $gp_index;
     $requested = str_replace(' ', '_', $requested);
     if (!isset($gp_index[$requested])) {
         return '{{' . htmlspecialchars($requested) . '}}';
     }
     $file = \gp\tool\Files::PageFile($requested);
     $file_sections = \gp\tool\Files::Get($file, 'file_sections');
     if (!$file_sections) {
         return '{{' . htmlspecialchars($requested) . '}}';
     }
     return self::Render($file_sections, self::$title, self::$meta);
 }
Ejemplo n.º 24
0
 /**
  * Get current configuration settings
  *
  */
 function Init()
 {
     $this->config_file = '_ckeditor/config';
     $this->cke_config = \gp\tool\Files::Get($this->config_file, 'cke_config');
     //$this->cke_config 	+= array('custom_config'=>array());
     $this->cke_config += array('plugins' => array());
     $this->BuildConfig();
 }
Ejemplo n.º 25
0
 /**
  * Retreive the data file for the current title and update the data if necessary
  *
  */
 function GetFile()
 {
     $this->file_sections = \gp\tool\Files::Get($this->file, 'file_sections');
     $this->meta_data = \gp\tool\Files::$last_meta;
     $this->fileModTime = \gp\tool\Files::$last_modified;
     $this->file_stats = \gp\tool\Files::$last_stats;
     if (count($this->file_sections) == 0) {
         $this->file_sections[0] = array('type' => 'text', 'content' => '<p>Oops, this page no longer has any content.</p>');
     }
 }
Ejemplo n.º 26
0
 /**
  * Get usage information about a image
  *
  */
 static function SaveUsage($index, $data)
 {
     global $dataDir;
     $data_file = $dataDir . '/data/_resized/' . $index . '/data.php';
     return \gp\tool\Files::SaveData($data_file, 'usage', $data);
 }
Ejemplo n.º 27
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;
     }
 }
Ejemplo n.º 28
0
 /**
  * View the current public facing version of the file
  *
  */
 public function ViewCurrent()
 {
     if (!$this->draft_exists) {
         $this->DefaultDisplay();
         return;
     }
     $file_sections = \gp\tool\Files::Get($this->file, 'file_sections');
     $this->revision = $this->fileModTime;
     echo \gp\tool\Output\Sections::Render($file_sections, $this->title, $this->file_stats);
 }
Ejemplo n.º 29
0
 /**
  * Set global variables ( $gp_index, $gp_titles, $gp_menu and $gpLayouts ) from _site/pages.php
  *
  */
 public static function GetPagesPHP()
 {
     global $gp_index, $gp_titles, $gp_menu, $gpLayouts, $config;
     $gp_index = array();
     $pages = \gp\tool\Files::Get('_site/pages');
     //update for < 2.0a3
     if (array_key_exists('gpmenu', $pages) && array_key_exists('gptitles', $pages) && !array_key_exists('gp_titles', $pages) && !array_key_exists('gp_menu', $pages)) {
         foreach ($pages['gptitles'] as $title => $info) {
             $index = self::NewFileIndex();
             $gp_index[$title] = $index;
             $gp_titles[$index] = $info;
         }
         foreach ($pages['gpmenu'] as $title => $level) {
             $index = $gp_index[$title];
             $gp_menu[$index] = array('level' => $level);
         }
         return;
     }
     $gpLayouts = $pages['gpLayouts'];
     $gp_index = $pages['gp_index'];
     $gp_titles = $pages['gp_titles'];
     $gp_menu = $pages['gp_menu'];
     if (!is_array($gp_menu)) {
         self::stop();
     }
     //update for 3.5,
     if (!isset($gp_titles['special_gpsearch'])) {
         $gp_titles['special_gpsearch'] = array();
         $gp_titles['special_gpsearch']['label'] = 'Search';
         $gp_titles['special_gpsearch']['type'] = 'special';
         $gp_index['Search'] = 'special_gpsearch';
         //may overwrite special_search settings
     }
     //fix the gpmenu
     if (version_compare(\gp\tool\Files::$last_version, '3.0b1', '<')) {
         $gp_menu = \gp\tool\Output::FixMenu($gp_menu);
         // fix gp_titles for 3.0+
         // just make sure any ampersands in the label are escaped
         foreach ($gp_titles as $key => $value) {
             if (isset($gp_titles[$key]['label'])) {
                 $gp_titles[$key]['label'] = self::GetLabelIndex($key, true);
             }
         }
     }
     //title related configuration settings
     if (empty($config['homepath_key'])) {
         $config['homepath_key'] = key($gp_menu);
     }
     $config['homepath'] = self::IndexToTitle($config['homepath_key']);
 }
Ejemplo n.º 30
0
 /**
  * Connect to ftp server using either Post or saved values
  * Connection values will not be kept in $config in case they're being used for a system revert which will replace the config.php file
  * Also handle moving ftp connection values from $config to a sep
  *
  * @return bool
  */
 public function connect()
 {
     global $config, $dataDir, $langmessage;
     $save_values = false;
     $connect_args = \gp\tool\Files::Get('_updates/connect', 'connect_args');
     if (!$connect_args || !isset($connect_args['ftp_user'])) {
         if (isset($config['ftp_user'])) {
             $connect_args['ftp_user'] = $config['ftp_user'];
             $connect_args['ftp_server'] = $config['ftp_server'];
             $connect_args['ftp_pass'] = $config['ftp_pass'];
             $connect_args['ftp_root'] = $config['ftp_root'];
             $save_values = true;
         }
     }
     if (isset($_POST['ftp_pass'])) {
         $connect_args = $_POST;
         $save_values = true;
     }
     $connect_args = $this->get_connect_vars($connect_args);
     $connected = $this->connect_handler($connect_args);
     if (!is_null($connected)) {
         return false;
     }
     //get the ftp_root
     if (empty($connect_args['ftp_root']) || $save_values) {
         $this->ftp_root = $this->get_base_dir();
         if (!$this->ftp_root) {
             return $langmessage['couldnt_connect'] . ' (Couldn\'t find root)';
         }
         $connect_args['ftp_root'] = $this->ftp_root;
         $save_values = true;
     } else {
         $this->ftp_root = $connect_args['ftp_root'];
     }
     //save ftp info
     if (!$save_values) {
         return true;
     }
     $connection_file = $dataDir . '/data/_updates/connect.php';
     if (!\gp\tool\Files::SaveData($connection_file, 'connect_args', $connect_args)) {
         return true;
     }
     /*
      * Remove from $config if it's not a safe mode installation
      */
     if (!isset($config['useftp']) && isset($config['ftp_user'])) {
         unset($config['ftp_user']);
         unset($config['ftp_server']);
         unset($config['ftp_pass']);
         unset($config['ftp_root']);
         \gp\admin\Tools::SaveConfig();
     }
     return true;
 }