This repository has been archived by the owner on Nov 19, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.user_toctoc_comments_ttnews.php
302 lines (269 loc) · 11.3 KB
/
class.user_toctoc_comments_ttnews.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
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 - 2016 Gisele Wendl <gisele.wendl@toctoc.ch>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*
*
*
* 52: class user_toctoc_comments_ttnews
* 62: public function extraItemMarkerProcessor($markerArray, $row, $lConf, &$pObj)
* 223: private function getNumberOfComments($newsUid, &$pObj)
* 242: private function getTemplate($section, $conf, &$pObj)
* 275: private function getItemLink($itemUid, &$pObj)
*
* TOTAL FUNCTIONS: 4
* (This index is automatically created/updated by the extension "extdeveval")
*
*/
if (version_compare(TYPO3_version, '6.0', '<')) {
require_once(t3lib_extMgm::extPath('lang', 'lang.php'));
} else {
require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('lang') . 'Classes/LanguageService.php';
}
/**
* This class provides hook to tt_news to add extra markers.
*
* @author Gisele Wendl <gisele.wendl@toctoc.ch>
* @package TYPO3
* @subpackage toctoc_comments
*/
class user_toctoc_comments_ttnews {
/**
* Processes comments-specific markers for tt_news
*
* @param array $markerArray Array with merkers
* @param array $row tt_news record
* @param array $lConf Configuration array for current tt_news view
* @param tx_ttnews $pObj Reference to parent object
* @return array Modified marker array
*/
public function extraItemMarkerProcessor($markerArray, $row, $lConf, &$pObj) {
/* @var $pObj tx_ttnews */
if (version_compare(TYPO3_version, '6.3', '>')) {
(class_exists('t3lib_extMgm', FALSE)) ? TRUE : class_alias('\TYPO3\CMS\Core\Utility\ExtensionManagementUtility', 't3lib_extMgm');
(class_exists('t3lib_div', FALSE)) ? TRUE : class_alias('TYPO3\CMS\Core\Utility\GeneralUtility', 't3lib_div');
(class_exists('language', FALSE)) ? TRUE : class_alias('TYPO3\CMS\Lang\LanguageService', 'language');
(class_exists('tslib_cObj', FALSE)) ? TRUE : class_alias('TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer', 'tslib_cObj');
}
$beginlist =0;
$endlist =0;
$poscommentscount=0;
$poscommentsplugin =0;
if ($pObj->theCode == 'LIST') {
$beginlist= strpos ($pObj->templateCode, '###TEMPLATE_LIST### begin');
$endlist= strpos ($pObj->templateCode, '###TEMPLATE_LIST### end');
$poscommentscount= strpos ($pObj->templateCode, '###TX_COMMENTS_COUNT###', $beginlist);
$poscommentsplugin = strpos ($pObj->templateCode, '###TX_TOCTOCCOMMENTS###', $beginlist);
}
if ($pObj->theCode == 'LIST2') {
$beginlist= strpos ($pObj->templateCode, '###TEMPLATE_LIST2### begin');
$endlist= strpos ($pObj->templateCode, '###TEMPLATE_LIST2### end');
$poscommentscount= strpos ($pObj->templateCode, '###TX_COMMENTS_COUNT###', $beginlist);
$poscommentsplugin = strpos ($pObj->templateCode, '###TX_TOCTOCCOMMENTS###', $beginlist);
}
if ($pObj->theCode == 'LIST3') {
$beginlist= strpos ($pObj->templateCode, '###TEMPLATE_LIST2### begin');
$endlist= strpos ($pObj->templateCode, '###TEMPLATE_LIST2### end');
$poscommentscount= strpos ($pObj->templateCode, '###TX_COMMENTS_COUNT###', $beginlist);
$poscommentsplugin = strpos ($pObj->templateCode, '###TX_TOCTOCCOMMENTS###', $beginlist);
}
if ($pObj->theCode == 'SINGLE') {
$beginlist= strpos ($pObj->templateCode, '###TEMPLATE_SINGLE### begin');
$endlist= strpos ($pObj->templateCode, '###TEMPLATE_SINGLE### end');
$poscommentscount= strpos ($pObj->templateCode, '###TX_COMMENTS_COUNT###', $beginlist);
$poscommentsplugin = strpos ($pObj->templateCode, '###TX_TOCTOCCOMMENTS###', $beginlist);
}
if ($pObj->theCode == 'LATEST') {
$beginlist= strpos ($pObj->templateCode, '###TEMPLATE_LATEST### begin');
$endlist= strpos ($pObj->templateCode, '###TEMPLATE_LATEST### end');
$poscommentscount= strpos ($pObj->templateCode, '###TX_COMMENTS_COUNT###', $beginlist);
$poscommentsplugin = strpos ($pObj->templateCode, '###TX_TOCTOCCOMMENTS###', $beginlist);
}
if ($pObj->theCode == 'SEARCH') {
$beginlist= strpos ($pObj->templateCode, '###TEMPLATE_SEARCH### begin');
$endlist= strpos ($pObj->templateCode, '###TEMPLATE_SEARCH### end');
$poscommentscount= strpos ($pObj->templateCode, '###TX_COMMENTS_COUNT###', $beginlist);
$poscommentsplugin = strpos ($pObj->templateCode, '###TX_TOCTOCCOMMENTS###', $beginlist);
}
if ($poscommentscount > 0) {
$markerArray['###TX_COMMENTS_COUNT###'] = 'poscommentscount: '.$poscommentscount . ' $beginlist: '.$beginlist. ' $endlist: '.$endlist;
if (($poscommentscount > $beginlist) && ($poscommentscount < $endlist)) {
switch ($pObj->theCode) {
case 'LATEST':
case 'LIST':
case 'LIST2':
case 'LIST3':
case 'SINGLE':
case 'SEARCH':
// Add marker for number of comments
$commentCount = $this->getNumberOfComments($row['uid'], $pObj);
$templateName = $commentCount ? '###TTNEWS_COMMENT_COUNT_SUB###' : '###TTNEWS_COMMENT_NONE_SUB###';
if (($template = $this->getTemplate($templateName, $lConf, $pObj))) {
$lang = t3lib_div::makeInstance('language');
/* @var $lang language */
$lang->init($GLOBALS['TSFE']->lang);
$commenttextoption=0;
if (is_array($pObj->conf['toctoc_comments.'])) {
$commenttextoption= intval($pObj->conf['toctoc_comments.'][$pObj->theCode . '.']['commentsShowCountText']);
}
if ($commenttextoption==0) {
if ($commentCount==1) {
$commenttextnb=$lang->sL('LLL:EXT:toctoc_comments/locallang_hooks.xml:comments_number_one');
} else {
$commenttextnb = sprintf($lang->sL('LLL:EXT:toctoc_comments/locallang_hooks.xml:comments_number'), $commentCount);
}
$markerArray['###TX_COMMENTS_COUNT###'] = $pObj->cObj->substituteMarkerArray(
$template, array(
'###COMMENTS_COUNT_NUMBER###' => $commentCount,
'###COMMENTS_COUNT###' => $commenttextnb,
'###COMMENTS_COUNT_NONE###' => $lang->sL('LLL:EXT:toctoc_comments/locallang_hooks.xml:comments_number_none'),
'###UID###' => $row['uid'],
'###COMMENTS_LINK###' => $this->getItemLink($row['uid'], $pObj),
)
);
} else {
$markerArray['###TX_COMMENTS_COUNT###'] = $pObj->cObj->substituteMarkerArray(
$template, array(
'###COMMENTS_COUNT_NUMBER###' => intval($commentCount),
'###COMMENTS_COUNT###' => intval($commentCount),
'###COMMENTS_COUNT_NONE###' => '0',
'###UID###' => $row['uid'],
'###COMMENTS_LINK###' => $this->getItemLink($row['uid'], $pObj),
)
);
}
unset($lang);
// Free memory explicitely!
}
break;
}
}
}
if ($poscommentsplugin > 0) {
if (($poscommentsplugin > $beginlist) && ($poscommentsplugin < $endlist)) {
include_once (t3lib_extMgm::extPath('toctoc_comments', 'pi1/class.toctoc_comments_pi1.php'));
$lib = new tx_toctoccomments_pi1;
switch ($pObj->theCode) {
case 'LATEST':
case 'LIST':
case 'LIST2':
case 'LIST3':
case 'SEARCH':
$content='';
if (!$this->cObj) {
$this->cObj = t3lib_div::makeInstance('tslib_cObj');
$this->cObj->start('', '');
}
$conftc=array();
$conftc= $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_toctoccomments_pi1.'];
if (is_array($pObj->conf['toctoc_comments.'])) {
// stuff to merge
$conftc = array_replace_recursive($conftc, $pObj->conf['toctoc_comments.']);
}
$markerArray['###TX_TOCTOCCOMMENTS###'] = $lib->main($content, $conftc, 'tx_ttnews', $row['uid'], $this->cObj);
unset($lib);
break;
}
}
}
return $markerArray;
}
/**
* Retrieves number of comments
*
* @param int $newsUid UID of tt_news item
* @param tx_ttnews $pObj Reference to parent object
* @return int Number of comments for this news item
* @access private
*/
private function getNumberOfComments($newsUid, &$pObj) {
/* @var $pObj tx_ttnews */
$recs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('COUNT(*) AS t', 'tx_toctoc_comments_comments',
'external_prefix=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('tx_ttnews', 'tx_toctoc_comments_comments') .
' AND external_ref=' . $GLOBALS['TYPO3_DB']->fullQuoteStr('tt_news_' . $newsUid, 'tx_toctoc_comments_comments') .
' AND approved=1 ' .
$pObj->cObj->enableFields('tx_toctoc_comments_comments'));
return $recs[0]['t'];
}
/**
* Retrieves template for custom marker
*
* @param string $section Section name in the template
* @param arrasy $conf tt_news configuration
* @param tx_ttnews $pObj Reference to parent object
* @return string Template section
* @access private
*/
private function getTemplate($section, $conf, &$pObj) {
// Search for file
if (isset($conf['commentsTemplateFile'])) {
$file = $conf['commentsTemplateFile'];
}
elseif (isset($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_toctoccomments_pi1.']['templateFile'])) {
$file = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_toctoccomments_pi1.']['templateFile'];
}
else {
// Use default
$file = 'EXT:toctoc_comments/res/template/toctoccomments_template.html';
}
if (($template = $pObj->cObj->fileResource($file))) {
$template = $pObj->cObj->getSubpart($template, $section);
}
return $template;
}
/**
* Attempts to build URL to item.
* Firsts it checks if marker value is not empty. If yes, it treats it as a
* link to item and attempts to extract the link. If value is empty, it uses item
* uid to manually create link
*
* @param int $itemUid Item uid
* @param tx_ttnews $pObj Reference to parent object
* @return string Generated URL to item
* @access private
*/
private function getItemLink($itemUid, &$pObj) {
$result = '';
if (isset($GLOBALS['TSFE']->register['newsMoreLink']) &&
($pos = strpos($GLOBALS['TSFE']->register['newsMoreLink'], 'href="')) !== FALSE) {
$value = substr($GLOBALS['TSFE']->register['newsMoreLink'], $pos + 6);
$result = substr($value, 0, strpos($value, '"'));
}
if (!$result) {
$params = array(
'additionalParams' => '&tx_ttnews[tt_news]=' . $itemUid,
'no_cache' => $GLOBALS['TSFE']->no_cache,
'parameter' => $pObj->conf['singlePid'] ? $pObj->conf['singlePid'] : $GLOBALS['TSFE']->id,
'useCacheHash' => !$GLOBALS['TSFE']->no_cache,
'returnLast' => 'url',
);
$result = $pObj->cObj->typolink('|', $params);
}
return $result;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/toctoc_comments/class.user_toctoc_comments_ttnews.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/toctoc_comments/class.user_toctoc_comments_ttnews.php']);
}
?>