[5179] | 1 | <?php |
---|
| 2 | |
---|
| 3 | global $user, $template, $lang, $conf, $im_priority; |
---|
| 4 | |
---|
| 5 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 6 | |
---|
| 7 | include_once(NBC_NEWS_PATH.'include/constants.php'); |
---|
| 8 | include_once(NBC_NEWS_PATH.'include/functions_news.inc.php'); |
---|
| 9 | load_language('plugin.lang', NBC_NEWS_PATH); |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | $template->set_filenames(array('NewsOnIndex' => NBC_NEWS_PATH.'template/NewsOnIndex.tpl')); |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | $conf_nbc_News = explode(";" ,$conf['nbc_News']); |
---|
| 17 | $conf['nb_news_homepage'] = $conf_nbc_News[0]; |
---|
| 18 | $conf['nb_news_page'] = $conf_nbc_News[1]; |
---|
| 19 | $conf['nb_news_page_option'] = explode("," ,$conf_nbc_News[2]); |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | $user['forbidden_news'] = calculate_news_permissions($user['id']); |
---|
| 25 | |
---|
| 26 | $query = ' |
---|
| 27 | SELECT n.id AS new_id |
---|
| 28 | , n.date |
---|
| 29 | , n.author |
---|
| 30 | FROM '.NEWS_TABLE.' AS n |
---|
| 31 | WHERE n.id NOT IN ('.$user['forbidden_news'].') |
---|
| 32 | ORDER BY date DESC |
---|
| 33 | LIMIT '.$conf['nb_news_homepage'].' |
---|
| 34 | ;'; |
---|
| 35 | |
---|
| 36 | $result = pwg_query($query); |
---|
| 37 | |
---|
| 38 | $start=0; |
---|
| 39 | |
---|
| 40 | while ($row = mysql_fetch_array($result)) |
---|
| 41 | { |
---|
| 42 | if ($start == 0) |
---|
| 43 | $template->assign('news', array( |
---|
| 44 | 'U_NEWS' => NBC_NEWS_PATH.'news.php' |
---|
| 45 | )); |
---|
| 46 | |
---|
| 47 | $new_id = $row['new_id']; |
---|
| 48 | |
---|
| 49 | //get the news translation |
---|
| 50 | $query = ' |
---|
| 51 | SELECT id AS news_translation_id,language,title,content |
---|
| 52 | FROM '.NEWS_TRANSLATION_TABLE.' |
---|
| 53 | WHERE new_id = '.$new_id.' |
---|
| 54 | '; |
---|
| 55 | |
---|
| 56 | $no_news_translation=false; |
---|
| 57 | |
---|
| 58 | $subresult = pwg_query($query.'AND language = \''.$user['language'].'\';'); |
---|
| 59 | $subrow = mysql_fetch_array($subresult); |
---|
| 60 | |
---|
| 61 | //there is a no translation for the user language |
---|
| 62 | if (empty($subrow)) |
---|
| 63 | { |
---|
| 64 | $no_news_translation=true; |
---|
| 65 | |
---|
| 66 | $research = pwg_query('SELECT language FROM '.USER_INFOS_TABLE.' WHERE user_id = '.$conf['guest_id'].';'); |
---|
| 67 | $defaultlanguage = mysql_fetch_array($research); |
---|
| 68 | |
---|
| 69 | //get the default translation |
---|
| 70 | $subresult = pwg_query($query.'AND language = \''.$defaultlanguage['language'].'\';'); |
---|
| 71 | $subrow = mysql_fetch_array($subresult); |
---|
| 72 | |
---|
| 73 | //there is no translation for the default language |
---|
| 74 | if (empty($subrow)) |
---|
| 75 | { |
---|
| 76 | //get the first translation |
---|
| 77 | $subresult = pwg_query($query.'LIMIT 1;'); |
---|
| 78 | $subrow = mysql_fetch_array($subresult); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | $message=$subrow['content']; |
---|
| 83 | |
---|
| 84 | $read_more=(strlen($message)!=strlen($subrow['content'])); |
---|
| 85 | |
---|
| 86 | $template->assign( |
---|
| 87 | 'news.a_news', |
---|
| 88 | array( |
---|
| 89 | 'NEWS_AUTHOR'=>$row['author'], |
---|
| 90 | 'NEWS_DATE'=>format_date($row['date'],'mysql_datetime',true), |
---|
| 91 | 'TITLE'=>$subrow['title'], |
---|
| 92 | 'CONTENT'=>$message |
---|
| 93 | )); |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | //there is no tranlstation for this news |
---|
| 97 | if ($no_news_translation) |
---|
| 98 | { |
---|
| 99 | $template->assign('news.a_news.no_news_translation', array()); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | //news has been cuted |
---|
| 103 | if ($read_more) |
---|
| 104 | { |
---|
| 105 | $template->assign( |
---|
| 106 | 'news.a_news.read_more', |
---|
| 107 | array( |
---|
| 108 | 'URL' => add_url_params(__FILE__, array( |
---|
| 109 | 'nb_news_page' => '1', |
---|
| 110 | 'start' => $start, |
---|
| 111 | )), |
---|
| 112 | ) |
---|
| 113 | ); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | $start++; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | if (isset($im_priority)) |
---|
| 122 | { |
---|
| 123 | $insert_before = $im_priority['NewsOnIndex'] < $im_priority['Categories'] ? '<div class="titrePage">' : '</div> <!-- content -->'; |
---|
| 124 | } |
---|
| 125 | else |
---|
| 126 | { |
---|
| 127 | $insert_before = $conf_nbc_News[0] == 'on' ? '<div class="titrePage">' : '</div> <!-- content -->'; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | //$template->loadfile('index'); |
---|
| 131 | $template->uncompiled_code['index'] = str_replace($insert_before, '{NEWSONINDEX_CONTENT}' . $insert_before, $template->uncompiled_code['index']); |
---|
| 132 | |
---|
| 133 | $template->assign_var_from_handle('NEWSONINDEX_CONTENT', 'NewsOnIndex'); |
---|
| 134 | |
---|
| 135 | ?> |
---|