Dream Dedecms 5.7 GBK According to the method of alphabetical search

Source: Internet
Author: User
Keywords Dedecms Letter Search

Current Dream Dedecms v5.7 has been officially released, but in the actual use of the environment often we need to do some specific function of the implementation, such as the letter search, and so on, let us say how the function is implemented, the main method is to extract the first letter of the publication resources, stored in the datasheet, and then indexed.

Dedecms is based on PHP and MySQL technology and can be used at the same time in Windows, Linux, UNIX platform, the environment needs are as follows:

1. Windows Platform:
Iis/apache + PHP4/PHP5 + MYSQL3/4/5
If used in a Windows environment, it is recommended to use the Dedeampz suite provided by DEDECMS for optimal performance.

2, Linux/unix Platform
Apache + php4/php5 + MYSQL3/4/5 (PHP must run in unsafe mode)

Suggested use platform: Linux + Apache2.2 + PHP5.2 + MySQL5.0

Dream version for 5.7 GBK other no test


to back up the database before doing this


first to add a database field


ALTER TABLE ' dede_archives ' ADD ' fpy ' VARCHAR not NULL after ' weight ';


is used to save the first letter of the title


open dede/templets/article_add.htm about 136 lines (</td> above) add the following code to indicate whether to save


<input name= "f_py" type= "checkbox" id= "S_py" class= "NP" value= "1" checked= "checked" > Save Pinyin


also need to add
in article_edit.htm

Open dede/article_add.php Add $fpy= $F _py==1 below 102 lines? Str_replace (' _ ', ', ', Getpinyin stripslashes





($title), 1)): '; to get the phonetic alphabet of the title to find 191 lines, to the newly created field to assign value, I believe everyone will:


the original $query = "INSERT into ' dede_archives '





(Id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,sour





ce,litpic,pubdate,senddate,mid,voteid,notpost,description,keywords,filename,dutyadmin,weight) VALUES





(' $arcID ', ' $typeid ', ' $typeid 2 ', ' $sortrank ', ' $flag ', ' $ismake ', ' $channelid ', ' $arcrank ', ' $click ', ' $money '





, ' $title ', ' $shorttitle ', ' $color ', ' $writer ', ' $source ', ' $litpic ', ' $pubdate ', ' $senddate ', ' $adminid ', ' $vot





Eid ', ' $notpost ', ' $description ', ' $keywords ', ' $filename ', ' $adminid ', ' $weight ');


changed to


$query = INSERT into Dede_archives '





(Id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,sour





ce,litpic,pubdate,senddate,mid,voteid,notpost,description,keywords,filename,dutyadmin,weight,fpy)





VALUES





(' $arcID ', ' $typeid ', ' $typeid 2 ', ' $sortrank ', ' $flag ', ' $ismake ', ' $channelid ', ' $arcrank ', ' $click ', ' $money '





, ' $title ', ' $shorttitle ', ' $color ', ' $writer ', ' $source ', ' $litpic ', ' $pubdate ', ' $senddate ',





' $adminid ', ' $voteid ', ' $notpost ', ' $description ', ' $keywords ', ' $filename ', ' $adminid ', ' $weight ', ' $fpy ');





you should be able to read.





The title pinyin will be saved automatically when you add the article.








next to see search.php


I wrote a label to make it easy to call. Add {dede:letter/} (Include/tablib) to the call only to create a new letter.lib.php


<?php


if (!defined (' Dedeinc '))


{


Exit ("Request error!");


}


function Lib_letter (& $ctag,& $refObj)


{


Global $dsql, $sqlCt, $cfg _soft_lang, $cfg _indexurl;


$attlist = "letter| A,row|26 ";


Fillattsdefault ($ctag->cattribute->items, $attlist);


Extract ($ctag->cattribute->items, Extr_skip);


    


$letter = ';


$le _end=64+ $row;


for ($i =65 $i <= $le _end; $i + +) {


$letter. = "<a href= ' $cfg _indexurl/plus/search.php?keyword=". Strtolower (CHR





($i)). " &searchtype=pytitle ' > '. chr ($i). " </a> ";


    }


return $letter;


}


?>





the last and most critical change search.php default is a
that cannot be less than 2 characters

Find plus/search.php


will if (($keyword = = ' | | strlen ($KEYWORD) <2) && Empty ($typeid))


{


showmsg (' keyword cannot be less than 2 bytes! ', '-1 ');


exit ();


} to if ($searchtype <> ' Pytitle ') {


if ($keyword = = ' | | strlen ($KEYWORD) <2) && Empty ($typeid))


{


showmsg (' keyword cannot be less than 2 bytes! ', '-1 ');


exit ();


}


} can be





Find include/arc.searchview.class.php


first set the SQL statement function Getkeywordsql


Find if ($this->searchtype== "title") {


$kwsqls [] = "arc.title like '% $k% '";


}else{


$kwsqls [] = "CONCAT (Arc.title, ', Arc.writer, ', arc.keywords) like '% $k% '";


} to:


if ($this->searchtype== "title") {


$kwsqls [] = "arc.title like '% $k% '";


}else if ($this->searchtype== ' Pytitle ') {


$kwsqls [] = "CONCAT (Arc.title, ', Arc.keywords, ', arc.fpy) like '% $k% '";


}else{


$kwsqls [] = "CONCAT (Arc.title, ', Arc.writer, ', arc.keywords) like '% $k% '";


}





Add a function under this function:


function Getletter ($num =26, $t, $k) {


Global $cfg _indexurl;


$le _end=64+ $num;


for ($i =65 $i <= $le _end; $i + +) {


if (Ord (Strtoupper ($k)) = = $i) {


$letter. = "<a style= ' background: #000; color: #fff '





href= ' $cfg _indexurl/plus/search.php?keyword= '. Strtolower (Chr ($i)). " &searchtype=pytitle ' > ' CHR





($i). " </a> ";


re-enters;


            }


$letter. = "<a href= ' $cfg _indexurl/plus/search.php?keyword=". Strtolower (CHR





($i)). " &searchtype=pytitle ' > '. chr ($i). " </a> ";


        }


return $letter;


    }

The
function is to let the letters of the current search be highlighted





The tag display function of the underlying template that sets search


in Else if ($tagname = = "Likewords")


            {


$this->dtp->assign ($tagid, $this->getlikewords ($ctag->getatt (' num '));

Add
under
}

else if ($tagname = = ' letter ' and $this->searchtype== ' Pytitle ') {


$this->dtp->assign ($tagid, $this->getletter ($num =26, $this->searchtype, $this-





>keyword));


        }





to this end, haha, in fact, it is not difficult. Remember to back up your original program!

Note: This modification is to use the original template dedecms5.7, you can set the specific! I'm not going to explain the method here.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.