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']); } } // Выдержка с поста // $len_cut = 500; // Длина выдержки с поста (символов) $advComText = cot_parse($comarray['com_text'], cot::$cfg['plugin']['comments']['markup']); // $advComText = cot_string_truncate($advComText, $len_cut, true, false, '...'); // /Выдержка с поста // Автор комментария $advCommenterName = cot::$L['Anonymous']; $advCommenterUrl = ''; if (cot::$usr['id'] > 0) { $advCommenterName = cot_user_full_name(cot::$usr['profile']); $advCommenterUrl = cot_url('users', array('m' => 'details', 'id' => cot::$usr['id'], 'u' => htmlspecialchars(cot::$usr['name']))); if (!cot_url_check($advCommenterUrl)) { $advCommenterUrl = COT_ABSOLUTE_URL . $advCommenterUrl; } } elseif ($comarray['com_author'] != '') { $advCommenterName = $comarray['com_author']; } // /Автор комментария $mailView = new View(); $mailView->advert = $advert; $mailView->owner = $owner; $mailView->commentText = $advComText; $mailView->commentUrl = $advertUrl . "#c" . $id; $mailView->commenter = cot::$usr['id'] > 0 ? cot::$usr['profile'] : array(); $mailView->commenterName = $advCommenterName;
* @copyright Portal30 Studio http://portal30.ru * * You can use templates: advboard.notify_admin_new_adv.<lang>.<categoty>.php */ /** @var advboard_model_Advert $advert */ $advert = $this->advert; $title = !empty($advert->title) ? $advert->title : cot::$L['advboard_no_title']; ?> Добрый день! <p> Пользователь <a href="<?php echo $this->userUrl; ?> "><?php echo cot_user_full_name(cot::$usr['profile']); ?> </a> (<a href="<?php echo $this->userUrl; ?> "><?php echo $this->userUrl; ?> </a>), <br /><br /> добавил или отредактировал объявление: <a href="<?php echo $this->advertUrl; ?> "><?php echo htmlspecialchars($title);
/** * Returns all user tags for XTemplate * * @param mixed $user_data User Info Array * @param string $tag_prefix Prefix for tags * @param string $emptyname Name text if user is not exist * @param bool $allgroups Build info about all user groups * @param bool $cacheitem Cache tags * @return array * @global CotDB $db */ function cot_generate_usertags($user_data, $tag_prefix = '', $emptyname = '', $allgroups = false, $cacheitem = true) { global $db, $cot_extrafields, $cot_groups, $cfg, $L, $user_cache, $db_users; static $extp_first = null, $extp_main = null; $return_array = array(); if (is_null($extp_first)) { $extp_first = cot_getextplugins('usertags.first'); $extp_main = cot_getextplugins('usertags.main'); } /* === Hook === */ foreach ($extp_first as $pl) { include $pl; } /* ===== */ $user_id = is_array($user_data) ? (int) $user_data['user_id'] : (is_numeric($user_data) ? (int) $user_data : 0); if (isset($user_cache[$user_id])) { $temp_array = $user_cache[$user_id]; } else { if (!is_array($user_data) && $user_id > 0) { $sql = $db->query("SELECT * FROM {$db_users} WHERE user_id = {$user_id} LIMIT 1"); $user_data = $sql->fetch(); } else { if (!is_array($user_data)) { $user_data = array(); } } if (is_array($user_data) && $user_data['user_id'] > 0 && !empty($user_data['user_name'])) { $user_data['user_birthdate'] = cot_date2stamp($user_data['user_birthdate']); $user_data['user_text'] = cot_parse($user_data['user_text'], $cfg['users']['usertextimg']); $temp_array = array('ID' => $user_data['user_id'], 'NAME' => cot_build_user($user_data['user_id'], htmlspecialchars($user_data['user_name'])), 'NICKNAME' => htmlspecialchars($user_data['user_name']), 'DETAILSLINK' => cot_url('users', 'm=details&id=' . $user_data['user_id'] . '&u=' . htmlspecialchars($user_data['user_name'])), 'DETAILSLINKSHORT' => cot_url('users', 'm=details&id=' . $user_data['user_id']), 'FULL_NAME' => htmlspecialchars(cot_user_full_name($user_data)), 'TITLE' => $cot_groups[$user_data['user_maingrp']]['title'], 'MAINGRP' => cot_build_group($user_data['user_maingrp']), 'MAINGRPID' => $user_data['user_maingrp'], 'MAINGRPNAME' => $cot_groups[$user_data['user_maingrp']]['name'], 'MAINGRPTITLE' => cot_build_group($user_data['user_maingrp'], true), 'MAINGRPSTARS' => cot_build_stars($cot_groups[$user_data['user_maingrp']]['level']), 'MAINGRPICON' => cot_build_groupicon($cot_groups[$user_data['user_maingrp']]['icon']), 'COUNTRY' => cot_build_country($user_data['user_country']), 'COUNTRYFLAG' => cot_build_flag($user_data['user_country']), 'TEXT' => $user_data['user_text'], 'EMAIL' => cot_build_email($user_data['user_email'], $user_data['user_hideemail']), 'THEME' => $user_data['user_theme'], 'SCHEME' => $user_data['user_scheme'], 'LANG' => $user_data['user_lang'], 'GENDER' => $user_data['user_gender'] == '' || $user_data['user_gender'] == 'U' ? '' : $L['Gender_' . $user_data['user_gender']], 'BIRTHDATE' => is_null($user_data['user_birthdate']) ? '' : cot_date('date_full', $user_data['user_birthdate']), 'BIRTHDATE_STAMP' => is_null($user_data['user_birthdate']) ? '' : $user_data['user_birthdate'], 'AGE' => is_null($user_data['user_birthdate']) ? '' : cot_build_age($user_data['user_birthdate']), 'TIMEZONE' => cot_build_timezone(cot_timezone_offset($user_data['user_timezone'], false, false)) . ' ' . str_replace('_', ' ', $user_data['user_timezone']), 'REGDATE' => cot_date('datetime_medium', $user_data['user_regdate']), 'REGDATE_STAMP' => $user_data['user_regdate'], 'LASTLOG' => cot_date('datetime_medium', $user_data['user_lastlog']), 'LASTLOG_STAMP' => $user_data['user_lastlog'], 'LOGCOUNT' => $user_data['user_logcount'], 'POSTCOUNT' => $user_data['user_postcount'], 'LASTIP' => $user_data['user_lastip']); if ($allgroups) { $temp_array['GROUPS'] = cot_build_groupsms($user_data['user_id'], FALSE, $user_data['user_maingrp']); } // Extra fields if (isset($cot_extrafields[$db_users])) { foreach ($cot_extrafields[$db_users] as $exfld) { $temp_array[strtoupper($exfld['field_name'])] = cot_build_extrafields_data('user', $exfld, $user_data['user_' . $exfld['field_name']]); $temp_array[strtoupper($exfld['field_name']) . '_TITLE'] = isset($L['user_' . $exfld['field_name'] . '_title']) ? $L['user_' . $exfld['field_name'] . '_title'] : $exfld['field_description']; $temp_array[strtoupper($exfld['field_name']) . '_VALUE'] = $user_data['user_' . $exfld['field_name']]; } } } else { $temp_array = array('ID' => 0, 'NAME' => !empty($emptyname) ? $emptyname : $L['Deleted'], 'NICKNAME' => !empty($emptyname) ? $emptyname : $L['Deleted'], 'FULL_NAME' => !empty($emptyname) ? $emptyname : $L['Deleted'], 'MAINGRP' => cot_build_group(1), 'MAINGRPID' => 1, 'MAINGRPSTARS' => '', 'MAINGRPICON' => cot_build_groupicon($cot_groups[1]['icon']), 'COUNTRY' => cot_build_country(''), 'COUNTRYFLAG' => cot_build_flag(''), 'TEXT' => '', 'EMAIL' => '', 'GENDER' => '', 'BIRTHDATE' => '', 'BIRTHDATE_STAMP' => '', 'AGE' => '', 'REGDATE' => '', 'REGDATE_STAMP' => '', 'POSTCOUNT' => '', 'LASTIP' => ''); } /* === Hook === */ foreach ($extp_main as $pl) { include $pl; } /* ===== */ if (is_array($user_data) && isset($user_data['user_id'])) { $cacheitem && ($user_cache[$user_data['user_id']] = $temp_array); } } foreach ($temp_array as $key => $val) { $return_array[$tag_prefix . $key] = $val; } return $return_array; }
public function indexAction() { global $structure; $uid = cot_import('uid', 'G', 'INT'); if (empty($uid)) { $uid = cot::$usr['id']; } // Незарегов, если они не смотрят объявления другого пользователя перенаправляем if (!$uid) { cot_redirect(cot_url('advboard', '', '', true)); } // Проверить существование пользователя $user = cot_user_data($uid); if (!$user) { cot_die_message(404, TRUE); } $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 $condition = array(array('user', $uid)); if (!cot::$usr['isadmin'] && $uid != cot::$usr['id']) { $condition[] = array('state', advboard_model_Advert::PUBLISHED); $condition[] = array('begin', cot::$sys['now'], '<='); $condition[] = array('SQL', "expire = 0 OR expire > " . cot::$sys['now']); } $order = array(array('state', 'ASC'), array('sort', 'DESC')); cot::$out['canonical_uri'] = cot_url('advboard', array('m' => 'user', 'uid' => $uid)); $urlParams = array('m' => 'user'); if ($uid != cot::$usr['id']) { $urlParams['uid'] = $uid; } $title = ''; $crumbs = array(); if ($uid != cot::$usr['id']) { cot::$out['subtitle'] = $title = cot::$L['advboard_user_ads'] . ': ' . cot_user_full_name($user); $crumbs[] = array(cot_url("users"), cot::$L['Users']); $crumbs[] = array(cot_url("users", "m=details&id=" . $user["user_id"] . "&u=" . $user["user_name"]), cot_user_full_name($user)); $crumbs[] = cot::$L['advboard_user_ads']; // $advUrlParams['uid'] = $user['user_id']; $urlParams['uid'] = $user['user_id']; } else { cot::$out['subtitle'] = $title = cot::$L['advboard_my_ads']; $crumbs[] = array(cot_url('users', array('m' => 'details')), cot::$L['advboard_my_page']); $crumbs[] = cot::$L['advboard_my_ads']; } /* === Hook === */ foreach (cot_getextplugins('advboard.user.list.query') as $pl) { include $pl; } /* ===== */ $totallines = advboard_model_Advert::count($condition); $advertisement = advboard_model_Advert::find($condition, $maxrowsperpage, $d, $order); $addNewUrl = ''; if ((cot::$usr['auth_write'] || cot::$usr['isadmin']) && !empty($structure['advboard'])) { // Ищем категорию куда пользователь может подать оьбъявление foreach ($structure['advboard'] as $catCode => $catRow) { $auth_write = cot_auth('advboard', $catCode, 'W'); if ($auth_write) { $addNewUrl = cot_url('advboard', array('a' => 'edit', 'c' => $catCode)); break; } } } $pagenav = cot_pagenav('advboard', $urlParams, $d, $totallines, $maxrowsperpage); if (empty($pagenav['current'])) { $pagenav['current'] = 1; } $breadcrumbs = ''; if (!empty($crumbs)) { $breadcrumbs = cot_breadcrumbs($crumbs, cot::$cfg['homebreadcrumb'], true); } $template = array('advboard', 'list', 'user'); $pageUrlParams = $urlParams; if ($durl > 1) { $pageUrlParams['d'] = $durl; } $view = new View(); $view->breadcrumbs = $breadcrumbs; $view->page_title = htmlspecialchars($title); $view->advertisement = $advertisement; $view->allowComments = true; $view->totalitems = $totallines; $view->pagenav = $pagenav; $view->addNewUrl = $addNewUrl; $view->urlParams = $urlParams; $view->pageUrlParams = $pageUrlParams; /* === Hook === */ foreach (cot_getextplugins('advboard.user.list.view') as $pl) { include $pl; } /* ===== */ return $view->render($template); }
public function editAction() { global $structure, $cot_extrafields, $db_structure; $id = cot_import('id', 'G', 'INT'); // id Объявления $c = cot_import('c', 'G', 'TXT'); $act = cot_import('act', 'G', 'ALP'); if (empty($act)) { $act = cot_import('act', 'P', 'ALP'); } /* === Hook === */ foreach (cot_getextplugins('advboard.edit.first') as $pl) { include $pl; } /* ===== */ // Права на любую категорию доски объявлений list(cot::$usr['auth_read'], cot::$usr['auth_write'], cot::$usr['isadmin']) = cot_auth('advboard', 'any'); cot_block(cot::$usr['auth_write']); if (!$c || !isset($structure['advboard'][$c])) { cot_die_message(404, TRUE); } $category = $structure['advboard'][$c]; $category['config'] = cot::$cfg['advboard']['cat_' . $c]; $category['code'] = $c; // 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; } $published = 0; if (!$id) { $advert = new advboard_model_Advert(); $advert->category = $c; $advert->user = cot::$usr['id']; } else { $advert = advboard_model_Advert::getById($id); if (!$advert) { cot_die_message(404, TRUE); } if (!cot::$usr['isadmin']) { if ($advert->user != cot::$usr['id']) { cot_die_message(404, TRUE); } } if ($c != $advert->category && isset($structure['advboard'][$advert->category])) { $tmp = array('c' => $advert->category, 'a' => 'edit', 'id' => $advert->id); if (!empty($act)) { $tmp['act'] = $act; } cot_redirect(cot_url('advboard', array('c' => $advert->category, 'a' => 'edit', 'id' => $advert->id), '', true)); } if ($act == 'clone') { $id = null; $advert = clone $advert; // Установить статус и пользователя нового объекта $advert->user = cot::$usr['id']; $advert->state = advboard_model_Advert::DRAFT; } $published = $advert->state < 2 ? 1 : 0; } //Проверим права на категорию: list(cot::$usr['auth_read'], cot::$usr['auth_write'], cot::$usr['isadmin'], cot::$usr['auth_upload']) = cot_auth('advboard', $c, 'RWA1'); if ($structure['advboard'][$c]['locked'] && !cot::$usr['isadmin']) { cot_die_message(602, TRUE); } elseif ($advert->id == 0) { // Если у пользователя нет прав на подачу объявления, то ищем категорию куда он может подать оьбъявление if (!cot::$usr['auth_write']) { foreach ($structure['advboard'] as $catCode => $catRow) { $auth_write = cot_auth('advboard', $catCode, 'W'); if ($auth_write) { cot_redirect(cot_url('advboard', array('c' => $catCode, 'a' => 'edit'), '', true)); } } } cot_block(cot::$usr['auth_write']); } // Владелец объявления $user = array(); if ($advert->user > 0) { $user = cot_user_data($advert->user); } $periodItems = adv_periodItems($c); // Сохранение if ($act == 'save') { unset($_POST['id'], $_POST['user']); cot_shield_protect(); /* === Hook === */ foreach (cot_getextplugins('advboard.save.first') as $pl) { include $pl; } /* ===== */ // импортировать даты $begin = (int) cot_import_date('begin'); $expire = (int) cot_import_date('expire'); if ($begin == 0) { $begin = !empty($advert->begin) ? $advert->begin : cot::$sys['now']; } // Пересчитать период публикации объявления if ($expire == 0 && cot::$cfg['advboard']['cat_' . $c]['maxPeriod'] > 0) { $period = cot_import('period', 'P', 'INT'); $maxPeriod = max($periodItems); if (empty($period)) { $period = $maxPeriod; } if (!cot::$usr['isadmin'] && $period > $maxPeriod) { $period = $maxPeriod; } if ($period > 0) { $expire = $begin + $period * 86400; } } if ($category['config']['title_require']) { $advert->setValidator('title', 'required'); } // Валидатор 'allowemptytext' if (!$category['config']['allowemptytext']) { $advert->setValidator('text', 'required'); } if ($category['config']['phone_require']) { // проверить надичие заполненного поля в профиле пользователя - владельца if (empty($user['user_phone'])) { $advert->setValidator('phone', 'required'); } } if ($category['config']['city_require']) { // Проверить наличие заполненного города (id или названия) в профиле владельца if (empty($user['user_city_name']) && empty($user['user_city'])) { if (cot_plugin_active('regioncity')) { $advert->setValidator('city', function ($value) { $value = (int) $value; if ($value == 0) { return cot::$L['field_required'] . ': ' . advboard_model_Advert::fieldLabel('city'); } return true; }); } else { $advert->setValidator('city_name', 'required'); } } } if (cot::$usr['id'] == 0) { $advert->setValidator('person', 'required'); // Email $email = cot_import('email', 'P', 'TXT'); if (cot::$cfg['advboard']['guestEmailRequire']) { if ($email == '') { cot_error(cot::$L['advboard_err_noemail'], 'email'); } } if ($email != '') { $tmp = advert_checkEmail($email); if ($tmp !== true) { cot_error($tmp, 'email'); } } // Капча if (cot::$cfg['advboard']['guestUseCaptcha']) { $verify = cot_import('verify', 'P', 'TXT'); if (!cot_captcha_validate($verify)) { cot_error(cot::$L['captcha_verification_failed'], 'verify'); } } } $advert->setData($_POST); $advert->begin = $begin; $advert->expire = $expire; if (!cot::$usr['isadmin']) { if (!cot::$cfg['advboard']['cat_' . $c]['allowSticky']) { $advert->sticky = 0; } if (cot::$usr['id'] == 0) { $advert->sticky = 0; } // гости не дают срочных объявлений } $advert->category = $c; if (empty($advert->user) || !cot::$usr['isadmin']) { $advert->user = cot::$usr['id']; } $published = cot_import('published', 'P', 'BOL'); if (!$published) { $advert->state = advboard_model_Advert::DRAFT; } elseif (cot::$usr['isadmin'] || cot_auth('advboard', $c, '2')) { $advert->state = advboard_model_Advert::PUBLISHED; } else { $advert->state = advboard_model_Advert::AWAITING_MODERATION; } /* === Hook === */ foreach (cot_getextplugins('advboard.save.validate') as $pl) { include $pl; } /* ===== */ // There is some errors if (!$advert->validate() || cot_error_found()) { $urlParams = array('c' => $c, 'a' => 'edit'); if ($advert->id > 0) { $urlParams['id'] = $advert->id; } cot_redirect(cot_url('advboard', $urlParams, '', true)); } if (empty($advert->sort)) { $advert->sort = cot::$sys['now']; } $isNew = $advert->id == 0; // Сохранение if ($advert->save()) { // Для незарега запомним id страницы для чтого, чтобы он мог ее отредактировать в пределах сесии if ($isNew) { if (cot::$usr['id'] == 0) { if (empty($_SESSION['advboard'])) { $_SESSION['advboard'] = array(); } if (!in_array($id, $_SESSION['advboard'])) { $_SESSION['advboard'][] = $advert->id; } } if ($advert->state == advboard_model_Advert::PUBLISHED) { cot_message(cot::$L['advboard_created']); } } else { if ($advert->state == advboard_model_Advert::PUBLISHED) { cot_message(cot::$L['advboard_updated']); } } if ($advert->state == advboard_model_Advert::AWAITING_MODERATION) { cot_message(cot::$L['advboard_awaiting_moderation']); } elseif ($advert->state == advboard_model_Advert::DRAFT) { cot_message(cot::$L['Saved']); } $redirectUrl = $advert->getUrl(true); /* === Hook === */ foreach (cot_getextplugins('advboard.save.done') as $pl) { include $pl; } /* ===== */ // Редирект на станицу объявления cot_redirect($redirectUrl); } } $crumbs = cot_structure_buildpath('advboard', $c); if (cot::$cfg['advboard']['firstCrumb']) { array_unshift($crumbs, array(cot_url('advboard'), cot::$L['advboard_ads'])); } if (!$id) { $crumbs[] = $title = cot::$L['advboard_add_new']; cot::$out['subtitle'] = $title; } else { $crumbs[] = array($advert->url, $advert->title); $crumbs[] = cot::$L['Edit']; $title = cot::$L['advboard_advert'] . ' #' . $advert->id; if (!empty($advert->title)) { $title = $advert->title; } $title .= ': ' . cot::$L['Edit']; if (!empty(cot::$out['subtitle'])) { $title .= ' - ' . cot::$out['subtitle']; } cot::$out['subtitle'] = $title; } // Elemets placeholders $placeHolder_Person = ''; $placeHolder_Phone = ''; $placeHolder_Email = ''; $placeHolder_City = ''; //if($advboard->user == cot::$usr['id'] && cot::$usr['id'] > 0) { if (!empty($user)) { // Контакное лицо $placeHolder_Person = cot_user_full_name($user); // Телефон if (!empty($user['user_phone'])) { $placeHolder_Phone = $user['user_phone']; } // email if (!$user['user_hideemail']) { $placeHolder_Email = $user['user_email']; } // город if (!empty($user['user_city_name'])) { $placeHolder_City = $user['user_city_name']; } } // 'input_textarea_editor', 'input_textarea_medieditor', 'input_textarea_minieditor', '' $editor = 'input_textarea_editor'; /* === Hook === */ foreach (cot_getextplugins('advboard.edit.main') as $pl) { include $pl; } /* ===== */ $minYear = date('Y'); $maxYear = $minYear + 30; $price = $advert->rawValue('price'); if ($price <= 0) { $price = ''; } $formElements = array('hidden' => array('element' => cot_inputbox('hidden', 'act', 'save')), 'category' => array('element' => cot_selectbox_structure('advboard', $advert->category, 'category'), 'label' => advboard_model_Advert::fieldLabel('category')), 'price' => array('element' => cot_inputbox('text', 'price', $price), 'label' => advboard_model_Advert::fieldLabel('price'), 'hint' => cot::$L['advboard_price_hint']), 'title' => array('element' => cot_inputbox('text', 'title', $advert->rawValue('title')), 'required' => true, 'label' => advboard_model_Advert::fieldLabel('title')), 'description' => array('element' => cot_inputbox('text', 'description', $advert->rawValue('description')), 'label' => advboard_model_Advert::fieldLabel('description')), 'text' => array('element' => cot_textarea('text', $advert->rawValue('text'), 5, 120, '', $editor), 'label' => advboard_model_Advert::fieldLabel('text')), 'person' => array('element' => cot_inputbox('text', 'person', $advert->rawValue('person'), array('class' => 'form-control', 'placeholder' => $placeHolder_Person)), 'label' => advboard_model_Advert::fieldLabel('person'), 'required' => cot::$usr['id'] == 0), 'email' => array('element' => cot_inputbox('text', 'email', $advert->rawValue('email'), array('class' => 'form-control', 'placeholder' => $placeHolder_Email)), 'label' => advboard_model_Advert::fieldLabel('email')), 'city' => array('element' => cot_inputbox('text', 'city_name', $advert->rawValue('city_name'), array('class' => 'form-control', 'placeholder' => $placeHolder_City)), 'label' => advboard_model_Advert::fieldLabel('city_name'), 'required' => $category['config']['city_require']), 'phone' => array('element' => cot_inputbox('text', 'phone', $advert->rawValue('phone'), array('class' => 'form-control', 'placeholder' => $placeHolder_Phone)), 'label' => advboard_model_Advert::fieldLabel('phone'), 'required' => $category['config']['phone_require']), 'sticky' => array('element' => cot_checkbox($advert->sticky, 'sticky', advboard_model_Advert::fieldLabel('sticky')), 'label' => advboard_model_Advert::fieldLabel('sticky')), 'published' => array('element' => cot_checkbox($published, 'published', cot::$L['advboard_published'] . '?'), 'label' => cot::$L['advboard_published'] . '?'), 'begin' => array('element' => cot_selectbox_date($advert->begin, 'long', 'begin', $maxYear, $minYear), 'label' => advboard_model_Advert::fieldLabel('begin')), 'expire' => array('element' => cot_selectbox_date($advert->expire, 'long', 'expire', $maxYear, $minYear), 'label' => advboard_model_Advert::fieldLabel('expire')), 'sort' => array('element' => cot_selectbox_date($advert->sort, 'long', 'sort', $maxYear, $minYear), 'label' => advboard_model_Advert::fieldLabel('sort')), 'period' => array('element' => cot_selectbox('', 'period', $periodItems, array(), false), 'label' => cot::$L['advboard_period'])); if (!empty($cot_extrafields[cot::$db->advboard])) { // Extra fields for ads foreach ($cot_extrafields[cot::$db->advboard] as $exfld) { $fName = $exfld['field_name']; $formElements[$fName] = array('element' => cot_build_extrafields($fName, $exfld, $advert->rawValue($fName))); if ($exfld['field_type'] !== 'checkbox') { $formElements[$fName]['label'] = isset(cot::$L['advboard_' . $exfld['field_name'] . '_title']) ? cot::$L['advboard_' . $exfld['field_name'] . '_title'] : advboard_model_Advert::fieldLabel($fName); } } } if (cot_plugin_active('regioncity')) { $formElements['city']['element'] = rec_select2_city('city', $advert->rawValue('city'), true, array('class' => 'form-control', 'placeholder' => $placeHolder_City)); } if ($category['config']['city_require']) { $formElements['city']['required'] = true; } if ($category['config']['phone_require']) { $formElements['phone']['required'] = true; } // Hints if (!empty($user)) { // Контакное лицо $formElements['person']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . cot_user_full_name($user); // Телефон if (!empty($user['user_phone'])) { $formElements['phone']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . $user['user_phone']; } // email if (!$user['user_hideemail']) { $formElements['email']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . $user['user_email']; } // город if (!empty($user['user_city_name'])) { $formElements['city']['hint'] = cot::$L['advboard_leave_empty_to_use'] . ": " . $user['user_city_name']; } } if (!cot::$usr['isadmin']) { unset($formElements['begin']); unset($formElements['expire']); unset($formElements['sort']); if (cot::$usr['id'] == 0) { if (cot::$cfg['advboard']['guestEmailRequire']) { $formElements['email']['required'] = true; } // Гости не дают срочных объявлений unset($formElements['sticky']); // Капча if (cot::$cfg['advboard']['guestUseCaptcha']) { $formElements['verify'] = array('element' => cot_inputbox('text', 'verify'), 'img' => cot_captcha_generate(), 'label' => cot::$L['advboard_captcha'], 'required' => true); } } if (!cot::$cfg['advboard']['cat_' . $c]['allowSticky'] && isset($formElements['sticky'])) { unset($formElements['sticky']); } } else { // Администратор напрямую указывает дату окончания публикации unset($formElements['period']); } $actionParams = array('a' => 'edit', 'c' => $advert->category); if ($advert->id > 0) { $actionParams['id'] = $advert->id; } $view = new View(); $view->breadcrumbs = cot_breadcrumbs($crumbs, cot::$cfg['homebreadcrumb'], true); $view->page_title = $title; $view->category = $category; $view->advert = $advert; $view->user = $user; $view->formElements = $formElements; $view->formAction = cot_url('advboard', $actionParams); /* === Hook === */ foreach (cot_getextplugins('advboard.edit.view') as $pl) { include $pl; } /* ===== */ return $view->render(array('advboard', 'edit', $structure['advboard'][$c]['tpl'])); }
/** * Обработка Ajax запроса на подписку на рассылку * Используется виджетом * Принимает email пользователя * Допускается подписка неавторизованными пользователями (они должны подтвердить email) */ public function ajxSubscribeAction() { global $db_users; $ret = array('error' => '', 'message' => ''); $id = cot_import('id', 'P', 'INT'); $email = cot_import('email', 'P', 'TXT'); if (!$id) { $ret['error'] = cot::$L['subscribe_err_not_found']; echo json_encode($ret); exit; } $subscribe = subscribe_model_Subscribe::getById($id); if (!$subscribe) { $ret['error'] = cot::$L['subscribe_err_not_found']; echo json_encode($ret); exit; } if (!$subscribe->active) { $ret['error'] = cot::$L['subscribe_err_disabled']; echo json_encode($ret); exit; } if (empty($email)) { $ret['error'] = cot::$L['field_required'] . ': ' . cot::$L['Email']; echo json_encode($ret); exit; } $tmp = subscribe_checkEmail($email); if ($tmp !== true) { $ret['error'] = $tmp; echo json_encode($ret); exit; } $email = mb_strtolower($email); $subscriber = subscribe_model_Subscriber::fetchOne(array(array('subscribe', $id), array('email', $email))); if ($subscriber) { if ($subscriber->active) { $ret['error'] = sprintf(cot::$L['subscribe_err_user_subscribed'], $email, $subscribe->title); echo json_encode($ret); exit; } } else { $subscriber = new subscribe_model_Subscriber(); } $sql = cot::$db->query("SELECT * FROM {$db_users} WHERE user_email = ? LIMIT 1", $email); $user = $sql->fetch(); $subscriber->subscribe = $id; $subscriber->email = $email; if (!empty($user)) { $subscriber->user = $user['user_id']; $subscriber->name = cot_user_full_name($user); } $needConfirm = cot::$cfg['subscribe']['guestConfirmMail']; if (cot::$usr['id'] > 0) { if (cot::$usr['id'] == $user['user_id'] || cot::$usr['isadmin']) { $needConfirm = false; } } if ($needConfirm) { // Возможно пользователь уже подтверждал свой email $tmp = subscribe_model_Subscriber::count(array(array('email', $email), array('email_valid', 1))); if ($tmp > 0) { $needConfirm = false; } } if (!$needConfirm) { $subscriber->email_valid = 1; $subscriber->email_valid_date = date('Y-m-d H:i:s', cot::$sys['now']); $subscriber->active = 1; } // Сохранение $subscriber->save(); $ret['message'] = sprintf(cot::$L['subscribe_msg_you_subscribed'], $subscribe->title); // Письмо для поджтверждения e-mail адреса if ($needConfirm) { $confirmUrl = cot_url('subscribe', array('m' => 'user', 'a' => 'confirm', 'code' => $subscriber->unsubscr_code)); if (!cot_url_check($confirmUrl)) { $confirmUrl = cot::$cfg['mainurl'] . '/' . $confirmUrl; } $mailView = new View(); $mailView->subscriber = $subscriber; $mailView->subscribe = $subscribe; $mailView->confirmUrl = $confirmUrl; $mailTpl = array('subscribe', 'mail_confirm', cot::$usr['lang']); $mailBody = $mailView->render($mailTpl); cot_mail($email, cot::$L['subscribe_confirm'], $mailBody, '', false, null, true); $ret['message'] .= cot::$L['subscribe_wait_confirm']; } echo json_encode($ret); exit; }
public function ajxEditAction() { global $db_users; $ret = array('error' => ''); $id = cot_import('subrid', 'P', 'INT'); unset($_POST['id'], $_POST['subrid']); if ($id > 0) { $subscriber = subscribe_model_Subscriber::getById($id); if (!$subscriber) { $ret['error'] = cot::$L['subscribe_err_subscriber_not_found']; echo json_encode($ret); exit; } } else { $subscriber = new subscribe_model_Subscriber(); } if (!empty($_POST['email'])) { $_POST['email'] = mb_strtolower($_POST['email']); } $subscriber->setData($_POST); $error = array(); $subscr = null; $tmp = $subscriber->rawValue('subscribe'); if (empty($tmp)) { $error[] = cot::$L['field_required'] . ': ' . cot::$L['subscribe_subscribe']; } else { $subscr = subscribe_model_Subscribe::getById($subscriber->rawValue('subscribe')); if (!$subscr) { $error[] = cot::$L['subscribe_err_not_found']; } } $user = null; if (!empty($subscriber->user)) { $user = cot_user_data($subscriber->user); // Если получили данные пользователя, то e-mail всегда берем из профиля if (isset($user['user_email'])) { $subscriber->email = mb_strtolower($user['user_email']); } } if (empty($subscriber->email)) { $error[] = cot::$L['field_required'] . ': ' . cot::$L['Email']; } else { $tmp = subscribe_checkEmail($subscriber->email); if ($tmp !== true) { $error[] = $tmp; } if ($subscriber->rawValue('subscribe') > 0) { if (!empty($subscr)) { $cond = array(array('email', $subscriber->email), array('subscribe', $subscr->id)); if ($subscriber->id > 0) { $cond[] = array('id', $subscriber->id, '<>'); } $cnt = subscribe_model_Subscriber::count($cond); if ($cnt > 0) { $error[] = sprintf(cot::$L['subscribe_err_user_subscribed'], $subscriber->email, htmlspecialchars($subscr->title)); } } } } if (!empty($error)) { $ret['error'] = implode('<br />', $error); echo json_encode($ret); exit; } if (empty($subscriber->name) && (!empty($subscriber->email) || !empty($user))) { if (!empty($user)) { $subscriber->name = cot_user_full_name($user); } else { $sql = cot::$db->query("SELECT * FROM {$db_users} WHERE user_email = ? LIMIT 1", $subscriber->email); $user = $sql->fetch(); if (!empty($user)) { $subscriber->name = cot_user_full_name($user); if (empty($subscriber->user)) { $subscriber->user = $user['user_id']; } } } } // Админ при сохранении подтверждает e-mail if (!$subscriber->email_valid && (empty($subscriber->id) || $subscriber->active)) { $subscriber->email_valid = 1; $subscriber->email_valid_date = date('Y-m-d H:i:s', cot::$sys['now']); } // Сохранение $subscriber->save(); cot_message(cot::$L['Saved']); echo json_encode($ret); exit; }
/** * Пользователь - Владелец объявления * @return array */ public function getOwner() { if (is_null($this->_owner)) { if ($this->_data['user'] > 0) { $this->_owner = cot_user_data($this->_data['created_by']); if (empty($this->_owner)) { $this->_owner = array('user_id' => null, 'user_maingrp' => 1, 'user_name' => cot::$L['Deleted'], 'full_name' => cot::$L['Deleted'], 'user_avatar' => ''); } else { $this->_owner['full_name'] = cot_user_full_name($this->_owner); $this->_owner['url'] = cot_url('users', 'm=details&id=' . $this->_owner['user_id'] . '&u=' . htmlspecialchars($this->_owner['user_name'])); } } else { $this->_owner = array('user_id' => 0, 'user_maingrp' => 1, 'user_name' => cot::$L['Guest'], 'full_name' => cot::$L['Guest'], 'user_avatar' => ''); } } return $this->_owner; }