Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pressi committed Jan 11, 2018
1 parent 020fc2b commit c0bfb14
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Config/BundleConfig.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*******************************************************************
* (c) 2017 Stephan Preßl, www.prestep.at <[email protected]>
* (c) 2018 Stephan Preßl, www.prestep.at <[email protected]>
* All rights reserved
* Modification, distribution or any other action on or with
* this file is permitted unless explicitly granted by IIDO
Expand Down
5 changes: 1 addition & 4 deletions ConnectTool.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php
/*******************************************************************
*
* (c) 2017 Stephan Preßl, www.prestep.at <[email protected]>
* (c) 2018 Stephan Preßl, www.prestep.at <[email protected]>
* All rights reserved
*
* Modification, distribution or any other action on or with
* this file is permitted unless explicitly granted by IIDO
* www.iido.at <[email protected]>
*
*******************************************************************/

namespace IIDO\BasicBundle;
Expand Down
5 changes: 1 addition & 4 deletions ConnectToolUser.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php
/*******************************************************************
*
* (c) 2017 Stephan Preßl, www.prestep.at <[email protected]>
* (c) 2018 Stephan Preßl, www.prestep.at <[email protected]>
* All rights reserved
*
* Modification, distribution or any other action on or with
* this file is permitted unless explicitly granted by IIDO
* www.iido.at <[email protected]>
*
*******************************************************************/

namespace IIDO\BasicBundle;
Expand Down
5 changes: 1 addition & 4 deletions ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php
/*******************************************************************
*
* (c) 2017 Stephan Preßl, www.prestep.at <[email protected]>
* (c) 2018 Stephan Preßl, www.prestep.at <[email protected]>
* All rights reserved
*
* Modification, distribution or any other action on or with
* this file is permitted unless explicitly granted by IIDO
* www.iido.at <[email protected]>
*
*******************************************************************/

namespace IIDO\BasicBundle\ContaoManager;
Expand Down
2 changes: 1 addition & 1 deletion Helper/ContentHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*******************************************************************
* (c) 2017 Stephan Preßl, www.prestep.at <[email protected]>
* (c) 2018 Stephan Preßl, www.prestep.at <[email protected]>
* All rights reserved
* Modification, distribution or any other action on or with
* this file is permitted unless explicitly granted by IIDO
Expand Down
56 changes: 49 additions & 7 deletions Helper/DcaHelper.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<?php
/******************************************************************
*
* (c) 2015 Stephan Preßl <[email protected]>
/*******************************************************************
* (c) 2018 Stephan Preßl, www.prestep.at <[email protected]>
* All rights reserved
*
* Modification, distribution or any other action on or with
* this file is permitted unless explicitly granted by IIDO
* www.iido.at <[email protected]>
*
******************************************************************/
*******************************************************************/

namespace IIDO\BasicBundle\Helper;


use IIDO\BasicBundle\Table\AllTables;


