public function addComment(PHPBoostAccess $PHPBoostAccess, $topic_id, stdClass $comment) { $users = $PHPBoostAccess->getAllUsers(); $userId = -1; if ($comment->user_id != 0 && array_key_exists($comment->comment_author, $users)) { $userId = $users[$comment->comment_author]->user_id; } $insert = $PHPBoostAccess->getSql()->prepare(' INSERT INTO ' . $PHPBoostAccess->getPrefix() . 'comments(id_topic, message, user_id, pseudo, user_ip, note, timestamp) VALUES (:id_topic, :message, :user_id, :pseudo, :user_ip, :note, :timestamp) '); $insert->execute(array('id_topic' => $topic_id, 'message' => $comment->comment_content, 'user_id' => $userId, 'pseudo' => $comment->comment_author, 'user_ip' => $comment->comment_author_IP, 'note' => 0, 'timestamp' => (new DateTime($comment->comment_date))->getTimestamp())); }
protected function addArticle(IOManager $io, PHPBoostAccess $phpBoostAccess, stdClass $post, WordPressAccess $wordPressAccess) { $query = $phpBoostAccess->getSql()->prepare(' INSERT INTO ' . $phpBoostAccess->getPrefix() . 'news(id_category, picture_url, name, rewrited_name, contents, short_contents, creation_date, updated_date, approbation_type, author_user_id) VALUES (:id_category, :picture_url, :name, :rewrited_name, :contents, :short_contents, :creation_date, :updated_date, :approbation_type, :author_user_id) '); // Gestion de l'auteur (si un utilisateur portant ce nom existe => On le prends) // Sinon on utilise le DEFAULT_AUTHOR_ID $users = $phpBoostAccess->getAllUsers(); if (array_key_exists($post->author_name, $users)) { $authorUserId = $users[$post->author_name]->user_id; } else { $authorUserId = DEFAULT_AUTHOR_ID; } // Gestion des images/media $medias = $wordPressAccess->getMediaForPost($post->ID); foreach ($medias as $media) { if ($this->importMedia($media, $authorUserId, $wordPressAccess, $phpBoostAccess)) { $io->writeln('Info: Media ' . $media->path . ' importé.'); } else { $io->writeln('Erreur lors de l\'importation de ' . $media->path . ', soit la destination existe déjà où la source est inexistante.'); } $post->post_content = str_replace($media->url, FILESYSTEM_IMPORT_LOCATION . $media->path, $post->post_content); } // Nettoyage du code des images $post->post_content = preg_replace('#<img (.+)src="([^\\"]+)"(.+)/>#', '<img src="$2" alt="" />', $post->post_content); // Gestion du caption $post->post_content = preg_replace('#\\[caption(.+)align="align(center|left|right)"(.+)\\](.+)</a>(.+)\\[\\/caption\\]#', '<p style="text-align:$2">$4</a><br>$5</p>', $post->post_content); // Gestion de la categorie $idCategory = 0; if (!is_null($post->term_slug)) { $cats = $phpBoostAccess->getAllNewsCats(); if (array_key_exists($post->term_slug, $cats)) { $idCategory = $cats[$post->term_slug]->id; } } // Ajout de l'article dans la BDD $query->execute(array('id_category' => $idCategory, 'picture_url' => !empty($post->thumbnail) ? FILESYSTEM_IMPORT_LOCATION . $post->thumbnail : '', 'name' => $post->post_title, 'rewrited_name' => $post->post_name, 'contents' => str_replace('<!--more-->', '', $post->post_content), 'short_contents' => count(explode('<!--more-->', $post->post_content)) > 1 ? explode('<!--more-->', $post->post_content)[0] : '', 'creation_date' => (new DateTime($post->post_date_gmt))->getTimestamp(), 'updated_date' => (new DateTime($post->post_modified))->getTimestamp(), 'approbation_type' => 1, 'author_user_id' => $authorUserId)); $newsID = $phpBoostAccess->getSql()->lastInsertId(); // Gestion des tags $tags = $wordPressAccess->getPostsTags($post->ID); foreach ($tags as $tag) { $this->addTag($phpBoostAccess, $newsID, $tag); } }
public function import(IOManager $io, WordPressAccess $wordPressAccess, PHPBoostAccess $phpBoostAccess) { // Récupération de la liste des utilisateurs existants dans PHPBoost $phpBoostUsers = $phpBoostAccess->getAllUsers(); // Récupération de la liste des utilisateurs existants dans Wordpress $wordPressUsers = $wordPressAccess->getAllUsers(); // Parcours des différents utilisateurs WordPress foreach ($wordPressUsers as $currentUser) { if (!array_key_exists($currentUser->user_login, $phpBoostUsers)) { // Si l'utilisateur n'existe pas $this->addUser($phpBoostAccess, $currentUser); $io->writeln('Info: Utilisateur ' . $currentUser->user_login . ' ajouté.'); } else { // Si l'utilisateur existe $io->writeln('Erreur: L\'utilisateur ' . $currentUser->user_login . ' existe déjà.'); } } }