Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
 /**
  * показывает форму для изменения сайта или его создания
  *
  * @param $id - идентификатор редактируемого сайта, если null - создание сайта
  * @return ничего не возвращает
  */
 public function index($id = null)
 {
     $current_site_info = null;
     $categories_tree = $this->category_model->get_html_tree();
     $id_channel = $this->input->post('id_channel');
     if (!empty($id)) {
         $siteModel = new Sppc_SiteModel();
         $this->_site = $siteModel->findObjectById($id);
         $mode = "modify";
         // Set Site layout
         try {
             if (is_null($this->_site)) {
                 throw new Exception('New site');
             }
             $layoutModel = new Sppc_Site_LayoutModel();
             $layout = $layoutModel->findBySite($this->_site);
             if (is_null($layout)) {
                 throw new Exception('Site without layout');
             }
             $this->_add_java_script_inline("var siteLayoutJson='{$layout->toString()}';", 'siteLayoutJson');
         } catch (Exception $e) {
             $this->_add_java_script_inline("var siteLayoutJson='';", 'siteLayoutJson');
         }
     } else {
         $this->_add_java_script_inline("var siteLayoutJson='';", 'siteLayoutJson');
     }
     if (is_null($this->_site) || $this->user_id != $this->_site->getIdEntityPublisher()) {
         $this->_site = null;
         $mode = "create";
     }
     $form = array("id" => is_null($this->_site) ? '' : $this->_site->getId(), "name" => "site_form", "view" => $this->views_paths['site_form'], "vars" => array('CATEGORIES_TREE' => $categories_tree, 'IMAGE' => $this->site->get_thumb($this->site_id) . "?ac=" . rand(100, 9999999), 'IMAGEPATH' => ltrim($this->config->item('path_to_images'), './')), "fields" => array("domain" => array("display_name" => __("Site URL"), "id_field_type" => "string", "form_field_type" => "text", "validation_rules" => "trim|required|hostname", "max" => 150), "title" => array("display_name" => "Title", "id_field_type" => "string", "form_field_type" => "text", "validation_rules" => "trim|required", "max" => 100), "description" => array("display_name" => __("Description"), "id_field_type" => "string", "form_field_type" => "textarea", "validation_rules" => "trim|required", "max" => 300), "category" => array("display_name" => __("Category"), "id_field_type" => "int", "form_field_type" => "hidden", "validation_rules" => "required"), 'thumb_id' => array('id_field_type' => 'string', 'form_field_type' => 'hidden', 'default' => 'DEFAULT'), 'layout_json' => array('id_field_type' => 'string', 'form_field_type' => 'text')));
     if ($this->input->post('redirect_after_save')) {
         $form['redirect'] = $this->input->post('redirect_after_save');
     }
     switch ($mode) {
         case 'create':
             $form['vars']['FORM_TITLE'] = "Create site";
             $form['vars']['CURRENT_SITE_NAME'] = '';
             $form['vars']['APPLY_BTN_CAPTION'] = "Create";
             if (!array_key_exists('redirect', $form)) {
                 $form['redirect'] = "/" . $this->role . "/edit_site/create_complete";
             }
             if ($id_channel) {
                 $this->load->model('channel');
                 $channel_info = $this->channel->get_info($id_channel);
                 $form['vars']['FORM_TITLE'] = sprintf(__("Create site and add channel %s to this site"), '<span class="green i">&bdquo;' . $channel_info->name . '&ldquo;</span>');
                 $form['fields']['id_channel'] = array("display_name" => "{@ID channel@}", "id_field_type" => "string", "form_field_type" => "hidden", "default" => $id_channel);
             }
             break;
         case 'modify':
             $form['vars']['FORM_TITLE'] = __("Edit site") . ':';
             $form['vars']['CURRENT_SITE_NAME'] = '&bdquo;' . type_to_str($this->_site->getName(), 'encode') . ' (' . $this->_site->getUrl() . ')&ldquo;';
             $form['vars']['APPLY_BTN_CAPTION'] = "Save";
             if (!array_key_exists('redirect', $form)) {
                 $form['redirect'] = "/" . $this->role . "/edit_site/edit_complete/" . type_to_str($this->_site->getId(), 'textcode');
             }
             break;
     }
     $this->_add_java_script('ajaxupload.3.9');
     $this->_set_content($this->form->get_form_content($mode, $form, $this->input, $this));
     $this->_display();
 }
 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 '';
 }
Exemplo n.º 4
0
 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 "";
 }
Exemplo n.º 5
0
 /**
  * Создание сайта
  *
  * @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;
 }