<fim-prefix># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

from __future__ import unicode_literals

import frappe
from frappe import _
from frappe.website.website_generator import WebsiteGenerator
from frappe.website.render import clear_cache
from frappe.utils import today, cint, global_date_format, get_fullname, strip_html_tags, markdown, sanitize_html
from math import ceil
from frappe.website.utils import (find_first_image, get_html_content_based_on_type,
	get_comment_list)

class BlogPost(WebsiteGenerator):
	website = frappe._dict(
		route = 'blog',
		order_by = "published_on desc"
	)
	# BUG: CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
	# 
	# FIXED:
	@<fim-middle>frappe.whitelist()
	def make_route(self):
		if not self.route:
			return frappe.db.get_value('Blog Category', self.blog_category,
				'route') + '/' + self.scrub(self.title)

	def get_feed(self):
		ret<fix-suffix>urn self.title

	def validate(self):
		super(BlogPost, self).validate()

		if not self.blog_intro:
			content = get_html_content_based_on_type(self, 'content', self.content_type)
			self.blog_intro = content[:200]
			self.blog_intro = strip_html_tags(self.blog_intro)

		if self.blog_intro:
			self.blog_intro = self.blog_intro[:200]

		if not self.meta_title:
			self.meta_title = self.title[:60]
		else:
			self.meta_title = self.meta_title[:60]

		if not self.meta_description:
			self.meta_description = self.blog_intro[:140]
		else:
			self.meta_description = self.meta_description[:140]

		if self.published and not self.published_on:
			self.published_on = today()

		if self.featured:
			if not self.meta_image:
				frappe.throw(_("A featured post must have a cover image"))
			self.reset_featured_for_other_blogs()

		self.set_read_time()

	def reset_featured_for_other_blogs(self):
		all_posts = frappe.get_all("Blog Post", {"featured": 1})
		for post in all_posts:
			frappe.db.set_value("<|endoftext|>