Skip to content

Commit

Permalink
Merge pull request #22 from cccraig/minor-bug-fixes-and-enhancements
Browse files Browse the repository at this point in the history
Minor bug fixes and enhancements
  • Loading branch information
cccraig authored Aug 29, 2021
2 parents 60fe337 + 9d705f1 commit a9308bb
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 54 deletions.
4 changes: 4 additions & 0 deletions css/admin_style.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,8 @@
position: absolute;
top: 0;
left: 0;
}

.mugshot-hidden-while-selecting {
display: none !important;
}
108 changes: 108 additions & 0 deletions include/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');

/*
* Creates the tagging user group and associates the current user with that group;
*/
function create_tag_group() {
// Checks to see if a taggers group exists.
$checkTaggerGroupQuery = "SELECT id FROM " . GROUPS_TABLE . " WHERE name='Taggers'";

$result = fetch_sql($checkTaggerGroupQuery, 'id', false);

if ($result == 0)
{
$makeTaggerGroupQuery = "INSERT INTO " . GROUPS_TABLE . ' (name) VALUES ("Taggers")';
pwg_query($makeTaggerGroupQuery);

$result = fetch_sql($checkTaggerGroupQuery, 'id', false);
}

$group_id = $result[0];

$user = $_SESSION['pwg_uid'];

// Determines if the taggers group is associated with the current user and, if not, associates it.
$checkUserAssociationQuery = "SELECT * FROM " . USER_GROUP_TABLE . " WHERE group_id=$group_id AND user_id=$user";

$association = fetch_sql($checkUserAssociationQuery, 'id', false);

if ($association == 0)
{
$makeUserAssociationQuery = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id) VALUES ('$group_id','$user')";

pwg_query($makeUserAssociationQuery);
}

// Updates mugshot configuration
$data = unserialize(conf_get_param(MUGSHOT_ID));

$data['groups'] = array_unique(array_push($data['groups'], $group_id));

conf_update_param(MUGSHOT_ID, pwg_db_real_escape_string(serialize($data)));
}

/*
* Creates the drop trigger to clear database values
*/
function create_tag_drop_trigger() {
$deleteTriggerQuery = "DROP TRIGGER IF EXISTS `sync_mug_shot`;";

pwg_query($deleteTriggerQuery);

// [mysql error 1419] You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
// This query is silently failing.
$makeTriggerQuery = "CREATE TRIGGER `sync_mug_shot`
AFTER DELETE ON ".TAGS_TABLE."
FOR EACH ROW DELETE FROM face_tag_positions
WHERE face_tag_positions.tag_id = old.id";

pwg_query($makeTriggerQuery);
}

/*
* Creates the MugShot face tag table with all data columns required for resizing.
*/
function create_facetag_table() {
$configQuery = 'INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) VALUES ("MugShot","","MugShot configuration values");';

pwg_query($configQuery);

$createTableQuery = 'CREATE TABLE IF NOT EXISTS `face_tag_positions` (
`image_id` mediumint(8) unsigned NOT NULL default "0",
`tag_id` smallint(5) unsigned NOT NULL default "0",
`top` float unsigned NOT NULL default "0",
`lft` float unsigned NOT NULL default "0",
`width` float unsigned NOT NULL default "0",
`height` float unsigned NOT NULL default "0",
`image_width` float unsigned NOT NULL default "0",
`image_height` float unsigned NOT NULL default "0",
PRIMARY KEY (`image_id`,`tag_id`)
)';

pwg_query($createTableQuery);
}

/*
* Fetches Sql
*/
function fetch_sql($sql, $col, $ser) {
$result = pwg_query($sql);

while ($row = pwg_db_fetch_assoc($result)) {
$data[] = $row;
}

if (!isset($data)) {
$data = 0;
} else {
if($col !== false) {
$data = array_column($data, $col);
}
}

return ($ser) ? json_encode($data) : $data;
}

