wpml.class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. /**
  3. * @author ThemePunch <info@themepunch.com>
  4. * @link http://www.themepunch.com/
  5. * @copyright 2015 ThemePunch
  6. */
  7. if( !defined( 'ABSPATH') ) exit();
  8. class RevSliderWpml{
  9. /**
  10. *
  11. * true / false if the wpml plugin exists
  12. */
  13. public static function isWpmlExists(){
  14. return did_action( 'wpml_loaded' );
  15. }
  16. /**
  17. *
  18. * valdiate that wpml exists
  19. */
  20. private static function validateWpmlExists(){
  21. if(!self::isWpmlExists())
  22. RevSliderFunctions::throwError("The wpml plugin is not activated");
  23. }
  24. /**
  25. *
  26. * get languages array
  27. */
  28. public static function getArrLanguages($getAllCode = true){
  29. self::validateWpmlExists();
  30. $arrLangs = apply_filters( 'wpml_active_languages', array() );
  31. $response = array();
  32. if($getAllCode == true)
  33. $response["all"] = __("All Languages",'revslider');
  34. foreach($arrLangs as $code=>$arrLang){
  35. $name = $arrLang["native_name"];
  36. $response[$code] = $name;
  37. }
  38. return($response);
  39. }
  40. /**
  41. *
  42. * get assoc array of lang codes
  43. */
  44. public static function getArrLangCodes($getAllCode = true){
  45. $arrCodes = array();
  46. if($getAllCode == true)
  47. $arrCodes["all"] = "all";
  48. self::validateWpmlExists();
  49. $arrLangs = apply_filters( 'wpml_active_languages', array() );
  50. foreach($arrLangs as $code=>$arr){
  51. $arrCodes[$code] = $code;
  52. }
  53. return($arrCodes);
  54. }
  55. /**
  56. *
  57. * check if all languages exists in the given langs array
  58. */
  59. public static function isAllLangsInArray($arrCodes){
  60. $arrAllCodes = self::getArrLangCodes();
  61. $diff = array_diff($arrAllCodes, $arrCodes);
  62. return(empty($diff));
  63. }
  64. /**
  65. *
  66. * get langs with flags menu list
  67. * @param $props
  68. */
  69. public static function getLangsWithFlagsHtmlList($props = "",$htmlBefore = ""){
  70. $arrLangs = self::getArrLanguages();
  71. if(!empty($props))
  72. $props = " ".$props;
  73. $html = "<ul".$props.">"."\n";
  74. $html .= $htmlBefore;
  75. foreach($arrLangs as $code=>$title){
  76. $urlIcon = self::getFlagUrl($code);
  77. /* NEW:
  78. foreach($arrLangs as $lang){
  79. $code = $lang['language_code'];
  80. $title = $lang['native_name'];
  81. $urlIcon = $lang['country_flag_url'];
  82. */
  83. $html .= "<li data-lang='".$code."' class='item_lang'><a data-lang='".$code."' href='javascript:void(0)'>"."\n";
  84. $html .= "<img src='".$urlIcon."'/> $title"."\n";
  85. $html .= "</a></li>"."\n";
  86. }
  87. $html .= "</ul>";
  88. return($html);
  89. }
  90. /**
  91. * get flag url
  92. */
  93. public static function getFlagUrl($code){
  94. self::validateWpmlExists();
  95. if ( empty( $code ) || $code == "all" ) {
  96. $url = RS_PLUGIN_URL.'admin/assets/images/icon-all.png'; // NEW: ICL_PLUGIN_URL . '/res/img/icon16.png';
  97. } else {
  98. $active_languages = apply_filters( 'wpml_active_languages', array() );
  99. $url = isset( $active_languages[$code]['country_flag_url'] ) ? $active_languages[$code]['country_flag_url'] : null;
  100. }
  101. //default: show all
  102. if(empty($url)){
  103. $url = RS_PLUGIN_URL.'admin/assets/images/icon-all.png';
  104. // NEW: $url = ICL_PLUGIN_URL . '/res/img/icon16.png';
  105. }
  106. return($url);
  107. }
  108. /**
  109. *
  110. * get language title by code
  111. */
  112. public static function getLangTitle($code){
  113. if($code == "all")
  114. return(__("All Languages", 'revslider'));
  115. $default_language = apply_filters( 'wpml_default_language', null );
  116. return apply_filters( 'wpml_translated_language_name', '', $code, $default_language );
  117. }
  118. /**
  119. *
  120. * get current language
  121. */
  122. public static function getCurrentLang(){
  123. self::validateWpmlExists();
  124. if ( is_admin() ) {
  125. return apply_filters( 'wpml_default_language', null );
  126. }
  127. return apply_filters( 'wpml_current_language', null );
  128. return($lang);
  129. }
  130. }
  131. /**
  132. * old classname extends new one (old classnames will be obsolete soon)
  133. * @since: 5.0
  134. **/
  135. class UniteWpmlRev extends RevSliderWpml {}
  136. ?>