/** * Процесс клика * */ public function click() { // Получаем данные клика $click_data = Sppc_Stats_Utils::extractClickId($this->clickid); if ($click_data == false) { // Вылетели по ошибке невозможности прочтения данных клика $this->error = 'click_data_error'; $this->result = Sppc_Protection::DENY; return false; } // Устанавливаем урл для редиректа $this->url = $click_data['destination_url']; // Статистика... if ($click_data['id_feed'] == 0) { $this->obj->load->model('stat'); $add_data = $this->obj->stat->get_click_info($click_data['id_ad'], $click_data['id_group_site_channel'], $click_data['id_channel']); if ($add_data != false) { foreach ($add_data as $key => $value) { $click_data[$key] = $add_data[$key]; } } else { return false; } } $click_data['clicks'] = 1; if ($this->firephp) { $this->firephp->log($click_data, 'Click data'); } // register click $this->registerStat(array($click_data)); return true; }
/** * Метод по умолчанию * */ public function index() { $this->noCache(); $this->load->model('global_variables'); // Создаем объект поиска $this->load->library('search_builder'); $this->search_builder->setSite($this->id_site); $this->search_builder->setChannel($this->id_channel); $this->search_builder->setReferer($this->referer); $this->search_builder->setRealReferer($this->real_referer); $this->search_builder->setSearchType('js'); $this->search_builder->setUseFlash(0 != $this->use_flash ? true : false); $this->search_builder->loadParameters(); // Запускаем процесс поиска $site = $this->search_builder->getSiteInfo(); $channel = $this->search_builder->getChannelInfo(); // Выводим $next_page = true; $data = array(); $view = ''; if (null !== $channel && null !== $site) { $results = array(); $this->load->model('entity'); // $user_status = $this->entity->get_role_status($this->id_user, 'publisher'); // if ('active' == $user_status) { $user_status = false; $roles = $this->entity->get_roles($this->id_user); if (in_array2(array('admin', 'publisher'), $roles)) { $user_status = true; $dimension = $this->getDimension($channel->id_dimension); if ($this->search_builder->search()) { // Получаем результаты $results = $this->search_builder->getResults(); } // Получаем код ошибки $error = $this->search_builder->getLastError(); } if ('active' != $user_status) { $view = 'show_ads/error.html'; $data = array('error' => __('Publisher has been blocked or deleted'), 'width' => $this->width - 2, 'height' => $this->height - 2); } elseif (0 < count($results)) { // Выводим объявления if (Search_builder::TYPE_TEXT == $this->search_builder->getAdType()) { $this->prepareResults($results); // Подгружаем данные по палитре $palette = $this->getPalette(); $data = $palette; $view = 'show_ads/' . $channel->width . 'x' . $channel->height . '.html'; $data['results'] = $results; $data['width'] = $channel->width - 2; $data['height'] = $channel->height - 2; $data['item_width'] = floor(($channel->width - 2) / $channel->max_ad_slots); $data['item_height'] = floor(($channel->height - 2) / count($results)); $data['rows_count'] = $dimension['rows_count']; $data['columns_count'] = $dimension['columns_count']; } elseif (Search_builder::TYPE_IMAGE == $this->search_builder->getAdType()) { $view = 'show_ads/image.html'; $data = current($results); $data['width'] = $channel->width; $data['height'] = $channel->height; $data['results'] = $results; } elseif (Search_builder::TYPE_FLASH == $this->search_builder->getAdType()) { $view = 'show_ads/flash.html'; $data = current($results); $data['width'] = $channel->width; $data['height'] = $channel->height; $data['loader'] = 'loader_u_' . $channel->width . 'x' . $channel->height . '.swf'; $data['click_url'] = urlencode($data['click_url']); $data['results'] = $results; } } elseif ('' == $error || 'protection_fail' == $error || 'targeting' == $error) { // Выводим то, что настроил владелец канала if ('blank' == $channel->ad_settings || 'blank_color' == $channel->ad_settings) { $view = 'show_ads/blank_color.html'; $data['color'] = 'ffffff'; $data['width'] = $channel->width - 2; $data['height'] = $channel->height - 2; if ('blank_color' == $channel->ad_settings) { $data['color'] = $channel->blank_color; } } else { if ('tag' == $channel->ad_settings) { $tag = $this->getTag(); if (!is_null($tag)) { $next_page = false; $view = 'show_ads/js_wrapper.html'; if ($this->is_iframe) { $view = 'show_ads/js_iframe_wrapper.html'; } $data['code'] = $tag->getCode(); } else { $view = 'show_ads/blank_color.html'; $data['color'] = 'ffffff'; $data['width'] = $channel->width - 2; $data['height'] = $channel->height - 2; } } } } } else { $view = 'show_ads/blank_color.html'; $data['color'] = 'ffffff'; $data['width'] = $channel->width - 2; $data['height'] = $channel->height - 2; } $data['base_url'] = base_url(); if (empty($view)) { // Получаем локаль $locale = $this->global_variables->get('Locale', $this->id_user); if (is_null($locale)) { $locale = $this->global_variables->get('DefaultLocale'); } // Подгружаем языковые файлы $this->initTranslate($locale); $view = 'show_ads/error.html'; $data = array('error' => $this->search_builder->getErrorMessage(), 'width' => $this->width - 2, 'height' => $this->height - 2); } if (!empty($view)) { if ($next_page) { // Сохраняем вывод в сессию $id = time() . '_' . md5(uniqid(Sppc_Stats_Utils::makeSeed())); $showYourAdHereLink = $this->global_variables->get('ShowYourAdHereLink'); if ($showYourAdHereLink) { $data['your_ad_here_link'] = array(array('siteurl' => base_url(), 'your_ad_here_link_text' => $this->global_variables->get('YourAdHereLinkText'), 'site_id' => type_to_str($this->id_site, 'textcode'), 'channel_id' => type_to_str($this->id_channel, 'textcode'))); } else { $data['your_ad_here_link'] = array(); } $content = $this->parser->parse($view, $data, true); if (!$this->is_iframe) { // Сохраняем контент в кеш $cache = $this->getCache(); $cache->save($content, $id); $data = array('id_site' => $this->id_site, 'id_channel' => $this->id_channel, 'width' => $this->width, 'height' => $showYourAdHereLink ? $this->height + 15 : $this->height, 'id' => $id, 'ident' => $this->ident, 'base_url' => base_url()); $view = 'show_ads/iframe_wrapper.html'; $this->output->set_header('Content-Type: text/javascript'); $this->parser->parse($view, $data); } else { $this->output->set_output($content); } return; } if (!$this->is_iframe) { $this->output->set_header('Content-Type: text/javascript'); } $this->parser->parse($view, $data); } }
/** * Получение массива результатов поиска * * @param string $content * @return array */ private function getSearchResults($content) { $this->timers = array(); $result = $this->parseSearchResultsArray($content); $our_db_results = $result->our_db_results; $xml_feeds_results = $result->xml_feeds_results; // $organic_results = $result->organic_results; // Получаем тип ourdatabase объявлений $this->ad_type = self::TYPE_TEXT; if (0 < count($our_db_results)) { // Если нашлись ourdatabase результаты, то смотрим на их тип $result = current($our_db_results); if (array_key_exists('ad_type', $result) && self::TYPE_IMAGE == $result['ad_type']) { if ('true' == $result['is_flash']) { $this->ad_type = self::TYPE_FLASH; } else { $this->ad_type = self::TYPE_IMAGE; } } } if (0 < count($xml_feeds_results)) { // Для xml результатов переопределяем биды foreach ($xml_feeds_results as $offset => &$result) { // Программа для XML фидов - CPC $result['program_type'] = self::PROG_CPC; $result['pre_bid'] = $result['bid']; $result['bid'] = round($result['bid'] * $result['commission'] / 100, Sppc_Pay::PRECISION); } unset($result); } $this->results = array(); if (self::TYPE_TEXT == $this->ad_type) { // Одновременно разбиваем рекламные объявления на программы $prog_results = array(); $primary_program = self::PROG_CPM; $find_primary_program = false; foreach ($our_db_results as $result) { if (!$find_primary_program && $result['program_type'] == self::PROG_CPM) { $primary_program = self::PROG_CPM; $find_primary_program = true; } if (!isset($prog_results[$result['program_type']])) { $prog_results[$result['program_type']] = array(); } array_push($prog_results[$result['program_type']], $result); } // Мержим CPC и сортируем $prog_results[self::PROG_CPC] = $xml_feeds_results; usort($prog_results[self::PROG_CPC], array($this, 'compare_bid')); // Мержим результаты в зависимости от порядка показа программ if (isset($prog_results[self::PROG_FLAT_RATE])) { $this->results = $prog_results[self::PROG_FLAT_RATE]; } if ($primary_program == self::PROG_CPM) { // Сначала показываем CPM, затем CPC if (isset($prog_results[self::PROG_CPM])) { $this->results = array_merge($this->results, $prog_results[self::PROG_CPM]); } if (isset($prog_results[self::PROG_CPC])) { $this->results = array_merge($this->results, $prog_results[self::PROG_CPC]); } } } else { $this->results = $our_db_results; } $this->total_results_count = count($this->results); // Отсекаем лишние результаты if (0 < $this->count) { $offset = $this->count * $this->page; $this->results = array_slice($this->results, $offset, $this->count); } // Для статистики $xml_stats = array(); $ourdatabase_stats = array(); // получаем идентификатор паблишера $currentPublisherId = 1; // Обрабатываем результаты foreach ($this->results as $id => $result) { // Вычисляем биды $bid = $result['bid']; if (self::RESULT_OURDATABASE == $result['feed_params']['sb_type']) { // Наша база if (self::PROG_CPM == $result['program_type']) { $bid = $result['cost'] / 1000; } } $result['bid'] = round($bid, Sppc_Pay::PRECISION); if ($this->enable_stats) { if (self::RESULT_XML == $result['feed_params']['sb_type']) { // Подготавливаем статистику для XML результата $temp = array('id_group_site_channel' => 0, 'id_ad' => 0, 'id_feed' => $result['id_feed'], 'id_channel' => $this->id_channel, 'destination_url' => $result['click_url'], 'spent' => $result['bid']); // Генерируем идентификатор клика $result['clickid'] = Sppc_Stats_Utils::generateClickId($temp); $click_data = array('clickid' => $result['clickid'], 'id_feed' => $result['id_feed'], 'id_publisher' => $currentPublisherId, 'id_site' => $this->id_site, 'id_channel' => $this->id_channel, 'position' => $id + 1, 'click_url' => $result['click_url'], 'bid' => $result['bid']); array_push($xml_stats, $click_data); } elseif (self::RESULT_OURDATABASE == $result['feed_params']['sb_type']) { // Подготавливаем статистику для Ourdatabase результата $temp = array('id_group_site_channel' => $result['id_group_site_channel'], 'id_ad' => $result['id'], 'id_feed' => 0, 'id_channel' => $this->id_channel, 'destination_url' => $result['click_url'], 'spent' => 0); // Генерируем идентификатор клика $result['clickid'] = Sppc_Stats_Utils::generateClickId($temp); $click_data = array('clickid' => $result['clickid'], 'program_type' => $result['program_type'], 'ad_type' => $result['ad_type'], 'id_advertiser' => $result['id_advertiser'], 'id_campaign' => $result['id_campaign'], 'id_group' => $result['id_group'], 'id_group_site_channel' => isset($result['id_group_site_channel']) ? $result['id_group_site_channel'] : 0, 'id_group_site' => isset($result['id_group_site']) ? $result['id_group_site'] : 0, 'id_ad' => $result['id'], 'id_publisher' => $currentPublisherId, 'id_site' => $this->id_site, 'id_channel' => $this->id_channel, 'position' => $id + 1, 'click_url' => $result['click_url'], 'bid' => $result['bid']); array_push($ourdatabase_stats, $click_data); } } // Формируем click_url $result['click_url'] = base_url() . 'click?id=' . $result['clickid']; // Формируем display_url $result['display_url'] = rtrim(preg_replace('~^[a-z]+://~', '', $result['display_url']), '/'); // Формируем filename if (isset($result['filename'])) { $result['filename'] = base_url() . 'files/images/' . $result['filename']; } $this->results[$id] = $result; } if ($this->enable_stats) { $this->setXmlStats($xml_stats); $this->setOurdatabaseStats($ourdatabase_stats); } if ($this->enable_stats && $this->enable_alternative_stats && 0 == count($this->results)) { // Регистрируем alternative impression // Собираем данные для регистрации $click_data = array('id_publisher' => 0 < $this->id_channel ? $this->channel_info->id_publisher : $this->obj->global_variables->get('admin_entity'), 'id_site' => $this->id_site, 'id_channel' => $this->id_channel); $this->setAlternativeImpressionStats($click_data); } if ($this->enable_stats && 0 < count($this->clicks)) { $this->registerStat($this->clicks); } // Группируем результаты (если это нужно) $this->group_results = array(); if ($this->use_group_results) { foreach ($this->results as $result) { $ident = $result['feed_params']['client_file']; if (!isset($this->group_results[$ident])) { $this->group_results[$ident] = $result['feed_params']; $this->group_results[$ident]['data'] = array(); } array_push($this->group_results[$ident]['data'], $result); } $this->group_results = array_values($this->group_results); } return $this->results; }