Skip to content

Commit

Permalink
update syntax and fix config saving issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cccraig committed Sep 4, 2021
1 parent a9308bb commit 6f0ab20
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
2 changes: 1 addition & 1 deletion admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
* Retrieve configuration variable.
*/
if (empty($_POST)) {
$data = unserialize(conf_get_param(MUGSHOT_ID));
$data = conf_get_param(MUGSHOT_ID);
} else {
$data = $_POST;
}
Expand Down
9 changes: 9 additions & 0 deletions include/config_default.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

$config_default = array (
'groups' => array (),
'max_tags' => '500',
'autotag' => '0',
)

?>
21 changes: 17 additions & 4 deletions include/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@

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() {
global $conf;

if (!isset($conf['MugShot'])):
include(dirname(__FILE__).'/config_default.inc.php');
conf_update_param('MugShot', $config_default);
load_conf_from_db();
endif;

$conf['MugShot'] = unserialize($conf['MugShot']);

// Checks to see if a taggers group exists.
$checkTaggerGroupQuery = "SELECT id FROM " . GROUPS_TABLE . " WHERE name='Taggers'";

Expand Down Expand Up @@ -35,12 +46,14 @@ function create_tag_group() {
pwg_query($makeUserAssociationQuery);
}

// Updates mugshot configuration
$data = unserialize(conf_get_param(MUGSHOT_ID));
// Note that array_push returns the index of the new array item.
array_push($conf['MugShot']['groups'], $group_id);

$conf['MugShot']['groups'] = array_unique($conf['MugShot']['groups']);

$data['groups'] = array_unique(array_push($data['groups'], $group_id));
conf_update_param(MUGSHOT_ID, $conf['MugShot']);

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

/*
Expand Down
21 changes: 15 additions & 6 deletions main.inc.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<?php
/*
Plugin Name: Mug Shot
Version: 2.0.0
Version: 2.0.2
Description: Improved face tagging for Piwigo
Plugin URI: http://piwigo.org/ext/extension_view.php?eid=867
Author: cccraig
Has Settings: true
Plugin URI: http://piwigo.org/ext/extension_view.php?eid=910
Author: ccraige90
Has Settings: webmaster
*/

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

global $conf;

if (!isset($conf['MugShot'])):
include(dirname(__FILE__).'/include/config_default.inc.php');
conf_update_param('MugShot', $config_default);
load_conf_from_db();
endif;

$conf['MugShot'] = unserialize($conf['MugShot']);

/*
* Plugin Constants
Expand All @@ -18,7 +27,7 @@
define('MUGSHOT_PATH' , PHPWG_PLUGINS_PATH . MUGSHOT_ID . '/');
define('MUGSHOT_ADMIN', get_root_url() . 'admin.php?page=plugin-' . MUGSHOT_ID);
define('MUGSHOT_BASE_URL', get_root_url() . 'admin.php?page=plugin-' . MUGSHOT_ID);
define('MUGSHOT_VERSION', '2.0.0');
define('MUGSHOT_VERSION', '2.0.2');
define('MUGSHOT_TABLE', '`face_tag_positions`');


Expand Down Expand Up @@ -48,7 +57,7 @@
$intersect = array();

if (count($current_user_groups) != 0) {
$plugin_config = unserialize(conf_get_param(MUGSHOT_ID));
$plugin_config = conf_get_param(MUGSHOT_ID);

$group_list = $plugin_config['groups'] ?? array();

Expand Down
2 changes: 0 additions & 2 deletions maintain.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ function install($plugin_version, &$errors=array())
function deactivate()
{
// Do nothing
create_tag_group();
}

function update($old_version, $new_version, &$errors=array())
Expand All @@ -71,5 +70,4 @@ function uninstall()
{
conf_delete_param('MugShot');
}

}

0 comments on commit 6f0ab20

Please sign in to comment.