Changeset 502 for trunk/lib/App.inc.php


Ignore:
Timestamp:
Dec 30, 2014 10:24:51 PM (9 years ago)
Author:
anonymous
Message:

Many minor fixes during pulso development

File:
1 edited

Legend:

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

    r501 r502  
    4040require_once dirname(__FILE__) . '/Utilities.inc.php';
    4141
    42 class App {
     42class App
     43{
    4344
    4445    // Minimum version of PHP required for this version of the Codebase.
     
    627628        }
    628629
    629         // Make sure to log in the system's locale.
    630         $locale = setlocale(LC_TIME, 0);
    631         setlocale(LC_TIME, 'C');
    632 
    633630        // Strip HTML tags except any with more than 7 characters because that's probably not a HTML tag, e.g. <email@address.com>.
    634631        preg_match_all('/(<[^>\s]{7,})[^>]*>/', $message, $strip_tags_allow);
     
    678675        }
    679676
     677        // Make sure to log in the system's locale.
     678        $locale = setlocale(LC_TIME, 0);
     679        setlocale(LC_TIME, 'C');
     680
    680681        // Data to be stored for a log event.
    681682        $event = array(
     
    692693        $event_short['url'] = truncate($event_short['url'], 120);
    693694
     695        // Restore original locale.
     696        setlocale(LC_TIME, $locale);
    694697
    695698        // FILE ACTION
     
    702705        if (false !== $this->getParam('log_email_priority') && $priority <= $this->getParam('log_email_priority') && $send_notifications) {
    703706            $hostname = (isset($_SERVER['HTTP_HOST']) && '' != $_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : php_uname('n');
    704             $subject = sprintf('[%s %s] %s', $hostname, $event['type'], mb_substr($message, 0, 64));
     707            $subject = sprintf('[%s %s] %s', $hostname, $event['type'], mb_substr($event['message'], 0, 64));
    705708            $email_msg = sprintf("A %s log event occurred on %s\n\n", $event['type'], $hostname);
    706709            $headers = 'From: ' . $this->getParam('site_email');
     
    724727            file_put_contents('php://stderr', "[{$event['type']}] [{$event['message']}]\n", FILE_APPEND);
    725728        }
    726 
    727         // Restore original locale.
    728         setlocale(LC_TIME, $locale);
    729 
    730         unset($event, $event_short);
    731729
    732730        return true;
     
    850848     *                                     header('Location...') redirections.
    851849     *
     850     * @param   bool    $include_csrf_token     Set to true to include the csrf_token in the form. Only use this for forms with action="post" to prevent the token from being revealed in the URL.
    852851     * @return string url with attached queries and, if not using cookies, the session id
    853852     */
    854     public function url($url, $carry_args=null, $always_include_sid=false)
     853    public function url($url, $carry_args=null, $always_include_sid=false, $include_csrf_token=false)
    855854    {
    856855        if (!$this->running) {
    857856            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    858857            return false;
     858        }
     859
     860        if ($this->getParam('csrf_token_enabled') && $include_csrf_token) {
     861            // Include the csrf_token as a carried query argument.
     862            // This token can be validated upon form submission with $app->verifyCSRFToken() or $app->requireValidCSRFToken()
     863            $carry_args = is_array($carry_args) ? $carry_args : array();
     864            $carry_args = array_merge($carry_args, array($this->getParam('csrf_token_name') => $this->getCSRFToken()));
    859865        }
    860866
     
    938944     *
    939945     * @access  public
    940      * @param   string  $url    Input URL to parse.
    941      * @return  string          URL passed through $app->url() and then & turned to $amp;.
     946     * @param   (see param reference for url() method)
     947     * @return  string          URL passed through $app->url() with ampersamds transformed to $amp;
    942948     * @author  Quinn Comendant <quinn@strangecode.com>
    943949     * @since   09 Dec 2005 17:58:45
    944950     */
    945     public function oHREF($url, $carry_args=null, $always_include_sid=false)
    946     {
    947         $url = $this->url($url, $carry_args, $always_include_sid);
    948 
    949         // Replace any & not followed by an html or unicode entity with it's &amp; equivalent.
     951    public function oHREF($url, $carry_args=null, $always_include_sid=false, $include_csrf_token=false)
     952    {
     953        // Process the URL.
     954        $url = $this->url($url, $carry_args, $always_include_sid, $include_csrf_token);
     955
     956        // Replace any & not followed by an html or unicode entity with its &amp; equivalent.
    950957        $url = preg_replace('/&(?![\w\d#]{1,10};)/', '&amp;', $url);
    951958
     
    10931100            return false;
    10941101        }
    1095         $this->logMsg(sprintf('Verified CSRF token %s is in %s', $user_submitted_csrf_token, $csrf_token), LOG_DEBUG, __FILE__, __LINE__);
     1102        $this->logMsg(sprintf('Verified CSRF token %s', $user_submitted_csrf_token), LOG_DEBUG, __FILE__, __LINE__);
    10961103        return true;
    10971104    }
     
    11421149        }
    11431150
    1144         if ('' == $url) {
     1151        if (!$url) {
    11451152            // If URL is not specified, use the redirect_home_url.
    11461153            $url = $this->getParam('redirect_home_url');
     
    12951302        }
    12961303
    1297         $this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $this->getBoomerangURL($id)), LOG_DEBUG, __FILE__, __LINE__);
    1298 
    12991304        if (isset($id) && isset($_SESSION['_app'][$this->_ns]['boomerang']['url'][$id])) {
     1305            $url = $this->getBoomerangURL($id);
    13001306            unset($_SESSION['_app'][$this->_ns]['boomerang']['url'][$id]);
    13011307        } else if (is_array($_SESSION['_app'][$this->_ns]['boomerang']['url'])) {
    1302             array_pop($_SESSION['_app'][$this->_ns]['boomerang']['url']);
    1303         }
     1308            $url = array_pop($_SESSION['_app'][$this->_ns]['boomerang']['url']);
     1309        }
     1310        $this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    13041311    }
    13051312
Note: See TracChangeset for help on using the changeset viewer.