Changeset 119


Ignore:
Timestamp:
May 20, 2006 2:12:12 AM (18 years ago)
Author:
scdev
Message:

Q - making codebase 2 work with php5. Rewrote ImageThumb? class to work with GD

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/module_maker/module.cli.php

    r111 r119  
    442442
    443443if ('var' == $op) {
    444     if (isset($replace[$_SERVER['argv'][5]])) {
     444    if (isset($_SERVER['argv'][5]) && isset($replace[$_SERVER['argv'][5]])) {
    445445        echo "\n\n" . $replace[$_SERVER['argv'][5]] . "\n\n";
    446     } else if (isset($skel_files[$_SERVER['argv'][5]])) {
     446    } else if (isset($_SERVER['argv'][5]) && isset($skel_files[$_SERVER['argv'][5]])) {
    447447        echo "\n\n" . preg_replace($search, $replace, $skel_files[$_SERVER['argv'][5]]) . "\n\n";
    448448    } else {
    449         die(basename($_SERVER['argv'][0]) . " Error: variable " . $_SERVER['argv'][5] . " not defined. Please choose one of:\n" . join(', ', array_keys(array_merge($replace, $skel_files))) . "\n");
     449        die(basename($_SERVER['argv'][0]) . " Error: variable " . (isset($_SERVER['argv'][5]) ? $_SERVER['argv'][5] : '') . " not defined. Please choose one of:\n" . join(', ', array_keys(array_merge($replace, $skel_files))) . "\n");
    450450    }
    451451    die;
     
    549549    // Make user trash folder.
    550550    if (!is_dir($user_trash_folder)) {
     551        echo "Attempting to create user trash folder: $user_trash_folder/\n";
    551552        mkdir($user_trash_folder);
    552         chmod($user_trash_folder, 0777);
    553         echo "Attempting to create user trash folder: $user_trash_folder/\n";
     553        chmod($user_trash_folder, 0700);
    554554    }
    555555    if (!is_dir("$user_trash_folder/") || !is_writable("$user_trash_folder/")) {
  • trunk/lib/App.inc.php

    r108 r119  
    1616define('MSG_NOTICE', 4);
    1717define('MSG_SUCCESS', 8);
     18define('MSG_ALL', MSG_SUCCESS | MSG_NOTICE | MSG_WARNING | MSG_ERROR);
    1819
    1920require_once dirname(__FILE__) . '/Utilities.inc.php';
     
    163164    function setParam($param=null)
    164165    {
    165         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    166             $this =& App::getInstance();
     166        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     167            $_this =& App::getInstance();
    167168        }
    168169
    169170        if (isset($param) && is_array($param)) {
    170171            // Merge new parameters with old overriding only those passed.
    171             $this->_params = array_merge($this->_params, $param);
     172            $_this->_params = array_merge($_this->_params, $param);
    172173        }
    173174    }
     
    182183    function &getParam($param=null)
    183184    {
    184         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    185             $this =& App::getInstance();
     185        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     186            $_this =& App::getInstance();
    186187        }
    187188
    188189        if ($param === null) {
    189             return $this->_params;
    190         } else if (isset($this->_params[$param])) {
    191             return $this->_params[$param];
     190            return $_this->_params;
     191        } else if (isset($_this->_params[$param])) {
     192            return $_this->_params[$param];
    192193        } else {
    193194            trigger_error(sprintf('Parameter is not set: %s', $param), E_USER_NOTICE);
     
    359360    function raiseMsg($message, $type=MSG_NOTICE, $file=null, $line=null)
    360361    {
    361         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    362             $this =& App::getInstance();
     362        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     363            $_this =& App::getInstance();
    363364        }
    364365
    365366        $message = trim($message);
    366367
    367         if (!$this->running || '' == $message) {
    368             $this->logMsg(sprintf('Canceled method call %s, application not running or message is an empty string.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     368        if (!$_this->running || '' == $message) {
     369            $_this->logMsg(sprintf('Canceled method call %s, application not running or message is an empty string.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    369370            return false;
    370371        }
     
    372373        // Save message in session under unique key to avoid duplicate messages.
    373374        $msg_id = md5($type . $message . $file . $line);
    374         $_SESSION[$this->app]['messages'][$msg_id] = array(
     375        $_SESSION[$_this->app]['messages'][$msg_id] = array(
    375376            'type'    => $type,
    376377            'message' => $message,
    377378            'file'    => $file,
    378379            'line'    => $line,
    379             'count'   => (isset($_SESSION[$this->app]['messages'][$msg_id]['count']) ? (1 + $_SESSION[$this->app]['messages'][$msg_id]['count']) : 1)
     380            'count'   => (isset($_SESSION[$_this->app]['messages'][$msg_id]['count']) ? (1 + $_SESSION[$_this->app]['messages'][$msg_id]['count']) : 1)
    380381        );
    381382
    382383        if (!in_array($type, array(MSG_NOTICE, MSG_SUCCESS, MSG_WARNING, MSG_ERR))) {
    383             $this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_DEBUG, __FILE__, __LINE__);
     384            $_this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_DEBUG, __FILE__, __LINE__);
    384385        }
    385386    }
     
    395396    function getRaisedMessages()
    396397    {
    397         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    398             $this =& App::getInstance();
    399         }
    400 
    401         if (!$this->running) {
    402             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     398        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     399            $_this =& App::getInstance();
     400        }
     401
     402        if (!$_this->running) {
     403            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    403404            return false;
    404405        }
    405406       
    406407        $output = array();
    407         while (isset($_SESSION[$this->app]['messages']) && $message = array_shift($_SESSION[$this->app]['messages'])) {
     408        while (isset($_SESSION[$_this->app]['messages']) && $message = array_shift($_SESSION[$_this->app]['messages'])) {
    408409            $output[] = $message;
    409410        }
     
    420421    function clearRaisedMessages()
    421422    {
    422         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    423             $this =& App::getInstance();
    424         }
    425 
    426         if (!$this->running) {
    427             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     423        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     424            $_this =& App::getInstance();
     425        }
     426
     427        if (!$_this->running) {
     428            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    428429            return false;
    429430        }
    430431       
    431         $_SESSION[$this->app]['messages'] = array();
     432        $_SESSION[$_this->app]['messages'] = array();
    432433    }
    433434
     
    441442    function printRaisedMessages()
    442443    {
    443         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    444             $this =& App::getInstance();
    445         }
    446 
    447         if (!$this->running) {
    448             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    449             return false;
    450         }
    451 
    452         while (isset($_SESSION[$this->app]['messages']) && $message = array_shift($_SESSION[$this->app]['messages'])) {
     444        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     445            $_this =& App::getInstance();
     446        }
     447
     448        if (!$_this->running) {
     449            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     450            return false;
     451        }
     452
     453        while (isset($_SESSION[$_this->app]['messages']) && $message = array_shift($_SESSION[$_this->app]['messages'])) {
    453454            ?><div class="sc-msg"><?php
    454             if (error_reporting() > 0 && $this->getParam('display_errors')) {
     455            if (error_reporting() > 0 && $_this->getParam('display_errors')) {
    455456                echo "\n<!-- [" . $message['file'] . ' : ' . $message['line'] . '] -->';
    456457            }
     
    500501        static $previous_events = array();
    501502
    502         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    503             $this =& App::getInstance();
     503        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     504            $_this =& App::getInstance();
    504505        }
    505506
    506507        // If priority is not specified, assume the worst.
    507         if (!$this->logPriorityToString($priority)) {
    508             $this->logMsg(sprintf('Log priority %s not defined. (Message: %s)', $priority, $message), LOG_EMERG, $file, $line);
     508        if (!$_this->logPriorityToString($priority)) {
     509            $_this->logMsg(sprintf('Log priority %s not defined. (Message: %s)', $priority, $message), LOG_EMERG, $file, $line);
    509510            $priority = LOG_EMERG;
    510511        }
    511512
    512513        // If log file is not specified, don't log to a file.
    513         if (!$this->getParam('log_directory') || !$this->getParam('log_filename') || !is_dir($this->getParam('log_directory')) || !is_writable($this->getParam('log_directory'))) {
    514             $this->setParam(array('log_file_priority' => false));
     514        if (!$_this->getParam('log_directory') || !$_this->getParam('log_filename') || !is_dir($_this->getParam('log_directory')) || !is_writable($_this->getParam('log_directory'))) {
     515            $_this->setParam(array('log_file_priority' => false));
    515516            // We must use trigger_error to report this problem rather than calling App::logMsg, which might lead to an infinite loop.
    516             trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $this->getParam('log_directory')), E_USER_NOTICE);
     517            trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $_this->getParam('log_directory')), E_USER_NOTICE);
    517518        }
    518519
     
    530531            $previous_events[$msg_id]++;
    531532            if ($previous_events[$msg_id] == 2) {
    532                 $this->logMsg(sprintf('%s (Event repeated %s or more times)', $message, $previous_events[$msg_id]), $priority, $file, $line);
     533                $_this->logMsg(sprintf('%s (Event repeated %s or more times)', $message, $previous_events[$msg_id]), $priority, $file, $line);
    533534            }
    534535            return false;
     
    542543            'remote ip' => getRemoteAddr(),
    543544            'pid'       => (substr(PHP_OS, 0, 3) != 'WIN' ? posix_getpid() : ''),
    544             'type'      => $this->logPriorityToString($priority),
     545            'type'      => $_this->logPriorityToString($priority),
    545546            'file:line' => "$file : $line",
    546547            'url'       => (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''),
     
    549550
    550551        // FILE ACTION
    551         if ($this->getParam('log_file_priority') && $priority <= $this->getParam('log_file_priority')) {
     552        if ($_this->getParam('log_file_priority') && $priority <= $_this->getParam('log_file_priority')) {
    552553            $event_str = '[' . join('] [', $event) . ']';
    553             error_log($event_str . "\n", 3, $this->getParam('log_directory') . '/' . $this->getParam('log_filename'));
     554            error_log($event_str . "\n", 3, $_this->getParam('log_directory') . '/' . $_this->getParam('log_filename'));
    554555        }
    555556
    556557        // EMAIL ACTION
    557         if ($this->getParam('log_email_priority') && $priority <= $this->getParam('log_email_priority')) {
     558        if ($_this->getParam('log_email_priority') && $priority <= $_this->getParam('log_email_priority')) {
    558559            $subject = sprintf('[%s %s] %s', getenv('HTTP_HOST'), $event['type'], $message);
    559560            $email_msg = sprintf("A %s log event occured on %s\n\n", $event['type'], getenv('HTTP_HOST'));
     
    562563                $email_msg .= sprintf("%-11s%s\n", $k, $v);
    563564            }
    564             mail($this->getParam('log_to_email_address'), $subject, $email_msg, $headers, '-f codebase@strangecode.com');
     565            mail($_this->getParam('log_to_email_address'), $subject, $email_msg, $headers, '-f codebase@strangecode.com');
    565566        }
    566567
    567568        // SMS ACTION
    568         if ($this->getParam('log_sms_priority') && $priority <= $this->getParam('log_sms_priority')) {
     569        if ($_this->getParam('log_sms_priority') && $priority <= $_this->getParam('log_sms_priority')) {
    569570            $subject = sprintf('[%s %s]', getenv('HTTP_HOST'), $priority);
    570571            $sms_msg = sprintf('%s [%s:%s]', $event['message'], basename($file), $line);
    571572            $headers = "From: codebase@strangecode.com";
    572             mail($this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers, '-f codebase@strangecode.com');
     573            mail($_this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers, '-f codebase@strangecode.com');
    573574        }
    574575
    575576        // SCREEN ACTION
    576         if ($this->getParam('log_screen_priority') && $priority <= $this->getParam('log_screen_priority')) {
     577        if ($_this->getParam('log_screen_priority') && $priority <= $_this->getParam('log_screen_priority')) {
    577578            echo "[{$event['date']}] [{$event['type']}] [{$event['file:line']}] [{$event['message']}]\n";
    578579        }
     
    619620    function carryQuery($query_key)
    620621    {
    621         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    622             $this =& App::getInstance();
     622        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     623            $_this =& App::getInstance();
    623624        }
    624625
    625626        // If not already set, and there is a non-empty value provided in the request...
    626         if (!isset($this->_carry_queries[$query_key]) && getFormData($query_key, false)) {
     627        if (!isset($_this->_carry_queries[$query_key]) && getFormData($query_key, false)) {
    627628            // Copy the value of the specified query argument into the _carry_queries array.
    628             $this->_carry_queries[$query_key] = getFormData($query_key);
     629            $_this->_carry_queries[$query_key] = getFormData($query_key);
    629630        }
    630631    }
     
    651652    function url($url, $carry_args=null, $always_include_sid=false)
    652653    {
    653         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    654             $this =& App::getInstance();
    655         }
    656 
    657         if (!$this->running) {
    658             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     654        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     655            $_this =& App::getInstance();
     656        }
     657
     658        if (!$_this->running) {
     659            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    659660            return false;
    660661        }
     
    690691        if ($do_carry_queries) {
    691692            // Join the global _carry_queries and local one_time_carry_queries.
    692             $query_args = urlEncodeArray(array_merge($this->_carry_queries, $one_time_carry_queries));
     693            $query_args = urlEncodeArray(array_merge($_this->_carry_queries, $one_time_carry_queries));
    693694            foreach ($query_args as $key=>$val) {
    694695                // Check value is set and value does not already exist in the url.
     
    714715                    (
    715716                        !isset($_COOKIE[session_name()])
    716                         || !$this->getParam('session_use_cookies')
     717                        || !$_this->getParam('session_use_cookies')
    717718                    )
    718                     && $this->getParam('enable_session')
     719                    && $_this->getParam('enable_session')
    719720                    && isMyDomain($url)
    720721                    &&
     
    747748    function oHREF($url, $carry_args=null, $always_include_sid=false)
    748749    {
    749         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    750             $this =& App::getInstance();
    751         }
    752 
    753         $url = $this->url($url, $carry_args, $always_include_sid);
     750        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     751            $_this =& App::getInstance();
     752        }
     753
     754        $url = $_this->url($url, $carry_args, $always_include_sid);
    754755
    755756        // Replace any & not followed by an html or unicode entity with it's &amp; equivalent.
     
    771772    function printHiddenSession($carry_args=null)
    772773    {
    773         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    774             $this =& App::getInstance();
    775         }
    776 
    777         if (!$this->running) {
    778             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     774        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     775            $_this =& App::getInstance();
     776        }
     777
     778        if (!$_this->running) {
     779            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    779780            return false;
    780781        }
     
    807808            // Join the global _carry_queries and local one_time_carry_queries.
    808809            // urlencode is not used here, not for form data!
    809             $query_args = array_merge($this->_carry_queries, $one_time_carry_queries);
     810            $query_args = array_merge($_this->_carry_queries, $one_time_carry_queries);
    810811            foreach ($query_args as $key=>$val) {
    811812                echo '<input type="hidden" name="' . $key . '" value="' . $val . '" />';
     
    834835    function dieURL($url, $carry_args=null, $always_include_sid=false)
    835836    {
    836         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    837             $this =& App::getInstance();
    838         }
    839 
    840         if (!$this->running) {
    841             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     837        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     838            $_this =& App::getInstance();
     839        }
     840
     841        if (!$_this->running) {
     842            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    842843            return false;
    843844        }
     
    845846        if ('' == $url) {
    846847            // If URL is not specified, use the redirect_home_url.
    847             $url = $this->getParam('redirect_home_url');
     848            $url = $_this->getParam('redirect_home_url');
    848849        }
    849850
     
    855856        }
    856857
    857         $url = $this->url($url, $carry_args, $always_include_sid);
     858        $url = $_this->url($url, $carry_args, $always_include_sid);
    858859
    859860        header(sprintf('Location: %s', $url));
    860         $this->logMsg(sprintf('dieURL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
     861        $_this->logMsg(sprintf('dieURL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
    861862
    862863        // End this application.
    863864        // Recommended, although I'm not sure it's necessary: http://cn2.php.net/session_write_close
    864         $this->stop();
     865        $_this->stop();
    865866        die;
    866867    }
     
    883884    function dieBoomerangURL($id=null, $carry_args=null, $default_url=null)
    884885    {
    885         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    886             $this =& App::getInstance();
    887         }
    888 
    889         if (!$this->running) {
    890             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     886        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     887            $_this =& App::getInstance();
     888        }
     889
     890        if (!$_this->running) {
     891            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    891892            return false;
    892893        }
    893894
    894895        // Get URL from stored boomerang. Allow non specific URL if ID not valid.
    895         if ($this->validBoomerangURL($id, true)) {
    896             if (isset($id) && isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
    897                 $url = $_SESSION[$this->app]['boomerang']['url'][$id];
    898                 $this->logMsg(sprintf('dieBoomerangURL(%s) found: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     896        if ($_this->validBoomerangURL($id, true)) {
     897            if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
     898                $url = $_SESSION[$_this->app]['boomerang']['url'][$id];
     899                $_this->logMsg(sprintf('dieBoomerangURL(%s) found: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    899900            } else {
    900                 $url = end($_SESSION[$this->app]['boomerang']['url']);
    901                 $this->logMsg(sprintf('dieBoomerangURL(%s) using: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     901                $url = end($_SESSION[$_this->app]['boomerang']['url']);
     902                $_this->logMsg(sprintf('dieBoomerangURL(%s) using: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    902903            }
    903904            // Delete stored boomerang.
    904             $this->deleteBoomerangURL($id);
     905            $_this->deleteBoomerangURL($id);
    905906        } else if (isset($default_url)) {
    906907            $url = $default_url;
     
    908909            // Ensure that the redirecting page is not also the referrer.
    909910            $url = getenv('HTTP_REFERER');
    910             $this->logMsg(sprintf('dieBoomerangURL(%s) using referrer: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     911            $_this->logMsg(sprintf('dieBoomerangURL(%s) using referrer: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    911912        } else {
    912913            // If URL is not specified, use the redirect_home_url.
    913             $url = $this->getParam('redirect_home_url');
    914             $this->logMsg(sprintf('dieBoomerangURL(%s) not found, using redirect_home_url: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     914            $url = $_this->getParam('redirect_home_url');
     915            $_this->logMsg(sprintf('dieBoomerangURL(%s) not found, using redirect_home_url: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    915916        }
    916917
    917918        // A redirection will never happen immediately twice.
    918919        // Set the time so ensure this doesn't happen.
    919         $_SESSION[$this->app]['boomerang']['time'] = time();
    920         $this->dieURL($url, $carry_args);
     920        $_SESSION[$_this->app]['boomerang']['time'] = time();
     921        $_this->dieURL($url, $carry_args);
    921922    }
    922923
     
    930931    function setBoomerangURL($url=null, $id=null)
    931932    {
    932         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    933             $this =& App::getInstance();
    934         }
    935 
    936         if (!$this->running) {
    937             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     933        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     934            $_this =& App::getInstance();
     935        }
     936
     937        if (!$_this->running) {
     938            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    938939            return false;
    939940        }
     
    945946            $url = preg_replace('/boomerang=[\w]+/', '', $url);
    946947
    947             if (isset($_SESSION[$this->app]['boomerang']['url']) && is_array($_SESSION[$this->app]['boomerang']['url']) && !empty($_SESSION[$this->app]['boomerang']['url'])) {
     948            if (isset($_SESSION[$_this->app]['boomerang']['url']) && is_array($_SESSION[$_this->app]['boomerang']['url']) && !empty($_SESSION[$_this->app]['boomerang']['url'])) {
    948949                // If the URL currently exists in the boomerang array, delete.
    949                 while ($existing_key = array_search($url, $_SESSION[$this->app]['boomerang']['url'])) {
    950                     unset($_SESSION[$this->app]['boomerang']['url'][$existing_key]);
     950                while ($existing_key = array_search($url, $_SESSION[$_this->app]['boomerang']['url'])) {
     951                    unset($_SESSION[$_this->app]['boomerang']['url'][$existing_key]);
    951952                }
    952953            }
    953954
    954955            if (isset($id)) {
    955                 $_SESSION[$this->app]['boomerang']['url'][$id] = $url;
     956                $_SESSION[$_this->app]['boomerang']['url'][$id] = $url;
    956957            } else {
    957                 $_SESSION[$this->app]['boomerang']['url'][] = $url;
    958             }
    959             $this->logMsg(sprintf('setBoomerangURL(%s): %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     958                $_SESSION[$_this->app]['boomerang']['url'][] = $url;
     959            }
     960            $_this->logMsg(sprintf('setBoomerangURL(%s): %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    960961            return true;
    961962        } else {
    962             $this->logMsg(sprintf('setBoomerangURL(%s) is empty!', $id, $url), LOG_NOTICE, __FILE__, __LINE__);
     963            $_this->logMsg(sprintf('setBoomerangURL(%s) is empty!', $id, $url), LOG_NOTICE, __FILE__, __LINE__);
    963964            return false;
    964965        }
     
    972973    function getBoomerangURL($id=null)
    973974    {
    974         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    975             $this =& App::getInstance();
    976         }
    977 
    978         if (!$this->running) {
    979             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     975        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     976            $_this =& App::getInstance();
     977        }
     978
     979        if (!$_this->running) {
     980            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    980981            return false;
    981982        }
    982983
    983984        if (isset($id)) {
    984             if (isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
    985                 return $_SESSION[$this->app]['boomerang']['url'][$id];
     985            if (isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
     986                return $_SESSION[$_this->app]['boomerang']['url'][$id];
    986987            } else {
    987988                return '';
    988989            }
    989         } else if (is_array($_SESSION[$this->app]['boomerang']['url'])) {
    990             return end($_SESSION[$this->app]['boomerang']['url']);
     990        } else if (is_array($_SESSION[$_this->app]['boomerang']['url'])) {
     991            return end($_SESSION[$_this->app]['boomerang']['url']);
    991992        } else {
    992993            return false;
     
    10011002    function deleteBoomerangURL($id=null)
    10021003    {
    1003         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    1004             $this =& App::getInstance();
    1005         }
    1006 
    1007         if (!$this->running) {
    1008             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    1009             return false;
    1010         }
    1011 
    1012         $this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $this->getBoomerangURL($id)), LOG_DEBUG, __FILE__, __LINE__);
    1013 
    1014         if (isset($id) && isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
    1015             unset($_SESSION[$this->app]['boomerang']['url'][$id]);
    1016         } else if (is_array($_SESSION[$this->app]['boomerang']['url'])) {
    1017             array_pop($_SESSION[$this->app]['boomerang']['url']);
     1004        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     1005            $_this =& App::getInstance();
     1006        }
     1007
     1008        if (!$_this->running) {
     1009            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     1010            return false;
     1011        }
     1012
     1013        $_this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $_this->getBoomerangURL($id)), LOG_DEBUG, __FILE__, __LINE__);
     1014
     1015        if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
     1016            unset($_SESSION[$_this->app]['boomerang']['url'][$id]);
     1017        } else if (is_array($_SESSION[$_this->app]['boomerang']['url'])) {
     1018            array_pop($_SESSION[$_this->app]['boomerang']['url']);
    10181019        }
    10191020    }
     
    10271028    function validBoomerangURL($id=null, $use_nonspecificboomerang=false)
    10281029    {
    1029         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    1030             $this =& App::getInstance();
    1031         }
    1032 
    1033         if (!$this->running) {
    1034             $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    1035             return false;
    1036         }
    1037 
    1038         if (!isset($_SESSION[$this->app]['boomerang']['url'])) {
    1039             $this->logMsg(sprintf('validBoomerangURL(%s) no boomerang URL set.', $id), LOG_DEBUG, __FILE__, __LINE__);
     1030        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     1031            $_this =& App::getInstance();
     1032        }
     1033
     1034        if (!$_this->running) {
     1035            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     1036            return false;
     1037        }
     1038
     1039        if (!isset($_SESSION[$_this->app]['boomerang']['url'])) {
     1040            $_this->logMsg(sprintf('validBoomerangURL(%s) no boomerang URL set.', $id), LOG_DEBUG, __FILE__, __LINE__);
    10401041            return false;
    10411042        }
     
    10441045        // a boomerang redirection will always occur at least several seconds after the last boomerang redirect
    10451046        // or a boomerang being set.
    1046         $boomerang_time = isset($_SESSION[$this->app]['boomerang']['time']) ? $_SESSION[$this->app]['boomerang']['time'] : 0;
     1047        $boomerang_time = isset($_SESSION[$_this->app]['boomerang']['time']) ? $_SESSION[$_this->app]['boomerang']['time'] : 0;
    10471048
    10481049        $url = '';
    1049         if (isset($id) && isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
    1050             $url = $_SESSION[$this->app]['boomerang']['url'][$id];
     1050        if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
     1051            $url = $_SESSION[$_this->app]['boomerang']['url'][$id];
    10511052        } else if (!isset($id) || $use_nonspecificboomerang) {
    10521053            // Use non specific boomerang if available.
    1053             $url = end($_SESSION[$this->app]['boomerang']['url']);
    1054         }
    1055 
    1056         $this->logMsg(sprintf('validBoomerangURL(%s) testing: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     1054            $url = end($_SESSION[$_this->app]['boomerang']['url']);
     1055        }
     1056
     1057        $_this->logMsg(sprintf('validBoomerangURL(%s) testing: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    10571058
    10581059        if ('' == $url) {
    1059             $this->logMsg(sprintf('validBoomerangURL(%s) not valid, empty!', $id), LOG_DEBUG, __FILE__, __LINE__);
     1060            $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, empty!', $id), LOG_DEBUG, __FILE__, __LINE__);
    10601061            return false;
    10611062        }
    10621063        if ($url == absoluteMe()) {
    10631064            // The URL we are directing to is the current page.
    1064             $this->logMsg(sprintf('validBoomerangURL(%s) not valid, same as absoluteMe: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     1065            $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, same as absoluteMe: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    10651066            return false;
    10661067        }
    10671068        if ($boomerang_time >= (time() - 2)) {
    10681069            // Last boomerang direction was more than 2 seconds ago.
    1069             $this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__);
    1070             return false;
    1071         }
    1072 
    1073         $this->logMsg(sprintf('validBoomerangURL(%s) is valid: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     1070            $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__);
     1071            return false;
     1072        }
     1073
     1074        $_this->logMsg(sprintf('validBoomerangURL(%s) is valid: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    10741075        return true;
    10751076    }
     
    10811082    function sslOn()
    10821083    {
    1083         if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
    1084             $this =& App::getInstance();
     1084        if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
     1085            $_this =& App::getInstance();
    10851086        }
    10861087
     
    10921093        }
    10931094
    1094         if ('' == getenv('HTTPS') && $this->getParam('ssl_enabled') && in_array('mod_ssl', $modules)) {
    1095             $this->raiseMsg(sprintf(_("Secure SSL connection made to %s"), $this->getParam('ssl_domain')), MSG_NOTICE, __FILE__, __LINE__);
     1095        if ('' == getenv('HTTPS') && $_this->getParam('ssl_enabled') && in_array('mod_ssl', $modules)) {
     1096            $_this->raiseMsg(sprintf(_("Secure SSL connection made to %s"), $_this->getParam('ssl_domain')), MSG_NOTICE, __FILE__, __LINE__);
    10961097            // Always append session because some browsers do not send cookie when crossing to SSL URL.
    1097             $this->dieURL('https://' . $this->getParam('ssl_domain') . getenv('REQUEST_URI'), null, true);
     1098            $_this->dieURL('https://' . $_this->getParam('ssl_domain') . getenv('REQUEST_URI'), null, true);
    10981099        }
    10991100    }
  • trunk/lib/Auth_SQL.inc.php

    r111 r119  
    720720            WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
    721721        ");
     722       
     723        if (mysql_affected_rows(DB::getDBH()) != 1) {
     724            App::logMsg(sprintf('setPassword failed to update password for user %s', $user_id), LOG_NOTICE, __FILE__, __LINE__);
     725        }
    722726    }
    723727
  • trunk/lib/DB.inc.php

    r71 r119  
    8585    function setParam($params)
    8686    {
    87         if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
    88             $this =& DB::getInstance();
     87        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
     88            $_this =& DB::getInstance();
    8989        }
    9090
    9191        if (isset($params) && is_array($params)) {
    9292            // Merge new parameters with old overriding only those passed.
    93             $this->_params = array_merge($this->_params, $params);
     93            $_this->_params = array_merge($_this->_params, $params);
    9494        } else {
    9595            App::logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
     
    108108    function getParam($param)
    109109    {
    110         if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
    111             $this =& DB::getInstance();
    112         }
    113 
    114         if (isset($this->_params[$param])) {
    115             return $this->_params[$param];
     110        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
     111            $_this =& DB::getInstance();
     112        }
     113
     114        if (isset($_this->_params[$param])) {
     115            return $_this->_params[$param];
    116116        } else {
    117117            App::logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     
    129129    function connect()
    130130    {
    131         if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
    132             $this =& DB::getInstance();
    133         }
    134 
    135         if (!$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass')) {
     131        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
     132            $_this =& DB::getInstance();
     133        }
     134
     135        if (!$_this->getParam('db_name') || !$_this->getParam('db_user') || !$_this->getParam('db_pass')) {
    136136            App::logMsg('Database credentials missing.', LOG_EMERG, __FILE__, __LINE__);
    137137            return false;
     
    139139
    140140        // Connect to database. Always create a new link to the server.
    141         if ($this->dbh = mysql_connect($this->getParam('db_server'), $this->getParam('db_user'), $this->getParam('db_pass'), true)) {
     141        if ($_this->dbh = mysql_connect($_this->getParam('db_server'), $_this->getParam('db_user'), $_this->getParam('db_pass'), true)) {
    142142            // Select database
    143             mysql_select_db($this->getParam('db_name'), $this->dbh);
     143            mysql_select_db($_this->getParam('db_name'), $_this->dbh);
    144144        }
    145145
    146146        // Test for connection errors.
    147         if (!$this->dbh || mysql_error($this->dbh)) {
    148             $mysql_error_msg = $this->dbh ? 'Codebase MySQL error: (' . mysql_errno($this->dbh) . ') ' . mysql_error($this->dbh) : 'Codebase MySQL error: Could not connect to server.';
     147        if (!$_this->dbh || mysql_error($_this->dbh)) {
     148            $mysql_error_msg = $_this->dbh ? 'Codebase MySQL error: (' . mysql_errno($_this->dbh) . ') ' . mysql_error($_this->dbh) : 'Codebase MySQL error: Could not connect to server.';
    149149            App::logMsg($mysql_error_msg, LOG_EMERG, __FILE__, __LINE__);
    150150
    151151            // Print helpful or pretty error?
    152             if ($this->getParam('db_debug')) {
     152            if ($_this->getParam('db_debug')) {
    153153                echo $mysql_error_msg . "\n";
    154154            } else {
     
    157157
    158158            // Die or continue without connection?
    159             if ($this->getParam('db_die_on_failure')) {
     159            if ($_this->getParam('db_die_on_failure')) {
    160160                echo "\n\n<!-- Script execution stopped out of embarrassment. -->";
    161161                die;
     
    166166
    167167        // DB connection success!
    168         $this->_connected = true;
     168        $_this->_connected = true;
    169169
    170170        // Tell MySQL what character set we're useing. Available only on MySQL verions > 4.01.01.
    171         $this->query("/*!40101 SET NAMES '" . $this->mysql_character_sets[strtolower(App::getParam('character_set'))] . "' */");
     171        $_this->query("/*!40101 SET NAMES '" . $_this->mysql_character_sets[strtolower(App::getParam('character_set'))] . "' */");
    172172
    173173        return true;
     
    183183    function close()
    184184    {
    185         if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
    186             $this =& DB::getInstance();
    187         }
    188 
    189         if (!$this->_connected) {
    190             return false;
    191         }
    192 
    193         mysql_close($this->dbh);
     185        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
     186            $_this =& DB::getInstance();
     187        }
     188
     189        if (!$_this->_connected) {
     190            return false;
     191        }
     192
     193        mysql_close($_this->dbh);
    194194    }
    195195
     
    204204    function getDBH()
    205205    {
    206         if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
    207             $this =& DB::getInstance();
    208         }
    209 
    210         if (!$this->_connected) {
    211             return false;
    212         }
    213 
    214         return $this->dbh;
     206        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
     207            $_this =& DB::getInstance();
     208        }
     209
     210        if (!$_this->_connected) {
     211            return false;
     212        }
     213
     214        return $_this->dbh;
    215215    }
    216216
     
    238238    function escapeString($string)
    239239    {
    240         if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
    241             $this =& DB::getInstance();
    242         }
    243         return mysql_real_escape_string($string, $this->dbh);
     240        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
     241            $_this =& DB::getInstance();
     242        }
     243        return mysql_real_escape_string($string, $_this->dbh);
    244244    }
    245245
     
    256256        static $_query_count = 0;
    257257
    258         if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
    259             $this =& DB::getInstance();
    260         }
    261 
    262         if (!$this->_connected) {
     258        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
     259            $_this =& DB::getInstance();
     260        }
     261
     262        if (!$_this->_connected) {
    263263           return false;
    264264        }
     
    266266        $_query_count++;
    267267        $debugqry = preg_replace("/\n[\t ]+/", "\n", $query);
    268         if ($this->getParam('db_always_debug') || $debug) {
     268        if ($_this->getParam('db_always_debug') || $debug) {
    269269            echo "<!-- ----------------- Query $_query_count ---------------------\n$debugqry\n-->\n";
    270270        }
    271271
    272272        // Execute!
    273         $qid = mysql_query($query, $this->dbh);
     273        $qid = mysql_query($query, $_this->dbh);
    274274
    275275        // Error checking.
    276         if (!$qid || mysql_error($this->dbh)) {
    277             if ($this->getParam('db_debug')) {
    278                 echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
     276        if (!$qid || mysql_error($_this->dbh)) {
     277            if ($_this->getParam('db_debug')) {
     278                echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($_this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
    279279            } else {
    280280                echo _("This page is temporarily unavailable. It should be back up in a few minutes.");
    281281            }
    282             App::logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($this->dbh), mysql_error($this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
    283             if ($this->getParam('db_die_on_failure')) {
     282            App::logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($_this->dbh), mysql_error($_this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
     283            if ($_this->getParam('db_die_on_failure')) {
    284284                echo "\n\n<!-- Script execution stopped out of embarrassment. -->";
    285285                die;
     
    302302    function tableExists($table, $use_cached_results=true)
    303303    {
    304         if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
    305             $this =& DB::getInstance();
    306         }
    307 
    308         if (!$this->_connected) {
    309             return false;
    310         }
    311 
    312         if (!isset($this->existing_tables) || !$use_cached_results) {
    313             $this->existing_tables = array();
    314             $qid = $this->query("SHOW TABLES");
     304        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
     305            $_this =& DB::getInstance();
     306        }
     307
     308        if (!$_this->_connected) {
     309            return false;
     310        }
     311
     312        if (!isset($_this->existing_tables) || !$use_cached_results) {
     313            $_this->existing_tables = array();
     314            $qid = $_this->query("SHOW TABLES");
    315315            while (list($row) = mysql_fetch_row($qid)) {
    316                 $this->existing_tables[] = $row;
    317             }
    318         }
    319         if (in_array($table, $this->existing_tables)) {
     316                $_this->existing_tables[] = $row;
     317            }
     318        }
     319        if (in_array($table, $_this->existing_tables)) {
    320320            return true;
    321321        } else {
    322             App::logMsg(sprintf('nonexistent DB table: %s.%s', $this->getParam('db_name'), $table), LOG_ALERT, __FILE__, __LINE__);
     322            App::logMsg(sprintf('nonexistent DB table: %s.%s', $_this->getParam('db_name'), $table), LOG_ALERT, __FILE__, __LINE__);
    323323            return false;
    324324        }
     
    336336    function columnExists($table, $columns, $strict=true, $use_cached_results=true)
    337337    {
    338         if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
    339             $this =& DB::getInstance();
    340         }
    341 
    342         if (!$this->_connected) {
     338        if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
     339            $_this =& DB::getInstance();
     340        }
     341
     342        if (!$_this->_connected) {
    343343            return false;
    344344        }
    345345
    346346        // Ensure the table exists.
    347         if (!$this->tableExists($table, $use_cached_results)) {
     347        if (!$_this->tableExists($table, $use_cached_results)) {
    348348            return false;
    349349        }
     
    354354        }
    355355
    356         if (!isset($this->table_columns[$table]) || !$use_cached_results) {
     356        if (!isset($_this->table_columns[$table]) || !$use_cached_results) {
    357357            // Populate and cache array of current columns for this table.
    358             $this->table_columns[$table] = array();
    359             $qid = $this->query("DESCRIBE $table");
     358            $_this->table_columns[$table] = array();
     359            $qid = $_this->query("DESCRIBE $table");
    360360            while ($row = mysql_fetch_row($qid)) {
    361                 $this->table_columns[$table][] = $row[0];
     361                $_this->table_columns[$table][] = $row[0];
    362362            }
    363363        }
     
    366366            // Do an exact comparison of table schemas.
    367367            sort($columns);
    368             sort($this->table_columns[$table]);
    369             return $this->table_columns[$table] == $columns;
     368            sort($_this->table_columns[$table]);
     369            return $_this->table_columns[$table] == $columns;
    370370        } else {
    371371            // Only check that the specified columns are available in the table.
    372             $match_columns = array_intersect($this->table_columns[$table], $columns);
     372            $match_columns = array_intersect($_this->table_columns[$table], $columns);
    373373            sort($columns);
    374374            sort($match_columns);
  • trunk/lib/Email.inc.php

    r114 r119  
    281281        if (mail($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header)) {
    282282            App::logMsg(sprintf('Email successfully sent to %s', $final_to), LOG_DEBUG, __FILE__, __LINE__);
    283             return true
     283            return true;
    284284        } else {
    285285            App::logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $final_to, $this->_params['subject'], str_replace("\r\n", '\r\n', $final_headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__);
  • trunk/lib/FormValidator.inc.php

    r106 r119  
    417417
    418418        // Check domain exists: It's a domain if ip2long fails; Checkdnsrr ensures a MX record exists; Gethostbyname() ensures the domain exists.
    419         if (ip2long($domain) == '-1' && function_exists('checkdnsrr') && !checkdnsrr($domain . '.', 'MX') && gethostbyname($domain) == $domain) {
     419        // Compare ip2long twice for php4 backwards compat.
     420        if ((ip2long($domain) == '-1' || ip2long($domain) === false) && function_exists('checkdnsrr') && !checkdnsrr($domain . '.', 'MX') && gethostbyname($domain) == $domain) {
    420421            $this->addError($form_name, sprintf(_("<strong>%s</strong> is not a valid email domain name"), oTxt($domain)));
    421422            App::logMsg(sprintf('The email address %s contains an invalid email domain name (%s).', getFormData($form_name), $domain), LOG_INFO, __FILE__, __LINE__);
  • trunk/lib/ImageThumb.inc.php

    r42 r119  
    33 * ImageThumb.inc.php
    44 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
    5  */
    6 
    7 /**
    8  * The ImageThumb class resizes images.
    95 *
    106 * @author   Quinn Comendant <quinn@strangecode.com>
    11  * @requires Netpbm binaries from http://sourceforge.net/projects/netpbm/
    12  * @version  1.1
     7 * @requires Netpbm <http://sourceforge.net/projects/netpbm/> and libjpeg or GD.
     8 * @version  2.0
    139 */
    1410
     11// Image resize options.
    1512define('IMAGETHUMB_FIT_WIDTH', 1);
    1613define('IMAGETHUMB_FIT_HEIGHT', 2);
     
    1815define('IMAGETHUMB_STRETCH', 4);
    1916define('IMAGETHUMB_NO_SCALE', 5);
     17define('IMAGETHUMB_METHOD_NETPBM', 6);
     18define('IMAGETHUMB_METHOD_GD', 7);
    2019
    2120class ImageThumb {
    22 
    23     // The location for images to create thumbnails from.
    24     var $source_dir = null;
    25 
    26     // Specifications for thumbnail images.
    27     var $spec;
    28 
    29     // Array of acceptable file extensions (lowercase).
    30     var $valid_file_extensions = array('jpg', 'jpeg', 'gif', 'png');
    31 
    32     // The uploaded files will be owned by user 'apache'. Set world-read/write
    33     // if the website admin needs to read/delete these files. Must be at least 0400 with owner=apache.
    34     var $dest_file_perms = 0644;
    35 
    36     // Must be at least 0700 with owner=apache.
    37     var $dest_dir_perms = 0777;
    38 
    39     // Executable binary locations.
    40     var $anytopnm_binary = '/usr/bin/anytopnm';
    41     var $pnmscale_binary = '/usr/bin/pnmscale';
    42     var $cjpeg_binary = '/usr/bin/cjpeg';
    43     var $_valid_binaries = true;
    44 
    45     // Display messages raised in this object?
    46     var $display_messages = true;
    47 
    48     /**
    49      * Constructor.
    50      *
    51      * @access  public
    52      */
    53     function ImageThumb()
    54     {
    55         if (!file_exists($this->anytopnm_binary)) {
    56             App::logMsg(sprintf('ImageThumb error: anytopnm binary %s not found.', $this->anytopnm_binary), LOG_ERR, __FILE__, __LINE__);
    57             $this->_valid_binaries = false;
    58         }
    59         if (!file_exists($this->pnmscale_binary)) {
    60             App::logMsg(sprintf('ImageThumb error: pnmscale binary %s not found.', $this->pnmscale_binary), LOG_ERR, __FILE__, __LINE__);
    61             $this->_valid_binaries = false;
    62         }
    63         if (!file_exists($this->cjpeg_binary)) {
    64             App::logMsg(sprintf('ImageThumb error: cjpeg binary %s not found.', $this->cjpeg_binary), LOG_ERR, __FILE__, __LINE__);
    65             $this->_valid_binaries = false;
    66         }
    67     }
    68 
    69     /**
    70      * Set the directory of the source images.
    71      *
    72      * @access  public
    73      * @param   string $source_dir The full directory path of the source images.
     21   
     22    // General object parameters.
     23    var $_params = array(
     24        // The location for images to create thumbnails from.
     25        'source_dir' => null,
     26
     27        // Existing files will be overwritten when there is a name conflict?
     28        'allow_overwriting' => false,
     29
     30        // The file permissions of the uploaded files. Remember, files will be owned by the web server user.
     31        'dest_file_perms' => 0600,
     32
     33        // Permissions of autocreated directories. Must be at least 0700 with owner=apache.
     34        'dest_dir_perms' => 0777,
     35       
     36        // Destination file types. (IMG_JPG, IMG_PNG, IMG_GIF, IMG_WBMP)
     37        'dest_file_type' => IMG_JPG,
     38
     39        // Destination file types. ('jpg', 'png', 'gif', 'wbmp')
     40        'dest_file_extention' => 'jpg',
     41
     42        // Require file to have one of the following file name extentions.
     43        'valid_file_extensions' => array('jpg', 'jpeg', 'gif', 'png'),
     44       
     45        // Method to use for resizing. (IMAGETHUMB_METHOD_NETPBM or IMAGETHUMB_METHOD_GD)
     46        'resize_method' => IMAGETHUMB_METHOD_NETPBM,
     47
     48        // Netpbm and libjpeg binary locations.
     49        'anytopnm_binary' => '/usr/bin/anytopnm',
     50        'pnmscale_binary' => '/usr/bin/pnmscale',
     51        'cjpeg_binary' => '/usr/bin/cjpeg',
     52
     53        // Which messages do we pass to raiseMsg? Use one of the MSG_* constants or false to disable.
     54        'display_messages' => MSG_ALL,
     55    );
     56   
     57    // Default image size specs.
     58    var $default_image_specs = array(
     59        // The destination for an image thumbnail size. Path relative to source_dir (eg: ../thumbs).
     60        'dest_dir' => null,
     61        // Type of scaling to perform, and sizes used to calculate max dimentions.
     62        'scaling_type' => IMAGETHUMB_FIT_LARGER,
     63        'width' => null,
     64        'height' => null,
     65        // Percentage quality of image compression output 0-100.
     66        'quality' => 65,
     67        // Create progressive jpegs?
     68        'progressive' => false,
     69        // If source image is smaller than thumbnail, allow upscaling?
     70        'allow_upscaling' => false,
     71        // If thumb exists and filesize is smaller than this, do not overwrite the thumb.
     72        'keep_filesize' => null,
     73    );
     74
     75    // Final specifications for image sizes, set with setSpec().
     76    var $image_specs = array();
     77
     78    /**
     79     * Set (or overwrite existing) parameters by passing an array of new parameters.
     80     *
     81     * @access public
     82     * @param  array    $params     Array of parameters (key => val pairs).
     83     */
     84    function setParam($params)
     85    {
     86        if (isset($params) && is_array($params)) {
     87
     88            // Enforce valid upload_path parameter.
     89            if (isset($params['source_dir'])) {
     90                $params['source_dir'] = realpath($params['source_dir']);
     91                // Must be directory.
     92                if (!is_dir($params['source_dir'])) {
     93                    App::logMsg(sprintf('Source directory invalid: %s', $params['source_dir']), LOG_ERR, __FILE__, __LINE__);
     94                    trigger_error(sprintf('Source directory invalid: %s', $params['source_dir']), E_USER_ERROR);
     95                }
     96                // Must be readable.
     97                if (!is_readable($params['source_dir'])) {
     98                    App::logMsg(sprintf('Source directory not readable: %s', $params['source_dir']), LOG_ERR, __FILE__, __LINE__);
     99                    trigger_error(sprintf('Source directory not readable: %s', $params['source_dir']), E_USER_ERROR);
     100                }
     101            }
     102           
     103            if (isset($params['dest_file_type'])) {
     104                switch ($params['dest_file_type']) {
     105                case IMG_JPG :
     106                    if (imagetypes() & IMG_JPG == 0) {
     107                        App::logMsg(sprintf('IMG_JPG is not supported by this version of PHP GD.', null), LOG_ERR, __FILE__, __LINE__);
     108                    }
     109                    $params['dest_file_extention'] = 'jpg';
     110                    break;
     111                case IMG_PNG :
     112                    if (imagetypes() & IMG_PNG == 0) {
     113                        App::logMsg(sprintf('IMG_PNG is not supported by this version of PHP GD.', null), LOG_ERR, __FILE__, __LINE__);
     114                    }
     115                    $params['dest_file_extention'] = 'png';
     116                    break;
     117                case IMG_GIF :
     118                    if (imagetypes() & IMG_GIF == 0) {
     119                        App::logMsg(sprintf('IMG_GIF is not supported by this version of PHP GD.', null), LOG_ERR, __FILE__, __LINE__);
     120                    }
     121                    $params['dest_file_extention'] = 'gif';
     122                    break;
     123                case IMG_WBMP :
     124                    if (imagetypes() & IMG_WBMP == 0) {
     125                        App::logMsg(sprintf('IMG_WBMP is not supported by this version of PHP GD.', null), LOG_ERR, __FILE__, __LINE__);
     126                    }
     127                    $params['dest_file_extention'] = 'wbmp';
     128                    break;
     129                default :
     130                    App::logMsg(sprintf('Invalid dest_file_type: %s', $params['dest_file_type']), LOG_ERR, __FILE__, __LINE__);
     131                    break;
     132                }
     133            }
     134
     135            // Merge new parameters with old overriding only those passed.
     136            $this->_params = array_merge($this->_params, $params);
     137        } else {
     138            App::logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
     139        }
     140    }
     141
     142    /**
     143     * Return the value of a parameter, if it exists.
     144     *
     145     * @access public
     146     * @param string $param        Which parameter to return.
     147     * @return mixed               Configured parameter value.
     148     */
     149    function getParam($param)
     150    {
     151        if (isset($this->_params[$param])) {
     152            return $this->_params[$param];
     153        } else {
     154            App::logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     155            return null;
     156        }
     157    }
     158
     159    /**
     160     * Set the specification of thumbnails.
     161     *
     162     * @access  public
     163     * @param   array $spec The specifications for a size of output image.
     164     */
     165    function setSpec($spec)
     166    {
     167        // A little sanity checking.
     168        if (!isset($spec['dest_dir']) || '' == $spec['dest_dir']) {
     169            App::logMsg('setSpec error: dest_dir not specified.', LOG_ERR, __FILE__, __LINE__);
     170            return false;
     171        }
     172        if (!isset($spec['width']) || !is_int($spec['width'])) {
     173            App::logMsg('setSpec error: width not specified.', LOG_ERR, __FILE__, __LINE__);
     174            return false;
     175        }
     176        if (!isset($spec['height']) || !is_int($spec['height'])) {
     177            App::logMsg('setSpec error: height not specified.', LOG_ERR, __FILE__, __LINE__);
     178            return false;
     179        }
     180        if (isset($spec['quality']) && IMG_JPG != $this->getParam('dest_file_type')) {
     181            App::logMsg('The "quality" specification is not used unless IMG_JPG is the dest_file_type.', LOG_INFO, __FILE__, __LINE__);
     182        }
     183        if (isset($spec['progressive']) && IMG_JPG != $this->getParam('dest_file_type')) {
     184            App::logMsg('The "progressive" specification is not used unless IMG_JPG is the dest_file_type.', LOG_INFO, __FILE__, __LINE__);
     185        }
     186        // Merge defaults with provided.
     187        $this->image_specs[] = array_merge($this->default_image_specs, $spec);
     188    }
     189
     190    /**
     191     * Process an entire directory of images.
     192     *
     193     * @access  public
    74194     * @return  bool true on success, false on failure.
    75195     */
    76     function setSourceDirectory($source_dir)
    77     {
    78 
    79         // Set the source directory path, stripping any extra slashes if needed.
    80         $this->source_dir = preg_replace('!/+$!', '', $source_dir);
    81 
    82         if (!is_dir($this->source_dir)) {
    83             App::logMsg(sprintf('ImageThumb error: source directory not found: %s', $this->source_dir), LOG_ERR, __FILE__, __LINE__);
    84             return false;
    85         }
    86         if (!is_readable($this->source_dir)) {
    87             App::logMsg(sprintf('ImageThumb error: source directory not readable: %s', $this->source_dir), LOG_ERR, __FILE__, __LINE__);
    88             return false;
    89         }
    90         return true;
    91     }
    92 
    93     /**
    94      * Set the specification of thumbnails.
    95      *
    96      * @access  public
    97      * @param   array $spec The specifications for each size of output image.
    98      * @return  bool true on success, false on failure.
    99      */
    100     function setSpec($spec = array())
    101     {
    102         $dest_dir        = preg_replace('!/+$!', '', $spec['dest_dir']);
    103         $width           = $spec['width'];
    104         $height          = $spec['height'];
    105         $scaling_type    = $spec['scaling_type'];
    106         $quality         = isset($spec['quality']) ? $spec['quality'] : 75;
    107         $progressive     = isset($spec['progressive']) ? $spec['progressive'] : false;
    108         $allow_upscaling = isset($spec['allow_upscaling']) ? $spec['allow_upscaling'] : false;
    109         $keep_filesize   = isset($spec['keep_filesize']) ? $spec['keep_filesize'] : null;
    110 
    111         // Define pnmscale arguments.
    112         switch ($scaling_type) {
    113         case IMAGETHUMB_FIT_WIDTH :
    114             if (empty($width)) {
    115                 App::logMsg('ImageThumb error: width not specified for IMAGETHUMB_FIT_WIDTH.', LOG_ERR, __FILE__, __LINE__);
    116                 return false;
    117             }
    118             $pnmscale_args = sprintf(' -width %s ', escapeshellcmd($width));
    119             break;
    120         case IMAGETHUMB_FIT_HEIGHT :
    121             if (empty($height)) {
    122                 App::logMsg('ImageThumb error: height not specified for IMAGETHUMB_FIT_HEIGHT.', LOG_ERR, __FILE__, __LINE__);
    123                 return false;
    124             }
    125             $pnmscale_args = sprintf(' -height %s ', escapeshellcmd($height));
    126             break;
    127         case IMAGETHUMB_FIT_LARGER :
    128             if (empty($width) || empty($height)) {
    129                 App::logMsg('ImageThumb error: width or height not specified for IMAGETHUMB_FIT_LARGER.', LOG_ERR, __FILE__, __LINE__);
    130                 return false;
    131             }
    132             $pnmscale_args = sprintf(' -xysize %s %s ', escapeshellcmd($width), escapeshellcmd($height));
    133             break;
    134         case IMAGETHUMB_STRETCH :
    135             if (empty($width) || empty($height)) {
    136                 App::logMsg('ImageThumb error: width or height not specified for IMAGETHUMB_STRETCH.', LOG_ERR, __FILE__, __LINE__);
    137                 return false;
    138             }
    139             $pnmscale_args = sprintf(' -width %s -height %s ', escapeshellcmd($width), escapeshellcmd($height));
    140             break;
    141         case IMAGETHUMB_NO_SCALE :
    142         default :
    143             $pnmscale_args = ' 1 ';
    144             break;
    145         }
    146 
    147         // Define cjpeg arguments.
    148         $cjpeg_args = sprintf(' -optimize -quality %s ', escapeshellcmd($quality));
    149         $cjpeg_args .= (true === $progressive) ? ' -progressive ' : '';
    150 
    151         $this->spec[] = array(
    152             'dest_dir' => $dest_dir,
    153             'width' => $width,
    154             'height' => $height,
    155             'scaling_type' => $scaling_type,
    156             'quality' => $quality,
    157             'progressive' => $progressive,
    158             'pnmscale_args' => $pnmscale_args,
    159             'cjpeg_args' => $cjpeg_args,
    160             'allow_upscaling' => $allow_upscaling,
    161             'keep_filesize' => $keep_filesize,
    162         );
    163     }
    164 
    165     /**
    166      * Make directory for each specified thumbnail size, if it doesn't exist.
    167      *
    168      * @access  public
    169      * @return  bool true on success, false on failure.
    170      */
    171     function createDestDirs()
     196    function processAll()
    172197    {
    173198        // Ensure we have a source.
    174         if (!isset($this->source_dir)) {
    175             App::logMsg(sprintf('Source directory not set before creating destination directories.'), LOG_ERR, __FILE__, __LINE__);
    176             return false;
    177         }
    178         $return_val = 0;
    179         foreach ($this->spec as $s) {
    180             if (!is_dir($this->source_dir . '/' . $s['dest_dir'])) {
    181                 if (!mkdir($this->source_dir . '/' . $s['dest_dir'], $this->dest_dir_perms)) {
    182                     $return_val += 1;
    183                     App::logMsg(sprintf('mkdir failure: %s', $this->source_dir . '/' . $s['dest_dir']), LOG_ERR, __FILE__, __LINE__);
    184                 }
    185             }
    186         }
    187 
    188         // If > 0, there was a problem creating dest dirs.
    189         return (0 == $return_val);
     199        if ('' == $this->getParam('source_dir')) {
     200            App::logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
     201            return false;
     202        }
     203
     204        // Get all files in source directory.
     205        $dir_handle = opendir($this->getParam('source_dir'));
     206        while ($dir_handle && ($file = readdir($dir_handle)) !== false) {
     207            // If the file name does not start with a dot (. or .. or .htaccess).
     208            if (!preg_match('/^\./', $file) && in_array(strtolower(substr($file, strrpos($file, '.') + 1)), $this->getParam('valid_file_extensions'))) {
     209                $files[] = $file;
     210            }
     211        }
     212
     213        // Process each found file.
     214        if (is_array($files) && !empty($files)) {
     215            $return_val = 0;
     216            foreach ($files as $file_name) {
     217                $return_val += $this->processFile($file_name);
     218            }
     219            return 0 === $return_val;
     220        } else {
     221            App::logMsg(sprintf('No images found to thumbnail in directory %s.', $this->getParam('source_dir')), LOG_NOTICE, __FILE__, __LINE__);
     222            return false;
     223        }
    190224    }
    191225
     
    199233    function processFile($file_name)
    200234    {
    201         // Ensure we have valid binaries.
    202         if (!$this->_valid_binaries) {
    203             return false;
    204         }
    205 
     235        // Source file determinted by provided file_name.
     236        $source_file = realpath(sprintf('%s/%s', $this->getParam('source_dir'), $file_name));
     237       
    206238        // Ensure we have a source.
    207         if (!isset($this->source_dir)) {
     239        if (sizeof($this->image_specs) < 1) {
     240            App::logMsg(sprintf('Image specifications not set before processing.'), LOG_ERR, __FILE__, __LINE__);
     241            return false;
     242        }
     243
     244        // Ensure we have a source.
     245        if ('' == $this->getParam('source_dir')) {
    208246            App::logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    209247            return false;
    210248        }
    211249
     250        // Confirm source image exists.
     251        if (!file_exists($source_file)) {
     252            $this->_raiseMsg(sprintf(_("Image resizing failed: source image not found: <strong>%s</strong>"), $file_name), MSG_ERR, __FILE__, __LINE__);
     253            App::logMsg(sprintf('Source image not found: %s', $file_name), LOG_ALERT, __FILE__, __LINE__);
     254            return false;
     255        }
     256
     257        // Confirm source image is readable.
     258        if (!is_readable($source_file)) {
     259            $this->_raiseMsg(sprintf(_("Image resizing failed: source image not readable: <strong>%s</strong>"), $file_name), MSG_ERR, __FILE__, __LINE__);
     260            App::logMsg(sprintf('Source image not readable: %s', $file_name), LOG_ALERT, __FILE__, __LINE__);
     261            return false;
     262        }
     263
     264        // Confirm source image contains data.
     265        if (filesize($source_file) <= 0) {
     266            $this->_raiseMsg(sprintf(_("Image resizing failed: source image corrupt: <strong>%s</strong>"), $file_name), MSG_ERR, __FILE__, __LINE__);
     267            App::logMsg(sprintf('Source image is zero bytes: %s', $file_name), LOG_ALERT, __FILE__, __LINE__);
     268            return false;
     269        }
     270
     271        // Confirm source image has a valid file extension.
     272        if (!$this->_validFileExtension($file_name)) {
     273            $this->_raiseMsg(sprintf(_("Image resizing failed: source image not of valid type: <strong>%s</strong>"), $file_name), MSG_ERR, __FILE__, __LINE__);
     274            App::logMsg(sprintf('Image resizing failed: source image not of valid type: %s', $file_name), LOG_ERR, __FILE__, __LINE__);
     275            return false;
     276        }
     277
     278        // Ensure destination directories are created. This will only be called once per page load.
     279        $this->_createDestDirs();
     280       
    212281        // To keep this script running even if user tries to stop browser.
    213282        ignore_user_abort(true);
     
    216285        }
    217286
    218         // Confirm source image exists.
    219         if (!file_exists($this->source_dir . '/' . $file_name)) {
    220             $this->raiseMsg(sprintf(_("Image resizing failed: source image not found: <strong>%s</strong>"), $file_name), MSG_ERR, __FILE__, __LINE__);
    221             App::logMsg(sprintf('Source image not found: %s', $file_name), LOG_ALERT, __FILE__, __LINE__);
    222             return false;
    223         }
    224 
    225         // Confirm source image is readable.
    226         if (!is_readable($this->source_dir . '/' . $file_name)) {
    227             $this->raiseMsg(sprintf(_("Image resizing failed: source image not readable: <strong>%s</strong>"), $file_name), MSG_ERR, __FILE__, __LINE__);
    228             App::logMsg(sprintf('Source image not readable: %s', $file_name), LOG_ALERT, __FILE__, __LINE__);
    229             return false;
    230         }
    231 
    232         // Confirm source image contains data.
    233         if (filesize($this->source_dir . '/' . $file_name) < 1) {
    234             $this->raiseMsg(sprintf(_("Image resizing failed: source image corrupt: <strong>%s</strong>"), $file_name), MSG_ERR, __FILE__, __LINE__);
    235             App::logMsg(sprintf('Source image is zero bytes: %s', $file_name), LOG_ALERT, __FILE__, __LINE__);
    236             return false;
    237         }
    238 
    239         // Confirm source image has a valid file extension.
    240         if (!$this->validFileExtension($file_name)) {
    241             $this->raiseMsg(sprintf(_("Image resizing failed: source image not of valid type: <strong>%s</strong>"), $file_name), MSG_ERR, __FILE__, __LINE__);
    242             App::logMsg(sprintf('Image resizing failed: source image not of valid type: %s', $file_name), LOG_ERR, __FILE__, __LINE__);
    243             return false;
    244         }
    245 
    246         // Output file will be a jpg. Set file extension.
    247         $file_name = substr($file_name, 0, strrpos($file_name, '.')) . '.jpg';
    248 
    249287        // This remains zero until something goes wrong.
    250         $final_return_val = 0;
    251 
    252         foreach ($this->spec as $s) {
    253 
    254             // Skip existing thumbnails with file size below $s['keep_filesize'].
    255             if (file_exists(realpath($this->source_dir . '/' . $s['dest_dir'] . '/' . $file_name)) && isset($s['keep_filesize'])) {
    256                 $file_size = filesize(realpath($this->source_dir . '/' . $s['dest_dir'] . '/' . $file_name));
    257                 if ($file_size && $file_size < $s['keep_filesize']) {
    258                     App::logMsg(sprintf('Skipping thumbnail %s. File already exists and file size is less than %s bytes.', $s['dest_dir'] . '/' . $file_name, $s['keep_filesize']), LOG_DEBUG, __FILE__, __LINE__);
     288        $return_val = 0;
     289
     290        foreach ($this->image_specs as $spec) {
     291           
     292            // Destination filename uses the extention defined by dest_file_extention.
     293            $dest_file = realpath(sprintf('%s/%s/%s.%s', $this->getParam('source_dir'), $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $this->getParam('dest_file_extention')));
     294
     295            // Skip existing thumbnails with file size below $spec['keep_filesize'].
     296            if (isset($spec['keep_filesize']) && file_exists($dest_file)) {
     297                $file_size = filesize($dest_file);
     298                if (false !== $file_size && $file_size < $spec['keep_filesize']) {
     299                    App::logMsg(sprintf('Skipping thumbnail %s. File already exists and file size is less than %s bytes.', $spec['dest_dir'] . '/' . $file_name, $spec['keep_filesize']), LOG_DEBUG, __FILE__, __LINE__);
    259300                    continue;
    260301                }
    261302            }
    262303
    263             // Determine if original file size is smaller than specified thumbnail size. Do not scale-up if allow_upscaling config is set to false.
    264             $image_size = getimagesize(realpath($this->source_dir . '/' . $file_name));
    265             if ($image_size['0'] <= $s['width'] && $image_size['1'] <= $s['height'] && !$s['allow_upscaling']) {
    266                 $pnmscale_args = ' 1 ';
    267                 App::logMsg(sprintf('Image %s smaller than specified %s thumbnail size. Keeping original size.', $file_name, $s['dest_dir']), LOG_DEBUG, __FILE__, __LINE__);
     304            // Determine if original file size is smaller than specified thumbnail size. Do not scale-up if $spec['allow_upscaling'] config is set to false.
     305            $image_size = getimagesize($source_file);
     306            if ($image_size['0'] <= $spec['width'] && $image_size['1'] <= $spec['height'] && !$spec['allow_upscaling']) {
     307                $spec['scaling_type'] = IMAGETHUMB_NO_SCALE;
     308                App::logMsg(sprintf('Image %s smaller than specified %s thumbnail size. Keeping original size.', $file_name, $spec['dest_dir']), LOG_DEBUG, __FILE__, __LINE__);
     309            }
     310
     311            // DO IT! Based on available method.
     312            if (IMAGETHUMB_METHOD_NETPBM === $this->getParam('resize_method') && file_exists($this->getParam('anytopnm_binary')) && file_exists($this->getParam('pnmscale_binary')) && file_exists($this->getParam('cjpeg_binary'))) {
     313                // Resize using Netpbm binaries.
     314                App::logMsg(sprintf('Resizing with Netpbm...', null), LOG_DEBUG, __FILE__, __LINE__);
     315                $return_val += $this->_resizeWithNetpbm($source_file, $dest_file, $spec);
     316            } else if (IMAGETHUMB_METHOD_GD === $this->getParam('resize_method') && extension_loaded('gd')) {
     317                // Resize with GD.
     318                App::logMsg(sprintf('Resizing with GD...', null), LOG_DEBUG, __FILE__, __LINE__);
     319                $return_val += $this->_resizeWithGD($source_file, $dest_file, $spec);
    268320            } else {
    269                 $pnmscale_args = $s['pnmscale_args'];
    270             }
    271 
    272             // Execute the command that creates the thumbnail.
    273             $command = sprintf('%s %s/%s | %s %s | %s %s > %s/%s',
    274                 escapeshellcmd($this->anytopnm_binary),
    275                 escapeshellcmd($this->source_dir),
    276                 escapeshellcmd($file_name),
    277                 escapeshellcmd($this->pnmscale_binary),
    278                 escapeshellcmd($pnmscale_args),
    279                 escapeshellcmd($this->cjpeg_binary),
    280                 escapeshellcmd($s['cjpeg_args']),
    281                 escapeshellcmd(realpath($this->source_dir . '/' . $s['dest_dir'])),
    282                 escapeshellcmd($file_name)
    283             );
    284             App::logMsg(sprintf('ImageThumb command: %s', $command), LOG_DEBUG, __FILE__, __LINE__);
    285             exec($command, $output, $return_val);
    286 
    287             if (0 == $return_val) {
    288                 // Make the thumbnail writable so the user can delete it over ftp without being 'apache'.
    289                 chmod(realpath($this->source_dir . '/' . $s['dest_dir'] . '/' . $file_name), $this->dest_file_perms);
    290                 App::logMsg(sprintf('Successfully resized image %s', $s['dest_dir'] . '/' . $file_name, $return_val), LOG_DEBUG, __FILE__, __LINE__);
     321                App::logMsg(sprintf('Image thumbnailing failed. Neither Netpbm or GD is available.', null), LOG_DEBUG, __FILE__, __LINE__);
     322                return false;
     323            }
     324        }
     325
     326        // If > 0, there was a problem thumb-nailing.
     327        return 0 === $return_val;
     328    }
     329   
     330    /*
     331    * Use the Netpbm and libjpg cjpeg tools to generate a rescaled compressed image.
     332    * This is the preferred method over GD which has (supposedly) less quality.
     333    *
     334    * @access   private
     335    * @param    string  $source_file    Full path to source image file.
     336    * @param    string  $dest_file      Full path to destination image file.
     337    * @param    array   $spec           Array of image size specifications.
     338    * @return   bool                    Success value.
     339    * @author   Quinn Comendant <quinn@strangecode.com>
     340    * @version  1.0
     341    * @since    19 May 2006 13:55:46
     342    */
     343    function _resizeWithNetpbm($source_file, $dest_file, $spec)
     344    {
     345        // Define pnmscale arguments.
     346        switch ($spec['scaling_type']) {
     347        case IMAGETHUMB_FIT_WIDTH :
     348            $pnmscale_args = sprintf(' -width %s ', escapeshellarg($spec['width']));
     349            break;
     350        case IMAGETHUMB_FIT_HEIGHT :
     351            $pnmscale_args = sprintf(' -height %s ', escapeshellarg($spec['height']));
     352            break;
     353        case IMAGETHUMB_FIT_LARGER :
     354            $pnmscale_args = sprintf(' -xysize %s %s ', escapeshellarg($spec['width']), escapeshellarg($spec['height']));
     355            break;
     356        case IMAGETHUMB_STRETCH :
     357            $pnmscale_args = sprintf(' -width %s -height %s ', escapeshellarg($spec['width']), escapeshellarg($spec['height']));
     358            break;
     359        case IMAGETHUMB_NO_SCALE :
     360        default :
     361            $pnmscale_args = ' 1 ';
     362            break;
     363        }
     364
     365        // Define cjpeg arguments.
     366        $cjpeg_args = sprintf(' -optimize -quality %s ', escapeshellarg($spec['quality']));
     367        $cjpeg_args .= (true === $spec['progressive']) ? ' -progressive ' : '';
     368
     369        // Format the command that creates the thumbnail.
     370        $command = sprintf('%s %s | %s %s | %s %s > %s/%s',
     371            escapeshellcmd($this->getParam('anytopnm_binary')),
     372            escapeshellcmd($source_file),
     373            escapeshellcmd($this->getParam('pnmscale_binary')),
     374            escapeshellcmd($pnmscale_args),
     375            escapeshellcmd($this->getParam('cjpeg_binary')),
     376            escapeshellcmd($cjpeg_args),
     377            escapeshellcmd($dest_file),
     378            escapeshellcmd($file_name)
     379        );
     380        App::logMsg(sprintf('ImageThumb Netpbm command: %s', $command), LOG_DEBUG, __FILE__, __LINE__);
     381       
     382        // Execute!
     383        exec($command, $output, $return_val);
     384
     385        if (0 === $return_val) {
     386            // Success!
     387            // Make the thumbnail writable so the user can delete it over ftp without being 'apache'.
     388            chmod($dest_file, $this->getParam('dest_file_perms'));
     389            App::logMsg(sprintf('Successfully resized image %s', $spec['dest_dir'] . '/' . $file_name, $return_val), LOG_DEBUG, __FILE__, __LINE__);
     390        } else {
     391            // An error occurred.
     392            App::logMsg(sprintf('Image %s failed resizing with return value: %s%s', $spec['dest_dir'] . '/' . $file_name, $return_val, empty($output) ? '' : ' (' . getDump($output) . ')'), LOG_ERR, __FILE__, __LINE__);
     393        }
     394
     395        // Return from the command will be > 0 if there was an error.
     396        return $return_val;
     397    }
     398
     399    /*
     400    * Use PHP's built-in GD tools to generate a rescaled compressed image.
     401    *
     402    * @access   private
     403    * @param    string  $source_file    Full path to source image file.
     404    * @param    string  $dest_file      Full path to destination image file.
     405    * @param    array   $spec           Array of image size specifications.
     406    * @return   bool                    Success value.
     407    * @author   Quinn Comendant <quinn@strangecode.com>
     408    * @version  1.0
     409    * @since    19 May 2006 15:46:02
     410    */
     411    function _resizeWithGD($source_file, $dest_file, $spec)
     412    {
     413        // Get original file dimensions and type.
     414        list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_file);
     415
     416        // Define destination image dimentions.
     417        switch ($spec['scaling_type']) {
     418        case IMAGETHUMB_FIT_WIDTH :
     419            $dest_image_height = $source_image_height * ($spec['width'] / $source_image_width);
     420            $dest_image_width = $spec['width'];
     421            break;
     422        case IMAGETHUMB_FIT_HEIGHT :
     423            $dest_image_width = $source_image_width * ($spec['height'] / $source_image_height);
     424            $dest_image_height = $spec['height'];
     425            break;
     426        case IMAGETHUMB_FIT_LARGER :
     427            if ($source_image_width < $source_image_height) {
     428               $dest_image_width = $source_image_width * ($spec['height'] / $source_image_height);
     429               $dest_image_height = $source_image_height;
    291430            } else {
    292                 App::logMsg(sprintf('Image %s failed resizing with return value: %s%s', $s['dest_dir'] . '/' . $file_name, $return_val, empty($output) ? '' : ' (' . getDump($output) . ')'), LOG_ERR, __FILE__, __LINE__);
    293             }
    294 
    295             // Return from the command will be > 0 if there was an error.
    296             $final_return_val += $return_val;
    297         }
    298 
    299         // If > 0, there was a problem thumbnailing.
    300         return (0 == $final_return_val);
    301     }
    302 
    303     /**
    304      * Process an entire directory of images.
    305      *
    306      * @access  public
    307      * @return  bool true on success, false on failure.
    308      */
    309     function processAll()
    310     {
    311         // Ensure we have a source.
    312         if (!isset($this->source_dir)) {
    313             App::logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    314             return false;
    315         }
    316 
    317         // Get all files in source directory.
    318         $dir_handle = opendir($this->source_dir);
    319         while ($dir_handle && ($file = readdir($dir_handle)) !== false) {
    320             // If the file name does not start with a dot (. or .. or .htaccess).
    321             if (!preg_match('/^\./', $file) && in_array(strtolower(substr($file, strrpos($file, '.') + 1)), $this->valid_file_extensions)) {
    322                 $files[] = $file;
    323             }
    324         }
    325 
    326         // Process each found file.
    327         if (is_array($files) && !empty($files)) {
    328             foreach ($files as $file_name) {
    329                 $this->processFile($file_name);
    330             }
    331             return sizeof($files);
     431               $dest_image_height = $source_image_height * ($spec['width'] / $source_image_width);
     432               $dest_image_width = $source_image_width;
     433            }
     434            break;
     435        case IMAGETHUMB_STRETCH :
     436            $dest_image_width = $spec['width'];
     437            $dest_image_height = $spec['height'];
     438            break;
     439        case IMAGETHUMB_NO_SCALE :
     440        default :
     441            $dest_image_width = $source_image_width;
     442            $dest_image_height = $source_image_height;
     443            break;
     444        }
     445       
     446        echo '<li> sourceWidth: ' . $source_image_width;
     447        echo '<li> sourceHeight: ' . $source_image_height;
     448        echo '<li> Width: ' . $dest_image_width;
     449        echo '<li> Height: ' . $dest_image_height;
     450        die;///
     451
     452        // Create source image data in memory.
     453        switch ($source_image_type) {
     454        case IMAGETYPE_JPEG :
     455            $source_image_data = imagecreatefromjpeg($source_file);
     456            break;
     457        case IMAGETYPE_PNG :
     458            $source_image_data = imagecreatefrompng($source_file);
     459            break;
     460        case IMAGETYPE_GIF :
     461            $source_image_data = imagecreatefromgif($source_file);
     462            break;
     463        case IMAGETYPE_WBMP :
     464            $source_image_data = imagecreatefromwbmp($source_file);
     465        default :
     466            App::logMsg(sprintf('Source image type %s not supported.', $source_image_type), LOG_WARNING, __FILE__, __LINE__);
     467            return false;
     468            break;
     469        }
     470        if (!$source_image_data) {
     471            App::logMsg(sprintf('Error creating %s image in memory from %s', $source_image_type, $source_file), LOG_WARNING, __FILE__, __LINE__);
     472            return false;
     473        }
     474       
     475        // Create destination image data in memory.
     476        $dest_image_data = imagecreatetruecolor($dest_image_width, $dest_image_height);
     477
     478        // Resample!
     479        if (!imagecopyresampled($dest_image_data, $source_image_data, 0, 0, 0, 0, $dest_image_width, $dest_image_height, $source_image_width, $source_image_height)) {
     480            App::logMsg(sprintf('Error resampling image %s', $source_file), LOG_WARNING, __FILE__, __LINE__);
     481            return false;
     482        }
     483
     484        // Save image.
     485        $return_val = true;
     486        switch ($this->getParam('dest_file_type')) {
     487        case IMG_JPG :
     488            imageinterlace($dest_image_data, (true == $spec['progressive'] ? 1 : 0));
     489            $return_val = imagejpeg($dest_image_data, $dest_file, $spec['quality']);
     490            break;
     491        case IMG_PNG :
     492            $return_val = imagepng($dest_image_data, $dest_file);
     493            break;
     494        case IMG_GIF :
     495            $return_val = imagegif($dest_image_data, $dest_file);
     496            break;
     497        case IMG_WBMP :
     498            $return_val = imagewbmp($dest_image_data, $dest_file);
     499            break;
     500        default :
     501            App::logMsg(sprintf('Destination image type %s not supported for image %s.', $this->getParam('dest_file_type'), $dest_file), LOG_WARNING, __FILE__, __LINE__);
     502            return false;
     503            break;
     504        }
     505
     506        if ($return_val) {
     507            // Success!
     508            // Make the thumbnail writable so the user can delete it over ftp without being 'apache'.
     509            chmod($source_file, $this->getParam('dest_file_perms'));
     510            App::logMsg(sprintf('Successfully resized image %s', $dest_file), LOG_DEBUG, __FILE__, __LINE__);
     511            return true;
    332512        } else {
    333             App::logMsg(sprintf('No images found to thumbnail in directory %s.', $this->source_dir), LOG_NOTICE, __FILE__, __LINE__);
    334             return 0;
     513            // An error occurred.
     514            App::logMsg(sprintf('Image %s failed resizing.', $dest_file), LOG_ERR, __FILE__, __LINE__);
     515            return false;
    335516        }
    336517    }
     
    346527    {
    347528        // Ensure we have a source.
    348         if (!isset($this->source_dir)) {
     529        if ('' == $this->getParam('source_dir')) {
    349530            App::logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    350531            return false;
    351532        }
    352533
    353         $ret = 0;
    354         foreach ($this->spec as $s) {
    355             $file_path_name = realpath($this->source_dir . '/' . $s['dest_dir'] . '/' . $file_name);
    356             if (file_exists($file_path_name)) {
    357                 if (!unlink($file_path_name)) {
    358                     $ret++;
    359                     App::logMsg(sprintf(_("Delete thumbs failed: %s"), $file_path_name), LOG_WARNING, __FILE__, __LINE__);
     534        $return_val = 0;
     535        foreach ($this->image_specs as $spec) {
     536            $dest_file = realpath(sprintf('%s/%s/%s.%s', $this->getParam('source_dir'), $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $this->getParam('dest_file_extention')));
     537            if (file_exists($dest_file)) {
     538                if (!unlink($dest_file)) {
     539                    $return_val++;
     540                    App::logMsg(sprintf(_("Delete thumbs failed: %s"), $dest_file), LOG_WARNING, __FILE__, __LINE__);
    360541                }
    361542            }
    362543        }
    363         $this->raiseMsg(sprintf(_("The thumbnails for file <strong>%s</strong> have been deleted."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
    364         return (0 == $ret);
     544        $this->_raiseMsg(sprintf(_("The thumbnails for file <strong>%s</strong> have been deleted."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
     545        return 0 === $return_val;
    365546    }
    366547
     
    375556    {
    376557        // Ensure we have a source.
    377         if (!isset($this->source_dir)) {
     558        if ('' == $this->getParam('source_dir')) {
    378559            App::logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    379560            return false;
    380561        }
    381562
    382         $file_path_name = $this->source_dir . '/' . $file_name;
    383         if (!unlink($file_path_name)) {
    384             App::logMsg(sprintf(_("Delete original failed: %s"), $file_path_name), LOG_WARNING, __FILE__, __LINE__);
    385             return false;
    386         }
    387         $this->raiseMsg(sprintf(_("The original file <strong>%s</strong> has been deleted."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
     563        $source_file = realpath(sprintf('%s/%s', $this->getParam('source_dir'), $file_name));
     564        if (!unlink($source_file)) {
     565            App::logMsg(sprintf(_("Delete original failed: %s"), $source_file), LOG_WARNING, __FILE__, __LINE__);
     566            return false;
     567        }
     568        $this->_raiseMsg(sprintf(_("The original file <strong>%s</strong> has been deleted."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
    388569        return true;
    389570    }
     
    399580    {
    400581        // Ensure we have a source.
    401         if (!isset($this->source_dir)) {
     582        if ('' == $this->getParam('source_dir')) {
    402583            App::logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    403584            return false;
    404585        }
    405586
    406         return file_exists($this->source_dir . '/' . $file_name);
     587        $source_file = realpath(sprintf('%s/%s', $this->getParam('source_dir'), $file_name));
     588        return file_exists($source_file);
    407589    }
    408590
     
    414596     * @return  bool    True on success, false on failure.
    415597     */
    416     function validFileExtension($file_name)
     598    function _validFileExtension($file_name)
    417599    {
    418600        preg_match('/.*?\.(\w+)$/i', $file_name, $ext);
    419         return in_array(strtolower($ext[1]), $this->valid_file_extensions);
    420     }
    421 
    422     /**
    423      * An alias for App::raiseMsg that only sends messages if display_messages is true.
     601        return in_array(strtolower($ext[1]), $this->getParam('valid_file_extensions'));
     602    }
     603
     604    /**
     605     * Make directory for each specified thumbnail size, if it doesn't exist.
     606     *
     607     * @access  public
     608     * @return  bool true on success, false on failure.
     609     */
     610    function _createDestDirs()
     611    {
     612        static $already_checked = false;
     613
     614        if (!$already_checked) {
     615            // Ensure we have a source.
     616            if ('' == $this->getParam('source_dir')) {
     617                App::logMsg(sprintf('Source directory not set before creating destination directories.'), LOG_ERR, __FILE__, __LINE__);
     618                return false;
     619            }
     620       
     621            // Loop through specs and ensure all dirs are created.
     622            $return_val = 0;
     623            foreach ($this->image_specs as $spec) {
     624                if (!file_exists($this->getParam('source_dir') . '/' . $spec['dest_dir'])) {
     625                    if (!mkdir($this->getParam('source_dir') . '/' . $spec['dest_dir'], $this->getParam('dest_dir_perms'))) {
     626                        $return_val++;
     627                        App::logMsg(sprintf('mkdir failure: %s', $this->getParam('source_dir') . '/' . $spec['dest_dir']), LOG_ERR, __FILE__, __LINE__);
     628                    }
     629                }
     630            }
     631
     632            // If > 0, there was a problem creating dest dirs.
     633            return 0 === $return_val;
     634        }
     635
     636        $already_checked = true;
     637    }
     638
     639    /**
     640     * An alias for App::raiseMsg that only sends messages configured by display_messages.
    424641     *
    425642     * @access public
     
    431648     * @param string $line    __LINE__.
    432649     */
    433     function raiseMsg($message, $type, $file, $line)
    434     {
    435         if ($this->display_messages) {
     650    function _raiseMsg($message, $type, $file, $line)
     651    {
     652        if ($this->getParam('display_messages') === true || (is_int($this->getParam('display_messages')) && $this->getParam('display_messages') & $type > 0)) {
    436653            App::raiseMsg($message, $type, $file, $line);
    437654        }
  • trunk/lib/SessionCache.inc.php

    r53 r119  
    4444    function setParam($params)
    4545    {
    46         if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
    47             $this =& SessionCache::getInstance();
     46        if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
     47            $_this =& SessionCache::getInstance();
    4848        }
    4949
    5050        if (isset($params) && is_array($params)) {
    5151            // Merge new parameters with old overriding only those passed.
    52             $this->_params = array_merge($this->_params, $params);
     52            $_this->_params = array_merge($_this->_params, $params);
    5353        } else {
    5454            App::logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
     
    6565    function getParam($param)
    6666    {
    67         if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
    68             $this =& SessionCache::getInstance();
    69         }
    70 
    71         if (isset($this->_params[$param])) {
    72             return $this->_params[$param];
     67        if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
     68            $_this =& SessionCache::getInstance();
     69        }
     70
     71        if (isset($_this->_params[$param])) {
     72            return $_this->_params[$param];
    7373        } else {
    7474            App::logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     
    9595    function putCache($var, $var_id, $force_it_in=false)
    9696    {
    97         if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
    98             $this =& SessionCache::getInstance();
    99         }
    100 
    101         if (!$this->getParam('enabled')) {
     97        if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
     98            $_this =& SessionCache::getInstance();
     99        }
     100
     101        if (!$_this->getParam('enabled')) {
    102102            App::logMsg(sprintf('SessionCache not enabled, not saving data.', null), LOG_DEBUG, __FILE__, __LINE__);
    103103            return false;
     
    108108        $serialized_var_len = strlen($serialized_var);
    109109
    110         if ($serialized_var_len >= $this->getParam('soft_limit') && !$force_it_in) {
    111             App::logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $this->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
    112             return false;
    113         }
    114 
    115         if ($serialized_var_len >= $this->getParam('hard_limit')) {
    116             App::logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $this->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
     110        if ($serialized_var_len >= $_this->getParam('soft_limit') && !$force_it_in) {
     111            App::logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $_this->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
     112            return false;
     113        }
     114
     115        if ($serialized_var_len >= $_this->getParam('hard_limit')) {
     116            App::logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $_this->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
    117117            return false;
    118118        }
     
    123123            unset($_SESSION['_session_cache'][$var_id]);
    124124            // Continue to prune the cache if it's length is too long for the new variable to fit, but keep at least MIN_ITEMS at least.
    125             while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $this->getParam('soft_limit')
    126             && sizeof($_SESSION['_session_cache']) >= $this->getParam('min_items')) {
     125            while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $_this->getParam('soft_limit')
     126            && sizeof($_SESSION['_session_cache']) >= $_this->getParam('min_items')) {
    127127                array_shift($_SESSION['_session_cache']);
    128128            }
     
    149149    function getCache($var_id)
    150150    {
    151         if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
    152             $this =& SessionCache::getInstance();
    153         }
    154 
    155         if (!$this->getParam('enabled')) {
     151        if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
     152            $_this =& SessionCache::getInstance();
     153        }
     154
     155        if (!$_this->getParam('enabled')) {
    156156            return false;
    157157        }
     
    179179    function isCached($var_id)
    180180    {
    181         if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
    182             $this =& SessionCache::getInstance();
    183         }
    184 
    185         if (!$this->getParam('enabled')) {
     181        if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
     182            $_this =& SessionCache::getInstance();
     183        }
     184
     185        if (!$_this->getParam('enabled')) {
    186186            return false;
    187187        }
  • trunk/lib/SortOrder.inc.php

    r111 r119  
    33 * SortOrder.inc.php
    44 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
    5  */
    6 
    7 /**
     5 *
    86 * SortOrder can determing how to sort results of a database query for display
    97 * on a listing. It can print column headers that will be links to
    108 * automatically change the sort and order.
    119 *
    12  * @requires    This class requires App.inc.php
    13  * @requires    This class requires Utilities.inc.php
    1410 * @requires    This class requires Prefs.inc.php
    1511 *
    1612 * @author  Quinn Comendant <quinn@strangecode.com>
    17  * @version 1.6.1
     13 * @version 1.6.2
    1814 */
    19 require_once dirname(__FILE__) . '/App.inc.php';
    20 require_once dirname(__FILE__) . '/Utilities.inc.php';
    2115require_once dirname(__FILE__) . '/Prefs.inc.php';
    2216
  • trunk/lib/Upload.inc.php

    r118 r119  
    88 * @author  Quinn Comendant <quinn@strangecode.com>
    99 * @requires App.inc.php
    10  * @version 1.3
     10 * @version 1.4
    1111 */
    1212
    13 // Message Types.
    14 define('UPLOAD_MSG_ERR', MSG_ERR);
    15 define('UPLOAD_MSG_ERROR', MSG_ERROR);
    16 define('UPLOAD_MSG_WARNING', MSG_WARNING);
    17 define('UPLOAD_MSG_NOTICE', MSG_NOTICE);
    18 define('UPLOAD_MSG_SUCCESS', MSG_SUCCESS);
    19 define('UPLOAD_MSG_ALL', MSG_SUCCESS + MSG_NOTICE + MSG_WARNING + MSG_ERROR);
    20 
    21 require_once dirname(__FILE__) . '/App.inc.php';
     13// Upload error types.
     14define('UPLOAD_USER_ERR_EMPTY_FILE', 100);
     15define('UPLOAD_USER_ERR_NOT_UPLOADED_FILE', 101);
     16define('UPLOAD_USER_ERR_INVALID_EXTENSION', 102);
     17define('UPLOAD_USER_ERR_NOT_UNIQUE', 103);
     18define('UPLOAD_USER_ERR_MOVE_FAILED', 104);
    2219
    2320class Upload {
     
    2724
    2825        // Which messages do we pass to raiseMsg?
    29         'display_messages' => UPLOAD_MSG_ALL,
     26        'display_messages' => MSG_ALL,
    3027
    3128        // Existing files will be overwritten when there is a name conflict?
     
    116113        if (!$this->getParam('upload_path')) {
    117114            App::logMsg(sprintf('Upload directory not set before processing.'), LOG_ERR, __FILE__, __LINE__);
    118             $this->raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
     115            $this->_raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
    119116            return false;
    120117        }
     
    123120        if (!isset($_FILES[$form_name])) {
    124121            App::logMsg(sprintf(_("Form element %s does not exist."), $form_name), LOG_ERR, __FILE__, __LINE__);
    125             $this->raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
     122            $this->_raiseMsg(_("There was a problem with the file upload. Please try again later."), MSG_ERR, __FILE__, __LINE__);
    126123            return false;
    127124        }
     
    162159                    // Valid custom file name.
    163160                    $file_name = $custom_file_name;
    164                     $this->raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
     161                    $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
    165162                    App::logMsg(sprintf('Using custom file name: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__);
    166163                } else {
     
    174171                    // Valid custom file name.
    175172                    $file_name = $custom_file_name[$i];
    176                     $this->raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
     173                    $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> has been renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
    177174                    App::logMsg(sprintf('Using custom file name: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__);
    178175                } else {
     
    200197            if (UPLOAD_ERR_INI_SIZE === $files['error'][$i]) {
    201198                if ($this->getParam('display_messages')) {
    202                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload file size of %s."), $file_name, ini_get('upload_max_filesize')), MSG_ERR, __FILE__, __LINE__);
     199                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload file size of %s."), $file_name, ini_get('upload_max_filesize')), MSG_ERR, __FILE__, __LINE__);
    203200                }
    204201                App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_INI_SIZE (currently %s)."), $files['error'][$i], $file_name, ini_get('upload_max_filesize')), LOG_ERR, __FILE__, __LINE__);
    205                 $this->errors[] = $file_name;
     202                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_ERR_INI_SIZE);
    206203                continue;
    207204            }
    208205            if (UPLOAD_ERR_FORM_SIZE === $files['error'][$i]) {
    209                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload file size of %s."), $file_name, $_POST['MAX_FILE_SIZE']), MSG_ERR, __FILE__, __LINE__);
     206                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it exceeds the maximum allowed upload file size of %s."), $file_name, $_POST['MAX_FILE_SIZE']), MSG_ERR, __FILE__, __LINE__);
    210207                App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_FORM_SIZE (currently %s)."), $files['error'][$i], $file_name, $_POST['MAX_FILE_SIZE']), LOG_ERR, __FILE__, __LINE__);
    211                 $this->errors[] = $file_name;
     208                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_ERR_FORM_SIZE);
    212209                continue;
    213210            }
    214211            if (UPLOAD_ERR_PARTIAL === $files['error'][$i]) {
    215                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it was only partially uploaded."), $file_name), MSG_ERR, __FILE__, __LINE__);
     212                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it was only partially uploaded."), $file_name), MSG_ERR, __FILE__, __LINE__);
    216213                App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_PARTIAL."), $files['error'][$i], $file_name), LOG_ERR, __FILE__, __LINE__);
    217                 $this->errors[] = $file_name;
     214                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_ERR_PARTIAL);
    218215                continue;
    219216            }
    220217            if (UPLOAD_ERR_NO_FILE === $files['error'][$i]) {
    221                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: no file was uploaded."), $file_name), MSG_ERR, __FILE__, __LINE__);
     218                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: no file was uploaded."), $file_name), MSG_ERR, __FILE__, __LINE__);
    222219                App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_NO_FILE."), $files['error'][$i], $file_name), LOG_ERR, __FILE__, __LINE__);
    223                 $this->errors[] = $file_name;
     220                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_ERR_NO_FILE);
    224221                continue;
    225222            }
    226223            if (UPLOAD_ERR_NO_TMP_DIR === $files['error'][$i]) {
    227                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: temporary upload directory missing."), $file_name), MSG_ERR, __FILE__, __LINE__);
     224                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: temporary upload directory missing."), $file_name), MSG_ERR, __FILE__, __LINE__);
    228225                App::logMsg(sprintf(_("The file %s failed uploading with PHP error %s UPLOAD_ERR_NO_TMP_DIR."), $files['error'][$i], $file_name), LOG_ERR, __FILE__, __LINE__);
    229                 $this->errors[] = $file_name;
     226                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_ERR_NO_TMP_DIR);
    230227                continue;
    231228            }
     
    233230            // Check to be sure it's an uploaded file.
    234231            if (!is_uploaded_file($files['tmp_name'][$i])) {
    235                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $file_name), MSG_ERR, __FILE__, __LINE__);
     232                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $file_name), MSG_ERR, __FILE__, __LINE__);
    236233                App::logMsg(sprintf(_("The file %s failed is_uploaded_file."), $file_name), LOG_ERR, __FILE__, __LINE__);
    237                 $this->errors[] = $file_name;
     234                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_USER_ERR_NOT_UPLOADED_FILE);
    238235                continue;
    239236            }
    240237
    241238            // Check to be sure the file is not empty.
    242             if ($files['size'][$i] < 1) {
    243                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it contains zero bytes."), $file_name), MSG_ERR, __FILE__, __LINE__);
     239            if ($files['size'][$i] <= 0) {
     240                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it contains zero bytes."), $file_name), MSG_ERR, __FILE__, __LINE__);
    244241                App::logMsg(sprintf(_("The uploaded file %s contains zero bytes."), $file_name), LOG_ERR, __FILE__, __LINE__);
    245                 $this->errors[] = $file_name;
     242                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_USER_ERR_EMPTY_FILE);
    246243                continue;
    247244            }
     
    249246            // Check to be sure the file has a valid file name extension.
    250247            if (!in_array(strtolower($this->getFilenameExtension($file_name)), $this->getParam('valid_file_extensions'))) {
    251                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it is an unrecognized type. Files must have one of the following file name extensions: %s."), $file_name, join(', ', $this->getParam('valid_file_extensions'))), MSG_ERR, __FILE__, __LINE__);
     248                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: it is an unrecognized type. Files must have one of the following file name extensions: %s."), $file_name, join(', ', $this->getParam('valid_file_extensions'))), MSG_ERR, __FILE__, __LINE__);
    252249                App::logMsg(sprintf(_("The uploaded file %s has an unrecognized file name extension."), $file_name), LOG_WARNING, __FILE__, __LINE__);
    253                 $this->errors[] = $file_name;
     250                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_USER_ERR_INVALID_EXTENSION);
    254251                continue;
    255252            }
     
    257254            // Check to be sure the file has a unique file name.
    258255            if (!$this->getParam('allow_overwriting') && $this->exists($file_name)) {
    259                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: a file with that name already exists."), $file_name), MSG_ERR, __FILE__, __LINE__);
     256                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading: a file with that name already exists."), $file_name), MSG_ERR, __FILE__, __LINE__);
    260257                App::logMsg(sprintf(_("The uploaded file %s doesn't have a unique filename."), $file_name), LOG_WARNING, __FILE__, __LINE__);
    261                 $this->errors[] = $file_name;
     258                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_USER_ERR_NOT_UNIQUE);
    262259                continue;
    263260            }
     
    267264                chmod($file_path_name, $this->getParam('dest_file_perms'));
    268265                App::logMsg(sprintf('File uploaded: %s', $file_path_name), LOG_INFO, __FILE__, __LINE__);
    269                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> uploaded successfully."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
     266                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> uploaded successfully."), $file_name), MSG_SUCCESS, __FILE__, __LINE__);
    270267                if (!isset($custom_file_name) && $files['name'][$i] != $file_name) {
    271268                    // Notify user if uploaded file name was modified (unless a custom file name will be used anyways).
    272                     $this->raiseMsg(sprintf(_("The file <strong>%s</strong> was renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
     269                    $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> was renamed to <strong>%s</strong>."), $files['name'][$i], $file_name), MSG_NOTICE, __FILE__, __LINE__);
    273270                }
    274271                $new_file_names[] = array(
     
    279276                continue;
    280277            } else {
    281                 $this->raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $file_name), MSG_ERR, __FILE__, __LINE__);
     278                $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> failed uploading."), $file_name), MSG_ERR, __FILE__, __LINE__);
    282279                App::logMsg(sprintf(_("Moving file failed: %s -> %s"), $files['tmp_name'][$i], $file_path_name), LOG_ALERT, __FILE__, __LINE__);
    283                 $this->errors[] = $file_name;
     280                $this->errors[] = array('filename' => $file_name, 'errortype' => UPLOAD_USER_ERR_MOVE_FAILED);
    284281                continue;
    285282            }
     
    313310            App::logMsg(sprintf('Deleted file: %s', $file_path_name), LOG_INFO, __FILE__, __LINE__);
    314311        } else {
    315             $this->raiseMsg(sprintf(_("The file <strong>%s</strong> could not be deleted."), $file_name), MSG_ERR, __FILE__, __LINE__);
     312            $this->_raiseMsg(sprintf(_("The file <strong>%s</strong> could not be deleted."), $file_name), MSG_ERR, __FILE__, __LINE__);
    316313            App::logMsg(sprintf(_("Failed deleting file: %s"), $file_path_name), LOG_ERR, __FILE__, __LINE__);
    317314            return false;
     
    339336        if (file_exists($old_file_path_name)) {
    340337            if (rename($old_file_path_name, $new_file_path_name)) {
    341                 $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__);
     338                $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__);
    342339                App::logMsg(sprintf('File renamed from %s to %s', $old_file_path_name, $new_file_path_name), LOG_DEBUG, __FILE__, __LINE__);
    343340            } else {
    344                 $this->raiseMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), MSG_WARNING, __FILE__, __LINE__);
     341                $this->_raiseMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), MSG_WARNING, __FILE__, __LINE__);
    345342                App::logMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), LOG_WARNING, __FILE__, __LINE__);
    346343                return false;
    347344            }
    348345        } else {
    349             $this->raiseMsg(sprintf(_("Couldn't rename nonexistent file <strong>%s</strong>."), $old_name), MSG_WARNING, __FILE__, __LINE__);
     346            $this->_raiseMsg(sprintf(_("Couldn't rename nonexistent file <strong>%s</strong>."), $old_name), MSG_WARNING, __FILE__, __LINE__);
    350347            App::logMsg(sprintf(_("Error renaming nonexistent file: %s"), $old_file_path_name), LOG_WARNING, __FILE__, __LINE__);
    351348            return false;
     
    455452     * @param string $line    __LINE__.
    456453     */
    457     function raiseMsg($message, $type, $file, $line)
    458     {
    459         if ($this->getParam('display_messages') === true || (is_int($this->getParam('display_messages')) && $this->getParam('display_messages') >= $type)) {
     454    function _raiseMsg($message, $type, $file, $line)
     455    {
     456        if ($this->getParam('display_messages') === true || (is_int($this->getParam('display_messages')) && $this->getParam('display_messages') & $type > 0)) {
    460457            App::raiseMsg($message, $type, $file, $line);
    461458        }
  • trunk/services/templates/password.ihtml

    r22 r119  
    88        <td class="right"><label for="oldpassword"<?php $fv->err('oldpassword', ' class="error"') ?>><?php echo _("Old password"); ?></label></td>
    99        <td>
    10             <input type="text" class="medium" size="50" name="oldpassword" />
     10            <input type="password" class="medium" size="50" name="oldpassword" />
    1111        </td>
    1212    </tr>
Note: See TracChangeset for help on using the changeset viewer.