implemented title & keyword exchange

This commit is contained in:
Ulf Gebhardt 2016-05-17 17:54:35 +02:00
parent 60fb33a7ab
commit ebefaec531
4 changed files with 36 additions and 0 deletions

View File

@ -30,6 +30,25 @@ abstract class api_default extends api_system {
}
}
}
//Title
if(array_key_exists('title', $state[0])){
$html->getElementsByTagName('title')[0]->nodeValue = $state[0]['title'];}
//Meta
if(array_key_exists('meta', $state[0])){
$meta = $html->getElementsByTagName('meta');//[0]->nodeValue = $state[0]['title'];
foreach($state[0]['meta'] as $metaname=>$metavalue){
$found = false;
for ($i = 0; $i < $meta->length; $i++) {
if($meta->item($i)->getAttribute('name') == $metaname){
$found = true;
$meta->item($i)->setAttribute('content',$metavalue);}
}
if(!$found){
$node = $head->appendChild($html->createElement('meta'));
$node->setAttribute($metaname, $metavalue);}
}
}
//print_r($state);
echo $html->saveHTML();
new \SYSTEM\LOG\COUNTER("API was called sucessfully.");
die();

View File

@ -70,6 +70,17 @@ SYSTEM.prototype.handle_call_pages_page = function (html,entry,id,forced,cached,
}
return;
}
//Title
if(entry['title']){
document.title = entry['title'];}
//meta
for(var metaname in entry['meta']) {
$('meta[name='+metaname+']').attr('content', entry['meta'][metaname]);
}
for(var i=0; i < entry['css'].length; i++){
$('meta[name=keywords]').attr('content', new_keywords);
$('meta[name=description]').attr('content', new_description);
}
//load css
for(var i=0; i < entry['css'].length; i++){
this.load_css(entry['css'][i],forced);}

View File

@ -6,4 +6,6 @@ abstract class Page {
abstract public function html();
//abstract public function js();
//abstract public function css();
//abstract public function title();
//abstract public function meta();
}

View File

@ -40,6 +40,10 @@ class State {
if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'js') && \is_callable($row['php_class'].'::js')){
$row['js'] = array_merge($row['js'], \call_user_func($row['php_class'].'::js'));}
$row['js'] = count($row['js']) > 0 ? array(\SYSTEM\CACHE\cache_js::url($row['js'])) : array();
if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'title') && \is_callable($row['php_class'].'::title')){
$row['title'] = \call_user_func($row['php_class'].'::title');}
if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'meta') && \is_callable($row['php_class'].'::meta')){
$row['meta'] = \call_user_func($row['php_class'].'::meta');}
unset($row['php_class']);
$skip = false;