瀏覽代碼

added php functions for back up work

causefx 7 年之前
父節點
當前提交
fff28d8f20
共有 2 個文件被更改,包括 89 次插入40 次删除
  1. 48 0
      api/functions/backup-functions.php
  2. 41 40
      api/functions/normal-functions.php

+ 48 - 0
api/functions/backup-functions.php

@@ -0,0 +1,48 @@
+<?php
+function fileArray($files)
+{
+	foreach ($files as $file) {
+		if (file_exists($file)) {
+			$list[] = $file;
+		}
+	}
+	if (!empty($list)) {
+		return $list;
+	}
+}
+
+function backupDB()
+{
+	$directory = $GLOBALS['dbLocation'] . 'backups' . DIRECTORY_SEPARATOR;
+	@mkdir($directory, 0770, true);
+	$orgFiles = array(
+		'orgLog' => $GLOBALS['organizrLog'],
+		'loginLog' => $GLOBALS['organizrLoginLog'],
+		'config' => $GLOBALS['userConfigPath'],
+		'database' => $GLOBALS['dbLocation'] . $GLOBALS['dbName']
+	);
+	$files = fileArray($orgFiles);
+	if (!empty($files)) {
+		writeLog('success', 'BACKUP: backup process started', 'SYSTEM');
+		$zipname = $directory . 'backup[' . date('Y-m-d_H-i') . '][' . $GLOBALS['installedVersion'] . '].zip';
+		$zip = new ZipArchive;
+		$zip->open($zipname, ZipArchive::CREATE);
+		foreach ($files as $file) {
+			$zip->addFile($file);
+		}
+		$zip->close();
+		writeLog('success', 'BACKUP: backup process finished', 'SYSTEM');
+		return true;
+	} else {
+		return false;
+	}
+	
+}
+
+function getBackups()
+{
+	$path = $GLOBALS['dbLocation'] . 'backups' . DIRECTORY_SEPARATOR;
+	@mkdir($path, 0770, true);
+	$files = array_diff(scandir($path), array('.', '..'));
+	return array_reverse($files);
+}

+ 41 - 40
api/functions/normal-functions.php

@@ -428,57 +428,58 @@ function getServer($over = false)
 	}
 	return isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : $_SERVER["SERVER_NAME"];
 }
+
 /* Function is to get all the contents from ics and explode all the datas according to the events and its sections */
 function getIcsEventsAsArray($file)
 {
-    $icalString = file_get_contents_curl($file);
-    $icsDates = array();
-    /* Explode the ICs Data to get datas as array according to string ‘BEGIN:’ */
-    $icsData = explode("BEGIN:", $icalString);
-    /* Iterating the icsData value to make all the start end dates as sub array */
-    foreach ($icsData as $key => $value) {
-        $icsDatesMeta [$key] = explode("\n", $value);
-    }
-    /* Itearting the Ics Meta Value */
-    foreach ($icsDatesMeta as $key => $value) {
-        foreach ($value as $subKey => $subValue) {
-            /* to get ics events in proper order */
-            $icsDates = getICSDates($key, $subKey, $subValue, $icsDates);
-        }
-    }
-    return $icsDates;
+	$icalString = file_get_contents_curl($file);
+	$icsDates = array();
+	/* Explode the ICs Data to get datas as array according to string ‘BEGIN:’ */
+	$icsData = explode("BEGIN:", $icalString);
+	/* Iterating the icsData value to make all the start end dates as sub array */
+	foreach ($icsData as $key => $value) {
+		$icsDatesMeta [$key] = explode("\n", $value);
+	}
+	/* Itearting the Ics Meta Value */
+	foreach ($icsDatesMeta as $key => $value) {
+		foreach ($value as $subKey => $subValue) {
+			/* to get ics events in proper order */
+			$icsDates = getICSDates($key, $subKey, $subValue, $icsDates);
+		}
+	}
+	return $icsDates;
 }
 
 /* funcion is to avaid the elements wich is not having the proper start, end  and summary informations */
 function getICSDates($key, $subKey, $subValue, $icsDates)
 {
-    if ($key != 0 && $subKey == 0) {
-        $icsDates [$key] ["BEGIN"] = $subValue;
-    } else {
-        $subValueArr = explode(":", $subValue, 2);
-        if (isset ($subValueArr [1])) {
-            $icsDates [$key] [$subValueArr [0]] = $subValueArr [1];
-        }
-    }
-    return $icsDates;
+	if ($key != 0 && $subKey == 0) {
+		$icsDates [$key] ["BEGIN"] = $subValue;
+	} else {
+		$subValueArr = explode(":", $subValue, 2);
+		if (isset ($subValueArr [1])) {
+			$icsDates [$key] [$subValueArr [0]] = $subValueArr [1];
+		}
+	}
+	return $icsDates;
 }
 
 function file_get_contents_curl($url)
 {
+	$ch = curl_init();
+	curl_setopt($ch, CURLOPT_AUTOREFERER, true);
+	curl_setopt($ch, CURLOPT_HEADER, 0);
+	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+	curl_setopt($ch, CURLOPT_URL, $url);
+	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
+	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
+	$data = curl_exec($ch);
+	curl_close($ch);
+	return $data;
+}
 
-    $ch = curl_init();
-
-    curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
-    curl_setopt($ch, CURLOPT_HEADER, 0);
-    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
-    curl_setopt($ch, CURLOPT_URL, $url);
-    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
-    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
-    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
-
-    $data = curl_exec($ch);
-    curl_close($ch);
-
-    return $data;
-
+function getExtension($string)
+{
+	return preg_replace("#(.+)?\.(\w+)(\?.+)?#", "$2", $string);
 }