public function indexAction() { global $structure; if (!cot_module_active('rss')) { cot_die_message(404, TRUE); } $c = cot_import('c', 'G', 'TXT'); if (!empty($c)) { if (!isset($structure['advboard'][$c])) { cot_die_message(404, TRUE); } list(cot::$usr['auth_read'], cot::$usr['auth_write'], cot::$usr['isadmin']) = cot_auth('advboard', $c); cot_block(cot::$usr['auth_read']); } $rss_title = cot::$L['advboard_rss_feed'] . cot::$cfg['maintitle']; $rss_link = cot::$cfg['mainurl']; $rss_description = cot::$cfg['subtitle']; $domain = cot::$sys['domain']; $condition = array(array('state', advboard_model_Advert::PUBLISHED), array('begin', cot::$sys['now'], '<='), array('SQL', "expire = 0 OR expire > " . cot::$sys['now'])); if (!empty($c)) { $rss_title = cot::$L['advboard_rss_feed'] . $structure['advboard'][$c]['title'] . ' - ' . cot::$cfg['maintitle']; $condition[] = array('category', $c); } $advertisement = advboard_model_Advert::find($condition, cot::$cfg['rss']['rss_maxitems'], 0, array(array('sort', 'desc'))); $t = new XTemplate(cot_tplfile('rss')); $now = cot::$sys['now']; $now += cot::$usr['timezone'] * 3600; $t->assign(array('RSS_ENCODING' => cot::$cfg['rss']['rss_charset'], 'RSS_TITLE' => htmlspecialchars($rss_title), 'RSS_LINK' => $rss_link, 'RSS_LANG' => cot::$cfg['defaultlang'], 'RSS_DESCRIPTION' => htmlspecialchars($rss_description), 'RSS_DATE' => $this->fixPubDate(date("r", $now)))); if (!empty($advertisement)) { foreach ($advertisement as $advert) { $url = $advert->url; if (!cot_url_check($url)) { $url = COT_ABSOLUTE_URL . $url; } $date = ''; if (!empty($advert->created)) { $date = strtotime($advert->created); $date += cot::$usr['timezone'] * 3600; $date = date('r', $date); $date = $this->fixPubDate($date); } $text = $advert->text; $textlength = intval(cot::$cfg['rss']['rss_pagemaxsymbols']); if ($textlength > 0 && mb_strlen($text) > $textlength) { $text = cot_string_truncate($text, $textlength, true, false, cot::$R['advboard_cuttext']); } $t->assign(array('RSS_ROW_TITLE' => htmlspecialchars($advert->title), 'RSS_ROW_DESCRIPTION' => $this->convertRelativeUrls($text), 'RSS_ROW_DATE' => $date, 'RSS_ROW_LINK' => $url)); $t->parse('MAIN.ITEM_ROW'); } } $t->parse('MAIN'); // ob_clean(); header('Content-type: text/xml; charset=UTF-8'); echo $t->text('MAIN'); exit; }
/** * Рассылка уведомлений об истечении сроков публикации объявления */ public static function sendExpireNotify() { global $L; $cacheFileName = cot::$cfg["modules_dir"] . '/advboard/inc/send.txt'; if (file_exists($cacheFileName)) { $adv_send = file_get_contents($cacheFileName); } else { $adv_send = 0; } $tmp = getdate(cot::$sys['now']); $today = mktime(0, 0, 0, $tmp["mon"], $tmp["mday"], $tmp["year"]); // Рассылаем раз в сутки if ($today - $adv_send >= 86400) { // Период за который рассылаем if ($adv_send == 0) { // не разу не рассылали еще $adv_sendPer = cot::$cfg['advboard']['expNotifyPeriod']; } else { $adv_sendPer = floor(($today - $adv_send) / 86400); } // Уведомляем об истечении // Пока тупо шлем напоминание всем объявлениям у которых дата истечения // Больше той, когда заходили последний раз, но меньше текущей минус <уведомить за> $stDay = $tmp["mday"] + cot::$cfg['advboard']['expNotifyPeriod'] - $adv_sendPer; $periodStart = mktime(0, 0, 0, $tmp["mon"], $stDay, $tmp["year"]); if ($periodStart < cot::$sys['now']) { $periodStart = cot::$sys['now']; } $periodEnd = mktime(0, 0, 0, $tmp["mon"], $tmp["mday"] + cot::$cfg['advboard']['expNotifyPeriod'], $tmp["year"]); $condition = array(array('expire', $periodStart, '>='), array('expire', $periodEnd, '<'), array('state', advboard_model_Advert::PUBLISHED), array('user', 0, '>')); $advertisement = advboard_model_Advert::find($condition, 0, 0, array(array('id', 'ASC'))); $cnt = 0; if ($advertisement) { foreach ($advertisement as $advRow) { if (!$advRow->issetEmail(true)) { return false; } $advertUrl = $advRow->getUrl(); if (!cot_url_check($advertUrl)) { $advertUrl = COT_ABSOLUTE_URL . $advertUrl; } $advertEditUrl = $advRow->getEditUrl(); if (!cot_url_check($advertEditUrl)) { $advertEditUrl = COT_ABSOLUTE_URL . $advertEditUrl; } $myAdvsUrl = cot_url('advboard', 'm=user'); if (!cot_url_check($myAdvsUrl)) { $myAdvsUrl = COT_ABSOLUTE_URL . $myAdvsUrl; } $tmpL = $L; $text = $advRow->description; if (empty($text)) { $text = $advRow->text; } $user = null; $userLang = cot::$cfg['defaultlang']; $owner = $advRow->getOwner(); if ($owner['user_id'] > 0) { if (cot::$cfg['defaultlang'] != $owner['user_lang']) { $userLang = $owner['user_lang']; include cot_langfile('main', 'core', cot::$cfg['defaultlang'], $owner['user_lang']); include cot_langfile('advboard', 'module', cot::$cfg['defaultlang'], $owner['user_lang']); } } $mailView = new View(); $mailView->advert = $advRow; $mailView->user = $owner; $mailView->advertUrl = $advertUrl; $mailView->advertEditUrl = $advertEditUrl; $mailView->myAdvsUrl = $myAdvsUrl; $mailView->advertText = $text; $mailSubject = cot::$L['advboard_expire_title']; $mailBody = $mailView->render('advboard.notify_expire.' . $userLang . '.' . $advRow->category); if (cot_mail($advRow->getEmail(false, true), $mailSubject, $mailBody, '', false, null, true)) { $cnt++; } // Вернем язык на место $L = $tmpL; } } file_put_contents($cacheFileName, $today); return $cnt; } return 0; }
public function ajxAddAction() { $ret = array('error' => '', 'added' => array(), 'addedIds' => array(), 'removedIds' => array()); $ids = null; if (isset($_POST['ids'])) { if (is_array($_POST['ids'])) { $ids = cot_import('ids', 'P', 'ARR'); $ids = array_unique(array_map('intval', $ids)); } elseif (is_int($_POST['ids']) || ctype_digit($_POST['ids'])) { $tmp = cot_import('ids', 'P', 'INT'); if ($tmp) { $ids = array($tmp); } } } if (!$ids) { $ret['error'] = cot::$L['advboard_not_found']; echo json_encode($ret); exit; } $advertisement = advboard_model_Advert::find(array(array('id', $ids))); if (!$advertisement) { $ret['error'] = cot::$L['advboard_not_found']; echo json_encode($ret); exit; } foreach ($advertisement as $advRow) { if ($tmp = $this->addToCompare($advRow)) { $ret['added'][] = $tmp; } } $ret['count'] = count($_SESSION['advboard_compare'][cot::$sys['site_id']]); echo json_encode($ret); exit; }
/** * Список объявлений * @param $c * @return string * @throws Exception */ public function adList($c) { global $structure, $cot_extrafields, $db_structure, $Ls; if ($c == 'all') { cot_block(cot::$usr['isadmin']); } elseif (!in_array($c, array('unvalidated', 'saved-drafts'))) { if (!isset($structure['advboard'][$c])) { cot_die_message(404, TRUE); } else { list(cot::$usr['auth_read'], cot::$usr['auth_write'], cot::$usr['isadmin']) = cot_auth('advboard', $c); cot_block(cot::$usr['auth_read']); } } $sort = cot_import('s', 'G', 'ALP'); // order field name $way = cot_import('w', 'G', 'ALP', 4); // order way (asc, desc) $maxrowsperpage = cot::$cfg['advboard']['cat_' . $c]['maxrowsperpage'] ? cot::$cfg['advboard']['cat_' . $c]['maxrowsperpage'] : cot::$cfg['advboard']['cat___default']['maxrowsperpage']; if ($maxrowsperpage < 1) { $maxrowsperpage = 1; } list($pg, $d, $durl) = cot_import_pagenav('d', $maxrowsperpage); //page number for pages list list($pgc, $dc, $dcurl) = cot_import_pagenav('dc', cot::$cfg['advboard']['maxlistsperpage']); // page number for cats list // Фильтры для модератора $mf = array('period' => 0, 'state' => -2); if (cot::$usr['isadmin']) { $mf['period'] = isset($_GET['mf']['period']) ? cot_import($_GET['mf']['period'], 'D', 'ALP') : 0; $mf['state'] = isset($_GET['mf']['state']) ? cot_import($_GET['mf']['state'], 'D', 'INT') : -2; } /* === Hook === */ foreach (cot_getextplugins('advboard.list.first') as $pl) { include $pl; } /* ===== */ $category = array('config' => array()); if (isset($structure['advboard'][$c])) { $category = $structure['advboard'][$c]; $category['config'] = cot::$cfg['advboard']['cat_' . $c]; } $category['code'] = $c; $fields = advboard_model_Advert::getColumns(); if (empty($sort)) { $sort = cot::$cfg['advboard']['cat_' . $c]['order']; } elseif (!in_array($sort, $fields)) { $sort = 'sort'; } $way = empty($way) ? cot::$cfg['advboard']['cat_' . $c]['way'] : $way; $sort = empty($sort) ? cot::$cfg['advboard']['cat___default']['order'] : $sort; $way = empty($way) || !in_array($way, array('asc', 'desc')) ? cot::$cfg['advboard']['cat___default']['way'] : $way; $urlParams = array('c' => $c); if ($sort != cot::$cfg['advboard']['cat_' . $c]['order']) { $urlParams['s'] = $sort; } if ($way != cot::$cfg['advboard']['cat_' . $c]['way']) { $urlParams['w'] = $way; } $canonicalUrlParams = array('c' => $c); if ($durl > 1) { $canonicalUrlParams['d'] = $durl; } if ($dcurl > 1) { $canonicalUrlParams['dc'] = $dcurl; } $template = array('advboard', 'list'); $where = array(); if ($c == 'unvalidated') { $template = array('advboard', 'list', 'unvalidated'); $where['state'] = array('state', advboard_model_Advert::AWAITING_MODERATION); if (!cot::$usr['isadmin']) { $where['user'] = array('user', cot::$usr['id']); } $category['title'] = cot::$L['page_validation']; $category['desc'] = cot::$L['page_validation_desc']; $sort = 'created'; $way = 'desc'; } elseif ($c == 'saved-drafts') { $template = array('advboard', 'list', 'unvalidated'); $where['state'] = array('state', advboard_model_Advert::DRAFT); if (!cot::$usr['isadmin']) { $where['user'] = array('user', cot::$usr['id']); } $category['title'] = cot::$L['page_drafts']; $category['desc'] = cot::$L['page_drafts_desc']; $sort = 'created'; $way = 'desc'; } elseif ($c == 'all') { $category['title'] = cot::$L['advboard_ads_board']; } else { $where['category'] = array('category', $c); $where['state'] = array('state', advboard_model_Advert::PUBLISHED); $where['begin'] = array('begin', cot::$sys['now'], '<='); $where['expire'] = array('SQL', "expire = 0 OR expire > " . cot::$sys['now']); $template = array('advboard', 'list', $structure['advboard'][$c]['tpl']); } $moderatorFilters = array(); if (cot::$usr['isadmin']) { if ($mf['state'] == -1) { unset($where['state']); } elseif ($mf['state'] >= 0 && $mf['state'] < 3) { $where['state'] = array('state', $mf['state']); } if ($mf['period'] == 'all') { unset($where['begin'], $where['expire']); } elseif ($mf['period'] == 'exp') { unset($where['begin']); $where['expire'] = array('SQL', "expire > 0 AND expire <= " . cot::$sys['now']); } elseif ($mf['period'] == 'fut') { unset($where['expire']); $where['begin'] = array('begin', cot::$sys['now'], '>'); } $tmp = array(-2 => cot::$R['code_option_empty'], -1 => cot::$L['All'], 0 => cot::$L['advboard_state_0'], 1 => cot::$L['advboard_state_1'], 2 => cot::$L['advboard_state_2']); $moderatorFilters['state'] = cot_selectbox($mf['state'], 'mf[state]', array_keys($tmp), array_values($tmp), false); $tmp = array('0' => cot::$R['code_option_empty'], 'all' => cot::$L['All'], 'exp' => cot::$L['advboard_expired'], 'fut' => cot::$L['advboard_future']); $moderatorFilters['period'] = cot_selectbox(strval($mf['period']), 'mf[period]', array_keys($tmp), array_values($tmp), false); $moderatorFilters['action'] = cot_url('advboard', $urlParams); $moderatorFilters['hidden'] = ''; foreach ($urlParams as $key => $val) { $moderatorFilters['hidden'] .= cot_inputbox('hidden', $key, $val); } $moderatorFilters['reset'] = cot_url('advboard', $urlParams); } cot_die(empty($category['title']) && !cot::$usr['isadmin']); cot::$out['desc'] = htmlspecialchars(strip_tags($category['desc'])); cot::$out['subtitle'] = $category['title']; if (!empty(cot::$cfg['advboard']['cat_' . $c]['keywords'])) { cot::$out['keywords'] = cot::$cfg['advboard']['cat_' . $c]['keywords']; } if (!empty(cot::$cfg['advboard']['cat_' . $c]['metadesc'])) { cot::$out['desc'] = cot::$cfg['advboard']['cat_' . $c]['metadesc']; } if (!empty(cot::$cfg['advboard']['cat_' . $c]['metatitle'])) { cot::$out['subtitle'] = cot::$cfg['advboard']['cat_' . $c]['metatitle']; } // Building the canonical URL cot::$out['canonical_uri'] = cot_url('advboard', $canonicalUrlParams); $condition = array(); foreach ($where as $key => $val) { $condition[] = $val; } $order = array(array('sticky', 'desc'), array($sort, $way)); /* === Hook === */ foreach (cot_getextplugins('advboard.list.query') as $pl) { include $pl; } /* ===== */ $totallines = advboard_model_Advert::count($condition); $advertisement = null; if ($totallines > 0) { $advertisement = advboard_model_Advert::find($condition, $maxrowsperpage, $d, $order); } $allowComments = cot_plugin_active('comments'); if ($allowComments) { if (!isset(cot::$cfg['advboard']['cat_' . $c])) { $allowComments = false; } else { $allowComments = cot::$cfg['advboard']['cat_' . $c]['enable_comments']; } } $addNewUrl = ''; if ((cot::$usr['auth_write'] || cot::$usr['isadmin']) && !empty($category['id'])) { $addNewUrl = cot_url('advboard', array('a' => 'edit', 'c' => $category['code'])); } /* === Hook === */ foreach (cot_getextplugins('advboard.list.main') as $pl) { include $pl; } /* ===== */ // Extra fields for structure foreach ($cot_extrafields[$db_structure] as $exfld) { $uname = $exfld['field_name']; $val = $structure['advboard'][$c][$exfld['field_name']]; $category[$uname . '_title'] = isset(cot::$L['structure_' . $exfld['field_name'] . '_title']) ? cot::$L['structure_' . $exfld['field_name'] . '_title'] : $exfld['field_description']; $category[$uname] = cot_build_extrafields_data('structure', $exfld, $val); $category[$uname . '_value'] = $val; } $kk = 0; $allsub = cot_structure_children('advboard', $c, false, false, true, false); $subcat = array_slice($allsub, $dc, cot::$cfg['advboard']['maxlistsperpage']); /* === Hook === */ foreach (cot_getextplugins('advboard.list.rowcat.first') as $pl) { include $pl; } /* ===== */ /* === Hook - Part1 : Set === */ $extp = cot_getextplugins('advboard.list.rowcat.loop'); /* ===== */ $subCategories = array(); foreach ($subcat as $x) { $kk++; $cat_childs = cot_structure_children('advboard', $x); $sub_count = 0; foreach ($cat_childs as $cat_child) { $sub_count += (int) $structure['advboard'][$cat_child]['count']; } $sub_url_path = $urlParams; $sub_url_path['c'] = $x; $subCategories[$x] = $structure['advboard'][$x]; $subCategories[$x]['config'] = cot::$cfg['advboard']['cat_' . $x]; $subCategories[$x]['code'] = $x; $subCategories[$x]['count'] = $sub_count; $subCategories[$x]['num'] = $kk; // Extra fields for structure foreach ($cot_extrafields[$db_structure] as $exfld) { $uname = $exfld['field_name']; $val = $structure['advboard'][$x][$exfld['field_name']]; $subCategories[$x][$uname . '_title'] = isset(cot::$L['structure_' . $exfld['field_name'] . '_title']) ? cot::$L['structure_' . $exfld['field_name'] . '_title'] : $exfld['field_description']; $subCategories[$x][$uname] = cot_build_extrafields_data('structure', $exfld, $val); $subCategories[$x][$uname . '_value'] = $val; } /* === Hook - Part2 : Include === */ foreach ($extp as $pl) { include $pl; } /* ===== */ } $crumbs = array(); if (!empty($category['id'])) { $crumbs = cot_structure_buildpath('advboard', $c); if (cot::$cfg['advboard']['firstCrumb']) { array_unshift($crumbs, array(cot_url('advboard'), cot::$L['advboard_ads'])); } } // Фильтры для модератора if (cot::$usr['isadmin']) { if ($mf['period'] != '0') { $urlParams['mf[period]'] = $mf['period']; } if ($mf['state'] != -2) { $urlParams['mf[state]'] = $mf['state']; } } $pagenavCategory = cot_pagenav('advboard', $urlParams + array('d' => $durl), $dc, count($allsub), cot::$cfg['advboard']['maxlistsperpage'], 'dc'); if (empty($pagenavCategory['current'])) { $pagenavCategory['current'] = 1; } $pagenav = cot_pagenav('advboard', $urlParams + array('dc' => $dcurl), $d, $totallines, $maxrowsperpage); if (empty($pagenav['current'])) { $pagenav['current'] = 1; } $breadcrumbs = ''; if (!empty($crumbs)) { $breadcrumbs = cot_breadcrumbs($crumbs, cot::$cfg['homebreadcrumb'], true); } $pageUrlParams = $urlParams; if ($durl > 1) { $pageUrlParams['d'] = $durl; } $view = new View(); $view->breadcrumbs = $breadcrumbs; $view->page_title = htmlspecialchars($category['title']); $view->category = $category; $view->subCategories = $subCategories; $view->condition = $condition; $view->order = $order; $view->advertisement = $advertisement; $view->totalitems = $totallines; $view->allowComments = $allowComments; $view->pagenav = $pagenav; $view->pagenavCategory = $pagenavCategory; $view->moderatorFilters = $moderatorFilters; $view->addNewUrl = $addNewUrl; $view->urlParams = $urlParams; $view->pageUrlParams = $pageUrlParams; /* === Hook === */ foreach (cot_getextplugins('advboard.list.view') as $pl) { include $pl; } /* ===== */ return $view->render($template); }
public static function adsList($condition = array(), $tpl = 'advboard.widget.list', $items = 0, $order = '', $onlyActive = true, $pagination = 'pld', $params = array()) { // Get pagination number if necessary if (!empty($pagination)) { list($pg, $d, $durl) = cot_import_pagenav($pagination, $items); } else { $d = 0; } if (empty($condition)) { $condition = array(); } if ($onlyActive) { $condition[] = array('begin', cot::$sys['now'], '<='); $condition[] = array('SQL', "expire = 0 OR expire > " . cot::$sys['now']); $condition[] = array('state', advboard_model_Advert::PUBLISHED); } if (empty($order)) { $order = array(array('state', 'ASC'), array('sort', 'DESC')); } /* === Hook === */ foreach (cot_getextplugins('advboard.widget.list.query') as $pl) { include $pl; } /* ===== */ $totallines = advboard_model_Advert::count($condition); $advertisement = advboard_model_Advert::find($condition, $items, $d, $order); // Render pagination if (empty($params['module'])) { $params['module'] = defined('COT_PLUG') ? 'plug' : cot::$env['ext']; } if (empty($params['urlParams'])) { if (defined('COT_LIST')) { global $list_url_path; $params['urlParams'] = $list_url_path; } elseif (defined('COT_PAGES')) { global $al, $id, $pag; $params['urlParams'] = empty($al) ? array('c' => $pag['page_cat'], 'id' => $id) : array('c' => $pag['page_cat'], 'al' => $al); } else { $params['urlParams'] = array(); } } if (empty($params['ajax'])) { $params['ajax'] = false; } if (empty($params['target_div'])) { $params['target_div'] = ''; } if (empty($params['ajax_module'])) { $params['ajax_module'] = ''; } if (empty($params['ajax_params'])) { $params['ajax_params'] = array(); } $pagenav = cot_pagenav($params['module'], $params['urlParams'], $d, $totallines, $items, $pagination, '', $params['ajax'], $params['target_div'], $params['ajax_module'], $params['ajax_params']); if (empty($pagenav['current'])) { $pagenav['current'] = 1; } $view = new View(); /* === Hook === */ foreach (cot_getextplugins('advboard.widget.list.view') as $pl) { include $pl; } /* ===== */ $view->advertisement = $advertisement; $view->totalitems = $totallines; $view->pagenav = $pagenav; return $view->render($tpl); }
$sitemap_where['begin'] = array('begin', cot::$sys['now'], '<='); $sitemap_where['expire'] = array('SQL', "expire = 0 OR expire > " . cot::$sys['now']); /* === Hook === */ foreach (cot_getextplugins('sitemap.advboard.query') as $pl) { include $pl; } /* ===== */ $condition = array(); foreach ($sitemap_where as $key => $val) { $condition[] = $val; } $order = array(array('sort', 'DESC')); $cnt = advboard_model_Advert::count($condition); if ($cnt > 0) { $i = 0; while ($i <= $cnt) { $advertisement = advboard_model_Advert::find($condition, 20, $i, $order); if (!$advertisement) { break; } foreach ($advertisement as $advert) { $i++; if (!$auth_cache[$advert->category]) { continue; } sitemap_parse($t, $items, array('url' => $advert->url, 'date' => !empty($advert->updated) ? strtotime($advert->updated) : '', 'freq' => cot::$cfg['plugin']['sitemap']['freq'], 'prio' => cot::$cfg['plugin']['sitemap']['prio'])); unset($advert); } unset($advertisement); } }
<?php /* ==================== [BEGIN_COT_EXT] Hooks=users.edit.update.delete [END_COT_EXT] ==================== */ /** * Ads board module for Cotonti Siena * * @package Advboard * @author Kalnov Alexey <*****@*****.**> * @copyright (c) Portal30 Studio http://portal30.ru */ defined('COT_CODE') or die('Wrong URL'); require_once cot_incfile('advboard', 'module'); // Удалить все объявления пользователя $condition = array(array('user', $id)); $advertisement = advboard_model_Advert::find($condition, 20, $i, array(array('id', 'ASC'))); if (!empty($advertisement)) { foreach ($advertisement as $advert) { $advert->delete(); unset($advert); } unset($advertisement); }