OpenSencillo  2015.009
Long live the simplicity of PHP
 All Data Structures Namespaces Files Functions Pages
header.seo.hdrseo.php
1 <?php
11 class headerSeo
12 {
13  public $seo;
14  public $info;
15 
16  private $header;
17  private $body;
18  private $lang;
19  private $oginfo;
20 
24  public function __construct()
25  {
26  $this->header['doctype-def']='<!DOCTYPE html>';
27  $this->header['html-def']='<html><head>';
28  $this->body='</head>';
29  }
30 
34  public function nocache()
35  {
36  header("Cache-Control: no-store, no-cache, must-revalidate");
37  header("Cache-Control: post-check=0, pre-check=0", false);
38  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
39  $this->header['cache-control-def'] = '<meta http-equiv="cache-control" content="no-cache">';
40  $this->header['expires-def'] = '<meta http-equiv="expires" content="-1">';
41  $this->header['pragma-def'] = '<meta http-equiv="pragma" content="no-cache">';
42  }
47  public function keywords($kw)
48  {
49  $this->header['keywords-def'] = '<meta name="keywords" content="'.$kw.'" />';
50  }
51 
56  public function encode($ec='UTF-8')
57  {
58  $this->header['charset-def'] = '<meta charset="'.$ec.'" />';
59  }
60 
64  public function responsive()
65  {
66  $this->header['responsive-def'] = '<meta name="viewport" content="width=device-width, initial-scale=1">';
67  }
68 
73  public function title($t)
74  {
75  if(strlen($t)>69)
76  {
77  $t = substr($t,0,66).'...';
78  }
79  $this->header['title-def'] = '<title>'.$t.'</title>';
80  $this->oginfo['title'] = $t;
81  }
82 
87  public function description($data)
88  {
89  if(strlen($data)>159)
90  {
91  $data = substr($data,0,155).'...';
92  }
93  $this->header['description-def'] = '<meta name="description" content="'.$data.'">';
94  $this->oginfo['description'] = $data;
95  }
96 
100  public function robots()
101  {
102  $this->header['robots-def'] = '<meta name="ROBOTS" content="NOODP"><meta name="Slurp" content="NOYDIR">';
103  }
104 
109  public function owner($author)
110  {
111  $this->header['owner-def'] = '<meta name="author" content="'.$author.'">';
112  }
113 
117  public function generator()
118  {
119  $this->header['generator-def'] = '<meta name="generator" content="OpenSencillo Framework (www.opensencillo.com)">';
120  }
121 
126  public function custom($code)
127  {
128  $this->header['custom'][] = $code;
129  }
130 
136  public function script($code)
137  {
138  $this->custom('<script type="text/javascript" src="'.$code.'"></script>');
139  }
140 
145  public function css($link)
146  {
147  $this->custom('<link rel="stylesheet" href="'.$link.'">');
148  }
149 
154  public function style($link)
155  {
156  $this->css($link);
157  }
158 
163  public function save()
164  {
165  $this->seo = $this->header['doctype-def'].PHP_EOL;
166  $this->seo .= (isset($this->header['html-def-snippet'])?$this->header['html-def-snippet']:$this->header['html-def']).PHP_EOL;
167  $this->seo .= $this->header['charset-def'].PHP_EOL;
168  $this->seo .= $this->header['responsive-def'].PHP_EOL;
169  $this->seo .= $this->header['title-def'].PHP_EOL;
170  $this->seo .= $this->header['description-def'].PHP_EOL;
171  $this->generator();
172 
173  unset($this->header['html-def']);
174  unset($this->header['html-def-snippet']);
175  unset($this->header['doctype-def']);
176  unset($this->header['charset-def']);
177  unset($this->header['responsive-def']);
178  unset($this->header['title-def']);
179  unset($this->header['description-def']);
180 
181  foreach($this->header as $key => $val)
182  {
183  if(!is_array($val))
184  {
185  $this->seo .= $val.PHP_EOL;
186  $this->info['head'][] = $key;
187  }
188  }
189  foreach($this->header['custom'] as $key => $val)
190  {
191  $this->seo .= $val.PHP_EOL;
192  $this->info['head'][] = $key;
193  }
194 
195  $this->seo .= $this->body;
196  return $this->seo;
197  }
198 
204  public function lang($lang)
205  {
206  unset($this->header['html-def']);
207  $this->header['html-def']='<html lang="'.$lang.'"><head>';
208  }
209 
213  public function googleLoad()
214  {
215  $this->header['jquery-js']='<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>';
216  $this->header['jqueryui-js']='<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>';
217  }
218 
222  public function jquery()
223  {
224  self::googleLoad();
225  }
226 
231  public function socialTags($arr, $snippet=false)
232  {
233  $this->custom('<meta property="og:url" content="'.$arr['url'].'" />');
234  $this->custom('<meta property="og:type" content="'.$arr['type'].'" />');
235  $this->custom('<meta property="og:title" content="'.$this->oginfo['title'].'" />');
236  $this->custom('<meta property="og:description" content="'.$this->oginfo['description'].'" />');
237  $this->custom('<meta property="og:image" content="'.$arr['image'].'" />');
238 
239  if($snippet)
240  {
241  $this->header['html-def-snippet'] = '<html itemscope itemtype="http://schema.org/Other"><head>';
242 
243  $this->custom('<meta itemprop="name" content="'.$this->oginfo['title'].'">');
244  $this->custom('<meta itemprop="description" content="'.$this->oginfo['description'].'">');
245  $this->custom('<meta itemprop="image" content="'.$arr['image'].'">');
246  }
247  }
248 
252  public function bootstrapDefs()
253  {
254  $this->header['bootstrap-css']='<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">';
255  $this->header['jquery-js']='<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>';
256  $this->header['bootstrap-js']='<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>';
257  }
258 }
259 ?>