Changeset 588 for trunk/lib


Ignore:
Timestamp:
Mar 18, 2017 12:33:50 PM (7 years ago)
Author:
anonymous
Message:

Added as fifth parameter to logMsg(). Change logPriorityToString() also map the reverse. Update App->url() to never allow indexed array query params for carried queries, use arr[]&arr[] instead.

File:
1 edited

Legend:

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

    r581 r588  
    742742     * @param string $file      The file where the log event occurs.
    743743     * @param string $line      The line of the file where the log event occurs.
    744      */
    745     public function logMsg($message, $priority=LOG_INFO, $file=null, $line=null)
     744     * @param string $url       The URL where the log event occurs ($_SERVER['REQUEST_URI'] will be used if left null).
     745     */
     746    public function logMsg($message, $priority=LOG_INFO, $file=null, $line=null, $url=null)
    746747    {
    747748        static $previous_events = array();
     
    756757        $file = '' == $file ? 'unknown-file' : $file;
    757758        $line = '' == $line ? 'unknown-line' : $line;
     759
     760        // Get the URL, or used the provided value.
     761        if (!isset($url)) {
     762            $url = isset($_SERVER['REQUEST_URI']) ? mb_substr($_SERVER['REQUEST_URI'], 0, $this->getParam('log_message_max_length')) : '';
     763        }
    758764
    759765        // If log file is not specified, don't log to a file.
     
    831837            'type'      => $this->logPriorityToString($priority),
    832838            'file:line' => "$file : $line",
    833             'url'       => isset($_SERVER['REQUEST_URI']) ? mb_substr($_SERVER['REQUEST_URI'], 0, $this->getParam('log_message_max_length')) : '',
     839            'url'       => $url,
    834840            'message'   => mb_substr($message, 0, $this->getParam('log_message_max_length')),
    835841        );
     
    880886    /**
    881887     * Returns the string representation of a LOG_* integer constant.
    882      *
    883      * @param int  $priority  The LOG_* integer constant.
    884      *
    885      * @return                The string representation of $priority.
     888     * Updated: also returns the LOG_* integer constant if passed a string log value ('info' returns 6).
     889     *
     890     * @param int  $priority  The LOG_* integer constant (to return the string name), or a string name of a log priority to return the integer LOG_* value..
     891     *
     892     * @return                The string representation of $priority (if integer given), or integer representation (if string given).
    886893     */
    887894    public function logPriorityToString($priority) {
     
    898905        if (isset($priorities[$priority])) {
    899906            return $priorities[$priority];
     907        } else if (is_string($priority) && false !== ($key = array_search($priority, $priorities))) {
     908            return $key;
    900909        } else {
    901910            return false;
     
    10451054            $query_args = urlEncodeArray(array_merge($this->_carry_queries, $one_time_carry_queries));
    10461055            foreach ($query_args as $key=>$val) {
     1056                // Avoid indexed-array query params because in a URL array param keys should all match.
     1057                // I.e, we want to use `array[]=A&array[]=B` instead of `array[0]=A&array[1]=B`.
     1058                $key = preg_replace('/\[\d+\]$/', '[]', $key);
    10471059                // Check value is set and value does not already exist in the url.
    10481060                if (!preg_match('/[?&]' . preg_quote($key) . '=/', $url)) {
Note: See TracChangeset for help on using the changeset viewer.