<?php
ob_start ();
session_start ();
/**
* required files
*/
require_once ('class/odocclass.cls.php');
require_once ('class/odocfunc.cls.php');
require_once ('class/ohtml.cls.php');
require_once ('class/olocale.cls.php');
require_once ('localize.check.php');
/**
* default localization.
* well, I'm French... ;-)
*/
if (!isset ($_SESSION['locale']) || empty ($_SESSION['locale'])) {
$_SESSION['locale'] = 'francais';
}
$oloc = new olocale ($_SESSION['locale']);
/**
* checking directories existence
*/
if (!is_dir ('classes')) {
mkdir ('classes', 0644);
}
if (!is_dir ('fonctions')) {
mkdir ('fonctions', 0644);
}
if (!is_dir ('docs')) {
mkdir ('docs', 0644);
}
if (!is_dir ('docs/'.$oloc -> getLoc ())) {
mkdir ('docs/'.$oloc -> getLoc (), 0644);
}
if (!is_dir ('docs/'.$oloc -> getLoc ().'/classes')) {
mkdir ('docs/'.$oloc -> getLoc ().'/classes', 0644);
}
if (!is_dir ('docs/'.$oloc -> getLoc ().'/fonctions')) {
mkdir ('docs/'.$oloc -> getLoc ().'/fonctions', 0644);
}
?>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<link rel="stylesheet" type="text/css" href="css/maindoc.css" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h2 class="titre">ClassFuncDoc : <em><?php echo $oloc -> getMsg ('gui', 'app_title'); ?></em></h2>
<?php
/**
* here is the little form for the localization choice.
* it is outside because I thought it would be easier to add a language later, that way.
*/
require_once ('localize.form.html');
/**
* checking package creation requests
*/
if (isset ($_POST['pack_create']) && $_POST['pack_create'] === $oloc -> getMsg ('gui', 'app_package_tocreate') && !empty ($_POST['pack_nom'])) {
if (!is_dir ('classes/'.$_POST['pack_nom'])) {
mkdir ('classes/'.$_POST['pack_nom'], 0644);
} else {
$sError = $oloc -> getMsg ('errors', 'package_exists');
}
}
/**
* checking uploads requests
*/
if (isset ($_POST['uploadfile']) && $_POST['uploadfile'] === $oloc -> getMsg ('gui', 'app_upload') && !empty ($_FILES['fichierfunc'])) {
if (!@move_uploaded_file ($_FILES['fichierfunc']['tmp_name'], 'fonctions/'.basename ($_FILES['fichierfunc']['name']))) {
$sError = $oloc -> getMsg ('errors', 'failed_upload');
}
}
if (isset ($_POST['upload']) && $_POST['upload'] === $oloc -> getMsg ('gui', 'app_upload') && !empty ($_FILES['fichier'])) {
if (!@move_uploaded_file ($_FILES['fichier']['tmp_name'], 'classes/'.$_POST['pack'].'/'.basename ($_FILES['fichier']['name']))) {
$sError = $oloc -> getMsg ('errors', 'failed_upload');
}
}
/**
* checking doc generation requests
*/
if (isset ($_POST['documenterfunc']) && $_POST['documenterfunc'] === $oloc -> getMsg ('gui', 'app_document') && !empty ($_POST['funcs'])) {
require_once ('fonctions/'.$_POST['funcs']);
$aUser = get_defined_functions ();
try {
$doc = new odocfunc ($aUser['user'], $_POST['funcs']);
$sError = $oloc -> getMsg ('gui', 'app_document_created').$_POST['funcs'];
} catch (Exception $e) {
$sError = $oloc -> getMsg ('errors', 'failed_doc');
}
}
/**
* here is a difficult bit...
* we are checking package documentation requests.
* So, first, we scan the package folder, to find all the classes in it.
* Then, we parse with a regular expression the file to find the classes declarations (maybe several in a single file)
* We take the classname (instance name), ând the parent if any (via extends, or implements)
* We put in an array (aArbo) the name as the associative key, and for this key, its parent and its filename.
* A while loop to create another array (aIncs) to sort in a correct order the classes for the include : a parent MUST be included before all of his children...
* Let's include them ;-) But we make sure that the file is NOT already included from another path (if, for example, we want to document the ClassDoc classes...)
* Now, we make a little update on aArbo : if a class extends a NOT user-defined class (that is, an internal class), we do not have any file, so we cannot really parse it.
* Finally, we give our odocclass the package to analyze, and aArbo as a helper :-)
*/
if (isset ($_POST['documenter']) && $_POST['documenter'] === $oloc -> getMsg ('gui', 'app_document') && !empty ($_POST['package'])) {
$aDocs = scandir ('classes/'.$_POST['package']);
foreach ($aDocs as $clef => $obj) {
if ($obj !== '.' && $obj !== '..') {
$content = file_get_contents ('classes/'.$_POST['package'].'/'.$obj);
if (preg_match_all('@(class|interface)\s+([\w\d_]+)(\s+(extends|implements)\s+([\w\d_]+))?\s*{@im',$content,$res)) {
foreach ($res[2] as $clef => $val) {
if (!empty ($res[5][$clef])) {
$aParents[] = $res[5][$clef];
}
$aArbo[$res[2][$clef]]['parent'] = $res[5][$clef];
$aArbo[$res[2][$clef]]['file'] = $obj;
}
}
}
}
foreach ($aArbo as $files => $dump) {
$className = $files;
$aIncs[] = $aArbo[$className]['file'];
while (!empty ($aArbo[$className]['parent'])) {
$className = $aArbo[$className]['parent'];
$aIncs[] = isset ($aArbo[$className]['file'])?$aArbo[$className]['file']:'';
}
}
$aIncs = array_reverse ($aIncs);
foreach ($aIncs as $file) {
if (!empty ($file)) {
$aIncluded = get_included_files ();
foreach ($aIncluded as $clef => $finc) {
$aIncluded[$clef] = basename ($finc);
}
if (!in_array ($file, $aIncluded)) {
require_once ('classes/'.$_POST['package'].'/'.$file);
}
}
}
if (isset ($aParents) && !empty ($aParents)) {
foreach ($aParents as $parent) {
if (!array_key_exists ($parent, $aArbo)) {
$aArbo[$parent] = array ('parent' => '', 'file' => '');
}
}
}
try {
$doc = new odocclass ($_POST['package'], $aArbo);
$sError = $oloc -> getMsg ('gui', 'app_document_created').$_POST['package'];
} catch (Exception $e) {
$sError = $oloc -> getMsg ('errors', 'failed_instance');
}
}
/**
* html content starts here
*/
?>
<div class="menudoc">
<div class="clsdoc">
<ul><?php echo $oloc -> getMsg ('gui', 'app_package_list'); ?><br /><br />
<?php
$aDocs = scandir ('docs/'.$oloc -> getLoc ().'/classes');
foreach ($aDocs as $obj) {
if ($obj !== '.' && $obj !== '..') {
echo '<li><a class="other" href="docs/',$oloc -> getLoc (),'/classes/',$obj,'/index.html" title="', $oloc -> getMsg ('gui', 'app_doc_about'),' ',$obj, '" target="_blank">',$obj,'</a></li>';
}
}
?>
</ul>
</div>
<div class="funcdoc">
<ul><?php echo $oloc -> getMsg ('gui', 'app_func_list'); ?><br /><br />
<?php
$aDocs = scandir ('docs/'.$oloc -> getLoc ().'/fonctions');
foreach ($aDocs as $func) {
if ($func !== '.' && $func !== '..') {
echo '<li><a class="other" href="docs/',$oloc -> getLoc (),'/fonctions/',$func,'/',$func,'.html" title="', $oloc -> getMsg ('gui', 'app_doc_about'),' ',$func, '" target="_blank">',$func,'</a></li>';
}
}
?>
</ul>
</div>
</div>
<div class="formcontent">
<div class="cls">
<form method="post" action="">
<fieldset>
<legend><?php echo $oloc -> getMsg ('gui', 'app_package_create'); ?></legend>
<p>
<input type="text" id="nom" name="pack_nom" title="<?php echo $oloc -> getMsg ('gui', 'app_package_name'); ?>" />
</p>
<p>
<input type="submit" name="pack_create" value="<?php echo $oloc -> getMsg ('gui', 'app_package_tocreate'); ?>" title="<?php echo $oloc -> getMsg ('gui', 'app_package_tocreate'); ?>"/>
</p>
</fieldset>
</form>
<form method="post" action="" enctype="multipart/form-data">
<fieldset>
<legend><?php echo $oloc -> getMsg ('gui', 'app_class_upload'); ?></legend>
<p>
<input type="hidden" name="MAX_FILE_SIZE" value="80000000" />
<input type="file" name="fichier" title="<?php echo $oloc -> getMsg ('gui', 'app_class_fileupload'); ?>" />
</p>
<p>
<select name="pack">
<?php
$aDocs = scandir ('classes');
foreach ($aDocs as $obj) {
if ($obj !== '.' && $obj !== '..') {
echo '<option value="', $obj,'">',$obj,'</option>';
}
}
?>
</select>
</p>
<p>
<input type="submit" name="upload" value="<?php echo $oloc -> getMsg ('gui', 'app_upload'); ?>" title="<?php echo $oloc -> getMsg ('gui', 'app_class_toupload'); ?>"/>
</p>
</fieldset>
</form>
<form method="post" action="">
<fieldset>
<legend><?php echo $oloc -> getMsg ('gui', 'app_class_gendoc'); ?></legend>
<p>
<select name="package">
<?php
$aDocs = scandir ('classes');
foreach ($aDocs as $obj) {
if ($obj !== '.' && $obj !== '..') {
echo '<option value="', $obj,'">',$obj,'</option>';
}
}
?>
</select>
</p>
<p>
</p>
<p>
<input type="submit" name="documenter" value="<?php echo $oloc -> getMsg ('gui', 'app_document'); ?>" title="<?php echo $oloc -> getMsg ('gui', 'app_class_chosen_doc'); ?>"/>
</p>
</fieldset>
</form>
</div>
<br /><br />
<div class="func">
<form method="post" action="" enctype="multipart/form-data">
<fieldset>
<legend><?php echo $oloc -> getMsg ('gui', 'app_func_upload'); ?></legend>
<p>
<input type="hidden" name="MAX_FILE_SIZE" value="80000000" />
<input type="file" name="fichierfunc" title="<?php echo $oloc -> getMsg ('gui', 'app_func_fileupload'); ?>" />
</p>
<p>
<input type="submit" name="uploadfile" value="<?php echo $oloc -> getMsg ('gui', 'app_upload'); ?>" title="<?php echo $oloc -> getMsg ('gui', 'app_func_toupload'); ?>"/>
</p>
</fieldset>
</form>
<form method="post" action="">
<fieldset>
<legend><?php echo $oloc -> getMsg ('gui', 'app_func_gendoc'); ?></legend>
<p>
<select name="funcs">
<?php
$aDocs = scandir ('fonctions');
foreach ($aDocs as $func) {
if ($func !== '.' && $func !== '..') {
echo '<option value="', $func,'">',$func,'</option>';
}
}
?>
</select>
</p>
<p>
<input type="submit" name="documenterfunc" value="<?php echo $oloc -> getMsg ('gui', 'app_document'); ?>" title="<?php echo $oloc -> getMsg ('gui', 'app_func_chosen_doc'); ?>"/>
</p>
</fieldset>
</form>
</div>
</div>
<div class="error">
<?php
if (isset ($sError)) {
echo $sError;
}
?>
</div>
</html>
<?php
ob_end_flush ();
?>
|