Skip to content

Commit

Permalink
Switch to Contao5
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnysp committed Dec 10, 2024
1 parent 27194b2 commit 4baa037
Show file tree
Hide file tree
Showing 23 changed files with 583 additions and 442 deletions.
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jonnysp/vegas",
"type": "contao-bundle",
"description": "Adds Vegas functionality to Contao 4",
"description": "Adds Vegas functionality to Contao 5",
"keywords":["slideshow","vegas", "contao"],
"license": "LGPL-3.0+",
"authors": [
Expand All @@ -11,11 +11,11 @@
}
],
"require": {
"php":">=5.6.0",
"contao/core-bundle":"^4.4"
"php":">=8.1.0",
"contao/core-bundle":"^5.3"
},
"conflict": {
"contao/core-bundle": "<4.4.1"
"contao/core-bundle": "<5.3"
},
"autoload": {
"psr-4": {
Expand All @@ -40,5 +40,6 @@
"support": {
"issues": "https://github.com/jonnysp/Vegas/issues",
"source": "https://github.com/jonnysp/Vegas"
}
},
"version": "1.0.0"
}
9 changes: 9 additions & 0 deletions src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/*
* Copyright (c) 2005-2024 Jonny Spitzner
*
* @license LGPL-3.0+
*/

namespace Jonnysp\Vegas\ContaoManager;

use Jonnysp\Vegas\JonnyspVegas;
Expand All @@ -11,6 +17,9 @@

