Created
July 17, 2016 00:28
-
-
Save landsman/76fe66dea6343c451724491cb6ce1ffe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// CSV export Sunlight CMS for Wordpress, with plugin: https://wordpress.org/plugins/really-simple-csv-importer/ | |
ini_set('display_errors', 1); | |
ini_set('display_startup_errors', 1); | |
error_reporting(E_ALL); | |
/* --- kontrola jadra --- */ | |
if(!defined('_core')) exit; | |
if(isset($_POST['posts']) || isset($_POST['pages']) || isset($_POST['widgets'])) | |
{ | |
if(isset($_POST['posts'])) | |
{ | |
$query = DB::query("SELECT a.id as a_id, a.title as a_title, a.title_seo, a.description, a.perex, a.picture_uid, a.content as a_content, a.author, a.home1, a.home2, a.home3, a.time as a_time, a.readed, r.title, r.title_seo as r_title_seo, r2.title_seo as r2_title_seo, r3.title_seo as r3_title_seo, u.username | |
FROM `"._mysql_prefix."-articles` a | |
LEFT JOIN `"._mysql_prefix."-users` u ON(a.author=u.id) | |
LEFT JOIN `"._mysql_prefix."-root` r ON(a.home1=r.id) | |
LEFT JOIN `"._mysql_prefix."-root` r2 ON(a.home2=r2.id) | |
LEFT JOIN `"._mysql_prefix."-root` r3 ON(a.home3=r3.id)"); | |
$file = 'posts.csv'; | |
} | |
if(isset($_POST['pages'])) | |
{ | |
$query = DB::query("SELECT r.id, r.title as r_title, r.title_seo as slug, r.description, r.type, r.intersection, r.ord, r.content as r_content, r.level FROM `"._mysql_prefix."-root` r"); | |
$file = 'pages.csv'; | |
} | |
$fp = fopen(__DIR__ . '/' . $file, 'w'); | |
// legend | |
fputcsv($fp, array( | |
'post_id', | |
'post_name', | |
'post_author', | |
'post_date', | |
'post_type', | |
'post_status', | |
'post_title', | |
'post_content', | |
'post_category', | |
'post_thumbnail', | |
)); | |
// rows | |
while($i = DB::row($query)) | |
{ | |
if(isset($_POST['posts'])) | |
{ | |
$post = array( | |
'', // post_ID - $i['a_id'] | |
$i['title_seo'], // post_name | |
$i['username'], // post_author | |
date("Y-m-d H:i:s", $i['a_time']), // post_date | |
'post', // post type | |
'publish', // post status | |
$i['a_title'], // title | |
$i['a_content'], // post content | |
implode(array($i['r_title_seo'], $i['r2_title_seo'], $i['r3_title_seo']), ","), // post category | |
_url . "/pictures/articles/" . $i['picture_uid'] . ".jpg" // thumb | |
); | |
} | |
if(isset($_POST['pages'])) | |
{ | |
$post = array( | |
'', // id | |
$i['slug'], // post_name | |
'', // post_author | |
'', // post_date | |
'page', // post_type | |
'publish', // post status | |
$i['r_title'], // title | |
$i['r_content'], // post content | |
); | |
} | |
fputcsv($fp, $post); | |
} | |
fclose($fp); | |
} | |
$output .= '<fieldset> | |
<legend>Vygenerovat CSV pro export</legend> | |
<form name="gensm" method="post" enctype="multipart/form-data"> | |
<input name="posts" type="submit" value="Články"> | |
<input name="pages" type="submit" value="Stránky"> | |
'._xsrfProtect().' | |
</form> | |
</fieldset>'; | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment