This repository has been archived by the owner on Sep 4, 2022. It is now read-only.
/
Seo.php
61 lines (49 loc) · 1.69 KB
/
Seo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/*
Add this to your API to enabe SEO.
http://agiletoolkit.org/addons/seotags
*/
class Controller_Seo extends AbstractController {
public $move_tags=array('seo_keywords','seo_description','seo_title'=>'page_title');
public $copy_tags=array('page_title');
public $cur=array();
function init(){
parent::init();
$this->api->versionRequirement('4.0.2');
$this->cur['page_title']=$this->api->template->get('page_title');
foreach(array_merge($this->move_tags,$this->copy_tags) as $key=>$val){
if(is_int($key))$key=$val;
if($this->api->template->is_set($val));
$this->cur[$val]=$this->api->template->get($val);
}
$this->api->addHook('post-init',array($this,'SeoTags'));
}
function SeoTags(){
$this->api->template->trySet('_page',str_replace('/','_',$this->api->page));
if($this->api->page_object){
foreach($this->move_tags as $key=>$val){
if(is_int($key))$key=$val;
// If it's changed already, skip it
if($this->api->template->get($val)
!=$this->cur[$val])continue;
// Move seo_keywords from page to shared.html
if($this->api->page_object->template->is_set($key)){
$this->api->template->trySet($val,
$this->api->page_object->template->get($key));
$this->api->page_object->template->del($key);
}
}
foreach($this->copy_tags as $key=>$val){
if(is_int($key))$key=$val;
// Move seo_keywords from page to shared.html
if($this->api->page_object->template->is_set($key)){
$this->api->template->trySet($val,
$this->api->page_object->template->get($key));
}
}
}
}
function outputSitemap(){
// TODO:
}
}