aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-08-20 21:08:15 -0400
committerAndrew Manning <tamanning@zoho.com>2016-08-20 21:08:15 -0400
commit1c61e316b477460f05b263b9a01cc5d37b5e8cb6 (patch)
treefc151860f3899135ec1d5303c21e31e0618b911f
parent2d42d587388aeaedf8b53b2b56b3b4ccda37af03 (diff)
downloadvolse-hubzilla-1c61e316b477460f05b263b9a01cc5d37b5e8cb6.tar.gz
volse-hubzilla-1c61e316b477460f05b263b9a01cc5d37b5e8cb6.tar.bz2
volse-hubzilla-1c61e316b477460f05b263b9a01cc5d37b5e8cb6.zip
Block export and re-import works. Fixed bug where layout content was not being imported properly.
-rw-r--r--Zotlabs/Module/Webpages.php69
-rw-r--r--include/import.php55
-rw-r--r--view/tpl/webpage_export_list.tpl36
3 files changed, 157 insertions, 3 deletions
diff --git a/Zotlabs/Module/Webpages.php b/Zotlabs/Module/Webpages.php
index 9a0e311d6..0fec06c38 100644
--- a/Zotlabs/Module/Webpages.php
+++ b/Zotlabs/Module/Webpages.php
@@ -71,12 +71,14 @@ class Webpages extends \Zotlabs\Web\Controller {
$pages = get_webpage_elements($channel, 'pages');
$layouts = get_webpage_elements($channel, 'layouts');
+ $blocks = get_webpage_elements($channel, 'blocks');
$o .= replace_macros(get_markup_template('webpage_export_list.tpl'), array(
'$title' => t('Export Webpage Elements'),
'$exportbtn' => t('Export selected'),
'$action' => $_SESSION['export'], // value should be 'zipfile' or 'cloud'
'$pages' => $pages['pages'],
'$layouts' => $layouts['layouts'],
+ '$blocks' => $blocks['blocks'],
));
$_SESSION['export'] = null;
return $o;
@@ -314,6 +316,7 @@ class Webpages extends \Zotlabs\Web\Controller {
$path = $website;
}
$elements['pages'] = scan_webpage_elements($path, 'page', $cloud);
+ logger('$elements pages: ' . json_encode($elements['pages']));
$elements['layouts'] = scan_webpage_elements($path, 'layout', $cloud);
$elements['blocks'] = scan_webpage_elements($path, 'block', $cloud);
$_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 ($cloud === false && $website && $elements) {
- rrmdir($website); // Delete the temporary decompressed files
+ $_SESSION['tempimportpath'] = $website;
+ //rrmdir($website); // Delete the temporary decompressed files
}
break;
@@ -399,6 +403,10 @@ class Webpages extends \Zotlabs\Web\Controller {
if(!(empty($_SESSION['import_pages']) && empty($_SESSION['import_blocks']) && empty($_SESSION['import_layouts']))) {
info( t('Import complete.') . EOL);
}
+ if(isset($_SESSION['tempimportpath'])) {
+ rrmdir($_SESSION['tempimportpath']); // Delete the temporary decompressed files
+ unset($_SESSION['tempimportpath']);
+ }
break;
case 'exportzipfile':
@@ -432,6 +440,64 @@ class Webpages extends \Zotlabs\Web\Controller {
}
$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'];
$layouts = [];
if (!empty($checkedlayouts)) {
@@ -452,6 +518,7 @@ class Webpages extends \Zotlabs\Web\Controller {
'json' => array(
'description' => $l['title'],
'name' => $l['v'],
+ 'mimetype' => $l['mimetype'],
)
);
switch ($layoutinfo['mimetype']) {
diff --git a/include/import.php b/include/import.php
index a62747d9b..10664aa53 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1311,9 +1311,15 @@ function scan_webpage_elements($path, $type, $cloud = false) {
return false;
}
$content = file_get_contents($folder . '/' . $contentfilename);
+ logger('contentfile: ' . $folder . '/' . $contentfilename, LOGGER_DEBUG);
+ logger('content: ' . $content, LOGGER_DEBUG);
if (!$content) {
- logger('Failed to get file content for ' . $metadata['contentfile']);
- return false;
+ if(is_readable($folder . '/' . $contentfilename)) {
+ $content = '';
+ } else {
+ logger('Failed to get file content for ' . $metadata['contentfile']);
+ return false;
+ }
}
$elements[] = $metadata;
}
@@ -1403,6 +1409,10 @@ function scan_webpage_elements($path, $type, $cloud = false) {
}
// Import the actual element content
$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
$arr['owner_xchan'] = get_observer_hash();
// The author is either the owner or whomever was specified
@@ -1573,6 +1583,47 @@ function get_webpage_elements($channel, $type = 'all') {
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:
break;
}
diff --git a/view/tpl/webpage_export_list.tpl b/view/tpl/webpage_export_list.tpl
index faffbf8c6..1df4586b0 100644
--- a/view/tpl/webpage_export_list.tpl
+++ b/view/tpl/webpage_export_list.tpl
@@ -82,6 +82,42 @@
{{/foreach}}
</table>
</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>
</form>
</div>