Elfet Опубликовано 13 Апреля 2006 Жалоба Поделиться Опубликовано 13 Апреля 2006 У меня есть класс для чтения новостей с форума. Правильно ли я его посторил с точки зрения IPB?class news { var $ipsclass; var $parser = ""; var $statfunc = ""; function get($input_array) { //------------------------------------------- // input array //------------------------------------------- $max = ( $input_array[0] != "" ) ? $input_array[0] : 5; //------------------------------------------- // loading skin and lang //------------------------------------------- $this->ipsclass->load_template('skin_topic'); $this->ipsclass->load_language('lang_topic'); //----------------------------------------- // Load and config the post parser //----------------------------------------- require_once( ROOT_PATH."sources/handlers/han_parse_bbcode.php" ); $this->parser = new parse_bbcode(); $this->parser->ipsclass = $this->ipsclass; $this->parser->allow_update_caches = 1; $this->parser->bypass_badwords = intval($this->ipsclass->member['g_bypass_badwords']); $this->ipsclass->load_template('skin_topic'); $this->ipsclass->load_language('lang_topic'); //----------------------------------------- // news forum id //----------------------------------------- if(!$this->ipsclass->vars['news_forum_id']) return ""; //----------------------------------------- // Query MySQL //----------------------------------------- $query = $this->ipsclass->DB->query("SELECT t.*, t.posts as replies, p.* FROM ibf_topics AS t LEFT JOIN ibf_posts AS p ON (p.topic_id=t.tid AND p.new_topic='1') WHERE ( t.forum_id=".$this->ipsclass->vars['news_forum_id']." AND t.approved=1 ) ORDER BY t.tid DESC LIMIT 0, ".$max); $html = ""; while ( $row = $this->ipsclass->DB->fetch_row($query) ) { $row['start_date'] = $this->ipsclass->get_date( $row['start_date'], 'LONG' ); if($row['description'] != "") $row['title'] .= ", ".$row['description']; $row['icon'] = $row['icon_id'] ? $this->ipsclass->compiled_templates['skin_topic']->post_icon( $row['icon_id'] ) : ""; //----------------------------------------- // Parse HTML tag on the fly //----------------------------------------- $this->parser->parse_html = ( $this->forum['use_html'] and $this->ipsclass->cache['group_cache'][ $poster['mgroup'] ]['g_dohtml'] and $row['post_htmlstate'] ) ? 1 : 0; $this->parser->parse_nl2br = $row['post_htmlstate'] == 2 ? 1 : 0; $row['post'] = $this->parser->pre_display_parse( $row['post'] ); $html .= $this->ipsclass->compiled_templates['skin_welcome']->news_row($row); if($row['topic_hasattach'] != 0) { $html = $this->parse_attachments( $html, array( $row['pid'] ) ); } } return $this->ipsclass->compiled_templates['skin_welcome']->tmpl_news( $html, $this->ipsclass->vars['news_forum_id'] ); } /*-------------------------------------------------------------------------*/ // ATTACHMENTS /*-------------------------------------------------------------------------*/ function parse_attachments( $html, $attach_pids, $type='attach_pid', $from='pid', $method='post' ) { $final_attachments = array(); if ( count( $attach_pids ) ) { $this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'attachments', 'where' => "$type IN (".implode(",", $attach_pids).")" ) ); $this->ipsclass->DB->simple_exec(); while ( $a = $this->ipsclass->DB->fetch_row() ) { $final_attachments[ $a[ $type ] ][ $a['attach_id'] ] = $a; } foreach ( $final_attachments as $pid => $data ) { $temp_out = ""; $temp_hold = array(); foreach( $final_attachments[$pid] as $aid => $row ) { //----------------------------------------- // Is it an image, and are we viewing the image in the post? //----------------------------------------- if ( $this->ipsclass->vars['show_img_upload'] and $row['attach_is_image'] ) { if ( $this->ipsclass->vars['siu_thumb'] AND $row['attach_thumb_location'] AND $row['attach_thumb_width'] ) { $tmp = $this->ipsclass->compiled_templates['skin_topic']->Show_attachments_img_thumb( $row['attach_thumb_location'], $row['attach_thumb_width'], $row['attach_thumb_height'], $row['attach_id'], $this->ipsclass->size_format( $row['attach_filesize'] ), $row['attach_hits'], $row['attach_file'], $method ); if ( strstr( $html, '[attachmentid='.$row['attach_id'].']' ) ) { $html = str_replace( '[attachmentid='.$row['attach_id'].']', $tmp, $html ); } else { $temp_hold['thumb'] .= $tmp . ' '; } } else { //----------------------------------------- // Standard size.. //----------------------------------------- $tmp = $this->ipsclass->compiled_templates['skin_topic']->Show_attachments_img( $row['attach_location'] ); if ( strstr( $html, '[attachmentid='.$row['attach_id'].']' ) ) { $html = str_replace( '[attachmentid='.$row['attach_id'].']', $tmp, $html ); } else { $temp_hold['image'] .= $tmp . ' '; } } } else { //----------------------------------------- // Full attachment thingy //----------------------------------------- $tmp = $this->ipsclass->compiled_templates['skin_topic']->Show_attachments( array ( 'hits' => $row['attach_hits'], 'image' => $this->ipsclass->cache['attachtypes'][ $row['attach_ext'] ]['atype_img'], 'name' => $row['attach_file'], $from => $row[$type], 'id' => $row['attach_id'], 'method'=> $method, 'size' => $this->ipsclass->size_format( $row['attach_filesize'] ), ) ); if ( strstr( $html, '[attachmentid='.$row['attach_id'].']' ) ) { $html = str_replace( '[attachmentid='.$row['attach_id'].']', $tmp, $html ); } else { $temp_hold['attach'] .= $tmp; } } } //----------------------------------------- // Anyfink to show? //----------------------------------------- if ( $temp_hold['thumb'] ) { $temp_out = $this->ipsclass->compiled_templates['skin_topic']->show_attachment_title($this->ipsclass->lang['attach_thumbs']) . $temp_hold['thumb']; } if ( $temp_hold['image'] ) { $temp_out .= $this->ipsclass->compiled_templates['skin_topic']->show_attachment_title($this->ipsclass->lang['attach_images']) . $temp_hold['image']; } if ( $temp_hold['attach'] ) { $temp_out .= $this->ipsclass->compiled_templates['skin_topic']->show_attachment_title($this->ipsclass->lang['attach_normal']) . $temp_hold['attach']; } if ( $temp_out ) { $html = str_replace( "<!--IBF.ATTACHMENT_".$attach_pids[0]."-->", $temp_out, $html ); } } } return $html; } } Мне здесь не нравиться, что на каждый пост с атачем, будер вызываться вторая функция, которая даёт дополнительные запросы. Цитата Ссылка на комментарий Поделиться на других сайтах Прочее
Вопрос
Elfet
У меня есть класс для чтения новостей с форума. Правильно ли я его посторил с точки зрения IPB?
Мне здесь не нравиться, что на каждый пост с атачем, будер вызываться вторая функция, которая даёт дополнительные запросы.
Ссылка на комментарий
Поделиться на других сайтах
0 ответов на этот вопрос
Рекомендуемые сообщения
Присоединиться к обсуждению
Вы можете ответить сейчас, а зарегистрироваться позже. Если у вас уже есть аккаунт, войдите, чтобы ответить от своего имени.