8 require_once(CH_DIRECTORY_PATH_INC .
'header.inc.php' );
21 'title' =>
'_ch_ads_Ads',
22 'table' =>
'ch_ads_main',
23 'ownFields' => array(
'ID',
'IDProfile',
'IDClassifiedsSubs',
'DateTime',
'LifeTime',
'Subject',
'EntryUri',
'Message',
'CustomFieldValue1',
'CustomFieldValue2',
'Media',
'Tags',
'Status',
'Rate',
'RateCount',
'CommentsCount'),
24 'searchFields' => array(
'Subject',
'Message',
'Tags',
'City'),
26 'subcategory' => array(
28 'table' =>
'ch_ads_category_subs',
29 'mainField' =>
'IDClassifiedsSubs',
31 'joinFields' => array(
'NameSub',
'SEntryUri',
'ID')
35 'table' =>
'ch_ads_category',
36 'mainTable' =>
'ch_ads_category_subs',
37 'mainField' =>
'IDClassified',
39 'joinFields' => array(
'Name',
'CEntryUri',
'ID',
'Unit1',
'Unit2',
'CustomFieldName1',
'CustomFieldName2')
43 'table' =>
'Profiles',
44 'mainTable' =>
'ch_ads_main',
45 'mainField' =>
'IDProfile',
47 'joinFields' => array()
50 'restriction' => array(
51 'activeStatus' => array(
'value'=>
'active',
'field'=>
'Status',
'operator'=>
'='),
52 'status' => array(
'value'=>
'',
'field'=>
'Status',
'operator'=>
'='),
53 'featuredStatus' => array(
'value'=>
'',
'field'=>
'Featured',
'operator'=>
'='),
54 'owner' => array(
'value'=>
'',
'field'=>
'IDProfile',
'operator'=>
'=',
'table' =>
'ch_ads_main'),
55 'tag' => array(
'value'=>
'',
'field'=>
'Tags',
'operator'=>
'like'),
56 'categoryID'=> array(
'value'=>
'',
'field'=>
'ID',
'operator'=>
'=',
'table' =>
'ch_ads_category'),
57 'subcategoryID'=> array(
'value'=>
'',
'field'=>
'ID',
'operator'=>
'=',
'table' =>
'ch_ads_category_subs'),
58 'id'=> array(
'value'=>
'',
'field'=>
'ID',
'operator'=>
'='),
59 'country'=> array(
'value'=>
'',
'field'=>
'Country',
'operator'=>
'=',
'table' =>
'ch_ads_main'),
60 'message_filter'=> array(
'value'=>
'',
'field'=>
'Subject',
'operator'=>
'like'),
61 'today'=> array(
'value'=>
'',
'field'=>
'ID',
'operator'=>
'=',
'table' =>
'ch_ads_category'),
62 'allow_view' => array(
'value'=>
'',
'field'=>
'AllowView',
'operator'=>
'in',
'table'=>
'ch_ads_main'),
64 'paginate' => array(
'perPage' => 4,
'page' => 1,
'totalNum' => 10,
'totalPages' => 1),
66 'custom_filter1' =>
'',
67 'custom_filter2' =>
'',
79 $this->sHomePath = $oMain->_oConfig->getHomePath();
80 $this->sHomeUrl = $oMain->_oConfig->getHomeUrl();
82 $this->aPermalinks = array(
83 'param' =>
'permalinks_module_ads',
85 'file' =>
'ads/entry/{uri}',
86 'category' =>
'ads/cat/{uri}',
87 'subcategory' =>
'ads/subcat/{uri}',
88 'tag' =>
'ads/tag/{uri}',
89 'browseAll' =>
'ads/',
90 'admin_file' =>
'ads/entry/{uri}',
91 'admin_category' =>
'ads/cat/{uri}',
92 'admin_subcategory' =>
'ads/subcat/{uri}',
93 'admin_tag' =>
'ads/tag/{uri}',
94 'admin_browseAll' =>
'ads/'
97 'file' =>
'classifieds.php?ShowAdvertisementID={id}',
98 'category' =>
'classifieds.php?bClassifiedID={id}',
99 'subcategory' =>
'classifieds.php?bSubClassifiedID={id}',
100 'tag' =>
'classifieds_tags.php?tag={uri}',
101 'browseAll' =>
'classifieds.php',
102 'admin_file' =>
'classifieds.php?ShowAdvertisementID={id}',
103 'admin_category' =>
'classifieds.php?bClassifiedID={id}',
104 'admin_subcategory' =>
'classifieds.php?bSubClassifiedID={id}',
105 'admin_tag' =>
'classifieds_tags.php?tag={uri}',
106 'admin_browseAll' =>
'classifieds.php'
110 $this->bShowCheckboxes =
false;
112 parent::__construct();
114 $this->sSelectedUnit =
'unit_ads';
128 $bUseFriendlyLinks =
getParam(
'permalinks_module_ads') ==
'on' ?
true :
false;
129 $sPath = ($bUseFriendlyLinks) ? CH_WSB_URL_ROOT : $this->sHomeUrl;
131 $sLink = $this->aConstants[
'linksTempl'][
$sType];
133 $sLink = str_replace(
'{id}',
$iId, $sLink);
134 $sLink = str_replace(
'{uri}', $sUri, $sLink);
135 if (is_array($aOwner) && !
empty($aOwner)) {
136 $sLink = str_replace(
'{ownerName}', $aOwner[
'ownerName'], $sLink);
137 $sLink = str_replace(
'{ownerId}', $aOwner[
'ownerId'], $sLink);
140 return $sPath . $sLink;
145 $sWhereSQL = parent::getRestriction();
149 if (isset($this->aCurrent[
'third_restr']) && $this->aCurrent[
'third_restr'] !=
'') {
150 $sWhereSQL .=
" AND {$this->aCurrent['third_restr']} ";
153 if (isset($this->aCurrent[
'custom_filter1']) && $this->aCurrent[
'custom_filter1'] !=
'') {
154 $sWhereSQL .=
" AND {$this->aCurrent['custom_filter1']} ";
157 if (isset($this->aCurrent[
'custom_filter2']) && $this->aCurrent[
'custom_filter2'] !=
'') {
158 $sWhereSQL .=
" AND {$this->aCurrent['custom_filter2']} ";
163 $sTimeCheck =
" AND UNIX_TIMESTAMP() - `{$oMain->_oConfig->sSQLPostsTable}`.`LifeTime`*24*60*60 __sign__ `{$oMain->_oConfig->sSQLPostsTable}`.`DateTime`";
164 switch($this->aCurrent[
'second_restr']) {
178 $sWhereSQL .= str_replace(
'__sign__', $sSign, $sTimeCheck);
186 if (is_array($aData) && count($aData) > 0) {
188 foreach ($aData
as $iKey => $aValue) {
195 $sCode =
$GLOBALS[
'oSysTemplate']->parseHtmlByName(
'default_padding.html', array(
'content' =>
$sCode));
206 $sFromC =
_t(
'_Added by');
210 $iAdID = (int)$aResSQL[
'id'];
212 $bPossibleToView = $oMain->oPrivacy->check(
'view', $iAdID, $oMain->_iVisitorID);
213 if (! $bPossibleToView)
return $oMain->_oTemplate->parseHtmlByName(
'browse_unit_private.html', array(
'extra_css_class' =>
''));
215 $iOwnerID = (int)$aResSQL[
'ownerId'];
216 $sOwnerName = getNickname($iOwnerID);
221 $sVotePostRating =
'';
222 if (!is_null($this->oRate) && $this->oRate->isEnabled())
223 $sVotePostRating = $this->oRate->getJustVotingElement(0, 0, $aResSQL[
'Rate']);
225 $iCatID = (int)$aResSQL[
'categoryId'];
226 $iSubCatID = (int)$aResSQL[
'subcategoryId'];
231 $sAdUrl = $this->
genUrlX($iAdID, $sEntryUri);
239 $sCustomStyle1 = $sCustomStyle2 =
'';
240 $sCustomStyle1 = ($sCustomVal1!=
'') ?
'' :
'display:none;';
241 $sCustomStyle2 = ($sCustomVal2!=
'') ?
'' :
'display:none;';
248 $sCEntryUri = htmlspecialchars($aResSQL[
'categoryUri']);
249 $sSEntryUri = htmlspecialchars($aResSQL[
'subcategoryUri']);
251 $sCategUrl = ($oMain->_oConfig->bUseFriendlyLinks) ? CH_WSB_URL_ROOT .
'ads/cat/'.$sCEntryUri :
"{$oMain->_oConfig->sCurrBrowsedFile}?bClassifiedID={$iCatID}";
252 $sSubCategUrl = ($oMain->_oConfig->bUseFriendlyLinks) ? CH_WSB_URL_ROOT .
'ads/subcat/'.$sSEntryUri :
"{$oMain->_oConfig->sCurrBrowsedFile}?bSubClassifiedID={$iSubCatID}";
254 $sAdCover = $oMain->getAdCover($aResSQL[
'media']);
255 $sAdBigCover = $oMain->getAdCover($aResSQL[
'media'],
'big_thumb');
258 if ($this->bShowCheckboxes) {
259 $sAdminCheck = <<<EOF
260 <div
class=
"browseCheckbox">
261 <input
id=
"ad{$iAdID}" type=
"checkbox" name=
"ads[]" value=
"{$iAdID}" />
265 $sPostStatus =
'<div class="ads_From">' .
_t(
'_Status') .
': ' .
process_line_output($aResSQL[
'Status']) .
'</div>';
268 $aUnitReplace = array(
269 'ad_cover_img' => $sAdCover,
270 'ad_link' => $sAdUrl,
271 'rating' => $sVotePostRating,
272 'ad_title' => $sAdTitle,
273 'ad_status' => $sPostStatus,
274 'ad_date' => mb_strtolower($sTimeAgo),
275 'from_label' => mb_strtolower($sFromC),
276 'ad_owner_link' => $sOwnerLink,
277 'ad_owner_name' => $sOwnerName,
278 'cats' => $oMain->_oTemplate->parseHtmlByTemplateName(
'category', array(
279 'cat_link' => $sCategUrl,
280 'sub_cat_link' => $sSubCategUrl,
281 'cat_name' => $sCategName,
282 'sub_cat_name' => $sSubCategName,
284 'admin_check' => $sAdminCheck,
285 'ad_big_cover_img' => $sAdBigCover,
286 'ch_if:using_c1' => array(
287 'condition' => ($sCustomName1 && $sCustomVal1),
289 'cust_style1' => $sCustomStyle1,
'custom_name1' => $sCustomName1,
'custom1' => $sCustomVal1,
'unit' => $sUnit1,
292 'ch_if:using_c2' => array(
293 'condition' => ($sCustomName2 && $sCustomVal2),
295 'cust_style2' => $sCustomStyle2,
'custom_name2' => $sCustomName2,
'custom2' => $sCustomVal2,
'unit2' => $sUnit2,
298 'ch_if:expired' => array(
299 'condition' => (
time() - $aResSQL[
'date']) > 24*60*60*$aResSQL[
'LifeTime'],
300 'content' => array(1 => 1)
303 return $oMain->_oTemplate->parseHtmlByTemplateName($this->sSelectedUnit, $aUnitReplace);
312 $sEntryUri =
db_value(
"SELECT `EntryUri` FROM `{$oMain->_oConfig->sSQLPostsTable}` WHERE `ID`='{$iEntryId}' LIMIT 1");
314 $sMainUrl = CH_WSB_URL_ROOT;
316 if ($oMain->_oConfig->bUseFriendlyLinks) {
317 $sUrl = $sMainUrl.
"ads/{$sType}/{$sEntryUri}";
322 $sUrl =
"{$oMain->_oConfig->sCurrBrowsedFile}?ShowAdvertisementID={$iEntryId}";
332 $aDBBottomMenu = array();
334 return array( $aDBTopMenu, $aDBBottomMenu );
339 $aDBTopMenu = array();
340 foreach( array(
'last')
as $sMyMode ) {
343 $OrderBy =
'`DateTime` DESC';
344 $sModeTitle =
_t(
'_Latest' );
349 $sLink .=
"ads_mode=".$sMyMode;
350 $aDBTopMenu[$sModeTitle] = array(
'href' => $sLink,
'dynamic' =>
true,
'active' => ( $sMyMode == $this->aCurrent[
'sorting'] ));
358 $aDBBottomMenu = array();
359 if ($this->aCurrent[
'paginate'][
'totalPages'] > 1) {
360 $sViewAllClass =
'viewAllMembers';
363 if ($this->aCurrent[
'paginate'][
'page'] > 1) {
364 $iPrevPage = $this->aCurrent[
'paginate'][
'page'] - 1;
365 $aDBBottomMenu[
_t(
'_Back') ] = array(
'href' =>
ch_html_attribute($_SERVER[
'PHP_SELF']) .
"?ads_mode={$this->aCurrent['sorting']}&page=$iPrevPage{$sUserAddon}{$sFileAddon}",
'dynamic' =>
true,
'class' =>
'backMembers',
'icon_class' =>
'left' );
367 $sViewAllClass =
'backMembers';
369 if( $this->aCurrent[
'paginate'][
'page'] < $this->aCurrent[
'paginate'][
'totalPages'] ) {
370 $iNextPage = $this->aCurrent[
'paginate'][
'page'] + 1;
371 $aDBBottomMenu[
_t(
'_Next') ] = array(
'href' =>
ch_html_attribute($_SERVER[
'PHP_SELF']) .
"?ads_mode={$this->aCurrent['sorting']}&page=$iNextPage{$sUserAddon}{$sFileAddon}",
'dynamic' =>
true,
'class' =>
'moreMembers' );
373 $sViewAllClass =
'moreMembers';
375 if (isset($this->aConstants[
'linksTempl'][$sAllLinkType]))
380 $aDBBottomMenu[
_t(
'_View All').
' ('. $this->aCurrent[
'paginate'][
'totalNum'] .
')' ] = array(
'href' =>
"$sAllUrl",
'class' => $sViewAllClass );
382 return $aDBBottomMenu;
387 $this->aCurrent[
'sorting'] = (
false !==
ch_get(
'ads_mode')) ?
ch_get(
'ads_mode') : $this->aCurrent[
'sorting'];
389 if( $this->aCurrent[
'sorting'] !=
'top' && $this->aCurrent[
'sorting'] !=
'last' && $this->aCurrent[
'sorting'] !=
'score' && $this->aCurrent[
'sorting'] !=
'popular')
390 $this->aCurrent[
'sorting'] =
'last';
395 if ($this->aCurrent[
'sorting'] ==
'popular') {
398 $aSql[
'order'] =
" ORDER BY `{$oMain->_oConfig->sSQLPostsTable}`.`Views` DESC, `DateTime` DESC";
407 'page_url' => $this->aCurrent[
'paginate'][
'page_url'],
408 'count' => $this->aCurrent[
'paginate'][
'totalNum'],
409 'per_page' => $this->aCurrent[
'paginate'][
'perPage'],
410 'page' => $this->aCurrent[
'paginate'][
'page'],
413 if (mb_strlen($aPgnParams[
'page_url']) == 0) {
417 foreach($aLinkAddon
as $sValue)
418 $sPageLink .= $sValue;
422 $sLoadDynamicUrl = $this->
id .
', \'' . CH_WSB_URL_ROOT .
'searchKeywordContent.php?searchMode=ajax§ion[]=ch_ads' . $aLinkAddon[
'params'];
423 $sKeyword =
ch_get(
'keyword');
424 if ($sKeyword !==
false && mb_strlen($sKeyword) > 0)
425 $sLoadDynamicUrl .=
'&keyword=' . rawurlencode(strip_tags($sKeyword));
427 $aPgnParams[
'page_url'] = $sPageLink;
428 $aPgnParams[
'on_change_page'] =
'return !loadDynamicBlock(' . $sLoadDynamicUrl . $aLinkAddon[
'paginate'].
'\');
';
429 $aPgnParams['on_change_per_page
'] = 'return !loadDynamicBlock(
' . $sLoadDynamicUrl .'&page=1&per_page=\
' + this.value);';
433 $sPaginate =
'<div class="clear_both"></div>'.$oPaginate->getPaginate();
444 'page_url' => $this->aCurrent[
'paginate'][
'page_url'],
445 'count' => $this->aCurrent[
'paginate'][
'totalNum'],
446 'per_page' => $this->aCurrent[
'paginate'][
'perPage'],
447 'page' => $this->aCurrent[
'paginate'][
'page'],
448 'on_change_page' =>
'return !loadDynamicBlock({id}, \''.
ch_html_attribute($_SERVER[
'PHP_SELF']).
'?ads_mode='.$this->aCurrent[
'sorting'].$aLinkAddon[
'params'].
'&page={page}&per_page={per_page}\');',
451 $sPaginate =
'<div class="clear_both"></div>'.$oPaginate->getSimplePaginate($sAllUrl);
460 'title' =>
'Subject',
461 'date' =>
'DateTime',
463 'ownerId' =>
'IDProfile',
464 'bodyText' =>
'Message',
467 'subcategoryId' =>
'ID',
468 'subcategoryName' =>
'NameSub',
469 'subcategoryUri' =>
'SEntryUri',
470 'categoryId' =>
'ID',
471 'categoryName' =>
'Name',
472 'categoryUri' =>
'CEntryUri'