Ejemplo n.º 1
0
 function afterGet($item)
 {
     $item['avatar_small'] = null;
     if (!empty($item['avatar'])) {
         if ($this->dsp->eis->isEisUrl($item['avatar'])) {
             list($w, $h) = _isMobile() ? array(40, 40) : array(49, 49);
             $item['avatar'] = $this->dsp->eis->Resize($item['avatar'], $w, $h, 'crop');
             $item['avatar_small'] = $this->dsp->eis->Resize($item['avatar'], 21, 21, 'crop');
         } else {
             $item['avatar_small'] = $item['avatar'];
         }
     }
     return $item;
 }
Ejemplo n.º 2
0
 function runBlocks($layout = 1, $typeservice = 1, $itemid = 0, $vars = array())
 {
     $arr = $this->getBlocksArr($layout, $typeservice, $itemid, $vars);
     $exclusions = array();
     foreach ($arr as $i => $block) {
         if ($block['exclusion'] == 1 && ($block['layout_id'] == $layout || $block['layout_id'] == 0)) {
             $exclusions[$block['id']] = true;
         }
         if (isset($exclusions[$block['id']])) {
             continue;
         }
         $bid = $block['id'];
         $name = $block['title'];
         $name_admin = $block['name_admin'];
         $class = $block['class_name'];
         $method = $block['params'];
         $cached = $block['cached'];
         $timeout = $block['timeout'];
         $place = $block['place_id'];
         $layout = $block['layout_id'];
         $order = $block['order'];
         $type = !empty($block['type']) ? $block['type'] : 1;
         $cache_key = '';
         $st = microtime(true);
         if ($type == 1) {
             if (empty($class)) {
                 continue;
             }
             if (gettype($this->dsp->{$class}) != 'object') {
                 continue;
             }
             if (!method_exists($this->dsp->{$class}, $method)) {
                 continue;
             }
             $articles_ids = array();
             $r = array();
             // хак для уникальности кеша у каждого блока
             $vars['temp_block_id'] = $bid;
             $vars['blocks_ids'] = array();
             // mannuals
             $manuals = array();
             $multi_service = FALSE;
             //проверка есть ли ручной вывод в блоке и добавленные в него элементы
             $sql = 'SELECT
                                             a.id AS id, a.service, b.multi_service, a.block_manual_id
                                     FROM blocks_manual AS b, blocks_manual_items AS a, blocks AS bl
                                     WHERE
                                             ' . ($layout ? ' ( b.layout_id = ' . $layout . ' or b.layout_id = 0 ) AND ' : '') . ($typeservice ? ' ( b.service_id = ' . $typeservice . ' or b.service_id = 29 ) AND ' : '') . ($itemid ? ' ( b.item_id = ' . $itemid . ' or b.item_id = 0 ) AND ' : '') . 'b.block_id = ? AND
                                              b.id = a.block_manual_id AND
                                              b.block_id = bl.blocks_id
                                     ORDER BY a.position ASC, a.date DESC limit 10';
             $items = $this->dsp->db->Select($sql, $bid);
             foreach ($items as $item) {
                 if (!isset($manuals[$item['service']])) {
                     $manuals[$item['service']] = array();
                 }
                 $manuals[$item['service']][] = $item['id'];
                 if ($item['multi_service']) {
                     $multi_service = TRUE;
                 }
                 $vars['blocks_ids'][$item['service']] = $item['block_manual_id'];
             }
             $vars['manual'] = is_array($manuals) && count($manuals) > 0 ? $multi_service ? $manuals : reset($manuals) : array();
             // end manuals
             $no_block_cache = 0;
             if (!empty($_REQUEST['no_cache_id']) && $_REQUEST['no_cache_id'] == $bid) {
                 $no_block_cache = 1;
             }
             if ($cached && empty($vars['go_dynamic']) && !$no_block_cache) {
                 if (_isMobile()) {
                     $vars['mobile_version'] = 1;
                 }
                 $r = $this->dsp->cache->go(array($this->dsp->{$class}, $method), array($vars), $timeout);
                 $cache_key = $r['key'];
                 $r = $r['data'];
             } else {
                 //выполнение метода класса, указанного в развеске
                 $result = $this->dsp->{$class}->{$method}($vars);
                 //слияние полученных массивов
                 if (count($r) > 0 && count($result) > 0) {
                     $r = array_merge($r, $result);
                 } elseif (count($result) > 0) {
                     $r = $result;
                 }
                 unset($vars['temp_block_id']);
                 if (isset($vars['count'])) {
                     unset($vars['count']);
                 }
                 if (isset($vars['manual'])) {
                     unset($vars['manual']);
                 }
             }
             if ($r === false) {
                 continue;
             }
         } elseif ($type == 2) {
             // Add Google Analytics (GA) attribute
             $method = preg_replace('~^<div~i', '<div data-ga="' . $bid . '"', trim($method));
             $r = array('data' => $method);
         }
         $et = microtime(true);
         $time = number_format($et - $st, 6);
         //list($int, $dec) = explode('.', $time);
         //$time = number_format($time, strlen($dec));
         //$dec = round( $dec );
         //$time = $int . '.' . $dec;
         $this->dsp->_Builder->addArray((array) $r, $tag = 'block', $extra_attrs = array('id' => $bid, 'type' => $type, 'name' => $name, 'name_admin' => $name_admin, 'place' => $place, 'layout' => $layout, 'order' => $order, 'debug' => Param('_blocks') ? 'on' : (Param('_sblocks') ? 'short' : 'off'), 'cached' => $cached, 'cahe_timeout' => $timeout, 'time' => $time, 'cashed' => $cached, 'cache_key' => $cache_key), $node = '', $asItems = false, $attrs = array());
     }
 }