class Plugin implements BundlePluginInterface
{
/**
* {@inheritdoc}
*/
public function getBundles(ParserInterface $parser)
{
return [
Expand Down
61 changes: 45 additions & 16 deletions src/Resources/contao/classes/VegasViewer.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,61 @@
<?php


/*
* Copyright (c) 2005-2024 Jonny Spitzner
*
* @license LGPL-3.0+
*/

use Contao\ContentElement;
use Contao\BackendTemplate;
use Contao\StringUtil;
use Contao\System;
use Contao\FilesModel;
use Contao\File;
use Contao\Environment;

use Vegas\Model\VegasModel;
use Vegas\Model\VegasSlidesModel;

class VegasViewer extends ContentElement{

protected $strTemplate = 'ce_vegas';

public function generate() {
if(TL_MODE == 'BE') {
$objVegas = \VegasModel::findByPK($this->vegas);
public function generate(): string
{
$request = System::getContainer()->get('request_stack')->getCurrentRequest();

if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
{

if (isset($objVegas)) {
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->title = $objVegas->title;
$objTemplate->wildcard = '';
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '';

if (null !== ($objVegas = VegasModel::findByPK($this->vegas)))
{
$objTemplate->title ='['. $objVegas->id.'] - '. $objVegas->title;
}

return($objTemplate->parse());
}
}

return(parent::generate());
return parent::generate();
}


protected function compile() {
protected function compile(): void
{

$GLOBALS['TL_JAVASCRIPT'][] = 'bundles/jonnyspvegas/vegas/vegas.min.js';
$GLOBALS['TL_CSS'][] = 'bundles/jonnyspvegas/vegas/vegas.css';

$config = '';

$vegas = \VegasModel::findByPK($this->vegas);
if (null === ($vegas = VegasModel::findByPK($this->vegas)))
{
$this->Template->vegasconfig = $config;
return;
}

$config .= '$("'.html_entity_decode($vegas->target).'").vegas(';
$slides['preload'] = boolval($vegas->preload);
Expand Down Expand Up @@ -57,14 +85,15 @@ protected function compile() {
}

if($vegas->overlay <> ''){
$slides['overlay']= \Environment::get('base').'bundles/jonnyspvegas/vegas/overlays/'.$vegas->overlay.'.png';
$slides['overlay']= Environment::get('base').'bundles/jonnyspvegas/vegas/overlays/'.$vegas->overlay.'.png';
}

$images = \VegasSlidesModel::findBy(array('pid=?', 'published=?'),array($vegas->id, '1'),array('order'=>'sorting ASC'));
if (isset($images)){
$images = VegasSlidesModel::findBy(array('pid=?', 'published=?'),array($vegas->id, '1'),array('order'=>'sorting ASC'));

if (null !== $images){
foreach ($images as $key => $value) {

$slide['src'] = \Environment::get('base').\FilesModel::findByPk($value->src)->path;
$slide['src'] = Environment::get('base').FilesModel::findByPk($value->src)->path;
$slide['align'] = $value->align;
$slide['valign'] = $value->valign;
if($value->transition <> ''){
Expand Down
59 changes: 33 additions & 26 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
@@ -1,48 +1,55 @@
<?php

/**
*
* Copyright (c) 2005-2022 Jonny Spitzner
/*
* Copyright (c) 2005-2024 Jonny Spitzner
*
* @license LGPL-3.0+
*/
*/

/**
* Back end modules
*/
array_insert($GLOBALS['BE_MOD']['vegas'], 100, array
use Vegas\Model\VegasModel;
use Vegas\Model\VegasSlidesModel;
use Contao\ArrayUtil;
use Contao\System;
use Symfony\Component\HttpFoundation\Request;

$GLOBALS['TL_MODELS']['tl_vegas'] = VegasModel::class;
$GLOBALS['TL_MODELS']['tl_vegas_slides'] = VegasSlidesModel::class;

ArrayUtil::arrayInsert($GLOBALS['BE_MOD']['vegas'], 100, array
(
'vegas' => array
(
'tables' => array('tl_vegas','tl_vegas_slides')
)
'vegas' => array('tables' => array('tl_vegas','tl_vegas_slides'))
));


/**
* Style sheet
*/
if (TL_MODE == 'BE')
if (System::getContainer()->get('contao.routing.scope_matcher')
->isBackendRequest(System::getContainer()->get('request_stack')->getCurrentRequest() ?? Request::create(''))
)
{
$GLOBALS['TL_CSS'][] = 'bundles/jonnyspvegas/vegas/vegasbe.css|static';
}
};


/**
* Front end modules
*/
array_insert($GLOBALS['TL_CTE'], 1, array
(
'includes' => array
///**
// * Front end modules
// */
ArrayUtil::arrayInsert($GLOBALS['TL_CTE'], 1, array
(
'includes' => array
(
'vegas' => 'VegasViewer'
)
)
));
);

array_insert($GLOBALS['FE_MOD'], 2, array
(
'miscellaneous' => array

ArrayUtil::arrayInsert($GLOBALS['FE_MOD'], 2, array
(
'vegas' => 'ModuleVegas'
'miscellaneous' => array
(
'vegas' => 'ModuleVegas'
)
)
));
);
34 changes: 25 additions & 9 deletions src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
<?php

$GLOBALS['TL_DCA']['tl_content']['palettes']['vegas'] = '{type_legend},type;{vegas_legend},vegas;{protected_legend:hide},protected;{expert_legend:hide},cssID,space;{invisible_legend:hide},invisible,start,stop';
/*
* Copyright (c) 2005-2024 Jonny Spitzner
*
* @license LGPL-3.0+
*/

use Contao\System;
use Contao\Backend;
use Vegas\Model\VegasModel;
use Contao\DataContainer;
use Contao\StringUtil;
use Contao\Image;

$GLOBALS['TL_DCA']['tl_content']['palettes']['vegas'] = '{type_legend},type;{vegas_legend},vegas;{protected_legend:hide},protected;{expert_legend:hide},cssID,space;{invisible_legend:hide},invisible,start,stop';
$GLOBALS['TL_DCA']['tl_content']['fields']['vegas'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_content']['vegas'],
'inputType' => 'select',
'options_callback' => array('tl_content_vegas', 'getVegas'),
'eval' => array('mandatory'=>true, 'chosen'=>true, 'submitOnChange'=>true),
'eval' => array('includeBlankOption' => true,'mandatory'=>true, 'chosen'=>true, 'submitOnChange'=>true),
'wizard' => array(array('tl_content_vegas', 'editVegas')),
'sql' => "int(10) unsigned NOT NULL default '0'"
);


class tl_content_vegas extends Backend
{

public function getVegas()
public function getVegas(): array
{
$objVegas = \VegasModel::findAll();
$arrVegas = array();
if( isset($objVegas)){

if ($objVegas = VegasModel::findAll())
{
foreach ($objVegas as $itemVegas)
{
$arrVegas[$itemVegas->id] = $itemVegas->title . ' (ID ' . $itemVegas->id . ')';
$arrVegas[$itemVegas->id] =' [ID ' . $itemVegas->id . '] - '. $itemVegas->title ;
}
}

return $arrVegas;
}

public function editVegas(DataContainer $dc)
public function editVegas(DataContainer $dc): string
{
$this->loadLanguageFile('tl_vegas');
return ($dc->value < 1) ? '' : ' <a href="contao/main.php?do=vegas&amp;act=edit&amp;id=' . $dc->value . '&amp;popup=1&amp;nb=1&amp;rt=' . REQUEST_TOKEN . '" title="' . sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['tl_vegas']['edit'][1]), $dc->value) . '" onclick="Backend.openModalIframe({\'title\':\'' . StringUtil::specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['tl_vegas']['edit'][1], $dc->value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.svg', $GLOBALS['TL_LANG']['tl_vegas']['edit'][0]) . '</a>';
$title = sprintf($GLOBALS['TL_LANG']['tl_vegas']['editheader'][1], $dc->value);
$href = System::getContainer()->get('router')->generate('contao_backend', array('do'=>'vegas', 'table'=>'tl_vegas','act'=>'edit', 'id'=>$dc->value , 'popup'=>'1', 'nb'=>'1'));

return ' <a href="' . StringUtil::specialcharsUrl($href) . '" title="' . StringUtil::specialchars($title) . '" onclick="Backend.openModalIframe({\'title\':\'' . StringUtil::specialchars(str_replace("'", "\\'", $title)) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.svg', $title) . '</a>';

}

}
32 changes: 25 additions & 7 deletions src/Resources/contao/dca/tl_module.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,56 @@
<?php

/*
* Copyright (c) 2005-2024 Jonny Spitzner
*
* @license LGPL-3.0+
*/

use Contao\System;
use Contao\Backend;
use Vegas\Model\VegasModel;
use Contao\DataContainer;
use Contao\StringUtil;
use Contao\Image;

$GLOBALS['TL_DCA']['tl_module']['palettes']['vegas'] = '{title_legend},name,vegas,type;';

$GLOBALS['TL_DCA']['tl_module']['fields']['vegas'] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_module']['vegas'],
'inputType' => 'select',
'options_callback' => array('tl_module_vegas', 'getVegas'),
'eval' => array('mandatory'=>true, 'chosen'=>true, 'submitOnChange'=>true,'tl_class'=>'w50'),
'eval' => array('includeBlankOption' => true,'mandatory'=>true, 'chosen'=>true, 'submitOnChange'=>true,'tl_class'=>'w50'),
'wizard' => array(array('tl_module_vegas', 'editVegas')),
'sql' => "int(10) unsigned NOT NULL default '0'"
);

class tl_module_vegas extends Backend
{

public function getVegas()
public function getVegas(): array
{
$objVegas = \VegasModel::findAll();
$arrVegas = array();
if(isset($objVegas)){

if ($objVegas = VegasModel::findAll())
{
foreach ($objVegas as $itemVegas)
{
$arrVegas[$itemVegas->id] = '[ID ' . $itemVegas->id . '] - '. $itemVegas->title;
$arrVegas[$itemVegas->id] =' [ID ' . $itemVegas->id . '] - '. $itemVegas->title ;
}
}

return $arrVegas;
}

public function editVegas(DataContainer $dc)
public function editVegas(DataContainer $dc): string
{
$this->loadLanguageFile('tl_vegas');
return ($dc->value < 1) ? '' : ' <a href="contao/main.php?do=vegas&amp;act=edit&amp;id=' . $dc->value . '&amp;popup=1&amp;nb=1&amp;rt=' . REQUEST_TOKEN . '" title="' . sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['tl_vegas']['edit'][1]), $dc->value) . '" onclick="Backend.openModalIframe({\'title\':\'' . StringUtil::specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['tl_vegas']['edit'][1], $dc->value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.svg', $GLOBALS['TL_LANG']['tl_vegas']['edit'][0]) . '</a>';
$title = sprintf($GLOBALS['TL_LANG']['tl_vegas']['editheader'][1], $dc->value);
$href = System::getContainer()->get('router')->generate('contao_backend', array('do'=>'vegas', 'table'=>'tl_vegas','act'=>'edit', 'id'=>$dc->value , 'popup'=>'1', 'nb'=>'1'));

return ' <a href="' . StringUtil::specialcharsUrl($href) . '" title="' . StringUtil::specialchars($title) . '" onclick="Backend.openModalIframe({\'title\':\'' . StringUtil::specialchars(str_replace("'", "\\'", $title)) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.svg', $title) . '</a>';

}

}
Loading

0 comments on commit 4baa037

Please sign in to comment.