$message = __("Removing temp-directory"); $path = ABS_PATH . 'oc-temp'; $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST); for ($dir->rewind(); $dir->valid(); $dir->next()) { if ($dir->isDir()) { if ($dir->getFilename() != '.' && $dir->getFilename() != '..') { rmdir($dir->getPathname()); } } else { unlink($dir->getPathname()); } } rmdir($path); break; case 'db-backup': osc_dbdump(); break; case 'zip-osclass': $archive_name = ABS_PATH . "OSClass_backup." . date('YmdHis') . ".zip"; $archive_folder = ABS_PATH; if (osc_zip_folder($archive_folder, $archive_name)) { $message = __('Archiving is sucessful!'); } else { $message = __('Error, can\'t create a zip file!'); } break; case 'unzip-file': if (Params::getParam('file') != '') { @mkdir(ABS_PATH . 'oc-temp', 0777); $res = osc_unzip_file(osc_content_path() . 'downloads/' . Params::getParam('file'), ABS_PATH . 'oc-temp/'); if ($res == 1) {
function doModel() { parent::doModel(); switch ($this->action) { case 'import': // calling import view $this->doView('tools/import.php'); break; case 'import_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import'); } // calling $sql = Params::getFiles('sql'); if (isset($sql['size']) && $sql['size'] != 0) { $content_file = file_get_contents($sql['tmp_name']); $conn = DBConnectionClass::newInstance(); $c_db = $conn->getOsclassDb(); $comm = new DBCommandClass($c_db); if ($comm->importSQL($content_file)) { osc_add_flash_ok_message(_m('Import complete'), 'admin'); } else { osc_add_flash_error_message(_m('There was a problem importing data to the database'), 'admin'); } } else { osc_add_flash_warning_message(_m('No file was uploaded'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import'); break; case 'images': // calling images view $this->doView('tools/images.php'); break; case 'images_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images'); } $preferences = Preference::newInstance()->toArray(); $wat = new Watermark(); $aResources = ItemResource::newInstance()->getAllResources(); foreach ($aResources as $resource) { osc_run_hook('regenerate_image', $resource); $path = osc_content_path() . 'uploads/'; // comprobar que no haya original $img_original = $path . $resource['pk_i_id'] . "_original*"; $aImages = glob($img_original); // there is original image if (count($aImages) == 1) { $image_tmp = $aImages[0]; } else { $img_normal = $path . $resource['pk_i_id'] . ".*"; $aImages = glob($img_normal); if (count($aImages) == 1) { $image_tmp = $aImages[0]; } else { $img_thumbnail = $path . $resource['pk_i_id'] . "_thumbnail*"; $aImages = glob($img_thumbnail); $image_tmp = $aImages[0]; } } // extension preg_match('/\\.(.*)$/', $image_tmp, $matches); if (isset($matches[1])) { $extension = $matches[1]; // Create normal size $path_normal = $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '.jpg'; $size = explode('x', osc_normal_dimensions()); ImageResizer::fromFile($image_tmp)->resizeTo($size[0], $size[1])->saveToFile($path); if (osc_is_watermark_text()) { $wat->doWatermarkText($path, osc_watermark_text_color(), osc_watermark_text(), 'image/jpeg'); } elseif (osc_is_watermark_image()) { $wat->doWatermarkImage($path, 'image/jpeg'); } // Create preview $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '_preview.jpg'; $size = explode('x', osc_preview_dimensions()); ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path); // Create thumbnail $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '_thumbnail.jpg'; $size = explode('x', osc_thumbnail_dimensions()); ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path); // update resource info ItemResource::newInstance()->update(array('s_path' => 'oc-content/uploads/', 's_name' => osc_genRandomPassword(), 's_extension' => 'jpg', 's_content_type' => 'image/jpeg'), array('pk_i_id' => $resource['pk_i_id'])); osc_run_hook('regenerated_image', ItemResource::newInstance()->findByPrimaryKey($resource['pk_i_id'])); // si extension es direfente a jpg, eliminar las imagenes con $extension si hay if ($extension != 'jpg') { $files_to_remove = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . "*" . $extension; $fs = glob($files_to_remove); if (is_array($fs)) { array_map("unlink", $fs); } } // .... } else { // no es imagen o imagen sin extesión } } osc_add_flash_ok_message(_m('Re-generation complete'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images'); break; case 'category': $this->doView('tools/category.php'); break; case 'category_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category'); } osc_update_cat_stats(); osc_add_flash_ok_message(_m("Recount category stats has been successful"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category'); break; case 'locations': $this->doView('tools/locations.php'); break; case 'locations_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations'); } $workToDo = LocationsTmp::newInstance()->count(); if ($workToDo > 0) { $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations'); break; } // we need populate location tmp table $aCountry = Country::newInstance()->listAll(); foreach ($aCountry as $country) { $aRegionsCountry = Region::newInstance()->getByCountry($country['pk_c_code']); LocationsTmp::newInstance()->insert(array('id_location' => $country['pk_c_code'], 'e_type' => 'COUNTRY')); foreach ($aRegionsCountry as $region) { $aCitiesRegion = City::newInstance()->getByRegion($region['pk_i_id']); LocationsTmp::newInstance()->insert(array('id_location' => $region['pk_i_id'], 'e_type' => 'REGION')); foreach ($aCitiesRegion as $city) { LocationsTmp::newInstance()->insert(array('id_location' => $city['pk_i_id'], 'e_type' => 'CITY')); } unset($aCitiesRegion); } unset($aRegionsCountry); } unset($aCountry); $workToDo = LocationsTmp::newInstance()->count(); Preference::newInstance()->replace('location_todo', $workToDo); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations'); break; case 'upgrade': $this->doView('tools/upgrade.php'); break; case 'backup': $this->doView('tools/backup.php'); break; case 'backup-sql': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //databasse dump... if (Params::getParam('bck_dir') != '') { $path = trim(Params::getParam('bck_dir')); if (substr($path, -1, 1) != "/") { $path .= '/'; } } else { $path = osc_base_path(); } $filename = 'OSClass_mysqlbackup.' . date('YmdHis') . '.sql'; switch (osc_dbdump($path, $filename)) { case -1: $msg = _m('Path is empty'); osc_add_flash_error_message($msg, 'admin'); break; case -2: $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -3: $msg = _m('There are no tables to back up'); osc_add_flash_error_message($msg, 'admin'); break; case -4: $msg = _m('The folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; default: $msg = _m('Backup completed successfully'); osc_add_flash_ok_message($msg, 'admin'); break; } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-sql_file': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //databasse dump... $filename = 'OSClass_mysqlbackup.' . date('YmdHis') . '.sql'; $path = sys_get_temp_dir() . "/"; switch (osc_dbdump($path, $filename)) { case -1: $msg = _m('Path is empty'); osc_add_flash_error_message($msg, 'admin'); break; case -2: $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -3: $msg = sprintf(_m('Could not select the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -4: $msg = _m('There are no tables to back up'); osc_add_flash_error_message($msg, 'admin'); break; case -5: $msg = _m('The folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; default: $msg = _m('Backup completed successfully'); osc_add_flash_ok_message($msg, 'admin'); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($path . $filename)); flush(); readfile($path . $filename); exit; break; } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-zip_file': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } $filename = "OSClass_backup." . date('YmdHis') . ".zip"; $path = sys_get_temp_dir() . "/"; if (osc_zip_folder(osc_base_path(), $path . $filename)) { $msg = _m('Archived successfully!'); osc_add_flash_ok_message($msg, 'admin'); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($path . $filename)); flush(); readfile($path . $filename); exit; } else { $msg = _m('Error, the zip file was not created in the specified directory'); osc_add_flash_error_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-zip': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //zip of the code just to back it up if (Params::getParam('bck_dir') != '') { $archive_name = trim(Params::getParam('bck_dir')); if (substr(trim($archive_name), -1, 1) != "/") { $archive_name .= '/'; } $archive_name = Params::getParam('bck_dir') . '/OSClass_backup.' . date('YmdHis') . '.zip'; } else { $archive_name = osc_base_path() . "OSClass_backup." . date('YmdHis') . ".zip"; } $archive_folder = osc_base_path(); if (osc_zip_folder($archive_folder, $archive_name)) { $msg = _m('Archived successfully!'); osc_add_flash_ok_message($msg, 'admin'); } else { $msg = _m('Error, the zip file was not created in the specified directory'); osc_add_flash_error_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup_post': $this->doView('tools/backup.php'); break; case 'maintenance': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->doView('tools/maintenance.php'); break; } $mode = Params::getParam('mode'); if ($mode == 'on') { $maintenance_file = osc_base_path() . '.maintenance'; $fileHandler = @fopen($maintenance_file, 'w'); if ($fileHandler) { osc_add_flash_ok_message(_m('Maintenance mode is ON'), 'admin'); } else { osc_add_flash_error_message(_m('There was an error creating the .maintenance file, please create it manually at the root folder'), 'admin'); } fclose($fileHandler); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance'); } else { if ($mode == 'off') { $deleted = @unlink(osc_base_path() . '.maintenance'); if ($deleted) { osc_add_flash_ok_message(_m('Maintenance mode is OFF'), 'admin'); } else { osc_add_flash_error_message(_m('There was an error removing the .maintenance file, please remove it manually from the root folder'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance'); } } $this->doView('tools/maintenance.php'); break; default: } }
function doModel() { switch ($this->action) { case 'import': // calling import view $this->doView('tools/import.php'); break; case 'import_post': // calling $sql = Params::getFiles('sql'); //dev.conquer: if the file es too big, we can have problems with the upload or with memory $content_file = file_get_contents($sql['tmp_name']); $conn = getConnection(); if ($conn->osc_dbImportSQL($content_file)) { osc_add_flash_message(_m('Import complete'), 'admin'); } else { osc_add_flash_message(_m('There was a problem importing data to the database'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import'); break; case 'images': // calling images view $this->doView('tools/images.php'); break; case 'images_post': $preferences = Preference::newInstance()->toArray(); $path = osc_content_path() . 'uploads/'; $dir = opendir($path); while ($file = readdir($dir)) { if (preg_match('|([0-9]+)_thumbnail\\.png|i', $file, $matches)) { $orig_file = str_replace('_thumbnail.', '_original.', $file); $tmpName = osc_content_path() . 'uploads/' . $orig_file; if (!file_exists($orig_file)) { copy(str_replace('_original.', '.', $tmpName), $tmpName); } // Create thumbnail $thumbnailPath = osc_content_path() . 'uploads/' . $file; $size = explode('x', osc_thumbnail_dimensions()); ImageResizer::fromFile($tmpName)->resizeTo($size[0], $size[1])->saveToFile($thumbnailPath); // Create preview $thumbnailPath = osc_content_path() . 'uploads/' . str_replace('_thumbnail.', '_preview.', $file); $size = explode('x', osc_preview_dimensions()); ImageResizer::fromFile($tmpName)->resizeTo($size[0], $size[1])->saveToFile($thumbnailPath); // Create normal size $thumbnailPath = osc_content_path() . 'uploads/' . str_replace('_thumbnail.', '.', $file); $size = explode('x', osc_normal_dimensions()); ImageResizer::fromFile($tmpName)->resizeTo($size[0], $size[1])->saveToFile($thumbnailPath); if (!osc_keep_original_image()) { @unlink($tmpName); } } } closedir($dir); osc_add_flash_message(_m('Re-generation complete'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images'); break; case 'upgrade': $this->doView('tools/upgrade.php'); break; case 'backup': $this->doView('tools/backup.php'); break; case 'backup-sql': //databasse dump... if (Params::getParam('bck_dir') != '') { $path = trim(Params::getParam('bck_dir')); if (substr($path, -1, 1) != "/") { $path .= '/'; } } else { $path = osc_base_path(); } $filename = 'OSClass_mysqlbackup.' . date('YmdHis') . '.sql'; switch (osc_dbdump($path, $filename)) { case -1: $msg = _m('Path is empty'); break; case -2: $msg = _m('Could not connect with the database') . '. Error: ' . mysql_error(); break; case -3: $msg = _m('Could not select the database') . '. Error: ' . mysql_error(); break; case -4: $msg = _m('There are no tables to back up'); break; case -5: $msg = _m('The folder is not writable'); break; default: $msg = _m('Backup has been done properly'); break; } osc_add_flash_message($msg, 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-zip': //zip of the code just to back it up if (Params::getParam('bck_dir') != '') { $archive_name = trim(Params::getParam('bck_dir')); if (substr(trim($archive_name), -1, 1) != "/") { $archive_name .= '/'; } $archive_name = Params::getParam('bck_dir') . '/OSClass_backup.' . date('YmdHis') . '.zip'; } else { $archive_name = osc_base_path() . "OSClass_backup." . date('YmdHis') . ".zip"; } $archive_folder = osc_base_path(); if (osc_zip_folder($archive_folder, $archive_name)) { $msg = _m('Archiving successful!'); } else { $msg = _m('Error, the zip file was not created at the specified directory'); } osc_add_flash_message($msg, 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup_post': $this->doView('tools/backup.php'); break; default: } }
function doModel() { switch ($this->action) { case 'import': // calling import view $this->doView('tools/import.php'); break; case 'import_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import'); } // calling $sql = Params::getFiles('sql'); if (isset($sql['size']) && $sql['size'] != 0) { $content_file = file_get_contents($sql['tmp_name']); $conn = DBConnectionClass::newInstance(); $c_db = $conn->getOsclassDb(); $comm = new DBCommandClass($c_db); if ($comm->importSQL($content_file)) { osc_add_flash_ok_message(_m('Import complete'), 'admin'); } else { osc_add_flash_error_message(_m('There was a problem importing data to the database'), 'admin'); } } else { osc_add_flash_error_message(_m('No file was uploaded'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import'); break; case 'images': // calling images view $this->doView('tools/images.php'); break; case 'images_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images'); } $preferences = Preference::newInstance()->toArray(); $wat = new Watermark(); $aResources = ItemResource::newInstance()->getAllResources(); foreach ($aResources as $resource) { osc_run_hook('regenerate_image', $resource); $path = osc_content_path() . 'uploads/'; // comprobar que no haya original $img_original = $path . $resource['pk_i_id'] . "_original*"; $aImages = glob($img_original); // there is original image if (count($aImages) == 1) { $image_tmp = $aImages[0]; } else { $img_normal = $path . $resource['pk_i_id'] . ".*"; $aImages = glob($img_normal); if (count($aImages) == 1) { $image_tmp = $aImages[0]; } else { $img_thumbnail = $path . $resource['pk_i_id'] . "_thumbnail*"; $aImages = glob($img_thumbnail); $image_tmp = $aImages[0]; } } // extension preg_match('/\\.(.*)$/', $image_tmp, $matches); if (isset($matches[1])) { $extension = $matches[1]; // Create normal size $path_normal = $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '.jpg'; $size = explode('x', osc_normal_dimensions()); ImageResizer::fromFile($image_tmp)->resizeTo($size[0], $size[1])->saveToFile($path); if (osc_is_watermark_text()) { $wat->doWatermarkText($path, osc_watermark_text_color(), osc_watermark_text(), 'image/jpeg'); } elseif (osc_is_watermark_image()) { $wat->doWatermarkImage($path, 'image/jpeg'); } // Create preview $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '_preview.jpg'; $size = explode('x', osc_preview_dimensions()); ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path); // Create thumbnail $path = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . '_thumbnail.jpg'; $size = explode('x', osc_thumbnail_dimensions()); ImageResizer::fromFile($path_normal)->resizeTo($size[0], $size[1])->saveToFile($path); // update resource info ItemResource::newInstance()->update(array('s_path' => 'oc-content/uploads/', 's_name' => osc_genRandomPassword(), 's_extension' => 'jpg', 's_content_type' => 'image/jpeg'), array('pk_i_id' => $resource['pk_i_id'])); osc_run_hook('regenerated_image', ItemResource::newInstance()->findByPrimaryKey($resource['pk_i_id'])); // si extension es direfente a jpg, eliminar las imagenes con $extension si hay if ($extension != 'jpg') { $files_to_remove = osc_content_path() . 'uploads/' . $resource['pk_i_id'] . "*" . $extension; $fs = glob($files_to_remove); if (is_array($fs)) { array_map("unlink", $fs); } } // .... } else { // no es imagen o imagen sin extesión } } osc_add_flash_ok_message(_m('Re-generation complete'), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=images'); break; case 'upgrade': $this->doView('tools/upgrade.php'); break; case 'backup': $this->doView('tools/backup.php'); break; case 'backup-sql': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //databasse dump... if (Params::getParam('bck_dir') != '') { $path = trim(Params::getParam('bck_dir')); if (substr($path, -1, 1) != "/") { $path .= '/'; } } else { $path = osc_base_path(); } $filename = 'OSClass_mysqlbackup.' . date('YmdHis') . '.sql'; switch (osc_dbdump($path, $filename)) { case -1: $msg = _m('Path is empty'); osc_add_flash_error_message($msg, 'admin'); break; case -2: $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -3: $msg = sprintf(_m('Could not select the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -4: $msg = _m('There are no tables to back up'); osc_add_flash_error_message($msg, 'admin'); break; case -5: $msg = _m('The folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; default: $msg = _m('Backup has been done properly'); osc_add_flash_ok_message($msg, 'admin'); break; } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-zip': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //zip of the code just to back it up if (Params::getParam('bck_dir') != '') { $archive_name = trim(Params::getParam('bck_dir')); if (substr(trim($archive_name), -1, 1) != "/") { $archive_name .= '/'; } $archive_name = Params::getParam('bck_dir') . '/OSClass_backup.' . date('YmdHis') . '.zip'; } else { $archive_name = osc_base_path() . "OSClass_backup." . date('YmdHis') . ".zip"; } $archive_folder = osc_base_path(); if (osc_zip_folder($archive_folder, $archive_name)) { $msg = _m('Archiving successful!'); osc_add_flash_ok_message($msg, 'admin'); } else { $msg = _m('Error, the zip file was not created at the specified directory'); osc_add_flash_error_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup_post': $this->doView('tools/backup.php'); break; case 'maintenance': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because is a demo site"), 'admin'); $this->doView('tools/maintenance.php'); break; } $mode = Params::getParam('mode'); if ($mode == 'on') { $maintenance_file = ABS_PATH . '.maintenance'; $fileHandler = @fopen($maintenance_file, 'w'); if ($fileHandler) { osc_add_flash_ok_message(_m('Maintenance mode is ON'), 'admin'); } else { osc_add_flash_error_message(_m('There was an error creating .maintenance file, please create it manually at the root folder'), 'admin'); } fclose($fileHandler); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance'); } else { if ($mode == 'off') { $deleted = @unlink(ABS_PATH . '.maintenance'); if ($deleted) { osc_add_flash_ok_message(_m('Maintenance mode is OFF'), 'admin'); } else { osc_add_flash_error_message(_m('There was an error removing .maintenance file, please remove it manually from the root folder'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance'); } } $this->doView('tools/maintenance.php'); break; default: } }
function doModel() { parent::doModel(); switch ($this->action) { case 'import': // calling import view $this->doView('tools/import.php'); break; case 'import_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import'); } // calling osc_csrf_check(); $sql = Params::getFiles('sql'); if (isset($sql['size']) && $sql['size'] != 0) { $content_file = file_get_contents($sql['tmp_name']); $conn = DBConnectionClass::newInstance(); $c_db = $conn->getOsclassDb(); $comm = new DBCommandClass($c_db); if ($comm->importSQL($content_file)) { osc_calculate_location_slug(osc_subdomain_type()); osc_add_flash_ok_message(_m('Import complete'), 'admin'); } else { osc_add_flash_error_message(_m('There was a problem importing data to the database'), 'admin'); } } else { osc_add_flash_warning_message(_m('No file was uploaded'), 'admin'); } @unlink($sql['tmp_name']); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=import'); break; case 'category': $this->doView('tools/category.php'); break; case 'category_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category'); } osc_update_cat_stats(); osc_add_flash_ok_message(_m("Recount category stats has been successful"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=category'); break; case 'locations': $this->doView('tools/locations.php'); break; case 'locations_post': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations'); } osc_update_location_stats(true); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=locations'); break; case 'upgrade': $this->doView('tools/upgrade.php'); break; case 'version': $this->doView('tools/version.php'); break; case 'backup': $this->doView('tools/backup.php'); break; case 'backup-sql': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } osc_csrf_check(); //databasse dump... if (Params::getParam('bck_dir') != '') { $path = trim(Params::getParam('bck_dir')); if (substr($path, -1, 1) != "/") { $path .= '/'; } } else { $path = osc_base_path(); } $filename = 'Osclass_mysqlbackup.' . date('YmdHis') . '.sql'; switch (osc_dbdump($path, $filename)) { case -1: $msg = _m('Path is empty'); osc_add_flash_error_message($msg, 'admin'); break; case -2: $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -3: $msg = _m('There are no tables to back up'); osc_add_flash_error_message($msg, 'admin'); break; case -4: $msg = _m('The folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; default: $msg = _m('Backup completed successfully'); osc_add_flash_ok_message($msg, 'admin'); break; } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-sql_file': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //databasse dump... $filename = 'Osclass_mysqlbackup.' . date('YmdHis') . '.sql'; $path = sys_get_temp_dir() . "/"; switch (osc_dbdump($path, $filename)) { case -1: $msg = _m('Path is empty'); osc_add_flash_error_message($msg, 'admin'); break; case -2: $msg = sprintf(_m('Could not connect with the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -3: $msg = sprintf(_m('Could not select the database. Error: %s'), mysql_error()); osc_add_flash_error_message($msg, 'admin'); break; case -4: $msg = _m('There are no tables to back up'); osc_add_flash_error_message($msg, 'admin'); break; case -5: $msg = _m('The folder is not writable'); osc_add_flash_error_message($msg, 'admin'); break; default: $msg = _m('Backup completed successfully'); osc_add_flash_ok_message($msg, 'admin'); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($path . $filename)); flush(); readfile($path . $filename); exit; break; } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-zip_file': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } $filename = "Osclass_backup." . date('YmdHis') . ".zip"; $path = sys_get_temp_dir() . "/"; if (osc_zip_folder(osc_base_path(), $path . $filename)) { $msg = _m('Archived successfully!'); osc_add_flash_ok_message($msg, 'admin'); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($path . $filename)); flush(); readfile($path . $filename); exit; } else { $msg = _m('Error, the zip file was not created in the specified directory'); osc_add_flash_error_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup-zip': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); } //zip of the code just to back it up osc_csrf_check(); if (Params::getParam('bck_dir') != '') { $archive_name = trim(Params::getParam('bck_dir')); if (substr(trim($archive_name), -1, 1) != "/") { $archive_name .= '/'; } $archive_name = Params::getParam('bck_dir') . '/Osclass_backup.' . date('YmdHis') . '.zip'; } else { $archive_name = osc_base_path() . "Osclass_backup." . date('YmdHis') . ".zip"; } $archive_folder = osc_base_path(); if (osc_zip_folder($archive_folder, $archive_name)) { $msg = _m('Archived successfully!'); osc_add_flash_ok_message($msg, 'admin'); } else { $msg = _m('Error, the zip file was not created in the specified directory'); osc_add_flash_error_message($msg, 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=backup'); break; case 'backup_post': $this->doView('tools/backup.php'); break; case 'maintenance': if (defined('DEMO')) { osc_add_flash_warning_message(_m("This action cannot be done because it is a demo site"), 'admin'); $this->doView('tools/maintenance.php'); break; } $mode = Params::getParam('mode'); if ($mode == 'on') { osc_csrf_check(); $maintenance_file = osc_base_path() . '.maintenance'; $fileHandler = @fopen($maintenance_file, 'w'); if ($fileHandler) { osc_add_flash_ok_message(_m('Maintenance mode is ON'), 'admin'); } else { osc_add_flash_error_message(_m('There was an error creating the .maintenance file, please create it manually at the root folder'), 'admin'); } fclose($fileHandler); $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance'); } else { if ($mode == 'off') { osc_csrf_check(); $deleted = @unlink(osc_base_path() . '.maintenance'); if ($deleted) { osc_add_flash_ok_message(_m('Maintenance mode is OFF'), 'admin'); } else { osc_add_flash_error_message(_m('There was an error removing the .maintenance file, please remove it manually from the root folder'), 'admin'); } $this->redirectTo(osc_admin_base_url(true) . '?page=tools&action=maintenance'); } } $this->doView('tools/maintenance.php'); break; default: } }