123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace Content\Lib;
- use Dever;
- class Article
- {
-
- public function get($data)
- {
- if (!is_array($data)) {
- $data = Dever::db('content/article')->getOne($data);
- }
-
- if (!$data) {
- Dever::alert('错误的文章信息');
- }
-
-
- $data['content_array'] = array();
- if (strstr($data['content'], 'font-family:" gb","microsoft="" sans="" hiragino="" yahei","simsun";')) {
- $data['content'] = str_replace('font-family:" gb","microsoft="" sans="" hiragino="" yahei","simsun";', '', $data['content']);
- }
- if (strstr($data['content'], 'font-family:" yahei","simsun";')) {
- $data['content'] = str_replace('font-family:" yahei","simsun";', '', $data['content']);
- }
- if (strstr($data['content'], '"="" gb","microsoft="" sans="" hiragino="')) {
- $data['content'] = str_replace('"="" gb","microsoft="" sans="" hiragino="', '', $data['content']);
- }
- if (strstr($data['content'], '"="')) {
- $data['content'] = str_replace('"="', '', $data['content']);
- }
- if (strstr($data['content'], 'embed')) {
-
-
- preg_match_all('/<embed src="(.*?)"(.*?)\/>/i', $data['content'], $matches);
- if (isset($matches[1])) {
- foreach ($matches[1] as $k => $v) {
- }
- }
- }
- if (strstr($data['content'], 'data-id')) {
-
- preg_match_all('/<p>(\s[^>]*)<img(.*?)data-id="(.*?)" data-key="(.*?)" \/>(\s[^>]*)<\/p>/is', $data['content'], $matches);
- $replace = array();
- $content = $data['content'];
- if (isset($matches[3][0]) && isset($matches[4][0])) {
- foreach ($matches[3] as $k => $v) {
- $content = str_replace($matches[0][$k], '{replace}'.$k.'{replace}', $content);
- if ($matches[4][$k] == 'video/lib/core.vod') {
- $method = 'video/lib/vod';
- $type = 2;
- } else {
- $type = 3;
- $method = 'video/lib/live';
- }
- $info = Dever::load($method)->get($v);
- $replace[$k] = array('id' => $v, 'type' => $type, 'content' => $info);
- }
- }
-
- $content = explode('{replace}', $content);
- $data['content_array'] = array();
- foreach ($content as $k => $v) {
- if (is_numeric($v) && $v >= 0 && isset($replace[$v])) {
- $data['content_array'][] = $replace[$v];
- } elseif ($content[$k]) {
- $data['content_array'][] = array
- (
- 'type' => 1,
- 'content' => $v,
- );
- }
- }
- }
- if (!$data['content_array']) {
- $data['content_array'][] = array
- (
- 'type' => 1,
- 'content' => $data['content'],
- );
- }
- unset($data['content']);
- print_r($data);die;
- return $data;
- }
-
- public function getRelation($info)
- {
- $where['noid'] = $info['id'];
- $where['cate_id'] = $info['cate_id'];
- return Dever::db('content/article')->getRelation($where);
- }
-
- public function addView($id)
- {
- Dever::db('content/article')->addView($id);
- }
- }
|