Exemple #1
0
 def post(self):
     ctype = normalize_mctr_type(self)
     if not ctype:
         return
     parid = intz(self.request.get("parentid"))
     pnm = None
     penid = self.request.get("penid")
     if penid and int(penid):
         acc = moracct.authenticated(self.request)
         if acc:
             pnm = cached_get(penid, pen.PenName)
     field = normalized_count_field(pnm, self.request.get("field"))
     refer = self.request.get("refer")
     logging.info("BumpCounter ctype: " + str(ctype) + ", parentid: " + str(parid) + ", penid: " + str(penid) + ", field: " + str(field) + ", refer: " + str(refer))
     counter = get_mctr(ctype, parid)
     if pnm:  # note any new visitors
         name = re.sub(r",+", "", pnm.name)  # strip any commas
         name = moracct.safeURIEncode(name)
         val = penid + ":" + name
         if not csv_contains(val, counter.logvis):
             counter.logvis = prepend_to_csv(val, counter.logvis)
     if refer:  # note referral if given
         refer = safe_csv_counter_key(refer)
         if refer:
             counter.refers = csv_increment(refer, counter.refers)
     note_agent(counter, self.request)
     # update the count
     cval = getattr(counter, field)
     cval = cval or 0  # counter field may not be initialized yet
     cval += 1
     setattr(counter, field, cval)
     put_mctr(counter, field)
     logging.info("BumpCounter " + counter.refp + "." + field + 
                  ": " + str(cval))
     moracct.returnJSON(self.response, [counter])
Exemple #2
0
def prepare_content(handler, gcname, content):
    # Same index retrieval used for unique group name checking
    groups = Group.gql("WHERE name_c=:1 LIMIT 1", gcname)
    if groups.count() != 1:
        handler.error(404)
        handler.response.out.write("Group identifier " + gcname + " not found")
        return
    group = groups[0];
    qres = recent_group_reviews(group)
    picurl = "img/emptyprofpic.png"
    if group.picture:
        picurl = "grppic?groupid=" + str(group.key().id())
    # facebook doesn't like "../" relative urls
    if "localhost" in handler.request.url:
        picurl = "../" + picurl
    else:
        picurl = "http://www.fgfweb.com/" + picurl
    content = re.sub('\$GROUPNAME', group.name, content)
    content = re.sub('\$GROUPDESCR', group.description, content)
    content = re.sub('\$IMGSRC', picurl, content)
    content = re.sub('\$GROUPID', str(group.key().id()), content)
    content = re.sub('\$GROUPJSON', obj2JSON(group), content)
    content = re.sub('\$REVDATA', qres2JSON(
            qres.objects, "", -1, ""), content)
    refer = handler.request.referer
    if refer:
        refer = "<img src=\"../bytheimg?grpinqref=" +\
            safeURIEncode(refer) + "\"/>\n"
    else:
        refer = "<img id=\"btwimg\" src=\"../bytheimg?grpinq=" +\
            str(group.key().id()) + "\"/>\n"
    content = re.sub('\$REFER', refer, content)
    content = re.sub('\&quot;', "\\\"", content)  #browser interp pre-parse
    return content
Exemple #3
0
 def get(self, revid):
     review = cached_get(intz(revid), Review)
     if not review:
         self.error(404)
         self.response.out.write("Review " + revid + " not found")
         return
     pen = cached_get(review.penid, PenName)
     if not pen:
         self.error(404)
         self.response.out.write("PenName " + review.penid + " not found")
         return
     # filter sensitive PenName fields
     pen.mid = 0
     pen.gsid = "0"
     pen.fbid = 0
     pen.twid = 0
     pen.ghid = 0
     pen.abusive = ""
     # write content
     logging.info("request: " + str(self.request))
     revtitle = review.title;
     if not revtitle:
         revtitle = review.name;
     rdesc = descrip(review)
     timg = "../img/" + typeImage(review.revtype)
     simg = timg[0:-6] + "Pic2.png"
     content = html
     content = write_group_content(content, review)
     content = re.sub('\$REVDESC', rdesc, content)
     content = re.sub('\$IMGSRC', simg, content)
     content = re.sub('\$PENNAME', pen.name, content)
     content = re.sub('\$REVTITLE', revtitle, content)
     content = re.sub('\$PENID', str(pen.key().id()), content)
     content = re.sub('\$PENJSON', obj2JSON(pen), content)
     content = re.sub(', "abusive": ""', '', content)  #ugly field name 2 C
     content = re.sub('\$REVJSON', obj2JSON(review), content)
     refer = self.request.referer
     if refer:
         refer = "<img src=\"../bytheimg?statinqref=" +\
             safeURIEncode(refer) + "\"/>\n"
     else:
         refer = "<img id=\"btwimg\" src=\"../bytheimg?statinq=" +\
             str(review.key().id()) + "\"/>\n"
     content = re.sub('\$REFER', refer, content)
     content = re.sub('\&quot;', "\\\"", content)  #browser interp pre-parse
     self.response.headers['Content-Type'] = "text/html; charset=UTF-8";
     self.response.out.write(content);
Exemple #4
0
def prepare_content(handler, cpen, content):
    # Same index retrieval already used by pen.py NewPenName
    pens = PenName.gql("WHERE name_c=:1 LIMIT 1", cpen)
    if pens.count() != 1:
        handler.error(404)
        handler.response.out.write("Blog identifier " + cpen + " not found")
        return
    pen = pens[0];
    # filter sensitive PenName fields
    pen.mid = 0
    pen.gsid = "0"
    pen.fbid = 0
    pen.twid = 0
    pen.ghid = 0
    pen.abusive = ""
    # retrieve reviews
    qres = fetch_blog_reviews(pen)
    # write content
    picurl = "img/emptyprofpic.png"
    if pen.profpic:
        picurl = "profpic?profileid=" + str(pen.key().id())
    # facebook doesn't like "../" relative urls
    if "localhost" in handler.request.url:
        picurl = "../" + picurl
    else:
        picurl = "http://www.fgfweb.com/" + picurl
    content = re.sub('\$PENNAME', pen.name, content)
    content = re.sub('\$PAGEDESCR', make_page_desc(handler, pen), content)
    content = re.sub('\$IMGSRC', picurl, content)
    content = re.sub('\$PENID', str(pen.key().id()), content)
    content = re.sub('\$PENJSON', obj2JSON(pen), content)
    content = re.sub(', "abusive": ""', '', content)  #bad SEO :-)
    content = re.sub('\$REVDATA', qres2JSON(
            qres.objects, "", -1, ""), content)
    refer = handler.request.referer
    if refer:
        refer = "<img src=\"../bytheimg?bloginqref=" +\
            safeURIEncode(refer) + "\"/>\n"
    else:
        refer = "<img id=\"btwimg\" src=\"../bytheimg?bloginq=" +\
            str(pen.key().id()) + "\"/>\n"
    content = re.sub('\$REFER', refer, content)
    content = re.sub('\&quot;', "\\\"", content)  #browser interp pre-parse
    return content