<?php require_once __DIR__ . '/Page.php'; require_once __DIR__ . '/../File.php'; abstract class BasePage implements Page { protected $repositories; protected $title; public function __construct( array $repositories ) { $this->repositories = $repositories; } protected function renderLayout( $contentCallback, $currentRepo = null ) { ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><?php echo Config::SITE_TITLE . ($this->title ? ' - ' . htmlspecialchars( $this->title ) : ''); ?></title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css"> <link rel="stylesheet" href="repo.css"> </head> <body> <div class="container"> <header> <h1><?php echo Config::SITE_TITLE; ?></h1> <nav class="nav"> <a href="?">Home</a> <?php if( $currentRepo ): $safeName = urlencode( $currentRepo['safe_name'] ); ?> <a href="?repo=<?php echo $safeName; ?>">Files</a> <a href="?action=commits&repo=<?php echo $safeName; ?>">Commits</a> <a href="?action=refs&repo=<?php echo $safeName; ?>">Branches</a> <a href="?action=tags&repo=<?php echo $safeName; ?>">Tags</a> <?php endif; ?> <?php if( $currentRepo ): ?> <div class="repo-selector"> <label>Repository:</label> <select onchange="window.location.href='?repo=' + encodeURIComponent(this.value)"> <?php foreach( $this->repositories as $r ): ?> <option value="<?php echo htmlspecialchars( $r['safe_name'] ); ?>" <?php echo $r['safe_name'] === $currentRepo['safe_name'] ? 'selected' : ''; ?>> <?php echo htmlspecialchars( $r['name'] ); ?> </option> <?php endforeach; ?> </select> </div> <?php endif; ?> </nav> <?php if( $currentRepo ): ?> <div class="repo-info-banner"> <span class="current-repo"> Current: <strong><?php echo htmlspecialchars( $currentRepo['name'] ); ?></strong> </span> </div> <?php endif; ?> </header> <?php call_user_func( $contentCallback ); ?> </div> </body> </html> <?php } }