?>
18 changes: 17 additions & 1 deletion js/admin_mug.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,25 @@ function beginCapture(e) {
MugShot.selecting = true;
MugShot.img.addEventListener('mousemove', updateCapture);
MugShot.img.addEventListener('mouseup', haltCapture);

// left top height width
var frame = {
'lft': e.pageX - MugShot.offset.left,
'top': e.pageY - MugShot.offset.top,
'height': 5,
'width': 5,
};

MugShot.createBoundingBox(frame);
// MugShot.createBoundingBox(e.pageX - MugShot.offset.left, e.pageY - MugShot.offset.top, 5, 5);

// Hide all the frames while we select the new one. Keeps them from interfering.
for (let index = 0; index < MugShot.mugs.length - 1; index++) {
MugShot.mugs[index].frame.el.classList.toggle('mugshot-hidden-while-selecting');
MugShot.mugs[index].name.el.classList.toggle('mugshot-hidden-while-selecting');
}

MugShot.mugs[MugShot.cfi].frame.el.classList.toggle('mugshot-active');

MugShot.toggleSubmitBtn('on');
}
}
Expand All @@ -441,6 +450,13 @@ function haltCapture(e) {
MugShot.img.removeEventListener('mouseup', haltCapture, false);
MugShot.mugs[MugShot.cfi].frame.el.ondblclick = updateBoundingBox;
MugShot.mugs[MugShot.cfi].frame.el.classList.toggle('mugshot-mousetrap');

// Done capturing so re-show the other mugshot frames
for (let index = 0; index < MugShot.mugs.length - 1; index++) {
MugShot.mugs[index].frame.el.classList.toggle('mugshot-hidden-while-selecting');
MugShot.mugs[index].name.el.classList.toggle('mugshot-hidden-while-selecting');
}

var pos = MugShot.setBoundingBoxPosition(e.pageX - MugShot.offset.left, e.pageY - MugShot.offset.top);
MugShot.mugs[MugShot.cfi].frame.left = pos[0];
MugShot.mugs[MugShot.cfi].frame.top = pos[1];
Expand Down
4 changes: 4 additions & 0 deletions language/en_UK/plugin.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@
$lang['Groups'] = 'Groups';
$lang['Type in a search term'] = 'Type in a search term';
$lang['The following groups can use MugShot to tag people'] = 'The following groups can use MugShot to tag people';
$lang['MugShot to crop tagged faces from photos'] = 'MugShot to crop tagged faces from photos';
$lang['ALLOW'] = 'ALLOW';
$lang['DO NOT ALLOW'] = 'DO NOT ALLOW';
$lang['Maximum number of tags to load client side for auto complete functionality'] = 'Maximum number of tags to load client side for auto complete functionality';
4 changes: 4 additions & 0 deletions language/en_US/plugin.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@
$lang['Groups'] = 'Groups';
$lang['Type in a search term'] = 'Type in a search term';
$lang['The following groups can use MugShot to tag people'] = 'The following groups can use MugShot to tag people';
$lang['MugShot to crop tagged faces from photos'] = 'MugShot to crop tagged faces from photos';
$lang['ALLOW'] = 'ALLOW';
$lang['DO NOT ALLOW'] = 'DO NOT ALLOW';
$lang['Maximum number of tags to load client side for auto complete functionality'] = 'Maximum number of tags to load client side for auto complete functionality';
36 changes: 11 additions & 25 deletions main.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
add_event_handler('loc_begin_page_header', 'mugshot_files', 40, 2);
add_event_handler('loc_end_picture', 'mugshot_button');

/*
* Include custom helper functions
*/
include_once(MUGSHOT_PATH . 'include/helpers.php');

/*
* Conditional Logic for groups
Expand Down Expand Up @@ -84,28 +88,6 @@
}


/*
* Fetches Sql
*/
function fetch_sql($sql, $col, $ser) {
$result = pwg_query($sql);

while ($row = pwg_db_fetch_assoc($result)) {
$data[] = $row;
}

if (!isset($data)) {
$data = 0;
} else {
if($col !== false) {
$data = array_column($data, $col);
}
}

return ($ser) ? json_encode($data) : $data;
}


/*
* Loads translations
*/
Expand Down Expand Up @@ -161,8 +143,8 @@ function query_mugshot_groups() {
/*
* Queries all tags in database
*/
function defined_tags() {
$sql = 'SELECT name FROM ' . TAGS_TABLE . ' ORDER BY lastmodified ASC LIMIT 100;';
function defined_tags($max_tags) {
$sql = 'SELECT name FROM ' . TAGS_TABLE . " ORDER BY lastmodified ASC LIMIT $max_tags;";

$x = fetch_sql($sql, 'name', false);

Expand Down Expand Up @@ -253,10 +235,14 @@ function insert_tag_list() {

global $template;

$plugin_config = unserialize(conf_get_param(MUGSHOT_ID));

$max_tags = $plugin_config['max_tags'] ?? 500;

/*
* Array of tags
*/
$template -> assign('MUGSHOT_TAG_LIST', defined_tags());
$template -> assign('MUGSHOT_TAG_LIST', defined_tags($max_tags));

/*
* Specify the tag list template file
Expand Down
40 changes: 17 additions & 23 deletions maintain.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');

/*
* Plugin Constants
*/
defined('MUGSHOT_ID') or define('MUGSHOT_ID', basename(dirname(__FILE__)));
defined('MUGSHOT_PATH') or define('MUGSHOT_PATH' , PHPWG_PLUGINS_PATH . MUGSHOT_ID . '/');

/*
* Include custom helper functions
*/
include_once(MUGSHOT_PATH . 'include/helpers.php');

/**
* This class is used to expose maintenance methods to the plugins manager
Expand All @@ -26,38 +36,22 @@ function __construct($plugin_id)
*/
function install($plugin_version, &$errors=array())
{
$configQuery = 'INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment) VALUES ("MugShot","","MugShot configuration values");';

$createTableQuery = 'CREATE TABLE IF NOT EXISTS `face_tag_positions` (
`image_id` mediumint(8) unsigned NOT NULL default "0",
`tag_id` smallint(5) unsigned NOT NULL default "0",
`top` float unsigned NOT NULL default "0",
`lft` float unsigned NOT NULL default "0",
`width` float unsigned NOT NULL default "0",
`height` float unsigned NOT NULL default "0",
`image_width` float unsigned NOT NULL default "0",
`image_height` float unsigned NOT NULL default "0",
PRIMARY KEY (`image_id`,`tag_id`)
)';

$deleteTriggerQuery = "DROP TRIGGER IF EXISTS `sync_mug_shot`;";
// Create the table to store face vector information
create_facetag_table();

$makeTriggerQuery = "CREATE TRIGGER `sync_mug_shot`
AFTER DELETE ON ".TAGS_TABLE."
FOR EACH ROW DELETE FROM face_tag_positions
WHERE face_tag_positions.tag_id = old.id";
// Create the trigger to automatically clean tag references when tags are removed.
create_tag_drop_trigger();

pwg_query($configQuery);
pwg_query($createTableQuery);
pwg_query($deleteTriggerQuery);
pwg_query($makeTriggerQuery);
// Create the tagging user group and associate the current user.
create_tag_group();

$this->installed = true;
}

function deactivate()
{
// Do nothing
create_tag_group();
}

function update($old_version, $new_version, &$errors=array())
Expand Down
24 changes: 19 additions & 5 deletions template/admin.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
input[type="radio"] {
margin-right: 10px;
}
.tagbox {
width:581px;
height:1.25em;
padding:5px 8px 2px;
border:1px solid #787777a6;
margin-right:25px;
background: white;
}
{/literal}{/html_style}

{combine_script id='LocalStorageCache' load='footer' path='admin/themes/default/js/LocalStorageCache.js'}
Expand Down Expand Up @@ -57,17 +65,23 @@ jQuery(document).ready(function() {
{/if}
</p>

<p><br>
<label for="max_tags">
<strong>{'Maximum number of tags to load client side for auto complete functionality'|@translate}</strong><br><br>
<input id="max_tags" type="text" size="2" maxlength="3" name="max_tags" value="{$max_tags|default:'500'}" class="tagbox nice">
</p>

<!-- Enable automatic cropping of tagged faces -->
<p><br>
<label for="autotag">
<strong>{'Enable cropping of faces for automated tagging'|@translate}</strong><br>
<i>This requires ImageMagick to be installed, including the PHP plugin</i><br><br>
<i>{'This requires ImageMagick to be installed, including the PHP plugin'|@translate}</i><br><br>
{if $autotag }
<input type="radio" id="autotag1" name="autotag" value="1" checked /><b><i>ALLOW</i></b> MugShot to crop tagged faces from photos<br>
<input type="radio" id="autotag2" name="autotag" value="0"/><b><i>DO NOT ALLOW</i></b> MugShot to crop tagged faces from photos<br>
<input type="radio" id="autotag1" name="autotag" value="1" checked /><b><i>{'ALLOW'|@translate}</i></b> {'MugShot to crop tagged faces from photos'|@translate}<br>
<input type="radio" id="autotag2" name="autotag" value="0"/><b><i>D{'DO NOT ALLOW'|@translate}</i></b> {'MugShot to crop tagged faces from photos'|@translate}<br>
{else}
<input type="radio" id="autotag1" name="autotag" value="1"/><b><i>ALLOW</i></b> MugShot to crop tagged faces from photos<br>
<input type="radio" id="autotag2" name="autotag" value="0" checked /><b><i>DO NOT ALLOW</i></b> MugShot to crop tagged faces from photos<br>
<input type="radio" id="autotag1" name="autotag" value="1"/><b><i>{'ALLOW'|@translate}</i></b> {'MugShot to crop tagged faces from photos'|@translate}<br>
<input type="radio" id="autotag2" name="autotag" value="0" checked /><b><i>{'DO NOT ALLOW'|@translate}</i></b> {'MugShot to crop tagged faces from photos'|@translate}<br>
{/if}
</label>
</p><br>
Expand Down

0 comments on commit a9308bb

Please sign in to comment.