-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.php
More file actions
165 lines (140 loc) · 4.23 KB
/
import.php
File metadata and controls
165 lines (140 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
// Load WordPress
require_once './wp-load.php';
require_once './wp-admin/includes/taxonomy.php';
ini_set('memory_limit', '2048M');
// Set the timezone so times are calculated correctly
date_default_timezone_set('Europe/Paris');
function traitement_youtube($content){
$re = '/(\<div.+youtube\.com\/watch\?v=(\w+).+\<\/div\>)/';
//$replacement = "<iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/$2\" frameborder=\"0\" allowfullscreen></iframe>";
$replacement = "http://www.youtube.com/watch?v=$2";
$content = preg_replace($re, $replacement, $content);
//preg_match_all($re, $content, $matches, PREG_SET_ORDER, 0);
return $content;
}
function insert_news($news_id,$old_newsid) {
$host = "localhost";
$dbname = "wp";
$login_db = "root";
$pwd_db = "";
$bdd = new PDO('mysql:host='.$host.';dbname='.$dbname.';charset=utf8', $login_db , $pwd_db);
$reponse = $bdd->query('insert into wp_transpo_news values(\''.$news_id.'\','.$old_newsid.');');
$donnees = $reponse->fetch();
}
function update_news($news_id,$old_newsid) {
$host = "localhost";
$dbname = "wp";
$login_db = "root";
$pwd_db = "";
$bdd = new PDO('mysql:host='.$host.';dbname='.$dbname.';charset=utf8', $login_db , $pwd_db);
$reponse = $bdd->query('update wp_posts set ID = '.$old_newsid.' where ID = '.$news_id.';');
$donnees = $reponse->fetch();
return $old_newsid;
}
function get_user($oldid) {
$host = "localhost";
$dbname = "wp";
$login_db = "root";
$pwd_db = "";
$bdd = new PDO('mysql:host='.$host.';dbname='.$dbname.';charset=utf8', $login_db , $pwd_db);
$reponse = $bdd->query('select * from wp_transpo_authors where author_id=\''.$oldid.'\';');
$donnees = $reponse->fetch();
return $donnees['id'];
}
function get_game($id) {
$host = "localhost";
$dbname = "nofrag_old";
$login_db = "root";
$pwd_db = "";
$bdd = new PDO('mysql:host='.$host.';dbname='.$dbname.';charset=utf8', $login_db , $pwd_db);
$reponse = $bdd->query('select * from games where id=\''.$id.'\';');
$donnees = $reponse->fetch();
return $donnees['name'];
}
$host = "localhost";
$dbname = "nofrag_old";
$login_db = "root";
$pwd_db = "";
$bdd = new PDO('mysql:host='.$host.';dbname='.$dbname.';charset=utf8', $login_db , $pwd_db);
$reponse = $bdd->query('select * from news order by news_id desc;');
$i = 0;
while ($donnees = $reponse->fetch()){
$content = traitement_youtube($donnees['content']);
// Create post
$id = wp_insert_post(array(
'post_title' => $donnees['title'],
'post_content' => $content,
'post_date' => $donnees['date'],
'post_author' => get_user($donnees['author_id']),
'post_type' => "post",
'post_status' => 'publish',
));
if ($id) {
$id = update_news($id,$id+200000);
insert_news($id,$donnees['news_id']);
// Set category - create if it doesn't exist yet
if ($donnees['game_id'] > 0){
$jeu = get_game($donnees['game_id']);
wp_set_post_tags($id, $jeu, false);
}
switch ($donnees['type']){
//annonce
case '9':
wp_set_post_terms($id, 147, 'category');
break ;
//chroniques
case '23':
wp_set_post_terms($id, 132, 'category');
break;
// bullshit
case '36' :
wp_set_post_terms($id, 144, 'category');
break ;
// business
case '20' :
wp_set_post_terms($id, 141, 'category');
break;
// dossiers
case '22' :
wp_set_post_terms($id, 133, 'category');
break;
// mod
case '15' :
wp_set_post_terms($id, 146, 'category');
break;
// vrac
case '18' :
wp_set_post_terms($id, 142, 'category');
break ;
// patch
case '7' :
wp_set_post_terms($id, 143, 'category');
break ;
// preview
case '2' :
wp_set_post_terms($id, 131, 'category');
break ;
// bons plans
case '35' :
wp_set_post_terms($id, 134, 'category');
break;
//Tests
case '12' :
wp_set_post_terms($id, 129, 'category');
break;
//vidéos
case '6':
wp_set_post_terms($id, 145, 'category');
break;
default :
// news par défaut
wp_set_post_terms($id, 130, 'category');
}
$i++;
} else {
echo "WARNING: Failed to insert post into WordPress\n";
}
}
echo "ok ".$i;
?>