Переглянути джерело

View of directory containing only commented images

k4be 1 рік тому
батько
коміт
2925e1f10d
6 змінених файлів з 70 додано та 22 видалено
  1. 15 4
      dir.php
  2. 2 1
      dirlist.php
  3. 14 4
      image.js
  4. 17 7
      image.php
  5. 6 5
      include/db.php
  6. 16 1
      index.php

+ 15 - 4
dir.php

@@ -7,16 +7,21 @@ $dir = @$_GET['dir'];
 if (empty($dir)) {
 	die('Niepoprawne żądanie');
 }
+$mode = @$_GET['mode'];
 
 $dirinfo = get_dir_info($dir);
 if (!$dirinfo) {
 	die('Nie ma katalogu');
 }
-$images = get_dir_images($dir);
+$images = get_dir_images($dir, $mode);
 $content = '';
 foreach ($images as $image) {
 	$path = urlencode($image['path']);
-	$content .= '<a href="image.php?dir='.$dir.'&amp;file='.$path.'"><img src="' . $config['thumbnailpath'] . urlencode($dir) . '/' . $config['thumbnailsize'] . '-' . $path . '" alt="Obrazek"/></a>';
+	$content .= '<a href="image.php?dir='.$dir.'&amp;file='.$path;
+	if ($mode) {
+		$content .= '&mode=' . urlencode($mode);
+	}
+	$content .= '"><img src="' . $config['thumbnailpath'] . urlencode($dir) . '/' . $config['thumbnailsize'] . '-' . $path . '" alt="Obrazek"/></a>';
 }
 
 if (!$images || count($images) == 0) {
@@ -24,6 +29,9 @@ if (!$images || count($images) == 0) {
 }
 
 $dirname = htmlspecialchars($dirinfo['name']);
+if ($mode == 'viewcomments') {
+	$dirname .= ' (tylko komentarze)';
+}
 
 $comments_data = get_comments($dirinfo['id'], 'dir');
 $comments = generate_comment_field($comments_data, 'dir', $dirinfo['id']);
@@ -33,6 +41,8 @@ if ($dirinfo['comment']) {
 	$topcomment = '<h3>' . htmlspecialchars($dirinfo['comment']) . '</h3>';
 }
 
+$mode = json_encode($mode);
+
 ?><!DOCTYPE html>
 <html>
 <head>
@@ -40,8 +50,9 @@ if ($dirinfo['comment']) {
 <link rel="stylesheet" href="style.css?<?=$time?>" type="text/css">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <script type="text/javascript">
-const imageUrlPrefix = <?=$config['imagepath']?>;
-const scriptUrlPrefix = <?=$config['basepath']?>;
+const imageUrlPrefix = '<?=$config['imagepath']?>';
+const scriptUrlPrefix = '<?=$config['basepath']?>';
+const mode = '<?=$mode?>';
 </script>
 <script type="text/javascript" src="https://k4be.pl/jquery/jquery-3.6.3.min.js"></script>
 <script type="text/javascript" src="comment.js?<?=$time?>"></script>

+ 2 - 1
dirlist.php

@@ -7,7 +7,8 @@ function dirlist($dir) {
 		throw new Exception('Niepoprawne żądanie');
 	}
 
-	$images = get_dir_images($dir);
+	$mode = @$_GET['mode'];
+	$images = get_dir_images($dir, $mode);
 	if (!$images) {
 		throw new Exception('Brak wyników');
 	}

+ 14 - 4
image.js

@@ -4,6 +4,13 @@ var dirname = null;
 var filename = null;
 var currId = 0;
 
+function makeImageUrl(dir, file) {
+	var res = scriptUrlPrefix + 'image.php?dir=' + dirname + '&file=' + filename;
+	if (mode && mode.length > 0) {
+		res += '&mode=' + mode;
+	}
+}
+
 function setLinks(e) {
 	var doPush = false;
 
@@ -17,13 +24,13 @@ function setLinks(e) {
 	/* replace the content */
 	filename = imglist[currId].name;
 	if (currId > 0) {
-		$('#poprz').attr('href', scriptUrlPrefix + 'image.php?dir=' + dirname + '&file=' + imglist[currId-1].name);
+		$('#poprz').attr('href', makeImageUrl(dirname, imglist[currId-1].name));
 		$('#poprz').show();
 	} else {
 		$('#poprz').hide();
 	}
 	if (currId < imglist.length - 1) {
-		var url = scriptUrlPrefix + 'image.php?dir=' + dirname + '&file=' + imglist[currId+1].name;
+		var url = makeImageUrl(dirname, imglist[currId+1].name);
 		$('#nast').attr('href', url);
 		$('#imagelink').attr('href', url);
 		$('#nast').show();
@@ -38,7 +45,7 @@ function setLinks(e) {
 	image.css('opacity', '1');
     });
     if (doPush)
-	window.history.pushState(currId, '', scriptUrlPrefix + 'image.php?dir=' + dirname + '&file=' + filename);
+	window.history.pushState(currId, '', makeImageUrl(dirname, filename));
     commentsImageReplace(imglist[currId]);
     refreshComments();
 }
@@ -79,7 +86,7 @@ function imglistReceived(data) {
 	$('#imagelink').click(nextImage);
 	$('#nast').click(nextImage);
 	window.onpopstate = setLinks;
-	window.history.replaceState(currId, '', scriptUrlPrefix + 'image.php?dir=' + dirname + '&file=' + filename);
+	window.history.replaceState(currId, '', makeImageUrl(dirname, filename));
 }
 
 function getImgList() {
@@ -92,6 +99,9 @@ function getImgList() {
 	if (dirname === null || filename === null) /* invalid params */
 		return;
 	var args = 'dir=' + dirname;
+	if (mode && mode.length > 0) {
+		args += '&mode=' + mode;
+	}
 	$.ajax({
 		dataType: 'json',
 		url: scriptUrlPrefix+'dirlist.php?'+args,

+ 17 - 7
image.php

@@ -8,12 +8,13 @@ $file = @$_GET['file'];
 if (empty($dir) || empty($file)) {
 	die('Niepoprawne żądanie');
 }
+$mode = @$_GET['mode'];
 
 $dirinfo = get_dir_info($dir);
 if (!$dirinfo) {
 	die('Nie ma katalogu');
 }
-$images = get_dir_images($dir);
+$images = get_dir_images($dir, $mode);
 
 $found = false;
 $prev = null;
@@ -40,11 +41,16 @@ if (!$fileinfo) {
 
 $dirhtml = urlencode($dirinfo['path']);
 $filehtml = urlencode($fileinfo['path']);
+if ($mode) {
+	$modehtml = '&mode=' . urlencode($mode);
+} else {
+	$modehtml = '';
+};
 
-$content = '<div class="full-image-div"><a class="gora" href="dir.php?dir='.$dirhtml.'"></a><a id="poprz" ';
+$content = '<div class="full-image-div"><a class="gora" href="dir.php?dir='.$dirhtml.$modehtml.'"></a><a id="poprz" ';
 if ($prev) {
 	$prevhtml = urlencode($prev['path']);
-	$content .= 'href="image.php?file='.$prevhtml.'&amp;dir='.$dirhtml.'"';
+	$content .= 'href="image.php?file='.$prevhtml.'&amp;dir='.$dirhtml.$modehtml.'"';
 } else {
 	$content .= 'style="display:none;"';
 }
@@ -52,17 +58,20 @@ if ($prev) {
 $content .= '></a><div><a id="imagelink"';
 if ($next) {
 	$nexthtml = urlencode($next['path']);
-	$content .= ' href="image.php?file='.$nexthtml.'&amp;dir='.$dirhtml.'"';
+	$content .= ' href="image.php?file='.$nexthtml.'&amp;dir='.$dirhtml.$modehtml.'"';
 }
 $content .= '><img id="image" src="'.$config['imagepath'] . $dirhtml.'/'.$filehtml.'" class="pelny"/></a><a id="nast" ';
 if ($next) {
-	$content .= 'href="image.php?file='.$nexthtml.'&amp;dir='.$dirhtml.'"';
+	$content .= 'href="image.php?file='.$nexthtml.'&amp;dir='.$dirhtml.$modehtml.'"';
 } else {
 	$content .= 'style="display:none;"';
 }
 $content .= '></a>';
 
 $dirname = htmlspecialchars($dirinfo['name']);
+if ($mode == 'viewcomments') {
+	$dirname .= ' (tylko komentarze)';
+}
 
 $comments_data = get_comments($fileinfo['id'], 'image');
 $comments = generate_comment_field($comments_data, 'image', $fileinfo['id']);
@@ -74,8 +83,9 @@ $comments = generate_comment_field($comments_data, 'image', $fileinfo['id']);
 <link rel="stylesheet" href="style.css?<?=$time?>" type="text/css">
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <script type="text/javascript">
-const imageUrlPrefix = <?=$config['imagepath']?>;
-const scriptUrlPrefix = <?=$config['basepath']?>;
+const imageUrlPrefix = '<?=$config['imagepath']?>';
+const scriptUrlPrefix = '<?=$config['basepath']?>';
+const mode = '<?=$mode?>';
 </script>
 <script type="text/javascript" src="https://k4be.pl/jquery/jquery-3.6.3.min.js"></script>
 <script type="text/javascript" src="image.js?<?=$time?>"></script>

+ 6 - 5
include/db.php

@@ -1,4 +1,5 @@
 <?php
+require_once('comment.php');
 $pdo = null;
 $dsn = 'mysql:host=' . $config['host'] . ';dbname=' . $config['db'];
 $time = time();
@@ -112,7 +113,7 @@ function update_dir_count($dirpath, $count) {
 
 }
 
-function get_dir_images($dir) {
+function get_dir_images($dir, $mode = '') {
 	global $pdo;
 	$images = [];
 
@@ -129,12 +130,12 @@ function get_dir_images($dir) {
 	}
 
 	while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
+		if ($mode == 'viewcomments') {
+			if (count_comments($row['id'], 'image') == 0)
+				continue;
+		}
 		$images[] = $row;
 		$dirname = $row['dir_name']; // probably should do this only once
-	/*	echo '<pre>';
-		print_r($row);
-		echo '</pre>';
-		echo '<img src="' . $config['thumbnailpath'] . urlencode($dir) . '/' . $config['thumbnailsize'] . '-' . urlencode($row['path']) . '">';*/
 	}
 	return $images;
 }

+ 16 - 1
index.php

@@ -8,7 +8,22 @@ $dirs = get_dir_list();
 $dirs_html = '';
 
 foreach ($dirs as $dir) {
-	$dirs_html .= '<tr><td><a href="' . $config['basepath'] . 'dir.php?dir=' . urlencode($dir['path']) . '">' . htmlspecialchars($dir['name']) . '</a></td><td>' . $dir['count'] . '</td><td>' . date('j.m.Y', $dir['date']) . '</td><td>' . count_comments($dir['id'], 'dir') . '</td><td>' . count_comments_all_dir_images($dir['id']) . '</td></tr>';
+	$dirs_html .= '<tr><td><a href="' . $config['basepath'] . 'dir.php?dir=' . urlencode($dir['path']) . '">' . htmlspecialchars($dir['name']) . '</a></td>';
+	$dirs_html .= '<td>' . $dir['count'] . '</td>';
+	$dirs_html .= '<td>' . date('j.m.Y', $dir['date']) . '</td>';
+	$dirs_html .= '<td>' . count_comments($dir['id'], 'dir') . '</td>';
+	$dirs_html .= '<td>';
+
+	$comments = count_comments_all_dir_images($dir['id']);
+	if ($comments > 0) {
+		$dirs_html .= '<a href="' . $config['basepath'] . 'dir.php?dir=' . urlencode($dir['path']) . '&mode=viewcomments">';
+	}
+	$dirs_html .= $comments;
+	if ($comments > 0) {
+		$dirs_html .= '</a>';
+	}
+
+	$dirs_html .= '</td></tr>';
 }
 
 ?><!DOCTYPE html>