aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/SwiftThemeCreator/theme_creator.php
diff options
context:
space:
mode:
authorvdigital <vdigital@piwigo.org>2008-07-23 21:53:15 +0000
committervdigital <vdigital@piwigo.org>2008-07-23 21:53:15 +0000
commitc48ec88ed478dc14f846efeb47091d389d09c3c0 (patch)
treef2cd0fbb9c4bc463c5456a0dde9a3a55bc519576 /plugins/SwiftThemeCreator/theme_creator.php
parent49f337a9d8964f8ecd3c8c5eb75601ba9635df13 (diff)
Swift Theme Creator (minor changes): Still incomplete but first functional version (5).
git-svn-id: http://piwigo.org/svn/trunk@2454 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--plugins/SwiftThemeCreator/theme_creator.php182
1 files changed, 113 insertions, 69 deletions
diff --git a/plugins/SwiftThemeCreator/theme_creator.php b/plugins/SwiftThemeCreator/theme_creator.php
index 1c9f0d9df..7bac595ef 100644
--- a/plugins/SwiftThemeCreator/theme_creator.php
+++ b/plugins/SwiftThemeCreator/theme_creator.php
@@ -63,7 +63,20 @@ function darken( $r, $g, $b, $percent)
$b = max(round($b-(($percent*$b)/100)),0);
return sprintf('#%02X%02X%02X', $r, $g, $b);
}
-
+/*
+ * stc_newfile create a new file
+ */
+function stc_newfile( $filename, $data )
+{
+ $fp = fopen($filename, 'w');
+ if ($fp)
+ {
+ $ret = fwrite($fp, $data);
+ fclose($fp);
+ return $ret;
+ }
+ return false;
+}
$errors = array();
$infos = array();
@@ -104,20 +117,23 @@ if (isset($_POST['submit']) and (!is_adviser()))
// 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.
+ // 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 < 125 )
+ if ( $dif < 65 )
array_push($errors,
- l10n('Insufficient brightness difference between text and background. dif=') . $dif);
+ 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);
+ l10n('Insufficient colour difference between '
+ . 'text and background. dif=') . $dif);
// 2.2 - Background and Internal links control
list($r1,$g1,$b1) = stc_hex2rgb($main['color'][0]);
@@ -125,25 +141,28 @@ if (isset($_POST['submit']) and (!is_adviser()))
// 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 < 125 )
+ if ( $dif < 65 )
array_push($errors,
- l10n('Insufficient brightness difference between Internal links and background. dif=') . $dif);
+ 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);
+ 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'] . '/' . $main['newtheme'];
+ $themedir = $main['templatedir'] . '/theme/' . $main['newtheme'];
if (is_dir( $themedir ))
array_push($errors,
- '['.$themedir.'] : '.l10n('Invalid theme: This theme exists already (no override available).'));
+ '['.$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'));
@@ -179,66 +198,85 @@ if (isset($_POST['submit']) and (!is_adviser()))
// Go ahead
if (count($errors) == 0) {
umask(0000);
- // mkdir($themedir, 0777);
+ mkdir($themedir, 0777);
if (!is_dir( $themedir ))
array_push($errors,
- l10n('Theme directory creation failure: it can\'t be created (for now en attendant la suite 8-) ).'));
+ 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'=>
+ dirname(__FILE__) . '/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'=>
+ dirname(__FILE__) . '/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'=>
+ dirname(__FILE__) . '/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(dirname(__FILE__) . '/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( dirname(__FILE__)
+ . '/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.'));
+ }
+ }
}
-
- $main['ldelim'] = '{ldelim}';
- /*
- * Build themeconf.inc.php
- **/
- $plugin_tpl = new Template();
- $plugin_tpl->set_filenames(array('themeconf'=>
- dirname(__FILE__) . '/themeconf.inc.tpl'));
- $plugin_tpl->assign('main',$main);
- $main['themeconf_inc_php'] = $plugin_tpl->parse('themeconf', true);
- /*
- * Build mail-css.tpl
- **/
- $plugin_tpl->set_filenames(array('mailcss'=>
- dirname(__FILE__) . '/mail-css.tpl2'));
- $plugin_tpl->assign('main',$main);
- $main['mail-css.tpl'] = $plugin_tpl->parse('mailcss', true);
-
- // Smarty trace
- $plugin_tpl->assign('main',$main);
// Interesting Graphic Charter
// http://accessites.org/site/2006/08/visual-vs-structural/
- /*
- * Build background image for titrePage or definition list (in #menubar)
- **/
- if (function_exists('imagecreatefrompng'))
- {
- $img = imagecreatefrompng(dirname(__FILE__) . '/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($i * $r1 / 255, 255),
- min($i * $g1 / 255, 255),
- min($i * $b1 / 255, 255));
- }
- // to be tested imagecopymerge($dest,$img,0,0,0,0,1,64,33);
-
- // Uncomment to create the header stc.png
- // imagepng( $dest, dirname(__FILE__) . '/stc.png', 9 );
- imagedestroy ($img);
- imagedestroy ($dest);
- }
-
-
- /* All logic is there
- * On "todo" : Create files and uncomment some previous statements.
- */
-
-
$swift_theme_creator->save_theme_config();
}
@@ -256,10 +294,13 @@ if (isset($_POST['submit']) and (!is_adviser()))
$template->set_filenames(array(
'plugin_admin_content' => dirname(__FILE__) . '/theme_creator.tpl'));
$template->append('head_elements',
- '<script type="text/javascript" src="./plugins/SwiftThemeCreator/farbtastic/farbtastic.js"></script>
-<link rel="stylesheet" href="./plugins/SwiftThemeCreator/farbtastic/farbtastic.css" type="text/css" />
+ '<script type="text/javascript"
+ src="./plugins/SwiftThemeCreator/farbtastic/farbtastic.js"></script>
+<link rel="stylesheet" type="text/css"
+ href="./plugins/SwiftThemeCreator/farbtastic/farbtastic.css" />
<style type="text/css" media="screen">
-.colorwell { border: 3px double #F30; width: 6em; text-align: center; cursor: pointer; }
+.colorwell { border: 3px double #F30; width: 6em;
+ text-align: center; cursor: pointer; }
body .colorwell-selected { border: 3px double #F36; font-weight: bold; }
.radio { margin: 0 10px 0 50px; }
</style>'
@@ -306,9 +347,11 @@ 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($_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($_POST['picture_height']))
+ $main['picture_height'] = $_POST['picture_height'];
if (!isset($main['picture_height'])) $main['picture_height'] = 100;
if (isset($_POST['background_mode']))
@@ -321,9 +364,10 @@ $template->assign('background_mode_options',
'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();
-?>
+?> \ No newline at end of file