reload(); $main = $swift_theme_creator->theme_config; if (isset($_POST['submit']) and (!is_adviser())) { // 1 - Theme name control $main['newtheme'] = strip_tags($_POST['new_theme']); if ( !preg_match('/^[a-z0-9-_]{1,8}$/', $main['newtheme']) ) array_push($errors, l10n('Invalid theme name: 1 to 8 lowercase alphanumeric characters' . ' including "-" and "_".')); // 2 - Colours control $main['color'] = array($_POST['color1'], $_POST['color2'], $_POST['color3'], $_POST['color4'], $_POST['color5']); $colors = $main['color'][0] . $main['color'][1] . $main['color'][2] . $main['color'][3] . $main['color'][4]; if ( !preg_match('/^(#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})){5}$/', $colors) ) array_push($errors, l10n('Invalid color code: 3 or 6 hexadecimal characters, preceded' . ' or not by "#"')); // 2.1 - Background and text control list($r1,$g1,$b1) = stc_hex2rgb($main['color'][0]); list($r2,$g2,$b2) = stc_hex2rgb($main['color'][1]); // Formula for converting RGB values to YIQ values // as perceived brightness difference. // Background and text "brightness" difference control: $dif = abs( ( (($r1*299)+($g1*587)+($b1*114)) / 1000 ) - ( (($r2*299)+($g2*587)+($b2*114)) / 1000 )); if ( $dif < 65 ) array_push($errors, l10n('Insufficient brightness difference between ' . 'text and background. dif=') . $dif); // Background and text "colour" difference control: $dif = (max($r1, $r2) - min($r1, $r2)) + (max($g1, $g2) - min($g1, $g2)) + (max($b1, $b2) - min($b1, $b2)); if ( $dif < 200 ) array_push($errors, l10n('Insufficient colour difference between ' . 'text and background. dif=') . $dif); // 2.2 - Background and Internal links control if (isset($do_it)) { list($r1,$g1,$b1) = stc_hex2rgb($main['color'][0]); list($r2,$g2,$b2) = stc_hex2rgb($main['color'][2]); // Background and Internal links "brightness" difference control: $dif = abs( ( (($r1*299)+($g1*587)+($b1*114)) / 1000 ) - ( (($r2*299)+($g2*587)+($b2*114)) / 1000 )); if ( $dif < 65 ) array_push($errors, l10n('Insufficient brightness difference between ' . 'Internal links and background. dif=') . $dif); // Background and Internal links "colour" difference control: $dif = (max($r1, $r2) - min($r1, $r2)) + (max($g1, $g2) - min($g1, $g2)) + (max($b1, $b2) - min($b1, $b2)); if ( $dif < 200 ) array_push($errors, l10n('Insufficient colour difference between ' . 'Internal links and background. dif=') . $dif); } // 3 - Directory control $main['templatedir'] = PHPWG_ROOT_PATH . 'template/' . $available_templates[$_POST['template']]; $main['newtpl'] = $available_templates[$_POST['template']]; $themedir = $main['templatedir'] . '/theme/' . $main['newtheme']; if (is_dir( $themedir )) array_push($errors, '['.$themedir.'] : '.l10n('Invalid theme: This theme exists ' . 'already (no override available).')); elseif (!is_writable($main['templatedir'])) array_push($errors, '['.$main['templatedir'].'] : '.l10n('no_write_access')); // 4 - Picture URL control if ( $_POST['background'] == 'fixed' and (is_dir($_POST['picture_url']) or !is_file($_POST['picture_url'])) ) array_push($errors, l10n('Header picture is not found, check its path and name.')); // 5 - Expected Width and Height limits control if ( !(ctype_digit($_POST['picture_width']) and $_POST['picture_width'] > 11 and $_POST['picture_width'] < 4097 ) ) array_push($errors, '['.$_POST['picture_width'].'] : ' . l10n('incorrect width value [12-4096].')); if ( !(ctype_digit($_POST['picture_height']) and $_POST['picture_height'] > 11 and $_POST['picture_height'] < 201 ) ) array_push($errors, '['.$_POST['picture_height'].'] : ' . l10n('incorrect width value [12-200].')); // 6 - Generate missing colors values list($r1,$g1,$b1) = stc_hex2rgb($main['color'][0]); if ((( (($r1+1)/256)*(($g1+1)/256)*(($b1+1)/256) ) * 1000 ) < 125 ) $main['color6'] = lighten( $r1, $g1, $b1, 10); else $main['color6'] = darken( $r1, $g1, $b1, 10); list($r1,$g1,$b1) = stc_hex2rgb($main['color'][4]); if ((( (($r1+1)/256)*(($g1+1)/256)*(($b1+1)/256) ) * 1000 ) < 125 ) $main['color7'] = lighten( $r1, $g1, $b1, 10); else $main['color7'] = darken( $r1, $g1, $b1, 10); // Go ahead if (count($errors) == 0) { umask(0000); @mkdir($themedir, 0705); if (!is_dir( $themedir )) array_push($errors, l10n('Theme directory creation failure: ' . 'it can\'t be created (for now en attendant la suite 8-) ).')); else { $main['ldelim'] = '{ldelim}'; /* * Build themeconf.inc.php **/ $plugin_tpl = new Template(); $plugin_tpl->set_filenames(array('themeconf'=> STC_PATH . 'themeconf.inc.tpl')); $plugin_tpl->assign('main',$main); $main['themeconf_inc_php'] = $plugin_tpl->parse('themeconf', true); $r = stc_newfile( $themedir . '/themeconf.inc.php', $main['themeconf_inc_php'] ); /* * Build mail-css.tpl **/ $plugin_tpl->set_filenames(array('mailcss'=> STC_PATH . 'mail-css.tpl2')); $plugin_tpl->assign('main',$main); $main['mail-css.tpl'] = $plugin_tpl->parse('mailcss', true); $r = $r && stc_newfile( $themedir . '/mail-css.tpl', $main['mail-css.tpl'] ); /* * Build theme.css **/ $plugin_tpl->set_filenames(array('theme'=> STC_PATH . 'theme.tpl')); $plugin_tpl->assign('main',$main); $main['theme.css'] = $plugin_tpl->parse('theme', true); $r = $r && stc_newfile( $themedir . '/theme.css', $main['theme.css'] ); /* * Build background image for titrePage or definition list (in #menubar) **/ if (function_exists('imagecreatefrompng')) { $img = imagecreatefrompng(STC_PATH . '/titrePage-bg.png'); $dest = imagecreate(1, 64); for ($i=0; $i<256; $i++) { imagecolorallocate($dest, $i, $i, $i); } imagecopy($dest, $img, 0, 0, 0, 0, 1, 64); list($r1,$g1,$b1) = stc_hex2rgb($main['color'][4]); for ($i = 0; $i < 256; $i++) { imagecolorset($dest, $i, min(floor($i * $r1 / 255), 255), min(floor($i * $g1 / 255), 255), min(floor($i * $b1 / 255), 255)); } // to be tested imagecopymerge($dest,$img,0,0,0,0,1,64,33); imagepng( $dest, $themedir . '/stc.png', 9 ); imagedestroy ($img); imagedestroy ($dest); } else @copy( STC_PATH . '/titrePage-bg.png', $themedir . '/stc.png'); if ($r == false) { array_push($errors, l10n('Theme files creation failure: theme should be deleted.')); @unlink( $themedir . '/stc.png' ); @unlink( $themedir . '/themeconf.inc.php' ); @unlink( $themedir . '/mail-css.tpl' ); @unlink( $themedir . '/theme.css' ); @rmdir( $themedir ); } else { array_push($infos, '['.$main['newtpl'] . '/' . $main['newtheme'].'] : ' .l10n('Congratulation! You have got(/ten) a new available theme.')); } } } // TODO ******** HEADER ********* // Interesting Graphic Charter // http://accessites.org/site/2006/08/visual-vs-structural/ $swift_theme_creator->save_theme_config(); } // +-----------------------------------------------------------------------+ // | reset values // +-----------------------------------------------------------------------+ if (isset($_POST['reset']) and (!is_adviser())) { $main = array(); $swift_theme_creator->theme_config = $main; $swift_theme_creator->save_theme_config(); redirect( get_admin_plugin_menu_link(dirname(__FILE__).'/theme_creator.php')); } // To be implemented delete $main save and redirect // Don't forget to re-read because some statements are superfluous // +-----------------------------------------------------------------------+ // | template initialization // +-----------------------------------------------------------------------+ $template->set_filenames(array( 'plugin_admin_content' => dirname(__FILE__) . '/theme_creator.tpl')); $template->append('head_elements', ' ' ); /* Templates */ $template->assign('template_options', $available_templates); if (!isset($main['template_options'])) $main['template_options'] = 0; /* New theme */ if (isset($_POST['new_theme'])) $main['new_theme'] = $_POST['new_theme']; /* Colors */ if (isset($_POST['color1'])) $main['color1'] = $_POST['color1']; if (isset($_POST['color2'])) $main['color2'] = $_POST['color2']; if (isset($_POST['color3'])) $main['color3'] = $_POST['color3']; if (isset($_POST['color4'])) $main['color4'] = $_POST['color4']; if (isset($_POST['color5'])) $main['color5'] = $_POST['color5']; if (!isset($main['color1'])) $main['color1'] = '#111111'; if (!isset($main['color2'])) $main['color2'] = '#EEEEEE'; if (!isset($main['color3'])) $main['color3'] = '#FF7700'; if (!isset($main['color4'])) $main['color4'] = '#FF3333'; if (!isset($main['color5'])) $main['color5'] = '#FF3363'; /* header */ if (isset($_POST['background'])) $main['background'] = $_POST['background']; if (!isset($main['background'])) $main['background'] = 'off'; $template->assign('background_options', array( 'off' => l10n('No'), 'random' => l10n('24H Random'), 'fixed' => l10n('Fixed URL'), )); $query = ' SELECT id,name,uppercats,global_rank FROM ' . CATEGORIES_TABLE . ';'; display_select_cat_wrapper($query,array(),'src_category'); if (isset($_POST['src_category'])) $main['src_category'] = $_POST['src_category']; $main['picture_url'] = PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/sample.jpg'; if (isset($swift_theme_creator->picture_url)) $main['picture_url'] = $swift_theme_creator->picture_url; if (isset($_POST['picture_url'])) $main['picture_url'] = $_POST['picture_url']; if (isset($_POST['picture_width'])) $main['picture_width'] = $_POST['picture_width']; if (!isset($main['picture_width'])) $main['picture_width'] = 2048; if (isset($_POST['picture_height'])) $main['picture_height'] = $_POST['picture_height']; if (!isset($main['picture_height'])) $main['picture_height'] = 100; if (isset($_POST['background_mode'])) $main['background_mode'] = $_POST['background_mode']; if (!isset($main['background_mode'])) $main['background_mode'] = 'as'; $template->assign('background_mode_options', array( 'as' => l10n('As is'), 'crop' => l10n('Truncated'), 'sized' => l10n('Resized'), )); if (count($errors) != 0) $template->assign('errors', $errors); if (count($infos) != 0) $template->assign('infos', $infos); /* Restore Main values */ $template->assign('main', $main); $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); $swift_theme_creator->theme_config = $main; $swift_theme_creator->save_theme_config(); ?>