/**
  * Get selected blog posts from blog
  * @param int $blogid
  * @param string $selected comma separated sequence of selected post ids to filter by
  * @param bool $inccomments - blog uses comments or not
  * @param string $username - used to ensure user posts only
  * @return array of posts
  */
 public static function get_blog_posts($blogid, $bcontextid, $selected, $inccomments = false, $username)
 {
     global $DB;
     $params = self::validate_parameters(self::get_blog_posts_parameters(), array('blogid' => $blogid, 'bcontextid' => $bcontextid, 'selected' => $selected, 'inccomments' => $inccomments, 'username' => $username));
     $user = $DB->get_field('user', 'id', array('username' => $username), IGNORE_MISSING);
     if (!$user) {
         return array();
     }
     $selected = explode(',', $params['selected']);
     $return = oublog_import_getposts($params['blogid'], $params['bcontextid'], $selected, $params['inccomments'], $user);
     // Convert file objects into a custom known object to send.
     foreach ($return as &$post) {
         foreach ($post->images as &$file) {
             $file = (object) array('contextid' => $file->get_contextid(), 'filearea' => $file->get_filearea(), 'filepath' => $file->get_filepath(), 'filename' => $file->get_filename(), 'itemid' => $file->get_itemid());
         }
         foreach ($post->attachments as &$file) {
             $file = (object) array('contextid' => $file->get_contextid(), 'filearea' => $file->get_filearea(), 'filepath' => $file->get_filepath(), 'filename' => $file->get_filename(), 'itemid' => $file->get_itemid());
         }
         foreach ($post->comments as &$comment) {
             foreach ($comment->images as &$file) {
                 $file = (object) array('contextid' => $file->get_contextid(), 'filearea' => $file->get_filearea(), 'filepath' => $file->get_filepath(), 'filename' => $file->get_filename(), 'itemid' => $file->get_itemid());
             }
         }
     }
     return $return;
 }
     if (strpos($name, 'post_') === 0) {
         $selected[] = $val;
     }
 }
 $selected = array_filter(array_unique(array_merge($selected, $preselected), SORT_NUMERIC));
 $stepinfo = array('step' => 2, 'bid' => $bid, 'preselected' => implode(',', $selected), 'remote' => $remote);
 if (empty($selected)) {
     echo html_writer::tag('p', get_string('import_step2_none', 'oublog'));
     echo $OUTPUT->continue_button(new moodle_url('/mod/oublog/import.php', array_merge($params, $stepinfo, array('step' => 1))));
     echo $OUTPUT->footer();
     exit;
 }
 if ($remote) {
     $posts = oublog_import_remote_call('mod_oublog_get_blog_posts', array('username' => $USER->username, 'blogid' => $boublogid, 'selected' => implode(',', $selected), 'inccomments' => $oublog->allowcomments != OUBLOG_COMMENTS_PREVENT, 'bcontextid' => $bcontextid));
 } else {
     $posts = oublog_import_getposts($boublogid, $bcontextid, $selected, $oublog->allowcomments != OUBLOG_COMMENTS_PREVENT, $USER->id);
 }
 if (empty($posts)) {
     print_error('import_step2_none', 'oublog');
 }
 // Get/create user blog instance for this activity.
 if ($oublog->global) {
     list($notused, $oubloginstance) = oublog_get_personal_blog($USER->id);
 } else {
     if (!($oubloginstance = $DB->get_record('oublog_instances', array('oublogid' => $oublog->id, 'userid' => $USER->id)))) {
         if (!($oubloginstance = oublog_add_bloginstance($oublog->id, $USER->id))) {
             print_error('Failed to create blog instance');
         }
         $oubloginstance = (object) array('id' => $oubloginstance);
     }
 }