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();
 }
Beispiel #2
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 "";
 }
Beispiel #3
0
 /**
  * Создание сайта
  *
  * @param array $fields параметры создаваемого сайта
  * @return string описание ошибки ('' при успешном создании)
  */
 public function _create($fields)
 {
     $siteModel = new Sppc_SiteModel();
     $site = $siteModel->createRow();
     /* @var Sppc_Site $site */
     $categoryModel = new Sppc_CategoryModel();
     $category = $categoryModel->find(explode(',', $fields['category']));
     $site->setUrl(trim($fields['domain']));
     $site->setName(trim($fields['title']));
     $site->setCreationDate(Zend_Date::now());
     $site->setDescription(trim($fields['description']));
     $site->setCategories($category);
     $site->setIdEntityPublisher($this->user_id);
     $siteStatus = 'active';
     if ($this->role != 'admin') {
         $siteConfirmationRequired = (bool) $this->global_variables->get('SitesOwnershipConfirmationRequired', 0, '0');
         $siteAdminApproveRequired = (bool) $this->global_variables->get('ApproveSites', 0, '0');
         if ($siteConfirmationRequired) {
             $siteStatus = 'unapproved';
         } else {
             if ($siteAdminApproveRequired) {
                 $siteStatus = 'pending';
             }
         }
     }
     $site->setStatus($siteStatus);
     if (array_key_exists('id_channel', $fields)) {
         $channelModel = new Sppc_ChannelModel();
         $channel = $channelModel->findObjectById($fields['id_channel']);
         if (!is_null($channel)) {
             $site->addChannel($channel);
         }
     }
     try {
         $site->save();
     } catch (Exception $e) {
         return $e->getMessage();
     }
     $siteLayoutModel = new Sppc_Site_LayoutModel();
     $siteLayoutModel->updateFromJson($site, trim($fields['layout_json']));
     if (strtolower($fields['thumb_id']) != 'default') {
         $from = $this->config->item('path_to_images') . 'thumbs/' . $fields['thumb_id'] . '.jpeg';
         $to = $this->config->item('path_to_images') . 'thumbs/' . $site->getId() . '.jpeg';
         if (file_exists($to)) {
             unlink($to);
         }
         rename($from, $to);
     }
     if ($this->role != 'admin' && $siteConfirmationRequired) {
         redirect($this->role . '/edit_site/create_complete/' . $site->getId());
         exit;
     }
     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 '';
 }