/** * Отправка описания выбранной категории в формате JSON. * */ public function ajax_get_category_details() { $categoryDetails = new stdClass(); $categoryDetails->id_category = 0; $categoryDetails->sites_in_cat = 0; $categoryDetails->sites_in_cat_and_subcat = 0; try { $categoryId = $this->input->post('id_category'); if (false === $categoryId) { throw new Sppc_Exception('Category not specified'); } $categoryModel = new Sppc_CategoryModel(); $category = $categoryModel->findObjectById($categoryId); if (is_null($category)) { throw new Sppc_Exception('Specified category not found'); } $categoryDetails->id_category = $category->getId(); $categoryDetails->description = $category->getDescription(); $siteModel = new Sppc_SiteModel(); $searchFilter = new Sppc_Site_SearchFilter(); $searchFilter->setHasCpc(true)->setCategories($category); $categoryDetails->sites_in_cat = $siteModel->getCount($searchFilter); $categories = array($category); $childs = $category->getChildCategories(true); $categories = array_merge($categories, $childs); $searchFilter->setCategories($categories); $categoryDetails->sites_in_cat_and_subcat = $siteModel->getCount($searchFilter); echo json_encode(array('message' => 'OK', 'category_details' => $categoryDetails)); } catch (Exception $e) { echo json_encode(array('message' => $e->getMessage(), 'category_details' => $categoryDetails)); } }
public function index($site_code = NULL) { $error_flag = false; $error_message = ''; if (is_null($site_code)) { $error_flag = true; $error_message = __('Site is not found'); } if (!$error_flag) { $id_site = type_cast($site_code, 'textcode'); $this->load->model('site'); $site_info = $this->site->get_list(array('fields' => 'sites.name, sites.url, SUM(stat_sites.impressions) as impressions, ' . 'UNIX_TIMESTAMP(sites.creation_date) as creation_date, site_categories.id_category as id_category, ' . 'sites.description', 'site_id_filter' => array($id_site), 'joinCategories' => true)); try { if (is_null($site_info)) { throw new Exception('Site was not found'); } $siteModel = new Sppc_SiteModel(); $site = $siteModel->findObjectById($id_site); if (is_null($site)) { throw new Exception('Site was not found'); } try { $siteLayoutModel = new Sppc_Site_LayoutModel(); $siteLayout = $siteLayoutModel->findBySite($site); if (is_null($siteLayout)) { throw new Exception('layout is not found'); } $jsonLayout = $siteLayout->toString(); //die($jsonLayout); //$this->_add_java_script_inline( "var siteLayoutJson='{$jsonLayout}';" ); $this->content['JSCODE'] = "siteLayoutJson='{$jsonLayout}';"; } catch (Exception $e) { //$this->_add_java_script_inline( "var siteLayoutJson='';" ); $this->content['JSCODE'] = "siteLayoutJson='';"; } } catch (Exception $e) { $error_flag = true; $error_message = __('Site is not found'); } } if ($error_flag) { $data = array('MESSAGE' => __($error_message), 'REDIRECT' => $this->site_url . $this->index_page . $this->role . '/site_directory'); $content = $this->parser->parse('common/errorbox.html', $data, FALSE); $this->_set_content($content); $this->_display(); return; } $site_info = $site_info[0]; $this->load->model('category_model', 'category'); $category_list = $this->category->get_list_by_site($id_site); $this->load->model('channel'); $channels_list = $this->channel->get_list(array('fields' => 'channels.id_channel as channel_code, channels.name as channel_name', 'show_deleted_in_site_channels' => false, 'hide_wo_programs' => true, 'site_id_filter' => $id_site)); if (is_null($channels_list)) { $channels_list = array(); } foreach ($channels_list as &$channel) { $channel['id_channel'] = $channel['channel_code']; $channel['channel_code'] = type_to_str($channel['channel_code'], 'textcode'); } $channels_list = array_merge($channels_list, $this->plugins->run('get_channels', $this)); $rank_script = "http://xslt.alexa.com/site_stats/js/s/a?url={$site_info['url']}"; $vars = array('SITE_VIEWS_COUNT' => type_to_str($site_info['impressions'], 'impressions'), 'SITE_CREATION_DATE' => type_to_str($site_info['creation_date'], 'date'), 'SITE_CATEGORY' => implode(', ', $category_list), 'SITE_DESCRIPTION' => nl2br(type_to_str($site_info['description'], 'encode')), 'SITE_DESTINATION_URL' => $site_info['url'], 'SITE_TITLE' => type_to_str($site_info['name'], 'encode'), 'SITE_CODE' => $site_code, 'SITE_CHANNELS_LIST' => json_encode($channels_list), 'IMAGE' => $this->site->get_thumb($id_site), 'SITE_ALEXA_RANK' => $rank_script, 'ROLE' => $this->role); $this->_set_content($this->parser->parse("common/site_directory/site_information/template.html", $vars, TRUE)); $this->_display(); }
public function _validator($fields) { $trimmed_url = trim($fields['domain']); if ($trimmed_url != '') { $siteModel = new Sppc_SiteModel(); $site = $siteModel->findByUrl($trimmed_url); $check = false; if (is_null($this->_site)) { $check = true; } elseif (!is_null($site)) { $check = $site->getId() != $this->_site->getId(); } if (!is_null($site) && $check) { $this->validation->domain_error = "<p class='errorP'>" . __("Site with such URL is already exists") . ".</p>"; return FALSE; } } return TRUE; }
public function update($id, $params, $id_entity = -1) { $jsonLayout = $params['layout_json']; unset($params['layout_json']); if (isset($params['url'])) { if (!$this->check_unique_url($params['url'], $id)) { return "Site with such URL is already exists"; } } $this->db->where(array($this->_id_field_name => $id, 'id_entity_publisher' => $id_entity))->update($this->_table_name, $params); ////////////////////////////////////////// // Register layout try { $siteModel = new Sppc_SiteModel(); $site = $siteModel->findObjectById($id); if (is_null($site)) { throw new Exception('Site was not found'); } $siteLayoutModel = new Sppc_Site_LayoutModel(); $siteLayoutModel->updateFromJson($site, $jsonLayout); } catch (Exception $e) { } ////////////////////////////////////////// return ""; }
public function _save($idSite, $fields) { try { if (isset($fields['layout_json'])) { $siteModel = new Sppc_SiteModel(); $site = $siteModel->findObjectById($idSite); $siteLayoutModel = new Sppc_Site_LayoutModel(); $siteLayoutModel->updateFromJson($site, $fields['layout_json']); } } catch (Exception $e) { $this->_set_notification('There is an error while saving your site data:' . $e->getMessage(), 'error'); return $e->getMessage(); } $this->_set_notification('Site layout was saved', 'notification', true); return ''; }
/** * Создание сайта * * @param array $fields параметры создаваемого канала * @return string описание ошибки ('' при успешном создании) */ public function _create($fields) { try { if ('' == $fields['format']) { throw new Sppc_Exception('Channel dimension is not selected'); } // check channel ad type $channelAdTypes = array(); if ($fields['ad_type_text']) { $channelAdTypes[] = Sppc_Channel::AD_TYPE_TEXT; } if ($fields['ad_type_image']) { $channelAdTypes[] = Sppc_Channel::AD_TYPE_IMAGE; } if (count($channelAdTypes) == 0) { throw new Sppc_Exception('At least one ad type must be selected'); } // channel ad sources if ($this->role == 'admin') { $channelAdSources = array(); if ($fields['ad_sources_advertisers'] == true) { $channelAdSources[] = Sppc_Channel::AD_SOURCE_ADVERTISERS; } if ($fields['ad_sources_xml_feeds'] == true) { $channelAdSources[] = Sppc_Channel::AD_SOURCE_XMLFEEDS; } } else { $channelAdSources = array(Sppc_Channel::AD_SOURCE_ADVERTISERS, Sppc_Channel::AD_SOURCE_XMLFEEDS); } if (count($channelAdSources) == 0) { throw new Sppc_Exception('At least one ad source must be selected'); } if (empty($fields['channel_type'])) { $fields['channel_type'] = 'contextual'; } $parentSite = null; if (isset($fields['id_site'])) { $siteModel = new Sppc_SiteModel(); $parentSite = $siteModel->findObjectById($fields['id_site']); } $dimensionModel = new Sppc_DimensionModel(); $dimension = $dimensionModel->findObjectById($fields['format']); $channelModel = new Sppc_ChannelModel(); $channel = $channelModel->createRow(); $channel->setName(trim($fields['name'])); $channel->setDescription(trim($fields['description'])); if ($fields['category'] != $parentSite->getCategory()) { $categoryModel = new Sppc_CategoryModel(); $categories = $categoryModel->find(explode(',', $fields['category'])); $channel->setCategories($categories); } $channel->setDimension($dimension); $channel->setAdTypes($channelAdTypes); $channel->setAdSettings($fields['ad_settings']); if ($fields['ad_settings'] == 'blank_color') { $channel->setBlankColor(str_replace('#', '', $fields['blank_color'])); } $channel->setChannelType($fields['channel_type']); $channel->setAdSources($channelAdSources); if (!is_null($parentSite)) { $channel->setParentSite($parentSite); $channel->addSite($parentSite); } $channel->save(); $tagModel = new Sppc_TagModel(); if ($fields["ad_settings"] == 'tag') { $tag = $tagModel->createRow($channel, $fields["tag_code"]); } else { $tag = $tagModel->createRow($channel, ''); } $tag->save(); // Сохраняем айдишник в сессию $this->session->set_userdata(get_class($this) . '_id_channel', $channel->getId()); } catch (Exception $e) { return __($e->getMessage()); } return false; }