├── README ├── aws.py ├── cookbook.py ├── images.py ├── schema.sql ├── settings-template.py ├── static ├── css │ └── base.css ├── favicon.ico └── js │ ├── base.js │ └── jquery.js └── templates ├── activity-item.html ├── activity-stream.html ├── base.html ├── category.html ├── cookbook.html ├── edit.html ├── facepile.html ├── home-empty.html ├── home.html ├── recipe-actions.html ├── recipe-clips.html ├── recipe-context.html ├── recipe-info.html ├── recipe-list.html ├── recipe-photo-upload.html ├── recipe-photo.html └── recipe.html /README: -------------------------------------------------------------------------------- 1 | A social cookbook based on Facebook's Open Graph: 2 | https://developers.facebook.com/docs/beta/opengraph/. 3 | 4 | You can see all the recipes in your friends' cookbooks in addition to your 5 | own. When you add a recipe to your cookbook or cook a recipe, your friends 6 | will see it in an activity feed on Social Cookbook as well as Facebook 7 | via Open Graph. 8 | 9 | You can play with the site at http://socialcookbook.me/ 10 | 11 | To run your own version of the site or locally, copy settings-template.py to 12 | settings.py and edit all the options to your local setup. The Amazon S3 and 13 | CloudFront settings are required to support photo uploads for your recipes. 14 | The rest of the options should be self-explanatory. 15 | -------------------------------------------------------------------------------- /aws.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2011 Bret Taylor 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | # not use this file except in compliance with the License. You may obtain 7 | # a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | 17 | """A Tornado-based Amazon S3 client""" 18 | 19 | import base64 20 | import email.utils 21 | import hashlib 22 | import hmac 23 | import mimetypes 24 | import re 25 | import time 26 | import tornado.httpclient 27 | import urllib 28 | 29 | from tornado.options import define, options 30 | 31 | define("aws_access_key_id") 32 | define("aws_secret_access_key") 33 | 34 | 35 | class S3Client(object): 36 | def __init__(self, bucket, access_key_id=None, secret_access_key=None): 37 | self.bucket = bucket 38 | if access_key_id is not None: 39 | self.access_key_id = access_key_id 40 | self.secret_access_key = secret_access_key 41 | else: 42 | self.access_key_id = options.aws_access_key_id 43 | self.secret_access_key = options.aws_secret_access_key 44 | if isinstance(self.secret_access_key, unicode): 45 | self.secret_access_key = self.secret_access_key.encode("utf-8") 46 | self.host = "http://" + bucket + ".s3.amazonaws.com" 47 | 48 | def put_object(self, key, body, callback, headers={}): 49 | headers = self._default_headers(headers) 50 | headers["Content-Length"] = len(body) 51 | if self.access_key_id: 52 | headers["Authorization"] = self._auth_header("PUT", key, headers) 53 | http = tornado.httpclient.AsyncHTTPClient() 54 | http.fetch(self.host + "/" + key, method="PUT", headers=headers, 55 | body=body, callback=callback) 56 | 57 | def put_cdn_content(self, data, callback, file_name=None, mime_type=None): 58 | """Uploads the given data as an object optimized for CloudFront. 59 | 60 | The object name is the hash of the mime type and file contents, 61 | so every unique file is represented exactly once in the CDN. We 62 | set the HTTP headers on the object to be optimized for public CDN 63 | consumption, including an infinite expiration time (since the file 64 | is named by its contents, it is guaranteed not to change) and the 65 | appropriate public Amazon ACL. 66 | 67 | If file_name is given, we include that in the object as a 68 | Content-Disposition header, so if a user saves the file, it will 69 | have a friendlier name upon download. If given, we also infer 70 | the mime type from the file name. 71 | 72 | We return the hash we used as the object name. 73 | """ 74 | # Infer the mime type and extension if not given 75 | if not mime_type and file_name: 76 | mime_type, encoding = mimetypes.guess_type(file_name) 77 | if not mime_type: 78 | mime_type = "application/unknown" 79 | if isinstance(mime_type, unicode): 80 | mime_type = mime_type.encode("utf-8") 81 | 82 | # Cache the file forever, and inlcude the mime type in the file hash 83 | # since the Content-Type header will change the way the browser renders 84 | headers = { 85 | "Content-Type": mime_type, 86 | "Expires": email.utils.formatdate(time.time() + 86400 * 365 * 10), 87 | "Cache-Control": "public, max-age=" + str(86400 * 365 * 10), 88 | "Vary": "Accept-Encoding", 89 | "x-amz-acl": "public-read", 90 | } 91 | file_hash = hashlib.sha1(mime_type + "|" + data).hexdigest() 92 | 93 | # Retain the file name for friendly downloading 94 | if file_name: 95 | if file_name != re.sub(r"[\x00-\x1f]", " ", file_name)[:4000]: 96 | raise Exception("Unsafe file name %r" % file_name) 97 | file_name = file_name.split("/")[-1] 98 | file_name = file_name.split("\\")[-1] 99 | file_name = file_name.replace('"', '').strip() 100 | if isinstance(file_name, unicode): 101 | file_name = file_name.encode("utf-8") 102 | if file_name: 103 | headers["Content-Disposition"] = \ 104 | 'inline; filename="%s"' % file_name 105 | 106 | def on_put(response): 107 | if response.error: 108 | logging.error("Amazon S3 error: %r", response) 109 | callback(None) 110 | else: 111 | callback(file_hash) 112 | self.put_object(file_hash, data, callback=on_put, headers=headers) 113 | 114 | def _default_headers(self, custom={}): 115 | headers = { 116 | "Date": email.utils.formatdate(time.time()) 117 | } 118 | headers.update(custom) 119 | return headers 120 | 121 | def _auth_header(self, method, key, headers): 122 | special_headers = ("content-md5", "content-type", "date") 123 | signed_headers = dict((k, "") for k in special_headers) 124 | signed_headers.update( 125 | (k.lower(), v) for k, v in headers.items() 126 | if k.lower().startswith("x-amz-") or k.lower() in special_headers) 127 | sorted_header_keys = list(sorted(signed_headers.keys())) 128 | 129 | buffer = "%s\n" % method 130 | for header_key in sorted_header_keys: 131 | if header_key.startswith("x-amz-"): 132 | buffer += "%s:%s\n" % (header_key, signed_headers[header_key]) 133 | else: 134 | buffer += "%s\n" % signed_headers[header_key] 135 | buffer += "/%s" % self.bucket + "/%s" % urllib.quote_plus(key) 136 | 137 | signature = hmac.new(self.secret_access_key, buffer, hashlib.sha1) 138 | return "AWS " + self.access_key_id + ":" + \ 139 | base64.encodestring(signature.digest()).strip() 140 | -------------------------------------------------------------------------------- /cookbook.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2011 Bret Taylor 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | # not use this file except in compliance with the License. You may obtain 7 | # a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | 17 | import aws 18 | import base64 19 | import datetime 20 | import functools 21 | import images 22 | import json 23 | import logging 24 | import os.path 25 | import random 26 | import re 27 | import string 28 | import tornado.database 29 | import tornado.escape 30 | import tornado.httpclient 31 | import tornado.ioloop 32 | import tornado.web 33 | import urllib 34 | import urlparse 35 | 36 | from tornado.options import define, options 37 | 38 | define("aws_s3_bucket") 39 | define("aws_cloudfront_host") 40 | define("compiled_css_url") 41 | define("compiled_jquery_url") 42 | define("compiled_js_url") 43 | define("config") 44 | define("cookie_secret") 45 | define("comments", type=bool, default=True) 46 | define("debug", type=bool) 47 | define("facebook_app_id") 48 | define("facebook_app_secret") 49 | define("facebook_canvas_id") 50 | define("mysql_host") 51 | define("mysql_database") 52 | define("mysql_user") 53 | define("mysql_password") 54 | define("port", type=int, default=8080) 55 | define("silent", type=bool) 56 | 57 | 58 | class CookbookApplication(tornado.web.Application): 59 | def __init__(self): 60 | base_dir = os.path.dirname(__file__) 61 | settings = { 62 | "cookie_secret": options.cookie_secret, 63 | "static_path": os.path.join(base_dir, "static"), 64 | "template_path": os.path.join(base_dir, "templates"), 65 | "debug": options.debug, 66 | "ui_modules": { 67 | "RecipeList": RecipeList, 68 | "RecipeClips": RecipeClips, 69 | "ActivityStream": ActivityStream, 70 | "ActivityItem": ActivityItem, 71 | "RecipePhoto": RecipePhoto, 72 | "RecipeInfo": RecipeInfo, 73 | "RecipeActions": RecipeActions, 74 | "RecipeContext": RecipeContext, 75 | "Facepile": Facepile, 76 | }, 77 | } 78 | tornado.web.Application.__init__(self, [ 79 | tornado.web.url(r"/", HomeHandler, name="home"), 80 | tornado.web.url(r"/recipe/([^/]+)", RecipeHandler, name="recipe"), 81 | tornado.web.url(r"/category", CategoryHandler, name="category"), 82 | tornado.web.url(r"/cookbook/([^/]+)", CookbookHandler, 83 | name="cookbook"), 84 | tornado.web.url(r"/edit", EditHandler, name="edit"), 85 | tornado.web.url(r"/a/login", LoginHandler, name="login"), 86 | tornado.web.url(r"/a/clip", ClipHandler, name="clip"), 87 | tornado.web.url(r"/a/cook", CookHandler, name="cook"), 88 | tornado.web.url(r"/a/upload", UploadHandler, name="upload"), 89 | ], **settings) 90 | 91 | 92 | class BaseHandler(tornado.web.RequestHandler): 93 | @property 94 | def backend(self): 95 | return Backend.instance() 96 | 97 | def get_current_user(self): 98 | uid = self.get_secure_cookie("uid") 99 | return self.backend.get_user(uid) if uid else None 100 | 101 | def get_login_url(self, next=None): 102 | if not next: 103 | next = self.request.full_url() 104 | if not next.startswith("http://") and not next.startswith("https://"): 105 | next = urlparse.urljoin(self.request.full_url(), next) 106 | if self.get_argument("code", None): 107 | return "http://" + self.request.host + \ 108 | self.reverse_url("login") + "?" + urllib.urlencode({ 109 | "next": next, 110 | "code": self.get_argument("code"), 111 | }) 112 | redirect_uri = "http://" + self.request.host + \ 113 | self.reverse_url("login") + "?" + urllib.urlencode({"next": next}) 114 | if self.get_argument("code", None): 115 | args["code"] = self.get_argument("code") 116 | return "https://www.facebook.com/dialog/oauth?" + urllib.urlencode({ 117 | "client_id": options.facebook_app_id, 118 | "redirect_uri": redirect_uri, 119 | "scope": "offline_access,publish_actions", 120 | }) 121 | 122 | def write_json(self, obj): 123 | self.set_header("Content-Type", "application/json; charset=UTF-8") 124 | self.finish(json.dumps(obj)) 125 | 126 | def render(self, template, **kwargs): 127 | kwargs["error_message"] = self.get_secure_cookie("message") 128 | if kwargs["error_message"]: 129 | kwargs["error_message"] = base64.b64decode(kwargs["error_message"]) 130 | self.clear_cookie("message") 131 | tornado.web.RequestHandler.render(self, template, **kwargs) 132 | 133 | def render_string(self, template, **kwargs): 134 | args = { 135 | "markdown": self.markdown, 136 | "options": options, 137 | "user_possessive": self.user_possessive, 138 | "user_link": self.user_link, 139 | "friend_list": self.friend_list, 140 | } 141 | args.update(kwargs) 142 | return tornado.web.RequestHandler.render_string(self, template, **args) 143 | 144 | def set_error_message(self, message): 145 | self.set_secure_cookie("message", base64.b64encode(message)) 146 | 147 | def user_possessive(self, user): 148 | if user["gender"] == "male": 149 | return "his" 150 | else: 151 | return "her" 152 | 153 | def friend_list(self, friends, size=3): 154 | if len(friends) == 1: 155 | return self.user_link(friends[0], True, True) 156 | elif len(friends) > size + 1: 157 | return ", ".join(self.user_link(f, True, i == 0) for i, f in 158 | enumerate(friends[:size])) + \ 159 | " and " + str(len(friends) - size) + " other friends" 160 | else: 161 | return ", ".join(self.user_link(f, True, i == 0) for i, f in 162 | enumerate(friends[:len(friends) - 1])) + \ 163 | " and " + \ 164 | self.user_link(friends[len(friends) - 1], True, False) 165 | 166 | def user_link(self, user, you=False, capitalize=True): 167 | if you and self.current_user and self.current_user["id"] == user["id"]: 168 | name = "You" if capitalize else "you" 169 | else: 170 | name = user["name"] 171 | return '' + \ 172 | tornado.escape.xhtml_escape(name) + '' 173 | 174 | def markdown(self, text): 175 | text = re.sub(r"\n\s*\n", "
",
176 | tornado.escape.xhtml_escape(text.strip()))
177 | text = re.sub(r"\n", "
", text)
178 | return '
' + text + '
' 179 | 180 | 181 | class HomeHandler(BaseHandler): 182 | @tornado.web.authenticated 183 | def get(self): 184 | all_recipes = self.backend.get_recently_clipped_recipes( 185 | [self.current_user["id"]]) 186 | existing_ids = set(r["id"] for r in all_recipes) 187 | friends_recent = self.backend.get_recently_clipped_recipes( 188 | self.backend.get_friend_ids(self.current_user), 10, existing_ids) 189 | user_recipe_ids = set(r["id"] for r in all_recipes) 190 | friends_recent = [r for r in friends_recent 191 | if r["id"] not in user_recipe_ids] 192 | user_recent = all_recipes[:2] if friends_recent else all_recipes[:4] 193 | if not all_recipes: 194 | friends_recent = friends_recent[:6] 195 | elif len(all_recipes) < 4: 196 | friends_recent = friends_recent[:4] 197 | else: 198 | friends_recent = friends_recent[:2] 199 | if not all_recipes and len(friends_recent) < 2: 200 | self.render("home-empty.html") 201 | return 202 | self.render("home.html", all_recipes=all_recipes, 203 | user_recent=user_recent, friends_recent=friends_recent) 204 | 205 | 206 | class UploadHandler(BaseHandler): 207 | @tornado.web.authenticated 208 | @tornado.web.asynchronous 209 | def post(self): 210 | recipe = self.backend.get_recipe(int(self.get_argument("recipe"))) 211 | if not recipe: 212 | raise tornado.web.HTTPError(404) 213 | if recipe["photo"] and recipe["author_id"] != self.current_user["id"]: 214 | raise tornado.web.HTTPError(403) 215 | full = images.resize_image( 216 | self.request.files.values()[0][0]["body"], max_width=800, 217 | max_height=800, quality=85) 218 | thumb = images.resize_image( 219 | self.request.files.values()[0][0]["body"], max_width=300, 220 | max_height=800, quality=85) 221 | resized = {"full": full, "thumb": thumb} 222 | if full["width"] < 300 or full["height"] < 300: 223 | self.set_error_message( 224 | "Recipe images must be at least 300 pixels wide and " 225 | "300 pixels tall.") 226 | self.redirect(self.reverse_url("recipe", recipe["slug"])) 227 | return 228 | thumb["uploaded"] = False 229 | full["uploaded"] = False 230 | self.backend.s3.put_cdn_content( 231 | data=thumb["data"], mime_type=thumb["mime_type"], 232 | callback=functools.partial( 233 | self.on_upload, "thumb", recipe, resized)) 234 | self.backend.s3.put_cdn_content( 235 | data=full["data"], mime_type=full["mime_type"], 236 | callback=functools.partial( 237 | self.on_upload, "full", recipe, resized)) 238 | 239 | def on_upload(self, image_size, recipe, images, hash): 240 | if not hash: 241 | raise tornado.web.HTTPError(500) 242 | images[image_size]["uploaded"] = True 243 | images[image_size]["hash"] = hash 244 | if images["thumb"]["uploaded"] and images["full"]["uploaded"]: 245 | self.backend.save_photos(recipe, images["full"], images["thumb"]) 246 | self.redirect(self.reverse_url("recipe", recipe["slug"])) 247 | url = "http://" + self.request.host + \ 248 | self.reverse_url("recipe", recipe["slug"]) 249 | # Force Facebook to recrawl the object to get the new image 250 | ping_url = "http://developers.facebook.com/tools/lint/?" + \ 251 | urllib.urlencode({"url": url}) 252 | client = tornado.httpclient.AsyncHTTPClient() 253 | client.fetch(ping_url, self.on_ping) 254 | 255 | def on_ping(self, response): 256 | if response.error: 257 | logging.error("Error refreshing Open Graph page: %r", 258 | response.error) 259 | 260 | 261 | class RecipeHandler(BaseHandler): 262 | @tornado.web.asynchronous 263 | def get(self, slug): 264 | if "facebookexternalhit" not in self.request.headers["User-Agent"] \ 265 | and not self.current_user: 266 | self.redirect(self.get_login_url()) 267 | return 268 | recipe = self.backend.get_recipe_by_slug(slug) 269 | if not recipe: 270 | raise tornado.web.HTTPError(404) 271 | self.render("recipe.html", recipe=recipe) 272 | 273 | 274 | class CookbookHandler(BaseHandler): 275 | def get(self, id): 276 | user = self.backend.get_user(id) 277 | if not user: 278 | raise tornado.web.HTTPError(404) 279 | recipes = self.backend.get_recently_clipped_recipes([user["id"]]) 280 | self.render("cookbook.html", user=user, recipes=recipes) 281 | 282 | 283 | class CategoryHandler(BaseHandler): 284 | @tornado.web.authenticated 285 | def get(self): 286 | category = self.get_argument("name") 287 | recipes = self.backend.get_recently_clipped_recipes( 288 | [self.current_user.id], category=category) 289 | recipes.sort(key=lambda r: r["title"].lower()) 290 | friend_recipes = self.backend.get_recently_clipped_recipes( 291 | self.backend.get_friend_ids(self.current_user), category=category, 292 | exclude_ids=[r["id"] for r in recipes])[:4] 293 | self.render("category.html", category=category, recipes=recipes, 294 | friend_recipes=friend_recipes) 295 | 296 | 297 | class EditHandler(BaseHandler): 298 | @tornado.web.authenticated 299 | def get(self): 300 | id = self.get_argument("id", None) 301 | recipe = self.backend.get_recipe(int(id)) if id else None 302 | if recipe and recipe["author_id"] != self.current_user["id"]: 303 | raise tornado.web.HTTPError(403) 304 | categories = self.backend.get_categories(self.current_user) 305 | self.render("edit.html", recipe=recipe, categories=categories) 306 | 307 | @tornado.web.authenticated 308 | def post(self): 309 | id = self.get_argument("id", None) 310 | recipe = self.backend.get_recipe(int(id)) if id else None 311 | if recipe: 312 | created = False 313 | if recipe["author_id"] != self.current_user["id"]: 314 | raise tornado.web.HTTPError(403) 315 | self.backend.update_recipe( 316 | id=recipe["id"], 317 | title=self.get_argument("title"), 318 | category=self.get_argument("category"), 319 | description=self.get_argument("description"), 320 | instructions=self.get_argument("instructions", ""), 321 | ingredients=self.get_argument("ingredients", ""), 322 | ) 323 | else: 324 | created = True 325 | id = self.backend.create_recipe( 326 | author=self.current_user, 327 | title=self.get_argument("title"), 328 | category=self.get_argument("category"), 329 | description=self.get_argument("description"), 330 | instructions=self.get_argument("instructions", ""), 331 | ingredients=self.get_argument("ingredients", ""), 332 | ) 333 | self.backend.clip_recipe(user=self.current_user, recipe_id=id) 334 | recipe = self.backend.get_recipe(int(id)) 335 | self.redirect(self.reverse_url("recipe", recipe["slug"])) 336 | if not options.silent and created: 337 | url = "http://" + self.request.host + \ 338 | self.reverse_url("recipe", recipe["slug"]) 339 | self.backend.save_open_graph_action( 340 | type="clip", recipe=url, user=self.current_user, 341 | callback=self.on_open_graph) 342 | 343 | def on_open_graph(self, response): 344 | if response.error: 345 | logging.error("Error publishing clip to open graph: %r", 346 | response.error) 347 | 348 | 349 | class ClipHandler(BaseHandler): 350 | @tornado.web.authenticated 351 | def post(self): 352 | recipe_id = int(self.get_argument("recipe")) 353 | recipe = self.backend.get_recipe(recipe_id) 354 | if not recipe: 355 | raise tornado.web.HTTPError(404) 356 | if not options.silent: 357 | self.backend.clip_recipe(self.current_user, recipe["id"]) 358 | self.write_json({ 359 | "html": self.ui.modules.ActivityItem( 360 | self.current_user, recipe, datetime.datetime.utcnow(), 361 | "clipped"), 362 | }) 363 | url = "http://" + self.request.host + \ 364 | self.reverse_url("recipe", recipe["slug"]) 365 | if not options.silent: 366 | self.backend.save_open_graph_action( 367 | type="clip", recipe=url, user=self.current_user, 368 | callback=self.on_open_graph) 369 | 370 | def on_open_graph(self, response): 371 | if response.error: 372 | logging.error("Error publishing clip to open graph: %r", 373 | response.error) 374 | 375 | 376 | class CookHandler(BaseHandler): 377 | @tornado.web.authenticated 378 | def post(self): 379 | recipe_id = int(self.get_argument("recipe")) 380 | recipe = self.backend.get_recipe(recipe_id) 381 | if not recipe: 382 | raise tornado.web.HTTPError(404) 383 | if not options.silent: 384 | self.backend.cook_recipe(self.current_user, recipe["id"]) 385 | self.write_json({ 386 | "html": self.ui.modules.ActivityItem( 387 | self.current_user, recipe, datetime.datetime.utcnow(), 388 | "cooked"), 389 | }) 390 | url = "http://" + self.request.host + \ 391 | self.reverse_url("recipe", recipe["slug"]) 392 | if not options.silent: 393 | self.backend.save_open_graph_action( 394 | type="cook", recipe=url, user=self.current_user, 395 | callback=self.on_open_graph) 396 | 397 | def on_open_graph(self, response): 398 | if response.error: 399 | logging.error("Error publishing cook to open graph: %r (%r)", 400 | response.error, response.body) 401 | 402 | 403 | class LoginHandler(BaseHandler): 404 | @tornado.web.asynchronous 405 | def get(self): 406 | next = self.get_argument("next", None) 407 | code = self.get_argument("code", None) 408 | if not next: 409 | self.redirect(self.get_login_url(self.reverse_url("home"))) 410 | return 411 | if not next.startswith("https://" + self.request.host + "/") and \ 412 | not next.startswith("http://" + self.request.host + "/"): 413 | raise tornado.web.HTTPError( 414 | 404, "Login redirect (%s) spans hosts", next) 415 | if self.get_argument("error", None): 416 | logging.warning("Facebook login error: %r", self.request.arguments) 417 | self.set_error_message( 418 | "An error occured with Facebook. Please try again later.") 419 | self.redirect(self.reverse_url("home")) 420 | return 421 | if not code: 422 | self.redirect(self.get_login_url(next)) 423 | return 424 | redirect_uri = self.request.protocol + "://" + self.request.host + \ 425 | self.request.path + "?" + urllib.urlencode({"next": next}) 426 | url = "https://graph.facebook.com/oauth/access_token?" + \ 427 | urllib.urlencode({ 428 | "client_id": options.facebook_app_id, 429 | "client_secret": options.facebook_app_secret, 430 | "redirect_uri": redirect_uri, 431 | "code": code, 432 | }) 433 | client = tornado.httpclient.AsyncHTTPClient() 434 | client.fetch(url, self.on_access_token) 435 | 436 | def on_access_token(self, response): 437 | if response.error: 438 | self.set_error_message( 439 | "An error occured with Facebook. Please try again later.") 440 | self.redirect(self.reverse_url("home")) 441 | return 442 | access_token = urlparse.parse_qs(response.body)["access_token"][-1] 443 | url = "https://graph.facebook.com/me?" + urllib.urlencode({ 444 | "access_token": access_token, 445 | }) 446 | client = tornado.httpclient.AsyncHTTPClient() 447 | client.fetch(url, functools.partial(self.on_profile, access_token)) 448 | 449 | def on_profile(self, access_token, response): 450 | if response.error: 451 | self.set_error_message( 452 | "An error occured with Facebook. Please try again later.") 453 | self.redirect(self.reverse_url("home")) 454 | return 455 | profile = json.loads(response.body) 456 | url = "https://graph.facebook.com/me/friends?" + urllib.urlencode({ 457 | "access_token": access_token, 458 | }) 459 | client = tornado.httpclient.AsyncHTTPClient() 460 | client.fetch(url, functools.partial( 461 | self.on_friends, access_token, profile)) 462 | 463 | def on_friends(self, access_token, profile, response): 464 | if response.error: 465 | self.set_error_message( 466 | "An error occured with Facebook. Please try again later.") 467 | self.redirect(self.reverse_url("home")) 468 | return 469 | friend_ids = [f["id"] for f in json.loads(response.body)["data"]] 470 | self.backend.create_user(profile, access_token) 471 | self.backend.update_friends(profile, friend_ids) 472 | self.set_secure_cookie("uid", profile["id"]) 473 | self.redirect(self.get_argument("next", self.reverse_url("home"))) 474 | 475 | 476 | class Backend(object): 477 | def __init__(self): 478 | self.db = tornado.database.Connection( 479 | host=options.mysql_host, database=options.mysql_database, 480 | user=options.mysql_user, password=options.mysql_password) 481 | self.s3 = aws.S3Client(options.aws_s3_bucket) 482 | 483 | @classmethod 484 | def instance(cls): 485 | if not hasattr(cls, "_instance"): 486 | cls._instance = cls() 487 | return cls._instance 488 | 489 | def save_open_graph_action(self, user, type, callback, **properties): 490 | url = "https://graph.facebook.com/me/" + options.facebook_canvas_id + \ 491 | ":" + type 492 | properties.update({ 493 | "access_token": user["access_token"], 494 | }) 495 | client = tornado.httpclient.AsyncHTTPClient() 496 | client.fetch(url, method="POST", body=urllib.urlencode(properties), 497 | callback=callback) 498 | 499 | def get_user(self, id): 500 | return self.get_users([id]).get(id) 501 | 502 | def get_users(self, ids): 503 | if not ids: 504 | return {} 505 | users = self.db.query( 506 | "SELECT * FROM cookbook_users WHERE id IN (" + 507 | ",".join(["%s"] * len(ids)) + ")", *ids) 508 | for user in users: 509 | user["picture"] = "http://graph.facebook.com/" + user["id"] + \ 510 | "/picture" 511 | return dict((a["id"], a) for a in users) 512 | 513 | def create_user(self, profile, access_token): 514 | profile.setdefault("gender", "male") 515 | self.db.execute( 516 | "INSERT IGNORE INTO cookbook_users (id,name,link,gender," 517 | "access_token,created) VALUES (%s,%s,%s,%s,%s,UTC_TIMESTAMP) " 518 | "ON DUPLICATE KEY UPDATE name=%s, link=%s, gender=%s, " 519 | "access_token = %s", 520 | profile["id"], profile["name"], profile["link"], profile["gender"], 521 | access_token, profile["name"], profile["link"], profile["gender"], 522 | access_token) 523 | 524 | def update_friends(self, user, friend_ids): 525 | if not friend_ids: 526 | return 527 | friend_ids = [r["id"] for r in self.db.query( 528 | "SELECT * FROM cookbook_users WHERE id IN (" + 529 | ",".join(["%s"] * len(friend_ids)) + ")", *friend_ids)] 530 | if not friend_ids: 531 | return 532 | rows = [(user["id"], fid) for fid in friend_ids] 533 | rows += [(fid, user["id"]) for fid in friend_ids] 534 | self.db.executemany( 535 | "INSERT IGNORE INTO cookbook_friends (user_id, friend_id) " 536 | "VALUES (%s,%s)", rows) 537 | 538 | def get_friend_ids(self, user): 539 | return [r["friend_id"] for r in self.db.query( 540 | "SELECT friend_id FROM cookbook_friends WHERE user_id = %s", 541 | user["id"])] 542 | 543 | def get_recipe(self, id): 544 | return self.get_recipes([id]).get(id) 545 | 546 | def get_recipe_by_slug(self, slug): 547 | recipe = self.db.get( 548 | "SELECT * FROM cookbook_recipes WHERE slug = %s", slug) 549 | if not recipe: 550 | return None 551 | self._fill_recipes([recipe]) 552 | return recipe 553 | 554 | def create_recipe(self, title, category, description, ingredients, 555 | instructions, author): 556 | slug_base = title.replace(" ", "-").lower() 557 | valid_letters = string.ascii_letters + string.digits + "-" 558 | slug_base = "".join(c for c in slug_base if c in valid_letters)[:90] 559 | tries = 0 560 | while True: 561 | try: 562 | slug = slug_base + "-" + str(tries) if tries > 0 else slug_base 563 | return self.db.execute( 564 | "INSERT INTO cookbook_recipes (title,category,description," 565 | "ingredients,instructions,author_id,slug,created) VALUES " 566 | "(%s,%s,%s,%s,%s,%s,%s,UTC_TIMESTAMP)", title, category, 567 | description, ingredients, instructions, author["id"], slug) 568 | except tornado.database.IntegrityError: 569 | tries += 1 570 | 571 | def update_recipe(self, id, title, category, description, ingredients, 572 | instructions): 573 | return self.db.execute( 574 | "UPDATE cookbook_recipes SET title = %s, category = %s, " 575 | "description = %s, ingredients = %s, instructions = %s " 576 | "WHERE id = %s", title, category, description, ingredients, 577 | instructions, id) 578 | 579 | def clip_recipe(self, user, recipe_id): 580 | self.db.execute( 581 | "INSERT IGNORE INTO cookbook_clipped (user_id, recipe_id) " 582 | "VALUES (%s,%s)", user["id"], recipe_id) 583 | 584 | def cook_recipe(self, user, recipe_id): 585 | self.db.execute( 586 | "INSERT IGNORE INTO cookbook_cooked (user_id, recipe_id) " 587 | "VALUES (%s,%s)", user["id"], recipe_id) 588 | 589 | def get_clipped_recipes(self, user): 590 | recipe_ids = [row["recipe_id"] for row in self.db.query( 591 | "SELECT recipe_id FROM cookbook_clipped WHERE user_id = %s", 592 | user["id"])] 593 | return self.get_recipes(recipe_ids).values() 594 | 595 | def save_photos(self, recipe, full, thumb): 596 | self.db.execute( 597 | "REPLACE INTO cookbook_photos (recipe_id,full_hash,full_width," 598 | "full_height,thumb_hash,thumb_width,thumb_height) VALUES " 599 | "(%s,%s,%s,%s,%s,%s,%s)", recipe["id"], full["hash"], 600 | full["width"], full["height"], thumb["hash"], thumb["width"], 601 | thumb["height"]) 602 | 603 | def get_recently_clipped_recipes(self, user_ids, num=None, 604 | exclude_ids=None, category=None): 605 | if not user_ids: 606 | return [] 607 | query = "SELECT DISTINCT recipe_id FROM cookbook_clipped WHERE " \ 608 | "user_id IN (" + ",".join(["%s"] * len(user_ids)) + ")" 609 | args = list(user_ids) 610 | if exclude_ids: 611 | query += " AND recipe_id NOT IN (" + \ 612 | ",".join(["%s"] * len(exclude_ids)) + ")" 613 | args += exclude_ids 614 | query += " ORDER BY created DESC" 615 | if num is not None: 616 | query += " LIMIT " + str(num) 617 | recipe_ids = [row["recipe_id"] for row in self.db.query(query, *args)] 618 | recipe_map = self.get_recipes(recipe_ids) 619 | if category: 620 | return [recipe_map[id] for id in recipe_ids 621 | if recipe_map[id]["category"] == category] 622 | else: 623 | return [recipe_map[id] for id in recipe_ids] 624 | 625 | def get_recently_cooked_recipes(self, user, num): 626 | recipe_ids = [row["recipe_id"] for row in self.db.query( 627 | "SELECT recipe_id FROM cookbook_cooked WHERE user_id = %s " 628 | "ORDER BY created DESC LIMIT " + str(num), user["id"])] 629 | recipe_map = self.get_recipes(recipe_ids) 630 | return [recipe_map[id] for id in recipe_ids] 631 | 632 | def get_friend_activity(self, user, num): 633 | friend_ids = self.get_friend_ids(user) + [user["id"]] 634 | activity = self._make_activity("cooked", self.db.query( 635 | "SELECT user_id, recipe_id, created FROM cookbook_cooked WHERE " 636 | "user_id IN (" + ",".join(["%s"] * len(friend_ids)) + ") ORDER BY " 637 | "created DESC LIMIT " + str(num), *friend_ids)) 638 | activity += self._make_activity("clipped", self.db.query( 639 | "SELECT user_id, recipe_id, created FROM cookbook_clipped WHERE " 640 | "user_id IN (" + ",".join(["%s"] * len(friend_ids)) + ") ORDER BY " 641 | "created DESC LIMIT " + str(num), *friend_ids)) 642 | activity.sort(key=lambda a: a["created"], reverse=True) 643 | activity = activity[:num] 644 | users = self.get_users(set(a["user_id"] for a in activity)) 645 | recipes = self.get_recipes(set(a["recipe_id"] for a in activity)) 646 | for item in activity: 647 | item["user"] = users[item["user_id"]] 648 | item["recipe"] = recipes[item["recipe_id"]] 649 | return activity 650 | 651 | def get_recipes(self, ids): 652 | if not ids: 653 | return {} 654 | recipes = dict((r["id"], r) for r in self.db.query( 655 | "SELECT * FROM cookbook_recipes WHERE id IN (" + 656 | ",".join(["%s"] * len(ids)) + ")", *ids)) 657 | self._fill_recipes(recipes.values()) 658 | return recipes 659 | 660 | def get_categories(self, user): 661 | friend_ids = self.get_friend_ids(user) + [user["id"]] 662 | recipe_ids = [r["recipe_id"] for r in self.db.query( 663 | "SELECT DISTINCT recipe_id FROM cookbook_clipped WHERE " 664 | "user_id IN (" + ",".join(["%s"] * len(friend_ids)) + ")", 665 | *friend_ids)] 666 | if not recipe_ids: 667 | return [] 668 | categories = [r["category"] for r in self.db.query( 669 | "SELECT DISTINCT category FROM cookbook_recipes WHERE id " 670 | "IN (" + ",".join(["%s"] * len(recipe_ids)) + ")", *recipe_ids)] 671 | categories.sort(key=lambda c: c.lower()) 672 | return categories 673 | 674 | def recipe_is_clipped(self, user, recipe): 675 | return self.db.get( 676 | "SELECT recipe_id FROM cookbook_clipped WHERE user_id = %s AND " 677 | "recipe_id = %s", user["id"], recipe["id"]) is not None 678 | 679 | def get_friends_who_clipped(self, user, recipe): 680 | all_friends = self.get_friend_ids(user) 681 | if not all_friends: 682 | return [] 683 | friend_ids = [r["user_id"] for r in self.db.query( 684 | "SELECT user_id FROM cookbook_clipped WHERE recipe_id = %s AND " 685 | "user_id IN (" + ",".join(["%s"] * len(all_friends)) + ") " 686 | "ORDER BY created DESC", recipe["id"], *all_friends)] 687 | friends = self.get_users(friend_ids) 688 | return [friends[fid] for fid in friend_ids] 689 | 690 | def get_clip_count(self, recipe): 691 | return self.db.get( 692 | "SELECT COUNT(*) AS num FROM cookbook_clipped WHERE " 693 | "recipe_id = %s", recipe["id"]).num 694 | 695 | def get_cook_count(self, recipe): 696 | return self.db.get( 697 | "SELECT COUNT(*) AS num FROM cookbook_cooked WHERE " 698 | "recipe_id = %s", recipe["id"]).num 699 | 700 | def get_recipe_photos(self, recipe_ids): 701 | if not recipe_ids: 702 | return {} 703 | photos = {} 704 | for row in self.db.query( 705 | "SELECT * FROM cookbook_photos WHERE recipe_id IN (" + 706 | ",".join(["%s"] * len(recipe_ids)) + ")", *recipe_ids): 707 | photos[row["recipe_id"]] = { 708 | "full": { 709 | "hash": row["full_hash"], 710 | "url": cdn_url(row["full_hash"]), 711 | "width": row["full_width"], 712 | "height": row["full_height"], 713 | }, 714 | "thumb": { 715 | "hash": row["thumb_hash"], 716 | "url": cdn_url(row["thumb_hash"]), 717 | "width": row["thumb_width"], 718 | "height": row["thumb_height"], 719 | }, 720 | } 721 | return photos 722 | 723 | def _fill_recipes(self, recipes): 724 | author_ids = set(r["author_id"] for r in recipes) 725 | recipe_ids = set(r["id"] for r in recipes) 726 | authors = self.get_users(author_ids) 727 | photos = self.get_recipe_photos(recipe_ids) 728 | for recipe in recipes: 729 | recipe["author"] = authors[recipe["author_id"]] 730 | recipe["photo"] = photos.get(recipe["id"]) 731 | 732 | def _make_activity(self, action, rows): 733 | for row in rows: 734 | row["action"] = action 735 | return rows 736 | 737 | 738 | class RecipeList(tornado.web.UIModule): 739 | def render(self, recipes): 740 | categories = {} 741 | for recipe in recipes: 742 | categories.setdefault(recipe["category"], []).append(recipe) 743 | for recipes in categories.itervalues(): 744 | recipes.sort(key=lambda r: r["title"].lower()) 745 | return self.render_string("recipe-list.html", categories=categories) 746 | 747 | 748 | class Facepile(tornado.web.UIModule): 749 | def render(self, friends, num=7): 750 | return self.render_string("facepile.html", friends=friends, num=num) 751 | 752 | 753 | class RecipeClips(tornado.web.UIModule): 754 | def render(self, recipes): 755 | return self.render_string("recipe-clips.html", recipes=recipes) 756 | 757 | 758 | class ActivityStream(tornado.web.UIModule): 759 | def render(self, num=10): 760 | if not self.current_user: 761 | return "" 762 | activity = self.handler.backend.get_friend_activity( 763 | self.current_user, num=num) 764 | if not activity: 765 | return "" 766 | return self.render_string("activity-stream.html", activity=activity) 767 | 768 | 769 | class ActivityItem(tornado.web.UIModule): 770 | def render(self, user, recipe, date, action): 771 | return self.render_string( 772 | "activity-item.html", user=user, recipe=recipe, date=date, 773 | action=action) 774 | 775 | 776 | class RecipePhoto(tornado.web.UIModule): 777 | def render(self, recipe, width, max_height=None, height=None, href=None): 778 | if not recipe["photo"]: 779 | if not height: 780 | height = max_height 781 | return self.render_string( 782 | "recipe-photo-upload.html", recipe=recipe, width=width, 783 | height=height) 784 | thumb = recipe["photo"]["thumb"] 785 | if max_height: 786 | ratio = width / (1.0 * thumb["width"]) 787 | visible_height = min(int(ratio * thumb["height"]), max_height) 788 | else: 789 | ratio = max(height / (1.0 * thumb["height"]), 790 | width / (1.0 * thumb["width"])) 791 | visible_height = height 792 | real_width = int(ratio * thumb["width"]) 793 | real_height = int(ratio * thumb["height"]) 794 | offset_x = (width - real_width) / 2 795 | offset_y = (visible_height - real_height) / 2 796 | return self.render_string( 797 | "recipe-photo.html", recipe=recipe, href=href, 798 | real_width=real_width, real_height=real_height, offset_x=offset_x, 799 | offset_y=offset_y, width=width, height=visible_height) 800 | 801 | 802 | class RecipeActions(tornado.web.UIModule): 803 | def render(self, recipe): 804 | clipped = self.handler.backend.recipe_is_clipped( 805 | self.current_user, recipe) 806 | return self.render_string( 807 | "recipe-actions.html", recipe=recipe, clipped=clipped) 808 | 809 | 810 | class RecipeInfo(tornado.web.UIModule): 811 | def render(self, recipe): 812 | cook_count = self.handler.backend.get_cook_count(recipe) 813 | clip_count = self.handler.backend.get_clip_count(recipe) 814 | return self.render_string( 815 | "recipe-info.html", recipe=recipe, cook_count=cook_count, 816 | clip_count=clip_count) 817 | 818 | 819 | class RecipeContext(tornado.web.UIModule): 820 | def render(self, recipe, facepile_size=5, friend_list_size=3): 821 | friends = self.handler.backend.get_friends_who_clipped( 822 | self.current_user, recipe) 823 | if not friends: 824 | return "" 825 | clipped = self.handler.backend.recipe_is_clipped( 826 | self.current_user, recipe) 827 | return self.render_string( 828 | "recipe-context.html", recipe=recipe, friends=friends, 829 | clipped=clipped, friend_list_size=friend_list_size, 830 | facepile_size=facepile_size) 831 | 832 | 833 | def cdn_url(hash): 834 | return "http://" + options.aws_cloudfront_host + "/" + hash 835 | 836 | 837 | def main(): 838 | tornado.options.parse_command_line() 839 | if options.config: 840 | tornado.options.parse_config_file(options.config) 841 | else: 842 | path = os.path.join(os.path.dirname(__file__), "settings.py") 843 | tornado.options.parse_config_file(path) 844 | CookbookApplication().listen(options.port) 845 | tornado.ioloop.IOLoop.instance().start() 846 | 847 | 848 | if __name__ == "__main__": 849 | main() 850 | -------------------------------------------------------------------------------- /images.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2011 Bret Taylor 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | # not use this file except in compliance with the License. You may obtain 7 | # a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | # License for the specific language governing permissions and limitations 15 | # under the License. 16 | 17 | """An image resizing library based on ImageMagick and ctypes""" 18 | 19 | import binascii 20 | import ctypes 21 | import ctypes.util 22 | 23 | 24 | def get_image_info(data): 25 | """Returns the width, height, and MIME type of the given image as a dict""" 26 | return _ImageMagick.instance().get_image_info(data) 27 | 28 | 29 | def resize_image(data, max_width, max_height, quality=85, crop=False, 30 | force=False): 31 | """Resizes the given image to the given specifications. 32 | 33 | We size down the image to the given maximum width and height. Unless force 34 | is True, we don't resize an image smaller than the given width and height. 35 | 36 | We use the JPEG format for any image that has to be resized. If the image 37 | does not have to be resized, we retain the original image format. 38 | 39 | If crop is True, we resize the image so that at least one of the width or 40 | height is within the given bounds, and then we crop the other dimension. 41 | 42 | We use the given JPEG quality in the cases where we use the JPEG format. 43 | We always convert to JPEG for image formats other than PNG and GIF. 44 | 45 | We return a dict with the keys "data", "mime_type", "width", and "height". 46 | """ 47 | return _ImageMagick.instance().resize_image( 48 | data=data, max_width=max_width, max_height=max_height, quality=quality, 49 | crop=crop, force=force) 50 | 51 | 52 | class ImageException(Exception): 53 | """An exception related to the ImageMagick library""" 54 | pass 55 | 56 | 57 | class _ImageMagick(object): 58 | def __init__(self): 59 | wand_path = ctypes.util.find_library("MagickWand") 60 | if not wand_path: 61 | raise Exception("Package libmagick9 or libmagick10 required") 62 | self.lib = ctypes.CDLL(wand_path) 63 | method = self.lib.MagickResizeImage 64 | method.restype = ctypes.c_int 65 | method.argtypes = (ctypes.c_void_p, ctypes.c_ulong, ctypes.c_ulong, 66 | ctypes.c_int, ctypes.c_double) 67 | self.pixel_wand = self.lib.NewPixelWand() 68 | self.lib.PixelSetColor(self.pixel_wand, "#ffffff") 69 | 70 | @classmethod 71 | def instance(cls): 72 | if not hasattr(cls, "_instance"): 73 | cls._instance = cls() 74 | return cls._instance 75 | 76 | def get_image_info(self, data): 77 | wand = self.lib.NewMagickWand() 78 | try: 79 | if not self.lib.MagickReadImageBlob(wand, data, len(data)): 80 | raise ImageException("Unsupported image format; data: %s...", 81 | binascii.b2a_hex(data[:32])) 82 | ptr = self.lib.MagickGetImageFormat(wand) 83 | format = ctypes.string_at(ptr).upper() 84 | self.lib.MagickRelinquishMemory(ptr) 85 | return { 86 | "mime_type": "image/" + format.lower(), 87 | "width": self.lib.MagickGetImageWidth(wand), 88 | "height": self.lib.MagickGetImageHeight(wand), 89 | } 90 | finally: 91 | self.lib.DestroyMagickWand(wand) 92 | 93 | def resize_image(self, data, max_width, max_height, quality=85, 94 | crop=False, force=False): 95 | wand = self.lib.NewMagickWand() 96 | try: 97 | if not self.lib.MagickReadImageBlob(wand, data, len(data)): 98 | raise ImageException("Unsupported image format; data: %s...", 99 | binascii.b2a_hex(data[:32])) 100 | width = self.lib.MagickGetImageWidth(wand) 101 | height = self.lib.MagickGetImageHeight(wand) 102 | self.lib.MagickStripImage(wand) 103 | if crop: 104 | ratio = max(max_height * 1.0 / height, max_width * 1.0 / width) 105 | else: 106 | ratio = min(max_height * 1.0 / height, max_width * 1.0 / width) 107 | 108 | ptr = self.lib.MagickGetImageFormat(wand) 109 | src_format = ctypes.string_at(ptr).upper() 110 | self.lib.MagickRelinquishMemory(ptr) 111 | format = src_format 112 | 113 | if ratio < 1.0 or force: 114 | format = "JPEG" 115 | self.lib.MagickResizeImage( 116 | wand, int(ratio * width + 0.5), int(ratio * height + 0.5), 117 | 0, 1.0) 118 | elif format not in ("GIF", "JPEG", "PNG"): 119 | format = "JPEG" 120 | 121 | if format != src_format: 122 | # Flatten to fix background on transparent images. We have to 123 | # do this before cropping, as MagickFlattenImages appears to 124 | # drop all the crop info from that step 125 | self.lib.MagickSetImageBackgroundColor(wand, self.pixel_wand) 126 | flat_wand = self.lib.MagickFlattenImages(wand) 127 | self.lib.DestroyMagickWand(wand) 128 | wand = flat_wand 129 | 130 | if crop: 131 | x = (self.lib.MagickGetImageWidth(wand) - max_width) / 2 132 | y = (self.lib.MagickGetImageHeight(wand) - max_height) / 2 133 | self.lib.MagickCropImage(wand, max_width, max_height, x, y) 134 | 135 | if format == "JPEG": 136 | # Default compression is best for PNG, GIF. 137 | self.lib.MagickSetCompressionQuality(wand, quality) 138 | 139 | self.lib.MagickSetFormat(wand, format) 140 | size = ctypes.c_size_t() 141 | ptr = self.lib.MagickGetImageBlob(wand, ctypes.byref(size)) 142 | body = ctypes.string_at(ptr, size.value) 143 | self.lib.MagickRelinquishMemory(ptr) 144 | 145 | return { 146 | "data": body, 147 | "mime_type": "image/" + format.lower(), 148 | "width": self.lib.MagickGetImageWidth(wand), 149 | "height": self.lib.MagickGetImageHeight(wand), 150 | } 151 | finally: 152 | self.lib.DestroyMagickWand(wand) 153 | -------------------------------------------------------------------------------- /schema.sql: -------------------------------------------------------------------------------- 1 | -- Copyright 2011 Bret Taylor 2 | -- 3 | -- Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | -- not use this file except in compliance with the License. You may obtain 5 | -- a copy of the License at 6 | -- 7 | -- http://www.apache.org/licenses/LICENSE-2.0 8 | -- 9 | -- Unless required by applicable law or agreed to in writing, software 10 | -- distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | -- WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | -- License for the specific language governing permissions and limitations 13 | -- under the License. 14 | 15 | SET SESSION storage_engine = "InnoDB"; 16 | SET SESSION time_zone = "+0:00"; 17 | ALTER DATABASE CHARACTER SET "utf8"; 18 | 19 | DROP TABLE IF EXISTS cookbook_recipes; 20 | CREATE TABLE cookbook_recipes ( 21 | id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 22 | author_id VARCHAR(25) NOT NULL REFERENCES cookbook_users(id), 23 | slug VARCHAR(100) NOT NULL UNIQUE, 24 | title VARCHAR(512) NOT NULL, 25 | category VARCHAR(512) NOT NULL, 26 | description MEDIUMTEXT NOT NULL, 27 | ingredients MEDIUMTEXT NOT NULL, 28 | instructions MEDIUMTEXT NOT NULL, 29 | created DATETIME NOT NULL, 30 | updated TIMESTAMP NOT NULL, 31 | KEY (author_id, created), 32 | KEY (category) 33 | ); 34 | 35 | DROP TABLE IF EXISTS cookbook_users; 36 | CREATE TABLE cookbook_users ( 37 | id VARCHAR(25) NOT NULL PRIMARY KEY, 38 | link VARCHAR(255) NOT NULL, 39 | name VARCHAR(100) NOT NULL, 40 | gender VARCHAR(25) NOT NULL, 41 | access_token VARCHAR(255) NOT NULL, 42 | created DATETIME NOT NULL, 43 | updated TIMESTAMP NOT NULL 44 | ); 45 | 46 | DROP TABLE IF EXISTS cookbook_friends; 47 | CREATE TABLE cookbook_friends ( 48 | user_id VARCHAR(25) NOT NULL, 49 | friend_id VARCHAR(25) NOT NULL, 50 | created TIMESTAMP NOT NULL, 51 | PRIMARY KEY (user_id, friend_id) 52 | ); 53 | 54 | DROP TABLE IF EXISTS cookbook_clipped; 55 | CREATE TABLE cookbook_clipped ( 56 | user_id VARCHAR(25) NOT NULL REFERENCES cookbook_users(id), 57 | recipe_id INT NOT NULL REFERENCES cookbook_recipes(id), 58 | created TIMESTAMP NOT NULL, 59 | PRIMARY KEY (user_id, recipe_id), 60 | KEY (user_id, created), 61 | KEY (recipe_id) 62 | ); 63 | 64 | DROP TABLE IF EXISTS cookbook_cooked; 65 | CREATE TABLE cookbook_cooked ( 66 | user_id VARCHAR(25) NOT NULL REFERENCES cookbook_users(id), 67 | recipe_id INT NOT NULL REFERENCES cookbook_recipes(id), 68 | created TIMESTAMP NOT NULL, 69 | KEY (user_id, recipe_id), 70 | KEY (user_id, created), 71 | KEY (recipe_id) 72 | ); 73 | 74 | DROP TABLE IF EXISTS cookbook_photos; 75 | CREATE TABLE cookbook_photos ( 76 | recipe_id INT NOT NULL PRIMARY KEY REFERENCES cookbook_recipes(id), 77 | created TIMESTAMP NOT NULL, 78 | full_hash VARCHAR(40) NOT NULL, 79 | full_width INT NOT NULL, 80 | full_height INT NOT NULL, 81 | thumb_hash VARCHAR(40) NOT NULL, 82 | thumb_width INT NOT NULL, 83 | thumb_height INT NOT NULL 84 | ); 85 | -------------------------------------------------------------------------------- /settings-template.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | port = 8000 4 | cookie_secret = "" 5 | 6 | facebook_app_id = "" 7 | facebook_app_secret = "" 8 | facebook_canvas_id = "" 9 | 10 | mysql_database = "" 11 | mysql_user = "" 12 | mysql_password = "" 13 | mysql_host = "" 14 | 15 | aws_access_key_id = "" 16 | aws_secret_access_key = "" 17 | aws_s3_bucket = "" 18 | aws_cloudfront_host = "" 19 | 20 | compiled_css_url = "" 21 | compiled_js_url = "" 22 | compiled_jquery_url = "" 23 | -------------------------------------------------------------------------------- /static/css/base.css: -------------------------------------------------------------------------------- 1 | /* Copyright 2011 Facebook */ 2 | 3 | body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, 4 | pre, a, code, em, img, dl, dt, dd, ol, ul, li, form, table, caption, th, 5 | td, canvas, embed, button { 6 | margin: 0; 7 | padding: 0; 8 | border: 0; 9 | } 10 | 11 | ul, ol { 12 | list-style-type: none; 13 | } 14 | 15 | body { 16 | background: white; 17 | margin: 0; 18 | margin-bottom: 25px; 19 | } 20 | 21 | body, 22 | input, 23 | textarea, 24 | td, 25 | button { 26 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 27 | font-size: 13px; 28 | text-rendering: optimizeLegibility; 29 | -webkit-font-smoothing: antialiased; 30 | color: #333; 31 | } 32 | 33 | a { 34 | color: #3b5998; 35 | text-decoration: none; 36 | } 37 | 38 | a.name { 39 | font-weight: bold; 40 | } 41 | 42 | a:hover { 43 | text-decoration: underline; 44 | } 45 | 46 | .column { 47 | margin: auto; 48 | width: 1000px; 49 | } 50 | 51 | 52 | /* Buttons */ 53 | 54 | button, 55 | a.button, 56 | button.primary:disabled, 57 | button:disabled:hover, 58 | button.primary:disabled:hover, 59 | button:disabled:active, 60 | button.primary:disabled:active { 61 | cursor: pointer; 62 | margin: 0; 63 | outline-style: none; 64 | 65 | border: 1px solid #bcbcbc; 66 | border-bottom-color: #a2a2a2; 67 | border-top-color: #c9c9c9; 68 | border-radius: 5px; 69 | -webkit-border-radius: 5px; 70 | -moz-border-radius: 5px; 71 | 72 | box-shadow: rgba(0, 0, 0, 0.1) 0 1px 0 0; 73 | -webkit-box-shadow: rgba(0, 0, 0, 0.1) 0 1px 0 0; 74 | -moz-box-shadow: rgba(0, 0, 0, 0.1) 0 1px 0 0; 75 | 76 | padding: 5px; 77 | padding-left: 11px; 78 | padding-right: 11px; 79 | 80 | background: #f9f9f9; 81 | background: -webkit-gradient(linear, left top, left bottom, from(#ffffff), to(#f6f6f6)); 82 | background: -moz-linear-gradient(top, #ffffff, #f6f6f6); 83 | 84 | text-decoration: none; 85 | font-weight: bold; 86 | color: #333; 87 | } 88 | 89 | a.button:hover, 90 | button:hover { 91 | border-color: #a2a2a2; 92 | text-decoration: none; 93 | } 94 | 95 | a.button:active, 96 | button:active { 97 | background: #f6f6f6; 98 | } 99 | 100 | button.primary { 101 | border-color: #3a5691; 102 | border-bottom-color: #1b305d; 103 | 104 | background: #4f6aa3; 105 | background: -webkit-gradient(linear, left top, left bottom, from(#738cc0), to(#4f6aa3)); 106 | background: -moz-linear-gradient(top, #738cc0, #4f6aa3); 107 | 108 | text-shadow: none; 109 | color: white; 110 | } 111 | 112 | button.primary:hover { 113 | border-color: #1b305d; 114 | } 115 | 116 | button.primary:active { 117 | background: #4f6aa3; 118 | } 119 | 120 | button:disabled, 121 | button:disabled:hover, 122 | button:disabled:active { 123 | color: #aaa; 124 | } 125 | 126 | 127 | /* Layout */ 128 | 129 | #page { 130 | margin-top: 20px; 131 | overflow: hidden; 132 | } 133 | 134 | #error div { 135 | border: 1px solid #be3333; 136 | background: #feb8b8; 137 | padding: 8px;; 138 | margin-bottom: 16px; 139 | font-weight: bold; 140 | } 141 | 142 | #body { 143 | margin-right: 285px; 144 | } 145 | 146 | #sidebar { 147 | float: right; 148 | width: 235px; 149 | margin-top: 30px; 150 | padding-left: 18px; 151 | border-left: 1px solid #ddd; 152 | 153 | } 154 | 155 | 156 | /* Sidebar */ 157 | 158 | #sidebar .actions button, 159 | #sidebar .actions a.button, 160 | .homeempty a.button { 161 | font-size: 16px; 162 | padding: 8px; 163 | padding-left: 20px; 164 | padding-right: 20px; 165 | -webkit-transition: opacity 0.25s ease-in-out; 166 | } 167 | 168 | #sidebar .actions .help { 169 | margin-top: 5px; 170 | color: #999; 171 | } 172 | 173 | #sidebar .info { 174 | margin-top: 25px; 175 | } 176 | 177 | #sidebar .info .facepile { 178 | margin-bottom: 5px; 179 | } 180 | 181 | #sidebar .info .stats { 182 | margin-top: 1em; 183 | } 184 | 185 | #sidebar .info .stats b { 186 | font-size: 175%; 187 | padding-right: 2px; 188 | } 189 | 190 | .activity { 191 | margin-top: 25px; 192 | } 193 | 194 | .activity h3 { 195 | font-size: 13px; 196 | margin-bottom: 10px; 197 | } 198 | 199 | .activity .action { 200 | padding-top: 6px; 201 | padding-bottom: 6px; 202 | overflow: hidden; 203 | -webkit-transition: background-color 0.25s ease-in-out; 204 | } 205 | 206 | .activity .action.highlighted { 207 | background-color: #fffcdb; 208 | } 209 | 210 | .activity .action .picture { 211 | display: block; 212 | line-height: 0; 213 | float: left; 214 | } 215 | 216 | .activity .action .picture img { 217 | width: 40px; 218 | height: 40px; 219 | } 220 | 221 | .activity .action .body { 222 | margin-left: 47px; 223 | } 224 | 225 | .activity .action .time { 226 | display: block; 227 | color: #999; 228 | font-size: 11px; 229 | margin-top: 2px; 230 | } 231 | 232 | 233 | /* Recipe */ 234 | 235 | .recipe h1, 236 | .category h1, 237 | .cookbook h1, 238 | .homeempty h1, 239 | .edit input[name=title] { 240 | font-size: 30px; 241 | font-weight: bold; 242 | } 243 | 244 | .breadcrumbs { 245 | color: #999; 246 | margin-bottom: 6px; 247 | } 248 | 249 | .recipe .description, 250 | .recipe .ingredients, 251 | .recipe .instructions, 252 | .homeempty p, 253 | .edit textarea { 254 | font-family: Georgia, serif; 255 | font-size: 16px; 256 | line-height: 23px; 257 | } 258 | 259 | p { 260 | margin-bottom: 1em; 261 | } 262 | 263 | .recipe h1 { 264 | margin-bottom: 13px; 265 | } 266 | 267 | .recipe .description { 268 | background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC0AAAAjBAMAAADyPp7ZAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj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Y7v399ByI8fVHBeNT9OyThhl3E18zLh0+drPWAYAnCRrmQGR51r64aIptj+x/W1eylqI8gAAAABJRU5ErkJggg==') no-repeat top left; 269 | padding-top: 20px; 270 | padding-left: 52px; 271 | } 272 | 273 | .recipe .meta { 274 | margin-left: 325px; 275 | } 276 | 277 | .recipe .author { 278 | color: #999; 279 | overflow: hidden; 280 | margin-left: 52px; 281 | } 282 | 283 | .recipe .author .picture { 284 | display: block; 285 | line-height: 0; 286 | float: left; 287 | } 288 | 289 | .recipe .author .picture img { 290 | width: 50px; 291 | height: 50px; 292 | } 293 | 294 | .recipe .author .body { 295 | margin-left: 58px; 296 | margin-top: 16px; 297 | } 298 | 299 | .recipe .photos { 300 | float: left; 301 | width: 306px; 302 | } 303 | 304 | .recipe .text { 305 | clear: left; 306 | } 307 | 308 | .recipe .edit { 309 | margin-top: 3px; 310 | } 311 | 312 | .recipe h2, 313 | .edit h2, 314 | .category h2 { 315 | color: #999; 316 | font-weight: normal; 317 | font-size: 22px; 318 | margin-top: 23px; 319 | margin-bottom: 6px; 320 | } 321 | 322 | .photo { 323 | display: block; 324 | border: 1px solid #ccc; 325 | padding: 2px; 326 | } 327 | 328 | .photo span { 329 | display: block; 330 | overflow: hidden; 331 | } 332 | 333 | .facepile { 334 | overflow: hidden; 335 | white-space: nowrap; 336 | } 337 | 338 | .facepile a { 339 | display: block; 340 | width: 40px; 341 | height: 40px; 342 | background-size: 40px 40px; 343 | margin-right: 3px; 344 | float: left; 345 | } 346 | 347 | .context .names { 348 | margin-top: 3px; 349 | } 350 | 351 | 352 | /* Home */ 353 | 354 | .home h2 { 355 | font-size: 30px; 356 | margin-bottom: 10px; 357 | } 358 | 359 | .section { 360 | margin-bottom: 30px; 361 | } 362 | 363 | .clips { 364 | overflow: hidden; 365 | margin-bottom: 25px; 366 | } 367 | 368 | div.clip { 369 | width: 348px; 370 | padding-right: 15px; 371 | float: left; 372 | height: 156px; 373 | position: relative; 374 | } 375 | 376 | .clip:last-child { 377 | padding-right: 0; 378 | width: 352px; 379 | } 380 | 381 | .clip h3 { 382 | font-size: 20px; 383 | margin-left: 164px; 384 | } 385 | 386 | .clip .context { 387 | position: absolute; 388 | padding-right: 12px; 389 | left: 164px; 390 | bottom: 0; 391 | } 392 | 393 | .clip:last-child .context { 394 | padding-right: 0; 395 | } 396 | 397 | .clip .photo { 398 | float: left; 399 | } 400 | 401 | .photoupload span { 402 | background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAABBBAMAAAB/btpeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RTREMDI1QzU5N0IwMTFFMEIxQzI5QTYwRUY4Qzc4NEIiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RTREMDI1QzY5N0IwMTFFMEIxQzI5QTYwRUY4Qzc4NEIiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpFNEQwMjVDMzk3QjAxMUUwQjFDMjlBNjBFRjhDNzg0QiIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpFNEQwMjVDNDk3QjAxMUUwQjFDMjlBNjBFRjhDNzg0QiIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PkoZaIEAAAASUExURf///ztZmG2EtI2fxdTb6dTc6RqdAfkAAAABdFJOUwBA5thmAAAAXklEQVQ4y2MwUsIODBjAQIEBO1CgjrQLFuBAP2lnHJ5Xhkg74XA+E3WkWUOxgBElLSg6OKUDBcGANtKDzN/gFIk7xiiRhpQtOKUZ8OumhzSuHEoFaWacZcsoGAV0AgDoePgUifLGWgAAAABJRU5ErkJggg==') no-repeat center center; 403 | background-color: #eceff6; 404 | position: relative; 405 | } 406 | 407 | .photoupload span span { 408 | background: none; 409 | position: absolute; 410 | top: 50%; 411 | left: 0; 412 | width: 100%; 413 | padding-top: 19px; 414 | text-align: center; 415 | font-size: 11px; 416 | } 417 | 418 | a.photo.photoupload:hover { 419 | text-decoration: none; 420 | } 421 | 422 | #uploaddialog p { 423 | margin-bottom: 1em; 424 | } 425 | 426 | #uploaddialog { 427 | display: none; 428 | } 429 | 430 | .dialog .loading { 431 | display: none; 432 | float: left; 433 | font-size: 11px; 434 | padding-left: 24px; 435 | margin-top: 8px; 436 | margin-left: 3px; 437 | background: url('data:image/gif;base64,R0lGODlhEAALAMQaAPT09PDw8JeXl6Ojo+/v76ioqL6+vr29vbS0tOLi4uPj49fX1+jo6KysrODg4JiYmMvLy6Wlpc7Ozvn5+bW1tevr6/X19ZaWlvf39+7u7v///wAAAAAAAAAAAAAA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m4r1ah0WoYAACH5BAULABoALAAAAAABAAEAAAUDoBYCADs=') no-repeat left center; 438 | color: gray; 439 | } 440 | 441 | 442 | /* Dialog */ 443 | 444 | .dialog { 445 | background-color: rgba(82, 82, 82, 0.65); 446 | border-radius: 8px; 447 | -webkit-border-radius: 8px; 448 | -moz-border-radius: 8px; 449 | padding: 8px; 450 | position: fixed; 451 | top: 125px; 452 | left: 50%; 453 | margin-left: -250px; 454 | width: 500px; 455 | z-index: 100; 456 | } 457 | 458 | .dialog h2, 459 | .dialog .body, 460 | .dialog .buttons { 461 | padding: 7px; 462 | padding-left: 10px; 463 | padding-right: 10px; 464 | } 465 | 466 | .dialog h2 { 467 | background: #5988b4; 468 | border: 1px solid #3b5998; 469 | border-bottom-style: none; 470 | display: block; 471 | color: white; 472 | font-size: 15px; 473 | } 474 | 475 | .dialog .body { 476 | border: 1px solid #555; 477 | border-top-style: none; 478 | border-bottom-color: #ccc; 479 | background: white; 480 | } 481 | 482 | .dialog .buttons { 483 | background: #f2f2f2; 484 | border: 1px solid #555; 485 | border-top-style: none; 486 | text-align: right; 487 | } 488 | 489 | .dialog .buttons button { 490 | margin-left: 5px; 491 | } 492 | 493 | 494 | /* Edit form */ 495 | 496 | .edit textarea, 497 | .edit input { 498 | width: 600px; 499 | } 500 | 501 | .edit textarea { 502 | height: 200px; 503 | } 504 | 505 | .edit textarea[name=description] { 506 | height: 50px; 507 | } 508 | 509 | .edit input[name=category] { 510 | width: 200px; 511 | } 512 | 513 | .edit h2, 514 | .edit .buttons { 515 | margin-top: 13px; 516 | } 517 | 518 | 519 | .edit .note { 520 | color: #999; 521 | float: right; 522 | margin-top: 20px; 523 | margin-right: 110px; 524 | } 525 | 526 | 527 | /* Recipe index */ 528 | 529 | .category h1, 530 | .cookbook h1, 531 | .homeempty h1 { 532 | margin-bottom: 6px; 533 | } 534 | 535 | .index { 536 | overflow: hidden; 537 | } 538 | 539 | .index .lhs { 540 | float: left; 541 | width: 343px; 542 | } 543 | 544 | .index .rhs { 545 | margin-left: 363px; 546 | } 547 | 548 | .index li { 549 | font-family: Georgia, serif; 550 | font-size: 16px; 551 | line-height: 23px; 552 | } 553 | 554 | .index h3 { 555 | color: #999; 556 | font-weight: normal; 557 | font-size: 22px; 558 | margin-top: 10px; 559 | margin-bottom: 3px; 560 | } 561 | 562 | 563 | /* Header */ 564 | 565 | #header { 566 | background: #5988b4; 567 | background: -webkit-gradient(linear, left top, left bottom, from(#6e99bf), to(#5988b4)); 568 | background: -moz-linear-gradient(top, #6e99bf, #5988b4); 569 | height: 39px; 570 | box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); 571 | -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); 572 | -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); 573 | } 574 | 575 | #header, 576 | #header a { 577 | color: white; 578 | text-shadow: rgba(36, 81, 124, 0.5) 0 -1px 0; 579 | } 580 | 581 | #header ul { 582 | list-style-type: none; 583 | float: right; 584 | } 585 | 586 | #header ul li { 587 | float: left; 588 | } 589 | 590 | #header ul a { 591 | display: block; 592 | line-height: 39px; 593 | padding-left: 12px; 594 | padding-right: 12px; 595 | font-weight: bold; 596 | } 597 | 598 | #logo { 599 | display: block; 600 | width: 235px; 601 | height: 39px; 602 | background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOsAAAAhCAYAAAA4eVwHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYg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hZ3vilqn7vpiC3VUKVryKdXn2B5vzZNlNeJf1c7yZMwxApVS6MdbvBltiycD9+YxxAGwBYknjE9NyfiLLYKLvZCYwY8YOgRAZjo+PWr/Ib4klA/+3br4KeQQ/8fK8XioWljPR1fQCM7398iXrz2dYYskD+sNUTB6HvAJJZMwYZW4Qy0uvE9HbBpQUQK/aLSTH2vorcpZYEjqwWmKJJRZYLbHEEj3yX/9y7UChP61tAAAAAElFTkSuQmCC') no-repeat center center; 603 | } 604 | -------------------------------------------------------------------------------- /static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/finiteloop/socialcookbook/9c18fc528491582ca6019a7f6bf6bf414e1c97e8/static/favicon.ico -------------------------------------------------------------------------------- /static/js/base.js: -------------------------------------------------------------------------------- 1 | // Copyright 2011 Facebook 2 | 3 | $(function() { 4 | $("button.newrecipe").live("click", function() { 5 | location.href = "/edit"; 6 | return false; 7 | }); 8 | $("a.photoupload").live("click", function() { 9 | $("#uploaddialog input[name=recipe]").val($(this).attr("recipe")); 10 | $("#uploaddialog").fadeIn(150); 11 | return false; 12 | }); 13 | // TODO: Loading indicators 14 | $("button.clip").live("click", function() { 15 | var button = $(this); 16 | button.attr("disabled", "disabled"); 17 | $.post("/a/clip", {recipe: $(this).attr("recipe")}, 18 | function(response) { 19 | $(".activity h3").after(response.html); 20 | highlight($(".activity .action:first")); 21 | button.get(0).className = "cook"; 22 | button.css({"opacity": 0}); 23 | window.setTimeout(function() { 24 | button.removeAttr("disabled"); 25 | button.text("I just cooked this"); 26 | button.css({"opacity": 1}); 27 | }, 300); 28 | }); 29 | return false; 30 | }); 31 | $("button.cook").live("click", function() { 32 | var button = $(this); 33 | button.attr("disabled", "disabled"); 34 | $.post("/a/cook", {recipe: $(this).attr("recipe")}, 35 | function(response) { 36 | button.removeAttr("disabled"); 37 | $(".activity h3").after(response.html); 38 | highlight($(".activity .action:first")); 39 | }); 40 | return false; 41 | }); 42 | $("button.dialogcancel").live("click", function() { 43 | $(this).parents("form").find("button").removeAttr("disabled"); 44 | $(this).parents(".dialog").fadeOut(150).find(".loading").hide(); 45 | }); 46 | $("#uploaddialog form").live("submit", function() { 47 | $("#uploaddialog button[type=submit]").attr("disabled", "disabled"); 48 | $("#uploaddialog .loading").show(); 49 | return true; 50 | }); 51 | $("#uploaddialog input[type=file]").live("change", function() { 52 | $(this).parents("form").submit(); 53 | }); 54 | $("a.newcategory").live("click", function() { 55 | var div = $(this).parent(); 56 | var current = div.find("select").val(); 57 | div.html('').find("input").val(current).select(); 58 | return false; 59 | }); 60 | $("form.edit").live("submit", function() { 61 | var required = ["title", "description", "category"]; 62 | for (var i = 0; i < required.length; i++) { 63 | if (!this[required[i]].value) { 64 | this[required[i]].select(); 65 | return false; 66 | } 67 | } 68 | return true; 69 | }); 70 | window.setTimeout(function() { 71 | $("#error").slideUp(); 72 | }, 4000); 73 | }); 74 | 75 | 76 | function highlight(node) { 77 | node.addClass("highlighted"); 78 | node.hide(); 79 | node.slideDown(); 80 | window.setTimeout(function() { 81 | node.removeClass("highlighted"); 82 | }, 1500); 83 | } 84 | -------------------------------------------------------------------------------- /static/js/jquery.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * jQuery JavaScript Library v1.6.1 3 | * http://jquery.com/ 4 | * 5 | * Copyright 2011, John Resig 6 | * Dual licensed under the MIT or GPL Version 2 licenses. 7 | * http://jquery.org/license 8 | * 9 | * Includes Sizzle.js 10 | * http://sizzlejs.com/ 11 | * Copyright 2011, The Dojo Foundation 12 | * Released under the MIT, BSD, and GPL Licenses. 13 | * 14 | * Date: Thu May 12 15:04:36 2011 -0400 15 | */ 16 | (function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cv(a){if(!cj[a]){var b=f("<"+a+">").appendTo("body"),d=b.css("display");b.remove();if(d==="none"||d===""){ck||(ck=c.createElement("iframe"),ck.frameBorder=ck.width=ck.height=0),c.body.appendChild(ck);if(!cl||!ck.createElement)cl=(ck.contentWindow||ck.contentDocument).document,cl.write("");b=cl.createElement(a),cl.body.appendChild(b),d=f.css(b,"display"),c.body.removeChild(ck)}cj[a]=d}return cj[a]}function cu(a,b){var c={};f.each(cp.concat.apply([],cp.slice(0,b)),function(){c[this]=a});return c}function ct(){cq=b}function cs(){setTimeout(ct,0);return cq=f.now()}function ci(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ch(){try{return new a.XMLHttpRequest}catch(b){}}function cb(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g=0===c})}function W(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function O(a,b){return(a&&a!=="*"?a+".":"")+b.replace(A,"`").replace(B,"&")}function N(a){var b,c,d,e,g,h,i,j,k,l,m,n,o,p=[],q=[],r=f._data(this,"events");if(!(a.liveFired===this||!r||!r.live||a.target.disabled||a.button&&a.type==="click")){a.namespace&&(n=new RegExp("(^|\\.)"+a.namespace.split(".").join("\\.(?:.*\\.)?")+"(\\.|$)")),a.liveFired=this;var s=r.live.slice(0);for(i=0;it |