content_output.class.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <?php
  2. class content_output {
  3. var $fields;
  4. var $data;
  5. function __construct($modelid,$catid = 0,$categorys = array()) {
  6. $this->modelid = $modelid;
  7. $this->catid = $catid;
  8. $this->categorys = $categorys;
  9. $this->fields = getcache('model_field_'.$modelid,'model');
  10. }
  11. function get($data) {
  12. $this->data = $data;
  13. $this->id = $data['id'];
  14. $info = array();
  15. foreach($this->fields as $field=>$v) {
  16. if(!isset($data[$field])) continue;
  17. $func = $v['formtype'];
  18. $value = $data[$field];
  19. $result = method_exists($this, $func) ? $this->$func($field, $data[$field]) : $data[$field];
  20. if($result !== false) $info[$field] = $result;
  21. }
  22. return $info;
  23. }
  24. function editor($field, $value) {
  25. $setting = string2array($this->fields[$field]['setting']);
  26. if($setting['enablekeylink']) {
  27. $value = $this->_keylinks($value, $setting['replacenum'],$setting['link_mode']);
  28. }
  29. return $value;
  30. }
  31. function _base64_encode($matches) {
  32. return $matches[1]."\"".base64_encode($matches[2])."\"";
  33. }
  34. function _base64_decode($matches) {
  35. return $matches[1]."\"".base64_decode($matches[2])."\"";
  36. }
  37. function _keylinks($txt, $replacenum = '',$link_mode = 1) {
  38. $search = "/(alt\s*=\s*|title\s*=\s*)[\"|\'](.+?)[\"|\']/is";
  39. $txt = preg_replace_callback($search, array($this, '_base64_encode'), $txt);
  40. $keywords = $this->data['keywords'];
  41. if($keywords) $keywords = strpos(',',$keywords) === false ? explode(' ',$keywords) : explode(',',$keywords);
  42. if($link_mode && !empty($keywords)) {
  43. foreach($keywords as $keyword) {
  44. $linkdatas[] = $keyword;
  45. }
  46. } else {
  47. $linkdatas = getcache('keylink','commons');
  48. }
  49. if($linkdatas) {
  50. $word = $replacement = array();
  51. foreach($linkdatas as $v) {
  52. if($link_mode && $keywords) {
  53. $word1[] = '/(?!(<a.*?))' . preg_quote($v, '/') . '(?!.*<\/a>)/s';
  54. $word2[] = $v;
  55. $replacement[] = '<a href="javascript:;" onclick="show_ajax(this)" class="keylink">'.$v.'</a>';
  56. } else {
  57. $word1[] = '/(?!(<a.*?))' . preg_quote($v[0], '/') . '(?!.*<\/a>)/s';
  58. $word2[] = $v[0];
  59. $replacement[] = '<a href="'.$v[1].'" target="_blank" class="keylink">'.$v[0].'</a>';
  60. }
  61. }
  62. if($replacenum != '') {
  63. $txt = preg_replace($word1, $replacement, $txt, $replacenum);
  64. } else {
  65. $txt = str_replace($word2, $replacement, $txt);
  66. }
  67. }
  68. $txt = preg_replace_callback($search, array($this, '_base64_decode'), $txt);
  69. return $txt;
  70. }
  71. function title($field, $value) {
  72. $value = new_html_special_chars($value);
  73. return $value;
  74. }
  75. function box($field, $value) {
  76. extract(string2array($this->fields[$field]['setting']));
  77. if($outputtype) {
  78. return $value;
  79. } else {
  80. $options = explode("\n",$this->fields[$field]['options']);
  81. foreach($options as $_k) {
  82. $v = explode("|",$_k);
  83. $k = trim($v[1]);
  84. $option[$k] = $v[0];
  85. }
  86. $string = '';
  87. switch($this->fields[$field]['boxtype']) {
  88. case 'radio':
  89. $string = $option[$value];
  90. break;
  91. case 'checkbox':
  92. $value_arr = explode(',',$value);
  93. foreach($value_arr as $_v) {
  94. if($_v) $string .= $option[$_v].' 、';
  95. }
  96. break;
  97. case 'select':
  98. $string = $option[$value];
  99. break;
  100. case 'multiple':
  101. $value_arr = explode(',',$value);
  102. foreach($value_arr as $_v) {
  103. if($_v) $string .= $option[$_v].' 、';
  104. }
  105. break;
  106. }
  107. return $string;
  108. }
  109. }
  110. function images($field, $value) {
  111. return string2array($value);
  112. }
  113. function datetime($field, $value) {
  114. $setting = string2array($this->fields[$field]['setting']);
  115. extract($setting);
  116. if($fieldtype=='date' || $fieldtype=='datetime') {
  117. return $value;
  118. } else {
  119. $format_txt = $format;
  120. }
  121. if(strlen($format_txt)<6) {
  122. $isdatetime = 0;
  123. } else {
  124. $isdatetime = 1;
  125. }
  126. if(!$value) $value = SYS_TIME;
  127. $value = date($format_txt,$value);
  128. return $value;
  129. }
  130. function keyword($field, $value) {
  131. if($value == '') return '';
  132. $v = '';
  133. if(strpos($value, ',')===false) {
  134. $tags = explode(' ', $value);
  135. } else {
  136. $tags = explode(',', $value);
  137. }
  138. return $tags;
  139. }
  140. function copyfrom($field, $value) {
  141. static $copyfrom_array;
  142. if(!$copyform_array) $copyfrom_array = getcache('copyfrom','admin');
  143. if($value && strpos($value,'|')!==false) {
  144. $arr = explode('|',$value);
  145. $value = $arr[0];
  146. $value_data = $arr[1];
  147. }
  148. if($value_data) {
  149. $copyfrom_link = $copyfrom_array[$value_data];
  150. if(!empty($copyfrom_array)) {
  151. $imgstr = '';
  152. if($value=='') $value = $copyfrom_link['siteurl'];
  153. if($copyfrom_link['thumb']) $imgstr = "<a href='{$copyfrom_link[siteurl]}' target='_blank'><img src='{$copyfrom_link[thumb]}' height='15'></a> ";
  154. return $imgstr."<a href='$value' target='_blank' style='color:#AAA'>{$copyfrom_link[sitename]}</a>";
  155. }
  156. } else {
  157. return $value;
  158. }
  159. }
  160. function groupid($field, $value) {
  161. if($value) $value = explode(',',$value);
  162. return $value;
  163. }
  164. function linkage($field, $value) {
  165. $setting = string2array($this->fields[$field]['setting']);
  166. $datas = getcache($setting['linkageid'],'linkage');
  167. $infos = $datas['data'];
  168. if($setting['showtype']==1 || $setting['showtype']==3) {
  169. $result = get_linkage($value, $setting['linkageid'], $setting['space'], $setting['showtype']);
  170. } elseif($setting['showtype']==2) {
  171. $result = $value;
  172. } else {
  173. $result = get_linkage($value, $setting['linkageid'], $setting['space'], 2);
  174. }
  175. return $result;
  176. }
  177. function downfile($field, $value) {
  178. extract(string2array($this->fields[$field]['setting']));
  179. $list_str = array();
  180. if($value){
  181. $value_arr = explode('|',$value);
  182. $fileurl = $value_arr['0'];
  183. if($fileurl) {
  184. $sel_server = $value_arr['1'] ? explode(',',$value_arr['1']) : '';
  185. $server_list = getcache('downservers','commons');
  186. if(is_array($server_list)) {
  187. foreach($server_list as $_k=>$_v) {
  188. if($value && is_array($sel_server) && in_array($_k,$sel_server)) {
  189. $downloadurl = $_v[siteurl].$fileurl;
  190. if($downloadlink) {
  191. $a_k = urlencode(sys_auth("i=$this->id&s=$_v[siteurl]&m=1&f=$fileurl&d=$downloadtype&modelid=$this->modelid&catid=$this->catid", 'ENCODE', pc_base::load_config('system','auth_key')));
  192. $list_str[] = "<a href='".APP_PATH."index.php?m=content&c=down&a_k={$a_k}' target='_blank'>{$_v[sitename]}</a>";
  193. } else {
  194. $list_str[] = "<a href='{$downloadurl}' target='_blank'>{$_v[sitename]}</a>";
  195. }
  196. }
  197. }
  198. }
  199. return $list_str;
  200. }
  201. }
  202. }
  203. function downfiles($field, $value) {
  204. extract(string2array($this->fields[$field]['setting']));
  205. $list_str = array();
  206. $file_list = string2array($value);
  207. if(is_array($file_list)) {
  208. foreach($file_list as $_k=>$_v) {
  209. if($_v[fileurl]){
  210. $filename = $_v[filename] ? $_v[filename] : L('click_to_down');
  211. if($downloadlink) {
  212. $a_k = urlencode(sys_auth("i=$this->id&s=&m=1&f=$_v[fileurl]&d=$downloadtype&modelid=$this->modelid&catid=$this->catid", 'ENCODE', pc_base::load_config('system','auth_key')));
  213. $list_str[] = "<a href='".APP_PATH."index.php?m=content&c=down&a_k={$a_k}' target='_blank'>{$filename}</a>";
  214. } else {
  215. $list_str[] = "<a href='{$_v[fileurl]}' target='_blank'>{$filename}</a>";
  216. }
  217. }
  218. }
  219. }
  220. return $list_str;
  221. }
  222. function map($field, $value) {
  223. $str = '';
  224. $setting = string2array($this->fields[$field]['setting']);
  225. $setting[width] = $setting[width] ? $setting[width] : '600';
  226. $setting[height] = $setting[height] ? $setting[height] : '400';
  227. list($lngX, $latY,$zoom) = explode('|', $value);
  228. if($setting['maptype']==1) {
  229. $str = "<script src='http://app.mapabc.com/apis?&t=flashmap&v=2.4&key=$setting[api_key]&hl=zh-CN' type='text/javascript'></script>";
  230. } elseif($setting['maptype']==2) {
  231. $str = "<script type='text/javascript' src='http://api.map.baidu.com/api?v=1.2&key=$setting[api_key]'></script>";
  232. }
  233. $str .= '<div id="mapObj" class="view" style="width: '.$setting[width].'px; height:'.$setting[height].'px"></div>';
  234. $str .='<script type="text/javascript">';
  235. if($setting['maptype']==1) {
  236. $str .='
  237. var mapObj=null;
  238. lngX = "'.$lngX.'";
  239. latY = "'.$latY.'";
  240. zoom = "'.$zoom.'";
  241. var mapOptions = new MMapOptions();
  242. mapOptions.toolbar = MConstants.MINI;
  243. mapOptions.scale = new MPoint(20,20);
  244. mapOptions.zoom = zoom;
  245. mapOptions.mapComButton = MConstants.SHOW_NO
  246. mapOptions.center = new MLngLat(lngX,latY);
  247. var mapObj = new MMap("mapObj", mapOptions);
  248. var maptools = new MMapTools(mapObj);
  249. drawPoints();
  250. ';
  251. $str .='
  252. function drawPoints(){
  253. var markerOption = new MMarkerOptions();
  254. var tipOption=new MTipOptions();//添加信息窗口
  255. var address = "'.$address.'";
  256. tipOption.tipType = MConstants.HTML_BUBBLE_TIP;//信息窗口标题
  257. tipOption.title = address;//信息窗口标题
  258. tipOption.content = address;//信息窗口内容
  259. var markerOption = new MMarkerOptions();
  260. markerOption.imageUrl="'.IMG_PATH.'icon/mak.png";
  261. markerOption.picAgent=false;
  262. markerOption.imageAlign=MConstants.BOTTOM_CENTER;
  263. markerOption.tipOption = tipOption;
  264. markerOption.canShowTip= address ? true : false;
  265. markerOption.dimorphicColor="0x00A0FF";
  266. Mmarker = new MMarker(new MLngLat(lngX,latY),markerOption);
  267. Mmarker.id="mark101";
  268. mapObj.addOverlay(Mmarker,true)
  269. }';
  270. } elseif($setting['maptype']==2) {
  271. $str .='
  272. var mapObj=null;
  273. lngX = "'.$lngX.'";
  274. latY = "'.$latY.'";
  275. zoom = "'.$zoom.'";
  276. var mapObj = new BMap.Map("mapObj");
  277. var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
  278. mapObj.addControl(ctrl_nav);
  279. mapObj.enableDragging();
  280. mapObj.enableScrollWheelZoom();
  281. mapObj.enableDoubleClickZoom();
  282. mapObj.enableKeyboard();//启用键盘上下左右键移动地图
  283. mapObj.centerAndZoom(new BMap.Point(lngX,latY),zoom);
  284. drawPoints();
  285. ';
  286. $str .='
  287. function drawPoints(){
  288. var myIcon = new BMap.Icon("'.IMG_PATH.'icon/mak.png", new BMap.Size(27, 45));
  289. var center = mapObj.getCenter();
  290. var point = new BMap.Point(lngX,latY);
  291. var marker = new BMap.Marker(point, {icon: myIcon});
  292. mapObj.addOverlay(marker);
  293. }';
  294. }
  295. $str .='</script>';
  296. return $str;
  297. }
  298. function video($field, $value) {
  299. $video_content_db = pc_base::load_model('video_content_model');
  300. $video_store_db = pc_base::load_model('video_store_model');
  301. //先获取目前contentid下面的videoid
  302. $videos = $video_content_db->select(array('contentid'=>$this->id, 'modelid'=>$this->modelid), 'videoid', '', '`listorder` ASC', '', 'videoid');
  303. if (is_array($videos) && !empty($videos)) {
  304. $videoids = '';
  305. foreach ($videos as $_vid => $r) {
  306. $videoids .= $_vid.',';
  307. }
  308. $videoids = substr($videoids, 0, -1);
  309. $result = $video_store_db->select("`videoid` IN($videoids) AND `status`=21", '*', '', '', '', 'videoid');
  310. $pagenumber = count($result);
  311. $return_data = array();
  312. if ($pagenumber>0) {
  313. if (is_array($result) && !empty($result)) {
  314. //首先对$result按照$videos的videoid排序
  315. foreach ($videos as $_vid => $v) {
  316. if ($result[$_vid]) $new_result[] = $result[$_vid];
  317. }
  318. unset($result, $_vid, $v);
  319. }
  320. $this->url = pc_base::load_app_class('url', 'content');
  321. for($i=1; $i<=$pagenumber; $i++) {
  322. $pageurls[$i] = $this->url->show($this->id, $i, $this->data['catid'], $this->data['inputtime']);
  323. }
  324. //构建返回数组
  325. foreach ($pageurls as $page =>$urls) {
  326. $_k = $page - 1;
  327. if ($_k==0) $arr = reset($new_result);
  328. else $arr = next($new_result);
  329. $return_data['data'][$page]['title'] = $arr['title'] ? new_html_special_chars($arr['title']) : new_html_special_chars($this->data['title']);
  330. $return_data['data'][$page]['url'] = $urls[0];
  331. $return_data['vid'] = $arr['vid'];
  332. $return_data['channelid'] = $arr['channelid'];
  333. }
  334. $category_db = pc_base::load_model('category_model');
  335. $r = $category_db->get_one(array('catid'=>$this->data['catid']), 'modelid, setting, siteid');
  336. $setting = string2array($r['setting']);
  337. $siteid = intval($r['siteid']);
  338. if ($setting['content_ishtml']) {
  339. if (!function_exists('content_pages')) {
  340. pc_base::load_app_func('util', 'content');
  341. }
  342. $modelid = intval($r['modelid']);
  343. $data = $this->data;
  344. unset($data[$field]);
  345. $output_data = $this->get($data);
  346. extract($output_data);
  347. $id = $this->id;
  348. //SEO
  349. $seo_keywords = '';
  350. if(!empty($keywords)) $seo_keywords = implode(',',$keywords);
  351. $SEO = seo($siteid, $catid, $title, $description, $seo_keywords);
  352. $this->html_root = pc_base::load_config('system','html_root');
  353. $this->sitelist = getcache('sitelist','commons');
  354. $this->queue = pc_base::load_model('queue_model');
  355. $template = $this->data['template'] ? $this->data['template'] : $setting['show_template'];
  356. foreach ($pageurls as $page => $urls) {
  357. $_k = $page - 1;
  358. if ($_k==0) {
  359. $arr = $first = reset($new_result);
  360. } else {
  361. $arr = next($new_result);
  362. }
  363. $return_data['vid'] = $arr['vid'];
  364. ${$field} = $return_data;
  365. $pagefile = $urls[1];
  366. if($siteid!=1) {
  367. $site_dir = $this->sitelist[$siteid]['dirname'];
  368. $pagefile = $this->html_root.'/'.$site_dir.$pagefile;
  369. }
  370. $this->queue->add_queue('add',$pagefile,$siteid);
  371. $pagefile = PHPCMS_PATH.$pagefile;
  372. ob_start();
  373. include template('content', $template);
  374. $data = ob_get_contents();
  375. ob_clean();
  376. $dir = dirname($pagefile);
  377. if(!is_dir($dir)) {
  378. mkdir($dir, 0777,1);
  379. }
  380. $strlen = file_put_contents($pagefile, $data);
  381. @chmod($file,0777);
  382. }
  383. $return_data['vid'] = $first['vid'];
  384. unset($new_result);
  385. }
  386. return $return_data;
  387. } else {
  388. return array();
  389. }
  390. }
  391. }
  392. }
  393. ?>