File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/wp-content/themes/vadimarketv4/inc/guncelle.php
<?php
define( 'NOTIFIER_THEME_FOLDER_NAME', 'vadimarketv4' );
class updateWPTheme
{
function __construct()
{
$this->oldTheme = wp_get_theme();
$this->oldThemeName = $this->oldTheme->get('Name');
$this->oldThemeVersion = $this->oldTheme->get('Version');
$this->oldthemePath = get_parent_theme_file_path();
}
public function backupTheme()
{
// Backup and compress to zip the theme
$themeName = $this->oldThemeName;
$themeVersion = $this->oldThemeVersion;
$themePath = get_parent_theme_file_path();
$bugun = date('d-m-Y--H-i');
$zipPath = get_theme_root() . '/' . NOTIFIER_THEME_FOLDER_NAME . '-' . $themeVersion . '--' . $bugun . '_old.zip';
$zip = new ZipArchive;
$zip->open($zipPath, ZipArchive::CREATE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($themePath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file) {
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = NOTIFIER_THEME_FOLDER_NAME . '/' . substr($filePath, strlen($themePath));
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
}
private function deleteDirectory($dir)
{
if (!file_exists($dir)) {
return true;
}
if (!is_dir($dir)) {
return unlink($dir);
}
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') {
continue;
}
if (!$this->deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
return false;
}
}
return rmdir($dir);
}
public function installLatestThemeVersion()
{
$klasor = NOTIFIER_THEME_FOLDER_NAME;
$gelberi = curl_init('https://demo.temavadisi.com/veriler/guncelurl.php?tema='.$klasor);
curl_setopt($gelberi, CURLOPT_RETURNTRANSFER, true);
$cekdostum = curl_exec($gelberi);
curl_close($gelberi);
// Install the latest version of the theme
$oldthemePath = $this->oldthemePath;
$oldThemeName = $this->oldThemeName;
$themesLocation = get_theme_root();
$zipLocation = $themesLocation . '/' . $oldThemeName . '.zip';
$downloadLatestTheme = file_put_contents($zipLocation, fopen($cekdostum , 'r')); // Download the latest theme version
$this->deleteDirectory($oldthemePath); // Delete the old theme
$zip = new ZipArchive;
$zip->open($zipLocation);
$newThemeName = $zip->getNameIndex(0);
$zip->extractTo($themesLocation);
$zip->close();
// delete the zip file
unlink($zipLocation);
// Activate if not active
if ($oldThemeName != $newThemeName) {
switch_theme($newThemeName);
}
// redirect to the theme options page
wp_redirect(admin_url('admin.php?page=temavadisi-panel'));
exit;
}
}
//post data and proccess
if (isset($_POST['updateTheme'])) {
$updateTheme = new updateWPTheme();
$updateTheme->backupTheme();
$updateTheme->installLatestThemeVersion();
}