3 if (!defined('GNUSOCIAL')) {
7 class SensitiveContentPlugin extends Plugin
9 const VERSION = '0.0.1';
11 function onPluginVersion(array &$versions)
13 $versions[] = array('name' => 'Sensitive Content',
14 'version' => self::VERSION,
15 'author' => 'MoonMan',
16 'homepage' => 'https://gitgud.io/ShitposterClub/SensitiveContent/',
18 _m('Mark, hide/show sensitive notices like on Twitter.'));
22 static function settings($setting)
24 $settings['blockerimage'] = Plugin::staticPath('SensitiveContent', '').'img/blocker.png';
26 $configphpsettings = common_config('site','sensitivecontent') ?: array();
27 foreach($configphpsettings as $configphpsetting=>$value) {
28 $settings[$configphpsetting] = $value;
31 if(isset($settings[$setting])) {
32 return $settings[$setting];
37 function onNoticeSimpleStatusArray($notice, &$twitter_status, $scoped)
39 $twitter_status['tags'] = $notice->getTags();
42 function onTwitterUserArray($profile, &$twitter_user, $scoped)
44 if ($scoped instanceof Profile && $scoped->sameAs($profile)) {
45 $twitter_user['hide_sensitive'] = $this->getHideSensitive($scoped);
49 public function onRouterInitialized(URLMapper $m)
51 $m->connect('settings/sensitivecontent',
52 array('action' => 'sensitivecontentsettings'));
56 function onEndAccountSettingsNav($action)
58 $action->menuItem(common_local_url('sensitivecontentsettings'),
59 _m('MENU', 'Sensitive Content'),
60 _m('Settings for display of sensitive content.'));
66 public function onQvitterEndShowHeadElements(Action $action)
68 $blocker = static::settings('blockerimage');
69 common_log( LOG_DEBUG, "SENSITIVECONTENT " . $blocker );
78 div.stream-item.notice.sensitive-notice .sensitive-blocker {
84 background-color: #d4baba;
85 background-image: url($blocker);
86 background-repeat: no-repeat;
87 background-position: center center;
88 background-size: contain;
89 transition: opacity 1s ease-in-out;
92 .sensitive-blocker:hover {
96 div.stream-item.notice.expanded.sensitive-notice .sensitive-blocker {
98 background-color: transparent;
99 background-image: none;
104 $action->style($styles);
107 function onQvitterEndShowScripts(Action $action)
109 $action->script( Plugin::staticPath('SensitiveContent', '').'js/sensitivecontent.js' );
112 function onEndShowStyles(Action $action)
114 $blocker = static::settings('blockerimage');
118 /* default no show */
119 html .tagcontainer > footer > .attachments > .inline-attachment > .attachment-wrapper > .sensitive-blocker {
123 html[data-hidesensitive='true'] .tagcontainer.data-tag-nsfw > footer > .attachments > .inline-attachment > .attachment-wrapper > .sensitive-blocker {
129 /*background-color: #d4baba;*/
130 background-color: black;
131 background-image: url($blocker);
132 background-repeat: no-repeat;
133 background-position: center center;
134 background-size: contain;
135 transition: opacity 1s ease-in-out;
138 html[data-hidesensitive='true'] .tagcontainer.data-tag-nsfw > footer > .attachments > .inline-attachment > .attachment-wrapper > .sensitive-blocker.reveal {
144 $action->style($styles);
147 function onStartShowAttachmentRepresentation($out, $file)
149 $profile = Profile::current();
151 if (!is_null($profile) && $profile instanceof Profile)
153 $hidesensitive = $this->getHideSensitive($profile);
157 $hidesensitive = false;
161 $classes = "sensitive-blocker"; //'sensitive-blocker';
163 $out->elementStart('div', array(
164 'class'=>'attachment-wrapper',
165 'style'=>'height: ' . $file->getThumbnail()->height . 'px; width: ' . $file->getThumbnail()->width . 'px;'
166 )); /*needs height of thumb*/
167 $out->elementStart('div', array(
169 'onclick'=>'toggleSpoiler(event)',
170 'style'=>'height: ' . $file->getThumbnail()->height . 'px; width: ' . $file->getThumbnail()->width . 'px;'
173 $out->elementEnd('div');
176 function onEndShowAttachmentRepresentation($out, $file)
178 $out->elementEnd('div');
181 function onEndShowScripts(Action $action)
183 $profile = $action->getScoped();
184 if (!is_null($profile) && $profile instanceof Profile)
186 $hidesensitive = $this->getHideSensitive($profile) ? "true" : "false";
190 $hidesensitive = "false";
195 window.hidesensitive = $hidesensitive ;
197 function toggleSpoiler(evt) {
198 if (window.hidesensitive) evt.target.classList.toggle('reveal');
201 $action->inlineScript($inline);
204 function onEndOpenNoticeListItemElement(NoticeListItem $nli)
206 $rawtags = $nli->getNotice()->getTags();
207 $classes = "tagcontainer";
209 foreach($rawtags as $tag)
211 $classes = $classes . ' data-tag-' . $tag;
215 $nli->elementStart('span', array('class' => $classes));
216 //$nli->elementEnd('span');
219 function onStartCloseNoticeListItemElement(NoticeListItem $nli)
221 $nli->elementEnd('span');
224 function onStartHtmlElement($action, &$attrs) {
225 $profile = Profile::current();
227 if (!is_null($profile) && $profile instanceof Profile)
229 $hidesensitive = $this->getHideSensitive($profile);
233 $hidesensitive = false;
237 $attrs = array_merge($attrs,
238 array('data-hidesensitive' => ($hidesensitive ? "true" : "false"))
243 function getHideSensitive($profile) {
244 $c = Cache::instance();
248 $hidesensitive = $c->get(Cache::key('profile:hide_sensitive:'.$profile->id));
249 if (is_numeric($hidesensitive)) {
250 return (boolean) $hidesensitive;
256 $hidesensitive = $profile->getPref('MoonMan', 'hide_sensitive', '0');
260 $c->set(Cache::key('profile:hide_sensitive:'.$profile->id), $hidesensitive);
263 //common_log(LOG_DEBUG, "SENSITIVECONTENT hidesensitive? id " . $profile->id . " value " . (boolean)$hidesensitive );
265 if (is_null($hidesensitive)) {
268 if (is_numeric($hidesensitive)) {
269 return (boolean) $hidesensitive;