/**
* Class Helper
* Class DCA Helper
*
* @package IIDO\BasicBundle
*/
class DcaHelper extends \Frontend
Expand Down Expand Up @@ -63,6 +64,10 @@ public static function addField($fieldName, $fieldType, $strTable, $eval = array
// self::addTextField($fieldName, $strTable, $eval, $classes, $replaceClasses, $langTable, $defaultConfig);
break;

case "alias":
self::addAliasField($fieldName, $strTable, $eval, $classes, $replaceClasses, $langTable);
break;

case "color":
case "colorfield":
self::addColorField($fieldName, $strTable, $eval, $classes, $replaceClasses, $langTable);
Expand Down Expand Up @@ -777,6 +782,43 @@ public static function addUrlField($fieldName, $strTable, $eval = array(), $clas



public static function addAliasField($fieldName, $strTable, $eval = array(), $classes = '', $replaceClasses = false, $langTable = '')
{
if( strlen($langTable) )
{
\Controller::loadLanguageFile( $langTable );
}

$defaultEval = array
(
'rgxp' => 'alias',
'doNotCopy' => true,
'maxlength' => 128,
'tl_class' => ($replaceClasses ? $classes : 'w50 clr' . (strlen($classes) ? ' ' . $classes : ''))
);

if( count($eval) )
{
$defaultEval = array_merge($defaultEval, $eval);
}

$GLOBALS['TL_DCA'][ $strTable ]['fields'][ $fieldName ] = array
(
'label' => &$GLOBALS['TL_LANG']['tl_article']['alias'],
'exclude' => true,
'inputType' => 'text',
'search' => true,
'eval' => $defaultEval,
'save_callback' => array
(
array(AllTables::class, 'generateAlias')
),
'sql' => "varchar(" . $defaultEval['maxlength']?:128 . ") COLLATE utf8mb4_bin NOT NULL default ''"
);
}



public static function addProtectedFieldsToTable( $strTable, $toPalette = '', $replaceLegend = '', $replacePosition = 'after' )
{
\Controller::loadLanguageFile( $strTable );
Expand Down
5 changes: 1 addition & 4 deletions IIDOBasicBundle.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php
/*******************************************************************
*
* (c) 2017 Stephan Preßl, www.prestep.at <[email protected]>
* (c) 2018 Stephan Preßl, www.prestep.at <[email protected]>
* All rights reserved
*
* Modification, distribution or any other action on or with
* this file is permitted unless explicitly granted by IIDO
* www.iido.at <[email protected]>
*
*******************************************************************/

namespace IIDO\BasicBundle;
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/listener.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ services:
class: IIDO\BasicBundle\Table\AllTables


iido_website.twig_extension:
iido_basic.twig_extension:
class: IIDO\BasicBundle\Twig\AppExtension
public: false
tags:
Expand Down
10 changes: 5 additions & 5 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ services:
arguments:
- "@session"

contao.connect_tool_twig_extension:
class: SensioLabs\AnsiConverter\Bridge\Twig\AnsiExtension
public: false
tags:
- { name: twig.extension }
# contao.connect_tool_twig_extension:
# class: SensioLabs\AnsiConverter\Bridge\Twig\AnsiExtension
# public: false
# tags:
# - { name: twig.extension }
67 changes: 63 additions & 4 deletions Table/AllTables.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php
/*******************************************************************
*
* (c) 2017 Stephan Preßl, www.prestep.at <[email protected]>
* (c) 2018 Stephan Preßl, www.prestep.at <[email protected]>
* All rights reserved
*
* Modification, distribution or any other action on or with
* this file is permitted unless explicitly granted by IIDO
* www.iido.at <[email protected]>
*
*******************************************************************/

namespace IIDO\BasicBundle\Table;
Expand Down Expand Up @@ -199,4 +196,66 @@ public function rewFilePicker(\DataContainer $dc)
{
return ' <a href="contao/file.php?do='.\Input::get('do').'&amp;table='.$dc->table.'&amp;field='.preg_replace('/_row[0-9]*_/i', '__', $dc->field).'&amp;value='.$dc->value.'" title="'.specialchars(str_replace("'", "\\'", $GLOBALS['TL_LANG']['MSC']['filepicker'])).'" onclick="Backend.getScrollOffset();Backend.openModalSelector({\'width\':765,\'title\':\''.specialchars($GLOBALS['TL_LANG']['MOD']['files'][0]).'\',\'url\':this.href,\'id\':\''.$dc->field.'\',\'tag\':\'ctrl_'.$dc->field . ((\Input::get('act') == 'editAll') ? '_' . $dc->id : '').'\',\'self\':this});return false">' . \Image::getHtml('pickfile.gif', $GLOBALS['TL_LANG']['MSC']['filepicker'], 'style="vertical-align:top;cursor:pointer"') . '</a>';
}



/**
* Auto-generate an article alias if it has not been set yet
*
* @param mixed $varValue
* @param \DataContainer $dc
*
* @return string
*
* @throws \Exception
*/
public function generateAlias($varValue, \DataContainer $dc)
{
echo "<pre>"; print_r( $dc ); exit;
$prefix = 'article-';
$strTable = '';

$autoAlias = false;

// Generate an alias if there is none
if ($varValue == '')
{
$autoAlias = true;
$slugOptions = array();

// Read the slug options from the associated page
if (($objPage = \PageModel::findWithDetails($dc->activeRecord->pid)) !== null)
{
$slugOptions['locale'] = $objPage->language;

if ($objPage->validAliasCharacters)
{
$slugOptions['validChars'] = $objPage->validAliasCharacters;
}
}

$varValue = \System::getContainer()->get('contao.slug.generator')->generate(\StringUtil::stripInsertTags($dc->activeRecord->title), $slugOptions);
}

// Add a prefix to reserved names (see #6066)
if ($strTable === "tl_article" && \in_array($varValue, array('top', 'wrapper', 'header', 'container', 'main', 'left', 'right', 'footer')))
{
$varValue = $prefix . $varValue;
}

$objAlias = \Database::getInstance()->prepare("SELECT id FROM " . $strTable . " WHERE id=? OR alias=?")->execute($dc->id, $varValue);

// Check whether the page alias exists
if ($objAlias->numRows > 1)
{
if (!$autoAlias)
{
throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
}

$varValue .= '-' . $dc->id;
}

return $varValue;
}
}
13 changes: 6 additions & 7 deletions Twig/AppExtension.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php
/***************************************************************************
*
* (c) 2016 Stephan Preßl, www.stephanpressl.at <[email protected]>
/*******************************************************************
* (c) 2018 Stephan Preßl, www.prestep.at <[email protected]>
* All rights reserved
*
* Modification, distribution or any other action on or with
* this file is permitted unless explicitly granted by Stephan Preßl
*
***************************************************************************/
* this file is permitted unless explicitly granted by IIDO
* www.iido.at <[email protected]>
*******************************************************************/

namespace IIDO\BasicBundle\Twig;


Expand Down
4 changes: 2 additions & 2 deletions Util/ColorUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0
*/
namespace IIDO\BasicBundle\Util;

namespace IIDO\BasicBundle\Util;

if ( ! class_exists( 'ColorUtil' ) )
if ( !class_exists( 'ColorUtil' ) )
{

/**
Expand Down

0 comments on commit c0bfb14

Please sign in to comment.