Zachary Kotlarek 13 年 前
親
コミット
f5dcc549aa
3 ファイル変更、49 行追加、7 行削除
  1. 40 1
      web/includes/season.php
  2. 1 4
      web/includes/series.php
  3. 8 2
      web/index.php

+ 40 - 1
web/includes/season.php

@@ -78,7 +78,46 @@ function findSeasons($path) {
 }
 
 # Save the search status for all seasons in a series
-function saveSeasons($data) {
+function saveSeasons($series_path, $data, $series_last, $seasons_last) {
+	# Do nothing if we are or just were in "skip" mode
+	if ($series['skip'] || $series_last['skip']) {
+		return;
+	}
+
+	# Fresh data from disk
+	$series = readFlags($series_path);
+	$seasons = findSeasons($series_path);
+
+	# For each season
+	foreach ($seasons as $season => $status) {
+		$season_path = $series_path . '/Season ' . $season;
+
+		$monitored = $data[ 'season_' . $season ];
+		$monitored_path = $season_path . '/season_done';
+		if ($monitored) {
+			if (file_exists($monitored_path)) {
+				unlink($monitored_path);
+			}
+		} else {
+			if (!file_exists($monitored_path)) {
+				touch($monitored_path);
+			}
+		}
+
+		$url = $data[ 'url_' . $season ];
+		$url_path = $season_path . '/url';
+		if ($url) {
+			if (isMonitored($season_path)) {
+				file_put_contents($url_path, $url . "\n");
+			}
+		} else {
+			if ($seasons_last[ $season ] && isMonitored($season_path)) {
+				if (file_exists($url_path)) {
+					unlink($url_path);
+				}
+			}
+		}
+	}
 }
 
 # Add a folder for the provided show and season

+ 1 - 4
web/includes/series.php

@@ -65,13 +65,10 @@ function readFlags($path) {
 }
 
 # Parse and save all of the serires-level exists and content files
-function saveFlags($show, $data) {
-	global $TV_PATH;
+function saveFlags($series_path, $data, $series_last, $seasons_last) {
 	global $EXISTS_FILES;
 	global $CONTENT_FILES;
 
-	$series_path = $TV_PATH . '/' . $show;
-
 	# Exists files
 	foreach ($EXISTS_FILES as $file) {
 		$path = $series_path . '/' . $file;

+ 8 - 2
web/index.php

@@ -18,8 +18,14 @@ if (isset($_REQUEST['show'])) {
 if ($show !== false && isset($_POST['Save'])) {
 	echo '<h4 style="color: red;">Saving not yet implemented</h4>';
 
-	#saveFlags($show, $_POST);
-	saveSeasons($show, $_POST);
+	# Grab the current settings for comparison
+	global $TV_PATH;
+	$series_path = $TV_PATH . '/'. $show;
+	$series_last = readFlags($series_path);
+	$seasons_last = findSeasons($series_path);
+
+	saveFlags($series_path, $_POST, $series_last, $seasons_last);
+	saveSeasons($series_path, $_POST, $series_last, $seasons_last);
 }
 
 #=========================================================================================