dedeeims做的是不错,可是相比dedecms来说,少了个tags的功能,有人不需要,但是我相信需要的人还是不在少数的,网上一直也没人放出了修改方法,自己研究了2天,终于搞定,但是提取tags的功能还不是很了解,按道理是从关键词部分直接提取,可是在dedecms中也是提取不成功,希望有人能完善之。转载请注明出处:本文出自:http://www.5756653.cn,相信这个难不倒你吧。
查看tags列表需要模板文件tag.htm和taglist.htm,请从dedecms默认模板中拷贝就行,另外:属于本篇文章的tags调用方法没空去写了,哪位如果有了,请告之。
拿文章功能来讲:
0.dedeeims里是没有tags的数据表的,要先把dedecms中dede_tagindex和dede_taglist两个表复制过来,用sql语句建也行
- Drop TABLE IF EXISTS
#@__tagindex
; - Create TABLE
#@__tagindex
( -
id
int(10) unsigned NOT NULL auto_increment, -
tag
char(12) NOT NULL default '', -
typeid
smallint(5) unsigned NOT NULL default '0', -
count
int(10) unsigned NOT NULL default '0', -
total
int(10) unsigned NOT NULL default '0', -
weekcc
int(10) unsigned NOT NULL default '0', -
monthcc
int(10) unsigned NOT NULL default '0', -
weekup
int(10) unsigned NOT NULL default '0', -
monthup
int(10) unsigned NOT NULL default '0', -
addtime
int(10) unsigned NOT NULL default '0', - PRIMARY KEY (
id
) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
- Drop TABLE IF EXISTS
#@__taglist
; - Create TABLE
#@__taglist
( -
tid
int(10) unsigned NOT NULL default '0', -
aid
int(10) unsigned NOT NULL default '0', -
arcrank
smallint(6) NOT NULL default '0', -
typeid
smallint(5) unsigned NOT NULL default '0', -
tag
varchar(12) NOT NULL default '', - PRIMARY KEY (
tid
,aid
) - ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
1.打开文章的添加页面的功能文件dede/article_add.php,查找“//生成html”,位置比较靠下,在下面插入代码:
- InsertTags($tags,$arcID);
2.打开添加文章的模板页面 dede/templets/article_add.html ,在合适的位置加上以下文本框代码,是让输入tags用的:
- <input name="tags" type="text" class="txt" id="tags" value="" style="width:60%" />
3.打开include/archives.func.php,添加及修改函数
首先找到UpIndexKey函数,用dedecms的完整函数替换,并加入InsertTags、InsertOneTag两个函数,所有代码如下:
- /**
- * 更新微表key及Tag
- *
- * @access public
- * @param int $id 文档ID
- * @param string $arcrank 权限值
- * @param int $typeid 栏目ID
- * @param int $sortrank 排序ID
- * @param string $tags tag标签
- * @return string
- */
- if ( ! function_exists('UpIndexKey'))
- {
- function UpIndexKey($id, $arcrank, $typeid, $sortrank=0, $tags='')
- {
- global $dsql,$typeid2;
- if(empty($typeid2)) $typeid2 = 0;
- $addtime = time();
- $query = " Update
#@__arctiny
SETarcrank
='$arcrank',typeid
='$typeid',typeid2
='$typeid2',sortrank
='$sortrank' Where id = '$id' "; - $dsql->ExecuteNoneQuery($query);
- /*
- * 处理修改后的Tag
- */
- if($tags!='')
- {
- $oldtag = GetTags($id);
- $oldtags = explode(',',$oldtag);
- $tagss = explode(',',$tags);
- foreach($tagss as $tag)
- {
- $tag = trim($tag);
- if(isset($tag[12]) || $tag!=stripslashes($tag))
- {
- continue;
- }
- if(!in_array($tag,$oldtags))
- {
- InsertOneTag($tag,$id);
- }
- }
- foreach($oldtags as $tag)
- {
- if(!in_array($tag,$tagss))
- {
- $dsql->ExecuteNoneQuery("Delete FROM
#@__taglist
Where aid='$id' AND tag LIKE '$tag' "); - $dsql->ExecuteNoneQuery("Update
#@__tagindex
SET total=total-1 Where tag LIKE '$tag' "); - }
- else
- {
- $dsql->ExecuteNoneQuery("Update
#@__taglist
SETarcrank
= '$arcrank',typeid
= '$typeid' Where tag LIKE '$tag' "); - }
- }
- }
- }
- }
- /**
- * 插入Tags
- *
- * @access public
- * @param string $tag tag标签
- * @param int $aid 文档AID
- * @return void
- */
- if ( ! function_exists('InsertTags'))
- {
- function InsertTags($tag, $aid)
- {
- $tags = explode(',',$tag);
- foreach($tags as $tag)
- {
- $tag = trim($tag);
- if(isset($tag[20]) || $tag!=stripslashes($tag))
- {
- continue;
- }
- InsertOneTag($tag,$aid);
- }
- }
- }
- /**
- * 插入一个tag
- *
- * @access public
- * @param string $tag 标签
- * @param int $aid 文档AID
- * @return void
- */
- if ( ! function_exists('InsertOneTag'))
- {
- function InsertOneTag($tag, $aid)
- {
- global $typeid,$arcrank,$dsql;
- $tag = trim($tag);
- if($tag == '')
- {
- return '';
- }
- if(empty($typeid))
- {
- $typeid = 0;
- }
- if(empty($arcrank))
- {
- $arcrank = 0;
- }
- $rs = false;
- $addtime = time();
- $row = $dsql->GetOne("Select * FROM
#@__tagindex
Where tag LIKE '$tag' "); - if(!is_array($row))
- {
- $rs = $dsql->ExecuteNoneQuery(" Insert INTO
#@__tagindex
(tag
,typeid
,count
,total
,weekcc
,monthcc
,weekup
,monthup
,addtime
) VALUES('$tag','$typeid','0','1','0','0','$addtime','$addtime','$addtime'); "); - $tid = $dsql->GetLastID();
- }
- else
- {
- $rs = $dsql->ExecuteNoneQuery(" Update
#@__tagindex
SET total=total+1,addtime=$addtime Where tag LIKE '$tag' "); - $tid = $row['id'];
- }
- if($rs)
- {
- $dsql->ExecuteNoneQuery("Insert INTO
#@__taglist
(tid
,aid
,arcrank
,typeid
,tag
) VALUES('$tid','$aid','$arcrank','$typeid' , '$tag'); "); - }
- }
- }
4.复制dedecms中include/arc.taglist.class.php至dedeeims的include文件夹中,查找 ,tp.moresite,tp.siteurl,tp.sitepath 并删除之,注意前面的小逗号一并删除,因为dede_archives表中没有这三个字段,否则会报错。
5.include/dedetag.class.php文件,查找function SetDefault(),在此函数后加入以下语句:
- /**
- * 强制引用
- *
- * @access public
- * @param object $refObj 隶属对象
- * @return void
- */
- function SetRefObj(&$refObj)
- {
- $this->refObj = $refObj;
- }
6.文章修改部分
①在dede/article_edit.php中查找“//生成HTML”,下面一句是“UpIndexKey($id,$arcrank,$typeid,$sortrank,‘’);”,把最后的一个引号改为“$tags”,使之变成“UpIndexKey($id,$arcrank,$typeid,$sortrank,$tags);”
②打开include/common.func.php,查找“function GetTags($aid)”,原文件这个函数功能函数是空的,咱们把这个函数修改为以下内容:
- /**
- * 获得某文档的所有tag
- *
- * @param int $aid 文档id
- * @return string
- */
- if ( ! function_exists('GetTags'))
- {
- function GetTags($aid)
- {
- global $dsql;
- $tags = '';
- $query = "Select tag FROM
#@__taglist
Where aid='$aid' "; - $dsql->Execute('tag',$query);
- while($row = $dsql->GetArray('tag'))
- {
- $tags .= ($tags=='' ? $row['tag'] : ','.$row['tag']);
- }
- return $tags;
- }
- }
③在后台的dede/templets/article_edit.htm文件中添加tag标签的文本框
- <input name="tags" type="text" class="txt" id="tags" value="<?php echo $tags; ?>" style="width:60%" />
7.后台部分
①复制dedecms中dede目录中的tags_main.php,到dedeeims的dede目录中,复制模板文件dede/templets/tags_main.htm到dedeeims的dede的同路径文件夹中。在后台菜单中添加
- <m:item name='TAG标签管理' link='tags_main.php' rank='sys_Tags' target='main' />
菜单文件在dede/inc/inc_menu.php中,需要放在什么地方就添加在哪里。另外在inc_action_info.php及inc_menu_map.php两个文件中也有需要修改的地方,自己添加,这两个文件并不重要。
8.产品部分
1.dede/product_add.php 查找//生成html下面插入
- InsertTags($tags,$arcID);
2.dede/product_edit.php 查找//生成HTML,下面一句替换
- UpIndexKey($id,$arcrank,$typeid,$sortrank,$tags);
3.dede/templets/product_add.htm 在合适位置添加
- <input name="tags" type="text" class="txt" id="tags" value="" style="width:80%" />
4.dede/templets/product_add.htm 在合适位置添加
- <input name="tags" type="text" class="txt" id="tags" value="<?php echo $arcRow["tags"]?>" style="width:60%" />
5.archives部分貌似不添加自定义模型的话是用不上的,这个修改方法类似。只要修改后台文件和模板文件即可
转载请注明出处:本文出自:http://www.5756653.cn,
未经允许不得转载:Windy's Blog » 给dedeeims添加tag功能