| Difficulty | Intermediate |
| Skills Required | PHP,XML |
| Estimated Time Required | 60 minutes |
| Source Code Access Required | No |
| Categories | |
| Verified with Versions | 2.0 |
| Views | 2570 |
| Average Rating | |
When you create your social network on Ning, you have the option to export the additional member profile information your members choose to provide your network. In addition, you have the ability to back up the photos, videos, forums, blog posts, chatters, and comments that you and your members contribute to your social network.
To make the data export process easy, we've created a handy script that you can install on your network to let you easily export to a spreadsheet the additional data your members contribute to your social network.
The first step is to access the file system for your social network using WebDav.
Create a new file in the root directory of the file system for your social netork. The filename must be export-content.php with the following PHP contents:
<?php
$appOwner = XN_Application::load()->ownerName;
if ($appOwner != XN_Profile::load()->screenName) {
header('Location: /');
exit;
}
$type = $_POST['ctype'];
$user = $_POST['username'];
$pwd = $_POST['password'];
$contentTypes = array('Photo','Video','Topic','BlogPost');
if (!$type || !$user || !$pwd) { ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html>
<head>
<title>Content Export</title>
</head>
<body>
<h1>Export content from your network</h1>
<p>Please enter your Ning ID, password, and choose the type of content you want to export. This script lets provides you with the atom-format representation of 100 public items of the object type that you choose.</p>
<form method="post">
<dl>
<dt>User</dt>
<dd><input name="username" length=20/></dd>
</dl>
<dl>
<dt>Password</dt>
<dd><input name="password" length=20 type="password" /></dd>
</dl>
<dl>
<dt>Content Type</dt>
<dd>
<select name="ctype">
<?php
foreach ($contentTypes as $type) { ?>
<option value="<?php echo $type ?>"><?php echo $type ?></option>
<?php }
?>
</select>
</dd>
</dl>
<input type="submit" value="ok" />
</form>
</body>
</html>
<?php
} else {
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename=' . $type . '-export.xml');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://" . $_SERVER['HTTP_HOST'] . "/xn/atom/1.0/content(type='" . $type . "')");
curl_setopt($ch, CURLOPT_USERPWD, $user . ":" . $pwd);
curl_exec($ch);
curl_close($ch);
}
?>
Click the Create File button, and you're done.
Now you can go to yournetworkname.ning.com/export-content.php and this will ask you one more time for your username and password. Note: You need to be the network's owner to be able to run this script and obtain the content. You also need to choose which data type you want to obtain, and you'll receive back the option to save a file with the contents of the Atom feed for that particular content type.
Created Jun 12, 2008 at 2:13pm. Last updated just now.
© 2008 Created by Ning Developer Admin