Esempio n. 1
0
    def post(self):
        arguments = gminifb.validate(_FbSecret, self.request)
        session_key = arguments["session_key"]
        uid = arguments["user"]

        debug = self.request.get('message')

        translated_message = ''
        message = 'Write a message in your language...'
        language = self.request.get('language', 'en')

        if self.request.get('message'):
            message = self.request.get('message')
            message = message.replace("\\\\", "\\")
            message = message.replace("\\\'", "\'")
            message = message.replace("\\\"", "\"")
            message = cgi.escape(message)
            translated_message = translate(message, language)

        message_sent = self.request.get('message_sent')
        if not message_sent or int(message_sent) < 1:
            params = {
                'message': message,
                'language_list': LANGUAGE_LIST,
                'selected_language': language,
                'translated_message': translated_message
            }
            self.response.out.write(template.render('canvas.fbml', params))
        else:
            self.response.out.write(translated_message)
Esempio n. 2
0
  def post(self):
    arguments = gminifb.validate(_FbSecret, self.request)
    session_key = arguments["session_key"]
    uid = arguments["user"]

    debug = self.request.get('message')

    translated_message = ''
    message = 'Write a message in your language...'
    language = self.request.get('language', 'en')
    
    if self.request.get('message'):
      message = self.request.get('message')
      message = message.replace("\\\\", "\\")
      message = message.replace("\\\'", "\'")
      message = message.replace("\\\"", "\"")
      message = cgi.escape(message)
      translated_message = translate(message, language)
      
    message_sent = self.request.get('message_sent')  
    if not message_sent or int(message_sent) < 1:
      params = {
        'message' : message,
        'language_list': LANGUAGE_LIST,
        'selected_language' : language,
        'translated_message' : translated_message
      }
      self.response.out.write(template.render('canvas.fbml', params))
    else:
      self.response.out.write(translated_message)
Esempio n. 3
0
	def callback_help(self, req):
		signed = gminifb.validate(_FbSecret, self.request)

		added = signed.get('added',"0") == "1"	

		output = _genHeader("help", added)

		output += "<div class=content>"

		output += """
		<h1>Help Page</h1>
	<p>
	<b>[1]</b> Check out the <a href="http://keepnix.com/articles/hellominifb.html">Hello MiniFB Tutorial</a>
	<p>
	<b>[2]</b> Check out the <a href="http://www.facebook.com/apps/application.php?api_key=%s">Application Page / Message Boards</a> for Hello MiniFB.py
	<p>
	<b>[3]</b> If you found the %s app / tutorial helpful please <a href="http://www.facebook.com/inbox/?compose&id=716361400">let me know</a>.  I'd be happy to develop this tutorial further if it is helpful.

		""" % (_FbApiKey,_app_name)

		
		
		
		output += "</div>"
		return output
