| 1 |
<?php
|
| 2 |
function gen_ex_dir(mysqli $db_conn, int $sid, int $fid = 0, string $dir = "", string $name = "") : string | bool
|
| 3 |
{
|
| 4 |
$output = "";
|
| 5 |
$output_cur_dir = "";
|
| 6 |
|
| 7 |
// Generate menu of current dir
|
| 8 |
$output_cur_dir .= <<<MENU
|
| 9 |
#---------------------------------------------------------------------
|
| 10 |
%menu M_EX_{$sid}_{$fid}
|
| 11 |
title 0, 0, "精华区 > {$name}"
|
| 12 |
screen 2, 0, S_EX_DIR
|
| 13 |
page 4, 1, 20
|
| 14 |
|
| 15 |
MENU;
|
| 16 |
|
| 17 |
$sql = "SELECT FID, dir, name, dt FROM ex_dir WHERE SID = $sid AND dir REGEXP '^" .
|
| 18 |
mysqli_real_escape_string($db_conn, $dir) .
|
| 19 |
"[^/]+/$' AND enable ORDER BY dir";
|
| 20 |
$rs = mysqli_query($db_conn, $sql);
|
| 21 |
if ($rs == false)
|
| 22 |
{
|
| 23 |
echo ("Query dir_list error: " . mysqli_error($db_conn));
|
| 24 |
return false;
|
| 25 |
}
|
| 26 |
|
| 27 |
$display_row = 4;
|
| 28 |
while ($row = mysqli_fetch_array($rs))
|
| 29 |
{
|
| 30 |
$output_sub_dir = gen_ex_dir($db_conn, $sid, $row["FID"], $row["dir"], $row["name"]);
|
| 31 |
if ($output_sub_dir == false)
|
| 32 |
{
|
| 33 |
echo ("gen_ex_dir({$sid}, {$row['dir']}) error\n");
|
| 34 |
return false;
|
| 35 |
}
|
| 36 |
$output .= $output_sub_dir;
|
| 37 |
|
| 38 |
$dir_name_f = addslashes($row["name"]) . str_repeat(" ", 55 - str_length($row["name"]));
|
| 39 |
$dt = (new DateTimeImmutable($row["dt"]))->format("Y.m.d");
|
| 40 |
|
| 41 |
$output_cur_dir .= <<<MENU
|
| 42 |
!M_EX_{$sid}_{$row['FID']} {$display_row}, 4, 1, 0, "{$row['dir']}", " [目录] {$dir_name_f} {$dt}"
|
| 43 |
|
| 44 |
MENU;
|
| 45 |
|
| 46 |
$display_row = 0;
|
| 47 |
}
|
| 48 |
mysqli_free_result($rs);
|
| 49 |
|
| 50 |
$sql = "SELECT bbs.AID, title, sub_dt FROM bbs
|
| 51 |
LEFT JOIN ex_file ON bbs.AID = ex_file.AID
|
| 52 |
LEFT JOIN ex_dir ON ex_file.FID = ex_dir.FID
|
| 53 |
WHERE bbs.SID = $sid AND TID = 0 AND visible AND gen_ex
|
| 54 |
AND IF(dir IS NULL, '', dir) = '" .
|
| 55 |
mysqli_real_escape_string($db_conn, $dir) .
|
| 56 |
"' ORDER BY bbs.AID";
|
| 57 |
$rs = mysqli_query($db_conn, $sql);
|
| 58 |
if ($rs == false)
|
| 59 |
{
|
| 60 |
echo ("Query article error: " . mysqli_error($db_conn));
|
| 61 |
return false;
|
| 62 |
}
|
| 63 |
|
| 64 |
while ($row = mysqli_fetch_array($rs))
|
| 65 |
{
|
| 66 |
$aid_f = str_repeat(" ", 7 - strlen("{$row['AID']}")) . "{$row['AID']}";
|
| 67 |
$title_f = split_line($row["title"], "", 55, 1, "");
|
| 68 |
$title_f = addslashes($title_f) . str_repeat(" ", 55 - str_length($title_f));
|
| 69 |
$sub_dt = (new DateTimeImmutable($row["sub_dt"]))->format("Y.m.d");
|
| 70 |
|
| 71 |
$output_cur_dir .= <<<MENU
|
| 72 |
@VIEW_EX_ARTICLE {$display_row}, 4, 1, 0, "{$row['AID']}", "{$aid_f} {$title_f} {$sub_dt}"
|
| 73 |
|
| 74 |
MENU;
|
| 75 |
|
| 76 |
$display_row = 0;
|
| 77 |
}
|
| 78 |
mysqli_free_result($rs);
|
| 79 |
|
| 80 |
$output_cur_dir .= <<<MENU
|
| 81 |
%
|
| 82 |
|
| 83 |
MENU;
|
| 84 |
|
| 85 |
$output = $output_cur_dir . $output;
|
| 86 |
|
| 87 |
return $output;
|
| 88 |
}
|
| 89 |
|
| 90 |
if (!isset($_SERVER["argc"]))
|
| 91 |
{
|
| 92 |
echo ("Invalid usage");
|
| 93 |
exit(-1);
|
| 94 |
}
|
| 95 |
|
| 96 |
chdir(dirname($_SERVER["argv"][0]));
|
| 97 |
|
| 98 |
require_once "../lib/db_open.inc.php";
|
| 99 |
require_once "../lib/str_process.inc.php";
|
| 100 |
|
| 101 |
// Generate menu screen
|
| 102 |
$menu_screen = <<<MENU
|
| 103 |
#---------------------------------------------------------------------
|
| 104 |
%S_EX_DIR
|
| 105 |
返回[[1;32m←[0;37m] 进入[[1;32m→[0;37m] 选择[[1;32m↑ PgUp[0;37m,[1;32m↓ PgDn[0;37m]
|
| 106 |
[44;37m [1;37m编 号 文章标题 日 期 [m
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
%
|
| 128 |
|
| 129 |
MENU;
|
| 130 |
|
| 131 |
$sql = "SELECT section_config.SID, section_config.title AS s_title
|
| 132 |
FROM section_config
|
| 133 |
INNER JOIN section_class ON section_config.CID = section_class.CID
|
| 134 |
WHERE section_config.enable AND section_class.enable AND ex_menu_update
|
| 135 |
ORDER BY section_class.sort_order, section_config.sort_order";
|
| 136 |
|
| 137 |
$rs = mysqli_query($db_conn, $sql);
|
| 138 |
if ($rs == false)
|
| 139 |
{
|
| 140 |
echo ("Query section error: " . mysqli_error($db_conn));
|
| 141 |
exit(-2);
|
| 142 |
}
|
| 143 |
|
| 144 |
while ($row = mysqli_fetch_array($rs))
|
| 145 |
{
|
| 146 |
$buffer = gen_ex_dir($db_conn, $row["SID"], 0, "", $row["s_title"]);
|
| 147 |
|
| 148 |
if ($buffer !== false)
|
| 149 |
{
|
| 150 |
$menu_output_path = "../../var/gen_ex/" . $row["SID"];
|
| 151 |
file_put_contents($menu_output_path, $menu_screen . $buffer);
|
| 152 |
|
| 153 |
$sql = "UPDATE section_config SET ex_menu_tm = NOW(), ex_menu_update = 0 WHERE SID = " . $row["SID"];
|
| 154 |
$ret = mysqli_query($db_conn, $sql);
|
| 155 |
if ($ret == false)
|
| 156 |
{
|
| 157 |
echo ("Update tm error: " . mysqli_error($db_conn));
|
| 158 |
exit(-3);
|
| 159 |
}
|
| 160 |
}
|
| 161 |
else
|
| 162 |
{
|
| 163 |
echo ("gen_ex_dir({$row["SID"]}, /) error\n");
|
| 164 |
}
|
| 165 |
}
|
| 166 |
mysqli_free_result($rs);
|
| 167 |
|
| 168 |
mysqli_close($db_conn);
|