Commit 79bb6a14 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 6177ad6b
......@@ -90,7 +90,6 @@ class acl extends plugin
}
/* Users */
$ui = get_userinfo();
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
$ldap->search('(objectClass=gosaAccount)', array('uid', 'cn'));
......@@ -144,15 +143,14 @@ class acl extends plugin
}
/* Objects */
$tmp = session::global_get('plist');
$plist = $tmp->info;
$cats = array();
$tmp = session::global_get('plist');
$cats = array();
if (isset($this->parent) && $this->parent !== NULL) {
$oc = array();
foreach ($this->parent->by_object as $key => $obj) {
foreach ($this->parent->by_object as $obj) {
$oc = array_merge($oc, $obj->objectclasses);
if (isset($obj->acl_category)) {
$tmp = str_replace("/", "", $obj->acl_category);
$tmp = str_replace("/", "", $obj->acl_category);
$cats[$tmp] = $tmp;
}
}
......@@ -242,8 +240,7 @@ class acl extends plugin
$this->loadAclEntry();
}
foreach ($_POST as $name => $post) {
foreach (array_keys($_POST) as $name) {
/* Actions... */
if (preg_match('/^acl_edit_.*_x/', $name)) {
$this->dialogState = 'create';
......@@ -623,28 +620,21 @@ class acl extends plugin
*/
function sort_by_priority($list)
{
$tmp = session::global_get('plist');
$plist = $tmp->info;
asort($plist);
$newSort = array();
foreach ($list as $name => $translation) {
$na = preg_replace("/^.*\//", "", $name);
$prio = 0;
if (isset($plist[$na]['plPriority'])) {
$prio = $plist[$na]['plPriority'];
uasort($list,
function ($a, $b)
{
$infos_a = pluglist::pluginInfos($a);
$infos_b = pluglist::pluginInfos($b);
$pa = (isset($infos_a['plPriority'])?$infos_a['plPriority']:0);
$pb = (isset($infos_b['plPriority'])?$infos_b['plPriority']:0);
if ($pa == $pb) {
return 0;
}
return ($pa < $pb ? -1 : 1);
}
);
$newSort[$name] = $prio;
}
asort($newSort);
$ret = array();
foreach ($newSort as $name => $prio) {
$ret[$name] = $list[$name];
}
return $ret;
return $list;
}
/*!
......
......@@ -237,7 +237,7 @@ class plugin
{
/* Prepare saved attributes */
$this->saved_attributes = $this->attrs;
foreach ($this->saved_attributes as $index => $value) {
foreach (array_keys($this->saved_attributes) as $index) {
if (is_numeric($index)) {
unset($this->saved_attributes[$index]);
continue;
......@@ -259,7 +259,7 @@ class plugin
continue;
}
}
unset($this->saved_attributes["$index"]["count"]);
unset($this->saved_attributes[$index]["count"]);
}
}
......@@ -807,13 +807,7 @@ class plugin
if (!is_numeric($key)) {
continue;
}
$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);
}
$string = self::tpl_parse_string($string, $attrs);
}
unset($string);
}
......@@ -821,6 +815,22 @@ class plugin
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
*
......@@ -967,13 +977,13 @@ class plugin
}
$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 */
$new = array();
if ($sr = ldap_read($ds, LDAP::fix($src_dn), "objectClass=*")) {
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)) {
for ($i = 0; $i < $info['count']; $i++) {
if ($info['count'] == 1) {
......@@ -1097,8 +1107,6 @@ class plugin
*/
private function rename($src_dn, $dst_dn)
{
$start = microtime(1);
/* Try to move the source entry to the destination position */
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
......@@ -1299,23 +1307,6 @@ class plugin
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)
* Replaces placeholder by class values of this plugin instance.
......@@ -1329,11 +1320,7 @@ class plugin
if ($command != "") {
// Walk trough attributes list and add the plugins attributes.
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();
......@@ -1342,7 +1329,7 @@ class plugin
$addAttrs['dn'] = $plugin->dn;
$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 (preg_match("/%/", $command)) {
......@@ -1351,17 +1338,13 @@ class plugin
foreach ($plugin->parent->by_object as $object) {
foreach ($object->attributes as $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
......@@ -1383,7 +1366,7 @@ class plugin
}
$addAttrs[$name] = $value;
}
$command = self::matchHookVars($command, $addAttrs);
$command = self::tpl_parse_string($command, $addAttrs);
}
@DEBUG(DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
......
......@@ -420,33 +420,6 @@ class aclrole extends acl
return $smarty->fetch(get_template_path('acl_role.tpl', dirname(__FILE__)));
}
function sort_by_priority($list)
{
$tmp = session::get('plist');
$plist = $tmp->info;
asort($plist);
$newSort = array();
foreach ($list as $name => $translation) {
$na = preg_replace("/^.*\//", "", $name);
if (!isset($plist[$na]['plPriority'])) {
$prio = 0;
} else {
$prio = $plist[$na]['plPriority'];
}
$newSort[$name] = $prio;
}
asort($newSort);
$ret = array();
foreach ($newSort as $name => $prio) {
$ret[$name] = $list[$name];
}
return $ret;
}
function loadAclEntry($new = FALSE)
{
/* New entry gets presets... */
......
......@@ -54,9 +54,10 @@ class setup
exit();
}
foreach ($this->o_steps as $key => $step) {
$this->o_steps[$key]->parent = &$this;
foreach ($this->o_steps as &$step) {
$step->parent = &$this;
}
unset($step);
}
function execute()
......@@ -167,16 +168,17 @@ class setup
function disable_steps_from($start)
{
$found = FALSE;
foreach ($this->o_steps as $key => $step) {
foreach ($this->o_steps as $key => &$step) {
if ($key == $start) {
$found = TRUE;
}
if ($found) {
$this->o_steps[$key]->set_enabled(FALSE);
$this->o_steps[$key]->set_completed(FALSE);
$step->set_enabled(FALSE);
$step->set_completed(FALSE);
}
}
unset($step);
}
......
......@@ -142,9 +142,9 @@ class Step_Checks extends setup_step
$IMGVER = phpversion('imagick');
if ($IMGVER > 1.0) {
$R = method_exists('imagick', 'getImageBlob');
$R = method_exists('imagick', 'getImageBlob');
} else {
$R = is_callable("imagick_blob2image") || !empty($output);
$R = is_callable("imagick_blob2image");
}
$M = TRUE;
......
......@@ -60,12 +60,10 @@ class Step_Config2 extends setup_step
global $BASE_DIR;
/* 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 ($this->parent->captured_values as $replace_name => $replace_value) {
if (is_string($replace_value)) {
$this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/", $replace_value, $this->generic_settings[$attr]);
}
foreach (array("snapshot_base","snapshot_user","snapshot_server") as $attr) {
foreach ($this->parent->captured_values as $replace_name => $replace_value) {
if (is_string($replace_value)) {
$this->generic_settings[$attr] = preg_replace("/%".$replace_name."%/", $replace_value, $this->generic_settings[$attr]);
}
}
}
......
......@@ -79,14 +79,12 @@ class Step_Config3 extends setup_step
function execute()
{
global $BASE_DIR;
$cv = $this->parent->captured_values;
$smarty = get_smarty();
$smarty->assign("bool", array(FALSE => _("No"), TRUE => _("Yes")));
$smarty->assign("uniq_identifiers", array("entryCSN" => "entryCSN",
"contextCSN" => "contextCSN" ));
$smarty->assign("logging", $this->optional['logging']);
$smarty->assign("logging", $this->optional['logging']);
$smarty->assign("optional", reverse_html_entities($this->optional));
foreach ($this->attributes as $attr) {
$smarty->assign($attr, reverse_html_entities($this->$attr));
......
......@@ -133,12 +133,11 @@ class Step_Ldap extends setup_step
function resolve_user()
{
$filter = $this->resolve_filter;
$filter = $this->resolve_filter;
/* Establish ldap connection */
$cv = $this->parent->captured_values;
$ldap_l = new LDAP("", "", $this->connection, FALSE, $this->tls);
$ldap = new ldapMultiplexer($ldap_l);
$ldap = new ldapMultiplexer($ldap_l);
$ldap->cd($this->base);
$ldap->search("(&(objectClass=person)(|(uid=".$filter.")(cn=".$filter.")))");
$tmp = array();
......
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