content.php controller file Analysis for "PHPCMS-V9" background content module-Background Add code Analysis

Source: Internet
Author: User
The first step:
//path: phpcms/modules/content/content.php
//Construction method public
function __construct () {
		parent::__ Construct ();
		$this->db = Pc_base::load_model (' Content_model ');//content Model database operation class
		$this->siteid = $this->get_siteid (); Current site ID
		$this->categorys = GetCache (' Category_content_ '. $this->siteid, ' Commons ');//Detailed configuration information for all columns under the current site
		//Permission Judgement
		if (isset ($_get[' catid ']) && $_session[' Roleid ']!= 1 && route_a!= ' pass ' && Strpos (route_a, ' public_ ') ===false) {
			$catid = intval ($_get[' catid ']);
			$this->priv_db = Pc_base::load_model (' Category_priv_model ');
			$action = $this->categorys[$catid] [' type ']==0? Route_a: ' init ';
			$priv _datas = $this->priv_db->get_one (Array (' CATID ' => $catid, ' is_admin ' =>1, ' action ' => $action));
			if (! $priv _datas) showmessage (L (' permission_to_operate '), ' blank ');
		}
	

Add Content Code Analysis Public Function Add () {//click the "Automatically close after save" or "Save and Continue publishing" button, almost all form contents are stored in the $info [] array if (isset ($_post[' dosubmit ')) | |
			Isset ($_post[' dosubmit_continue ')) {define (' index_html ', true);
			Column id $catid = $_post[' info '] [' catid '] = intval ($_post[' info '] [' catid ']);
			Title if (Trim ($_post[' info '] [' title ']) = = ShowMessage (L (' title_is_empty '));
			The detailed configuration information of the current column $category = $this->categorys[$catid]; Current column type: 0-Internal Column 1-single page 2-External link if ($category [' type ']==0) {//Current column-owning model id:1-article Model 2-Download Model 3-picture Model $modelid = $this-
				>categorys[$catid] [' modelid '];
				Set up the main table of the model and the data main table, such as news, Gt_news $this->db->set_model ($modelid);
				If the column has a workflow set up, then you must go to the workflow setting//Convert the $category[' setting ' in the current column details configuration to an array $setting = String2array ($category [' setting ']); $workflowid = $setting [' WorkflowId '];//workflow settings//$_post[' status ']==99 representative publishes if ($workflowid && $_post[' sta Tus ']!=99) {//If the user is a super administrator, then publish $_post[' info ' [' status '] in accordance with their own settings = $_session[' Roleid ']==1? inTval ($_post[' status '): 1; else {$_post[' info '] [' status '] = 99;//Assign the form to the publishing state to info[] array}//Add Content $this->db->add_content ($ _post[' info '];//View Step Two: phpcms/model/content_model.class.php//Click the "Automatically close after Save" button if (isset ($_post[' Dosubmit ')) {s Howmessage (L (' add_success '). L (' 2s_close '), ' blank ', ', ', ', ' function Set_time () {$ ("#secondid"). HTML (1);
				SetTimeout ("Set_time ()"); SetTimeout ("Window.close ()", 1200); ');
				else {//click on the "Save and continue to publish" button ShowMessage (' add_success '), http_referer);
				} else {//single page $this->page_db = Pc_base::load_model (' Page_model '); $style _font_weight = $_post[' Style_font_weight ']?
				' Font-weight: '. Strip_tags ($_post[' style_font_weight '): '; $_post[' info ' [' style '] = strip_tags ($_post[' Style_color ']).
				
				$style _font_weight;
				if ($_post[' edit ']) {$this->page_db->update ($_post[' info '],array (' catid ' => $catid));
			else {$catid = $this->page_db->insert ($_post[' info '],1);	$this->page_db->create_html ($catid, $_post[' info ');
			$forward = Http_referer;
		ShowMessage (L (' add_success '), $forward);
			else {//Display content Add page template $show _header = $show _dialog = $show _validator = ';
			Set the cookie to call Param::set_cookie (' module ', ' content ') at the attachment add; Column ID if (isset ($_get[' catid ')) && $_get[' catid ']) {//column id $catid = $_get[' catid '] = intval ($_get[' cat
				
				ID ']);
				Param::set_cookie (' catid ', $catid);
				Current column detailed configuration information $category = $this->categorys[$catid];
					Current column type: 0-Internal Column 1-single page 2-External link if ($category [' type ']==0) {//Current column-owning model ID $modelid = $category [' ModelID ']; Takes the model ID, generates the corresponding form require cache_model_path. ' content_form.class.php ' by the model ID;//Dynamic build content Add page corresponding form $content _form = new
					Content_form ($modelid, $catid, $this->categorys);
 					$forminfos = $content _form->get ()//Get content Add page corresponding form information $formValidator = $content _form->formvalidator; Converts the $category[' setting ' in the current column detail configuration information to an array $setting = sTring2array ($category [' setting ']);
					If you set up a workflow, you must take the workflow process $workflowid = $setting [' WorkflowId '];
					Gets the workflow detail configuration information under the current site $workflows = GetCache (' Workflow_ '. $this->siteid, ' Commons ');
					Get current Workflow information: 1-level Audit 2-two level audit 3-three level audit 4-four level audit $workflows = $workflows [$workflowid];
					$workflows _setting = String2array ($workflows [' setting ']);
					$nocheck _users = $workflows _setting[' nocheck_users '];
					$admin _username = Param::get_cookie (' Admin_username ');
					if (!empty ($nocheck _users) && In_array ($admin _username, $nocheck _users)) {$priv _status = true;
					else {$priv _status = false;
				///Show content Add page template include $this->admin_tpl (' Content_add ');
					
					else {//single page $this->page_db = Pc_base::load_model (' Page_model ');
					
					$r = $this->page_db->get_one (Array (' CATID ' => $catid));
						if ($r) {extract ($r);
						$style _arr = explode ('; ', $style);
						$style _color = $style _arr[0]; $style _font_weight = $STYLE_ARR[1]?
					substr ($style _arr[1],12): ';
				Include $this->admin_tpl (' content_page ');
			} else {include $this->admin_tpl (' Content_add ');
		Header ("Cache-control:private"); }
	}

Step two://path: phpcms/model/content_model.class.php content model Database operation class public $table _name = ';
	public $category = ';
		Public Function __construct () {$this->db_config = pc_base::load_config (' database ');
		$this->db_setting = ' default ';
		Parent::__construct ();
		$this->url = pc_base::load_app_class (' url ', ' content ');
	$this->siteid = Get_siteid (); The Public Function Set_model ($modelid) {$this->model = GetCache (' model ', ' Commons '),//Get detailed configuration information for all models $this->mode lid = $modelid;//The current model ID $this->table_name = $this->db_tablepre. $this->model[$modelid [' tablename '];// The main table name of the current model, prefixed with: For example, gt_news $this->model_tablename = $this->model[$modelid] [' tablename '];//the current model main table name without a prefix, such as: news}/ * * Add content * * @param $data data submitted by the form * @param $isimport whether to import the/Public function add_content ($data for the external interface, $isimpo
		RT = 0) {//returns the string or array processed by addslashes if ($isimport) $data = New_addslashes ($data);
		$this->search_db = Pc_base::load_model (' Search_model '); $modelid = $this->modelid;//The current model ID require_once cache_model_path. ' content_input.class.php ';
		Require_once cache_model_path. ' content_update.class.php ';
		$content _input = new Content_input ($this->modelid);
		$inputinfo = $content _input->get ($data, $isimport);
		System field information, stored in the main table $systeminfo = $inputinfo [' System '];
		Non-system field information, stored in the secondary table $modelinfo = $inputinfo [' model ']; The publication time is not empty and is not a number if ($data [' inputtime '] &&!is_numeric ($data [' Inputtime '])} {//Convert publication time to timestamp, classified as System field information $system
		info[' inputtime '] = strtotime ($data [' inputtime ']);
		ElseIf (! $data [' inputtime ']) {//Publish time is empty, assign the system timestamp information to $systeminfo[' Inputtime '] $systeminfo [' inputtime '] = sys_time;
		else {$systeminfo [' inputtime '] = $data [' Inputtime ']; ///Read model field configuration, about date configuration format, to combine date data $this->fields = GetCache (' model_field_ '. $modelid, ' model '); The details configuration information $setti		  ng = String2array ($this->fields[' inputtime '] [' setting '])//About date setting, converting array format/** * ' Setting ' => ' Array (* \ ' fieldtype\ ' => ' int\ ', integral type * \ ' format\ ' => \ ' y-m-d h:i:s\ ', time format * ' defaulttype\ ' => ' 0\ ', *) ', * *
		Extract ($setting);
		if ($fieldtype = = ' Date ') {$systeminfo [' inputtime '] = date (' y-m-d ');
		}elseif ($fieldtype = = ' datetime ') {$systeminfo [' inputtime '] = Date (' y-m-d h:i:s '); }//Update time if ($data [' updatetime '] &&!is_numeric ($data [' updatetime '])) {$systeminfo [' updatetime '] = Strtotim
		E ($data [' updatetime ']);
		} elseif (! $data [' updatetime ']) {$systeminfo [' updatetime '] = sys_time;
		else {$systeminfo [' updatetime '] = $data [' UpdateTime ']; }//user name $systeminfo [' username '] = $data [' username ']?
		$data [' username ']: Param::get_cookie (' admin_username '); System add $systeminfo [' sysadd '] = defined (' In_admin ')?
		
		1:0; Auto Extract Summary if (isset ($_post[' add_introduce ')) && $systeminfo [' description '] = = ' && isset ($modelinfo Content ']) {$content = Stripslashes ($modelinfo [' content ']);/$introcude _length = intval ($_post[' inTrocude_length '])//automatically intercepts the content length///If the automatically intercepted content contains [page] characters, replace it with an empty $systeminfo [' description '] = Str_cut (Str_replace (
			Array ("\ r \ n", "\ T", ' [Page] ', ' [/page] ', ' ' "', '" ', '   '), ' ", Strip_tags ($content)), $introcude _length);
		Abstract $inputinfo [' System '] [' description '] = $systeminfo [' description '] = addslashes ($systeminfo [' description ']); ///Automatically extract thumbnail if (isset ($_post[' Auto_thumb ')) && $systeminfo [' thumb '] = = ' && isset ($modelinfo ' content '
			) {$content = $content $content: stripslashes ($modelinfo [' content ']); $auto _thumb_no = intval ($_post[' auto_thumb_no ') -1;//the first few pictures in the content as the title picture if (Preg_match_all ("/src) = ([\" | "]?) ([^ \] ' >]+\. (gif|jpg|jpeg|bmp|png))  \\2/i ", $content, $matches)) {$systeminfo [' thumb '] = $matches [3][$auto _thumb_no];//Thumbnail}}//Main Table $tablename =
		$this->table_name = $this->db_tablepre. $this->model_tablename; The system field information is stored in the primary table and returns the id $id = $modelinfo [' id '] = $this->insert ($systeminfo, true);//Parameter 2-returns the inserted ID $this->uPdate ($systeminfo, array (' ID ' => $id));
		Update URL address if ($data [' Islink ']==1) {//steering link $urls [0] = $_post[' Linkurl ']; else {$urls = $this->url->show ($id, 0, $systeminfo [' catid '], $systeminfo [' Inputtime '], $data [' prefix '], $inputi
		NFO, ' add ');
		$this->table_name = $tablename;//Main Table $this->update (array (' URL ' => $urls [0]), array (' ID ' => $id)); Attached table $this->table_name = $this->table_name. '
		_data ';
		
		Deposit the value of the non-system field information into the satellite table $this->insert ($modelinfo); Add statistics $this->hits_db = Pc_base::load_model (' Hits_model ');//gt_hits table-Statistics $hitsid = ' C '. $modelid. '-' $id; The ID composition//Statistic information $this->hits_db->insert (Array (' Hitsid ' => $hitsid, ' catid ' => $systeminfo [' catid '], '
		
		UpdateTime ' =>sys_time));
		
		Update to Full station search $this->search_api ($id, $inputinfo);
		
		Update column statistics, such as: column of the article Data volume $this->update_category_items ($systeminfo [' catid '], ' add ', 1);
		Call Update $content _update = new Content_update ($this->modelid, $id); After merging, call Update $merge _data = Array_merge ($systeminfo, $modelinfo);
		
		$merge _data[' posids '] = $data [' posids '];//recommended bit $content _update->update ($merge _data); Publish to the Audit list if (!defined (' in_admin ') | | | $data [' status ']!=99] {$this->content_check_db = Pc_base::load_model (' Conten T_check_model ');//gt_content_check table $check _data = Array (' Checkid ' => ' C '. $id. ') $modelid, ' catid ' => $syst eminfo[' catid ', ' SiteID ' => $this->siteid, ' title ' => $systeminfo [' title '], ' username ' => $systeminfo ['
			Username '], ' inputtime ' => $systeminfo [' inputtime '], ' status ' => $data [' status '],);
		$this->content_check_db->insert ($check _data);
			//end published to the audit list if (! $isimport) {$html = Pc_base::load_app_class (' html ', ' content ');
			if ($urls [' content_ishtml '] && $data [' status ']==99] $html->show ($urls [1], $urls [' data ']);
		$catid = $systeminfo [' catid '];
			//Publish to other columns if ($id && isset ($_post[' Othor_catid ')) && Is_array ($_post[' Othor_catid '])) {$linkurl = $urls [0];
			$r = $this->get_one (array (' ID ' => $id)); foreach ($_post[' Othor_catid '] as $cid =>$_v) {$this->set_catid ($cid);//Set the model database where the CATID is located $mid = $this->ca tegory[$cid] [' modelid '];//model ID if ($modelid = = $mid) {//column of the same model inserts new data $inputinfo [' System '] [' catid '] = $systemi nfo[' catid ' = $cid; New column ID $newid = $modelinfo [' id '] = $this->insert ($systeminfo, true); The system field information is inserted into the primary table and returns the inserted ID $this->table_name = $tablename. '
					_data '//Schedule Data Warehousing $this->insert ($modelinfo); if ($data [' Islink ']==1) {//steering link $urls = $_post[' Linkurl '];//turn to link} else {$urls = $this->url->show ($
					NEWID, 0, $cid, $systeminfo [' Inputtime '], $data [' prefix '], $inputinfo, ' Add ');
					} $this->table_name = $tablename;
					$this->update (Array (' URL ' => $urls [0]), array (' ID ' => $newid)); Publish to the Audit list if ($data [' status ']!=99] {$check _data = array (' Checkid ' => ' C '. $newid. '-'. $mid, ' CA
					Tid ' => $cid,		' SiteID ' => $this->siteid, ' title ' => $systeminfo [' title '], ' username ' => $systeminfo [' username '],
						' Inputtime ' => $systeminfo [' inputtime '], ' status ' =>1,);
					$this->content_check_db->insert ($check _data);
				if ($urls [' content_ishtml '] && $data [' status ']==99] $html->show ($urls [1], $urls [' data ']); else {//different model inserts the switch to link address $newid = $this->insert (' title ' => $systeminfo [' title '], ' style ' =&G t; $systeminfo [' style '], ' thumb ' => $systeminfo [' Thumb '], ' keywords ' => $systeminfo [' keywords '], ' descr Iption ' => $systeminfo [' description '], ' status ' => $systeminfo [' status '], ' catid ' => $cid, ' url ' => $linkur
						L, ' Sysadd ' =>1, ' username ' => $systeminfo [' username '], ' inputtime ' => $systeminfo [' Inputtime '],
					' UpdateTime ' => $systeminfo [' updatetime '], ' Islink ' =>1), true); $this->table_name = $this->table_name. _datA ';
					$this->insert (Array (' ID ' => $newid)); Publish to the Audit list if ($data [' status ']!=99] {$check _data = array (' Checkid ' => ' C '. $newid. '-'. $mid, ' CA Tid ' => $systeminfo [' catid '], ' SiteID ' => $this->siteid, ' title ' => $systeminfo [' title '], ' user
						Name ' => $systeminfo [' username '], ' inputtime ' => $systeminfo [' inputtime '], ' status ' =>1,);
					$this->content_check_db->insert ($check _data);
				}} $hitsid = ' C '. $mid. '-'. $newid;
			$this->hits_db->insert (Array (' Hitsid ' => $hitsid, ' catid ' => $cid, ' UpdateTime ' =>sys_time)); //end Publish to other columns//update attachment status if (Pc_base::load_config (' System ', ' Attachment_stat ')) {$this->attachment_db = pc_
			Base::load_model (' Attachment_model '); $this->attachment_db->api_update (', ' C '. $systeminfo [' catid '].
		-'. $id, 2); }//Generate static if (! $isimport && $data [' status ']==99] {//index_html if (defined (' index_html ') is defined at the Add and modify content) $htMl->index ();
		if (defined (' relation_html ')) $html->create_relation_html ($catid); return $id;//Returns the record ID you just inserted}



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.