Browse Source

add ViewController

master
filesite 3 years ago
parent
commit
0c3b1e8024
  1. 16
      themes/manual/controller/SiteController.php
  2. 45
      themes/manual/controller/ViewController.php
  3. 16
      themes/manual/views/view/index.php
  4. 8
      www/css/manual.css

16
themes/manual/controller/SiteController.php

@ -10,13 +10,15 @@ Class SiteController extends Controller { @@ -10,13 +10,15 @@ Class SiteController extends Controller {
public function actionIndex() {
//获取数据
$titles = [];
$content = '';
$html = '';
$scanner = new DirScanner();
$scanner->setWebRoot('/content/');
$dirTree = $scanner->scan(__DIR__ . '/../../../www/content/', 4);
$readmeFile = $scanner->getDefaultReadme();
$titles = [];
$content = '';
$html = '';
if (!empty($readmeFile)) {
$titles = $scanner->getMDTitles($readmeFile['id']);
$content = file_get_contents($readmeFile['realpath']);
@ -26,15 +28,9 @@ Class SiteController extends Controller { @@ -26,15 +28,9 @@ Class SiteController extends Controller {
$html = $scanner->fixMDUrls($readmeFile['realpath'], $html);
}
//alert message test
//$this->sendMsgToClient('Alert message - danger', 'danger');
//$this->sendMsgToClient('Alert message - warning', 'warning');
//$this->sendMsgToClient('Alert message - success', 'success');
//$this->sendMsgToClient('Alert message - info', 'info');
$pageTitle = "FileSite.io - 无数据库、基于文件和目录的网址导航、图书、图片、视频网站PHP开源系统";
$viewName = 'index';
$params = compact('dirTree', 'readmeFile', 'titles', 'content', 'html');
$params = compact('titles', 'content', 'html');
return $this->render($viewName, $params, $pageTitle);
}

45
themes/manual/controller/ViewController.php

@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
<?php
/**
* View Controller
*/
require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php';
Class ViewController extends Controller {
public function actionIndex() {
$fileId = $this->get('id', '');
if (!empty($fileId)) {
$fileId = preg_replace('/\W/', '', $fileId);
}
//获取数据
$titles = [];
$content = '';
$html = '';
$scanner = new DirScanner();
$scanner->setWebRoot('/content/');
$dirTree = $scanner->scan(__DIR__ . '/../../../www/content/', 4);
$scanResults = $scanner->getScanResults();
if (!empty($scanResults[$fileId])) {
$readmeFile = $scanResults[$fileId];
$titles = $scanner->getMDTitles($readmeFile['id']);
$content = file_get_contents($readmeFile['realpath']);
$Parsedown = new Parsedown();
$html = $Parsedown->text($content);
$html = $scanner->fixMDUrls($readmeFile['realpath'], $html);
}else {
throw new Exception("404 - 文件编号 {$fileId} 找不到", 404);
}
$pageTitle = !empty($titles) ? $titles[0]['name'] : "404 - 文件找不到";
$viewName = 'index';
$params = compact('titles', 'content', 'html');
return $this->render($viewName, $params, $pageTitle);
}
}

16
themes/manual/views/view/index.php

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
<div class="indexes">
<?php
if (!empty($viewData['titles'])) {
foreach($viewData['titles'] as $title) {
$link = urlencode($title['name']);
echo <<<eof
<{$title['heading']}><a href="#{$link}">{$title['name']}</a></{$title['heading']}>
eof;
}
}
?>
</div>
<div class="content markdown-body">
<?php echo $viewData['html']; ?>
</div>

8
www/css/manual.css

@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
/* for theme manual */
*,html,body{padding:0:;margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"}
.indexes{width:23%;position:fixed;padding-left:0.5em;padding-top:1em}
.indexes{width:23%;position:fixed;text-align:left;padding-left:0.5em;padding-top:1em}
.content{margin-left:23.8%;padding:0.5em}
.footer{margin:1em auto;text-align:center}
.indexes h1,.indexes h2,.indexes h3,.indexes h4,.indexes h5,.indexes h6{font-size:1.2em;font-weight:normal;margin-bottom:0.35em}
.indexes h1{display:none}
.indexes h2{margin-top:1em}
.indexes h2{margin-top:1em;}
.indexes h3{text-indent:1em}
.indexes a{background-color:transparent;color:#0969da;text-decoration: none}
@media (max-width: 640px) {
.indexes{position:static;width:auto}
.indexes h1{display:block;padding-bottom:0.3em;text-align:center;font-size:2em;border-bottom:1px solid hsla(210,18%,87%,1)}
.indexes{position:static;width:auto;padding-bottom:0.5em;margin-bottom:0.5em;border-bottom:1px solid hsla(210,18%,87%,1)}
.indexes h1{display:block;padding-left:0;padding-bottom:0.3em;text-align:center;font-size:2em;border-bottom:1px solid hsla(210,18%,87%,1)}
.content{margin-left:0;}
}
Loading…
Cancel
Save