狂雨默认的章节内容保存在runtime/txt中,有这里有需要将内容保存在其它位置,不大想修改狂雨的代码,就开发一个简单的插件来实现这个需求。 ## 名称LocalStorage 在addons中创建一个文件名,名字为:LocalStorage,里面就两个文件,一个是config.php,一个是LocalStorage.php,下面由上代码。 ## config.php ```php <?php return [ 'chapter_content_path'=>[ 'title'=>'章节内容存放目录:', 'type'=>'text', 'value'=>'' ] ]; ``` ## LocalStorage.php ```php <?php namespace addons\LocalStorage; use app\common\addons\Addon; use think\facade\Env; use org\File; class LocalStorage extends Addon{ private $rootpath = ''; public $info = [ 'name'=>'LocalStorage', 'title'=>'本地存储插件', 'description'=>'章节内容本地存储插件,可以实现不用修改原系统代码而改变本地章节内容的存放路径', 'status'=>1, 'author'=>'hoping', 'version'=>'1.0.0', 'group'=>'storage', 'mold'=>'web,wap,wechat', 'sort'=>0 ]; public function install(){ return true; } public function uninstall(){ return true; } public function read($path) { $filename = $this->rootpath . '/' . $path; return File::read($filename); } public function unlink($path) { if(is_array($path)) { foreach($path as $v) { $filename = $this->rootpath . '/' . $v; File::unlink($filename); } } else { $filename = $this->rootpath . '/' . $path; File::unlink($filename); } } public function put($path, $content) { $filename = $this->rootpath . '/' . $path; File::put($filename, $content); } protected function initialize() { parent::initialize(); $cnf = $this->getConfig(); if(!$cnf['chapter_content_path']) { $cnf['chapter_content_path'] = Env::get('runtime_path').'txt'; } $this->rootpath = $cnf['chapter_content_path']; } } ``` 最后修改:5年前 © 著作权归作者所有