Exemplo n.º 1
0
 /**
  * Delete a remote theme
  *
  */
 function DeleteTheme()
 {
     global $langmessage, $dataDir, $gpLayouts, $config;
     $config_before = $config;
     $gpLayoutsBefore = $gpLayouts;
     $theme_folder_name =& $_POST['folder'];
     $theme_folder = $dataDir . '/data/_themes/' . $theme_folder_name;
     if (empty($theme_folder_name) || !ctype_alnum($theme_folder_name)) {
         message($langmessage['OOPS'] . ' (Invalid Request)');
         return false;
     }
     $order = false;
     if (isset($config['themes'][$theme_folder_name]['order'])) {
         $order = $config['themes'][$theme_folder_name]['order'];
     }
     if (!$this->CanDeleteTheme($theme_folder_name, $message)) {
         message($message);
         return false;
     }
     //remove layouts
     $rm_addon = false;
     foreach ($gpLayouts as $layout_id => $layout_info) {
         if (!isset($layout_info['is_addon']) || !$layout_info['is_addon']) {
             continue;
         }
         $layout_folder = dirname($layout_info['theme']);
         if ($layout_folder != $theme_folder_name) {
             continue;
         }
         if (array_key_exists('addon_key', $layout_info)) {
             $rm_addon = $layout_info['addon_key'];
         }
         $this->RmLayoutPrep($layout_id);
         unset($gpLayouts[$layout_id]);
     }
     //remove from settings
     unset($config['themes'][$theme_folder_name]);
     if ($rm_addon) {
         includeFile('admin/admin_addon_installer.php');
         $installer = new admin_addon_installer();
         if (!$installer->Uninstall($rm_addon)) {
             $gpLayouts = $gpLayoutsBefore;
         }
         $installer->OutputMessages();
     } else {
         if (!admin_tools::SaveAllConfig()) {
             $config = $config_before;
             $gpLayouts = $gpLayoutsBefore;
             message($langmessage['OOPS'] . ' (s1)');
             return false;
         }
         message($langmessage['SAVED']);
         if ($order) {
             $img_path = common::IdUrl('ci');
             common::IdReq($img_path);
         }
     }
     //delete the folder if it hasn't already been deleted by admin_addon_installer
     $dir = $dataDir . '/data/_themes/' . $theme_folder_name;
     if (file_exists($dir)) {
         gpFiles::RmAll($dir);
     }
 }
Exemplo n.º 2
0
 /**
  * Delete all files older than 2 weeks
  * If there are more than 200 files older than one week
  *
  */
 static function CleanCache()
 {
     global $dataDir;
     $dir = $dataDir . '/data/_cache';
     $files = scandir($dir);
     $times = array();
     foreach ($files as $file) {
         if ($file == '.' || $file == '..' || strpos($file, '.php') !== false) {
             continue;
         }
         $full_path = $dir . '/' . $file;
         $time = filemtime($full_path);
         $diff = time() - $time;
         //if relatively new ( < 3 days), don't delete it
         if ($diff < 259200) {
             continue;
         }
         //if old ( > 14 days ), delete it
         if ($diff > 1209600) {
             gpFiles::RmAll($full_path);
             continue;
         }
         $times[$file] = $time;
     }
     //reduce further if needed till we have less than 200 files
     arsort($times);
     $times = array_keys($times);
     while (count($times) > 200) {
         $full_path = $dir . '/' . array_pop($times);
         gpFiles::RmAll($full_path);
     }
 }
