/ Published in: PHP
1) name the file something like "template-pods-export.php"
2) create a new Pods Page & choose the newly created template
3) goto your worpress URL/export
4) enter filename.csv & pod name you want to export.
5) Submit.
6) Away Laughing
2) create a new Pods Page & choose the newly created template
3) goto your worpress URL/export
4) enter filename.csv & pod name you want to export.
5) Submit.
6) Away Laughing
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /* Template Name: Export Pods Data */ ?> <?php function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?> <form action="<?php echo curPageURL(); ?>" method="post"> <label for="out_file">Output File</label><br /> <input type="text" name="out_file" id="out_file" /><br /> <label for="use_pod">Pod to Export</label><br /> <input type="text" name="use_pod" id="use_pod" /><br /> <input type="submit" name="export_submit" /> </form> <?php $out_file = $_POST['out_file']; $use_pod = $_POST['use_pod']; export($out_file, $use_pod); } ?> <?php function export($out_file, $use_pod){ $export = "csv"; // Can be "php" or "csv" (default: php) $Record = new PodAPI($use_pod, $export); $data = $Record->export(); global $user_ID , $user_level; get_currentuserinfo(); //Get the information about the current user. if ($user_ID && 10 == $user_level) { //Check to see if the user is logged in and is an administrator if (($fp = fopen($out_file, 'w')) === FALSE) { //Attempt to open $out_file for writing and check for success. } foreach ($data as $line) { //Loop through the data line by line foreach ($line as &$field) { //Loop through each line of data by field $field = 'array(' . implode(', ', $field) . ')'; //Implode the items into a comma separated list wrapped in array(). } } } } else { //Otherwise, output the data as PHP } echo "Export complete. <a href='$out_file'>Open $out_file</a><br /><br />\n"; } else { //User doesn't have permission include(get_404_template()); //Nothing to see here, move along... } } function comma_trans(&$item) { } ?>