Browse Source

add ListController for theme GoogleImage

master
filesite 3 years ago
parent
commit
f8011e7477
  1. 2
      conf/app.php
  2. 12
      controller/Controller.php
  3. 42
      themes/googleimage/controller/ListController.php
  4. 5
      themes/googleimage/views/layout/main.php
  5. 1
      themes/googleimage/views/site/index.php

2
conf/app.php

@ -10,7 +10,7 @@ return array( @@ -10,7 +10,7 @@ return array(
//'theme' => 'manual', //name of theme which is enabled
//in developing
'content_directory' => 'dogs_2/', //directory of contents in /www/
'content_directory' => 'dogs/', //directory of contents in /www/
'theme' => 'googleimage', //name of theme which is enabled
'default_layout' => 'main', //default layout

12
controller/Controller.php

@ -25,8 +25,20 @@ Class Controller { @@ -25,8 +25,20 @@ Class Controller {
//render view
protected function render($viewName, $viewData = array(), $pageTitle = '') {
$layoutFile = __DIR__ . '/../views/layout/' . $this->layout . '.php';
$viewFile = __DIR__ . '/../views/' . FSC::$app['controller'] . '/' . $viewName . '.php';
//双斜杠//开头的共享视图支持
if (preg_match('/^\/\//', $viewName)) {
$viewFile = __DIR__ . '/../views/' . str_replace('//', '/', $viewName) . '.php';
}
if (!empty(FSC::$app['config']['theme'])) {
$layoutFile = __DIR__ . '/../themes/' . FSC::$app['config']['theme'] . '/views/layout/' . $this->layout . '.php';
$viewFile = __DIR__ . '/../themes/' . FSC::$app['config']['theme'] . '/views/' . FSC::$app['controller'] . '/' . $viewName . '.php';
//双斜杠//开头的共享视图支持
if (preg_match('/^\/\//', $viewName)) {
$viewFile = __DIR__ . '/../themes/' . FSC::$app['config']['theme'] . '/views/' .
str_replace('//', '/', $viewName) . '.php';
}
}
//include layout and view

42
themes/googleimage/controller/ListController.php

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
<?php
/**
* List Controller
*/
require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php';
Class ListController extends Controller {
public function actionIndex() {
//获取数据
$scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']);
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4);
$scanResults = $scanner->getScanResults();
//获取目录
$menus = $scanner->getMenus();
$cateId = $this->get('id', $menus[0]['id']);
$titles = [];
$html = '';
$readmeFile = $scanner->getDefaultReadme();
if (!empty($readmeFile)) {
$titles = $scanner->getMDTitles($readmeFile['id']);
$Parsedown = new Parsedown();
$content = file_get_contents($readmeFile['realpath']);
$html = $Parsedown->text($content);
$html = $scanner->fixMDUrls($readmeFile['realpath'], $html);
}
//TODO: 获取父目录,生成面包屑
$pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统";
$viewName = '//site/index'; //共享视图
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'html');
return $this->render($viewName, $params, $pageTitle);
}
}

5
themes/googleimage/views/layout/main.php

@ -30,8 +30,9 @@ @@ -30,8 +30,9 @@
<?php
//### Render view file
$viewFile = __DIR__ . '/../' . FSC::$app['controller'] . '/' . $viewName . '.php';
include_once $viewFile;
if (!empty($viewFile) && file_exists($viewFile)) {
include_once $viewFile;
}
?>
<div class="footer">

1
themes/googleimage/views/site/index.php

@ -58,6 +58,7 @@ eof; @@ -58,6 +58,7 @@ eof;
echo <<<eof
<a href="{$file['path']}" class="img-item img-preview" target="_blank">
<img src="{$file['path']}" alt="{$file['filename']}">
<strong>{$file['filename']}</strong>
</a>
eof;
}

Loading…
Cancel
Save