mirror of
https://github.com/lxsang/antd-web-apps
synced 2024-12-26 01:18:21 +01:00
fix blog
This commit is contained in:
parent
914bff3498
commit
9d8e0916a2
@ -1,5 +1,4 @@
|
||||
<?lua
|
||||
local args = {...}
|
||||
local jsclass = __main__:get("jsclass")
|
||||
if jsclass == nil then jsclass = "" end
|
||||
?>
|
||||
|
126
blog/assets/main.js
Normal file
126
blog/assets/main.js
Normal file
@ -0,0 +1,126 @@
|
||||
var scheme = undefined;
|
||||
String.prototype.__ = function()
|
||||
{
|
||||
return this
|
||||
}
|
||||
function subscribe(prefix)
|
||||
{
|
||||
if(scheme) return;
|
||||
// get scheme
|
||||
$.get(prefix+"/rst/subscribe.html")
|
||||
.done(function(d) {
|
||||
scheme = $.parseHTML(d)
|
||||
var obs = riot.observable()
|
||||
$(scheme).css("visibility","hidden")
|
||||
$("#desktop" ).append(scheme)
|
||||
obs.on("exit", function(){
|
||||
$(scheme).remove()
|
||||
scheme = undefined
|
||||
})
|
||||
obs.on("rendered", function(d){
|
||||
$(".afx-window-title", scheme).html("Subscribe")
|
||||
$("[data-id='send']", scheme).click(function(){
|
||||
var status = $("[data-id='status']", scheme)
|
||||
status.html("");
|
||||
var els = $("[data-class='data']", scheme)
|
||||
var data = {}
|
||||
|
||||
for(var i = 0; i < els.length; i++)
|
||||
data[els[i].name] = $(els[i]).val()
|
||||
if(data.email == "" || data.subject == "" || data.content == "" || data.name == "")
|
||||
return status.html("Please enter all the fields");
|
||||
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
if(!re.test(String(data.email).toLowerCase()))
|
||||
return status.html("Email is not correct");
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: prefix + "/service/subscribe",
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(data),
|
||||
dataType: 'json',
|
||||
success: null
|
||||
}).done(function(r){
|
||||
if(r.error)
|
||||
{
|
||||
console.log(r.error)
|
||||
alert(r.error)
|
||||
}
|
||||
else
|
||||
{
|
||||
obs.trigger("exit")
|
||||
alert("You have been subscribed. Thanks")
|
||||
}
|
||||
}).fail(function(e, s){
|
||||
console.log(e)
|
||||
alert("Error: " + e)
|
||||
})
|
||||
})
|
||||
$(scheme).css("visibility","visible")
|
||||
})
|
||||
riot.mount(scheme, {observable:obs})
|
||||
})
|
||||
.fail(function() {
|
||||
alert( "Cannot get the form" );
|
||||
})
|
||||
}
|
||||
function mailtoMe(prefix)
|
||||
{
|
||||
if(scheme) return;
|
||||
// get scheme
|
||||
$.get(prefix+"/rst/sendto.html")
|
||||
.done(function(d) {
|
||||
scheme = $.parseHTML(d)
|
||||
var obs = riot.observable()
|
||||
$(scheme).css("visibility","hidden")
|
||||
$("#desktop" ).append(scheme)
|
||||
obs.on("exit", function(){
|
||||
$(scheme).remove()
|
||||
scheme = undefined
|
||||
})
|
||||
obs.on("rendered", function(d){
|
||||
$(".afx-window-title", scheme).html("Send me an email")
|
||||
$("[data-id='send']", scheme).click(function(){
|
||||
var status = $("[data-id='status']", scheme)
|
||||
status.html("");
|
||||
var els = $("[data-class='data']", scheme)
|
||||
var data = {}
|
||||
|
||||
for(var i = 0; i < els.length; i++)
|
||||
data[els[i].name] = $(els[i]).val()
|
||||
if(data.email == "" || data.subject == "" || data.content == "" || data.name == "")
|
||||
return status.html("Please enter all the fields");
|
||||
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||
if(!re.test(String(data.email).toLowerCase()))
|
||||
return status.html("Email is not correct");
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: prefix + "/service/sendmail",
|
||||
contentType: 'application/json',
|
||||
data: JSON.stringify(data),
|
||||
dataType: 'json',
|
||||
success: null
|
||||
}).done(function(r){
|
||||
if(r.error)
|
||||
{
|
||||
console.log(r.error)
|
||||
alert(r.error)
|
||||
}
|
||||
else
|
||||
{
|
||||
obs.trigger("exit")
|
||||
alert("Email sent. Thank")
|
||||
}
|
||||
}).fail(function(){
|
||||
alert("Service unavailable at the moment")
|
||||
})
|
||||
})
|
||||
$(scheme).css("visibility","visible")
|
||||
})
|
||||
riot.mount(scheme, {observable:obs})
|
||||
})
|
||||
.fail(function() {
|
||||
alert( "Cannot get the form" );
|
||||
})
|
||||
}
|
@ -161,7 +161,7 @@ function PostController:analyse(n)
|
||||
end
|
||||
self.template:set(message, "Analyse complete")
|
||||
else
|
||||
self.template:set(message, "Cannotto analyse")
|
||||
self.template:set(message, "Cannot analyse")
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
57
blog/controllers/ServiceController.lua
Normal file
57
blog/controllers/ServiceController.lua
Normal file
@ -0,0 +1,57 @@
|
||||
BaseController:subclass(
|
||||
"ServiceController",
|
||||
{
|
||||
registry = {},
|
||||
models = {"subscribers"}
|
||||
}
|
||||
)
|
||||
|
||||
function fail(msg)
|
||||
std.json()
|
||||
std.t(JSON.encode({error = msg}))
|
||||
end
|
||||
|
||||
function result(obj)
|
||||
std.json()
|
||||
std.t(JSON.encode({result = obj, error = false}))
|
||||
end
|
||||
|
||||
function ServiceController:sendmail()
|
||||
if not REQUEST.query.json then
|
||||
fail("unknown request")
|
||||
end
|
||||
local rq = (JSON.decodeString(REQUEST.query.json))
|
||||
local to = "xsang.le@gmail.com"
|
||||
local from = "From: " .. rq.email .. "\n"
|
||||
local suject = "Subject: " .. rq.subject .. "\n"
|
||||
local content = "Contact request from:" .. rq.name .. "\n Email: " .. rq.email .. "\n" .. rq.content .. "\n"
|
||||
|
||||
local cmd = 'echo "' .. utils.escape(from .. suject .. content) .. '"| sendmail ' .. to
|
||||
|
||||
--print(cmd)
|
||||
local r = os.execute(cmd)
|
||||
|
||||
if r then
|
||||
result(r)
|
||||
else
|
||||
fail("Cannot send email at the moment, the service may be down")
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function ServiceController:subscribe()
|
||||
if not REQUEST.query.json then
|
||||
fail("unknown request")
|
||||
end
|
||||
local rq = (JSON.decodeString(REQUEST.query.json))
|
||||
-- check if email is exist
|
||||
local data = self.subscribers:find({exp = {["="] = {email = rq.email}}})
|
||||
if data and #data > 0 then
|
||||
fail("You are already/previously subscribed")
|
||||
else
|
||||
-- save to database
|
||||
self.subscribers:create(rq)
|
||||
result("Ok")
|
||||
end
|
||||
return false
|
||||
end
|
8
blog/models/SubscribersModel.lua
Normal file
8
blog/models/SubscribersModel.lua
Normal file
@ -0,0 +1,8 @@
|
||||
BaseModel:subclass("SubscribersModel",{
|
||||
registry = {},
|
||||
name = "subscribers",
|
||||
fields = {
|
||||
name = "TEXT",
|
||||
email = "TEXT"
|
||||
}
|
||||
})
|
@ -23,7 +23,7 @@
|
||||
<script src="<?=HTTP_ROOT?>/rst/gscripts/riot.min.js"> </script>
|
||||
<script src="<?=HTTP_ROOT?>/rst/resources/antos_tags.js"></script>
|
||||
<script src="<?=HTTP_ROOT?>/rst/gscripts/jquery-3.2.1.min.js"> </script>
|
||||
<script src="<?=HTTP_ROOT?>/rst/main.js"></script>
|
||||
<script src="<?=HTTP_ROOT?>/assets/main.js"></script>
|
||||
<meta property="og:image" content="" />
|
||||
<?lua if render then ?>
|
||||
<meta name="twitter:card" content="summary" />
|
||||
@ -98,11 +98,11 @@
|
||||
<ul>
|
||||
<li><i class = "fa fa-home"></i><a href="<?=HTTP_ROOT?>">Home</a></li>
|
||||
<li ><i class = "fa fa-address-card"></i><a href="https://info.lxsang.me" >Porfolio</a></li>
|
||||
<li><i class = "fa fa-envelope"></i><a href="#" onclick="mailtoMe('rst')" >Contact</a></li>
|
||||
<li><i class = "fa fa-envelope"></i><a href="#" onclick="mailtoMe('<?=HTTP_ROOT?>')" >Contact</a></li>
|
||||
<?lua
|
||||
if not HEADER.mobile then
|
||||
?>
|
||||
<li> <i class = "fa fa-paper-plane"></i><a href="#" onclick="subscribe('rst')">Subscribe</a></li>
|
||||
<li> <i class = "fa fa-paper-plane"></i><a href="#" onclick="subscribe('<?=HTTP_ROOT?>')">Subscribe</a></li>
|
||||
<li > <i class = "fa fa-globe"></i><a href = "https://os.lxsang.me" target="_blank">AntOS</a></li>
|
||||
<?lua end ?>
|
||||
</ul>
|
||||
|
@ -22,9 +22,10 @@
|
||||
end
|
||||
end
|
||||
echo(table.concat(atags, ", "))
|
||||
local old_url = HTTP_ROOT.."/r:id:"..data.id
|
||||
?>
|
||||
</span>
|
||||
<div class="fb-like" data-href="<?=url?>" data-layout="button_count" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div>
|
||||
<div class="fb-like" data-href="<?=old_url?>" data-layout="button_count" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div>
|
||||
<!--div class="g-plusone" data-action="share" data-size="medium" data-href="<?=url?>"></div-->
|
||||
<a class="twitter-share-button" href='https://twitter.com/intent/tweet?url=<?=url?>&text=<?=data.title?>'></a>
|
||||
</div>
|
||||
|
@ -29,9 +29,10 @@
|
||||
end
|
||||
echo(table.concat(atags, ", "))
|
||||
local url = HTTP_ROOT.."/post/id/"..data.id
|
||||
local old_url = HTTP_ROOT.."/r:id:"..data.id
|
||||
?>
|
||||
</span>
|
||||
<div class="fb-like" data-href="<?=url?>" data-layout="button_count" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div>
|
||||
<div class="fb-like" data-href="<?=old_url?>" data-layout="button_count" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div>
|
||||
<!--div class="g-plusone" data-action="share" data-size="medium" data-href="<?=url?>"></div-->
|
||||
<a class="twitter-share-button" href='https://twitter.com/intent/tweet?url=<?=url?>&text=<?=data.title?>'></a>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user