8 require_once(CH_DIRECTORY_PATH_INC .
'header.inc.php' );
12 if (!defined(
'CH_BLOGS_IMAGES_PATH')) {
13 define(
'CH_BLOGS_IMAGES_PATH', CH_DIRECTORY_PATH_ROOT .
"media/images/blog/");
15 if (!defined(
'CH_BLOGS_IMAGES_URL')) {
16 define(
'CH_BLOGS_IMAGES_URL', CH_WSB_URL_ROOT .
"media/images/blog/");
30 'name' =>
'blogposts',
31 'title' =>
'_ch_blog_Blogs',
32 'table' =>
'ch_blogs_posts',
33 'ownFields' => array(
'PostID',
'PostCaption',
'PostUri',
'PostDate',
'PostText',
'Tags',
'PostPhoto',
'PostStatus',
'Rate',
'RateCount',
'CommentsCount',
'Categories',
'Views'),
34 'searchFields' => array(
'PostCaption',
'PostText',
'Tags'),
38 'table' =>
'Profiles',
39 'mainField' =>
'OwnerID',
41 'joinFields' => array(
'NickName')
44 'restriction' => array(
45 'activeStatus' => array(
'value'=>
'approval',
'field'=>
'PostStatus',
'operator'=>
'='),
46 'featuredStatus' => array(
'value'=>
'',
'field'=>
'Featured',
'operator'=>
'='),
47 'owner' => array(
'value'=>
'',
'field'=>
'OwnerID',
'operator'=>
'='),
48 'tag' => array(
'value'=>
'',
'field'=>
'Tags',
'operator'=>
'like'),
49 'tag2' => array(
'value'=>
'',
'field'=>
'Tags',
'operator'=>
'against',
'paramName'=>
'tag'),
50 'id'=> array(
'value'=>
'',
'field'=>
'PostID',
'operator'=>
'='),
51 'category_uri'=> array(
'value'=>
'',
'field'=>
'Categories',
'operator'=>
'against',
'paramName'=>
'uri'),
52 'allow_view' => array(
'value'=>
'',
'field'=>
'allowView',
'operator'=>
'in',
'table'=>
'ch_blogs_posts'),
54 'paginate' => array(
'perPage' => 4,
'page' => 1,
'totalNum' => 10,
'totalPages' => 1),
70 $this->bShowCheckboxes =
false;
71 $this->bAdminMode =
false;
75 $this->iIconSize = $oMain->iIconSize;
76 $this->iThumbSize = $oMain->iThumbSize;
77 $this->iBigThumbSize = $oMain->iBigThumbSize;
78 $this->iImgSize = $oMain->iImgSize;
80 if ($oMain->isAdmin()) {
81 $this->bAdminMode =
true;
85 $this->sHomeUrl = $oMain->_oConfig->getHomeUrl();
86 $this->sHomePath = $oMain->_oConfig->getHomePath();
88 $this->aPermalinks = array(
89 'param' =>
'permalinks_blogs',
91 'file' =>
'blogs/entry/{uri}',
92 'category' =>
'blogs/posts/{ownerName}/category/{uri}',
93 'member' =>
'blogs/posts/{ownerName}',
94 'tag' =>
'blogs/tag/{uri}',
95 'browseAll' =>
'blogs/',
96 'admin_file' =>
'blogs/entry/{uri}',
97 'admin_category' =>
'blogs/posts/{ownerName}/category/{uri}',
98 'admin_member' =>
'blogs/posts/{ownerName}',
99 'admin_tag' =>
'blogs/tag/{uri}',
100 'admin_browseAll' =>
'blogs/',
101 'last_posts' =>
'blogs/all_posts/',
102 'popular_posts' =>
'blogs/popular_posts/',
103 'top_posts' =>
'blogs/top_posts/',
106 'file' =>
'blogs.php?action=show_member_post&post_id={id}',
107 'category' =>
'blogs.php?action=show_member_blog&ownerID={ownerId}&category={id}',
108 'member' =>
'blogs.php?action=show_member_blog&ownerID={ownerId}',
109 'tag' =>
'blogs.php?action=search_by_tag&tagKey={uri}',
110 'browseAll' =>
'blogs.php',
111 'admin_file' =>
'blogs.php?action=show_member_post&post_id={id}',
112 'admin_category' =>
'blogs.php?action=show_member_blog&ownerID={ownerId}&category={id}',
113 'admin_member' =>
'blogs.php?action=show_member_blog&ownerID={ownerId}',
114 'admin_tag' =>
'blogs.php?action=search_by_tag&tagKey={uri}',
115 'admin_browseAll' =>
'blogs.php',
116 'last_posts' =>
'blogs.php?action=all_posts',
117 'popular_posts' =>
'blogs.php?action=popular_posts',
118 'top_posts' =>
'blogs.php?action=top_posts'
126 if ( $this->bAdminMode || ( is_object($oBlogObject) && ($oBlogObject -> isAllowedApprove()
127 || $oBlogObject -> isAllowedPostEdit(-1) || $oBlogObject -> isAllowedPostDelete(-1)) )) {
129 $this->aCurrent[
'restriction'][
'activeStatus'] =
'';
131 parent::__construct();
133 $this->iPostViewType = 4;
134 $this->sSearchedTag =
'';
145 return $oMain->serviceGetCommonCss();
150 $GLOBALS[
'oChBlogsModule'] = $oBlogsModule;
153 $this->sHomePath = $oMain->_oConfig->getHomePath();
154 $this->sHomeUrl = $oMain->_oConfig->getHomeUrl();
163 if ($this->bAdminMode && isset($this->aConstants[
'linksTempl'][
'admin_' .
$sType])) {
167 $sLink = $this->aConstants[
'linksTempl'][
$sType];
168 $sLink = str_replace(
'{id}',
$iId, $sLink);
169 $sLink = str_replace(
'{uri}', $sUri, $sLink);
170 if (is_array($aOwner) && !
empty($aOwner)) {
171 $sLink = str_replace(
'{ownerName}', $aOwner[
'ownerName'], $sLink);
172 $sLink = str_replace(
'{ownerId}', $aOwner[
'ownerId'], $sLink);
176 return ($oMain->isPermalinkEnabled()) ? CH_WSB_URL_ROOT . $sLink : $this->sHomeUrl . $sLink;
181 $sCode =
DesignBoxContent(
_t($this->aCurrent[
'title']),
'<div class="ch-def-bc-padding">'.
$sCode .
'<div class="clear_both"></div></div>'. $sPaginate, 1);
182 if (
true !==
ch_get(
'searchMode'))
183 $sCode =
'<div id="page_block_'.$this->id.
'">'.
$sCode.
'<div class="clear_both"></div></div>';
193 $iPostID = (int)$aResSQL[
'id'];
194 $sBlogsImagesUrl = CH_BLOGS_IMAGES_URL;
196 $bPossibleToView = $oMain->oPrivacy->check(
'view', $iPostID, $oMain->_iVisitorID);
197 if (!$bPossibleToView) {
198 if ($this->sMobileWrapper)
199 return $this->
_wrapMobileUnit ($oMain->_oTemplate->parseHtmlByTemplateName(
'browse_unit_private_mobile', array()), $iPostID, $oMain);
201 return $oMain->_oTemplate->parseHtmlByName(
'browse_unit_private.html', array(
'extra_css_class' =>
''));
204 $sCategories = $aResSQL[
'Categories'];
205 $aCategories = $oMain->getTagLinks($aResSQL[
'Categories'],
'category',
CATEGORIES_DIVIDER);
211 $sVotePostRating = $this->oRate->getJustVotingElement(0, 0, $aResSQL[
'Rate']);
218 $sCategoryName = $aResSQL[
'Categories'];
219 $sPostLink = $this->
getCurrentUrl(
'file', $iPostID, $aResSQL[
'uri']) . $sCategoryUrlAdd;
221 $sAllCategoriesLinks =
'';
222 if (count($aCategories)>0) {
223 foreach ($aCategories
as $iKey => $sCatValue) {
224 $sCatLink = $this->
getCurrentUrl(
'category',
title2uri($sCatValue),
title2uri($sCatValue), array(
'ownerId' => $aResSQL[
'ownerId'],
'ownerName' => $sAuthorUsername));
226 $aAllCategoriesLinks[] =
'<a href="' . $sCatLink .
'">' . $sCatName .
'</a>';
228 $aAllCategoriesLinkHrefs = implode(
", ", $aAllCategoriesLinks);
229 $sAllCategoriesLinks = <<<EOF
230 <span
class=
"margined">
231 <span>{$aAllCategoriesLinkHrefs}</span>
236 $sAdminCheck = $sAdminStatus =
'';
237 if ($this->bShowCheckboxes) {
238 $sAdminCheck = <<<EOF
239 <div
class=
"browseCheckbox"><input
id=
"ch{$iPostID}" type=
"checkbox" name=
"bposts[]" value=
"{$iPostID}" /></div>
243 $sAdminStatus = <<<EOF
244 ({$sPostStatus})
249 $sPostCaptionHref = <<<EOF
250 <
a class=
"unit_title ch-def-font-h2" href=
"{$sPostLink}">{$sPostCaption}</
a>{$sAdminStatus}
253 if ($this->iPostViewType==3 || $this->sMobileWrapper) {
255 $sPostMode =
'_post';
256 $sPostCaptionHref =
'<div class="unit_title ch-def-font-h2">'.$sPostCaption.
'</div>';
262 $iCommentsCnt = (int)$aResSQL[
'CommentsCount'];
263 $iViewsCnt = (int)$aResSQL[
'Views'];
265 $sTagsCommas = $aResSQL[
'tag'];
267 $aTags = preg_split(
"/[;,]/", $sTagsCommas);
270 if ( $this->sSearchedTag !=
'' && in_array($this->sSearchedTag,$aTags)==
false )
return;
273 $aTagsHrefs = array();
274 foreach($aTags
as $sTagKey) {
275 if ($sTagKey !=
'') {
277 $sTagsHrefAny = <<<EOF
278 <
a href=
"{$sTagLink}" title=
"{$sTagKey}">{$sTagKey}</
a>
280 $aTagsHrefs[] = $sTagsHrefAny;
283 $sTagsHrefs = implode(
", ", $aTagsHrefs);
286 <span
class=
"margined">
287 <span>{$sTagsHrefs}</span>
291 $sPostText = $aResSQL[
'bodyText'];
292 $bOwner = ($iVisitorID==$aResSQL[
'ownerId']) ?
true :
false;
294 $sOwnerThumb = $sPostPicture = $sPreviewPicture =
'';
295 if($aResSQL[
'PostPhoto'] && in_array($this->iPostViewType, array(1, 3, 4, 5))) {
296 $oMain->_oTemplate->addJs(
'plugins/fancybox/|jquery.fancybox.js');
297 $oMain->_oTemplate->addCss(
'plugins/fancybox/|jquery.fancybox.css');
299 $sPostPicture = $oMain->_oTemplate->parseHtmlByName(
'picture_preview.html', array(
300 'img_url_big' => $sBlogsImagesUrl .
'orig_' . $aResSQL[
'PostPhoto'],
301 'img_url_small' => $sBlogsImagesUrl .
'big_' . $aResSQL[
'PostPhoto']
305 if ($this->iPostViewType==4) {
306 $sOwnerThumb =
$GLOBALS[
'oFunctions']->getMemberIcon($aResSQL[
'ownerId'],
'left');
309 if (in_array($this->iPostViewType, array(1, 4, 5))) {
310 $iBlogLimitChars = (int)
getParam(
'max_blog_preview');
311 $sPostText = trim(strip_tags($sPostText));
312 if (mb_strlen($sPostText) > $iBlogLimitChars) {
313 $sPostText = mb_substr( $sPostText, 0, $iBlogLimitChars);
314 $sLinkMore = $this->sMobileWrapper ?
'' :
' <a title="' .
htmlspecialchars_adv(
_t(
'_Read more')) .
'" href="' . $sPostLink .
'">…</a>';
319 $aUnitReplace = array(
320 'checkbox' => $sAdminCheck,
321 'post_caption' => $sPostCaptionHref,
322 'author_title' => $sAuthorTitle,
323 'author_username' => $sAuthorUsername,
324 'author_link' => $sAuthorLink,
325 'post_date' => $sDateTime,
326 'all_categories' => $sAllCategoriesLinks,
327 'comments_count' => $iCommentsCnt,
328 'views_count' => $iViewsCnt,
330 'friend_style' => $sFriendStyle,
331 'post_uthumb' => $sOwnerThumb,
332 'post_picture2' => $sPostPicture,
333 'preview_picture' => $sPreviewPicture,
334 'post_description' => $sPostText,
335 'post_vote' => $sVotePostRating,
336 'post_mode' => $sPostMode,
338 'ch_if:full' => array (
339 'condition' => $this->iPostViewType != 5,
341 'author_title' => $sAuthorTitle,
342 'author_username' => $sAuthorUsername,
343 'author_link' => $sAuthorLink,
344 'post_date' => $sDateTime,
345 'comments_count' => $iCommentsCnt,
346 'views_count' => $iViewsCnt,
351 if ($this->sMobileWrapper) {
352 return $this->
_wrapMobileUnit ($oMain->_oTemplate->parseHtmlByTemplateName(
'blogpost_unit_mobile', $aUnitReplace), $iPostID, $oMain);
354 return $oMain->_oTemplate->parseHtmlByTemplateName(
'blogpost_unit', $aUnitReplace);
360 $this->aCurrent[
'sorting'] = (
false !==
ch_get(
'blogs_mode')) ?
ch_get(
'blogs_mode') : $this->aCurrent[
'sorting'];
362 if( $this->aCurrent[
'sorting'] !=
'top' && $this->aCurrent[
'sorting'] !=
'last' && $this->aCurrent[
'sorting'] !=
'score' && $this->aCurrent[
'sorting'] !=
'popular')
363 $this->aCurrent[
'sorting'] =
'last';
368 if ($this->aCurrent[
'sorting'] ==
'popular') {
370 $aSql[
'order'] =
" ORDER BY `CommentsCount` DESC, `PostDate` DESC";
380 'page_url' => $this->aCurrent[
'paginate'][
'page_url'],
381 'count' => $this->aCurrent[
'paginate'][
'totalNum'],
382 'per_page' => $this->aCurrent[
'paginate'][
'perPage'],
383 'page' => $this->aCurrent[
'paginate'][
'page'],
384 'on_change_page' =>
'return !loadDynamicBlock('.$this->
id.
', \'searchKeywordContent.php?searchMode=ajax&blogs_mode='.$this->aCurrent[
'sorting'].
'§ion[]=blog&keyword='.
ch_get(
'keyword').$aLinkAddon[
'params'].
'&page={page}&per_page={per_page}\');',
385 'on_change_per_page' =>
'return !loadDynamicBlock('.$this->
id.
', \'searchKeywordContent.php?searchMode=ajax&blogs_mode='.$this->aCurrent[
'sorting'].
'§ion[]=blog&keyword='.
ch_get(
'keyword').$aLinkAddon[
'params'].
'&page=1&per_page=\' + this.value);'
387 $sPaginate =
'<div class="clear_both"></div>'.$oPaginate->getPaginate();
395 $sPgnAdd =
false === strpos($this->aCurrent[
'paginate'][
'page_url'],
'{page}') ?
'per_page={per_page}&page={page}' :
'';
398 'count' => $this->aCurrent[
'paginate'][
'totalNum'],
399 'per_page' => $this->aCurrent[
'paginate'][
'perPage'],
400 'page' => $this->aCurrent[
'paginate'][
'page'],
403 $sPaginate =
'<div class="clear_both"></div>'.$oPaginate->getPaginate();
408 function showPagination2($bAdmin =
false, $sOverrideViewAllUrl =
false, $bShort =
true)
413 $sAllUrl = $sOverrideViewAllUrl ? $sOverrideViewAllUrl : $this->
getCurrentUrl(
'browseAll', 0,
'');
414 $sLink =
ch_html_attribute($_SERVER[
'PHP_SELF']) .
'?blogs_mode=' . $this->aCurrent[
'sorting'] . $aLinkAddon[
'params'];
416 'page_url' => $sLink,
417 'count' => $this->aCurrent[
'paginate'][
'totalNum'],
418 'per_page' => $this->aCurrent[
'paginate'][
'perPage'],
419 'page' => $this->aCurrent[
'paginate'][
'page'],
420 'on_change_page' =>
'return !loadDynamicBlock({id}, \'' . $sLink .
'&page={page}&per_page={per_page}\');',
421 'on_change_per_page' =>
'return !loadDynamicBlock({id}, \'' . $sLink .
'&page=1&per_page=\' + this.value);',
424 $sPaginate = $bShort ? $oPaginate->getSimplePaginate($sAllUrl) : $oPaginate->getPaginate();
425 $sPaginate =
'<div class="clear_both"></div>' . $sPaginate;
434 $sLink = CH_WSB_URL_ROOT . ($sBaseUrl ? $sBaseUrl : $this->aCurrent[
'paginate'][
'page_url']);
438 'page_url' => $sLink,
439 'count' => $this->aCurrent[
'paginate'][
'totalNum'],
440 'per_page' => $this->aCurrent[
'paginate'][
'perPage'],
441 'page' => $this->aCurrent[
'paginate'][
'page'],
442 'on_change_page' =>
'getHtmlData(\'' .
ch_html_attribute($sContainerId) .
'\', \
'' .
ch_html_attribute($sLink) .
'&page={page}&per_page={per_page}\'); return false;',
443 'on_change_per_page' =>
'getHtmlData(\'' .
ch_html_attribute($sContainerId) .
'\', \
'' .
ch_html_attribute($sLink) .
'&page=1&per_page=\' + this.value); return false;',
446 $sPaginate =
'<div class="clear_both"></div>' . $oPaginate->getPaginate();
455 'title' =>
'PostCaption',
456 'date' =>
'PostDate',
458 'categoryName' =>
'CategoryName',
459 'categoryUri' =>
'CategoryUri',
460 'ownerId' =>
'OwnerID',
461 'ownerName' =>
'NickName',
462 'bodyText' =>
'PostText',
463 'countComment' =>
'cmt_id',
472 'url' =>
ch_js_string($oMain->genBlogSubUrl() .
'?action=mobile&mode=post&id=' . $iPostID),
476 return $oMobileTemplate->parseHtmlByName($this->sMobileWrapper,
$aVars);