News.class.php
4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* 默认控制器
*/
class Controller_News extends Controller_Abstract
{
public function indexAction()
{
$requestTag = trim($this->_request->tag);//标签
$limit = 40;
$tag = $requestTag;
if($requestTag == '视频')
{
//html5视频为手机视频
if($this->_platform == 'android' || $this->_platform == 'iphone')
{
$tag = '手机视频';
}
}
if($this->_platform == 'android' || $this->_platform == 'iphone')
{
$exceptTags = array('视频');
}
else
{
$exceptTags = array('手机视频');
}
$total = Facade_News::getTotal($tag, $exceptTags);
$page = new Lib_Helper_Pagination($total, $limit);
if ($tag)
{
$page->setParames(array('tag' => $requestTag)) ;
}
$tagKeys = Facade_News::$types;
$list = Facade_News::getList($tag, $page->getOffset(), $limit, $exceptTags);
$this->_view['list'] = $list;
$newTags = Facade_News::getTags();
$this->_view['total'] = 0;
$tags = array();
foreach($tagKeys as $tagKey)
{
$tags[$tagKey] = array('tag' => $tagKey, 'num'=> 0);
foreach($newTags as $newTag)
{
if($newTag['tag'] == '手机视频')//手机视频变成视频,HTML5
{
$newTag['tag'] = '视频';
}
if($tagKey == $newTag['tag'])
{
$tags[$tagKey] = $newTag;
}
}
}
$this->_view['tags'] = $tags;
foreach($this->_view['tags'] as $val)
{
$this->_view['total'] += $val['num'];
}
$page->setOptions(array('afterAppend' => 'setLayout'));
$this->_view['pagination'] = $page->getPagination();
$this->_view['current_tag'] = $requestTag;
/***设置网站的SEO信息***/
$seo = C('APP.Seo');
$this->setTitle($seo['channel_news_title']);
$this->setKeywords($seo['channel_news_keywords']);
$this->setDescription($seo['channel_news_description']);
$seo = null; unset($seo);
}
public function getnewsAction()
{
$tag = $this->_request->query('tag','');
$total = Facade_News::getTotal($tag);
$page = new Lib_Helper_Pagination($total);
list($offset, $limit) = $page->getLimit();
$page->setPageSize($limit)->setParames(array('tag' => $tag))->setModel('autoload2', '#img_flow')
->setOptions(array('afterAppend' => 'setLayout'));
if(!empty($tag))
{
$list = Facade_News::getList(tag, $page->getOffset(), $limit);
}
else
{
$list = Facade_News::getAllNews($page->getOffset(), $limit);
}
$this->_view['list'] = $list;
$this->_view['pagination'] = $page->getPagination();
}
/**
* 详情页
*/
public function detailAction()
{
$id = intval($this->_request->id);
if (empty($id))
{
return $this->_redirect('news/index');
}
$info = Facade_News::getOneById($id);
if (!$info)
{
return $this->_redirect('news/index');
}
$info['title'] = strip_tags($info['title']);
//增加浏览量
Facade_News::updateHits($id);
//获取上一个
$prev = Facade_News::getPrevNews($id);
if ($prev)
{
if ($prev['thumb'])
{
$thumb = Lib_Images::getImageUrl($prev['thumb'], '0138x0075','fragmentimg');
}
else
{
$thumb = SITE_IMG.'/pic01.png';
}
$prev['thumb'] = $thumb ;
$prev['title'] = Util_StringHelper::substr_cn( $this->stripTags($prev['title']),20 );
$prev['desc'] = Util_StringHelper::substr_cn( $this->stripTags($prev['content']),40 );
}
//获取下一个
$next = Facade_News::getNextNews($id);
if ($next)
{
if ($next['thumb'])
{
$thumb = Lib_Images::getImageUrl($next['thumb'], '0138x0075','fragmentimg');
}
else
{
$thumb = SITE_IMG.'/pic01.png';
}
$next['thumb'] = $thumb ;
$next['title'] = Util_StringHelper::substr_cn( $this->stripTags($next['title']),20 );
$next['desc'] = Util_StringHelper::substr_cn( $this->stripTags($next['content']),40 );
}
$this->_view['tags'] = Facade_News::$types;
$this->_view['next'] = $next ;
$this->_view['prev'] = $prev ;
$this->_view['info'] = $info ;
$this->_view['current_tag'] = $this->_request->query('current_tag', '');
/***设置网站的SEO信息***/
$seo = C('APP.Seo');
$this->setTitle($info['title']);
$this->setKeywords($seo['channel_news_keywords']);
$this->setDescription($seo['channel_news_description']);
}
}