/** * Copy a theme directory to create a new custom theme * * @param $source source directory * @param $target target directory * @return bool|string either true or an error message * @author Ozh * @since 1.3 */ function copyThemeDirectory($source, $target, $newname) { global $_zp_current_admin_obj; $message = true; $source = SERVERPATH . '/themes/' . internalToFilesystem($source); $target = SERVERPATH . '/themes/' . internalToFilesystem($target); // If the target theme already exists, nothing to do. if (is_dir($target)) { return gettext('Cannot create new theme.') . ' ' . sprintf(gettext('Directory “%s” already exists!'), basename($target)); } // If source dir is missing, exit too if (!is_dir($source)) { return gettext('Cannot create new theme.') . ' ' . sprintf(gettext('Cannot find theme directory “%s” to copy!'), basename($source)); } // We must be able to write to the themes dir. if (!is_writable(dirname($target))) { return gettext('Cannot create new theme.') . ' ' . gettext('The <tt>/themes</tt> directory is not writable!'); } // We must be able to create the directory if (!mkdir($target, FOLDER_MOD)) { return gettext('Cannot create new theme.') . ' ' . gettext('Could not create directory for the new theme'); } @chmod($target, FOLDER_MOD); // Get a list of files to copy: get all files from the directory, remove those containing '/.svn/' $source_files = array_filter(listDirectoryFiles($source), create_function('$str', 'return strpos($str, "/.svn/") === false;')); // Determine nested (sub)directories structure to create: go through each file, explode path on "/" // and collect every unique directory $dirs_to_create = array(); foreach ($source_files as $path) { $path = explode('/', dirname(str_replace($source . '/', '', $path))); $dirs = ''; foreach ($path as $subdir) { if ($subdir == '.svn' or $subdir == '.') { continue 2; } $dirs = "{$dirs}/{$subdir}"; $dirs_to_create[$dirs] = $dirs; } } // Create new directory structure foreach ($dirs_to_create as $dir) { mkdir("{$target}/{$dir}", FOLDER_MOD); @chmod("{$target}/{$dir}", FOLDER_MOD); } // Now copy every file foreach ($source_files as $file) { $newfile = str_replace($source, $target, $file); if (!copy("{$file}", "{$newfile}")) { return sprintf(gettext("An error occurred while copying files. Please delete manually the new theme directory “%s” and retry or copy files manually."), basename($target)); } @chmod("{$newfile}", FOLDER_MOD); } // Rewrite the theme header. if (file_exists($target . '/theme_description.php')) { $theme_description = array(); require $target . '/theme_description.php'; $theme_description['desc'] = sprintf(gettext('Your theme, based on theme %s'), $theme_description['name']); } else { $theme_description['desc'] = gettext('Your theme'); } $theme_description['name'] = $newname; $theme_description['author'] = $_zp_current_admin_obj->getUser(); $theme_description['version'] = '1.0'; $theme_description['date'] = date('Y-m-d H:m:s', time()); $description = sprintf('<' . '?php // Theme definition file $theme_description["name"] = "%s"; $theme_description["author"] = "%s"; $theme_description["version"] = "%s"; $theme_description["date"] = "%s"; $theme_description["desc"] = "%s"; ?' . '>', html_encode($theme_description['name']), html_encode($theme_description['author']), html_encode($theme_description['version']), html_encode($theme_description['date']), html_encode($theme_description['desc'])); $f = fopen($target . '/theme_description.php', 'w'); if ($f !== FALSE) { @fwrite($f, $description); fclose($f); $message = gettext('New custom theme created successfully!'); } else { $message = gettext('New custom theme created, but its description could not be updated'); } // Make a slightly custom theme image if (file_exists("{$target}/theme.png")) { $themeimage = "{$target}/theme.png"; } else { if (file_exists("{$target}/theme.gif")) { $themeimage = "{$target}/theme.gif"; } else { if (file_exists("{$target}/theme.jpg")) { $themeimage = "{$target}/theme.jpg"; } else { $themeimage = false; } } } if ($themeimage) { if ($im = zp_imageGet($themeimage)) { $x = zp_imageWidth($im) / 2 - 45; $y = zp_imageHeight($im) / 2 - 10; $text = "CUSTOM COPY"; $font = zp_imageLoadFont(); $ink = zp_colorAllocate($im, 0xff, 0xff, 0xff); // create a blueish overlay $overlay = zp_createImage(zp_imageWidth($im), zp_imageHeight($im)); $back = zp_colorAllocate($overlay, 0x60, 0x60, 0x90); zp_imageFill($overlay, 0, 0, $back); // Merge theme image and overlay zp_imageMerge($im, $overlay, 0, 0, 0, 0, zp_imageWidth($im), zp_imageHeight($im), 45); // Add text zp_writeString($im, $font, $x - 1, $y - 1, $text, $ink); zp_writeString($im, $font, $x + 1, $y + 1, $text, $ink); zp_writeString($im, $font, $x, $y, $text, $ink); // Save new theme image zp_imageOutput($im, 'png', $themeimage); } } return $message; }
<?php require '../../zp-core/admin-functions.php'; $string = sanitize($_GET['text_watermark_text'], 3); if (!empty($string)) { if (isset($_GET['transient'])) { header("Content-type: image/png"); $filename = NULL; } else { $filename = dirname(dirname(__FILE__)) . '/watermarks/' . seoFriendly($string) . '.png'; } $len = strlen($string); $font = zp_imageLoadFont(sanitize($_GET['text_watermark_font'], 3)); $fw = zp_imageFontWidth($font); $fh = zp_imageFontHeight($font); $image = zp_createImage($fw * $len, $fh); $color = sanitize($_GET['text_watermark_color'], 3); $cr = hexdec(substr($color, 1, 2)); $cg = hexdec(substr($color, 3, 2)); $cb = hexdec(substr($color, 5, 2)); $back = zp_colorAllocate($image, 255 - $cr, 255 - $cg, 255 - $cb); zp_imagecolortransparent($image, $back); zp_imagefill($image, 0, 0, $back); $ink = zp_colorAllocate($image, $cr, $cg, $cb); $l = 0; for ($i = 0; $i < $len; $i++) { zp_writeString($image, $font, $l, 0, substr($string, $i, 1), $ink); $l = $l + $fw; } zp_imageOutput($image, 'png', $filename); }
$key = getOption('zenphoto_captcha_key'); $string = rc4($key, pack("H*", $cypher)); $len = getOption('zenphoto_captcha_length'); $string = str_pad($string, $len - strlen($string), '*'); if (isset($_GET['f'])) { $fontname = sanitize($_GET['f'], 3); } else { $fontname = getOption('zenphoto_captcha_font'); if ($fontname == '*') { // Random selection $fonts = zp_getFonts(); shuffle($fonts); $fontname = array_shift($fonts); } } $font = zp_imageLoadFont($fontname, getOption('zenphoto_captcha_font_size')); $pallet = array(array('R' => 16, 'G' => 110, 'B' => 3), array('R' => 132, 'G' => 4, 'B' => 16), array('R' => 103, 'G' => 3, 'B' => 143), array('R' => 143, 'G' => 32, 'B' => 3), array('R' => 143, 'G' => 38, 'B' => 48), array('R' => 0, 'G' => 155, 'B' => 18)); $fw = zp_imageFontWidth($font); $w = $fw * $len + 2; $h = $fh = zp_imagefontheight($font); $kerning = min(4, floor($fw / 2) - 1); $leading = $fh - 4; $ink = $lead = $kern = array(); for ($i = 0; $i < $len; $i++) { $lead[$i] = rand(2, $leading); $h = max($h, $fh + $lead[$i] + 2); $kern[$i] = rand(2, $kerning); $w = $w + $kern[$i]; $p[$i] = $pallet[rand(0, 5)]; } $image = zp_createImage($w, $h);
$cypher = preg_replace('/[^0-9a-f]/', '', $_GET['i']); $key = getOption('zenphoto_captcha_key'); $string = rc4($key, pack("H*", $cypher)); $len = strlen($string); if (isset($_GET['f'])) { $fontname = sanitize($_GET['f'], 3); } else { $fontname = getOption('zenphoto_captcha_font'); if ($fontname == '*') { // Random selection $fonts = zp_getFonts(); shuffle($fonts); $fontname = array_shift($fonts); } } $font = zp_imageLoadFont($fontname); $pallet = array(array('R' => 16, 'G' => 110, 'B' => 3), array('R' => 132, 'G' => 4, 'B' => 16), array('R' => 103, 'G' => 3, 'B' => 143), array('R' => 143, 'G' => 32, 'B' => 3), array('R' => 143, 'G' => 38, 'B' => 48), array('R' => 0, 'G' => 155, 'B' => 18)); $fw = zp_imageFontWidth($font); $w = $fw * $len + 2; $h = $fh = zp_imagefontheight($font); $kerning = min(4, floor($fw / 2) - 1); $leading = $fh - 4; $ink = $lead = $kern = array(); for ($i = 0; $i < $len; $i++) { $lead[$i] = rand(2, $leading); $h = max($h, $fh + $lead[$i] + 2); $kern[$i] = rand(2, $kerning); $w = $w + $kern[$i]; $p[$i] = $pallet[rand(0, 5)]; } $image = zp_createImage($w, $h);