Phpcms v9 article module secondary development (sort username)

Source: Internet
Author: User
Tags abs explode php code trim

Change background document sorting

Modify file: content. php in phpcmsmodulescontent

 

The code is as follows: Copy code

$ Datas = $ this-> db-> listinfo ($ where, 'id desc', $ _ GET ['Page']);

Change

$ Datas = $ this-> db-> listinfo ($ where, 'listorder ASC, id desc ', $ _ GET ['Page']);

Outdated sorting of associated articles

Modify the phpcms/modules/content/classes/content_tag.class.php content model label file, and change the relation method in the content_tag class:

The code is as follows: Copy code

/**
* Related article tags
* @ Param $ data
*/
Public function relation ($ data ){
$ Catid = intval ($ data ['catid']);
If (! $ This-> set_modelid ($ catid) return false;
$ Order = $ data ['order'];
$ SQL = "'status' = 99 & Prime ;;
$ Limit = $ data ['id']? $ Data ['limit'] + 1: $ data ['limit'];
If ($ data ['relation']) {
$ Relations = explode ('|', trim ($ data ['relation'], '| '));
$ Relations = array_diff ($ relations, array (null ));
$ Relations = implode (',', $ relations );
$ SQL = "'id' IN ($ relations )";
$ Key_array = $ this-> db-> select ($ SQL, '*', $ limit, $ order, ", 'id ');
} Elseif ($ data ['keyword']) {
$ Keywords = str_replace ('%', ", $ data ['keyword']);
$ Keywords_arr = explode ('', $ keywords );
$ Key_array = array ();
$ Number = 0;
$ I = 1;
Foreach ($ keywords_arr as $ _ k ){
$ Sql2 = $ SQL. "AND 'keyword' LIKE '% $ _ k % '". (isset ($ data ['id']) & intval ($ data ['id'])? "AND 'id '! = '". Abs (intval ($ data ['id'])."' ":");
$ R = $ this-> db-> select ($ sql2, '*', $ limit, $ order, ", 'id ');
$ Number + = count ($ r );
Foreach ($ r as $ id => $ v ){
If ($ I <= $ data ['limit'] &! In_array ($ id, $ key_array) $ key_array [$ id] = $ v;
$ I ++;
}
If ($ data ['limit'] <$ number) break;
}
}
If ($ data ['id']) unset ($ key_array [$ data ['id']);
Return $ key_array;
}

In fact, only $ r = $ this-> db-> select ($ sql2, '*', $ limit, ",", 'id '); replace with $ r = $ this-> db-> select ($ sql2, '*', $ limit, $ order, ", 'id '); input the order parameter into the query method.
In the template, use the following tag and add the order parameter to sort the data.

The code is as follows: Copy code

{Pc: content action = "relation =" $ relation "id =" $ id "catid =" $ catid "num =" 5 & Prime; keywords = "$ rs [keywords]" order = "id DESC "}
{Loop $ data $ r}
{/Loop}
{/Pc}

If you have a friend who worries that directly modifying the PC will affect future upgrades, you can extract it separately. Use it as a function in the template. The code is as follows:

The code is as follows: Copy code
<? Php
/**
* Content model-related article tags (corrected sorting exceptions)
* @ Param $ data
*/
Function mk1_content_tag_relation ($ data ){
$ Db = pc_base: load_model ('content _ Model ');
$ Catid = intval ($ data ['catid']);
$ Siteids = getcache ('Category _ content', 'commons ');
If (! $ Siteids [$ catid]) return false;
$ Siteid = $ siteids [$ catid];
$ Category = getcache ('Category _ content _ '. $ siteid, 'commons ');
If (empty ($ category) return false;
If ($ category [$ catid] ['type']! = 0) return false;
$ Db-> set_model ($ category [$ catid] ['modelid']);
$ Order = $ data ['order'];
$ SQL = "'status' = 99 & Prime ;;
$ Limit = $ data ['id']? $ Data ['limit'] + 1: $ data ['limit'];
If ($ data ['relation']) {
$ Relations = explode ('|', trim ($ data ['relation'], '| '));
$ Relations = array_diff ($ relations, array (null ));
$ Relations = implode (',', $ relations );
$ SQL = "'id' IN ($ relations )";
$ Key_array = $ db-> select ($ SQL, '*', $ limit, $ order, ", 'id ');
} Elseif ($ data ['keyword']) {
$ Keywords = str_replace ('%', ", $ data ['keyword']);
$ Keywords_arr = explode ('', $ keywords );
$ Key_array = array ();
$ Number = 0;
$ I = 1;
Foreach ($ keywords_arr as $ _ k ){
$ Sql2 = $ SQL. "AND 'keyword' LIKE '% $ _ k % '". (isset ($ data ['id']) & intval ($ data ['id'])? "AND 'id '! = '". Abs (intval ($ data ['id'])."' ":");
$ R = $ db-> select ($ sql2, '*', $ limit, $ order, ", 'id ');
$ Number + = count ($ r );
Foreach ($ r as $ id => $ v ){
If ($ I <= $ data ['limit'] &! In_array ($ id, $ key_array) $ key_array [$ id] = $ v;
$ I ++;
}
If ($ data ['limit'] <$ number) break;
}
}
If ($ data ['id']) unset ($ key_array [$ data ['id']);
Return $ key_array;
}
?>

In the template, use the following PHP code.

The code is as follows: Copy code


{Php $ data = mk1_content_tag_relation (array ('relation' => $ relation, 'id' => $ id, 'catid' => $ catid, 'keyword' => $ rs ['keyword'], 'order' => 'Id DESC ', 'Limit' => '4 & prime ;));}
{Loop $ data $ r}
{/Loop}


No user name is displayed for published articles


V9 the foreground static sometimes does not display the updated user name. The specific modification method is as follows:

Row content_model.class.php 120th

The code is as follows: Copy code

$ Urls ['data'] ['username'] = $ systeminfo ['username'];
// End
Html. class. php line 29th:


// Amount. You must obtain the passed array value here.
$ Username = $ data ['username'];
Edit_content method, about 280 rows:


/* Edit the part to find the user name from the master table database and pass the template */
$ Temp = $ this-> get_one (array ('id' => $ id ));
$ Urls ['data'] ['username'] = $ temp ['username'];
// End


 

When adding an article, select the relevant article and call other model information.


First, in the model management designer model, modify the value of "related parameters" in the relevant article.
Find this line of statements

The code is as follows: Copy code

<Input type = 'Button 'value = "Add related" onclick = "omnipotent ('selectid ','? M = content & c = content & a = public_relationlist & modelid = {MODELID} ', 'Add related files', 1) "class =" button "style =" width: 66px; ">
To:

 

<Input type = 'Button 'value = "Add related" onclick = "omnipotent ('selectid ','? M = content & c = content & a = public_relationlist & modelid = 2 & prime;, 'Add related articles ', 1) "class =" button "style =" width: 66px; ">

In fact, I only changed {MODELID} to the target model ID (ID of the design case model.

This step allows you to select different models.

Next, we will solve the problem that the selection is saved and then the editing will not be displayed.
In the designer model of type management, modify the value of "related parameters" in the relevant article.
Set

The code is as follows: Copy code

 

<Input type = 'Button 'value = "show existing" onclick = "show_relation ({MODELID}, {ID})" class = "button" style = "width: 66px; ">
To:

 

<Input type = 'Button 'value = "show existing" onclick = "show_relation (, {ID})" class = "button" style = "width: 66px;">

Note that onclick = "show_relation ({MODELID}, {ID })"
I changed him to onclick = "show_relation (, {ID})". Here I need to explain that {MODELID} is the model ID that calls this article.
I changed it to show_relation (1, 2, {ID}). I knew it when I saw it. I had another parameter. Why is one more Parameter? As mentioned above, only articles of the same model can be selected by default, so a target model ID is created here. The first parameter is the source model ID, and the second parameter is the target model ID.

Save the modification.

 

Show_relation () is a JS function. Since there is one more parameter, we need to modify the JS file.
Locate about 153,154 lines of statics/js/content_addtop.js.

The code is as follows: Copy code
Function show_relation ....
$. GetJSON ("? M = content ;..........

I changed these two lines:

The code is as follows: Copy code

 

Function show_relation (modelid, target_modelid, id ){
$. GetJSON ("? M = content & c = content & a = public_getjson_ids & modelid = "+ modelid +" & target_modelid = "+ target_modelid +" & id = "+ id, function (json ){

After the JS modification, we will modify the final php file.

Locate the phpcmsmodulescontentcontent. php line 574, that is, about the public function public_getjson_ids () line.

Add the following lines to the $ modelid = intval ($ _ GET ['modelid']) and line feed:

The code is as follows: Copy code

 

$ Target_modelid = intval ($ _ GET ['target _ modelid']);

Add the following lines to line 7, that is, $ infos = array:

The code is as follows: Copy code
$ This-> db-> set_model ($ target_modelid );
$ This-> model = getcache ('model', 'commons ');
$ This-> db-> table_name = $ this-> db-> db_tablepre. $ this-> model [$ target_modelid] ['tablename'];
The line "$ this-> db-> table_name = $ tablename;" is replaced by the third row above.

OK. Success.
Because the native article functions have been damaged. If you want to use the functions of relevant articles in the future, remember to first go to the value of "related parameters" in the model field.

When calling related articles at the front-end, use the following labels:

The code is as follows: Copy code


If $ relation! = "}
{Php $ rel = explode ('|', $ relation );}
{Loop $ rel $ design_id} </p>
<P> {pc: get SQL = "select title, id, url, thumb from v9_design where id = $ design_id "}
{Loop $ data $ r}
<Td class = "pr5 & Prime;> <a href = "http://www.111cn.net/blog/{$ r [url]}" title = "{$ r [title]}" target = "_ blank"> </a> <p class =" mt5 & Prime;> <a href = "http://www.111cn.net/blog/{$ r [url]}" title = "{$ r [title]}" target = "_ blank"> {str_cut ($ r [title], '32 & prime;) }</a> </p> </td>
{/Loop}
{/Pc} </p>
<P> {/loop}
{/If}

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.