Esempio n. 4
0
	def callback(self, req):
		"""FBML Main Canvas page called when _canvas_url is viewed"""

		#signed = _getSignedValues(req.params)
		signed = gminifb.validate(_FbSecret, self.request)

		added = signed.get('added',"0") == "1"	

		#	redir = "http://www.facebook.com/add.php?api_key=%s&next=%%3fret%%3d%s" % (_FbApiKey, _canvas_url)
		#	return """<fb:redirect url="%s" />""" % redir

		output = ""
		output += _genHeader(page = "home", added = added)
		
		# Delete this line to remove the grey box messaging from your app
		output += """<P><div class="content" style="background: #dddddd; padding: 10px 10px 10px 10px;">This is an installed version of the tutorial code provided by <a href="http://apps.facebook.com/hellominifb">Hello MiniFB.py App</font></a> (view <a href="http://keepnix.com/articles/hellominifb.html"><font size=+1><b>Tutorial</b></font></a> or <a href="http://keepnix.com/articles/hello.py.txt"><font size=+1><b>Source Code</b></font></a>).  If you are not the developer who is working through the tutorial please visit the original <a href="http://apps.facebook.com/hellominifb"><font size=+1><b>Original Hello MiniFB.py App</b></font></a> for more info.</div><p><div class=content><h1>Welcome to %s</h1><p>This is a simple "Hello World" application written in Python (Apache2/mod_python) using minifb.py.  It was written to help provide a starting point for people to write their own Facebook applications using minifb/python and therefore contains code to demonstrate most of the APIs you will need.  I'm no expert but hopefully this code/tutorial will help you avoid some of the confusion I initially had.  <i>Note:</i> I did not write <a href="http://code.google.com/p/minifb/">minifb.py</a> nor am I affiliated with its authors.</p><p>All the <a href="http://keepnix.com/articles/hellominifb_code.html"><font size=+1><b>source code</b></font></a> for this actual application is available as well as a <a href="http://keepnix.com/articles/hellominifb.html"><font size=+1><b>tutorial</b></font></a>to help you get it setup. </p><p> Probably the best way to get started is to explore the features of this application (it is pretty basic) so that you are familiar with what you'll be seeing in the tutorial and in the code.  While viewing most of the app doesn't require you to install it, you may want to do so anyhow to see how it works.  Once you're familiar with the app you can follow the <a href="http://keepnix.com/articles/hellominifb.html"><b>tutorial</b></a> and use the code to create your own app. </p><p>Hello MiniFB.py is designed for folks who like to hit the ground running... you're basically spending a couple minutes copying Hello FiniFB.py into your own account and then spending the rest of your time adding your own functionality and you're done. </p>""" % _app_name

		# this fb:comments tag can be used to attach a message board to any "object" in
		# you application.  If you had icons or images you were displaying you can simply
		# have a message board attached to each by using your identifier for your icon
		# as the first parameter to this function, i.e. the xid


		output += "<p>"

		output += "<i>(you have to add this app before you will be able to write messages here)</i>"
		
		output += _genFBComments("home", "%s Testimonials/Comments" % _app_name, added)
		output += "</div>"
		return output
Esempio n. 5
0
    def callback(self, req):
        """FBML Main Canvas page called when _canvas_url is viewed"""

        #signed = _getSignedValues(req.params)
        signed = gminifb.validate(_FbSecret, self.request)

        added = signed.get('added', "0") == "1"

        #	redir = "http://www.facebook.com/add.php?api_key=%s&next=%%3fret%%3d%s" % (_FbApiKey, _canvas_url)
        #	return """<fb:redirect url="%s" />""" % redir

        output = ""
        output += _genHeader(page="home", added=added)

        # Delete this line to remove the grey box messaging from your app
        output += """<P><div class="content" style="background: #dddddd; padding: 10px 10px 10px 10px;">This is an installed version of the tutorial code provided by <a href="http://apps.facebook.com/hellominifb">Hello MiniFB.py App</font></a> (view <a href="http://keepnix.com/articles/hellominifb.html"><font size=+1><b>Tutorial</b></font></a> or <a href="http://keepnix.com/articles/hello.py.txt"><font size=+1><b>Source Code</b></font></a>).  If you are not the developer who is working through the tutorial please visit the original <a href="http://apps.facebook.com/hellominifb"><font size=+1><b>Original Hello MiniFB.py App</b></font></a> for more info.</div><p><div class=content><h1>Welcome to %s</h1><p>This is a simple "Hello World" application written in Python (Apache2/mod_python) using minifb.py.  It was written to help provide a starting point for people to write their own Facebook applications using minifb/python and therefore contains code to demonstrate most of the APIs you will need.  I'm no expert but hopefully this code/tutorial will help you avoid some of the confusion I initially had.  <i>Note:</i> I did not write <a href="http://code.google.com/p/minifb/">minifb.py</a> nor am I affiliated with its authors.</p><p>All the <a href="http://keepnix.com/articles/hellominifb_code.html"><font size=+1><b>source code</b></font></a> for this actual application is available as well as a <a href="http://keepnix.com/articles/hellominifb.html"><font size=+1><b>tutorial</b></font></a>to help you get it setup. </p><p> Probably the best way to get started is to explore the features of this application (it is pretty basic) so that you are familiar with what you'll be seeing in the tutorial and in the code.  While viewing most of the app doesn't require you to install it, you may want to do so anyhow to see how it works.  Once you're familiar with the app you can follow the <a href="http://keepnix.com/articles/hellominifb.html"><b>tutorial</b></a> and use the code to create your own app. </p><p>Hello MiniFB.py is designed for folks who like to hit the ground running... you're basically spending a couple minutes copying Hello FiniFB.py into your own account and then spending the rest of your time adding your own functionality and you're done. </p>""" % _app_name

        # this fb:comments tag can be used to attach a message board to any "object" in
        # you application.  If you had icons or images you were displaying you can simply
        # have a message board attached to each by using your identifier for your icon
        # as the first parameter to this function, i.e. the xid

        output += "<p>"

        output += "<i>(you have to add this app before you will be able to write messages here)</i>"

        output += _genFBComments("home",
                                 "%s Testimonials/Comments" % _app_name, added)
        output += "</div>"
        return output
