Changeset 2849254
- Timestamp:
- 01/16/2023 03:34:43 PM (3 years ago)
- Location:
- slickplan-importer/trunk
- Files:
-
- 1 added
- 3 edited
-
assets/languages.json (added)
-
readme.txt (modified) (1 diff)
-
slickplan.php (modified) (7 diffs)
-
views/options.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
slickplan-importer/trunk/readme.txt
r2790191 r2849254 3 3 Donate link: https://slickplan.com/ 4 4 Tags: slickplan, import, xml 5 Requires at least: 3.06 Tested up to: 6. 0.25 Requires at least: 4.0 6 Tested up to: 6.1.1 7 7 Stable tag: trunk 8 8 License: GPL-3.0 -
slickplan-importer/trunk/slickplan.php
r2790191 r2849254 6 6 Author: Slickplan.com <[email protected]> 7 7 Author URI: https://slickplan.com/ 8 Version: 2.2. 28 Version: 2.2.3 9 9 License: GPL-3.0 - https://www.gnu.org/licenses/gpl-3.0.html 10 10 */ … … 296 296 'titles' => $form['titles_change'] ?? '', 297 297 'content' => $form['content'] ?? '', 298 'content_lang' => $form['content_lang'] ?? '', 298 299 'content_files' => ( 299 300 isset($form['content'], $form['content_files']) … … 318 319 $this->_options['create_menu'] = false; 319 320 } 321 if (isset($form['content_lang']) && $form['content_lang']) { 322 foreach ($xml['pages'] as $pageId => $pageData) { 323 if ( 324 isset($xml['pages'][$pageId]['contents']) 325 && is_array($xml['pages'][$pageId]['contents']) 326 && array_keys($xml['pages'][$pageId]['contents']) === range(0, count($xml['pages'][$pageId]['contents']) - 1) 327 ) { 328 $xml['pages'][$pageId]['contents'] = array_reduce($xml['pages'][$pageId]['contents'], function ($result, $item) use ($form) { 329 if ($item['@attributes']['lang'] === $form['content_lang']) { 330 return $item; 331 } 332 return $result; 333 }, []); 334 } 335 } 336 } 320 337 if ($this->_options['content_files']) { 321 338 // Redirect to AJAX importer … … 324 341 wp_redirect($this->_getAdminUrl('import')); 325 342 } else { 343 if (isset($form['content_lang']) && $form['content_lang']) { 344 update_option(SLICKPLAN_PLUGIN_OPTION, $xml); 345 } 346 326 347 // There is no files, so we can import pages faster than using AJAX importer 327 348 foreach (['home', '1', 'util', 'foot'] as $type) { … … 342 363 } 343 364 365 $allLanguages = $this->_getLanguages(); 366 $content_languages = []; 344 367 $no_of_files = 0; 345 368 $filesize_total = []; 346 369 if (isset($xml['pages']) and is_array($xml['pages'])) { 347 370 foreach ($xml['pages'] as $page) { 348 if (isset($page['contents']['body']) and is_array($page['contents']['body'])) { 349 foreach ($page['contents']['body'] as $body) { 350 if (isset($body['type']) and ($body['type'] === 'image' or $body['type'] === 'video' or $body['type'] === 'file')) { 351 foreach ($this->_getMediaElementArray($body) as $item) { 352 if (isset($item['type']) and $item['type'] === 'library') { 353 ++$no_of_files; 354 } 355 if (isset($item['file_size'], $item['file_id']) and $item['file_size']) { 356 $filesize_total[$item['file_id']] = (int)$item['file_size']; 357 } 358 } 371 if (isset($page['contents'][0]['@attributes']['lang'])) { 372 foreach ($page['contents'] as $row) { 373 if (isset($row['@attributes']['lang'], $allLanguages[$row['@attributes']['lang']]['name']) and $row['@attributes']['lang']) { 374 $content_languages[$row['@attributes']['lang']] = $allLanguages[$row['@attributes']['lang']]['name']; 359 375 } 360 } 376 if (isset($row['body']) && is_array($row['body'])) { 377 $filesData = $this->_sumFiles($row['body']); 378 $no_of_files += $filesData[0]; 379 $filesize_total = array_merge($filesize_total, $filesData[1]); 380 } 381 } 382 } elseif (isset($page['contents']['body']) and is_array($page['contents']['body'])) { 383 $filesData = $this->_sumFiles($page['contents']['body']); 384 $no_of_files += $filesData[0]; 385 $filesize_total = array_merge($filesize_total, $filesData[1]); 361 386 } 362 387 } … … 1078 1103 1079 1104 /** 1105 * @param $name 1106 * @param string $label 1107 * @param $options 1108 * @return string 1109 */ 1110 public function displayDropdown($name, string $label, $options): string { 1111 $id = sanitize_title('slickplan-importer-form-' . $name); 1112 $attrs = [ 1113 'name' => 'slickplan_importer[' . $name . ']', 1114 'id' => $id, 1115 ]; 1116 1117 $html = '<label for="' . $id . '">' . $label . ':</label> <select'; 1118 foreach ($attrs as $key => $value) { 1119 $html .= ' ' . $key . '="' . esc_attr($value) . '"'; 1120 } 1121 $html .= '>'; 1122 foreach ($options as $value => $name) { 1123 $html .= '<option value="' . esc_attr($value) . '">' . esc_attr($name) . '</option>'; 1124 } 1125 $html .= '</select>'; 1126 return $html; 1127 } 1128 1129 /** 1080 1130 * Display checkbox. 1081 1131 * … … 1510 1560 1511 1561 /** 1562 * @param $bodyItems 1563 * @return array 1564 */ 1565 private function _sumFiles($bodyItems) 1566 { 1567 $no_of_files = 0; 1568 $filesize_total = []; 1569 foreach ($bodyItems as $body) { 1570 if (isset($body['type']) and ($body['type'] === 'image' or $body['type'] === 'video' or $body['type'] === 'file')) { 1571 foreach ($this->_getMediaElementArray($body) as $item) { 1572 if (isset($item['type']) and $item['type'] === 'library') { 1573 ++$no_of_files; 1574 } 1575 if (isset($item['file_size'], $item['file_id']) and $item['file_size']) { 1576 $filesize_total[$item['file_id']] = (int)$item['file_size']; 1577 } 1578 } 1579 } 1580 } 1581 return [$no_of_files, $filesize_total]; 1582 } 1583 1584 private function _getLanguages() 1585 { 1586 return json_decode(file_get_contents(SLICKPLAN_PLUGIN_PATH . 'assets/languages.json'), true); 1587 } 1588 1589 /** 1512 1590 * @return bool 1513 1591 */ -
slickplan-importer/trunk/views/options.php
r2553277 r2849254 100 100 true 101 101 ); 102 if (isset($content_languages) and count($content_languages) > 1) { 103 $radio .= '<br class="content-suboption-br">' 104 . '<span class="content-suboption" style="display: inline-block; padding: 3px 0 0 20px;">' 105 . $this->displayDropdown( 106 'content_lang', 107 'Language', 108 $content_languages 109 ) 110 . '</span>'; 111 } 102 112 if (isset($no_of_files) and $no_of_files) { 103 113 $radio .= '<br class="content-suboption-br">'
Note: See TracChangeset
for help on using the changeset viewer.