Skip to content

Commit

Permalink
some conflicts with previous version (Contao3)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGausi committed Oct 30, 2018
1 parent 8ab26f0 commit ba3479a
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 60 deletions.
10 changes: 5 additions & 5 deletions src/Resources/contao/dca/tl_calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
* Add palettes to tl_calendar
*/

$GLOBALS['TL_DCA']['tl_calendar']['palettes']['default'] .= ';{edit_legend},allowEdit';
$GLOBALS['TL_DCA']['tl_calendar']['palettes']['default'] .= ';{edit_legend},AllowEdit';

$GLOBALS['TL_DCA']['tl_calendar']['palettes']['__selector__'][] = 'allowEdit';
$GLOBALS['TL_DCA']['tl_calendar']['subpalettes']['allowEdit']='caledit_onlyFuture, caledit_jumpTo, caledit_loginRequired, caledit_onlyUser, caledit_groups, caledit_adminGroup';
$GLOBALS['TL_DCA']['tl_calendar']['palettes']['__selector__'][] = 'AllowEdit';
$GLOBALS['TL_DCA']['tl_calendar']['subpalettes']['AllowEdit']='caledit_onlyFuture, caledit_jumpTo, caledit_loginRequired, caledit_onlyUser, caledit_groups, caledit_adminGroup';



