Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Want to merge with your rebuild branch #13

Open
wants to merge 4 commits into
base: rebuild
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.idea
*.bak
*.pyc
*.pyo
Expand Down
55 changes: 0 additions & 55 deletions appengine_console.py

This file was deleted.

100 changes: 0 additions & 100 deletions filter.py

This file was deleted.

2 changes: 1 addition & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class Blog(db.Model):
blognotice=db.TextProperty(default='')
domain=db.StringProperty()
show_excerpt=db.BooleanProperty(default=True)
version=0.742
version=0.743
timedelta=db.FloatProperty(default=8.0)# hours
language=db.StringProperty(default="en-us")
sitemap_entries=db.IntegerProperty(default=30)
Expand Down
4 changes: 4 additions & 0 deletions plugins/eric_plugin/BingSiteAuth.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<users>
<user>DF917E2AEAEFAF016363FEFC87337857</user>
</users>
1 change: 1 addition & 0 deletions plugins/eric_plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from eric_plugin import *
180 changes: 180 additions & 0 deletions plugins/eric_plugin/eric_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
# -*- coding: utf-8 -*-
from micolog_plugin import *
import logging,re
from google.appengine.api import mail
from model import *
from google.appengine.api import users
from base import BaseRequestHandler,urldecode
from google.appengine.ext.webapp import template

SBODY='''New comment on post "%(title)s"
Author : %(author)s
E-mail : %(email)s
URL : %(weburl)s
Comment:
%(content)s
You can see all comments on this post here:
%(commenturl)s
'''

BBODY='''Hi~ New reference on your comment for post "%(title)s"
Author : %(author)s
URL : %(weburl)s
Comment:
%(content)s
You can see all comments on this post here:
%(commenturl)s
'''

class NotifyHandler(BaseRequestHandler):
def __init__(self):
BaseRequestHandler.__init__(self)
self.current="config"
self.sbody=OptionSet.getValue('eric_plugin_sbody',SBODY)
self.bbody=OptionSet.getValue('eric_plugin_bbody',BBODY)

def get(self):
self.template_vals.update({'self':self})
content=template.render('plugins/eric_plugin/setup.html',self.template_vals)
self.render2('views/admin/setup_base.html', dict(m_id='ericplugin_notify', content=content))
#Also you can use:
#self.render2('plugins/eric_plugin/setup2.html',{'m_id':'ericplugin_notify','self':self})

def post(self):
self.bbody=self.param('bbody')
self.sbody=self.param('sbody')
self.blog.comment_notify_mail=self.parambool('comment_notify_mail')
self.blog.put()
OptionSet.setValue('eric_plugin_sbody',self.sbody)
OptionSet.setValue('eric_plugin_bbody',self.bbody)

self.get()


class eric_plugin(Plugin):
def __init__(self):
Plugin.__init__(self,__file__)
self.author="Eric Guo"
self.authoruri="http://eric.cloud-mes.com/"
self.uri="http://eric.cloud-mes.com/"
self.description="Eric plugin for micolog"
self.name="Eric Plugin"
self.version="0.1"
self.blocklist=OptionSet.getValue("eric_plugin_blocklist",default="")
self.register_filter('head',self.head)
self.register_filter('footer',self.footer)

self.register_urlmap('eric_plugin/setup',self.setup)

self.register_urlhandler('/admin/eric_plugin/notify',NotifyHandler)
self.register_setupmenu('ericplugin_notify','Notify','/admin/eric_plugin/notify')

self.register_action('pre_comment',self.pre_comment)
self.register_action('save_comment',self.save_comment)
self.sbody=OptionSet.getValue('eric_plugin_sbody',SBODY)
self.bbody=OptionSet.getValue('eric_plugin_bbody',BBODY)

def head(self,content,blog=None,*arg1,**arg2):
return content+'''<meta property="fb:admins" content="630081856" />
<meta content="name=About Me;action-uri=/about_me;icon-uri=favicon.ico" name="msapplication-task" />'''

def footer(self,content,blog=None,*arg1,**arg2):
return content+'''<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
{"parsetags": "explicit"}
</script>
<script type="text/javascript">
gapi.plusone.go("toprss");
</script>
<div id="fb-root"></div>
<script type="text/javascript" src="https://connect.facebook.net/en_US/all.js#appId=250358181670499&amp;xfbml=1">
</script>
<script type="text/javascript">
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>'''

def setup(self,page=None,*arg1,**arg2):
if not page.is_login:
page.redirect(users.create_login_url(page.request.uri))
tempstr='''
<p>blocklist:</p>
<form action="" method="post">
<p>
<textarea name="ta_list" style="width:400px;height:300px">%s</textarea>
</p>
<input type="submit" value="submit">
</form>'''
if page.request.method=='GET':
page.render2('views/admin/base.html', dict(m_id='ericplugin_block', content=tempstr % self.blocklist))
else:
self.blocklist=page.param("ta_list")
OptionSet.setValue("eric_plugin_blocklist",self.blocklist)
page.render2('views/admin/base.html', dict(m_id='ericplugin_block', content=tempstr % self.blocklist))

def get(self,page):
return '''<h3>Eric Plugin</h3>
<p>This is a eric plugin for micolog. <br>Also a demo for how to write plugin for micolog.</p>
<h4>feature</h4>
<p><ol>
<li>Add Meta &lt;meta name="generator" content="Micolog x.x" /&gt;</li>
<li>Add footer "&lt;!--Powered by micolog x.x--&gt;"</li>
<li>Comments Filter with blocklist <a href="/e/eric_plugin/setup">Setup</a></li>
<li>Comment Notify <a href="/admin/eric_plugin/notify">Setup</a></li>
</ol></p>
'''

def pre_comment(self,comment,*arg1,**arg2):
for s in self.blocklist.splitlines():
if comment.content.find(s)>-1:
raise Exception

def save_comment(self,comment,*arg1,**arg2):
if self.blog.comment_notify_mail:
self.notify(comment)

def notify(self,comment):
try:
sbody=self.sbody.decode('utf-8')
except:
sbody=self.sbody

try:
bbody=self.bbody.decode('utf-8')
except:
bbody=self.bbody

if self.blog.comment_notify_mail and self.blog.owner and not users.is_current_user_admin() :
sbody=sbody%{'title':comment.entry.title,
'author':comment.author,
'weburl':comment.weburl,
'email':comment.email,
'content':comment.content,
'commenturl':comment.entry.fullurl+"#comment-"+str(comment.key().id())
}
mail.send_mail_to_admins(self.blog.owner.email(),'Comments:'+comment.entry.title, sbody,reply_to=comment.email)

#reply comment mail notify
refers = re.findall(r'#comment-(\d+)', comment.content)
if len(refers)!=0:
replyIDs=[int(a) for a in refers]
commentlist=comment.entry.comments()
emaillist=[c.email for c in commentlist if c.reply_notify_mail and c.key().id() in replyIDs]
emaillist = {}.fromkeys(emaillist).keys()
for refer in emaillist:
if self.blog.owner and mail.is_email_valid(refer):
emailbody = bbody%{'title':comment.entry.title,
'author':comment.author,
'weburl':comment.weburl,
'email':comment.email,
'content':comment.content,
'commenturl':comment.entry.fullurl+"#comment-"+str(comment.key().id())
}
message = mail.EmailMessage(sender = self.blog.owner.email(),subject = 'Comments:'+comment.entry.title)
message.to = refer
message.body = emailbody
message.send()
Binary file added plugins/eric_plugin/favicon.ico
Binary file not shown.
Loading