Created
October 9, 2009 01:22
-
-
Save sminnee/205609 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: modules/sapphire/branches/airnz/iteration3/core/model/SiteTree.php | |
=================================================================== | |
--- modules/sapphire/branches/airnz/iteration2/core/model/SiteTree.php (revision 85655) | |
+++ modules/sapphire/branches/airnz/iteration3/core/model/SiteTree.php (revision 88403) | |
@@ -93,29 +93,27 @@ | |
static $has_many = array( | |
"Comments" => "PageComment" | |
); | |
static $many_many = array( | |
"LinkTracking" => "SiteTree", | |
"ImageTracking" => "File", | |
"ViewerGroups" => "Group", | |
"EditorGroups" => "Group", | |
- "UsersCurrentlyEditing" => "Member", | |
); | |
static $belongs_many_many = array( | |
"BackLinkTracking" => "SiteTree" | |
); | |
static $many_many_extraFields = array( | |
- "UsersCurrentlyEditing" => array("LastPing" => "SSDatetime"), | |
"LinkTracking" => array("FieldName" => "Varchar"), | |
"ImageTracking" => array("FieldName" => "Varchar") | |
); | |
static $casting = array( | |
"Breadcrumbs" => "HTMLText", | |
"LastEdited" => "SSDatetime", | |
"Created" => "SSDatetime", | |
); | |
@@ -563,20 +561,23 @@ | |
/** | |
* This function should return true if the current user can add children | |
* to this page. It can be overloaded to customise the security model for an | |
* application. | |
* | |
* Returns true if the member is allowed to do the given action. | |
* | |
* @uses DataObjectDecorator->can() | |
* | |
+ * If a page is set to inherit, but has no parent, it inherits from | |
+ * {@link SiteConfig} | |
+ * | |
* @param string $perm The permission to be checked, such as 'View'. | |
* @param Member $member The member whose permissions need checking. | |
* Defaults to the currently logged in user. | |
* | |
* @return boolean True if the the member is allowed to do the given | |
* action. | |
* | |
* @todo Check we get a endless recursion if we use parent::can() | |
*/ | |
function can($perm, $member = null) { | |
@@ -957,21 +958,21 @@ | |
// Set all the relevant items in $result to true | |
$result = array_fill_keys($groupedByParent[$parentID], true) + $result; | |
} | |
} | |
} | |
} | |
$combinedStageResult = $combinedStageResult + $result; | |
} | |
- return $combinedStageResult; | |
+ return isset($combinedStageResult) ? $combinedStageResult : array(); | |
/* | |
// check for empty spec | |
if(!$this->CanEditType || $this->CanEditType == 'Anyone') return true; | |
// check for inherit | |
if($this->CanEditType == 'Inherit') { | |
if($this->ParentID) return $this->Parent()->canEdit($member); | |
else return ($member && Permission::checkMember($member, 'CMS_ACCESS_CMSMain')); | |
@@ -1250,41 +1251,48 @@ | |
$this->HasBrokenFile = false; | |
if($links) foreach($links as $link) { | |
if(preg_match('/^([A-Za-z0-9_-]+)\/?(#.*)?$/', $link, $parts)) { | |
$candidatePage = DataObject::get_one("SiteTree", "\"URLSegment\" = '" . urldecode( $parts[1] ). "'", false); | |
if($candidatePage) { | |
$linkedPages[] = $candidatePage->ID; | |
} else { | |
$this->HasBrokenLink = true; | |
} | |
+ } else if(substr($link,0,7) == 'assets/') { | |
+ $candidateFile = File::find(Convert::raw2sql(urldecode($link))); | |
+ if($candidateFile) { | |
+ $linkedFiles[] = $candidateFile->ID; | |
+ } else { | |
+ $this->HasBrokenLink = true; | |
+ } | |
} else if($link == '' || $link[0] == '/') { | |
$this->HasBrokenLink = true; | |
- } else if($candidateFile = DataObject::get_one("File", "\"Filename\" = '" . Convert::raw2sql(urldecode($link)) . "'", false)) { | |
- $linkedFiles[] = $candidateFile->ID; | |
} | |
} | |
$images = HTTP::getImagesIn($this->Content); | |
if($images) { | |
foreach($images as $image) { | |
$image = Director::makeRelative($image); | |
if(substr($image,0,7) == 'assets/') { | |
- $candidateImage = DataObject::get_one("File", "\"Filename\" = '$image'"); | |
+ $candidateImage = File::find($image); | |
if($candidateImage) $linkedFiles[] = $candidateImage->ID; | |
else $this->HasBrokenFile = true; | |
} | |
} | |
} | |
$this->LinkTracking()->setByIDList($linkedPages); | |
$this->ImageTracking()->setByIDList($linkedFiles); | |
+ | |
+ $this->extend('augmentSyncLinkTracking'); | |
} | |
function onAfterWrite() { | |
// Need to flush cache to avoid outdated versionnumber references | |
$this->flushCache(); | |
// Update any virtual pages that might need updating | |
$linkedPages = DataObject::get("VirtualPage", "CopyContentFromID = $this->ID"); | |
if($linkedPages) foreach($linkedPages as $page) { | |
$page->copyFrom($page->CopyContentFrom()); | |
@@ -1451,47 +1459,47 @@ | |
$backLinksNote = ''; | |
$backLinksTable = new LiteralField('BackLinksNote', '<p>' . _t('NOBACKLINKEDPAGES', 'There are no pages linked to this page.') . '</p>'); | |
// Create a table for showing pages linked to this one | |
if($this->BackLinkTracking() && $this->BackLinkTracking()->Count() > 0) { | |
$backLinksNote = new LiteralField('BackLinksNote', '<p>' . _t('SiteTree.PAGESLINKING', 'The following pages link to this page:') . '</p>'); | |
$backLinksTable = new TableListField( | |
'BackLinkTracking', | |
'SiteTree', | |
array( | |
- 'Title' => 'Title' | |
+ 'Title' => 'Title', | |
+ 'AbsoluteLink' => 'URL' | |
), | |
'"ChildID" = ' . $this->ID, | |
'', | |
'LEFT JOIN "SiteTree_LinkTracking" ON "SiteTree"."ID" = "SiteTree_LinkTracking"."SiteTreeID"' | |
); | |
$backLinksTable->setFieldFormatting(array( | |
- 'Title' => '<a href=\"admin/show/$ID\">$Title</a>' | |
+ 'Title' => '<a href=\"admin/show/$ID\">$Title</a>', | |
+ 'AbsoluteLink' => '<a href=\"$value\">$value</a>', | |
)); | |
$backLinksTable->setPermissions(array( | |
'show', | |
'export' | |
)); | |
} | |
// Lay out the fields | |
$fields = new FieldSet( | |
// Add a field with a bit of metadata for concurrent editing. The fact that we're using | |
// non-standard attributes does not really matter, all modern UA's just ignore em. | |
- new LiteralField("SiteTree_Alert", '<div deletedfromstage="'.((int) $this->getIsDeletedFromStage()).'" id="SiteTree_Alert"></div>'), | |
new TabSet("Root", | |
$tabContent = new TabSet('Content', | |
$tabMain = new Tab('Main', | |
new TextField("Title", $this->fieldLabel('Title')), | |
new TextField("MenuTitle", $this->fieldLabel('MenuTitle')), | |
- new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", PR_MEDIUM, 'HTML editor title')), | |
- new HiddenField("Version", "Version", $this->Version) | |
+ new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", PR_MEDIUM, 'HTML editor title')) | |
), | |
$tabMeta = new Tab('Metadata', | |
new FieldGroup(_t('SiteTree.URL', "URL"), | |
new LabelField('BaseUrlLabel',Director::absoluteBaseURL()), | |
new UniqueRestrictedTextField("URLSegment", | |
"URLSegment", | |
"SiteTree", | |
_t('SiteTree.VALIDATIONURLSEGMENT1', "Another page is using that URL. URL must be unique for each page"), | |
"[^A-Za-z0-9-]+", | |
"-", | |
@@ -1576,23 +1584,32 @@ | |
$viewersOptionsField->setSource($viewersOptionsSource); | |
$editorsOptionsSource = array(); | |
if($this->Parent()->ID || $this->CanEditType == 'Inherit') $editorsOptionsSource["Inherit"] = _t('SiteTree.INHERIT', "Inherit from parent page"); | |
$editorsOptionsSource["LoggedInUsers"] = _t('SiteTree.EDITANYONE', "Anyone who can log-in to the CMS"); | |
$editorsOptionsSource["OnlyTheseUsers"] = _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)"); | |
$editorsOptionsField->setSource($editorsOptionsSource); | |
if(!Permission::check('SITETREE_GRANT_ACCESS')) { | |
$fields->makeFieldReadonly($viewersOptionsField); | |
- $fields->makeFieldReadonly($viewerGroupsField); | |
+ if($this->CanViewType == 'OnlyTheseUsers') { | |
+ $fields->makeFieldReadonly($viewerGroupsField); | |
+ } else { | |
+ $fields->removeByName('ViewerGroups'); | |
+ } | |
+ | |
$fields->makeFieldReadonly($editorsOptionsField); | |
- $fields->makeFieldReadonly($editorGroupsField); | |
+ if($this->CanEditType == 'OnlyTheseUsers') { | |
+ $fields->makeFieldReadonly($editorGroupsField); | |
+ } else { | |
+ $fields->removeByName('EditorGroups'); | |
+ } | |
} | |
$tabContent->setTitle(_t('SiteTree.TABCONTENT', "Content")); | |
$tabMain->setTitle(_t('SiteTree.TABMAIN', "Main")); | |
$tabMeta->setTitle(_t('SiteTree.TABMETA', "Metadata")); | |
$tabBehaviour->setTitle(_t('SiteTree.TABBEHAVIOUR', "Behaviour")); | |
$tabReports->setTitle(_t('SiteTree.TABREPORTS', "Reports")); | |
$tabAccess->setTitle(_t('SiteTree.TABACCESS', "Access")); | |
$tabBacklinks->setTitle(_t('SiteTree.TABBACKLINKS', "BackLinks")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment