Reformatted Webpages.php to clean up whitespace, where there was a mixture of spaces and tabs for indentation. No other changes made.

This commit is contained in:
Andrew Manning 2017-04-29 12:56:25 -04:00
parent 635b8ff73a
commit e99be61d49

View File

@ -1,36 +1,34 @@
<?php
namespace Zotlabs\Module;
require_once('include/channel.php');
require_once('include/conversation.php');
require_once('include/acl_selectors.php');
class Webpages extends \Zotlabs\Web\Controller {
function init() {
if(argc() > 1 && argv(1) === 'sys' && is_site_admin()) {
if (argc() > 1 && argv(1) === 'sys' && is_site_admin()) {
$sys = get_sys_channel();
if($sys && intval($sys['channel_id'])) {
if ($sys && intval($sys['channel_id'])) {
\App::$is_sys = true;
}
}
if(argc() > 1)
if (argc() > 1)
$which = argv(1);
else
return;
profile_load($which);
}
function get() {
if(! \App::$profile) {
notice( t('Requested profile is not available.') . EOL );
if (!\App::$profile) {
notice(t('Requested profile is not available.') . EOL);
\App::$error = 404;
return;
}
@ -63,7 +61,7 @@ class Webpages extends \Zotlabs\Web\Controller {
break;
case 'export_select_list':
$_SESSION['action'] = null;
if(!$uid) {
if (!$uid) {
$_SESSION['export'] = null;
break;
}
@ -89,55 +87,53 @@ class Webpages extends \Zotlabs\Web\Controller {
}
if(\App::$is_sys && is_site_admin()) {
if (\App::$is_sys && is_site_admin()) {
$sys = get_sys_channel();
if($sys && intval($sys['channel_id'])) {
if ($sys && intval($sys['channel_id'])) {
$uid = $owner = intval($sys['channel_id']);
$channel = $sys;
$observer = $sys;
}
}
if(! $owner) {
if (!$owner) {
// Figure out who the page owner is.
$r = q("select channel_id from channel where channel_address = '%s'",
dbesc($which)
$r = q("select channel_id from channel where channel_address = '%s'", dbesc($which)
);
if($r) {
if ($r) {
$owner = intval($r[0]['channel_id']);
}
}
$ob_hash = (($observer) ? $observer['xchan_hash'] : '');
$perms = get_all_perms($owner,$ob_hash);
$perms = get_all_perms($owner, $ob_hash);
if(! $perms['write_pages']) {
notice( t('Permission denied.') . EOL);
if (!$perms['write_pages']) {
notice(t('Permission denied.') . EOL);
return;
}
$mimetype = (($_REQUEST['mimetype']) ? $_REQUEST['mimetype'] : get_pconfig($owner,'system','page_mimetype'));
$mimetype = (($_REQUEST['mimetype']) ? $_REQUEST['mimetype'] : get_pconfig($owner, 'system', 'page_mimetype'));
$layout = (($_REQUEST['layout']) ? $_REQUEST['layout'] : get_pconfig($owner,'system','page_layout'));
$layout = (($_REQUEST['layout']) ? $_REQUEST['layout'] : get_pconfig($owner, 'system', 'page_layout'));
// Create a status editor (for now - we'll need a WYSIWYG eventually) to create pages
// Nickname is set to the observers xchan, and profile_uid to the owner's.
// This lets you post pages at other people's channels.
if((! $channel) && ($uid) && ($uid == \App::$profile_uid)) {
if ((!$channel) && ($uid) && ($uid == \App::$profile_uid)) {
$channel = \App::get_channel();
}
if($channel) {
if ($channel) {
$channel_acl = array(
'allow_cid' => $channel['channel_allow_cid'],
'allow_gid' => $channel['channel_allow_gid'],
'deny_cid' => $channel['channel_deny_cid'],
'deny_gid' => $channel['channel_deny_gid']
);
}
else {
$channel_acl = [ 'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '' ];
} else {
$channel_acl = ['allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => ''];
}
@ -150,7 +146,7 @@ class Webpages extends \Zotlabs\Web\Controller {
'is_owner' => true,
'nickname' => \App::$profile['channel_address'],
'lockstate' => (($channel['channel_allow_cid'] || $channel['channel_allow_gid'] || $channel['channel_deny_cid'] || $channel['channel_deny_gid']) ? 'lock' : 'unlock'),
'acl' => (($is_owner) ? populate_acl($channel_acl,false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_pages')) : ''),
'acl' => (($is_owner) ? populate_acl($channel_acl, false, \Zotlabs\Lib\PermissionDescription::fromGlobalPermission('view_pages')) : ''),
'permissions' => $channel_acl,
'showacl' => (($is_owner) ? true : false),
'visitor' => true,
@ -162,16 +158,16 @@ class Webpages extends \Zotlabs\Web\Controller {
'layout' => $layout,
'layoutselect' => true,
'expanded' => true,
'novoting'=> true,
'novoting' => true,
'bbco_autocomplete' => 'bbcode',
'bbcode' => true
);
if($_REQUEST['title'])
if ($_REQUEST['title'])
$x['title'] = $_REQUEST['title'];
if($_REQUEST['body'])
if ($_REQUEST['body'])
$x['body'] = $_REQUEST['body'];
if($_REQUEST['pagetitle'])
if ($_REQUEST['pagetitle'])
$x['pagetitle'] = $_REQUEST['pagetitle'];
@ -180,15 +176,12 @@ class Webpages extends \Zotlabs\Web\Controller {
/** @TODO - this should be replaced with pagelist_widget */
$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)
$sql_extra order by item.created desc", intval($owner), intval(ITEM_TYPE_WEBPAGE)
);
// $r = q("select * from item_id left join item on item_id.iid = item.id
@ -197,16 +190,16 @@ class Webpages extends \Zotlabs\Web\Controller {
// intval(ITEM_TYPE_WEBPAGE)
// );
if(! $r)
if (!$r)
$x['pagetitle'] = 'home';
$editor = status_editor($a,$x);
$editor = status_editor($a, $x);
$pages = null;
if($r) {
if ($r) {
$pages = array();
foreach($r as $rr) {
foreach ($r as $rr) {
unobscure($rr);
$lockstate = (($rr['allow_cid'] || $rr['allow_gid'] || $rr['deny_cid'] || $rr['deny_gid']) ? 'lock' : 'unlock');
@ -226,8 +219,8 @@ class Webpages extends \Zotlabs\Web\Controller {
'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']),
'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
);
@ -262,7 +255,7 @@ class Webpages extends \Zotlabs\Web\Controller {
function post() {
$action = $_REQUEST['action'];
if( $action ){
if ($action) {
switch ($action) {
case 'scan':
@ -270,7 +263,7 @@ class Webpages extends \Zotlabs\Web\Controller {
$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'])) {
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;
@ -281,8 +274,8 @@ class Webpages extends \Zotlabs\Web\Controller {
break;
}
}
if(!$okay) {
notice( t('Invalid file type.') . EOL);
if (!$okay) {
notice(t('Invalid file type.') . EOL);
return;
}
$zip = new \ZipArchive();
@ -294,22 +287,21 @@ class Webpages extends \Zotlabs\Web\Controller {
@unlink($source); // delete the compressed file now that the content has been extracted
$cloud = false;
} else {
notice( t('Error opening zip file') . EOL);
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'])) {
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);
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
@ -317,7 +309,7 @@ class Webpages extends \Zotlabs\Web\Controller {
if ($cloud !== null) {
require_once('include/import.php');
$elements = [];
if($cloud) {
if ($cloud) {
$path = $_POST['path'];
} else {
$path = $website;
@ -328,14 +320,13 @@ class Webpages extends \Zotlabs\Web\Controller {
$_SESSION['blocks'] = $elements['blocks'];
$_SESSION['layouts'] = $elements['layouts'];
$_SESSION['pages'] = $elements['pages'];
if(!(empty($elements['pages']) && empty($elements['blocks']) && empty($elements['layouts']))) {
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);
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
@ -352,7 +343,6 @@ class Webpages extends \Zotlabs\Web\Controller {
// 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 = [];
@ -406,10 +396,10 @@ class Webpages extends \Zotlabs\Web\Controller {
}
}
$_SESSION['import_pages'] = $pages;
if(!(empty($_SESSION['import_pages']) && empty($_SESSION['import_blocks']) && empty($_SESSION['import_layouts']))) {
info( t('Import complete.') . EOL);
if (!(empty($_SESSION['import_pages']) && empty($_SESSION['import_blocks']) && empty($_SESSION['import_layouts']))) {
info(t('Import complete.') . EOL);
}
if(isset($_SESSION['tempimportpath'])) {
if (isset($_SESSION['tempimportpath'])) {
rrmdir($_SESSION['tempimportpath']); // Delete the temporary decompressed files
unset($_SESSION['tempimportpath']);
}
@ -417,22 +407,21 @@ class Webpages extends \Zotlabs\Web\Controller {
case 'exportzipfile':
if(isset($_POST['w_download'])) {
if (isset($_POST['w_download'])) {
$_SESSION['action'] = 'export_select_list';
$_SESSION['export'] = 'zipfile';
if(isset($_POST['zipfilename']) && $_POST['zipfilename'] !== '') {
if (isset($_POST['zipfilename']) && $_POST['zipfilename'] !== '') {
$filename = filter_var($_POST['zipfilename'], FILTER_SANITIZE_ENCODED);
} else {
$filename = 'website.zip';
}
$_SESSION['zipfilename'] = $filename;
}
break;
case 'exportcloud':
if(isset($_POST['exportcloudpath']) && $_POST['exportcloudpath'] !== '') {
if (isset($_POST['exportcloudpath']) && $_POST['exportcloudpath'] !== '') {
$_SESSION['action'] = 'export_select_list';
$_SESSION['export'] = 'cloud';
$_SESSION['exportcloudpath'] = filter_var($_POST['exportcloudpath'], FILTER_SANITIZE_ENCODED);
@ -462,11 +451,9 @@ class Webpages extends \Zotlabs\Web\Controller {
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'])
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) {
if ($b) {
$b = $b[0];
$blockinfo = array(
'body' => $b['body'],
@ -520,11 +507,9 @@ class Webpages extends \Zotlabs\Web\Controller {
foreach ($checkedlayouts as $mid) {
$l = 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 = 'PDL' order by iconfig.v asc limit 1",
dbesc($mid),
intval($channel['channel_id'])
where mid = '%s' and item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' order by iconfig.v asc limit 1", dbesc($mid), intval($channel['channel_id'])
);
if($l) {
if ($l) {
$l = $l[0];
$layoutinfo = array(
'body' => $l['body'],
@ -564,24 +549,19 @@ class Webpages extends \Zotlabs\Web\Controller {
foreach ($checkedpages as $mid) {
$p = q("select * from iconfig left join item on iconfig.iid = item.id
where item.uid = %d and item.mid = '%s' and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item_type = %d",
intval($channel['channel_id']),
dbesc($mid),
intval(ITEM_TYPE_WEBPAGE)
where item.uid = %d and item.mid = '%s' and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item_type = %d", intval($channel['channel_id']), dbesc($mid), intval(ITEM_TYPE_WEBPAGE)
);
if($p) {
if ($p) {
foreach ($p as $pp) {
// Get the associated layout
$layoutinfo = array();
if($pp['layout_mid']) {
if ($pp['layout_mid']) {
$l = 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 = 'PDL' order by iconfig.v asc limit 1",
dbesc($pp['layout_mid']),
intval($channel['channel_id'])
where mid = '%s' and item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' order by iconfig.v asc limit 1", dbesc($pp['layout_mid']), intval($channel['channel_id'])
);
if($l) {
if ($l) {
$l = $l[0];
$layoutinfo = array(
'body' => $l['body'],
@ -637,12 +617,12 @@ class Webpages extends \Zotlabs\Web\Controller {
'pagelink' => $pp['v'],
'mimetype' => $pp['mimetype'],
'contentfile' => $pp['v'] . '.' . $page_ext,
'layout' => ((x($layoutinfo,'name')) ? $layoutinfo['name'] : ''),
'layout' => ((x($layoutinfo, 'name')) ? $layoutinfo['name'] : ''),
'json' => array(
'title' => $pp['title'],
'pagelink' => $pp['v'],
'mimetype' => $pp['mimetype'],
'layout' => ((x($layoutinfo,'name')) ? $layoutinfo['name'] : ''),
'layout' => ((x($layoutinfo, 'name')) ? $layoutinfo['name'] : ''),
)
);
$page_filename = $pageinfo['pagelink'] . '.' . $page_ext;
@ -660,7 +640,7 @@ class Webpages extends \Zotlabs\Web\Controller {
}
}
}
if($action === 'zipfile') {
if ($action === 'zipfile') {
// Generate the zip file
\Zotlabs\Lib\ExtendedZip::zipTree($tmp_folderpath, $zip_filepath, \ZipArchive::CREATE);
// Output the file for download
@ -668,12 +648,12 @@ class Webpages extends \Zotlabs\Web\Controller {
header("Content-Type: application/zip");
$success = readfile($zip_filepath);
} elseif ($action === 'cloud') { // Only zipfile or cloud should be possible values for $action here
if(isset($_SESSION['exportcloudpath'])) {
if (isset($_SESSION['exportcloudpath'])) {
require_once('include/attach.php');
$cloudpath = urldecode($_SESSION['exportcloudpath']);
$channel = \App::get_channel();
$dirpath = get_dirpath_by_cloudpath($channel, $cloudpath);
if(!$dirpath) {
if (!$dirpath) {
$x = attach_mkdirp($channel, $channel['channel_hash'], array('pathname' => $cloudpath));
$folder_hash = (($x['success']) ? $x['data']['hash'] : '');
@ -689,19 +669,18 @@ class Webpages extends \Zotlabs\Web\Controller {
$success = copy_folder_to_cloudfiles($channel, $channel['channel_hash'], $tmp_folderpath, $cloudpath);
}
}
if(!$success) {
if (!$success) {
logger('Error exporting webpage elements', LOGGER_NORMAL);
}
rrmdir($zip_folderpath); rrmdir($tmp_folderpath); // delete temporary files
rrmdir($zip_folderpath);
rrmdir($tmp_folderpath); // delete temporary files
break;
default :
break;
}
}
}
}