From 2d8434a43fd8be2d250cbafccfe9c021f894f2fd Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 11 Aug 2008 02:57:59 +0000 Subject: [PATCH] (merged from branches/roa. use "svn log -c -g " for detailed commit message) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60327 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- api/RestfulServer.php | 3 ++- api/RestfulService.php | 21 +++++++++++---------- api/XMLDataFormatter.php | 1 + core/control/Controller.php | 7 ++++++- core/control/HTTPRequest.php | 16 ++++++++++++++++ core/model/SQLQuery.php | 6 +++--- forms/ComplexTableField.php | 2 +- forms/TableListField.php | 20 +++++++++++++++++--- javascript/TableListField.js | 7 ++++--- security/Member.php | 6 +++--- templates/ComplexTableField.ss | 2 +- tests/security/SecurityTest.php | 1 - 12 files changed, 65 insertions(+), 27 deletions(-) diff --git a/api/RestfulServer.php b/api/RestfulServer.php index bb8004dc6..63ad99b16 100644 --- a/api/RestfulServer.php +++ b/api/RestfulServer.php @@ -225,12 +225,13 @@ class RestfulServer extends Controller { $extension = $this->request->getExtension(); $contentType = $this->request->getHeader('Content-Type'); $accept = $this->request->getHeader('Accept'); + $mimetypes = $this->request->getAcceptMimetypes(); // get formatter if(!empty($extension)) { $formatter = DataFormatter::for_extension($extension); }elseif($includeAcceptHeader && !empty($accept) && $accept != '*/*') { - $formatter = DataFormatter::for_mimetypes(explode(',',$accept)); + $formatter = DataFormatter::for_mimetypes($mimetypes); } elseif(!empty($contentType)) { $formatter = DataFormatter::for_mimetype($contentType); } else { diff --git a/api/RestfulService.php b/api/RestfulService.php index e38f7dc56..322d19d32 100644 --- a/api/RestfulService.php +++ b/api/RestfulService.php @@ -58,7 +58,7 @@ class RestfulService extends ViewableData { * Connects to the RESTful service and gets its response. * @deprecated Use {@link request()} instead. */ - function connect($subURL = ""){ + public function connect($subURL = ""){ // url for the request $url = $this->constructURL() . $subURL; @@ -148,7 +148,7 @@ class RestfulService extends ViewableData { * * This is a replacement of {@link connect()}. */ - function request($subURL, $method = "GET", $data = null, $headers = null) { + public function request($subURL, $method = "GET", $data = null, $headers = null) { $url = $this->baseURL . $subURL; //url for the request $method = strtoupper($method); @@ -218,7 +218,7 @@ class RestfulService extends ViewableData { * @param string $element The element we need to extract the attributes. */ - function getAttributes($xml, $collection=NULL, $element=NULL){ + public function getAttributes($xml, $collection=NULL, $element=NULL){ $xml = new SimpleXMLElement($xml); $output = new DataObjectSet(); @@ -249,21 +249,22 @@ class RestfulService extends ViewableData { * @param string $attr The name of the attribute */ - function getAttribute($xml, $collection=NULL, $element=NULL, $attr){ - $xml = new SimpleXMLElement($xml); - $attr_value = ""; + public function getAttribute($xml, $collection=NULL, $element=NULL, $attr){ + $xml = new SimpleXMLElement($xml); + $attr_value = ""; - if($collection) + if($collection) $childElements = $xml->{$collection}; if($element) $childElements = $xml->{$collection}->{$element}; - + if($childElements) $attr_value = (string) $childElements[$attr]; - + return Convert::raw2xml($attr_value); } + /** * Gets set of node values as an array. @@ -273,7 +274,7 @@ class RestfulService extends ViewableData { * @param string $element The element we need to extract the node values. */ - function getValues($xml, $collection=NULL, $element=NULL){ + public function getValues($xml, $collection=NULL, $element=NULL){ $xml = new SimpleXMLElement($xml); $output = new DataObjectSet(); diff --git a/api/XMLDataFormatter.php b/api/XMLDataFormatter.php index 89b45e1ac..6dfcdc4df 100644 --- a/api/XMLDataFormatter.php +++ b/api/XMLDataFormatter.php @@ -17,6 +17,7 @@ class XMLDataFormatter extends DataFormatter { public function supportedMimeTypes() { return array( 'text/xml', + 'application/xml', ); } diff --git a/core/control/Controller.php b/core/control/Controller.php index 9238bbc34..b7e068644 100644 --- a/core/control/Controller.php +++ b/core/control/Controller.php @@ -69,10 +69,15 @@ class Controller extends RequestHandlingData { $body = parent::handleRequest($request); if($body instanceof HTTPResponse) { + if(isset($_REQUEST['debug_request'])) Debug::message("Request handler returned HTTPResponse object to $this->class controller; returning it without modification."); $this->response = $body; } else { - if(is_object($body)) $body = $body->getViewer($request->latestParam('Action'))->process($body); + if(is_object($body)) { + if(isset($_REQUEST['debug_request'])) Debug::message("Request handler $body->class object to $this->class controller;, rendering with template returned by $body->class::getViewer()"); + $body = $body->getViewer($request->latestParam('Action'))->process($body); + } + $this->response->setBody($body); } diff --git a/core/control/HTTPRequest.php b/core/control/HTTPRequest.php index 5315ab57c..eb74e2457 100644 --- a/core/control/HTTPRequest.php +++ b/core/control/HTTPRequest.php @@ -353,4 +353,20 @@ class HTTPRequest extends Object implements ArrayAccess { return $_SERVER['REMOTE_ADDR']; } } + + /** + * Returns all mimetypes from the HTTP "Accept" header + * as an array. + * + * @param boolean $includeQuality Don't strip away optional "quality indicators", e.g. "application/xml;q=0.9" (Default: false) + * @return array + */ + function getAcceptMimetypes($includeQuality = false) { + $mimetypes = array(); + $mimetypesWithQuality = explode(',',$this->getHeader('Accept')); + foreach($mimetypesWithQuality as $mimetypeWithQuality) { + $mimetypes[] = ($includeQuality) ? $mimetypeWithQuality : preg_replace('/;.*/', '', $mimetypeWithQuality); + } + return $mimetypes; + } } \ No newline at end of file diff --git a/core/model/SQLQuery.php b/core/model/SQLQuery.php index 1f0d54b28..bfd3120f4 100755 --- a/core/model/SQLQuery.php +++ b/core/model/SQLQuery.php @@ -235,13 +235,13 @@ class SQLQuery extends Object { foreach($lumpedSortParts as $i => $sortPart) { $sortPart = trim($sortPart); if(substr(strtolower($sortPart),-5) == ' desc') { - $select[] = substr($sortPart,0,-5) . " AS _SortColumn{$i}"; + $this->select[] = substr($sortPart,0,-5) . " AS _SortColumn{$i}"; $newSorts[] = "_SortColumn{$i} DESC"; } else if(substr(strtolower($sortPart),-4) == ' asc') { - $select[] = substr($sortPart,0,-4) . " AS _SortColumn{$i}"; + $this->select[] = substr($sortPart,0,-4) . " AS _SortColumn{$i}"; $newSorts[] = "_SortColumn{$i} ASC"; } else { - $select[] = "$sortPart AS _SortColumn{$i}"; + $this->select[] = "$sortPart AS _SortColumn{$i}"; $newSorts[] = "_SortColumn{$i} ASC"; } } diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php index a62de175d..da913ecfd 100755 --- a/forms/ComplexTableField.php +++ b/forms/ComplexTableField.php @@ -122,7 +122,7 @@ class ComplexTableField extends TableListField { } function getViewer() { - return new SSViewer('ComplexTableField'); + return new SSViewer($this->template); } diff --git a/forms/TableListField.php b/forms/TableListField.php index c3fa1c2c8..045b55b0f 100755 --- a/forms/TableListField.php +++ b/forms/TableListField.php @@ -982,7 +982,20 @@ JS function setTemplate($template) { $this->template = $template; } + + function CurrentLink() { + $link = $this->Link(); + + if(isset($_REQUEST['ctf'][$this->Name()]['start']) && is_numeric($_REQUEST['ctf'][$this->Name()]['start'])) { + $start = ($_REQUEST['ctf'][$this->Name()]['start'] < 0) ? 0 : $_REQUEST['ctf'][$this->Name()]['start']; + $link .= "/?ctf[{$this->Name()}][start]={$start}"; + } + if($this->extraLinkParams) $link .= "&" . http_build_query($this->extraLinkParams); + + return $link; + } + function BaseLink() { user_error("TableListField::BaseLink() deprecated, use Link() instead", E_USER_NOTICE); return $this->Link(); @@ -1130,14 +1143,15 @@ class TableListField_Item extends ViewableData { function Can($mode) { return $this->parent->Can($mode); } + + function Link() { + return Controller::join_links($this->parent->Link() . "item/" . $this->item->ID); + } function BaseLink() { user_error("TableListField_Item::BaseLink() deprecated, use Link() instead", E_USER_NOTICE); return $this->Link() . '/ajax_refresh'; } - function Link() { - return Controller::join_links($this->parent->Link() . "item/" . $this->item->ID); - } function DeleteLink() { return Controller::join_links($this->Link(), "delete"); diff --git a/javascript/TableListField.js b/javascript/TableListField.js index cbf42b6b2..5e03a51e4 100755 --- a/javascript/TableListField.js +++ b/javascript/TableListField.js @@ -126,12 +126,13 @@ TableListField.prototype = { } else { var el = $(this.id); } - new Ajax.Updater( - $(this.id), + + new Ajax.Request( el.getAttribute('href'), { postBody: 'update=1', - onComplete: function() { + onComplete: function(response) { + Element.replace(this.id, response.responseText) Behaviour.apply($(this.id)) }.bind(this) } diff --git a/security/Member.php b/security/Member.php index bb0e95734..9f31c2f9a 100644 --- a/security/Member.php +++ b/security/Member.php @@ -61,9 +61,9 @@ class Member extends DataObject { * (LIKE, FULLTEXT) and default FormFields to construct a searchform. */ static $searchable_fields = array( - 'FirstName' => true, - 'Surname' => true, - 'Email' => true, + 'FirstName', + 'Surname', + 'Email', ); diff --git a/templates/ComplexTableField.ss b/templates/ComplexTableField.ss index 27e0e0ef4..edcc97865 100755 --- a/templates/ComplexTableField.ss +++ b/templates/ComplexTableField.ss @@ -1,4 +1,4 @@ -
+
<% include TableListField_PageControls %> diff --git a/tests/security/SecurityTest.php b/tests/security/SecurityTest.php index 295bb4ceb..9cadab1cf 100644 --- a/tests/security/SecurityTest.php +++ b/tests/security/SecurityTest.php @@ -1,5 +1,4 @@