mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: Ning importer
This commit is contained in:
@ -11,10 +11,16 @@ if ARGV.include?('bbcode-to-md')
|
||||
require 'ruby-bbcode-to-md'
|
||||
end
|
||||
|
||||
require_dependency 'url_helper'
|
||||
require_dependency 'file_helper'
|
||||
|
||||
|
||||
module ImportScripts; end
|
||||
|
||||
class ImportScripts::Base
|
||||
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
def initialize
|
||||
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
|
||||
preload_i18n
|
||||
@ -269,6 +275,7 @@ class ImportScripts::Base
|
||||
|
||||
bio_raw = opts.delete(:bio_raw)
|
||||
website = opts.delete(:website)
|
||||
location = opts.delete(:location)
|
||||
avatar_url = opts.delete(:avatar_url)
|
||||
|
||||
opts[:name] = User.suggest_name(opts[:email]) unless opts[:name]
|
||||
@ -296,6 +303,7 @@ class ImportScripts::Base
|
||||
if bio_raw.present? || website.present?
|
||||
u.user_profile.bio_raw = bio_raw if bio_raw.present?
|
||||
u.user_profile.website = website if website.present?
|
||||
u.user_profile.location = location if location.present?
|
||||
u.user_profile.save!
|
||||
end
|
||||
end
|
||||
@ -323,6 +331,8 @@ class ImportScripts::Base
|
||||
results.each do |c|
|
||||
params = yield(c)
|
||||
|
||||
next if params.nil? # block returns nil to skip
|
||||
|
||||
# Basic massaging on the category name
|
||||
params[:name] = "Blank" if params[:name].blank?
|
||||
params[:name].strip!
|
||||
@ -552,6 +562,22 @@ class ImportScripts::Base
|
||||
end
|
||||
end
|
||||
|
||||
def html_for_upload(upload, display_filename)
|
||||
if FileHelper.is_image?(upload.url)
|
||||
embedded_image_html(upload)
|
||||
else
|
||||
attachment_html(upload, display_filename)
|
||||
end
|
||||
end
|
||||
|
||||
def embedded_image_html(upload)
|
||||
%Q[<img src="#{upload.url}" width="#{[upload.width, 640].compact.min}" height="#{[upload.height,480].compact.min}"><br/>]
|
||||
end
|
||||
|
||||
def attachment_html(upload, display_filename)
|
||||
"<a class='attachment' href='#{upload.url}'>#{display_filename}</a> (#{number_to_human_size(upload.filesize)})"
|
||||
end
|
||||
|
||||
def print_status(current, max)
|
||||
print "\r%9d / %d (%5.1f%%) " % [current, max, ((current.to_f / max.to_f) * 100).round(1)]
|
||||
end
|
||||
|
Reference in New Issue
Block a user