Changeset 518


Ignore:
Timestamp:
May 1, 2015 1:15:16 AM (9 years ago)
Author:
anonymous
Message:

Non-breaking function changes to App and Utilities.

Location:
trunk/lib
Files:
3 edited

Legend:

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

    r505 r518  
    6161    protected $_carry_queries = array();
    6262
     63    // Array of raised message counters.
     64    protected $_raised_msg_counter = array(MSG_NOTICE => 0, MSG_SUCCESS => 0, MSG_WARNING => 0, MSG_ERR => 0);
     65
    6366    // Dictionary of global application parameters.
    6467    protected $_params = array();
     
    514517        if (!in_array($type, array(MSG_NOTICE, MSG_SUCCESS, MSG_WARNING, MSG_ERR))) {
    515518            $this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_NOTICE, __FILE__, __LINE__);
     519        }
     520
     521        // Increment the counter for this message type.
     522        $this->_raised_msg_counter[$type] += 1;
     523    }
     524
     525    /*
     526    * Returns the number of raised message (all, or by type) for the current script execution (this number may not match the total number of messages stored in session for multiple script executions)
     527    *
     528    * @access   public
     529    * @param
     530    * @return
     531    * @author   Quinn Comendant <quinn@strangecode.com>
     532    * @version  1.0
     533    * @since    30 Apr 2015 17:13:03
     534    */
     535    public function getRaisedMessageCount($type='all')
     536    {
     537        if ('all' == $type) {
     538            return array_sum($this->_raised_msg_counter);
     539        } else if (isset($this->_raised_msg_counter[$type])) {
     540            return $this->_raised_msg_counter[$type];
     541        } else {
     542            $this->logMsg(sprintf('Cannot return count of unknown raised message type: %s', $type), LOG_WARNING, __FILE__, __LINE__);
     543            return false;
    516544        }
    517545    }
  • trunk/lib/Upload.inc.php

    r502 r518  
    304304
    305305            // Clean the file name of bad characters.
    306             $file_name = $this->cleanFileName($file_name);
     306            $file_name = cleanFileName($file_name);
    307307
    308308            // FINAL path and file name, lowercase extension.
     
    475475
    476476    /**
    477      * Removes non-latin characters from file name, using htmlentities to convert known weirdos into regular squares.
    478      *
    479      * @access  public
    480      * @param   string  $file_name  A name of a file.
    481      * @return  string              The same name, but cleaned.
    482      */
    483     public function cleanFileName($file_name)
    484     {
    485         $file_name = preg_replace(array(
    486             '/&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/ui',
    487             '/&(?:amp);/ui',
    488             '/[&;]+/u',
    489             '/[^a-zA-Z0-9()@._=+-]+/u',
    490             '/^_+|_+$/u'
    491         ), array(
    492             '$1',
    493             'and',
    494             '',
    495             '_',
    496             ''
    497         ), htmlentities($file_name, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'));
    498         return mb_substr($file_name, 0, 250);
    499     }
    500 
    501 
    502     /**
    503477     * Returns the extension of a file name, or an empty string if non exists.
    504478     *
  • trunk/lib/Utilities.inc.php

    r507 r518  
    8282    if (!empty($var)) {
    8383        ?>
    84         <script type="text/javascript" charset="utf-8">
     84        <script type="text/javascript">
    8585        /* <![CDATA[ */
    86         window.console && console.log('<?php printf('%s: %s (on line %s of %s)', $prefix, str_replace("'", "\\'", getDump($var, true)), $line, $file); ?>');
     86        console.log('<?php printf('%s: %s (on line %s of %s)', $prefix, str_replace("'", "\\'", getDump($var, true)), $line, $file); ?>');
    8787        /* ]]> */
    8888        </script>
     
    536536}
    537537
     538/**
     539 * Removes non-latin characters from file name, using htmlentities to convert known weirdos into regular squares.
     540 *
     541 * @access  public
     542 * @param   string  $file_name  A name of a file.
     543 * @return  string              The same name, but cleaned.
     544 */
     545function cleanFileName($file_name)
     546{
     547    $app =& App::getInstance();
     548
     549    $file_name = preg_replace(array(
     550        '/&([a-z]{1,2})(?:acute|cedil|circ|grave|lig|orn|ring|slash|th|tilde|uml|caron);/ui',
     551        '/&(?:amp);/ui',
     552        '/[&;]+/u',
     553        '/[^a-zA-Z0-9()@._=+-]+/u',
     554        '/^_+|_+$/u'
     555    ), array(
     556        '$1',
     557        'and',
     558        '',
     559        '_',
     560        ''
     561    ), htmlentities($file_name, ENT_NOQUOTES | ENT_IGNORE, $app->getParam('character_set')));
     562    return mb_substr($file_name, 0, 250);
     563}
     564
    538565/*
    539566* Convert a php.ini value (8M, 512K, etc), into integer value of bytes.
Note: See TracChangeset for help on using the changeset viewer.