phpcms-v 9]フロントテンプレートファイルにおける{pc}ラベルの実行フロー
59895 ワード
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 lists , :function lists($data=array())
:content_tag.class.php lists
: catid id, id , :news
: , : _tag.class.php
: {pc} , " " ,
content_tag.class.php -pc
<?php
class content_tag {
private $db; // v9_news
public function __construct() {
$this->db = pc_base::load_model('content_model'); // , news news_data
$this->position = pc_base::load_model('position_data_model'); //position_data
}
/**
* , id :news- 、v9_news-
* @param $catid
*/
public function set_modelid($catid) {
$siteids = getcache('category_content','commons'); // id
if(!$siteids[$catid]) return false; // , false
$siteid = $siteids[$catid]; // id
$this->category = getcache('category_content_'.$siteid,'commons');// id
if($this->category[$catid]['type']!=0) return false;// , false 0- 1- 2-
$this->modelid = $this->category[$catid]['modelid'];// id
$this->db->set_model($this->modelid); // id 1: -news 3: -picture 2: -download
$this->tablename = $this->db->table_name; // :v9_news
if(empty($this->category)) { // , false
return false;
} else { // , true
return true;
}
}
/**
*
* @param $data
*/
public function count($data) {
if($data['action'] == 'lists') {
$catid = intval($data['catid']);
if(!$this->set_modelid($catid)) return false;
if(isset($data['where'])) {
$sql = $data['where'];
} else {
if($this->category[$catid]['child']) {
$catids_str = $this->category[$catid]['arrchildid'];
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos);
$sql = "status=99 AND catid IN ($catids_str)";
} else {
$sql = "status=99 AND catid='$catid'";
}
}
return $this->db->count($sql);
}
}
/**
* : , {pc:content action="lists"} {/pc} lists
* @param $data
*/
public function lists($data) {
$catid = intval($data['catid']); //pc catid
if(!$this->set_modelid($catid)) return false; // id-> id->
if(isset($data['where'])) { // pc where ,
$sql = $data['where'];
} else { // pc where
$thumb = intval($data['thumb']) ? " AND thumb != ''" : ''; // thumb
if($this->category[$catid]['child']) { //
$catids_str = $this->category[$catid]['arrchildid']; // id, id
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos); // id, id
$sql = "status=99 AND catid IN ($catids_str)".$thumb; // sql
} else {
$sql = "status=99 AND catid='$catid'".$thumb; //
}
}
$order = $data['order']; //pc order
//$sql , model.calss.php select , , 'id'
$return = $this->db->select($sql, '*', $data['limit'], $order, '', 'id');// , sql
//
if (isset($data['moreinfo']) && intval($data['moreinfo']) == 1) { // pc moreinfo :
$ids = array();
//$return
foreach ($return as $v) { // :$v-
if (isset($v['id']) && !empty($v['id'])) {
$ids[] = $v['id']; //ids[] id
} else {
continue;
}
}
if (!empty($ids)) {
$this->db->table_name = $this->db->table_name.'_data'; //
$ids = implode('\',\'', $ids); //
$r = $this->db->select("`id` IN ('$ids')", '*', '', '', '', 'id');//
if (!empty($r)) {
foreach ($r as $k=>$v) { //
//$return: , id id , id id
if (isset($return[$k])) $return[$k] = array_merge($v, $return[$k]);//
}
}
}
}
return $return;
}
/**
* ,{pc:content action="relation"} {/pc} relation
* @param $data
*/
public function relation($data) {
$catid = intval($data['catid']); //pc catid : id
if(!$this->set_modelid($catid)) return false;
$order = $data['order']; //pc order
$sql = "`status`=99"; // sql
$limit = $data['id'] ? $data['limit']+1 : $data['limit'];
if($data['relation']) { //pc relation : id :2|7|5
$relations = explode('|',trim($data['relation'],'|')); // |
$relations = array_diff($relations, array(null));
$relations = implode(',',$relations);
$sql = " `id` IN ($relations)"; // sql
$key_array = $this->db->select($sql, '*', $limit, $order,'','id');//
} elseif($data['keywords']) { //
$keywords = str_replace('%', '',$data['keywords']);
$keywords_arr = explode(' ',$keywords); //
$key_array = array();
$number = 0; //
$i =1; //
foreach ($keywords_arr as $_k) {
$sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');
$r = $this->db->select($sql2, '*', $limit, '','','id');
$number += count($r); //
foreach ($r as $id=>$v) {
if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;//$key_array[ id]=
$i++;
}
if($data['limit']<$number) break;
}
}
if($data['id']) unset($key_array[$data['id']]);//
return $key_array;
}
/**
* {pc:content action="hits"} {/pc} hits
* @param $data
*/
public function hits($data) {
$catid = intval($data['catid']); // id,pc catid
if(!$this->set_modelid($catid)) return false; // id-> id-> , :news
$this->hits_db = pc_base::load_model('hits_model'); //hits:
$sql = $desc = $ids = '';
$array = $ids_array = array();
$order = $data['order']; //pc order
$hitsid = 'c-'.$this->modelid.'-%'; //hits hitsid :c- id- id
$sql = "hitsid LIKE '$hitsid'"; // sql
if(isset($data['day'])) { //pc day :
$updatetime = SYS_TIME-intval($data['day'])*86400; //
$sql .= " AND updatetime>'$updatetime'"; // sql
}
if($this->category[$catid]['child']) { //
$catids_str = $this->category[$catid]['arrchildid']; // id, id
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos); // id, id
$sql .= " AND catid IN ($catids_str)"; // sql
} else {
$sql .= " AND catid='$catid'"; //
}
$hits = array();
$result = $this->hits_db->select($sql, '*', $data['limit'], $order);// v9_hits
foreach ($result as $r) { //$result:v9_hits
$pos = strpos($r['hitsid'],'-',2) + 1; // :c- id- id, ,c-1-1 , "-"
$ids_array[] = $id = substr($r['hitsid'],$pos); // id
$hits[$id] = $r; // , :$hits[ id]=
}
$ids = implode(',', $ids_array); //
if($ids) {
$sql = "status=99 AND id IN ($ids)"; // sql
} else {
$sql = '';
}
$this->db->table_name = $this->tablename; // :v9_news
$result = $this->db->select($sql, '*', $data['limit'],'','','id'); // :v9_news
foreach ($ids_array as $id) {
if($result[$id]['title']!='') {
$array[$id] = $result[$id];
$array[$id] = array_merge($array[$id], $hits[$id]); // v9_news v9_hits , id
}
}
return $array;
}
/**
* : url :{pc:content action="category"} {/pc} category
* @param $data
*/
public function category($data) {
$data['catid'] = intval($data['catid']); //pc catid : id
$array = array();
$siteid = $data['siteid'] && intval($data['siteid']) ? intval($data['siteid']) : get_siteid();//pc siteid :
$categorys = getcache('category_content_'.$siteid,'commons'); //
$site = siteinfo($siteid); //
$i = 1;
foreach ($categorys as $catid=>$cat) {
if($i>$data['limit']) break;
if((!$cat['ismenu']) || $siteid && $cat['siteid']!=$siteid) continue;//ismenu: ,1- 0-
if (strpos($cat['url'], '://') === false) { // url "://"
$cat['url'] = substr($site['domain'],0,-1).$cat['url']; // url
}
if($cat['parentid']==$data['catid']) { // 0, ,$cat['parentid']
$array[$catid] = $cat; //
$i++;
}
}
return $array;
}
/**
* , url :{pc:content action="position"} {/pc} position
* @param $data
*/
public function position($data) {
$sql = '';
$array = array();
$posid = intval($data['posid']); //pc posid : id
$order = $data['order']; //pc order
$thumb = (empty($data['thumb']) || intval($data['thumb']) == 0) ? 0 : 1;//pc thumb
$siteid = $GLOBALS['siteid'] ? $GLOBALS['siteid'] : 1; // id
$catid = (empty($data['catid']) || $data['catid'] == 0) ? '' : intval($data['catid']);//pc catid
if($catid) { // id
$siteids = getcache('category_content','commons'); // id
if(!$siteids[$catid]) return false; // , false
$siteid = $siteids[$catid]; // id
$this->category = getcache('category_content_'.$siteid,'commons');// id
}
if($catid && $this->category[$catid]['child']) { //
$catids_str = $this->category[$catid]['arrchildid']; // id, id
$pos = strpos($catids_str,',')+1;
$catids_str = substr($catids_str, $pos); // id, id
$sql = "`catid` IN ($catids_str) AND "; // sql
} elseif($catid && !$this->category[$catid]['child']) { //
$sql = "`catid` = '$catid' AND ";
}
if($thumb) $sql .= "`thumb` = '1' AND "; //
if(isset($data['where'])) $sql .= $data['where'].' AND '; //pc where :
if(isset($data['expiration']) && $data['expiration']==1) $sql .= '(`expiration` >= \''.SYS_TIME.'\' OR `expiration` = \'0\' ) AND ';
$sql .= "`posid` = '$posid' AND `siteid` = '".$siteid."'"; // sql
$pos_arr = $this->position->select($sql, '*', $data['limit'],$order);// v9_position_data
if(!empty($pos_arr)) {
foreach ($pos_arr as $info) { // v9_position_data
$key = $info['catid'].'-'.$info['id']; // : id- id
$array[$key] = string2array($info['data']); // v9_position_data data
$array[$key]['url'] = go($info['catid'],$info['id']); //url
$array[$key]['id'] = $info['id']; // id
$array[$key]['catid'] = $info['catid']; // id
$array[$key]['listorder'] = $info['listorder']; //
}
}
return $array;
}
/**
* , pc
*/
public function pc_tag() {
$positionlist = getcache('position','commons');
$sites = pc_base::load_app_class('sites','admin');
$sitelist = $sites->pc_tag_list();
foreach ($positionlist as $_v) if($_v['siteid'] == get_siteid() || $_v['siteid'] == 0) $poslist[$_v['posid']] = $_v['name'];
return array(
'action'=>array('lists'=>L('list','', 'content'),'position'=>L('position','', 'content'), 'category'=>L('subcat', '', 'content'), 'relation'=>L('related_articles', '', 'content'), 'hits'=>L('top', '', 'content')),
'lists'=>array(
'catid'=>array('name'=>L('catid', '', 'content'),'htmltype'=>'input_select_category','data'=>array('type'=>0),'validator'=>array('min'=>1)),
'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'))),
'thumb'=>array('name'=>L('thumb', '', 'content'), 'htmltype'=>'radio','data'=>array('0'=>L('all_list', '', 'content'), '1'=>L('thumb_list', '', 'content'))),
'moreinfo'=>array('name'=>L('moreinfo', '', 'content'), 'htmltype'=>'radio', 'data'=>array('1'=>L('yes'), '0'=>L('no')))
),
'position'=>array(
'posid'=>array('name'=>L('posid', '', 'content'),'htmltype'=>'input_select','data'=>$poslist,'validator'=>array('min'=>1)),
'catid'=>array('name'=>L('catid', '', 'content'),'htmltype'=>'input_select_category','data'=>array('type'=>0),'validator'=>array('min'=>0)),
'thumb'=>array('name'=>L('thumb', '', 'content'), 'htmltype'=>'radio','data'=>array('0'=>L('all_list', '', 'content'), '1'=>L('thumb_list', '', 'content'))),
'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'))),
),
'category'=>array(
'siteid'=>array('name'=>L('siteid'), 'htmltype'=>'input_select', 'data'=>$sitelist),
'catid'=>array('name'=>L('catid', '', 'content'), 'htmltype'=>'input_select_category', 'data'=>array('type'=>0))
),
'relation'=>array(
'catid'=>array('name'=>L('catid', '', 'content'), 'htmltype'=>'input_select_category', 'data'=>array('type'=>0), 'validator'=>array('min'=>1)),
'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'))),
'relation'=>array('name'=>L('relevant_articles_id', '', 'content'), 'htmltype'=>'input'),
'keywords'=>array('name'=>L('key_word', '', 'content'), 'htmltype'=>'input')
),
'hits'=>array(
'catid'=>array('name'=>L('catid', '', 'content'), 'htmltype'=>'input_select_category', 'data'=>array('type'=>0), 'validator'=>array('min'=>1)),
'day'=>array('name'=>L('day_select', '', 'content'), 'htmltype'=>'input', 'data'=>array('type'=>0)),
),
);
}
}