diff options
author | Mario <mario@mariovavti.com> | 2021-10-21 10:36:31 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2021-10-21 10:36:31 +0000 |
commit | 9b9ca9695ce12fae8a542acadd6ff69abb6eac02 (patch) | |
tree | ed85c77d3b0622ae38c0ad8f7ec6fa32a185a8e1 | |
parent | 6357c69868218475145d9abb01d2851bf9e816e9 (diff) | |
download | volse-hubzilla-9b9ca9695ce12fae8a542acadd6ff69abb6eac02.tar.gz volse-hubzilla-9b9ca9695ce12fae8a542acadd6ff69abb6eac02.tar.bz2 volse-hubzilla-9b9ca9695ce12fae8a542acadd6ff69abb6eac02.zip |
import_items: cleanup
-rw-r--r-- | Zotlabs/Module/Import_items.php | 151 |
1 files changed, 76 insertions, 75 deletions
diff --git a/Zotlabs/Module/Import_items.php b/Zotlabs/Module/Import_items.php index f14058e6a..4232de621 100644 --- a/Zotlabs/Module/Import_items.php +++ b/Zotlabs/Module/Import_items.php @@ -1,8 +1,10 @@ <?php + namespace Zotlabs\Module; use App; use ZipArchive; +use Zotlabs\Web\Controller; require_once('include/import.php'); @@ -11,16 +13,16 @@ require_once('include/import.php'); * * Import existing posts and content from an export file. */ -class Import_items extends \Zotlabs\Web\Controller { +class Import_items extends Controller { function post() { - if(! local_channel()) + if (!local_channel()) return; check_form_security_token_redirectOnErr('/import_items', 'import_items'); - $data = null; + $data = null; $src = $_FILES['filename']['tmp_name']; $filename = basename($_FILES['filename']['name']); @@ -29,9 +31,9 @@ class Import_items extends \Zotlabs\Web\Controller { $channel = App::get_channel(); - if($src) { + if ($src) { - if($filetype === 'application/zip'){ + if ($filetype === 'application/zip') { $zip = new ZipArchive; $r = $zip->open($src); @@ -45,7 +47,7 @@ class Import_items extends \Zotlabs\Web\Controller { return; } - notice( t('Not a zip file or zip file corrupted.') . EOL); + notice(t('Not a zip file or zip file corrupted.') . EOL); unlink($src); return; } @@ -54,51 +56,51 @@ class Import_items extends \Zotlabs\Web\Controller { // mostly used for Diaspora which exports gzipped files. //if(strpos($filename,'.gz')){ - //@rename($src,$src . '.gz'); - //@system('gunzip ' . escapeshellarg($src . '.gz')); + //@rename($src,$src . '.gz'); + //@system('gunzip ' . escapeshellarg($src . '.gz')); //} - if($filesize) { + if ($filesize) { $data = @file_get_contents($src); self::import($channel, $data); } unlink($src); return; } -/* - if(! $src) { + /* + if(! $src) { - $old_address = ((x($_REQUEST,'old_address')) ? $_REQUEST['old_address'] : ''); + $old_address = ((x($_REQUEST,'old_address')) ? $_REQUEST['old_address'] : ''); - if(! $old_address) { - logger('Nothing to import.'); - notice( t('Nothing to import.') . EOL); - return; - } + if(! $old_address) { + logger('Nothing to import.'); + notice( t('Nothing to import.') . EOL); + return; + } - $email = ((x($_REQUEST,'email')) ? $_REQUEST['email'] : ''); - $password = ((x($_REQUEST,'password')) ? $_REQUEST['password'] : ''); - - $year = ((x($_REQUEST,'year')) ? $_REQUEST['year'] : ''); - - $channelname = substr($old_address,0,strpos($old_address,'@')); - $servername = substr($old_address,strpos($old_address,'@')+1); - - $scheme = 'https://'; - $api_path = '/api/red/channel/export/items?f=&channel=' . $channelname . '&year=' . intval($year); - $binary = false; - $redirects = 0; - $opts = array('http_auth' => $email . ':' . $password); - $url = $scheme . $servername . $api_path; - $ret = z_fetch_url($url, $binary, $redirects, $opts); - if(! $ret['success']) - $ret = z_fetch_url('http://' . $servername . $api_path, $binary, $redirects, $opts); - if($ret['success']) - $data = $ret['body']; - else - notice( t('Unable to download data from old server') . EOL); - } -*/ + $email = ((x($_REQUEST,'email')) ? $_REQUEST['email'] : ''); + $password = ((x($_REQUEST,'password')) ? $_REQUEST['password'] : ''); + + $year = ((x($_REQUEST,'year')) ? $_REQUEST['year'] : ''); + + $channelname = substr($old_address,0,strpos($old_address,'@')); + $servername = substr($old_address,strpos($old_address,'@')+1); + + $scheme = 'https://'; + $api_path = '/api/red/channel/export/items?f=&channel=' . $channelname . '&year=' . intval($year); + $binary = false; + $redirects = 0; + $opts = array('http_auth' => $email . ':' . $password); + $url = $scheme . $servername . $api_path; + $ret = z_fetch_url($url, $binary, $redirects, $opts); + if(! $ret['success']) + $ret = z_fetch_url('http://' . $servername . $api_path, $binary, $redirects, $opts); + if($ret['success']) + $data = $ret['body']; + else + notice( t('Unable to download data from old server') . EOL); + } + */ } @@ -110,18 +112,18 @@ class Import_items extends \Zotlabs\Web\Controller { */ function get() { - if(! local_channel()) { - notice( t('Permission denied') . EOL); + if (!local_channel()) { + notice(t('Permission denied') . EOL); return login(); } - $o = replace_macros(get_markup_template('item_import.tpl'), array( - '$title' => t('Import Items'), - '$desc' => t('Use this form to import existing posts and content from an export file.'), - '$label_filename' => t('File to Upload'), + $o = replace_macros(get_markup_template('item_import.tpl'), [ + '$title' => t('Import Items'), + '$desc' => t('Use this form to import existing posts and content from an export file.'), + '$label_filename' => t('File to Upload'), '$form_security_token' => get_form_security_token('import_items'), - '$submit' => t('Submit') - )); + '$submit' => t('Submit') + ]); return $o; } @@ -129,9 +131,9 @@ class Import_items extends \Zotlabs\Web\Controller { public static function import($channel, $data) { - if(! $data) { + if (!$data) { logger('Empty file.'); - notice( t('Imported file is empty.') . EOL); + notice(t('Imported file is empty.') . EOL); return; } @@ -139,58 +141,57 @@ class Import_items extends \Zotlabs\Web\Controller { //logger('import: data: ' . print_r($data,true)); //print_r($data); - if(! is_array($data)) + if (!is_array($data)) return; - if(array_key_exists('compatibility',$data) && array_key_exists('database',$data['compatibility'])) { - $v1 = substr($data['compatibility']['database'],-4); - $v2 = substr(DB_UPDATE_VERSION,-4); - if($v2 > $v1) { - $t = sprintf( t('Warning: Database versions differ by %1$d updates.'), $v2 - $v1 ); + if (array_key_exists('compatibility', $data) && array_key_exists('database', $data['compatibility'])) { + $v1 = substr($data['compatibility']['database'], -4); + $v2 = substr(DB_UPDATE_VERSION, -4); + if ($v2 > $v1) { + $t = sprintf(t('Warning: Database versions differ by %1$d updates.'), $v2 - $v1); notice($t . EOL); } } - if(array_key_exists('item',$data) && is_array($data['item'])) { - import_items($channel, $data['item'], false, ((array_key_exists('relocate',$data)) ? $data['relocate'] : null)); - info( t('Content import completed') . EOL); + if (array_key_exists('item', $data) && is_array($data['item'])) { + import_items($channel, $data['item'], false, ((array_key_exists('relocate', $data)) ? $data['relocate'] : null)); + info(t('Content import completed') . EOL); } - if (array_key_exists('chatroom',$data) && is_array($data['chatroom'])) { + if (array_key_exists('chatroom', $data) && is_array($data['chatroom'])) { import_chatrooms($channel, $data['chatroom']); - info( t('Chatroom import completed') . EOL); + info(t('Chatroom import completed') . EOL); } - if (array_key_exists('event',$data) && is_array($data['event'])) { + if (array_key_exists('event', $data) && is_array($data['event'])) { import_events($channel, $data['event']); - info( t('Channel calendar import 1/2 completed') . EOL); + info(t('Channel calendar import 1/2 completed') . EOL); } - if (array_key_exists('event_item',$data) && is_array($data['event_item'])) { - import_items($channel, $data['event_item'], false, ((array_key_exists('relocate',$data)) ? $data['relocate'] : null)); - info( t('Channel calendar import 2/2 completed') . EOL); + if (array_key_exists('event_item', $data) && is_array($data['event_item'])) { + import_items($channel, $data['event_item'], false, ((array_key_exists('relocate', $data)) ? $data['relocate'] : null)); + info(t('Channel calendar import 2/2 completed') . EOL); } - if (array_key_exists('menu',$data) && is_array($data['menu'])) { + if (array_key_exists('menu', $data) && is_array($data['menu'])) { import_menus($channel, $data['menu']); - info( t('Menu import completed') . EOL); + info(t('Menu import completed') . EOL); } - if (array_key_exists('wiki',$data) && is_array($data['wiki'])) { - import_items($channel, $data['wiki'], false, ((array_key_exists('relocate',$data)) ? $data['relocate'] : null)); - info( t('Wiki import completed') . EOL); + if (array_key_exists('wiki', $data) && is_array($data['wiki'])) { + import_items($channel, $data['wiki'], false, ((array_key_exists('relocate', $data)) ? $data['relocate'] : null)); + info(t('Wiki import completed') . EOL); } - if (array_key_exists('webpages',$data) && is_array($data['webpages'])) { - import_items($channel, $data['webpages'], false, ((array_key_exists('relocate',$data)) ? $data['relocate'] : null)); - info( t('Webpages import completed') . EOL); + if (array_key_exists('webpages', $data) && is_array($data['webpages'])) { + import_items($channel, $data['webpages'], false, ((array_key_exists('relocate', $data)) ? $data['relocate'] : null)); + info(t('Webpages import completed') . EOL); } - return; } } |