-
Notifications
You must be signed in to change notification settings - Fork 0
/
CspThemePlugin.inc.php
303 lines (277 loc) · 9.73 KB
/
CspThemePlugin.inc.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?php
import('lib.pkp.classes.plugins.ThemePlugin');
class CspThemePlugin extends ThemePlugin {
/**
* Carrega os estilos personalizados de nosso tema
* @return null
*/
public function init() {
$this->setParent('bootstrapthreethemeplugin');
$this->addStyle('child-stylesheet', 'styles/index.less');
$this->addScript('csp', 'js/index.js');
$this->addScript('lens', 'js/lens.js');
$this->addStyle('csp', 'styles/backend.less', array( 'contexts' => 'backend'));
HookRegistry::register ('TemplateManager::display', array($this, 'loadTemplateData'));
HookRegistry::register('TemplateManager::fetch', array($this, 'fetchTemplate'));
HookRegistry::register('Templates::Common::Sidebar', array($this, 'addDates'));
}
/**
* Obtem o nome de exibição deste tema
* @return string
*/
function getDisplayName() {
return __('plugins.themes.csp.name');
}
/**
* Obtem a descrição deste plugin
* @return string
*/
function getDescription() {
return __('plugins.themes.csp.description');
}
public function fetchTemplate($hookName, $args){
$request = Application::get()->getRequest();
$router = $request->getRouter();
$page = $router->_page;
$op = $router->getRequestedOp($request);
if($op == "index"){
$context = $request->getContext();
$requestPath = $request->getRequestPath();
$baseUrl = $request->getBaseUrl();
$count = $args[1] != 'frontend/pages/issueArchive.tpl' ? 1 : null;
$params = array(
'contextId' => $context->getId(),
'orderBy' => 'seq',
'orderDirection' => 'ASC',
'count' => $count,
'offset' => 0,
'isPublished' => true
);
$issues = iterator_to_array(Services::get('issue')->getMany($params));
if (isset($issues[0])) {
$coverImageUrl = $issues[0]->getLocalizedCoverImageUrl();
$coverImageAltText = $issues[0]->getLocalizedCoverImageAltText();
} else {
$coverImageUrl = null;
$coverImageAltText = null;
}
$templateMgr = $args[0];
$templateMgr->assign(array(
'issues' => $issues,
'requestPath' => $requestPath,
'baseUrl' => $baseUrl,
'page' => $page,
'coverImageUrl' => $coverImageUrl,
'coverImageAltText' => $coverImageAltText,
'context' => $context,
'op' => $op
));
}
}
public function loadTemplateData($hookName, $args) {
$templateMgr = $args[0];
$request = Application::get()->getRequest();
$context = $args[0]->get_template_vars('currentContext');
$requestPath = $request->getRequestPath();
$baseUrl = $request->getBaseUrl();
$router = $request->getRouter();
$page = $router->_page;
$op = $router->getRequestedOp($request);
$navigationLocale = AppLocale::getLocale();
if (str_contains($args[1], 'frontend')){
$issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
$currentIssue = $issueDao->getCurrent($context->getId());
$userDao = DAORegistry::getDAO('UserDAO');
$interviews = $userDao->retrieve(
<<<QUERY
SELECT p.publication_id, s.setting_value
FROM publications p
LEFT JOIN publication_settings s
ON s.publication_id = p.publication_id
WHERE section_id = (SELECT DISTINCT section_id FROM ojs.section_settings WHERE setting_value = 'ENTREVISTA'
) AND s.setting_name = 'title' AND s.locale = '$navigationLocale'
ORDER BY publication_id DESC LIMIT 3
QUERY
);
if(!is_null($currentIssue)){
$coverImageUrl = $currentIssue->getLocalizedCoverImageUrl();
$coverImageAltText = $currentIssue->getLocalizedCoverImageAltText();
}
} else {
$coverImageUrl = null;
$coverImageAltText = null;
}
/* Make citation */
if($args[1] == "frontend/pages/article.tpl"){
$pathArray = explode("/",$requestPath);
$submissionId = end($pathArray);
$submissionDAO = Application::getSubmissionDAO();
$submission = $submissionDAO->getById($submissionId);
$publication = $submission->getCurrentPublication();
$publicationLocale = $publication->getData('locale');
foreach ($publication->getData('authors') as $key => $value) {
$givenName = $value->getData('givenName',$publicationLocale);
$familyName = !is_null($value->getData('givenName')) ? $value->getData('familyName',$publicationLocale) : null;
if(strpos($givenName, ',')){
$givenNameArray = explode(",", $givenName);
$beginningNameArray = explode(" ", $givenNameArray[1]);
$arraySize = count($beginningNameArray);
for ($i=1; $i < $arraySize; $i++) {
if($beginningNameArray[$i] === strtolower($beginningNameArray[$i])){
$abbrev .= "";
}else{
$abbrev .= substr($beginningNameArray[$i], 0,1);
}
}
$authors[] = $givenNameArray[0]." ".$abbrev;
}else{
if (!is_null($familyName)) {
$givenNameArray = explode(" ", $givenName);
$arraySize = count($givenNameArray);
for ($i=0; $i <= $arraySize; $i++) {
if($givenNameArray[$i] === strtolower($givenNameArray[$i])){
$abbrev .= "";
}else{
$abbrev .= substr($givenNameArray[$i], 0,1);
}
}
$familyNameArray = explode(" ", $familyName);
$arraySize = count($familyNameArray);
for ($i=0; $i < ($arraySize-1); $i++) {
if($familyNameArray[$i] === strtolower($familyNameArray[$i])){
$abbrev .= "";
}else{
$abbrev .= substr($familyNameArray[$i], 0,1);
}
}
$authors[]= end($familyNameArray)." ".$abbrev;
}else{
$givenNameArray = explode(" ", $givenName);
$arraySize = count($givenNameArray);
for ($i=0; $i < ($arraySize-1); $i++) {
if($givenNameArray[$i] === strtolower($givenNameArray[$i])){
$abbrev .= "";
}else{
$abbrev .= substr($givenNameArray[$i], 0,1);
}
}
$authors[] = $givenNameArray[$arraySize-1]." ".$abbrev;
}
}
unset($abbrev);
}
$issueDao = DAORegistry::getDAO('IssueDAO'); /* @var $issueDao IssueDAO */
$issue = $issueDao->getById($publication->getData('issueId'));
$citation = implode(", ",$authors).". ";
$citation .= $publication->getData('title',$publicationLocale).". ";
$citation .= $context->getLocalizedName()." ";
$citation .= $issue->getData('year')."; ";
$citation .= $issue->getData('volume');
$citation .= "(".$issue->getData('number').")";
if($issue->getData('year') > 2016){
$doiArray = explode('x', strtolower($publication->getLocalizedData('pub-id::doi')));
$citation .= ':e00'.substr($doiArray[1],2);
}
if ($publication->getLocalizedData('pub-id::doi')) {
$citation .= " doi: ".$publication->getLocalizedData('pub-id::doi');
}
$templateMgr->assign(array(
'issue' => $issue,
));
}
$templateMgr->assign(array(
'requestPath' => $requestPath,
'baseUrl' => $baseUrl,
'page' => $page,
'coverImageUrl' => $coverImageUrl,
'coverImageAltText' => $coverImageAltText,
'context' => $context,
'op' => $op,
'interviews' => $interviews,
'citation' => $citation,
'navigationLocale' => $navigationLocale
));
if($args[1] == 'frontend/pages/userRegister.tpl'){ /* Passa id de avaliador para checkbox ir marcado */
$userGroupDao = DAORegistry::getDAO('UserGroupDAO');
$group = $userGroupDao->getDefaultByRoleId($context->getId(), ROLE_ID_REVIEWER);
$userGroupIds[] = $group->getData('id');
$templateMgr->assign('userGroupIds',$userGroupIds);
}
if($args[1] == 'frontend/pages/issueArchive.tpl'){
$userDao = DAORegistry::getDAO('UserDAO');
$resultAno = $userDao->retrieve(
<<<QUERY
SELECT DISTINCT `year` AS ANO
FROM ojs.issues i
ORDER BY i.`year` DESC
QUERY
);
foreach ($resultAno as $rowAno) {
$resultMes = $userDao->retrieve(
<<<QUERY
SELECT
`year`,
volume,
CASE
WHEN `year` <= 2005 AND setting_value like '%sup%' THEN CONCAT('Supl.', `number`)
WHEN `year` <= 2005 AND `number` > 12 THEN CONCAT('Supl.', (`number` - 12))
WHEN `year` > 2005 AND `number` > 12 THEN CONCAT('Supl.', (`number` - 12))
ELSE `number`
END numero,
number,
i.issue_id,
CASE
WHEN setting_value like '%sup%' THEN 12 + CONVERT(REPLACE(i.`number`,'supl.',''),INT)
ELSE CONVERT(`number`,INT)
END ordem
FROM
ojs.issues i
LEFT JOIN
ojs.issue_settings s
ON
s.issue_id = i.issue_id
WHERE
`year` = $rowAno->ANO
AND s.setting_name = 'title'
and s.locale = 'pt_BR'
and i.published = 1
ORDER BY ordem
QUERY
);
foreach ($resultMes as $rowIssue) {
$array[$rowAno->ANO][$rowIssue->volume][$rowIssue->numero] = $rowIssue->issue_id;
}
}
$templateMgr = $args[0];
$templateMgr->assign('issues', $array);
}
}
function addDates($hookName, $params) {
$request = Application::get()->getRequest();
if(strpos($request->_requestPath, 'article/view')){
$smarty = $params[1];
$article = $smarty->get_template_vars('article');
$dates = "";
$submitdate = $article->getDateSubmitted();
$publishdate = $article->getDatePublished();
// Get all decisions for this submission
$editDecisionDao = DAORegistry::getDAO('EditDecisionDAO');
$decisions = $editDecisionDao->getEditorDecisions($article->getId());
// Loop through the decisions
foreach ($decisions as $decision) {
// If we have a review stage decision and it was a submission accepted decision, get to date for the decision
if ($decision['decision'] == '1')
$reviewdate = $decision['dateDecided'];
}
$dates = array();
if ($submitdate)
$dates['received'] = date('Y-m-d',strtotime($submitdate));
if ($reviewdate)
$dates['accepted'] = date('Y-m-d',strtotime($reviewdate));
if ($publishdate)
$dates['published'] = date('Y-m-d',strtotime($publishdate));
$smarty->assign('dates', $dates);
return false;
}
}
}