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_PROFILE_CUSTOMIZE_DIR_IMAGES',
'data/images/');
14 define(
'CH_PROFILE_CUSTOMIZE_SMALL_PREFIX',
's_');
15 define(
'CH_PROFILE_CUSTOMIZE_THEME_PREFIX',
't_');
16 define(
'CH_PROFILE_CUSTOMIZE_THUMB_EXT',
'.jpg');
17 define(
'CH_PROFILE_CUSTOMIZE_THEME_CONF',
'conf.php');
18 define(
'CH_PROFILE_CUSTOMIZE_THEME_THUMB',
'thumb.jpg');
19 define(
'CH_PROFILE_CUSTOMIZE_IMAGES_DELETE', 0);
20 define(
'CH_PROFILE_CUSTOMIZE_IMAGES_COPY', 1);
22 define(
'CH_PROFILE_PAGE', 1);
27 $a = $aModuleOverwright ? $aModuleOverwright :
$aModule;
28 if (!$a || $a[
'uri'] !=
'profile_customize') {
30 $a = $oMain->_aModule;
75 $this->_oConfig->init($this->_oDb);
76 $this->_oTemplate->setModule($this);
78 $this->_aCssMatch = $this->_oDb->getUnits();
83 header(
'Content-Type: text/html; charset=utf-8');
92 if (isset($_POST[
'page']) && isset($_POST[
'trg'])) {
96 unset($_POST[
'page']);
99 $aTmpStyle = $this->_oDb->getProfileTmpByUserId($this->iUserId);
102 if (!
empty($aTmpStyle) && isset($aTmpStyle[$sPage][$sTarget])) {
103 foreach ($aTmpStyle[$sPage][$sTarget]
as $sKey => $sValue) {
104 if ($sKey !=
'image')
105 unset($aTmpStyle[$sPage][$sTarget][$sKey]);
109 if (isset($_FILES[
'image'])) {
111 if (strlen($sImage) > 0) {
112 if (isset($aTmpStyle[$sPage][$sTarget][
'image']))
113 $this->
_deleteImage($aTmpStyle[$sPage][$sTarget][
'image']);
115 $aTmpStyle[$sPage][$sTarget][
'image'] = $sImage;
116 if (!isset(
$aVars[
'useimage']))
117 $aVars[
'useimage'] =
'on';
121 foreach (
$aVars as $sKey => $sValue) {
122 if ($sValue !=
'' && $sValue !=
'default' && $sValue !=
'-1')
125 }
else if (!
empty($aTmpStyle) && isset($aTmpStyle[$sPage][$sTarget])) {
127 unset($aTmpStyle[$sPage][$sTarget]);
130 $this->_oDb->updateProfileTmpByUserId($this->iUserId, $aTmpStyle);
137 $iTheme = (int)$iTheme;
142 $sCss =
'<style type="text/css">';
145 $aStyles = $this->_oDb->getProfileByUserId($this->iUserId);
146 if (!
empty($aStyles)) {
149 $this->_oDb->saveProfileByUserId($this->iUserId);
150 $sCss .= $this->
_getCssFromArray($this->_oDb->getProfileCssByUserId($this->iUserId));
155 $sCss .= $this->
_getCssFromArray($this->_oDb->getProfileTmpByUserId($this->iUserId));
163 $sCss .= $this->
_getCssFromArray($this->_oDb->getProfileCssByUserId($this->iUserId));
167 header(
'Content-Type: text/html; charset=utf-8');
168 echo $this->_oTemplate->profilePage($this->iUserId, $sCss);
178 if ($isSave && isset($_POST[
'name_theme']) && $_POST[
'name_theme']) {
180 $aTheme = $this->_oDb->getThemeByName(
$sName);
182 if (
empty($aTheme)) {
185 if ($iThemeId != -1) {
186 $sThumb =
'thumbnail';
188 if (isset($_FILES[$sThumb]) && is_uploaded_file($_FILES[$sThumb][
'tmp_name'])) {
189 if (strpos($_FILES[$sThumb][
'type'],
'image') !==
false) {
191 $sExt =
'.' . pathinfo($_FILES[$sThumb][
'name'], PATHINFO_EXTENSION);
192 $sTmpName =
'tmp_' .
time() . $this->iUserId .
$sExt;
195 if (move_uploaded_file($_FILES[$sThumb][
'tmp_name'], $sDestDir . $sTmpName)) {
196 imageResize($sDestDir . $sTmpName, $sDestDir . $sThumbName, 64, 64,
true);
197 unlink($sDestDir . $sTmpName);
200 unlink($_FILES[$sThumb][
'tmp_name']);
203 $sComplete =
_t(
'_ch_profile_customize_complete');
205 $sComplete =
_t(
'_ch_profile_customize_err_add_theme');
207 $sComplete = sprintf(
_t(
'_ch_profile_customize_err_already_exist'),
$sName);
210 header(
'Content-Type: text/html; charset=utf-8');
211 echo $this->_oTemplate->getPublishForm($sComplete);
216 $iThemeId = (int)$iThemeId;
222 $aTheme = $this->_oDb->getThemeStyle($iThemeId);
224 if (!
empty($aTheme)) {
225 $aStyles = $this->_oDb->getProfileByUserId($this->iUserId);
226 if (!
empty($aStyles)) {
234 $this->_oDb->updateProfileTmpByUserId($this->iUserId, $aTheme);
235 $this->_oDb->updateProfileCssByUserId($this->iUserId, $aTheme);
237 $sCss =
'<style type="text/css">';
238 $sCss .= $this->
_getCssFromArray($this->_oDb->getProfileCssByUserId($this->iUserId));
242 echo $this->_oTemplate->profilePage($this->iUserId, $sCss);
247 $iThemeId = (int)$iThemeId;
261 $aStyles = $this->_oDb->getProfileByUserId($this->iUserId);
262 if (!
empty($aStyles)) {
265 $this->_oDb->resetProfileStyleByUserId($this->iUserId);
268 $sCss =
'<style type="text/css">';
269 $sCss .= $this->
_getCssFromArray($this->_oDb->getProfileCssByUserId($this->iUserId));
272 header(
'Content-Type: text/html; charset=utf-8');
273 echo $this->_oTemplate->profilePage($this->iUserId, $sCss);
282 $iUnitId = (int)$iUnitId;
289 $this->_oTemplate->addAdminCss(array(
'forms_adv.css',
'main.css',
'admin.css'));
290 $this->_oTemplate->addAdminJs(array(
'main.js'));
292 $this->_oTemplate->pageCodeAdmin (
_t(
'_ch_profile_customize_administration'),
$sType, $iUnitId, $this->
_checkActions());
301 if (!$this->iUserId || !
getParam(
'ch_profile_customize_enable'))
304 $sUrl = CH_WSB_URL_ROOT . $this->_oConfig->getBaseUri() .
'customizepage/';
305 $aMenuItems = array(
'themes',
'background',
'font',
'border');
310 $sPage = $aMenuItems[0];
312 foreach ($aMenuItems
as $sItem) {
313 $aTopMenu[
_t(
'_ch_profile_customize_page_' . $sItem)] = array(
314 'href' =>
$sUrl . $sItem,
316 'active' => $sItem == $sPage
320 if (isset($this->_aCssMatch[$sPage])) {
322 $sTarget = key($this->_aCssMatch[$sPage]);
324 foreach ($this->_aCssMatch[$sPage]
as $sKey => $aValues) {
326 'name' =>
_t($aValues[
'name']),
327 'value' =>
$sUrl . $sPage .
'/' . $sKey,
328 'select' => $sKey == $sTarget ?
'selected' :
''
331 }
else if ($sPage ==
'themes') {
332 $aThemesTargets = array(
'my',
'shared');
335 $sTarget = $aThemesTargets[0];
337 foreach ($aThemesTargets
as $sValue) {
339 'name' =>
_t(
'_ch_profile_customize_page_themes_' . $sValue),
340 'value' =>
$sUrl . $sPage .
'/' . $sValue,
341 'select' => $sValue == $sTarget ?
'selected' :
''
347 $aStyle = $this->_oDb->getProfileTmpByUserId($this->iUserId);
348 if (!
empty($aStyle) && isset($aStyle[$sPage][$sTarget]))
349 $aVars = $aStyle[$sPage][$sTarget];
351 return $this->_oTemplate->profileCustomizeBlock($aTopMenu, $sPage, $aTargets, $sTarget,
$aVars);
356 $iUserId = (int)$iUserId;
358 if (!$iUserId || !
getParam(
'ch_profile_customize_enable'))
361 return $this->
_getCssFromArray($this->_oDb->getProfileCssByUserId($iUserId));
366 return isAdmin($this->iUserId);
381 if (isset($_FILES[
$sName]) && is_uploaded_file($_FILES[
$sName][
'tmp_name'])) {
382 $sExt = pathinfo($_FILES[
$sName][
'name'], PATHINFO_EXTENSION);
383 if (strpos($_FILES[
$sName][
'type'],
'image') !==
false && in_array(
$sExt, array (
'gif',
'png',
'jpg',
'jpeg'))) {
384 $sFileName = $this->_oDb->addImage(
$sExt);
387 if (move_uploaded_file($_FILES[
$sName][
'tmp_name'], $sDestDir . $sFileName)) {
393 unlink($_FILES[
$sName][
'tmp_name']);
401 if ($this->_oDb->deleteImage($sFileName)) {
403 if (file_exists($sDestDir . $sFileName))
404 unlink($sDestDir . $sFileName);
412 foreach (
$aVars as $sKey => $sValue) {
416 if ($sValue !=
'' && $sValue !=
'default' && $sValue !=
'-1')
417 $aResult[$sPage][$sTarget][$sKey] = $sValue;
423 $bPageBackgroundChanged =
false;
426 if (
empty($aTmpStyle))
429 foreach ($aTmpStyle
as $sKey => $aValue) {
430 if (!isset($this->_aCssMatch[$sKey]))
433 foreach ($aValue
as $sValKey => $aParam) {
434 if (!isset($this->_aCssMatch[$sKey][$sValKey][
'css_name']))
437 $sPartCss = $this->_aCssMatch[$sKey][$sValKey][
'css_name'] .
' {';
439 $sMethod =
'_compile' . ucfirst($sKey);
440 $s = method_exists($this, $sMethod) ? call_user_func_array(array($this, $sMethod), array($aParam)) :
'';
441 if (
'body' == $sValKey &&
'background' == $sKey &&
'' !=
$s &&
'background-image: none;' !=
$s)
442 $bPageBackgroundChanged =
true;
450 if ($bPageBackgroundChanged)
451 $sCss .=
' html div.sys_root_bg {display:none;} ';
458 $aTmpStyle = $this->_oDb->getProfileTmpByUserId($this->iUserId);
460 if (
empty($aTmpStyle))
465 return serialize($aTmpStyle);
473 foreach ($aCss
as $sKey => $mixedValue) {
474 if (!is_array($mixedValue)) {
475 if ($sKey ==
'image') {
476 switch ($iOperation) {
482 $this->_oDb->copyImage($mixedValue);
498 foreach ($aCss
as $sKey => $mixedValue) {
499 if (!is_array($mixedValue)) {
500 if ($sKey ==
'image')
516 foreach ($aCss
as $sKey => $mixedValue) {
517 if (!is_array($mixedValue)) {
518 if ($sKey ==
'image') {
519 $sExt = pathinfo($mixedValue, PATHINFO_EXTENSION);
520 $sFileName = $this->_oDb->addImage(
$sExt);
523 $oFile = fopen($sDestDir . $sFileName,
'w',
false);
525 fwrite($oFile, $oZip->GetData($aImages[$mixedValue]));
542 $sTmpCss = $this->
_getCssFromArray($this->_oDb->getProfileTmpByUserId($this->iUserId));
543 $this->_oDb->updateProfileCssByUserId($this->iUserId, $sTmpCss);
548 $sResult =
_t(
'_ch_profile_customize_err_delete_theme');
553 $aTheme = $this->_oDb->getThemeById($iThemeId);
554 if (!
empty($aTheme) && $this->_oDb->deleteTheme($iThemeId)) {
560 $sResult =
_t(
'_ch_profile_customize_delete_complete');
569 $sFileImport =
'theme_file';
571 if ($_POST[
'theme']) {
572 if ($_POST[
'action_theme_export'])
575 if ($_POST[
'action_theme_delete'])
577 }
else if (isset($_FILES[$sFileImport]) && is_uploaded_file($_FILES[$sFileImport][
'tmp_name'])) {
579 unlink($_FILES[$sFileImport][
'tmp_name']);
587 $aTheme = $this->_oDb->getThemeById($iThemeId);
592 $sConf =
"\$sThemeName = '{$aTheme['name']}';\n";
593 $sConf .=
"\$sThemeStyle = '{$aTheme['css']}';\n";
600 if (file_exists(
$sFile)) {
601 $oData = implode(
"", file(
$sFile));
605 $aImages = $this->
_getImages(unserialize($aTheme[
'css']));
606 foreach ($aImages
as $sImage) {
608 if (file_exists(
$sFile)) {
609 $oData = implode(
"", file(
$sFile));
610 $oZipFile->addFile($oData,
'images/' . $sImage);
614 header(
"Content-type: application/octet-stream");
615 header(
"Content-disposition: attachment; filename={$aTheme['name']}.dfn");
616 echo $oZipFile->file();
628 if (pathinfo($_FILES[$sFileImport][
'name'], PATHINFO_EXTENSION) !=
'dfn')
629 return _t(
'_ch_profile_customize_err_format');
631 $oUnZip =
new SimpleUnzip($_FILES[$sFileImport][
'tmp_name']);
636 return sprintf(
_t(
'_ch_profile_customize_err_conf_php'),
'conf.php');
641 if (!isset($sThemeName) || !isset($sThemeStyle))
642 return _t(
'_ch_profile_customize_err_theme_parameters');
645 $aTheme = $this->_oDb->getThemeByName($sThemeName);
647 return sprintf(
_t(
'_ch_profile_customize_err_already_exist'), $sThemeName);
649 $aStyle = unserialize($sThemeStyle);
655 $iThemeId = $this->_oDb->addTheme($sThemeName, 0, serialize($aStyle));
657 return _t(
'_ch_profile_customize_err_add_theme');
663 $oFile = fopen($sDestDir . $sThumbName,
'w',
false);
670 return _t(
'_ch_profile_customize_import_complete');
677 for ($i = 0; $i < $oZipFile->Count(); $i++) {
678 if ($oZipFile->GetPath($i) == $sPath)
679 $aFiles[$oZipFile->GetName($i)] = $i;
689 foreach ($aParam
as $sKey => $sValue) {
695 $sParams .=
'background-color: ' . $sValue .
';';
696 if (!isset($aParam[
'image']))
697 $sParams .=
'background-image: none;';
701 if (isset($aParam[
'useimage']))
702 $sParams .=
'background-image: url(' . $this->
_getImagesPath() . $sValue .
');';
704 $sParams .=
'background-image: none;';
708 $sParams .=
'background-repeat: ' . $sValue .
';';
712 $sParams .=
'background-position: ' . $sValue .
';';
724 foreach ($aParam
as $sKey => $sValue) {
730 $sParams .=
'font-size: ' . $sValue .
'px;';
734 $sParams .=
'color: ' . $sValue .
';';
738 $sParams .=
'font-family: ' . $sValue .
';';
744 $sParams .=
'font-style: normal;';
748 $sParams .=
'font-weight: bold;';
752 $sParams .=
'font-style: italic;';
764 $aProperties = array(
768 if (isset($aParam[
'position']))
769 switch($aParam[
'position']) {
771 $aProperties = array(
777 $aProperties = array(
783 $aProperties = array(
789 $aProperties = array(
795 $aProperties = array(
802 $aProperties = array(
809 $aProperties = array(
816 $aProperties = array(
823 $aProperties = array(
830 $aProperties = array(
837 foreach ($aParam
as $sKey => $sValue) {
844 foreach ($aProperties
as $sVal)
845 $sParams .= $sVal .
'-width: ' . $sValue .
'px;';
849 foreach ($aProperties
as $sVal)
850 $sParams .= $sVal .
'-color: ' . $sValue .
';';
854 foreach ($aProperties
as $sVal)
855 $sParams .= $sVal .
'-style: ' . $sValue .
';';