Phpcms v9 Add a list of keywords similar to PHPCMS 2008

Source: Internet
Author: User

Add a keyword_ext_model.class.php to the Model folder. Keyword_model actually exists in the Model folder, do not know why there is no keyword this table?
So do not in this basically increase, perhaps the future model will be used,

The code is as follows Copy Code
<?php
Defined (' In_phpcms ') or exit (' No permission resources ');
Pc_base::load_sys_class (' model ', ', ', 0);
Class Keyword_ext_model extends Model {
Public $table _name = ';
Public Function __construct () {
$this->db_config = pc_base::load_config (' database ');
$this->db_setting = ' default ';
$this->table_name = ' keyword_ext ';
Parent::__construct ();
}
}
?>

Then create a table

  code is as follows copy code

CREATE TABLE ' T_v9_keyword_ext ' (
' TagID ' smallint (5) unsigned not NULL auto_increment,
' Tag ' char (not NULL),
' Style ' char (5) Not NULL,
' Usetimes ' smallint (5) unsigned not NULL DEFAULT ' 0 ',
' Lastusetime ' int (a) unsigned not NULL DEFAULT ' 0 ',
' Hits ' Mediumint (8) unsigned not NULL DEFAULT ' 0 ',
' Lasthittime ' int (a) unsigned not NULL DEFAULT ' 0 ',
' Listorder ' tinyint (3) unsigned not NULL DEFAULT ' 0 ',
' ModelID ' smallint (6) DEFAULT ' 0 ',
PRIMARY KEY (' TagID '),
UNIQUE KEY ' tag ' (' tag '),
KEY ' usetimes ' (' usetimes ', ' Listorder '),
KEY ' hits ' (' Hits ', ' Listorder ')
) Engine=myisam auto_increment=2 DEFAULT Charset=utf8;

The final step is to add a input.inc.php to the Phpcms/modules/content/fields/keyword.

The code is as follows Copy Code
function tags ($field, $value)
{
if (! $value) return ";
if (Strpos ($value, ', '))
{
$s = ', ';
}
Else
{
$s = ', ';
}

$keywords = Isset ($s)? Array_unique (Array_filter (Explode ($s, $value)): Array ($value);
$keyword _db = Pc_base::load_model (' Keyword_ext_model ');

foreach ($keywords as $tag)
{
$tag = Trim ($tag);
$keyword _db->delete (Array ("tag" => $tag, "ModelID" => $this->modelid));
$c = $this->db->count ("keywords like '%". $tag. " %'");
$keyword _db->insert (Array ("ModelID" => $this->modelid, "tag" => $tag, "Usetimes" => $c, "lastusetime" = >sys_time), false,true);
}

Return implode ($s, $keywords);

So in the article added keyword, will automatically increase to a keyword_ext, call the whole station tags when directly to the table on the line

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.