Exemplo n.º 3
0
 function CleanInstallFolder()
 {
     $addoncode = $this->addon_folder;
     $folders = gpFiles::readDir($addoncode, 1);
     foreach ($folders as $folder) {
         if (!isset($this->config[$folder])) {
             $full_path = $addoncode . '/' . $folder;
             gpFiles::RmAll($full_path);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Remove a plugin
  *
  */
 function RemovePlugin()
 {
     global $langmessage, $dataDir;
     $plugin =& $_REQUEST['plugin'];
     if (!is_array($this->cke_config['plugins']) || !array_key_exists($plugin, $this->cke_config['plugins'])) {
         message($langmessage['OOPS'] . ' ( )');
         return;
     }
     unset($this->cke_config['plugins'][$plugin]);
     if (!$this->SaveConfig()) {
         message($langmessage['OOPS'] . ' (Not Saved)');
     } else {
         message($langmessage['SAVED']);
     }
     $path = $dataDir . '/data/_ckeditor/' . $plugin;
     gpFiles::RmAll($path);
 }
Exemplo n.º 5
0
 function ChangeInstallConfirmed(&$addonName)
 {
     global $dataDir, $langmessage;
     $installFolder = $dataDir . '/data/_addoncode/' . $addonName;
     $fromFolder = $dataDir . '/addons/' . $addonName;
     if (!file_exists($installFolder)) {
         message($langmessage['OOPS']);
         return;
     }
     if (!file_exists($fromFolder)) {
         message($langmessage['OOPS']);
         return;
     }
     if (is_link($installFolder)) {
         unlink($installFolder);
         if (!admin_addon_install::CopyAddonDir($fromFolder, $installFolder)) {
             message($langmessage['OOPS']);
             return;
         }
     } else {
         gpFiles::RmAll($installFolder);
         if (!symlink($fromFolder, $installFolder)) {
             message($langmessage['OOPS']);
             return;
         }
     }
     message('Install Type Changed');
 }
Exemplo n.º 6
0
 /**
  * Finalize theme removal
  *
  */
 function DeleteThemeConfirmed()
 {
     global $langmessage, $dataDir, $gpLayouts, $config;
     $gpLayoutsBefore = $gpLayouts;
     $can_delete = true;
     $theme_folder_name =& $_POST['folder'];
     $theme_folder = $dataDir . '/data/_themes/' . $theme_folder_name;
     if (empty($theme_folder_name) || !ctype_alnum($theme_folder_name) || !isset($config['themes'][$theme_folder_name])) {
         message($langmessage['OOPS']);
         return false;
     }
     $order = false;
     if (isset($config['themes'][$theme_folder_name]['order'])) {
         $order = $config['themes'][$theme_folder_name]['order'];
     }
     if (!$this->CanDeleteTheme($theme_folder_name, $message)) {
         message($message);
         return false;
     }
     //remove layouts
     foreach ($gpLayouts as $layout_id => $layout_info) {
         if (!isset($layout_info['is_addon']) || !$layout_info['is_addon']) {
             continue;
         }
         $layout_folder = dirname($layout_info['theme']);
         if ($layout_folder == $theme_folder_name) {
             $this->RmLayout($layout_id);
         }
     }
     //delete the folder
     $dir = $dataDir . '/data/_themes/' . $theme_folder_name;
     gpFiles::RmAll($dir);
     //remove from settings
     unset($config['themes'][$theme_folder_name]);
     if (admin_tools::SaveAllConfig()) {
         message($langmessage['SAVED']);
         if ($order) {
             $img_path = common::IdUrl('ci');
             common::IdReq($img_path);
         }
     } else {
         $gpLayouts = $gpLayoutsBefore;
         message($langmessage['OOPS'] . ' (s1)');
     }
 }
Exemplo n.º 7
0
 /**
  * Remove a file or directory and it's contents
  *
  */
 public static function RmAll($path)
 {
     if (empty($path)) {
         return false;
     }
     if (is_link($path)) {
         return @unlink($path);
     }
     if (!is_dir($path)) {
         return @unlink($path);
     }
     $success = true;
     $subDirs = array();
     //$files = scandir($path);
     $files = gpFiles::ReadDir($path, false);
     foreach ($files as $file) {
         $full_path = $path . '/' . $file;
         if (!is_link($full_path) && is_dir($full_path)) {
             $subDirs[] = $full_path;
             continue;
         }
         if (!@unlink($full_path)) {
             $success = false;
         }
     }
     foreach ($subDirs as $subDir) {
         if (!gpFiles::RmAll($subDir)) {
             $success = false;
         }
     }
     if ($success) {
         return gpFiles::RmDir($path);
     }
     return false;
 }
Exemplo n.º 8
0
 /**
  * Remove unused code folders created by incomplete addon installations
  *
  */
 function CleanAddonFolder()
 {
     global $config;
     //get a list of all folders
     $folder = '/data/_addoncode';
     $code_folders = $this->GetCleanFolders($folder);
     $folder = '/data/_addondata';
     $data_folders = $this->GetCleanFolders($folder);
     //check against folders used by addons
     $addons = $config['addons'];
     foreach ($addons as $addon_key => $info) {
         $addon_config = gpPlugin::GetAddonConfig($addon_key);
         if (array_key_exists($addon_config['code_folder_part'], $code_folders)) {
             $code_folders[$addon_config['code_folder_part']] = false;
         }
         if (array_key_exists($addon_config['data_folder_part'], $data_folders)) {
             $data_folders[$addon_config['data_folder_part']] = false;
         }
     }
     //remove unused folders
     $folders = array_filter($code_folders) + array_filter($data_folders);
     foreach ($folders as $folder => $full_path) {
         gpFiles::RmAll($full_path);
     }
 }
Exemplo n.º 9
0
 /**
  * Clean old files and folders from the temporary folder
  * Delete after 36 hours (129600 seconds)
  *
  */
 function CleanTemp()
 {
     global $dataDir;
     $temp_folder = $dataDir . '/data/_temp';
     $files = gpFiles::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;
         }
         gpFiles::RmAll($full_path);
     }
 }
Exemplo n.º 10
0
 /**
  * Remove unused code folders created by incomplete addon installations
  *
  */
 function CleanInstallFolder()
 {
     if (!$this->remote_install) {
         return;
     }
     if (file_exists($this->source)) {
         gpFiles::RmAll($this->source);
     }
     if (file_exists($this->trash_path)) {
         gpFiles::RmAll($this->trash_path);
     }
 }
Exemplo n.º 11
0
 /**
  * Remove all of the resized images for an image that is deleted
  *
  */
 function RemoveResized($removed)
 {
     global $dataDir;
     foreach ($removed as $key => $info) {
         $img = admin_uploaded::TrimBaseDir($info['realpath']);
         $index = array_search($img, gp_resized::$index);
         if (!$index) {
             continue;
         }
         unset(gp_resized::$index[$index]);
         $folder = $dataDir . '/data/_resized/' . $index;
         if (file_exists($folder)) {
             gpFiles::RmAll($folder);
         }
     }
 }
Exemplo n.º 12
0
 /**
  * Check and remove the requested files from the trash
  *
  */
 function DeleteFromTrash()
 {
     global $dataDir, $langmessage;
     if (empty($_POST['titles']) || !is_array($_POST['titles'])) {
         message($langmessage['OOPS'] . ' (No Titles)');
         return;
     }
     $titles = array();
     $incomplete = false;
     foreach ($_POST['titles'] as $trash_index) {
         $title_info = admin_trash::GetInfo($trash_index);
         if ($title_info === false) {
             $incomplete = true;
             continue;
         }
         $titles[$trash_index] = $title_info;
     }
     if (!admin_trash::ModTrashData(null, $titles)) {
         return false;
     }
     //remove the data
     foreach ($titles as $trash_index => $info) {
         gpFiles::RmAll($info['rm_path']);
         unset($this->trash_files[$trash_index]);
     }
     if ($incomplete) {
         message($langmessage['delete_incomplete']);
     }
 }