Changeset 3730:5c45a5df9a59 for plugins/importExport/inc
- Timestamp:
- 03/08/18 17:58:39 (8 years ago)
- Branch:
- default
- Location:
- plugins/importExport/inc
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/importExport/inc/class.dc.ieModule.php
r2825 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 abstract class dcIeModule 15 15 { 16 17 18 19 16 public $type; 17 public $id; 18 public $name; 19 public $description; 20 20 21 22 23 21 protected $import_url; 22 protected $export_url; 23 protected $core; 24 24 25 26 27 $this->core =&$core;28 25 public function __construct($core) 26 { 27 $this->core = &$core; 28 $this->setInfo(); 29 29 30 if (!in_array($this->type,array('import','export'))) {31 throw new Exception(sprintf('Unknow type for module %s',get_class($this)));32 30 if (!in_array($this->type, array('import', 'export'))) { 31 throw new Exception(sprintf('Unknow type for module %s', get_class($this))); 32 } 33 33 34 35 36 34 if (!$this->name) { 35 $this->name = get_class($this); 36 } 37 37 38 $this->id= get_class($this);39 $this->url = sprintf('plugin.php?p=importExport&type=%s&module=%s',$this->type,$this->id);40 38 $this->id = get_class($this); 39 $this->url = sprintf('plugin.php?p=importExport&type=%s&module=%s', $this->type, $this->id); 40 } 41 41 42 43 44 42 public function init() 43 { 44 } 45 45 46 46 abstract protected function setInfo(); 47 47 48 final public function getURL($escape=false)49 50 51 48 final public function getURL($escape = false) 49 { 50 return $escape ? html::escapeHTML($this->url) : $this->url; 51 } 52 52 53 53 abstract public function process($do); 54 54 55 55 abstract public function gui(); 56 56 57 58 59 60 61 62 63 return '<div class="ie-progress"><div style="width:'.$percent.'%">'.$percent.' %</div></div>';64 57 protected function progressBar($percent) 58 { 59 $percent = ceil($percent); 60 if ($percent > 100) { 61 $percent = 100; 62 } 63 return '<div class="ie-progress"><div style="width:' . $percent . '%">' . $percent . ' %</div></div>'; 64 } 65 65 66 67 68 return form::hidden(array('autosubmit'),1);69 66 protected function autoSubmit() 67 { 68 return form::hidden(array('autosubmit'), 1); 69 } 70 70 71 72 73 74 '<h3>'.__('Congratulation!').'</h3>'.75 '<p class="success">'.__('Your blog has been successfully imported. Welcome on Dotclear 2!').'</p>'.76 '<ul><li><strong><a href="'.$this->core->decode('admin.post').'">'.__('Why don\'t you blog this now?').'</a></strong></li>'.77 '<li>'.__('or').' <a href="'.$this->core->decode('admin.home').'">'.__('visit your dashboard').'</a></li></ul>';78 71 protected function congratMessage() 72 { 73 return 74 '<h3>' . __('Congratulation!') . '</h3>' . 75 '<p class="success">' . __('Your blog has been successfully imported. Welcome on Dotclear 2!') . '</p>' . 76 '<ul><li><strong><a href="' . $this->core->decode('admin.post') . '">' . __('Why don\'t you blog this now?') . '</a></strong></li>' . 77 '<li>' . __('or') . ' <a href="' . $this->core->decode('admin.home') . '">' . __('visit your dashboard') . '</a></li></ul>'; 78 } 79 79 } -
plugins/importExport/inc/flat/class.flat.backup.php
r3393 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class flatBackup 15 15 { 16 17 18 19 16 protected $fp; 17 private $line_cols = array(); 18 private $line_name; 19 private $line_num; 20 20 21 22 23 24 25 '/(\\\\\\\\)/'=> '\\'26 21 private $replacement = array( 22 '/(?<!\\\\)(?>(\\\\\\\\)*+)(\\\\n)/u' => "\$1\n", 23 '/(?<!\\\\)(?>(\\\\\\\\)*+)(\\\\r)/u' => "\$1\r", 24 '/(?<!\\\\)(?>(\\\\\\\\)*+)(\\\\")/u' => '$1"', 25 '/(\\\\\\\\)/' => '\\' 26 ); 27 27 28 29 30 31 $this->fp = fopen($file,'rb');32 33 34 35 36 28 public function __construct($file) 29 { 30 if (file_exists($file) && is_readable($file)) { 31 $this->fp = fopen($file, 'rb'); 32 $this->line_num = 1; 33 } else { 34 throw new Exception(__('No file to read.')); 35 } 36 } 37 37 38 39 40 41 42 43 38 public function __destruct() 39 { 40 if ($this->fp) { 41 @fclose($this->fp); 42 } 43 } 44 44 45 46 47 48 49 45 public function getLine() 46 { 47 if (($line = $this->nextLine()) === false) { 48 return false; 49 } 50 50 51 if (substr($line,0,1) == '[') 52 { 53 $this->line_name = substr($line,1,strpos($line,' ')-1); 51 if (substr($line, 0, 1) == '[') { 52 $this->line_name = substr($line, 1, strpos($line, ' ') - 1); 54 53 55 $line = substr($line,strpos($line,' ')+1,-1);56 $this->line_cols = explode(',',$line);54 $line = substr($line, strpos($line, ' ') + 1, -1); 55 $this->line_cols = explode(',', $line); 57 56 58 return $this->getLine(); 59 } 60 elseif (substr($line,0,1) == '"') 61 { 62 $line = preg_replace('/^"|"$/','',$line); 63 $line = preg_split('/(^"|","|(?<!\\\)\"$)/m',$line); 57 return $this->getLine(); 58 } elseif (substr($line, 0, 1) == '"') { 59 $line = preg_replace('/^"|"$/', '', $line); 60 $line = preg_split('/(^"|","|(?<!\\\)\"$)/m', $line); 64 61 65 66 throw new Exception(sprintf('Invalid row count at line %s',$this->line_num));67 62 if (count($this->line_cols) != count($line)) { 63 throw new Exception(sprintf('Invalid row count at line %s', $this->line_num)); 64 } 68 65 69 66 $res = array(); 70 67 71 for ($i=0; $i<count($line); $i++) {72 73 preg_replace(array_keys($this->replacement),array_values($this->replacement),$line[$i]);74 68 for ($i = 0; $i < count($line); $i++) { 69 $res[$this->line_cols[$i]] = 70 preg_replace(array_keys($this->replacement), array_values($this->replacement), $line[$i]); 71 } 75 72 76 return new flatBackupItem($this->line_name,$res,$this->line_num); 77 } 78 else 79 { 80 return $this->getLine(); 81 } 82 } 73 return new flatBackupItem($this->line_name, $res, $this->line_num); 74 } else { 75 return $this->getLine(); 76 } 77 } 83 78 84 85 86 87 88 89 79 private function nextLine() 80 { 81 if (feof($this->fp)) { 82 return false; 83 } 84 $this->line_num++; 90 85 91 92 86 $line = fgets($this->fp); 87 $line = trim($line); 93 88 94 95 89 return empty($line) ? $this->nextLine() : $line; 90 } 96 91 } 97 92 98 93 class flatBackupItem 99 94 { 100 101 102 95 public $__name; 96 public $__line; 97 private $__data = array(); 103 98 104 public function __construct($name,$data,$line)105 106 107 108 109 99 public function __construct($name, $data, $line) 100 { 101 $this->__name = $name; 102 $this->__data = $data; 103 $this->__line = $line; 104 } 110 105 111 112 113 return iconv('UTF-8','UTF-8//IGNORE',$this->__data[$name]);114 106 public function f($name) 107 { 108 return iconv('UTF-8', 'UTF-8//IGNORE', $this->__data[$name]); 109 } 115 110 116 117 118 119 111 public function __get($name) 112 { 113 return $this->f($name); 114 } 120 115 121 public function __set($n,$v)122 123 124 116 public function __set($n, $v) 117 { 118 $this->__data[$n] = $v; 119 } 125 120 126 127 128 129 121 public function exists($n) 122 { 123 return isset($this->__data[$n]); 124 } 130 125 131 132 133 134 135 136 137 138 126 public function drop() 127 { 128 foreach (func_get_args() as $n) { 129 if (isset($this->__data[$n])) { 130 unset($this->__data[$n]); 131 } 132 } 133 } 139 134 140 public function substitute($old,$new)141 142 143 144 145 146 135 public function substitute($old, $new) 136 { 137 if (isset($this->__data[$old])) { 138 $this->__data[$new] = $this->__data[$old]; 139 unset($this->__data[$old]); 140 } 141 } 147 142 } -
plugins/importExport/inc/flat/class.flat.export.php
r2566 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class flatExport 15 15 { 16 17 16 private $con; 17 private $prefix; 18 18 19 private $line_reg = array('/\\\\/u', '/\n/u','/\r/u','/"/u');20 private $line_rep = array('\\\\\\\\', '\n' ,'\r' ,'\"');19 private $line_reg = array('/\\\\/u', '/\n/u', '/\r/u', '/"/u'); 20 private $line_rep = array('\\\\\\\\', '\n', '\r', '\"'); 21 21 22 22 public $fp; 23 23 24 function __construct($con,$out='php://output',$prefix=null)25 26 $this->con =&$con;27 24 public function __construct($con, $out = 'php://output', $prefix = null) 25 { 26 $this->con = &$con; 27 $this->prefix = $prefix; 28 28 29 if (($this->fp = fopen($out,'w')) === false) {30 31 32 33 29 if (($this->fp = fopen($out, 'w')) === false) { 30 return false; 31 } 32 @set_time_limit(300); 33 } 34 34 35 36 37 38 39 40 35 public function __destruct() 36 { 37 if (is_resource($this->fp)) { 38 fclose($this->fp); 39 } 40 } 41 41 42 function export($name,$sql)43 44 42 public function export($name, $sql) 43 { 44 $rs = $this->con->select($sql); 45 45 46 if (!$rs->isEmpty()) 47 { 48 fwrite($this->fp,"\n[".$name.' '.implode(',',$rs->columns())."]\n"); 49 while ($rs->fetch()) { 50 fwrite($this->fp,$this->getLine($rs)); 51 } 52 fflush($this->fp); 53 } 54 } 46 if (!$rs->isEmpty()) { 47 fwrite($this->fp, "\n[" . $name . ' ' . implode(',', $rs->columns()) . "]\n"); 48 while ($rs->fetch()) { 49 fwrite($this->fp, $this->getLine($rs)); 50 } 51 fflush($this->fp); 52 } 53 } 55 54 56 57 58 55 public function exportAll() 56 { 57 $tables = $this->getTables(); 59 58 60 foreach ($tables as $table) 61 { 62 $this->exportTable($table); 63 } 64 } 59 foreach ($tables as $table) { 60 $this->exportTable($table); 61 } 62 } 65 63 66 67 68 $req = 'SELECT * FROM '.$this->con->escapeSystem($this->prefix.$table);64 public function exportTable($table) 65 { 66 $req = 'SELECT * FROM ' . $this->con->escapeSystem($this->prefix . $table); 69 67 70 $this->export($table,$req);71 68 $this->export($table, $req); 69 } 72 70 73 74 75 $schema= dbSchema::init($this->con);76 71 public function getTables() 72 { 73 $schema = dbSchema::init($this->con); 74 $db_tables = $schema->getTables(); 77 75 78 $tables = array(); 79 foreach ($db_tables as $t) 80 { 81 if ($this->prefix) { 82 if (strpos($t,$this->prefix) === 0) { 83 $tables[] = $t; 84 } 85 } else { 86 $tables[] = $t; 87 } 88 } 76 $tables = array(); 77 foreach ($db_tables as $t) { 78 if ($this->prefix) { 79 if (strpos($t, $this->prefix) === 0) { 80 $tables[] = $t; 81 } 82 } else { 83 $tables[] = $t; 84 } 85 } 89 86 90 91 87 return $tables; 88 } 92 89 93 94 95 $l= array();96 97 98 $s= $rs->f($c);99 $s = preg_replace($this->line_reg,$this->line_rep,$s);100 $s = '"'.$s.'"';101 102 103 return implode(',',$l)."\n";104 90 public function getLine($rs) 91 { 92 $l = array(); 93 $cols = $rs->columns(); 94 foreach ($cols as $i => &$c) { 95 $s = $rs->f($c); 96 $s = preg_replace($this->line_reg, $this->line_rep, $s); 97 $s = '"' . $s . '"'; 98 $l[$i] = $s; 99 } 100 return implode(',', $l) . "\n"; 101 } 105 102 } -
plugins/importExport/inc/flat/class.flat.import.php
r3606 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class flatImport extends flatBackup 15 15 { 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 'post'=> array(),33 'media'=> array()34 35 36 37 'categories'=>null,38 'cat_id'=>1,39 'cat_lft'=>array(),40 'post_id'=>1,41 'media_id'=>1,42 'comment_id'=>1,43 'link_id'=>1,44 'log_id'=> 145 46 47 48 49 public function __construct($core,$file)50 51 52 53 54 if (strpos($first_line,'///DOTCLEAR|') !== 0) {55 56 57 58 59 60 $l = explode('|',$first_line);61 62 63 64 65 66 67 68 69 70 71 if (version_compare('1.2',$this->dc_version,'<=') &&72 version_compare('1.3',$this->dc_version,'>')) {73 74 75 76 77 78 $this->core =&$core;79 $this->con =&$core->con;80 81 82 $this->cur_blog = $this->con->openCursor($this->prefix.'blog');83 $this->cur_category = $this->con->openCursor($this->prefix.'category');84 $this->cur_link = $this->con->openCursor($this->prefix.'link');85 $this->cur_setting = $this->con->openCursor($this->prefix.'setting');86 $this->cur_user = $this->con->openCursor($this->prefix.'user');87 $this->cur_pref = $this->con->openCursor($this->prefix.'pref');88 $this->cur_permissions = $this->con->openCursor($this->prefix.'permissions');89 $this->cur_post = $this->con->openCursor($this->prefix.'post');90 $this->cur_meta = $this->con->openCursor($this->prefix.'meta');91 $this->cur_media = $this->con->openCursor($this->prefix.'media');92 $this->cur_post_media = $this->con->openCursor($this->prefix.'post_media');93 $this->cur_log = $this->con->openCursor($this->prefix.'log');94 $this->cur_ping = $this->con->openCursor($this->prefix.'ping');95 $this->cur_comment = $this->con->openCursor($this->prefix.'comment');96 $this->cur_spamrule = $this->con->openCursor($this->prefix.'spamrule');97 $this->cur_version = $this->con->openCursor($this->prefix.'version');98 99 100 $this->core->callBehavior('importInit',$this,$this->core);101 102 103 104 105 106 107 108 109 if (!$this->core->auth->check('admin',$this->core->blog->id)) {110 111 112 113 114 115 116 'SELECT cat_id, cat_title, cat_url '.117 'FROM '.$this->prefix.'category '.118 "WHERE blog_id = '".$this->con->escape($this->blog_id)."' "119 120 121 $rs = $this->con->select('SELECT MAX(cat_id) FROM '.$this->prefix.'category');122 $this->stack['cat_id'] = ((integer) $rs->f(0))+1;123 124 $rs = $this->con->select('SELECT MAX(link_id) FROM '.$this->prefix.'link');125 $this->stack['link_id'] = ((integer) $rs->f(0))+1;126 127 $rs = $this->con->select('SELECT MAX(post_id) FROM '.$this->prefix.'post');128 $this->stack['post_id'] = ((integer) $rs->f(0))+1;129 130 $rs = $this->con->select('SELECT MAX(media_id) FROM '.$this->prefix.'media');131 $this->stack['media_id'] = ((integer) $rs->f(0))+1;132 133 $rs = $this->con->select('SELECT MAX(comment_id) FROM '.$this->prefix.'comment');134 $this->stack['comment_id'] = ((integer) $rs->f(0))+1;135 136 $rs = $this->con->select('SELECT MAX(log_id) FROM '.$this->prefix.'log');137 $this->stack['log_id'] = ((integer) $rs->f(0))+1;138 139 140 'SELECT MAX(cat_rgt) AS cat_rgt FROM '.$this->prefix.'category '.141 "WHERE blog_id = '".$this->con->escape($this->core->blog->id)."'"142 143 144 145 $this->has_categories= true;146 147 148 149 150 151 152 153 154 $constrained= array('post', 'meta', 'post_media', 'ping', 'comment');155 156 while (($line = $this->getLine()) !== false) 157 { 158 # import DC 1.2.x, we fix lines before insert 159 if ($this->dc_major_version == '1.2') { 160 $this->prepareDC12line($line); 161 } 162 163 if ($last_line_name != $line->__name) {164 if (in_array($last_line_name,$constrained)) { 165 # UNDEFER 166 if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli' || $this->con->driver() == 'mysqlimb4')$this->con->execute('SET foreign_key_checks = 1');167 if ($this->con->driver() == 'pgsql') $this->con->execute('SET CONSTRAINTS ALL DEFERRED'); 168 } 169 170 if (in_array($line->__name,$constrained)) { 171 # DEFER 172 if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli' || $this->con->driver() == 'mysqlimb4') $this->con->execute('SET foreign_key_checks = 0'); 173 if ($this->con->driver() == 'pgsql') $this->con->execute('SET CONSTRAINTS ALL IMMEDIATE'); 174 } 175 176 $last_line_name = $line->__name; 177 } 178 179 switch ($line->__name) 180 { 181 case 'category': 182 $this->insertCategorySingle($line);183 break; 184 case 'link': 185 $this->insertLinkSingle($line); 186 break; 187 case 'post': 188 $this->insertPostSingle($line); 189 break; 190 case 'meta': 191 $this->insertMetaSingle($line); 192 break;193 case 'media': 194 $this->insertMediaSingle($line); 195 break;196 case 'post_media': 197 $this->insertPostMediaSingle($line); 198 break;199 case 'ping': 200 $this->insertPingSingle($line); 201 break;202 case 'comment': 203 $this->insertCommentSingle($line); 204 break;205 } 206 207 # --BEHAVIOR-- importSingle 208 $this->core->callBehavior('importSingle',$line,$this,$this->core);209 } 210 211 if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli' || $this->con->driver() == 'mysqlimb4') $this->con->execute('SET foreign_key_checks = 1');212 if ($this->con->driver() == 'pgsql') $this->con->execute('SET CONSTRAINTS ALL DEFERRED'); 213 } 214 catch (Exception $e) 215 { 216 @fclose($this->fp); 217 $this->con->rollback(); 218 throw new Exception($e->getMessage().' - '.sprintf(__('Error raised at line %s'),$line->__line));219 220 @fclose($this->fp); 221 $this->con->commit(); 222 } 223 224 public function importFull() 225 226 if ($this->mode != 'full') { 227 throw new Exception(__('File is not a full export.')); 228 } 229 230 if (!$this->core->auth->isSuperAdmin()) { 231 throw new Exception(__('Permission denied.'));232 } 233 234 $this->con->begin();235 $this->con->execute('DELETE FROM '.$this->prefix.'blog');236 $this->con->execute('DELETE FROM '.$this->prefix.'media'); 237 $this->con->execute('DELETE FROM '.$this->prefix.'spamrule'); 238 $this->con->execute('DELETE FROM '.$this->prefix.'setting'); 239 $this->con->execute('DELETE FROM '.$this->prefix.'log'); 240 241 try 242 { 243 while (($line = $this->getLine()) !== false) 244 245 switch ($line->__name) 246 { 247 case 'blog': 248 $this->insertBlog($line);249 break;250 case 'category': 251 $this->insertCategory($line);252 break;253 case 'link': 254 $this->insertLink($line); 255 break; 256 case 'setting': 257 $this->insertSetting($line); 258 break; 259 case 'user':260 $this->insertUser($line);261 262 case 'pref':263 $this->insertPref($line);264 265 case 'permissions':266 $this->insertPermissions($line);267 268 case 'post':269 $this->insertPost($line);270 271 case 'meta':272 $this->insertMeta($line);273 274 case 'media':275 $this->insertMedia($line);276 277 case 'post_media':278 $this->insertPostMedia($line);279 280 case 'log'; 281 $this->insertLog($line);282 283 case 'ping':284 $this->insertPing($line);285 286 case 'comment':287 $this->insertComment($line);288 289 case 'spamrule':290 $this->insertSpamRule($line);291 292 } 293 # --BEHAVIOR-- importFull 294 $this->core->callBehavior('importFull',$line,$this,$this->core);295 } 296 } 297 catch (Exception $e) 298 { 299 @fclose($this->fp);300 $this->con->rollback();301 throw new Exception($e->getMessage().' - '.sprintf(__('Error raised at line %s'),$line->__line)); 302 } 303 @fclose($this->fp);304 $this->con->commit(); 305 } 306 307 private function insertBlog($blog) 308 309 $this->cur_blog->clean();310 311 $this->cur_blog->blog_id = (string) $blog->blog_id;312 $this->cur_blog->blog_uid = (string) $blog->blog_uid; 313 $this->cur_blog->blog_creadt = (string) $blog->blog_creadt;314 $this->cur_blog->blog_upddt = (string) $blog->blog_upddt;315 $this->cur_blog->blog_url = (string) $blog->blog_url; 316 $this->cur_blog->blog_name = (string) $blog->blog_name; 317 $this->cur_blog->blog_desc = (string) $blog->blog_desc; 318 319 $this->cur_blog->blog_status = $blog->exists('blog_status') ? (integer) $blog->blog_status : 1;320 321 $this->cur_blog->insert();322 } 323 324 private function insertCategory($category) 325 { 326 $this->cur_category->clean();327 328 $this->cur_category->cat_id = (string) $category->cat_id; 329 $this->cur_category->blog_id = (string) $category->blog_id;330 $this->cur_category->cat_title = (string) $category->cat_title; 331 $this->cur_category->cat_url = (string) $category->cat_url;332 $this->cur_category->cat_desc = (string) $category->cat_desc; 333 334 if (!$this->has_categories && $category->exists('cat_lft') && $category->exists('cat_rgt')) { 335 $this->cur_category->cat_lft = (integer) $category->cat_lft; 336 $this->cur_category->cat_rgt = (integer) $category->cat_rgt;337 } else { 338 if (!isset($this->stack['cat_lft'][$category->blog_id])) { 339 $this->stack['cat_lft'][$category->blog_id] = 2;340 } 341 $this->cur_category->cat_lft = $this->stack['cat_lft'][$category->blog_id]++;342 $this->cur_category->cat_rgt = $this->stack['cat_lft'][$category->blog_id]++;343 } 344 345 $this->cur_category->insert();346 } 347 348 private function insertLink($link) 349 { 350 $this->cur_link->clean(); 351 352 $this->cur_link->link_id = (integer) $link->link_id;353 $this->cur_link->blog_id = (string) $link->blog_id; 354 $this->cur_link->link_href = (string) $link->link_href; 355 $this->cur_link->link_title = (string) $link->link_title;356 $this->cur_link->link_desc = (string) $link->link_desc; 357 $this->cur_link->link_lang = (string) $link->link_lang; 358 $this->cur_link->link_xfn = (string) $link->link_xfn; 359 $this->cur_link->link_position = (integer) $link->link_position; 360 361 $this->cur_link->insert(); 362 } 363 364 private function insertSetting($setting) 365 { 366 $this->cur_setting->clean();367 368 $this->cur_setting->setting_id = (string) $setting->setting_id;369 $this->cur_setting->blog_id = !$setting->blog_id ? null : (string) $setting->blog_id;370 $this->cur_setting->setting_ns = (string) $setting->setting_ns; 371 $this->cur_setting->setting_value = (string) $setting->setting_value;372 $this->cur_setting->setting_type = (string) $setting->setting_type; 373 $this->cur_setting->setting_label = (string) $setting->setting_label; 374 375 $this->cur_setting->insert(); 376 } 377 378 private function insertPref($pref) 379 { 380 if ($this->prefExists($pref->pref_ws,$pref->pref_id,$pref->user_id)) { 381 return;382 } 383 384 $this->cur_pref->clean(); 385 386 $this->cur_pref->pref_id = (string) $pref->pref_id; 387 $this->cur_pref->user_id = !$pref->user_id ? null : (string) $pref->user_id; 388 $this->cur_pref->pref_ws = (string) $pref->pref_ws; 389 $this->cur_pref->pref_value = (string) $pref->pref_value; 390 $this->cur_pref->pref_type = (string) $pref->pref_type; 391 $this->cur_pref->pref_label = (string) $pref->pref_label;392 393 $this->cur_pref->insert(); 394 } 395 396 private function insertUser($user) 397 { 398 if ($this->userExists($user->user_id)) { 399 return;400 } 401 402 $this->cur_user->clean(); 403 404 $this->cur_user->user_id = (string) $user->user_id; 405 $this->cur_user->user_super = (integer) $user->user_super; 406 $this->cur_user->user_pwd = (string) $user->user_pwd; 407 $this->cur_user->user_recover_key = (string) $user->user_recover_key; 408 $this->cur_user->user_name = (string) $user->user_name; 409 $this->cur_user->user_firstname = (string) $user->user_firstname;410 $this->cur_user->user_displayname = (string) $user->user_displayname; 411 $this->cur_user->user_email = (string) $user->user_email; 412 $this->cur_user->user_url = (string) $user->user_url;413 $this->cur_user->user_default_blog = !$user->user_default_blog ? null : (string) $user->user_default_blog; 414 $this->cur_user->user_lang = (string) $user->user_lang;415 $this->cur_user->user_tz = (string) $user->user_tz;416 $this->cur_user->user_post_status = (integer) $user->user_post_status;417 $this->cur_user->user_creadt = (string) $user->user_creadt;418 $this->cur_user->user_upddt = (string) $user->user_upddt;419 420 $this->cur_user->user_desc = $user->exists('user_desc') ? (string) $user->user_desc : null;421 $this->cur_user->user_options = $user->exists('user_options') ? (string) $user->user_options : null;422 $this->cur_user->user_status = $user->exists('user_status') ? (integer) $user->user_status : 1;423 424 $this->cur_user->insert();425 426 $this->stack['users'][$user->user_id] = true;427 } 428 429 private function insertPermissions($permissions) 430 { 431 $this->cur_permissions->clean();432 433 $this->cur_permissions->user_id = (string) $permissions->user_id; 434 $this->cur_permissions->blog_id = (string) $permissions->blog_id;435 $this->cur_permissions->permissions = (string) $permissions->permissions; 436 437 $this->cur_permissions->insert(); 438 } 439 440 private function insertPost($post) 441 { 442 $this->cur_post->clean(); 443 444 $cat_id = (integer) $post->cat_id;445 if (!$cat_id) { 446 $cat_id = null; 447 } 448 449 $post_password = $post->post_password ? (string) $post->post_password : null; 450 451 $this->cur_post->post_id = (integer) $post->post_id; 452 $this->cur_post->blog_id = (string) $post->blog_id;453 $this->cur_post->user_id = (string) $this->getUserId($post->user_id); 454 $this->cur_post->cat_id = $cat_id;455 $this->cur_post->post_dt = (string) $post->post_dt; 456 $this->cur_post->post_creadt = (string) $post->post_creadt;457 $this->cur_post->post_upddt = (string) $post->post_upddt; 458 $this->cur_post->post_password = $post_password; 459 $this->cur_post->post_type = (string) $post->post_type;460 $this->cur_post->post_format = (string) $post->post_format; 461 $this->cur_post->post_url = (string) $post->post_url;462 $this->cur_post->post_lang = (string) $post->post_lang;463 $this->cur_post->post_title = (string) $post->post_title;464 $this->cur_post->post_excerpt = (string) $post->post_excerpt;465 $this->cur_post->post_excerpt_xhtml = (string) $post->post_excerpt_xhtml;466 $this->cur_post->post_content = (string) $post->post_content;467 $this->cur_post->post_content_xhtml = (string) $post->post_content_xhtml;468 $this->cur_post->post_notes = (string) $post->post_notes;469 $this->cur_post->post_words = (string) $post->post_words;470 $this->cur_post->post_meta = (string) $post->post_meta;471 $this->cur_post->post_status = (integer) $post->post_status;472 $this->cur_post->post_selected = (integer) $post->post_selected;473 $this->cur_post->post_open_comment = (integer) $post->post_open_comment;474 $this->cur_post->post_open_tb = (integer) $post->post_open_tb;475 $this->cur_post->nb_comment = (integer) $post->nb_comment;476 $this->cur_post->nb_trackback = (integer) $post->nb_trackback;477 $this->cur_post->post_position = (integer) $post->post_position;478 479 $this->cur_post->post_tz = $post->exists('post_tz') ? (string) $post->post_tz : 'UTC';480 481 $this->cur_post->insert();482 } 483 484 private function insertMeta($meta) 485 { 486 $this->cur_meta->clean();487 488 $this->cur_meta->meta_id = (string) $meta->meta_id; 489 $this->cur_meta->meta_type = (string) $meta->meta_type;490 $this->cur_meta->post_id = (integer) $meta->post_id; 491 492 $this->cur_meta->insert(); 493 } 494 495 private function insertMedia($media) 496 { 497 $this->cur_media->clean(); 498 499 $this->cur_media->media_id = (integer) $media->media_id;500 $this->cur_media->user_id = (string) $media->user_id;501 $this->cur_media->media_path = (string) $media->media_path; 502 $this->cur_media->media_title = (string) $media->media_title;503 $this->cur_media->media_file = (string) $media->media_file; 504 $this->cur_media->media_meta = (string) $media->media_meta; 505 $this->cur_media->media_dt = (string) $media->media_dt; 506 $this->cur_media->media_creadt = (string) $media->media_creadt; 507 $this->cur_media->media_upddt = (string) $media->media_upddt;508 $this->cur_media->media_private = (integer) $media->media_private; 509 510 $this->cur_media->media_dir = $media->exists('media_dir') ? (string) $media->media_dir : dirname($media->media_file);511 512 if (!$this->mediaExists()) { 513 $this->cur_media->insert();514 } 515 } 516 517 private function insertPostMedia($post_media) 518 { 519 $this->cur_post_media->clean(); 520 521 $this->cur_post_media->media_id = (integer) $post_media->media_id; 522 $this->cur_post_media->post_id = (integer) $post_media->post_id; 523 524 $this->cur_post_media->insert(); 525 526 527 private function insertLog($log)528 529 $this->cur_log->clean();530 531 $this->cur_log->log_id = (integer) $log->log_id;532 $this->cur_log->user_id = (string) $log->user_id;533 $this->cur_log->log_table = (string) $log->log_table; 534 $this->cur_log->log_dt = (string) $log->log_dt;535 $this->cur_log->log_ip = (string) $log->log_ip; 536 $this->cur_log->log_msg = (string) $log->log_msg; 537 538 $this->cur_log->insert(); 539 } 540 541 private function insertPing($ping) 542 { 543 $this->cur_ping->clean();544 545 $this->cur_ping->post_id = (integer) $ping->post_id;546 $this->cur_ping->ping_url = (string) $ping->ping_url;547 $this->cur_ping->ping_dt = (string) $ping->ping_dt; 548 549 $this->cur_ping->insert(); 550 } 551 552 private function insertComment($comment) 553 { 554 $this->cur_comment->clean(); 555 556 $this->cur_comment->comment_id = (integer) $comment->comment_id;557 $this->cur_comment->post_id = (integer) $comment->post_id;558 $this->cur_comment->comment_dt = (string) $comment->comment_dt; 559 $this->cur_comment->comment_upddt = (string) $comment->comment_upddt;560 $this->cur_comment->comment_author = (string) $comment->comment_author; 561 $this->cur_comment->comment_email = (string) $comment->comment_email; 562 $this->cur_comment->comment_site = (string) $comment->comment_site; 563 $this->cur_comment->comment_content = (string) $comment->comment_content; 564 $this->cur_comment->comment_words = (string) $comment->comment_words;565 $this->cur_comment->comment_ip = (string) $comment->comment_ip; 566 $this->cur_comment->comment_status = (integer) $comment->comment_status;567 $this->cur_comment->comment_spam_status = (string) $comment->comment_spam_status;568 $this->cur_comment->comment_trackback = (integer) $comment->comment_trackback;569 570 $this->cur_comment->comment_tz = $comment->exists('comment_tz') ? (string) $comment->comment_tz : 'UTC';571 $this->cur_comment->comment_spam_filter = $comment->exists('comment_spam_filter') ? (string) $comment->comment_spam_filter : null;572 573 $this->cur_comment->insert();574 } 575 576 private function insertSpamRule($spamrule) 577 { 578 $this->cur_spamrule->clean();579 580 $this->cur_spamrule->rule_id = (integer) $spamrule->rule_id;581 $this->cur_spamrule->blog_id = !$spamrule->blog_id ? null : (string) $spamrule->blog_id;582 $this->cur_spamrule->rule_type = (string) $spamrule->rule_type; 583 $this->cur_spamrule->rule_content = (string) $spamrule->rule_content;584 585 $this->cur_spamrule->insert(); 586 } 587 588 private function insertCategorySingle($category) 589 { 590 $this->cur_category->clean();591 592 $m = $this->searchCategory($this->stack['categories'],$category->cat_url);593 594 $old_id = $category->cat_id; 595 if ($m !== false) 596 { 597 $cat_id = $m; 598 } 599 else 600 { 601 $cat_id = $this->stack['cat_id']; 602 $category->cat_id = $cat_id;603 $category->blog_id = $this->blog_id; 604 605 $this->insertCategory($category); 606 $this->stack['cat_id']++;607 } 608 609 $this->old_ids['category'][(integer) $old_id]= $cat_id;610 } 611 612 private function insertLinkSingle($link) 613 { 614 $link->blog_id = $this->blog_id; 615 $link->link_id = $this->stack['link_id']; 616 617 $this->insertLink($link); 618 $this->stack['link_id']++; 619 } 620 621 private function insertPostSingle($post) 622 { 623 if (!$post->cat_id || isset($this->old_ids['category'][(integer) $post->cat_id])) { 624 $post_id = $this->stack['post_id'];625 $this->old_ids['post'][(integer) $post->post_id] = $post_id;626 627 $cat_id = $post->cat_id ? $this->old_ids['category'][(integer) $post->cat_id] : null; 628 629 $post->post_id = $post_id; 630 $post->cat_id = $cat_id; 631 $post->blog_id = $this->blog_id;632 633 $post->post_url = $this->core->blog->getPostURL( 634 $post->post_url,$post->post_dt,$post->post_title,$post->post_id 635 ); 636 637 $this->insertPost($post);638 $this->stack['post_id']++;639 } else { 640 self::throwIdError($post->__name,$post->__line,'category'); 641 } 642 } 643 644 private function insertMetaSingle($meta) 645 { 646 if (isset($this->old_ids['post'][(integer) $meta->post_id])){647 $meta->post_id = $this->old_ids['post'][(integer) $meta->post_id];648 $this->insertMeta($meta); 649 } else { 650 self::throwIdError($meta->__name,$meta->__line,'post'); 651 } 652 } 653 654 private function insertMediaSingle($media) 655 { 656 $media_id = $this->stack['media_id']; 657 $old_id = $media->media_id;658 659 $media->media_id = $media_id; 660 $media->media_path = $this->core->blog->settings->system->public_path; 661 $media->user_id = $this->getUserId($media->user_id); 662 663 $this->insertMedia($media);664 $this->stack['media_id']++;665 $this->old_ids['media'][(integer) $old_id] = $media_id; 666 } 667 668 private function insertPostMediaSingle($post_media) 669 { 670 if (isset($this->old_ids['media'][(integer) $post_media->media_id]) && 671 isset($this->old_ids['post'][(integer) $post_media->post_id])) { 672 $post_media->media_id = $this->old_ids['media'][(integer) $post_media->media_id];673 $post_media->post_id = $this->old_ids['post'][(integer) $post_media->post_id]; 674 675 $this->insertPostMedia($post_media); 676 } elseif (!isset($this->old_ids['media'][(integer) $post_media->media_id])){677 self::throwIdError($post_media->__name,$post_media->__line,'media'); 678 }else{679 self::throwIdError($post_media->__name,$post_media->__line,'post');680 } 681 } 682 683 private function insertPingSingle($ping) 684 { 685 if (isset($this->old_ids['post'][(integer) $ping->post_id])){686 $ping->post_id = $this->old_ids['post'][(integer) $ping->post_id];687 688 $this->insertPing($ping); 689 } else { 690 self::throwIdError($ping->__name,$ping->__line,'post'); 691 } 692 } 693 694 private function insertCommentSingle($comment) 695 { 696 if (isset($this->old_ids['post'][(integer) $comment->post_id])){697 $comment_id = $this->stack['comment_id'];698 699 $comment->comment_id = $comment_id; 700 $comment->post_id = $this->old_ids['post'][(integer) $comment->post_id]; 701 702 $this->insertComment($comment); 703 $this->stack['comment_id']++; 704 } else { 705 self::throwIdError($comment->__name,$comment->__line,'post'); 706 } 707 } 708 709 private static function throwIdError($name,$line,$related) 710 { 711 throw new Exception(sprintf( 712 __('ID of "%3$s" does not match on record "%1$s" at line %2$s of backup file.'), 713 html::escapeHTML($name), 714 html::escapeHTML($line), 715 html::escapeHTML($related) 716 )); 717 } 718 719 public function searchCategory($rs,$url) 720 { 721 while ($rs->fetch()) 722 { 723 if ($rs->cat_url == $url) { 724 return $rs->cat_id; 725 } 726 } 727 728 return false; 729 } 730 731 public function getUserId($user_id) 732 { 733 if (!$this->userExists($user_id)) 734 { 735 if ($this->core->auth->isSuperAdmin()) 736 { 737 # Sanitizes user_id and create a lambda user 738 $user_id = preg_replace('/[^A-Za-z0-9]$/','',$user_id); 739 $user_id .= strlen($user_id) < 2 ? '-a' : ''; 740 741 # We change user_id, we need to check again 742 if (!$this->userExists($user_id)) 743 { 744 $this->cur_user->clean(); 745 $this->cur_user->user_id = (string) $user_id; 746 $this->cur_user->user_pwd = md5(uniqid()); 747 748 $this->core->addUser($this->cur_user);749 750 $this->stack['users'][$user_id] = true; 751 } 752 } 753 else 754 { 755 # Returns current user id 756 $user_id = $this->core->auth->userID(); 757 } 758 759 760 return $user_id; 761 } 762 763 private function userExists($user_id) 764 { 765 if (isset($this->stack['users'][$user_id])){766 return $this->stack['users'][$user_id]; 767 } 768 769 $strReq = 'SELECT user_id '. 770 'FROM '.$this->prefix.'user '.771 "WHERE user_id = '".$this->con->escape($user_id)."' "; 772 773 $rs = $this->con->select($strReq); 774 775 $this->stack['users'][$user_id] = !$rs->isEmpty(); 776 return $this->stack['users'][$user_id];777 } 778 779 private function prefExists($pref_ws,$pref_id,$user_id) 780 { 781 $strReq = 'SELECT pref_id,pref_ws,user_id '. 782 'FROM '.$this->prefix.'pref '.783 "WHERE pref_id = '".$this->con->escape($pref_id)."' ".784 "AND pref_ws = '".$this->con->escape($pref_ws)."' "; 785 if (!$user_id) { 786 $strReq .= "AND user_id IS NULL "; 787 } else { 788 $strReq .= "AND user_id = '".$this->con->escape($user_id)."' "; 789 } 790 791 $rs = $this->con->select($strReq); 792 793 return !$rs->isEmpty(); 794 } 795 796 private function mediaExists() 797 { 798 $strReq = 'SELECT media_id '. 799 'FROM '.$this->prefix.'media '.800 "WHERE media_path = '".$this->con->escape($this->cur_media->media_path)."' ".801 "AND media_file = '".$this->con->escape($this->cur_media->media_file)."' "; 802 803 $rs = $this->con->select($strReq); 804 805 return !$rs->isEmpty(); 806 } 807 808 private function prepareDC12line(&$line) 809 { 810 $settings = array('dc_theme','dc_nb_post_per_page','dc_allow_comments', 811 'dc_allow_trackbacks','dc_comment_pub','dc_comments_ttl',812 'dc_wiki_comments','dc_use_smilies','dc_date_format','dc_time_format',813 'dc_url_scan'); 814 815 switch ($line->__name) 816 817 818 $line->substitute('cat_libelle','cat_title');819 $line->substitute('cat_libelle_url','cat_url');820 $line->__name= 'category';821 822 823 824 $line->substitute('href','link_href');825 $line->substitute('label','link_title');826 $line->substitute('title','link_desc');827 $line->substitute('lang','link_lang');828 $line->substitute('rel','link_xfn');829 $line->substitute('position','link_position');830 831 832 833 $line->substitute('post_titre','post_title');834 $line->post_title= html::decodeEntities($line->post_title);835 $line->post_url = date('Y/m/d/',strtotime($line->post_dt)).$line->post_id.'-'.$line->post_titre_url;836 $line->post_url = substr($line->post_url,0,255);837 $line->post_format= $line->post_content_wiki == '' ? 'xhtml' : 'wiki';838 839 840 841 842 843 844 845 846 847 848 849 850 $line->post_type= 'post';851 $line->blog_id= 'default';852 853 $line->drop('post_titre_url','post_content_wiki','post_chapo','post_chapo_wiki','post_pub');854 855 856 857 858 $line->substitute('meta_key','meta_type');859 $line->substitute('meta_value','meta_id');860 $line->__name= 'meta';861 862 863 864 $line->substitute('comment_auteur','comment_author');865 if ($line->comment_site != '' && !preg_match('!^http://.*$!', $line->comment_site,$m)) {866 $line->comment_site = 'http://'.$line->comment_site;867 868 869 870 871 872 873 874 $this->core->callBehavior('importPrepareDC12',$line,$this,$this->core);875 16 private $core; 17 private $con; 18 private $prefix; 19 20 private $dc_version; 21 private $dc_major; 22 private $mode; 23 24 private $blog_url; 25 private $blog_name; 26 private $blog_desc; 27 28 private $users = array(); 29 30 public $old_ids = array( 31 'category' => array(), 32 'post' => array(), 33 'media' => array() 34 ); 35 36 public $stack = array( 37 'categories' => null, 38 'cat_id' => 1, 39 'cat_lft' => array(), 40 'post_id' => 1, 41 'media_id' => 1, 42 'comment_id' => 1, 43 'link_id' => 1, 44 'log_id' => 1 45 ); 46 47 public $has_categories = false; 48 49 public function __construct($core, $file) 50 { 51 parent::__construct($file); 52 53 $first_line = fgets($this->fp); 54 if (strpos($first_line, '///DOTCLEAR|') !== 0) { 55 throw new Exception(__('File is not a DotClear backup.')); 56 } 57 58 @set_time_limit(300); 59 60 $l = explode('|', $first_line); 61 62 if (isset($l[1])) { 63 $this->dc_version = $l[1]; 64 } 65 66 $this->mode = isset($l[2]) ? strtolower(trim($l[2])) : 'single'; 67 if ($this->mode != 'full' && $this->mode != 'single') { 68 $this->mode = 'single'; 69 } 70 71 if (version_compare('1.2', $this->dc_version, '<=') && 72 version_compare('1.3', $this->dc_version, '>')) { 73 $this->dc_major_version = '1.2'; 74 } else { 75 $this->dc_major_version = '2.0'; 76 } 77 78 $this->core = &$core; 79 $this->con = &$core->con; 80 $this->prefix = $core->prefix; 81 82 $this->cur_blog = $this->con->openCursor($this->prefix . 'blog'); 83 $this->cur_category = $this->con->openCursor($this->prefix . 'category'); 84 $this->cur_link = $this->con->openCursor($this->prefix . 'link'); 85 $this->cur_setting = $this->con->openCursor($this->prefix . 'setting'); 86 $this->cur_user = $this->con->openCursor($this->prefix . 'user'); 87 $this->cur_pref = $this->con->openCursor($this->prefix . 'pref'); 88 $this->cur_permissions = $this->con->openCursor($this->prefix . 'permissions'); 89 $this->cur_post = $this->con->openCursor($this->prefix . 'post'); 90 $this->cur_meta = $this->con->openCursor($this->prefix . 'meta'); 91 $this->cur_media = $this->con->openCursor($this->prefix . 'media'); 92 $this->cur_post_media = $this->con->openCursor($this->prefix . 'post_media'); 93 $this->cur_log = $this->con->openCursor($this->prefix . 'log'); 94 $this->cur_ping = $this->con->openCursor($this->prefix . 'ping'); 95 $this->cur_comment = $this->con->openCursor($this->prefix . 'comment'); 96 $this->cur_spamrule = $this->con->openCursor($this->prefix . 'spamrule'); 97 $this->cur_version = $this->con->openCursor($this->prefix . 'version'); 98 99 # --BEHAVIOR-- importInit 100 $this->core->callBehavior('importInit', $this, $this->core); 101 } 102 103 public function importSingle() 104 { 105 if ($this->mode != 'single') { 106 throw new Exception(__('File is not a single blog export.')); 107 } 108 109 if (!$this->core->auth->check('admin', $this->core->blog->id)) { 110 throw new Exception(__('Permission denied.')); 111 } 112 113 $this->blog_id = $this->core->blog->id; 114 115 $this->stack['categories'] = $this->con->select( 116 'SELECT cat_id, cat_title, cat_url ' . 117 'FROM ' . $this->prefix . 'category ' . 118 "WHERE blog_id = '" . $this->con->escape($this->blog_id) . "' " 119 ); 120 121 $rs = $this->con->select('SELECT MAX(cat_id) FROM ' . $this->prefix . 'category'); 122 $this->stack['cat_id'] = ((integer) $rs->f(0)) + 1; 123 124 $rs = $this->con->select('SELECT MAX(link_id) FROM ' . $this->prefix . 'link'); 125 $this->stack['link_id'] = ((integer) $rs->f(0)) + 1; 126 127 $rs = $this->con->select('SELECT MAX(post_id) FROM ' . $this->prefix . 'post'); 128 $this->stack['post_id'] = ((integer) $rs->f(0)) + 1; 129 130 $rs = $this->con->select('SELECT MAX(media_id) FROM ' . $this->prefix . 'media'); 131 $this->stack['media_id'] = ((integer) $rs->f(0)) + 1; 132 133 $rs = $this->con->select('SELECT MAX(comment_id) FROM ' . $this->prefix . 'comment'); 134 $this->stack['comment_id'] = ((integer) $rs->f(0)) + 1; 135 136 $rs = $this->con->select('SELECT MAX(log_id) FROM ' . $this->prefix . 'log'); 137 $this->stack['log_id'] = ((integer) $rs->f(0)) + 1; 138 139 $rs = $this->con->select( 140 'SELECT MAX(cat_rgt) AS cat_rgt FROM ' . $this->prefix . 'category ' . 141 "WHERE blog_id = '" . $this->con->escape($this->core->blog->id) . "'" 142 ); 143 144 if ((integer) $rs->cat_rgt > 0) { 145 $this->has_categories = true; 146 $this->stack['cat_lft'][$this->core->blog->id] = (integer) $rs->cat_rgt + 1; 147 } 148 149 $this->con->begin(); 150 151 try 152 { 153 $last_line_name = ''; 154 $constrained = array('post', 'meta', 'post_media', 'ping', 'comment'); 155 156 while (($line = $this->getLine()) !== false) { 157 # import DC 1.2.x, we fix lines before insert 158 if ($this->dc_major_version == '1.2') { 159 $this->prepareDC12line($line); 160 } 161 162 if ($last_line_name != $line->__name) { 163 if (in_array($last_line_name, $constrained)) { 164 # UNDEFER 165 if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli' || $this->con->driver() == 'mysqlimb4') { 166 $this->con->execute('SET foreign_key_checks = 1'); 167 } 168 169 if ($this->con->driver() == 'pgsql') { 170 $this->con->execute('SET CONSTRAINTS ALL DEFERRED'); 171 } 172 173 } 174 175 if (in_array($line->__name, $constrained)) { 176 # DEFER 177 if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli' || $this->con->driver() == 'mysqlimb4') { 178 $this->con->execute('SET foreign_key_checks = 0'); 179 } 180 181 if ($this->con->driver() == 'pgsql') { 182 $this->con->execute('SET CONSTRAINTS ALL IMMEDIATE'); 183 } 184 185 } 186 187 $last_line_name = $line->__name; 188 } 189 190 switch ($line->__name) { 191 case 'category': 192 $this->insertCategorySingle($line); 193 break; 194 case 'link': 195 $this->insertLinkSingle($line); 196 break; 197 case 'post': 198 $this->insertPostSingle($line); 199 break; 200 case 'meta': 201 $this->insertMetaSingle($line); 202 break; 203 case 'media': 204 $this->insertMediaSingle($line); 205 break; 206 case 'post_media': 207 $this->insertPostMediaSingle($line); 208 break; 209 case 'ping': 210 $this->insertPingSingle($line); 211 break; 212 case 'comment': 213 $this->insertCommentSingle($line); 214 break; 215 } 216 217 # --BEHAVIOR-- importSingle 218 $this->core->callBehavior('importSingle', $line, $this, $this->core); 219 } 220 221 if ($this->con->driver() == 'mysql' || $this->con->driver() == 'mysqli' || $this->con->driver() == 'mysqlimb4') { 222 $this->con->execute('SET foreign_key_checks = 1'); 223 } 224 225 if ($this->con->driver() == 'pgsql') { 226 $this->con->execute('SET CONSTRAINTS ALL DEFERRED'); 227 } 228 229 } catch (Exception $e) { 230 @fclose($this->fp); 231 $this->con->rollback(); 232 throw new Exception($e->getMessage() . ' - ' . sprintf(__('Error raised at line %s'), $line->__line)); 233 } 234 @fclose($this->fp); 235 $this->con->commit(); 236 } 237 238 public function importFull() 239 { 240 if ($this->mode != 'full') { 241 throw new Exception(__('File is not a full export.')); 242 } 243 244 if (!$this->core->auth->isSuperAdmin()) { 245 throw new Exception(__('Permission denied.')); 246 } 247 248 $this->con->begin(); 249 $this->con->execute('DELETE FROM ' . $this->prefix . 'blog'); 250 $this->con->execute('DELETE FROM ' . $this->prefix . 'media'); 251 $this->con->execute('DELETE FROM ' . $this->prefix . 'spamrule'); 252 $this->con->execute('DELETE FROM ' . $this->prefix . 'setting'); 253 $this->con->execute('DELETE FROM ' . $this->prefix . 'log'); 254 255 try 256 { 257 while (($line = $this->getLine()) !== false) { 258 switch ($line->__name) { 259 case 'blog': 260 $this->insertBlog($line); 261 break; 262 case 'category': 263 $this->insertCategory($line); 264 break; 265 case 'link': 266 $this->insertLink($line); 267 break; 268 case 'setting': 269 $this->insertSetting($line); 270 break; 271 case 'user': 272 $this->insertUser($line); 273 break; 274 case 'pref': 275 $this->insertPref($line); 276 break; 277 case 'permissions': 278 $this->insertPermissions($line); 279 break; 280 case 'post': 281 $this->insertPost($line); 282 break; 283 case 'meta': 284 $this->insertMeta($line); 285 break; 286 case 'media': 287 $this->insertMedia($line); 288 break; 289 case 'post_media': 290 $this->insertPostMedia($line); 291 break; 292 case 'log'; 293 $this->insertLog($line); 294 break; 295 case 'ping': 296 $this->insertPing($line); 297 break; 298 case 'comment': 299 $this->insertComment($line); 300 break; 301 case 'spamrule': 302 $this->insertSpamRule($line); 303 break; 304 } 305 # --BEHAVIOR-- importFull 306 $this->core->callBehavior('importFull', $line, $this, $this->core); 307 } 308 } catch (Exception $e) { 309 @fclose($this->fp); 310 $this->con->rollback(); 311 throw new Exception($e->getMessage() . ' - ' . sprintf(__('Error raised at line %s'), $line->__line)); 312 } 313 @fclose($this->fp); 314 $this->con->commit(); 315 } 316 317 private function insertBlog($blog) 318 { 319 $this->cur_blog->clean(); 320 321 $this->cur_blog->blog_id = (string) $blog->blog_id; 322 $this->cur_blog->blog_uid = (string) $blog->blog_uid; 323 $this->cur_blog->blog_creadt = (string) $blog->blog_creadt; 324 $this->cur_blog->blog_upddt = (string) $blog->blog_upddt; 325 $this->cur_blog->blog_url = (string) $blog->blog_url; 326 $this->cur_blog->blog_name = (string) $blog->blog_name; 327 $this->cur_blog->blog_desc = (string) $blog->blog_desc; 328 329 $this->cur_blog->blog_status = $blog->exists('blog_status') ? (integer) $blog->blog_status : 1; 330 331 $this->cur_blog->insert(); 332 } 333 334 private function insertCategory($category) 335 { 336 $this->cur_category->clean(); 337 338 $this->cur_category->cat_id = (string) $category->cat_id; 339 $this->cur_category->blog_id = (string) $category->blog_id; 340 $this->cur_category->cat_title = (string) $category->cat_title; 341 $this->cur_category->cat_url = (string) $category->cat_url; 342 $this->cur_category->cat_desc = (string) $category->cat_desc; 343 344 if (!$this->has_categories && $category->exists('cat_lft') && $category->exists('cat_rgt')) { 345 $this->cur_category->cat_lft = (integer) $category->cat_lft; 346 $this->cur_category->cat_rgt = (integer) $category->cat_rgt; 347 } else { 348 if (!isset($this->stack['cat_lft'][$category->blog_id])) { 349 $this->stack['cat_lft'][$category->blog_id] = 2; 350 } 351 $this->cur_category->cat_lft = $this->stack['cat_lft'][$category->blog_id]++; 352 $this->cur_category->cat_rgt = $this->stack['cat_lft'][$category->blog_id]++; 353 } 354 355 $this->cur_category->insert(); 356 } 357 358 private function insertLink($link) 359 { 360 $this->cur_link->clean(); 361 362 $this->cur_link->link_id = (integer) $link->link_id; 363 $this->cur_link->blog_id = (string) $link->blog_id; 364 $this->cur_link->link_href = (string) $link->link_href; 365 $this->cur_link->link_title = (string) $link->link_title; 366 $this->cur_link->link_desc = (string) $link->link_desc; 367 $this->cur_link->link_lang = (string) $link->link_lang; 368 $this->cur_link->link_xfn = (string) $link->link_xfn; 369 $this->cur_link->link_position = (integer) $link->link_position; 370 371 $this->cur_link->insert(); 372 } 373 374 private function insertSetting($setting) 375 { 376 $this->cur_setting->clean(); 377 378 $this->cur_setting->setting_id = (string) $setting->setting_id; 379 $this->cur_setting->blog_id = !$setting->blog_id ? null : (string) $setting->blog_id; 380 $this->cur_setting->setting_ns = (string) $setting->setting_ns; 381 $this->cur_setting->setting_value = (string) $setting->setting_value; 382 $this->cur_setting->setting_type = (string) $setting->setting_type; 383 $this->cur_setting->setting_label = (string) $setting->setting_label; 384 385 $this->cur_setting->insert(); 386 } 387 388 private function insertPref($pref) 389 { 390 if ($this->prefExists($pref->pref_ws, $pref->pref_id, $pref->user_id)) { 391 return; 392 } 393 394 $this->cur_pref->clean(); 395 396 $this->cur_pref->pref_id = (string) $pref->pref_id; 397 $this->cur_pref->user_id = !$pref->user_id ? null : (string) $pref->user_id; 398 $this->cur_pref->pref_ws = (string) $pref->pref_ws; 399 $this->cur_pref->pref_value = (string) $pref->pref_value; 400 $this->cur_pref->pref_type = (string) $pref->pref_type; 401 $this->cur_pref->pref_label = (string) $pref->pref_label; 402 403 $this->cur_pref->insert(); 404 } 405 406 private function insertUser($user) 407 { 408 if ($this->userExists($user->user_id)) { 409 return; 410 } 411 412 $this->cur_user->clean(); 413 414 $this->cur_user->user_id = (string) $user->user_id; 415 $this->cur_user->user_super = (integer) $user->user_super; 416 $this->cur_user->user_pwd = (string) $user->user_pwd; 417 $this->cur_user->user_recover_key = (string) $user->user_recover_key; 418 $this->cur_user->user_name = (string) $user->user_name; 419 $this->cur_user->user_firstname = (string) $user->user_firstname; 420 $this->cur_user->user_displayname = (string) $user->user_displayname; 421 $this->cur_user->user_email = (string) $user->user_email; 422 $this->cur_user->user_url = (string) $user->user_url; 423 $this->cur_user->user_default_blog = !$user->user_default_blog ? null : (string) $user->user_default_blog; 424 $this->cur_user->user_lang = (string) $user->user_lang; 425 $this->cur_user->user_tz = (string) $user->user_tz; 426 $this->cur_user->user_post_status = (integer) $user->user_post_status; 427 $this->cur_user->user_creadt = (string) $user->user_creadt; 428 $this->cur_user->user_upddt = (string) $user->user_upddt; 429 430 $this->cur_user->user_desc = $user->exists('user_desc') ? (string) $user->user_desc : null; 431 $this->cur_user->user_options = $user->exists('user_options') ? (string) $user->user_options : null; 432 $this->cur_user->user_status = $user->exists('user_status') ? (integer) $user->user_status : 1; 433 434 $this->cur_user->insert(); 435 436 $this->stack['users'][$user->user_id] = true; 437 } 438 439 private function insertPermissions($permissions) 440 { 441 $this->cur_permissions->clean(); 442 443 $this->cur_permissions->user_id = (string) $permissions->user_id; 444 $this->cur_permissions->blog_id = (string) $permissions->blog_id; 445 $this->cur_permissions->permissions = (string) $permissions->permissions; 446 447 $this->cur_permissions->insert(); 448 } 449 450 private function insertPost($post) 451 { 452 $this->cur_post->clean(); 453 454 $cat_id = (integer) $post->cat_id; 455 if (!$cat_id) { 456 $cat_id = null; 457 } 458 459 $post_password = $post->post_password ? (string) $post->post_password : null; 460 461 $this->cur_post->post_id = (integer) $post->post_id; 462 $this->cur_post->blog_id = (string) $post->blog_id; 463 $this->cur_post->user_id = (string) $this->getUserId($post->user_id); 464 $this->cur_post->cat_id = $cat_id; 465 $this->cur_post->post_dt = (string) $post->post_dt; 466 $this->cur_post->post_creadt = (string) $post->post_creadt; 467 $this->cur_post->post_upddt = (string) $post->post_upddt; 468 $this->cur_post->post_password = $post_password; 469 $this->cur_post->post_type = (string) $post->post_type; 470 $this->cur_post->post_format = (string) $post->post_format; 471 $this->cur_post->post_url = (string) $post->post_url; 472 $this->cur_post->post_lang = (string) $post->post_lang; 473 $this->cur_post->post_title = (string) $post->post_title; 474 $this->cur_post->post_excerpt = (string) $post->post_excerpt; 475 $this->cur_post->post_excerpt_xhtml = (string) $post->post_excerpt_xhtml; 476 $this->cur_post->post_content = (string) $post->post_content; 477 $this->cur_post->post_content_xhtml = (string) $post->post_content_xhtml; 478 $this->cur_post->post_notes = (string) $post->post_notes; 479 $this->cur_post->post_words = (string) $post->post_words; 480 $this->cur_post->post_meta = (string) $post->post_meta; 481 $this->cur_post->post_status = (integer) $post->post_status; 482 $this->cur_post->post_selected = (integer) $post->post_selected; 483 $this->cur_post->post_open_comment = (integer) $post->post_open_comment; 484 $this->cur_post->post_open_tb = (integer) $post->post_open_tb; 485 $this->cur_post->nb_comment = (integer) $post->nb_comment; 486 $this->cur_post->nb_trackback = (integer) $post->nb_trackback; 487 $this->cur_post->post_position = (integer) $post->post_position; 488 489 $this->cur_post->post_tz = $post->exists('post_tz') ? (string) $post->post_tz : 'UTC'; 490 491 $this->cur_post->insert(); 492 } 493 494 private function insertMeta($meta) 495 { 496 $this->cur_meta->clean(); 497 498 $this->cur_meta->meta_id = (string) $meta->meta_id; 499 $this->cur_meta->meta_type = (string) $meta->meta_type; 500 $this->cur_meta->post_id = (integer) $meta->post_id; 501 502 $this->cur_meta->insert(); 503 } 504 505 private function insertMedia($media) 506 { 507 $this->cur_media->clean(); 508 509 $this->cur_media->media_id = (integer) $media->media_id; 510 $this->cur_media->user_id = (string) $media->user_id; 511 $this->cur_media->media_path = (string) $media->media_path; 512 $this->cur_media->media_title = (string) $media->media_title; 513 $this->cur_media->media_file = (string) $media->media_file; 514 $this->cur_media->media_meta = (string) $media->media_meta; 515 $this->cur_media->media_dt = (string) $media->media_dt; 516 $this->cur_media->media_creadt = (string) $media->media_creadt; 517 $this->cur_media->media_upddt = (string) $media->media_upddt; 518 $this->cur_media->media_private = (integer) $media->media_private; 519 520 $this->cur_media->media_dir = $media->exists('media_dir') ? (string) $media->media_dir : dirname($media->media_file); 521 522 if (!$this->mediaExists()) { 523 $this->cur_media->insert(); 524 } 525 } 526 527 private function insertPostMedia($post_media) 528 { 529 $this->cur_post_media->clean(); 530 531 $this->cur_post_media->media_id = (integer) $post_media->media_id; 532 $this->cur_post_media->post_id = (integer) $post_media->post_id; 533 534 $this->cur_post_media->insert(); 535 } 536 537 private function insertLog($log) 538 { 539 $this->cur_log->clean(); 540 541 $this->cur_log->log_id = (integer) $log->log_id; 542 $this->cur_log->user_id = (string) $log->user_id; 543 $this->cur_log->log_table = (string) $log->log_table; 544 $this->cur_log->log_dt = (string) $log->log_dt; 545 $this->cur_log->log_ip = (string) $log->log_ip; 546 $this->cur_log->log_msg = (string) $log->log_msg; 547 548 $this->cur_log->insert(); 549 } 550 551 private function insertPing($ping) 552 { 553 $this->cur_ping->clean(); 554 555 $this->cur_ping->post_id = (integer) $ping->post_id; 556 $this->cur_ping->ping_url = (string) $ping->ping_url; 557 $this->cur_ping->ping_dt = (string) $ping->ping_dt; 558 559 $this->cur_ping->insert(); 560 } 561 562 private function insertComment($comment) 563 { 564 $this->cur_comment->clean(); 565 566 $this->cur_comment->comment_id = (integer) $comment->comment_id; 567 $this->cur_comment->post_id = (integer) $comment->post_id; 568 $this->cur_comment->comment_dt = (string) $comment->comment_dt; 569 $this->cur_comment->comment_upddt = (string) $comment->comment_upddt; 570 $this->cur_comment->comment_author = (string) $comment->comment_author; 571 $this->cur_comment->comment_email = (string) $comment->comment_email; 572 $this->cur_comment->comment_site = (string) $comment->comment_site; 573 $this->cur_comment->comment_content = (string) $comment->comment_content; 574 $this->cur_comment->comment_words = (string) $comment->comment_words; 575 $this->cur_comment->comment_ip = (string) $comment->comment_ip; 576 $this->cur_comment->comment_status = (integer) $comment->comment_status; 577 $this->cur_comment->comment_spam_status = (string) $comment->comment_spam_status; 578 $this->cur_comment->comment_trackback = (integer) $comment->comment_trackback; 579 580 $this->cur_comment->comment_tz = $comment->exists('comment_tz') ? (string) $comment->comment_tz : 'UTC'; 581 $this->cur_comment->comment_spam_filter = $comment->exists('comment_spam_filter') ? (string) $comment->comment_spam_filter : null; 582 583 $this->cur_comment->insert(); 584 } 585 586 private function insertSpamRule($spamrule) 587 { 588 $this->cur_spamrule->clean(); 589 590 $this->cur_spamrule->rule_id = (integer) $spamrule->rule_id; 591 $this->cur_spamrule->blog_id = !$spamrule->blog_id ? null : (string) $spamrule->blog_id; 592 $this->cur_spamrule->rule_type = (string) $spamrule->rule_type; 593 $this->cur_spamrule->rule_content = (string) $spamrule->rule_content; 594 595 $this->cur_spamrule->insert(); 596 } 597 598 private function insertCategorySingle($category) 599 { 600 $this->cur_category->clean(); 601 602 $m = $this->searchCategory($this->stack['categories'], $category->cat_url); 603 604 $old_id = $category->cat_id; 605 if ($m !== false) { 606 $cat_id = $m; 607 } else { 608 $cat_id = $this->stack['cat_id']; 609 $category->cat_id = $cat_id; 610 $category->blog_id = $this->blog_id; 611 612 $this->insertCategory($category); 613 $this->stack['cat_id']++; 614 } 615 616 $this->old_ids['category'][(integer) $old_id] = $cat_id; 617 } 618 619 private function insertLinkSingle($link) 620 { 621 $link->blog_id = $this->blog_id; 622 $link->link_id = $this->stack['link_id']; 623 624 $this->insertLink($link); 625 $this->stack['link_id']++; 626 } 627 628 private function insertPostSingle($post) 629 { 630 if (!$post->cat_id || isset($this->old_ids['category'][(integer) $post->cat_id])) { 631 $post_id = $this->stack['post_id']; 632 $this->old_ids['post'][(integer) $post->post_id] = $post_id; 633 634 $cat_id = $post->cat_id ? $this->old_ids['category'][(integer) $post->cat_id] : null; 635 636 $post->post_id = $post_id; 637 $post->cat_id = $cat_id; 638 $post->blog_id = $this->blog_id; 639 640 $post->post_url = $this->core->blog->getPostURL( 641 $post->post_url, $post->post_dt, $post->post_title, $post->post_id 642 ); 643 644 $this->insertPost($post); 645 $this->stack['post_id']++; 646 } else { 647 self::throwIdError($post->__name, $post->__line, 'category'); 648 } 649 } 650 651 private function insertMetaSingle($meta) 652 { 653 if (isset($this->old_ids['post'][(integer) $meta->post_id])) { 654 $meta->post_id = $this->old_ids['post'][(integer) $meta->post_id]; 655 $this->insertMeta($meta); 656 } else { 657 self::throwIdError($meta->__name, $meta->__line, 'post'); 658 } 659 } 660 661 private function insertMediaSingle($media) 662 { 663 $media_id = $this->stack['media_id']; 664 $old_id = $media->media_id; 665 666 $media->media_id = $media_id; 667 $media->media_path = $this->core->blog->settings->system->public_path; 668 $media->user_id = $this->getUserId($media->user_id); 669 670 $this->insertMedia($media); 671 $this->stack['media_id']++; 672 $this->old_ids['media'][(integer) $old_id] = $media_id; 673 } 674 675 private function insertPostMediaSingle($post_media) 676 { 677 if (isset($this->old_ids['media'][(integer) $post_media->media_id]) && 678 isset($this->old_ids['post'][(integer) $post_media->post_id])) { 679 $post_media->media_id = $this->old_ids['media'][(integer) $post_media->media_id]; 680 $post_media->post_id = $this->old_ids['post'][(integer) $post_media->post_id]; 681 682 $this->insertPostMedia($post_media); 683 } elseif (!isset($this->old_ids['media'][(integer) $post_media->media_id])) { 684 self::throwIdError($post_media->__name, $post_media->__line, 'media'); 685 } else { 686 self::throwIdError($post_media->__name, $post_media->__line, 'post'); 687 } 688 } 689 690 private function insertPingSingle($ping) 691 { 692 if (isset($this->old_ids['post'][(integer) $ping->post_id])) { 693 $ping->post_id = $this->old_ids['post'][(integer) $ping->post_id]; 694 695 $this->insertPing($ping); 696 } else { 697 self::throwIdError($ping->__name, $ping->__line, 'post'); 698 } 699 } 700 701 private function insertCommentSingle($comment) 702 { 703 if (isset($this->old_ids['post'][(integer) $comment->post_id])) { 704 $comment_id = $this->stack['comment_id']; 705 706 $comment->comment_id = $comment_id; 707 $comment->post_id = $this->old_ids['post'][(integer) $comment->post_id]; 708 709 $this->insertComment($comment); 710 $this->stack['comment_id']++; 711 } else { 712 self::throwIdError($comment->__name, $comment->__line, 'post'); 713 } 714 } 715 716 private static function throwIdError($name, $line, $related) 717 { 718 throw new Exception(sprintf( 719 __('ID of "%3$s" does not match on record "%1$s" at line %2$s of backup file.'), 720 html::escapeHTML($name), 721 html::escapeHTML($line), 722 html::escapeHTML($related) 723 )); 724 } 725 726 public function searchCategory($rs, $url) 727 { 728 while ($rs->fetch()) { 729 if ($rs->cat_url == $url) { 730 return $rs->cat_id; 731 } 732 } 733 734 return false; 735 } 736 737 public function getUserId($user_id) 738 { 739 if (!$this->userExists($user_id)) { 740 if ($this->core->auth->isSuperAdmin()) { 741 # Sanitizes user_id and create a lambda user 742 $user_id = preg_replace('/[^A-Za-z0-9]$/', '', $user_id); 743 $user_id .= strlen($user_id) < 2 ? '-a' : ''; 744 745 # We change user_id, we need to check again 746 if (!$this->userExists($user_id)) { 747 $this->cur_user->clean(); 748 $this->cur_user->user_id = (string) $user_id; 749 $this->cur_user->user_pwd = md5(uniqid()); 750 751 $this->core->addUser($this->cur_user); 752 753 $this->stack['users'][$user_id] = true; 754 } 755 } else { 756 # Returns current user id 757 $user_id = $this->core->auth->userID(); 758 } 759 } 760 761 return $user_id; 762 } 763 764 private function userExists($user_id) 765 { 766 if (isset($this->stack['users'][$user_id])) { 767 return $this->stack['users'][$user_id]; 768 } 769 770 $strReq = 'SELECT user_id ' . 771 'FROM ' . $this->prefix . 'user ' . 772 "WHERE user_id = '" . $this->con->escape($user_id) . "' "; 773 774 $rs = $this->con->select($strReq); 775 776 $this->stack['users'][$user_id] = !$rs->isEmpty(); 777 return $this->stack['users'][$user_id]; 778 } 779 780 private function prefExists($pref_ws, $pref_id, $user_id) 781 { 782 $strReq = 'SELECT pref_id,pref_ws,user_id ' . 783 'FROM ' . $this->prefix . 'pref ' . 784 "WHERE pref_id = '" . $this->con->escape($pref_id) . "' " . 785 "AND pref_ws = '" . $this->con->escape($pref_ws) . "' "; 786 if (!$user_id) { 787 $strReq .= "AND user_id IS NULL "; 788 } else { 789 $strReq .= "AND user_id = '" . $this->con->escape($user_id) . "' "; 790 } 791 792 $rs = $this->con->select($strReq); 793 794 return !$rs->isEmpty(); 795 } 796 797 private function mediaExists() 798 { 799 $strReq = 'SELECT media_id ' . 800 'FROM ' . $this->prefix . 'media ' . 801 "WHERE media_path = '" . $this->con->escape($this->cur_media->media_path) . "' " . 802 "AND media_file = '" . $this->con->escape($this->cur_media->media_file) . "' "; 803 804 $rs = $this->con->select($strReq); 805 806 return !$rs->isEmpty(); 807 } 808 809 private function prepareDC12line(&$line) 810 { 811 $settings = array('dc_theme', 'dc_nb_post_per_page', 'dc_allow_comments', 812 'dc_allow_trackbacks', 'dc_comment_pub', 'dc_comments_ttl', 813 'dc_wiki_comments', 'dc_use_smilies', 'dc_date_format', 'dc_time_format', 814 'dc_url_scan'); 815 816 switch ($line->__name) { 817 case 'categorie': 818 $line->substitute('cat_libelle', 'cat_title'); 819 $line->substitute('cat_libelle_url', 'cat_url'); 820 $line->__name = 'category'; 821 $line->blog_id = 'default'; 822 break; 823 case 'link': 824 $line->substitute('href', 'link_href'); 825 $line->substitute('label', 'link_title'); 826 $line->substitute('title', 'link_desc'); 827 $line->substitute('lang', 'link_lang'); 828 $line->substitute('rel', 'link_xfn'); 829 $line->substitute('position', 'link_position'); 830 $line->blog_id = 'default'; 831 break; 832 case 'post': 833 $line->substitute('post_titre', 'post_title'); 834 $line->post_title = html::decodeEntities($line->post_title); 835 $line->post_url = date('Y/m/d/', strtotime($line->post_dt)) . $line->post_id . '-' . $line->post_titre_url; 836 $line->post_url = substr($line->post_url, 0, 255); 837 $line->post_format = $line->post_content_wiki == '' ? 'xhtml' : 'wiki'; 838 $line->post_content_xhtml = $line->post_content; 839 $line->post_excerpt_xhtml = $line->post_chapo; 840 841 if ($line->post_format == 'wiki') { 842 $line->post_content = $line->post_content_wiki; 843 $line->post_excerpt = $line->post_chapo_wiki; 844 } else { 845 $line->post_content = $line->post_content; 846 $line->post_excerpt = $line->post_chapo; 847 } 848 849 $line->post_status = (integer) $line->post_pub; 850 $line->post_type = 'post'; 851 $line->blog_id = 'default'; 852 853 $line->drop('post_titre_url', 'post_content_wiki', 'post_chapo', 'post_chapo_wiki', 'post_pub'); 854 855 break; 856 case 'post_meta': 857 $line->drop('meta_id'); 858 $line->substitute('meta_key', 'meta_type'); 859 $line->substitute('meta_value', 'meta_id'); 860 $line->__name = 'meta'; 861 $line->blog_id = 'default'; 862 break; 863 case 'comment': 864 $line->substitute('comment_auteur', 'comment_author'); 865 if ($line->comment_site != '' && !preg_match('!^http://.*$!', $line->comment_site, $m)) { 866 $line->comment_site = 'http://' . $line->comment_site; 867 } 868 $line->comment_status = (integer) $line->comment_pub; 869 $line->drop('comment_pub'); 870 break; 871 } 872 873 # --BEHAVIOR-- importPrepareDC12 874 $this->core->callBehavior('importPrepareDC12', $line, $this, $this->core); 875 } 876 876 }
Note: See TracChangeset
for help on using the changeset viewer.