Skip to content

Commit

Permalink
Private tags netPhotoGraphics#1098
Browse files Browse the repository at this point in the history
implements tags that are private--only can be seen/used by someone with
tags rights.
  • Loading branch information
sbillard committed Mar 24, 2018
1 parent e2e5e9a commit f3ca900
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 68 deletions.
144 changes: 81 additions & 63 deletions zp-core/admin-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,12 @@ function getLanguageFlags() {
*/
function sortTagList($tagsort = 'alpha') {
global $_zp_admin_ordered_taglist;
if (zp_loggedin(TAGS_RIGHTS)) {
$private = '';
} else {
$private = ' AND (tags.private=0)';
}

if (is_null($_zp_admin_ordered_taglist)) {
switch ($tagsort) {
case 'language':
Expand All @@ -1438,14 +1444,15 @@ function sortTagList($tagsort = 'alpha') {
$order = '`name`';
break;
}
$masters = $translations = $them = $languages = array();
$sql = "SELECT DISTINCT tags.id, tags.name, tags.masterid, tags.language, (SELECT COUNT(*) FROM " . prefix('obj_to_tag') . " as object WHERE object.tagid = tags.id) AS count FROM " . prefix('tags') . " as tags ORDER BY $order, `masterid`";
$masters = $translations = $_zp_admin_ordered_taglist = $languages = array();
$sql = "SELECT DISTINCT tags.id, tags.name, tags.masterid, tags.language, tags.private, (SELECT COUNT(*) FROM " . prefix('obj_to_tag') .
' as object WHERE (object.tagid=tags.id)' . $private . ') AS count FROM ' . prefix('tags') . " as tags ORDER BY $order, `masterid`";
$tagresult = query($sql);
if ($tagresult) {
while ($tag = db_fetch_assoc($tagresult)) {
$tagname = mb_strtolower($tag['name']);
$lang = $tag['language'];
$them[$lang . $tagname] = array('tag' => $tag['name'], 'lang' => $lang, 'count' => $tag['count'], 'subtags' => NULL);
$_zp_admin_ordered_taglist[$lang . $tagname] = array('tag' => $tag['name'], 'lang' => $lang, 'count' => $tag['count'], 'subtags' => NULL, 'private' => $tag['private']);
if (is_null($tag['masterid'])) {
$masters[$tag['id']] = $lang . $tagname;
} else {
Expand All @@ -1456,23 +1463,21 @@ function sortTagList($tagsort = 'alpha') {
foreach ($translations as $master => $list) {
$subtags = array();
foreach ($list as $lang => $tagname) {
$subtags[$lang] = $them[$lang . $tagname];
unset($them[$lang . $tagname]);
$subtags[$lang] = $_zp_admin_ordered_taglist[$lang . $tagname];
unset($_zp_admin_ordered_taglist[$lang . $tagname]);
}
$them[$masters[$master]]['subtags'] = $subtags;
$_zp_admin_ordered_taglist[$masters[$master]]['subtags'] = $subtags;
}

if ($tagsort == 'mostused') {
arsort($counts, SORT_NUMERIC);
}
}

$_zp_admin_ordered_taglist = $them;
}
return $_zp_admin_ordered_taglist;
}

function tagListElement($postit, $class, $tagLC, $item, $lang, $count, $indent, $checked = false) {
function tagListElement($postit, $class, $tagLC, $item, $lang, $private, $count, $indent, $checked = false) {
global $_zp_language_flags, $_tagListIndex;
$listitem = $postit . postIndexEncode($item);
$flag = $_zp_language_flags[$lang];
Expand All @@ -1481,19 +1486,21 @@ function tagListElement($postit, $class, $tagLC, $item, $lang, $count, $indent,
<label class="displayinline">
<?php
if ($indent) {
echo '&nbsp;&nbsp';
echo '&nbsp;
&nbsp';
$indent = ' ' . $indent;
}
if (empty($indent)) {
$auto = ' onclick="$(\'.' . 'subto_' . $listitem . '\').prop(\'checked\', $(\'#' . $listitem . '\').prop(\'checked\'));"';
$auto = ' onclick = "$(\'.' . 'subto_' . $listitem . '\').prop(\'checked\', $(\'#' . $listitem . '\').prop(\'checked\'));"';
} else {
$auto = '';
}
?>
<input id="<?php echo $listitem; ?>" class="<?php echo $class . $indent; ?>" name="<?php echo 'tag_list_' . $postit . '[' . ++$_tagListIndex . ']'; ?>" type="checkbox" value="<?php echo html_encode($item); ?>"<?php
echo $auto;
if ($checked) {
echo ' checked="checked";';
echo ' checked = "checked";
';
}
?> />
<input type="hidden" name="<?php echo 'lang_list_' . $postit . '[' . $_tagListIndex . ']'; ?>" value="<?php echo html_encode($lang); ?>" />
Expand All @@ -1503,11 +1510,15 @@ function tagListElement($postit, $class, $tagLC, $item, $lang, $count, $indent,
<img src="<?php echo $flag; ?>" height="10" width="15" />
<?php
}
if (is_int($count)) {
echo html_encode($item) . ' [' . $count . ']';

if ($private) {
echo '<span style = "text-decoration: overline underline">' . html_encode($item) . '</span>';
} else {
echo html_encode($item);
}
if (is_int($count)) {
echo ' [' . $count . ']';
}
?>
</label>
</li>
Expand All @@ -1527,11 +1538,13 @@ function tagListElement($postit, $class, $tagLC, $item, $lang, $count, $indent,
*/
function tagSelector($that, $postit, $showCounts = false, $tagsort = 'alpha', $addnew = true, $resizeable = false, $class = 'checkTagsAuto') {
global $_zp_admin_ordered_taglist;
$admin = zp_loggedin(TAGS_RIGHTS);
if ((int) $addnew <= 1 && is_null($_zp_admin_ordered_taglist)) {
$them = sortTagList($that, $tagsort);
} else {
$them = $_zp_admin_ordered_taglist;
}

$flags = getLanguageFlags();

if ((int) $addnew == 2) {
Expand Down Expand Up @@ -1564,7 +1577,8 @@ function tagSelector($that, $postit, $showCounts = false, $tagsort = 'alpha', $a
minHeight: 120,
resize: function (event, ui) {
$(this).css("width", '');
$('#list_<?php echo $postit; ?>').height($('#resizable_<?php echo $postit; ?>').height());
$('#list_<?php echo $postit;
?>').height($('#resizable_<?php echo $postit; ?>').height());
}
})
});</script>
Expand Down Expand Up @@ -1595,23 +1609,27 @@ function tagSelector($that, $postit, $showCounts = false, $tagsort = 'alpha', $a
<?php
if (count($tags) > 0) {
foreach ($tags as $tag) {
tagListElement($postit, $class, mb_strtolower($tag), $tag, '', false, false, true);
if ($admin || empty($tag['private'])) {
tagListElement($postit, $class, mb_strtolower($tag), $tag, '', $tag['private'], false, false, true);
}
}
?>
<li><hr /></li>
<?php
}
foreach ($them as $tagitem) {
$item = $tagitem['tag'];
$tagLC = mb_strtolower($item);
tagListElement($postit, $class, $tagLC, $item, $tagitem['lang'], $showCounts ? $tagitem['count'] : false, false);
if (is_array($tagitem['subtags'])) {
$itemarray = $tagitem['subtags'];
ksort($itemarray);
foreach ($itemarray as $lang => $tagitem) {
$tag = $tagitem['tag'];
$LCtag = mb_strtolower($tag);
tagListElement($postit, $class, $LCtag, $tag, $lang, false, 'subto_' . $postit . postIndexEncode($item));
if ($admin || empty($tagitem['private'])) {
$tagLC = mb_strtolower($item);
tagListElement($postit, $class, $tagLC, $item, $tagitem['lang'], $tagitem['private'], $showCounts ? $tagitem['count'] : false, false);
if (is_array($tagitem['subtags'])) {
$itemarray = $tagitem['subtags'];
ksort($itemarray);
foreach ($itemarray as $lang => $tagitem) {
$tag = $tagitem['tag'];
$LCtag = mb_strtolower($tag);
tagListElement($postit, $class, $LCtag, $tag, $lang, $tagitem['private'], false, 'subto_' . $postit . postIndexEncode($item));
}
}
}
}
Expand Down Expand Up @@ -1845,7 +1863,7 @@ class="passignore<?php echo $suffix; ?> ignoredirty" autocomplete="off"
name="disclose_password<?php echo $suffix; ?>"
id="disclose_password<?php echo $suffix; ?>"
onclick="passwordClear('<?php echo $suffix; ?>');
togglePassword('<?php echo $suffix; ?>');" />
togglePassword('<?php echo $suffix; ?>');" />
<?php echo addslashes(gettext('Show')); ?>
</label>

Expand Down Expand Up @@ -2309,7 +2327,7 @@ class="passignore<?php echo $suffix; ?> ignoredirty" autocomplete="off"
} else {
?>
onclick="toggleAlbumMCR('<?php echo $prefix; ?>', '');
deleteConfirm('Delete-<?php echo $prefix; ?>', '<?php echo $prefix; ?>', deleteAlbum1);"
deleteConfirm('Delete-<?php echo $prefix; ?>', '<?php echo $prefix; ?>', deleteAlbum1);"
<?php
}
?> />
Expand Down Expand Up @@ -4305,30 +4323,30 @@ function printBulkActions($checkarray, $checkAll = false) {
<script type="text/javascript">
//<!-- <![CDATA[
function checkFor(obj) {
var sel = obj.options[obj.selectedIndex].value;
var mark;
switch (sel) {
var sel = obj.options[obj.selectedIndex].value;
var mark;
switch (sel) {
<?php
foreach ($colorboxBookmark as $key => $mark) {
?>
case '<?php echo $key; ?>':
mark = '<?php echo $mark; ?>';
break;
case '<?php echo $key; ?>':
mark = '<?php echo $mark; ?>';
break;
<?php
}
?>
default:
mark = false;
break;
default:
mark = false;
break;
}
if (mark) {
$.colorbox({
href: '#' + mark,
inline: true,
open: true,
close: '<?php echo gettext("ok"); ?>'
});
}
$.colorbox({
href: '#' + mark,
inline: true,
open: true,
close: '<?php echo gettext("ok"); ?>'
});
}
}
// ]]> -->
</script>
Expand Down Expand Up @@ -4721,27 +4739,27 @@ function stripTableRows($custom) {
function codeblocktabsJS() {
?>
<script type="text/javascript" charset="utf-8">
// <!-- <![CDATA[
$(function () {
var tabContainers = $('div.tabs > div');
$('.first').addClass('selected');
});
function cbclick(num, id) {
$('.cbx-' + id).hide();
$('#cb' + num + '-' + id).show();
$('.cbt-' + id).removeClass('selected');
$('#cbt' + num + '-' + id).addClass('selected');
}
// <!-- <![CDATA[
$(function () {
var tabContainers = $('div.tabs > div');
$('.first').addClass('selected');
});
function cbclick(num, id) {
$('.cbx-' + id).hide();
$('#cb' + num + '-' + id).show();
$('.cbt-' + id).removeClass('selected');
$('#cbt' + num + '-' + id).addClass('selected');
}

function cbadd(id, offset) {
var num = $('#cbu-' + id + ' li').size() - offset;
$('li:last', $('#cbu-' + id)).remove();
$('#cbu-' + id).append('<li><a class="cbt-' + id + '" id="cbt' + num + '-' + id + '" onclick="cbclick(' + num + ',' + id + ');" title="' + '<?php echo gettext('codeblock %u'); ?>'.replace(/%u/, num) + '">&nbsp;&nbsp;' + num + '&nbsp;&nbsp;</a></li>');
$('#cbu-' + id).append('<li><a id="cbp-' + id + '" onclick="cbadd(' + id + ',' + offset + ');" title="<?php echo gettext('add codeblock'); ?>">&nbsp;&nbsp;+&nbsp;&nbsp;</a></li>');
$('#cbd-' + id).append('<div class="cbx-' + id + '" id="cb' + num + '-' + id + '" style="display:none">' +
'<textarea name="codeblock' + num + '-' + id + '" class="codeblock" id="codeblock' + num + '-' + id + '" rows="40" cols="60"></textarea>' +
'</div>');
cbclick(num, id);
var num = $('#cbu-' + id + ' li').size() - offset;
$('li:last', $('#cbu-' + id)).remove();
$('#cbu-' + id).append('<li><a class="cbt-' + id + '" id="cbt' + num + '-' + id + '" onclick="cbclick(' + num + ',' + id + ');" title="' + '<?php echo gettext('codeblock %u'); ?>'.replace(/%u/, num) + '">&nbsp;&nbsp;' + num + '&nbsp;&nbsp;</a></li>');
$('#cbu-' + id).append('<li><a id="cbp-' + id + '" onclick="cbadd(' + id + ',' + offset + ');" title="<?php echo gettext('add codeblock'); ?>">&nbsp;&nbsp;+&nbsp;&nbsp;</a></li>');
$('#cbd-' + id).append('<div class="cbx-' + id + '" id="cb' + num + '-' + id + '" style="display:none">' +
'<textarea name="codeblock' + num + '-' + id + '" class="codeblock" id="codeblock' + num + '-' + id + '" rows="40" cols="60"></textarea>' +
'</div>');
cbclick(num, id);
}
// ]]> -->
</script>
Expand Down Expand Up @@ -5595,7 +5613,7 @@ function linkPickerIcon($obj, $id = NULL, $extra = NULL) {
}
?>
<a onclick="<?php echo $clickid; ?>$('.pickedObject').removeClass('pickedObject');
$('#<?php echo $iconid; ?>').addClass('pickedObject');<?php linkPickerPick($obj, $id, $extra); ?>" title="<?php echo gettext('pick source'); ?>">
$('#<?php echo $iconid; ?>').addClass('pickedObject');<?php linkPickerPick($obj, $id, $extra); ?>" title="<?php echo gettext('pick source'); ?>">
<?php echo CLIPBOARD; ?>
</a>
<?php
Expand Down
20 changes: 20 additions & 0 deletions zp-core/admin-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@
}
$action = gettext('Checked tags deleted');
break;
case 'private':
$sql = "UPDATE " . prefix('tags') . " SET `private`=0 WHERE `private`=1";
query($sql);
if (count($tags) > 0) {
$sql = "UPDATE " . prefix('tags') . " SET `private`=1 WHERE ";
foreach ($tags as $key => $tag) {
$sql .= "(`name`=" . (db_quote($tag)) . ' AND `language`=' . db_quote($langs[$key]) . ") OR ";
}
$sql = substr($sql, 0, strlen($sql) - 4);
query($sql);
}
$action = gettext('Checked tags marked private');
break;
case'assign':
if (count($tags) > 0) {
$tbdeleted = array();
Expand Down Expand Up @@ -246,6 +259,12 @@
<?php echo gettext("Delete checked tags"); ?>
</button>
</p>
<p class="buttons"<?php if (getOption('multi_lingual')) echo ' style="padding-bottom: 27px;"'; ?>>
<button type="submit" id="delete_tags" onclick="$('#tag_action').val('private'); this.form.submit();">
<?php echo KEY_RED; ?>
<?php echo gettext("Mark checked tags private"); ?>
</button>
</p>

<?php
if (getOption('multi_lingual')) {
Expand Down Expand Up @@ -286,6 +305,7 @@
} else {
echo gettext('Place a checkmark in the box for each tag you wish to delete then press the appropriate button. The brackets contain the number of times the tag appears.');
}
echo gettext('Tags that are <span style="text-decoration: overline underline">over/underlined</span> are private.');
?></p>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions zp-core/class-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ protected function searchFieldsAndTags($searchstring, $tbl, $sorttype, $sortdire
global $_zp_gallery;
$weights = $idlist = array();
$sql = $allIDs = NULL;
$admin = zp_loggedin(TAGS_RIGHTS);
$tagPattern = $this->tagPattern;
// create an array of [tag, objectid] pairs for tags
$tag_objects = array();
Expand Down Expand Up @@ -1169,6 +1170,9 @@ protected function searchFieldsAndTags($searchstring, $tbl, $sorttype, $sortdire
if (getOption('languageTagSearch')) {
$tagsql .= 'AND (t.language LIKE ' . db_quote(db_LIKE_escape($this->language) . '%') . ' OR t.language="") ';
}
if (!$admin) {
$tagsql .= 'AND (t.private=0) ';
}
$tagsql .= 'AND o.`type`="' . $tbl . '" AND (';
foreach ($searchstring as $singlesearchstring) {
switch ($singlesearchstring) {
Expand Down
2 changes: 1 addition & 1 deletion zp-core/databaseTemplate

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions zp-core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,13 @@ function getAllTagsUnique($language = NULL, $count = 1, $returnCount = NULL) {
} else {
$lang = ' AND (tag.language="" OR tag.language LIKE ' . db_quote(db_LIKE_escape($language) . '%') . ')';
}
if ($_zp_loggedin & TAGS_RIGHTS) {
$private = '';
} else {
$private = ' AND (tag.private=0)';
}

$sql = 'SELECT tag.name, count(DISTINCT tag.name, obj.type, obj.objectid) as count FROM ' . prefix('tags') . ' tag, ' . $source . ' obj WHERE (tag.id=obj.tagid) ' . $lang . ' GROUP BY tag.name';
$sql = 'SELECT tag.name, count(DISTINCT tag.name, obj.type, obj.objectid) as count FROM ' . prefix('tags') . ' tag, ' . $source . ' obj WHERE (tag.id=obj.tagid) ' . $lang . $private . ' GROUP BY tag.name';
$unique_tags = query($sql);

if ($unique_tags) {
Expand Down Expand Up @@ -1219,10 +1224,16 @@ function readTags($id, $tbl, $language) {
break;
}
}
if (zp_loggedin(TAGS_RIGHTS)) {
$private = '';
} else {
$private = ' AND tags.private=0';
}


$tags = array();

$sql = 'SELECT * FROM ' . prefix('tags') . ' AS tags, ' . prefix('obj_to_tag') . ' AS objects WHERE `type`="' . $tbl . '" AND `objectid`="' . $id . '" AND tagid=tags.id';
$sql = 'SELECT * FROM ' . prefix('tags') . ' AS tags, ' . prefix('obj_to_tag') . ' AS objects WHERE `type`="' . $tbl . '" AND `objectid`="' . $id . '" AND tagid=tags.id' . $private;

if ($language) {
$sql .= ' AND (tags.language="" OR tags.language LIKE ' . db_quote(db_LIKE_escape($language) . '%') . ')';
Expand Down

0 comments on commit f3ca900

Please sign in to comment.