Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yml lang files #99

Merged
merged 9 commits into from Apr 15, 2012
4 changes: 2 additions & 2 deletions code/controllers/AssetAdmin.php
Expand Up @@ -290,8 +290,8 @@ public function getSearchContext() {
'image' => _t('AssetAdmin.AppCategoryImage', 'Image'),
'audio' => _t('AssetAdmin.AppCategoryAudio', 'Audio'),
'mov' => _t('AssetAdmin.AppCategoryVideo', 'Video'),
'flash' => _t('AssetAdmin.AppCategoryFlash', 'Flash', PR_MEDIUM, 'The fileformat'),
'zip' => _t('AssetAdmin.AppCategoryArchive', 'Archive', PR_MEDIUM, 'A collection of files'),
'flash' => _t('AssetAdmin.AppCategoryFlash', 'Flash', 'The fileformat'),
'zip' => _t('AssetAdmin.AppCategoryArchive', 'Archive', 'A collection of files'),
);
$context->addField(
new DropdownField(
Expand Down
114 changes: 59 additions & 55 deletions code/controllers/CMSMain.php
Expand Up @@ -190,7 +190,7 @@ function SearchForm() {
),
new DropdownField(
'ClassName',
_t('CMSMain.PAGETYPEOPT','Page Type', PR_MEDIUM, 'Dropdown for limiting search to a page type'),
_t('CMSMain.PAGETYPEOPT','Page Type', 'Dropdown for limiting search to a page type'),
$pageTypes,
null,
null,
Expand Down Expand Up @@ -244,67 +244,72 @@ public function Breadcrumbs($unlinked = false) {
* @return String Serialized JSON
*/
public function SiteTreeHints() {
$classes = ClassInfo::subclassesFor( $this->stat('tree_class') );

$def['Root'] = array();
$def['Root']['disallowedParents'] = array();
$json = '';

foreach($classes as $class) {
$obj = singleton($class);

if($obj instanceof HiddenClass) continue;

$allowedChildren = $obj->allowedChildren();

// SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none'
if($allowedChildren == null) $allowedChildren = array();

// Exclude SiteTree from possible Children
$possibleChildren = array_diff($allowedChildren, array("SiteTree"));
$classes = ClassInfo::subclassesFor( $this->stat('tree_class') );

// Find i18n - names and build allowed children array
foreach($possibleChildren as $child) {
$instance = singleton($child);
$cacheCanCreate = array();
foreach($classes as $class) $cacheCanCreate[$class] = singleton($class)->canCreate();

// Generate basic cache key. Too complex to encompass all variations
$cache = SS_Cache::factory('CMSMain_SiteTreeHints');
$cacheKey = md5(implode('_', array(Member::currentUserID(), implode(',', $cacheCanCreate), implode(',', $classes))));
if($this->request->getVar('flush')) $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
$json = $cache->load($cacheKey);
if(!$json) {
$def['Root'] = array();
$def['Root']['disallowedParents'] = array();

foreach($classes as $class) {
$obj = singleton($class);
if($obj instanceof HiddenClass) continue;

$allowedChildren = $obj->allowedChildren();

if($instance instanceof HiddenClass) continue;
// SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none'
if($allowedChildren == null) $allowedChildren = array();

// Exclude SiteTree from possible Children
$possibleChildren = array_diff($allowedChildren, array("SiteTree"));

if(!$instance->canCreate()) continue;
// Find i18n - names and build allowed children array
foreach($possibleChildren as $child) {
$instance = singleton($child);

if($instance instanceof HiddenClass) continue;

// skip this type if it is restricted
if($instance->stat('need_permission') && !$this->can(singleton($class)->stat('need_permission'))) continue;
if(!$cacheCanCreate[$child]) continue;

$title = $instance->i18n_singular_name();
// skip this type if it is restricted
if($instance->stat('need_permission') && !$this->can(singleton($class)->stat('need_permission'))) continue;

$def[$class]['allowedChildren'][] = array("ssclass" => $child, "ssname" => $title);
}
$title = $instance->i18n_singular_name();

$allowedChildren = array_keys(array_diff($classes, $allowedChildren));
if($allowedChildren) $def[$class]['disallowedChildren'] = $allowedChildren;

$defaultChild = $obj->defaultChild();

if($defaultChild != 'Page' && $defaultChild != null)
$def[$class]['defaultChild'] = $defaultChild;

$defaultParent = $obj->defaultParent();
$def[$class]['allowedChildren'][] = array("ssclass" => $child, "ssname" => $title);
}

$parent = SiteTree::get_by_link($defaultParent);

$id = $parent ? $parent->id : null;

if ($defaultParent != 1 && $defaultParent != null) $def[$class]['defaultParent'] = $defaultParent;

if(isset($def[$class]['disallowedChildren'])) {
foreach($def[$class]['disallowedChildren'] as $disallowedChild) {
$def[$disallowedChild]['disallowedParents'][] = $class;
$allowedChildren = array_keys(array_diff($classes, $allowedChildren));
if($allowedChildren) $def[$class]['disallowedChildren'] = $allowedChildren;
$defaultChild = $obj->defaultChild();
if($defaultChild != 'Page' && $defaultChild != null) $def[$class]['defaultChild'] = $defaultChild;
$defaultParent = $obj->defaultParent();
$parent = SiteTree::get_by_link($defaultParent);
$id = $parent ? $parent->id : null;
if ($defaultParent != 1 && $defaultParent != null) $def[$class]['defaultParent'] = $defaultParent;
if(isset($def[$class]['disallowedChildren'])) {
foreach($def[$class]['disallowedChildren'] as $disallowedChild) {
$def[$disallowedChild]['disallowedParents'][] = $class;
}
}

// Are any classes allowed to be parents of root?
$def['Root']['disallowedParents'][] = $class;
}

// Are any classes allowed to be parents of root?
$def['Root']['disallowedParents'][] = $class;
}

return Convert::raw2xml(Convert::raw2json($def));
$json = Convert::raw2xml(Convert::raw2json($def));
$cache->save($json, $cacheKey);
}
return $json;
}

/**
Expand Down Expand Up @@ -705,7 +710,6 @@ public function save($data, $form) {
_t(
'LeftAndMain.STATUSPUBLISHEDSUCCESS',
"Published '%s' successfully",
PR_MEDIUM,
'Status message after publishing a page, showing the page title'
),
$record->Title
Expand Down Expand Up @@ -738,7 +742,7 @@ public function getNewItem($id, $setID = true) {
$id = $id . $suffix;
}

$newItem->Title = _t('CMSMain.NEW',"New ",PR_MEDIUM,'"New " followed by a className').$className;
$newItem->Title = _t('CMSMain.NEW',"New ",'"New " followed by a className').$className;
$newItem->URLSegment = "new-" . strtolower($className);
$newItem->ClassName = $className;
$newItem->ParentID = $parentID;
Expand Down Expand Up @@ -849,7 +853,7 @@ public function revert($data, $form) {
$this->response->addHeader(
'X-Status',
sprintf(
_t('CMSMain.RESTORED',"Restored '%s' successfully",PR_MEDIUM,'Param %s is a title'),
_t('CMSMain.RESTORED',"Restored '%s' successfully",'Param %s is a title'),
$record->Title
)
);
Expand Down Expand Up @@ -1076,7 +1080,7 @@ function publishall($request) {
first built.') . '</p>
<form method="post" action="publishall">
<input type="submit" name="confirm" value="'
. _t('CMSMain.PUBALLCONFIRM',"Please publish every page in the site, copying content stage to live",PR_LOW,'Confirmation button') .'" />'
. _t('CMSMain.PUBALLCONFIRM',"Please publish every page in the site, copying content stage to live",'Confirmation button') .'" />'
. $tokenHtml .
'</form>';
}
Expand All @@ -1101,7 +1105,7 @@ function restore($data, $form) {
$this->response->addHeader(
'X-Status',
sprintf(
_t('CMSMain.RESTORED',"Restored '%s' successfully",PR_MEDIUM,'Param %s is a title'),
_t('CMSMain.RESTORED',"Restored '%s' successfully",'Param %s is a title'),
$restoredPage->TreeTitle
)
);
Expand Down
89 changes: 49 additions & 40 deletions code/model/SiteTree.php
Expand Up @@ -17,35 +17,40 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* class is allowed - no subclasses. Otherwise, the class and all its
* subclasses are allowed.
* To control allowed children on root level (no parent), use {@link $can_be_root}.
*
* Note that this setting is cached when used in the CMS, use the "flush" query parameter to clear it.
*
* @var array
*/
static $allowed_children = array("SiteTree");

/**
* The default child class for this page.
* Note: Value might be cached, see {@link $allowed_chilren}.
*
* @var string
*/
static $default_child = "Page";

/**
* The default parent class for this page.
* Note: Value might be cached, see {@link $allowed_chilren}.
*
* @var string
*/
static $default_parent = null;

/**
* Controls whether a page can be in the root of the site tree.
* Note: Value might be cached, see {@link $allowed_chilren}.
*
* @var bool
*/
static $can_be_root = true;

/**
* List of permission codes a user can have to allow a user to create a
* page of this type.
* List of permission codes a user can have to allow a user to create a page of this type.
* Note: Value might be cached, see {@link $allowed_chilren}.
*
* @var array
*/
Expand Down Expand Up @@ -1494,7 +1499,7 @@ function validate() {
_t(
'SiteTree.PageTypeNotAllowed',
'Page type "%s" not allowed as child of this parent page',
PR_MEDIUM,

'First argument is a class name'
),
$subject->i18n_singular_name()
Expand All @@ -1511,7 +1516,7 @@ function validate() {
_t(
'SiteTree.PageTypNotAllowedOnRoot',
'Page type "%s" is not allowed on the root level',
PR_MEDIUM,

'First argument is a class name'
),
$this->i18n_singular_name()
Expand Down Expand Up @@ -1833,7 +1838,7 @@ function getCMSFields() {
$tabMain = new Tab('Main',
new TextField("Title", $this->fieldLabel('Title')),
new TextField("MenuTitle", $this->fieldLabel('MenuTitle')),
$htmlField = new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", PR_MEDIUM, 'HTML editor title'))
$htmlField = new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", 'HTML editor title'))
),
$tabMeta = new Tab('Metadata',
$urlsegment,
Expand Down Expand Up @@ -1984,40 +1989,44 @@ function getSettingsFields() {
*
*/
function fieldLabels($includerelations = true) {
$labels = parent::fieldLabels($includerelations);

$labels['Title'] = _t('SiteTree.PAGETITLE', "Page name");
$labels['MenuTitle'] = _t('SiteTree.MENUTITLE', "Navigation label");
$labels['MetaTitle'] = _t('SiteTree.METATITLE', "Meta Title");
$labels['MetaDescription'] = _t('SiteTree.METADESC', "Meta Description");
$labels['MetaKeywords'] = _t('SiteTree.METAKEYWORDS', "Meta Keywords");
$labels['ExtraMeta'] = _t('SiteTree.METAEXTRA', "Custom Meta Tags");
$labels['ClassName'] = _t('SiteTree.PAGETYPE', "Page type", PR_MEDIUM, 'Classname of a page object');
$labels['ParentType'] = _t('SiteTree.PARENTTYPE', "Page location", PR_MEDIUM);
$labels['ParentID'] = _t('SiteTree.PARENTID', "Parent page", PR_MEDIUM);
$labels['ShowInMenus'] =_t('SiteTree.SHOWINMENUS', "Show in menus?");
$labels['ShowInSearch'] = _t('SiteTree.SHOWINSEARCH', "Show in search?");
$labels['ProvideComments'] = _t('SiteTree.ALLOWCOMMENTS', "Allow comments on this page?");
$labels['ViewerGroups'] = _t('SiteTree.VIEWERGROUPS', "Viewer Groups");
$labels['EditorGroups'] = _t('SiteTree.EDITORGROUPS', "Editor Groups");
$labels['URLSegment'] = _t('SiteTree.URLSegment', 'URL Segment', PR_MEDIUM, 'URL for this page');
$labels['Content'] = _t('SiteTree.Content', 'Content', PR_MEDIUM, 'Main HTML Content for a page');
$labels['CanViewType'] = _t('SiteTree.Viewers', 'Viewers Groups');
$labels['CanEditType'] = _t('SiteTree.Editors', 'Editors Groups');
$labels['Comments'] = _t('SiteTree.Comments', 'Comments');
$labels['Visibility'] = _t('SiteTree.Visibility', 'Visibility');
$labels['LinkChangeNote'] = _t (
'SiteTree.LINKCHANGENOTE', 'Changing this page\'s link will also affect the links of all child pages.'
);

if($includerelations){
$labels['Parent'] = _t('SiteTree.has_one_Parent', 'Parent Page', PR_MEDIUM, 'The parent page in the site hierarchy');
$labels['LinkTracking'] = _t('SiteTree.many_many_LinkTracking', 'Link Tracking');
$labels['ImageTracking'] = _t('SiteTree.many_many_ImageTracking', 'Image Tracking');
$labels['BackLinkTracking'] = _t('SiteTree.many_many_BackLinkTracking', 'Backlink Tracking');
$cacheKey = $this->class . '_' . $includerelations;
if(!isset(self::$_cache_field_labels[$cacheKey])) {
$labels = parent::fieldLabels($includerelations);
$labels['Title'] = _t('SiteTree.PAGETITLE', "Page name");
$labels['MenuTitle'] = _t('SiteTree.MENUTITLE', "Navigation label");
$labels['MetaTitle'] = _t('SiteTree.METATITLE', "Meta Title");
$labels['MetaDescription'] = _t('SiteTree.METADESC', "Meta Description");
$labels['MetaKeywords'] = _t('SiteTree.METAKEYWORDS', "Meta Keywords");
$labels['ExtraMeta'] = _t('SiteTree.METAEXTRA', "Custom Meta Tags");
$labels['ClassName'] = _t('SiteTree.PAGETYPE', "Page type", 'Classname of a page object');
$labels['ParentType'] = _t('SiteTree.PARENTTYPE', "Page location");
$labels['ParentID'] = _t('SiteTree.PARENTID', "Parent page");
$labels['ShowInMenus'] =_t('SiteTree.SHOWINMENUS', "Show in menus?");
$labels['ShowInSearch'] = _t('SiteTree.SHOWINSEARCH', "Show in search?");
$labels['ProvideComments'] = _t('SiteTree.ALLOWCOMMENTS', "Allow comments on this page?");
$labels['ViewerGroups'] = _t('SiteTree.VIEWERGROUPS', "Viewer Groups");
$labels['EditorGroups'] = _t('SiteTree.EDITORGROUPS', "Editor Groups");
$labels['URLSegment'] = _t('SiteTree.URLSegment', 'URL Segment', 'URL for this page');
$labels['Content'] = _t('SiteTree.Content', 'Content', 'Main HTML Content for a page');
$labels['CanViewType'] = _t('SiteTree.Viewers', 'Viewers Groups');
$labels['CanEditType'] = _t('SiteTree.Editors', 'Editors Groups');
$labels['Comments'] = _t('SiteTree.Comments', 'Comments');
$labels['Visibility'] = _t('SiteTree.Visibility', 'Visibility');
$labels['LinkChangeNote'] = _t (
'SiteTree.LINKCHANGENOTE', 'Changing this page\'s link will also affect the links of all child pages.'
);

if($includerelations){
$labels['Parent'] = _t('SiteTree.has_one_Parent', 'Parent Page', 'The parent page in the site hierarchy');
$labels['LinkTracking'] = _t('SiteTree.many_many_LinkTracking', 'Link Tracking');
$labels['ImageTracking'] = _t('SiteTree.many_many_ImageTracking', 'Image Tracking');
$labels['BackLinkTracking'] = _t('SiteTree.many_many_BackLinkTracking', 'Backlink Tracking');
}

self::$_cache_field_labels[$cacheKey] = $labels;
}
return $labels;

return self::$_cache_field_labels[$cacheKey];
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -2323,7 +2332,7 @@ protected function getClassDropdown() {
$translation = _t(
'SiteTree.CHANGETO',
'Change to "%s"',
PR_MEDIUM,

"Pagetype selection dropdown with class names"
);

Expand Down Expand Up @@ -2695,7 +2704,7 @@ function provideI18nEntities() {
$inst = singleton($type);
$entities[$type . '.DESCRIPTION'] = array(
$inst->stat('description'),
PR_MEDIUM,

'Description of the page type (shown in the "add page" dialog)'
);
}
Expand Down
2 changes: 1 addition & 1 deletion code/model/VirtualPage.php
Expand Up @@ -304,7 +304,7 @@ function validate() {
_t(
'VirtualPage.PageTypNotAllowedOnRoot',
'Original page type "%s" is not allowed on the root level for this virtual page',
PR_MEDIUM,

'First argument is a class name'
),
$orig->i18n_singular_name()
Expand Down
2 changes: 1 addition & 1 deletion code/reports/SideReport.php
Expand Up @@ -51,7 +51,7 @@ function forTemplate() {
} else {
$result = "<p class=\"message notice\">" .
sprintf(
_t('SideReport.REPEMPTY','The %s report is empty.',PR_MEDIUM,'%s is a report title'),
_t('SideReport.REPEMPTY','The %s report is empty.','%s is a report title'),
$this->report->title()
)
. "</p>";
Expand Down