Skip to content

Commit

Permalink
some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pressi committed Jun 19, 2017
1 parent b091e0c commit e5d5be0
Show file tree
Hide file tree
Showing 63 changed files with 2,122 additions and 200 deletions.
146 changes: 141 additions & 5 deletions ConnectTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,19 @@ public function connectionLost()
{
$arrData = $this->testConnection();

if( key_exists("ERROR", $arrData) )
if( is_array($arrData) && key_exists("ERROR", $arrData) )
{
if( $arrData[ 'ERROR' ] === $this->container->get("translator")->trans("connection_failed") )
{
return true;
}
}

if( !is_array($arrData) )
{
return $arrData;
}

return false;
}

Expand Down Expand Up @@ -381,6 +386,12 @@ public function getData($returnAsArray = false)
}

$objData = json_decode($arrData, $returnAsArray);
$clientID = $this->getConfig( "clientID" );

if( !$clientID )
{
$this->persistConfig("clientID", (($returnAsArray) ? $objData['clientID'] : $objData->clientID) );
}

return $objData;
}
Expand All @@ -391,14 +402,51 @@ public function getActionData( $actionName, array $actionParams = array(), $retu
{
if( $actionName == "checkPassword" )
{
// $this->setPassword( $actionParams['pwd'] );
$this->setPassword( $actionParams['pwd'] );
unset( $actionParams['pwd'] );
}

$connectionUrl = $this->getConnectionUrl() . '&act=' . $actionName . (count($actionParams)?'&':'') . implode('&', $actionParams);
$arrData = @file_get_contents( $connectionUrl );
// $opts = array
// (
// 'http'=>array
// (
// 'method'=>"GET",
// 'header'=>"Cache-Control: no-store, no-cache, must-revalidate, max-age=0\r\n" .
// "Cache-Control: post-check=0, pre-check=0\r\n" .
// "Pragma: no-cache\r\n" .
// "Content-Type: application/json;charset=utf-8"
// )
// );

// $context = stream_context_create($opts);

$arrParams = array();

if( count($actionParams) )
{
foreach($actionParams as $paramKey => $paramValue)
{
$param = $paramKey . '=' . $paramValue;

if( is_numeric($paramKey) )
{
$param = $paramValue;
}

$arrParams[] = $param;
}
}

$connectionUrl = $this->getConnectionUrl() . '&act=' . $actionName . (count($arrParams)?'&':'') . implode('&', $arrParams);
// $arrData = trim(file_get_contents( $connectionUrl, false, $context ), "\xEF\xBB\xBF");
$arrData = file_get_contents( $connectionUrl );
$return = false;
//echo "<pre>";
//print_r( $connectionUrl );
// print_r( $arrData );
//echo "</pre>";

//print_r( parse)
if( !$arrData )
{
if( !$returnBoolean )
Expand All @@ -409,6 +457,19 @@ public function getActionData( $actionName, array $actionParams = array(), $retu
else
{
$return = json_decode($arrData, $returnAsArray);

if( !is_array($return) && !is_object($return) )
{
$return = json_decode($return, $returnAsArray);
}
}

if( $returnBoolean )
{
if( key_exists('ERROR', $return) )
{
return false;
}
}

return $returnBoolean ? true : $return;
Expand Down Expand Up @@ -482,7 +543,7 @@ protected function getPassword()



public function setUpFiles( $arrFiles )
public function setUpFilesFolder( $arrFiles )
{
$arrFolders = array();

Expand All @@ -499,6 +560,11 @@ public function setUpFiles( $arrFiles )
$objFolder = new \Folder( $strFolderPath );
}

// if( $objFolder )
// {
// $objFolder->protected =
// }

$arrFolders[] = $objFolder->path;

if( is_array($arrSubfolders) && count($arrSubfolders) && $objFolder && is_dir( $this->rootDir . '/../' . $objFolder->path) )
Expand Down Expand Up @@ -548,6 +614,9 @@ public function createNewOneModelEntry($modelName, array $arrModelValue, array $
{
if( is_array($arrModelValue) && count($arrModelValue) )
{
$request = $this->container->get('request_stack')->getCurrentRequest();
$customerAlias = $request->request->get('customer_alias');

$modelClass = '\\' . $modelName . 'Model';
$objModel = new $modelClass();

Expand All @@ -560,6 +629,14 @@ public function createNewOneModelEntry($modelName, array $arrModelValue, array $

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

if( $valueVar == "password" )
{
if( !preg_match('/^[a-f0-9]{32}$/', $valueVarValue) )
{
$valueVarValue = md5( $valueVarValue );
}
}

$objModel->$valueVar = $valueVarValue;
}

Expand All @@ -575,10 +652,42 @@ public function createNewOneModelEntry($modelName, array $arrModelValue, array $

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

if( $key == "password" )
{
if( !preg_match('/^[a-f0-9]{32}$/', $value) )
{
$value = md5( $value );
}
}

$objModel->$key = $value;
}
}

if( $modelName === "Theme" )
{
$objModel->templates = 'templates/' . $customerAlias;

$arrFolders = array();
$objMasterFolder = \FilesModel::findByPath("files/master");
$objCustomerFolder = \FilesModel::findByPath("files/" . $customerAlias );

if( $objMasterFolder )
{
$arrFolders[] = $objMasterFolder->uuid;
}

if( $objCustomerFolder )
{
$arrFolders[] = $objCustomerFolder->uuid;
}

if( count($arrFolders) )
{
$objModel->folders = serialize($arrFolders);
}
}

return $objModel->save();
}

Expand Down Expand Up @@ -819,6 +928,11 @@ public function replaceVars( $varValue )
{
$varValue = $request->request->get("customer_name");
}

if( $arrParts[1] === "websiteTitle" )
{
$varValue = $this->renderTitleString( $varValue );
}
}
elseif( $arrParts[0] == "cms" )
{
Expand Down Expand Up @@ -858,4 +972,26 @@ public function isConnectToolInitialized()
{
return $this->getConfig("iido_initSystem");
}



protected function renderTitleString( $strTitle )
{
$strTitle = preg_replace(array('/ä/', '/ö/', '/ü/', '/Ä/', '/Ö/', '/Ü/'), array(';ae;', ';oe;', ';ue;', ';AE;', ';OE;', ';UE;'), $strTitle);
$strTitle = preg_replace('/ß/', ';ss;', $strTitle);
$strTitle = preg_replace('/ /', '+', $strTitle);

return $strTitle;
}



protected function getFilesFromMaster( $arrFolders )
{
$arrData = $this->getActionData("getFolderFiles", array('foldersPath'=>implode(",", $arrFolders)));

echo "<pre>";
print_r( $arrData->files );
exit;
}
}
38 changes: 38 additions & 0 deletions ContentElement/NavigationElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2017 Leo Feyer
*
* @license LGPL-3.0+
*/

namespace IIDO\BasicBundle\ContentElement;

use IIDO\BasicBundle\Helper\BasicHelper;


/**
* Front end content element "text".
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
class NavigationElement extends \ContentElement
{

/**
* Template
* @var string
*/
protected $strTemplate = 'ce_navigation';


/**
* Generate the content element
*/
protected function compile()
{
$this->Template->content = BasicHelper::renderNavigation( $this->navModule, 'main', $this->cssID[1] );
}
}
11 changes: 7 additions & 4 deletions Controller/ConnectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,22 +290,24 @@ private function setUpClient( $connectTool )

$arrData = $connectTool->getActionData("getContaoInit", array('themeID=' . $themeID) );

$connectTool->setUpFiles( $arrData->files );
$connectTool->setUpFilesFolder( $arrData->folders );
$connectTool->setUpTemplates( $arrData->templates );

// $connectTool->getFilesFromMaster( $arrData->files );

$arrTheme = (array) $arrData->theme;
unset($arrTheme['layouts']);
unset($arrTheme['modules']);
unset($arrTheme['imageSizes']);
unset($arrTheme['imageSizeItems']);

$connectTool->createNewOneModelEntry("Theme", $arrTheme, array('master_ID', $themeID));
$connectTool->createNewOneModelEntry("Theme", $arrTheme, array('master_ID' => $themeID));

// Create Layouts
$connectTool->createNewModelEntry("Layout", (array) $arrData->theme->layouts, array('master_ID', 'field_id'));
$connectTool->createNewModelEntry("Layout", (array) $arrData->theme->layouts, array('master_ID' => 'field_id'));

// Create Modules
$connectTool->createNewModelEntry("Module", (array) $arrData->theme->modules, array('master_ID', 'field_id'));
$connectTool->createNewModelEntry("Module", (array) $arrData->theme->modules, array('master_ID' => 'field_id'));

// Create Image Sizes
$connectTool->createNewModelEntry("ImageSize", (array) $arrData->theme->imageSizes);
Expand Down Expand Up @@ -368,6 +370,7 @@ private function setUpClient( $connectTool )
}

$connectTool->persistConfig( 'iido_initSystem', TRUE);
$connectTool->persistConfig( 'clientID', $arrData->clientID);

return $this->getRedirectResponse();
}
Expand Down
11 changes: 7 additions & 4 deletions EventListener/CombinerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function getCustomizeCombinedFile($strContent, $strKey, $strMode, &$arrFi
// {
// $varName .= '_' . $objCurPage->alias;
// }
$varValue = preg_replace('/&#35;/', '#', $varValue);
$varValue = preg_replace(array('/&#35;/', '/&#40;/', '/&#41;/'), array('#', '(', ')'), $varValue);
}

$strContent = preg_replace('/\/\*#' . $varName . '#\*\/' . $add . '/', $varValue, $strContent);
Expand All @@ -124,9 +124,12 @@ public function getCustomizeCombinedFile($strContent, $strKey, $strMode, &$arrFi
{
if( $isInFiles || $isInBundle )
{
$objMinify = new Minify\JS();
$objMinify->add( $strContent );
$strContent = $objMinify->minify();
if( !preg_match('/min' . \Combiner::JS . '$/', trim($arrFile['name'])) )
{
$objMinify = new Minify\JS();
$objMinify->add( $strContent );
$strContent = $objMinify->minify();
}
}
}

Expand Down
Loading

0 comments on commit e5d5be0

Please sign in to comment.