$GLOBALS['TL_DCA']['tl_calendar']['fields']['allowEdit'] = array
$GLOBALS['TL_DCA']['tl_calendar']['fields']['AllowEdit'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_calendar']['allowEdit'],
'label' => &$GLOBALS['TL_LANG']['tl_calendar']['AllowEdit'],
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/languages/de/tl_calendar.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$GLOBALS['TL_LANG']['tl_calendar']['allowEdit'] = array('Bearbeitung im Frontend erlauben', 'Erlaubt Frontend-Usern das Hinzufügen und Bearbeiten von Terminen in diesem Kalender.');
$GLOBALS['TL_LANG']['tl_calendar']['AllowEdit'] = array('Bearbeitung im Frontend erlauben', 'Erlaubt Frontend-Usern das Hinzufügen und Bearbeiten von Terminen in diesem Kalender.');
$GLOBALS['TL_LANG']['tl_calendar']['caledit_onlyFuture'] = array('Nur zukünftige Events', 'Wenn aktiviert, ist die Bearbeitung nur für zukünftige Termine möglich.');
$GLOBALS['TL_LANG']['tl_calendar']['caledit_jumpTo'] = array('Weiterleitungsseite zum Bearbeiten','Bitte wählen Sie eine Seite mit dem Event-Editor, auf den der User bei einem Klick auf einen Bearbeiten-Link weitergeleitet wird.');
$GLOBALS['TL_LANG']['tl_calendar']['caledit_loginRequired'] = array('Login benötigt für die Bearbeitung (empfohlen)','Wenn aktiviert, können nur registrierte Nutzer (aus den gewählten Gruppen) Events bearbeiten/hinzufügen. Warnung: Sonst kann das JEDER Besucher der Seite.');
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/languages/en/tl_calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Miscellaneous
*/

$GLOBALS['TL_LANG']['tl_calendar']['allowEdit'] = array('Enable Frontend editing','Allow Frontend-Users to add and edit events in this calendar.');
$GLOBALS['TL_LANG']['tl_calendar']['AllowEdit'] = array('Enable Frontend editing','Allow Frontend-Users to add and edit events in this calendar.');
$GLOBALS['TL_LANG']['tl_calendar']['caledit_onlyFuture'] = array('Only future events','Allow editing only for future events.');
$GLOBALS['TL_LANG']['tl_calendar']['caledit_jumpTo'] = array('Redirect page for editing','Please choose the event editor page to which the user will be redirected when clicking an edit link.');
$GLOBALS['TL_LANG']['tl_calendar']['caledit_loginRequired'] = array('Login required for Frontend editing (strongly recommended)', 'If this is checked, only registered user (from the groups below) are allowed to add/edit events. WARNING: Otherwise EVERYBODY can add/edit events.');
Expand Down
10 changes: 5 additions & 5 deletions src/Resources/contao/modules/CEAuthCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

// Check, whether the User is an Admin to add/edit Events in this objCalendar
function UserIsAdmin($objCalendar, $User){
if (!$objCalendar->allowEdit) {
if (!$objCalendar->AllowEdit) {
return false;
} else {
if (FE_USER_LOGGED_IN) {
Expand All @@ -38,7 +38,7 @@ function UserIsAdmin($objCalendar, $User){

// Check, whether the User is authorized to add/edit Events in this objCalendar
function UserIsAuthorizedUser($objCalendar, $User){
if (!$objCalendar->allowEdit) {
if (!$objCalendar->AllowEdit) {
return false;
} else {
if (!$objCalendar->caledit_loginRequired) {
Expand Down Expand Up @@ -67,7 +67,7 @@ function UserIsAuthorizedUser($objCalendar, $User){
}

function UserIsAuthorizedElapsedEvents($objCalendar, $User){
if (!$objCalendar->allowEdit) {
if (!$objCalendar->AllowEdit) {
return false;
} else {
// User is authorized to edit/add elapsed Events if
Expand All @@ -79,7 +79,7 @@ function UserIsAuthorizedElapsedEvents($objCalendar, $User){

// used in GetAllEvents Hook
function EditLinksAreAllowed ($objCalendar, $aEvent, $userID, $UserIsAdmin, $UserIsMember, $currentTime){
if (!$objCalendar->allowEdit) {
if (!$objCalendar->AllowEdit) {
return false;
} else {
if ($UserIsAdmin && (!$aEvent['disable_editing'])) {
Expand All @@ -104,7 +104,7 @@ function EditLinksAreAllowed ($objCalendar, $aEvent, $userID, $UserIsAdmin, $Use

// used in Module ModuleEventReaderEdit
function EditLinksAreAllowed2 ($objCalendar, $objEvent, $User, $UserIsAdmin, $UserIsMember){
if (!$objCalendar->allowEdit) {
if (!$objCalendar->AllowEdit) {
return false;
} else {
if ($UserIsAdmin && (!$objEvent->disable_editing)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/contao/modules/ListAllEvents_Hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function updateAllEvents($arrEvents, $arrCalendars, $intStart, $intEnd, $

$CalendarObjects[$currentPID] = $objCalendar;

if ($objCalendar->allowEdit) {
if ($objCalendar->AllowEdit) {
// is user admin for this calendar?
$UserIsAdminForCalendar[$currentPID] = UserIsAdmin ($objCalendar, $this->User);
$UserIsMemberForCalendar[$currentPID] = UserIsAuthorizedUser ($objCalendar, $this->User);
Expand Down Expand Up @@ -101,7 +101,7 @@ public function updateAllEvents($arrEvents, $arrCalendars, $intStart, $intEnd, $
foreach ($intnext as &$intdate) {
foreach ($intdate as &$aEvent){
$cPID = $aEvent['pid'];
if ( ($CalendarObjects[$cPID]->allowEdit) && EditLinksAreAllowed($CalendarObjects[$cPID], $aEvent, $this->User->id, $UserIsAdminForCalendar[$cPID], $UserIsMemberForCalendar[$cPID], $currentTime)){
if ( ($CalendarObjects[$cPID]->AllowEdit) && EditLinksAreAllowed($CalendarObjects[$cPID], $aEvent, $this->User->id, $UserIsAdminForCalendar[$cPID], $UserIsMemberForCalendar[$cPID], $currentTime)){
$this->addEditLinks($aEvent, $JumpPages[$cPID]);
}
}
Expand Down
108 changes: 63 additions & 45 deletions src/Resources/contao/modules/ModuleEventEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,25 @@ public function GetEditorFrontendURLForEvent($EventObj)
*/
public function addTinyMCE($str) {
if (!empty($str)) {
$strFile = sprintf('%s/vendor/danielgausi/contao-calendareditor-bundle/src/Resources/contao/tinyMCE/%s.php', TL_ROOT, $str);

$this->rteFields = 'ctrl_details,ctrl_teaser,teaser';
$this->language = 'en';
// Fallback to English if the user language is not supported
if (file_exists(TL_ROOT . '/assets/tinymce4/js/langs/' . $GLOBALS['TL_LANGUAGE'] . '.js')) {
$this->language = $GLOBALS['TL_LANGUAGE'];
}
$this->rteFields = 'ctrl_details,ctrl_teaser,teaser';
// Fallback to English if the user language is not supported
$this->language = 'en';

if(version_compare(VERSION.'.'.BUILD, '4.4.0', '>=')) {
// Contao 4.4+
$strFile = sprintf('%s/vendor/danielgausi/contao-calendareditor-bundle/src/Resources/contao/tinyMCE/%s.php', TL_ROOT, $str);
if (file_exists(TL_ROOT . '/assets/tinymce4/js/langs/' . $GLOBALS['TL_LANGUAGE'] . '.js')) {
$this->language = $GLOBALS['TL_LANGUAGE'];
}
} else {
// Contao 3.x
// or below 4.4 (not supported)
$strFile = sprintf('%s/system/config/%s.php', TL_ROOT, $str);
if (file_exists(TL_ROOT . '/assets/tinymce4/langs/' . $GLOBALS['TL_LANGUAGE'] . '.js')) {
$this->language = $GLOBALS['TL_LANGUAGE'];
}
}

if (!file_exists($strFile)) {
echo (sprintf('Cannot find rich text editor configuration file "%s"', $strFile));
}else {
Expand Down Expand Up @@ -215,8 +226,8 @@ public function checkUserEditRights($user, $eventID, $CurrentObjectData) {
return false; // Event not found or something else is wrong
}

if (!$objCalendar->allowEdit) {
$this->ErrorString = $GLOBALS['TL_LANG']['MSC']['caledit_NoEditAllowed'];
if (!$objCalendar->AllowEdit) {
$this->ErrorString = $GLOBALS['TL_LANG']['MSC']['caledit_NoEditAllowed'].'wuppdi';
return false;
}

Expand Down Expand Up @@ -633,11 +644,7 @@ protected function HandleEdit($editID, $currentEventObject) {
$this->Template->FatalError = $fatalError;
return ;
}
}

//$GLOBALS['TL_JAVASCRIPT'][] = 'assets/jquery-ui/js/jquery-ui.min.js';
//$GLOBALS['TL_JAVASCRIPT'][] = 'assets/hofff/calendarfield/jquery-ui.datepicker/js/widgets/datepicker.min.js';
//$GLOBALS['TL_JAVASCRIPT'][] = 'assets/hofff/calendarfield/jquery-ui.datepicker/js/i18n/datepicker-de.js';
}

$mandfields = deserialize($this->caledit_mandatoryfields);
$mandTeaser = (is_array($mandfields) && array_intersect(array('teaser') , $mandfields));
Expand All @@ -650,15 +657,11 @@ protected function HandleEdit($editID, $currentEventObject) {
$fields['startDate'] = array(
'name' => 'startDate',
'label' => $GLOBALS['TL_LANG']['MSC']['caledit_startdate'],
'inputType' => 'text', // or: 'calendarfield',
'inputType' => 'text', // or: 'calendarfield' (see below),
'value' => $NewEventData['startDate'],
'eval' => array('rgxp' => 'date',
'mandatory' => true,
'decodeEntities' => true)
//'dateImage' => '1',
//'dateIncludeCSS' => '1',
//'dateIncludeCSSTheme' => 'smoothness',
//'dateDirection' => 'gtToday')
'decodeEntities' => true)
);

$fields['endDate'] = array(
Expand All @@ -669,9 +672,13 @@ protected function HandleEdit($editID, $currentEventObject) {
'eval' => array('rgxp' => 'date', 'mandatory' => false, 'maxlength' => 128, 'decodeEntities' => true)
);

if ($this->caledit_useDatePicker) {
$this->addDatePicker($fields['startDate']);
$this->addDatePicker($fields['endDate']);
if(version_compare(VERSION.'.'.BUILD, '4.4.0', '>=')) {
// Contao 4.4+ is using "calenderfield" by default
// Contao 3.5 will have to install it manually and install a proper Hook to achieve this
if ($this->caledit_useDatePicker) {
$this->addDatePicker($fields['startDate']);
$this->addDatePicker($fields['endDate']);
}
}

$fields['startTime'] = array(
Expand Down Expand Up @@ -750,11 +757,20 @@ protected function HandleEdit($editID, $currentEventObject) {
$ref = array();
$opt = array();

foreach ($cssValues as $cssv) {
$opt[] = $cssv['value'];
$ref[$cssv['value']] = $cssv['label'];
if(version_compare(VERSION.'.'.BUILD, '4.4.0', '>=')) {
// Contao 4.4+ uses a different module for this multi-text-stuff
// and a slightly different DCA
foreach ($cssValues as $cssv) {
$opt[] = $cssv['value'];
$ref[$cssv['value']] = $cssv['label'];
}
} else {
foreach ($cssValues as $cssv) {
$opt[] = $cssv['1'];
$ref[$cssv['1']] = $cssv['0'];
}
}

$fields['cssClass'] = array(
'name' => 'cssClass',
'label' => $cssLabel,
Expand Down Expand Up @@ -864,10 +880,12 @@ protected function HandleEdit($editID, $currentEventObject) {
}
}
$arrWidgets[$arrField['name']] = $objWidget;
}
if(version_compare(VERSION.'.'.BUILD, '4.4.0', '>=')) {
// Contao 4.4+: The CalendarFields need to be parsed to activate JS
$arrWidgets['startDate']->parse();
$arrWidgets['endDate']->parse();
}
// parse the Date fields, to show the Datepicker
$arrWidgets['startDate']->parse();
$arrWidgets['endDate']->parse();


// Check, whether the user is allowed to edit past events
Expand Down Expand Up @@ -957,8 +975,7 @@ protected function HandleDelete($currentEventObject) {
$published = $currentEventObject->published;

$this->Template->CurrentEventLink = $this->GetEditorFrontendURLForEvent($currentEventObject);



$this->Template->CurrentTitle = $currentEventObject->title;
$this->Template->CurrentDate = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $currentEventObject->startDate);

Expand Down Expand Up @@ -1042,22 +1059,20 @@ protected function HandleClone($currentEventObject) {
$currentEventData = array();
$currentContentData = array();
$contentID = '';

// add a "Edit this event"-Link
$del = str_replace('?clone=', '?edit=', $this->Environment->request);
$this->Template->editRef = $del;
$this->Template->editLabel = $GLOBALS['TL_LANG']['MSC']['caledit_editLabel'];
$this->Template->editTitle = $GLOBALS['TL_LANG']['MSC']['caledit_editTitle'];



if ($this->caledit_allowDelete){
// add a "Delete this event"-Link
$del = str_replace('?clone=', '?delete=', $this->Environment->request);
$this->Template->deleteRef = $del;
$this->Template->deleteLabel = $GLOBALS['TL_LANG']['MSC']['caledit_deleteLabel'];
$this->Template->deleteTitle = $GLOBALS['TL_LANG']['MSC']['caledit_deleteTitle'];
}


// get a proper Content-Element
$this->getContentElements($currentID, $contentID, $currentContentData);
Expand Down Expand Up @@ -1112,11 +1127,12 @@ protected function HandleClone($currentEventObject) {
'eval' => array('rgxp' => 'date', 'mandatory' => false, 'maxlength' => 128, 'decodeEntities' => true)
);

if ($this->caledit_useDatePicker) {
$this->addDatePicker($fields['start'.$i]);
$this->addDatePicker($fields['end'.$i]);
if(version_compare(VERSION.'.'.BUILD, '4.4.0', '>=')) {
if ($this->caledit_useDatePicker) {
$this->addDatePicker($fields['start'.$i]);
$this->addDatePicker($fields['end'.$i]);
}
}

}

if (!FE_USER_LOGGED_IN) {
Expand Down Expand Up @@ -1157,7 +1173,6 @@ protected function HandleClone($currentEventObject) {
}
}


// Initialize widgets
$arrWidgets = array();
$doNotSubmit = false;
Expand All @@ -1176,9 +1191,12 @@ protected function HandleClone($currentEventObject) {
$arrWidgets[$arrField['name']] = $objWidget;
}

for ($i = 1; $i <= 10; $i++) {
$arrWidgets['start'.$i]->parse();
$arrWidgets['end'.$i]->parse();
if(version_compare(VERSION.'.'.BUILD, '4.4.0', '>=')) {
// Contao 4.4+: The CalendarFields need to be parsed to activate JS
for ($i = 1; $i <= 10; $i++) {
$arrWidgets['start'.$i]->parse();
$arrWidgets['end'.$i]->parse();
}
}

$allDatesAllowed = $this->allDatesAllowed($currentEventData['pid']);
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/modules/ModuleEventReaderEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function compile()
return; // No calendar found
}

if ($objCalendar->allowEdit) {
if ($objCalendar->AllowEdit) {
// Calendar allows editing
// check user rights

Expand Down

0 comments on commit ba3479a

Please sign in to comment.