| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 # MantisBT - A PHP based bugtracking system 3 4 # MantisBT is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 2 of the License, or 7 # (at your option) any later version. 8 # 9 # MantisBT is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Twitter API 19 * 20 * @package CoreAPI 21 * @subpackage TwitterAPI 22 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 23 * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net 24 * @link http://www.mantisbt.org 25 * 26 * @uses bug_api.php 27 * @uses category_api.php 28 * @uses config_api.php 29 * @uses constant_inc.php 30 * @uses database_api.php 31 * @uses lang_api.php 32 * @uses news_api.php 33 * @uses project_api.php 34 * @uses user_api.php 35 * @uses utility_api.php 36 */ 37 38 require_api( 'bug_api.php' ); 39 require_api( 'category_api.php' ); 40 require_api( 'config_api.php' ); 41 require_api( 'constant_inc.php' ); 42 require_api( 'database_api.php' ); 43 require_api( 'lang_api.php' ); 44 require_api( 'news_api.php' ); 45 require_api( 'project_api.php' ); 46 require_api( 'user_api.php' ); 47 require_api( 'utility_api.php' ); 48 49 $g_twitter_enabled = null; 50 51 /** 52 * Checks if twitter is used for the current installation. 53 * returns true for enabled, false otherwise. 54 * 55 * @return true: twitter enabled, false: otherwise. 56 * @access public 57 */ 58 function twitter_enabled() { 59 global $g_twitter_enabled; 60 61 if( null === $g_twitter_enabled ) { 62 $g_twitter_enabled = !is_blank( config_get( 'twitter_username' ) ); 63 } 64 65 if( $g_twitter_enabled && !function_exists( 'curl_init' ) ) { 66 trigger_error( ERROR_TWITTER_NO_CURL_EXT, ERROR ); 67 } 68 69 return $g_twitter_enabled; 70 } 71 72 /** 73 * Posts a twitter update when a bug is resolved. 74 * 75 * @param $p_bug_id The bug id that was resolved. 76 * @access public 77 */ 78 function twitter_issue_resolved( $p_bug_id ) { 79 if( !twitter_enabled() ) { 80 return true; 81 } 82 83 $t_bug = bug_get( $p_bug_id, false ); 84 85 # Do not twitter except fixed issues 86 if( $t_bug->resolution < config_get( 'bug_resolution_fixed_threshold' ) || 87 $t_bug->resolution >= config_get( 'bug_resolution_not_fixed_threshold' ) ) { 88 return true; 89 } 90 91 # Do not twitter private bugs. 92 if( $t_bug->view_state != VS_PUBLIC ) { 93 return true; 94 } 95 96 # Do not twitter bugs belonging to private projects. 97 if( VS_PRIVATE == project_get_field( $t_bug->project_id, 'view_state' ) ) { 98 return true; 99 } 100 101 $c_bug_id = db_prepare_int( $p_bug_id ); 102 103 if( is_blank( $t_bug->fixed_in_version ) ) { 104 $t_message = sprintf( lang_get( 'twitter_resolved_no_version' ), $c_bug_id, category_full_name( $t_bug->category_id, 105 106 /* include project */ 107 false ), $t_bug->summary, user_get_name( $t_bug->handler_id ) ); 108 } else { 109 $t_message = sprintf( lang_get( 'twitter_resolved' ), $c_bug_id, category_full_name( $t_bug->category_id, 110 111 /* include project */ 112 false ), $t_bug->summary, user_get_name( $t_bug->handler_id ), $t_bug->fixed_in_version ); 113 } 114 115 return twitter_update( $t_message ); 116 } 117 118 /** 119 * Posts a twitter update when a news entry is submitted. 120 * 121 * @param $p_news_id The newly posted news id. 122 * @access public 123 */ 124 function twitter_news( $p_news_id ) { 125 if( !twitter_enabled() ) { 126 return true; 127 } 128 129 $t_news_view_state = news_get_field( $p_news_id, 'view_state' ); 130 if( VS_PUBLIC != $t_news_view_state ) { 131 return true; 132 } 133 134 $t_news_project_id = news_get_field( $p_news_id, 'project_id' ); 135 if( $t_news_project_id != ALL_PROJECTS ) { 136 $t_project_view_state = project_get_field( $t_news_project_id, 'view_state' ); 137 if( VS_PUBLIC != $t_project_view_state ) { 138 return true; 139 } 140 } 141 142 $t_news_headline = news_get_field( $p_news_id, 'headline' ); 143 144 return twitter_update( $t_news_headline ); 145 } 146 147 /** 148 * Posts an update to twitter 149 * 150 * @param $p_message The message to post. 151 * @access private 152 */ 153 function twitter_update( $p_message ) { 154 if( !twitter_enabled() ) { 155 return true; 156 } 157 158 if( is_blank( $p_message ) ) { 159 return true; 160 } 161 162 # don't prepare the string, otherwise it will be escaped twice once by MantisBT and once by Twitter 163 $c_message = $p_message; 164 165 // Set username and password 166 $t_username = config_get( 'twitter_username' ); 167 $t_password = config_get( 'twitter_password' ); 168 169 // The twitter API address 170 $t_url = 'http://twitter.com/statuses/update.xml'; 171 172 // Set up and execute the curl process 173 $t_curl = curl_init(); 174 175 curl_setopt( $t_curl, CURLOPT_URL, $t_url ); 176 curl_setopt( $t_curl, CURLOPT_CONNECTTIMEOUT, 2 ); 177 curl_setopt( $t_curl, CURLOPT_RETURNTRANSFER, 1 ); 178 curl_setopt( $t_curl, CURLOPT_POST, 1 ); 179 curl_setopt( $t_curl, CURLOPT_POSTFIELDS, 'status=' . $c_message ); 180 curl_setopt( $t_curl, CURLOPT_USERPWD, $t_username . ':' . $t_password ); 181 182 $t_buffer = curl_exec( $t_curl ); 183 184 curl_close( $t_curl ); 185 186 return !is_blank( $t_buffer ); 187 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |