unify single and global history pages
This commit is contained in:
		
							parent
							
								
									b04b5af190
								
							
						
					
					
						commit
						f6112d26a2
					
				| @ -151,7 +151,7 @@ class SourceHistory extends Extension | |||||||
| 
 | 
 | ||||||
|         // lets get the values out of the result
 |         // lets get the values out of the result
 | ||||||
|         //$stored_result_id = $result['id'];
 |         //$stored_result_id = $result['id'];
 | ||||||
|         $stored_image_id = $result['image_id']; |         $stored_image_id = (int)$result['image_id']; | ||||||
|         $stored_source = $result['source']; |         $stored_source = $result['source']; | ||||||
| 
 | 
 | ||||||
|         log_debug("source_history", 'Reverting source of Image #'.$stored_image_id.' to ['.$stored_source.']'); |         log_debug("source_history", 'Reverting source of Image #'.$stored_image_id.' to ['.$stored_source.']'); | ||||||
|  | |||||||
| @ -1,49 +1,13 @@ | |||||||
| <?php declare(strict_types=1); | <?php declare(strict_types=1); | ||||||
|  | use function MicroHTML\{UL,LI,A,INPUT,FORM,DIV,LABEL,P,B,SPAN,rawHTML}; | ||||||
|  | 
 | ||||||
