Changeset 2450


Ignore:
Timestamp:
Jul 22, 2008, 11:49:35 PM (16 years ago)
Author:
vdigital
Message:

Swift Theme Creator (minor changes): non functional version yet (3).

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

Legend:

Unmodified
Added
Removed
  • trunk/plugins/SwiftThemeCreator/theme_creator.php

    r2449 r2450  
    4444  return array(hexdec($r), hexdec($g), hexdec($b));
    4545}
     46/*
     47 * lighten returns array of x% of lighter RGB values
     48 */
     49function lighten( $r, $g, $b, $percent)
     50{
     51  $r = min(round($r+(($percent*(255-$r))/100)),255);
     52  $g = min(round($g+(($percent*(255-$g))/100)),255);
     53  $b = min(round($b+(($percent*(255-$b))/100)),255);
     54  return sprintf('#%02X%02X%02X', $r, $g, $b);
     55}
     56/*
     57 * darken returns array of x% of darker RGB values
     58 */
     59function darken( $r, $g, $b, $percent)
     60{
     61  $r = max(round($r-(($percent*$r)/100)),0);
     62  $g = max(round($g-(($percent*$g)/100)),0);
     63  $b = max(round($b-(($percent*$b)/100)),0);
     64  return sprintf('#%02X%02X%02X', $r, $g, $b);
     65}
     66
     67
    4668$errors = array();
    4769$infos = array();
     
    116138
    117139  // 3 - Directory control
    118   $templatedir = PHPWG_ROOT_PATH . 'template/'
     140  $main['templatedir'] = PHPWG_ROOT_PATH . 'template/'
    119141               . $available_templates[$_POST['template']];
    120   $themedir = $templatedir . '/' . $main['newtheme'];
     142  $main['newtpl'] = $available_templates[$_POST['template']];
     143  $themedir = $main['templatedir'] . '/' . $main['newtheme'];
    121144  if (is_dir(  $themedir ))
    122145    array_push($errors,
    123146       '['.$themedir.'] : '.l10n('Invalid theme: This theme exists already (no override available).'));
    124   elseif (!is_writable($templatedir))
    125     array_push($errors,
    126        '['.$templatedir.'] : '.l10n('no_write_access'));
     147  elseif (!is_writable($main['templatedir']))
     148    array_push($errors,
     149       '['.$main['templatedir'].'] : '.l10n('no_write_access'));
    127150
    128151  // 4 - Picture URL control
     
    133156 
    134157  // 5 - Expected Width and Height limits control
    135   if ( !(is_numeric($_POST['picture_width']) and ($_POST['picture_width'] < 12
    136        or $_POST['picture_width'] > 4096 )) )
     158  if ( !(ctype_digit($_POST['picture_width']) and $_POST['picture_width'] > 11
     159       and $_POST['picture_width'] < 4097 ) )
    137160    array_push($errors,
    138161       '['.$_POST['picture_width'].'] : '
    139162       . l10n('incorrect width value [12-4096].'));
    140   if ( !(is_numeric($_POST['picture_height']) and ($_POST['picture_height'] < 12
    141        or $_POST['picture_height'] > 200 )) )
    142     array_push($errors,
    143        '['.$_POST['picture_width'].'] : '
    144        . l10n('incorrect width value [12-4096].'));
     163  if ( !(ctype_digit($_POST['picture_height']) and $_POST['picture_height'] > 11
     164       and $_POST['picture_height'] < 201 ) )
     165    array_push($errors,
     166       '['.$_POST['picture_height'].'] : '
     167       . l10n('incorrect width value [12-200].'));
    145168       
    146169  // 6 - Generate missing colors values
     170  list($r1,$g1,$b1) = stc_hex2rgb($main['color'][0]);
     171  if ((( (($r1+1)/256)*(($g1+1)/256)*(($b1+1)/256) ) * 1000 ) < 125 )
     172       $main['color6'] = lighten( $r1, $g1, $b1, 10);
     173  else $main['color6'] = darken( $r1, $g1, $b1, 10);
     174  list($r1,$g1,$b1) = stc_hex2rgb($main['color'][4]);
     175  if ((( (($r1+1)/256)*(($g1+1)/256)*(($b1+1)/256) ) * 1000 ) < 125 )
     176       $main['color7'] = lighten( $r1, $g1, $b1, 10);
     177  else $main['color7'] = darken( $r1, $g1, $b1, 10);
     178 
     179  /* en gros reste à faire:
     180   * creation des différents fichiers
     181   */
     182
     183  // Go ahead
     184  if (count($errors) == 0) {
     185    umask(0000);
     186    // mkdir($themedir, 0777);
     187    if (!is_dir(  $themedir ))
     188        array_push($errors,
     189          l10n('Theme directory creation failure: it can\'t be created (for now en attendant la suite 8-) ).'));
     190  }
     191
     192  /*
     193   * Build themeconf.inc.php
     194   **/
     195  $plugin_tpl = new Template();
     196  $plugin_tpl->set_filenames(array('themeconf'=>
     197  dirname(__FILE__) . '/themeconf.inc.tpl'));
     198  $plugin_tpl->assign('main',$main);
     199  $main['themeconf_inc_php'] = $plugin_tpl->parse('themeconf', true);
     200
     201  // Smarty trace
     202  $plugin_tpl->assign('main',$main);
     203 
     204  // Interesting Graphic Charter
     205  // http://accessites.org/site/2006/08/visual-vs-structural/
    147206
    148207  /*
     
    170229    imagedestroy ($dest);
    171230  }
    172   /* en gros reste à faire:
    173    * creation de la directory
    174    * creation des différents fichiers
    175    * parse pour theme.css et ecriture directe pour les autres 
    176    */
    177   // Lors du parse si le second arg est à true, on récupère le résultat
    178   // http://www.barelyfitz.com/projects/csscolor/csscolor.zip
    179 
    180   // Go ahead
    181   if (count($errors) == 0) {
    182     umask(0000);
    183     // mkdir($themedir, 0777);
    184     if (!is_dir(  $themedir ))
    185         array_push($errors,
    186           l10n('Theme directory creation failure: it can\'t be created (for now en attendant la suite 8-) ).'));
    187   }
     231
     232
     233
    188234  $swift_theme_creator->save_theme_config(); 
    189235}
Note: See TracChangeset for help on using the changeset viewer.