class_pluglist.inc 18.29 KiB
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2003-2010  Cajus Pollmeier
  Copyright (C) 2011-2019  FusionDirectory
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
/*!
 * \file class_pluglist.inc
 * Source code for the class pluglist
/*!
 * \brief This class contains all the function needed to make list
 * of plugin and manage them
 * \see class_plugin
class pluglist
  var $menu           = '';
  protected $iconmenu = '';
  /*!
   * \brief The plInfo result for all plugin, using class as key.
   * Contains the plugin index in 'INDEX' and the path in 'PATH'
  var $info             = [];
  /*!
   * \brief Foreign references on DNs
  var $dnForeignRefs = [];
  /*!
   * \brief Using the plugin index as a key, the class of the plugin.
  var $dirlist          = [];
  /*!
   * \brief List plugin indexes of all plugin that the user have acl for
  protected $allowed_plugins  = [];
  protected $silly_cache      = [];
  /*!
   * \brief List the plugins
  function __construct ()
    global $class_mapping;
    /* Fill info part of pluglist */
    $classes = get_declared_classes();
    /* To avoid plugins changing index when reloading */
    sort($classes);
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
$index = 0; $depends_infos = []; $conflicts_infos = []; $foreign_refs = []; foreach ($classes as $cname) { $cmethods = get_class_methods($cname); if (in_array_ics('plInfo', $cmethods)) { $infos = call_user_func([$cname, 'plInfo']); if (empty($infos)) { continue; } if (is_subclass_of($cname, 'simpleService')) { $infos['plSelfModify'] = FALSE; /* services are not part of any objectType */ unset($infos['plObjectType']); $infos['plCategory'] = ['server']; } else { if (!isset($infos['plSelfModify'])) { $infos['plSelfModify'] = FALSE; } } if (isset($class_mapping[$cname])) { $infos['PATH'] = dirname($class_mapping[$cname]); } if (isset($infos['plDepends'])) { $depends_infos[] = $cname; } if (isset($infos['plConflicts'])) { $conflicts_infos[] = $cname; } if (isset($infos['plForeignKeys'])) { foreach ($infos['plForeignKeys'] as $ofield => &$pfks) { if (!is_array($pfks)) { $pfks = [$pfks]; } if (!is_array($pfks[0])) { $pfks = [$pfks]; } foreach ($pfks as &$pfk) { $class = $pfk[0]; if (isset($pfk[1])) { $field = $pfk[1]; } else { $field = 'dn'; $pfk[1] = $field; } $filter = NULL; if (isset($pfk[2])) { $filter = $pfk[2]; } if ($filter === NULL) { $filter = "$ofield=%oldvalue%"; } $pfk[2] = $filter; if (!isset($foreign_refs[$class])) { $foreign_refs[$class] = []; } if (!isset($foreign_refs[$class][$field])) { $foreign_refs[$class][$field] = []; } $foreign_refs[$class][$field][] = [$cname, $ofield, $filter]; if ($field == 'dn') { $this->dnForeignRefs[] = [$cname, $ofield, $filter, (isset($pfk[3]) ? $pfk[3] : "$ofield=*%oldvalue%")]; } } unset($pfk); } unset($pfks); } else {
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
$infos['plForeignKeys'] = []; } if (!isset($infos['plProvidedAcls'])) { $infos['plProvidedAcls'] = []; } if (!isset($infos['plCategory'])) { $infos['plCategory'] = []; } if (!isset($infos['plTitle']) && isset($infos['plShortName'])) { $infos['plTitle'] = $infos['plShortName']; } if (!empty($infos['plObjectClass']) && !isset($infos['plFilter'])) { if (count($infos['plObjectClass']) == 1) { $infos['plFilter'] = '(objectClass='.$infos['plObjectClass'][0].')'; } else { $infos['plFilter'] = '(&(objectClass='.implode(')(objectClass=', $infos['plObjectClass']).'))'; } } if (isset($infos['plFilter'])) { $infos['plFilterObject'] = ldapFilter::parse($infos['plFilter']); } if (isset($infos['plObjectType']) && !isset($infos['plPriority']) && !is_numeric(key($infos['plObjectType']))) { /* Set main tab priority to 0 */ $infos['plPriority'] = 0; } $infos['plForeignRefs'] = []; $infos['INDEX'] = $index; $this->info[$cname] = $infos; $this->dirlist[$index++] = $cname; } } foreach ($depends_infos as $cname) { foreach ($this->info[$cname]['plDepends'] as $depend) { if (isset($this->info[$depend])) { if (isset($this->info[$depend]['plDepending'])) { $this->info[$depend]['plDepending'][] = $cname; } else { $this->info[$depend]['plDepending'] = [$cname]; } } else { trigger_error("$cname depends of the inexisting plugin $depend"); } } } foreach ($conflicts_infos as $cname) { foreach ($this->info[$cname]['plConflicts'] as $conflict) { if (isset($this->info[$conflict])) { if (isset($this->info[$conflict]['plConflicts'])) { if (!in_array($cname, $this->info[$conflict]['plConflicts'])) { $this->info[$conflict]['plConflicts'][] = $cname; } } else { $this->info[$conflict]['plConflicts'] = [$cname]; } } } } foreach ($foreign_refs as $cname => $refs) { if (isset($this->info[$cname])) { $this->info[$cname]['plForeignRefs'] = $refs; } } /* Provide field for 'all' */ $this->info['all'] = []; $this->info['all']['plProvidedAcls'] = []; $this->info['all']['plDescription'] = _("All objects in this category"); $this->info['all']['plSelfModify'] = FALSE;