/** * @return string * @throws sfError404Exception */ public function executeGet() { /** @var myWebRequest $request **/ $request = $this->getRequest(); $redir = $this->getRequestParameter('redir', false); $uri = $this->getRequestParameter('uri'); if (!$uri) { $uri = "http://" . $request->getPathInfoParam('HTTP_HOST') . $request->getPathInfoParam('REQUEST_URI'); //strip trailing type $uri = preg_replace('/\\.\\w+$/U', '', $uri); //strip _dev script if it's part of the URI' $uri = preg_replace('%\\w+\\_dev.php/%', '', $uri); } $module = $this->getRequestParameter('type'); if ('unknown' == $module) { $accept = $request->getPathInfoParam('HTTP_ACCEPT'); $agent = $request->getPathInfoParam('HTTP_USER_AGENT'); //any of these will return html /*RewriteCond %{HTTP_ACCEPT} !application/rdf\+xml.*(text/html|application/xhtml\+xml) RewriteCond %{HTTP_ACCEPT} text/html [OR] RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml [OR] RewriteCond %{HTTP_USER_AGENT} ^Mozilla/.* RewriteRule ^(.*)$ rdtest.php?type=html&uri=$1 [QSA,L] */ if (!preg_match('%application/rdf\\+xml.*(text/html|application/xhtml\\+xml)%im', $accept) && (preg_match('%text/html%im', $accept) || preg_match('%application/xhtml\\+xml%im', $accept) || preg_match('%^Mozilla/.*%im', $agent) && preg_match('%\\*/\\*%im', $accept))) { $module = 'html'; } elseif (preg_match('%application/rdf\\+xml%im', $accept)) { $module = 'rdf'; } elseif (preg_match('%text/rdf+n3%im', $accept)) { $module = 'n3'; } else { $module = sfConfig::get('default_conneg_type'); } } $class = strtolower($this->getRequestParameter('class')); switch ($class) { case 'concept': switch ($module) { case 'html': /** @var Concept $concept **/ $concept = ConceptPeer::getConceptByUri($uri); $this->forward404Unless($concept); $uri = $request->getUriPrefix() . "/concept/show/id/" . $concept->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); //forward //$request->setParameter('vocabulary_id', $vocabulary->getId()); //$this->forward('concept','list'); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('type', 'api_uri'); $this->forwardIf($uri, 'rdf', 'showConcept'); break; } break; case 'concept_scheme': case 'conceptscheme': switch ($module) { case 'html': /** @var Vocabulary $vocabulary **/ $vocabulary = VocabularyPeer::retrieveByUri($uri); $this->forward404Unless($vocabulary); $uri = $request->getUriPrefix() . "/vocabulary/show/id/" . $vocabulary->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); //forward //$request->setParameter('vocabulary_id', $vocabulary->getId()); //$this->forward('concept','list'); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('type', 'api_uri'); $this->forwardIf($uri, 'rdf', 'showScheme'); break; case 'xsd': //reset the type $request->setParameter('type', 'api_uri'); $this->forwardIf($uri, 'xml', 'showScheme'); break; } break; case 'schema': /** @var Schema $schema **/ $schema = SchemaPeer::retrieveByUri($uri); $this->forward404Unless($schema); switch ($module) { case 'html': $uri = $request->getUriPrefix() . "/schema/show/id/" . $schema->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('id', $schema->getId()); $this->forwardIf($uri, 'schema', 'showRdf'); break; } break; case 'schema_property': case 'schemaproperty': /** @var SchemaProperty $property **/ $property = SchemaPropertyPeer::retrieveByUri($uri); $this->forward404Unless($property); switch ($module) { case 'html': $uri = $request->getUriPrefix() . "/schemaprop/show/id/" . $property->getId() . ".html"; //redirect $this->redirectIf($redir, $uri, 303); //return the url return $this->renderText($uri); break; case 'rdf': //redirect $this->redirectIf($redir, $uri . '.rdf', 303); //forward $request->setParameter('id', $property->getId()); $this->forwardIf($uri, 'schemaprop', 'showRdf'); break; } break; default: $this->forward404(); } return sfView::NONE; }
/** * Executes show action * */ public function executeShowScheme() { //build the complete URI $rootUri = $this->getRequest()->getUriPrefix() . '/'; $schemeUri = $rootUri . 'uri/' . $this->getRequestParameter('scheme', ''); $type = $this->getRequestParameter('type'); $ts = strtotime($this->getRequestParameter('ts')); $this->timestamp = $ts; $version = $this->getRequestParameter('version'); //$_SERVER['HTTP_ACCEPT'] = ''; //$_SERVER['HTTP_USER_AGENT'] = ''; switch ($type) { case 'xmlschema': //this URI HAS an 'id', HAS an 'rdf' suffix, and does NOT have a 'uri' action $id = $this->getRequestParameter('id'); $vocabulary = VocabularyPeer::retrieveByPK($id); $this->getContext()->getResponse()->setStatusCode(200); break; case 'html': //this URI does NOT have an 'id', HAS an 'html' suffix, and HAS a 'uri' action //redirect to the base registry using the correct id for the scheme: // http://metadataregistry.org/concept/list/vocabulary_id/16.html $vocabulary = VocabularyPeer::retrieveByUri($schemeUri); $this->forward404Unless($vocabulary); //redirect $this->getContext()->getResponse()->setStatusCode(303); $this->redirect($this->getRequest()->getUriPrefix() . '/concept/list/vocabulary_id/' . $vocabulary->getId() . '.html'); break; case 'uri': //this URI does NOT have an 'id', HAS an 'rdf' suffix, and HAS a 'uri' action //$this->getContext()->getResponse()->setStatusCode(303); $vocabulary = VocabularyPeer::retrieveByUri($schemeUri); break; case 'api_uri': //this URI does NOT have an 'id', does NOT have an 'html' suffix, and comes from the API $uri = $this->getRequestParameter('uri', ''); $vocabulary = VocabularyPeer::retrieveByUri($uri); break; default: //covers case of 'unknown' too //this URI does NOT have an 'id', does NOT have a suffix, and HAS a 'uri' action //do content negotiation if (true === strpos($_SERVER['HTTP_ACCEPT'], 'text/html') || true === strpos($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') || 0 === strpos($_SERVER['HTTP_USER_AGENT'], 'Mozilla')) { //we redirect to html $vocabulary = VocabularyPeer::retrieveByUri($schemeUri); $this->forward404Unless($vocabulary); //redirect $this->redirect($this->getRequest()->getUriPrefix() . '/concept/list/vocabulary_id/' . $vocabulary->getId() . '.html'); } else { $vocabulary = VocabularyPeer::retrieveByUri($schemeUri); } break; } $this->forward404Unless($vocabulary); $this->vocabulary = $vocabulary; //forward to the timeslice if there's a version if ($version && !$ts) { $c = new Criteria(); $c->add(VocabularyHasVersionPeer::NAME, $version); $version = VocabularyHasVersionPeer::doSelectOne($c); $this->forward404Unless($version, 'Unknown version!'); $ts = $version->getTimeslice('YmdHis'); $this->getRequest()->getParameterHolder()->set('ts', $ts); $this->forward('xml', 'showScheme'); } if (!$ts) { $this->concepts = $vocabulary->getConcepts(); } else { $this->concepts = ConceptPeer::doSelectConceptByHistoryTimestamp($vocabulary->getid(), $ts); } }