(merged from branches/roa. use "svn log -c <changeset> -g <module-svn-path>" for detailed commit message)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@60327 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-08-11 02:57:59 +00:00
parent 3f9c14d60c
commit 2d8434a43f
12 changed files with 65 additions and 27 deletions

View File

@ -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 {

View File

@ -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();

View File

@ -17,6 +17,7 @@ class XMLDataFormatter extends DataFormatter {
public function supportedMimeTypes() {
return array(
'text/xml',
'application/xml',
);
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -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";
}
}

View File

@ -122,7 +122,7 @@ class ComplexTableField extends TableListField {
}
function getViewer() {
return new SSViewer('ComplexTableField');
return new SSViewer($this->template);
}

View File

@ -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");

View File

@ -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)
}

View File

@ -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',
);

View File

@ -1,4 +1,4 @@
<div id="$id" class="$CSSClasses field" href="$Link">
<div id="$id" class="$CSSClasses field" href="$CurrentLink">
<div class="middleColumn">
<% include TableListField_PageControls %>
<table class="data">

View File

@ -1,5 +1,4 @@
<?php
/**
* Test the security class, including log-in form, change password form, etc
*