コード例 #1
0
 /**
  * Routine
  *
  * @param	int		$cat_id		The category ID
  * @param	int		$link_id	The link ID
  * @param	string	$mode		add|edit
  * @return	null|\Symfony\Component\HttpFoundation\Response	A Symfony Response object
  * @throws	\phpbb\exception\http_exception
  */
 private function _data_processing($cat_id, $link_id = 0, $mode = 'new')
 {
     if ($mode == 'edit' && !$this->auth->acl_get('m_edit_dir') && !$this->auth->acl_get('u_edit_dir') || $mode == 'new' && !$this->auth->acl_get('u_submit_dir')) {
         throw new \phpbb\exception\http_exception(403, 'DIR_ERROR_NOT_AUTH');
     }
     if (!check_form_key('dir_form')) {
         return $this->helper->message('FORM_INVALID');
     }
     $this->url = $this->request->variable('url', '');
     $this->site_name = $this->request->variable('site_name', '', true);
     $this->description = $this->request->variable('description', '', true);
     $this->guest_email = $this->request->variable('guest_email', '');
     $this->rss = $this->request->variable('rss', '');
     $this->banner = $this->request->variable('banner', '');
     $this->back = $this->request->variable('back', '');
     $this->flag = $this->request->variable('flag', '');
     if (!function_exists('validate_data')) {
         include $this->root_path . 'includes/functions_user.' . $this->php_ext;
     }
     // We define variables to check
     $data = array('email' => $this->guest_email, 'site_name' => $this->site_name, 'website' => $this->url, 'description' => $this->description, 'rss' => $this->rss, 'banner' => $this->banner, 'back' => $this->back, 'cat' => (int) $cat_id);
     // We define verification type for each variable
     $data2 = array('email' => array(array('string', $this->user->data['is_registered'], 6, 60), array('user_email', '')), 'site_name' => array(array('string', false, 1, 100)), 'website' => array(array('string', false, 12, 255), array('match', true, '#^http[s]?://(.*?\\.)*?[a-z0-9\\-]+\\.[a-z]{2,4}#i')), 'description' => array(array('string', !$this->categorie->data['cat_must_describe'], 1, $this->config['dir_length_describe'])), 'rss' => array(array('string', true, 12, 255), array('match', empty($this->rss), '#^http[s]?://(.*?\\.)*?[a-z0-9\\-]+\\.[a-z]{2,4}#i')), 'banner' => array(array('string', true, 5, 255)), 'back' => array(array('string', !$this->categorie->data['cat_link_back'], 12, 255), array(array($this->link, 'link_back'), true)), 'cat' => array(array('num', '', 1)));
     $this->user->add_lang('ucp');
     $error = validate_data($data, $data2);
     $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$this->user->lang['\\1'])) ? \$this->user->lang['\\1'] : '\\1'", $error);
     // We check that url have good format
     if (preg_match('/^(http|https):\\/\\//si', $this->url) && $this->config['dir_activ_checkurl'] && !$this->link->checkurl($this->url)) {
         $error[] = $this->user->lang['DIR_ERROR_CHECK_URL'];
     }
     if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm']) {
         $vc_response = $this->captcha->validate($data);
         if ($vc_response !== false) {
             $error[] = $vc_response;
         }
         if ($this->config['dir_visual_confirm_max_attempts'] && $this->captcha->get_attempt_count() > $this->config['dir_visual_confirm_max_attempts']) {
             $error[] = $this->user->lang['TOO_MANY_ADDS'];
         }
     }
     if (!$error) {
         /**
          * No errrors, we execute heavy tasks wich need a valid url
          */
         // Banner
         $this->link->banner_process($this->banner, $error);
         // PageRank
         $pagerank = $this->link->pagerank_process($this->url);
         // Thumb ;)
         $thumb = $this->link->thumb_process($this->url);
     }
     // Still no errors?? So let's go!
     if (!$error) {
         $uid = $bitfield = $flags = '';
         generate_text_for_storage($this->description, $uid, $bitfield, $flags, (bool) $this->config['allow_bbcode'], (bool) $this->config['allow_post_links'], (bool) $this->config['allow_smilies']);
         $this->banner = !$this->banner && !$this->request->is_set_post('delete_banner') ? $this->request->variable('old_banner', '') : $this->banner;
         $this->url = $this->link->clean_url($this->url);
         $data_edit = array('link_user_id' => $this->link_user_id, 'link_guest_email' => $this->guest_email, 'link_name' => $this->site_name, 'link_url' => $this->url, 'link_description' => $this->description, 'link_cat' => (int) $cat_id, 'link_rss' => $this->rss, 'link_banner' => $this->banner, 'link_back' => $this->back, 'link_uid' => $uid, 'link_flags' => $flags, 'link_flag' => $this->flag, 'link_bitfield' => $bitfield, 'link_pagerank' => (int) $pagerank, 'link_thumb' => $thumb);
         $need_approval = $this->categorie->need_approval() && !$this->auth->acl_get('a_') && !$this->auth->acl_get('m_') ? true : false;
         if ($mode == 'edit') {
             $data_edit['link_cat_old'] = $this->request->variable('old_cat_id', 0);
             $this->link->edit($data_edit, $link_id, $need_approval);
         } else {
             $data_add = array('link_time' => time(), 'link_view' => 0, 'link_active' => $need_approval ? false : true, 'link_user_id' => $this->user->data['user_id']);
             $data_add = array_merge($data_edit, $data_add);
             $this->link->add($data_add, $need_approval);
         }
         $meta_info = $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $cat_id));
         meta_refresh(3, $meta_info);
         $message = $need_approval ? $this->user->lang['DIR_' . strtoupper($mode) . '_SITE_ACTIVE'] : $this->user->lang['DIR_' . strtoupper($mode) . '_SITE_OK'];
         $message = $message . '<br /><br />' . $this->user->lang('DIR_CLICK_RETURN_DIR', '<a href="' . $this->helper->route('ernadoo_phpbbdirectory_base_controller') . '">', '</a>') . '<br /><br />' . $this->user->lang('DIR_CLICK_RETURN_CAT', '<a href="' . $this->helper->route('ernadoo_phpbbdirectory_page_controller', array('cat_id' => (int) $cat_id)) . '">', '</a>');
         return $this->helper->message($message);
     } else {
         if ($mode == 'edit') {
             $this->s_hidden_fields = array('old_cat_id' => $this->request->variable('old_cat_id', 0), 'old_banner' => $this->request->variable('old_banner', ''));
         }
         $this->template->assign_vars(array('ERROR' => isset($error) ? implode('<br />', $error) : ''));
     }
 }