pagecontent/app/controllers/page_contents_controller.rb

36 lines
1.4 KiB
Ruby

class PageContentsController < OrbitAdminController
require 'uri'
def index
params = OrbitHelper.params
if params["wiki"].present?
page = WikiPage.where(:uid => params["wiki"].to_s).first
page.view_count += 1
page.save
name = page.name rescue ""
html = page.content rescue ""
url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/wiki_pages/#{page.id}/edit?page_id=#{page.page.id.to_s}" : ""
else
page = Page.where(:page_id => params[:page_id].to_s).first
name = page.name rescue ""
html = page.page_contexts.order(:version=>-1).first.content rescue ""
url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/page_contents/new?page_id=#{page.id.to_s}" : ""
end
request = OrbitHelper.request
meta_desc = html.nil? ? "" : ActionView::Base.full_sanitizer.sanitize(html)[0..200]
doc = Nokogiri::HTML( html )
img_srcs = doc.css('img').map{ |i| i['src'] }.compact
metas = [{"property" => "og:description", "content" => meta_desc},{"property" => "og:type", "content" => "Article"}]
# if img_srcs.count > 0
# metas << {"property" => "og:image", "content" => URI.join(request.base_url, URI.encode(img_srcs[0])).to_s}
# end
OrbitHelper.render_meta_tags(metas)
{
"html" => html,
"title" => name,
"view_count" => (page.view_count rescue ""),
"view-count-head" =>t('page_content.view_count'),
"url_to_edit" => url_to_edit
}
end
end