aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Webpages.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Module/Webpages.php')
-rw-r--r--Zotlabs/Module/Webpages.php185
1 files changed, 184 insertions, 1 deletions
diff --git a/Zotlabs/Module/Webpages.php b/Zotlabs/Module/Webpages.php
index cc0a01cce..d3199f223 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'),
+ '$importbtn' => t('Import selected'),
+ '$action' => 'import',
+ '$pages' => $_SESSION['pages'],
+ '$layouts' => $_SESSION['layouts'],
+ '$blocks' => $_SESSION['blocks'],
+ ));
+ 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'])) {
@@ -209,4 +231,165 @@ class Webpages extends \Zotlabs\Web\Controller {
return $o;
}
+ function post() {
+
+ $action = $_REQUEST['action'];
+ if( $action ){
+ switch ($action) {
+ case 'scan':
+
+ // the state of this variable tracks whether website files have been scanned (null, true, false)
+ $cloud = null;
+
+ // Website files are to be imported from an uploaded zip file
+ if(($_FILES) && array_key_exists('zip_file',$_FILES) && isset($_POST['w_upload'])) {
+ $source = $_FILES["zip_file"]["tmp_name"];
+ $type = $_FILES["zip_file"]["type"];
+ $okay = false;
+ $accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
+ foreach ($accepted_types as $mime_type) {
+ if ($mime_type == $type) {
+ $okay = true;
+ break;
+ }
+ }
+ if(!$okay) {
+ notice( t('Invalid file type.') . EOL);
+ return;
+ }
+ $zip = new \ZipArchive();
+ if ($zip->open($source) === true) {
+ $tmp_folder_name = random_string(5);
+ $website = dirname($source) . '/' . $tmp_folder_name;
+ $zip->extractTo($website); // change this to the correct site path
+ $zip->close();
+ @unlink($source); // delete the compressed file now that the content has been extracted
+ $cloud = false;
+ } else {
+ notice( t('Error opening zip file') . EOL);
+ return null;
+ }
+ }
+
+ // Website files are to be imported from the channel cloud files
+ if (($_POST) && array_key_exists('path',$_POST) && isset($_POST['cloudsubmit'])) {
+
+ $channel = \App::get_channel();
+ $dirpath = get_dirpath_by_cloudpath($channel, $_POST['path']);
+ if(!$dirpath) {
+ notice( t('Invalid folder path.') . EOL);
+ return null;
+ }
+ $cloud = true;
+
+ }
+
+ // If the website files were uploaded or specified in the cloud files, then $cloud
+ // should be either true or false
+ if ($cloud !== null) {
+ require_once('include/import.php');
+ $elements = [];
+ if($cloud) {
+ $path = $_POST['path'];
+ } else {
+ $path = $website;
+ }
+ $elements['pages'] = scan_webpage_elements($path, 'page', $cloud);
+ $elements['layouts'] = scan_webpage_elements($path, 'layout', $cloud);
+ $elements['blocks'] = scan_webpage_elements($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);
+ $_SESSION['action'] = 'import';
+ } else {
+ notice( t('No webpage elements detected.') . EOL);
+ $_SESSION['action'] = null;
+ }
+
+ }
+
+ // 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
+ }
+
+ 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;
+ if(!(empty($_SESSION['import_pages']) && empty($_SESSION['import_blocks']) && empty($_SESSION['import_layouts']))) {
+ info( t('Import complete.') . EOL);
+ }
+ break;
+
+ default :
+ break;
+ }
+ }
+
+
+
+
+ }
+
}