From 76b5adc979515557c0633a205df2696e5e766b06 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Tue, 28 Apr 2009 23:52:15 +0000 Subject: [PATCH] Merged from branches/2.3 git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@75579 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- .htaccess | 4 ++++ core/Requirements.php | 37 +++++++++++++++++++++++++++++++-- core/ViewableData.php | 2 +- core/model/DataObjectSet.php | 6 +++++- core/model/Image.php | 4 ++-- core/model/SiteTree.php | 2 ++ css/ComplexTableField_popup.css | 2 +- dev/SapphireTest.php | 1 + filesystem/File.php | 11 ++++++++-- filesystem/Folder.php | 24 ++++++++++----------- filesystem/GD.php | 4 ++-- forms/CustomRequiredFields.php | 2 +- forms/FieldSet.php | 8 +++++-- forms/InlineFormAction.php | 2 +- forms/RequiredFields.php | 2 +- forms/Validator.php | 2 +- templates/email/GenericEmail.ss | 4 ++-- tests/SQLQueryTest.php | 2 +- tests/forms/FormTest.php | 2 +- 19 files changed, 87 insertions(+), 34 deletions(-) create mode 100644 .htaccess diff --git a/.htaccess b/.htaccess new file mode 100644 index 000000000..2ba5f8c74 --- /dev/null +++ b/.htaccess @@ -0,0 +1,4 @@ + +Order deny,allow +Deny from all + \ No newline at end of file diff --git a/core/Requirements.php b/core/Requirements.php index b6ac5ea0c..35b70dc32 100644 --- a/core/Requirements.php +++ b/core/Requirements.php @@ -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; diff --git a/core/ViewableData.php b/core/ViewableData.php index 4a8b1f4b1..0509c1f89 100644 --- a/core/ViewableData.php +++ b/core/ViewableData.php @@ -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); diff --git a/core/model/DataObjectSet.php b/core/model/DataObjectSet.php index 38a92e619..85ae4119e 100644 --- a/core/model/DataObjectSet.php +++ b/core/model/DataObjectSet.php @@ -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; } diff --git a/core/model/Image.php b/core/model/Image.php index b0512209a..7b2fd8f4b 100755 --- a/core/model/Image.php +++ b/core/model/Image.php @@ -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 "\"$title\""; } } @@ -789,4 +789,4 @@ class Image_Uploader extends Controller { } } -?> \ No newline at end of file +?> diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index 80b800900..c36fd87cb 100644 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -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'); } /** diff --git a/css/ComplexTableField_popup.css b/css/ComplexTableField_popup.css index e2e071f5b..e3874cd6a 100755 --- a/css/ComplexTableField_popup.css +++ b/css/ComplexTableField_popup.css @@ -6,7 +6,7 @@ html { overflow-y: auto !important; } body { - height: auto; + height: 100%; } #ComplexTableField_Popup_DetailForm input.loading { diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 6afeca74a..fae51acbd 100644 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -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); } /** diff --git a/filesystem/File.php b/filesystem/File.php index bfbbe6e92..4ff0ea589 100755 --- a/filesystem/File.php +++ b/filesystem/File.php @@ -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 { } -?> \ No newline at end of file +?> diff --git a/filesystem/Folder.php b/filesystem/Folder.php index 1f6c4aa1b..82baae8c3 100755 --- a/filesystem/Folder.php +++ b/filesystem/Folder.php @@ -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", - "

"._t('Folder.UNUSEDFILESTITLE', 'Unused files')."

" - ), - $this->getAssetList(), - new LiteralField("UnusedThumbnails", - "
-
-

"._t('Folder.UNUSEDTHUMBNAILSTITLE', 'Unused thumbnails')."

- -
" - ) - ) - ), + new LiteralField( "UnusedAssets", "

"._t('Folder.UNUSEDFILESTITLE', 'Unused files')."

" ), + $this->getAssetList(), + new FieldGroup( + new LiteralField( "UnusedThumbnails", "

"._t('Folder.UNUSEDTHUMBNAILSTITLE', 'Unused thumbnails')."

"), + $inlineFormAction + ) + ) + ), new HiddenField("ID") ); diff --git a/filesystem/GD.php b/filesystem/GD.php index 43c0afa97..d71079c92 100755 --- a/filesystem/GD.php +++ b/filesystem/GD.php @@ -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']); diff --git a/forms/CustomRequiredFields.php b/forms/CustomRequiredFields.php index 78547f336..86a2d52c0 100755 --- a/forms/CustomRequiredFields.php +++ b/forms/CustomRequiredFields.php @@ -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" ); diff --git a/forms/FieldSet.php b/forms/FieldSet.php index 6d5e13778..350cd3dfa 100755 --- a/forms/FieldSet.php +++ b/forms/FieldSet.php @@ -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); + } + } } } diff --git a/forms/InlineFormAction.php b/forms/InlineFormAction.php index 45a9e465c..8d7dea706 100755 --- a/forms/InlineFormAction.php +++ b/forms/InlineFormAction.php @@ -60,7 +60,7 @@ class InlineFormAction_ReadOnly extends FormField { protected $readonly = true; function Field() { - return "name}\" value=\"{$this->title}\" id=\"{$this->id()}\" disabled=\"disabled\" class=\"action$this->extraClass\" />"; + return "name}\" value=\"{$this->title}\" id=\"{$this->id()}\" disabled=\"disabled\" class=\"action disabled$this->extraClass\" />"; } function Title() { diff --git a/forms/RequiredFields.php b/forms/RequiredFields.php index f87acbc45..d2c3c9b5e 100755 --- a/forms/RequiredFields.php +++ b/forms/RequiredFields.php @@ -102,7 +102,7 @@ JS; $this->validationError( $fieldName, sprintf( - _t('Form.FIELDISREQUIRED'), + _t('Form.FIELDISREQUIRED').'.', strip_tags('"' . ($formField->Title() ? $formField->Title() : $fieldName) . '"') ), "required" diff --git a/forms/Validator.php b/forms/Validator.php index 3cd447edd..c49b54a95 100755 --- a/forms/Validator.php +++ b/forms/Validator.php @@ -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() { diff --git a/templates/email/GenericEmail.ss b/templates/email/GenericEmail.ss index 0f45c4ef4..2da3240be 100644 --- a/templates/email/GenericEmail.ss +++ b/templates/email/GenericEmail.ss @@ -1,12 +1,12 @@ - + <% base_tag %>

-$Body + $Body

diff --git a/tests/SQLQueryTest.php b/tests/SQLQueryTest.php index 9090e7678..ec76b85f8 100644 --- a/tests/SQLQueryTest.php +++ b/tests/SQLQueryTest.php @@ -203,4 +203,4 @@ class SQLQueryTest_DO extends DataObject implements TestOnly { ); } -?> \ No newline at end of file +?> diff --git a/tests/forms/FormTest.php b/tests/forms/FormTest.php index 9e3160ed3..dc1b145ef 100644 --- a/tests/forms/FormTest.php +++ b/tests/forms/FormTest.php @@ -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' );