原码笔记

原码笔记

pbootcms英文模板搜索效果页面面包屑显示的优化

小诸哥 0

切换英文模板搜索结果显示还是中文的

修改方法如下
打开\apps\home\controller\SearchController.php文件,把里面的代码全部替换成以下(分为2x和3x版本,对应版本替换):
pbootcms2.1.1版本替换

 

  1. <?php
  2. /**
  3. * @copyright (C)2020-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2020年3月8日
  7. * 搜索控制器
  8. */
  9. namespace app\home\controller;
  10. use core\basic\Controller;
  11. class SearchController extends Controller
  12. {
  13. protected $parser;
  14. protected $htmldir;
  15. public function __construct()
  16. {
  17. $this->parser = new ParserController();
  18. $this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
  19. }
  20. // 内容搜索@mk-lang 增加英语
  21. public function index()
  22. {
  23. if (cookie('lg') == 'cn') {
  24. $searchtpl = request('searchtpl');
  25. if (! preg_match('/^[\w]+\.html$/', $searchtpl)) {
  26. $searchtpl = 'search.html';
  27. }
  28. $content = parent::parser($this->htmldir . $searchtpl); // 框架标签解析
  29. $content = $this->parser->parserBefore($content); // CMS公共标签前置解析
  30. $pagetitle = get('keyword') ? get('keyword') . '-' : '';
  31. $content = str_replace('{pboot:pagetitle}', $this->config('search_title') ?: $pagetitle . '搜索结果-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
  32. $content = $this->parser->parserPositionLabel($content, 0, '搜索', homeurl('search')); // CMS当前位置标签解析
  33. $content = $this->parser->parserSpecialPageSortLabel($content, - 1, '搜索结果', homeurl('search')); // 解析分类标签
  34. $content = $this->parser->parserSearchLabel($content); // 搜索结果标签
  35. $content = $this->parser->parserAfter($content); // CMS公共标签后置解析
  36. echo $content; // 搜索页面不缓存
  37. exit();
  38. } else {
  39. $searchtpl = request('searchtpl');
  40. if (! preg_match('/^[\w]+\.html$/', $searchtpl)) {
  41. $searchtpl = 'search.html';
  42. }
  43. $content = parent::parser($this->htmldir . $searchtpl); // 框架标签解析
  44. $content = $this->parser->parserBefore($content); // CMS公共标签前置解析
  45. $pagetitle = get('keyword') ? get('keyword') . '-' : '';
  46. $content = str_replace('{pboot:pagetitle}', $this->config('search_title') ?: $pagetitle . 'The search results-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
  47. $content = $this->parser->parserPositionLabel($content, 0, 'Search', homeurl('search')); // CMS当前位置标签解析
  48. $content = $this->parser->parserSpecialPageSortLabel($content, - 1, 'The search results', homeurl('search')); // 解析分类标签
  49. $content = $this->parser->parserSearchLabel($content); // 搜索结果标签
  50. $content = $this->parser->parserAfter($content); // CMS公共标签后置解析
  51. echo $content; // 搜索页面不缓存
  52. exit();
  53. }
  54. }
  55. }

pbootcms3.0.3版本替换

  1. <?php
  2. /**
  3. * @copyright (C)2020-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2020年3月8日
  7. * 搜索控制器
  8. */
  9. namespace app\home\controller;
  10. use core\basic\Controller;
  11. use core\basic\Url;
  12. class SearchController extends Controller
  13. {
  14. protected $parser;
  15. protected $htmldir;
  16. public function __construct()
  17. {
  18. $this->parser = new ParserController();
  19. $this->htmldir = $this->config('tpl_html_dir') ? $this->config('tpl_html_dir') . '/' : '';
  20. }
  21. // 内容搜索
  22. public function index()
  23. {
  24. if (cookie('lg') == 'cn') {
  25. $searchtpl = request('searchtpl');
  26. if (! preg_match('/^[\w]+\.html$/', $searchtpl)) {
  27. $searchtpl = 'search.html';
  28. }
  29. $content = parent::parser($this->htmldir . $searchtpl); // 框架标签解析
  30. $content = $this->parser->parserBefore($content); // CMS公共标签前置解析
  31. $pagetitle = get('keyword') ? get('keyword') . '-' : '';
  32. $content = str_replace('{pboot:pagetitle}', $this->config('search_title') ?: $pagetitle . '搜索结果-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
  33. $content = $this->parser->parserPositionLabel($content, 0, '搜索', Url::home('search')); // CMS当前位置标签解析
  34. $content = $this->parser->parserSpecialPageSortLabel($content, - 1, '搜索结果', Url::home('search')); // 解析分类标签
  35. $content = $this->parser->parserSearchLabel($content); // 搜索结果标签
  36. $content = $this->parser->parserAfter($content); // CMS公共标签后置解析
  37. echo $content; // 搜索页面不缓存
  38. exit();
  39. } else {
  40. $searchtpl = request('searchtpl');
  41. if (! preg_match('/^[\w]+\.html$/', $searchtpl)) {
  42. $searchtpl = 'search.html';
  43. }
  44. $content = parent::parser($this->htmldir . $searchtpl); // 框架标签解析
  45. $content = $this->parser->parserBefore($content); // CMS公共标签前置解析
  46. $pagetitle = get('keyword') ? get('keyword') . '-' : '';
  47. $content = str_replace('{pboot:pagetitle}', $this->config('search_title') ?: $pagetitle . 'The search results-{pboot:sitetitle}-{pboot:sitesubtitle}', $content);
  48. $content = $this->parser->parserPositionLabel($content, 0, 'Search', Url::home('search')); // CMS当前位置标签解析
  49. $content = $this->parser->parserSpecialPageSortLabel($content, - 1, 'The search results', Url::home('search')); // 解析分类标签
  50. $content = $this->parser->parserSearchLabel($content); // 搜索结果标签
  51. $content = $this->parser->parserAfter($content); // CMS公共标签后置解析
  52. echo $content; // 搜索页面不缓存
  53. exit();
  54. }
  55. }
  56. }

效果图

标签: 面包屑 英语 pbootcms