array('CMSMain.PAGETYPE', 'Page Type'),
'Status' => array('CMSMain.STATUS', 'Status'),
'MetaDescription' => array('CMSMain.METADESC', 'Description'),
'MetaKeywords' => array('CMSMain.METAKEYWORDS', 'Keywords')
);
static function T_SiteTreeFilterOptions(){
return array(
'ClassName' => _t('CMSMain.PAGETYPEOPT', 'Page Type', 0, "The dropdown title in CMSMain left SiteTreeFilterOptions"),
'Status' => _t('CMSMain.STATUSOPT', 'Status', 0, "The dropdown title in CMSMain left SiteTreeFilterOptions"),
'MetaDescription' => _t('CMSMain.METADESCOPT', 'Description', 0, "The dropdown title in CMSMain left SiteTreeFilterOptions"),
'MetaKeywords' => _t('CMSMain.METAKEYWORDSOPT', 'Keywords', 0, "The dropdown title in CMSMain left SiteTreeFilterOptions"),
);
}
public function init() {
parent::init();
// 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(),
"Lang" => i18n::get_tinymce_lang()
));
}
Requirements::javascript('cms/javascript/CMSMain.js');
Requirements::javascript('cms/javascript/CMSMain_left.js');
Requirements::javascript('cms/javascript/CMSMain_right.js');
Requirements::javascript('sapphire/javascript/UpdateURL.js');
/**
* HACK ALERT: Project-specific requirements
*
* 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?
*/
Requirements::css("mot/css/WorkflowWidget.css");
Requirements::css("survey/css/SurveyFilter.css");
Requirements::javascript("survey/javascript/SurveyResponses.js");
Requirements::javascript("survey/javascript/FormResponses.js");
Requirements::javascript("parents/javascript/NotifyMembers.js");
Requirements::css("tourism/css/SurveyCMSMain.css");
Requirements::javascript("tourism/javascript/QuotasReport.js");
Requirements::javascript("sapphire/javascript/ReportField.js");
Requirements::javascript("ptraining/javascript/BookingList.js");
Requirements::javascript("forum/javascript/ForumAccess.js");
Requirements::javascript('gallery/javascript/GalleryPage_CMS.js');
}
//------------------------------------------------------------------------------------------//
// 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::T_SiteTreeFilterOptions() 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();
// ParentID can be hard-set in the URL. This is useful for pages with multiple parents
if($_GET['parentID'] && is_numeric($_GET['parentID'])) {
$newPage->ParentID = $_GET['parentID'];
$newPage->write();
}
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] = sprintf(_t('CMSMain.ACCESS', "Access to %s in CMS"), $class);
}
return $perms;
}
/**
* Return a dropdown with existing languages
*/
function LangSelector() {
$langs = i18n::get_existing_content_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_content_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());
} else {
return false;
}
}
}
$filterCache = array();
// TODO: Find way to put this in a class
function cmsMainMarkingFilterFunction($node) {
// Expand all nodes
// $node->markingFinished();
$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::T_SiteTreeFilterOptions() 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) {
// 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.
foreach($node->AllChildrenIncludingDeleted() as $childNode) {
if(cmsMainMarkingFilterFunction($childNode)) {
$node->markOpened();
$filterCache[$node->ID] = true;
return true;
}
}
}
$filterCache[$node->ID] = false;
return false;
} else {
if($node->AllChildrenIncludingDeleted()->count() > 0) {
$node->markOpened();
}
$filterCache[$node->ID] = true;
return true;
}
}
?>