aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Webpages.php
diff options
context:
space:
mode:
authorAndrew Manning <tamanning@zoho.com>2016-07-30 09:56:47 -0400
committerAndrew Manning <tamanning@zoho.com>2016-07-30 09:56:47 -0400
commit32366284a8372a4d5c7798b3ee3b238a614915ab (patch)
tree5f777a13eb7e9d1db7a2471321b3851e246940f8 /Zotlabs/Module/Webpages.php
parentf17f51a9c1f62dc0229e2428cacea4e84313560e (diff)
downloadvolse-hubzilla-32366284a8372a4d5c7798b3ee3b238a614915ab.tar.gz
volse-hubzilla-32366284a8372a4d5c7798b3ee3b238a614915ab.tar.bz2
volse-hubzilla-32366284a8372a4d5c7798b3ee3b238a614915ab.zip
Import element selection page added to allow selective importing.
Diffstat (limited to 'Zotlabs/Module/Webpages.php')
-rw-r--r--Zotlabs/Module/Webpages.php113
1 files changed, 91 insertions, 22 deletions
diff --git a/Zotlabs/Module/Webpages.php b/Zotlabs/Module/Webpages.php
index ab03b0a37..ee9633243 100644
--- a/Zotlabs/Module/Webpages.php
+++ b/Zotlabs/Module/Webpages.php
@@ -45,7 +45,29 @@ class Webpages extends \Zotlabs\Web\Controller {
$observer = \App::get_observer();
$channel = \App::get_channel();
-
+
+ switch ($_SESSION['action']) {
+ case 'import':
+ $_SESSION['action'] = null;
+ $o .= replace_macros(get_markup_template('webpage_import.tpl'), array(
+ '$title' => t('Import Webpage Elements'),
+ '$action' => 'import',
+ '$pages' => $_SESSION['pages'],
+ '$layouts' => $_SESSION['layouts'],
+ '$blocks' => $_SESSION['blocks'],
+ ));
+ //logger('webpage_import.tpl: ' . $o);
+ return $o;
+
+ case 'importselected':
+ $_SESSION['action'] = null;
+ break;
+ default :
+ $_SESSION['action'] = null;
+ break;
+ }
+
+
if(\App::$is_sys && is_site_admin()) {
$sys = get_sys_channel();
if($sys && intval($sys['channel_id'])) {
@@ -270,29 +292,15 @@ class Webpages extends \Zotlabs\Web\Controller {
$elements['pages'] = scan_webpage_elements($_POST['path'], 'page', $cloud);
$elements['layouts'] = scan_webpage_elements($_POST['path'], 'layout', $cloud);
$elements['blocks'] = scan_webpage_elements($_POST['path'], 'block', $cloud);
-
+ $_SESSION['blocks'] = $elements['blocks'];
+ $_SESSION['layouts'] = $elements['layouts'];
+ $_SESSION['pages'] = $elements['pages'];
if(!(empty($elements['pages']) && empty($elements['blocks']) && empty($elements['layouts']))) {
info( t('Webpages elements detected.') . EOL);
-
- $o .= replace_macros(get_markup_template('webpage_import.tpl'), array(
- '$title' => t('Import Webpage Elements'),
- ));
-
- return $o;
-
+ $_SESSION['action'] = 'import';
} else {
notice( t('No webpage elements detected.') . EOL);
- }
- // Import layout first so that pages that reference new layouts will find
- // the mid of layout items in the database
- foreach($elements['layouts'] as &$layout) {
- $layout = import_webpage_element($layout, $channel, 'layout');
- }
- foreach($elements['pages'] as &$page) {
- $page = import_webpage_element($page, $channel, 'page');
- }
- foreach($elements['blocks'] as &$block) {
- $block = import_webpage_element($block, $channel, 'block');
+ $_SESSION['action'] = null;
}
}
@@ -303,8 +311,69 @@ class Webpages extends \Zotlabs\Web\Controller {
}
break;
- case 'import':
- break;
+
+ case 'importselected':
+ require_once('include/import.php');
+ $channel = \App::get_channel();
+
+ // Import layout first so that pages that reference new layouts will find
+ // the mid of layout items in the database
+
+ // Obtain the user-selected layouts to import and import them
+ $checkedlayouts = $_POST['layout'];
+ $layouts = [];
+ if (!empty($checkedlayouts)) {
+ foreach ($checkedlayouts as $name) {
+ foreach ($_SESSION['layouts'] as &$layout) {
+ if ($layout['name'] === $name) {
+ $layout['import'] = 1;
+ $layoutstoimport[] = $layout;
+ }
+ }
+ }
+ foreach ($layoutstoimport as $elementtoimport) {
+ $layouts[] = import_webpage_element($elementtoimport, $channel, 'layout');
+ }
+ }
+ $_SESSION['import_layouts'] = $layouts;
+
+ // Obtain the user-selected blocks to import and import them
+ $checkedblocks = $_POST['block'];
+ $blocks = [];
+ if (!empty($checkedblocks)) {
+ foreach ($checkedblocks as $name) {
+ foreach ($_SESSION['blocks'] as &$block) {
+ if ($block['name'] === $name) {
+ $block['import'] = 1;
+ $blockstoimport[] = $block;
+ }
+ }
+ }
+ foreach ($blockstoimport as $elementtoimport) {
+ $blocks[] = import_webpage_element($elementtoimport, $channel, 'block');
+ }
+ }
+ $_SESSION['import_blocks'] = $blocks;
+
+ // Obtain the user-selected pages to import and import them
+ $checkedpages = $_POST['page'];
+ $pages = [];
+ if (!empty($checkedpages)) {
+ foreach ($checkedpages as $pagelink) {
+ foreach ($_SESSION['pages'] as &$page) {
+ if ($page['pagelink'] === $pagelink) {
+ $page['import'] = 1;
+ $pagestoimport[] = $page;
+ }
+ }
+ }
+ foreach ($pagestoimport as $elementtoimport) {
+ $pages[] = import_webpage_element($elementtoimport, $channel, 'page');
+ }
+ }
+ $_SESSION['import_pages'] = $pages;
+ break;
+
default :
break;
}