/** * Сборщик мусора */ protected function garbageCollect() { // Удаление старых неподтвержденных подписчиков $delDate = new DateTime(); // 1 неделя $delDate->sub(new DateInterval('P1W')); $items = subscribe_model_Subscriber::find(array(array('email_valid', 0), array('created', $delDate->format('Y-m-d H:i:s'), '<='))); if (!empty($items)) { foreach ($items as $itemRow) { $itemRow->delete(); } } }
protected function beforeDelete() { // Удалить всех подписчиков $items = subscribe_model_Subscriber::find(array(array('subscribe', $this->_data['id']))); if (!empty($items)) { foreach ($items as $itemRow) { $itemRow->delete(); } } return parent::beforeDelete(); }
/** * Подтверждение подписки на рассылку */ public function confirmAction() { $code = cot_import('code', 'G', 'TXT'); if (!$code) { cot_die_message('404'); } $title = cot::$L['subscribe_confirm']; $subscriber = subscribe_model_Subscriber::fetchOne(array(array('unsubscr_code', $code))); if (!$subscriber) { cot_error(cot::$L['subscribe_err_wrong_confirm_code']); } cot::$sys['sublocation'] = $title; cot::$out['subtitle'] = $title; if ($subscriber) { if (!$subscriber->subscribe->active) { cot_error(cot::$L['subscribe_err_disabled']); } $title .= ': ' . $subscriber->subscribe->title; cot::$sys['sublocation'] = $title; cot::$out['subtitle'] = $title; $allItems = subscribe_model_Subscriber::find(array(array('email', $subscriber->email), array('email_valid', 0), array('id', $subscriber->id, '<>'))); if ($allItems) { foreach ($allItems as $itemRow) { $itemRow->active = 1; $itemRow->email_valid = 1; $itemRow->email_valid_date = date('Y-m-d H:i:s', cot::$sys['now']); $itemRow->save(); } unset($allItems); } $subscriber->active = 1; $subscriber->email_valid = 1; $subscriber->email_valid_date = date('Y-m-d H:i:s', cot::$sys['now']); $subscriber->save(); cot_message(sprintf(cot::$L['subscribe_confirmed'], $subscriber->email, $subscriber->subscribe->title)); } $template = array('subscribe', 'confirm'); $view = new View(); $view->page_title = $title; $view->subscriber = $subscriber; /* === Hook === */ foreach (cot_getextplugins('subscribe.confirm.view') as $pl) { include $pl; } /* ===== */ return $view->render($template); }
/** * Список рассылок */ public function indexAction() { $maxrowsperpage = cot::$cfg['maxrowsperpage']; if ($maxrowsperpage < 1) { $maxrowsperpage = 1; } list($pg, $d, $durl) = cot_import_pagenav('d', $maxrowsperpage); //page number for pages list $sort = 'title'; $way = 'asc'; /* === Hook === */ foreach (cot_getextplugins('subscribe.list.first') as $pl) { include $pl; } /* ===== */ $urlParams = array(); $canonicalUrlParams = array(); if ($durl > 1) { $canonicalUrlParams['d'] = $durl; } $where = array(); cot::$out['subtitle'] = $title = cot::$L['subscribe_subscribes']; // Building the canonical URL cot::$out['canonical_uri'] = cot_url('subscribe', $canonicalUrlParams); $condition = array(array('active', 1), array('periodical', 1)); $order = array(array('active', 'desc'), array($sort, $way)); $userSubscribesCondition = array(); if (cot::$usr['id'] > 0) { $userSubscribesCondition[] = array('active', 1); $userSubscribesCondition[] = array('user', cot::$usr['id']); if (!empty(cot::$usr['profile']['user_email'])) { //$userSubscribesCondition[] = array('email', cot::$usr['profile']['user_email'], '=', 'OR'); $userSubscribesCondition = array(array('SQL', 'active=1 AND (user='******'id'] . ' OR email=' . cot::$db->quote(cot::$usr['profile']['user_email']) . ')')); } } /* === Hook === */ foreach (cot_getextplugins('subscribe.list.query') as $pl) { include $pl; } /* ===== */ $totallines = subscribe_model_Subscribe::count($condition); $items = null; if ($totallines > 0) { $items = subscribe_model_Subscribe::find($condition, $maxrowsperpage, $d, $order); } // Подписки пользователя $userSubscribes = null; $userSubscribesIds = array(); if (!empty($items)) { if (cot::$usr['id'] > 0) { $userSubscribes = subscribe_model_Subscriber::find($userSubscribesCondition, 0, 0, array(array('active', 'desc'))); if (!empty($userSubscribes)) { foreach ($userSubscribes as $usRow) { $userSubscribesIds[] = $usRow->rawValue('subscribe'); } } } } /* === Hook === */ foreach (cot_getextplugins('subscribe.list.main') as $pl) { include $pl; } /* ===== */ if (cot::$usr['id'] > 0) { Resources::linkFileFooter(cot::$cfg['modules_dir'] . '/subscribe/js/subscriber.js'); } $crumbs = array(cot::$L['subscribe_subscribes']); $pagenav = cot_pagenav('subscribe', $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('subscribe', 'list'); // $pageUrlParams = $urlParams; // if($durl > 1) $pageUrlParams['d'] = $durl; $view = new View(); $view->breadcrumbs = $breadcrumbs; $view->page_title = htmlspecialchars($title); $view->items = $items; $view->userSubscribes = $userSubscribes; $view->userSubscribesIds = $userSubscribesIds; $view->totalitems = $totallines; $view->pagenav = $pagenav; $view->urlParams = $urlParams; // $view->pageUrlParams = $pageUrlParams; /* === Hook === */ foreach (cot_getextplugins('subscribe.list.view') as $pl) { include $pl; } /* ===== */ return $view->render($template); }
/** * Список рассылок * @return string * @throws Exception */ public function indexAction() { global $admintitle, $adminpath, $Ls; $admintitle = cot::$L['subscribe_subscribers']; $adminpath[] = array(cot_url('admin', array('m' => 'subscribe', 'n' => 'user')), $admintitle); $sort = cot_import('s', 'G', 'ALP'); // order field name $way = cot_import('w', 'G', 'ALP', 4); // order way (asc, desc) $maxrowsperpage = cot::$cfg['maxrowsperpage']; if ($maxrowsperpage < 1) { $maxrowsperpage = 1; } list($pg, $d, $durl) = cot_import_pagenav('d', $maxrowsperpage); //page number for pages list /* === Hook === */ foreach (cot_getextplugins('subscribe.admin.subscriber.list.first') as $pl) { include $pl; } /* ===== */ $sort = empty($sort) ? 'email' : $sort; $way = empty($way) || !in_array($way, array('asc', 'desc')) ? 'asc' : $way; $urlParams = array('m' => 'subscribe', 'n' => 'user'); if ($sort != 'email') { $urlParams['s'] = $sort; } if ($way != 'asc') { $urlParams['w'] = $way; } $where = array(); $states = array(-1 => cot::$R['code_option_empty'], 0 => cot::$L['Disabled'], 1 => cot::$L['Enabled']); // Фильтры $allowedFilters = array('id', 'sid', 'name', 'email', 'active'); $f = cot_import('f', 'G', 'ARR'); $filterForm = array('hidden' => ''); if (!empty($f)) { foreach ($f as $key => $val) { if (!in_array($key, $allowedFilters)) { unset($f[$key]); } } if (!empty($f['id'])) { $where['id'] = array('id', $f['id']); $urlParams['f[id]'] = $f['id']; } if (!empty($f['sid'])) { $where['sid'] = array('subscribe', $f['sid']); $urlParams['f[sid]'] = $f['sid']; } $f['active'] = isset($_GET['f']['active']) ? cot_import($_GET['f']['active'], 'D', 'INT') : -2; if ($f['active'] == -1) { unset($where['active']); } elseif ($f['active'] >= 0 && $f['active'] < 2) { $where['active'] = array('active', $f['active']); $urlParams['f[active]'] = $f['active']; } if (!empty($f['name'])) { $where['name'] = array('name', '*' . $f['name'] . '*'); $urlParams['f[name]'] = $f['name']; } if (!empty($f['email'])) { $where['email'] = array('email', '*' . $f['email'] . '*'); $urlParams['f[email]'] = $f['email']; } } if (isset(cot::$cfg['plugin']['urleditor']) && cot::$cfg['plugin']['urleditor']['preset'] != 'handy') { $filterForm['hidden'] .= cot_inputbox('hidden', 'm', 'subscribe'); } $filterForm['hidden'] .= cot_inputbox('hidden', 'n', 'user'); $condition = array(); foreach ($where as $key => $val) { $condition[] = $val; } $order = array(array($sort, $way)); /* === Hook === */ foreach (cot_getextplugins('subscribe.admin.subscriber.list.query') as $pl) { include $pl; } /* ===== */ $totallines = subscribe_model_Subscriber::count($condition); $items = null; if ($totallines > 0) { $items = subscribe_model_Subscriber::find($condition, $maxrowsperpage, $d, $order); } // Если передан номер страницы превышающий максимальный if (empty($items) && $totallines > 0 && $pg > 1) { $totalpages = ceil($totallines / $maxrowsperpage); $args = $urlParams; if ($totalpages > 1) { if (cot::$cfg['easypagenav']) { $args['d'] = $totalpages; } else { $args['d'] = ($totalpages - 1) * $maxrowsperpage; } } cot_redirect(cot_url('admin', $args, '', true)); } //$addNewUrl = cot_url('admin', array('m'=>'subscribe','a' => 'edit')); /* === Hook === */ foreach (cot_getextplugins('subscribe.admin.subscriber.list.main') as $pl) { include $pl; } /* ===== */ $pagenav = cot_pagenav('admin', $urlParams, $d, $totallines, $maxrowsperpage, 'd', '', true); if (empty($pagenav['current'])) { $pagenav['current'] = 1; } $pagenav['page'] = $pagenav['current']; if (!cot::$cfg['easypagenav']) { $pagenav['page'] = ($pagenav['current'] - 1) * $maxrowsperpage; } $subscribes = subscribe_model_Subscribe::keyValPairs(); Resources::linkFileFooter(cot::$cfg['modules_dir'] . '/subscribe/js/admin.subscriber.js'); $template = array('subscribe', 'admin', 'subscriber', 'list'); $view = new View(); $view->page_title = $admintitle; $view->fistNumber = $d + 1; $view->items = $items; $view->totalitems = $totallines; $view->pagenav = $pagenav; $view->subscribes = $subscribes; $view->urlParams = $urlParams; $view->filter = $f; $view->filterForm = $filterForm; $view->states = $states; /* === Hook === */ foreach (cot_getextplugins('subscribe.admin.subscriber.list.view') as $pl) { include $pl; } /* ===== */ return $view->render($template); }