diff --git a/BackendModule/ConfigClientModule.php b/BackendModule/ConfigClientModule.php index dc963e1..f8020c1 100644 --- a/BackendModule/ConfigClientModule.php +++ b/BackendModule/ConfigClientModule.php @@ -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(); } @@ -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; diff --git a/Connection/ClientSetup.php b/Connection/ClientSetup.php index 1b8bfd2..e49e835 100644 --- a/Connection/ClientSetup.php +++ b/Connection/ClientSetup.php @@ -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); } @@ -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 { @@ -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) ) diff --git a/Connection/MasterConnection.php b/Connection/MasterConnection.php index 3673666..bbe25c7 100644 --- a/Connection/MasterConnection.php +++ b/Connection/MasterConnection.php @@ -53,7 +53,14 @@ public static function getInstance() return self::$instance; } - + + + + public function testConnection() + { + return $this->getActionData("testConnection", array(), true); + } + public function setPassword( $pwd ) @@ -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; @@ -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); } @@ -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 { @@ -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; } @@ -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") ); } } } diff --git a/EventListener/PageListener.php b/EventListener/PageListener.php index a38552f..3fd6d64 100644 --- a/EventListener/PageListener.php +++ b/EventListener/PageListener.php @@ -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 ) @@ -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 ) @@ -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('/