Source Code Documentation


s2member\includes\classes\labels.inc.php


  1. <?php
  2. /**
  3. * Membership Level Labels.
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * Released under the terms of the GNU General Public License.
  10. * You should have received a copy of the GNU General Public License,
  11. * along with this software. In the main directory, see: /licensing/
  12. * If not, see: {@link http://www.gnu.org/licenses/}.
  13. *
  14. * @package s2Member\Roles_Caps
  15. * @since 3.5
  16. */
  17. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  18. exit ("Do not access this file directly.");
  19.  
  20. if (!class_exists ("c_ws_plugin__s2member_labels"))
  21. {
  22. /**
  23. * Membership Level Labels.
  24. *
  25. * @package s2Member\Roles_Caps
  26. * @since 3.5
  27. */
  28. class c_ws_plugin__s2member_labels
  29. {
  30. /**
  31. * Configures Label translations.
  32. *
  33. * @package s2Member\Roles_Caps
  34. * @since 3.5
  35. *
  36. * @attaches-to ``add_action("init");``
  37. *
  38. * @return null
  39. */
  40. public static function config_label_translations ()
  41. {
  42. do_action ("ws_plugin__s2member_before_config_label_translations", get_defined_vars ());
  43.  
  44. if ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["apply_label_translations"])
  45. add_filter ("gettext_with_context", "c_ws_plugin__s2member_labels::_label_translations", 10, 3);
  46.  
  47. do_action ("ws_plugin__s2member_after_config_label_translations", get_defined_vars ());
  48.  
  49. return /* Return for uniformity. */;
  50. }
  51. /**
  52. * A sort of callback function that deals with Label translations.
  53. *
  54. * @package s2Member\Roles_Caps
  55. * @since 3.5
  56. *
  57. * @attaches-to ``add_filter("gettext_with_context");``
  58. *
  59. * @param str $translation Expects a string; already translated.
  60. * @param str $original The original text, passed in by the Filter.
  61. * @param str $context Contextual specification for this translation.
  62. * @return str The ``$translation``, after translations applied by this routine.
  63. */
  64. public static function _label_translations ($translation = FALSE, $original = FALSE, $context = FALSE)
  65. {
  66. if ($original && $context && stripos ($context, "User role") === 0 && ($role = $original))
  67. {
  68. if (preg_match ("/^(Free )?Subscriber$/i", $role) && !empty ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level0_label"]))
  69. $translation = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level0_label"];
  70.  
  71. else if (preg_match ("/^s2Member Level ([0-9]+)$/i", $role, $m) && !empty ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $m[1] . "_label"]))
  72. $translation = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $m[1] . "_label"];
  73.  
  74. $translation = apply_filters ("_ws_plugin__s2member_label_translations", $translation, get_defined_vars ());
  75. }
  76.  
  77. return /* Return translation. */ $translation;
  78. }
  79. }
  80. }
  81. ?>

s2member\includes\classes\labels.inc.php

Source Code Documentation