Plugin Directory

Changeset 1889361


Ignore:
Timestamp:
06/08/2018 04:27:59 AM (8 years ago)
Author:
velathemes
Message:

version 1.0.4

File:
1 edited

Legend:

Unmodified
Added
Removed
  • astore-companion/trunk/astore-companion.php

    r1889355 r1889361  
    154154    }
    155155   
     156   
     157    public static function replaceStar($str, $start, $length = 0)
     158{
     159  $i = 0;
     160  $star = '';
     161  if($start >= 0) {
     162   if($length > 0) {
     163    $str_len = strlen($str);
     164    $count = $length;
     165    if($start >= $str_len) {//当开始的下标大于字符串长度的时候,就不做替换了
     166     $count = 0;
     167    }
     168   }elseif($length < 0){
     169    $str_len = strlen($str);
     170    $count = abs($length);
     171    if($start >= $str_len) {//当开始的下标大于字符串长度的时候,由于是反向的,就从最后那个字符的下标开始
     172     $start = $str_len - 1;
     173    }
     174    $offset = $start - $count + 1;//起点下标减去数量,计算偏移量
     175    $count = $offset >= 0 ? abs($length) : ($start + 1);//偏移量大于等于0说明没有超过最左边,小于0了说明超过了最左边,就用起点到最左边的长度
     176    $start = $offset >= 0 ? $offset : 0;//从最左边或左边的某个位置开始
     177   }else {
     178    $str_len = strlen($str);
     179    $count = $str_len - $start;//计算要替换的数量
     180   }
     181  }else {
     182   if($length > 0) {
     183    $offset = abs($start);
     184    $count = $offset >= $length ? $length : $offset;//大于等于长度的时候 没有超出最右边
     185   }elseif($length < 0){
     186    $str_len = strlen($str);
     187    $end = $str_len + $start;//计算偏移的结尾值
     188    $offset = abs($start + $length) - 1;//计算偏移量,由于都是负数就加起来
     189    $start = $str_len - $offset;//计算起点值
     190    $start = $start >= 0 ? $start : 0;
     191    $count = $end - $start + 1;
     192   }else {
     193    $str_len = strlen($str);
     194    $count = $str_len + $start + 1;//计算需要偏移的长度
     195    $start = 0;
     196   }
     197  }
     198 
     199  while ($i < $count) {
     200   $star .= '*';
     201   $i++;
     202  }
     203 
     204  return substr_replace($str, $star, $start, $count);
     205}
    156206    /**
    157207     * Admin menu
     
    192242            $astore_companion_options = wp_parse_args($options,AStoreCompanion::default_options());
    193243           
     244           
    194245        ?>
    195246        <div class="wrap">
    196247
    197248          <div class="license">
     249         
     250          <?php if($astore_companion_options['license_key'] == '' ):?>
    198251        <p><?php _e( 'AStore License Key', 'astore-companion' );?>: <input size="50" name="astore_companion_options[license_key]" value="<?php echo $astore_companion_options['license_key'];?>" type="text" /></p>
    199252        <p></p>
     253        <?php
     254       
     255        else:
     256        $astore_companion_options['license_key'] = AStoreCompanion::replaceStar($astore_companion_options['license_key'],10,8);
     257        ?>
     258        <p><?php _e( 'AStore License Key', 'astore-companion' );?>: <input size="50" disabled="disabled" name="astore_companion_options[license_key_hide]" value="<?php echo $astore_companion_options['license_key'];?>" type="text" /><input size="50" type="hidden" name="astore_companion_options[license_key]" value="" type="text" /></p>
     259        <p></p>
     260       
     261        <?php endif;?>
    200262         
    201263           </div>
    202264            <p class="submit">
    203             <input type="submit" class="button-primary" value="<?php _e('Save Changes','astore-companion');?>" />
     265            <?php if($astore_companion_options['license_key'] == '' ):?>
     266            <input type="submit" class="button-primary" value="<?php _e('Active','astore-companion');?>" />
     267            <?php   else:?>
     268            <input type="submit" class="button-primary" value="<?php _e('Deactivate','astore-companion');?>" />
     269         <?php endif;?>
    204270            </p>
    205271        </div>
Note: See TracChangeset for help on using the changeset viewer.