示例#1
0
 /**
  * Forum-specific export format
  *
  * @todo Project file size / export time and possibly break into multiple files
  *
  * @param ExportModel $Ex
  *
  */
 protected function ForumExport($Ex)
 {
     $Ex->BeginExport('', 'PunBB 1.*', array('HashMethod' => 'punbb'));
     $this->cdn = $this->Param('cdn', '');
     if ($AvatarPath = $this->Param('avatarpath', false)) {
         if (!($AvatarPath = realpath($AvatarPath))) {
             echo "Unable to access path to avatars: {$AvatarPath}\n";
             exit(1);
         }
         $this->AvatarPath = $AvatarPath;
     }
     unset($AvatarPath);
     // User.
     $User_Map = array('AvatarID' => array('Column' => 'Photo', 'Filter' => array($this, 'GetAvatarByID')), 'id' => 'UserID', 'username' => 'Name', 'email' => 'Email', 'timezone' => 'HourOffset', 'registration_ip' => 'InsertIPAddress', 'PasswordHash' => 'Password');
     $Ex->ExportTable('User', "\n         SELECT\n             u.*, u.id AS AvatarID,\n             concat(u.password, '\$', u.salt) AS PasswordHash,\n             from_unixtime(registered) AS DateInserted,\n             from_unixtime(last_visit) AS DateLastActive\n         FROM :_users u\n         WHERE group_id <> 2", $User_Map);
     // Role.
     $Role_Map = array('g_id' => 'RoleID', 'g_title' => 'Name');
     $Ex->ExportTable('Role', "SELECT * FROM :_groups", $Role_Map);
     // Permission.
     $Permission_Map = array('g_id' => 'RoleID', 'g_modertor' => 'Garden.Moderation.Manage', 'g_mod_edit_users' => 'Garden.Users.Edit', 'g_mod_rename_users' => 'Garden.Users.Delete', 'g_read_board' => 'Vanilla.Discussions.View', 'g_view_users' => 'Garden.Profiles.View', 'g_post_topics' => 'Vanilla.Discussions.Add', 'g_post_replies' => 'Vanilla.Comments.Add', 'g_pun_attachment_allow_download' => 'Plugins.Attachments.Download.Allow', 'g_pun_attachment_allow_upload' => 'Plugins.Attachments.Upload.Allow');
     $Permission_Map = $Ex->FixPermissionColumns($Permission_Map);
     $Ex->ExportTable('Permission', "\n      SELECT\n         g.*,\n         g_post_replies AS `Garden.SignIn.Allow`,\n         g_mod_edit_users AS `Garden.Users.Add`,\n         CASE WHEN g_title = 'Administrators' THEN 'All' ELSE NULL END AS _Permissions\n      FROM :_groups g", $Permission_Map);
     // UserRole.
     $UserRole_Map = array('id' => 'UserID', 'group_id' => 'RoleID');
     $Ex->ExportTable('UserRole', "SELECT\n            CASE u.group_id WHEN 2 THEN 0 ELSE id END AS id,\n            u.group_id\n          FROM :_users u", $UserRole_Map);
     // Signatures.
     $Ex->ExportTable('UserMeta', "\n         SELECT\n         id,\n         'Plugin.Signatures.Sig' AS Name,\n         signature\n      FROM :_users u\n      WHERE u.signature IS NOT NULL", array('id ' => 'UserID', 'signature' => 'Value'));
     // Category.
     $Category_Map = array('id' => 'CategoryID', 'et_name' => 'Name', 'et_desc' => 'Description', 'disp_position' => 'Sort', 'parent_id' => 'ParentCategoryID');
     $Ex->ExportTable('Category', "\n      SELECT\n        id,\n        et_name,\n        et_desc,\n        disp_position,\n        cat_id * 1000 AS parent_id\n      FROM :_forums f\n      UNION\n\n      SELECT\n        id * 1000,\n        cat_name,\n        '',\n        disp_position,\n        NULL\n      FROM :_categories", $Category_Map);
     // Discussion.
     $Discussion_Map = array('id' => 'DiscussionID', 'poster_id' => 'InsertUserID', 'poster_ip' => 'InsertIPAddress', 'closed' => 'Closed', 'sticky' => 'Announce', 'et_id' => 'CategoryID', 'subject' => 'Name', 'message' => 'Body');
     $Ex->ExportTable('Discussion', "\n      SELECT t.*,\n        from_unixtime(p.posted) AS DateInserted,\n        p.poster_id,\n        p.poster_ip,\n        p.message,\n        from_unixtime(p.edited) AS DateUpdated,\n        eu.id AS UpdateUserID,\n        'BBCode' AS Format\n      FROM :_topics t\n      LEFT JOIN :_posts p\n        ON t.first_post_id = p.id\n      LEFT JOIN :_users eu\n        ON eu.username = p.edited_by", $Discussion_Map);
     // Comment.
     $Comment_Map = array('id' => 'CommentID', 'topic_id' => 'DiscussionID', 'poster_id' => 'InsertUserID', 'poster_ip' => 'InsertIPAddress', 'message' => 'Body');
     $Ex->ExportTable('Comment', "\n            SELECT p.*,\n        'BBCode' AS Format,\n        from_unixtime(p.posted) AS DateInserted,\n        from_unixtime(p.edited) AS DateUpdated,\n        eu.id AS UpdateUserID\n      FROM :_topics t\n      JOIN :_posts p\n        ON t.id = p.topic_id\n      LEFT JOIN :_users eu\n        ON eu.username = p.edited_by\n      WHERE p.id <> t.first_post_id;", $Comment_Map);
     if ($Ex->Exists('tags')) {
         // Tag.
         $Tag_Map = array('id' => 'TagID', 'tag' => 'Name');
         $Ex->ExportTable('Tag', "SELECT * FROM :_tags", $Tag_Map);
         // TagDisucssion.
         $TagDiscussionMap = array('topic_id' => 'DiscussionID', 'tag_id' => 'TagID');
         $Ex->ExportTable('TagDiscussion', "SELECT * FROM :_topic_tags", $TagDiscussionMap);
     }
     if ($Ex->Exists('attach_files')) {
         // Media.
         $Media_Map = array('id' => 'MediaID', 'filename' => 'Name', 'file_mime_type' => 'Type', 'size' => 'Size', 'owner_id' => 'InsertUserID');
         $Ex->ExportTable('Media', "\n          SELECT f.*,\n             concat({$this->cdn}, 'FileUpload/', f.file_path) AS Path,\n             from_unixtime(f.uploaded_at) AS DateInserted,\n             CASE WHEN post_id IS NULL THEN 'Discussion' ELSE 'Comment' END AS ForeignTable,\n             coalesce(post_id, topic_id) AS ForieignID\n          FROM :_attach_files f", $Media_Map);
     }
     // End
     $Ex->EndExport();
 }