123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace app\common\model;
- class Seo extends BaseModel {
-
- private $seo;
-
- public function type($type) {
- if (is_array($type)) {
- $this->seo['seo_title'] = isset($type[1])?$type[1]:'';
- $this->seo['seo_keywords'] = isset($type[2])?$type[2]:'';
- $this->seo['seo_description'] = isset($type[3])?$type[3]:'';
- } else {
- $this->seo = $this->getSeo($type);
- }
- if (!is_array($this->seo))
- return $this;
- foreach ($this->seo as $key => $value) {
- $this->seo[$key] = str_replace(array('{sitename}'), array(config('ds_config.site_name')), $value);
- }
- return $this;
- }
-
- private function getSeo($type) {
- $list = rkcache('seo', true);
- return $list[$type];
- }
-
- public function param($array = null) {
- if (!is_array($this->seo))
- return $this;
- if (is_array($array)) {
- $array_key = array_keys($array);
- foreach ($array_key as $k=>$val){
- $array_key[$k]='{'.$val.'}';
- }
- foreach ($this->seo as $key => $value) {
- $this->seo[$key] = str_replace($array_key, array_values($array), $value);
- }
- }
- return $this;
- }
-
- public function show() {
- $this->seo['seo_title'] = preg_replace("/{.*}/siU", '', $this->seo['seo_title']);
- $this->seo['seo_keywords'] = preg_replace("/{.*}/siU", '', $this->seo['seo_keywords']);
- $this->seo['seo_description'] = preg_replace("/{.*}/siU", '', $this->seo['seo_description']);
- return array(
- 'html_title' => $this->seo['seo_title'] ? $this->seo['seo_title'] : config('ds_config.site_name'),
- 'seo_keywords' => $this->seo['seo_keywords'] ? $this->seo['seo_keywords'] : config('ds_config.site_name'),
- 'seo_description' => $this->seo['seo_description'] ? $this->seo['seo_description'] : config('ds_config.site_name'),
- );
- }
- }
- ?>
|