/**
  * Creates an attachment playspace for editing attachments. The playspace
  * contains all current attachments of the post, if specified.
  * @param forum_post $post Optional post to copy attachments from
  * @return int Unique playspace ID
  */
 static function create_attachment_playspace($post = null, $userid = 0)
 {
     // Pick random ID and create folder
     do {
         $playspaceid = forum_utils::get_real_userid($userid) . ',' . mt_rand();
         $folder = self::get_attachment_playspace_folder($playspaceid);
     } while (is_dir($folder));
     if (!check_dir_exists($folder, true, true)) {
         throw new forum_exception("Failed to create playspace folder {$folder}");
     }
     // Copy files into it
     if ($post && $post->has_attachments()) {
         $postfiles = $post->get_attachment_names();
         $postfolder = $post->get_attachment_folder();
         foreach ($postfiles as $name) {
             forum_utils::copy("{$postfolder}/{$name}", "{$folder}/{$name}");
         }
     }
     // Return id
     return $playspaceid;
 }