source: extensions/NBC_News/trunk/news.php @ 26862

Last change on this file since 26862 was 5179, checked in by Eric, 15 years ago

[NBC_News]

  • Initial commit for Piwigo 2.0.x : Not fully functionnal and a lot work to do...
  • Property svn:eol-style set to LF
File size: 5.7 KB
RevLine 
[5179]1<?php
2
3global $user, $template, $lang, $conf;
4
5if (!defined('PHPWG_ROOT_PATH')) define('PHPWG_ROOT_PATH','../../');
6
7include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
8
9check_status(ACCESS_GUEST);
10
11include_once('./include/constants.php');
12include_once('./include/functions_news.inc.php');
13include(get_language_filepath('plugin.lang.php', './'));
14
15
16
17$conf_nbc_News = explode(";" , $conf['nbc_News']);
18$conf['nb_news_homepage'] = $conf_nbc_News[0];
19$conf['nb_news_page'] = $conf_nbc_News[1];
20$conf['nb_news_page_option'] = explode("," ,$conf_nbc_News[2]);
21
22
23
24// detection of the start news to display
25if ( !isset( $_GET['start'] ) or !is_numeric( $_GET['start'] ) or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
26{
27  $page['start'] = 0;
28}
29else
30{
31  $page['start'] = $_GET['start'];
32}
33
34// detection of the number of news to display per page
35if ( !isset( $_GET['nb_news_page'] ) or !is_numeric( $_GET['nb_news_page'] ) or ( is_numeric( $_GET['nb_news_page'] ) and $_GET['nb_news_page'] < 0 ) )
36{
37  $page['nb_news_page'] = $conf['nb_news_page'];
38}
39else
40{
41  $page['nb_news_page'] = $_GET['nb_news_page'];
42}
43
44
45
46// +-----------------------------------------------------------------------+
47// |                               options                                 |
48// +-----------------------------------------------------------------------+
49
50$title= $lang['title_news'];
51$template_title = $lang['title_news'];
52$page['body_id'] = 'theNewsPage';
53
54$template->set_filenames(array('news' => NBC_NEWS_PATH.'template/news.tpl'));
55
56$template->assign_vars(
57  array(
58    'U_NEWS_HOME' => PHPWG_ROOT_PATH,
59    'U_NEWS_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=news',
60    'NEWS_CSS' => '<link rel="stylesheet" type="text/css" href="'.NBC_NEWS_PATH.'template/newspage.css">',
61  )
62);
63 
64
65
66// +-----------------------------------------------------------------------+
67// |               news per pages & nav bar display                        |
68// +-----------------------------------------------------------------------+
69
70$user['forbidden_news'] = calculate_news_permissions($user['id']);
71
72$query = '
73  SELECT COUNT(DISTINCT(id)) as nb_news
74  FROM '.NEWS_TABLE.'
75  WHERE id NOT IN ('.$user['forbidden_news'].')
76  ;';
77       
78$result = pwg_query($query);
79
80$row = mysql_fetch_array($result);
81$page['nb_news']=$row['nb_news'];
82
83//display number of news per page link
84$template->assign_block_vars('news_per_page', array());
85
86foreach ($conf['nb_news_page_option'] as $option)
87{
88  $template->assign_block_vars(
89    'news_per_page.nb_option',
90    array(
91      'OPTION' => $option,
92      'T_STYLE' => ($option == $page['nb_news_page'])?'text-decoration:underline;':'',
93      'U_OPTION' => add_url_params(NBC_NEWS_PATH.'news.php', array('nb_news_page' => $option)),
94    )
95  );
96}
97 
98//display nav bar
99$page['navigation_bar'] = create_navigation_bar( add_url_params(NBC_NEWS_PATH.'news.php', array('nb_news_page' => $page['nb_news_page'])), $page['nb_news'],$page['start'],$page['nb_news_page'], false);
100 
101$template->assign_block_vars('navigation', array('NAV_BAR' => $page['navigation_bar'])
102);
103
104 
105// +-----------------------------------------------------------------------+
106// |                          last news display                            |
107// +-----------------------------------------------------------------------+
108 
109//get every languages
110$available_lang=get_languages();
111 
112// affiche les news publics + les news du groupe de l'utilisateur + les news de l'utilisateur
113$user['forbidden_news'] = calculate_news_permissions($user['id']);
114
115$query = '
116  SELECT id AS new_id, date, author
117  FROM '.NEWS_TABLE.'
118  WHERE id NOT IN ('.$user['forbidden_news'].')
119  ORDER BY date DESC
120  LIMIT '.$page['start'].','.$page['nb_news_page'].'
121  ;';
122   
123$result = pwg_query($query);
124
125while ($row = mysql_fetch_array($result))
126{
127  $new_id = $row['new_id'];
128 
129  $template->assign_block_vars(
130    'news',
131    array(
132      'NEWS_AUTHOR'=>$row['author'],
133      'NEWS_DATE'=>format_date($row['date'],'mysql_datetime',true),
134    )
135  );
136 
137  //get the news translation
138  $query = '
139    SELECT id AS news_translation_id, language, title, content
140    FROM '.NEWS_TRANSLATION_TABLE.'
141    WHERE new_id = \''.$new_id.'\'
142    ';
143   
144  $no_news_translation = false;
145   
146  $subresult = pwg_query($query.'AND language = \''.$user['language'].'\';');
147  $subrow = mysql_fetch_array($subresult);
148       
149  //there is a no translation for the user language
150  if (empty($subrow))
151  {
152    $no_news_translation=true;
153     
154                $research = pwg_query('SELECT language FROM '.USER_INFOS_TABLE.' WHERE user_id = '.$conf['guest_id'].';');
155                $defaultlanguage = mysql_fetch_array($research);
156
157                //get the default translation   
158                $subresult = pwg_query($query.'AND language = \''.$defaultlanguage['language'].'\';');
159                $subrow = mysql_fetch_array($subresult);
160                       
161    //there is no translation for the default language
162    if (empty($subrow))
163    {
164      //get the first translation                       
165      $subresult = pwg_query($query.'LIMIT 1;');
166      $subrow = mysql_fetch_array($subresult);
167    }           
168  }
169     
170  $message = $subrow['content'];
171     
172  $template->assign_block_vars(
173    'news.news_translation',
174    array(
175      'TITLE'=>$subrow['title'],
176      'CONTENT'=>$message,
177    )
178  );   
179         
180  //there is no tranlstation for this news
181  if ($no_news_translation)
182  {
183    $template->assign_block_vars('news.news_translation.no_news_translation', array());
184  }
185}
186
187// +-----------------------------------------------------------------------+
188// |                           html code display                           |
189// +-----------------------------------------------------------------------+
190
191include(PHPWG_ROOT_PATH.'include/page_header.php');
192//$template->assign_block_vars('title', array());
193$template->parse('news');
194include(PHPWG_ROOT_PATH.'include/page_tail.php');
195?>
Note: See TracBrowser for help on using the repository browser.