Changeset 2454


Ignore:
Timestamp:
Jul 23, 2008, 11:53:15 PM (16 years ago)
Author:
vdigital
Message:

Swift Theme Creator (minor changes): Still incomplete but first functional version (5).

Location:
trunk/plugins/SwiftThemeCreator
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/SwiftThemeCreator/mail-css.tpl2

    r2453 r2454  
    11/* Theme {$main.newtheme} mail css */
    22
    3 body {$main.ldelim} background-color:{$main.colour1}; color:{$main.colour2};}
    4 #the_page {$main.ldelim} background: {$main.colour1} url({ldelim}$ROOT_URL}template/{ldelim}$themeconf.template}/mail/text/html/images/mailbody-bg.png) repeat-y scroll left top;}
     3body {$main.ldelim} background-color:{$main.color1}; color:{$main.color2};}
     4#the_page {$main.ldelim} background: {$main.color1} url({ldelim}$ROOT_URL}template/{ldelim}$themeconf.template}/mail/text/html/images/mailbody-bg.png) repeat-y scroll left top;}
    55#content {$main.ldelim} background: transparent url({ldelim}$ROOT_URL}template/{ldelim}$themeconf.template}/mail/text/html/images/header-bg.png) no-repeat scroll left top;}
    66#copyright {$main.ldelim} background: transparent url({ldelim}$ROOT_URL}template/{ldelim}$themeconf.template}/mail/text/html/images/footer-bg.png) no-repeat scroll left bottom;
    7 color: {$main.colour2};}
    8 h2 {$main.ldelim} background-color: {$main.colour7};color:#eee;background-image: url({ldelim}$ROOT_URL}template/{ldelim}$themeconf.template}/theme/{ldelim}$themeconf.theme}/images/tableh1_bg.png);}
     7color: {$main.color2};}
     8h2 {$main.ldelim} background-color: {$main.color7};color:#eee;background-image: url({ldelim}$ROOT_URL}template/{ldelim}$themeconf.template}/theme/{ldelim}$themeconf.theme}/images/tableh1_bg.png);}
    99img {$main.ldelim} margin: 16px; padding:15px;border:1px solid #eee; -moz-border-radius: 4px; border-radius: 4px 4px; }
    10 img:hover {$main.ldelim} border:1px solid {$main.colour2}; -moz-border-radius: 4px; border-radius: 4px 4px; }
    11 a {$main.ldelim} color: {$main.colour2}; background: transparent; }
    12 a:hover {$main.ldelim} color: {$main.colour3}; }
     10img:hover {$main.ldelim} border:1px solid {$main.color2}; -moz-border-radius: 4px; border-radius: 4px 4px; }
     11a {$main.ldelim} color: {$main.color2}; background: transparent; }
     12a:hover {$main.ldelim} color: {$main.color3}; }
    1313a.PWG {$main.ldelim} border: 0px; }
    14 a.PWG .P {$main.ldelim} color : {$main.colour3}; }
    15 a.PWG .W {$main.ldelim} color : {$main.colour5}; }
    16 a.PWG .G {$main.ldelim} color : {$main.colour2}; }
    17 a.PWG:hover .P {$main.ldelim} color : {$main.colour2}; }
    18 a.PWG:hover .G {$main.ldelim} color : {$main.colour3}; }
     14a.PWG .P {$main.ldelim} color : {$main.color3}; }
     15a.PWG .W {$main.ldelim} color : {$main.color5}; }
     16a.PWG .G {$main.ldelim} color : {$main.color2}; }
     17a.PWG:hover .P {$main.ldelim} color : {$main.color2}; }
     18a.PWG:hover .G {$main.ldelim} color : {$main.color3}; }
  • trunk/plugins/SwiftThemeCreator/theme_creator.php

    r2453 r2454  
    6464  return sprintf('#%02X%02X%02X', $r, $g, $b);
    6565}
    66 
     66/*
     67 * stc_newfile create a new file
     68 */
     69function stc_newfile( $filename, $data )
     70{
     71  $fp = fopen($filename, 'w');
     72  if ($fp)
     73  {
     74    $ret = fwrite($fp, $data);
     75    fclose($fp);
     76    return $ret;
     77  }
     78  return false;
     79}
    6780
    6881$errors = array();
     
    105118  list($r1,$g1,$b1) = stc_hex2rgb($main['color'][0]);
    106119  list($r2,$g2,$b2) = stc_hex2rgb($main['color'][1]);
    107   // Formula for converting RGB values to YIQ values as perceived brightness difference.
     120  // Formula for converting RGB values to YIQ values
     121  // as perceived brightness difference.
    108122  // Background and text "brightness" difference control:
    109123  $dif = abs( ( (($r1*299)+($g1*587)+($b1*114)) / 1000 )
    110124          - ( (($r2*299)+($g2*587)+($b2*114)) / 1000 ));
    111   if ( $dif < 125 )
     125  if ( $dif < 65 )
    112126      array_push($errors,
    113        l10n('Insufficient brightness difference between text and background. dif=') . $dif);
     127       l10n('Insufficient brightness difference between '
     128            . 'text and background. dif=') . $dif);
    114129  // Background and text "colour" difference control:
    115130  $dif = (max($r1, $r2) - min($r1, $r2))
     
    118133  if ( $dif < 200 )
    119134    array_push($errors,
    120        l10n('Insufficient colour difference between text and background. dif=') . $dif);
     135       l10n('Insufficient colour difference between '
     136            . 'text and background. dif=') . $dif);
    121137
    122138  // 2.2 - Background and Internal links control
     
    126142  $dif = abs( ( (($r1*299)+($g1*587)+($b1*114)) / 1000 )
    127143          - ( (($r2*299)+($g2*587)+($b2*114)) / 1000 ));
    128   if ( $dif < 125 )
     144  if ( $dif < 65 )
    129145      array_push($errors,
    130        l10n('Insufficient brightness difference between Internal links and background. dif=') . $dif);
     146       l10n('Insufficient brightness difference between '
     147            . 'Internal links and background. dif=') . $dif);
    131148  // Background and Internal links "colour" difference control:
    132149  $dif = (max($r1, $r2) - min($r1, $r2))
     
    135152  if ( $dif < 200 )
    136153    array_push($errors,
    137        l10n('Insufficient colour difference between Internal links and background. dif=') . $dif);
     154       l10n('Insufficient colour difference between '
     155            . 'Internal links and background. dif=') . $dif);
    138156
    139157  // 3 - Directory control
     
    141159               . $available_templates[$_POST['template']];
    142160  $main['newtpl'] = $available_templates[$_POST['template']];
    143   $themedir = $main['templatedir'] . '/' . $main['newtheme'];
     161  $themedir = $main['templatedir'] . '/theme/' . $main['newtheme'];
    144162  if (is_dir(  $themedir ))
    145163    array_push($errors,
    146        '['.$themedir.'] : '.l10n('Invalid theme: This theme exists already (no override available).'));
     164       '['.$themedir.'] : '.l10n('Invalid theme: This theme exists '
     165                           . 'already (no override available).'));
    147166  elseif (!is_writable($main['templatedir']))
    148167    array_push($errors,
     
    180199  if (count($errors) == 0) {
    181200    umask(0000);
    182     // mkdir($themedir, 0777);
     201    mkdir($themedir, 0777);
    183202    if (!is_dir(  $themedir ))
    184203        array_push($errors,
    185           l10n('Theme directory creation failure: it can\'t be created (for now en attendant la suite 8-) ).'));
     204          l10n('Theme directory creation failure: '
     205          . 'it can\'t be created (for now en attendant la suite 8-) ).'));
     206    else {
     207      $main['ldelim'] = '{ldelim}';
     208      /*
     209       * Build themeconf.inc.php
     210       **/
     211      $plugin_tpl = new Template();
     212      $plugin_tpl->set_filenames(array('themeconf'=>
     213      dirname(__FILE__) . '/themeconf.inc.tpl'));
     214      $plugin_tpl->assign('main',$main);
     215      $main['themeconf_inc_php'] = $plugin_tpl->parse('themeconf', true);
     216      $r = stc_newfile( $themedir . '/themeconf.inc.php',
     217        $main['themeconf_inc_php'] );
     218      /*
     219       * Build mail-css.tpl
     220       **/ 
     221      $plugin_tpl->set_filenames(array('mailcss'=>
     222      dirname(__FILE__) . '/mail-css.tpl2'));
     223      $plugin_tpl->assign('main',$main);
     224      $main['mail-css.tpl'] = $plugin_tpl->parse('mailcss', true); 
     225      $r = $r && stc_newfile( $themedir . '/mail-css.tpl',
     226        $main['mail-css.tpl'] );
     227      /*
     228       * Build theme.css
     229       **/ 
     230      $plugin_tpl->set_filenames(array('theme'=>
     231      dirname(__FILE__) . '/theme.tpl'));
     232      $plugin_tpl->assign('main',$main);
     233      $main['theme.css'] = $plugin_tpl->parse('theme', true); 
     234      $r = $r && stc_newfile( $themedir . '/theme.css',
     235        $main['theme.css'] );
     236      /*
     237       * Build background image for titrePage or definition list (in #menubar)
     238       **/
     239      if (function_exists('imagecreatefrompng'))
     240      {
     241        $img = imagecreatefrompng(dirname(__FILE__) . '/titrePage-bg.png');
     242        $dest = imagecreate(1, 64);
     243        for ($i=0; $i<256; $i++) {
     244          imagecolorallocate($dest, $i, $i, $i);
     245        }
     246        imagecopy($dest, $img, 0, 0, 0, 0, 1, 64);
     247        list($r1,$g1,$b1) = stc_hex2rgb($main['color'][4]);
     248        for ($i = 0; $i < 256; $i++) {
     249          imagecolorset($dest, $i, min(floor($i * $r1 / 255), 255),
     250                         min(floor($i * $g1 / 255), 255),
     251                         min(floor($i * $b1 / 255), 255));
     252        }
     253        // to be tested imagecopymerge($dest,$img,0,0,0,0,1,64,33);
     254        imagepng( $dest, $themedir . '/stc.png', 9 );
     255        imagedestroy ($img);
     256        imagedestroy ($dest);
     257      }
     258      else @copy( dirname(__FILE__)
     259                 . '/titrePage-bg.png', $themedir . '/stc.png');     
     260      if ($r == false) {
     261        array_push($errors,
     262          l10n('Theme files creation failure: theme should be deleted.'));
     263        @unlink( $themedir . '/stc.png' );
     264        @unlink( $themedir . '/themeconf.inc.php' );
     265        @unlink( $themedir . '/mail-css.tpl' );
     266        @unlink( $themedir . '/theme.css' );
     267        @rmdir( $themedir );
     268      }
     269      else {
     270        array_push($infos,
     271       '['.$main['newtpl'] . '/' . $main['newtheme'].'] : '
     272       .l10n('Congratulation! You have got(/ten) a new available theme.'));
     273      }
     274    }
    186275  }
    187 
    188   $main['ldelim'] = '{ldelim}';
    189   /*
    190    * Build themeconf.inc.php
    191    **/
    192   $plugin_tpl = new Template();
    193   $plugin_tpl->set_filenames(array('themeconf'=>
    194   dirname(__FILE__) . '/themeconf.inc.tpl'));
    195   $plugin_tpl->assign('main',$main);
    196   $main['themeconf_inc_php'] = $plugin_tpl->parse('themeconf', true);
    197   /*
    198    * Build mail-css.tpl
    199    **/ 
    200   $plugin_tpl->set_filenames(array('mailcss'=>
    201   dirname(__FILE__) . '/mail-css.tpl2'));
    202   $plugin_tpl->assign('main',$main);
    203   $main['mail-css.tpl'] = $plugin_tpl->parse('mailcss', true); 
    204 
    205   // Smarty trace
    206   $plugin_tpl->assign('main',$main);
    207276 
    208277  // Interesting Graphic Charter
    209278  // http://accessites.org/site/2006/08/visual-vs-structural/
    210279
    211   /*
    212    * Build background image for titrePage or definition list (in #menubar)
    213    **/
    214   if (function_exists('imagecreatefrompng'))
    215   {
    216     $img = imagecreatefrompng(dirname(__FILE__) . '/titrePage-bg.png');
    217     $dest = imagecreate(1, 64);
    218     for ($i=0; $i<256; $i++) {
    219       imagecolorallocate($dest, $i, $i, $i);
    220     }
    221     imagecopy($dest, $img, 0, 0, 0, 0, 1, 64);
    222     list($r1,$g1,$b1) = stc_hex2rgb($main['color'][4]);
    223     for ($i = 0; $i < 256; $i++) {
    224       imagecolorset($dest, $i, min($i * $r1 / 255, 255),
    225                      min($i * $g1 / 255, 255),
    226                      min($i * $b1 / 255, 255));
    227     }
    228     // to be tested imagecopymerge($dest,$img,0,0,0,0,1,64,33);
    229    
    230     // Uncomment to create the header stc.png
    231     // imagepng( $dest, dirname(__FILE__) . '/stc.png', 9 );
    232     imagedestroy ($img);
    233     imagedestroy ($dest);
    234   }
    235 
    236  
    237   /* All logic is there
    238    * On "todo" : Create files and uncomment some previous statements.
    239    */
    240 
    241 
    242280  $swift_theme_creator->save_theme_config(); 
    243281}
     
    257295    'plugin_admin_content' => dirname(__FILE__) . '/theme_creator.tpl'));
    258296$template->append('head_elements',
    259   '<script type="text/javascript" src="./plugins/SwiftThemeCreator/farbtastic/farbtastic.js"></script>
    260 <link rel="stylesheet" href="./plugins/SwiftThemeCreator/farbtastic/farbtastic.css" type="text/css" />
     297   '<script type="text/javascript"
     298        src="./plugins/SwiftThemeCreator/farbtastic/farbtastic.js"></script>
     299<link rel="stylesheet" type="text/css"
     300      href="./plugins/SwiftThemeCreator/farbtastic/farbtastic.css" />
    261301<style type="text/css" media="screen">
    262 .colorwell { border: 3px double #F30; width: 6em; text-align: center; cursor: pointer; }
     302.colorwell { border: 3px double #F30; width: 6em;
     303  text-align: center; cursor: pointer; }
    263304body .colorwell-selected { border: 3px double #F36; font-weight: bold; }
    264305.radio { margin: 0 10px 0 50px; }
     
    307348if (isset($_POST['picture_url'])) $main['picture_url'] = $_POST['picture_url'];
    308349
    309 if (isset($_POST['picture_width'])) $main['picture_width'] = $_POST['picture_width'];
     350if (isset($_POST['picture_width']))
     351    $main['picture_width'] = $_POST['picture_width'];
    310352if (!isset($main['picture_width'])) $main['picture_width'] = 2048;
    311 if (isset($_POST['picture_height'])) $main['picture_height'] = $_POST['picture_height'];
     353if (isset($_POST['picture_height']))
     354    $main['picture_height'] = $_POST['picture_height'];
    312355if (!isset($main['picture_height'])) $main['picture_height'] = 100;
    313356
     
    322365  ));
    323366if (count($errors) != 0) $template->assign('errors', $errors);
     367if (count($infos) != 0) $template->assign('infos', $infos);
    324368/* Restore Main values */
    325369$template->assign('main', $main);
Note: See TracChangeset for help on using the changeset viewer.