feat: snapshot thumbnails link to their events refs #8293 (#8294)

This commit is contained in:
Jash Ambaliya authored and GitHub committed 2026-11-25 18:19:08 -05:00
1 parent 4aea51b7f8
commit 5bc06eaa0e
2 files changed
+123 -5

No files matched your search

+116
View File
@@ -0,0 +1,116 @@
<?php
// The snapshot view showed one thumbnail per event but the thumbnails did not link
// anywhere, so there was no way to open an event from its snapshot. Each thumbnail
// of an event the user may view is now wrapped in a link to that event; events the
// user may not view keep the plain image.
//
// Includes the real view with a stubbed ZM\Snapshot, ZM\Event and web helpers.
//
// Run as: php tests/php/test_snapshot_event_links.php [web root]
namespace ZM {
class Snapshot {
function __construct($id = null) {}
function Id() { return 5; }
function CreatedOn() { return '2026-01-01 00:00:00'; }
function Name() { return 'reference'; }
function Description() { return 'notes'; }
function CreatedBy() { return 9; }
function Events() { return $GLOBALS['snapshot_events']; }
}
class Event {
private $id;
private $viewable;
function __construct($id, $viewable) {
$this->id = $id;
$this->viewable = $viewable;
}
function Id() { return $this->id; }
function canView() { return $this->viewable; }
function getThumbnailSrc($args = array(), $querySep = '&') {
return '?view=image&eid='.$this->id.'&fid=snapshot';
}
}
}
namespace {
$root = isset($argv[1]) ? rtrim($argv[1], '/') : __DIR__.'/../../web';
// The view requires these; empty stubs keep the real classes out of the way.
$stubdir = sys_get_temp_dir().'/zm_snapshot_links_stubs_'.getmypid();
@mkdir($stubdir.'/includes', 0700, true);
foreach (array('Event', 'Filter', 'Snapshot') as $f) {
file_put_contents($stubdir.'/includes/'.$f.'.php', "<?php\n");
}
set_include_path($stubdir.PATH_SEPARATOR.get_include_path());
class StubUser {
function Id() { return 2; }
function unviewableMonitorIds() { return array(); }
function viewableMonitorIds() { return array(); }
}
function canView($area, $mid = false) { return $area === 'Snapshots'; }
function canEdit($area, $mid = false) { return false; }
function translate($s) { return $s; }
function validHtmlStr($s) { return htmlspecialchars($s, ENT_QUOTES); }
function validInt($v) {
if (!is_scalar($v)) return '';
return preg_replace('/[^0-9]/', '', (string)$v);
}
function xhtmlHeaders($file, $title) {}
function getBodyTopHTML() {}
function getNavBarHTML() { return ''; }
function xhtmlFooter() {}
define('ZM_FEATURES_SNAPSHOTS', true);
function render_snapshot($events) {
global $root;
$GLOBALS['snapshot_events'] = $events;
$_REQUEST = array('id' => '5');
$user = new StubUser();
$view = '';
ob_start();
include $root.'/skins/classic/views/snapshot.php';
return ob_get_clean();
}
$failures = 0;
function check($name, $got, $want) {
global $failures;
if ($got === $want) {
echo "ok - $name\n";
} else {
$failures++;
echo "FAIL - $name (got ".var_export($got, true).", want ".var_export($want, true).")\n";
}
}
$html = render_snapshot(array(new ZM\Event(11, true), new ZM\Event(12, true)));
check('viewable event 11 links to its event view',
strpos($html, '<a href="?view=event&amp;eid=11">') !== false, true);
check('viewable event 12 links to its event view',
strpos($html, '<a href="?view=event&amp;eid=12">') !== false, true);
check('event 11 thumbnail is still shown',
strpos($html, '?view=image&eid=11&fid=snapshot') !== false, true);
check('event 12 thumbnail is still shown',
strpos($html, '?view=image&eid=12&fid=snapshot') !== false, true);
$html = render_snapshot(array(new ZM\Event(21, true), new ZM\Event(22, false)));
check('viewable event 21 links to its event view',
strpos($html, '<a href="?view=event&amp;eid=21">') !== false, true);
check('unviewable event 22 is not linked',
strpos($html, 'eid=22">') === false, true);
check('unviewable event 22 thumbnail is still shown',
strpos($html, '?view=image&eid=22&fid=snapshot') !== false, true);
@unlink($stubdir.'/includes/Event.php');
@unlink($stubdir.'/includes/Filter.php');
@unlink($stubdir.'/includes/Snapshot.php');
@rmdir($stubdir.'/includes');
@rmdir($stubdir);
exit($failures ? 1 : 0);
}
+7 -5
View File
@@ -33,10 +33,6 @@ require_once('includes/Snapshot.php');
$id = isset($_REQUEST['id']) ? validInt($_REQUEST['id']) : null;
$snapshot = new ZM\Snapshot($id);
$monitors = array();
if ( count($user->unviewableMonitorIds())) {
$monitor_ids = $user->viewableMonitorIds();
}
xhtmlHeaders(__FILE__, translate('Snapshot').' '.$snapshot->Id());
getBodyTopHTML();
echo getNavBarHTML();
@@ -91,7 +87,13 @@ if ( !$snapshot->Id() ) {
$width = 100 / ( count($events) < 2 ? 1 : ( ( count($events) < 4 ) ? count($events) : 4 ) )-1;
foreach ( $snapshot->Events() as $event ) {
$imgSrc = $event->getThumbnailSrc(array(), '&amp;');
echo '<img src="?view=image&eid='.$event->Id().'&fid=snapshot" width="'.$width.'%"/>';
$eid = validInt($event->Id());
$img = '<img src="?view=image&eid='.$eid.'&fid=snapshot" width="'.$width.'%"/>';
if ( $event->canView() ) {
echo '<a href="?view=event&amp;eid='.$eid.'">'.$img.'</a>';
} else {
echo $img;
}
}
?>
</div><!--content-->