Changeset 3366451
- Timestamp:
- 09/23/2025 12:14:53 PM (5 months ago)
- Location:
- slickplan-importer/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (5 diffs)
-
slickplan.php (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
slickplan-importer/trunk/readme.txt
r3251226 r3366451 8 8 License: GPL-3.0 9 9 License URI: https://www.gnu.org/licenses/gpl-3.0.html 10 11 The Slickplan import plugin allows you to quickly import your Slickplan projects into your WordPress site. 12 13 == Description == 10 14 11 15 The Slickplan import plugin allows you to quickly import your Slickplan projects into your WordPress site. … … 23 27 == Changelog == 24 28 29 = 2.5 = 30 * New: Support for new meta fields and featured image import 31 25 32 = 2.4 = 26 * New: Added per-page mapping33 * New: Per-page mapping 27 34 28 35 = 2.3 = 29 * New: Added custom posts typesmapping36 * New: Custom post type mapping 30 37 31 38 = 2.2 = 32 * New: Added basic support for Gutenberg39 * New: Basic support for Gutenberg 33 40 * New: Dropped support for PHP 5 34 * Fix: Non-recognizable files in Content Planner upload blocks with"multiple" option enabled41 * Fix: Unrecognized files in Content Planner upload blocks with the "multiple" option enabled 35 42 36 43 = 2.1.3 = … … 38 45 39 46 = 2.1.2 = 40 * Fix: Non-recognizableXML file when section ID is missing47 * Fix: Unrecognized XML file when section ID is missing 41 48 42 49 = 2.1.1 = 43 * Fix: Import content blocks in correct order, fixed file download bug 50 * Fix: Import content blocks in the correct order 51 * Fix: File download bug 44 52 45 53 = 2.1 = 46 * New: Added support for internal links when importing content47 * New: A dded an information about approx total files size to"import files" option54 * New: Support for internal links when importing content 55 * New: Approximate total file size information added to the "import files" option 48 56 * Fix: Don't use AJAX importer when importing content from notes 49 * Fix: Hide "import files" option when there isno files to import57 * Fix: Hide the "import files" option when there are no files to import 50 58 51 59 = 2.0 = 52 * New: Import is now a 2 steps process -import options have been moved to Step 253 * New: Added Content Planner support - plugin now can import page content, SEO meta and download files tomedia library54 * Fix: Dropped the PHP 's libxml extension requirement, plugin now requires DOMElement which is default PHP5 extension60 * New: Import is now a 2-step process — import options have been moved to Step 2 61 * New: Content Planner support — plugin can now import page content, SEO meta, and download files to the media library 62 * Fix: Dropped the PHP libxml extension requirement; plugin now requires DOMElement, which is a default PHP 5 extension 55 63 56 64 = 1.2 = 57 * New: Automatically add c urrect page order attribute65 * New: Automatically add correct page order attribute 58 66 59 67 = 1.1 = … … 65 73 = 1.0 = 66 74 * New: Options to manipulate page titles prior to import 67 * Fix: updated styling to suitWordPress 3.875 * Fix: Updated styling to match WordPress 3.8 68 76 69 77 = 0.4 = … … 74 82 75 83 = 0.2 = 76 * New: Import notes as page s contents84 * New: Import notes as page content 77 85 * New: Import footer section items 78 86 -
slickplan-importer/trunk/slickplan.php
r3364102 r3366451 66 66 class Slickplan_Importer extends WP_Importer 67 67 { 68 public $pages = []; 69 public $pagesIds = []; 70 71 /** 72 * Menu order increment. 73 * 74 * @var int 75 */ 76 private $_order = 0; 77 78 /** 79 * An array of import options. 80 * 81 * @var array 82 */ 83 private $_options = []; 84 85 /** 86 * An array of imported pages or errors. 87 * 88 * @var array 89 */ 90 private $_summary = []; 91 92 /** 93 * An array of imported files 94 * 95 * @var array 96 */ 97 private $_files = []; 98 99 /** 100 * If page has unparsed internal pages 101 * 102 * @var bool 103 */ 104 private $_has_unparsed_internal_links = false; 105 106 /** 107 * @var WP_oEmbed 108 */ 109 private $_wp_oembed = null; 110 111 /** 112 * @var string 113 */ 114 private $_temp_file = null; 115 116 private $_postTypes = []; 117 private $_sectionsMap = []; 68 public array $pages = []; 69 public array $pagesIds = []; 70 71 private int $_order = 0; 72 private array $_options = []; 73 private array $_summary = []; 74 private array $_files = []; 75 private bool $_has_unparsed_internal_links = false; 76 private ?WP_oEmbed $_wp_oembed = null; 77 private ?string $_temp_file = null; 78 private array $_postTypes = []; 79 private array $_sectionsMap = []; 118 80 119 81 public function __construct() … … 130 92 } 131 93 132 /**133 * Importer page routing.134 */135 94 public function dispatch() 136 95 { … … 175 134 } 176 135 177 /**178 * Handle file upload and prepare to import pages.179 */180 136 public function handleFileUpload() 181 137 { … … 200 156 } 201 157 202 /**203 * Get HTML of a summary row204 *205 * @param array $page206 * @return string207 */208 158 public function getSummaryRow(array $page = [], array $form = []): string 209 159 { … … 245 195 } 246 196 247 /**248 * AJAX import action249 *250 * @param array $form251 * @return array252 */253 197 public function ajaxImport(array $form): array 254 198 { … … 287 231 } 288 232 289 /** 290 * Get admin URL. 291 * 292 * @param string|null $step 293 * @return string 294 */ 295 private function _getAdminUrl(string $step = null): string 233 private function _getAdminUrl(?string $step = null): string 296 234 { 297 235 $url = 'admin.php?import=' . SLICKPLAN_PLUGIN_ID; … … 514 452 } 515 453 516 /**517 * Display AJAX import page.518 */519 454 private function _doImport(array $xml) 520 455 { … … 543 478 'content' => $form['content'] ?? '', 544 479 'content_lang' => $form['content_lang'] ?? '', 545 'content_files' => ( 546 isset($form['content'], $form['content_files']) 547 and $form['content'] === 'contents' 548 and $form['content_files'] 549 ), 480 'content_files' => (($form['content'] ?? '') === 'contents' && ($form['content_files'] ?? '')), 550 481 'create_menu' => (isset($form['create_menu']) and $form['create_menu']), 551 482 'post_type' => $form['page_type'] ?? 'page', … … 702 633 'menu-item-status' => 'publish', 703 634 'menu-item-parent-id' => $menu_parent, 704 ] 705 ); 635 ]); 706 636 } 707 637 … … 710 640 // All In One SEO Pack integration 711 641 $this->_importPageAioSeo($data['contents'], $page['ID']); 642 643 if ( 644 ($featuredImage = $data['contents']['meta_featured_image'] ?? null) 645 && filter_var($featuredImage['url'] ?? '', FILTER_VALIDATE_URL) 646 ) { 647 $file = $this->_addMedia($featuredImage['url'], [ 648 'alt' => $featuredImage['alt'] ?? '', 649 'title' => $featuredImage['title'] ?? '', 650 'file_name' => $featuredImage['file_name'] ?? '', 651 ], true); 652 if ($file['id'] ?? null) { 653 set_post_thumbnail($page['ID'], $file['id']); 654 } 655 } 712 656 713 657 $page['url'] = get_permalink($page['ID']); … … 802 746 } 803 747 804 /**805 * Replace internal links with correct pages URLs.806 *807 * @param $content808 * @param bool $force_parse809 * @return bool|string810 */811 748 private function _parseInternalLinks($content, bool $force_parse = false) 812 749 { … … 835 772 } 836 773 837 /** 838 * Check if there are any pages with unparsed internal links, if yes - replace links with real URLs 839 */ 840 private function _checkForInternalLinks() 774 private function _checkForInternalLinks(): void 841 775 { 842 776 if (isset($this->_options['internal_links']) and is_array($this->_options['internal_links'])) { … … 856 790 } 857 791 858 /**859 * @param array $element860 * @return array861 */862 792 private function _getPrependAppend(array $element): array 863 793 { … … 875 805 } 876 806 $tag = preg_replace('/[^a-z]+/', '', $tag); 877 $prepend = '<' .$tag;807 $prepend = '<' . $tag; 878 808 if (isset($element['options']['tag_id']) and $element['options']['tag_id']) { 879 $prepend .= ' id="' .esc_attr($element['options']['tag_id']).'"';809 $prepend .= ' id="' . esc_attr($element['options']['tag_id']) . '"'; 880 810 } 881 811 if (isset($element['options']['tag_class']) and $element['options']['tag_class']) { 882 $prepend .= ' class="' .esc_attr($element['options']['tag_class']).'"';812 $prepend .= ' class="' . esc_attr($element['options']['tag_class']) . '"'; 883 813 } 884 814 $prepend .= '>'; 885 $append = '</' .$tag.'>';815 $append = '</' . $tag . '>'; 886 816 } 887 817 } … … 889 819 } 890 820 891 /**892 * Get formatted HTML content.893 *894 * @param array|string|int $contents895 * @return string896 */897 821 private function _getFormattedContent($contents): string 898 822 { … … 991 915 } 992 916 993 /**994 * @param array $element995 * @return array996 */997 917 private function _getMediaElementArray(array $element): array 998 918 { … … 1003 923 } 1004 924 1005 /**1006 * @param array $element1007 * @return string1008 */1009 925 private function _getGutenbergBlock(array $element): string 1010 926 { … … 1167 1083 } 1168 1084 1169 /**1170 * Reformat title.1171 *1172 * @param array $data1173 * @return string1174 */1175 1085 private function _getFormattedTitle(array $data): string 1176 1086 { … … 1195 1105 } 1196 1106 1197 /** 1198 * Add a file to Media Library from URL 1199 * 1200 * @param $url 1201 * @param array $attrs 1202 * @return array|bool|WP_Error 1203 */ 1204 private function _addMedia($url, array $attrs = []) 1205 { 1206 if (!($this->_options['content_files'] ?? null)) { 1107 private function _addMedia($url, array $attrs = [], bool $forceAdd = false) 1108 { 1109 if (!($this->_options['content_files'] ?? null) && !$forceAdd) { 1207 1110 return false; 1208 1111 } … … 1254 1157 } 1255 1158 1256 /**1257 * Display importer errors.1258 *1259 * @param array|string $errors1260 */1261 1159 private function _displayError($errors) 1262 1160 { … … 1271 1169 } 1272 1170 1273 /**1274 * Display importer HTML form.1275 *1276 * @param bool $hide_info1277 */1278 1171 private function _displayUploadForm(bool $hide_info = false) 1279 1172 { … … 1310 1203 } 1311 1204 1312 /**1313 * Display importer page header HTML.1314 */1315 1205 private function _displayHeader() 1316 1206 { … … 1322 1212 } 1323 1213 1324 /**1325 * Display importer page footer HTML.1326 */1327 1214 private function _displayFooter() 1328 1215 { … … 1365 1252 } 1366 1253 1367 /**1368 * Display checkbox.1369 *1370 * @param $name1371 * @param string $label1372 * @param bool $checked1373 * @param string|array $description1374 * @param string|int $value1375 * @param string $type1376 * @param string $class1377 * @return string1378 */1379 1254 public function displayCheckbox( 1380 1255 $name, … … 1415 1290 } 1416 1291 1417 /**1418 * Display radio element.1419 *1420 * @param $name1421 * @param string $label1422 * @param string|int $value1423 * @param string|array $description1424 * @param bool $checked1425 * @param string $class1426 * @return string1427 */1428 1292 public function displayRadio( 1429 1293 $name, … … 1437 1301 } 1438 1302 1439 /**1440 * Display dropdown element with users.1441 *1442 * @param $name1443 */1444 1303 public function displayUsersDropdown($name, $selected = '') 1445 1304 { … … 1450 1309 } 1451 1310 1452 /**1453 * Display dropdown element with users.1454 */1455 1311 public function displayPageTypesDropdown($name = null, $includeManually = false, $label = 'Import as', $singularName = false, $value = null) 1456 1312 { … … 1507 1363 } 1508 1364 1509 /**1510 * Parse Slickplan's XML file. Converts an XML DOMDocument to an array.1511 *1512 * @param string $input_xml1513 * @return WP_Error|array1514 */1515 1365 private function _parseSlickplanXml(string $input_xml) 1516 1366 { … … 1577 1427 } 1578 1428 1579 /**1580 * Parse single node XML element.1581 *1582 * @param DOMElement|DOMNode $node1583 * @return array|string1584 */1585 1429 private function _parseSlickplanXmlNode($node) 1586 1430 { … … 1636 1480 } 1637 1481 1638 /**1639 * Check if the array is from a correct Slickplan XML file.1640 *1641 * @param array $array1642 * @param bool $parsed1643 * @return bool1644 */1645 1482 private function _isCorrectSlickplanXmlFile(array $array, bool $parsed = false): bool 1646 1483 { … … 1716 1553 } 1717 1554 1718 /**1719 * Get multidimensional array, put all child pages as nested array of the parent page.1720 *1721 * @param array $array1722 * @return array1723 */1724 1555 private function _getMultidimensionalArrayHelper(array $array): array 1725 1556 { … … 1805 1636 } 1806 1637 1807 /**1808 * @param array $cell1809 * @return string1810 */1811 1638 private function _getCellLevel(array $cell): string 1812 1639 { … … 1824 1651 } 1825 1652 1826 /**1827 * Put all child pages as nested array of the parent page.1828 *1829 * @param array $array1830 * @param string $parent1831 * @return array1832 */1833 1653 private function _getMultidimensionalArray(array $array, string $parent): array 1834 1654 { … … 1850 1670 } 1851 1671 1852 /**1853 * Sort cells.1854 *1855 * @param array $a1856 * @param array $b1857 * @return int1858 */1859 1672 private function _sortPages(array $a, array $b): int 1860 1673 { … … 1865 1678 } 1866 1679 1867 /**1868 * Change the WordPress language1869 *1870 * @param string $language1871 */1872 1680 private function _changeLanguage(string $language) 1873 1681 { … … 1890 1698 } 1891 1699 1892 1893 /**1894 * @param $title1895 * @param string $type1896 *1897 * @return string1898 */1899 1700 private function _metaTitle($title, string $type = 'yoast'): string 1900 1701 { … … 1907 1708 } 1908 1709 1909 /**1910 * @param string|int $slug1911 * @param string|int $pageName1912 *1913 * @return string1914 */1915 1710 private function _metaSlug($slug, $pageName): string 1916 1711 { … … 1918 1713 $slug = str_replace('%page_name%', $pageName, $slug); 1919 1714 $slug = str_replace('%separator%', '-', $slug); 1715 1920 1716 return $slug ? sanitize_title($slug) : ''; 1921 1717 } … … 1945 1741 } 1946 1742 1947 /**1948 * @return bool1949 */1950 1743 private function shouldUseGutenberg(): bool 1951 1744 { … … 2019 1812 } 2020 1813 2021 /**2022 * AJAX action2023 */2024 1814 function slickplan_importer_ajax_action() 2025 1815 {
Note: See TracChangeset
for help on using the changeset viewer.