-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
148 lines (121 loc) · 5.75 KB
/
view.php
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
<?php
/******************************************************************************
*
* Subrion Articles Publishing Script
* Copyright (C) 2018 Intelliants, LLC <https://intelliants.com>
*
* This file is part of Subrion Articles Publishing Script
*
* This program is a commercial software and any kind of using it must agree
* to the license, see <https://subrion.pro/license.html>.
*
* This copyright notice may not be removed from the software source without
* the permission of Subrion respective owners.
*
*
* @link https://subrion.pro/product/publishing.html
*
******************************************************************************/
if (iaView::REQUEST_HTML == $iaView->getRequestType()) {
// get article id
$articleId = (int)end($iaCore->requestPath);
if (empty($articleId)) {
$articleId = (int)end($iaView->url);
if (empty($articleId)) {
return iaView::errorPage(iaView::ERROR_NOT_FOUND);
}
}
$iaField = $iaCore->factory('field');
$iaArticle = $iaCore->factoryItem('article');
$iaArticleCat = $iaCore->factoryItem('articlecat');
$article = $iaArticle->getById($articleId);
if (empty($article) || ($article['status'] == iaCore::STATUS_APPROVAL && $article['member_id'] != iaUsers::getIdentity()->id)) {
return iaView::errorPage(iaView::ERROR_NOT_FOUND);
}
if ($article['status'] == $iaArticle::STATUS_DRAFT && (!iaUsers::hasIdentity() || iaUsers::getIdentity()->id != $article['member_id'])) {
return iaView::errorPage(iaView::ERROR_FORBIDDEN);
}
$article['item'] = $iaArticle->getItemName();
$iaArticle->incrementViewsCounter($article['id']);
$iaCore->startHook('phpViewListingBeforeStart', [
'listing' => $articleId,
'item' => $article['item'],
'title' => $article['title'],
'url' => $iaArticle->url('view', $article),
'desc' => $article['summary']
]);
// get account information
if ($article['member_id']) {
if ($author = $iaCore->factory('users')->getInfo($article['member_id'])) {
$iaItem = $iaCore->factory('item');
if (iaUsers::hasIdentity() && $article['member_id'] == iaUsers::getIdentity()->id) {
$iaItem->setItemTools([
'id' => 'action-edit',
'title' => iaLanguage::get('edit_article'),
'attributes' => [
'href' => $iaArticle->url(iaCore::ACTION_EDIT, $article)
]
]);
$iaItem->setItemTools([
'id' => 'action-delete',
'title' => iaLanguage::get('delete_article'),
'attributes' => [
'href' => $iaArticle->url(iaCore::ACTION_DELETE, $article),
'class' => 'js-delete-article'
]
]);
}
if ($iaView->blockExists('author_info')) {
$author['rss'] = IA_URL . $iaDb->one('`alias`', "`name` = 'rss_articles'", 'pages') . 'author' . IA_URL_DELIMITER . $author['username'] . '.' . iaCore::EXTENSION_XML;
$author['articles_num'] = $iaDb->one_bind(iaDb::STMT_COUNT_ROWS, '`member_id` = :user AND `status` = :status', ['status' => iaCore::STATUS_ACTIVE, 'user' => (int)$article['member_id']], iaArticle::getTable());
}
if (isset($author['adsense_id'])) {
if (empty($author['adsense_id']) || !preg_match('#^ca\-pub\-[0-9]{16}$#', $author['adsense_id'])) {
unset($author['adsense_id']);
}
}
$iaView->assign('author', $author);
// process default article url
if (!$article['url']) {
$article['url'] = $author['articles_url'];
$article['url_description'] = $author['articles_url_description'];
}
}
}
// breadcrumb
if ($article['category_id']) {
foreach ($iaArticleCat->getParents($article['category_id']) as $p) {
iaBreadcrumb::add($p['title'], $p['link'], -1);
}
}
iaBreadcrumb::replaceEnd($article['title'], IA_SELF);
//
if (iaCore::STATUS_ACTIVE != $article['status']) {
$iaView->setMessages(iaLanguage::get('article_' . $article['status']), iaView::ALERT);
}
// get next & previous articles
$article['prev_article'] = $iaArticle->getPreviousArticle($article['date_added'], $article['category_id']);
$article['next_article'] = $iaArticle->getNextArticle($article['date_added'], $article['category_id']);
// get more author articles
if ($iaView->blockExists('author_articles') && $article['member_id']) {
$authorArticles = [];
$where = 'AND `t1`.`member_id` = ' . $article['member_id'] . ' AND t1.`id` != ' . $articleId;
$authorArticles = $iaArticle->get($where, 0, $iaCore->get('art_perpage_block', 5));
$iaView->assign('author_articles', $authorArticles);
}
$sections = $iaField->getTabs($iaArticle->getItemName(), $article);
if ($iaCore->get('articles_source_link')) {
$article['body'] .= iaLanguage::getf('article_source_url', ['url' => $iaArticle->url('view', $article)]);
}
$category = $iaArticleCat->getById($article['category_id']);
$iaView->assign('category', $category);
$iaView->assign('item', $article);
$iaView->assign('sections', $sections);
$iaView->assign('session_id', session_id());
// define page params
$iaView->set('subpage', $article['category_id']);
$iaView->set('keywords', $article['meta_keywords']);
$iaView->set('description', $article['meta_description']);
$iaView->title(isset($article['title']) ? $article['title'] : iaLanguage::get('page_title_' . $iaView->name()));
$iaView->display('view');
}