Block export and re-import works. Fixed bug where layout content was not being imported properly.
This commit is contained in:
parent
2d42d58738
commit
1c61e316b4
@ -71,12 +71,14 @@ class Webpages extends \Zotlabs\Web\Controller {
|
|||||||
|
|
||||||
$pages = get_webpage_elements($channel, 'pages');
|
$pages = get_webpage_elements($channel, 'pages');
|
||||||
$layouts = get_webpage_elements($channel, 'layouts');
|
$layouts = get_webpage_elements($channel, 'layouts');
|
||||||
|
$blocks = get_webpage_elements($channel, 'blocks');
|
||||||
$o .= replace_macros(get_markup_template('webpage_export_list.tpl'), array(
|
$o .= replace_macros(get_markup_template('webpage_export_list.tpl'), array(
|
||||||
'$title' => t('Export Webpage Elements'),
|
'$title' => t('Export Webpage Elements'),
|
||||||
'$exportbtn' => t('Export selected'),
|
'$exportbtn' => t('Export selected'),
|
||||||
'$action' => $_SESSION['export'], // value should be 'zipfile' or 'cloud'
|
'$action' => $_SESSION['export'], // value should be 'zipfile' or 'cloud'
|
||||||
'$pages' => $pages['pages'],
|
'$pages' => $pages['pages'],
|
||||||
'$layouts' => $layouts['layouts'],
|
'$layouts' => $layouts['layouts'],
|
||||||
|
'$blocks' => $blocks['blocks'],
|
||||||
));
|
));
|
||||||
$_SESSION['export'] = null;
|
$_SESSION['export'] = null;
|
||||||
return $o;
|
return $o;
|
||||||
@ -314,6 +316,7 @@ class Webpages extends \Zotlabs\Web\Controller {
|
|||||||
$path = $website;
|
$path = $website;
|
||||||
}
|
}
|
||||||
$elements['pages'] = scan_webpage_elements($path, 'page', $cloud);
|
$elements['pages'] = scan_webpage_elements($path, 'page', $cloud);
|
||||||
|
logger('$elements pages: ' . json_encode($elements['pages']));
|
||||||
$elements['layouts'] = scan_webpage_elements($path, 'layout', $cloud);
|
$elements['layouts'] = scan_webpage_elements($path, 'layout', $cloud);
|
||||||
$elements['blocks'] = scan_webpage_elements($path, 'block', $cloud);
|
$elements['blocks'] = scan_webpage_elements($path, 'block', $cloud);
|
||||||
$_SESSION['blocks'] = $elements['blocks'];
|
$_SESSION['blocks'] = $elements['blocks'];
|
||||||
@ -331,7 +334,8 @@ class Webpages extends \Zotlabs\Web\Controller {
|
|||||||
|
|
||||||
// If the website elements were imported from a zip file, delete the temporary decompressed files
|
// If the website elements were imported from a zip file, delete the temporary decompressed files
|
||||||
if ($cloud === false && $website && $elements) {
|
if ($cloud === false && $website && $elements) {
|
||||||
rrmdir($website); // Delete the temporary decompressed files
|
$_SESSION['tempimportpath'] = $website;
|
||||||
|
//rrmdir($website); // Delete the temporary decompressed files
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -399,6 +403,10 @@ class Webpages extends \Zotlabs\Web\Controller {
|
|||||||
if(!(empty($_SESSION['import_pages']) && empty($_SESSION['import_blocks']) && empty($_SESSION['import_layouts']))) {
|
if(!(empty($_SESSION['import_pages']) && empty($_SESSION['import_blocks']) && empty($_SESSION['import_layouts']))) {
|
||||||
info( t('Import complete.') . EOL);
|
info( t('Import complete.') . EOL);
|
||||||
}
|
}
|
||||||
|
if(isset($_SESSION['tempimportpath'])) {
|
||||||
|
rrmdir($_SESSION['tempimportpath']); // Delete the temporary decompressed files
|
||||||
|
unset($_SESSION['tempimportpath']);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'exportzipfile':
|
case 'exportzipfile':
|
||||||
@ -432,6 +440,64 @@ class Webpages extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
$zip_filepath = '/tmp/' . $zip_folder_name . '/' . $zip_filename;
|
$zip_filepath = '/tmp/' . $zip_folder_name . '/' . $zip_filename;
|
||||||
|
|
||||||
|
$checkedblocks = $_POST['block'];
|
||||||
|
$blocks = [];
|
||||||
|
if (!empty($checkedblocks)) {
|
||||||
|
foreach ($checkedblocks as $mid) {
|
||||||
|
$b = q("select iconfig.v, iconfig.k, mimetype, title, body from iconfig
|
||||||
|
left join item on item.id = iconfig.iid
|
||||||
|
where mid = '%s' and item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'BUILDBLOCK' order by iconfig.v asc limit 1",
|
||||||
|
dbesc($mid),
|
||||||
|
intval($channel['channel_id'])
|
||||||
|
);
|
||||||
|
if($b) {
|
||||||
|
$b = $b[0];
|
||||||
|
$blockinfo = array(
|
||||||
|
'body' => $b['body'],
|
||||||
|
'mimetype' => $b['mimetype'],
|
||||||
|
'title' => $b['title'],
|
||||||
|
'name' => $b['v'],
|
||||||
|
'json' => array(
|
||||||
|
'title' => $b['title'],
|
||||||
|
'name' => $b['v'],
|
||||||
|
'mimetype' => $b['mimetype'],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
switch ($blockinfo['mimetype']) {
|
||||||
|
case 'text/html':
|
||||||
|
$block_ext = 'html';
|
||||||
|
break;
|
||||||
|
case 'text/bbcode':
|
||||||
|
$block_ext = 'bbcode';
|
||||||
|
break;
|
||||||
|
case 'text/markdown':
|
||||||
|
$block_ext = 'md';
|
||||||
|
break;
|
||||||
|
case 'application/x-pdl':
|
||||||
|
$block_ext = 'pdl';
|
||||||
|
break;
|
||||||
|
case 'application/x-php':
|
||||||
|
$block_ext = 'php';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$block_ext = 'bbcode';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$block_filename = $blockinfo['name'] . '.' . $block_ext;
|
||||||
|
$tmp_blockfolder = $tmp_folderpath . '/blocks/' . $blockinfo['name'];
|
||||||
|
$block_filepath = $tmp_blockfolder . '/' . $block_filename;
|
||||||
|
$blockinfo['json']['contentfile'] = $block_filename;
|
||||||
|
$block_jsonpath = $tmp_blockfolder . '/block.json';
|
||||||
|
if (!is_dir($tmp_blockfolder) && !mkdir($tmp_blockfolder, 0770, true)) {
|
||||||
|
logger('Error creating temp export folder: ' . $tmp_blockfolder, LOGGER_NORMAL);
|
||||||
|
json_return_and_die(array('message' => 'Error creating temp export folder'));
|
||||||
|
}
|
||||||
|
file_put_contents($block_filepath, $blockinfo['body']);
|
||||||
|
file_put_contents($block_jsonpath, json_encode($blockinfo['json'], JSON_UNESCAPED_SLASHES));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$checkedlayouts = $_POST['layout'];
|
$checkedlayouts = $_POST['layout'];
|
||||||
$layouts = [];
|
$layouts = [];
|
||||||
if (!empty($checkedlayouts)) {
|
if (!empty($checkedlayouts)) {
|
||||||
@ -452,6 +518,7 @@ class Webpages extends \Zotlabs\Web\Controller {
|
|||||||
'json' => array(
|
'json' => array(
|
||||||
'description' => $l['title'],
|
'description' => $l['title'],
|
||||||
'name' => $l['v'],
|
'name' => $l['v'],
|
||||||
|
'mimetype' => $l['mimetype'],
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
switch ($layoutinfo['mimetype']) {
|
switch ($layoutinfo['mimetype']) {
|
||||||
|
@ -1311,10 +1311,16 @@ function scan_webpage_elements($path, $type, $cloud = false) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$content = file_get_contents($folder . '/' . $contentfilename);
|
$content = file_get_contents($folder . '/' . $contentfilename);
|
||||||
|
logger('contentfile: ' . $folder . '/' . $contentfilename, LOGGER_DEBUG);
|
||||||
|
logger('content: ' . $content, LOGGER_DEBUG);
|
||||||
if (!$content) {
|
if (!$content) {
|
||||||
|
if(is_readable($folder . '/' . $contentfilename)) {
|
||||||
|
$content = '';
|
||||||
|
} else {
|
||||||
logger('Failed to get file content for ' . $metadata['contentfile']);
|
logger('Failed to get file content for ' . $metadata['contentfile']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$elements[] = $metadata;
|
$elements[] = $metadata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1403,6 +1409,10 @@ function scan_webpage_elements($path, $type, $cloud = false) {
|
|||||||
}
|
}
|
||||||
// Import the actual element content
|
// Import the actual element content
|
||||||
$arr['body'] = file_get_contents($element['path']);
|
$arr['body'] = file_get_contents($element['path']);
|
||||||
|
if($arr['item_type'] === ITEM_TYPE_PDL) {
|
||||||
|
logger(' body: ' . $arr['body'], LOGGER_DEBUG);
|
||||||
|
logger(' path: ' . $element['path'], LOGGER_DEBUG);
|
||||||
|
}
|
||||||
// The element owner is the channel importing the elements
|
// The element owner is the channel importing the elements
|
||||||
$arr['owner_xchan'] = get_observer_hash();
|
$arr['owner_xchan'] = get_observer_hash();
|
||||||
// The author is either the owner or whomever was specified
|
// The author is either the owner or whomever was specified
|
||||||
@ -1573,6 +1583,47 @@ function get_webpage_elements($channel, $type = 'all') {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case 'blocks':
|
||||||
|
$elements['blocks'] = null;
|
||||||
|
$owner = $channel['channel_id'];
|
||||||
|
|
||||||
|
$sql_extra = item_permissions_sql($owner);
|
||||||
|
|
||||||
|
|
||||||
|
$r = q("select iconfig.iid, iconfig.k, iconfig.v, mid, title, body, mimetype, created, edited from iconfig
|
||||||
|
left join item on iconfig.iid = item.id
|
||||||
|
where uid = %d and iconfig.cat = 'system' and iconfig.k = 'BUILDBLOCK'
|
||||||
|
and item_type = %d order by item.created desc",
|
||||||
|
intval($owner),
|
||||||
|
intval(ITEM_TYPE_BLOCK)
|
||||||
|
);
|
||||||
|
|
||||||
|
$blocks = null;
|
||||||
|
|
||||||
|
if($r) {
|
||||||
|
$elements['blocks'] = array();
|
||||||
|
$blocks = array();
|
||||||
|
foreach($r as $rr) {
|
||||||
|
unobscure($rr);
|
||||||
|
|
||||||
|
$elements['blocks'][] = array(
|
||||||
|
'type' => 'block',
|
||||||
|
'title' => $rr['title'],
|
||||||
|
'body' => $rr['body'],
|
||||||
|
'created' => $rr['created'],
|
||||||
|
'edited' => $rr['edited'],
|
||||||
|
'mimetype' => $rr['mimetype'],
|
||||||
|
'name' => $rr['v'],
|
||||||
|
'mid' => $rr['mid']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if($type !== 'all') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,42 @@
|
|||||||
{{/foreach}}
|
{{/foreach}}
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="clear"></div>
|
||||||
|
<h4>Blocks</h4>
|
||||||
|
<div>
|
||||||
|
<table class="table-striped table-responsive table-hover" style="width: 100%;">
|
||||||
|
<thead>
|
||||||
|
<tr><th>Export?</th><th>Block Title</th><th>Block Name</th><th>Type</th></tr>
|
||||||
|
</thead>
|
||||||
|
{{foreach $blocks as $block}}
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<div class='squaredThree'>
|
||||||
|
<input type="checkbox" id="block_{{$block.mid}}" name="block[]" value="{{$block.mid}}">
|
||||||
|
<label for="block_{{$block.mid}}"></label>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="desc">
|
||||||
|
{{$block.title}}<br>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class='desc'>
|
||||||
|
{{$block.name}}<br>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class='desc'>
|
||||||
|
{{$block.mimetype}}<br>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{{/foreach}}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user