Esempio n. 6
0
    def callback_null(self, req):
        """Called when your return from the multi-friend selector when the user clicks on skip this step """

        #Just redirect back to canvas page
        #
        #return """<fb:redirect url="%s" />""" % _canvas_url

        signed = gminifb.validate(_FbSecret, self.request)

        added = signed.get('added', "0") == "1"

        output = _genHeader("skipstep", added)
        output += "<div class=content>"
        output += """<h1>Hello MiniFB: Invite Friends - Skip this step</h1><p>In my apps I just redirect this page to the main canvas page using a &lt;fb:redirect url="%s" /&gt; (see "def callbacknull" in the code), but in this tutorial it is included so that you can more easily see where "skip this step" ends up.<p><a href="%s">Back to canvas page</a>""" % (
            _canvas_url, _canvas_url)
        output += "</div>"
        return output
Esempio n. 7
0
    def callback_null(self, req):
        """Called when your return from the multi-friend selector when the user clicks on skip this step """

        #Just redirect back to canvas page
        #
        #return """<fb:redirect url="%s" />""" % _canvas_url

        signed = gminifb.validate(_FbSecret, self.request)

        added = signed.get('added', "0") == "1"

        output = _genHeader("skipstep", added)
        output += "<div class=content>"
        output += """<h1>Hello MiniFB: Invite Friends - Skip this step</h1><p>In my apps I just redirect this page to the main canvas page using a &lt;fb:redirect url="%s" /&gt; (see "def callbacknull" in the code), but in this tutorial it is included so that you can more easily see where "skip this step" ends up.<p><a href="%s">Back to canvas page</a>""" % (
            _canvas_url, _canvas_url)
        output += "</div>"
        return output
Esempio n. 8
0
	def callback_invitefriends(self, req):
		signed = gminifb.validate(_FbSecret, self.request)

		added = signed.get('added',"0") == "1"	

		if not added:
			redir = "http://www.facebook.com/add.php?api_key=%s&next=%%3fret%%3d%s" % (_FbApiKey, "%s/invitefriends")
			return """<fb:redirect url="%s" />""" % redir		

		excludeIds = _getAppFriends(signed['session_key'])

		output = _genHeader("invitefriends", added = True)

		output += """<fb:request-form content='%s <fb:req-choice url="%s" label="%s" />' image=hello type="%s">""" % ("You have been invited to check out the %s application" % _app_name, _canvas_url, "View Application", "invitation")
		output += """<fb:multi-friend-selector exclude_ids="%s" max=20 actiontext="%s" />""" % (",".join(["%s" % x for x in excludeIds]),"Tell your friends who haven't heard about %s yet." % _app_name)
		output += "</fb:request-form>"	

		return output
Esempio n. 9
0
    def callback_viewusers(self, req, page="0"):
        #signed = _getSignedValues(req.params)
        signed = gminifb.validate(_FbSecret, self.request)

        added = signed.get('added', "0") == "1"

        userdata = _readDatabase()
        userdata.reverse()

        numusers = len(userdata)
        ppage = 50
        if numusers < int(page) * ppage: page = "0"
        start = ppage * int(page)
        displayusers = userdata[start:start + ppage]
        next = False
        if numusers > (int(page) + 1) * ppage: next = True
        previous = False
        if int(page) > 0: previous = True

        output = _genHeader("users", added)

        output += "<div class=content>"
        output += "<h1>Users who have ever installed Hello MiniFB</h1>"

        output += "<table>"
        for ix, (uid, t) in enumerate(displayusers):
            if ix == 0: output += "<tr>"
            elif ix % 5 == 0: output += "</tr><tr>"
            output += """<td><fb:profile-pic size=thumb uid="%s" /><br><fb:name useyou="false" ifcantsee="(private)" uid="%s" /><br><fb:time t="%s" /></td>""" % (
                uid, uid, t)
            if ix == len(displayusers) - 1: output += "</tr>"
        output += "</table>"

        output += "<p>"
        if previous:
            output += """[<a href="viewusers?page=%s">%s</a>]""" % (
                (int(page) - 1), "Previous")
        if next:
            output += """[<a href="viewusers?page=%s">%s</a>]""" % (
                (int(page) + 1), "Next")

        output += "</div>"

        return output
