Add tick mood display.
This commit is contained in:
		
							parent
							
								
									efe9688289
								
							
						
					
					
						commit
						35033e50a6
					
				| @ -65,7 +65,7 @@ class AdminController extends Controller { | ||||
|             $basePath            = trim($_POST['base_path'] ?? '/'); | ||||
|             $itemsPerPage        = (int) ($_POST['items_per_page'] ?? 25); | ||||
|             $strictAccessibility = isset($_POST['strict_accessibility']); | ||||
|             $showTickMood = isset($_POST['strict_accessibility']); | ||||
|             $showTickMood        = isset($_POST['show_tick_mood']); | ||||
| 
 | ||||
|             // Password
 | ||||
|             $password        = $_POST['password'] ?? ''; | ||||
|  | ||||
| @ -29,7 +29,7 @@ class HomeController extends Controller { | ||||
|         if ($_SERVER['REQUEST_METHOD'] === 'POST' and isset($_POST['new_tick'])) { | ||||
|             // save the tick
 | ||||
|             if (trim($_POST['new_tick'])){ | ||||
|                 TickModel::save($_POST['new_tick']); | ||||
|                 TickModel::save($_POST['new_tick'], $_POST['tick_mood']); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|  | ||||
| @ -72,7 +72,7 @@ class ConfigModel { | ||||
|                 strict_accessibility, | ||||
|                 show_tick_mood | ||||
|                 ) | ||||
|                 VALUES (1, ?, ?, ?, ?, ?, ?)");
 | ||||
|                 VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?)");
 | ||||
|         } else { | ||||
|             $stmt = $db->prepare("UPDATE settings SET
 | ||||
|                 site_title=?, | ||||
|  | ||||
| @ -34,13 +34,14 @@ class TickModel { | ||||
| 
 | ||||
|                 // Ticks are pipe-delimited: timestamp|text
 | ||||
|                 // But just in case a tick contains a pipe, only split on the first one that occurs
 | ||||
|                 list($time, $emoji, $tick) = explode('|', $line, 3); | ||||
|                 list($time, $mood, $tick) = explode('|', $line, 3); | ||||
| 
 | ||||
|                 // Build the timestamp from the date and time
 | ||||
|                 // Ticks are always stored in UTC
 | ||||
|                 $timestampUTC = "$year-$month-$day $time"; | ||||
|                 yield [ | ||||
|                     'timestamp' => $timestampUTC, | ||||
|                     'mood' => $mood, | ||||
|                     'tick' => $tick, | ||||
|                 ]; | ||||
| 
 | ||||
| @ -51,7 +52,7 @@ class TickModel { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static function save(string $tick): void { | ||||
|     public static function save(string $tick, string $mood=''): void { | ||||
|         // build the tick path and filename from the current time
 | ||||
|         $now = new DateTime('now', new DateTimeZone('UTC')); | ||||
| 
 | ||||
| @ -70,7 +71,7 @@ class TickModel { | ||||
|         } | ||||
| 
 | ||||
|         // write the tick to the file (the file will be created if it doesn't exist)
 | ||||
|         $content = $time . "|" . $tick . "\n"; | ||||
|         $content = $time . '|' . $mood . '|' . $tick . "\n"; | ||||
|         file_put_contents($filename, $content, FILE_APPEND); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -1,6 +1,7 @@ | ||||
| <?php | ||||
| class HomeView { | ||||
|     public function renderTicksSection(string $siteDescription, array $ticks, int $page, int $limit){ | ||||
|         global $config; | ||||
|         ob_start(); | ||||
|         ?>
 | ||||
| 
 | ||||
| @ -12,6 +13,9 @@ class HomeView { | ||||
|                 ?>
 | ||||
|                 <li class="tick" tabindex="0"> | ||||
|                     <time datetime="<?php echo $datetime->format('c') ?>"><?php echo Util::escape_html($relativeTime) ?></time>
 | ||||
|                     <?php if ($config->showTickMood): ?>
 | ||||
|                         <span><?php echo $tick['mood'] ?></span>
 | ||||
|                     <?php endif; ?>
 | ||||
|                     <span class="tick-text"><?php echo Util::linkify(Util::escape_html($tick['tick'])) ?></span>
 | ||||
|                 </li> | ||||
|             <?php endforeach; ?>
 | ||||
|  | ||||
| @ -32,6 +32,7 @@ | ||||
|                 <div class="profile-tick"> | ||||
|                     <form class="profile-tick-form" method="post"> | ||||
|                         <input type="hidden" name="csrf_token" value="<?= Util::escape_html($_SESSION['csrf_token']) ?>"> | ||||
|                         <input type="hidden" name="tick_mood" value="<?= Util::escape_html($user->mood) ?>"> | ||||
|                         <textarea name="new_tick" | ||||
|                                   aria-label="What's ticking?" | ||||
|                                   placeholder="What's ticking?" | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user