Hongmu Notes
Home Program Notes Imperial CMS 7.5 function decryption field processing function
Program Notes Empire cms

Imperial CMS 7.5 function decryption field processing function

Imperial CMS 7.5 function decryption field processing function

Foreword:
When adding/modifying fields, you can set "backend information processing function", "backend information modification processing function", "foreground information processing function", and "foreground modification information processing function". You can set functions for processing field content respectively, which are often used for models that have special requirements for the storage format of field content. Today we will briefly explain the processing function production format.
帝国CMS 7.5功能解密之字段处理函数

Basic setup steps:
1. Write the processing function;
2. Copy the function to the content of the e/class/userfun.php file;
3. Modify the field setting processing function name.
Field processing function format:

function user_FieldFun($mid,$f,$isadd,$isq,$value,$cs){
        return $value;
}

Parameter description:
user_FieldFun: function name
$mid: system model ID
$f: field name
$isadd: When the value is 1, it is to add information; when the value is 0, it is to modify information.
$isq: When the value is 0, it is background processing; when the value is 1, it is foreground processing.
$value: original content of the field
$cs: field additional parameters, parameter content set at the field processing function
Field processing function example:
Example 1: Automatically add "[EmpireCMS]" in front of the title
Background field function settings: user_AddTitle

function user_AddTitle($mid,$f,$isadd,$isq,$value,$cs){
        $value='[EmpireCMS]'.$value;
        return $value;
}

Example 2: Title content is a combination of writer and befrom fields
Background field function settings: user_TogTitle
The title field displays HTML code: <input type="hidden" name="title" value="test">
(Note: Because the title is a required item, an initial value must be given so that it will not prompt that the content is empty)

function user_TogTitle($mid,$f,$isadd,$isq,$value,$cs){
        $value=$_POST['writer'].$_POST['befrom'];
        return $value;
}

Example 3: Upload images and automatically generate thumbnails
Background field function settings: user_TranImgAuto##170,120
(Note: The background parameter 170 represents the thumbnail width, and 120 is the thumbnail height)
The upload image field displays HTML code: <input type="file" name="titlepicimgrs" size="45">
(Note: The variable name uses "field name" + imgrs, which corresponds to the "$filetf" variable in the function)

function user_TranImgAuto($mid,$f,$isadd,$isq,$value,$cs){
        global $empire,$dbtbpre,$public_r,$emod_r,$class_r,$tranpicturetype,$musername;
        $filetf=$f.'imgrs';//变量名
        if(!$_FILES[$filetf]['name'])
        {
                return $value;
        }
        $classid=(int)$_POST['classid'];
        $id=(int)$_POST['id'];
        $filepass=(int)$_POST['filepass'];
        $filetype=GetFiletype($_FILES[$filetf]['name']);
        $pr=$empire->fetch1("select qaddtran,qaddtransize,qaddtranimgtype from {$dbtbpre}enewspublic limit 1");
        if(!$pr['qaddtran'])
        {
                printerror("CloseQTranPic","",1);
        }
        if(!strstr($pr['qaddtranimgtype'],"|".$filetype."|"))
        {
                printerror("NotQTranFiletype","",1);
        }
        if($_FILES[$filetf]['size']>$pr['qaddtransize']*1024)
        {
                printerror("TooBigQTranFile","",1);
        }
        if(!strstr($tranpicturetype,','.$filetype.','))
        {
                printerror("NotQTranFiletype","",1);
        }
        $tfr=DoTranFile($_FILES[$filetf]['tmp_name'],$_FILES[$filetf]['name'],$_FILES[$filetf]['type'],$_FILES[$filetf]['size'],$classid);
        if($tfr['tran'])
        {
                $csr=explode(',',$cs);
                $maxwidth=$csr[0];
                $maxheight=$csr[1];
                $yname=$tfr['yname'];
                $name=$tfr['name'];
                include_once(ECMS_PATH.'e/class/gd.php');
                //生成缩图
                $filer=ResizeImage($yname,$name,$maxwidth,$maxheight,$public_r['spickill']);
                DelFiletext($yname);
                if($filer['file'])
                {
                        //写入数据库
                        $type=1;
                        $filetime=date("Y-m-d H:i:s");
                        $filesize=@filesize($filer['file']);
                        $filename=GetFilename(str_replace(ECMS_PATH,'',$filer['file']));
                        $adduser='[Member]'.$musername;
                        $infoid=$isadd==1?0:$id;
                        $empire->query("insert into {$dbtbpre}enewsfile(filename,filesize,adduser,path,filetime,classid,no,type,id,cjid,fpath) values('$filename','$filesize','$adduser','$tfr[filepath]','$filetime','$classid','[".$f."]".addslashes(RepPostStr($_POST[title]))."','$type','$infoid','$filepass','$public_r[fpath]');");
                        if($isadd==0)
                        {
                                $tbname=$emod_r[$mid]['tbname'];
                                if(strstr($emod_r[$mid]['tbdataf'],','.$f.','))
                                {
                                        $ir=$empire->fetch1("select stb from {$dbtbpre}ecms_".$tbname." where id='$id'");
                                        $ifr=$empire->fetch1("select ".$f." from {$dbtbpre}ecms_".$tbname."_data_".$ir[stb]." where id='$id'");
                                        $ifval=$ifr[$f];
                                }
                                else
                                {
                                        $ir=$empire->fetch1("select ".$f." from {$dbtbpre}ecms_".$tbname." where id='$id'");
                                        $ifval=$ir[$f];
                                }
                                if($ifval)
                                {
                                        DelYQTranFile($classid,$id,$ifval,$f);
                                }
                        }
                        $value=str_replace($tfr['filename'],$filename,$tfr['url']);
                }
        }
        else
        {
                $value='';
        }
        return $value;
}