Esempio n. 10
0
    def callback_viewusers(self, req, page="0"):
        #signed = _getSignedValues(req.params)
        signed = gminifb.validate(_FbSecret, self.request)

        added = signed.get('added', "0") == "1"

        userdata = _readDatabase()
        userdata.reverse()

        numusers = len(userdata)
        ppage = 50
        if numusers < int(page) * ppage: page = "0"
        start = ppage * int(page)
        displayusers = userdata[start:start + ppage]
        next = False
        if numusers > (int(page) + 1) * ppage: next = True
        previous = False
        if int(page) > 0: previous = True

        output = _genHeader("users", added)

        output += "<div class=content>"
        output += "<h1>Users who have ever installed Hello MiniFB</h1>"

        output += "<table>"
        for ix, (uid, t) in enumerate(displayusers):
            if ix == 0: output += "<tr>"
            elif ix % 5 == 0: output += "</tr><tr>"
            output += """<td><fb:profile-pic size=thumb uid="%s" /><br><fb:name useyou="false" ifcantsee="(private)" uid="%s" /><br><fb:time t="%s" /></td>""" % (
                uid, uid, t)
            if ix == len(displayusers) - 1: output += "</tr>"
        output += "</table>"

        output += "<p>"
        if previous:
            output += """[<a href="viewusers?page=%s">%s</a>]""" % (
                (int(page) - 1), "Previous")
        if next:
            output += """[<a href="viewusers?page=%s">%s</a>]""" % (
                (int(page) + 1), "Next")

        output += "</div>"

        return output
Esempio n. 11
0
    def get(self):

        arguments = gminifb.validate(_FbSecret, self.request)

        #    usersInfo = gminifb.call("facebook.users.getInfo",
        #              _FbApiKey, _FbSecret, session_key=arguments["session_key"],
        #              call_id=True, fields="name,pic_square",
        #              uids=arguments["user"]) # uids can be comma separated list

        #    name = usersInfo[0]["name"]
        #    photo = usersInfo[0]["pic_square"]
        #    else:
        #        session_key =
        #        uid = arguments["user"]

        self.response.headers["Content-Type"] = "text/plain"
        self.response.out.write("Hello, webapp World!\n")
        self.response.out.write("REQUEST:\n")
        self.response.out.write(self.request)
        self.response.out.write("\nAND arguments:\n")
        self.response.out.write(arguments)
Esempio n. 12
0
    def callback_dumpvars(self, req):
        signed = gminifb.validate(_FbSecret, self.request)

        added = signed.get('added', "0") == "1"

        output = _genHeader("dumpvars", added)
        output += "<div class=content>"
        output += "<h1>A dump of all the variables</h1>"

        if added: output += "<i>(You currently have this app added)</i>"
        else: output += "<i>(You currently do NOT have this app added)</i>"
        output += "<p>"
        output += """This page is designed to get your oriented in terms of which values are being
		passed to your application and how minifb plays the role of validating the signed values"""
        output += "<p>"
        output += _genDumpHashHtml(dict(req.params), "Cgi Variables")
        output += "<p>"
        output += _genDumpHashHtml(signed, "Signed Variables")
        output += "</div>"

        return output
Esempio n. 13
0
	def callback_dumpvars(self, req):
		signed = gminifb.validate(_FbSecret, self.request)

		added = signed.get('added',"0") == "1"	

		output = _genHeader("dumpvars",added)
		output += "<div class=content>"
		output += "<h1>A dump of all the variables</h1>"

		if added: output += "<i>(You currently have this app added)</i>"
		else: output += "<i>(You currently do NOT have this app added)</i>"
		output += "<p>"
		output += """This page is designed to get your oriented in terms of which values are being
		passed to your application and how minifb plays the role of validating the signed values"""
		output += "<p>"
		output += _genDumpHashHtml(dict(req.params), "Cgi Variables")
		output += "<p>"
		output += _genDumpHashHtml(signed, "Signed Variables")
		output += "</div>"

		return output
