• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

setup/classes/class.ilCtrlStructureReader.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00033 class ilCtrlStructureReader
00034 {
00035         var $class_script;
00036         var $class_childs;
00037         var $executed;
00038 
00039         function ilCtrlStructureReader()
00040         {
00041                 $this->class_script = array();
00042                 $this->class_childs = array();
00043                 $this->executed = false;
00044         }
00045 
00046         function setErrorObject(&$err)
00047         {
00048                 $this->err_object =& $err;
00049         }
00050         
00054         function getStructure()
00055         {
00056                 $this->get_structure = true;
00057         }
00058                 
00059         function readStructure($a_force = false)
00060         {
00061 
00062                 if (!$this->get_structure && !$a_force)
00063                 {
00064                         return;
00065                 }
00066 
00067                 // only run one time per db_update request
00068                 if (!$this->executed)
00069                 {
00070                         $this->read(ILIAS_ABSOLUTE_PATH);
00071                         $this->store();
00072                         $this->executed = true;
00073                 }
00074                 
00075                 // read module information
00076                 // not clear whether this is a good place for module reading info
00077                 // or not
00078                 require_once("../classes/class.ilCtrl.php");
00079                 $ctrl = new ilCtrl();
00080                 $ctrl->storeCommonStructures();
00081         }
00082 
00088         function read($a_cdir)
00089         {
00090                 global $ilDB, $lng;
00091                 
00092                 // check wether $a_cdir is a directory
00093                 if (!@is_dir($a_cdir))
00094                 {
00095                         return false;
00096                 }
00097 
00098                 // read current directory
00099                 $dir = opendir($a_cdir);
00100 
00101                 while($file = readdir($dir))
00102                 {
00103                         if ($file != "." and
00104                                 $file != "..")
00105                         {
00106                                 // directories
00107                                 if (@is_dir($a_cdir."/".$file))
00108                                 {
00109                                         if ($a_cdir."/".$file != ILIAS_ABSOLUTE_PATH."/data")
00110                                         {
00111                                                 $this->read($a_cdir."/".$file);
00112                                         }
00113                                 }
00114 
00115                                 // files
00116                                 if (@is_file($a_cdir."/".$file))
00117                                 {
00118                                         if (eregi("^class.*php$", $file))
00119                                         {
00120                                                 $handle = fopen($a_cdir."/".$file, "r");
00121 //echo "<br>".$a_cdir."/".$file;
00122                                                 while (!feof($handle)) {
00123                                                         $line = fgets($handle, 4096);
00124                                                         
00125                                                         // handle @ilctrl_calls
00126                                                         $pos = strpos(strtolower($line), "@ilctrl_calls");
00127                                                         if (is_int($pos))
00128                                                         {
00129                                                                 $com = substr($line, $pos + 14);
00130                                                                 $pos2 = strpos($com, ":");
00131                                                                 if (is_int($pos2))
00132                                                                 {
00133                                                                         $com_arr = explode(":", $com);
00134                                                                         $parent = strtolower(trim($com_arr[0]));
00135                                                                         
00136                                                                         // check file duplicates
00137                                                                         if ($parent != "" && isset($this->class_script[$parent]) &&
00138                                                                                 $this->class_script[$parent] != $a_cdir."/".$file)
00139                                                                         {
00140                                                                                 // delete all class to file assignments
00141                                                                                 $q = "DELETE FROM ctrl_classfile";
00142                                                                                 $ilDB->query($q);
00143                                                                 
00144                                                                                 // delete all call entries
00145                                                                                 $q = "DELETE FROM ctrl_calls";
00146                                                                                 $ilDB->query($q);
00147                                                                                 
00148                                                                                 $this->err_object->raiseError(
00149                                                                                         sprintf($lng->txt("duplicate_ctrl"),
00150                                                                                                 $parent,
00151                                                                                                 $this->class_script[$parent],
00152                                                                                                 $a_cdir."/".$file)
00153                                                                                         , $this->err_object->MESSAGE);
00154                                                                         }
00155 
00156                                                                         $this->class_script[$parent] = $a_cdir."/".$file;
00157                                                                         $childs = explode(",", $com_arr[1]);
00158                                                                         foreach($childs as $child)
00159                                                                         {
00160                                                                                 $child = trim(strtolower($child));
00161                                                                                 if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
00162                                                                                 {
00163                                                                                         $this->class_childs[$parent][] = $child;
00164                                                                                 }
00165                                                                         }
00166                                                                 }
00167                                                         }
00168                                                         
00169                                                         // handle isCalledBy comments
00170                                                         $pos = strpos(strtolower($line), "@ilctrl_iscalledby");
00171                                                         if (is_int($pos))
00172                                                         {
00173                                                                 $com = substr($line, $pos + 19);
00174                                                                 $pos2 = strpos($com, ":");
00175                                                                 if (is_int($pos2))
00176                                                                 {
00177                                                                         $com_arr = explode(":", $com);
00178                                                                         $child = strtolower(trim($com_arr[0]));
00179 
00180                                                                         $parents = explode(",", $com_arr[1]);
00181                                                                         foreach($parents as $parent)
00182                                                                         {
00183                                                                                 $parent = trim(strtolower($parent));
00184                                                                                 if (!is_array($this->class_childs[$parent]) || !in_array($child, $this->class_childs[$parent]))
00185                                                                                 {
00186                                                                                         $this->class_childs[$parent][] = $child;
00187                                                                                 }
00188                                                                         }
00189                                                                 }
00190                                                         }
00191                                                 }
00192                                                 fclose($handle);
00193                                         }
00194                                 }
00195                         }
00196                 }
00197         }
00198 
00204         function store($a_cdir = "./..")
00205         {
00206                 global $ilDB;
00207 
00208                 // delete all class to file assignments
00209                 $q = "DELETE FROM ctrl_classfile";
00210                 $ilDB->query($q);
00211 
00212                 // delete all call entries
00213                 $q = "DELETE FROM ctrl_calls";
00214                 $ilDB->query($q);
00215 
00216                 foreach($this->class_script as $class => $script)
00217                 {
00218                         $file = substr($script, strlen(ILIAS_ABSOLUTE_PATH) + 1);
00219 
00220                         // store class to file assignment
00221                         $q = "INSERT INTO ctrl_classfile (class, file) VALUES".
00222                                 "(".$ilDB->quote($class).",".$ilDB->quote($file).")";
00223                         $ilDB->query($q);
00224 
00225                         if (is_array($this->class_childs[$class]))
00226                         {
00227                                 foreach($this->class_childs[$class] as $child)
00228                                 {
00229                                         // store call entry
00230                                         $q = "INSERT INTO ctrl_calls (parent, child) VALUES".
00231                                                 "(".$ilDB->quote($class).",".$ilDB->quote($child).")";
00232                                         $ilDB->query($q);
00233                                 }
00234                         }
00235                 }
00236 
00237         }
00238 
00239 }

Generated on Fri Dec 13 2013 17:57:03 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1