The processing function can realize many very complex field content storage format requirements. The above are just a few simple examples, and more need to be practiced by users.

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Empire CMS database statement & SQL statement format

Empire CMS database statement & SQL statement format Program Notes Empire cms

Introduction to Imperial CMS extended SQL program writing, basic examples of Imperial CMS database statements & SQL statement formats: Note: The following examples are based on placing PHP files in the system root directory. Example 1: Connect to MYSQL program. (a.php)<?php require('e/class/connect.php'); //Introduce database configuration files and public function files requ…
👁 351
Empire CMS obtains the system COOKIE variable function getcvar()

Empire CMS obtains the system COOKIE variable function getcvar() Program Notes Empire cms

Get the system COOKIE variable function syntax: getcvar($var,$ecms) Description: $var: is the variable name $ecms: 0 is to set the foreground COOKIE variable, 1 is to set the background COOKIE variable. This parameter can be omitted and defaults to 0. Usage example: getcvar('mlusername'), get the user name of the front-end login member getcvar('loginu...
👁 295
Empire CMS smart label call field collection

Empire CMS smart label call field collection Program Notes Empire cms

Collect and classify all fields that support smart tag calls into Empire CMS smart tags: [e:loop={column ID/topic ID, number of items displayed, operation type, only display pictures with titles, additional SQL conditions, display sorting}] Template code content [/e:loop] Calling time: <?=date('m-d',$bqr[newstime])?> <?=dat…
👁 3749

Recommended reading

Resource website typecho001 template

Resource website typecho001 template Program Notes Typecho

typecho001 template template please do not modify the folder name of this template. The folder name is: typecho001 1.4 Fix the js output problem on the article page 1.3 Fix the error prompt when the plug-in is not installed Optimize the list page code output 1.2 Fix the comment function and add a custom homepage title 1.1 Fix the comment reply asymmetry function Add a separate title setting function on the homepage Add the website favicon.ico icon Add one...
👁 198
Modification of typecho paging style

Modification of typecho paging style Program Notes Typecho

Sir, times have changed! Typecho is currently the most perfect solution, because Baidu can only see the code of fixed thinking. The actual generated HTML code is breathtakingly clean and fully customized, including adding classes to the li element, adding classes to the a element, adding classes to the previous page and next page, and removing the li tags that come with typecho to express more. I can even add some text to the content inside...
👁 517
Typecho article page comment style modification

Typecho article page comment style modification Program Notes Typecho

When you need to use typecho for template development, the default comment style is ugly. Therefore, comments need to be re-output or styled. The default comment template file path is: comments.php Mainly used related variables<?php $comments->gravatar('40', ''); ?> //Avatar has two parameters, size,...
👁 389
Typecho's API for adding, deleting, modifying and querying databases

Typecho's API for adding, deleting, modifying and querying databases Program Notes Typecho

Typecho database provides a very easy-to-use API, which is not much different from the native SQL writing method. At the same time, it also handles common SQL security issues, such as SQL injection. From a practical perspective, this article introduces common scenarios for typecho to operate databases and related API usage. Table creation and deletion During the development process of Typecho plug-in, you often need to create your own table. Typecho_… mentioned above
👁 552
PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
Summary of methods for calling popular comment articles and calling latest articles in Typecho

Summary of methods for calling popular comment articles and calling latest articles in Typecho Program Notes Typecho

Typecho articles call the Typecho program. When designing a theme, the sidebar sometimes needs to call popular articles or the latest articles. We can call it directly through the script at the specified location. In this article, we will organize this method of calling articles, which can be directly called and used in templates where needed in the future. In fact, designing a theme is just that. After the static template is completed, it is called directly. The latest article calls <?php $t…
👁 295