phpcms-v 9フロントテンプレートファイルにおける{pc}ラベルの実行フロー
71782 ワード
フロントPCタグの使用:{pc:contentパラメータ名="パラメータ値"パラメータ名="パラメータ値"パラメータ名="パラメータ値"}たとえば:{pc:content action="lists"catid="9"cache="3600"num="20"page="$page"}{/pc}実行フローは次のとおりです. ①モジュール名:content ②モジュール類ファイル:modules/content/classes/content_tag.class.php、二次開発やラベルの拡張に便利 ③ファイル内の方法:lists ④actionの後のパラメータは、function lists($data=array()など)このラベルが実際に取得したのは、content_tag.class.phpファイルでlistsメソッドが返すデータ注意:このラベルはcatidの値に基づいて対応するモデルidを探し、対応するモデルidに基づいて対応するモデルテーブルを探します.例えば、news注意:ほとんどのモジュールにはラベルクラスがあり、フォーマットは以下の通りです.モジュール名_tag.class.php注意:フロントテンプレートファイルに{pc}ラベルが表示される場所は、「フラグメント管理」で編集変更でき、content_tag.class.phpファイル分析-pcラベル呼び出しの方法
1 <?php
2 class content_tag {
3 private $db; // v9_news
4 public function __construct() {
5 $this->db = pc_base::load_model('content_model'); // , news news_data
6 $this->position = pc_base::load_model('position_data_model'); //position_data
7 }
8 /**
9 * , id :news- 、v9_news-
10 * @param $catid
11 */
12 public function set_modelid($catid) {
13 $siteids = getcache('category_content','commons'); // id
14 if(!$siteids[$catid]) return false; // , false
15 $siteid = $siteids[$catid]; // id
16 $this->category = getcache('category_content_'.$siteid,'commons');// id
17 if($this->category[$catid]['type']!=0) return false;// , false 0- 1- 2-
18 $this->modelid = $this->category[$catid]['modelid'];// id
19 $this->db->set_model($this->modelid); // id 1: -news 3: -picture 2: -download
20 $this->tablename = $this->db->table_name; // :v9_news
21 if(empty($this->category)) { // , false
22 return false;
23 } else { // , true
24 return true;
25 }
26 }
27 /**
28 *
29 * @param $data
30 */
31 public function count($data) {
32 if($data['action'] == 'lists') {
33 $catid = intval($data['catid']);
34 if(!$this->set_modelid($catid)) return false;
35 if(isset($data['where'])) {
36 $sql = $data['where'];
37 } else {
38 if($this->category[$catid]['child']) {
39 $catids_str = $this->category[$catid]['arrchildid'];
40 $pos = strpos($catids_str,',')+1;
41 $catids_str = substr($catids_str, $pos);
42 $sql = "status=99 AND catid IN ($catids_str)";
43 } else {
44 $sql = "status=99 AND catid='$catid'";
45 }
46 }
47 return $this->db->count($sql);
48 }
49 }
50
51 /**
52 * : , {pc:content action="lists"} {/pc} lists
53 * @param $data
54 */
55 public function lists($data) {
56 $catid = intval($data['catid']); //pc catid
57 if(!$this->set_modelid($catid)) return false; // id-> id->
58 if(isset($data['where'])) { // pc where ,
59 $sql = $data['where'];
60 } else { // pc where
61 $thumb = intval($data['thumb']) ? " AND thumb != ''" : ''; // thumb
62 if($this->category[$catid]['child']) { //
63 $catids_str = $this->category[$catid]['arrchildid']; // id, id
64 $pos = strpos($catids_str,',')+1;
65 $catids_str = substr($catids_str, $pos); // id, id
66 $sql = "status=99 AND catid IN ($catids_str)".$thumb; // sql
67 } else {
68 $sql = "status=99 AND catid='$catid'".$thumb; //
69 }
70 }
71 $order = $data['order']; //pc order
72 //$sql , model.calss.php select , , 'id'
73 $return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');// , sql
74
75 //
76 if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) { // pc moreinfo :
77 $ids = array();
78 //$return
79 foreach ($return as $v) { // :$v-
80 if (isset($v['id']) && !empty($v['id'])) {
81 $ids[] = $v['id']; //ids[] id
82 } else {
83 continue;
84 }
85 }
86 if (!empty($ids)) {
87 $this->db->table_name = $this->db->table_name.'_data'; //
88 $ids = implode('\',\'', $ids); //
89 $r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id');//
90 if (!empty($r)) {
91 foreach ($r as $k=>$v) { //
92 //$return: , id id , id id
93 if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);//
94 }
95 }
96 }
97 }
98 return $return;
99 }
100
101 /**
102 * ,{pc:content action="relation"} {/pc} relation
103 * @param $data
104 */
105 public function relation($data) {
106 $catid = intval($data['catid']); //pc catid : id
107 if(!$this->set_modelid($catid)) return false;
108 $order = $data['order']; //pc order
109 $sql = "`status`=99"; // sql
110 $limit = $data['id'] ? $data['limit']+1 : $data['limit'];
111 if($data['relation']) { //pc relation : id :2|7|5
112 $relations = explode('|',trim($data['relation'],'|')); // |
113 $relations = array_diff($relations, array(null));
114 $relations = implode(',',$relations);
115 $sql = " `id` IN ($relations)"; // sql
116 $key_array = $this->db->select($sql, '*', $limit, $order,'','id');//
117 } elseif($data['keywords']) { //
118 $keywords = str_replace('%', '',$data['keywords']);
119 $keywords_arr = explode(' ',$keywords); //
120 $key_array = array();
121 $number = 0; //
122 $i =1; //
123 foreach ($keywords_arr as $_k) {
124 $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');
125 $r = $this->db->select($sql2, '*', $limit, '','','id');
126 $number += count($r); //
127 foreach ($r as $id=>$v) {
128 if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;//$key_array[ id]=
129 $i++;
130 }
131 if($data['limit']<$number) break;
132 }
133 }
134 if($data['id']) unset($key_array[$data['id']]);//
135 return $key_array;
136 }
137
138 /**
139 * {pc:content action="hits"} {/pc} hits
140 * @param $data
141 */
142 public function hits($data) {
143 $catid = intval($data['catid']); // id,pc catid
144 if(!$this->set_modelid($catid)) return false; // id-> id-> , :news
145
146 $this->hits_db = pc_base::load_model('hits_model'); //hits:
147 $sql = $desc = $ids = '';
148 $array = $ids_array = array();
149 $order = $data['order']; //pc order
150 $hitsid = 'c-'.$this->modelid.'-%'; //hits hitsid :c- id- id
151 $sql = "hitsid LIKE '$hitsid'"; // sql
152 if(isset($data['day'])) { //pc day :
153 $updatetime = SYS_TIME-intval($data['day'])*86400; //
154 $sql .= " AND updatetime>'$updatetime'"; // sql
155 }
156 if($this->category[$catid]['child']) { //
157 $catids_str = $this->category[$catid]['arrchildid']; // id, id
158 $pos = strpos($catids_str,',')+1;
159 $catids_str = substr($catids_str, $pos); // id, id
160 $sql .= " AND catid IN ($catids_str)"; // sql
161 } else {
162 $sql .= " AND catid='$catid'"; //
163 }
164 $hits = array();
165 $result = $this->hits_db->select($sql, '*', $data['limit'], $order);// v9_hits
166 foreach ($result as $r) { //$result:v9_hits
167 $pos = strpos($r['hitsid'],'-',2) + 1; // :c- id- id, ,c-1-1 , "-"
168 $ids_array[] = $id = substr($r['hitsid'],$pos); // id
169 $hits[$id] = $r; // , :$hits[ id]=
170 }
171 $ids = implode(',', $ids_array); //
172 if($ids) {
173 $sql = "status=99 AND id IN ($ids)"; // sql
174 } else {
175 $sql = '';
176 }
177 $this->db->table_name = $this->tablename; // :v9_news
178 $result = $this->db->select($sql, '*', $data['limit'],'','','id'); // :v9_news
179 foreach ($ids_array as $id) {
180 if($result[$id]['title']!='') {
181 $array[$id] = $result[$id];
182 $array[$id] = array_merge($array[$id], $hits[$id]); // v9_news v9_hits , id
183 }
184 }
185 return $array;
186 }
187 /**
188 * : url :{pc:content action="category"} {/pc} category
189 * @param $data
190 */
191 public function category($data) {
192 $data['catid'] = intval($data['catid']); //pc catid : id
193 $array = array();
194 $siteid = $data['siteid'] && intval($data['siteid']) ? intval($data['siteid']) : get_siteid();//pc siteid :
195 $categorys = getcache('category_content_'.$siteid,'commons'); //
196 $site = siteinfo($siteid); //
197 $i = 1;
198 foreach ($categorys as $catid=>$cat) {
199 if($i>$data['limit']) break;
200 if((!$cat['ismenu']) || $siteid && $cat['siteid']!=$siteid) continue;//ismenu: ,1- 0-
201 if (strpos($cat['url'], '://') === false) { // url "://"
202 $cat['url'] = substr($site['domain'],0,-1).$cat['url']; // url
203 }
204 if($cat['parentid']==$data['catid']) { // 0, ,$cat['parentid']
205 $array[$catid] = $cat; //
206 $i++;
207 }
208 }
209 return $array;
210 }
211
212 /**
213 * , url :{pc:content action="position"} {/pc} position
214 * @param $data
215 */
216 public function position($data) {
217 $sql = '';
218 $array = array();
219 $posid = intval($data['posid']); //pc posid : id
220 $order = $data['order']; //pc order
221 $thumb = (empty($data['thumb']) || intval($data['thumb']) == 0) ? 0 : 1;//pc thumb
222 $siteid = $GLOBALS['siteid'] ? $GLOBALS['siteid'] : 1; // id
223 $catid = (empty($data['catid']) || $data['catid'] == 0) ? '' : intval($data['catid']);//pc catid
224 if($catid) { // id
225 $siteids = getcache('category_content','commons'); // id
226 if(!$siteids[$catid]) return false; // , false
227 $siteid = $siteids[$catid]; // id
228 $this->category = getcache('category_content_'.$siteid,'commons');// id
229 }
230 if($catid && $this->category[$catid]['child']) { //
231 $catids_str = $this->category[$catid]['arrchildid']; // id, id
232 $pos = strpos($catids_str,',')+1;
233 $catids_str = substr($catids_str, $pos); // id, id
234 $sql = "`catid` IN ($catids_str) AND "; // sql
235 } elseif($catid && !$this->category[$catid]['child']) { //
236 $sql = "`catid` = '$catid' AND ";
237 }
238 if($thumb) $sql .= "`thumb` = '1' AND "; //
239 if(isset($data['where'])) $sql .= $data['where'].' AND '; //pc where :
240 if(isset($data['expiration']) && $data['expiration']==1) $sql .= '(`expiration` >= \''.SYS_TIME.'\' OR `expiration` = \'0\' ) AND ';
241 $sql .= "`posid` = '$posid' AND `siteid` = '".$siteid."'"; // sql
242 $pos_arr = $this->position->select($sql, '*', $data['limit'],$order);// v9_position_data
243 if(!empty($pos_arr)) {
244 foreach ($pos_arr as $info) { // v9_position_data
245 $key = $info['catid'].'-'.$info['id']; // : id- id
246 $array[$key] = string2array($info['data']); // v9_position_data data
247 $array[$key]['url'] = go($info['catid'],$info['id']); //url
248 $array[$key]['id'] = $info['id']; // id
249 $array[$key]['catid'] = $info['catid']; // id
250 $array[$key]['listorder'] = $info['listorder']; //
251 }
252 }
253 return $array;
254 }
255 /**
256 * , pc
257 */
258 public function pc_tag() {
259 $positionlist = getcache('position','commons');
260 $sites = pc_base::load_app_class('sites','admin');
261 $sitelist = $sites->pc_tag_list();
262
263 foreach ($positionlist as $_v) if($_v['siteid'] == get_siteid() || $_v['siteid'] == 0) $poslist[$_v['posid']] = $_v['name'];
264 return array(
265 'action'=>array('lists'=>L('list','', 'content'),'position'=>L('position','', 'content'), 'category'=>L('subcat', '', 'content'), 'relation'=>L('related_articles', '', 'content'), 'hits'=>L('top', '', 'content')),
266 'lists'=>array(
267 'catid'=>array('name'=>L('catid', '', 'content'),'htmltype'=>'input_select_category','data'=>array('type'=>0),'validator'=>array('min'=>1)),
268 'order'=>array('name'=>L('sort', '', 'content'), 'htmltype'=>'select','data'=>array('id DESC'=>L('id_desc', '', 'content'), 'updatetime DESC'=>L('updatetime_desc', '', 'content'), 'listorder ASC'=>L('listorder_asc', '', 'content'))),
269 'thumb'=>array('name'=>L('thumb', '', 'content'), 'htmltype'=>'radio','data'=>array('0'=>L('all_list', '', 'content'), '1'=>L('thumb_list', '', 'content'))),
270 'moreinfo'=>array('name'=>L('moreinfo', '', 'content'), 'htmltype'=>'radio', 'data'=>array('1'=>L('yes'), '0'=>L('no')))
271 ),
272 'position'=>array(
273 'posid'=>array('name'=>L('posid', '', 'content'),'htmltype'=>'input_select','data'=>$poslist,'validator'=>array('min'=>1)),
274 'catid'=>array('name'=>L('catid', '', 'content'),'htmltype'=>'input_select_category','data'=>array('type'=>0),'validator'=>array('min'=>0)),
275 'thumb'=>array('name'=>L('thumb', '', 'content'), 'htmltype'=>'radio','data'=>array('0'=>L('all_list', '', 'content'), '1'=>L('thumb_list', '', 'content'))),
276 'order'=>array('name'=>L('sort', '', 'content'), 'htmltype'=>'select','data'=>array('listorder DESC'=>L('listorder_desc', '', 'content'),'listorder ASC'=>L('listorder_asc', '', 'content'),'id DESC'=>L('id_desc', '', 'content'))),
277 ),
278 'category'=>array(
279 'siteid'=>array('name'=>L('siteid'), 'htmltype'=>'input_select', 'data'=>$sitelist),
280 'catid'=>array('name'=>L('catid', '', 'content'), 'htmltype'=>'input_select_category', 'data'=>array('type'=>0))
281 ),
282 'relation'=>array(
283 'catid'=>array('name'=>L('catid', '', 'content'), 'htmltype'=>'input_select_category', 'data'=>array('type'=>0), 'validator'=>array('min'=>1)),
284 'order'=>array('name'=>L('sort', '', 'content'), 'htmltype'=>'select','data'=>array('id DESC'=>L('id_desc', '', 'content'), 'updatetime DESC'=>L('updatetime_desc', '', 'content'), 'listorder ASC'=>L('listorder_asc', '', 'content'))),
285 'relation'=>array('name'=>L('relevant_articles_id', '', 'content'), 'htmltype'=>'input'),
286 'keywords'=>array('name'=>L('key_word', '', 'content'), 'htmltype'=>'input')
287 ),
288 'hits'=>array(
289 'catid'=>array('name'=>L('catid', '', 'content'), 'htmltype'=>'input_select_category', 'data'=>array('type'=>0), 'validator'=>array('min'=>1)),
290 'day'=>array('name'=>L('day_select', '', 'content'), 'htmltype'=>'input', 'data'=>array('type'=>0)),
291 ),
292
293 );
294 }
295 }