Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pressi committed Apr 11, 2017
1 parent d765db2 commit d974f64
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 27 deletions.
19 changes: 18 additions & 1 deletion BackendModule/ConfigClientModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ public function generate()
}
}

$connection = MasterConnection::getInstance()->testConnection();

if( key_exists("ERROR", $connection) )
{
if( preg_match('/connection failed/', strtolower($connection['ERROR'])) )
{
$this->strTemplate = 'be_mod_iido_errorMaster';
\Session::getInstance()->set("iidoMessage", $connection['ERROR']);
return parent::generate();
}
}

return parent::generate();
}

Expand All @@ -92,8 +104,13 @@ protected function compile()
if( is_array($arrMessage) && count($arrMessage) )
{
$strMessage = Message::render($arrMessage);
\Session::getInstance()->remove("iidoMessage");
}
else
{
$strMessage = Message::render( array("error"=>$arrMessage) );
}

\Session::getInstance()->remove("iidoMessage");
}

$this->Template->masterData = $masterData;
Expand Down
40 changes: 38 additions & 2 deletions Connection/ClientSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ protected function setUpContao()

$varValue = $this->replaceVars( $varValue );

$this->Config->update( "\$GLOBALS['TL_CONFIG']['" . $varName . "']", $varValue);
$this->Config->persist( $varName, $varValue);
// $this->Config->update( "\$GLOBALS['TL_CONFIG']['" . $varName . "']", $varValue);
}

$this->Config->update( "\$GLOBALS['TL_CONFIG']['']", TRUE);
// $this->Config->update( "\$GLOBALS['TL_CONFIG']['']", TRUE);
// $this->Config->persist( 'iido_initSystem', TRUE);
}


