comparison includes/common.inc @ 15:4347c45bb494 6.7

Drupal 6.7
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:32:44 +0100
parents 8b6c45761e01
children 8e6257f3ae39
comparison
equal deleted inserted replaced
14:626fcabfa4b8 15:4347c45bb494
1 <?php 1 <?php
2 // $Id: common.inc,v 1.756.2.29 2008/10/22 19:26:01 goba Exp $ 2 // $Id: common.inc,v 1.756.2.35 2008/12/10 22:30:13 goba Exp $
3 3
4 /** 4 /**
5 * @file 5 * @file
6 * Common functions that many Drupal modules will need to reference. 6 * Common functions that many Drupal modules will need to reference.
7 * 7 *
497 } 497 }
498 498
499 $request = $method .' '. $path ." HTTP/1.0\r\n"; 499 $request = $method .' '. $path ." HTTP/1.0\r\n";
500 $request .= implode("\r\n", $defaults); 500 $request .= implode("\r\n", $defaults);
501 $request .= "\r\n\r\n"; 501 $request .= "\r\n\r\n";
502 if ($data) { 502 $request .= $data;
503 $request .= $data ."\r\n"; 503
504 }
505 $result->request = $request; 504 $result->request = $request;
506 505
507 fwrite($fp, $request); 506 fwrite($fp, $request);
508 507
509 // Fetch response. 508 // Fetch response.
663 } 662 }
664 663
665 /** 664 /**
666 * Translate strings to the page language or a given language. 665 * Translate strings to the page language or a given language.
667 * 666 *
668 * All human-readable text that will be displayed somewhere within a page should 667 * Human-readable text that will be displayed somewhere within a page should
669 * be run through the t() function. 668 * be run through the t() function.
670 * 669 *
671 * Examples: 670 * Examples:
672 * @code 671 * @code
673 * if (!$info || !$info['extension']) { 672 * if (!$info || !$info['extension']) {
730 * Here is an example of t() used correctly: 729 * Here is an example of t() used correctly:
731 * @code 730 * @code
732 * $output .= '<p>'. t('Go to the <a href="@contact-page">contact page</a>.', array('@contact-page' => url('contact'))) .'</p>'; 731 * $output .= '<p>'. t('Go to the <a href="@contact-page">contact page</a>.', array('@contact-page' => url('contact'))) .'</p>';
733 * @endcode 732 * @endcode
734 * 733 *
735 * Also avoid escaping quotation marks wherever possible. 734 * Avoid escaping quotation marks wherever possible.
736 * 735 *
737 * Incorrect: 736 * Incorrect:
738 * @code 737 * @code
739 * $output .= t('Don\'t click me.'); 738 * $output .= t('Don\'t click me.');
740 * @endcode 739 * @endcode
741 * 740 *
742 * Correct: 741 * Correct:
743 * @code 742 * @code
744 * $output .= t("Don't click me."); 743 * $output .= t("Don't click me.");
745 * @endcode 744 * @endcode
745 *
746 * Because t() is designed for handling code-based strings, in almost all
747 * cases, the actual string and not a variable must be passed through t().
748 *
749 * Extraction of translations is done based on the strings contained in t()
750 * calls. If a variable is passed through t(), the content of the variable
751 * cannot be extracted from the file for translation.
752 *
753 * Incorrect:
754 * @code
755 * $message = 'An error occurred.';
756 * drupal_set_message(t($message), 'error');
757 * $output .= t($message);
758 * @endcode
759 *
760 * Correct:
761 * @code
762 * $message = t('An error occurred.');
763 * drupal_set_message($message, 'error');
764 * $output .= $message;
765 * @endcode
766 *
767 * The only case in which variables can be passed safely through t() is when
768 * code-based versions of the same strings will be passed through t() (or
769 * otherwise extracted) elsewhere.
770 *
771 * In some cases, modules may include strings in code that can't use t()
772 * calls. For example, a module may use an external PHP application that
773 * produces strings that are loaded into variables in Drupal for output.
774 * In these cases, module authors may include a dummy file that passes the
775 * relevant strings through t(). This approach will allow the strings to be
776 * extracted.
777 *
778 * Sample external (non-Drupal) code:
779 * @code
780 * class Time {
781 * public $yesterday = 'Yesterday';
782 * public $today = 'Today';
783 * public $tomorrow = 'Tomorrow';
784 * }
785 * @endcode
786 *
787 * Sample dummy file.
788 * @code
789 * // Dummy function included in example.potx.inc.
790 * function example_potx() {
791 * $strings = array(
792 * t('Yesterday'),
793 * t('Today'),
794 * t('Tomorrow'),
795 * );
796 * // No return value needed, since this is a dummy function.
797 * }
798 * @endcode
799 *
800 * Having passed strings through t() in a dummy function, it is then
801 * okay to pass variables through t().
802 *
803 * Correct (if a dummy file was used):
804 * @code
805 * $time = new Time();
806 * $output .= t($time->today);
807 * @endcode
808 *
809 * However tempting it is, custom data from user input or other non-code
810 * sources should not be passed through t(). Doing so leads to the following
811 * problems and errors:
812 * - The t() system doesn't support updates to existing strings. When user
813 * data is updated, the next time it's passed through t() a new record is
814 * created instead of an update. The database bloats over time and any
815 * existing translations are orphaned with each update.
816 * - The t() system assumes any data it receives is in English. User data may
817 * be in another language, producing translation errors.
818 * - The "Built-in interface" text group in the locale system is used to
819 * produce translations for storage in .po files. When non-code strings are
820 * passed through t(), they are added to this text group, which is rendered
821 * inaccurate since it is a mix of actual interface strings and various user
822 * input strings of uncertain origin.
823 *
824 * Incorrect:
825 * @code
826 * $item = item_load();
827 * $output .= check_plain(t($item['title']));
828 * @endcode
829 *
830 * Instead, translation of these data can be done through the locale system,
831 * either directly or through helper functions provided by contributed
832 * modules.
833 * @see hook_locale()
834 *
835 * During installation, st() is used in place of t(). Code that may be called
836 * during installation or during normal operation should use the get_t()
837 * helper function.
838 * @see st()
839 * @see get_t()
746 * 840 *
747 * @param $string 841 * @param $string
748 * A string containing the English string to translate. 842 * A string containing the English string to translate.
749 * @param $args 843 * @param $args
750 * An associative array of replacements to make after translation. Incidences 844 * An associative array of replacements to make after translation. Incidences
1818 // Prefix with base and remove '../' segments where possible. 1912 // Prefix with base and remove '../' segments where possible.
1819 $path = $_base . $matches[1]; 1913 $path = $_base . $matches[1];
1820 $last = ''; 1914 $last = '';
1821 while ($path != $last) { 1915 while ($path != $last) {
1822 $last = $path; 1916 $last = $path;
1823 $path = preg_replace('`(^|/)(?!../)([^/]+)/../`', '$1', $path); 1917 $path = preg_replace('`(^|/)(?!\.\./)([^/]+)/\.\./`', '$1', $path);
1824 } 1918 }
1825 return 'url('. $path .')'; 1919 return 'url('. $path .')';
1826 } 1920 }
1827 1921
1828 /** 1922 /**
3535 // Change query-strings on css/js files to enforce reload for all users. 3629 // Change query-strings on css/js files to enforce reload for all users.
3536 _drupal_flush_css_js(); 3630 _drupal_flush_css_js();
3537 3631
3538 drupal_clear_css_cache(); 3632 drupal_clear_css_cache();
3539 drupal_clear_js_cache(); 3633 drupal_clear_js_cache();
3540 system_theme_data(); 3634
3635 // If invoked from update.php, we must not update the theme information in the
3636 // database, or this will result in all themes being disabled.
3637 if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {
3638 _system_theme_data();
3639 }
3640 else {
3641 system_theme_data();
3642 }
3643
3541 drupal_rebuild_theme_registry(); 3644 drupal_rebuild_theme_registry();
3542 menu_rebuild(); 3645 menu_rebuild();
3543 node_types_rebuild(); 3646 node_types_rebuild();
3544 // Don't clear cache_form - in-progress form submissions may break. 3647 // Don't clear cache_form - in-progress form submissions may break.
3545 // Ordered so clearing the page cache will always be the last action. 3648 // Ordered so clearing the page cache will always be the last action.