[ 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/ -> twitter_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: twitter_api.php,v 1.4.2.1 2007-10-13 22:35:46 giallu Exp $
  22      # --------------------------------------------------------
  23  
  24      $t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
  25  
  26      require_once ( $t_core_dir . 'config_api.php' );
  27  
  28      $g_twitter_enabled = null;
  29  
  30      # --------------------
  31      # Checks if twitter is used for the current installation.
  32      # returns true for enabled, false otherwise.
  33  	function twitter_enabled() {
  34          global $g_twitter_enabled;
  35  
  36          if ( null === $g_twitter_enabled ) {
  37              $g_twitter_enabled = !is_blank( config_get( 'twitter_username' ) );
  38          }
  39          
  40          if ( $g_twitter_enabled && !function_exists( 'curl_init' ) ) {
  41              trigger_error( ERROR_TWITTER_NO_CURL_EXT, ERROR );
  42          }
  43  
  44          return $g_twitter_enabled;
  45      }
  46      
  47      # --------------------
  48      # Posts a twitter update when a bug is resolved.
  49      # @param $p_bug_id The bug id that was resolved.
  50  	function twitter_issue_resolved( $p_bug_id ) {
  51          if ( !twitter_enabled() ) {
  52              return true;
  53          }
  54          
  55          $t_bug = bug_get( $p_bug_id, false );
  56  
  57          # Do not twitter except fixed issues
  58          if ( $t_bug->resolution != FIXED ) {
  59              return true;
  60          }
  61  
  62          # Do not twitter private bugs.
  63          if ( $t_bug->view_state != VS_PUBLIC ) {
  64              return true;
  65          }
  66          
  67          # Do not twitter bugs belonging to private projects.
  68          if ( VS_PRIVATE == project_get_field( $t_bug->project_id, 'view_state' ) ) {
  69              return true;
  70          }
  71  
  72          $c_bug_id = db_prepare_int( $p_bug_id );
  73  
  74          if ( is_blank( $t_bug->fixed_in_version ) ) {
  75              $t_message = sprintf( 
  76                              lang_get( 'twitter_resolved_no_version' ), 
  77                              $c_bug_id, 
  78                              $t_bug->category,
  79                              $t_bug->summary, 
  80                              user_get_name( $t_bug->handler_id ) );
  81          } else {
  82              $t_message = sprintf(
  83                              lang_get( 'twitter_resolved' ), 
  84                              $c_bug_id, 
  85                              $t_bug->category,
  86                              $t_bug->summary, 
  87                              user_get_name( $t_bug->handler_id ),
  88                              $t_bug->fixed_in_version );
  89          }
  90  
  91          return twitter_update( $t_message );
  92      }
  93      
  94      # --------------------
  95      # Posts a twitter update when a news entry is submitted.
  96      # @param $p_news_id The newly posted news id.
  97  	function twitter_news( $p_news_id ) {
  98          if ( !twitter_enabled() ) {
  99              return true;
 100          }
 101  
 102          $t_news_view_state = news_get_field( $p_news_id, 'view_state' );
 103          if ( VS_PUBLIC != $t_news_view_state ) {
 104              return true;
 105          }
 106  
 107          $t_news_project_id = news_get_field( $p_news_id, 'project_id' );
 108          if ( $t_news_project_id != ALL_PROJECTS ) {
 109              $t_project_view_state = project_get_field( $t_news_project_id, 'view_state' );
 110              if ( VS_PUBLIC != $t_project_view_state ) {
 111                  return true;
 112              }
 113          }
 114  
 115          $t_news_headline = news_get_field( $p_news_id, 'headline' );
 116  
 117          return twitter_update( $t_news_headline );
 118      }
 119  
 120      # --------------------
 121      # Posts an update to twitter
 122      # @param $p_message  The message to post.
 123  	function twitter_update( $p_message ) {
 124          if ( !twitter_enabled() ) {
 125              return true;
 126          }
 127  
 128          if ( is_blank( $p_message ) ) {
 129              return true;
 130          }
 131          
 132          $c_message = db_prepare_string( $p_message );
 133  
 134          // Set username and password
 135          $t_username = config_get( 'twitter_username' );
 136          $t_password = config_get( 'twitter_password' );
 137  
 138          // The twitter API address
 139          $t_url = 'http://twitter.com/statuses/update.xml';
 140  
 141          // Set up and execute the curl process
 142          $t_curl = curl_init();
 143  
 144          curl_setopt( $t_curl, CURLOPT_URL, $t_url );
 145          curl_setopt( $t_curl, CURLOPT_CONNECTTIMEOUT, 2 );
 146          curl_setopt( $t_curl, CURLOPT_RETURNTRANSFER, 1);
 147          curl_setopt( $t_curl, CURLOPT_POST, 1);
 148          curl_setopt( $t_curl, CURLOPT_POSTFIELDS, "status=$c_message" );
 149          curl_setopt( $t_curl, CURLOPT_USERPWD, "$t_username:$t_password" );
 150  
 151          $t_buffer = curl_exec( $t_curl );
 152  
 153          curl_close( $t_curl );
 154          
 155          return !is_blank( $t_buffer );
 156      }
 157  ?>


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