Changeset 20 for trunk/lib


Ignore:
Timestamp:
Nov 17, 2005 3:00:00 AM (19 years ago)
Author:
scdev
Message:

Tons of little updates and bugfixes. CSS updates to templates and core css files. File upload ability to module_maker. Remade Upload interface to use setParam/getParam.

Location:
trunk/lib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r19 r20  
    2929    // Instance of database object.
    3030    var $db;
     31   
     32    // Array of query arguments will be carried persistently between requests.
     33    var $_carry_queries = array();
    3134
    3235    // Hash of global application parameters.
     
    4750        'ssl_enabled' => false,
    4851   
    49         // Character set for page output. Set in the Content-Type header and an HTML <meta content-type> tag.
     52        // Character set for page output. Used in the Content-Type header and the HTML <meta content-type> tag.
    5053        'character_set' => 'utf-8',
    5154
     
    534537   
    535538    /**
     539     * Sets which query arguments will be carried persistently between requests.
     540     * Values in the _carry_queries array will be copied to URLs (via oHREF()) and
     541     * to hidden input values (via printHiddenSession()).
     542     *
     543     * @access  public
     544     * @param   string  $query_key  The key of the query argument to save. 
     545     * @author  Quinn Comendant <quinn@strangecode.com>
     546     * @since   14 Nov 2005 19:24:52
     547     */
     548    function carryQuery($query_key)
     549    {
     550        if (!isset($this) || !is_a($this, 'App')) {
     551            $this =& App::getInstance();
     552        }
     553       
     554        // If not already set, and there is a non-empty value provided in the request...
     555        if (!isset($this->_carry_queries[$query_key]) && getFormData($query_key, false)) {
     556            // Copy the value of the specified query argument into the _carry_queries array.
     557            $this->_carry_queries[$query_key] = getFormData($query_key);
     558        }
     559    }
     560   
     561    /**
    536562     * Outputs a fully qualified URL with a query of all the used (ie: not empty)
    537563     * keys and values, including optional queries. This allows simple printing of
    538564     * links without needing to know which queries to add to it. If cookies are not
    539565     * used, the session id will be propogated in the URL.
    540      *
    541      * @global string $carry_queries       An array of keys to define which values to
    542      *                                     carry through from the POST or GET.
    543      *                                     $carry_queries = array('qry'); for example.
    544566     *
    545567     * @param  string $url                 The initial url
     
    565587            return false;
    566588        }
    567        
    568         static $_using_trans_sid;
    569         global $carry_queries;
    570    
    571         // Save the trans_sid setting.
    572         if (!isset($_using_trans_sid)) {
    573             $_using_trans_sid = ini_get('session.use_trans_sid');
    574         }
    575    
    576         // Initialize the carried queries.
    577         if (!isset($carry_queries['_carry_queries_init'])) {
    578             if (!is_array($carry_queries)) {
    579                 $carry_queries = array($carry_queries);
    580             }
    581             $tmp = $carry_queries;
    582             $carry_queries = array();
    583             foreach ($tmp as $key) {
    584                 if (!empty($key) && getFormData($key, false)) {
    585                     $carry_queries[$key] = getFormData($key);
    586                 }
    587             }
    588             $carry_queries['_carry_queries_init'] = true;
    589         }
    590    
    591         // Get any additional query arguments to add to the $carry_queries array.
    592         // If FALSE is a function argument, DO NOT carry the queries.
     589   
     590        // Get any provided query arguments to include in the final URL.
     591        // If FALSE is a provided here, DO NOT carry the queries.
    593592        $do_carry_queries = true;
    594593        $one_time_carry_queries = array();
     
    611610            }
    612611        }
    613    
     612       
    614613        // Get the first delimiter that is needed in the url.
    615614        $delim = preg_match('/\?/', $url) ? ini_get('arg_separator.output') : '?';
     
    617616        $q = '';
    618617        if ($do_carry_queries) {
    619             // Join the perm and temp carry_queries and filter out the _carry_queries_init element for the final query args.
    620             $query_args = array_diff_assoc(urlEncodeArray(array_merge($carry_queries, $one_time_carry_queries)), array('_carry_queries_init' => true));
     618            // Join the global _carry_queries and local one_time_carry_queries.
     619            $query_args = urlEncodeArray(array_merge($this->_carry_queries, $one_time_carry_queries));
    621620            foreach ($query_args as $key=>$val) {
    622621                // Check value is set and value does not already exist in the url.
     
    648647                    &&
    649648                    (
    650                         !$_using_trans_sid
     649                        !ini_get('session.use_trans_sid')
    651650                        || preg_match('!^(http|https)://!i', $url)
    652651                    )
     
    668667     * as hidden form elements for GET_VARS that might be in use.
    669668     *
    670      * @global string $carry_queries     An array of keys to define which values to
    671      *                                   carry through from the POST or GET.
    672      *                                   $carry_queries = array('qry'); for example
    673      *
    674669     * @param  mixed  $carry_args        Additional url arguments to carry in the query,
    675670     *                                   or FALSE to prevent carrying queries. Can be any of the following formats:
     
    679674     */
    680675    function printHiddenSession($carry_args=null)
    681     {
     676    {   
    682677        if (!isset($this) || !is_a($this, 'App')) {
    683678            $this =& App::getInstance();
     
    687682            return false;
    688683        }
    689        
    690         static $_using_trans_sid;
    691         global $carry_queries;
    692    
    693         // Save the trans_sid setting.
    694         if (!isset($_using_trans_sid)) {
    695             $_using_trans_sid = ini_get('session.use_trans_sid');
    696         }
    697        
    698         // Initialize the carried queries.
    699         if (!isset($carry_queries['_carry_queries_init'])) {
    700             if (!is_array($carry_queries)) {
    701                 $carry_queries = array($carry_queries);
    702             }
    703             $tmp = $carry_queries;
    704             $carry_queries = array();
    705             foreach ($tmp as $key) {
    706                 if (!empty($key) && getFormData($key, false)) {
    707                     $carry_queries[$key] = getFormData($key);
    708                 }
    709             }
    710             $carry_queries['_carry_queries_init'] = true;
    711         }
    712    
    713         // Get any additional query names to add to the $carry_queries array
    714         // that are found as function arguments.
    715         // If FALSE is a function argument, DO NOT carry the queries.
     684   
     685        // Get any provided query arguments to include in the final hidden form data.
     686        // If FALSE is a provided here, DO NOT carry the queries.
    716687        $do_carry_queries = true;
    717688        $one_time_carry_queries = array();
     
    737708        // For each existing POST value, we create a hidden input to carry it through a form.
    738709        if ($do_carry_queries) {
    739             // Join the perm and temp carry_queries and filter out the _carry_queries_init element for the final query args.
    740             $query_args = array_diff_assoc(urlEncodeArray(array_merge($carry_queries, $one_time_carry_queries)), array('_carry_queries_init' => true));
     710            // Join the global _carry_queries and local one_time_carry_queries.
     711            // urlencode is not used here, not for form data!
     712            $query_args = array_merge($this->_carry_queries, $one_time_carry_queries);
    741713            foreach ($query_args as $key=>$val) {
    742714                echo '<input type="hidden" name="' . $key . '" value="' . $val . '" />';
     
    745717       
    746718        // Include the SID if cookies are disabled.
    747         if (!isset($_COOKIE[session_name()]) && !$_using_trans_sid) {
     719        if (!isset($_COOKIE[session_name()]) && !ini_get('session.use_trans_sid')) {
    748720            echo '<input type="hidden" name="' . session_name() . '" value="' . session_id() . '" />';
    749721        }
  • trunk/lib/PayPal.inc.php

    r19 r20  
    188188                if (!in_array($key, array('button_url', 'link_url', 'submit_img', 'submit_text'))) {
    189189                    ?>
    190                     <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $val; ?>">
     190                    <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $val; ?>" />
    191191                    <?php
    192192                }
     
    194194        }
    195195        ?>
    196         <input type="image" src="<?php echo $this->_buttons[$name]['options']['submit_img']; ?>" border="0" name="submit" alt="<?php echo $this->_buttons[$name]['options']['submit_text']; ?>">
     196        <input type="image" src="<?php echo $this->_buttons[$name]['options']['submit_img']; ?>" border="0" name="submit" alt="<?php echo $this->_buttons[$name]['options']['submit_text']; ?>" />
    197197        </form>
    198198        <?php
  • trunk/lib/RecordLock.inc.php

    r19 r20  
    345345        <?php if ($this->getSecondsElapsed() > $this->getParam('timeout')) { ?>
    346346        <p><?php printf(_("You can forcibly unlock the record if you believe the editing session has expired. You might want to confirm with %s before doing this."), $this->getEditor()) ?></p>
    347         <input type="submit" class="formsubmitbutton" name="unlock" value="<?php echo _("Unlock"); ?>">
     347        <input type="submit" class="formsubmitbutton" name="unlock" value="<?php echo _("Unlock"); ?>" />
    348348        <?php } ?>
    349349       
    350         <input type="submit" class="formsubmitbutton" name="cancel" value="<?php echo _("Cancel"); ?>">
     350        <input type="submit" class="formsubmitbutton" name="cancel" value="<?php echo _("Cancel"); ?>" />
    351351        </form>
    352352        <?php
  • trunk/lib/RecordVersion.inc.php

    r19 r20  
    4040    {
    4141        static $instances = array();
    42 
    43         if (!is_a($auth_object, 'Auth_SQL')) {
    44             trigger_error('Constructor not provided a valid Auth_SQL object.', E_USER_ERROR);
    45         }
    4642               
    4743        if (!isset($instances[$auth_object->getVal('auth_name')])) {
     
    6056    {
    6157        if (!is_a($auth_object, 'Auth_SQL')) {
    62             trigger_error('Passed argument is not a valid Auth_SQL object.', E_USER_ERROR);
     58            trigger_error('Constructor not provided a valid Auth_SQL object.', E_USER_ERROR);
    6359        }
    6460       
  • trunk/lib/SortOrder.inc.php

    r19 r20  
    1515 *
    1616 * @author  Quinn Comendant <quinn@strangecode.com>
    17  * @version 1.6
     17 * @version 1.6.1
    1818 */
    1919require_once dirname(__FILE__) . '/App.inc.php';
     
    2626    var $sort_by;
    2727    var $order;
    28     var $asc_widget;
    29     var $desc_widget;
     28    var $asc_widget = '<img src="/admin/_widgets/sort_ascending.gif" alt="" width="11" height="7" border="0">';
     29    var $desc_widget = '<img src="/admin/_widgets/sort_descending.gif" alt="" width="11" height="7" border="0">';
    3030    var $default_sort;
    3131    var $default_order;
     
    4141    function SortOrder($default_sort = '', $default_order = '')
    4242    {       
    43         $this->asc_widget = '<img src="/_widgets/sort_ascending.gif" alt="" width="11" height="7" border="0">';
    44         $this->desc_widget = '<img src="/_widgets/sort_descending.gif" alt="" width="11" height="7" border="0">';
    45        
    4643        $this->setDefault($default_sort, $default_order);
    4744   
     
    146143        }
    147144
    148         if (!empty($this->_columns[strtolower($this->sort_by)][strtolower(strtolower($this->order))])) {
    149             return ' ORDER BY ' . addslashes($this->_columns[strtolower($this->sort_by)][strtolower(strtolower($this->order))]);
     145        if (!empty($this->_columns[strtolower($this->sort_by)][strtolower($this->order)])) {
     146            return ' ORDER BY ' . addslashes($this->_columns[strtolower($this->sort_by)][strtolower($this->order)]);
    150147        } else {
    151148            App::logMsg(sprintf('Could not find SQL to sort by %s %s.', $this->sort_by, $this->order), LOG_WARNING, __FILE__, __LINE__);
  • trunk/lib/SpellCheck.inc.php

    r19 r20  
    346346                ?>
    347347                </select>
    348                 <input type="text" name="spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]" value="<?php echo $original_word ?>" size="20">
     348                <input type="text" name="spelling_corrections[<?php echo $form_name ?>][<?php echo $i ?>]" value="<?php echo $original_word ?>" size="20" />
    349349                <?php if ($this->_use_personal_wordlist) { ?>
    350350                <input name="save_to_personal_wordlist[]" type="checkbox" value="<?php echo $i ?>" /><?php echo _("Learn spelling") ?>
  • trunk/lib/Upload.inc.php

    r19 r20  
    33 * Upload.inc.php
    44 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
    5  */
    6 
    7 /**
     5 *
    86 * The Upload class provides an interface to deal with http uploaded files.
    97 *
    108 * @author  Quinn Comendant <quinn@strangecode.com>
    119 * @requires App.inc.php
    12  * @version 1.0
     10 * @version 1.2
    1311 */
    1412
     
    1917    // General object parameters.
    2018    var $_params = array(
     19   
     20        // Display message with raiseMsg?
    2121        'display_messages' => true,
     22       
     23        // Existing files will be overwritten when there is a name conflict?
    2224        'allow_overwriting' => false,
     25
     26        // The filesystem path to the final upload directory.
     27        'upload_path' => null,
     28
     29        // The file permissions of the uploaded files. Remember, files will be owned by the web server user.
     30        'dest_file_perms' => 0600,
     31
     32        // Require file to have one of the following file extentions.
     33        'valid_file_extensions' => array('jpg', 'jpeg', 'gif', 'png', 'pdf', 'txt', 'text', 'html', 'htm'),
    2334    );
    24 
    25     // Disk path where new image(s) will be uploaded.
    26     var $upload_directory_path = null;
    2735
    2836    // Array of files with errors.
    2937    var $errors = array();
    30    
    31     // Array of acceptable file extensions (lowercase).
    32     var $valid_file_extensions = array('jpg', 'jpeg', 'gif', 'png', 'pdf', 'txt', 'text', 'html', 'htm');
    33    
    34     // The uploaded files will normally be owned by user 'apache'. Set world-read/write
    35     // if the website admin needs to read/delete these files.
    36     var $dest_file_perms = 0600;
    37    
     38
    3839    // Array of file extensions and corresponding mime-types.
    3940    var $mime_extension_map = array(
     
    223224    {
    224225        if (isset($params) && is_array($params)) {
     226       
     227            // Enforce valid upload_path parameter.
     228            if (isset($params['upload_path'])) {
     229                $params['upload_path'] = realpath($params['upload_path']);
     230                // Must be directory.
     231                if (!is_dir($params['upload_path'])) {
     232                    App::logMsg(sprintf('Upload directory invalid: %s', $params['upload_path']), LOG_ERR, __FILE__, __LINE__);
     233                    trigger_error(sprintf('Upload directory invalid: %s', $params['upload_path']), E_USER_ERROR);
     234                }
     235                // Must be writable.
     236                if (!is_writable($params['upload_path'])) {
     237                    App::logMsg(sprintf('Upload directory not writable: %s', $params['upload_path']), LOG_ERR, __FILE__, __LINE__);
     238                    trigger_error(sprintf('Upload directory not writable: %s', $params['upload_path']), E_USER_ERROR);
     239                }
     240                // Set the default upload path, stripping any extra slashes if needed.
     241                $params['upload_path'] = preg_replace('!/+$!', '', $params['upload_path']);
     242            }
     243       
    225244            // Merge new parameters with old overriding only those passed.
    226245            $this->_params = array_merge($this->_params, $params);
     
    250269     *
    251270     */
    252     function setUploadPath($path)
    253     {
    254         $path = realpath($path);
    255        
    256         if (!is_dir($path)) {
    257             App::logMsg(sprintf('Upload directory invalid: %s', $path), LOG_ERR, __FILE__, __LINE__);
    258         }
    259         if (!is_writable($path)) {
    260             App::logMsg(sprintf('Upload directory not writable: %s', $path), LOG_ERR, __FILE__, __LINE__);
    261         }
    262        
    263         // Set the default upload path, stripping any extra slashes if needed.
    264         $this->upload_directory_path = preg_replace('!/+$!', '', $path);
    265     }
    266 
    267     /**
    268      *
    269      */
    270271    function process($form_name, $custom_file_name=null)
    271272    {
    272273        // Ensure we have a upload directory.
    273         if (!isset($this->upload_directory_path)) {
     274        if (!$this->getParam('upload_path')) {
    274275            App::logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    275276            $this->raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
     
    364365           
    365366            // Check to be sure the file has a valid file extension.
    366             if (!in_array(strtolower($this->getFilenameExtension($files['name'][$i])), $this->valid_file_extensions)) {
    367                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it is an unrecognized type. Files must have one of the following file extensions: %s."), $files['name'][$i], join(', ', $this->valid_file_extensions)), MSG_ERR, __FILE__, __LINE__);
     367            if (!in_array(strtolower($this->getFilenameExtension($files['name'][$i])), $this->getParam('valid_file_extensions'))) {
     368                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it is an unrecognized type. Files must have one of the following file extensions: %s."), $files['name'][$i], join(', ', $this->getParam('valid_file_extensions'))), MSG_ERR, __FILE__, __LINE__);
    368369                App::logMsg(sprintf(_("The uploaded file %s has an unrecognized file extension."), $files['name'][$i]), LOG_WARNING, __FILE__, __LINE__);
    369370                $this->errors[] = $files['name'][$i];
     
    417418           
    418419            // Set the path and file name.
    419             $file_path_name = $this->upload_directory_path . '/' . $file_name;
     420            $file_path_name = $this->getParam('upload_path') . '/' . $file_name;
    420421           
    421422            // Move the file to the final place.
    422423            if (move_uploaded_file($files['tmp_name'][$i], $file_path_name)) {
    423                 chmod($file_path_name, $this->dest_file_perms);
     424                chmod($file_path_name, $this->getParam('dest_file_perms'));
    424425                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> uploaded successfully."), $files['name'][$i]), MSG_SUCCESS, __FILE__, __LINE__);
    425426                if (!isset($custom_file_name) && $files['name'][$i] != $file_name) {
     
    449450    {
    450451        // Ensure we have a upload directory.
    451         if (!isset($this->upload_directory_path)) {
     452        if (!$this->getParam('upload_path')) {
    452453            App::logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    453454            return false;
    454455        }
    455456       
    456         $file_path_name = $this->upload_directory_path . '/' . $file_name;
     457        $file_path_name = $this->getParam('upload_path') . '/' . $file_name;
    457458
    458459        if (!is_file($file_path_name)) {
     
    474475    {
    475476        // Ensure we have an upload directory.
    476         if (!isset($this->upload_directory_path)) {
     477        if (!$this->getParam('upload_path')) {
    477478            App::logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    478479            return false;
    479480        }
    480481       
    481         $old_file_path_name = $this->upload_directory_path . '/' . $old_name;
    482         $new_file_path_name = $this->upload_directory_path . '/' . $new_name;
     482        $old_file_path_name = $this->getParam('upload_path') . '/' . $old_name;
     483        $new_file_path_name = $this->getParam('upload_path') . '/' . $new_name;
    483484        if (file_exists($old_file_path_name)) {
    484             if (!rename($old_file_path_name, $new_file_path_name)) {
     485            if (rename($old_file_path_name, $new_file_path_name)) {
     486                $this->raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), basename($old_file_path_name), basename($new_file_path_name)), MSG_NOTICE, __FILE__, __LINE__);
     487                App::logMsg(sprintf('File renamed from %s to %s', $old_file_path_name, $new_file_path_name), LOG_DEBUG, __FILE__, __LINE__);
     488            } else {
    485489                $this->raiseMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), MSG_ERR, __FILE__, __LINE__);
    486490                App::logMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), LOG_ERR, __FILE__, __LINE__);
     
    500504    {
    501505        // Ensure we have a upload directory.
    502         if (!isset($this->upload_directory_path)) {
     506        if (!$this->getParam('upload_path')) {
    503507            App::logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    504508            return false;
    505509        }
    506510       
    507         return file_exists($this->upload_directory_path . '/' . $file_name);
     511        return file_exists($this->getParam('upload_path') . '/' . $file_name);
     512    }
     513
     514    /**
     515     * Get filename by glob pattern. Searches a directory for an image that matches the
     516     * specified glob pattern and returns the filename of the first file found.
     517     *
     518     * @access  public
     519     * @param   string  $pattern   Pattern to match filename.
     520     * @return  string filename on success, empty string on failure.
     521     * @author  Quinn Comendant <quinn@strangecode.com>
     522     * @since   15 Nov 2005 20:55:22
     523     */
     524    function getFilenameGlob($pattern)
     525    {
     526        $file_list = glob(sprintf('%s/%s', $this->getParam('upload_path'), $pattern));
     527        if (isset($file_list[0])) {
     528            return basename($file_list[0]);
     529        } else {
     530            return '';
     531        }
    508532    }
    509533
  • trunk/lib/Utilities.inc.php

    r19 r20  
    298298        }
    299299    } else {
    300         // We've come to the last dimention of the array, save the "array" and it's value.
     300        // We've come to the last dimention of the array, save the "array" and its value.
    301301        $args[$prefix] = urlencode($data);
    302302    }
Note: See TracChangeset for help on using the changeset viewer.