Changeset 119
- Timestamp:
- May 20, 2006 2:12:12 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bin/module_maker/module.cli.php
r111 r119 442 442 443 443 if ('var' == $op) { 444 if (isset($ replace[$_SERVER['argv'][5]])) {444 if (isset($_SERVER['argv'][5]) && isset($replace[$_SERVER['argv'][5]])) { 445 445 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]])) { 447 447 echo "\n\n" . preg_replace($search, $replace, $skel_files[$_SERVER['argv'][5]]) . "\n\n"; 448 448 } 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"); 450 450 } 451 451 die; … … 549 549 // Make user trash folder. 550 550 if (!is_dir($user_trash_folder)) { 551 echo "Attempting to create user trash folder: $user_trash_folder/\n"; 551 552 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); 554 554 } 555 555 if (!is_dir("$user_trash_folder/") || !is_writable("$user_trash_folder/")) { -
trunk/lib/App.inc.php
r108 r119 16 16 define('MSG_NOTICE', 4); 17 17 define('MSG_SUCCESS', 8); 18 define('MSG_ALL', MSG_SUCCESS | MSG_NOTICE | MSG_WARNING | MSG_ERROR); 18 19 19 20 require_once dirname(__FILE__) . '/Utilities.inc.php'; … … 163 164 function setParam($param=null) 164 165 { 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(); 167 168 } 168 169 169 170 if (isset($param) && is_array($param)) { 170 171 // 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); 172 173 } 173 174 } … … 182 183 function &getParam($param=null) 183 184 { 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(); 186 187 } 187 188 188 189 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]; 192 193 } else { 193 194 trigger_error(sprintf('Parameter is not set: %s', $param), E_USER_NOTICE); … … 359 360 function raiseMsg($message, $type=MSG_NOTICE, $file=null, $line=null) 360 361 { 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(); 363 364 } 364 365 365 366 $message = trim($message); 366 367 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__); 369 370 return false; 370 371 } … … 372 373 // Save message in session under unique key to avoid duplicate messages. 373 374 $msg_id = md5($type . $message . $file . $line); 374 $_SESSION[$ this->app]['messages'][$msg_id] = array(375 $_SESSION[$_this->app]['messages'][$msg_id] = array( 375 376 'type' => $type, 376 377 'message' => $message, 377 378 'file' => $file, 378 379 '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) 380 381 ); 381 382 382 383 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__); 384 385 } 385 386 } … … 395 396 function getRaisedMessages() 396 397 { 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__); 403 404 return false; 404 405 } 405 406 406 407 $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'])) { 408 409 $output[] = $message; 409 410 } … … 420 421 function clearRaisedMessages() 421 422 { 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__); 428 429 return false; 429 430 } 430 431 431 $_SESSION[$ this->app]['messages'] = array();432 $_SESSION[$_this->app]['messages'] = array(); 432 433 } 433 434 … … 441 442 function printRaisedMessages() 442 443 { 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'])) { 453 454 ?><div class="sc-msg"><?php 454 if (error_reporting() > 0 && $ this->getParam('display_errors')) {455 if (error_reporting() > 0 && $_this->getParam('display_errors')) { 455 456 echo "\n<!-- [" . $message['file'] . ' : ' . $message['line'] . '] -->'; 456 457 } … … 500 501 static $previous_events = array(); 501 502 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(); 504 505 } 505 506 506 507 // 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); 509 510 $priority = LOG_EMERG; 510 511 } 511 512 512 513 // 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)); 515 516 // 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); 517 518 } 518 519 … … 530 531 $previous_events[$msg_id]++; 531 532 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); 533 534 } 534 535 return false; … … 542 543 'remote ip' => getRemoteAddr(), 543 544 'pid' => (substr(PHP_OS, 0, 3) != 'WIN' ? posix_getpid() : ''), 544 'type' => $ this->logPriorityToString($priority),545 'type' => $_this->logPriorityToString($priority), 545 546 'file:line' => "$file : $line", 546 547 'url' => (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''), … … 549 550 550 551 // 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')) { 552 553 $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')); 554 555 } 555 556 556 557 // 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')) { 558 559 $subject = sprintf('[%s %s] %s', getenv('HTTP_HOST'), $event['type'], $message); 559 560 $email_msg = sprintf("A %s log event occured on %s\n\n", $event['type'], getenv('HTTP_HOST')); … … 562 563 $email_msg .= sprintf("%-11s%s\n", $k, $v); 563 564 } 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'); 565 566 } 566 567 567 568 // 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')) { 569 570 $subject = sprintf('[%s %s]', getenv('HTTP_HOST'), $priority); 570 571 $sms_msg = sprintf('%s [%s:%s]', $event['message'], basename($file), $line); 571 572 $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'); 573 574 } 574 575 575 576 // 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')) { 577 578 echo "[{$event['date']}] [{$event['type']}] [{$event['file:line']}] [{$event['message']}]\n"; 578 579 } … … 619 620 function carryQuery($query_key) 620 621 { 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(); 623 624 } 624 625 625 626 // 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)) { 627 628 // 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); 629 630 } 630 631 } … … 651 652 function url($url, $carry_args=null, $always_include_sid=false) 652 653 { 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__); 659 660 return false; 660 661 } … … 690 691 if ($do_carry_queries) { 691 692 // 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)); 693 694 foreach ($query_args as $key=>$val) { 694 695 // Check value is set and value does not already exist in the url. … … 714 715 ( 715 716 !isset($_COOKIE[session_name()]) 716 || !$ this->getParam('session_use_cookies')717 || !$_this->getParam('session_use_cookies') 717 718 ) 718 && $ this->getParam('enable_session')719 && $_this->getParam('enable_session') 719 720 && isMyDomain($url) 720 721 && … … 747 748 function oHREF($url, $carry_args=null, $always_include_sid=false) 748 749 { 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); 754 755 755 756 // Replace any & not followed by an html or unicode entity with it's & equivalent. … … 771 772 function printHiddenSession($carry_args=null) 772 773 { 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__); 779 780 return false; 780 781 } … … 807 808 // Join the global _carry_queries and local one_time_carry_queries. 808 809 // 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); 810 811 foreach ($query_args as $key=>$val) { 811 812 echo '<input type="hidden" name="' . $key . '" value="' . $val . '" />'; … … 834 835 function dieURL($url, $carry_args=null, $always_include_sid=false) 835 836 { 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__); 842 843 return false; 843 844 } … … 845 846 if ('' == $url) { 846 847 // If URL is not specified, use the redirect_home_url. 847 $url = $ this->getParam('redirect_home_url');848 $url = $_this->getParam('redirect_home_url'); 848 849 } 849 850 … … 855 856 } 856 857 857 $url = $ this->url($url, $carry_args, $always_include_sid);858 $url = $_this->url($url, $carry_args, $always_include_sid); 858 859 859 860 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__); 861 862 862 863 // End this application. 863 864 // Recommended, although I'm not sure it's necessary: http://cn2.php.net/session_write_close 864 $ this->stop();865 $_this->stop(); 865 866 die; 866 867 } … … 883 884 function dieBoomerangURL($id=null, $carry_args=null, $default_url=null) 884 885 { 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__); 891 892 return false; 892 893 } 893 894 894 895 // 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__); 899 900 } 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__); 902 903 } 903 904 // Delete stored boomerang. 904 $ this->deleteBoomerangURL($id);905 $_this->deleteBoomerangURL($id); 905 906 } else if (isset($default_url)) { 906 907 $url = $default_url; … … 908 909 // Ensure that the redirecting page is not also the referrer. 909 910 $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__); 911 912 } else { 912 913 // 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__); 915 916 } 916 917 917 918 // A redirection will never happen immediately twice. 918 919 // 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); 921 922 } 922 923 … … 930 931 function setBoomerangURL($url=null, $id=null) 931 932 { 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__); 938 939 return false; 939 940 } … … 945 946 $url = preg_replace('/boomerang=[\w]+/', '', $url); 946 947 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'])) { 948 949 // 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]); 951 952 } 952 953 } 953 954 954 955 if (isset($id)) { 955 $_SESSION[$ this->app]['boomerang']['url'][$id] = $url;956 $_SESSION[$_this->app]['boomerang']['url'][$id] = $url; 956 957 } 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__); 960 961 return true; 961 962 } 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__); 963 964 return false; 964 965 } … … 972 973 function getBoomerangURL($id=null) 973 974 { 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__); 980 981 return false; 981 982 } 982 983 983 984 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]; 986 987 } else { 987 988 return ''; 988 989 } 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']); 991 992 } else { 992 993 return false; … … 1001 1002 function deleteBoomerangURL($id=null) 1002 1003 { 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']); 1018 1019 } 1019 1020 } … … 1027 1028 function validBoomerangURL($id=null, $use_nonspecificboomerang=false) 1028 1029 { 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__); 1040 1041 return false; 1041 1042 } … … 1044 1045 // a boomerang redirection will always occur at least several seconds after the last boomerang redirect 1045 1046 // 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; 1047 1048 1048 1049 $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]; 1051 1052 } else if (!isset($id) || $use_nonspecificboomerang) { 1052 1053 // 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__); 1057 1058 1058 1059 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__); 1060 1061 return false; 1061 1062 } 1062 1063 if ($url == absoluteMe()) { 1063 1064 // 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__); 1065 1066 return false; 1066 1067 } 1067 1068 if ($boomerang_time >= (time() - 2)) { 1068 1069 // 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__); 1074 1075 return true; 1075 1076 } … … 1081 1082 function sslOn() 1082 1083 { 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(); 1085 1086 } 1086 1087 … … 1092 1093 } 1093 1094 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__); 1096 1097 // 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); 1098 1099 } 1099 1100 } -
trunk/lib/Auth_SQL.inc.php
r111 r119 720 720 WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "' 721 721 "); 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 } 722 726 } 723 727 -
trunk/lib/DB.inc.php
r71 r119 85 85 function setParam($params) 86 86 { 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(); 89 89 } 90 90 91 91 if (isset($params) && is_array($params)) { 92 92 // 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); 94 94 } else { 95 95 App::logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__); … … 108 108 function getParam($param) 109 109 { 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]; 116 116 } else { 117 117 App::logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__); … … 129 129 function connect() 130 130 { 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')) { 136 136 App::logMsg('Database credentials missing.', LOG_EMERG, __FILE__, __LINE__); 137 137 return false; … … 139 139 140 140 // 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)) { 142 142 // Select database 143 mysql_select_db($ this->getParam('db_name'), $this->dbh);143 mysql_select_db($_this->getParam('db_name'), $_this->dbh); 144 144 } 145 145 146 146 // 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.'; 149 149 App::logMsg($mysql_error_msg, LOG_EMERG, __FILE__, __LINE__); 150 150 151 151 // Print helpful or pretty error? 152 if ($ this->getParam('db_debug')) {152 if ($_this->getParam('db_debug')) { 153 153 echo $mysql_error_msg . "\n"; 154 154 } else { … … 157 157 158 158 // Die or continue without connection? 159 if ($ this->getParam('db_die_on_failure')) {159 if ($_this->getParam('db_die_on_failure')) { 160 160 echo "\n\n<!-- Script execution stopped out of embarrassment. -->"; 161 161 die; … … 166 166 167 167 // DB connection success! 168 $ this->_connected = true;168 $_this->_connected = true; 169 169 170 170 // 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'))] . "' */"); 172 172 173 173 return true; … … 183 183 function close() 184 184 { 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); 194 194 } 195 195 … … 204 204 function getDBH() 205 205 { 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; 215 215 } 216 216 … … 238 238 function escapeString($string) 239 239 { 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); 244 244 } 245 245 … … 256 256 static $_query_count = 0; 257 257 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) { 263 263 return false; 264 264 } … … 266 266 $_query_count++; 267 267 $debugqry = preg_replace("/\n[\t ]+/", "\n", $query); 268 if ($ this->getParam('db_always_debug') || $debug) {268 if ($_this->getParam('db_always_debug') || $debug) { 269 269 echo "<!-- ----------------- Query $_query_count ---------------------\n$debugqry\n-->\n"; 270 270 } 271 271 272 272 // Execute! 273 $qid = mysql_query($query, $ this->dbh);273 $qid = mysql_query($query, $_this->dbh); 274 274 275 275 // 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>'; 279 279 } else { 280 280 echo _("This page is temporarily unavailable. It should be back up in a few minutes."); 281 281 } 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')) { 284 284 echo "\n\n<!-- Script execution stopped out of embarrassment. -->"; 285 285 die; … … 302 302 function tableExists($table, $use_cached_results=true) 303 303 { 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"); 315 315 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)) { 320 320 return true; 321 321 } 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__); 323 323 return false; 324 324 } … … 336 336 function columnExists($table, $columns, $strict=true, $use_cached_results=true) 337 337 { 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) { 343 343 return false; 344 344 } 345 345 346 346 // Ensure the table exists. 347 if (!$ this->tableExists($table, $use_cached_results)) {347 if (!$_this->tableExists($table, $use_cached_results)) { 348 348 return false; 349 349 } … … 354 354 } 355 355 356 if (!isset($ this->table_columns[$table]) || !$use_cached_results) {356 if (!isset($_this->table_columns[$table]) || !$use_cached_results) { 357 357 // 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"); 360 360 while ($row = mysql_fetch_row($qid)) { 361 $ this->table_columns[$table][] = $row[0];361 $_this->table_columns[$table][] = $row[0]; 362 362 } 363 363 } … … 366 366 // Do an exact comparison of table schemas. 367 367 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; 370 370 } else { 371 371 // 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); 373 373 sort($columns); 374 374 sort($match_columns); -
trunk/lib/Email.inc.php
r114 r119 281 281 if (mail($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header)) { 282 282 App::logMsg(sprintf('Email successfully sent to %s', $final_to), LOG_DEBUG, __FILE__, __LINE__); 283 return true 283 return true; 284 284 } else { 285 285 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 417 417 418 418 // 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) { 420 421 $this->addError($form_name, sprintf(_("<strong>%s</strong> is not a valid email domain name"), oTxt($domain))); 421 422 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 3 3 * ImageThumb.inc.php 4 4 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information 5 */6 7 /**8 * The ImageThumb class resizes images.9 5 * 10 6 * @author Quinn Comendant <quinn@strangecode.com> 11 * @requires Netpbm binaries from http://sourceforge.net/projects/netpbm/12 * @version 1.17 * @requires Netpbm <http://sourceforge.net/projects/netpbm/> and libjpeg or GD. 8 * @version 2.0 13 9 */ 14 10 11 // Image resize options. 15 12 define('IMAGETHUMB_FIT_WIDTH', 1); 16 13 define('IMAGETHUMB_FIT_HEIGHT', 2); … … 18 15 define('IMAGETHUMB_STRETCH', 4); 19 16 define('IMAGETHUMB_NO_SCALE', 5); 17 define('IMAGETHUMB_METHOD_NETPBM', 6); 18 define('IMAGETHUMB_METHOD_GD', 7); 20 19 21 20 class 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 74 194 * @return bool true on success, false on failure. 75 195 */ 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() 172 197 { 173 198 // 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 } 190 224 } 191 225 … … 199 233 function processFile($file_name) 200 234 { 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 206 238 // 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')) { 208 246 App::logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__); 209 247 return false; 210 248 } 211 249 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 212 281 // To keep this script running even if user tries to stop browser. 213 282 ignore_user_abort(true); … … 216 285 } 217 286 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 249 287 // 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__); 259 300 continue; 260 301 } 261 302 } 262 303 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); 268 320 } 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; 291 430 } 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; 332 512 } 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; 335 516 } 336 517 } … … 346 527 { 347 528 // Ensure we have a source. 348 if ( !isset($this->source_dir)) {529 if ('' == $this->getParam('source_dir')) { 349 530 App::logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__); 350 531 return false; 351 532 } 352 533 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__); 360 541 } 361 542 } 362 543 } 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; 365 546 } 366 547 … … 375 556 { 376 557 // Ensure we have a source. 377 if ( !isset($this->source_dir)) {558 if ('' == $this->getParam('source_dir')) { 378 559 App::logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__); 379 560 return false; 380 561 } 381 562 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__); 388 569 return true; 389 570 } … … 399 580 { 400 581 // Ensure we have a source. 401 if ( !isset($this->source_dir)) {582 if ('' == $this->getParam('source_dir')) { 402 583 App::logMsg(sprintf('Source directory not set before processing.'), LOG_ERR, __FILE__, __LINE__); 403 584 return false; 404 585 } 405 586 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); 407 589 } 408 590 … … 414 596 * @return bool True on success, false on failure. 415 597 */ 416 function validFileExtension($file_name)598 function _validFileExtension($file_name) 417 599 { 418 600 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. 424 641 * 425 642 * @access public … … 431 648 * @param string $line __LINE__. 432 649 */ 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)) { 436 653 App::raiseMsg($message, $type, $file, $line); 437 654 } -
trunk/lib/SessionCache.inc.php
r53 r119 44 44 function setParam($params) 45 45 { 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(); 48 48 } 49 49 50 50 if (isset($params) && is_array($params)) { 51 51 // 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); 53 53 } else { 54 54 App::logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__); … … 65 65 function getParam($param) 66 66 { 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]; 73 73 } else { 74 74 App::logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__); … … 95 95 function putCache($var, $var_id, $force_it_in=false) 96 96 { 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')) { 102 102 App::logMsg(sprintf('SessionCache not enabled, not saving data.', null), LOG_DEBUG, __FILE__, __LINE__); 103 103 return false; … … 108 108 $serialized_var_len = strlen($serialized_var); 109 109 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__); 117 117 return false; 118 118 } … … 123 123 unset($_SESSION['_session_cache'][$var_id]); 124 124 // 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')) { 127 127 array_shift($_SESSION['_session_cache']); 128 128 } … … 149 149 function getCache($var_id) 150 150 { 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')) { 156 156 return false; 157 157 } … … 179 179 function isCached($var_id) 180 180 { 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')) { 186 186 return false; 187 187 } -
trunk/lib/SortOrder.inc.php
r111 r119 3 3 * SortOrder.inc.php 4 4 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information 5 */ 6 7 /** 5 * 8 6 * SortOrder can determing how to sort results of a database query for display 9 7 * on a listing. It can print column headers that will be links to 10 8 * automatically change the sort and order. 11 9 * 12 * @requires This class requires App.inc.php13 * @requires This class requires Utilities.inc.php14 10 * @requires This class requires Prefs.inc.php 15 11 * 16 12 * @author Quinn Comendant <quinn@strangecode.com> 17 * @version 1.6. 113 * @version 1.6.2 18 14 */ 19 require_once dirname(__FILE__) . '/App.inc.php';20 require_once dirname(__FILE__) . '/Utilities.inc.php';21 15 require_once dirname(__FILE__) . '/Prefs.inc.php'; 22 16 -
trunk/lib/Upload.inc.php
r118 r119 8 8 * @author Quinn Comendant <quinn@strangecode.com> 9 9 * @requires App.inc.php 10 * @version 1. 310 * @version 1.4 11 11 */ 12 12 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. 14 define('UPLOAD_USER_ERR_EMPTY_FILE', 100); 15 define('UPLOAD_USER_ERR_NOT_UPLOADED_FILE', 101); 16 define('UPLOAD_USER_ERR_INVALID_EXTENSION', 102); 17 define('UPLOAD_USER_ERR_NOT_UNIQUE', 103); 18 define('UPLOAD_USER_ERR_MOVE_FAILED', 104); 22 19 23 20 class Upload { … … 27 24 28 25 // Which messages do we pass to raiseMsg? 29 'display_messages' => UPLOAD_MSG_ALL,26 'display_messages' => MSG_ALL, 30 27 31 28 // Existing files will be overwritten when there is a name conflict? … … 116 113 if (!$this->getParam('upload_path')) { 117 114 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__); 119 116 return false; 120 117 } … … 123 120 if (!isset($_FILES[$form_name])) { 124 121 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__); 126 123 return false; 127 124 } … … 162 159 // Valid custom file name. 163 160 $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__); 165 162 App::logMsg(sprintf('Using custom file name: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__); 166 163 } else { … … 174 171 // Valid custom file name. 175 172 $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__); 177 174 App::logMsg(sprintf('Using custom file name: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__); 178 175 } else { … … 200 197 if (UPLOAD_ERR_INI_SIZE === $files['error'][$i]) { 201 198 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__); 203 200 } 204 201 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); 206 203 continue; 207 204 } 208 205 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__); 210 207 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); 212 209 continue; 213 210 } 214 211 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__); 216 213 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); 218 215 continue; 219 216 } 220 217 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__); 222 219 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); 224 221 continue; 225 222 } 226 223 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__); 228 225 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); 230 227 continue; 231 228 } … … 233 230 // Check to be sure it's an uploaded file. 234 231 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__); 236 233 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); 238 235 continue; 239 236 } 240 237 241 238 // 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__); 244 241 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); 246 243 continue; 247 244 } … … 249 246 // Check to be sure the file has a valid file name extension. 250 247 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__); 252 249 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); 254 251 continue; 255 252 } … … 257 254 // Check to be sure the file has a unique file name. 258 255 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__); 260 257 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); 262 259 continue; 263 260 } … … 267 264 chmod($file_path_name, $this->getParam('dest_file_perms')); 268 265 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__); 270 267 if (!isset($custom_file_name) && $files['name'][$i] != $file_name) { 271 268 // 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__); 273 270 } 274 271 $new_file_names[] = array( … … 279 276 continue; 280 277 } 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__); 282 279 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); 284 281 continue; 285 282 } … … 313 310 App::logMsg(sprintf('Deleted file: %s', $file_path_name), LOG_INFO, __FILE__, __LINE__); 314 311 } 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__); 316 313 App::logMsg(sprintf(_("Failed deleting file: %s"), $file_path_name), LOG_ERR, __FILE__, __LINE__); 317 314 return false; … … 339 336 if (file_exists($old_file_path_name)) { 340 337 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__); 342 339 App::logMsg(sprintf('File renamed from %s to %s', $old_file_path_name, $new_file_path_name), LOG_DEBUG, __FILE__, __LINE__); 343 340 } 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__); 345 342 App::logMsg(sprintf(_("Error renaming file to %s"), $new_file_path_name), LOG_WARNING, __FILE__, __LINE__); 346 343 return false; 347 344 } 348 345 } 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__); 350 347 App::logMsg(sprintf(_("Error renaming nonexistent file: %s"), $old_file_path_name), LOG_WARNING, __FILE__, __LINE__); 351 348 return false; … … 455 452 * @param string $line __LINE__. 456 453 */ 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)) { 460 457 App::raiseMsg($message, $type, $file, $line); 461 458 } -
trunk/services/templates/password.ihtml
r22 r119 8 8 <td class="right"><label for="oldpassword"<?php $fv->err('oldpassword', ' class="error"') ?>><?php echo _("Old password"); ?></label></td> 9 9 <td> 10 <input type=" text" class="medium" size="50" name="oldpassword" />10 <input type="password" class="medium" size="50" name="oldpassword" /> 11 11 </td> 12 12 </tr>
Note: See TracChangeset
for help on using the changeset viewer.