@@ -3076,6 +3076,14 @@ private function importWordPressFile($file)
3076
3076
$ xml_str
3077
3077
);
3078
3078
$ obj = new SimpleXMLElement ($ xml_str , LIBXML_NOCDATA );
3079
+ $ redirects = [
3080
+ 'posts ' => [],
3081
+ 'categories ' => [],
3082
+ 'tags ' => [],
3083
+ 'authors ' => [],
3084
+ ];
3085
+ $ link = new Link ();
3086
+ $ default_lang = (int ) Context::getContext ()->language ->id ;
3079
3087
foreach ($ obj ->channel ->item as $ el ) {
3080
3088
// Post categories and post tags
3081
3089
$ post_categories = [];
@@ -3107,6 +3115,17 @@ private function importWordPressFile($file)
3107
3115
} else {
3108
3116
$ post_categories [] = $ category ->id ;
3109
3117
}
3118
+ $ old_path = '/category/ ' . (string ) $ wp_taxonomy ['nicename ' ];
3119
+ if (!isset ($ redirects ['categories ' ][$ old_path ])) {
3120
+ $ redirects ['categories ' ][$ old_path ] = $ link ->getModuleLink (
3121
+ 'everpsblog ' ,
3122
+ 'category ' ,
3123
+ [
3124
+ 'id_ever_category ' => $ category ->id ,
3125
+ 'link_rewrite ' => $ category ->link_rewrite [$ default_lang ],
3126
+ ]
3127
+ );
3128
+ }
3110
3129
} elseif ($ wp_taxonomy ->attributes ()['domain ' ] == 'post_tag '
3111
3130
&& (bool )Configuration::get ('EVERBLOG_IMPORT_TAGS ' ) === true
3112
3131
) {
@@ -3131,6 +3150,17 @@ private function importWordPressFile($file)
3131
3150
} else {
3132
3151
$ post_tags [] = $ tag ->id ;
3133
3152
}
3153
+ $ old_path = '/tag/ ' . (string ) $ wp_taxonomy ['nicename ' ];
3154
+ if (!isset ($ redirects ['tags ' ][$ old_path ])) {
3155
+ $ redirects ['tags ' ][$ old_path ] = $ link ->getModuleLink (
3156
+ 'everpsblog ' ,
3157
+ 'tag ' ,
3158
+ [
3159
+ 'id_ever_tag ' => $ tag ->id ,
3160
+ 'link_rewrite ' => $ tag ->link_rewrite [$ default_lang ],
3161
+ ]
3162
+ );
3163
+ }
3134
3164
}
3135
3165
}
3136
3166
// Post author
@@ -3156,6 +3186,18 @@ private function importWordPressFile($file)
3156
3186
$ author ->active = (bool ) Configuration::get ('EVERBLOG_ENABLE_AUTHORS ' );
3157
3187
$ result &= $ author ->save ();
3158
3188
}
3189
+ $ author_slug = Tools::str2url ((string ) $ el ->creator );
3190
+ $ old_path = '/author/ ' . $ author_slug ;
3191
+ if (!isset ($ redirects ['authors ' ][$ old_path ])) {
3192
+ $ redirects ['authors ' ][$ old_path ] = $ link ->getModuleLink (
3193
+ 'everpsblog ' ,
3194
+ 'author ' ,
3195
+ [
3196
+ 'id_ever_author ' => $ author ->id ,
3197
+ 'link_rewrite ' => $ author ->link_rewrite [$ default_lang ],
3198
+ ]
3199
+ );
3200
+ }
3159
3201
// Post
3160
3202
$ parsed_url = parse_url ((string ) $ el ->link );
3161
3203
$ host = $ parsed_url ['host ' ];
@@ -3225,6 +3267,7 @@ private function importWordPressFile($file)
3225
3267
$ post_content = preg_replace ('/<!--(.|\s)*?-->/ ' , '' , $ post_content );
3226
3268
$ post_content = preg_replace ("/(^[ \r\n]*|[ \r\n]+)[\s \t]*[ \r\n]+/ " , "\n" , $ post_content );
3227
3269
$ post_content = preg_replace ('#<script(.*?)>(.*?)</script>#is ' , '' , $ post_content );
3270
+ $ post_content = $ this ->cleanWpShortcodes ($ post_content );
3228
3271
$ post = new EverPsBlogPost ();
3229
3272
// Multilingual fields
3230
3273
foreach (Language::getLanguages (false ) as $ lang ) {
@@ -3283,8 +3326,31 @@ private function importWordPressFile($file)
3283
3326
$ result &= $ image ->save ();
3284
3327
}
3285
3328
}
3329
+ $ old_path = isset ($ parsed_url ['path ' ]) ? $ parsed_url ['path ' ] : '' ;
3330
+ if (!isset ($ redirects ['posts ' ][$ old_path ])) {
3331
+ $ redirects ['posts ' ][$ old_path ] = $ link ->getModuleLink (
3332
+ 'everpsblog ' ,
3333
+ 'post ' ,
3334
+ [
3335
+ 'id_ever_post ' => $ post ->id ,
3336
+ 'link_rewrite ' => $ post_link_rewrite ,
3337
+ ]
3338
+ );
3339
+ }
3340
+ }
3341
+ }
3342
+ $ redirect_lines = [];
3343
+ foreach ($ redirects as $ datas ) {
3344
+ foreach ($ datas as $ from => $ to ) {
3345
+ $ redirect_lines [] = 'Redirect 301 ' . rtrim ($ from , '/ ' ) . ' ' . $ to ;
3286
3346
}
3287
3347
}
3348
+ if (!empty ($ redirect_lines )) {
3349
+ file_put_contents (
3350
+ dirname (__FILE__ ) . '/wordpress_redirects.txt ' ,
3351
+ implode (PHP_EOL , $ redirect_lines )
3352
+ );
3353
+ }
3288
3354
// Reset iframes
3289
3355
if ((bool ) $ allow_iframes === false ) {
3290
3356
Configuration::updateValue ('PS_ALLOW_HTML_IFRAME ' , false );
@@ -3664,6 +3730,11 @@ public static function getConfigInMultipleLangs($key, $idShopGroup = null, $idSh
3664
3730
return $ resultsArray ;
3665
3731
}
3666
3732
3733
+ private function cleanWpShortcodes ($ html )
3734
+ {
3735
+ return preg_replace ('/\[(?!everpsblog)(?:\/)?[\w\-]+(?:\s[^\]]*)?\]/i ' , '' , $ html );
3736
+ }
3737
+
3667
3738
private function parseShortcodes ($ html )
3668
3739
{
3669
3740
return preg_replace_callback ('/\[everpsblog([^\]]*)\]/i ' , function ($ m ) {
0 commit comments