Changeset 7780 for extensions


Ignore:
Timestamp:
Nov 14, 2010, 9:50:00 PM (14 years ago)
Author:
plg
Message:

buf fixed: check that upload configuration settings are correctly defined before running pwg.images.addSimple

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/pwg_images_addSimple/main.inc.php

    r7566 r7780  
    9090  }
    9191
     92  prepare_upload_configuration();
     93
    9294  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
    93  
     95
    9496  $image_id = add_uploaded_file(
    9597    $_FILES['image']['tmp_name'],
     
    162164      ),
    163165    );
     166}
     167
     168// this function should not be here, this is a code duplication from
     169// admin/photos_add.php, unfortunately pwg.images.addSimple needs upload
     170// settings to be defined
     171function prepare_upload_configuration()
     172{
     173  global $conf;
     174 
     175  // automatic fill of configuration parameters
     176  $upload_form_config = array(
     177    'websize_resize' => array(
     178      'default' => true,
     179      'can_be_null' => false,
     180      ),
     181 
     182    'websize_maxwidth' => array(
     183      'default' => 800,
     184      'min' => 100,
     185      'max' => 1600,
     186      'pattern' => '/^\d+$/',
     187      'can_be_null' => true,
     188      'error_message' => l10n('The websize maximum width must be a number between %d and %d'),
     189      ),
     190   
     191    'websize_maxheight' => array(
     192      'default' => 600,
     193      'min' => 100,
     194      'max' => 1200,
     195      'pattern' => '/^\d+$/',
     196      'can_be_null' => true,
     197      'error_message' => l10n('The websize maximum height must be a number between %d and %d'),
     198      ),
     199   
     200    'websize_quality' => array(
     201      'default' => 95,
     202      'min' => 50,
     203      'max' => 100,
     204      'pattern' => '/^\d+$/',
     205      'can_be_null' => false,
     206      'error_message' => l10n('The websize image quality must be a number between %d and %d'),
     207      ),
     208   
     209    'thumb_maxwidth' => array(
     210      'default' => 128,
     211      'min' => 50,
     212      'max' => 300,
     213      'pattern' => '/^\d+$/',
     214      'can_be_null' => false,
     215      'error_message' => l10n('The thumbnail maximum width must be a number between %d and %d'),
     216      ),
     217   
     218    'thumb_maxheight' => array(
     219      'default' => 96,
     220      'min' => 50,
     221      'max' => 300,
     222      'pattern' => '/^\d+$/',
     223      'can_be_null' => false,
     224      'error_message' => l10n('The thumbnail maximum height must be a number between %d and %d'),
     225      ),
     226   
     227    'thumb_quality' => array(
     228      'default' => 95,
     229      'min' => 50,
     230      'max' => 100,
     231      'pattern' => '/^\d+$/',
     232      'can_be_null' => false,
     233      'error_message' => l10n('The thumbnail image quality must be a number between %d and %d'),
     234      ),
     235    );
     236 
     237  $inserts = array();
     238 
     239  foreach ($upload_form_config as $param_shortname => $param)
     240  {
     241    $param_name = 'upload_form_'.$param_shortname;
     242   
     243    if (!isset($conf[$param_name]))
     244    {
     245      $param_value = boolean_to_string($param['default']);
     246     
     247      array_push(
     248        $inserts,
     249        array(
     250          'param' => $param_name,
     251          'value' => $param_value,
     252          )
     253        );
     254      $conf[$param_name] = $param_value;
     255    }
     256  }
     257 
     258  if (count($inserts) > 0)
     259  {
     260    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     261    mass_inserts(
     262      CONFIG_TABLE,
     263      array_keys($inserts[0]),
     264      $inserts
     265      );
     266  }
    164267}
    165268
Note: See TracChangeset for help on using the changeset viewer.