D7FlagListsMaterio.php 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. <?php
  2. namespace Drupal\materio_migrate\Plugin\migrate\source;
  3. use Drupal\migrate\Plugin\migrate\source\SqlBase;
  4. use Drupal\migrate\Row;
  5. use Drupal\user\Entity\User;
  6. /**
  7. * Minimalistic example for a SqlBase source plugin.
  8. *
  9. * @MigrateSource(
  10. * id = "d7_flaglists_materio",
  11. * source_module = "flag_lists",
  12. * )
  13. */
  14. class D7FlagListsMaterio extends SqlBase {
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function query() {
  19. // Source data is queried from 'flag_lists_flags' table.
  20. $query = $this->select('flag_lists_flags', 'c');
  21. $query->join('flag', 'f', 'c.pfid = f.fid');
  22. // only import flaglist items for active users
  23. $query->join('users_roles', 'ur', 'c.uid = ur.uid');
  24. $query->condition('ur.rid', [3,4,6,10,11,13], 'IN');
  25. $query->fields('c', [
  26. 'fid',
  27. 'pfid',
  28. 'uid',
  29. 'entity_type',
  30. 'title',
  31. 'options',
  32. ])
  33. ->fields('f', [
  34. 'name',
  35. ]);
  36. return $query;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function fields() {
  42. $fields = [
  43. 'fid' => $this->t('Flag List #'),
  44. 'pfid' => $this->t('Parent flag id #'),
  45. 'uid' => $this->t('Owner'),
  46. 'entity_type' => $this->t('Entity type'),
  47. 'name' => $this->t('Machine name of the related flag'),
  48. 'title' => $this->t('Name of flag list'),
  49. 'option' => $this->t('Serielized info'),
  50. ];
  51. return $fields;
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. public function getIds() {
  57. return [
  58. 'fid' => [
  59. 'type' => 'integer',
  60. 'alias' => 'c',
  61. ],
  62. ];
  63. }
  64. /**
  65. * {@inheritdoc}
  66. */
  67. public function prepareRow(Row $row) {
  68. # WE GOT THE USER FROM LOOKUP PLUGIN
  69. // Check if the user exists.
  70. // $uid = $row->getSourceProperty('uid');
  71. // $user = User::load($uid);
  72. // if (!empty($user)) {
  73. // $owner = $uid;
  74. // }
  75. // else {
  76. // // Make the Administrator the owner.
  77. // $owner = 1;
  78. // }
  79. // $row->setSourceProperty('uid', $owner);
  80. # WE SET THE FLAG TEMPLATE DEFAULT "DOSSIER"
  81. // Check if the template flag exist.
  82. // $found = FALSE;
  83. // $flagService = \Drupal::service('flag');
  84. // $templateFlags = $flagService->getAllFlags(
  85. // $row->getSourceProperty('entity_type'));
  86. // foreach ($templateFlags as $flag) {
  87. // if ($found =
  88. // $flag->get('id') == $row->getSourceProperty('name')) {
  89. // break;
  90. // }
  91. // }
  92. // if (!$found) {
  93. // $message = $this->t('The template flag "@flag" wasn\'t found. Using fallback.',
  94. // ['@flag' => $row->getSourceProperty('name')]);
  95. // $messenger = \Drupal::messenger();
  96. // $logger = \Drupal::logger('flag_lists');
  97. // $messenger->addWarning($message);
  98. // $logger->warning($message);
  99. //
  100. // // Fall back to known existing flag.
  101. // $row->setSourceProperty('name', 'flag_list_template_1');
  102. // }
  103. // [error] Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException: Attempt to create a bundle with an ID longer than 32 characters: prototypage_rapide_grandes_dimensions(). in Drupal\Core\Entity\EntityBase->preSave() (line 439 of /var/www/html/d8.materio.com/public_html/web/core/lib/Drupal/Core/Entity/EntityBase.php).
  104. // [error] Attempt to create a bundle with an ID longer than 32 characters: prototypage_rapide_grandes_dimensions(). (/var/www/html/d8.materio.com/public_html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:846)
  105. // limit folder name to 32 characters (32 bytes, special chars like é use 2 bytes)
  106. $title = $row->getSourceProperty('title');
  107. $title = $this->remove_accents($title);
  108. $title = preg_replace("/\s+/", " ", $title);
  109. if (mb_strlen($title) > 32) {
  110. // drush_print('long ' . $title);
  111. $title = mb_strcut($title, 0 , 25).'…';
  112. // drush_print('short' . $title);
  113. }
  114. $row->setSourceProperty('title', $title);
  115. return parent::prepareRow($row);
  116. }
  117. /**
  118. * Converts all accent characters to ASCII characters.
  119. *
  120. * If there are no accent characters, then the string given is just returned.
  121. *
  122. * **Accent characters converted:**
  123. *
  124. * Currency signs:
  125. *
  126. * | Code | Glyph | Replacement | Description |
  127. * | -------- | ----- | ----------- | ------------------- |
  128. * | U+00A3 | £ | (empty) | British Pound sign |
  129. * | U+20AC | € | E | Euro sign |
  130. *
  131. * Decompositions for Latin-1 Supplement:
  132. *
  133. * | Code | Glyph | Replacement | Description |
  134. * | ------- | ----- | ----------- | -------------------------------------- |
  135. * | U+00AA | ª | a | Feminine ordinal indicator |
  136. * | U+00BA | º | o | Masculine ordinal indicator |
  137. * | U+00C0 | À | A | Latin capital letter A with grave |
  138. * | U+00C1 | Á | A | Latin capital letter A with acute |
  139. * | U+00C2 | Â | A | Latin capital letter A with circumflex |
  140. * | U+00C3 | Ã | A | Latin capital letter A with tilde |
  141. * | U+00C4 | Ä | A | Latin capital letter A with diaeresis |
  142. * | U+00C5 | Å | A | Latin capital letter A with ring above |
  143. * | U+00C6 | Æ | AE | Latin capital letter AE |
  144. * | U+00C7 | Ç | C | Latin capital letter C with cedilla |
  145. * | U+00C8 | È | E | Latin capital letter E with grave |
  146. * | U+00C9 | É | E | Latin capital letter E with acute |
  147. * | U+00CA | Ê | E | Latin capital letter E with circumflex |
  148. * | U+00CB | Ë | E | Latin capital letter E with diaeresis |
  149. * | U+00CC | Ì | I | Latin capital letter I with grave |
  150. * | U+00CD | Í | I | Latin capital letter I with acute |
  151. * | U+00CE | Î | I | Latin capital letter I with circumflex |
  152. * | U+00CF | Ï | I | Latin capital letter I with diaeresis |
  153. * | U+00D0 | Ð | D | Latin capital letter Eth |
  154. * | U+00D1 | Ñ | N | Latin capital letter N with tilde |
  155. * | U+00D2 | Ò | O | Latin capital letter O with grave |
  156. * | U+00D3 | Ó | O | Latin capital letter O with acute |
  157. * | U+00D4 | Ô | O | Latin capital letter O with circumflex |
  158. * | U+00D5 | Õ | O | Latin capital letter O with tilde |
  159. * | U+00D6 | Ö | O | Latin capital letter O with diaeresis |
  160. * | U+00D8 | Ø | O | Latin capital letter O with stroke |
  161. * | U+00D9 | Ù | U | Latin capital letter U with grave |
  162. * | U+00DA | Ú | U | Latin capital letter U with acute |
  163. * | U+00DB | Û | U | Latin capital letter U with circumflex |
  164. * | U+00DC | Ü | U | Latin capital letter U with diaeresis |
  165. * | U+00DD | Ý | Y | Latin capital letter Y with acute |
  166. * | U+00DE | Þ | TH | Latin capital letter Thorn |
  167. * | U+00DF | ß | s | Latin small letter sharp s |
  168. * | U+00E0 | à | a | Latin small letter a with grave |
  169. * | U+00E1 | á | a | Latin small letter a with acute |
  170. * | U+00E2 | â | a | Latin small letter a with circumflex |
  171. * | U+00E3 | ã | a | Latin small letter a with tilde |
  172. * | U+00E4 | ä | a | Latin small letter a with diaeresis |
  173. * | U+00E5 | å | a | Latin small letter a with ring above |
  174. * | U+00E6 | æ | ae | Latin small letter ae |
  175. * | U+00E7 | ç | c | Latin small letter c with cedilla |
  176. * | U+00E8 | è | e | Latin small letter e with grave |
  177. * | U+00E9 | é | e | Latin small letter e with acute |
  178. * | U+00EA | ê | e | Latin small letter e with circumflex |
  179. * | U+00EB | ë | e | Latin small letter e with diaeresis |
  180. * | U+00EC | ì | i | Latin small letter i with grave |
  181. * | U+00ED | í | i | Latin small letter i with acute |
  182. * | U+00EE | î | i | Latin small letter i with circumflex |
  183. * | U+00EF | ï | i | Latin small letter i with diaeresis |
  184. * | U+00F0 | ð | d | Latin small letter Eth |
  185. * | U+00F1 | ñ | n | Latin small letter n with tilde |
  186. * | U+00F2 | ò | o | Latin small letter o with grave |
  187. * | U+00F3 | ó | o | Latin small letter o with acute |
  188. * | U+00F4 | ô | o | Latin small letter o with circumflex |
  189. * | U+00F5 | õ | o | Latin small letter o with tilde |
  190. * | U+00F6 | ö | o | Latin small letter o with diaeresis |
  191. * | U+00F8 | ø | o | Latin small letter o with stroke |
  192. * | U+00F9 | ù | u | Latin small letter u with grave |
  193. * | U+00FA | ú | u | Latin small letter u with acute |
  194. * | U+00FB | û | u | Latin small letter u with circumflex |
  195. * | U+00FC | ü | u | Latin small letter u with diaeresis |
  196. * | U+00FD | ý | y | Latin small letter y with acute |
  197. * | U+00FE | þ | th | Latin small letter Thorn |
  198. * | U+00FF | ÿ | y | Latin small letter y with diaeresis |
  199. *
  200. * Decompositions for Latin Extended-A:
  201. *
  202. * | Code | Glyph | Replacement | Description |
  203. * | ------- | ----- | ----------- | ------------------------------------------------- |
  204. * | U+0100 | Ā | A | Latin capital letter A with macron |
  205. * | U+0101 | ā | a | Latin small letter a with macron |
  206. * | U+0102 | Ă | A | Latin capital letter A with breve |
  207. * | U+0103 | ă | a | Latin small letter a with breve |
  208. * | U+0104 | Ą | A | Latin capital letter A with ogonek |
  209. * | U+0105 | ą | a | Latin small letter a with ogonek |
  210. * | U+01006 | Ć | C | Latin capital letter C with acute |
  211. * | U+0107 | ć | c | Latin small letter c with acute |
  212. * | U+0108 | Ĉ | C | Latin capital letter C with circumflex |
  213. * | U+0109 | ĉ | c | Latin small letter c with circumflex |
  214. * | U+010A | Ċ | C | Latin capital letter C with dot above |
  215. * | U+010B | ċ | c | Latin small letter c with dot above |
  216. * | U+010C | Č | C | Latin capital letter C with caron |
  217. * | U+010D | č | c | Latin small letter c with caron |
  218. * | U+010E | Ď | D | Latin capital letter D with caron |
  219. * | U+010F | ď | d | Latin small letter d with caron |
  220. * | U+0110 | Đ | D | Latin capital letter D with stroke |
  221. * | U+0111 | đ | d | Latin small letter d with stroke |
  222. * | U+0112 | Ē | E | Latin capital letter E with macron |
  223. * | U+0113 | ē | e | Latin small letter e with macron |
  224. * | U+0114 | Ĕ | E | Latin capital letter E with breve |
  225. * | U+0115 | ĕ | e | Latin small letter e with breve |
  226. * | U+0116 | Ė | E | Latin capital letter E with dot above |
  227. * | U+0117 | ė | e | Latin small letter e with dot above |
  228. * | U+0118 | Ę | E | Latin capital letter E with ogonek |
  229. * | U+0119 | ę | e | Latin small letter e with ogonek |
  230. * | U+011A | Ě | E | Latin capital letter E with caron |
  231. * | U+011B | ě | e | Latin small letter e with caron |
  232. * | U+011C | Ĝ | G | Latin capital letter G with circumflex |
  233. * | U+011D | ĝ | g | Latin small letter g with circumflex |
  234. * | U+011E | Ğ | G | Latin capital letter G with breve |
  235. * | U+011F | ğ | g | Latin small letter g with breve |
  236. * | U+0120 | Ġ | G | Latin capital letter G with dot above |
  237. * | U+0121 | ġ | g | Latin small letter g with dot above |
  238. * | U+0122 | Ģ | G | Latin capital letter G with cedilla |
  239. * | U+0123 | ģ | g | Latin small letter g with cedilla |
  240. * | U+0124 | Ĥ | H | Latin capital letter H with circumflex |
  241. * | U+0125 | ĥ | h | Latin small letter h with circumflex |
  242. * | U+0126 | Ħ | H | Latin capital letter H with stroke |
  243. * | U+0127 | ħ | h | Latin small letter h with stroke |
  244. * | U+0128 | Ĩ | I | Latin capital letter I with tilde |
  245. * | U+0129 | ĩ | i | Latin small letter i with tilde |
  246. * | U+012A | Ī | I | Latin capital letter I with macron |
  247. * | U+012B | ī | i | Latin small letter i with macron |
  248. * | U+012C | Ĭ | I | Latin capital letter I with breve |
  249. * | U+012D | ĭ | i | Latin small letter i with breve |
  250. * | U+012E | Į | I | Latin capital letter I with ogonek |
  251. * | U+012F | į | i | Latin small letter i with ogonek |
  252. * | U+0130 | İ | I | Latin capital letter I with dot above |
  253. * | U+0131 | ı | i | Latin small letter dotless i |
  254. * | U+0132 | IJ | IJ | Latin capital ligature IJ |
  255. * | U+0133 | ij | ij | Latin small ligature ij |
  256. * | U+0134 | Ĵ | J | Latin capital letter J with circumflex |
  257. * | U+0135 | ĵ | j | Latin small letter j with circumflex |
  258. * | U+0136 | Ķ | K | Latin capital letter K with cedilla |
  259. * | U+0137 | ķ | k | Latin small letter k with cedilla |
  260. * | U+0138 | ĸ | k | Latin small letter Kra |
  261. * | U+0139 | Ĺ | L | Latin capital letter L with acute |
  262. * | U+013A | ĺ | l | Latin small letter l with acute |
  263. * | U+013B | Ļ | L | Latin capital letter L with cedilla |
  264. * | U+013C | ļ | l | Latin small letter l with cedilla |
  265. * | U+013D | Ľ | L | Latin capital letter L with caron |
  266. * | U+013E | ľ | l | Latin small letter l with caron |
  267. * | U+013F | Ŀ | L | Latin capital letter L with middle dot |
  268. * | U+0140 | ŀ | l | Latin small letter l with middle dot |
  269. * | U+0141 | Ł | L | Latin capital letter L with stroke |
  270. * | U+0142 | ł | l | Latin small letter l with stroke |
  271. * | U+0143 | Ń | N | Latin capital letter N with acute |
  272. * | U+0144 | ń | n | Latin small letter N with acute |
  273. * | U+0145 | Ņ | N | Latin capital letter N with cedilla |
  274. * | U+0146 | ņ | n | Latin small letter n with cedilla |
  275. * | U+0147 | Ň | N | Latin capital letter N with caron |
  276. * | U+0148 | ň | n | Latin small letter n with caron |
  277. * | U+0149 | ʼn | n | Latin small letter n preceded by apostrophe |
  278. * | U+014A | Ŋ | N | Latin capital letter Eng |
  279. * | U+014B | ŋ | n | Latin small letter Eng |
  280. * | U+014C | Ō | O | Latin capital letter O with macron |
  281. * | U+014D | ō | o | Latin small letter o with macron |
  282. * | U+014E | Ŏ | O | Latin capital letter O with breve |
  283. * | U+014F | ŏ | o | Latin small letter o with breve |
  284. * | U+0150 | Ő | O | Latin capital letter O with double acute |
  285. * | U+0151 | ő | o | Latin small letter o with double acute |
  286. * | U+0152 | Π| OE | Latin capital ligature OE |
  287. * | U+0153 | œ | oe | Latin small ligature oe |
  288. * | U+0154 | Ŕ | R | Latin capital letter R with acute |
  289. * | U+0155 | ŕ | r | Latin small letter r with acute |
  290. * | U+0156 | Ŗ | R | Latin capital letter R with cedilla |
  291. * | U+0157 | ŗ | r | Latin small letter r with cedilla |
  292. * | U+0158 | Ř | R | Latin capital letter R with caron |
  293. * | U+0159 | ř | r | Latin small letter r with caron |
  294. * | U+015A | Ś | S | Latin capital letter S with acute |
  295. * | U+015B | ś | s | Latin small letter s with acute |
  296. * | U+015C | Ŝ | S | Latin capital letter S with circumflex |
  297. * | U+015D | ŝ | s | Latin small letter s with circumflex |
  298. * | U+015E | Ş | S | Latin capital letter S with cedilla |
  299. * | U+015F | ş | s | Latin small letter s with cedilla |
  300. * | U+0160 | Š | S | Latin capital letter S with caron |
  301. * | U+0161 | š | s | Latin small letter s with caron |
  302. * | U+0162 | Ţ | T | Latin capital letter T with cedilla |
  303. * | U+0163 | ţ | t | Latin small letter t with cedilla |
  304. * | U+0164 | Ť | T | Latin capital letter T with caron |
  305. * | U+0165 | ť | t | Latin small letter t with caron |
  306. * | U+0166 | Ŧ | T | Latin capital letter T with stroke |
  307. * | U+0167 | ŧ | t | Latin small letter t with stroke |
  308. * | U+0168 | Ũ | U | Latin capital letter U with tilde |
  309. * | U+0169 | ũ | u | Latin small letter u with tilde |
  310. * | U+016A | Ū | U | Latin capital letter U with macron |
  311. * | U+016B | ū | u | Latin small letter u with macron |
  312. * | U+016C | Ŭ | U | Latin capital letter U with breve |
  313. * | U+016D | ŭ | u | Latin small letter u with breve |
  314. * | U+016E | Ů | U | Latin capital letter U with ring above |
  315. * | U+016F | ů | u | Latin small letter u with ring above |
  316. * | U+0170 | Ű | U | Latin capital letter U with double acute |
  317. * | U+0171 | ű | u | Latin small letter u with double acute |
  318. * | U+0172 | Ų | U | Latin capital letter U with ogonek |
  319. * | U+0173 | ų | u | Latin small letter u with ogonek |
  320. * | U+0174 | Ŵ | W | Latin capital letter W with circumflex |
  321. * | U+0175 | ŵ | w | Latin small letter w with circumflex |
  322. * | U+0176 | Ŷ | Y | Latin capital letter Y with circumflex |
  323. * | U+0177 | ŷ | y | Latin small letter y with circumflex |
  324. * | U+0178 | Ÿ | Y | Latin capital letter Y with diaeresis |
  325. * | U+0179 | Ź | Z | Latin capital letter Z with acute |
  326. * | U+017A | ź | z | Latin small letter z with acute |
  327. * | U+017B | Ż | Z | Latin capital letter Z with dot above |
  328. * | U+017C | ż | z | Latin small letter z with dot above |
  329. * | U+017D | Ž | Z | Latin capital letter Z with caron |
  330. * | U+017E | ž | z | Latin small letter z with caron |
  331. * | U+017F | ſ | s | Latin small letter long s |
  332. * | U+01A0 | Ơ | O | Latin capital letter O with horn |
  333. * | U+01A1 | ơ | o | Latin small letter o with horn |
  334. * | U+01AF | Ư | U | Latin capital letter U with horn |
  335. * | U+01B0 | ư | u | Latin small letter u with horn |
  336. * | U+01CD | Ǎ | A | Latin capital letter A with caron |
  337. * | U+01CE | ǎ | a | Latin small letter a with caron |
  338. * | U+01CF | Ǐ | I | Latin capital letter I with caron |
  339. * | U+01D0 | ǐ | i | Latin small letter i with caron |
  340. * | U+01D1 | Ǒ | O | Latin capital letter O with caron |
  341. * | U+01D2 | ǒ | o | Latin small letter o with caron |
  342. * | U+01D3 | Ǔ | U | Latin capital letter U with caron |
  343. * | U+01D4 | ǔ | u | Latin small letter u with caron |
  344. * | U+01D5 | Ǖ | U | Latin capital letter U with diaeresis and macron |
  345. * | U+01D6 | ǖ | u | Latin small letter u with diaeresis and macron |
  346. * | U+01D7 | Ǘ | U | Latin capital letter U with diaeresis and acute |
  347. * | U+01D8 | ǘ | u | Latin small letter u with diaeresis and acute |
  348. * | U+01D9 | Ǚ | U | Latin capital letter U with diaeresis and caron |
  349. * | U+01DA | ǚ | u | Latin small letter u with diaeresis and caron |
  350. * | U+01DB | Ǜ | U | Latin capital letter U with diaeresis and grave |
  351. * | U+01DC | ǜ | u | Latin small letter u with diaeresis and grave |
  352. *
  353. * Decompositions for Latin Extended-B:
  354. *
  355. * | Code | Glyph | Replacement | Description |
  356. * | -------- | ----- | ----------- | ----------------------------------------- |
  357. * | U+0218 | Ș | S | Latin capital letter S with comma below |
  358. * | U+0219 | ș | s | Latin small letter s with comma below |
  359. * | U+021A | Ț | T | Latin capital letter T with comma below |
  360. * | U+021B | ț | t | Latin small letter t with comma below |
  361. *
  362. * Vowels with diacritic (Chinese, Hanyu Pinyin):
  363. *
  364. * | Code | Glyph | Replacement | Description |
  365. * | -------- | ----- | ----------- | ----------------------------------------------------- |
  366. * | U+0251 | ɑ | a | Latin small letter alpha |
  367. * | U+1EA0 | Ạ | A | Latin capital letter A with dot below |
  368. * | U+1EA1 | ạ | a | Latin small letter a with dot below |
  369. * | U+1EA2 | Ả | A | Latin capital letter A with hook above |
  370. * | U+1EA3 | ả | a | Latin small letter a with hook above |
  371. * | U+1EA4 | Ấ | A | Latin capital letter A with circumflex and acute |
  372. * | U+1EA5 | ấ | a | Latin small letter a with circumflex and acute |
  373. * | U+1EA6 | Ầ | A | Latin capital letter A with circumflex and grave |
  374. * | U+1EA7 | ầ | a | Latin small letter a with circumflex and grave |
  375. * | U+1EA8 | Ẩ | A | Latin capital letter A with circumflex and hook above |
  376. * | U+1EA9 | ẩ | a | Latin small letter a with circumflex and hook above |
  377. * | U+1EAA | Ẫ | A | Latin capital letter A with circumflex and tilde |
  378. * | U+1EAB | ẫ | a | Latin small letter a with circumflex and tilde |
  379. * | U+1EA6 | Ậ | A | Latin capital letter A with circumflex and dot below |
  380. * | U+1EAD | ậ | a | Latin small letter a with circumflex and dot below |
  381. * | U+1EAE | Ắ | A | Latin capital letter A with breve and acute |
  382. * | U+1EAF | ắ | a | Latin small letter a with breve and acute |
  383. * | U+1EB0 | Ằ | A | Latin capital letter A with breve and grave |
  384. * | U+1EB1 | ằ | a | Latin small letter a with breve and grave |
  385. * | U+1EB2 | Ẳ | A | Latin capital letter A with breve and hook above |
  386. * | U+1EB3 | ẳ | a | Latin small letter a with breve and hook above |
  387. * | U+1EB4 | Ẵ | A | Latin capital letter A with breve and tilde |
  388. * | U+1EB5 | ẵ | a | Latin small letter a with breve and tilde |
  389. * | U+1EB6 | Ặ | A | Latin capital letter A with breve and dot below |
  390. * | U+1EB7 | ặ | a | Latin small letter a with breve and dot below |
  391. * | U+1EB8 | Ẹ | E | Latin capital letter E with dot below |
  392. * | U+1EB9 | ẹ | e | Latin small letter e with dot below |
  393. * | U+1EBA | Ẻ | E | Latin capital letter E with hook above |
  394. * | U+1EBB | ẻ | e | Latin small letter e with hook above |
  395. * | U+1EBC | Ẽ | E | Latin capital letter E with tilde |
  396. * | U+1EBD | ẽ | e | Latin small letter e with tilde |
  397. * | U+1EBE | Ế | E | Latin capital letter E with circumflex and acute |
  398. * | U+1EBF | ế | e | Latin small letter e with circumflex and acute |
  399. * | U+1EC0 | Ề | E | Latin capital letter E with circumflex and grave |
  400. * | U+1EC1 | ề | e | Latin small letter e with circumflex and grave |
  401. * | U+1EC2 | Ể | E | Latin capital letter E with circumflex and hook above |
  402. * | U+1EC3 | ể | e | Latin small letter e with circumflex and hook above |
  403. * | U+1EC4 | Ễ | E | Latin capital letter E with circumflex and tilde |
  404. * | U+1EC5 | ễ | e | Latin small letter e with circumflex and tilde |
  405. * | U+1EC6 | Ệ | E | Latin capital letter E with circumflex and dot below |
  406. * | U+1EC7 | ệ | e | Latin small letter e with circumflex and dot below |
  407. * | U+1EC8 | Ỉ | I | Latin capital letter I with hook above |
  408. * | U+1EC9 | ỉ | i | Latin small letter i with hook above |
  409. * | U+1ECA | Ị | I | Latin capital letter I with dot below |
  410. * | U+1ECB | ị | i | Latin small letter i with dot below |
  411. * | U+1ECC | Ọ | O | Latin capital letter O with dot below |
  412. * | U+1ECD | ọ | o | Latin small letter o with dot below |
  413. * | U+1ECE | Ỏ | O | Latin capital letter O with hook above |
  414. * | U+1ECF | ỏ | o | Latin small letter o with hook above |
  415. * | U+1ED0 | Ố | O | Latin capital letter O with circumflex and acute |
  416. * | U+1ED1 | ố | o | Latin small letter o with circumflex and acute |
  417. * | U+1ED2 | Ồ | O | Latin capital letter O with circumflex and grave |
  418. * | U+1ED3 | ồ | o | Latin small letter o with circumflex and grave |
  419. * | U+1ED4 | Ổ | O | Latin capital letter O with circumflex and hook above |
  420. * | U+1ED5 | ổ | o | Latin small letter o with circumflex and hook above |
  421. * | U+1ED6 | Ỗ | O | Latin capital letter O with circumflex and tilde |
  422. * | U+1ED7 | ỗ | o | Latin small letter o with circumflex and tilde |
  423. * | U+1ED8 | Ộ | O | Latin capital letter O with circumflex and dot below |
  424. * | U+1ED9 | ộ | o | Latin small letter o with circumflex and dot below |
  425. * | U+1EDA | Ớ | O | Latin capital letter O with horn and acute |
  426. * | U+1EDB | ớ | o | Latin small letter o with horn and acute |
  427. * | U+1EDC | Ờ | O | Latin capital letter O with horn and grave |
  428. * | U+1EDD | ờ | o | Latin small letter o with horn and grave |
  429. * | U+1EDE | Ở | O | Latin capital letter O with horn and hook above |
  430. * | U+1EDF | ở | o | Latin small letter o with horn and hook above |
  431. * | U+1EE0 | Ỡ | O | Latin capital letter O with horn and tilde |
  432. * | U+1EE1 | ỡ | o | Latin small letter o with horn and tilde |
  433. * | U+1EE2 | Ợ | O | Latin capital letter O with horn and dot below |
  434. * | U+1EE3 | ợ | o | Latin small letter o with horn and dot below |
  435. * | U+1EE4 | Ụ | U | Latin capital letter U with dot below |
  436. * | U+1EE5 | ụ | u | Latin small letter u with dot below |
  437. * | U+1EE6 | Ủ | U | Latin capital letter U with hook above |
  438. * | U+1EE7 | ủ | u | Latin small letter u with hook above |
  439. * | U+1EE8 | Ứ | U | Latin capital letter U with horn and acute |
  440. * | U+1EE9 | ứ | u | Latin small letter u with horn and acute |
  441. * | U+1EEA | Ừ | U | Latin capital letter U with horn and grave |
  442. * | U+1EEB | ừ | u | Latin small letter u with horn and grave |
  443. * | U+1EEC | Ử | U | Latin capital letter U with horn and hook above |
  444. * | U+1EED | ử | u | Latin small letter u with horn and hook above |
  445. * | U+1EEE | Ữ | U | Latin capital letter U with horn and tilde |
  446. * | U+1EEF | ữ | u | Latin small letter u with horn and tilde |
  447. * | U+1EF0 | Ự | U | Latin capital letter U with horn and dot below |
  448. * | U+1EF1 | ự | u | Latin small letter u with horn and dot below |
  449. * | U+1EF2 | Ỳ | Y | Latin capital letter Y with grave |
  450. * | U+1EF3 | ỳ | y | Latin small letter y with grave |
  451. * | U+1EF4 | Ỵ | Y | Latin capital letter Y with dot below |
  452. * | U+1EF5 | ỵ | y | Latin small letter y with dot below |
  453. * | U+1EF6 | Ỷ | Y | Latin capital letter Y with hook above |
  454. * | U+1EF7 | ỷ | y | Latin small letter y with hook above |
  455. * | U+1EF8 | Ỹ | Y | Latin capital letter Y with tilde |
  456. * | U+1EF9 | ỹ | y | Latin small letter y with tilde |
  457. *
  458. * German (`de_DE`), German formal (`de_DE_formal`), German (Switzerland) formal (`de_CH`),
  459. * and German (Switzerland) informal (`de_CH_informal`) locales:
  460. *
  461. * | Code | Glyph | Replacement | Description |
  462. * | -------- | ----- | ----------- | --------------------------------------- |
  463. * | U+00C4 | Ä | Ae | Latin capital letter A with diaeresis |
  464. * | U+00E4 | ä | ae | Latin small letter a with diaeresis |
  465. * | U+00D6 | Ö | Oe | Latin capital letter O with diaeresis |
  466. * | U+00F6 | ö | oe | Latin small letter o with diaeresis |
  467. * | U+00DC | Ü | Ue | Latin capital letter U with diaeresis |
  468. * | U+00FC | ü | ue | Latin small letter u with diaeresis |
  469. * | U+00DF | ß | ss | Latin small letter sharp s |
  470. *
  471. * Danish (`da_DK`) locale:
  472. *
  473. * | Code | Glyph | Replacement | Description |
  474. * | -------- | ----- | ----------- | --------------------------------------- |
  475. * | U+00C6 | Æ | Ae | Latin capital letter AE |
  476. * | U+00E6 | æ | ae | Latin small letter ae |
  477. * | U+00D8 | Ø | Oe | Latin capital letter O with stroke |
  478. * | U+00F8 | ø | oe | Latin small letter o with stroke |
  479. * | U+00C5 | Å | Aa | Latin capital letter A with ring above |
  480. * | U+00E5 | å | aa | Latin small letter a with ring above |
  481. *
  482. * Catalan (`ca`) locale:
  483. *
  484. * | Code | Glyph | Replacement | Description |
  485. * | -------- | ----- | ----------- | --------------------------------------- |
  486. * | U+00B7 | l·l | ll | Flown dot (between two Ls) |
  487. *
  488. * Serbian (`sr_RS`) and Bosnian (`bs_BA`) locales:
  489. *
  490. * | Code | Glyph | Replacement | Description |
  491. * | -------- | ----- | ----------- | --------------------------------------- |
  492. * | U+0110 | Đ | DJ | Latin capital letter D with stroke |
  493. * | U+0111 | đ | dj | Latin small letter d with stroke |
  494. *
  495. * @since 1.2.1
  496. * @since 4.6.0 Added locale support for `de_CH`, `de_CH_informal`, and `ca`.
  497. * @since 4.7.0 Added locale support for `sr_RS`.
  498. * @since 4.8.0 Added locale support for `bs_BA`.
  499. *
  500. * @param string $string Text that might have accent characters
  501. * @return string Filtered string with replaced "nice" characters.
  502. */
  503. private function remove_accents( $string ) {
  504. if ( ! preg_match( '/[\x80-\xff]/', $string ) ) {
  505. return $string;
  506. }
  507. if ( $this->seems_utf8( $string ) ) {
  508. $chars = array(
  509. // Decompositions for Latin-1 Supplement.
  510. 'ª' => 'a',
  511. 'º' => 'o',
  512. 'À' => 'A',
  513. 'Á' => 'A',
  514. 'Â' => 'A',
  515. 'Ã' => 'A',
  516. 'Ä' => 'A',
  517. 'Å' => 'A',
  518. 'Æ' => 'AE',
  519. 'Ç' => 'C',
  520. 'È' => 'E',
  521. 'É' => 'E',
  522. 'Ê' => 'E',
  523. 'Ë' => 'E',
  524. 'Ì' => 'I',
  525. 'Í' => 'I',
  526. 'Î' => 'I',
  527. 'Ï' => 'I',
  528. 'Ð' => 'D',
  529. 'Ñ' => 'N',
  530. 'Ò' => 'O',
  531. 'Ó' => 'O',
  532. 'Ô' => 'O',
  533. 'Õ' => 'O',
  534. 'Ö' => 'O',
  535. 'Ù' => 'U',
  536. 'Ú' => 'U',
  537. 'Û' => 'U',
  538. 'Ü' => 'U',
  539. 'Ý' => 'Y',
  540. 'Þ' => 'TH',
  541. 'ß' => 's',
  542. 'à' => 'a',
  543. 'á' => 'a',
  544. 'â' => 'a',
  545. 'ã' => 'a',
  546. 'ä' => 'a',
  547. 'å' => 'a',
  548. 'æ' => 'ae',
  549. 'ç' => 'c',
  550. 'è' => 'e',
  551. 'é' => 'e',
  552. 'ê' => 'e',
  553. 'ë' => 'e',
  554. 'ì' => 'i',
  555. 'í' => 'i',
  556. 'î' => 'i',
  557. 'ï' => 'i',
  558. 'ð' => 'd',
  559. 'ñ' => 'n',
  560. 'ò' => 'o',
  561. 'ó' => 'o',
  562. 'ô' => 'o',
  563. 'õ' => 'o',
  564. 'ö' => 'o',
  565. 'ø' => 'o',
  566. 'ù' => 'u',
  567. 'ú' => 'u',
  568. 'û' => 'u',
  569. 'ü' => 'u',
  570. 'ý' => 'y',
  571. 'þ' => 'th',
  572. 'ÿ' => 'y',
  573. 'Ø' => 'O',
  574. // Decompositions for Latin Extended-A.
  575. 'Ā' => 'A',
  576. 'ā' => 'a',
  577. 'Ă' => 'A',
  578. 'ă' => 'a',
  579. 'Ą' => 'A',
  580. 'ą' => 'a',
  581. 'Ć' => 'C',
  582. 'ć' => 'c',
  583. 'Ĉ' => 'C',
  584. 'ĉ' => 'c',
  585. 'Ċ' => 'C',
  586. 'ċ' => 'c',
  587. 'Č' => 'C',
  588. 'č' => 'c',
  589. 'Ď' => 'D',
  590. 'ď' => 'd',
  591. 'Đ' => 'D',
  592. 'đ' => 'd',
  593. 'Ē' => 'E',
  594. 'ē' => 'e',
  595. 'Ĕ' => 'E',
  596. 'ĕ' => 'e',
  597. 'Ė' => 'E',
  598. 'ė' => 'e',
  599. 'Ę' => 'E',
  600. 'ę' => 'e',
  601. 'Ě' => 'E',
  602. 'ě' => 'e',
  603. 'Ĝ' => 'G',
  604. 'ĝ' => 'g',
  605. 'Ğ' => 'G',
  606. 'ğ' => 'g',
  607. 'Ġ' => 'G',
  608. 'ġ' => 'g',
  609. 'Ģ' => 'G',
  610. 'ģ' => 'g',
  611. 'Ĥ' => 'H',
  612. 'ĥ' => 'h',
  613. 'Ħ' => 'H',
  614. 'ħ' => 'h',
  615. 'Ĩ' => 'I',
  616. 'ĩ' => 'i',
  617. 'Ī' => 'I',
  618. 'ī' => 'i',
  619. 'Ĭ' => 'I',
  620. 'ĭ' => 'i',
  621. 'Į' => 'I',
  622. 'į' => 'i',
  623. 'İ' => 'I',
  624. 'ı' => 'i',
  625. 'IJ' => 'IJ',
  626. 'ij' => 'ij',
  627. 'Ĵ' => 'J',
  628. 'ĵ' => 'j',
  629. 'Ķ' => 'K',
  630. 'ķ' => 'k',
  631. 'ĸ' => 'k',
  632. 'Ĺ' => 'L',
  633. 'ĺ' => 'l',
  634. 'Ļ' => 'L',
  635. 'ļ' => 'l',
  636. 'Ľ' => 'L',
  637. 'ľ' => 'l',
  638. 'Ŀ' => 'L',
  639. 'ŀ' => 'l',
  640. 'Ł' => 'L',
  641. 'ł' => 'l',
  642. 'Ń' => 'N',
  643. 'ń' => 'n',
  644. 'Ņ' => 'N',
  645. 'ņ' => 'n',
  646. 'Ň' => 'N',
  647. 'ň' => 'n',
  648. 'ʼn' => 'n',
  649. 'Ŋ' => 'N',
  650. 'ŋ' => 'n',
  651. 'Ō' => 'O',
  652. 'ō' => 'o',
  653. 'Ŏ' => 'O',
  654. 'ŏ' => 'o',
  655. 'Ő' => 'O',
  656. 'ő' => 'o',
  657. 'Œ' => 'OE',
  658. 'œ' => 'oe',
  659. 'Ŕ' => 'R',
  660. 'ŕ' => 'r',
  661. 'Ŗ' => 'R',
  662. 'ŗ' => 'r',
  663. 'Ř' => 'R',
  664. 'ř' => 'r',
  665. 'Ś' => 'S',
  666. 'ś' => 's',
  667. 'Ŝ' => 'S',
  668. 'ŝ' => 's',
  669. 'Ş' => 'S',
  670. 'ş' => 's',
  671. 'Š' => 'S',
  672. 'š' => 's',
  673. 'Ţ' => 'T',
  674. 'ţ' => 't',
  675. 'Ť' => 'T',
  676. 'ť' => 't',
  677. 'Ŧ' => 'T',
  678. 'ŧ' => 't',
  679. 'Ũ' => 'U',
  680. 'ũ' => 'u',
  681. 'Ū' => 'U',
  682. 'ū' => 'u',
  683. 'Ŭ' => 'U',
  684. 'ŭ' => 'u',
  685. 'Ů' => 'U',
  686. 'ů' => 'u',
  687. 'Ű' => 'U',
  688. 'ű' => 'u',
  689. 'Ų' => 'U',
  690. 'ų' => 'u',
  691. 'Ŵ' => 'W',
  692. 'ŵ' => 'w',
  693. 'Ŷ' => 'Y',
  694. 'ŷ' => 'y',
  695. 'Ÿ' => 'Y',
  696. 'Ź' => 'Z',
  697. 'ź' => 'z',
  698. 'Ż' => 'Z',
  699. 'ż' => 'z',
  700. 'Ž' => 'Z',
  701. 'ž' => 'z',
  702. 'ſ' => 's',
  703. // Decompositions for Latin Extended-B.
  704. 'Ș' => 'S',
  705. 'ș' => 's',
  706. 'Ț' => 'T',
  707. 'ț' => 't',
  708. // Euro sign.
  709. '€' => 'E',
  710. // GBP (Pound) sign.
  711. '£' => '',
  712. // Vowels with diacritic (Vietnamese).
  713. // Unmarked.
  714. 'Ơ' => 'O',
  715. 'ơ' => 'o',
  716. 'Ư' => 'U',
  717. 'ư' => 'u',
  718. // Grave accent.
  719. 'Ầ' => 'A',
  720. 'ầ' => 'a',
  721. 'Ằ' => 'A',
  722. 'ằ' => 'a',
  723. 'Ề' => 'E',
  724. 'ề' => 'e',
  725. 'Ồ' => 'O',
  726. 'ồ' => 'o',
  727. 'Ờ' => 'O',
  728. 'ờ' => 'o',
  729. 'Ừ' => 'U',
  730. 'ừ' => 'u',
  731. 'Ỳ' => 'Y',
  732. 'ỳ' => 'y',
  733. // Hook.
  734. 'Ả' => 'A',
  735. 'ả' => 'a',
  736. 'Ẩ' => 'A',
  737. 'ẩ' => 'a',
  738. 'Ẳ' => 'A',
  739. 'ẳ' => 'a',
  740. 'Ẻ' => 'E',
  741. 'ẻ' => 'e',
  742. 'Ể' => 'E',
  743. 'ể' => 'e',
  744. 'Ỉ' => 'I',
  745. 'ỉ' => 'i',
  746. 'Ỏ' => 'O',
  747. 'ỏ' => 'o',
  748. 'Ổ' => 'O',
  749. 'ổ' => 'o',
  750. 'Ở' => 'O',
  751. 'ở' => 'o',
  752. 'Ủ' => 'U',
  753. 'ủ' => 'u',
  754. 'Ử' => 'U',
  755. 'ử' => 'u',
  756. 'Ỷ' => 'Y',
  757. 'ỷ' => 'y',
  758. // Tilde.
  759. 'Ẫ' => 'A',
  760. 'ẫ' => 'a',
  761. 'Ẵ' => 'A',
  762. 'ẵ' => 'a',
  763. 'Ẽ' => 'E',
  764. 'ẽ' => 'e',
  765. 'Ễ' => 'E',
  766. 'ễ' => 'e',
  767. 'Ỗ' => 'O',
  768. 'ỗ' => 'o',
  769. 'Ỡ' => 'O',
  770. 'ỡ' => 'o',
  771. 'Ữ' => 'U',
  772. 'ữ' => 'u',
  773. 'Ỹ' => 'Y',
  774. 'ỹ' => 'y',
  775. // Acute accent.
  776. 'Ấ' => 'A',
  777. 'ấ' => 'a',
  778. 'Ắ' => 'A',
  779. 'ắ' => 'a',
  780. 'Ế' => 'E',
  781. 'ế' => 'e',
  782. 'Ố' => 'O',
  783. 'ố' => 'o',
  784. 'Ớ' => 'O',
  785. 'ớ' => 'o',
  786. 'Ứ' => 'U',
  787. 'ứ' => 'u',
  788. // Dot below.
  789. 'Ạ' => 'A',
  790. 'ạ' => 'a',
  791. 'Ậ' => 'A',
  792. 'ậ' => 'a',
  793. 'Ặ' => 'A',
  794. 'ặ' => 'a',
  795. 'Ẹ' => 'E',
  796. 'ẹ' => 'e',
  797. 'Ệ' => 'E',
  798. 'ệ' => 'e',
  799. 'Ị' => 'I',
  800. 'ị' => 'i',
  801. 'Ọ' => 'O',
  802. 'ọ' => 'o',
  803. 'Ộ' => 'O',
  804. 'ộ' => 'o',
  805. 'Ợ' => 'O',
  806. 'ợ' => 'o',
  807. 'Ụ' => 'U',
  808. 'ụ' => 'u',
  809. 'Ự' => 'U',
  810. 'ự' => 'u',
  811. 'Ỵ' => 'Y',
  812. 'ỵ' => 'y',
  813. // Vowels with diacritic (Chinese, Hanyu Pinyin).
  814. 'ɑ' => 'a',
  815. // Macron.
  816. 'Ǖ' => 'U',
  817. 'ǖ' => 'u',
  818. // Acute accent.
  819. 'Ǘ' => 'U',
  820. 'ǘ' => 'u',
  821. // Caron.
  822. 'Ǎ' => 'A',
  823. 'ǎ' => 'a',
  824. 'Ǐ' => 'I',
  825. 'ǐ' => 'i',
  826. 'Ǒ' => 'O',
  827. 'ǒ' => 'o',
  828. 'Ǔ' => 'U',
  829. 'ǔ' => 'u',
  830. 'Ǚ' => 'U',
  831. 'ǚ' => 'u',
  832. // Grave accent.
  833. 'Ǜ' => 'U',
  834. 'ǜ' => 'u',
  835. );
  836. $string = strtr( $string, $chars );
  837. } else {
  838. $chars = array();
  839. // Assume ISO-8859-1 if not UTF-8.
  840. $chars['in'] = "\x80\x83\x8a\x8e\x9a\x9e"
  841. . "\x9f\xa2\xa5\xb5\xc0\xc1\xc2"
  842. . "\xc3\xc4\xc5\xc7\xc8\xc9\xca"
  843. . "\xcb\xcc\xcd\xce\xcf\xd1\xd2"
  844. . "\xd3\xd4\xd5\xd6\xd8\xd9\xda"
  845. . "\xdb\xdc\xdd\xe0\xe1\xe2\xe3"
  846. . "\xe4\xe5\xe7\xe8\xe9\xea\xeb"
  847. . "\xec\xed\xee\xef\xf1\xf2\xf3"
  848. . "\xf4\xf5\xf6\xf8\xf9\xfa\xfb"
  849. . "\xfc\xfd\xff";
  850. $chars['out'] = 'EfSZszYcYuAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy';
  851. $string = strtr( $string, $chars['in'], $chars['out'] );
  852. $double_chars = array();
  853. $double_chars['in'] = array( "\x8c", "\x9c", "\xc6", "\xd0", "\xde", "\xdf", "\xe6", "\xf0", "\xfe" );
  854. $double_chars['out'] = array( 'OE', 'oe', 'AE', 'DH', 'TH', 'ss', 'ae', 'dh', 'th' );
  855. $string = str_replace( $double_chars['in'], $double_chars['out'], $string );
  856. }
  857. return $string;
  858. }
  859. private function seems_utf8( $str ) {
  860. $this->mbstring_binary_safe_encoding();
  861. $length = strlen( $str );
  862. $this->mbstring_binary_safe_encoding(true);
  863. for ( $i = 0; $i < $length; $i++ ) {
  864. $c = ord( $str[ $i ] );
  865. if ( $c < 0x80 ) {
  866. $n = 0; // 0bbbbbbb
  867. } elseif ( ( $c & 0xE0 ) == 0xC0 ) {
  868. $n = 1; // 110bbbbb
  869. } elseif ( ( $c & 0xF0 ) == 0xE0 ) {
  870. $n = 2; // 1110bbbb
  871. } elseif ( ( $c & 0xF8 ) == 0xF0 ) {
  872. $n = 3; // 11110bbb
  873. } elseif ( ( $c & 0xFC ) == 0xF8 ) {
  874. $n = 4; // 111110bb
  875. } elseif ( ( $c & 0xFE ) == 0xFC ) {
  876. $n = 5; // 1111110b
  877. } else {
  878. return false; // Does not match any model.
  879. }
  880. for ( $j = 0; $j < $n; $j++ ) { // n bytes matching 10bbbbbb follow ?
  881. if ( ( ++$i == $length ) || ( ( ord( $str[ $i ] ) & 0xC0 ) != 0x80 ) ) {
  882. return false;
  883. }
  884. }
  885. }
  886. return true;
  887. }
  888. private function mbstring_binary_safe_encoding( $reset = false ) {
  889. static $encodings = array();
  890. static $overloaded = null;
  891. if ( is_null( $overloaded ) ) {
  892. $overloaded = function_exists( 'mb_internal_encoding' ) && ( ini_get( 'mbstring.func_overload' ) & 2 ); // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.mbstring_func_overloadDeprecated
  893. }
  894. if ( false === $overloaded ) {
  895. return;
  896. }
  897. if ( ! $reset ) {
  898. $encoding = mb_internal_encoding();
  899. array_push( $encodings, $encoding );
  900. mb_internal_encoding( 'ISO-8859-1' );
  901. }
  902. if ( $reset && $encodings ) {
  903. $encoding = array_pop( $encodings );
  904. mb_internal_encoding( $encoding );
  905. }
  906. }
  907. }