Plugin Directory

Changeset 138201


Ignore:
Timestamp:
07/23/2009 06:59:03 AM (17 years ago)
Author:
sakuratan
Message:

Using WP_PLUGIN_URL and WP_PLUGIN_DIR.
Spaces for following the wordPress coding standards.

Location:
nitwpress/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nitwpress/trunk/nitwpress.php

    r136877 r138201  
    66Author: sakuratan
    77Author URI: http://sakuratan.biz/
    8 Version: 0.9.2.1
     8Version: 0.9.2.2
    99*/
    1010
     
    3131*/
    3232
    33 define('NITWPRESS_PLUGINS', '/wp-content/plugins/nitwpress/');
    34 define('NITWPRESS_CACHES', NITWPRESS_PLUGINS . 'caches/');
    35 define('NITWPRESS_CACHEDIR', ABSPATH . NITWPRESS_CACHES);
     33define( 'NITWPRESS_CACHES', '/nitwpress/caches' );
    3634
    3735/*
     
    5250    );
    5351
    54     return array_merge($defaults, get_option('nitwpress_options', array()));
     52    return array_merge( $defaults,
     53            get_option( 'nitwpress_options', array() ) );
    5554}
    5655
     
    5857 * Update options.
    5958 */
    60 function nitwpress_update_options(&$newvars, $prefix='') {
     59function nitwpress_update_options( &$newvars, $prefix='' ) {
    6160    $options = nitwpress_get_options();
    6261
     
    6463    $options['iconframe'] = false;
    6564
    66     foreach ($options as $key => $value) {
     65    foreach ( $options as $key => $value ) {
    6766    $nkey = "{$prefix}{$key}";
    68     if (array_key_exists($nkey, $newvars)) {
     67    if ( array_key_exists( $nkey, $newvars ) ) {
    6968        $newvalue = $newvars[$nkey];
    70         if (($key == 'logo' || $key == 'iconframe') && $newvalue) {
     69        if ( ( $key == 'logo' || $key == 'iconframe' ) && $newvalue ) {
    7170        $options[$key] = true;
    72         } elseif ($key == 'interval') {
     71        } elseif ( $key == 'interval' ) {
    7372        $options[$key] = (int)$newvalue;
    7473        } else {
     
    7877    }
    7978
    80     update_option('nitwpress_options', $options);
     79    update_option( 'nitwpress_options', $options );
    8180}
    8281
     
    8584 */
    8685function nitwpress_update_caches() {
    87     require_once dirname(__file__) . '/twitter.php';
     86    require_once dirname( __file__ ) . '/twitter.php';
    8887
    8988    $options = nitwpress_get_options();
    90     if (!$options['username'])
     89    if ( !$options['username'] )
    9190    return;
    9291
    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'] );
    9595}
    9696
     
    9898 * Implode with rawurlencode.
    9999 */
    100 function nitwpress_rawurlencode_array(&$arr) {
    101     if (!$arr)
     100function nitwpress_rawurlencode_array( &$arr ) {
     101    if ( !$arr )
    102102    return '';
    103103
    104104    $s = '';
    105     foreach ($arr as $key => $value) {
    106     if ($s)
     105    foreach ( $arr as $key => $value ) {
     106    if ( $s )
    107107        $s .= '&';
    108     $s .= rawurlencode($key) . '=' . rawurlencode($value);
     108    $s .= rawurlencode( $key ) . '=' . rawurlencode( $value );
    109109    }
    110110    return $s;
     
    114114 * The widget.
    115115 */
    116 function nitwpress_sidebar_widget($args) {
    117     extract($args);
     116function nitwpress_sidebar_widget( $args ) {
     117    extract( $args );
    118118
    119119    echo $before_widget;
    120120
    121121    $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 . '/' );
    128127
    129128    $_flashvars = array();
    130129
    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'] ) {
    144143        $_flashvars['disablelogo'] = '1';
    145144    }
    146145
    147     if ($options['iconframe']) {
     146    if ( $options['iconframe'] ) {
    148147        $_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'] ) . '"';
    157157    } else {
    158158        $style = '';
    159159    }
    160160
    161     if ($options['widgettitle']) :
     161    if ( $options['widgettitle'] ) :
    162162?>
    163 <h2 class="widgettitle"><?php echo htmlspecialchars($options['widgettitle']) ?></h2>
     163<h2 class="widgettitle"><?php echo htmlspecialchars( $options['widgettitle'] ) ?></h2>
    164164<?php
    165165    endif;
     
    194194 * Display errors.
    195195 */
    196 function nitwpress_display_error($mesg) {
     196function nitwpress_display_error( $mesg ) {
    197197    echo "<p style=\"color:red\">ERROR: {$mesg}</p>";
    198198}
     
    202202 */
    203203function 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_' );
    206206    nitwpress_update_caches();
    207207    }
     
    210210?>
    211211<form method="post">
    212   <h3><?php _e('Twitter account', 'nitwpress') ?></h3>
     212  <h3><?php _e( 'Twitter account', 'nitwpress' ) ?></h3>
    213213  <table>
    214214    <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>
    217217    </tr>
    218218
    219219    <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>
    222222    </tr>
    223223  </table>
    224224
    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 &quot;nitwpress_widget_content&quot; 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 &quot;nitwpress_widget_content&quot; 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>
    237237
    238238  <table>
    239239    <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>
    242242    </tr>
    243243    <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>
    246246    </tr>
    247247  </table>
    248248
    249   <p><?php _e('(Use hash color code (e.g. #ffffff) or &quot;auto&quot; 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 &quot;auto&quot;.)', '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 &quot;auto&quot; 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 &quot;auto&quot;.)', '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>
    263263</form>
    264264<?php
    265265
    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' ) );
    272273    }
    273274}
     
    277278 */
    278279function 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
     287add_action( 'init', 'nitwpress_init' );
    287288
    288289/*
     
    290291 */
    291292function hitwpress_activation() {
    292     wp_schedule_event(time(), 'nitwpress', 'nitwpress_hourly_event');
     293    wp_schedule_event( time(), 'nitwpress', 'nitwpress_hourly_event' );
    293294}
    294295
     
    297298 */
    298299function nitwpress_deactivation() {
    299     wp_clear_scheduled_hook('nitwpress_hourly_event');
     300    wp_clear_scheduled_hook( 'nitwpress_hourly_event' );
    300301}
    301302
     
    303304 * Filter for wp_cron that appends nitwpress schedule event.
    304305 */
    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)) {
     306function nitwpress_add_cron( $sched ) {
     307    if ( !array_key_exists( 'nitwpress', $sched ) ) {
     308    $options = get_option( 'nitwpress_options' );
     309    if ( array_key_exists( 'interval', $options ) ) {
    309310        $sched['nitwpress'] = array(
    310311        'interval' => (int)$options['interval'] * 60,
    311         'display' => __('Schedule for NiTwPress plugins', 'nitwpress')
     312        'display' => __( 'Schedule for NiTwPress plugins', 'nitwpress' )
    312313        );
    313314    }
     
    316317}
    317318
    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');
     319register_activation_hook( __FILE__, 'hitwpress_activation' );
     320register_deactivation_hook( __FILE__, 'nitwpress_deactivation' );
     321
     322add_action( 'nitwpress_hourly_event', 'nitwpress_update_caches' );
     323add_filter( 'cron_schedules', 'nitwpress_add_cron' );
    323324
    324325?>
  • nitwpress/trunk/readme.txt

    r136877 r138201  
    55Requires at least: 2.7.0
    66Tested up to: 2.7.1
    7 Stable tag: 0.9.2.1
     7Stable tag: 0.9.2.2
    88
    99A Twitter client widget.
     
    2222
    2323== Changelog ==
     24
     25= 0.9.2.2 =
     26* Using WP_PLUGIN_URL and WP_PLUGIN_DIR.
     27* Spaces for following the wordPress coding standards.
    2428
    2529= 0.9.2.1 =
Note: See TracChangeset for help on using the changeset viewer.