选择显示字体大小

小巧的php文档生成类


   在项目开发中发现对php的文档缺少管理,别人写了一个,功能不多

<?php
/**
* 类名: doc
* 描述: 文档生成类
* 其他: 可以对目录进行过滤,设置好源目录后,请用绝对路径指定生成目录,模式可调,模式
* 1为常规类型,即以 斜线**开头,以*斜线 结束
* 2为扩展类型,凡是 斜线*开头以*斜线 结束的部分都将成为文档的一部分
*/
class doc
{
var &#36;docdirname;
var &#36;docdir;

/**
* 函数名称: doc()
* 函数功能: 构造
* 输入参数: none
* 函数返回值: 返回值说明
* 其它说明: 2004-10-13
*/
function doc()
{
&#36;this->docdirname = &quot;doc/&quot;;
}

/**
* 函数名称: createdoc(&#36;root,&#36;newdir,&#36;mode=&quot;1&quot;,&#36;filter=null)
* 函数功能: 创建文档
* 输入参数: &#36;root -------------- 源目录
&#36;newdir ----------- 目标目录
&#36;mode ------------- 模式,1为普通,2为扩展
&#36;filter ------------ 过滤目录
* 函数返回值: 返回值说明
* 其它说明: 2004-10-13
*/
function createdoc(&#36;root,&#36;newdir,&#36;mode=&quot;1&quot;,&#36;filter=null)
{
&#36;getarr = &#36;this->loopdir(&#36;root,&#36;filter);
&#36;i = 0;
&#36;this->createframe(&#36;newdir);
foreach(&#36;getarr as &#36;key=>&#36;val)
{
if(&#36;this->getphpfiles(&#36;val))
{
&#36;content = &#36;this->getcontent(&#36;val);
&#36;content = &#36;this->getdoc(&#36;content,&#36;mode);
&#36;filepath = &#36;this->setfilepath(&#36;val,&#36;root,&#36;newdir);
&#36;filedir = &#36;this->getfiledir(&#36;filepath);
&#36;this->mkdirs(&#36;filedir);
&#36;this->setdoc(&#36;filepath,&#36;content);
&#36;data[&#36;i][&#39;url&#39;] = &quot;&#36;filepath&quot;;
&#36;data[&#36;i][&#39;name&#39;] = &quot;&#36;val&quot;;
&#36;i++;
}
}
if(!empty(&#36;data))
{
&#36;this->createmenu(&#36;newdir,&#36;data);
&#36;this->redirect(&#36;this->docdir);
}
}

/**
* 函数名称: redirect(&#36;path)
* 函数功能: 转向
* 输入参数: &#36;path ---------------- 转向路径
* 函数返回值: 返回值说明
* 其它说明: 2004-10-13
*/
function redirect(&#36;path)
{
echo &quot;<a href=&quot;.&#36;path.&quot; target=&#39;_blank&#39;>生成文档成功,点击此处查看</a>&quot;;
}

/**
* 函数名称: loopdir(&#36;root,&#36;filter=null)
* 函数功能: 遍历目录
* 输入参数: &#36;root ------------------- 源目录
&#36;filter ----------------- 过滤
* 函数返回值: array
* 其它说明: 2004-10-13
*/
function loopdir(&#36;root,&#36;filter=null)
{
static &#36;getarr=array();
&#36;d = dir(&#36;root);
while (false !== (&#36;entry = &#36;d->read()))
{
if (&#36;entry == &quot;.&quot; &#36;entry == &quot;..&quot;)
{
continue;
}
if(&#36;this->filter(&#36;entry,&#36;filter))
{
if(is_dir(&#36;root.&#36;entry))
{
&#36;this->loopdir(&#36;d->path.&#36;entry.&quot;/&quot;);
}
else
{
&#36;getarr[] = &#36;d->path.&#36;entry;
}
}
}
&#36;d->close();
return &#36;getarr;
}

/**
* 函数名称: getphpfiles(&#36;path)
* 函数功能: 提取php文档
* 输入参数: &#36;path ---------------- 文档路径
* 函数返回值: bool
* 其它说明: 2004-10-13
*/
function getphpfiles(&#36;path)
{
&#36;type = preg_replace(&#39;/.*\.(.*[^\.].*)/i&#39;,&#39;\\1&#39;,&#36;path);
&#36;type = strtolower(&#36;type);
if(&#36;type==&quot;php&quot;)
{
return true;
}
else
{
return false;
}
}

/**
* 函数名称: getcontent(&#36;path)
* 函数功能: 读取文件内容
* 输入参数: &#36;path ------------------- 文件路径
* 函数返回值: string
* 其它说明: 2004-10-13
*/
function getcontent(&#36;path)
{
&#36;fp = file(&#36;path);
&#36;content = implode(&#39;&#39;,&#36;fp);
return &#36;content;
}

/**
* 函数名称: getdoc(&#36;content,&#36;mode=&quot;1&quot;)
* 函数功能: 取出php文件中的注释
* 输入参数: &#36;content ------------ 文档内容
&#36;mode --------------- 模式,1为普通,2为扩展
* 函数返回值: string
* 其它说明: 2004-10-13
*/
function getdoc(&#36;content,&#36;mode=&quot;1&quot;)
{
switch(&#36;mode)
{
case &#39;1&#39;:
&#36;pattern = &#39;/\/(\*)[\r\n].*\*\//isu&#39;;
break;
case &#39;2&#39;:
&#36;pattern = &#39;/\/\*.*\*\//isu&#39;;
break;
}

preg_match_all(&#36;pattern,&#36;content,&#36;carr);
&#36;getarr = array();
foreach(&#36;carr[0] as &#36;key=>&#36;val)
{
&#36;getarr[] = trim(&#36;val);
}
&#36;str = implode(&quot;<br><br>&quot;,&#36;getarr);
&#36;str = preg_replace(&#39;/[\r]/i&#39;,&#39;<br>&#39;,&#36;str);
&#36;style = &#36;this->getstyle();
&#36;str = &#36;this->gettable(&#36;str);
&#36;str = &#36;style.&#36;str;
return &#36;str;
}

/**
* 函数名称: etfilepath(&#36;filepath,&#36;oldroot,&#36;newroot)
* 函数功能: 设置生成文件的路径
* 输入参数: &#36;filepath -------------- 源文件路径
&#36;oldroot -------------- 源目录路径
&#36;newroot -------------- 目标目录路径
* 函数返回值: string
* 其它说明: 2004-10-13
*/
function setfilepath(&#36;filepath,&#36;oldroot,&#36;newroot)
{
&#36;oldroot = str_replace(&#39;/&#39;,&quot;\\/&quot;,&#36;oldroot);
&#36;pattern = &quot;/&quot;.&#36;oldroot.&quot;(.*)/iu&quot;;
&#36;filepath = preg_replace(&#36;pattern,&#39;\\1&#39;,&#36;filepath);
&#36;newpath = &#36;newroot.&#36;this->docdirname.&#36;filepath;//echo &quot;&#36;newpath<br>&quot;;
&#36;newpath = preg_replace(&#39;/(.*\.)(.*[^\.].*)/i&#39;,&#39;\\1htm&#39;,&#36;newpath);
return &#36;newpath;
}

/**
* 函数名称: getfiledir(&#36;path)
* 函数功能: 取得文档目录
* 输入参数: &#36;path ------------- 文档路径
* 函数返回值: string
* 其它说明: 2004-10-13
*/
function getfiledir(&#36;path)
{
&#36;getpath = preg_replace(&#39;/(.*)(\/.*[^\.].*)/i&#39;,&#39;\\1&#39;,&#36;path);
return &#36;getpath;
}

/**
* 函数名称: setdoc
* 函数功能: 将注释写入指定目录并生成页面
* 输入参数: &#36;filepath --------------- 目录路径
&#36;content ---------------- 写入的内容
* 函数返回值: 返回值说明
* 其它说明: 说明
*/
function setdoc(&#36;filepath,&#36;content)
{
&#36;fp = fopen(&#36;filepath,&quot;w+&quot;);
flock(&#36;fp,lock_ex);
fwrite(&#36;fp,&#36;content);
flock(&#36;fp, lock_un);
}

/**
* 函数名称: mkdirs(&#36;path)
* 函数功能: 创建目录
* 输入参数: &#36;path ------------------- 路径
* 函数返回值: none
* 其它说明: 2004-10-13
*/
function mkdirs(&#36;path)
{
&#36;adir = explode(&#39;/&#39;,&#36;path);
&#36;dirlist = &#39;&#39;;
&#36;rootdir = &#36;adir[0];
array_shift (&#36;adir);
foreach(&#36;adir as &#36;key=>&#36;val)
{
if(&#36;val!=&#39;.&#39;&&&#36;val!=&#39;..&#39;)
{
&#36;dirlist .= &quot;/&quot;.&#36;val;
&#36;dirpath = &#36;rootdir.&#36;dirlist;
if(!file_exists(&#36;dirpath)&&!is_file(&#36;dirpath))
{
mkdir(&#36;dirpath);
chmod(&#36;dirpath,0777);
}
}
}
}

/**
* 函数名称: filter(&#36;item,&#36;arr=null)
* 函数功能: 过滤
* 输入参数: &#36;item -------------- 内容
&#36;arr --------------- 过滤项
* 函数返回值: bool
* 其它说明: 2004-10-13
*/
function filter(&#36;item,&#36;arr=null)
{
&#36;item = strtolower(&#36;item);
&#36;filter = explode(&#39;,&#39;,&#36;arr);
if(&#36;arr==null!in_array(&#36;item,&#36;filter))
{
return true;
}
else
{
return false;
}
}

/**
* 函数名称: createframe(&#36;root)
* 函数功能: 生成框架
* 输入参数: &#36;root --------------- 首页的存放目录
* 函数返回值: str
* 其它说明: 2004-10-13
*/
function createframe(&#36;root)
{
&#36;str = &#39;
<html>
<head>
<meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=gb2312&quot;>
<title>无标题文档</title>
</head>

<frameset cols=&quot;150,*&quot; frameborder=&quot;yes&quot; border=&quot;10&quot; framespacing=&quot;5&quot; bordercolor=&quot;#003366&quot;>
<frame src=&quot;menu.htm&quot; name=&quot;leftframe&quot; framespacing=&quot;5&quot; frameborder=&quot;auto&quot; border=&quot;5&quot; bordercolor=&quot;#f5f5f5&quot; topmargin=&quot;0&quot; leftmargin=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; >
<frame src=&quot;#&quot; name=&quot;mainframe&quot;>
</frameset>
<noframes><body>
</body></noframes>
</html>&#39;;
&#36;this->docdir = &#36;root.&quot;index.htm&quot;;
&#36;this->setdoc(&#36;this->docdir,&#36;str);
}

/**
* 函数名称: createmenu(&#36;root,&#36;data)
* 函数功能: 生成菜单
* 输入参数: &#36;root ------------------- 页面存入目录
&#36;data ------------------- 内容
* 函数返回值: string
* 其它说明: 2004-10-13
*/
function createmenu(&#36;root,&#36;data)
{
&#36;path = &#36;root.&quot;menu.htm&quot;;
&#36;str = &#36;this->getstyle();
&#36;str.= &quot;<table>&quot;;
foreach(&#36;data as &#36;key=>&#36;val)
{
&#36;str.= &quot;<tr><td><a href=&#39;&quot;.&#36;val[&#39;url&#39;].&quot;&#39; target=&#39;mainframe&#39;>&quot;.&#36;val[&#39;name&#39;].&quot;</a></td></tr>&quot;;
}
&#36;str.= &quot;</table>&quot;;
&#36;this->setdoc(&#36;path,&#36;str);
}

/**
* 函数名称: getstyle()
* 函数功能: 样式
* 输入参数: none
* 函数返回值: string
* 其它说明: 2004-10-13
*/
function getstyle()
{
&#36;str = &#39;
<style>
table {
font-family: &quot;courier new&quot;,&quot;宋体&quot;;
border-collapse: collapse;
word-break:break-all;
}
td {
font-family: &quot;courier new&quot;,&quot;宋体&quot;;
font-size: 12px;
line-height: 22px;
}
</style>&#39;;
return &#36;str;
}

/**
* 函数名称: gettable(&#36;content)
* 函数功能: 把内容放入table中
* 输入参数: &#36;content ------------ 内容
* 函数返回值: string
* 其它说明: 2004-10-13
*/
function gettable(&#36;content)
{
&#36;str = &quot;<table width=\&quot;100&#37;\&quot; border=\&quot;1\&quot; bordercolor=\&quot;#dbdbdb\&quot; cellpadding=\&quot;5\&quot; cellspacing=\&quot;0\&quot;>
<tr>
<td bgcolor=\&quot;#f5f5f5\&quot;>&quot;.&#36;content.&quot;</td>
</tr>
</table>&quot;;
return &#36;str;
}
}

// 使用
&#36;d = new doc;
&#36;filter = &quot;adodb,smarty,cvs,templates,templates_c&quot;;
&#36;d->createdoc(&quot;e:/www/kpub20/class/&quot;,&quot;e:/www/test/aaa/&quot;,1,&#36;filter);
?>


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons