[ Index ]
 

Code source de Mantis 1.1.0rc3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/core/ -> news_api.php (source)

   1  <?php
   2  # Mantis - a php based bugtracking system
   3  
   4  # Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
   5  # Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
   6  
   7  # Mantis is free software: you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation, either version 2 of the License, or
  10  # (at your option) any later version.
  11  #
  12  # Mantis is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  #
  17  # You should have received a copy of the GNU General Public License
  18  # along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
  19  
  20      # --------------------------------------------------------
  21      # $Id: news_api.php,v 1.25.2.1 2007-10-13 22:35:35 giallu Exp $
  22      # --------------------------------------------------------
  23  
  24      ### News API ###
  25  
  26      $t_core_path = config_get( 'core_path' );
  27  
  28      require_once ( $t_core_path . 'current_user_api.php' );
  29      require_once ( $t_core_path . 'twitter_api.php' );
  30  
  31      # --------------------
  32      # Add a news item
  33  	function news_create( $p_project_id, $p_poster_id, $p_view_state, $p_announcement, $p_headline, $p_body ) {
  34          $c_project_id    = db_prepare_int( $p_project_id );
  35          $c_poster_id    = db_prepare_int( $p_poster_id );
  36          $c_view_state    = db_prepare_int( $p_view_state );
  37          $c_announcement    = db_prepare_bool( $p_announcement );
  38          $c_headline        = db_prepare_string( $p_headline );
  39          $c_body            = db_prepare_string( $p_body );
  40  
  41          if ( is_blank( $c_headline ) ) {
  42              error_parameters( lang_get( 'headline' ) );
  43              trigger_error( ERROR_EMPTY_FIELD, ERROR );
  44          }
  45  
  46          if ( is_blank( $c_body ) ) {
  47              error_parameters( lang_get( 'body' ) );
  48              trigger_error( ERROR_EMPTY_FIELD, ERROR );
  49          }
  50  
  51          $t_news_table = config_get( 'mantis_news_table' );
  52  
  53          # Add item
  54          $query = "INSERT
  55                  INTO $t_news_table
  56                    ( project_id, poster_id, date_posted, last_modified,
  57                      view_state, announcement, headline, body )
  58                  VALUES
  59                    ( '$c_project_id', '$c_poster_id', " . db_now() . "," . db_now() .",
  60                      '$c_view_state', '$c_announcement', '$c_headline', '$c_body' )";
  61          db_query( $query );
  62  
  63          $t_news_id = db_insert_id();
  64   
  65          twitter_news( $t_news_id );
  66  
  67          return $t_news_id;
  68      }
  69      # --------------------
  70      # Delete the news entry
  71  	function news_delete( $p_news_id ) {
  72          $c_news_id = db_prepare_int( $p_news_id );
  73  
  74          $t_news_table = config_get( 'mantis_news_table' );
  75  
  76          $query = "DELETE FROM $t_news_table
  77                    WHERE id='$c_news_id'";
  78  
  79          db_query( $query );
  80  
  81          # db_query() errors on failure so:
  82          return true;
  83      }
  84      # --------------------
  85      # Delete the news entry
  86  	function news_delete_all( $p_project_id ) {
  87          $c_project_id = db_prepare_int( $p_project_id );
  88  
  89          $t_news_table = config_get( 'mantis_news_table' );
  90  
  91          $query = "DELETE FROM $t_news_table
  92                    WHERE project_id='$c_project_id'";
  93  
  94          db_query( $query );
  95  
  96          # db_query() errors on failure so:
  97          return true;
  98      }
  99      # --------------------
 100      # Update news item
 101  	function news_update( $p_news_id, $p_project_id, $p_view_state, $p_announcement, $p_headline, $p_body ) {
 102          $c_news_id        = db_prepare_int( $p_news_id );
 103          $c_project_id    = db_prepare_int( $p_project_id );
 104          $c_view_state    = db_prepare_int( $p_view_state );
 105          $c_announcement    = db_prepare_bool( $p_announcement );
 106          $c_headline        = db_prepare_string( $p_headline );
 107          $c_body            = db_prepare_string( $p_body );
 108  
 109          if ( is_blank( $c_headline ) ) {
 110              error_parameters( lang_get( 'headline' ) );
 111              trigger_error( ERROR_EMPTY_FIELD, ERROR );
 112          }
 113  
 114          if ( is_blank( $c_body ) ) {
 115              error_parameters( lang_get( 'body' ) );
 116              trigger_error( ERROR_EMPTY_FIELD, ERROR );
 117          }
 118  
 119          $t_news_table = config_get( 'mantis_news_table' );
 120  
 121          # Update entry
 122          $query = "UPDATE $t_news_table
 123                    SET view_state='$c_view_state',
 124                      announcement='$c_announcement',
 125                      headline='$c_headline',
 126                      body='$c_body',
 127                      project_id='$c_project_id',
 128                      last_modified= " . db_now() . "
 129                    WHERE id='$c_news_id'";
 130  
 131          db_query( $query );
 132  
 133          # db_query() errors on failure so:
 134          return true;
 135      }
 136      # --------------------
 137      # Selects the news item associated with the specified id
 138  	function news_get_row( $p_news_id ) {
 139          $c_news_id = db_prepare_int( $p_news_id );
 140  
 141          $t_news_table = config_get( 'mantis_news_table' );
 142  
 143          $query = "SELECT *
 144                    FROM $t_news_table
 145                    WHERE id='$c_news_id'";
 146          $result = db_query( $query );
 147  
 148          if ( 0 == db_num_rows( $result ) ) {
 149              trigger_error( ERROR_NEWS_NOT_FOUND, ERROR );
 150          } else {
 151              $row = db_fetch_array( $result );
 152              $row['date_posted'] = db_unixtimestamp ( $row['date_posted'] );
 153              return $row;
 154          }
 155      }
 156      # --------------------
 157      # get news count (selected project plus sitewide posts)
 158  	function news_get_count( $p_project_id, $p_sitewide=true ) {
 159          $c_project_id = db_prepare_int( $p_project_id );
 160  
 161          $t_news_table = config_get( 'mantis_news_table' );
 162          $t_project_where = helper_project_specific_where( $p_project_id );
 163  
 164          $query = "SELECT COUNT(*)
 165                    FROM $t_news_table
 166                    WHERE $t_project_where";
 167  
 168          if ( $p_sitewide ) {
 169              $query .= ' OR project_id=' . ALL_PROJECTS;
 170          }
 171  
 172          $result = db_query( $query );
 173  
 174          return db_result( $result, 0, 0 );
 175      }
 176      # --------------------
 177      # get news items (selected project plus sitewide posts)
 178  	function news_get_rows( $p_project_id, $p_sitewide=true ) {
 179          $t_news_table = config_get( 'mantis_news_table' );
 180  
 181          $t_projects = current_user_get_all_accessible_subprojects( $p_project_id );
 182          $t_projects[] = $p_project_id;
 183  
 184          if ( $p_sitewide && ALL_PROJECTS != $p_project_id ) {
 185              $t_projects[] = ALL_PROJECTS;
 186          }
 187  
 188          $t_projects = array_map( 'db_prepare_int', $t_projects );
 189  
 190          $query = "SELECT *
 191                    FROM $t_news_table";
 192  
 193          if ( 1 == count( $t_projects ) ) {
 194              $c_project_id = $t_projects[0];
 195              $query .= " WHERE project_id='$c_project_id'";
 196          } else {
 197              $query .= ' WHERE project_id IN (' . join( $t_projects, ',' ) . ')';
 198          }
 199  
 200          $query .= " ORDER BY date_posted DESC";
 201  
 202          $result = db_query( $query );
 203  
 204          $t_rows = array();
 205          $t_row_count = db_num_rows( $result );
 206  
 207          for ( $i=0 ; $i < $t_row_count ; $i++ ) {
 208              $row = db_fetch_array( $result ) ;
 209              $row['date_posted'] = db_unixtimestamp( $row['date_posted'] );
 210              array_push( $t_rows, $row );
 211          }
 212  
 213          return $t_rows;
 214      }
 215      # --------------------
 216      # Check if the specified news item is private
 217  	function news_get_field( $p_news_id, $p_field_name ) {
 218          $row = news_get_row( $p_news_id );
 219          return ( $row[$p_field_name] );
 220      }
 221      # --------------------
 222      # Check if the specified news item is private
 223  	function news_is_private( $p_news_id ) {
 224          return ( news_get_field( $p_news_id, 'view_state' ) == VS_PRIVATE );
 225      }
 226      # --------------------
 227      # Gets a limited set of news rows to be viewed on one page based on the criteria
 228      # defined in the configuration file.
 229  	function news_get_limited_rows( $p_offset, $p_project_id = null ) {
 230          if ( $p_project_id === null ) {
 231              $p_project_id = helper_get_current_project();
 232          }
 233  
 234          $c_offset        = db_prepare_int( $p_offset );
 235  
 236          $t_projects = current_user_get_all_accessible_subprojects( $p_project_id );
 237          $t_projects[] = $p_project_id;
 238          if ( ALL_PROJECTS != $p_project_id ) {
 239              $t_projects[] = ALL_PROJECTS;
 240          }
 241  
 242          $t_projects = array_map( 'db_prepare_int', $t_projects );
 243  
 244          $t_news_table            = config_get( 'mantis_news_table' );
 245          $t_news_view_limit        = config_get( 'news_view_limit' );
 246          $t_news_view_limit_days = config_get( 'news_view_limit_days' );
 247  
 248          switch ( config_get( 'news_limit_method' ) ) {
 249              case 0 :
 250                  # BY_LIMIT - Select the news posts
 251                  $query = "SELECT *
 252                          FROM $t_news_table";
 253  
 254                  if ( 1 == count( $t_projects ) ) {
 255                      $c_project_id = $t_projects[0];
 256                      $query .= " WHERE project_id='$c_project_id'";
 257                  } else {
 258                      $query .= ' WHERE project_id IN (' . join( $t_projects, ',' ) . ')';
 259                  }
 260  
 261                  $query .= ' ORDER BY announcement DESC, id DESC';
 262                  $result = db_query( $query , $t_news_view_limit , $c_offset);
 263                  break;
 264              case 1 :
 265                  # BY_DATE - Select the news posts
 266                  $query = "SELECT *
 267                          FROM $t_news_table";
 268  
 269                  if ( 1 == count( $t_projects ) ) {
 270                      $c_project_id = $t_projects[0];
 271                      $query .= " WHERE project_id='$c_project_id'";
 272                  } else {
 273                      $query .= ' WHERE project_id IN (' . join( $t_projects, ',' ) . ')';
 274                  }
 275  
 276                  $query .= " AND " . db_helper_compare_days( db_now(), 'date_posted', "< $t_news_view_limit_days") .
 277                            " OR  announcement = 1
 278                          ORDER BY announcement DESC, id DESC";
 279                  $result = db_query( $query, $t_news_view_limit, $c_offset );
 280                  break;
 281          } # end switch
 282  
 283          $t_row_count = db_num_rows( $result );
 284  
 285          $t_rows = array();
 286          for ( $i = 0; $i < $t_row_count; $i++ ) {
 287              $row = db_fetch_array( $result ) ;
 288              $row['date_posted'] = db_unixtimestamp( $row['date_posted'] );
 289              array_push( $t_rows, $row );
 290          }
 291  
 292          return $t_rows;
 293      }
 294  ?>


Généré le : Thu Nov 29 09:42:17 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics