8 require_once(CH_DIRECTORY_PATH_PLUGINS .
'myadmin/zip.lib.php');
9 require_once(CH_DIRECTORY_PATH_PLUGINS .
'myadmin/unzip.lib.php');
13 define(
'CH_SCTR_DIR_IMAGES',
'data/images/');
14 define(
'CH_SCTR_SMALL_PREFIX',
's_');
15 define(
'CH_SCTR_THEME_PREFIX',
't_');
16 define(
'CH_SCTR_THUMB_EXT',
'.jpg');
17 define(
'CH_SCTR_THEME_CONF',
'conf.php');
18 define(
'CH_SCTR_THEME_THUMB',
'thumb.jpg');
19 define(
'CH_SCTR_IMAGES_DELETE', 0);
20 define(
'CH_SCTR_IMAGES_COPY', 1);
25 $a = $aModuleOverwright ? $aModuleOverwright :
$aModule;
26 if (!$a || $a[
'uri'] !=
'site_customize') {
28 $a = $oMain->_aModule;
75 $this->_oConfig->init($this->_oDb);
76 $this->_oTemplate->initialize($this, $this->_oDb);
78 $this->_aCssMatch = $this->_oDb->getUnits();
83 $this->_oConfig->cancelSession();
85 header(
'Content-Type: text/html; charset=utf-8');
95 $this->_oConfig->doOpen();
97 $this->_oConfig->doClose();
105 $sPage = $sTarget =
'';
106 if (isset($_POST[
'page']) && isset($_POST[
'trg'])) {
110 unset($_POST[
'page']);
111 unset($_POST[
'trg']);
113 $aTmpStyle = $this->_oDb->getSiteTmp();
116 if (!
empty($aTmpStyle) && isset($aTmpStyle[$sPage][$sTarget])) {
117 foreach ($aTmpStyle[$sPage][$sTarget]
as $sKey => $sValue) {
118 if ($sKey !=
'image')
119 unset($aTmpStyle[$sPage][$sTarget][$sKey]);
123 if (isset($_FILES[
'image'])) {
125 if (strlen($sImage) > 0) {
126 if (isset($aTmpStyle[$sPage][$sTarget][
'image']))
127 $this->
_deleteImage($aTmpStyle[$sPage][$sTarget][
'image']);
129 $aTmpStyle[$sPage][$sTarget][
'image'] = $sImage;
130 if (!isset(
$aVars[
'useimage']))
131 $aVars[
'useimage'] =
'on';
135 foreach (
$aVars as $sKey => $sValue) {
136 if ($sValue !=
'' && $sValue !=
'default' && $sValue !=
'-1')
140 else if(!
empty($aTmpStyle) && isset($aTmpStyle[$sPage][$sTarget])) {
142 unset($aTmpStyle[$sPage][$sTarget]);
145 $this->_oDb->updateSiteTmp($aTmpStyle);
148 if(isset($_POST[
'action']) && !
empty($_POST[
'action'])) {
150 unset($_POST[
'action']);
153 if(isset($_POST[
'theme']) && !
empty($_POST[
'theme'])) {
154 $iTheme = (int)$_POST[
'theme'];
155 unset($_POST[
'theme']);
159 $this->_oConfig->setSessionData(array($sPage, $sTarget, 0,
''));
161 $this->_oConfig->setSessionData(array($sPage, $sTarget, $iTheme,
$sAction));
174 if ($isSave && isset($_POST[
'name_theme']) && $_POST[
'name_theme']) {
176 $aTheme = $this->_oDb->getThemeByName(
$sName);
178 if (
empty($aTheme)) {
181 if ($iThemeId != -1) {
182 $sThumb =
'thumbnail';
184 if (isset($_FILES[$sThumb]) && is_uploaded_file($_FILES[$sThumb][
'tmp_name'])) {
185 if (strpos($_FILES[$sThumb][
'type'],
'image') !==
false) {
187 $sExt =
'.' . pathinfo($_FILES[$sThumb][
'name'], PATHINFO_EXTENSION);
188 $sTmpName =
'tmp_' .
time() . $this->iUserId .
$sExt;
191 if (move_uploaded_file($_FILES[$sThumb][
'tmp_name'], $sDestDir . $sTmpName)) {
192 imageResize($sDestDir . $sTmpName, $sDestDir . $sThumbName, 64, 64,
true);
193 unlink($sDestDir . $sTmpName);
196 unlink($_FILES[$sThumb][
'tmp_name']);
199 $sComplete =
_t(
'_ch_sctr_complete');
201 $sComplete =
_t(
'_ch_sctr_err_add_theme');
203 $sComplete = sprintf(
_t(
'_ch_sctr_err_already_exist'),
$sName);
206 header(
'Content-Type: text/html; charset=utf-8');
207 echo $this->_oTemplate->getPublishForm($sComplete);
212 $iThemeId = (int)$iThemeId;
218 $aTheme = $this->_oDb->getThemeStyle($iThemeId);
220 if (!
empty($aTheme)) {
221 $aStyles = $this->_oDb->getSite();
222 if (!
empty($aStyles)) {
230 $this->_oDb->updateSiteTmp($aTheme);
231 $this->_oDb->updateSiteCss($aTheme);
233 $this->_oConfig->cancelSession();
244 header(
'Content-Type: text/html; charset=utf-8');
253 $aStyles = $this->_oDb->getSite();
254 if (!
empty($aStyles)) {
257 $this->_oDb->resetSite();
267 $iUnitId = (int)$iUnitId;
274 $this->_oTemplate->addAdminCss(array(
'forms_adv.css',
'main.css',
'admin.css'));
275 $this->_oTemplate->addAdminJs(array(
'main.js'));
277 $this->_oTemplate->pageCodeAdmin (
_t(
'_ch_sctr_administration'),
$sType, $iUnitId, $this->
_checkActions());
285 if(!
isAdmin() || !$this->_oConfig->isEnabled())
289 'evalResult' =>
'oChSctrMain.showBlock();',
290 'evalResultCssClassWrapper' =>
'ch-phone-hide'
295 if(!$this->_oConfig->isEnabled())
298 return $this->_oTemplate->parseHtmlByName(
'customize_block_wrp.html', array(
299 'name_id' =>
'site_customize',
300 'ch_if:hide' => array(
301 'condition' => !$this->_oConfig->isOpen(),
310 if(!$this->_oConfig->isEnabled())
313 list($sPage, $sTarget, $iTheme,
$sAction) = $this->_oConfig->getSessionData();
318 $aStyles = $this->_oDb->getSite();
319 if (!
empty($aStyles)) {
322 $this->_oDb->saveSite();
326 $this->_oConfig->setSessionData(array($sPage, $sTarget, $iTheme,
''));
341 return '<style type="text/css">' . $sCss .
'</style>';
346 return isAdmin($this->iUserId);
361 if (isset($_FILES[
$sName]) && is_uploaded_file($_FILES[
$sName][
'tmp_name'])) {
362 if (strpos($_FILES[
$sName][
'type'],
'image') !==
false) {
363 $sExt = pathinfo($_FILES[
$sName][
'name'], PATHINFO_EXTENSION);
364 $sFileName = $this->_oDb->addImage(
$sExt);
367 if (move_uploaded_file($_FILES[
$sName][
'tmp_name'], $sDestDir . $sFileName)) {
373 unlink($_FILES[
$sName][
'tmp_name']);
381 if ($this->_oDb->deleteImage($sFileName)) {
383 if (file_exists($sDestDir . $sFileName))
384 unlink($sDestDir . $sFileName);
392 foreach (
$aVars as $sKey => $sValue) {
396 if ($sValue !=
'' && $sValue !=
'default' && $sValue !=
'-1')
397 $aResult[$sPage][$sTarget][$sKey] = $sValue;
403 $bPageBackgroundChanged =
false;
406 if (
empty($aTmpStyle))
409 foreach ($aTmpStyle
as $sKey => $aValue) {
410 if (!isset($this->_aCssMatch[$sKey]))
413 foreach ($aValue
as $sValKey => $aParam) {
414 if (!isset($this->_aCssMatch[$sKey][$sValKey][
'css_name']))
417 $sPartCss = $this->_aCssMatch[$sKey][$sValKey][
'css_name'] .
' {';
419 $sMethod =
'_compile' . ucfirst($sKey);
420 $s = method_exists($this, $sMethod) ? call_user_func_array(array($this, $sMethod), array($aParam)) :
'';
421 if (
'bgbody' == $sValKey &&
'background' == $sKey &&
'' !=
$s &&
'background-image: none;' !=
$s)
422 $bPageBackgroundChanged =
true;
430 if ($bPageBackgroundChanged)
431 $sCss .=
' html div.sys_root_bg {display:none;} ';
438 $aTmpStyle = $this->_oDb->getSiteTmp();
440 if (
empty($aTmpStyle))
445 return serialize($aTmpStyle);
453 foreach ($aCss
as $sKey => $mixedValue) {
454 if (!is_array($mixedValue)) {
455 if ($sKey ==
'image') {
456 switch ($iOperation) {
462 $this->_oDb->copyImage($mixedValue);
478 foreach ($aCss
as $sKey => $mixedValue) {
479 if (!is_array($mixedValue)) {
480 if ($sKey ==
'image')
496 foreach ($aCss
as $sKey => $mixedValue) {
497 if (!is_array($mixedValue)) {
498 if ($sKey ==
'image') {
499 $sExt = pathinfo($mixedValue, PATHINFO_EXTENSION);
500 $sFileName = $this->_oDb->addImage(
$sExt);
503 $oFile = fopen($sDestDir . $sFileName,
'w',
false);
505 fwrite($oFile, $oZip->GetData($aImages[$mixedValue]));
523 $this->_oDb->updateSiteCss($this->iUserId, $sTmpCss);
533 $aTheme = $this->_oDb->getThemeById($iThemeId);
534 if (!
empty($aTheme) && $this->_oDb->deleteTheme($iThemeId)) {
549 $sFileImport =
'theme_file';
551 if ($_POST[
'theme']) {
552 if ($_POST[
'action_theme_export'])
555 if ($_POST[
'action_theme_delete'])
557 }
else if (isset($_FILES[$sFileImport]) && is_uploaded_file($_FILES[$sFileImport][
'tmp_name'])) {
559 unlink($_FILES[$sFileImport][
'tmp_name']);
567 $aTheme = $this->_oDb->getThemeById($iThemeId);
572 $sConf =
"\$sThemeName = '{$aTheme['name']}';\n";
573 $sConf .=
"\$sThemeStyle = '{$aTheme['css']}';\n";
580 if (file_exists(
$sFile)) {
581 $oData = implode(
"", file(
$sFile));
585 $aImages = $this->
_getImages(unserialize($aTheme[
'css']));
586 foreach ($aImages
as $sImage) {
588 if (file_exists(
$sFile)) {
589 $oData = implode(
"", file(
$sFile));
590 $oZipFile->addFile($oData,
'images/' . $sImage);
594 header(
"Content-type: application/octet-stream");
595 header(
"Content-disposition: attachment; filename={$aTheme['name']}.dfn");
596 echo $oZipFile->file();
607 if (pathinfo($_FILES[$sFileImport][
'name'], PATHINFO_EXTENSION) !=
'dfn')
608 return _t(
'_ch_sctr_err_format');
610 $oUnZip =
new SimpleUnzip($_FILES[$sFileImport][
'tmp_name']);
615 return sprintf(
_t(
'_ch_sctr_err_conf_php'),
'conf.php');
620 if (!isset($sThemeName) || !isset($sThemeStyle))
621 return _t(
'_ch_sctr_err_theme_parameters');
624 $aTheme = $this->_oDb->getThemeByName($sThemeName);
626 return sprintf(
_t(
'_ch_sctr_err_already_exist'), $sThemeName);
629 if (!
empty($aImages))
630 $sStyle = serialize($this->
_importImages(unserialize($sThemeStyle), $oUnZip, $aImages));
635 $iThemeId = $this->_oDb->addTheme($sThemeName, 0, $sStyle);
637 return _t(
'_ch_sctr_err_add_theme');
643 $oFile = fopen($sDestDir . $sThumbName,
'w',
false);
650 return _t(
'_ch_sctr_import_complete');
657 for ($i = 0; $i < $oZipFile->Count(); $i++) {
658 if ($oZipFile->GetPath($i) == $sPath)
659 $aFiles[$oZipFile->GetName($i)] = $i;
669 foreach ($aParam
as $sKey => $sValue) {
675 $sParams .=
'background-color: ' . $sValue .
';';
676 if (!isset($aParam[
'image']))
677 $sParams .=
'background-image: none;';
681 if (isset($aParam[
'useimage']))
682 $sParams .=
'background-image: url(' . $this->
_getImagesPath() . $sValue .
');';
684 $sParams .=
'background-image: none;';
688 $sParams .=
'background-repeat: ' . $sValue .
';';
692 $sParams .=
'background-position: ' . $sValue .
';';
704 foreach ($aParam
as $sKey => $sValue) {
710 $sParams .=
'font-size: ' . $sValue .
'px;';
714 $sParams .=
'color: ' . $sValue .
';';
718 $sParams .=
'font-family: ' . $sValue .
';';
724 $sParams .=
'font-style: normal;';
728 $sParams .=
'font-weight: bold;';
732 $sParams .=
'font-style: italic;';
744 $aProperties = array(
748 if (isset($aParam[
'position']))
749 switch($aParam[
'position']) {
751 $aProperties = array(
757 $aProperties = array(
763 $aProperties = array(
769 $aProperties = array(
775 $aProperties = array(
782 $aProperties = array(
789 $aProperties = array(
796 $aProperties = array(
803 $aProperties = array(
810 $aProperties = array(
817 foreach ($aParam
as $sKey => $sValue) {
824 foreach ($aProperties
as $sVal)
825 $sParams .= $sVal .
'-width: ' . $sValue .
'px;';
829 foreach ($aProperties
as $sVal)
830 $sParams .= $sVal .
'-color: ' . $sValue .
';';
834 foreach ($aProperties
as $sVal)
835 $sParams .= $sVal .
'-style: ' . $sValue .
';';
845 if (!$this->iUserId || !
isAdmin($this->iUserId) || !
getParam(
'ch_sctr_enable'))
848 $sUrl = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() .
'customizepage/';
849 $aMenuItems = array(
'themes',
'background',
'font',
'border');
853 list($sSesPage, $sSesTarget, $iSesTheme, $sSesAction) = $this->_oConfig->getSessionData();
854 if($sPage ==
'' && !
empty($sSesPage))
857 if($sTarget ==
'' && !
empty($sSesTarget))
858 $sTarget = $sSesTarget;
861 $sPage = $aMenuItems[0];
863 foreach ($aMenuItems
as $sItem) {
864 $aTopMenu[
_t(
'_ch_sctr_page_' . $sItem)] = array(
865 'href' =>
$sUrl . $sItem,
867 'active' => $sItem == $sPage
872 if (isset($this->_aCssMatch[$sPage])) {
874 $sTarget = key($this->_aCssMatch[$sPage]);
876 foreach ($this->_aCssMatch[$sPage]
as $sKey => $aValues) {
878 'name' =>
_t($aValues[
'name']),
879 'value' =>
$sUrl . $sPage .
'/' . $sKey,
880 'select' => $sKey == $sTarget ?
'selected' :
''
886 $aStyle = $this->_oDb->getSiteTmp();
887 if (!
empty($aStyle) && isset($aStyle[$sPage][$sTarget]))
888 $aVars = $aStyle[$sPage][$sTarget];
890 return $this->_oTemplate->profileCustomizeBlock($aTopMenu, $sPage, $aTargets, $sTarget,
$aVars);