image censoring per connection

This commit is contained in:
zotlabs 2019-07-30 17:56:35 -07:00
parent 7a068d29d0
commit 3bc243ea46
22 changed files with 1521 additions and 13 deletions

View file

@ -854,11 +854,6 @@ class Libsync {
continue;
}
// Catch some malformed entries from the past which still exist
if(strpos($location['address'],'/') !== false)
$location['address'] = substr($location['address'],0,strpos($location['address'],'/'));
// match as many fields as possible in case anything at all changed.
$r = q("select * from hubloc where hubloc_hash = '%s' and hubloc_guid = '%s' and hubloc_guid_sig = '%s' and hubloc_id_url = '%s' and hubloc_url = '%s' and hubloc_url_sig = '%s' and hubloc_site_id = '%s' and hubloc_host = '%s' and hubloc_addr = '%s' and hubloc_callback = '%s' and hubloc_sitekey = '%s' ",

View file

@ -441,6 +441,15 @@ class Connedit extends Controller {
goaway(z_root() . '/connedit/' . $contact_id);
}
if($cmd === 'censor') {
if(abook_toggle_flag($orig_record[0],ABOOK_FLAG_CENSORED)) {
$this->connedit_clone($a);
}
else
notice(t('Unable to set address book parameters.') . EOL);
goaway(z_root() . '/connedit/' . $contact_id);
}
if($cmd === 'archive') {
if(abook_toggle_flag($orig_record[0],ABOOK_FLAG_ARCHIVED)) {
$this->connedit_clone($a);
@ -575,6 +584,14 @@ class Connedit extends Controller {
'info' => (intval($contact['abook_ignored']) ? t('This connection is ignored!') : ''),
),
'censor' => array(
'label' => (intval($contact['abook_censor']) ? t('Uncensor') : t('Censor')),
'url' => z_root() . '/connedit/' . $contact['abook_id'] . '/censor',
'sel' => (intval($contact['abook_censor']) ? 'active' : ''),
'title' => t('Censor (or Uncensor) images from this connection'),
'info' => (intval($contact['abook_censor']) ? t('This connection is censored!') : ''),
),
'archive' => array(
'label' => (intval($contact['abook_archived']) ? t('Unarchive') : t('Archive')),
'url' => z_root() . '/connedit/' . $contact['abook_id'] . '/archive',

34
Zotlabs/Update/_1233.php Normal file
View file

@ -0,0 +1,34 @@
<?php
namespace Zotlabs\Update;
class _1233 {
function run() {
q("START TRANSACTION");
$r = q("ALTER TABLE abook ADD abook_censor INT UNSIGNED NOT NULL DEFAULT '0' ");
if($r) {
q("COMMIT");
return UPDATE_SUCCESS;
}
q("ROLLBACK");
return UPDATE_FAILED;
}
function verify() {
$columns = db_columns('abook');
if(in_array('abook_censor',$columns)) {
return true;
}
return false;
}
}

View file

@ -48,7 +48,7 @@ require_once('include/items.php');
define ( 'STD_VERSION', '3.5' );
define ( 'ZOT_REVISION', '6.0' );
define ( 'DB_UPDATE_VERSION', 1232 );
define ( 'DB_UPDATE_VERSION', 1233 );
define ( 'PLATFORM_NAME', 'zap' );
define ( 'PLATFORM_ARCHITECTURE', 'zap' );
@ -309,6 +309,7 @@ define ( 'ABOOK_FLAG_PENDING' , 0x0010);
define ( 'ABOOK_FLAG_UNCONNECTED', 0x0020);
define ( 'ABOOK_FLAG_SELF' , 0x0080);
define ( 'ABOOK_FLAG_FEED' , 0x0100);
define ( 'ABOOK_FLAG_CENSORED' , 0x0200);
define ( 'MAIL_DELETED', 0x0001);

View file

@ -17,6 +17,7 @@ function abook_store_lowlevel($arr) {
'abook_connected' => ((array_key_exists('abook_connected',$arr)) ? $arr['abook_connected'] : NULL_DATE),
'abook_dob' => ((array_key_exists('abook_dob',$arr)) ? $arr['abook_dob'] : NULL_DATE),
'abook_flags' => ((array_key_exists('abook_flags',$arr)) ? $arr['abook_flags'] : 0),
'abook_censor' => ((array_key_exists('abook_censor',$arr)) ? $arr['abook_censor'] : 0),
'abook_blocked' => ((array_key_exists('abook_blocked',$arr)) ? $arr['abook_blocked'] : 0),
'abook_ignored' => ((array_key_exists('abook_ignored',$arr)) ? $arr['abook_ignored'] : 0),
'abook_hidden' => ((array_key_exists('abook_hidden',$arr)) ? $arr['abook_hidden'] : 0),
@ -159,6 +160,9 @@ function abook_toggle_flag($abook,$flag) {
case ABOOK_FLAG_IGNORED:
$field = 'abook_ignored';
break;
case ABOOK_FLAG_CENSORED:
$field = 'abook_censor';
break;
case ABOOK_FLAG_HIDDEN:
$field = 'abook_hidden';
break;

View file

@ -1488,8 +1488,16 @@ function prepare_body(&$item,$attach = false,$opts = false) {
call_hooks('prepare_body_init', $item);
$pixelation = floatval(get_pconfig($item['uid'],'system','content_pixelation',0.05));
$censored = (($item['author']['abook_censor'] || $item['owner']['abook_censor'])
? 'data-pixelate data-value="' . $pixelation . '" data-reveal="true" '
: ''
);
$s = '';
$photo = '';
$is_photo = ((($item['verb'] === ACTIVITY_POST) && ($item['obj_type'] === ACTIVITY_OBJ_PHOTO)) ? true : false);
if($is_photo) {
@ -1499,13 +1507,13 @@ function prepare_body(&$item,$attach = false,$opts = false) {
if(array_key_exists('url',$object) && is_array($object['url']) && array_key_exists(0,$object['url'])) {
// if original photo width is <= 640px prepend it to item body
if(array_key_exists('width',$object['url'][0]) && $object['url'][0]['width'] <= 640) {
$s .= '<div class="inline-photo-item-wrapper"><a href="' . zid(rawurldecode($object['id'])) . '" target="_blank" rel="nofollow noopener" ><img class="inline-photo-item" style="max-width:' . $object['url'][0]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['url'][0]['href'])) . '"></a></div>' . $s;
$s .= '<div class="inline-photo-item-wrapper"><a href="' . zid(rawurldecode($object['id'])) . '" target="_blank" rel="nofollow noopener" ><img $censored class="inline-photo-item" style="max-width:' . $object['url'][0]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['url'][0]['href'])) . '"></a></div>' . $s;
}
// if original photo width is > 640px make it a cover photo
if(array_key_exists('width',$object['url'][0]) && $object['url'][0]['width'] > 640) {
$scale = ((($object['url'][1]['width'] == 1024) || ($object['url'][1]['height'] == 1024)) ? 1 : 0);
$photo = '<a href="' . zid(rawurldecode($object['id'])) . '" target="_blank" rel="nofollow noopener"><img style="max-width:' . $object['url'][$scale]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['url'][$scale]['href'])) . '"></a>';
$photo = '<a href="' . zid(rawurldecode($object['id'])) . '" target="_blank" rel="nofollow noopener"><img $censored style="max-width:' . $object['url'][$scale]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['url'][$scale]['href'])) . '"></a>';
}
}
}
@ -1522,6 +1530,11 @@ function prepare_body(&$item,$attach = false,$opts = false) {
}
}
if ($censored) {
$s = str_replace('<img ', '<img ' . $censored, $s);
}
$event = (($item['obj_type'] === ACTIVITY_OBJ_EVENT) ? format_event_obj($item['obj']) : false);
// This is not the most pleasant UI element possible, but this is difficult to add to one of the templates.
@ -1529,7 +1542,7 @@ function prepare_body(&$item,$attach = false,$opts = false) {
// of code re-factoring to make that happen.
if($event['header'] && $item['resource_id']) {
$event['header'] .= '<i class="fa fa-asterisk" title="' . t('Added to your calendar') . '"></i>';
$event['header'] .= '<i class="fa fa-asterisk" title="' . t('Added to your calendar') . '"></i>' . '&nbsp;' . t('Added to your calendar');
}
$prep_arr = array(

View file

@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS `abook` (
`abook_connected` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`abook_dob` datetime NOT NULL DEFAULT '0001-01-01 00:00:00',
`abook_flags` int(11) NOT NULL DEFAULT 0 ,
`abook_censor` int(11) NOT NULL DEFAULT 0 ,
`abook_blocked` tinyint(4) NOT NULL DEFAULT 0 ,
`abook_ignored` tinyint(4) NOT NULL DEFAULT 0 ,
`abook_hidden` tinyint(4) NOT NULL DEFAULT 0 ,

View file

@ -23,7 +23,8 @@ CREATE TABLE "abook" (
"abook_updated" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
"abook_connected" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
"abook_dob" timestamp NOT NULL DEFAULT '0001-01-01 00:00:00',
"abook_flags" bigint NOT NULL DEFAULT '0',
"abook_censor" bigint NOT NULL DEFAULT '0',
"abook_blocked" smallint NOT NULL DEFAULT '0',
"abook_blocked" smallint NOT NULL DEFAULT '0',
"abook_ignored" smallint NOT NULL DEFAULT '0',
"abook_hidden" smallint NOT NULL DEFAULT '0',

View file

@ -0,0 +1,6 @@
root = true
[*.{js,json}]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

View file

@ -0,0 +1,7 @@
{
"extends": "eslint:recommended",
"env": {
"browser": true,
"jquery": true
}
}

22
library/pixelate.js/.gitattributes vendored Normal file
View file

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

3
library/pixelate.js/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.swp
node_modules
pixelate.min.js

View file

@ -0,0 +1,45 @@
pixelate.js
===
**pixelate.js** is a simple library and jQuery plugin to pixelate any set of images and optionally reveal them on hover.
[Demo here](http://43081j.github.io/pixelate/)
Usage
===
**pixelate.js** can be used with jQuery:
```javascript
$('img').pixelate();
```
Or without via HTML data attributes:
```html
<img src="test.jpg" width="200" height="200" data-pixelate>
```
Options
===
* `value` The percentage of pixelation to perform, a value between `0` and `1`
* `reveal` Reveal the image on hover and remain revealed if clicked
* `revealonclick` Reveal the image on click. When combined with `reveal`, it will remain revealed after being clicked.
These options may be specified by data tags, like so:
```html
<img src="img.jpg" data-pixelate data-value="0.5" data-reveal="false">
```
or by jQuery/JavaScript:
```javascript
$('img#myimage').pixelate({ value: 0.5, reveal: false });
```
License
===
MIT

124
library/pixelate.js/dist/pixelate.js vendored Normal file
View file

@ -0,0 +1,124 @@
/*
* pixelate.js
* 43081j
* Pixelate images with ease
* License: MIT
*/
(function (window, $) {
var pixelate = function() {
var defaults = {
value: 0.05,
reveal: true,
revealonclick: false
};
var options = arguments[0] || {};
var element = this;
var elementParent = element.parentNode;
if (typeof options !== 'object') {
options = { value: parseInt(arguments[0]) };
}
options = (function() {
var opts = {};
for (var k in defaults) {
if (element.hasAttribute('data-' + k)) {
opts[k] = element.getAttribute('data-' + k);
continue;
}
if (k in options) {
opts[k] = options[k];
continue;
}
opts[k] = defaults[k];
}
return opts;
})();
var imgWidth = element.width;
var imgHeight = element.height;
var revealed = false;
var canv = document.createElement('canvas');
canv.width = imgWidth;
canv.height = imgHeight;
var ctx = canv.getContext('2d');
ctx.mozImageSmoothingEnabled = false;
ctx.webkitImageSmoothingEnabled = false;
ctx.imageSmoothingEnabled = false;
var width = imgWidth * options.value;
var height = imgHeight * options.value;
ctx.drawImage(element, 0, 0, width, height);
ctx.drawImage(canv, 0, 0, width, height, 0, 0, canv.width, canv.height);
element.style.display = 'none';
elementParent.insertBefore(canv, element);
if (options.revealonclick !== false && options.revealonclick !== 'false') {
/*
* Reveal on click
*/
canv.addEventListener('click', function () {
revealed = !revealed;
if (revealed) {
ctx.drawImage(element, 0, 0, imgWidth, imgHeight);
} else {
ctx.drawImage(element, 0, 0, width, height);
ctx.drawImage(canv, 0, 0, width, height, 0, 0, canv.width, canv.height);
}
});
}
if (options.reveal !== false && options.reveal !== 'false') {
/*
* Reveal on hover
*/
canv.addEventListener('mouseenter', function () {
if (revealed) {
return;
}
ctx.drawImage(element, 0, 0, imgWidth, imgHeight);
});
canv.addEventListener('mouseleave', function () {
if (revealed) {
return;
}
ctx.drawImage(element, 0, 0, width, height);
ctx.drawImage(canv, 0, 0, width, height, 0, 0, canv.width, canv.height);
});
}
};
if (typeof $ === 'function') {
$.fn.extend({
pixelate: function() {
var args = arguments;
return this.each(function () {
pixelate.apply(this, args);
});
}
});
}
document.addEventListener('DOMContentLoaded', function () {
var img = document.querySelectorAll('img[data-pixelate]');
for (var i = 0; i < img.length; i++) {
img[i].addEventListener('load', function () {
pixelate.apply(this);
});
}
});
})(window, typeof jQuery === 'undefined' ? null : jQuery);

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Pixelate.js</title>
<style type="text/css">
img, canvas { border:1px dashed; }
</style>
</head>
<body>
<img src="http://i.imgur.com/E7iu3UI.jpg" width="630" height="583" data-pixelate>
<script src="../dist/pixelate.js"></script>
</body>
</html>

1158
library/pixelate.js/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,33 @@
{
"name": "pixelate.js",
"version": "1.0.3",
"description": "Pure JavaScript library to pixelate images and reveal on hover",
"main": "dist/pixelate.js",
"directories": {
"example": "examples"
},
"scripts": {
"build": "npm run lint && uglifyjs dist/pixelate.js -c -m -o pixelate.min.js",
"lint": "eslint dist/*.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/43081j/pixelate.js.git"
},
"keywords": [
"pixelate",
"jquery",
"reveal",
"image"
],
"author": "43081j",
"license": "MIT",
"bugs": {
"url": "https://github.com/43081j/pixelate.js/issues"
},
"homepage": "https://github.com/43081j/pixelate.js#readme",
"devDependencies": {
"eslint": "^4.18.2",
"uglify-js": "^3.3.14"
}
}

View file

@ -0,0 +1,21 @@
{
"name": "pixelate",
"version": "1.0.3",
"title": "Pixelate.js - Pixelate any image with ease",
"author": {
"name": "43081j",
"url": "https://43081j.github.com/"
},
"licenses": [
{
"type": "MIT",
"url": "http://opensource.org/licenses/MIT"
}
],
"dependencies": {
"jquery": ">=1.6"
},
"description": "Plugin to easily pixelate any images and optionally reveal them on hover/click.",
"keywords": ["pixelate", "censor", "hide", "reveal"],
"demo": "http://43081j.github.io/pixelate/"
}

View file

@ -828,6 +828,7 @@ function updateConvItems(mode,data) {
$('.item_' + submid_encoded).addClass('item-highlight');
}
$(document.body).trigger("sticky_kit:recalc");
}
@ -878,6 +879,11 @@ function collapseHeight() {
console.log('collapsed above viewport count: ' + i);
$(window).scrollTop(sval);
}
// pixelate any images from censored connections
$('img[data-pixelate]').pixelate();
}
function updateInit() {

View file

@ -6,12 +6,14 @@ head_add_css('/library/bootstrap-tagsinput/bootstrap-tagsinput.css');
head_add_css('/view/css/bootstrap-red.css');
head_add_css('/library/datetimepicker/jquery.datetimepicker.css');
head_add_css('/library/bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css');
require_once('view/php/theme_init.php');
head_add_js('/vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js');
head_add_js('/library/bootbox/bootbox.min.js');
head_add_js('/library/bootstrap-tagsinput/bootstrap-tagsinput.js');
head_add_js('/library/datetimepicker/jquery.datetimepicker.js');
head_add_js('/library/pixelate.js/pixelate.min.js');
head_add_js('/library/bootstrap-colorpicker/dist/js/bootstrap-colorpicker.js');

View file

@ -14,6 +14,7 @@
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" title="{{$tools.block.title}}" onclick="window.location.href='{{$tools.block.url}}'; return false;">{{$tools.block.label}}</a>
<a class="dropdown-item" href="#" title="{{$tools.ignore.title}}" onclick="window.location.href='{{$tools.ignore.url}}'; return false;">{{$tools.ignore.label}}</a>
<a class="dropdown-item" href="#" title="{{$tools.censor.title}}" onclick="window.location.href='{{$tools.censor.url}}'; return false;">{{$tools.censor.label}}</a>
<a class="dropdown-item" href="#" title="{{$tools.archive.title}}" onclick="window.location.href='{{$tools.archive.url}}'; return false;">{{$tools.archive.label}}</a> <a class="dropdown-item" href="#" title="{{$tools.hide.title}}" onclick="window.location.href='{{$tools.hide.url}}'; return false;">{{$tools.hide.label}}</a>
<a class="dropdown-item" href="#" title="{{$tools.delete.title}}" onclick="window.location.href='{{$tools.delete.url}}'; return false;">{{$tools.delete.label}}</a>
</div>