Expand Down Expand Up @@ -366,6 +368,32 @@ protected function replaceVars( $varValue )
$funcName = $arrParts[1];
$varValue = str_replace($strChunk, $funcName(), $varValue);
}
elseif( $arrParts[0] == "env" )
{
$varValue = \Environment::get( $arrParts[1] );
}
elseif( $arrParts[0] == "config" )
{
$varValue = \Config::get( $arrParts[1] );
}
elseif( $arrParts[0] == "cms" )
{
switch( $arrParts[1] )
{
case "version":
$packages = System::getContainer()->getParameter('kernel.packages');
$varValue = $packages['contao/core-bundle'];
break;

case "bundles":
$varValue = array_keys(System::getContainer()->getParameter('kernel.bundles') );
break;

case "packages":
$varValue = System::getContainer()->getParameter('kernel.packages');
break;
}
}
}
else
{
Expand All @@ -382,6 +410,14 @@ protected function replaceVars( $varValue )



public static function replaceStaticVars( $strContent )
{
$self = new self();
return $self->replaceVars( $strContent );
}



protected function createPages( array $arrPages, array $arrAddToPage = array() )
{
if( is_array($arrPages) && count($arrPages) )
Expand Down
74 changes: 68 additions & 6 deletions Connection/MasterConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,14 @@ public static function getInstance()

return self::$instance;
}




public function testConnection()
{
return $this->getActionData("testConnection", array(), true);
}



public function setPassword( $pwd )
Expand All @@ -80,7 +87,13 @@ public function isPasswordValid()
public function getData($returnAsArray = false)
{
$connectionUrl = $this->getConnectionUrl();
$arrData = file_get_contents( $connectionUrl );
$arrData = @file_get_contents( $connectionUrl );

if( !$arrData )
{
return array("ERROR" => 'Connection Failed. Master not available! Please try again later.');
}

$objData = json_decode($arrData, $returnAsArray);

return $objData;
Expand All @@ -91,7 +104,12 @@ public function getData($returnAsArray = false)
public function getActionData( $actionName, array $actionParams = array(), $returnAsArray = false)
{
$connectionUrl = $this->getConnectionUrl() . '&act=' . $actionName . (count($actionParams)?'&':'') . implode('&', $actionParams);
$arrData = file_get_contents( $connectionUrl );
$arrData = @file_get_contents( $connectionUrl );

if( !$arrData )
{
return array("ERROR" => 'Connection Failed. Master not available! Please try again later.');
}

return json_decode($arrData, $returnAsArray);
}
Expand All @@ -115,7 +133,7 @@ public function redirectTo( $method = "", array $msg = array() )

if( $method )
{
\Controller::redirect( \Controller::addToUrl("do=iidoConfigContao&method=" . $method) );
\Controller::redirect( \Controller::addToUrl("do=iidoConfigContao&method=" . $method) );
}
else
{
Expand All @@ -135,7 +153,51 @@ public static function redirect( $method = "", array $msg = array() )
protected function getConnectionUrl()
{
$configData = $this->getConfigData();
return $configData->domain . $configData->connection->publicPath . $configData->connection->file . '?pwd=' . static::$password;
return $configData->domain . $configData->connection->publicPath . $configData->connection->file . '?pwd=' . static::$password . $this->getConnectionUrlVars( $configData );
}



protected function getConnectionUrlVars( $configData = NULL )
{
$requestVars = "";

if( $configData === NULL )
{
$configData = $this->getConfigData();
}

foreach( (array) $configData->vars as $varName => $varData )
{
$varDataParsed = "";
$varData = \StringUtil::deserialize( $varData );

if( is_string($varData) )
{
$varDataParsed = $varData;
}
else
{
$arrVarData = array();

foreach( (array) $varData as $key => $value )
{
$arrVarData[ $key ] = ClientSetup::replaceStaticVars( $value );
}

if( count($arrVarData) )
{
$varDataParsed = json_encode( $arrVarData );
}
}

if( $varDataParsed )
{
$requestVars .= '&' . $varName . '=' . $varDataParsed;
}
}

return $requestVars;
}


Expand All @@ -148,7 +210,7 @@ protected function validate( array $arrData )
{
if( !\Input::get("method") == "login" )
{
\Controller::redirect( \Controller::addToUrl("do=iidoConfigContao&method=login") );
\Controller::redirect( \Controller::addToUrl("do=iidoConfigContao&method=login") );
}
}
}
Expand Down
37 changes: 20 additions & 17 deletions EventListener/PageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public function generateCustomizePage( \PageModel $objPage, \LayoutModel $objLay
// $GLOBALS['TL_JAVASCRIPT'][] = 'web/bundles/' . $folderName . '/javascript/' . $jsPrefix . '/waypoints/inview.min.js|static';
// $GLOBALS['TL_JAVASCRIPT'][] = 'web/bundles/' . $folderName . '/javascript/' . $jsPrefix . '/waypoints/sticky.min.js|static';

$GLOBALS['TL_JAVASCRIPT'][] = $this->bundlePathPublic . '/javascript/' . $jsPrefix . '/iido/IIDO.Base.js|static';
$GLOBALS['TL_JAVASCRIPT']['iido_base'] = $this->bundlePathPublic . '/javascript/' . $jsPrefix . '/iido/IIDO.Base.js|static';
// $GLOBALS['TL_JAVASCRIPT'][] = 'web/bundles/' . $folderName . '/javascript/' . $jsPrefix . '/iido/IIDO.Functions.js|static';
$GLOBALS['TL_JAVASCRIPT'][] = $this->bundlePathPublic . '/javascript/' . $jsPrefix . '/iido/IIDO.Page.js|static';
$GLOBALS['TL_JAVASCRIPT']['iido_page'] = $this->bundlePathPublic . '/javascript/' . $jsPrefix . '/iido/IIDO.Page.js|static';
// $GLOBALS['TL_JAVASCRIPT'][] = 'web/bundles/' . $folderName . '/javascript/' . $jsPrefix . '/iido/IIDO.Content.js|static';

// if( $objLayout->loadJQueryUI )
Expand All @@ -126,7 +126,7 @@ public function generateCustomizePage( \PageModel $objPage, \LayoutModel $objLay

if( $footerMode )
{
$GLOBALS['TL_CSS'][] = $this->bundlePathPublic . '/css/footer.css||static';
$GLOBALS['TL_CSS']['footer'] = $this->bundlePathPublic . '/css/footer.css||static';
}

if( $objLayout->loadDomainCSS )
Expand Down Expand Up @@ -287,39 +287,42 @@ public function modifyCustomizeFrontendPage($strBuffer, $templateName)
{
if( preg_match('/open-fullscreen-search/', $strBuffer) )
{
$strModule = \Controller::getFrontendModule( 3 );
$pregMatch = '([A-Za-z0-9\s\-=",;.:_]{0,})';
$objModule = \ModuleModel::findOneBy("type", "search");

if( $objModule )
{
$strModule = \Controller::getFrontendModule( $objModule->id ); //6
$pregMatch = '([A-Za-z0-9\s\-=",;.:_]{0,})';

// if( preg_match('/<div' . $pregMatch . 'class="mod_search([A-Za-z0-9\s\-_]{0,})"' . $pregMatch . '>/', $strModule, $arrMatches) )
// {
// $strModule = preg_replace('/' . preg_quote($arrMatches[0], '/') . '/', '', $strModule);
// $strModule = preg_replace('/<\div>$/', '', trim($strModule));

// $strModule = preg_replace('/<form/', '<form class="' . trim(preg_replace('/block/', '', $arrMatches[2])) . '"', trim($strModule));
// }

// $strModule = preg_replace('/<div class="formbody">/', '', $strModule);
// $strModule = preg_replace('/<\/div>([\s\n]{0,})<\/form>/', '</form>', $strModule);

$strModule = preg_replace('/<input' . $pregMatch . 'type="submit"' . $pregMatch . 'value="([A-Za-z0-9öäüÖÄÜß]{0,})"' . $pregMatch . '>/', '<button$1type="submit"$2$4>$3</button>', $strModule);

$strModule = preg_replace('/<\/form>/', '<a href="" class="fullscreen-search-form-close">close</a></form>', $strModule);

$strBuffer = preg_replace('/<\/body>/', $strModule . '</body>', $strBuffer);
$strModule = preg_replace('/<input' . $pregMatch . 'type="submit"' . $pregMatch . 'value="([A-Za-z0-9öäüÖÄÜß]{0,})"' . $pregMatch . '>/', '<button$1type="submit"$2$4>$3</button>', $strModule);
$strModule = preg_replace('/<\/form>/', '<a href="" class="fullscreen-search-form-close">close</a></form>', $strModule);
$strBuffer = preg_replace('/<\/body>/', $strModule . '</body>', $strBuffer);
}
}

// Mobile Menü
$menuOpen = '<a href="javascript:void(0)" class="main-navigation-mobile-open">navigation</a>';
$menuClose = '<button class=" main-navigation-mobile-close">close</button>';

$objNavModule = \ModuleModel::findOneBy("type", "navigation");

// //TODO: set module ID flexible, make a change posible
// $modSearch = \Controller::getFrontendModule( 10 );
// $modNavi = \Controller::getFrontendModule( 11 );
// $modSocial = ''; //TODO: Add Socialmedia links
$modSearch = ''; //\Controller::getFrontendModule( 10 );
$modNavi = \Controller::getFrontendModule( $objNavModule->id ); // 11
$modSocial = ''; //TODO: Add Socialmedia links

// $menuMobile = '<div class="main-navigation-mobile">' . $modSearch . $modNavi . $modSocial . $menuClose . '</div>';
$menuMobile = '<div class="main-navigation-mobile">' . $modSearch . $modNavi . $modSocial . $menuClose . '</div>';

// $strBuffer = preg_replace('/<body([A-Za-z0-9\s\-_,;.:\{\}\(\)="\']{0,})>/', '<body$1>' . $menuOpen . $menuMobile, $strBuffer);
$strBuffer = preg_replace('/<body([A-Za-z0-9\s\-_,;.:\{\}\(\)="\']{0,})>/', '<body$1>' . $menuOpen . $menuMobile, $strBuffer);
}

return $strBuffer;
Expand Down
10 changes: 10 additions & 0 deletions Resources/config/master-connection.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,15 @@
"path" : "Resources/public/connection/",
"publicPath" : "bundles/iidomaster/connection/",
"file" : "connect.php"
},

"vars" :
{
"request" :
{
"host" : "##env__host##",
"name" : "##config__websiteTitle##",
"version" : "##cms__version##"
}
}
}
2 changes: 1 addition & 1 deletion Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

$GLOBALS['TL_HOOKS']['getPageStatusIcon'][] = array($listenerName . '.listener.page', 'getCustomizePageStatusIcon');
$GLOBALS['TL_HOOKS']['generatePage'][] = array($listenerName . '.listener.page', 'generateCustomizePage');
//$GLOBALS['TL_HOOKS']['modifyFrontendPage'][] = array($listenerName . '.listener.page', 'modifyCustomizeFrontendPage');
$GLOBALS['TL_HOOKS']['modifyFrontendPage'][] = array($listenerName . '.listener.page', 'modifyCustomizeFrontendPage');

$GLOBALS['TL_HOOKS']['getContentElement'][] = array($listenerName . '.listener.content', 'getCustomizeContentElement');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="backend-container error-master-container">

<h2>Verbindungsfehler!</h2>

<?= $this->message ?>

</div>
20 changes: 20 additions & 0 deletions Resources/contao/templates/navigation/nav_mobile.html5
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
$expandButton = '<button class="main-navigation-mobile-expand">expand</button>';

?>
<ul class="<?= $this->level ?>" role="<?= ($this->level == 'level_1') ? 'menubar' : 'menu' ?>">
<?php foreach ($this->items as $item):
$strSubmenuMobileButton = "";

if( $item['subitems'] )
{
$strSubmenuMobileButton = $expandButton;
}
?>
<?php if ($item['isActive']): ?>
<li class="<?= $item['class'] ?>"><span class="<?= $item['class'] ?>" role="menuitem"<?php if (!empty($item['subitems'])): ?> aria-haspopup="true"<?php endif; ?>><?= $item['link'] ?></span><?= $strSubmenuMobileButton ?><?= $item['subitems'] ?></li>
<?php else: ?>
<li<?php if ($item['class']): ?> class="<?= $item['class'] ?>"<?php endif; ?>><a href="<?= $item['href'] ?: './' ?>" title="<?= $item['pageTitle'] ?: $item['title'] ?>"<?php if ($item['class']): ?> class="<?= $item['class'] ?>"<?php endif; ?><?php if ($item['accesskey'] != ''): ?> accesskey="<?= $item['accesskey'] ?>"<?php endif; ?><?php if ($item['tabindex']): ?> tabindex="<?= $item['tabindex'] ?>"<?php endif; ?><?php if ($item['nofollow']): ?> rel="nofollow"<?php endif; ?><?= $item['target'] ?> role="menuitem"<?php if (!empty($item['subitems'])): ?> aria-haspopup="true"<?php endif; ?>><?= $item['link'] ?></a><?= $strSubmenuMobileButton ?><?= $item['subitems'] ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
1 change: 1 addition & 0 deletions Resources/public/css/footer.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d974f64

Please sign in to comment.