| class SourceHistoryTheme extends Themelet | class SourceHistoryTheme extends Themelet | ||||||
| { | { | ||||||
|     private $messages = []; |     private $messages = []; | ||||||
| 
 | 
 | ||||||
|     public function display_history_page(Page $page, int $image_id, array $history) |     public function display_history_page(Page $page, int $image_id, array $history) | ||||||
|     { |     { | ||||||
|         global $user; |         $history_html = $this->history_list($history, true); | ||||||
|         $start_string = " |  | ||||||
| 			<div style='text-align: left'> |  | ||||||
| 				".make_form(make_link("source_history/revert"))." |  | ||||||
| 					<ul style='list-style-type:none;'> |  | ||||||
| 		";
 |  | ||||||
| 
 |  | ||||||
|         $history_list = ""; |  | ||||||
|         $n = 0; |  | ||||||
|         foreach ($history as $fields) { |  | ||||||
|             $n++; |  | ||||||
|             $current_id = $fields['id']; |  | ||||||
|             $current_source = html_escape($fields['source']); |  | ||||||
|             $name = $fields['name']; |  | ||||||
|             $date_set = autodate($fields['date_set']); |  | ||||||
|             $h_ip = $user->can(Permissions::VIEW_IP) ? " ".show_ip($fields['user_ip'], "Sourcing Image #$image_id as '$current_source'") : ""; |  | ||||||
|             $setter = "<a href='".make_link("user/".url_escape($name))."'>".html_escape($name)."</a>$h_ip"; |  | ||||||
| 
 |  | ||||||
|             $selected = ($n == 2) ? " checked" : ""; |  | ||||||
| 
 |  | ||||||
|             $history_list .= " |  | ||||||
| 				<li> |  | ||||||
| 					<input type='radio' name='revert' id='$current_id' value='$current_id'$selected> |  | ||||||
| 					<label for='$current_id'> |  | ||||||
| 						$current_source |  | ||||||
| 						<br>      |  | ||||||
| 						Set by $setter $date_set |  | ||||||
| 					</label> |  | ||||||
| 				</li> |  | ||||||
| 				";
 |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $end_string = " |  | ||||||
| 					</ul> |  | ||||||
| 					<input type='submit' value='Revert To'> |  | ||||||
| 				</form> |  | ||||||
| 			</div> |  | ||||||
| 		";
 |  | ||||||
|         $history_html = $start_string . $history_list . $end_string; |  | ||||||
| 
 | 
 | ||||||
|         $page->set_title('Image '.$image_id.' Source History'); |         $page->set_title('Image '.$image_id.' Source History'); | ||||||
|         $page->set_heading('Source History: '.$image_id); |         $page->set_heading('Source History: '.$image_id); | ||||||
| @ -53,43 +17,12 @@ class SourceHistoryTheme extends Themelet | |||||||
| 
 | 
 | ||||||
|     public function display_global_page(Page $page, array $history, int $page_number) |     public function display_global_page(Page $page, array $history, int $page_number) | ||||||
|     { |     { | ||||||
|         $start_string = " |         $history_html = $this->history_list($history, false); | ||||||
| 			<div style='text-align: left'> |  | ||||||
| 				".make_form(make_link("source_history/revert"))." |  | ||||||
| 					<ul style='list-style-type:none;'> |  | ||||||
| 		";
 |  | ||||||
|         $end_string = " |  | ||||||
| 					</ul> |  | ||||||
| 					<input type='submit' value='Revert To'> |  | ||||||
| 				</form> |  | ||||||
| 			</div> |  | ||||||
| 		";
 |  | ||||||
| 
 | 
 | ||||||
|         global $user; |  | ||||||
|         $history_list = ""; |  | ||||||
|         foreach ($history as $fields) { |  | ||||||
|             $current_id = $fields['id']; |  | ||||||
|             $image_id = $fields['image_id']; |  | ||||||
|             $current_source = html_escape($fields['source']); |  | ||||||
|             $name = $fields['name']; |  | ||||||
|             $h_ip = $user->can(Permissions::VIEW_IP) ? " ".show_ip($fields['user_ip'], "Sourcing Image #$image_id as '$current_source'") : ""; |  | ||||||
|             $setter = "<a href='".make_link("user/".url_escape($name))."'>".html_escape($name)."</a>$h_ip"; |  | ||||||
| 
 |  | ||||||
|             $history_list .= ' |  | ||||||
| 				<li> |  | ||||||
| 					<input type="radio" name="revert" value="'.$current_id.'"> |  | ||||||
| 					<a href="'.make_link('post/view/'.$image_id).'">'.$image_id.'</a>: |  | ||||||
| 					'.$current_source.' (Set by '.$setter.') |  | ||||||
| 				</li> |  | ||||||
| 			'; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $history_html = $start_string . $history_list . $end_string; |  | ||||||
|         $page->set_title("Global Source History"); |         $page->set_title("Global Source History"); | ||||||
|         $page->set_heading("Global Source History"); |         $page->set_heading("Global Source History"); | ||||||
|         $page->add_block(new Block("Source History", $history_html, "main", 10)); |         $page->add_block(new Block("Source History", $history_html, "main", 10)); | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         $h_prev = ($page_number <= 1) ? "Prev" : |         $h_prev = ($page_number <= 1) ? "Prev" : | ||||||
|             '<a href="'.make_link('source_history/all/'.($page_number-1)).'">Prev</a>'; |             '<a href="'.make_link('source_history/all/'.($page_number-1)).'">Prev</a>'; | ||||||
|         $h_index = "<a href='".make_link()."'>Index</a>"; |         $h_index = "<a href='".make_link()."'>Index</a>"; | ||||||
| @ -105,11 +38,11 @@ class SourceHistoryTheme extends Themelet | |||||||
|     public function display_admin_block(string $validation_msg='') |     public function display_admin_block(string $validation_msg='') | ||||||
|     { |     { | ||||||
|         global $page; |         global $page; | ||||||
|          | 
 | ||||||
|         if (!empty($validation_msg)) { |         if (!empty($validation_msg)) { | ||||||
|             $validation_msg = '<br><b>'. $validation_msg .'</b>'; |             $validation_msg = '<br><b>'. $validation_msg .'</b>'; | ||||||
|         } |         } | ||||||
|          | 
 | ||||||
|         $html = ' |         $html = ' | ||||||
| 			Revert source changes by a specific IP address or username, optionally limited to recent changes. | 			Revert source changes by a specific IP address or username, optionally limited to recent changes. | ||||||
| 			'.$validation_msg.' | 			'.$validation_msg.' | ||||||
| @ -125,7 +58,7 @@ class SourceHistoryTheme extends Themelet | |||||||
| 		";
 | 		";
 | ||||||
|         $page->add_block(new Block("Mass Source Revert", $html)); |         $page->add_block(new Block("Mass Source Revert", $html)); | ||||||
|     } |     } | ||||||
|      | 
 | ||||||
|     /* |     /* | ||||||
|      * Show a standard page for results to be put into |      * Show a standard page for results to be put into | ||||||
|      */ |      */ | ||||||
| @ -140,4 +73,52 @@ class SourceHistoryTheme extends Themelet | |||||||
|     { |     { | ||||||
|         $this->messages[] = '<p><b>'. $title .'</b><br>'. $body .'</p>'; |         $this->messages[] = '<p><b>'. $title .'</b><br>'. $body .'</p>'; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     protected function history_list(array $history, bool $select_2nd): string | ||||||
|  |     { | ||||||
|  |         $history_list = ""; | ||||||
|  |         foreach ($history as $n => $fields) { | ||||||
|  |             $history_list .= $this->history_entry($fields, $select_2nd && $n == 1); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return " | ||||||
|  | 			<div style='text-align: left'> | ||||||
|  | 				" . make_form(make_link("source_history/revert")) . " | ||||||
|  | 					<ul style='list-style-type:none;'> | ||||||
|  | 					    $history_list | ||||||
|  | 					</ul> | ||||||
|  | 					<input type='submit' value='Revert To'> | ||||||
|  | 				</form> | ||||||
|  | 			</div> | ||||||
|  | 		";
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected function history_entry(array $fields, bool $selected): string | ||||||
|  |     { | ||||||
|  |         global $user; | ||||||
|  |         $image_id = $fields['image_id']; | ||||||
|  |         $current_id = $fields['id']; | ||||||
|  |         $current_source = html_escape($fields['source']); | ||||||
|  |         $name = $fields['name']; | ||||||
|  |         $date_set = rawHTML(autodate($fields['date_set'])); | ||||||
|  |         $ip = $user->can(Permissions::VIEW_IP) ? | ||||||
|  |             rawHTML(" " . show_ip($fields['user_ip'], "Sourcing Image #$image_id as '$current_source'")) | ||||||
|  |             : null; | ||||||
|  |         $setter = A(["href"=>make_link("user/" . url_escape($name))], $name); | ||||||
|  | 
 | ||||||
|  |         return (string)LI( | ||||||
|  |             INPUT(["type"=>"radio", "name"=>"revert", "id"=>"$current_id", "value"=>"$current_id", "checked"=>$selected]), | ||||||
|  |             A(["href"=>make_link("post/view/$image_id")], $image_id), | ||||||
|  |             ": ", | ||||||
|  |             LABEL( | ||||||
|  |                 ["for"=>"$current_id"], | ||||||
|  |                 $current_source, | ||||||
|  |                 " - ", | ||||||
|  |                 $setter, | ||||||
|  |                 $ip, | ||||||
|  |                 " - ", | ||||||
|  |                 $date_set | ||||||
|  |             ) | ||||||
|  |         ); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -1,56 +1,13 @@ | |||||||
| <?php declare(strict_types=1); | <?php declare(strict_types=1); | ||||||
|  | use function MicroHTML\{UL,LI,A,INPUT,FORM,DIV,LABEL,P,B,SPAN,rawHTML}; | ||||||
|  | 
 | ||||||
| class TagHistoryTheme extends Themelet | class TagHistoryTheme extends Themelet | ||||||
| { | { | ||||||
|     private $messages = []; |     private $messages = []; | ||||||
| 
 | 
 | ||||||
|     public function display_history_page(Page $page, int $image_id, array $history) |     public function display_history_page(Page $page, int $image_id, array $history) | ||||||
|     { |     { | ||||||
|         global $user; |         $history_html = $this->history_list($history, true); | ||||||
|         $start_string = " |  | ||||||
| 			<div style='text-align: left'> |  | ||||||
| 				".make_form(make_link("tag_history/revert"))." |  | ||||||
| 					<ul style='list-style-type:none;'> |  | ||||||
| 		";
 |  | ||||||
| 
 |  | ||||||
|         $history_list = ""; |  | ||||||
|         $n = 0; |  | ||||||
|         foreach ($history as $fields) { |  | ||||||
|             $n++; |  | ||||||
|             $current_id = $fields['id']; |  | ||||||
|             $current_tags = html_escape($fields['tags']); |  | ||||||
|             $name = $fields['name']; |  | ||||||
|             $date_set = autodate($fields['date_set']); |  | ||||||
|             $h_ip = $user->can(Permissions::VIEW_IP) ? " ".show_ip($fields['user_ip'], "Tagging Image #$image_id as '$current_tags'") : ""; |  | ||||||
|             $setter = "<a href='".make_link("user/".url_escape($name))."'>".html_escape($name)."</a>$h_ip"; |  | ||||||
| 
 |  | ||||||
|             $selected = ($n == 2) ? " checked" : ""; |  | ||||||
| 
 |  | ||||||
|             $current_tags = Tag::explode($current_tags); |  | ||||||
|             $taglinks = []; |  | ||||||
|             foreach ($current_tags as $tag) { |  | ||||||
|                 $taglinks[] = "<a href='".make_link("post/list/".$tag."/1")."'>".$tag."</a>"; |  | ||||||
|             } |  | ||||||
|             $current_tags = implode(' ', $taglinks); |  | ||||||
| 
 |  | ||||||
|             $history_list .= " |  | ||||||
| 				<li> |  | ||||||
| 					<input type='radio' name='revert' id='$current_id' value='$current_id'$selected> |  | ||||||
| 					<label for='$current_id'> |  | ||||||
| 						$current_tags |  | ||||||
| 						<br>      |  | ||||||
| 						Set by $setter $date_set |  | ||||||
| 					</label> |  | ||||||
| 				</li> |  | ||||||
| 				";
 |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $end_string = " |  | ||||||
| 					</ul> |  | ||||||
| 					<input type='submit' value='Revert To'> |  | ||||||
| 				</form> |  | ||||||
| 			</div> |  | ||||||
| 		";
 |  | ||||||
|         $history_html = $start_string . $history_list . $end_string; |  | ||||||
| 
 | 
 | ||||||
|         $page->set_title('Image '.$image_id.' Tag History'); |         $page->set_title('Image '.$image_id.' Tag History'); | ||||||
|         $page->set_heading('Tag History: '.$image_id); |         $page->set_heading('Tag History: '.$image_id); | ||||||
| @ -60,43 +17,12 @@ class TagHistoryTheme extends Themelet | |||||||
| 
 | 
 | ||||||
|     public function display_global_page(Page $page, array $history, int $page_number) |     public function display_global_page(Page $page, array $history, int $page_number) | ||||||
|     { |     { | ||||||
|         $start_string = " |         $history_html = $this->history_list($history, false); | ||||||
| 			<div style='text-align: left'> |  | ||||||
| 				".make_form(make_link("tag_history/revert"))." |  | ||||||
| 					<ul style='list-style-type:none;'> |  | ||||||
| 		";
 |  | ||||||
|         $end_string = " |  | ||||||
| 					</ul> |  | ||||||
| 					<input type='submit' value='Revert To'> |  | ||||||
| 				</form> |  | ||||||
| 			</div> |  | ||||||
| 		";
 |  | ||||||
| 
 | 
 | ||||||
|         global $user; |  | ||||||
|         $history_list = ""; |  | ||||||
|         foreach ($history as $fields) { |  | ||||||
|             $current_id = $fields['id']; |  | ||||||
|             $image_id = $fields['image_id']; |  | ||||||
|             $current_tags = html_escape($fields['tags']); |  | ||||||
|             $name = $fields['name']; |  | ||||||
|             $h_ip = $user->can(Permissions::VIEW_IP) ? " ".show_ip($fields['user_ip'], "Tagging Image #$image_id as '$current_tags'") : ""; |  | ||||||
|             $setter = "<a href='".make_link("user/".url_escape($name))."'>".html_escape($name)."</a>$h_ip"; |  | ||||||
| 
 |  | ||||||
|             $history_list .= ' |  | ||||||
| 				<li> |  | ||||||
| 					<input type="radio" name="revert" value="'.$current_id.'"> |  | ||||||
| 					<a href="'.make_link('post/view/'.$image_id).'">'.$image_id.'</a>: |  | ||||||
| 					'.$current_tags.' (Set by '.$setter.') |  | ||||||
| 				</li> |  | ||||||
| 			'; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         $history_html = $start_string . $history_list . $end_string; |  | ||||||
|         $page->set_title("Global Tag History"); |         $page->set_title("Global Tag History"); | ||||||
|         $page->set_heading("Global Tag History"); |         $page->set_heading("Global Tag History"); | ||||||
|         $page->add_block(new Block("Tag History", $history_html, "main", 10)); |         $page->add_block(new Block("Tag History", $history_html, "main", 10)); | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|         $h_prev = ($page_number <= 1) ? "Prev" : |         $h_prev = ($page_number <= 1) ? "Prev" : | ||||||
|             '<a href="'.make_link('tag_history/all/'.($page_number-1)).'">Prev</a>'; |             '<a href="'.make_link('tag_history/all/'.($page_number-1)).'">Prev</a>'; | ||||||
|         $h_index = "<a href='".make_link()."'>Index</a>"; |         $h_index = "<a href='".make_link()."'>Index</a>"; | ||||||
| @ -147,4 +73,59 @@ class TagHistoryTheme extends Themelet | |||||||
|     { |     { | ||||||
|         $this->messages[] = '<p><b>'. $title .'</b><br>'. $body .'</p>'; |         $this->messages[] = '<p><b>'. $title .'</b><br>'. $body .'</p>'; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     protected function history_list(array $history, bool $select_2nd): string | ||||||
|  |     { | ||||||
|  |         $history_list = ""; | ||||||
|  |         foreach ($history as $n => $fields) { | ||||||
|  |             $history_list .= $this->history_entry($fields, $select_2nd && $n == 1); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return " | ||||||
|  | 			<div style='text-align: left'> | ||||||
|  | 				" . make_form(make_link("tag_history/revert")) . " | ||||||
|  | 					<ul style='list-style-type:none;'> | ||||||
|  | 					    $history_list | ||||||
|  | 					</ul> | ||||||
|  | 					<input type='submit' value='Revert To'> | ||||||
|  | 				</form> | ||||||
|  | 			</div> | ||||||
|  | 		";
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected function history_entry(array $fields, bool $selected): string | ||||||
|  |     { | ||||||
|  |         global $user; | ||||||
|  |         $image_id = $fields['image_id']; | ||||||
|  |         $current_id = $fields['id']; | ||||||
|  |         $current_tags = html_escape($fields['tags']); | ||||||
|  |         $name = $fields['name']; | ||||||
|  |         $date_set = rawHTML(autodate($fields['date_set'])); | ||||||
|  |         $ip = $user->can(Permissions::VIEW_IP) ? | ||||||
|  |             rawHTML(" " . show_ip($fields['user_ip'], "Tagging Image #$image_id as '$current_tags'")) | ||||||
|  |             : null; | ||||||
|  |         $setter = A(["href"=>make_link("user/" . url_escape($name))], $name); | ||||||
|  | 
 | ||||||
|  |         $current_tags = Tag::explode($current_tags); | ||||||
|  |         $taglinks = SPAN(); | ||||||
|  |         foreach ($current_tags as $tag) { | ||||||
|  |             $taglinks->appendChild(A(["href"=>make_link("post/list/$tag/1")], $tag)); | ||||||
|  |             $taglinks->appendChild(" "); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return (string)LI( | ||||||
|  |             INPUT(["type"=>"radio", "name"=>"revert", "id"=>"$current_id", "value"=>"$current_id", "checked"=>$selected]), | ||||||
|  |             A(["href"=>make_link("post/view/$image_id")], $image_id), | ||||||
|  |             ": ", | ||||||
|  |             LABEL( | ||||||
|  |                 ["for"=>"$current_id"], | ||||||
|  |                 $taglinks, | ||||||
|  |                 " - ", | ||||||
|  |                 $setter, | ||||||
|  |                 $ip, | ||||||
|  |                 " - ", | ||||||
|  |                 $date_set | ||||||
|  |             ) | ||||||
|  |         ); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user