From 5ebb40d49d315440680f19430f3d50790736ba0b Mon Sep 17 00:00:00 2001 From: Naeltard Date: Thu, 29 Jan 2015 01:09:21 +0100 Subject: [PATCH] ajax crawling scheme prototype --- api/api.php | 4 ++-- api/api_default.php | 14 +++++++++++++- dbd/sql/mysql/data/system_api_default.sql | 2 ++ files/sys/system.js | 6 +++--- page/State.php | 8 ++++---- 5 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 dbd/sql/mysql/data/system_api_default.sql diff --git a/api/api.php b/api/api.php index 371b492..612c370 100644 --- a/api/api.php +++ b/api/api.php @@ -29,7 +29,7 @@ class api { //Commands $commands = self::do_commands($params, $tree); - if(count($commands) <= 0){ + if(count($commands) <= 0){ return self::do_default($default, $apiclassname);} //throws //Parameters @@ -85,7 +85,7 @@ class api { if( !method_exists($verifyclassname, $item[\SYSTEM\DBD\system_api::FIELD_VERIFY]) || !call_user_func(array($verifyclassname,$item[\SYSTEM\DBD\system_api::FIELD_VERIFY]),$params[$item[\SYSTEM\DBD\system_api::FIELD_NAME]])){ throw new \SYSTEM\LOG\ERROR('Parameter type missmacht or Missing Verifier. Param: '.$item[\SYSTEM\DBD\system_api::FIELD_NAME].' Verifier: '.$item[\SYSTEM\DBD\system_api::FIELD_VERIFY]);} - + //throw new \SYSTEM\LOG\ERROR("yo ".$call_funcname.' '.$apiclassname); \call_user_func_array(array($apiclassname,$call_funcname),array($params[$item[\SYSTEM\DBD\system_api::FIELD_NAME]])); } } diff --git a/api/api_default.php b/api/api_default.php index fb02279..ecb96f1 100644 --- a/api/api_default.php +++ b/api/api_default.php @@ -3,6 +3,18 @@ namespace SYSTEM\API; abstract class api_default { + //https://developers.google.com/webmasters/ajax-crawling/docs/getting-started + public static function static__escaped_fragment_($_escaped_fragment_){ + $state = \SYSTEM\PAGE\State::get(1, $_escaped_fragment_,false); + $result = ''; + foreach($state as $row){ + parse_str(\parse_url($row['url'],PHP_URL_QUERY), $params); + $result .= \SYSTEM\API\api::run('\SYSTEM\API\verify', 'page_neopolimatrix', $params, 1, true, true)->html(); + } + echo $result;//echo (new \default_page())->html(); + die(); + } + public static function default_page(){ - throw new RuntimeException("Unimplemented");} + throw new \RuntimeException("Unimplemented");} } \ No newline at end of file diff --git a/dbd/sql/mysql/data/system_api_default.sql b/dbd/sql/mysql/data/system_api_default.sql new file mode 100644 index 0000000..d3989c6 --- /dev/null +++ b/dbd/sql/mysql/data/system_api_default.sql @@ -0,0 +1,2 @@ +INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (0, 1, 4, -1, NULL, '_escaped_fragment_', 'STRING'); +INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (1, 1, 0, -1, NULL, 'page', NULL); diff --git a/files/sys/system.js b/files/sys/system.js index d4499e9..ee22a69 100644 --- a/files/sys/system.js +++ b/files/sys/system.js @@ -22,7 +22,7 @@ SYSTEM.prototype.handle_call_pages = function (data,id) { if(data['status']){ system.log(system.LOG_INFO,'load pages: endpoint '+system.endpoint+':group '+system.group+':state '+id+' - success'); if(id !== system.cur_state()){ - window.history.pushState(null, "", '#'+id);} + window.history.pushState(null, "", '#!'+id);} data['result'].forEach(function(entry) { //load pages $.ajax({ @@ -115,8 +115,8 @@ SYSTEM.prototype.load_css = function loadCSS(csssrc) { //what? SYSTEM.prototype.cur_state = function() { var pathName = window.location.href; - if (pathName.indexOf('#') != -1) { - return pathName.split('#').pop();} + if (pathName.indexOf('#!') != -1) { + return pathName.split('#!').pop();} return ''; }; diff --git a/page/State.php b/page/State.php index 9888db2..b55ef79 100644 --- a/page/State.php +++ b/page/State.php @@ -1,7 +1,7 @@ next()){ $row['url'] = \SYSTEM\PAGE\replace::replace($row['url'], $vars); $row['css'] = $row['js'] = array(); - if(/*\is_callable($row['php_class']) &&*/ \class_exists($row['php_class']) && \method_exists($row['php_class'], 'css') && \is_callable($row['php_class'].'::css')){ + if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'css') && \is_callable($row['php_class'].'::css')){ $row['css'] = array_merge($row['css'], call_user_func($row['php_class'].'::css'));} - if(/*\is_callable($row['php_class']) &&*/ \class_exists($row['php_class']) && \method_exists($row['php_class'], 'js') && \is_callable($row['php_class'].'::js')){ + 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'));} $result[] = $row;} - return \SYSTEM\LOG\JsonResult::toString($result);} + return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($result) : $result;} } \ No newline at end of file