aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2016-08-31 09:41:07 +0200
committerMario Vavti <mario@mariovavti.com>2016-08-31 09:41:07 +0200
commite9462ba14529b7172ba5a21e7985d24de91faa37 (patch)
treec2270ca2975f6683a361c5959894b6bbc954475d /include
parent2b9322fc7d879fecbe334083bbd028538c985c54 (diff)
parentb775a1aa0e36a74f0f937d85f458fd12af18a264 (diff)
downloadvolse-hubzilla-e9462ba14529b7172ba5a21e7985d24de91faa37.tar.gz
volse-hubzilla-e9462ba14529b7172ba5a21e7985d24de91faa37.tar.bz2
volse-hubzilla-e9462ba14529b7172ba5a21e7985d24de91faa37.zip
resolve merge conflict
Diffstat (limited to 'include')
-rw-r--r--include/attach.php46
-rw-r--r--include/import.php215
-rwxr-xr-xinclude/oembed.php15
-rw-r--r--include/text.php16
-rw-r--r--include/widgets.php4
5 files changed, 279 insertions, 17 deletions
diff --git a/include/attach.php b/include/attach.php
index ae7d71dc7..137d2b11c 100644
--- a/include/attach.php
+++ b/include/attach.php
@@ -1995,6 +1995,52 @@ function get_filename_by_cloudname($cloudname, $channel, $storepath) {
return null;
}
+
+// recursively copy a directory into cloud files
+function copy_folder_to_cloudfiles($channel, $observer_hash, $srcpath, $cloudpath)
+{
+ if (!is_dir($srcpath) || !is_readable($srcpath)) {
+ logger('Error reading source path: ' . $srcpath, LOGGER_NORMAL);
+ return false;
+ }
+ $nodes = array_diff(scandir($srcpath), array('.', '..'));
+ foreach ($nodes as $node) {
+ $clouddir = $cloudpath . '/' . $node; // Sub-folder in cloud files destination
+ $nodepath = $srcpath . '/' . $node; // Sub-folder in source path
+ if(is_dir($nodepath)) {
+ $x = attach_mkdirp($channel, $observer_hash, array('pathname' => $clouddir));
+ if(!$x['success']) {
+ logger('Error creating cloud path: ' . $clouddir, LOGGER_NORMAL);
+ return false;
+ }
+ // Recursively call this function where the source and destination are the subfolders
+ $success = copy_folder_to_cloudfiles($channel, $observer_hash, $nodepath, $clouddir);
+ if(!$success) {
+ logger('Error copying contents of folder: ' . $nodepath, LOGGER_NORMAL);
+ return false;
+ }
+ } elseif (is_file($nodepath) && is_readable($nodepath)) {
+ $x = attach_store($channel, $observer_hash, 'import',
+ array(
+ 'directory' => $cloudpath,
+ 'src' => $nodepath,
+ 'filename' => $node,
+ 'filesize' => @filesize($nodepath),
+ 'preserve_original' => true)
+ );
+ if(!$x['success']) {
+ logger('Error copying file: ' . $nodepath , LOGGER_NORMAL);
+ logger('Return value: ' . json_encode($x), LOGGER_NORMAL);
+ return false;
+ }
+ } else {
+ logger('Error scanning source path', LOGGER_NORMAL);
+ return false;
+ }
+ }
+
+ return true;
+}
/**
* attach_move()
* This function performs an in place directory-to-directory move of a stored attachment or photo.
diff --git a/include/import.php b/include/import.php
index 84881a420..ddffb2ac3 100644
--- a/include/import.php
+++ b/include/import.php
@@ -1312,8 +1312,12 @@ function scan_webpage_elements($path, $type, $cloud = false) {
}
$content = file_get_contents($folder . '/' . $contentfilename);
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;
}
@@ -1395,12 +1399,12 @@ function scan_webpage_elements($path, $type, $cloud = false) {
);
$arr['mid'] = $arr['parent_mid'] = $iteminfo[0]['mid'];
$arr['created'] = $iteminfo[0]['created'];
- $arr['edited'] = (($element['edited']) ? datetime_convert('UTC', 'UTC', $element['edited']) : datetime_convert());
} else { // otherwise, generate the creation times and unique id
- $arr['created'] = (($element['created']) ? datetime_convert('UTC', 'UTC', $element['created']) : datetime_convert());
- $arr['edited'] = datetime_convert('UTC', 'UTC', '0000-00-00 00:00:00');
+ $arr['created'] = datetime_convert('UTC', 'UTC');
$arr['mid'] = $arr['parent_mid'] = item_message_id();
}
+ // Update the edited time whether or not the element already exists
+ $arr['edited'] = datetime_convert('UTC', 'UTC');
// Import the actual element content
$arr['body'] = file_get_contents($element['path']);
// The element owner is the channel importing the elements
@@ -1415,7 +1419,7 @@ function scan_webpage_elements($path, $type, $cloud = false) {
'application/x-pdl',
'application/x-php'
];
- // Blocks and pages can have any mimetype, but layouts must be text/bbcode
+ // Blocks and pages can have any of the valid mimetypes, but layouts must be text/bbcode
if((in_array($element['mimetype'], $mimetypes)) && ($type === 'page' || $type === 'block') ) {
$arr['mimetype'] = $element['mimetype'];
} else {
@@ -1424,7 +1428,7 @@ function scan_webpage_elements($path, $type, $cloud = false) {
// Verify ability to use html or php!!!
$execflag = false;
- if ($arr['mimetype'] === 'application/x-php') {
+ if ($arr['mimetype'] === 'application/x-php' || $arr['mimetype'] === 'text/html') {
$z = q("select account_id, account_roles, channel_pageflags from account "
. "left join channel on channel_account_id = account_id where channel_id = %d limit 1",
intval(local_channel())
@@ -1432,10 +1436,15 @@ function scan_webpage_elements($path, $type, $cloud = false) {
if ($z && (($z[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($z[0]['channel_pageflags'] & PAGE_ALLOWCODE))) {
$execflag = true;
+ } else {
+ logger('Unable to import element "' . $name .'" because AllowCode permission is denied.');
+ notice( t('Unable to import element "' . $name .'" because AllowCode permission is denied.') . EOL);
+ $element['import_success'] = 0;
+ return $element;
}
}
- $z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'service' limit 1",
+ $z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'system' limit 1",
dbesc($name),
dbesc($namespace)
);
@@ -1472,3 +1481,193 @@ function scan_webpage_elements($path, $type, $cloud = false) {
return $element;
}
+
+function get_webpage_elements($channel, $type = 'all') {
+ $elements = array();
+ if(!$channel['channel_id']) {
+ return null;
+ }
+ switch ($type) {
+ case 'all':
+ // If all, execute all the pages, layouts, blocks case statements
+ case 'pages':
+ $elements['pages'] = null;
+ $owner = $channel['channel_id'];
+
+ $sql_extra = item_permissions_sql($owner);
+
+
+ $r = q("select * from iconfig left join item on iconfig.iid = item.id
+ where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item_type = %d
+ $sql_extra order by item.created desc",
+ intval($owner),
+ intval(ITEM_TYPE_WEBPAGE)
+ );
+
+ $pages = null;
+
+ if($r) {
+ $elements['pages'] = array();
+ $pages = array();
+ foreach($r as $rr) {
+ unobscure($rr);
+
+ //$lockstate = (($rr['allow_cid'] || $rr['allow_gid'] || $rr['deny_cid'] || $rr['deny_gid']) ? 'lock' : 'unlock');
+
+ $element_arr = array(
+ 'type' => 'webpage',
+ 'title' => $rr['title'],
+ 'body' => $rr['body'],
+ 'created' => $rr['created'],
+ 'edited' => $rr['edited'],
+ 'mimetype' => $rr['mimetype'],
+ 'pagetitle' => $rr['v'],
+ 'mid' => $rr['mid'],
+ 'layout_mid' => $rr['layout_mid']
+ );
+ $pages[$rr['iid']][] = array(
+ 'url' => $rr['iid'],
+ 'pagetitle' => $rr['v'],
+ 'title' => $rr['title'],
+ 'created' => datetime_convert('UTC',date_default_timezone_get(),$rr['created']),
+ 'edited' => datetime_convert('UTC',date_default_timezone_get(),$rr['edited']),
+ 'bb_element' => '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]',
+ //'lockstate' => $lockstate
+ );
+ $elements['pages'][] = $element_arr;
+ }
+
+ }
+ if($type !== 'all') {
+ break;
+ }
+
+ case 'layouts':
+ $elements['layouts'] = null;
+ $owner = $channel['channel_id'];
+
+ $sql_extra = item_permissions_sql($owner);
+
+
+ $r = q("select * from iconfig left join item on iconfig.iid = item.id
+ where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' and item_type = %d
+ $sql_extra order by item.created desc",
+ intval($owner),
+ intval(ITEM_TYPE_PDL)
+ );
+
+ $layouts = null;
+
+ if($r) {
+ $elements['layouts'] = array();
+ $layouts = array();
+ foreach($r as $rr) {
+ unobscure($rr);
+
+ $elements['layouts'][] = array(
+ 'type' => 'layout',
+ 'description' => $rr['title'], // description of the layout
+ 'body' => $rr['body'],
+ 'created' => $rr['created'],
+ 'edited' => $rr['edited'],
+ 'mimetype' => $rr['mimetype'],
+ 'name' => $rr['v'], // name of reference for the layout
+ 'mid' => $rr['mid'],
+ );
+ }
+
+ }
+
+ if($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;
+ }
+ return $elements;
+}
+
+/* creates a compressed zip file */
+
+function create_zip_file($files = array(), $destination = '', $overwrite = false) {
+ //if the zip file already exists and overwrite is false, return false
+ if (file_exists($destination) && !$overwrite) {
+ return false;
+ }
+ //vars
+ $valid_files = array();
+ //if files were passed in...
+ if (is_array($files)) {
+ //cycle through each file
+ foreach ($files as $file) {
+ //make sure the file exists
+ if (file_exists($file)) {
+ $valid_files[] = $file;
+ }
+ }
+ }
+
+ //if we have good files...
+ if (count($valid_files)) {
+ //create the archive
+ $zip = new ZipArchive();
+ if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
+ return false;
+ }
+ //add the files
+ foreach ($valid_files as $file) {
+ $zip->addFile($file, $file);
+ }
+ //debug
+ //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
+ //close the zip -- done!
+ $zip->close();
+
+ //check to make sure the file exists
+ return file_exists($destination);
+ } else {
+ return false;
+ }
+}
diff --git a/include/oembed.php b/include/oembed.php
index fe6f10d71..085637a00 100755
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -156,9 +156,12 @@ function oembed_fetch_url($embedurl){
if ($action !== 'block') {
// try oembed autodiscovery
$redirects = 0;
- $result = z_fetch_url($furl, false, $redirects, array('timeout' => 15, 'accept_content' => "text/*", 'novalidate' => true ));
+ $result = z_fetch_url($furl, false, $redirects, array('timeout' => 30, 'accept_content' => "text/*", 'novalidate' => true ));
+
if($result['success'])
$html_text = $result['body'];
+ else
+ logger('fetch failure: ' . $furl);
if($html_text) {
$dom = @DOMDocument::loadHTML($html_text);
@@ -171,7 +174,10 @@ function oembed_fetch_url($embedurl){
foreach($entries as $e){
$href = $e->getAttributeNode("href")->nodeValue;
$x = z_fetch_url($href . '&maxwidth=' . App::$videowidth);
- $txt = $x['body'];
+ if($x['success'])
+ $txt = $x['body'];
+ else
+ logger('fetch failed: ' . $href);
break;
}
// soundcloud is now using text/json+oembed instead of application/json+oembed,
@@ -180,7 +186,10 @@ function oembed_fetch_url($embedurl){
foreach($entries as $e){
$href = $e->getAttributeNode("href")->nodeValue;
$x = z_fetch_url($href . '&maxwidth=' . App::$videowidth);
- $txt = $x['body'];
+ if($x['success'])
+ $txt = $x['body'];
+ else
+ logger('json fetch failed: ' . $href);
break;
}
}
diff --git a/include/text.php b/include/text.php
index a2a6d918b..99ac59ca7 100644
--- a/include/text.php
+++ b/include/text.php
@@ -2267,11 +2267,11 @@ function design_tools() {
}
/**
- * @brief Creates website import tools menu
+ * @brief Creates website portation tools menu
*
* @return string
*/
-function website_import_tools() {
+function website_portation_tools() {
$channel = App::get_channel();
$sys = false;
@@ -2282,7 +2282,7 @@ function website_import_tools() {
$sys = true;
}
- return replace_macros(get_markup_template('website_import_tools.tpl'), array(
+ return replace_macros(get_markup_template('website_portation_tools.tpl'), array(
'$title' => t('Import'),
'$import_label' => t('Import website...'),
'$import_placeholder' => t('Select folder to import'),
@@ -2290,7 +2290,15 @@ function website_import_tools() {
'$file_import_text' => t('Import from cloud files:'),
'$desc' => t('/cloud/channel/path/to/folder'),
'$hint' => t('Enter path to website files'),
- '$select' => t('Select folder'),
+ '$select' => t('Select folder'),
+ '$export_label' => t('Export website...'),
+ '$file_download_text' => t('Export to a zip file'),
+ '$filename_desc' => t('website.zip'),
+ '$filename_hint' => t('Enter a name for the zip file.'),
+ '$cloud_export_text' => t('Export to cloud files'),
+ '$cloud_export_desc' => t('/path/to/export/folder'),
+ '$cloud_export_hint' => t('Enter a path to a cloud files destination.'),
+ '$cloud_export_select' => t('Specify folder'),
));
}
diff --git a/include/widgets.php b/include/widgets.php
index 765cb4d42..9429df249 100644
--- a/include/widgets.php
+++ b/include/widgets.php
@@ -779,7 +779,7 @@ function widget_design_tools($arr) {
return design_tools();
}
-function widget_website_import_tools($arr) {
+function widget_website_portation_tools($arr) {
// mod menu doesn't load a profile. For any modules which load a profile, check it.
// otherwise local_channel() is sufficient for permissions.
@@ -791,7 +791,7 @@ function widget_website_import_tools($arr) {
if(! local_channel())
return '';
- return website_import_tools();
+ return website_portation_tools();
}
function widget_findpeople($arr) {