2014-05-06 09:20:15 +00:00
|
|
|
class PageContentsController < OrbitAdminController
|
2022-10-24 09:52:02 +00:00
|
|
|
require 'uri'
|
2014-08-05 06:45:30 +00:00
|
|
|
def index
|
|
|
|
params = OrbitHelper.params
|
2016-08-24 13:28:22 +00:00
|
|
|
if params["wiki"].present?
|
2022-10-24 10:04:57 +00:00
|
|
|
page = WikiPage.where(:uid => params["wiki"].to_s).first
|
2021-11-23 03:53:23 +00:00
|
|
|
page.view_count += 1
|
|
|
|
page.save
|
2023-05-14 02:59:17 +00:00
|
|
|
name = page.name rescue ""
|
2016-08-24 13:28:22 +00:00
|
|
|
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
|
2022-10-24 10:04:57 +00:00
|
|
|
page = Page.where(:page_id => params[:page_id].to_s).first
|
2016-08-24 13:28:22 +00:00
|
|
|
name = page.name rescue ""
|
2020-11-14 03:30:45 +00:00
|
|
|
html = page.page_contexts.order(:version=>-1).first.content rescue ""
|
2016-08-24 13:28:22 +00:00
|
|
|
url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/page_contents/new?page_id=#{page.id.to_s}" : ""
|
|
|
|
end
|
2017-11-07 07:31:51 +00:00
|
|
|
request = OrbitHelper.request
|
|
|
|
meta_desc = html.nil? ? "" : ActionView::Base.full_sanitizer.sanitize(html)[0..200]
|
|
|
|
doc = Nokogiri::HTML( html )
|
2023-07-13 03:32:05 +00:00
|
|
|
img_srcs = doc.css('img').map{ |i| i['src'] }.compact
|
2023-05-14 02:59:17 +00:00
|
|
|
metas = [{"property" => "og:description", "content" => meta_desc},{"property" => "og:type", "content" => "Article"}]
|
2023-09-23 10:07:22 +00:00
|
|
|
# if img_srcs.count > 0
|
|
|
|
# metas << {"property" => "og:image", "content" => URI.join(request.base_url, URI.encode(img_srcs[0])).to_s}
|
|
|
|
# end
|
2017-11-07 07:31:51 +00:00
|
|
|
OrbitHelper.render_meta_tags(metas)
|
2016-08-24 13:28:22 +00:00
|
|
|
|
2014-08-05 06:45:30 +00:00
|
|
|
{
|
2016-08-24 13:28:22 +00:00
|
|
|
"html" => html,
|
|
|
|
"title" => name,
|
2015-04-13 06:35:21 +00:00
|
|
|
"view_count" => (page.view_count rescue ""),
|
2015-04-13 06:13:41 +00:00
|
|
|
"view-count-head" =>t('page_content.view_count'),
|
2014-08-05 06:45:30 +00:00
|
|
|
"url_to_edit" => url_to_edit
|
|
|
|
}
|
|
|
|
end
|
2014-05-06 09:20:15 +00:00
|
|
|
end
|