$useid = getUserId($useName); if ($useid == 0) { include INCLUDES . "p_notfound.php"; return; } // The user must be an artist (have at least 1 submission) // to be able to design custom themes. if (!isArtist($useid)) { include INCLUDES . "p_notfound.php"; return; } } $_documentTitle = "Theme Designer"; include_once INCLUDES . "customthemes.php"; $data = loadCustomThemeData($useid, $isClub); $lastThemeFile = getLastCustomThemeFile($useid, $isClub); ?> <div class="header"> <div class="header_title" style="height: 100px"> Theme Designer <div class="subheader">A tool for designing your custom theme</div> </div> <?php if (!$isClub) { $active = 6; include INCLUDES . "mod_setmenu.php"; } ?> </div> <div class="container">
function updateCustomTheme($useid, $isClub, $data, &$errors) { $themePath = getCustomThemePath($useid, $isClub); forceFolders($themePath); $lastThemeFile = getLastCustomThemeFile($useid, $isClub); $err = !uploadSingleImage("logo", 0, 0, 51200, $fnLogo, $errors, $themePath); $err |= !uploadSingleImage("outer", 0, 0, 25600, $fnOuter, $errors, $themePath); $err |= !uploadSingleImage("container", 0, 0, 51200, $fnContainer, $errors, $themePath); $err |= !uploadSingleImage("container2", 0, 0, 25600, $fnContainer2, $errors, $themePath); if ($err) { return false; } $fileLogo = urlf() . findNewestFile($themePath . "logo-*.jpg"); $fileOuter = urlf() . findNewestFile($themePath . "outer-*.jpg"); $fileContainer = urlf() . findNewestFile($themePath . "container-*.jpg"); $fileContainer2 = urlf() . findNewestFile($themePath . "container2-*.jpg"); $pixLogo = PIX($fnLogo); $pixOuter = PIX($fnOuter); $pixContainer = PIX($fnContainer); $pixContainer2 = PIX($fnContainer2); $pix00Container = PIX($fnContainer, 0, 0); $avgLogo = AVG($fnLogo); $avgOuter = AVG($fnOuter); $avgContainer = AVG($fnContainer); $avgContainer2 = AVG($fnContainer2); $colors = array('{bBody}' => $pixLogo, '{bOuter}' => $pixOuter, '{bContainer}' => $pixContainer, '{bContainer2}' => $pixContainer2, '{bInput}' => BRIGHT($pixContainer2, 1.2), '{bInputHover}' => BRIGHT($pixContainer2, 1.5), '{bInputFocus}' => $pix00Container, '{bButton}' => BRIGHT($pixContainer2, 1.2), '{bButtonHover}' => BRIGHT($pixContainer2, 1.5), '{bTabActive}' => $pix00Container, '{bTabInactive}' => $pixOuter, '{bUI2Layout}' => $pixContainer2, '{cBody}' => BRIGHT(CONTRAST($avgLogo), 1.3), '{cOuter}' => BRIGHT(CONTRAST($avgOuter), 1.2), '{cContainer}' => BRIGHT(CONTRAST($avgContainer), 1.3), '{cContainer2}' => BRIGHT(CONTRAST($avgContainer2), 1.3), '{cOutline}' => BRIGHT(CONTRAST($avgContainer2), 1.3), '{cTabActive}' => CONTRAST($avgContainer), '{cTabInactive}' => CONTRAST($avgOuter), '{cInput}' => CONTRAST($avgContainer2), '{cLink}' => RICH(BRIGHT($pixContainer2, -2.5), 1.1), '{cLinkHover}' => RICH(BRIGHT($pixContainer2, -3), 1.1), '{cHeaderLink}' => RICH(BRIGHT($pixOuter, -2.5), 1.1), '{cHeaderLinkHover}' => RICH(BRIGHT($pixOuter, -3), 1.1), '{cMarkedText}' => BRIGHT(HARMONY($pixContainer2), 1.5), '{cTabOutline}' => BRIGHT(CONTRAST($avgContainer2), 1.3), '{cThumbBorder}' => BRIGHT(CONTRAST($avgContainer2), 1.3), '{cThumbBorderMature}' => RICH(BRIGHT($pixContainer2, -3), 1.1)); if (tooClose($colors['{cLink}'], $colors['{cContainer2}'], 32)) { $colors['{cLink}'] = RICH(PIX($fnOuter), 2); $colors['{cLinkHover}'] = BRIGHT($colors['{cLink}'], 2.5); } if (tooClose($colors['{cContainer}'], $colors['{cMarkedText}'], 140)) { $colors['{cMarkedText}'] = BRIGHT(HARMONY(PIX($fnContainer2)), -1.3); } // Override auto-generated colors with POSTed colors. if (!isset($data["c"])) { $data["c"] = array(); } $acceptedColors = array("cBody", "cOuter", "cContainer", "cContainer2", "cOutline", "cTabActive", "cTabInactive", "cInput", "cLink", "cLinkHover", "cHeaderLink", "cHeaderLinkHover", "cMarkedText", "cTabOutline", "cThumbBorder", "cThumbBorderMature", "sOutline", "sTitleMargin", "bButton", "bButtonHover", "bInput", "bInputFocus", "bUI2Layout"); // Override some data from POST (if available) foreach ($acceptedColors as $c1) { if (isset($_POST[$c1]) && $_POST[$c1] != "") { $data["c"][$c1] = $_POST[$c1]; } } foreach ($data["c"] as $key => $value) { if (preg_match('/^[0-9A-Fa-f]{3}$/', $value)) { $r = hexdec(substr($value, 0, 1)) * 17; $g = hexdec(substr($value, 1, 1)) * 17; $b = hexdec(substr($value, 2, 1)) * 17; $colors["{" . $key . "}"] = getColor($r, $g, $b); } if (preg_match('/^[0-9A-Fa-f]{6}$/', $value)) { $r = hexdec(substr($value, 0, 2)); $g = hexdec(substr($value, 2, 2)); $b = hexdec(substr($value, 4, 2)); $colors["{" . $key . "}"] = getColor($r, $g, $b); } } $sOutline = 'border-width: 1px;'; if (isset($data["c"]["sOutline"])) { switch ($data["c"]["sOutline"]) { case 2: $sOutline = 'border-width: 2px;'; break; case 3: $sOutline = 'border-width: 2px; border-left: none; border-right: none;'; break; case 4: $sOutline = 'border: none;'; break; } } $sTitleMargin = 'padding-left: 0px;'; if (isset($data["c"]["sTitleMargin"])) { $m = intval($data["c"]["sTitleMargin"]); $m = $m > 400 ? 400 : $m; $m = $m < 0 ? 0 : $m; $data["c"]["sTitleMargin"] = $m; $sTitleMargin = 'padding-left: ' . $m . 'px;'; } $css = file_get_contents(INCLUDES . "p_themedesigner.css"); $css = str_replace('{sOutline}', $sOutline, $css); $css = str_replace('{sTitleMargin}', $sTitleMargin, $css); $css = str_replace('{fileLogo}', $fileLogo, $css); $css = str_replace('{fileOuter}', $fileOuter, $css); $css = str_replace('{fileContainer}', $fileContainer, $css); $css = str_replace('{fileContainer2}', $fileContainer2, $css); foreach ($colors as $colorVar => $colorValue) { $css = str_replace($colorVar, getWebColor($colorValue), $css); } if (!isset($data["Tile"]) || isset($_POST["submitTheme"])) { $data["Tile"] = 0; } // Override some data from POST (if available) if (isset($_POST["BGLayoutTiledH"])) { $data["Tile"] |= 1; } if (isset($_POST["BGOuterTiledH"])) { $data["Tile"] |= 2; } if (isset($_POST["BGContainerTiledH"])) { $data["Tile"] |= 4; } if (isset($_POST["BGContainer2TiledH"])) { $data["Tile"] |= 8; } if (isset($_POST["BGLayoutTiledV"])) { $data["Tile"] |= 16; } if (isset($_POST["BGOuterTiledV"])) { $data["Tile"] |= 32; } if (isset($_POST["BGContainerTiledV"])) { $data["Tile"] |= 64; } if (isset($_POST["BGContainer2TiledV"])) { $data["Tile"] |= 128; } $css = str_replace('{layoutTiling}', getTiling($data["Tile"] & 1, $data["Tile"] & 16), $css); $css = str_replace('{outerTiling}', getTiling($data["Tile"] & 2, $data["Tile"] & 32), $css); $css = str_replace('{containerTiling}', getTiling($data["Tile"] & 4, $data["Tile"] & 64), $css); $css = str_replace('{container2Tiling}', getTiling($data["Tile"] & 8, $data["Tile"] & 128), $css); // Remove comments from the final CSS file. $css = preg_replace('/\\/\\*(.+?)\\*\\//', "", $css); if ($lastThemeFile != "") { $css_orig = file_get_contents($lastThemeFile); } else { $css_orig = ""; } if ($css != $css_orig) { // Create new CSS file and delete the previous CSS file. $fp = fopen($themePath . "style-" . time() . ".css", "w"); fwrite($fp, $css); fclose($fp); if ($lastThemeFile != "") { unlink($lastThemeFile); } // Store updated data to the database. $cusWhere = dbWhere(array("cusUser" => $useid, "cusIsClub" => $isClub)); $result = sql_query("SELECT `cusid` FROM `customThemes`" . $cusWhere . "LIMIT 1"); if (mysql_num_rows($result) == 0) { sql_query("INSERT INTO `customThemes`" . dbValues(array("cusUser" => $useid, "cusIsClub" => $isClub, "cusData" => serialize($data)))); } else { sql_query("UPDATE `customThemes`" . dbSet(array("cusData" => serialize($data))) . $cusWhere . "LIMIT 1"); } return true; } else { return false; } }