Merged from branches/2.3

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@75579 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2009-04-28 23:52:15 +00:00
parent ec9765d9f2
commit 76b5adc979
19 changed files with 87 additions and 34 deletions

4
.htaccess Normal file
View File

@ -0,0 +1,4 @@
<Files cli-script.php>
Order deny,allow
Deny from all
</Files>

View File

@ -7,12 +7,14 @@
* @subpackage view
*/
class Requirements {
/**
* Enable combining of css/javascript files.
*
* @var boolean
*/
private static $combined_files_enabled = true;
public static function set_combined_files_enabled($enable) {
self::$combined_files_enabled = (bool) $enable;
}
@ -21,6 +23,34 @@ class Requirements {
return self::$combined_files_enabled;
}
/**
* Do we want requirements to suffix onto the requirement link
* tags for caching or is it disabled. Getter / Setter available
* through {@link Requirements::set_suffix_requirements()}
*
* @var bool
*/
private static $suffix_requirements = true;
/**
* Set whether we want to suffix requirements with the time /
* location on to the requirements
*
* @param bool
*/
public static function set_suffix_requirements($var) {
self::$suffix_requirements = $var;
}
/**
* Return whether we want to suffix requirements
*
* @return bool
*/
public static function get_suffix_requirements() {
return self::$suffix_requirements;
}
/**
* Instance of requirements for storage
*
@ -319,7 +349,7 @@ class Requirements_Backend {
* @var array $disabled
*/
protected $disabled = array();
/**
* The filepaths (relative to webroot) or
* uniquenessIDs of any included requirements
@ -668,7 +698,10 @@ class Requirements_Backend {
return $fileOrUrl;
} elseif(Director::fileExists($fileOrUrl)) {
$prefix = Director::absoluteBaseURL();
$mtimesuffix = "?m=" . filemtime(Director::baseFolder() . '/' . $fileOrUrl);
$mtimesuffix = "";
if(Requirements::get_suffix_requirements()) {
$mtimesuffix = "?m=" . filemtime(Director::baseFolder() . '/' . $fileOrUrl);
}
return "{$prefix}{$fileOrUrl}{$mtimesuffix}";
} else {
return false;

View File

@ -123,7 +123,7 @@ class ViewableData extends Object implements IteratorAggregate {
* @param mixed $val The field value.
*/
public function __set($field, $val) {
if(method_exists($this, $funcName = "set$field")) {
if($this->hasMethod($funcName = "set$field")) {
return $this->$funcName($val);
} else {
$this->setField($field, $val);

View File

@ -141,9 +141,10 @@ class DataObjectSet extends ViewableData implements IteratorAggregate {
* @param string $index The field you wish to use as a key for the array
* @param string $titleField The field or method you wish to use to get values for the map
* @param string $emptyString String for no option selected
* @param bool $sort If you want to sort the map based on $titleField
* @return array
*/
public function toDropDownMap($index = "ID",$titleField = "Title",$emptyString = null){
public function toDropDownMap($index = "ID",$titleField = "Title",$emptyString = null, $sort = false){
$map = array();
foreach($this->items as $item) {
$map[$item->$index] = $item->$titleField;
@ -151,6 +152,9 @@ class DataObjectSet extends ViewableData implements IteratorAggregate {
if($emptyString) {
$map = array("0"=>"$emptyString") + $map;
}
if($sort) {
asort($map);
}
return $map;
}

View File

@ -100,7 +100,7 @@ class Image extends File {
function getTag() {
if(file_exists("../" . $this->Filename)) {
$url = $this->URL();
$title = $this->Title;
$title = ($this->Title) ? $this->Title : $this->Filename;
return "<img src=\"$url\" alt=\"$title\" />";
}
}
@ -789,4 +789,4 @@ class Image_Uploader extends Controller {
}
}
?>
?>

View File

@ -1469,6 +1469,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$clone = DataObject::get_by_id("SiteTree", $this->ID);
$clone->Status = "Published";
$clone->writeWithoutVersion();
$this->extend('onAfterRevertToLive');
}
/**

View File

@ -6,7 +6,7 @@ html {
overflow-y: auto !important;
}
body {
height: auto;
height: 100%;
}
#ComplexTableField_Popup_DetailForm input.loading {

View File

@ -81,6 +81,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
$this->originalMailer = Email::mailer();
$this->mailer = new TestMailer();
Email::set_mailer($this->mailer);
Email::send_all_emails_to(null);
}
/**

View File

@ -227,6 +227,13 @@ class File extends DataObject {
return $upload->isError();
}
/**
* Should be called after the file was uploaded
*/
function onAfterUpload() {
$this->extend('onAfterUpload');
}
/**
* Delete the database record (recursively for folders) without touching the filesystem
@ -431,7 +438,7 @@ class File extends DataObject {
if($this->ParentID) {
$p = DataObject::get_one('Folder', "\"ID\"={$this->ParentID}");
if($p->ID) return $p->getRelativePath() . $this->getField("Name");
if($p && $p->ID) return $p->getRelativePath() . $this->getField("Name");
else return ASSETS_DIR . "/" . $this->getField("Name");
} else if($this->getField("Name")) {
@ -605,4 +612,4 @@ class File extends DataObject {
}
?>
?>

View File

@ -330,6 +330,9 @@ class Folder extends File {
$deleteButton = new HiddenField('deletemarked');
}
$inlineFormAction = new InlineFormAction("delete_unused_thumbnails", _t('Folder.DELETEUNUSEDTHUMBNAILS', 'Delete unused thumbnails'));
$inlineFormAction->includeDefaultJS(false) ;
$fields = new FieldSet(
new HiddenField("Title"),
new TabSet("Root",
@ -352,19 +355,14 @@ class Folder extends File {
)
),
new Tab("UnusedFiles", _t('Folder.UNUSEDFILESTAB', "Unused files"),
new LiteralField("UnusedAssets",
"<div id=\"UnusedAssets\"><h2>"._t('Folder.UNUSEDFILESTITLE', 'Unused files')."</h2>"
),
$this->getAssetList(),
new LiteralField("UnusedThumbnails",
"</div>
<div id=\"UnusedThumbnails\">
<h2>"._t('Folder.UNUSEDTHUMBNAILSTITLE', 'Unused thumbnails')."</h2>
<button class=\"action\">"._t('Folder.DELETEUNUSEDTHUMBNAILS', 'Delete unused thumbnails')."</button>
</div>"
)
)
),
new LiteralField( "UnusedAssets", "<h2>"._t('Folder.UNUSEDFILESTITLE', 'Unused files')."</h2>" ),
$this->getAssetList(),
new FieldGroup(
new LiteralField( "UnusedThumbnails", "<h2>"._t('Folder.UNUSEDTHUMBNAILSTITLE', 'Unused thumbnails')."</h2>"),
$inlineFormAction
)
)
),
new HiddenField("ID")
);

View File

@ -352,8 +352,8 @@ class GD extends Object {
$rr = ($rv == 0) ? 0 : 1/($rt/$rv);
$br = ($bv == 0) ? 0 : 1/($rt/$bv);
$gr = ($gv == 0) ? 0 : 1/($rt/$gv);
for($dy = 0; $dy <= $height; $dy++) {
for($dx = 0; $dx <= $width; $dx++) {
for($dy = 0; $dy < $height; $dy++) {
for($dx = 0; $dx < $width; $dx++) {
$pxrgb = imagecolorat($this->gd, $dx, $dy);
$heightgb = ImageColorsforIndex($this->gd, $pxrgb);
$newcol = ($rr*$heightgb['red']) + ($br*$heightgb['blue']) + ($gr*$heightgb['green']);

View File

@ -65,7 +65,7 @@ class CustomRequiredFields extends RequiredFields{
if(!$data[$fieldName] || preg_match('/^\s*$/', $data[$fieldName])) {
$this->validationError(
$fieldName,
sprintf(_t('Form.FIELDISREQUIRED', "%s is required"),
sprintf(_t('Form.FIELDISREQUIRED', "%s is required."),
$formField->Title()),
"required"
);

View File

@ -32,8 +32,12 @@ class FieldSet extends DataObjectSet {
$itemsArr = (!is_array($items) || count(func_get_args()) > 1) ? func_get_args() : $items;
parent::__construct($itemsArr);
foreach($this->items as $item) {
$item->setContainerFieldSet($this);
if(isset($this->items)&&count($this->items)){
foreach($this->items as $item) {
if(isset($item)&&is_a($item,"FormField")){
$item->setContainerFieldSet($this);
}
}
}
}

View File

@ -60,7 +60,7 @@ class InlineFormAction_ReadOnly extends FormField {
protected $readonly = true;
function Field() {
return "<input type=\"submit\" name=\"action_{$this->name}\" value=\"{$this->title}\" id=\"{$this->id()}\" disabled=\"disabled\" class=\"action$this->extraClass\" />";
return "<input type=\"submit\" name=\"action_{$this->name}\" value=\"{$this->title}\" id=\"{$this->id()}\" disabled=\"disabled\" class=\"action disabled$this->extraClass\" />";
}
function Title() {

View File

@ -102,7 +102,7 @@ JS;
$this->validationError(
$fieldName,
sprintf(
_t('Form.FIELDISREQUIRED'),
_t('Form.FIELDISREQUIRED').'.',
strip_tags('"' . ($formField->Title() ? $formField->Title() : $fieldName) . '"')
),
"required"

View File

@ -167,7 +167,7 @@ abstract class Validator extends Object {
}
function requireField($fieldName, $data) {
if(!$data[$fieldName]) $this->validationError($fieldName, "$fieldName is required", "required");
if(!$data[$fieldName]) $this->validationError($fieldName, "$fieldName is required.", "required");
}
function includeJavascriptValidation() {

View File

@ -1,12 +1,12 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<% base_tag %>
</head>
<body>
<p class="body">
$Body
$Body
</p>
</body>

View File

@ -203,4 +203,4 @@ class SQLQueryTest_DO extends DataObject implements TestOnly {
);
}
?>
?>

View File

@ -207,7 +207,7 @@ class FormTest extends FunctionalTest {
$this->assertPartialMatchBySelector(
'#SomeRequiredField span.required',
array(
sprintf(_t('Form.FIELDISREQUIRED'),'"SomeRequiredField"')
sprintf(_t('Form.FIELDISREQUIRED').'.','"SomeRequiredField"')
),
'Required fields show a notification on field when left blank'
);