diff --git a/api/api_default.php b/api/api_default.php index dc8bb14..b5b1e81 100644 --- a/api/api_default.php +++ b/api/api_default.php @@ -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(); diff --git a/lib/system/lib/system.js b/lib/system/lib/system.js index 845a391..dadd224 100644 --- a/lib/system/lib/system.js +++ b/lib/system/lib/system.js @@ -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);} diff --git a/page/Page.php b/page/Page.php index 509269e..ed1712d 100644 --- a/page/Page.php +++ b/page/Page.php @@ -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(); } \ No newline at end of file diff --git a/page/State.php b/page/State.php index 7c6aa50..23314a8 100644 --- a/page/State.php +++ b/page/State.php @@ -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;