2024.8.23
Loading...
Searching...
No Matches
class.tpl.app.logs.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
10/**
11 * Class TplAppLogs
12 *
13 * This class provides methods to generate and manage the logs menu within the Bearsampp application.
14 * It includes functionalities for creating the logs menu and listing log files.
15 */
17{
18 // Constant for the logs menu identifier
19 const MENU = 'logs';
20
21 /**
22 * Processes and generates the logs menu.
23 *
24 * This method generates the logs menu by retrieving the localized string for logs
25 * and calling the getMenu method from the TplApp class.
26 *
27 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
28 *
29 * @return array The generated logs menu as a string.
30 */
31 public static function process()
32 {
33 global $bearsamppLang;
34
35 return TplApp::getMenu($bearsamppLang->getValue(Lang::LOGS), self::MENU, get_called_class());
36 }
37
38 /**
39 * Generates the logs menu content.
40 *
41 * This method retrieves the list of log files from the logs directory, sorts them,
42 * and generates menu items for each log file using the getItemNotepad method from the TplAestan class.
43 *
44 * @global object $bearsamppRoot Provides access to the root directory of the application.
45 *
46 * @return string The generated logs menu content as a string.
47 */
48 public static function getMenuLogs()
49 {
50 global $bearsamppRoot;
51
52 $files = array();
53
54 // Open the logs directory
55 $handle = @opendir($bearsamppRoot->getLogsPath());
56 if (!$handle) {
57 return '';
58 }
59
60 // Read log files from the directory
61 while (false !== ($file = readdir($handle))) {
62 if ($file != "." && $file != ".." && Util::endWith($file, '.log')) {
63 $files[] = $file;
64 }
65 }
66
67 // Close the directory handle
68 closedir($handle);
69 ksort($files);
70
71 // Generate menu items for each log file
72 $result = '';
73 foreach ($files as $file) {
74 $result .= TplAestan::getItemNotepad(basename($file), $bearsamppRoot->getLogsPath() . '/' . $file) . PHP_EOL;
75 }
76 return $result;
77 }
78}
$result
global $bearsamppLang
global $bearsamppRoot
const LOGS
static getItemNotepad($caption, $path)
static getMenu($caption, $menu, $class)
static endWith($string, $search)