Example #1
0
 /**
  * Generates a banner widget.
  *
  * @param string $tpl
  * @param array|string $cat  Category, semicolon separated
  * @param string $order  'order' OR 'rand'
  * @param int $cnt  Banner count
  * @param int|bool $client
  * @param int|bool $subcats
  * @return string
  *
  */
 public static function banner($cat = '', $cnt = 1, $tpl = 'brs.banner', $order = 'order', $client = false, $subcats = false)
 {
     global $cache_ext;
     $cats = array();
     $client = (int) $client;
     $cnt = (int) $cnt;
     if (!empty($cat)) {
         if (is_array($cat)) {
             $cats = $cat;
         } elseif ($cat != '') {
             $categs = explode(';', $cat);
             if (is_array($categs)) {
                 foreach ($categs as $tmp) {
                     $tmp = trim($tmp);
                     if (empty($tmp)) {
                         continue;
                     }
                     if ($subcats) {
                         // Specific cat
                         //                    var_dump(cot_structure_children('banners', $tmp));
                         $cats = array_merge($cats, cot_structure_children('brs', $tmp, true, true, false, false));
                     } else {
                         $cats[] = $tmp;
                     }
                 }
             }
             $cats = array_unique($cats);
         }
     }
     $nullDate = date('Y-m-d H:i:s', 0);
     // 1970-01-01 00:00:00
     $condition = array(array('published', 1), array('publish_up', date('Y-m-d H:i:s', cot::$sys['now']), '<='), array('SQL', "publish_down >='" . date('Y-m-d H:i:s', cot::$sys['now']) . "' OR publish_down ='{$nullDate}'"), array('SQL', "imptotal = 0 OR impressions < imptotal"));
     if (count($cats) > 0) {
         $condition[] = array('category', $cats);
     }
     if ($client) {
         $condition[] = array('client', $client);
     }
     $ord = "lastimp ASC";
     if ($order == 'rand') {
         $ord = 'RAND()';
     }
     $items = brs_model_Banner::find($condition, $cnt, 0, $ord);
     if (!$items) {
         return '';
     }
     // Display the items
     $t = new XTemplate(cot_tplfile($tpl, 'plug'));
     foreach ($items as $itemRow) {
         // Если включено кеширование и это незарег не засчитываем показ. Баннер будет запрошен аяксом
         if (!(!empty($cache_ext) && cot::$usr['id'] == 0 && cot::$cfg['cache_' . $cache_ext])) {
             $itemRow->impress();
         }
         self::$count++;
         // Порядковый номер баннера на странице
         $itemRow->number = self::$count;
     }
     $view = new View();
     $view->items = $items;
     $view->order = $order;
     $view->client = $client;
     return $view->render($tpl);
 }
Example #2
0
 /**
  * Панель управления
  * Список баннеров
  */
 public function indexAction()
 {
     global $admintitle, $adminpath;
     $admintitle = cot::$L['brs_banners'];
     $adminpath[] = array(cot_url('admin', array('m' => 'brs')), cot::$L['brs_banners']);
     $sortFields = array('id' => 'ID', 'title' => cot::$L['Title'], 'category' => cot::$L['Category'], 'published' => cot::$L['brs_published'], 'client' => cot::$L['brs_client'], 'impressions' => cot::$L['brs_impressions'], 'clicks' => cot::$L['brs_clicks'], 'publish_up' => cot::$L['brs_publish_up'], 'publish_down' => cot::$L['brs_publish_down']);
     $sort = cot_import('s', 'G', 'ALP');
     // order field name
     $way = cot_import('w', 'G', 'ALP', 4);
     // order way (asc, desc)
     $f = cot_import('f', 'G', 'ARR');
     // filters
     $maxrowsperpage = cot::$cfg['maxrowsperpage'];
     if ($maxrowsperpage < 1) {
         $maxrowsperpage = 1;
     }
     list($pg, $d, $durl) = cot_import_pagenav('d', $maxrowsperpage);
     //page number for banners list
     $sort = empty($sort) ? 'title' : $sort;
     $way = empty($way) || !in_array($way, array('asc', 'desc')) ? 'asc' : $way;
     $urlParams = array('m' => 'brs');
     if ($sort != 'title') {
         $urlParams['s'] = $sort;
     }
     if ($way != 'asc') {
         $urlParams['w'] = $way;
     }
     $condition = array();
     if (!empty($f)) {
         foreach ($f as $key => $val) {
             $val = trim(cot_import($val, 'D', 'TXT'));
             if (empty($val) && $val !== '0') {
                 continue;
             }
             if (in_array($key, array('title'))) {
                 $condition[] = array($key, "*{$val}*");
                 $urlParams["f[{$key}]"] = $val;
             } else {
                 $condition[] = array($key, $val);
                 $urlParams["f[{$key}]"] = $val;
             }
         }
     } else {
         $f = array();
     }
     $totallines = brs_model_Banner::count($condition);
     $items = brs_model_Banner::find($condition, $maxrowsperpage, $d, $sort . ' ' . $way);
     $pagenav = cot_pagenav('admin', $urlParams, $d, $totallines, $maxrowsperpage, 'd', '', true);
     $template = array('brs', 'admin', 'list');
     $clients = brs_model_Client::keyValPairs();
     if (!$clients) {
         $clients = array();
     }
     $filterForm = array('hidden' => '', 'title' => array('element' => cot_inputbox('text', 'f[title]', $f['title']), 'label' => brs_model_Banner::fieldLabel('title')), 'category' => array('element' => brs_selectbox_structure('brs', $f['category'], 'f[category]', '', false, false, true), 'label' => brs_model_Banner::fieldLabel('category')), 'client' => array('element' => cot_selectbox($f['client'], 'f[client]', array_keys($clients), array_values($clients)), 'label' => brs_model_Banner::fieldLabel('client')), 'published' => array('element' => cot_selectbox($f['published'], 'f[published]', array(0, 1), array(cot::$L['No'], cot::$L['Yes'])), 'label' => brs_model_Banner::fieldLabel('published')), 'sort' => array('element' => cot_selectbox($sort, 's', array_keys($sortFields), array_values($sortFields), false), 'label' => cot::$L['adm_sort']), 'way' => array('element' => cot_selectbox($way, 'w', array('asc', 'desc'), array(cot::$L['Ascending'], cot::$L['Descending']), false)));
     if (isset(cot::$cfg['plugin']['urleditor']) && cot::$cfg['plugin']['urleditor']['preset'] != 'handy') {
         $filterForm['hidden'] .= cot_inputbox('hidden', 'm', 'brs');
     }
     $view = new View();
     $view->page_title = $admintitle;
     $view->fistNumber = $d + 1;
     $view->items = $items;
     $view->clients = $clients;
     $view->totalitems = $totallines;
     $view->filterForm = $filterForm;
     $view->pagenav = $pagenav;
     //        $view->addNewUrl = $addNewUrl;
     $view->urlParams = $urlParams;
     $view->filter = $f;
     /* === Hook === */
     foreach (cot_getextplugins('brs.admin.list.view') as $pl) {
         include $pl;
     }
     /* ===== */
     return $view->render($template);
 }