'Page Type', 'Status' => 'Status',
'MetaDescription' => 'Description', 'MetaKeywords' => 'Keywords');
public function init() {
parent::init();
Requirements::javascript(MCE_ROOT . "tiny_mce_src.js");
Requirements::javascript("jsparty/tiny_mce_improvements.js");
Requirements::javascript("jsparty/hover.js");
Requirements::javascript("jsparty/scriptaculous/controls.js");
Requirements::javascript("cms/javascript/MemberList.js");
Requirements::javascript("cms/javascript/CMSMain.js");
Requirements::javascript("cms/javascript/CMSMain_left.js");
Requirements::javascript("cms/javascript/CMSMain_right.js");
Requirements::javascript("cms/javascript/ForumAdmin.js");
Requirements::javascript("cms/javascript/SideTabs.js");
Requirements::javascript("cms/javascript/TaskList.js");
Requirements::javascript("cms/javascript/CommentList.js");
Requirements::javascript("cms/javascript/SideReports.js");
Requirements::javascript("cms/javascript/LangSelector.js");
Requirements::javascript('cms/javascript/TranslationTab.js');
Requirements::javascript("sapphire/javascript/UpdateURL.js");
Requirements::javascript("sapphire/javascript/UniqueFields.js");
Requirements::javascript("sapphire/javascript/RedirectorPage.js");
Requirements::css("sapphire/css/FieldEditor.css");
Requirements::javascript("sapphire/javascript/FieldEditor.js");
Requirements::javascript("sapphire/javascript/TableListField.js");
Requirements::javascript("sapphire/javascript/TableField.js");
Requirements::javascript("sapphire/javascript/ComplexTableField.js");
Requirements::javascript("sapphire/javascript/RelationComplexTableField.js");
Requirements::javascript("survey/javascript/SurveyResponses.js");
Requirements::javascript("survey/javascript/FormResponses.js");
Requirements::javascript( 'sapphire/javascript/DataReport.js' );
Requirements::css("survey/css/SurveyFilter.css");
Requirements::javascript("sapphire/javascript/SelectionGroup.js");
// For Parents
Requirements::javascript("parents/javascript/NotifyMembers.js");
// For Tourism
Requirements::css("tourism/css/SurveyCMSMain.css");
Requirements::javascript("tourism/javascript/QuotasReport.js");
// For Mikano
Requirements::javascript("sapphire/javascript/ReportField.js");
// For Ptraining
Requirements::javascript("ptraining/javascript/BookingList.js");
// For Forum
Requirements::javascript("forum/javascript/ForumAccess.js");
// For Gallery
Requirements::javascript('gallery/javascript/GalleryPage_CMS.js');
Requirements::themedCSS('typography');
// For Widgets
Requirements::css('cms/css/WidgetAreaEditor.css');
Requirements::javascript('cms/javascript/WidgetAreaEditor.js');
// HACK ALERT:
// We need a better way of including all of the CSS that *might* be used by this application.
// Perhaps the ajax responses can include some instructions to go get more CSS / JavaScript?
if(Director::fileExists('mot')) {
Requirements::css("mot/css/WorkflowWidget.css");
}
// We don't want this showing up in every ajax-response, it should always be present in a CMS-environment
if(!Director::is_ajax()) {
Requirements::javascriptTemplate("cms/javascript/tinymce.template.js", array(
"ContentCSS" => (SSViewer::current_theme() ? "themes/" . SSViewer::current_theme() : project()) . "/css/editor.css",
"BaseURL" => Director::absoluteBaseURL(),
));
}
}
//------------------------------------------------------------------------------------------//
// Main controllers
//------------------------------------------------------------------------------------------//
// Main UI components
/**
* Return the entire site tree as a nested set of ULs
*/
public function SiteTreeAsUL() {
$this->generateDataTreeHints();
$this->generateTreeStylingJS();
return $this->getSiteTreeFor("SiteTree");
}
/**
* Returns the SiteTree columns that can be filtered using the the Site Tree Search button as a DataObjectSet
*/
public function SiteTreeFilterOptions() {
$filter_options = new DataObjectSet();
foreach(self::$site_tree_filter_options as $key => $value) {
$record = array(
'Column' => $key,
'Title' => $value,
);
$filter_options->push(new ArrayData($record));
}
return $filter_options;
}
public function SiteTreeFilterDateField() {
$dateField = new CalendarDateField('SiteTreeFilterDate');
return $dateField->Field();
}
/**
* Returns a filtered Site Tree
*/
public function filterSiteTree() {
$className = 'SiteTree';
$rootID = null;
$obj = $rootID ? $this->getRecord($rootID) : singleton($className);
$obj->setMarkingFilterFunction('CMSMainMarkingFilterFunction');
$obj->markPartialTree();
if($p = $this->currentPage()) $obj->markToExpose($p);
// getChildrenAsUL is a flexible and complex way of traversing the tree
$siteTree = $obj->getChildrenAsUL("", '
"
' . _t('CMSMain.PUBALLFUN2', 'Pressing this button will do the equivalent of going to every page and pressing "publish". It\'s
intended to be used after there have been massive edits of the content, such as when the site was
first built.') . '
';
}
}
function restorepage() {
if($id = $this->urlParams['ID']) {
$restoredPage = Versioned::get_latest_version("SiteTree", $id);
$restoredPage->ID = $restoredPage->RecordID;
if(!DB::query("SELECT ID FROM SiteTree WHERE ID = $restoredPage->ID")->value()) {
DB::query("INSERT INTO SiteTree SET ID = $restoredPage->ID");
}
$restoredPage->forceChange();
$restoredPage->writeWithoutVersion();
Debug::show($restoredPage);
} else {
echo _t('CMSMain.VISITRESTORE',"visit restorepage/(ID)",PR_LOW,'restorepage/(ID) should not be translated (is an URL)');
}
}
function duplicate() {
if(($id = $this->urlParams['ID']) && is_numeric($id)) {
$page = DataObject::get_by_id("SiteTree", $id);
$newPage = $page->duplicate();
return $this->returnItemToUser($newPage);
} else {
user_error("CMSMain::duplicate() Bad ID: '$id'", E_USER_WARNING);
}
}
/**
* Switch the cms language and reload the site tree
*
*/
function switchlanguage($lang, $donotcreate = null) {
//is it's a clean switch (to an existing language deselect the current page)
if (is_string($lang)) $dontunloadPage = true;
$lang = (is_string($lang) ? $lang : urldecode($this->urlParams['ID']));
if ($lang != Translatable::default_lang()) {
Translatable::set_reading_lang(Translatable::default_lang());
$tree_class = $this->stat('tree_class');
$obj = new $tree_class;
$allIDs = $obj->getDescendantIDList();
$allChildren = $obj->AllChildren();
$classesMap = $allChildren->map('ID','ClassName');
$titlesMap = $allChildren->map();
Translatable::set_reading_lang($lang);
$obj = new $tree_class;
$languageIDs = $obj->getDescendantIDList();
$notcreatedlist = array_diff($allIDs,$languageIDs);
FormResponse::add("$('addpage').getElementsByTagName('button')[0].disabled=true;");
FormResponse::add("$('Form_AddPageOptionsForm').getElementsByTagName('div')[1].getElementsByTagName('input')[0].disabled=true;");
FormResponse::add("$('Translating_Message').innerHTML = 'Translating mode - ".i18n::get_language_name($lang)."';");
FormResponse::add("Element.removeClassName('Translating_Message','nonTranslating');");
} else {
Translatable::set_reading_lang($lang);
FormResponse::add("$('addpage').getElementsByTagName('button')[0].disabled=false;");
FormResponse::add("$('Form_AddPageOptionsForm').getElementsByTagName('div')[1].getElementsByTagName('input')[0].disabled=false;");
FormResponse::add("Element.addClassName('Translating_Message','nonTranslating');");
}
$obj = singleton($this->stat('tree_class'));
$obj->markPartialTree();
$siteTree = $obj->getChildrenAsUL("", '
"
";
FormResponse::add("$('sitetree').innerHTML ='". ereg_replace("[\n]","\\\n",$siteTree) ."';");
FormResponse::add("SiteTree.applyTo('#sitetree');");
if (isset($notcreatedlist)) {
foreach ($notcreatedlist as $notcreated) {
if ($notcreated == $donotcreate) continue;
$id = "new-{$classesMap[$notcreated]}-0-$notcreated";
Session::set($id . '_originalLangID',$notcreated);
$treeTitle = Convert::raw2js($titlesMap[$notcreated]);
$response = <<getRecord($originalLangID);
$temporalID = "new-$record->RecordClassName-$record->ParentID-$originalLangID";
Session::set($temporalID . '_originalLangID',$originalLangID);
$tree = $this->switchlanguage($langCode, $originalLangID);
FormResponse::add(<<ID = $temporalID;
$newrecord->CheckedPublicationDifferences = $newrecord->AddedToStage = true;
return $this->returnItemToUser($newrecord);
}
// HACK HACK HACK - Dont remove without telling simon ;-)
/**
* This is only used by parents inc.
* TODO Work out a better way of handling control to the individual page objects.
*/
function sethottip($data,$form) {
$page = DataObject::get_by_id("SiteTree", $_REQUEST['ID']);
return $page->sethottip($data,$form);
}
/**
* This is only used by parents inc.
* TODO Work out a better way of handling control to the individual page objects.
*/
function notifyInvitation($data,$form) {
$page = DataObject::get_by_id("SiteTree", $_REQUEST['ID']);
return $page->notifyInvitation($data,$form);
}
function testInvitation($data,$form) {
$page = DataObject::get_by_id("SiteTree", $_REQUEST['ID']);
return $page->testInvitation($data,$form);
}
/**
* Provide the permission codes used by LeftAndMain.
* Can't put it on LeftAndMain since that's an abstract base class.
*/
function providePermissions() {
$classes = ClassInfo::subclassesFor('LeftAndMain');
foreach($classes as $class) {
$perms["CMS_ACCESS_" . $class] = "Access to $class in CMS";
}
return $perms;
}
/**
* Return a dropdown with existing languages
*/
function LangSelector() {
$langs = i18n::get_existing_languages('SiteTree');
return new DropdownField("LangSelector","Language",$langs,Translatable::current_lang());
}
/**
* Determine if there are more than one languages in our site tree
*/
function MultipleLanguages() {
$langs = i18n::get_existing_languages('SiteTree');
return count($langs)>1;
}
/**
* Get the name of the language that we are translating in
*/
function EditingLang() {
if (!Translatable::is_default_lang()) return i18n::get_language_name(Translatable::current_lang());
}
}
// TODO: Find way to put this in a class
function CMSMainMarkingFilterFunction($node) {
// Expand all nodes
// $node->markingFinished();
// Don't ever hide nodes with children, because otherwise if one of their children matches the search, it wouldn't be shown.
if($node->AllChildrenIncludingDeleted()->count() > 0) {
// Open all nodes with children so it is easy to see any children that match the search.
$node->markOpened();
return true;
} else {
$failed_filter = false;
// First check for the generic search term in the URLSegment, Title, MenuTitle, & Content
if (!empty($_REQUEST['SiteTreeSearchTerm'])) {
// For childless nodes, show only those matching the filter
$filter = strtolower($_REQUEST['SiteTreeSearchTerm']);
if ( strpos( strtolower($node->URLSegment) , $filter) === false
&& strpos( strtolower($node->Title) , $filter) === false
&& strpos( strtolower($node->MenuTitle) , $filter) === false
&& strpos( strtolower($node->Content) , $filter) === false) {
$failed_filter = true;
}
}
// Check the 'Edited Since' date
if (!empty($_REQUEST['SiteTreeFilterDate'])) {
$edited_since = mktime(0, 0, 0, substr($_REQUEST['SiteTreeFilterDate'], 3, 2),
substr($_REQUEST['SiteTreeFilterDate'], 0, 2), substr($_REQUEST['SiteTreeFilterDate'], 6, 4));
if ( strtotime($node->LastEdited) < $edited_since ) {
$failed_filter = true;
}
}
// Now check if a specified Criteria attribute matches
foreach (CMSMain::$site_tree_filter_options as $key => $value)
{
if (!empty($_REQUEST[$key])) {
$parameterName = $key;
$filter = strtolower($_REQUEST[$key]);
// Show node only if the filter string exists anywere in the filter paramater (ignoring case)
if (strpos( strtolower($node->$parameterName) , $filter) === false) {
$failed_filter = true;
}
}
}
// Each filter must match or it fails
if (true == $failed_filter) {
return false;
} else {
return true;
}
}
}
?>