Changeset 138201
- Timestamp:
- 07/23/2009 06:59:03 AM (17 years ago)
- Location:
- nitwpress/trunk
- Files:
-
- 2 edited
-
nitwpress.php (modified) (17 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
nitwpress/trunk/nitwpress.php
r136877 r138201 6 6 Author: sakuratan 7 7 Author URI: http://sakuratan.biz/ 8 Version: 0.9.2. 18 Version: 0.9.2.2 9 9 */ 10 10 … … 31 31 */ 32 32 33 define('NITWPRESS_PLUGINS', '/wp-content/plugins/nitwpress/'); 34 define('NITWPRESS_CACHES', NITWPRESS_PLUGINS . 'caches/'); 35 define('NITWPRESS_CACHEDIR', ABSPATH . NITWPRESS_CACHES); 33 define( 'NITWPRESS_CACHES', '/nitwpress/caches' ); 36 34 37 35 /* … … 52 50 ); 53 51 54 return array_merge($defaults, get_option('nitwpress_options', array())); 52 return array_merge( $defaults, 53 get_option( 'nitwpress_options', array() ) ); 55 54 } 56 55 … … 58 57 * Update options. 59 58 */ 60 function nitwpress_update_options( &$newvars, $prefix='') {59 function nitwpress_update_options( &$newvars, $prefix='' ) { 61 60 $options = nitwpress_get_options(); 62 61 … … 64 63 $options['iconframe'] = false; 65 64 66 foreach ( $options as $key => $value) {65 foreach ( $options as $key => $value ) { 67 66 $nkey = "{$prefix}{$key}"; 68 if ( array_key_exists($nkey, $newvars)) {67 if ( array_key_exists( $nkey, $newvars ) ) { 69 68 $newvalue = $newvars[$nkey]; 70 if ( ($key == 'logo' || $key == 'iconframe') && $newvalue) {69 if ( ( $key == 'logo' || $key == 'iconframe' ) && $newvalue ) { 71 70 $options[$key] = true; 72 } elseif ( $key == 'interval') {71 } elseif ( $key == 'interval' ) { 73 72 $options[$key] = (int)$newvalue; 74 73 } else { … … 78 77 } 79 78 80 update_option( 'nitwpress_options', $options);79 update_option( 'nitwpress_options', $options ); 81 80 } 82 81 … … 85 84 */ 86 85 function nitwpress_update_caches() { 87 require_once dirname( __file__) . '/twitter.php';86 require_once dirname( __file__ ) . '/twitter.php'; 88 87 89 88 $options = nitwpress_get_options(); 90 if ( !$options['username'])89 if ( !$options['username'] ) 91 90 return; 92 91 93 nitwpress_twitter_update_caches(NITWPRESS_CACHEDIR, $options['username'], 94 $options['password']); 92 nitwpress_twitter_update_caches( 93 WP_PLUGIN_DIR . NITWPRESS_CACHES, 94 $options['username'], $options['password'] ); 95 95 } 96 96 … … 98 98 * Implode with rawurlencode. 99 99 */ 100 function nitwpress_rawurlencode_array( &$arr) {101 if ( !$arr)100 function nitwpress_rawurlencode_array( &$arr ) { 101 if ( !$arr ) 102 102 return ''; 103 103 104 104 $s = ''; 105 foreach ( $arr as $key => $value) {106 if ( $s)105 foreach ( $arr as $key => $value ) { 106 if ( $s ) 107 107 $s .= '&'; 108 $s .= rawurlencode( $key) . '=' . rawurlencode($value);108 $s .= rawurlencode( $key ) . '=' . rawurlencode( $value ); 109 109 } 110 110 return $s; … … 114 114 * The widget. 115 115 */ 116 function nitwpress_sidebar_widget( $args) {117 extract( $args);116 function nitwpress_sidebar_widget( $args ) { 117 extract( $args ); 118 118 119 119 echo $before_widget; 120 120 121 121 $options = nitwpress_get_options(); 122 if ($options['username']) : 123 $username = htmlspecialchars($options['username']); 124 $siteurl = get_option('siteurl'); 125 $plugin = $siteurl . NITWPRESS_PLUGINS; 126 $swf = htmlspecialchars("{$plugin}nitwpress.swf"); 127 $base = htmlspecialchars("{$siteurl}" . NITWPRESS_CACHES); 122 if ( $options['username'] ) : 123 $username = htmlspecialchars( $options['username'] ); 124 $siteurl = get_option( 'siteurl' ); 125 $swf = htmlspecialchars( WP_PLUGIN_URL . '/nitwpress/nitwpress.swf' ); 126 $base = htmlspecialchars( WP_PLUGIN_URL . NITWPRESS_CACHES . '/' ); 128 127 129 128 $_flashvars = array(); 130 129 131 if ( $options['fontcolor'] &&132 strcasecmp($options['fontcolor'], 'auto') != 0) {133 $_flashvars['fontcolor'] = preg_replace('/^#*/', '',134 $options['fontcolor']);135 } 136 137 if ( $options['linkcolor'] &&138 strcasecmp($options['linkcolor'], 'auto') != 0) {139 $_flashvars['linkcolor'] = preg_replace('/^#*/', '',140 $options['linkcolor']);141 } 142 143 if ( !$options['logo']) {130 if ( $options['fontcolor'] && 131 strcasecmp( $options['fontcolor'], 'auto' ) != 0 ) { 132 $_flashvars['fontcolor'] = 133 preg_replace( '/^#*/', '', $options['fontcolor'] ); 134 } 135 136 if ( $options['linkcolor'] && 137 strcasecmp( $options['linkcolor'], 'auto' ) != 0 ) { 138 $_flashvars['linkcolor'] = 139 preg_replace( '/^#*/', '', $options['linkcolor'] ); 140 } 141 142 if ( !$options['logo'] ) { 144 143 $_flashvars['disablelogo'] = '1'; 145 144 } 146 145 147 if ( $options['iconframe']) {146 if ( $options['iconframe'] ) { 148 147 $_flashvars['iconframe'] = '1'; 149 $_flashvars['iconframecolor'] = preg_replace('/^#*/', '', 150 $options['iconframecolor']); 151 } 152 153 $flashvars = nitwpress_rawurlencode_array($_flashvars); 154 155 if ($options['widgetstyles']) { 156 $style = ' style="'.htmlspecialchars($options['widgetstyles']).'"'; 148 $_flashvars['iconframecolor'] = 149 preg_replace( '/^#*/', '', $options['iconframecolor'] ); 150 } 151 152 $flashvars = nitwpress_rawurlencode_array( $_flashvars ); 153 154 if ( $options['widgetstyles'] ) { 155 $style = ' style="' . 156 htmlspecialchars( $options['widgetstyles'] ) . '"'; 157 157 } else { 158 158 $style = ''; 159 159 } 160 160 161 if ( $options['widgettitle']) :161 if ( $options['widgettitle'] ) : 162 162 ?> 163 <h2 class="widgettitle"><?php echo htmlspecialchars( $options['widgettitle']) ?></h2>163 <h2 class="widgettitle"><?php echo htmlspecialchars( $options['widgettitle'] ) ?></h2> 164 164 <?php 165 165 endif; … … 194 194 * Display errors. 195 195 */ 196 function nitwpress_display_error( $mesg) {196 function nitwpress_display_error( $mesg ) { 197 197 echo "<p style=\"color:red\">ERROR: {$mesg}</p>"; 198 198 } … … 202 202 */ 203 203 function nitwpress_widget_control() { 204 if ( array_key_exists('nitwpress_username', $_POST)) {205 nitwpress_update_options( $_POST, 'nitwpress_');204 if ( array_key_exists( 'nitwpress_username', $_POST ) ) { 205 nitwpress_update_options( $_POST, 'nitwpress_' ); 206 206 nitwpress_update_caches(); 207 207 } … … 210 210 ?> 211 211 <form method="post"> 212 <h3><?php _e( 'Twitter account', 'nitwpress') ?></h3>212 <h3><?php _e( 'Twitter account', 'nitwpress' ) ?></h3> 213 213 <table> 214 214 <tr> 215 <td><?php _e( 'Username:', 'nitwpress') ?></td>216 <td><input type="text" name="nitwpress_username" value="<?php echo htmlspecialchars( $options['username']) ?>" size="20" /></td>215 <td><?php _e( 'Username:', 'nitwpress' ) ?></td> 216 <td><input type="text" name="nitwpress_username" value="<?php echo htmlspecialchars( $options['username'] ) ?>" size="20" /></td> 217 217 </tr> 218 218 219 219 <tr> 220 <td><?php _e( 'Password:', 'nitwpress') ?></td>221 <td><input type="password" name="nitwpress_password" value="<?php echo htmlspecialchars( $options['password']) ?>" size="20" /></td>220 <td><?php _e( 'Password:', 'nitwpress' ) ?></td> 221 <td><input type="password" name="nitwpress_password" value="<?php echo htmlspecialchars( $options['password'] ) ?>" size="20" /></td> 222 222 </tr> 223 223 </table> 224 224 225 <h3><?php _e( 'Widget title', 'nitwpress') ?></h3>226 227 <div><input type="text" name="nitwpress_widgettitle" value="<?php echo htmlspecialchars( $options['widgettitle']) ?>" style="width:100%" /></div>228 229 <p><?php _e( '(The widget suppress the widget title when this field is empty.)', 'nitwpress') ?></p>230 231 <h3><?php _e( 'CSS for widget content', 'nitwpress') ?></h3>232 233 <div><input type="text" name="nitwpress_widgetstyles" value="<?php echo htmlspecialchars( $options['widgetstyles']) ?>" style="width:100%" /></div>234 <p><?php _e( '(The widget content area have "nitwpress_widget_content" class. You can use the CSS class for designing the widget with out this field.)', 'nitwpress') ?></p>235 236 <h3><?php _e( 'Font colors', 'nitwpress') ?></h3>225 <h3><?php _e( 'Widget title', 'nitwpress' ) ?></h3> 226 227 <div><input type="text" name="nitwpress_widgettitle" value="<?php echo htmlspecialchars( $options['widgettitle'] ) ?>" style="width:100%" /></div> 228 229 <p><?php _e( '(The widget suppress the widget title when this field is empty.)', 'nitwpress' ) ?></p> 230 231 <h3><?php _e( 'CSS for widget content', 'nitwpress' ) ?></h3> 232 233 <div><input type="text" name="nitwpress_widgetstyles" value="<?php echo htmlspecialchars( $options['widgetstyles'] ) ?>" style="width:100%" /></div> 234 <p><?php _e( '(The widget content area have "nitwpress_widget_content" class. You can use the CSS class for designing the widget with out this field.)', 'nitwpress' ) ?></p> 235 236 <h3><?php _e( 'Font colors', 'nitwpress' ) ?></h3> 237 237 238 238 <table> 239 239 <tr> 240 <td><?php _e( 'Color of comments:', 'nitwpress') ?></td>241 <td><input type="text" name="nitwpress_fontcolor" value="<?php echo htmlspecialchars( $options['fontcolor']) ?>" size="7" /></td>240 <td><?php _e( 'Color of comments:', 'nitwpress' ) ?></td> 241 <td><input type="text" name="nitwpress_fontcolor" value="<?php echo htmlspecialchars( $options['fontcolor'] ) ?>" size="7" /></td> 242 242 </tr> 243 243 <tr> 244 <td><?php _e( 'Color of links:', 'nitwpress') ?></td>245 <td><input type="text" name="nitwpress_linkcolor" value="<?php echo htmlspecialchars( $options['linkcolor']) ?>" size="7" /></td>244 <td><?php _e( 'Color of links:', 'nitwpress' ) ?></td> 245 <td><input type="text" name="nitwpress_linkcolor" value="<?php echo htmlspecialchars( $options['linkcolor'] ) ?>" size="7" /></td> 246 246 </tr> 247 247 </table> 248 248 249 <p><?php _e( '(Use hash color code (e.g. #ffffff) or "auto" for these fields. HTML color name (e.g. white) is not acceptable. The widget will read default font and link colors from Twitter API if you choose "auto".)', 'nitwpress', 'nitwpress') ?></p>250 <h3><?php _e( 'Frame for icon image', 'nitwpress') ?></h3>251 252 <p><input type="checkbox" id="nitwpress_iconframe_checkbox" name="nitwpress_iconframe" value="1" <?php if ( $options['iconframe']) { echo 'checked="checked"'; } ?> />253 <label for="nitwpress_iconframe_checkbox"><?php _e( 'Enable icon image frame.', 'nitwpress') ?></label></p>254 <p><?php _e( 'Color of icon frame:', 'nitwpress') ?> <input type="text" name="nitwpress_iconframecolor" value="<?php echo htmlspecialchars($options['iconframecolor']) ?>" size="7" /><br />255 <?php _e( '(Use hash color code (e.g. #ffffff) for this field. HTML color name (e.g. white) is not acceptable.)', 'nitwpress') ?></p>256 257 <h3><?php _e( 'Miscellaneous options', 'nitwpress') ?></h3>258 259 <p><?php _e( 'Cache updating interval:', 'nitwpress') ?> <input type="text" name="nitwpress_interval" value="<?php echo htmlspecialchars($options['interval']) ?>" size="3" /> <?php _e('(minutes)', 'nitwpress') ?></p>260 261 <p><input type="checkbox" id="nitwpress_logo_checkbox" name="nitwpress_logo" value="1" <?php if ( $options['logo']) { echo 'checked="checked"'; } ?> />262 <label for="nitwpress_logo_checkbox"><?php _e( 'Display NiTwPress logo on Flash.', 'nitwpress') ?></label></p>249 <p><?php _e( '(Use hash color code (e.g. #ffffff) or "auto" for these fields. HTML color name (e.g. white) is not acceptable. The widget will read default font and link colors from Twitter API if you choose "auto".)', 'nitwpress', 'nitwpress' ) ?></p> 250 <h3><?php _e( 'Frame for icon image', 'nitwpress' ) ?></h3> 251 252 <p><input type="checkbox" id="nitwpress_iconframe_checkbox" name="nitwpress_iconframe" value="1" <?php if ( $options['iconframe'] ) { echo 'checked="checked"'; } ?> /> 253 <label for="nitwpress_iconframe_checkbox"><?php _e( 'Enable icon image frame.', 'nitwpress' ) ?></label></p> 254 <p><?php _e( 'Color of icon frame:', 'nitwpress' ) ?> <input type="text" name="nitwpress_iconframecolor" value="<?php echo htmlspecialchars( $options['iconframecolor'] ) ?>" size="7" /><br /> 255 <?php _e( '(Use hash color code (e.g. #ffffff) for this field. HTML color name (e.g. white) is not acceptable.)', 'nitwpress' ) ?></p> 256 257 <h3><?php _e( 'Miscellaneous options', 'nitwpress' ) ?></h3> 258 259 <p><?php _e( 'Cache updating interval:', 'nitwpress' ) ?> <input type="text" name="nitwpress_interval" value="<?php echo htmlspecialchars( $options['interval'] ) ?>" size="3" /> <?php _e( '(minutes)', 'nitwpress' ) ?></p> 260 261 <p><input type="checkbox" id="nitwpress_logo_checkbox" name="nitwpress_logo" value="1" <?php if ( $options['logo'] ) { echo 'checked="checked"'; } ?> /> 262 <label for="nitwpress_logo_checkbox"><?php _e( 'Display NiTwPress logo on Flash.', 'nitwpress' ) ?></label></p> 263 263 </form> 264 264 <?php 265 265 266 if (!is_dir(NITWPRESS_CACHEDIR)) { 267 nitwpress_display_error(sprintf(__("Missing permissions for writing on %s. Fix the error before enter your Twitter account.", 'nitwpress'), NITWPRESS_CACHEDIR)); 268 } 269 270 if (!function_exists('curl_init')) { 271 nitwpress_display_error(__('Missing cURL module.', 'nitwpress')); 266 $dir = WP_PLUGIN_DIR . NITWPRESS_CACHES; 267 if ( !is_dir( $dir ) ) { 268 nitwpress_display_error( sprintf( __( "Missing permissions for writing on %s. Fix the error before enter your Twitter account.", 'nitwpress' ), $dir ) ); 269 } 270 271 if ( !function_exists( 'curl_init' ) ) { 272 nitwpress_display_error( __( 'Missing cURL module.', 'nitwpress' ) ); 272 273 } 273 274 } … … 277 278 */ 278 279 function nitwpress_init() { 279 require_once( ABSPATH . 'wp-includes/widgets.php');280 load_plugin_textdomain( 'nitwpress', 'wp-content/plugins/nitwpress/po',281 'nitwpress/po');282 register_sidebar_widget( 'NiTwPress', 'nitwpress_sidebar_widget');283 register_widget_control( 'NiTwPress', 'nitwpress_widget_control');284 } 285 286 add_action( 'init', 'nitwpress_init');280 require_once( ABSPATH . 'wp-includes/widgets.php' ); 281 load_plugin_textdomain( 'nitwpress', 'wp-content/plugins/nitwpress/po', 282 'nitwpress/po' ); 283 register_sidebar_widget( 'NiTwPress', 'nitwpress_sidebar_widget' ); 284 register_widget_control( 'NiTwPress', 'nitwpress_widget_control' ); 285 } 286 287 add_action( 'init', 'nitwpress_init' ); 287 288 288 289 /* … … 290 291 */ 291 292 function hitwpress_activation() { 292 wp_schedule_event( time(), 'nitwpress', 'nitwpress_hourly_event');293 wp_schedule_event( time(), 'nitwpress', 'nitwpress_hourly_event' ); 293 294 } 294 295 … … 297 298 */ 298 299 function nitwpress_deactivation() { 299 wp_clear_scheduled_hook( 'nitwpress_hourly_event');300 wp_clear_scheduled_hook( 'nitwpress_hourly_event' ); 300 301 } 301 302 … … 303 304 * Filter for wp_cron that appends nitwpress schedule event. 304 305 */ 305 function nitwpress_add_cron( $sched) {306 if ( !array_key_exists('nitwpress', $sched)) {307 $options = get_option( 'nitwpress_options');308 if ( array_key_exists('interval', $options)) {306 function nitwpress_add_cron( $sched ) { 307 if ( !array_key_exists( 'nitwpress', $sched ) ) { 308 $options = get_option( 'nitwpress_options' ); 309 if ( array_key_exists( 'interval', $options ) ) { 309 310 $sched['nitwpress'] = array( 310 311 'interval' => (int)$options['interval'] * 60, 311 'display' => __( 'Schedule for NiTwPress plugins', 'nitwpress')312 'display' => __( 'Schedule for NiTwPress plugins', 'nitwpress' ) 312 313 ); 313 314 } … … 316 317 } 317 318 318 register_activation_hook( __FILE__, 'hitwpress_activation');319 register_deactivation_hook( __FILE__, 'nitwpress_deactivation');320 321 add_action( 'nitwpress_hourly_event', 'nitwpress_update_caches');322 add_filter( 'cron_schedules', 'nitwpress_add_cron');319 register_activation_hook( __FILE__, 'hitwpress_activation' ); 320 register_deactivation_hook( __FILE__, 'nitwpress_deactivation' ); 321 322 add_action( 'nitwpress_hourly_event', 'nitwpress_update_caches' ); 323 add_filter( 'cron_schedules', 'nitwpress_add_cron' ); 323 324 324 325 ?> -
nitwpress/trunk/readme.txt
r136877 r138201 5 5 Requires at least: 2.7.0 6 6 Tested up to: 2.7.1 7 Stable tag: 0.9.2. 17 Stable tag: 0.9.2.2 8 8 9 9 A Twitter client widget. … … 22 22 23 23 == Changelog == 24 25 = 0.9.2.2 = 26 * Using WP_PLUGIN_URL and WP_PLUGIN_DIR. 27 * Spaces for following the wordPress coding standards. 24 28 25 29 = 0.9.2.1 =
Note: See TracChangeset
for help on using the changeset viewer.