Skip to:
Content
Pages
Categories
Search
Top
Bottom

Anyone Used bbPress Exporter 0.1a?

Viewing 3 replies - 1 through 3 (of 3 total)

  • Olaf Lederer
    Participant

    @finalwebsites

    don’t know what this is but be careful.

    I can’t open the files on Linux, but it might be some virus too (on a windows system)

    @Olaf: it’s a set of PHP scripts in zip archives, don’t freak. Just badly formatted is all. And yes, I just checked that under Windows with an up-to-date anti-virus running. Haven’t got the time to check the PHP code itself mind you ;)

    @gerikg: it’s a plugin, which I think is intended to be a relatively universal data exporter between forums. How you import is a good question though.

    bbPress Exporter 0.1a

    exporter-bbpress.php

    <?php
    /*
    Plugin Name: Export
    Plugin URI: https://www.bbpress.org/
    Description: Allows administrators to export forum data.
    Author: Dan Larkin
    Version: 0.1 alpha
    Author URI: http://www.stealyourcarbon.net/
    */

    /**
    * Includes necessary files.
    */
    function export_init ()
    {
    require_once ('wfxp.php');
    require_once ('wfxp-bbpress.php');
    }

    /**
    * Executes all necessary functions to make the exportation happen.
    */
    function export_main ()
    {
    global $bbdb;
    export_init ();
    $bbxp = new WFXP_bbPress ($bbdb);
    $bbxp->db = $bbdb;
    $filename = 'bbpress' . date ('Y-m-d') . '.xml';

    $bbxp->write_header ($filename);
    $bbxp->write_users ();
    $bbxp->write_forums ();
    $bbxp->write_topics ();
    $bbxp->write_footer ();

    die ();

    }

    /**
    * Displays the admin export page.
    *
    * Gives a simple explanation of how the export file works and gives
    * users a nice shiny button to click.
    */
    function export_page ()
    {
    ?>

    <div class="wrap">
    <h2><?php _e ('Export') ?></h2>
    <p><?php _e ('When you click the button below, bbPress will generate an XML file for you to save to your computer.'); ?></p>
    <p><?php _e ('This file will contain data about your users, forums, topics, and posts. You can use the Import function of another bbPress installation or another compatible web forums software to import this data.'); ?></p>
    <form action="" method="get">
    <p class="submit">
    <input type="submit" name="submit" value="<?php _e ('Download Export File'); ?>" />
    <input type="hidden" name="exporting" value="true" />
    </p>
    </form>
    </div>

    <?php
    }

    /**
    * Adds export link to admin menu.
    */
    function export_add_admin ()
    {
    global $bb_submenu;
    $bb_submenu['content.php'][] = array (__('Export'), 'use_keys', 'export_page', 'exporter-bbpress.php');
    }

    if ('true' == $_GET['exporting'] )
    {
    add_action ('bb_init', 'export_main');
    }

    add_action ('bb_admin_menu_generator', 'export_add_admin');

    ?>

    wfxp.php

    <?php
    /**
    * Web Forums Data Export Class
    *
    * This class contains a number of functions used to take formatted
    * input and output it into a standard XML file for use in transporting
    * data between installations. Class extensions and plugins can be found
    * for various software.
    */
    class WFXP
    {

    /**
    * Instance of BPDB.
    */
    var $db;

    /**
    * Pseudonym for BPDB's get_results.
    *
    * This is a renaming of BPDB's get_results method to eliminate the need
    * for the second parameter by always returning an associative array.
    */
    function fetch ($query)
    {
    return $this->db->get_results ($query, 'ARRAY_A');
    }

    /**
    * Adds formatted user data to the output.
    */
    function add_user ($user)
    {
    ?>
    <user id="<?php echo $user['id']; ?>">
    <login><?php echo $user['login']; ?></login>
    <pass type="<?php echo $user['pass']['type']; ?>"><?php echo $user['pass']['pass'] ?></pass>
    <incept><?php echo $user['incept']; ?></incept>
    <status><?php echo $user['status']; ?></status>
    <?php
    if ($user['meta'])
    {
    foreach ($user['meta'] as $meta)
    {
    $this->add_meta ($meta, 'user');
    }
    }
    ?>
    </user>

    <?php
    }

    /**
    * Adds formatted forum data to the output.
    */
    function add_forum ($forum)
    {
    ?>
    <forum id="<?php echo $forum['id']; ?>" in="<?php echo $forum['in']; ?>">
    <title><![CDATA[<?php echo $forum['title']; ?>]]></title>
    <content><![CDATA[<?php echo $forum['content']; ?>]]></content>
    <?php
    if ($forum['meta'])
    {
    foreach ($forum['meta'] as $meta)
    {
    $this->add_meta ($meta, 'forum');
    }
    }
    ?>
    </forum>

    <?php
    }

    /**
    * Adds formatted topic data to the output
    */
    function add_topic ($topic)
    {
    ?>
    <topic id="<?php echo $topic['id']; ?>" author="<?php echo $topic['author']; ?>" in="<?php echo $topic['in']; ?>">
    <title><![CDATA[<?php echo $topic['title']; ?>]]></title>
    <incept><?php echo $topic['incept']; ?></incept>
    <status><?php echo $topic['status']; ?></status>
    <?php
    if ($topic['meta'])
    {
    foreach ($topic['meta'] as $meta)
    {
    $this->add_meta ($meta, 'topic');
    }
    }
    if ($topic['tags'])
    {
    foreach ($topic['tags'] as $tag)
    {
    $this->add_tag ($tag);
    }
    }
    ?>

    <?php
    foreach ($topic['posts'] as $post)
    {
    $this->add_post ($post);
    }
    ?>
    </topic>

    <?php
    }

    /**
    * Adds formatted post data to the output.
    */
    function add_post ($post)
    {
    ?>
    <post id="<?php echo $post['id']; ?>" author="<?php echo $post['author']; ?>">
    <title><![CDATA[<?php echo $post['title']; ?>]]></title>
    <content><![CDATA[<?php echo $post['content']; ?>]]></content>
    <incept><?php echo $post['incept']; ?></incept>
    <status><?php echo $post['status']; ?></status>
    <?php
    if ($post['meta'])
    {
    foreach ($post['meta'] as $meta)
    {
    $this->add_meta ($meta, 'post');
    }
    }
    ?>
    </post>

    <?php
    }

    /**
    * Adds formatted tag data to the output.
    */
    function add_tag ($tag)
    {
    ?>
    <tag><![CDATA[<?php echo $tag; ?>]]></tag>
    <?php
    }

    /**
    * Adds formatted meta data to the output.
    *
    * Indentation varies depending on what type of element the meta data
    * is being added to so as to make the output pretty.
    */
    function add_meta ($meta, $type)
    {
    if ('post' == $type)
    {
    ?>
    <meta key="<?php echo $meta['key']; ?>"><![CDATA[<?php echo $meta['value']; ?>]]></meta>
    <?php

    }
    else
    {
    ?>
    <meta key="<?php echo $meta['key']; ?>"><![CDATA[<?php echo $meta['value']; ?>]]></meta>
    <?php

    }
    }

    /**
    * Writes file headers.
    *
    * Writes HTTP headers and adds the XML declaration as well as
    * the top level container to the output.
    */
    function write_header ($filename)
    {
    header ('Content-Description: File Transfer');
    header ('Content-Dispositon: attachment; filename=' . $filename);
    header ('Content-Type: text/xml');

    echo '<?xml version="1.0" encoding="UTF-8" ?>';
    ?>

    <forums_data>

    <?php
    }

    /**
    * Adds the closing tag for the top level container to the output.
    */
    function write_footer ()
    {
    ?>
    </forums_data>
    <?php
    }

    }
    ?>

    wfxp-bbpress.php

    <?php
    /**
    * bbPress WFXP Extension
    *
    * This class includes functions necessary for bbPress to interface
    * with the WFXP class, allowing for exportation of bbPress data to
    * a standard XML file.
    */
    class WFXP_bbPress extends WFXP
    {
    /**
    * Fetches users from the database.
    */
    function fetch_users ()
    {
    return $this->fetch ('SELECT * FROM ' . $this->db->users . ' WHERE 1');
    }

    /**
    * Fetches forums from the database.
    */
    function fetch_forums ()
    {
    return $this->fetch ('SELECT * FROM ' . $this->db->forums . ' WHERE 1');
    }

    /**
    * Fetches topics from the database.
    */
    function fetch_topics ()
    {
    return $this->fetch ('SELECT * FROM ' . $this->db->topics . ' WHERE 1');
    }

    /**
    * Fetches posts from the database.
    */
    function fetch_posts ($topic_id)
    {
    return $this->fetch ('SELECT * FROM ' . $this->db->posts . ' WHERE topic_id="' . $topic_id . '"');
    }

    /**
    * Fetches user meta data from the database.
    */
    function fetch_user_meta ($user_id)
    {
    return $this->fetch ('SELECT meta_key, meta_value FROM ' . $this->db->usermeta . ' WHERE user_id="' . $user_id . '"');
    }

    /**
    * Fetches topic meta data from the database.
    */
    function fetch_topic_meta ($topic_id)
    {
    return $this->fetch ('SELECT meta_key, meta_value FROM ' . $this->db->meta . ' WHERE object_type="bb_topic" AND object_id="' . $topic_id . '"');
    }

    /**
    * Fetches topic tags from the database.
    *
    * Fetching topic tags requires multiple queries to
    * determine the relationships between terms and IDs.
    */
    function fetch_topic_tags ($topic_id)
    {
    $taxonomy_ids = $this->fetch ('SELECT term_taxonomy_id FROM ' . $this->db->term_relationships . ' WHERE object_id="' . $topic_id . '"');
    if ($taxonomy_ids)
    {
    foreach ($taxonomy_ids as $taxonomy_id)
    {
    $term_id = $this->fetch ('SELECT term_id FROM ' . $this->db->term_taxonomy . ' WHERE term_taxonomy_id="' . $taxonomy_id['term_taxonomy_id'] . '"');
    $tag = $this->fetch ('SELECT name FROM ' . $this->db->terms . ' WHERE term_id="' . $term_id[0]['term_id'] . '"');
    $tags[] = $tag[0];
    }
    }
    return $tags;
    }

    /**
    * Prepares retrieved user data for output.
    */
    function prep_user_data ($raw_user, $raw_meta)
    {
    $user['id'] = $raw_user['ID'];
    $user['login'] = $raw_user['user_login'];
    if (32 < strlen ($raw_user['user_pass']))
    {
    if (!strcmp (substr ($raw_user['user_pass'], 0, 4), '$P$B'))
    {
    $user['pass']['type'] = 'phpass';
    }
    else
    {
    $user['pass']['type'] = 'unknown';
    }
    }
    else
    {
    $user['pass']['type'] = 'md5';
    }
    $user['pass']['pass'] = $raw_user['user_pass'];
    $user['incept'] = $raw_user['user_registered'];
    $user['status'] = $raw_user['user_status'];
    $user['meta'][] = array ('key' => 'nicename', 'value' => $raw_user['user_nicename']);
    $user['meta'][] = array ('key' => 'email', 'value' => $raw_user['user_email']);
    $user['meta'][] = array ('key' => 'url', 'value' => $raw_user['user_url']);
    $user['meta'][] = array ('key' => 'display_name', 'value' => $raw_user['display_name']);
    if ($raw_meta)
    {
    foreach ($raw_meta as $raw_meta_entry)
    {
    $user['meta'][] = $this->prep_meta_data ($raw_meta_entry);
    }
    }
    return $user;
    }

    /**
    * Prepares retrieved forum data for output.
    */
    function prep_forum_data ($raw_forum)
    {
    $forum['id'] = $raw_forum['forum_id'];
    $forum['in'] = $raw_forum['forum_parent'];
    $forum['title'] = $raw_forum['forum_name'];
    $forum['content'] = $raw_forum['forum_desc'];
    $forum['meta'][] = array ('key' => 'slug', 'value' => $raw_forum['forum_slug']);
    $forum['meta'][] = array ('key' => 'order', 'value' => $raw_forum['forum_order']);
    return $forum;
    }

    /**
    * Prepares retrieved topic data for output.
    */
    function prep_topic_data ($raw_topic, $raw_meta, $raw_tags, $raw_posts)
    {
    $topic['id'] = $raw_topic['topic_id'];
    $topic['author'] = $raw_topic['topic_poster'];
    $topic['in'] = $raw_topic['forum_id'];
    $topic['title'] = $raw_topic['topic_title'];
    $topic['incept'] = $raw_topic['topic_start_time'];
    $topic['status'] = $raw_topic['topic_status'];
    $topic['meta'][] = array ('key' => 'slug', 'value' => $raw_topic['topic_slug']);
    $topic['meta'][] = array ('key' => 'open', 'value' => $raw_topic['topic_open']);
    $topic['meta'][] = array ('key' => 'sticky', 'value' => $raw_topic['topic_sticky']);
    if ($raw_meta)
    {
    foreach ($raw_meta as $raw_meta_entry)
    {
    $topic['meta'][] = $this->prep_meta_data ($raw_meta_entry);
    }
    }
    if ($raw_tags)
    {
    foreach ($raw_tags as $raw_tag)
    {
    $topic['tags'][] = $this->prep_tag_data ($raw_tag);
    }
    }
    foreach ($raw_posts as $raw_post)
    {
    $topic['posts'][] = $this->prep_post_data ($raw_post);
    }
    return $topic;
    }

    /**
    * Prepares retrieved post data for output.
    */
    function prep_post_data ($raw_post)
    {
    $post['id'] = $raw_post['post_id'];
    $post['author'] = $raw_post['poster_id'];
    $post['title'] = '';
    $post['content'] = $raw_post['post_text'];
    $post['incept'] = $raw_post['post_time'];
    $post['status'] = $raw_post['post_status'];
    $post['meta'][] = array ('key' => 'ip_address', 'value' => $raw_post['poster_ip']);
    return $post;
    }

    /**
    * Prepares retrieved tag data for output.
    */
    function prep_tag_data ($raw_tag)
    {
    return $raw_tag['name'];
    }

    /**
    * Prepares retrieved meta data for output.
    */
    function prep_meta_data ($raw_meta)
    {
    return array ('key' => $raw_meta['meta_key'], 'value' => $raw_meta['meta_value']);
    }

    /**
    * Fetches, prepares, and outputs user data using subroutines.
    */
    function write_users ()
    {
    $users = $this->fetch_users ();
    foreach ($users as $user)
    {
    $user_meta = $this->fetch_user_meta ($user['ID']);
    $user = $this->prep_user_data ($user, $user_meta);
    $this->add_user ($user);
    }
    }

    /**
    * Fetches, prepares, and outputs forum data using subroutines.
    */
    function write_forums ()
    {
    $forums = $this->fetch_forums ();
    foreach ($forums as $forum)
    {
    $forum = $this->prep_forum_data ($forum, $forum_meta);
    $this->add_forum ($forum);
    }
    }

    /**
    * Fetches, prepares, and outputs topic data using subroutines.
    */
    function write_topics ()
    {
    $topics = $this->fetch_topics ();
    foreach ($topics as $topic)
    {
    $topic_meta = $this->fetch_topic_meta ($topic['topic_id']);
    $topic_tags = $this->fetch_topic_tags ($topic['topic_id']);
    $topic_posts = $this->fetch_posts ($topic['topic_id']);
    $topic = $this->prep_topic_data ($topic, $topic_meta, $topic_tags, $topic_posts);
    $this->add_topic ($topic);
    }
    }

    }
    ?>

    It also has the Web Forum Export/Import Standard Validator, but I think this post is long enough already :P

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar