superfluous whitespace cleanup
This commit is contained in:
		| @@ -112,7 +112,7 @@ class Import extends \Zotlabs\Web\Controller { | |||||||
| 	//	print_r($data); | 	//	print_r($data); | ||||||
| 	 | 	 | ||||||
| 	 | 	 | ||||||
| 		if(! array_key_exists('compatibility,$data)) { | 		if(! array_key_exists('compatibility',$data)) { | ||||||
| 			call_hooks('import_foreign_channel_data',$data); | 			call_hooks('import_foreign_channel_data',$data); | ||||||
| 			if($data['handled']) | 			if($data['handled']) | ||||||
| 				return; | 				return; | ||||||
|   | |||||||
| @@ -846,7 +846,7 @@ function channel_export_items($channel_id, $start, $finish) { | |||||||
| 		$ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()]; | 		$ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()]; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	$r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created < '%s'  and resource_type = '' order by created", | 	$r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created <= '%s'  and resource_type = '' order by created", | ||||||
| 		intval(ITEM_TYPE_POST), | 		intval(ITEM_TYPE_POST), | ||||||
| 		intval($channel_id), | 		intval($channel_id), | ||||||
| 		dbesc($start), | 		dbesc($start), | ||||||
|   | |||||||
| @@ -1187,413 +1187,420 @@ function convert_oldfields(&$arr,$old,$new) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function scan_webpage_elements($path, $type, $cloud = false) { | function scan_webpage_elements($path, $type, $cloud = false) { | ||||||
| 		$channel = \App::get_channel(); | 	$channel = \App::get_channel(); | ||||||
| 		$dirtoscan = $path; | 	$dirtoscan = $path; | ||||||
| 		switch ($type) { | 	switch ($type) { | ||||||
| 			case 'page': | 		case 'page': | ||||||
| 				$dirtoscan .= '/pages/'; | 			$dirtoscan .= '/pages/'; | ||||||
| 				$json_filename = 'page.json'; | 			$json_filename = 'page.json'; | ||||||
| 				break; | 			break; | ||||||
| 			case 'layout': | 		case 'layout': | ||||||
| 				$dirtoscan .= '/layouts/'; | 			$dirtoscan .= '/layouts/'; | ||||||
| 				$json_filename = 'layout.json'; | 			$json_filename = 'layout.json'; | ||||||
| 				break; | 			break; | ||||||
| 			case 'block': | 		case 'block': | ||||||
| 				$dirtoscan .= '/blocks/'; | 			$dirtoscan .= '/blocks/'; | ||||||
| 				$json_filename = 'block.json'; | 			$json_filename = 'block.json'; | ||||||
| 				break; | 			break; | ||||||
| 			default : | 		default : | ||||||
| 				return array(); | 			return array(); | ||||||
| 		} | 	} | ||||||
| 		if($cloud) { | 	if($cloud) { | ||||||
| 			$dirtoscan = get_dirpath_by_cloudpath($channel, $dirtoscan); | 		$dirtoscan = get_dirpath_by_cloudpath($channel, $dirtoscan); | ||||||
| 		} | 	} | ||||||
| 		$elements = []; | 	$elements = []; | ||||||
| 		if (is_dir($dirtoscan)) { | 	if(is_dir($dirtoscan)) { | ||||||
| 			$dirlist = scandir($dirtoscan); | 		$dirlist = scandir($dirtoscan); | ||||||
| 			if ($dirlist) { | 		if($dirlist) { | ||||||
| 				foreach ($dirlist as $element) { | 			foreach($dirlist as $element) { | ||||||
| 					if ($element === '.' || $element === '..') { | 				if($element === '.' || $element === '..') { | ||||||
| 						continue; | 					continue; | ||||||
|  | 				} | ||||||
|  | 				$folder = $dirtoscan . '/' . $element; | ||||||
|  | 				if(is_dir($folder)) { | ||||||
|  | 					if($cloud) { | ||||||
|  | 						$jsonfilepath = $folder . '/' . get_filename_by_cloudname($json_filename, $channel, $folder); | ||||||
| 					} | 					} | ||||||
| 					$folder = $dirtoscan . '/' . $element; | 					else { | ||||||
| 					if (is_dir($folder)) { | 						$jsonfilepath = $folder . '/' . $json_filename; | ||||||
|  | 					} | ||||||
|  | 					if(is_file($jsonfilepath)) { | ||||||
|  | 						$metadata = json_decode(file_get_contents($jsonfilepath), true); | ||||||
| 						if($cloud) { | 						if($cloud) { | ||||||
| 							$jsonfilepath = $folder . '/' . get_filename_by_cloudname($json_filename, $channel, $folder); | 							$contentfilename = get_filename_by_cloudname($metadata['contentfile'], $channel, $folder); | ||||||
| 						} else { | 							$metadata['path'] = $folder . '/' . $contentfilename; | ||||||
| 							$jsonfilepath = $folder . '/' . $json_filename; |  | ||||||
| 						} | 						} | ||||||
| 						if (is_file($jsonfilepath)) { | 						else { | ||||||
| 							$metadata = json_decode(file_get_contents($jsonfilepath), true); | 							$contentfilename = $metadata['contentfile']; | ||||||
| 							if($cloud) { | 							$metadata['path'] = $folder . '/' . $contentfilename; | ||||||
| 								$contentfilename = get_filename_by_cloudname($metadata['contentfile'], $channel, $folder); | 						} | ||||||
| 								$metadata['path'] = $folder . '/' . $contentfilename; | 						if($metadata['contentfile'] === '') { | ||||||
| 							} else { | 							logger('Invalid ' . $type . ' content file'); | ||||||
| 								$contentfilename = $metadata['contentfile']; | 							return false; | ||||||
| 								$metadata['path'] = $folder . '/' . $contentfilename; | 						} | ||||||
|  | 						$content = file_get_contents($folder . '/' . $contentfilename); | ||||||
|  | 						if(!$content) { | ||||||
|  | 							if(is_readable($folder . '/' . $contentfilename)) { | ||||||
|  | 								$content = ''; | ||||||
| 							} | 							} | ||||||
| 							if ($metadata['contentfile'] === '') { | 							else { | ||||||
| 								logger('Invalid ' . $type . ' content file'); | 								logger('Failed to get file content for ' . $metadata['contentfile']); | ||||||
| 								return false; | 								return false; | ||||||
| 							} | 							} | ||||||
| 							$content = file_get_contents($folder . '/' . $contentfilename); |  | ||||||
| 							if (!$content) { |  | ||||||
| 									if(is_readable($folder . '/' . $contentfilename)) { |  | ||||||
| 											$content = ''; |  | ||||||
| 									} else { |  | ||||||
| 										logger('Failed to get file content for ' . $metadata['contentfile']); |  | ||||||
| 										return false; |  | ||||||
| 									} |  | ||||||
| 							} |  | ||||||
| 							$elements[] = $metadata; |  | ||||||
| 						} | 						} | ||||||
|  | 						$elements[] = $metadata; | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		return $elements; |  | ||||||
| 	} | 	} | ||||||
|  | 	return $elements; | ||||||
|  | } | ||||||
| 	 | 	 | ||||||
|  |  | ||||||
| 	function import_webpage_element($element, $channel, $type) { | function import_webpage_element($element, $channel, $type) { | ||||||
| 		 | 		 | ||||||
| 		$arr = array();		// construct information for the webpage element item table record | 	$arr = array();		// construct information for the webpage element item table record | ||||||
| 		 | 		 | ||||||
| 		switch ($type) { | 	switch($type) { | ||||||
| 			// | 		// | ||||||
| 			//	PAGES | 		//	PAGES | ||||||
| 			// | 		// | ||||||
| 			case 'page': | 		case 'page': | ||||||
|         $arr['item_type'] = ITEM_TYPE_WEBPAGE; | 			$arr['item_type'] = ITEM_TYPE_WEBPAGE; | ||||||
|         $namespace = 'WEBPAGE'; | 			$namespace = 'WEBPAGE'; | ||||||
| 				$name = $element['pagelink']; | 			$name = $element['pagelink']; | ||||||
|         if($name) { |         	if($name) { | ||||||
| 						require_once('library/urlify/URLify.php'); | 				require_once('library/urlify/URLify.php'); | ||||||
| 						$name = strtolower(\URLify::transliterate($name)); | 				$name = strtolower(\URLify::transliterate($name)); | ||||||
|         } |         	} | ||||||
| 				$arr['title'] = $element['title']; | 			$arr['title'] = $element['title']; | ||||||
|         $arr['term'] = $element['term']; | 			$arr['term'] = $element['term']; | ||||||
| 				$arr['layout_mid'] = ''; // by default there is no layout associated with the page | 			$arr['layout_mid'] = ''; // by default there is no layout associated with the page | ||||||
| 				// If a layout was specified, find it in the database and get its info. If | 			// If a layout was specified, find it in the database and get its info. If | ||||||
|         // it does not exist, leave layout_mid empty | 	        // it does not exist, leave layout_mid empty | ||||||
|         if($element['layout'] !== '') { |     	    if($element['layout'] !== '') { | ||||||
|             $liid = q("select iid from iconfig where k = 'PDL' and v = '%s' and cat = 'system'", |         	    $liid = q("select iid from iconfig where k = 'PDL' and v = '%s' and cat = 'system'", | ||||||
|                     dbesc($element['layout']) | 					dbesc($element['layout']) | ||||||
|             ); |             	); | ||||||
|             if($liid) { | 				if($liid) { | ||||||
|                 $linfo = q("select mid from item where id = %d", |                 	$linfo = q("select mid from item where id = %d", | ||||||
|                         intval($liid[0]['iid']) | 						intval($liid[0]['iid']) | ||||||
|                 ); | 	                ); | ||||||
|                 $arr['layout_mid'] = $linfo[0]['mid']; |     	            $arr['layout_mid'] = $linfo[0]['mid']; | ||||||
|             }                  |         	    }                  | ||||||
|         } |         	} | ||||||
| 				break; | 			break; | ||||||
| 			// | 		// | ||||||
| 			//	LAYOUTS | 		//	LAYOUTS | ||||||
| 			// | 		// | ||||||
| 			case 'layout': | 		case 'layout': | ||||||
|         $arr['item_type'] = ITEM_TYPE_PDL; | 			$arr['item_type'] = ITEM_TYPE_PDL; | ||||||
|         $namespace = 'PDL'; | 			$namespace = 'PDL'; | ||||||
| 				$name = $element['name']; | 			$name = $element['name']; | ||||||
| 				$arr['title'] = $element['description']; | 			$arr['title'] = $element['description']; | ||||||
|         $arr['term'] = $element['term']; | 			$arr['term'] = $element['term']; | ||||||
| 				break; | 			break; | ||||||
| 			// | 		// | ||||||
| 			//	BLOCKS | 		//	BLOCKS | ||||||
| 			// | 		// | ||||||
| 			case 'block': | 		case 'block': | ||||||
|         $arr['item_type'] = ITEM_TYPE_BLOCK; | 			$arr['item_type'] = ITEM_TYPE_BLOCK; | ||||||
|         $namespace = 'BUILDBLOCK'; | 			$namespace = 'BUILDBLOCK'; | ||||||
| 				$name = $element['name']; | 			$name = $element['name']; | ||||||
| 				$arr['title'] = $element['title']; | 			$arr['title'] = $element['title']; | ||||||
| 				 | 				 | ||||||
| 				break; | 			break; | ||||||
| 			default : | 		default : | ||||||
| 				return null;	// return null if invalid element type | 			return null;	// return null if invalid element type | ||||||
| 		} | 	} | ||||||
| 		 | 		 | ||||||
| 		$arr['uid'] = $channel['channel_id']; | 	$arr['uid'] = $channel['channel_id']; | ||||||
| 		$arr['aid'] = $channel['channel_account_id']; | 	$arr['aid'] = $channel['channel_account_id']; | ||||||
| 		 | 		 | ||||||
| 	  // Check if an item already exists based on the name | 	// Check if an item already exists based on the name | ||||||
| 		$iid = q("select iid from iconfig where k = '" . $namespace . "' and v = '%s' and cat = 'system'", | 	$iid = q("select iid from iconfig where k = '" . $namespace . "' and v = '%s' and cat = 'system'", | ||||||
| 						dbesc($name) | 		dbesc($name) | ||||||
|  | 	); | ||||||
|  | 	if($iid) { // If the item does exist, get the item metadata | ||||||
|  | 		$iteminfo = q("select mid,created,edited from item where id = %d", | ||||||
|  | 			intval($iid[0]['iid']) | ||||||
| 		); | 		); | ||||||
| 		if($iid) { // If the item does exist, get the item metadata | 		$arr['mid'] = $arr['parent_mid'] = $iteminfo[0]['mid']; | ||||||
| 				$iteminfo = q("select mid,created,edited from item where id = %d", | 		$arr['created'] = $iteminfo[0]['created']; | ||||||
| 								intval($iid[0]['iid']) | 	} | ||||||
| 				); | 	else { // otherwise, generate the creation times and unique id | ||||||
| 				$arr['mid'] = $arr['parent_mid'] = $iteminfo[0]['mid']; | 		$arr['created'] = datetime_convert('UTC', 'UTC'); | ||||||
| 				$arr['created'] = $iteminfo[0]['created']; | 		$arr['mid'] = $arr['parent_mid'] = item_message_id(); | ||||||
| 		} else { // otherwise, generate the creation times and unique id | 	} | ||||||
| 				$arr['created'] = datetime_convert('UTC', 'UTC'); | 	// Update the edited time whether or not the element already exists | ||||||
| 				$arr['mid'] = $arr['parent_mid'] = item_message_id(); | 	$arr['edited'] = datetime_convert('UTC', 'UTC'); | ||||||
| 		} | 	// Import the actual element content | ||||||
| 		// Update the edited time whether or not the element already exists | 	$arr['body'] = file_get_contents($element['path']); | ||||||
| 		$arr['edited'] = datetime_convert('UTC', 'UTC'); | 	// The element owner is the channel importing the elements | ||||||
| 		// Import the actual element content | 	$arr['owner_xchan'] = get_observer_hash(); | ||||||
| 		$arr['body'] = file_get_contents($element['path']); | 	// The author is either the owner or whomever was specified | ||||||
| 		// The element owner is the channel importing the elements | 	$arr['author_xchan'] = (($element['author_xchan']) ? $element['author_xchan'] : get_observer_hash()); | ||||||
| 		$arr['owner_xchan'] = get_observer_hash(); | 	// Import mimetype if it is a valid mimetype for the element | ||||||
| 		// The author is either the owner or whomever was specified | 	$mimetypes = [	'text/bbcode', | ||||||
| 		$arr['author_xchan'] = (($element['author_xchan']) ? $element['author_xchan'] : get_observer_hash()); | 		'text/html', | ||||||
| 		// Import mimetype if it is a valid mimetype for the element | 		'text/markdown', | ||||||
| 		$mimetypes = [	'text/bbcode', | 		'text/plain', | ||||||
| 										'text/html', | 		'application/x-pdl', | ||||||
| 										'text/markdown', | 		'application/x-php'	 | ||||||
| 										'text/plain', | 	]; | ||||||
| 										'application/x-pdl', | 	// Blocks and pages can have any of the valid mimetypes, but layouts must be text/bbcode | ||||||
| 										'application/x-php'	 | 	if((in_array($element['mimetype'], $mimetypes))	&& ($type === 'page' || $type === 'block') ) { | ||||||
| 		]; | 		$arr['mimetype'] = $element['mimetype']; | ||||||
| 		// 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') ) { | 	else { | ||||||
| 				$arr['mimetype'] = $element['mimetype']; | 		$arr['mimetype'] = 'text/bbcode'; | ||||||
| 		} else { | 	} | ||||||
| 				$arr['mimetype'] = 'text/bbcode'; |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		// Verify ability to use html or php!!! | 	// Verify ability to use html or php!!! | ||||||
| 		$execflag = false; | 	$execflag = false; | ||||||
| 		if ($arr['mimetype'] === 'application/x-php' || $arr['mimetype'] === 'text/html') { | 	if($arr['mimetype'] === 'application/x-php' || $arr['mimetype'] === 'text/html') { | ||||||
| 				$z = q("select account_id, account_roles, channel_pageflags from account " | 		$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",  | 			. "left join channel on channel_account_id = account_id where channel_id = %d limit 1",  | ||||||
| 					intval(local_channel()) |  | ||||||
| 				); |  | ||||||
|  |  | ||||||
| 				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 = 'system' limit 1",  |  | ||||||
| 			dbesc($name),  |  | ||||||
| 			dbesc($namespace) |  | ||||||
| 		); |  | ||||||
|  |  | ||||||
| 		$i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1",  |  | ||||||
| 			dbesc($arr['mid']),  |  | ||||||
| 			intval(local_channel()) | 			intval(local_channel()) | ||||||
| 		); | 		); | ||||||
| 		$remote_id = 0; |  | ||||||
| 		if ($z && $i) { | 		if($z && (($z[0]['account_roles'] & ACCOUNT_ROLE_ALLOWCODE) || ($z[0]['channel_pageflags'] & PAGE_ALLOWCODE))) { | ||||||
| 				$remote_id = $z[0]['id']; | 			$execflag = true; | ||||||
| 				$arr['id'] = $i[0]['id']; |  | ||||||
| 				// don't update if it has the same timestamp as the original |  | ||||||
| 				if ($arr['edited'] > $i[0]['edited']) |  | ||||||
| 						$x = item_store_update($arr, $execflag); |  | ||||||
| 		} else { |  | ||||||
| 				if (($i) && (intval($i[0]['item_deleted']))) { |  | ||||||
| 						// was partially deleted already, finish it off |  | ||||||
| 						q("delete from item where mid = '%s' and uid = %d",  |  | ||||||
| 							dbesc($arr['mid']),  |  | ||||||
| 							intval(local_channel()) |  | ||||||
| 						); |  | ||||||
| 				} |  | ||||||
| 				$x = item_store($arr, $execflag); |  | ||||||
| 		} | 		} | ||||||
| 		if ($x['success']) { | 		else { | ||||||
| 				$item_id = $x['item_id']; | 			logger('Unable to import element "' . $name .'" because AllowCode permission is denied.'); | ||||||
| 				update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']); | 			notice( t('Unable to import element "' . $name .'" because AllowCode permission is denied.') . EOL); | ||||||
| 				$element['import_success'] = 1; | 			$element['import_success'] = 0; | ||||||
| 		} else { | 			return $element; | ||||||
| 				$element['import_success'] = 0; |  | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
| 		 | 		 | ||||||
| 		return $element; | 	$z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'system' limit 1",  | ||||||
|      | 		dbesc($name),  | ||||||
|  | 		dbesc($namespace) | ||||||
|  | 	); | ||||||
|  |  | ||||||
|  | 	$i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1",  | ||||||
|  | 		dbesc($arr['mid']),  | ||||||
|  | 		intval(local_channel()) | ||||||
|  | 	); | ||||||
|  | 	$remote_id = 0; | ||||||
|  | 	if($z && $i) { | ||||||
|  | 		$remote_id = $z[0]['id']; | ||||||
|  | 		$arr['id'] = $i[0]['id']; | ||||||
|  | 		// don't update if it has the same timestamp as the original | ||||||
|  | 		if($arr['edited'] > $i[0]['edited']) | ||||||
|  | 			$x = item_store_update($arr, $execflag); | ||||||
|  | 	} | ||||||
|  | 	else { | ||||||
|  | 		if(($i) && (intval($i[0]['item_deleted']))) { | ||||||
|  | 			// was partially deleted already, finish it off | ||||||
|  | 			q("delete from item where mid = '%s' and uid = %d",  | ||||||
|  | 				dbesc($arr['mid']),  | ||||||
|  | 				intval(local_channel()) | ||||||
|  | 			); | ||||||
|  | 		} | ||||||
|  | 		$x = item_store($arr, $execflag); | ||||||
|  | 	} | ||||||
|  | 	if($x['success']) { | ||||||
|  | 		$item_id = $x['item_id']; | ||||||
|  | 		update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']); | ||||||
|  | 		$element['import_success'] = 1; | ||||||
|  | 	} | ||||||
|  | 	else { | ||||||
|  | 		$element['import_success'] = 0; | ||||||
|  | 	} | ||||||
|  | 		 | ||||||
|  | 	return $element;     | ||||||
| } | } | ||||||
|  |  | ||||||
| function get_webpage_elements($channel, $type = 'all') { | function get_webpage_elements($channel, $type = 'all') { | ||||||
| 		$elements = array(); | 	$elements = array(); | ||||||
| 		if(!$channel['channel_id'])	{ | 	if(!$channel['channel_id'])	{ | ||||||
| 				return null; | 			return null; | ||||||
| 		} | 	} | ||||||
| 		switch ($type) { | 	switch($type) { | ||||||
| 				case 'all': | 		case 'all': | ||||||
| 						// If all, execute all the pages, layouts, blocks case statements | 			// If all, execute all the pages, layouts, blocks case statements | ||||||
| 				case 'pages': | 		case 'pages': | ||||||
| 						$elements['pages'] = null; | 			$elements['pages'] = null; | ||||||
| 						$owner = $channel['channel_id']; | 			$owner = $channel['channel_id']; | ||||||
| 							 | 							 | ||||||
| 						$sql_extra = item_permissions_sql($owner); | 			$sql_extra = item_permissions_sql($owner); | ||||||
|  |  | ||||||
|  |  | ||||||
| 						$r = q("select * from iconfig left join item on iconfig.iid = item.id  | 			$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  | 				where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'WEBPAGE' and item_type = %d  | ||||||
| 							$sql_extra order by item.created desc", | 				$sql_extra order by item.created desc", | ||||||
| 							intval($owner), | 				intval($owner), | ||||||
| 							intval(ITEM_TYPE_WEBPAGE) | 				intval(ITEM_TYPE_WEBPAGE) | ||||||
| 						); | 			); | ||||||
| 						 | 						 | ||||||
| 						$pages = null; | 			$pages = null; | ||||||
|  |  | ||||||
| 						if($r) { | 			if($r) { | ||||||
| 								$elements['pages'] = array(); | 				$elements['pages'] = array(); | ||||||
| 							$pages = array(); | 				$pages = array(); | ||||||
| 							foreach($r as $rr) { | 				foreach($r as $rr) { | ||||||
| 								unobscure($rr); | 					unobscure($rr); | ||||||
|  |  | ||||||
| 								//$lockstate = (($rr['allow_cid'] || $rr['allow_gid'] || $rr['deny_cid'] || $rr['deny_gid']) ? 'lock' : 'unlock'); | 					//$lockstate = (($rr['allow_cid'] || $rr['allow_gid'] || $rr['deny_cid'] || $rr['deny_gid']) ? 'lock' : 'unlock'); | ||||||
|  |  | ||||||
| 								$element_arr = array( | 					$element_arr = array( | ||||||
| 									'type'		=> 'webpage', | 						'type'		=> 'webpage', | ||||||
| 									'title'		=> $rr['title'], | 						'title'		=> $rr['title'], | ||||||
| 									'body'		=> $rr['body'], | 						'body'		=> $rr['body'], | ||||||
| 									'created'	=> $rr['created'], | 						'created'	=> $rr['created'], | ||||||
| 									'edited'	=> $rr['edited'], | 						'edited'	=> $rr['edited'], | ||||||
| 									'mimetype'	=> $rr['mimetype'], | 						'mimetype'	=> $rr['mimetype'], | ||||||
| 									'pagetitle'	=> $rr['v'], | 						'pagetitle'	=> $rr['v'], | ||||||
| 									'mid'		=> $rr['mid'], | 						'mid'		=> $rr['mid'], | ||||||
| 									'layout_mid'    => $rr['layout_mid'] | 						'layout_mid'    => $rr['layout_mid'] | ||||||
| 								); | 					); | ||||||
| 								$pages[$rr['iid']][] = array( | 					$pages[$rr['iid']][] = array( | ||||||
| 									'url'		=> $rr['iid'], | 						'url'		=> $rr['iid'], | ||||||
| 									'pagetitle'	=> $rr['v'], | 						'pagetitle'	=> $rr['v'], | ||||||
| 									'title'		=> $rr['title'], | 						'title'		=> $rr['title'], | ||||||
| 									'created'	=> datetime_convert('UTC',date_default_timezone_get(),$rr['created']), | 						'created'	=> datetime_convert('UTC',date_default_timezone_get(),$rr['created']), | ||||||
| 									'edited'	=> datetime_convert('UTC',date_default_timezone_get(),$rr['edited']), | 						'edited'	=> datetime_convert('UTC',date_default_timezone_get(),$rr['edited']), | ||||||
| 									'bb_element'	=> '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]', | 						'bb_element'	=> '[element]' . base64url_encode(json_encode($element_arr)) . '[/element]', | ||||||
| 									//'lockstate'     => $lockstate | 						//'lockstate'     => $lockstate | ||||||
| 								); | 					); | ||||||
| 								$elements['pages'][] = $element_arr; | 					$elements['pages'][] = $element_arr; | ||||||
| 							} | 				} | ||||||
| 							 | 							 | ||||||
| 						} | 			} | ||||||
| 						if($type !== 'all') { | 			if($type !== 'all') { | ||||||
| 								break; | 				break; | ||||||
| 						} | 			} | ||||||
|  |  | ||||||
| 				case 'layouts': | 		case 'layouts': | ||||||
| 						$elements['layouts'] = null; | 			$elements['layouts'] = null; | ||||||
| 						$owner = $channel['channel_id']; | 			$owner = $channel['channel_id']; | ||||||
| 							 | 							 | ||||||
| 						$sql_extra = item_permissions_sql($owner); | 			$sql_extra = item_permissions_sql($owner); | ||||||
|  |  | ||||||
|  |  | ||||||
| 						$r = q("select * from iconfig left join item on iconfig.iid = item.id  | 			$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  | 				where item.uid = %d and iconfig.cat = 'system' and iconfig.k = 'PDL' and item_type = %d  | ||||||
| 							$sql_extra order by item.created desc", | 				$sql_extra order by item.created desc", | ||||||
| 							intval($owner), | 				intval($owner), | ||||||
| 							intval(ITEM_TYPE_PDL) | 				intval(ITEM_TYPE_PDL) | ||||||
| 						); | 			); | ||||||
| 						 | 						 | ||||||
| 						$layouts = null; | 			$layouts = null; | ||||||
|  |  | ||||||
| 						if($r) { | 			if($r) { | ||||||
| 								$elements['layouts'] = array(); | 				$elements['layouts'] = array(); | ||||||
| 							$layouts = array(); | 				$layouts = array(); | ||||||
| 							foreach($r as $rr) { | 				foreach($r as $rr) { | ||||||
| 								unobscure($rr); | 					unobscure($rr); | ||||||
|  |  | ||||||
| 								$elements['layouts'][] = array( | 					$elements['layouts'][] = array( | ||||||
| 									'type'		=> 'layout', | 						'type'		=> 'layout', | ||||||
| 									'description'		=> $rr['title'],		// description of the layout | 						'description'		=> $rr['title'],		// description of the layout | ||||||
| 									'body'		=> $rr['body'], | 						'body'		=> $rr['body'], | ||||||
| 									'created'	=> $rr['created'], | 						'created'	=> $rr['created'], | ||||||
| 									'edited'	=> $rr['edited'], | 						'edited'	=> $rr['edited'], | ||||||
| 									'mimetype'	=> $rr['mimetype'], | 						'mimetype'	=> $rr['mimetype'], | ||||||
| 									'name'	=> $rr['v'],					// name of reference for the layout | 						'name'	=> $rr['v'],					// name of reference for the layout | ||||||
| 									'mid'		=> $rr['mid'], | 						'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) | ||||||
|  | 			); | ||||||
| 						 | 						 | ||||||
| 						if($type !== 'all') { | 			$blocks = null; | ||||||
| 								break; |  | ||||||
| 						} | 			if($r) { | ||||||
| 						 | 				$elements['blocks'] = array(); | ||||||
| 				case 'blocks': | 				$blocks = array(); | ||||||
| 						$elements['blocks'] = null; | 				foreach($r as $rr) { | ||||||
| 						$owner = $channel['channel_id']; | 					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'] | ||||||
|  | 					); | ||||||
|  | 				} | ||||||
| 							 | 							 | ||||||
| 						$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($type !== 'all') { | ||||||
|  | 				break; | ||||||
| 						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') { | 		default: | ||||||
| 								break; | 			break; | ||||||
| 						} | 	} | ||||||
| 						 | 	return $elements; | ||||||
| 				default: |  | ||||||
| 						break; |  | ||||||
| 		} |  | ||||||
| 		return $elements; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| /* creates a compressed zip file */ | /* creates a compressed zip file */ | ||||||
|  |  | ||||||
| function create_zip_file($files = array(), $destination = '', $overwrite = false) { | function create_zip_file($files = array(), $destination = '', $overwrite = false) { | ||||||
| 		//if the zip file already exists and overwrite is false, return false | 	// if the zip file already exists and overwrite is false, return false | ||||||
| 		if (file_exists($destination) && !$overwrite) { | 	if(file_exists($destination) && !$overwrite) { | ||||||
| 				return false; | 		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; | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 		//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 we have good files... | ||||||
| 		if (count($valid_files)) { | 	if(count($valid_files)) { | ||||||
| 				//create the archive | 		//create the archive | ||||||
| 				$zip = new ZipArchive(); | 		$zip = new ZipArchive(); | ||||||
| 				if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { | 		if($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { | ||||||
| 						return false; | 			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; |  | ||||||
| 		} | 		} | ||||||
|  | 		// 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; | ||||||
|  | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user