| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 | <!DOCTYPE html><html>	<head>		<meta charset="UTF-8">		<meta name="apple-mobile-web-app-capable" content="yes" />		<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>		<meta name="theme-color" content="#ff9224">		<link rel="stylesheet" href="../script/tocas/tocas.css">		<script src="../script/tocas/tocas.js"></script>		<script src="../script/jquery.min.js"></script>		<script src="../script/ao_module.js"></script>		<link rel="manifest" crossorigin="use-credentials" href="manifest.json">		<title>Blog</title>		<style>			body{				background-color: white;			}			.postControls{				position: absolute;				top: 0.5em;				right: 0.5em;			}			.blog.main{				background-color: #ff9224;				border: 1px solid #ff9224;				color: white;			}			.blog.main:hover{				background-color: #c7721c !important;				border: 1px solid #c7721c !important;				color: white !important;			}			.blog.green{				background-color: #47d191;				border: 1px solid #47d191;				color: white;			}			.blog.green:hover{				background-color: #38a170 !important;				border: 1px solid #38a170 !important;				color: white !important;			}			.blog.red{				background-color: #ff3d3d;				border: 1px solid #ff3d3d;				color: white;			}			.blog.red:hover{				background-color: #962d2d !important;				border: 1px solid #962d2d !important;				color: white !important;			}			.blog.blue{				background-color: #4287f5;				border: 1px solid #4287f5;				color: white;			}			.blog.blue:hover{				background-color: #336bc4 !important;				border: 1px solid #336bc4 !important;				color: white !important;			}			            .topPad{                margin-top: 4px;            }		</style>	</head>	<body>		<br><br>		<div class="ts container">			<div>				<h4><img class="ts mini spaced image" src="img/module_icon.png" style="margin-right: 12px;">  Blog Writer</h4>			</div>			<div class="ts divider"></div>			<div class="ts stackable grid">				<!-- Post container-->				<div class="twelve wide column" id="postList">									</div>				<!-- Setting container-->				<div class="four wide column">					<div class="ts segment">						<a class="ts fluid small button blog main" href="editor.html"><i class="add icon"></i> New Post</a>						<button class="ts fluid small button blog green topPad"><i class="text file outline icon"></i> Update Post Renders</button>						<div class="ts divider"></div>						<button class="ts fluid basic small button blog" onclick="openBlog();"><i class="text file outline icon"></i> View Blog</button>						<button class="ts fluid basic small button blog topPad" onclick="openWebRoot();"><i class="folder open icon"></i> Open www</button>						<div class="ts divider"></div>						<button class="ts fluid basic small button topPad" onclick="openBlogSettings();"><i class="home icon"></i> Blog Settings</button>						<button class="ts fluid basic small button topPad" onclick="openPersonalPageTab();"><i class="setting icon"></i> Homepage Settings</button>					</div>				</div>			</div>			<br><br><br>		</div>				<script>			var currentWebDeployRoot = "";			//Get the current web root path			getWebRoot(function(){				//List all the post stored in the system				listPost();			});			function openBlogSettings(){				window.location.href = "setting.html";			}			function openPost(object){				//Parse the file object following ArozOS file descriptor protocol				var filepath = $(object).attr("filepath");				var filename = filepath.split("/").pop();				var file = [{					filename: filename,					filepath: filepath				}]				var fd = encodeURIComponent(JSON.stringify(file));				window.location.href = "editor.html#" + fd;			}			function openWebRoot(){				getWebRoot(function(webroot){					if (webroot != ""){						ao_module_openPath(webroot);					}else{						alert("Web Root not set. Please go to Homepage Settings to setup your webroot before using B Blog Writer.")					}				});							}			function publishPostButton(object){				var filepath = $(object).attr("filepath");				publishPost(filepath);			}			function hidePostButton(btn){					var filepath = $(btn).attr('filepath');					$(btn).addClass("loading");					ao_module_agirun("Blog/backend/hidePost.js",{						webroot: currentWebDeployRoot,						filepath: filepath					}, function(data){						listPost();						$(btn).removeClass("loading");					}, function(){						//failed return						$(btn).removeClass("loading");					})				}			function publishPost(filepath){				ao_module_agirun("Blog/backend/publish.js", {					filepath: filepath,					webroot: currentWebDeployRoot				}, function(data){					console.log(data);					listPost();				})			}			function openBlog(){				checkIfWebRootEnabled(function(data){					if (data == true){						//Get the username of the current session						$.get("../system/desktop/user", function(userinfo){							//Open the page in new tab							window.open("../www/" + userinfo.Username + "/blog/");						});					}else{						alert("Personal page not enabled");					}				})			}			function openPersonalPageTab(){				ao_module_openSetting("Network", "Personal Page");			}			function checkIfWebRootEnabled(callback){				$.get("../system/network/www/toggle", function(data){					callback(data);				});			}			function getWebRoot(callback = undefined){				$.get("../system/network/www/webRoot", function(data){					if (data == null || data == "" || data == undefined){						callback("");						return;					}					currentWebDeployRoot = data;					if (callback != undefined){						callback(data);					}									});			}			function listPost(){				$("#postList").html(``);				ao_module_agirun("Blog/backend/listPosts.js", {					webroot: currentWebDeployRoot				}, function(data){					if (data.length == 0){						//There is no post in the system						$("#postList").html(`<div class="ts segment post">							<h5 class="ts header">								<div class="content">									No Blog Posts									<div class="sub header">Create your first post with the "New Post"</div>								</div>							</h5>													</div>`);					}else{						//Render the post						console.log(data);						data.forEach(post => {							//Generate the tag HTML 							var tags = post.tags;							var tagHTML = [];							tags.forEach(tag => {								tagHTML.push(`<a class="section">${tag}</a>`);							});							tagHTML = tagHTML.join(`<div class="divider">,</div>`);							//Post view permission indicator							var postViewIcon = "";							//Publish or hide post button							var publicPostOnly = "";							var privatePostOnly = "";							if (post.view == "private"){								postViewIcon = `<i class="hide icon"></i> Draft`;								publicPostOnly = "display:none;"							}else{								postViewIcon = `<i class="unhide icon"></i> Published`;								privatePostOnly = "display:none;"							}							$("#postList").append(`<div class="ts segment post">							<div class="ts header">								<a href="#" onclick="openPost(this);" filepath="${post.filepath}">${post.title} </a>								<div class="sub header">									<div>									<span style="padding-right: 1em;">${postViewIcon}</span>									<span  style="padding-right: 1em;"><i class="calendar icon"></i> ${post.modtime}</span>									<div class="ts breadcrumb">										<div class="section">											<i class="tag icon"></i>										</div>										${tagHTML}									</div>									</div>								</div>							</div>							${stripHtml(post.content)}										<div class="postControls">								<button onclick="hidePostButton(this);" filepath="${post.filepath}" style="${publicPostOnly}" class="ts mini icon button blog red" title="Hide Post"><i class="hide icon"></i></button>								<button onclick="publishPostButton(this);" filepath="${post.filepath}" style="${privatePostOnly}" class="ts mini icon button blog green" title="Publish Post"><i class="upload icon"></i></button>							</div>						</div>`)						})					}				});				function stripHtml(html){					let tmp = document.createElement("DIV");					tmp.innerHTML = html;					var result = tmp.textContent || tmp.innerText || "";					return result;				}			}		</script>	</body></html>
 |