Commit 2bfb3d16 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #2595 The code should follow code guidelines

parent fa176000
...@@ -90,7 +90,6 @@ class acl extends plugin ...@@ -90,7 +90,6 @@ class acl extends plugin
} }
/* Users */ /* Users */
$ui = get_userinfo();
$ldap = $config->get_ldap_link(); $ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']); $ldap->cd($config->current['BASE']);
$ldap->search('(objectClass=gosaAccount)', array('uid', 'cn')); $ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
...@@ -145,11 +144,10 @@ class acl extends plugin ...@@ -145,11 +144,10 @@ class acl extends plugin
/* Objects */ /* Objects */
$tmp = session::global_get('plist'); $tmp = session::global_get('plist');
$plist = $tmp->info;
$cats = array(); $cats = array();
if (isset($this->parent) && $this->parent !== NULL) { if (isset($this->parent) && $this->parent !== NULL) {
$oc = array(); $oc = array();
foreach ($this->parent->by_object as $key => $obj) { foreach ($this->parent->by_object as $obj) {
$oc = array_merge($oc, $obj->objectclasses); $oc = array_merge($oc, $obj->objectclasses);
if (isset($obj->acl_category)) { if (isset($obj->acl_category)) {
$tmp = str_replace("/", "", $obj->acl_category); $tmp = str_replace("/", "", $obj->acl_category);
...@@ -242,8 +240,7 @@ class acl extends plugin ...@@ -242,8 +240,7 @@ class acl extends plugin
$this->loadAclEntry(); $this->loadAclEntry();
} }
foreach ($_POST as $name => $post) { foreach (array_keys($_POST) as $name) {
/* Actions... */ /* Actions... */
if (preg_match('/^acl_edit_.*_x/', $name)) { if (preg_match('/^acl_edit_.*_x/', $name)) {
$this->dialogState = 'create'; $this->dialogState = 'create';
...@@ -623,28 +620,21 @@ class acl extends plugin ...@@ -623,28 +620,21 @@ class acl extends plugin
*/ */
function sort_by_priority($list) function sort_by_priority($list)
{ {
$tmp = session::global_get('plist'); uasort($list,
$plist = $tmp->info; function ($a, $b)
asort($plist); {
$newSort = array(); $infos_a = pluglist::pluginInfos($a);
$infos_b = pluglist::pluginInfos($b);
foreach ($list as $name => $translation) { $pa = (isset($infos_a['plPriority'])?$infos_a['plPriority']:0);
$na = preg_replace("/^.*\//", "", $name); $pb = (isset($infos_b['plPriority'])?$infos_b['plPriority']:0);
$prio = 0; if ($pa == $pb) {
if (isset($plist[$na]['plPriority'])) { return 0;
$prio = $plist[$na]['plPriority'];
} }
return ($pa < $pb ? -1 : 1);
$newSort[$name] = $prio;
} }
);
asort($newSort); return $list;
$ret = array();
foreach ($newSort as $name => $prio) {
$ret[$name] = $list[$name];
}
return $ret;
} }
/*! /*!
......
...@@ -238,7 +238,7 @@ class plugin ...@@ -238,7 +238,7 @@ class plugin
{ {
/* Prepare saved attributes */ /* Prepare saved attributes */
$this->saved_attributes = $this->attrs; $this->saved_attributes = $this->attrs;
foreach ($this->saved_attributes as $index => $value) { foreach (array_keys($this->saved_attributes) as $index) {
if (is_numeric($index)) { if (is_numeric($index)) {
unset($this->saved_attributes[$index]); unset($this->saved_attributes[$index]);
continue; continue;
...@@ -260,7 +260,7 @@ class plugin ...@@ -260,7 +260,7 @@ class plugin
continue; continue;
} }
} }
unset($this->saved_attributes["$index"]["count"]); unset($this->saved_attributes[$index]["count"]);
} }
} }
...@@ -627,6 +627,40 @@ class plugin ...@@ -627,6 +627,40 @@ class plugin
return FALSE; return FALSE;
} }
/*! Brief Parse attrs template masks
*
* return an array with the final values of attributes
*/
static function tpl_parse_attrs($attrs)
{
foreach ($attrs as &$attr) {
foreach ($attr as $key => &$string) {
if (!is_numeric($key)) {
continue;
}
$string = self::tpl_parse_string($string, $attrs);
}
unset($string);
}
unset($attr);
return $attrs;
}
/*! Brief Parse template masks in a single string
*
* return the string with patterns replaced by their values
*/
static function tpl_parse_string($string, $attrs)
{
$offset = 0;
while (preg_match('/%([^%]+)%/', $string, $m, PREG_OFFSET_CAPTURE, $offset)) {
$replace = self::tpl_parse_mask($m[1][0], $attrs);
$replace = $replace[0];
$string = substr_replace($string, $replace, $m[0][1], strlen($m[0][0]));
$offset = $m[0][1] + strlen($replace);
}
return $string;
}
/*! /*!
* \brief Show header message for tab dialogs * \brief Show header message for tab dialogs
...@@ -806,13 +840,13 @@ class plugin ...@@ -806,13 +840,13 @@ class plugin
} }
$pwd = $this->config->get_credentials($this->config->current['ADMINPASSWORD']); $pwd = $this->config->get_credentials($this->config->current['ADMINPASSWORD']);
$r = ldap_bind($ds, $this->config->current['ADMINDN'], $pwd); ldap_bind($ds, $this->config->current['ADMINDN'], $pwd);
/* Fill data from LDAP */ /* Fill data from LDAP */
$new = array(); $new = array();
if ($sr = ldap_read($ds, LDAP::fix($src_dn), "objectClass=*")) { if ($sr = ldap_read($ds, LDAP::fix($src_dn), "objectClass=*")) {
if ($ei = ldap_first_entry($ds, $sr)) { if ($ei = ldap_first_entry($ds, $sr)) {
foreach ($attrs as $attr => $val) { foreach (array_keys($attrs) as $attr) {
if ($info = @ldap_get_values_len($ds, $ei, $attr)) { if ($info = @ldap_get_values_len($ds, $ei, $attr)) {
for ($i = 0; $i < $info['count']; $i++) { for ($i = 0; $i < $info['count']; $i++) {
if ($info['count'] == 1) { if ($info['count'] == 1) {
...@@ -936,8 +970,6 @@ class plugin ...@@ -936,8 +970,6 @@ class plugin
*/ */
private function rename($src_dn, $dst_dn) private function rename($src_dn, $dst_dn)
{ {
$start = microtime(1);
/* Try to move the source entry to the destination position */ /* Try to move the source entry to the destination position */
$ldap = $this->config->get_ldap_link(); $ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']); $ldap->cd($this->config->current['BASE']);
...@@ -1138,23 +1170,6 @@ class plugin ...@@ -1138,23 +1170,6 @@ class plugin
return $this->handle_hooks('PRE', $mode, $addAttrs); return $this->handle_hooks('PRE', $mode, $addAttrs);
} }
static protected function matchHookVars ($command, $addAttrs)
{
// Sort attributes by length, ensures correct replacement
$tmp = array();
foreach ($addAttrs as $name => $value) {
$tmp[$name] = strlen($name);
}
arsort($tmp);
// Now replace the placeholder
foreach ($tmp as $name => $len) {
$command = str_replace("%$name%", escapeshellarg($addAttrs[$name]), $command);
}
return $command;
}
/*! /*!
* \brief Calls external hooks which are defined for this plugin (fusiondirectory.conf) * \brief Calls external hooks which are defined for this plugin (fusiondirectory.conf)
* Replaces placeholder by class values of this plugin instance. * Replaces placeholder by class values of this plugin instance.
...@@ -1168,12 +1183,8 @@ class plugin ...@@ -1168,12 +1183,8 @@ class plugin
if ($command != "") { if ($command != "") {
// Walk trough attributes list and add the plugins attributes. // Walk trough attributes list and add the plugins attributes.
foreach ($plugin->attributes as $attr) { foreach ($plugin->attributes as $attr) {
if (is_array($plugin->$attr)) {
$addAttrs[$attr] = join('|', $plugin->$attr);
} else {
$addAttrs[$attr] = $plugin->$attr; $addAttrs[$attr] = $plugin->$attr;
} }
}
$ui = get_userinfo(); $ui = get_userinfo();
...@@ -1181,7 +1192,7 @@ class plugin ...@@ -1181,7 +1192,7 @@ class plugin
$addAttrs['dn'] = $plugin->dn; $addAttrs['dn'] = $plugin->dn;
$addAttrs['location'] = $config->current['NAME']; $addAttrs['location'] = $config->current['NAME'];
$command = self::matchHookVars($command, $addAttrs); $command = self::tpl_parse_string($command, $addAttrs);
// If there are still some %.. in our command, try to fill these with some other tab vars // If there are still some %.. in our command, try to fill these with some other tab vars
if (preg_match("/%/", $command)) { if (preg_match("/%/", $command)) {
...@@ -1190,17 +1201,13 @@ class plugin ...@@ -1190,17 +1201,13 @@ class plugin
foreach ($plugin->parent->by_object as $object) { foreach ($plugin->parent->by_object as $object) {
foreach ($object->attributes as $attr) { foreach ($object->attributes as $attr) {
if (!isset($addAttrs[$attr])) { if (!isset($addAttrs[$attr])) {
if (is_array($object->$attr)) {
$addAttrs[$attr] = join('|', $object->$attr);
} else {
$addAttrs[$attr] = $object->$attr; $addAttrs[$attr] = $object->$attr;
} }
} }
} }
} }
}
$command = self::matchHookVars($command, $addAttrs); $command = self::tpl_parse_string($command, $addAttrs);
} }
// If there are still some %.. in our command, try to fill these with some other class vars // If there are still some %.. in our command, try to fill these with some other class vars
...@@ -1222,7 +1229,7 @@ class plugin ...@@ -1222,7 +1229,7 @@ class plugin
} }
$addAttrs[$name] = $value; $addAttrs[$name] = $value;
} }
$command = self::matchHookVars($command, $addAttrs); $command = self::tpl_parse_string($command, $addAttrs);
} }
@DEBUG(DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute"); @DEBUG(DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
......
...@@ -54,9 +54,10 @@ class setup ...@@ -54,9 +54,10 @@ class setup
exit(); exit();
} }
foreach ($this->o_steps as $key => $step) { foreach ($this->o_steps as &$step) {
$this->o_steps[$key]->parent = &$this; $step->parent = &$this;
} }
unset($step);
} }
function execute() function execute()
...@@ -167,16 +168,17 @@ class setup ...@@ -167,16 +168,17 @@ class setup
function disable_steps_from($start) function disable_steps_from($start)
{ {
$found = FALSE; $found = FALSE;
foreach ($this->o_steps as $key => $step) { foreach ($this->o_steps as $key => &$step) {
if ($key == $start) { if ($key == $start) {
$found = TRUE; $found = TRUE;
} }
if ($found) { if ($found) {
$this->o_steps[$key]->set_enabled(FALSE); $step->set_enabled(FALSE);
$this->o_steps[$key]->set_completed(FALSE); $step->set_completed(FALSE);
} }
} }
unset($step);
} }
......
...@@ -144,7 +144,7 @@ class Step_Checks extends setup_step ...@@ -144,7 +144,7 @@ class Step_Checks extends setup_step
if ($IMGVER > 1.0) { if ($IMGVER > 1.0) {
$R = method_exists('imagick', 'getImageBlob'); $R = method_exists('imagick', 'getImageBlob');
} else { } else {
$R = is_callable("imagick_blob2image") || !empty($output); $R = is_callable("imagick_blob2image");
} }
$M = TRUE; $M = TRUE;
......
...@@ -60,7 +60,6 @@ class Step_Config2 extends setup_step ...@@ -60,7 +60,6 @@ class Step_Config2 extends setup_step
global $BASE_DIR; global $BASE_DIR;
/* Update snapshot values, with already collected values */ /* Update snapshot values, with already collected values */
foreach ($this->generic_settings as $key => $value) {
foreach (array("snapshot_base","snapshot_user","snapshot_server") as $attr) { foreach (array("snapshot_base","snapshot_user","snapshot_server") as $attr) {
foreach ($this->parent->captured_values as $replace_name => $replace_value) { foreach ($this->parent->captured_values as $replace_name => $replace_value) {
if (is_string($replace_value)) { if (is_string($replace_value)) {
...@@ -68,7 +67,6 @@ class Step_Config2 extends setup_step ...@@ -68,7 +67,6 @@ class Step_Config2 extends setup_step
} }
} }
} }
}
$smarty = get_smarty(); $smarty = get_smarty();
$smarty->assign("generic_settings", reverse_html_entities($this->generic_settings)); $smarty->assign("generic_settings", reverse_html_entities($this->generic_settings));
......
...@@ -79,14 +79,12 @@ class Step_Config3 extends setup_step ...@@ -79,14 +79,12 @@ class Step_Config3 extends setup_step
function execute() function execute()
{ {
global $BASE_DIR; global $BASE_DIR;
$cv = $this->parent->captured_values;
$smarty = get_smarty(); $smarty = get_smarty();
$smarty->assign("bool", array(FALSE => _("No"), TRUE => _("Yes"))); $smarty->assign("bool", array(FALSE => _("No"), TRUE => _("Yes")));
$smarty->assign("uniq_identifiers", array("entryCSN" => "entryCSN", $smarty->assign("uniq_identifiers", array("entryCSN" => "entryCSN",
"contextCSN" => "contextCSN" )); "contextCSN" => "contextCSN" ));
$smarty->assign("logging", $this->optional['logging']); $smarty->assign("logging", $this->optional['logging']);
$smarty->assign("optional", reverse_html_entities($this->optional)); $smarty->assign("optional", reverse_html_entities($this->optional));
foreach ($this->attributes as $attr) { foreach ($this->attributes as $attr) {
$smarty->assign($attr, reverse_html_entities($this->$attr)); $smarty->assign($attr, reverse_html_entities($this->$attr));
......
...@@ -136,7 +136,6 @@ class Step_Ldap extends setup_step ...@@ -136,7 +136,6 @@ class Step_Ldap extends setup_step
$filter = $this->resolve_filter; $filter = $this->resolve_filter;
/* Establish ldap connection */ /* Establish ldap connection */
$cv = $this->parent->captured_values;
$ldap_l = new LDAP("", "", $this->connection, FALSE, $this->tls); $ldap_l = new LDAP("", "", $this->connection, FALSE, $this->tls);
$ldap = new ldapMultiplexer($ldap_l); $ldap = new ldapMultiplexer($ldap_l);
$ldap->cd($this->base); $ldap->cd($this->base);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment