function xoops_module_pre_uninstall_galleries($mod) { $dir = RMUtilities::module_config('galleries', 'storedir'); if (is_dir($dir)) { RMUtilities::delete_directory($dir); } return true; }
public function delete() { //Eliminamos las imágenes $sql = "SELECT * FROM " . $this->db->prefix('gs_images') . " WHERE owner='" . $this->uid() . "'"; $result = $this->db->query($sql); while ($rows = $this->db->fetchArray($result)) { $img = new GSImage(); $img->assignVars($rows); $img->delete(); } RMUtilities::delete_directory($this->filesPath()); //Eliminamos los albumes $sql = "SELECT * FROM " . $this->db->prefix('gs_sets') . " WHERE owner='" . $this->uid() . "'"; $result = $this->db->query($sql); while ($rows = $this->db->fetchArray($result)) { $set = new GSSet(); $set->assignVars($rows); $set->delete(); } return $this->deleteFromTable(); }
function download_file() { global $xoopsLogger, $rmTpl, $runFiles, $xoopsSecurity; $xoopsLogger->activated = false; $url = RMHttpRequest::post('url', 'string', ''); $cred = RMHttpRequest::post('credentials', 'string', ''); $type = RMHttpRequest::post('type', 'string', ''); $dir = RMHttpRequest::post('dir', 'string', ''); $ftpdata = RMHttpRequest::post('ftp', 'string', ''); if ($url == '') { jsonReturn(__('Invalid parameters!', 'rmcommon')); } // Request access $query = explode("?", $url); $query[1] = ($query[1] != '' ? $query[1] . '&' : '') . 'action=identity' . ($cred != '' ? '&l=' . $cred : ''); $response = json_decode(RMHttpRequest::load_url($query[0], $query[1], true), true); //$response = json_decode(file_get_contents($url.'&), true); if ($response['error'] == 1) { jsonReturn($response['message']); } //jsonReturn($response['data']['url']); if (!is_dir(XOOPS_CACHE_PATH . '/updates/')) { mkdir(XOOPS_CACHE_PATH . '/updates/', 511); } if (!file_put_contents(XOOPS_CACHE_PATH . '/updates/' . $type . '-' . $dir . '.zip', file_get_contents($response['data']['url']))) { jsonReturn(__('Unable to download update file!', 'rmcommon')); } // Get files list $details = json_decode(RMHttpRequest::load_url($url . '&action=update-details', '', true), true); if ($details['error'] == 1) { jsonReturn($details['message']); } $hash = $details['data']['hash']; $file_hash = md5_file(XOOPS_CACHE_PATH . '/updates/' . $type . '-' . $dir . '.zip'); if ($hash != $file_hash) { @unlink(XOOPS_CACHE_PATH . '/updates/' . $type . '-' . $dir . '.zip'); jsonReturn(__('The package file could be corrupted. Aborting!', 'rmcommon')); } // Extract files $zip = new ZipArchive(); $res = $zip->open(XOOPS_CACHE_PATH . '/updates/' . $type . '-' . $dir . '.zip'); if ($res !== TRUE) { jsonReturn(__('ERROR: unable to open downloaded zip file!', 'rmcommon')); } $rmUtil = RMUtilities::get(); $source = XOOPS_CACHE_PATH . '/updates/' . $type . '-' . $dir; if (is_dir($source)) { $rmUtil->delete_directory($source); } $zip->extractTo($source); $zip->close(); // Delete downloaded zip unlink(XOOPS_CACHE_PATH . '/updates/' . $type . '-' . $dir . '.zip'); // Prepare to copy files $target = XOOPS_ROOT_PATH . '/modules/'; if ($type == 'plugin') { $target .= 'rmcommon/plugins/' . $dir; } else { $target .= $dir; } if (!is_dir($target)) { jsonReturn(sprintf(__('Target path "%s" does not exists!', 'rmcommon'), $target)); } /** * When rmcommon is the module to be updated then we need * to make a backup before to delete files */ $excluded = array(); if ($dir == 'rmcommon') { $excluded = array($target . '/plugins'); } if (is_writable($target) && !empty($target)) { $target = str_replace('\\', '/', $target); // Deletes dir content to replace with new files RMUtilities::delete_directory($target, false, $excluded); // Copy new files $source = rtrim(str_replace('\\', '/', $source), '/'); $odir = opendir($source); while (($file = readdir($odir)) !== false) { if ($file == '.' || $file == '..') { continue; } @rename($source . '/' . $file, $target . '/' . $file); } closedir($odir); RMUtilities::delete_directory($source); } else { if ($ftpdata == '') { jsonReturn(__('FTP configuration not specified!', 'rmcommon')); } parse_str($ftpdata); if ($ftp_server == '' || $ftp_user == '' || $ftp_pass == '') { jsonReturn(__('FTP configuration not valid!', 'rmcommon')); } $target = str_replace('\\', '/', $target); global $ftpConfig; $ftpConfig->server = $ftp_server; $ftpConfig->user = $ftp_user; $ftpConfig->pass = $ftp_pass; $ftpConfig->dir = $ftp_dir; $ftpConfig->port = $ftp_port > 0 ? $ftp_port : 21; $ftp = new RMFtpClient($ftp_server, $ftp_port > 0 ? $ftp_port : 21, $ftp_user, $ftp_pass); if (!$ftp->connect()) { jsonReturn(sprintf(__('Unable to connect FTP server %s', 'rmcommon'), '<strong>' . $ftp_server . '</strong>')); } $ftpConfig->base = $ftpConfig->dir . '/modules/' . ($type == 'plugin' ? 'rmcommon/plugins/' : '') . $dir; $ftpConfig->source = $source; $ftpConfig->target = $target; // Clean current element directory deleteFTPDir($ftpConfig->base, $ftp, false); // Copy new files } // Update uploads file $updates = unserialize(base64_decode(file_get_contents(XOOPS_CACHE_PATH . '/updates.chk'))); $new = array(); foreach ($updates['updates'] as $upd) { if ($upd['data']['type'] == $type && $upd['data']['dir'] == $dir) { continue; } $new[] = $upd; } file_put_contents(XOOPS_CACHE_PATH . '/updates.chk', base64_encode(serialize(array('date' => $updates['date'], 'total' => intval($updates['total']) - 1, 'updates' => $new)))); if (!empty($runFiles)) { jsonReturn(__('Executing files...', 'rmcommon'), 0, array('run' => json_encode($runFiles))); } else { jsonReturn(sprintf(__('%s has been updated', 'rmcommon'), '<strong>' . $dir . '</strong>'), 0); } }
function xoops_module_update_rmcommon($mod, $prev) { $db = XoopsDatabaseFactory::getDatabaseConnection(); $result = $db->query("SHOW TABLES LIKE '" . $db->prefix("rmc_bkmod") . "'"); if ($db->getRowsNum($result) > 0) { /** * Update old tables */ $db->queryF('RENAME TABLE `' . $db->prefix("rmc_bkmod") . '` TO `' . $db->prefix("mod_rmcommon_blocks_assignations") . '` ;'); $db->queryF('RENAME TABLE `' . $db->prefix("rmc_blocks") . '` TO `' . $db->prefix("mod_rmcommon_blocks") . '` ;'); $db->queryF('RENAME TABLE `' . $db->prefix("rmc_blocks_positions") . '` TO `' . $db->prefix("mod_rmcommon_blocks_positions") . '` ;'); $db->queryF('RENAME TABLE `' . $db->prefix("rmc_comments") . '` TO `' . $db->prefix("mod_rmcommon_comments") . '` ;'); $db->queryF('RENAME TABLE `' . $db->prefix("rmc_comusers") . '` TO `' . $db->prefix("mod_rmcommon_comments_assignations") . '` ;'); $db->queryF('RENAME TABLE `' . $db->prefix("rmc_images") . '` TO `' . $db->prefix("mod_rmcommon_images") . '` ;'); $db->queryF('RENAME TABLE `' . $db->prefix("rmc_img_cats") . '` TO `' . $db->prefix("mod_rmcommon_images_categories") . '` ;'); $db->queryF('RENAME TABLE `' . $db->prefix("rmc_plugins") . '` TO `' . $db->prefix("mod_rmcommon_plugins") . '` ;'); $db->queryF('RENAME TABLE `' . $db->prefix("rmc_settings") . '` TO `' . $db->prefix("mod_rmcommon_settings") . '` ;'); $db->queryF('ALTER TABLE `' . $db->prefix("mod_rmcommon_blocks_assignations") . '` ENGINE = INNODB'); $db->queryF('ALTER TABLE `' . $db->prefix("mod_rmcommon_blocks") . '` ENGINE = INNODB'); $db->queryF('ALTER TABLE `' . $db->prefix("mod_rmcommon_blocks_positions") . '` ENGINE = INNODB'); $db->queryF('ALTER TABLE `' . $db->prefix("mod_rmcommon_comments") . '` ENGINE = INNODB'); $db->queryF('ALTER TABLE `' . $db->prefix("mod_rmcommon_comments_assignations") . '` ENGINE = INNODB'); $db->queryF('ALTER TABLE `' . $db->prefix("mod_rmcommon_images") . '` ENGINE = INNODB'); $db->queryF('ALTER TABLE `' . $db->prefix("mod_rmcommon_images_categories") . '` ENGINE = INNODB'); $db->queryF('ALTER TABLE `' . $db->prefix("mod_rmcommon_plugins") . '` ENGINE = INNODB'); $db->queryF('ALTER TABLE `' . $db->prefix("mod_rmcommon_settings") . '` ENGINE = INNODB'); } $result = $db->query("SHOW TABLES LIKE '" . $db->prefix("mod_rmcommon_notifications") . "'"); if ($db->getRowsNum($result) <= 0) { /** * Create notifications table if not exists */ $sql = 'CREATE TABLE `' . $db->prefix("mod_rmcommon_notifications") . '` ( `id_notification` int(11) NOT NULL AUTO_INCREMENT, `event` varchar(50) NOT NULL, `element` varchar(50) NOT NULL, `params` varchar(50) NOT NULL, `uid` int(11) NOT NULL, `type` varchar(10) NOT NULL DEFAULT \'module\', `date` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8;'; $db->queryF($sql); $sql = 'ALTER TABLE `' . $db->prefix("mod_rmcommon_notifications") . '` ADD PRIMARY KEY (`id_notification`), ADD KEY `event` (`event`), ADD KEY `element` (`element`), ADD KEY `uid` (`uid`);'; $db->queryF($sql); $sql = 'ALTER TABLE `' . $db->prefix("mod_rmcommon_notifications") . '` MODIFY `id_notification` int(11) NOT NULL AUTO_INCREMENT;COMMIT;'; $db->queryF($sql); } // Change theme from TwoP6 to Helium $sql = "UPDATE " . $db->prefix("config") . " SET conf_value='helium' WHERE conf_modid=" . $mod->getVar('mid') . " AND conf_name='theme'"; $db->queryF($sql); // Prepare welcome screen $domain = preg_replace("/http:\\/\\/|https:\\/\\//", '', XOOPS_URL); setcookie("rmcwelcome", 1, time() + 365 * 86400, '/', $domain); // Move system theme to right dir $target = XOOPS_ROOT_PATH . '/modules/system/themes/redmexico'; $source = XOOPS_ROOT_PATH . '/modules/rmcommon/redmexico'; if (!is_dir($source)) { return true; } global $msgs; if (!is_writable($target)) { $msgs[] = '<span class="text-danger">' . __('System theme "redmexico" could not move to destination directory (modules/system/themes). Please do it manually in order to get Common Utilities working correctly.', 'rmcommon') . '</span>'; return true; } // Deletes dir content to replace with new files RMUtilities::delete_directory($target, false); $odir = opendir($source); while (($file = readdir($odir)) !== false) { if ($file == '.' || $file == '..') { continue; } @rename($source . '/' . $file, $target . '/' . $file); } closedir($odir); RMUtilities::delete_directory($source); return true; }