Changeset 20 for trunk/lib/App.inc.php
- Timestamp:
- Nov 17, 2005 3:00:00 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/App.inc.php
r19 r20 29 29 // Instance of database object. 30 30 var $db; 31 32 // Array of query arguments will be carried persistently between requests. 33 var $_carry_queries = array(); 31 34 32 35 // Hash of global application parameters. … … 47 50 'ssl_enabled' => false, 48 51 49 // Character set for page output. Set in the Content-Type header and anHTML <meta content-type> tag.52 // Character set for page output. Used in the Content-Type header and the HTML <meta content-type> tag. 50 53 'character_set' => 'utf-8', 51 54 … … 534 537 535 538 /** 539 * Sets which query arguments will be carried persistently between requests. 540 * Values in the _carry_queries array will be copied to URLs (via oHREF()) and 541 * to hidden input values (via printHiddenSession()). 542 * 543 * @access public 544 * @param string $query_key The key of the query argument to save. 545 * @author Quinn Comendant <quinn@strangecode.com> 546 * @since 14 Nov 2005 19:24:52 547 */ 548 function carryQuery($query_key) 549 { 550 if (!isset($this) || !is_a($this, 'App')) { 551 $this =& App::getInstance(); 552 } 553 554 // If not already set, and there is a non-empty value provided in the request... 555 if (!isset($this->_carry_queries[$query_key]) && getFormData($query_key, false)) { 556 // Copy the value of the specified query argument into the _carry_queries array. 557 $this->_carry_queries[$query_key] = getFormData($query_key); 558 } 559 } 560 561 /** 536 562 * Outputs a fully qualified URL with a query of all the used (ie: not empty) 537 563 * keys and values, including optional queries. This allows simple printing of 538 564 * links without needing to know which queries to add to it. If cookies are not 539 565 * used, the session id will be propogated in the URL. 540 *541 * @global string $carry_queries An array of keys to define which values to542 * carry through from the POST or GET.543 * $carry_queries = array('qry'); for example.544 566 * 545 567 * @param string $url The initial url … … 565 587 return false; 566 588 } 567 568 static $_using_trans_sid; 569 global $carry_queries; 570 571 // Save the trans_sid setting. 572 if (!isset($_using_trans_sid)) { 573 $_using_trans_sid = ini_get('session.use_trans_sid'); 574 } 575 576 // Initialize the carried queries. 577 if (!isset($carry_queries['_carry_queries_init'])) { 578 if (!is_array($carry_queries)) { 579 $carry_queries = array($carry_queries); 580 } 581 $tmp = $carry_queries; 582 $carry_queries = array(); 583 foreach ($tmp as $key) { 584 if (!empty($key) && getFormData($key, false)) { 585 $carry_queries[$key] = getFormData($key); 586 } 587 } 588 $carry_queries['_carry_queries_init'] = true; 589 } 590 591 // Get any additional query arguments to add to the $carry_queries array. 592 // If FALSE is a function argument, DO NOT carry the queries. 589 590 // Get any provided query arguments to include in the final URL. 591 // If FALSE is a provided here, DO NOT carry the queries. 593 592 $do_carry_queries = true; 594 593 $one_time_carry_queries = array(); … … 611 610 } 612 611 } 613 612 614 613 // Get the first delimiter that is needed in the url. 615 614 $delim = preg_match('/\?/', $url) ? ini_get('arg_separator.output') : '?'; … … 617 616 $q = ''; 618 617 if ($do_carry_queries) { 619 // Join the perm and temp carry_queries and filter out the _carry_queries_init element for the final query args.620 $query_args = array_diff_assoc(urlEncodeArray(array_merge($carry_queries, $one_time_carry_queries)), array('_carry_queries_init' => true));618 // Join the global _carry_queries and local one_time_carry_queries. 619 $query_args = urlEncodeArray(array_merge($this->_carry_queries, $one_time_carry_queries)); 621 620 foreach ($query_args as $key=>$val) { 622 621 // Check value is set and value does not already exist in the url. … … 648 647 && 649 648 ( 650 ! $_using_trans_sid649 !ini_get('session.use_trans_sid') 651 650 || preg_match('!^(http|https)://!i', $url) 652 651 ) … … 668 667 * as hidden form elements for GET_VARS that might be in use. 669 668 * 670 * @global string $carry_queries An array of keys to define which values to671 * carry through from the POST or GET.672 * $carry_queries = array('qry'); for example673 *674 669 * @param mixed $carry_args Additional url arguments to carry in the query, 675 670 * or FALSE to prevent carrying queries. Can be any of the following formats: … … 679 674 */ 680 675 function printHiddenSession($carry_args=null) 681 { 676 { 682 677 if (!isset($this) || !is_a($this, 'App')) { 683 678 $this =& App::getInstance(); … … 687 682 return false; 688 683 } 689 690 static $_using_trans_sid; 691 global $carry_queries; 692 693 // Save the trans_sid setting. 694 if (!isset($_using_trans_sid)) { 695 $_using_trans_sid = ini_get('session.use_trans_sid'); 696 } 697 698 // Initialize the carried queries. 699 if (!isset($carry_queries['_carry_queries_init'])) { 700 if (!is_array($carry_queries)) { 701 $carry_queries = array($carry_queries); 702 } 703 $tmp = $carry_queries; 704 $carry_queries = array(); 705 foreach ($tmp as $key) { 706 if (!empty($key) && getFormData($key, false)) { 707 $carry_queries[$key] = getFormData($key); 708 } 709 } 710 $carry_queries['_carry_queries_init'] = true; 711 } 712 713 // Get any additional query names to add to the $carry_queries array 714 // that are found as function arguments. 715 // If FALSE is a function argument, DO NOT carry the queries. 684 685 // Get any provided query arguments to include in the final hidden form data. 686 // If FALSE is a provided here, DO NOT carry the queries. 716 687 $do_carry_queries = true; 717 688 $one_time_carry_queries = array(); … … 737 708 // For each existing POST value, we create a hidden input to carry it through a form. 738 709 if ($do_carry_queries) { 739 // Join the perm and temp carry_queries and filter out the _carry_queries_init element for the final query args. 740 $query_args = array_diff_assoc(urlEncodeArray(array_merge($carry_queries, $one_time_carry_queries)), array('_carry_queries_init' => true)); 710 // Join the global _carry_queries and local one_time_carry_queries. 711 // urlencode is not used here, not for form data! 712 $query_args = array_merge($this->_carry_queries, $one_time_carry_queries); 741 713 foreach ($query_args as $key=>$val) { 742 714 echo '<input type="hidden" name="' . $key . '" value="' . $val . '" />'; … … 745 717 746 718 // Include the SID if cookies are disabled. 747 if (!isset($_COOKIE[session_name()]) && ! $_using_trans_sid) {719 if (!isset($_COOKIE[session_name()]) && !ini_get('session.use_trans_sid')) { 748 720 echo '<input type="hidden" name="' . session_name() . '" value="' . session_id() . '" />'; 749 721 }
Note: See TracChangeset
for help on using the changeset viewer.