Esempio n. 14
0
    def callback_help(self, req):
        signed = gminifb.validate(_FbSecret, self.request)

        added = signed.get('added', "0") == "1"

        output = _genHeader("help", added)

        output += "<div class=content>"

        output += """
		<h1>Help Page</h1>
	<p>
	<b>[1]</b> Check out the <a href="http://keepnix.com/articles/hellominifb.html">Hello MiniFB Tutorial</a>
	<p>
	<b>[2]</b> Check out the <a href="http://www.facebook.com/apps/application.php?api_key=%s">Application Page / Message Boards</a> for Hello MiniFB.py
	<p>
	<b>[3]</b> If you found the %s app / tutorial helpful please <a href="http://www.facebook.com/inbox/?compose&id=716361400">let me know</a>.  I'd be happy to develop this tutorial further if it is helpful.

		""" % (_FbApiKey, _app_name)

        output += "</div>"
        return output
Esempio n. 15
0
	def callback_viewapps(self, req):
		signed = gminifb.validate(_FbSecret, self.request)

		added = signed.get('added',"0") == "1"	

		output = _genHeader("dumpvars",added)

		output += "<div class=content>"

		output += "<h1>Hello MiniFB.py Based Applications</h1>"
		output += "<p>"

		output += "If this tutorial / the Hello MiniFB.py code helped you get your application started or if your app is based on the Hello MiniFB.py code, please add it to this list and mention Hello MiniFB.py in your application somewhere (no need to blast your users with this fact, but plesae mention it somewhere).  It would be really cool to know that the time I spent putting this together helped someone."

		output += "<p>"

		output += "<i>(you have to add this app before you will be able to add your app here)</i>"

		output +=  _genFBComments("apps","Applications based on/helped by Hello MiniFB.py", added)

		output += "</div>"
		return output 
Esempio n. 16
0
    def callback_invitefriends(self, req):
        signed = gminifb.validate(_FbSecret, self.request)

        added = signed.get('added', "0") == "1"

        if not added:
            redir = "http://www.facebook.com/add.php?api_key=%s&next=%%3fret%%3d%s" % (
                _FbApiKey, "%s/invitefriends")
            return """<fb:redirect url="%s" />""" % redir

        excludeIds = _getAppFriends(signed['session_key'])

        output = _genHeader("invitefriends", added=True)

        output += """<fb:request-form content='%s <fb:req-choice url="%s" label="%s" />' image=hello type="%s">""" % (
            "You have been invited to check out the %s application" %
            _app_name, _canvas_url, "View Application", "invitation")
        output += """<fb:multi-friend-selector exclude_ids="%s" max=20 actiontext="%s" />""" % (
            ",".join(["%s" % x for x in excludeIds]),
            "Tell your friends who haven't heard about %s yet." % _app_name)
        output += "</fb:request-form>"

        return output
Esempio n. 17
0
    def callback_viewapps(self, req):
        signed = gminifb.validate(_FbSecret, self.request)

        added = signed.get('added', "0") == "1"

        output = _genHeader("dumpvars", added)

        output += "<div class=content>"

        output += "<h1>Hello MiniFB.py Based Applications</h1>"
        output += "<p>"

        output += "If this tutorial / the Hello MiniFB.py code helped you get your application started or if your app is based on the Hello MiniFB.py code, please add it to this list and mention Hello MiniFB.py in your application somewhere (no need to blast your users with this fact, but plesae mention it somewhere).  It would be really cool to know that the time I spent putting this together helped someone."

        output += "<p>"

        output += "<i>(you have to add this app before you will be able to add your app here)</i>"

        output += _genFBComments(
            "apps", "Applications based on/helped by Hello MiniFB.py", added)

        output += "</div>"
        return output
Esempio n. 18
0
    def postremove(self, req):
        signed = gminifb.validate(_FbSecret, self.request)

        return """<html><h1>Postremove called</h1>This page does not contain FBML notice that it is going to your webserver directly.  I've been using this url to perform some data store updates and then just redirecting this back to the main canvas page<a href="%s">Back to Canvas Page</a></html>""" % _canvas_url
Esempio n. 19
0
	def postremove(self, req):
		signed = gminifb.validate(_FbSecret, self.request)

		return """<html><h1>Postremove called</h1>This page does not contain FBML notice that it is going to your webserver directly.  I've been using this url to perform some data store updates and then just redirecting this back to the main canvas page<a href="%s">Back to Canvas Page</a></html>""" % _canvas_url