2015-09-28 20:55:31 -03:00
|
|
|
# name: discourse-signatures
|
|
|
|
|
# about: A plugin to get that nostalgia signatures in Discourse Foruns
|
2017-07-24 21:18:11 -03:00
|
|
|
# version: 2.0.0
|
2015-09-28 20:55:31 -03:00
|
|
|
# author: Rafael Silva <xfalcox@gmail.com>
|
|
|
|
|
# url: https://github.com/xfalcox/discourse-signatures
|
|
|
|
|
|
|
|
|
|
enabled_site_setting :signatures_enabled
|
|
|
|
|
|
2015-12-06 15:56:46 -02:00
|
|
|
DiscoursePluginRegistry.serialized_current_user_fields << "see_signatures"
|
|
|
|
|
DiscoursePluginRegistry.serialized_current_user_fields << "signature_url"
|
2016-04-08 17:30:39 -04:00
|
|
|
DiscoursePluginRegistry.serialized_current_user_fields << "signature_raw"
|
2015-09-28 20:55:31 -03:00
|
|
|
|
|
|
|
|
after_initialize do
|
|
|
|
|
|
2015-12-06 15:56:46 -02:00
|
|
|
User.register_custom_field_type('see_signatures', :boolean)
|
|
|
|
|
User.register_custom_field_type('signature_url', :text)
|
2016-04-08 17:30:39 -04:00
|
|
|
User.register_custom_field_type('signature_raw', :text)
|
2015-09-28 20:55:31 -03:00
|
|
|
|
2015-12-06 15:56:46 -02:00
|
|
|
if SiteSetting.signatures_enabled then
|
2016-04-08 17:30:39 -04:00
|
|
|
add_to_serializer(:post, :user_signature, false) {
|
|
|
|
|
if SiteSetting.signatures_advanced_mode then
|
2017-07-24 21:18:11 -03:00
|
|
|
object.user.custom_fields['signature_cooked'] if object.user
|
2016-04-08 17:30:39 -04:00
|
|
|
else
|
2017-03-14 17:28:30 +00:00
|
|
|
object.user.custom_fields['signature_url'] if object.user
|
2016-04-08 17:30:39 -04:00
|
|
|
end
|
2015-12-06 15:56:46 -02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# I guess this should be the default @ discourse. PR maybe?
|
|
|
|
|
add_to_serializer(:user, :custom_fields, false) {
|
|
|
|
|
if object.custom_fields == nil then
|
|
|
|
|
{}
|
|
|
|
|
else
|
|
|
|
|
object.custom_fields
|
|
|
|
|
end
|
|
|
|
|
}
|
2015-09-28 20:55:31 -03:00
|
|
|
end
|
2017-07-24 21:18:11 -03:00
|
|
|
|
|
|
|
|
# This is the code responsible for cooking a new advanced mode sig on user update
|
|
|
|
|
DiscourseEvent.on(:user_updated) do |user|
|
2017-08-29 08:26:14 -04:00
|
|
|
if SiteSetting.signatures_enabled? && SiteSetting.signatures_advanced_mode && user.custom_fields['signature_raw']
|
2017-07-24 21:18:11 -03:00
|
|
|
cooked_sig = PrettyText.cook(user.custom_fields['signature_raw'], omit_nofollow: user.has_trust_level?(TrustLevel[3]) && !SiteSetting.tl3_links_no_follow)
|
2018-04-03 19:55:00 +06:00
|
|
|
# avoid infinite recursion
|
2017-08-28 18:01:17 -04:00
|
|
|
if cooked_sig != user.custom_fields['signature_cooked']
|
|
|
|
|
user.custom_fields['signature_cooked'] = cooked_sig
|
|
|
|
|
user.save
|
|
|
|
|
end
|
2017-07-24 21:18:11 -03:00
|
|
|
end
|
|
|
|
|
end
|
2015-09-28 20:55:31 -03:00
|
|
|
end
|
2015-12-06 15:56:46 -02:00
|
|
|
|
|
|
|
|
register_asset "javascripts/discourse/templates/connectors/user-custom-preferences/signature-preferences.hbs"
|
|
|
|
|
register_asset "stylesheets/common/signatures.scss"
|