Changeset 2487


Ignore:
Timestamp:
Aug 26, 2008, 4:18:42 PM (16 years ago)
Author:
vdigital
Message:

Swift Theme Creator (minor changes): partly functional version.

Location:
trunk
Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/SwiftThemeCreator/theme.tpl

    r2461 r2487  
    1010A, INPUT.rateButton {ldelim} color: {$main.color3}; }
    1111
    12 UL.tabsheet LI.normal_tab:hover {ldelim} border: 1px solid {$main.color4}; }
     12UL.tabsheet LI.normal_tab:hover {ldelim} border: 1px solid {$main.color3}; }
    1313A:hover {ldelim}        color: {$main.color4}; }
    1414
     
    1616.content UL.thumbnailCategories DIV.thumbnailCategory:hover,
    1717.content UL.thumbnailCategories DIV.thumbnailCategory:hover A {ldelim}
    18  color: {$main.color4}; border: 1px solid {$main.color5}; background-color: {$main.color6}; }
     18 color: {$main.color4}; border: 1px solid {$main.color4}; background-color: {$main.color6}; }
    1919
    2020#menubar DL, .content, #comments DIV.comment BLOCKQUOTE,
    21 #imageHeaderBar, H2, #menubar DT, #imageToolBar {ldelim} border: 1px solid {$main.color5}; }
     21#imageHeaderBar, H2, #menubar DT, #imageToolBar {ldelim} border: 1px solid {$main.color4}; }
    2222
    2323#menubar DL, .content, #imageToolBar, .header_notes, UL.tabsheet LI.selected_tab {ldelim}
  • trunk/plugins/SwiftThemeCreator/theme_creator.php

    r2461 r2487  
    2222// +-----------------------------------------------------------------------+
    2323
    24 /* Ajouter le lien au menu de l'admin */
     24/* TODO: Revoir le lien du menu de l'admin */
    2525if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    2626if (!defined('IN_ADMIN') or !IN_ADMIN) die('Hacking attempt!');
    27 define(STC_PATH, PHPWG_PLUGINS_PATH.'SwiftThemeCreator/');
     27define('STC_PATH', PHPWG_PLUGINS_PATH.'SwiftThemeCreator/');
     28define('STC_INTERNAL_VERSION', '1.40');
    2829/*
    2930 * stc_hex2rgb convert any string to array of RGB values
     
    7778  return false;
    7879}
     80/*
     81 * Default values
     82 */
     83function init_main(&$main)
     84{
     85  global $available_templates;
     86  $main = array(
     87    STC_INTERNAL_VERSION => true, /* $main version */
     88    'template_sel' => 0,
     89    'newtpl' => 'yoga',
     90    'newtheme' => '',
     91    'simulate' => true,
     92    'colorize' => false,
     93    'brightness' => false,
     94    'contrast' => false,
     95    'new_theme' => '',
     96    'color1' => '#111111',
     97    'color' => array('#111111', '#EEEEEE', '#FF7700', '#FF3333', '#FF3363', ),
     98    'templatedir' => PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul',
     99    'color1' => '#111111',
     100    'color2' => '#EEEEEE',
     101    'color3' => '#FF7700',
     102    'color4' => '#FF3333',
     103    'color5' => '#FF3363',
     104    'background' => 'fixed',
     105    'picture_url' => PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/sample.jpg',
     106    'picture_width' => 2048,
     107    'picture_height' => 100,
     108    'background_mode' => 'as',
     109    'src_category' => 0,
     110    'category' => 'header',
     111    'phase' => 'Kernel init',
     112    'subphase' => 'New version',
     113  );   
     114}
    79115
    80116$errors = array();
    81117$infos = array();
     118
     119// +-----------------------------------------------------------------------+
     120// |                            Kernel init                                |
     121// +-----------------------------------------------------------------------+
     122if (!isset($swift_theme_creator)) $swift_theme_creator = new ThemeCreator();
     123$swift_theme_creator->reload();
     124$main = $swift_theme_creator->theme_config;
     125
     126/*
     127 * Find templates
     128 */
    82129$available_templates = array();
    83130$template_dir = PHPWG_ROOT_PATH.'template';
    84131foreach (get_dirs($template_dir) as $dir)
    85 {
    86   array_push($available_templates, $dir);
    87 }
    88 
    89 // +-----------------------------------------------------------------------+
    90 // |                            selected templates                         |
    91 // +-----------------------------------------------------------------------+
    92 if (!isset($swift_theme_creator)) $swift_theme_creator = new ThemeCreator();
    93 $swift_theme_creator->reload();
    94 $main = $swift_theme_creator->theme_config;
    95 
    96 if (isset($_POST['submit']) and (!is_adviser()))
    97 {
    98   // 1 - Theme name control
    99   $main['newtheme'] = strip_tags($_POST['new_theme']);
    100   if ( !preg_match('/^[a-z0-9-_]{1,8}$/', $main['newtheme']) )
    101       array_push($errors,
    102          l10n('Invalid theme name: 1 to 8 lowercase alphanumeric characters'
    103          . ' including "-" and "_".'));
    104 
    105   // 2 - Colours control
    106   $main['color'] = array($_POST['color1'], $_POST['color2'],
    107                          $_POST['color3'], $_POST['color4'],
    108                          $_POST['color5']);
    109   $colors = $main['color'][0] . $main['color'][1] . $main['color'][2]
    110           . $main['color'][3] . $main['color'][4];
     132{ array_push($available_templates, $dir);
     133}
     134/*
     135 * $main is reloaded but does template still exist?
     136 * Does the fixed background still exist? Category? ...
     137 */
     138if (!isset($main[STC_INTERNAL_VERSION])) init_main($main);
     139$flip = array_flip($available_templates);
     140$main['template_sel'] = (isset($flip[$main['newtpl']])) ?
     141    $flip[$main['newtpl']] : 0; /* Deleted ? First available */
     142$main['subphase'] = 'Find category';
     143$query = 'SELECT id,name,uppercats,global_rank
     144  FROM ' . CATEGORIES_TABLE . ';';
     145display_select_cat_wrapper($query,array(),'src_category');
     146$available_cat = $template->get_template_vars('src_category');
     147$flip = array_flip($available_cat);
     148$main['src_category'] = (isset($flip[$main['category']])) ?
     149    $flip[$main['category']] : max($flip); /* Deleted ? Most recent */
     150
     151   
     152// +-----------------------------------------------------------------------+
     153// |                            $_POST controls                            |
     154// +-----------------------------------------------------------------------+
     155$main['phase'] = 'POST controls';
     156if (!isset($_POST['reset']))
     157{
     158  $main['simulate'] = isset($_POST['simulate']);
     159  if (!isset($_POST['submit'])) $main['simulate'] = true;
     160  /*
     161   * Template controls
     162   */
     163  $main['subphase'] = 'template controls';
     164  if (isset($_POST['template'])) $main['template_sel'] = $_POST['template'];
     165  $main['newtpl'] = $available_templates[$main['template_sel']];
     166  if ($main['newtpl'] != 'yoga')
     167    array_push($infos, l10n('Unpredictable results could be observed with '
     168        . 'this template. Preview is based on yoga template only.'));
     169
     170  /*
     171   * Theme controls
     172   */
     173  $main['subphase'] = 'theme controls';
     174  if (isset($_POST['new_theme'])) $main['newtheme'] = strip_tags($_POST['new_theme']);
     175  if ($main['newtheme'] == '') $main['simulate'] = true; /* Empty = Simulate */
     176  $cleaning = true; /* Delete files on failure */
     177  if ( !$main['simulate'] and !preg_match('/^[a-z0-9-_]{1,8}$/', $main['newtheme']) )
     178    array_push($errors, l10n('Invalid theme name: 1 to 8 lowercase'
     179      . ' alphanumeric characters including "-" and "_".'));
     180  if ($main['simulate']) { /* $main['templatedir'] != $template_dir (Smarty) */
     181    $main['templatedir'] = PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul';
     182    $themedir = $main['templatedir'];
     183    $cleaning = false; /* No delete with simulate */
     184  } else {
     185    $main['templatedir'] = PHPWG_ROOT_PATH . 'template/' . $main['newtpl'];
     186    $themedir = $main['templatedir'] . '/theme/' . $main['newtheme'];
     187  }
     188
     189  /*
     190   * Directories controls
     191   */
     192  $main['subphase'] = 'directories controls';
     193  if (is_dir( $themedir ) and !$main['simulate']) {
     194    array_push($errors, '['.$themedir.'] : '.l10n('Invalid theme: This'
     195         . ' theme exists already (no override available).'));
     196    $cleaning = false; /* No delete on existing theme */
     197  } elseif ( !is_writable($main['templatedir']) )
     198    array_push($errors, '['.$main['templatedir'].'] : '.l10n('no_write_access'));
     199
     200  /*
     201   * Colors controls
     202   */
     203  $main['subphase'] = 'colors controls';
     204  if (isset($_POST['color1']))
     205    $main['color'] = array(
     206      $_POST['color1'], $_POST['color2'], $_POST['color3'], $_POST['color4'],
     207      $_POST['color5']);
     208  $main['color1'] = $main['color'][0];
     209  $main['color2'] = $main['color'][1];
     210  $main['color3'] = $main['color'][2];
     211  $main['color4'] = $main['color'][3];
     212  $main['color5'] = $main['color'][4];
     213  $colors = $main['color1'] . $main['color2']
     214          . $main['color3'] . $main['color4'] . $main['color5'];
    111215  if ( !preg_match('/^(#?([A-Fa-f0-9]{3}|[A-Fa-f0-9]{6})){5}$/', $colors) )
    112       array_push($errors,
    113          l10n('Invalid color code: 3 or 6 hexadecimal characters, preceded'
    114          . ' or not by "#"'));
    115 
    116   // 2.1 - Background and text control
    117   list($r1,$g1,$b1) = stc_hex2rgb($main['color'][0]);
     216    array_push($errors, l10n('Invalid color code: 3 or 6 hexadecimal characters,'
     217          . ' preceded or not by "#"'));
     218 
     219  /*
     220   * Background and text difference control
     221   */
     222  $main['subphase'] = 'text difference controls';
     223  list($r,$g,$b) = stc_hex2rgb($main['color'][0]);
    118224  list($r2,$g2,$b2) = stc_hex2rgb($main['color'][1]);
    119   // Formula for converting RGB values to YIQ values
    120   // as perceived brightness difference.
    121   // Background and text "brightness" difference control:
    122   $dif = abs( ( (($r1*299)+($g1*587)+($b1*114)) / 1000 )
    123           - ( (($r2*299)+($g2*587)+($b2*114)) / 1000 ));
     225  $dif = abs( ( (($r*299)+($g*587)+($b*114)) / 1000 )
     226          - ( (( $r2*299)+($g2*587)+($b2*114)) / 1000 ) );
    124227  if ( $dif < 65 )
    125       array_push($errors,
    126        l10n('Insufficient brightness difference between '
    127             . 'text and background. dif=') . $dif);
    128   // Background and text "colour" difference control:
    129   $dif = (max($r1, $r2) - min($r1, $r2))
    130      + (max($g1, $g2) - min($g1, $g2))
    131      + (max($b1, $b2) - min($b1, $b2));
     228    array_push($errors, l10n('Insufficient brightness difference between '
     229          . 'text and background. dif=') . $dif);
     230  $dif = (max($r, $r2) - min($r, $r2))
     231     + (max($g, $g2) - min($g, $g2)) + (max($b, $b2) - min($b, $b2));
    132232  if ( $dif < 200 )
    133     array_push($errors,
    134        l10n('Insufficient colour difference between '
    135             . 'text and background. dif=') . $dif);
    136 
    137   // 2.2 - Background and Internal links control
    138   if (isset($do_it))
     233    array_push($errors, l10n('Insufficient colour difference between '
     234          . 'text and background. dif=') . $dif);
     235
     236  /*
     237   * Background and Internal links difference control
     238   */
     239  $main['subphase'] = 'links difference controls';
     240  if (false)
    139241  {
    140     list($r1,$g1,$b1) = stc_hex2rgb($main['color'][0]);
     242    list($r,$g,$b) = stc_hex2rgb($main['color'][0]);
    141243    list($r2,$g2,$b2) = stc_hex2rgb($main['color'][2]);
    142     // Background and Internal links "brightness" difference control:
    143     $dif = abs( ( (($r1*299)+($g1*587)+($b1*114)) / 1000 )
     244    $dif = abs( ( (($r*299)+($g*587)+($b*114)) / 1000 )
    144245            - ( (($r2*299)+($g2*587)+($b2*114)) / 1000 ));
    145246    if ( $dif < 65 )
    146         array_push($errors,
    147          l10n('Insufficient brightness difference between '
    148               . 'Internal links and background. dif=') . $dif);
    149     // Background and Internal links "colour" difference control:
    150     $dif = (max($r1, $r2) - min($r1, $r2))
    151        + (max($g1, $g2) - min($g1, $g2))
    152        + (max($b1, $b2) - min($b1, $b2));
     247      array_push($errors, l10n('Insufficient brightness difference between '
     248            . 'Internal links and background. dif=') . $dif);
     249    $dif = (max($r, $r2) - min($r, $r2))
     250       + (max($g, $g2) - min($g, $g2)) + (max($b, $b2) - min($b, $b2));
    153251    if ( $dif < 200 )
    154       array_push($errors,
    155          l10n('Insufficient colour difference between '
    156               . 'Internal links and background. dif=') . $dif);
     252      array_push($errors, l10n('Insufficient colour difference between '
     253            . 'Internal links and background. dif=') . $dif);
    157254  }
    158   // 3 - Directory control
    159   $main['templatedir'] = PHPWG_ROOT_PATH . 'template/'
    160                . $available_templates[$_POST['template']];
    161   $main['newtpl'] = $available_templates[$_POST['template']];
    162   $themedir = $main['templatedir'] . '/theme/' . $main['newtheme'];
    163   if (is_dir(  $themedir ))
    164     array_push($errors,
    165        '['.$themedir.'] : '.l10n('Invalid theme: This theme exists '
    166                            . 'already (no override available).'));
    167   elseif (!is_writable($main['templatedir']))
    168     array_push($errors,
    169        '['.$main['templatedir'].'] : '.l10n('no_write_access'));
    170 
    171   // 4 - Picture URL control
    172   if ( $_POST['background'] == 'fixed' and (is_dir($_POST['picture_url'])
    173       or !is_file($_POST['picture_url'])) )
    174     array_push($errors,
    175        l10n('Header picture is not found, check its path and name.'));
    176  
    177   // 5 - Expected Width and Height limits control
    178   if ( !(ctype_digit($_POST['picture_width']) and $_POST['picture_width'] > 11
    179        and $_POST['picture_width'] < 4097 ) )
    180     array_push($errors,
    181        '['.$_POST['picture_width'].'] : '
    182        . l10n('incorrect width value [12-4096].'));
    183   if ( !(ctype_digit($_POST['picture_height']) and $_POST['picture_height'] > 11
    184        and $_POST['picture_height'] < 201 ) )
    185     array_push($errors,
    186        '['.$_POST['picture_height'].'] : '
    187        . l10n('incorrect width value [12-200].'));
    188        
    189   // 6 - Generate missing colors values
    190   list($r1,$g1,$b1) = stc_hex2rgb($main['color'][0]);
    191   if ((( (($r1+1)/256)*(($g1+1)/256)*(($b1+1)/256) ) * 1000 ) < 125 )
    192        $main['color6'] = lighten( $r1, $g1, $b1, 10);
    193   else $main['color6'] = darken( $r1, $g1, $b1, 10);
    194   list($r1,$g1,$b1) = stc_hex2rgb($main['color'][4]);
    195   if ((( (($r1+1)/256)*(($g1+1)/256)*(($b1+1)/256) ) * 1000 ) < 125 )
    196        $main['color7'] = lighten( $r1, $g1, $b1, 10);
    197   else $main['color7'] = darken( $r1, $g1, $b1, 10);
    198 
    199   // Go ahead
     255
     256  /*
     257   * Header background controls
     258   */
     259  $main['subphase'] = 'fixed background controls';
     260  if (isset($_POST['background'])) $main['background'] = $_POST['background'];
     261  // Fixed
     262  if ( $main['background'] == 'fixed' and isset($_POST['picture_url'])) {
     263    if ( is_dir($_POST['picture_url'])
     264        or !is_file($_POST['picture_url']) )
     265      array_push($errors, l10n('Header picture is not found, check its path and name.'));
     266    $extension = substr($_POST['picture_url'],strrpos($_POST['picture_url'],'.')+1);
     267    if (!in_array($extension, array('jpg','jpeg','png')))
     268      array_push($errors, l10n('Compliant extensions are .jpg, .jpeg or .png.'));
     269  }
     270  $main['subphase'] = 'random background controls';
     271  if (isset($_POST['src_category']))
     272    $main['src_category'] = (int) $_POST['src_category'];
     273  $main['category'] = $available_cat[$main['src_category']];
     274
     275  /*
     276   * Width and Height limits control
     277   */
     278  $main['subphase'] = 'width and height controls';
     279  if ($main['background'] != 'off'
     280    and isset($_POST['picture_width'])
     281    and isset($_POST['picture_height']))
     282  {
     283    if( !(ctype_digit($_POST['picture_width'])
     284      and $_POST['picture_width'] > 11
     285      and $_POST['picture_width'] < 4097 ) )
     286      array_push($errors, '['.$_POST['picture_width'].'] : '
     287            . l10n('incorrect width value [12-4096].'));
     288    else $main['picture_width'] = $_POST['picture_width'];
     289    if ( !(ctype_digit($_POST['picture_height'])
     290      and $_POST['picture_height'] > 11
     291      and $_POST['picture_height'] < 201 ) )
     292      array_push($errors, '['.$_POST['picture_height'].'] : '
     293            . l10n('incorrect width value [12-200].'));
     294    else $main['picture_height'] = $_POST['picture_height'];
     295  }     
     296
     297  /*
     298   * Generate missing colors values
     299   */
     300  $main['subphase'] = 'complementary colors';
     301  list($r,$g,$b) = stc_hex2rgb($main['color'][0]);
     302  if ((( (($r+1)/256)*(($g+1)/256)*(($b+1)/256) ) * 1000 ) < 125 )
     303       $main['color6'] = lighten( $r, $g, $b, 10);
     304  else $main['color6'] = darken( $r, $g, $b, 10);
     305  list($r,$g,$b) = stc_hex2rgb($main['color'][4]);
     306  if ((( (($r+1)/256)*(($g+1)/256)*(($b+1)/256) ) * 1000 ) < 125 )
     307       $main['color7'] = lighten( $r, $g, $b, 10);
     308  else $main['color7'] = darken( $r, $g, $b, 10);
     309  $main['colorize'] = isset($_POST['colorize']) ? true : false;
     310  $main['brightness'] = isset($_POST['brightness']) ? true : false;
     311  $main['contrast'] = isset($_POST['contrast']) ? true : false;
     312}
     313
     314// +-----------------------------------------------------------------------+
     315// |                            Build files                                |
     316// +-----------------------------------------------------------------------+
     317$main['phase'] = 'Files building';
     318if ((isset($_POST['submit']) or $main['simulate'] ) and (!is_adviser()))
     319{
     320  /*
     321   * Go ahead
     322   */
     323  $main['subphase'] = 'Mkdir control';
    200324  if (count($errors) == 0) {
    201325    umask(0000);
     
    210334       * Build themeconf.inc.php
    211335       **/
     336      $main['subphase'] = 'Build themeconf';
    212337      $plugin_tpl = new Template();
    213338      $plugin_tpl->set_filenames(array('themeconf'=>
     
    215340      $plugin_tpl->assign('main',$main);
    216341      $main['themeconf_inc_php'] = $plugin_tpl->parse('themeconf', true);
    217       $r = stc_newfile( $themedir . '/themeconf.inc.php',
     342      $rfs = stc_newfile( $themedir . '/themeconf.inc.php',
    218343        $main['themeconf_inc_php'] );
    219344      /*
    220345       * Build mail-css.tpl
    221346       **/ 
     347      $main['subphase'] = 'Build mail-css';
    222348      $plugin_tpl->set_filenames(array('mailcss'=>
    223349      STC_PATH . 'mail-css.tpl2'));
    224350      $plugin_tpl->assign('main',$main);
    225351      $main['mail-css.tpl'] = $plugin_tpl->parse('mailcss', true); 
    226       $r = $r && stc_newfile( $themedir . '/mail-css.tpl',
     352      $rfs = $rfs && stc_newfile( $themedir . '/mail-css.tpl',
    227353        $main['mail-css.tpl'] );
    228354      /*
    229355       * Build theme.css
    230        **/ 
    231       $plugin_tpl->set_filenames(array('theme'=>
    232       STC_PATH . 'theme.tpl'));
     356       **/
     357      $main['subphase'] = 'Build theme';
     358      $plugin_tpl->set_filenames(array('theme'=> STC_PATH . 'theme.tpl'));
    233359      $plugin_tpl->assign('main',$main);
    234360      $main['theme.css'] = $plugin_tpl->parse('theme', true); 
    235       $r = $r && stc_newfile( $themedir . '/theme.css',
    236         $main['theme.css'] );
     361      $rfs = $rfs && stc_newfile( $themedir . '/theme.css', $main['theme.css'] );
     362      $internal = stc_hex2rgb($main['color'][2]);
     363      list($r,$g,$b) = $internal;
     364      $background = stc_hex2rgb($main['color'][0]);
     365      list($r2,$g2,$b2) = $background;
     366      $delta = floor(((array_sum($internal)/3) - (array_sum($background)/3))/5.1);
     367      /* Brightness is half of difference between colors of internal lnks and bkground */
     368      /* but if color range is 0-255, resulting brightness range is between -50 and 50 */
     369      if ($delta > 0) { /* Colorize need a darker color on a dark background */
     370         $r = floor($r / 5);
     371         $g = floor($g / 5);
     372         $b = floor($b / 5);
     373      }
     374      if (isset($_POST['background']) and $_POST['background'] == 'random')
     375      {
     376        $main['subphase'] = 'Pick random for a pic';
     377        $main['random'] = mt_rand(12, 4096);
     378        $result = pwg_query('
     379        SELECT i.path
     380          FROM '.CATEGORIES_TABLE.' c,
     381               '.IMAGES_TABLE.' i,
     382               '.IMAGE_CATEGORY_TABLE.' ic
     383         WHERE c.status=\'public\'
     384           AND c.id = ic.category_id
     385           AND c.id = ' . $main['src_category'] . '
     386           AND ic.category_id = ' . $main['src_category'] . '
     387           AND ic.image_id = i.id
     388         ORDER BY RAND(' . $main['random'] . ')
     389         LIMIT 0,1');
     390      if($result) list($main['pic_path']) = mysql_fetch_array($result);
     391      else $main['pic_path'] =
     392           PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/header.jpg';
     393      $main['pic_ext'] = substr($main['pic_path'],strrpos($main['pic_path'],'.')+1);
     394      if ($main['pic_ext']=='png')
     395        $img = imagecreatefrompng($main['pic_path']);
     396      elseif (in_array($main['pic_ext'],array('jpg','jpeg')))
     397              $img = imagecreatefromjpeg($main['pic_path']);
     398      else $img = imagecreatefromjpeg(PHPWG_ROOT_PATH
     399                   . 'plugins/SwiftThemeCreator/simul/header.jpg');
     400      imagejpeg( $img, $themedir . '/header.jpg', 90 );
     401      imagedestroy ($img);
     402      }
     403      if (isset($_POST['background']) and $_POST['background'] == 'fixed')
     404      {
     405        if (function_exists('imagecreatefromjpeg'))
     406        {
     407          $hdr = imagecreatetruecolor ($main['picture_width'], $main['picture_height']);
     408          imagecolorset ( $hdr, 0, $r2, $g2, $b2 );
     409          if ($extension == 'png') $img = imagecreatefrompng($_POST['picture_url']);
     410          else $img = imagecreatefromjpeg($_POST['picture_url']);
     411          imagecopymerge ( $hdr, $img, 0, 0, 0, 0, $main['picture_width'], $main['picture_height'], 60 );
     412          imagedestroy ($img);
     413          if ($main['colorize']) imagefilter($hdr, IMG_FILTER_COLORIZE, $r, $g, $b);
     414          if ($main['brightness']) imagefilter($hdr, IMG_FILTER_BRIGHTNESS, $delta);
     415          if ($main['contrast']) imagefilter($hdr, IMG_FILTER_CONTRAST, 20);
     416          imagejpeg( $hdr, $themedir . '/header.jpg', 90 );
     417          imagedestroy ($hdr);
     418        }
     419        else @copy( $_POST['picture_url'], $themedir . '/header.jpg');     
     420      }
    237421      /*
    238422       * Build background image for titrePage or definition list (in #menubar)
     
    240424      if (function_exists('imagecreatefrompng'))
    241425      {
     426        $hdr = imagecreatetruecolor (1, 38);
     427        imagecolorset ( $hdr, 0, $r2, $g2, $b2 );
    242428        $img = imagecreatefrompng(STC_PATH . '/titrePage-bg.png');
    243         $dest = imagecreate(1, 64);
    244         for ($i=0; $i<256; $i++) {
    245           imagecolorallocate($dest, $i, $i, $i);
    246         }
    247         imagecopy($dest, $img, 0, 0, 0, 0, 1, 64);
    248         list($r1,$g1,$b1) = stc_hex2rgb($main['color'][4]);
    249         for ($i = 0; $i < 256; $i++) {
    250           imagecolorset($dest, $i, min(floor($i * $r1 / 255), 255),
    251                          min(floor($i * $g1 / 255), 255),
    252                          min(floor($i * $b1 / 255), 255));
    253         }
    254         // to be tested imagecopymerge($dest,$img,0,0,0,0,1,64,33);
    255         imagepng( $dest, $themedir . '/stc.png', 9 );
     429        imagecopymerge ( $hdr, $img, 0, 0, 0, 0, 1, 38, 60 );
    256430        imagedestroy ($img);
    257         imagedestroy ($dest);
     431        if ($main['colorize']) imagefilter($hdr, IMG_FILTER_COLORIZE, $r, $g, $b);
     432        if ($main['brightness']) imagefilter($hdr, IMG_FILTER_BRIGHTNESS, $delta);
     433        if ($main['contrast']) imagefilter($hdr, IMG_FILTER_CONTRAST, 20);
     434        imagepng( $hdr, $themedir . '/stc.png', 9 );
     435        imagedestroy ($hdr);
    258436      }
    259437      else @copy( STC_PATH
    260438                 . '/titrePage-bg.png', $themedir . '/stc.png');     
    261       if ($r == false) {
     439      if ($rfs == false) {
    262440        array_push($errors,
    263441          l10n('Theme files creation failure: theme should be deleted.'));
    264         @unlink( $themedir . '/stc.png' );
    265         @unlink( $themedir . '/themeconf.inc.php' );
    266         @unlink( $themedir . '/mail-css.tpl' );
    267         @unlink( $themedir . '/theme.css' );
    268         @rmdir( $themedir );
     442        if ($cleaning) {
     443          @unlink( $themedir . '/header.jpg' );
     444          @unlink( $themedir . '/stc.png' );
     445          @unlink( $themedir . '/themeconf.inc.php' );
     446          @unlink( $themedir . '/mail-css.tpl' );
     447          @unlink( $themedir . '/theme.css' );
     448          @rmdir( $themedir );
     449        }
    269450      }
    270       else {
     451      elseif (!$main['simulate']) {
    271452        array_push($infos,
    272453       '['.$main['newtpl'] . '/' . $main['newtheme'].'] : '
    273454       .l10n('Congratulation! You have got(/ten) a new available theme.'));
     455        @copy( $themedir . '/header.jpg', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/header.jpg');
     456        @copy( $themedir . '/stc.png', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/stc.png');
     457        @copy( $themedir . '/themeconf.inc.php', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/themeconf.inc.php');
     458        @copy( $themedir . '/mail-css.tpl', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/mail-css.tpl');
     459        @copy( $themedir . '/theme.css', PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/simul/theme.css');
    274460      }
    275461    }
    276462  }
    277   // TODO       ********   HEADER   *********
    278   // Interesting Graphic Charter
    279   // http://accessites.org/site/2006/08/visual-vs-structural/
    280 
     463
     464  // TODO       ********   theSwiftHeader itself   *********
     465 
    281466  $swift_theme_creator->save_theme_config(); 
    282467}
     
    287472if (isset($_POST['reset']) and (!is_adviser())) {
    288473  $main = array();
     474  init_main($main);
    289475  $swift_theme_creator->theme_config = $main;
    290476  $swift_theme_creator->save_theme_config(); 
    291477  redirect( get_admin_plugin_menu_link(dirname(__FILE__).'/theme_creator.php'));
    292478}
    293 // To be implemented delete $main save and redirect
    294479
    295480// Don't forget to re-read because some statements are superfluous
     
    312497</style>'
    313498    );
    314 
    315 /* Templates */
     499$template->assign('radio_options',
     500 array(
     501  'true' => l10n('Yes'),
     502  'false' => l10n('No')));
    316503$template->assign('template_options', $available_templates);
    317 if (!isset($main['template_options'])) $main['template_options'] = 0;
    318 
    319 /* New theme */
    320 if (isset($_POST['new_theme'])) $main['new_theme'] = $_POST['new_theme'];
    321 
    322 /* Colors */
    323 if (isset($_POST['color1'])) $main['color1'] = $_POST['color1'];
    324 if (isset($_POST['color2'])) $main['color2'] = $_POST['color2'];
    325 if (isset($_POST['color3'])) $main['color3'] = $_POST['color3'];
    326 if (isset($_POST['color4'])) $main['color4'] = $_POST['color4'];
    327 if (isset($_POST['color5'])) $main['color5'] = $_POST['color5'];
    328 if (!isset($main['color1'])) $main['color1'] = '#111111';
    329 if (!isset($main['color2'])) $main['color2'] = '#EEEEEE';
    330 if (!isset($main['color3'])) $main['color3'] = '#FF7700';
    331 if (!isset($main['color4'])) $main['color4'] = '#FF3333';
    332 if (!isset($main['color5'])) $main['color5'] = '#FF3363';
    333 
    334 /* header */
    335 if (isset($_POST['background'])) $main['background'] = $_POST['background'];
    336 if (!isset($main['background'])) $main['background'] = 'off';
    337504$template->assign('background_options',
    338505  array(
     
    341508    'fixed' => l10n('Fixed URL'),
    342509  ));
    343 
    344 $query = '
    345 SELECT id,name,uppercats,global_rank
    346   FROM ' . CATEGORIES_TABLE . ';';
    347 display_select_cat_wrapper($query,array(),'src_category');
    348 if (isset($_POST['src_category'])) $main['src_category'] =
    349     $_POST['src_category'];
    350 
    351510$main['picture_url'] = PHPWG_ROOT_PATH . 'plugins/SwiftThemeCreator/sample.jpg';
    352511if (isset($swift_theme_creator->picture_url))
     
    356515if (isset($_POST['picture_width']))
    357516    $main['picture_width'] = $_POST['picture_width'];
    358 if (!isset($main['picture_width'])) $main['picture_width'] = 2048;
    359517if (isset($_POST['picture_height']))
    360518    $main['picture_height'] = $_POST['picture_height'];
    361 if (!isset($main['picture_height'])) $main['picture_height'] = 100;
    362519
    363520if (isset($_POST['background_mode']))
    364521      $main['background_mode'] = $_POST['background_mode'];
    365 if (!isset($main['background_mode'])) $main['background_mode'] = 'as';
    366522$template->assign('background_mode_options',
    367523  array(
  • trunk/plugins/SwiftThemeCreator/theme_creator.tpl

    r2461 r2487  
    1515  {'Template'|@translate}
    1616</td><td>
    17   {html_options name=template options=$template_options selected=$main.template_options}
     17  {html_options name=template options=$template_options selected=$main.template_sel}
    1818</td></tr>
    1919<tr><td style="padding-right:20px;">
    2020  {'New theme to be created'|@translate}
    2121</td><td>
    22   <input type="text" maxlength="8" size="8" name="new_theme" id="new_theme" value="{$main.new_theme}" />
     22  <input type="text" maxlength="8" size="8" name="new_theme" id="new_theme" value="{$main.newtheme}" />
    2323</td></tr>
    2424</table>
     
    7878<table>
    7979  <tr>
     80    <td style="padding-right:120px;">
     81    <label><input class="radio" type="radio" value="off" name="background"
     82    {if ($main.background == 'off')} checked="checked" {/if}/>
     83      {'No picture'|@translate}</label> {* No / 24H Random public picture / Fixed URL *}
     84    </td>
     85    <td colspan="2"></td>
     86  </tr>
     87
     88  <tr>
     89    <td style="padding-right:120px;">
     90    <label>    <input class="radio" type="radio" value="random" name="background"
     91    {if ($main.background == 'random')} checked="checked" {/if}/>
     92      {'Random source'|@translate}</label>
     93    </td>
     94    <td colspan="2">
     95      {html_options style="margin: 0 0 0 10px;" name=src_category options=$src_category selected=$main.src_category}
     96    </td>
     97  </tr>
     98
     99
     100  <tr>
     101    <td style="padding-right:120px;">
     102    <label>    <input class="radio" type="radio" value="fixed" name="background"
     103    {if ($main.background == 'fixed')} checked="checked" {/if}/>
     104      {'Fixed path'|@translate}</label>
     105    </td>
     106    <td colspan="2">
     107      <input style="margin: 0 0 0 10px;" type="text" maxlength="255" size="70" name="picture_url" id="picture_url" value="{$main.picture_url}" />
     108    </td>
     109  </tr>
     110
     111  <tr>
    80112    <td style="padding-right:20px;">
    81       {'Use of a picture background'|@translate} {* No / 24H Random public picture / Fixed RRL *}
    82     </td>
    83    
    84     <td colspan="2">
    85     <label>
    86     <input class="radio" type="radio" value="off" name="background"
    87     {if ($main.background == 'off')}
    88       checked="checked"
    89     {/if}/>
    90     {$background_options.off}
    91     </label>
    92     </td>
    93   </tr>
    94 
    95   <tr>
    96     <td style="padding-right:20px;">
    97       {'Source category'|@translate}
    98     </td><td>
    99     <label>
    100     <input class="radio" type="radio" value="random" name="background"
    101     {if ($main.background == 'random')}
    102       checked="checked"
    103     {/if}/>
    104     {$background_options.random}
    105     </label>
    106     </td><td>
    107       {html_options style="margin: 0 0 0 10px;" name=src_category options=$src_category select=$main.src_category}
    108     </td>
    109   </tr>
    110 
    111   <tr>
    112     <td style="padding-right:20px;">
    113       {'Picture relative local path'|@translate}
    114     </td><td>
    115     <label>
    116     <input class="radio" type="radio" value="fixed" name="background"
    117     {if ($main.background == 'fixed')}
    118       checked="checked"
    119     {/if}/>
    120     {$background_options.fixed}
    121     </label>
    122     </td><td>
    123       <input style="margin: 0 0 0 10px;" type="text" maxlength="255" size="70" name="picture_url" id="picture_url" value="{$main.picture_url}" />
    124     </td>
    125   </tr>
    126 
    127   <tr>
    128     <td style="padding-right:20px;">
     113    &nbsp;
     114    </td><td colspan="2"  style="padding-left:20px;">
     115      <label style="padding-right:50px;">
     116        <input type="checkbox" name="colorize" {if ($main.colorize)}checked="checked"{/if} />
     117        {'Colorize'|@translate} {* Colorize / Enhance Brightness / Reduce contrast *}
     118      </label>
     119      <label style="padding-right:50px;">
     120        <input type="checkbox" name="brightness" {if ($main.brightness)}checked="checked"{/if} />
     121        {'Enhance brightness'|@translate}
     122      </label>
     123      <label>
     124        <input type="checkbox" name="contrast" {if ($main.contrast)}checked="checked"{/if} />
     125        {'Reduce contrast'|@translate}
     126      </label>
     127    </td>
     128  </tr>
     129 
     130  <tr>
     131    <td style="padding-right:5px; text-align: right;">
    129132      {'Width limit in pixels'|@translate}
    130133    </td><td colspan="2">
     
    137140
    138141  <tr>
    139     <td style="padding-right:20px;">
     142    <td style="padding-right:5px; text-align: right;">
    140143      {'Display mode'|@translate} {* As is / truncated / resized *}
    141144    </td><td colspan="2">
     
    147150
    148151<p>
    149 <input name="reset" class="submit" type="submit" value="{'Reset'|@translate}" /> &nbsp;
    150 <input name="submit" class="submit" type="submit" value="{'Submit'|@translate}" />
     152<input name="reset" class="submit" type="submit" value="{'Reset'|@translate}" style="margin-right:250px;" /> &nbsp;
     153<input name="submit" class="submit" type="submit" value="{'Generate'|@translate}" style="margin-right:50px;" /> &nbsp;
     154<input name="simulate" class="submit" type="submit" value="{'Simulate'|@translate}" />
    151155</p>
    152156</form>
     157<fieldset>
     158        <legend>{'Just a yoga preview... '|@translate}</legend>
     159<div style="background-color:{$main.color1}; width: 600px; overflow: hidden; margin: 5px auto 5px auto;
     160font-family:Univers,Helvetica,Optima,'Bitstream Vera Sans',sans-serif;">
     161  {* Preview header *}<div style="width: 600px; height: 80px; overflow: hidden;">
     162    {if ($main.background=='fixed')}
     163    <img src="{$main.templatedir}/header.jpg">
     164    <h2 style="position:relative;color:{$main.color2};top:-75px;left:5px;text-align:left;margin:0 auto 0 auto;">{'"Fixed header" preview'|@translate}</h2>
     165    {/if}
     166    {if ($main.background=='random')}
     167    <img src="{$main.templatedir}/header.jpg">
     168    <h2 style="position:relative;color:{$main.color2};top:-75px;left:5px;text-align:left;margin:0 auto 0 auto;">{'"Random header" preview'|@translate}</h2>
     169    {/if}
     170    {if ($main.background=='off')}
     171    <h2 style="position:relative;color:{$main.color2};top:25px;left:5px;text-align:left;margin:0 auto 0 auto;">{'"No header" preview'|@translate}</h2>
     172    {/if}
     173    </div>
     174  {* Preview menubar *}<div style="border:1px solid {$main.color3}; margin:2px 4px 0px 2px;
     175text-decoration:none; width: 120px; display:inline; background-color:{$main.color6};
     176float:left; padding:0pt; text-align:left; color:{$main.color2}; font-size:1em;">
     177    <dl style="margin: 0;">
     178      <dt style="background-image:url({$main.templatedir}/stc.png); text-align: center; height:18px;
     179font-weight:bold; font-style:normal; color:{$main.color3}; padding: 6px 0 0 0;">{'Preview'|@translate}</dt>
     180      <dd>
     181        <ul style="padding-left: 14px; font-size: 0.9em;">
     182          <li><a style="color:{$main.color3}; border:0;">{'Preview'|@translate}</a></li>
     183          <li>...</li>
     184        </ul>
     185        <p style="font-size: 0.9em;">{'Preview'|@translate}</p>
     186      </dd>
     187    </dl>
     188  </div>
     189  {* Preview content *}<div style="border:1px solid {$main.color3}; padding:0px;
     190background-color:{$main.color6}; margin: 2px 2px 0 132px; color:{$main.color2}; font-size:1em; width:462px;">
     191<h2 style="background-image:url({$main.templatedir}/stc.png); display:block; padding: 6px 0 0 20px;
     192font-size:1em; height:18px; letter-spacing:-1px; margin:0; position:relative; text-align: left;
     193font-style:normal; color:{$main.color2}; width: 442px; font-weight: normal;">{'home'|@translate}</h2>
     194  <ul style="padding-left:4px; padding-right:130px;">
     195    <li style="list-style:none;">
     196      <div style="border:1px solid {$main.color3}; margin:3px; padding:2px 0px 0px 2px;">
     197        <div style="width:114px; float:left; margin:2px 0pt 0pt 2px; text-align:left; color:{$main.color1};">
     198          <a style="border:0;">
     199          <img title="{'Preview'|@translate}" alt="{'Preview'|@translate}" src="{$main.templatedir}/header.jpg" style="width: 106px; height: 80px;"/>
     200          </a>
     201        </div>
     202        <div style="height:94px; font-size:90%; overflow:hidden;">
     203          <h3 style="background-image:url({$main.templatedir}/stc.png); text-align:center; height: 14px; margin-right: 0px; margin-bottom: 0px; line-height: 7px;">
     204          <a style="font-size: 10px; font-style:normal; border:0;">{'Preview'|@translate}</a>
     205          </h3>
     206          <p style="">{'Preview'|@translate}</p>
     207          <p/>
     208        </div>
     209      </div>
     210    </li>
     211  </ul>
     212  </div>
     213</div>
     214<span style='display:block;font-style:italic;color:#777;text-align:right;margin-right:25px;'>
     215{'...to get an idea of the expected result. Preview is based on yoga-like template only.'|@translate}</span>
     216</fieldset>
  • trunk/plugins/SwiftThemeCreator/themeconf.inc.tpl

    r2450 r2487  
    1515  'mime_icon_dir' => 'template/{$main.newtpl}/icon/mimetypes/',
    1616  'local_head' => '<!-- coming soon -->',
     17  /* Swift Theme Creator parameters */
     18  'stc_category' => {$main.src_category},
     19  'stc_background' => '{$main.background}',
     20  'stc_background_mode' => '{$main.background_mode}',
     21  'stc_width' => '{$main.picture_width}',
     22  'stc_height' => '{$main.picture_height}',
    1723);
    1824if ( !isset($lang['Theme: {$main.newtheme}']) )
  • trunk/template/yoga/header.tpl

    r2381 r2487  
    6868
    6969<div id="theHeader">{$PAGE_BANNER}</div>
    70 {if isset($pwgmenu)}
    71 <ul class="pwgmenu">
    72   <li><a href="{$pwgmenu.WIKI}" onclick="window.open(this.href, ''); return false;"><span class="bg">{'WIKI / DOC'|@translate}</span></a></li>
    73   <li><a href="{$pwgmenu.FORUM}" onclick="window.open(this.href, ''); return false;"><span class="bg">{'FORUM'|@translate}</span></a></li>
    74 </ul>   
    75 {/if}
     70{if isset($theSwiftHeader)}{$theSwiftHeader}{/if}
    7671{if not empty($header_notes)}
    7772<div class="header_notes">
Note: See TracChangeset for help on using the changeset viewer.