Changeset 105 for branches/1.1dev/lib


Ignore:
Timestamp:
Apr 20, 2006 3:30:23 AM (18 years ago)
Author:
scdev
Message:

Q - Removed getParam and getParam since to maintain backwards compatibility with old sites.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/lib/Upload.inc.php

    r104 r105  
    1717class Upload {
    1818   
    19     // General object parameters.
    20     var $_params = array(
    21         'display_messages' => true,
    22         'allow_overwriting' => false,
    23     );
     19    // Display error messages to the user?
     20    var $display_messages = true;
     21   
     22    // Existing files with the same name will be overwritten?
     23    var $allow_overwriting = false;
    2424
    2525    // Disk path where new image(s) will be uploaded.
     
    213213        'zip'     => 'application/zip'
    214214    );
    215    
    216     /**
    217      * Set (or overwrite existing) parameters by passing an array of new parameters.
    218      *
    219      * @access public
    220      *
    221      * @param  array    $params     Array of parameters (key => val pairs).
    222      */
    223     function setParam($params=null)
    224     {
    225         if (isset($params) && is_array($params)) {
    226             // Set parameters for this object.
    227             $this->_params = array_merge($this->_params, $params);
    228         }
    229     }
    230 
    231     /**
    232      * Return the value of a parameter.
    233      *
    234      * @access  public
    235      *
    236      * @param   string  $param      The key of the parameter to return.
    237      *
    238      * @return  mixed               Parameter value.
    239      */
    240     function getParam($param)
    241     {
    242         return $this->_params[$param];
    243     }
    244215
    245216    /**
     
    269240        if (!isset($this->upload_directory_path)) {
    270241            logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    271             if ($this->getParam('display_messages')) {
     242            if ($this->display_messages) {
    272243                raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
    273244            }
     
    277248        if (!isset($_FILES[$form_name])) {
    278249            logMsg(sprintf(_("Form element %s not posted."), $form_name), LOG_ERR, __FILE__, __LINE__);
    279             if ($this->getParam('display_messages')) {
     250            if ($this->display_messages) {
    280251                raiseMsg(_("There was a problem with the file upload. Please try again."), MSG_ERR, __FILE__, __LINE__);
    281252            }
     
    308279            $file_path_name = '';
    309280
    310             if ('' == trim($files['tmp_name'][$i])) {
     281            if ('' == trim($files['name'][$i])) {
    311282                // User may not have attached a file.
    312283                continue;
     
    315286            // Check The php upload error messages.
    316287            if (UPLOAD_ERR_INI_SIZE === $files['error'][$i]) {
    317                 if ($this->getParam('display_messages')) {
     288                if ($this->display_messages) {
    318289                    raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload filesize of %s."), $files['name'][$i], ini_get('upload_max_filesize')), MSG_ERR, __FILE__, __LINE__);
    319290                }
     
    323294            }
    324295            if (UPLOAD_ERR_FORM_SIZE === $files['error'][$i]) {
    325                 if ($this->getParam('display_messages')) {
     296                if ($this->display_messages) {
    326297                    raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload filesize of %s."), $files['name'][$i], $_POST['MAX_FILE_SIZE']), MSG_ERR, __FILE__, __LINE__);
    327298                }
     
    331302            }
    332303            if (UPLOAD_ERR_PARTIAL === $files['error'][$i]) {
    333                 if ($this->getParam('display_messages')) {
     304                if ($this->display_messages) {
    334305                    raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it was only partially uploaded."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__);
    335306                }
     
    339310            }
    340311            if (UPLOAD_ERR_NO_FILE === $files['error'][$i]) {
    341                 if ($this->getParam('display_messages')) {
     312                if ($this->display_messages) {
    342313                    raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: no file was uploaded."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__);
    343314                }
     
    347318            }
    348319            if (UPLOAD_ERR_NO_TMP_DIR === $files['error'][$i]) {
    349                 if ($this->getParam('display_messages')) {
     320                if ($this->display_messages) {
    350321                    raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: temporary upload directory missing."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__);
    351322                }
     
    357328            // Check to be sure it's an uploaded file.
    358329            if (!is_uploaded_file($files['tmp_name'][$i])) {
    359                 if ($this->getParam('display_messages')) {
     330                if ($this->display_messages) {
    360331                    raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__);
    361332                }
     
    367338            // Check to be sure the file is not empty.
    368339            if ($files['size'][$i] < 1) {
    369                 if ($this->getParam('display_messages')) {
     340                if ($this->display_messages) {
    370341                    raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it contains zero bytes."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__);
    371342                }
     
    377348            // Check to be sure the file has a valid file extension.
    378349            if (!in_array(strtolower($this->getFilenameExtension($files['name'][$i])), $this->valid_file_extensions)) {
    379                 if ($this->getParam('display_messages')) {
     350                if ($this->display_messages) {
    380351                    raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it is an unrecognised type. Files must have one of the following file extensions: %s."), $files['name'][$i], join(', ', $this->valid_file_extensions)), MSG_ERR, __FILE__, __LINE__);
    381352                }
     
    386357           
    387358            // Check to be sure the file has a unique file name.
    388             if (!$this->getParam('allow_overwriting') && $this->exists($files['name'][$i])) {
    389                 if ($this->getParam('display_messages')) {
     359            if (!$this->allow_overwriting && $this->exists($files['name'][$i])) {
     360                if ($this->display_messages) {
    390361                    raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: a file with that name already exists."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__);
    391362                }
     
    401372                    // Valid custom file name.
    402373                    $file_name = $custom_file_name;
    403                     if ($this->getParam('display_messages')) {
     374                    if ($this->display_messages) {
    404375                        raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
    405376                    }
     
    415386                    // Valid custom file name.
    416387                    $file_name = $custom_file_name[$i];
    417                     if ($this->getParam('display_messages')) {
     388                    if ($this->display_messages) {
    418389                        raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
    419390                    }
     
    442413            if (move_uploaded_file($files['tmp_name'][$i], $file_path_name)) {
    443414                chmod($file_path_name, $this->dest_file_perms);
    444                 if ($this->getParam('display_messages')) {
     415                if ($this->display_messages) {
    445416                    raiseMsg(sprintf(_("The file <strong>%s</strong> uploaded successfully."), $files['name'][$i]), MSG_SUCCESS, __FILE__, __LINE__);
    446417                }
    447418                if (!isset($custom_file_name) && $files['name'][$i] != $file_name) {
    448419                    // Notify user if uploaded file name was modified (unless a custom file name will be used anyways).
    449                     if ($this->getParam('display_messages')) {
     420                    if ($this->display_messages) {
    450421                        raiseMsg(sprintf(_("The file <strong>%s</strong> was renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
     422                        logMsg(sprintf('File successfully renamed: %s -> %s', $files['tmp_name'][$i], $file_path_name), LOG_DEBUG, __FILE__, __LINE__);
    451423                    }
    452424                }
     
    458430                continue;
    459431            } else {
    460                 if ($this->getParam('display_messages')) {
     432                if ($this->display_messages) {
    461433                    raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $files['name'][$i]), MSG_ERR, __FILE__, __LINE__);
    462434                }
     
    488460            logMsg(sprintf('Deleted file: %s', $file_path_name), LOG_DEBUG, __FILE__, __LINE__);
    489461        } else {
    490             if ($this->getParam('display_messages')) {
     462            if ($this->display_messages) {
    491463                raiseMsg(sprintf(_("The file <strong>%s</strong> could not be deleted."), $file_name), MSG_ERROR, __FILE__, __LINE__);
    492464            }
     
    511483        if (file_exists($old_file_path_name)) {
    512484            if (!rename($old_file_path_name, $new_file_path_name)) {
    513                 if ($this->getParam('display_messages')) {
     485                if ($this->display_messages) {
    514486                    raiseMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), MSG_ERR, __FILE__, __LINE__);
    515487                }
     
    518490            }
    519491        } else {
    520             if ($this->getParam('display_messages')) {
     492            if ($this->display_messages) {
    521493                raiseMsg(sprintf(_("Couldn't rename nonexistant file <strong>%s</strong>."), $old_name), MSG_ERR, __FILE__, __LINE__);
    522494            }
     
    553525    function cleanFileName($file_name)
    554526    {
    555         $bad  = '‡Ž’—œˆ“˜Š‘•šŸçƒêîòËéíñô€èì
    556 †‰”™žåæëï󖍂@';
     527        $bad  = 'áéíóúàÚìòùÀëïöÌÁÉÍÓÚÀÈÌÒÙÄËÏÖÜâêîÎûÂÊÎÔÛñçÇ@';
    557528        $good = 'aeiouaeiouaeiouAEIOUAEIOUAEIOUaeiouAEIOUncCa';
    558529        $file_name = trim($file_name);
Note: See TracChangeset for help on using the changeset viewer.