关于WordPress中提示has_cap的问题

WordPress 中不同用户等级拥有不同的操作权限,这给我们的网站安全提供了很大的保障。在 WordPress 2.0 以前,WP 插件中使用数字(用户等级)来标识不同的权限级别。这显然让程序的可阅读性大打折扣。所以从 WordPress 2.0 开始就启用了新的权限标识符号,使用有具体含义的英文字符串,同时保留原来的那一套表示方法。很多插件作者并没有采用新的权限表示方式,因而在开启 WordPress 的调试模式后,用户会看到警告。

>英文版本的警告类似于,

Notice: has_cap was called with an argument that is deprecated since version 2.0! Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead. in ......\wp-includes\functions.php on line 2998

为了安全,上面的语句中隐去了绝对路径而代之以省略号。

中文版本的警告类似于,

Notice: 自 2.0 版本起,已不建议给 has_cap 传入一个参数!插件和主题中,用户等级的使用已不被支持。请换用角色和权限。 in ....../wp-includes/functions.php on line 2998

可以看到,只是“不建议”,并不是完全不能用了。

要解决这个问题,只需要将插件(也许还包括某些主题)中用到的权限声明的表示方式替换为新的方式就可以了。

1. 定位需要改写的语句

首先要定位到需要改写的语句,这是个比较麻烦的任务。

从上面的警告信息中并不能直接知道是哪个文件调用了 functions.php 中的 has_cap 函数。所以这里只是给个思路,无法给出明确的方法。

对于插件,一般是因为插件需要在 WordPress 的管理后台创建插件的设置页面时进行权限声明的。比如在 WordPress Revision 插件中遇到的情况就是这样。出现这种情况的标志性语句是,

add_options_page

只要在插件源文件中搜索 add_options_page 关键词即可定位。

如果不是这种情况,那就可以挨个儿禁用 WP 中的插件,同时刷新页面以确定是否是当前插件造成的。如果恰好发现该警告信息不再提示了,就说明是当前的插件。然后在该插件的源文件中去找相关的语句。

另外,还可以通过在 WP 后台中操作时出现错误提示的路径信息来缩小检查范围。如果有什么需要,可以留言咨询。

2. 改写表达方式

如果定位到了出问题的 PHP 语句,改写表达方式就很简单了。下面一节介绍了 WordPress 中新旧角色权限表达方式的对比。只需要将原来的表示用户级别的数字改成新的表示权限的字符串就可以了。

例如,原来的 PHP 语句为,

add_options_page('Delete-Revision', 'Delete-Revision',8, basename(__FILE__), 'my_options_delete_revision');

该语句因为要在 WordPress 后台添加一个插件的“选项”页面,因而需要用到 WordPress 中的第 8 级权限。查到对应的新的权限字符串为 'manage_options'。对应修改为,

add_options_page('Delete-Revision', 'Delete-Revision', 'manage_options', basename(__FILE__), 'my_options_delete_revision');

只需要改其中那个数字 8,别的不需要动。

应该注意的是,根据 PHP 的规则,传递的参数如果是整型数字,可以不用加单引号,但是改成字符串之后,我们需要用英文半角的单引号将该字符串包起来。

3. 新旧权限表示方式对照

WordPress Codex 中有关于旧版本数字式用户级别和新的字符串式权限声明的详细说明可供参考。

在数字式用户级别页面的 3.12 User Level Capability Table 表格中列出了 11 个用户级别对应的权限。而在字符串式权限声明页面中 3.8 Capability vs. Role Table 一节里列举了所有权限字符串所代表的权限级别(对应于超级管理员、管理员等)。

原先的数字式级别与新的字符串式权限之间并不是一一对应的。具体应该将数字换成哪个字符串需要仔细斟酌。可能还需要根据在本文第 1 小节中定位出的 PHP 语句来辅助判断。原则上,权限在够用的前提下越小越好

例如,前面的例子中需要增加 options 页面,那肯定是管理员级别的权限。增加 options 页面的目的就是保存该插件的设置信息,这些信息是需要写入到 WordPress 数据库的 options 表中的。所以,可以确定为 manage_options 这个字符串。

在 Capabilities 一节中详细解释了各个字符串所代表的操作权限的范围。而在 User Levels 一节中则给出了旧式数字用户等级所对应的权限范围,方便缩小查找权限字符串的范围。8-10 级对应于管理员,3-7 级对应于编辑,2 级是作者,1 级是贡献者,0 级是权限最低的订阅者。

参考链接


关于 WP 中提示 has_cap 的问题

WordPress插件的语言国际化

$ brew install wp-cli

# Create a POT file for the WordPress plugin/theme in the current directory
# wp i18n make-pot . languages/my-plugin.pot
# Create a POT file for the continents and cities list in WordPress core.
#wp i18n make-pot . continents-and-cities.pot --include="wp-admin/includes/continents-cities.php" --ignore-domain

$ wp i18n make-pot . languages/SpeakIt-zh_CN.po

$ brew install gettext
 
$ brew link --force gettext
 
$ brew install Gtranslator

# 比较好用的反而是QT的 Linguist, 其实直接文本编辑器编辑,更直接
$ gtranslator languages/SpeakIt-zh_CN.po

$ msgfmt -o SpeakIt-zh_CN.mo SpeakIt-zh_CN.po 

调试的时候,通过在 wp-config.php 中定义 define('WPLANG', 'zh_CN');  来切换语言类型。

参考链接


Gettext po文件编辑器

Gettext 是一个非常老牌和成熟的国际化和本地化解决方案,在 Linux 下几乎每个 GNU 程序中都能见到 Gettext 的身影。在 Gettext 中,每个 locale 对应一个 po 文件,虽说 po 文件是纯文本,但是如果用普通的文本编辑器来编辑是非常麻烦的。

正好这两天国际化 ,搜到了几个 Linux 下的 po 编辑器~,推荐 GtranslatorWordPress 翻译( i18n )的时候使用这些工具。

macOS 下安装如下命令:

$ brew install gettext

$ brew link --force gettext

$ brew install Gtranslator

$ gtranslator

继续阅读Gettext po文件编辑器

WordPress文章内容加上TTS语音朗读

浏览一些博客的时候是否有看到过在内容上面有可以选择语音朗读功能,看着感觉还是蛮炫酷的。尤其是移动端的网站阅读体验比较好,比如一些内容教程、小说类型的网站可以使用这样的功能。

这里我们一般是使用的是百度提供的TTS(Text To Speech)文本到语音功能。

如下是实现这个基本功能的插件实现的代码。如下:

<?php
/**
 * @package SpeakIt
 */
/*
Plugin Name: Speak It
Plugin URI: https://www.mobibrw.com/speakit
Description: Plugin for Speak
Version: 1.0
Author: longsky
Author URI: https://www.mobibrw.com
License: GPLv2 or later
Text Domain: SpeakIt
*/
?>
<?php
  function mbStrSplit ($string, $len = 1) { //对内容进行分割
    $start = 0;
    $strlen = mb_strlen($string);
    while ($strlen) {
      $array[] = mb_substr($string, $start, $len, "utf8");
      $string = mb_substr($string, $len, $strlen, "utf8");
      $strlen = mb_strlen($string);
    }
    return $array;
  }

  function match_chinese($chars, $encoding = 'utf8') { //过滤特殊字符串
    $pattern = ($encoding == 'utf8')?'/[\x{4e00}-\x{9fa5}a-zA-Z0-9,,。 ]/u':'/[\x80-\xFF]/';
    preg_match_all($pattern, $chars, $result);
    $temp = join('', $result[0]);
    return $temp;
  }
	
  function load_template_html($tts_uri, $ctx) {
    $template_html = '<video id="speakit_video" style="display:none">
        <source id="speakit_src" type="video/mp4">
      </video>
      <script type="text/javascript">
        var speakitOff = 0;
        var speakitUri = "'.$tts_uri.'";
        var speakitCtx = eval('.$ctx.');
        var speakitAud = document.getElementById("speakit_video");
        if (speakitCtx.length > 0) {
          speakitAud.src = speakitUri + speakitCtx[speakitOff];
        }
        function playSpeakItContent() {
          var speakitAudBtn = document.getElementById("speakit_btn");
          if (speakitAud.paused && speakitCtx.length > 0) {
            speakitAudBtn.src = "'.plugins_url('images/pause.png', __FILE__).'"; //暂停图片
            speakitAud.src = speakitUri + speakitCtx[speakitOff];
            speakitAud.onended = function() {
              speakitOff = speakitOff + 1;
              if (speakitOff < speakitCtx.length) { 
               speakitAud.src = speakitUri + speakitCtx[speakitOff];
               speakitAud.play();
              } else {
                if (!speakitAud.paused) {
                  speakitAud.pause();
                }
                speakitOff = 0;
                speakitAudBtn.src = "'.plugins_url('images/play.png', __FILE__).'"; //暂停图片
              }
			};
			speakitAud.play();
          } else {
            if (!speakitAud.paused) {
              speakitAud.pause();
            }
            speakitAudBtn.src = "'.plugins_url('images/play.png', __FILE__).'"; //播放图片
          }
        }
      </script>
      <span style="float: left; margin-right: 10px; cursor: pointer;">
        <a href="javascript:playSpeakItContent();"><img src="'.plugins_url('images/play.png', __FILE__).'" width="25" height="25" id="speakit_btn" border="0"></a>
      </span>';
			
    return $template_html;
  }

  function load_speak_html($content) {
    $str = $content;
    $str = strip_tags($str);
    $str = str_replace("、", ",", $str); //保留顿号
    $str = match_chinese($str);
    $ctx_len = mb_strlen(preg_replace('/\s/', '', html_entity_decode(strip_tags($str))), 'UTF-8');
    $r = mbStrSplit($str, 900);
    $tts_uri = "https://tts.baidu.com/text2audio?cuid=baiduid&lan=zh&ctp=1&pdt=311&tex=";
    return load_template_html($tts_uri, json_encode($r));
  }

  function speakit_main($content) {
    if(is_single()||is_feed()) {
      $html = load_speak_html($content);
      $content = $html.$content;
    }
    return $content;
  }

  add_filter ('the_content', 'speakit_main');
?>

这里我们将代码添加到WordPressplugins目录下的SpeakIt目录下。

里面有两个按钮play.png,pause.png,需要存放到SpeakIt插件的images目录下:

 

 

参考链接


ubuntu 16.04安装配置WordPress 5.3.2并建立PHP调试环境

$ sudo apt-get install apache2

$ sudo apt-get install mysql-server

$ sudo apt-get install mysql-client

$ sudo apt-get install php7.0

$ sudo apt-get install php-gd

$ sudo apt install php-mbstring

$ sudo apt install php-dom

# 如果使用了WP-Statistics统计插件,需要安装依赖
$ sudo apt-get install php7.0-curl

$ sudo apt-get install php7.0-bcmath

# PHP Zip支持,提高网络以及内存压缩工具,提升性能
$ sudo apt-get install php-zip

# PHP图像处理支持,imagick替代默认的GD图像处理,提升图像处理性能
$ sudo apt install php-imagick

# 默认imagick是不启用的,需要手工开启
$ sudo phpenmod imagick

$ sudo a2dismod mpm_prefork

$ sudo a2enmod mpm_event

$ sudo apt-get install libapache2-mod-fastcgi php7.0-fpm

$ sudo service php7.0-fpm restart

$ sudo a2enmod actions fastcgi alias proxy_fcgi

$ sudo apt-get install php-mysql

# 启用 Rewrite 模块,我们后续的WP Super Cache需要这个模块的支持
$ sudo a2enmod rewrite

$ sudo service apache2 restart

# 我们以root连接数据库,我们需要手工创建数据库,否则会出现如下错误:
# “我们能够连接到数据库服务器(这意味着您的用户名和密码正确),但未能选择wordpress数据库。”
$ mysql -u root -p -e "create database wordpress;" 

$ cd /var/www

$ sudo chown -R www-data:www-data wordpress

WordPress配置文件

<VirtualHost *:80>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	#ServerName www.example.com

	ServerAdmin webmaster@localhost
	#DocumentRoot /var/www/html
	DocumentRoot /var/www/wordpress
	<Directory /var/www/wordpress>
		#Options Indexes FollowSymLinks MultiViews
		Options FollowSymLinks MultiViews
		AllowOverride All
#		Apache 2.2 
#		FCGIWrapper /usr/bin/php5-cgi .php
#		AddHandler fcgid-script .php
#               Options ExecCGI SymLinksIfOwnerMatch
#		Apache 2.4.10
		<FilesMatch \.php$>	
			SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost"
		</FilesMatch>
		Order allow,deny
		allow from all
	</Directory>

	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	# For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, it is possible to
	# include a line for only one particular virtual host. For example the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

继续阅读ubuntu 16.04安装配置WordPress 5.3.2并建立PHP调试环境

3.5寸硬盘参数表-PMR/SMR/TDMR-2018-10-24

几个列项的说明
Recording - HDD写入技术
Capacity - HDD容量
Sector - 逻辑扇区大小, 表格里只包含了512e和4Kn
Disk - 碟片数
TB/Platter - 单碟TB大小
Helium - 是否充氦
PWR IDLE - 待机功耗瓦数
PWR TYPC - 典型运行功耗瓦数
PWR PEAK - 峰值功耗瓦数
Workload - 工作负荷 (TB/年)
UBER - 不可恢复比特误码率, 14=10^14内1个bit错误
L/UL- 磁头加载/卸载循环次数, 单位是千, 所以300=300,000次
AFR - 年化故障率
POH - 通电小时数/年
MTBF - 平均故障间隔小时数, 单位是百万, 所以0.75=750,000小时, Toshiba的数值为MTTF, 跟MTBF有所不同
Warranty - 质保年数

3.5''+SATA+HDD+Database+2018-10-24+(by+jerrytsao).xlsx

Size Recording MFG Series STD Model Capacity (TB) Disk RPM Cache (MB)
3.5'' SMR Seagate Archive ST5000AS0011 5 4 5980 128
3.5'' SMR Seagate Archive ST6000AS0002 6 6 5980 128
3.5'' SMR Seagate Archive ST8000AS0002 8 6 5980 128
3.5'' SMR Seagate Exos 5E8 ST8000AS0003 8 4 5980 256
3.5'' SMR Seagate BarraCuda ST2000DM005 2 1 5400 256
3.5'' SMR Seagate BarraCuda ST2000DM008 2 1 7200 256
3.5'' SMR Seagate BarraCuda ST3000DM007 3 2 5400 256
3.5'' SMR Seagate BarraCuda ST4000DM004 4 2 5400 256
3.5'' SMR Seagate BarraCuda ST6000DM003 6 3 5400 256
3.5'' SMR Seagate BarraCuda ST8000DM004 8 4 5400 256
3.5'' SMR Seagate SkyHawk ST3000VX009 3 2 5900 256
3.5'' SMR Seagate SkyHawk ST6000VX001 6 4 5900 256
3.5'' SMR HGST Ultrastar Archive Ha10 HMH7210A0ALE60y 10 7 7200 256
3.5'' SMR HGST Ultrastar Archive Ha10 HMH7210A0ALN60y 10 7 7200 256
3.5'' SMR HGST Ultrastar DC HC620/Hs14 HSH721414ALE6M0 14 8 7200 512
3.5'' SMR HGST Ultrastar DC HC620/Hs14 HSH721414ALN6M0 14 8 7200 512
3.5'' SMR HGST Ultrastar DC HC620 HSH721415ALE6M0 15 8 7200 512
3.5'' SMR HGST Ultrastar DC HC620 HSH721415ALE6M0 15 8 7200 512
3.5'' SMR WDC Blue WD20EZAZ 2 1 5400 256
3.5'' SMR WDC Blue WD60EZAZ 6 3 5400 256
2.5'' SMR WDC Blue WD10SPZX 1 1 5400 128
2.5'' SMR WDC Blue WD20SPZX 1 1 5400 128
2.5'' SMR WDC Black WD10SPSX 1 1 7200 64
3.5'' PMR Seagate Desktop ST1000DM003 1 1 7200 64/32
3.5'' PMR Seagate Desktop ST2000DM001 2 2/3 7200 64
3.5'' PMR Seagate Desktop ST3000DM001 3 3 7200 64
3.5'' PMR Seagate Desktop ST4000DM000 4 4 5900 64
3.5'' PMR Seagate Desktop ST5000DM002 5 6 7200 128
3.5'' PMR Seagate Desktop ST6000DM001 6 6 7200 128
3.5'' PMR Seagate Desktop ST8000DM002 8 6 7200 256
3.5'' PMR Seagate BarraCuda ST1000DM010 1 1 7200 64
3.5'' PMR Seagate BarraCuda ST2000DM006 2 2/3 7200 64
3.5'' PMR Seagate BarraCuda ST3000DM008 3 3 7200 64
3.5'' PMR Seagate BarraCuda ST4000DM005 4 3 5900 64
3.5'' PMR Seagate BarraCuda Pro ST2000DM009 2 2 7200 128
3.5'' PMR Seagate BarraCuda Pro ST4000DM006 4 4 7200 128
3.5'' PMR Seagate BarraCuda Pro ST6000DM004 6 6 7200 256
3.5'' PMR Seagate BarraCuda Pro ST8000DM005 8 6 7200 256
3.5'' PMR Seagate BarraCuda Pro ST8000DM0004 8 7 7200 256
3.5'' PMR Seagate BarraCuda Pro ST10000DM0001 10 7 7200 256
3.5'' PMR Seagate BarraCuda Pro ST12000DM0001 12 8 7200 256
3.5'' PMR+TDMR Seagate BarraCuda Pro ST14000DM0001 14 8 7200 256
3.5'' PMR Seagate SV35 ST1000VX000 1 1 7200 64
3.5'' PMR Seagate SV35 ST2000VX000 2 3 7200 64
3.5'' PMR Seagate SV35 ST3000VX000 3 3 7200 64
3.5'' PMR Seagate Surveillance ST1000VX001 1 1 5900 64
3.5'' PMR Seagate Surveillance ST2000VX003 2 2 5900 64
3.5'' PMR Seagate Surveillance ST3000VX006 3 3 5900 64
3.5'' PMR Seagate Surveillance ST3000VX002 3 3 5900 64
3.5'' PMR Seagate Surveillance ST4000VX000 4 3 5900 64
3.5'' PMR Seagate Surveillance ST5000VX001 5 5 7200 128
3.5'' PMR Seagate Surveillance ST6000VX001 6 6 7200 128
3.5'' PMR Seagate Surveillance ST8000VX002 8 6 7200 256
3.5'' PMR Seagate SkyHawk ST1000VX005 1 1 5900 64
3.5'' PMR Seagate SkyHawk ST2000VX008 2 2 5900 64
3.5'' PMR Seagate SkyHawk ST3000VX010 3 3 5900 64
3.5'' PMR Seagate SkyHawk ST4000VX007 4 3 5900 64
3.5'' PMR Seagate SkyHawk ST6000VX0023 6 5 7200 256
3.5'' PMR Seagate SkyHawk ST8000VX0022 8 6 7200 256
3.5'' PMR Seagate SkyHawk ST10000VX0008 10 7 7200 256
3.5'' PMR Seagate SkyHawk ST12000VX0008 12 8 7200 256
3.5'' PMR+TDMR Seagate SkyHawk ST14000VX0008 14 8 7200 256
3.5'' PMR Seagate SkyHawk AI ST8000VE0004 4 5 7200 256
3.5'' PMR Seagate SkyHawk AI ST8000VE0004 6 5 7200 256
3.5'' PMR Seagate SkyHawk AI ST8000VE0004 8 6 7200 256
3.5'' PMR Seagate SkyHawk AI ST10000VE0004 10 7 7200 256
3.5'' PMR Seagate NAS ST1000VN000 1 1 5900 64
3.5'' PMR Seagate NAS ST2000VN000 2 2 5900 64
3.5'' PMR Seagate NAS ST3000VN000 3 4 5900 64
3.5'' PMR Seagate NAS ST4000VN000 4 4 5900 64
3.5'' PMR Seagate NAS ST6000VN0021 6 6 7200 128
3.5'' PMR Seagate NAS ST8000VN0002 8 6 7200 256
3.5'' PMR Seagate IronWolf ST1000VN002 1 1 5900 64
3.5'' PMR Seagate IronWolf ST2000VN004 2 2 5900 64
3.5'' PMR Seagate IronWolf ST3000VN007 3 3 5900 64
3.5'' PMR Seagate IronWolf ST4000VN008 4 3 5900 64
3.5'' PMR Seagate IronWolf ST6000VN0033 6 5 7200 256
3.5'' PMR Seagate IronWolf ST8000VN0022 8 6 7200 256
3.5'' PMR Seagate IronWolf ST10000VN0008 10 7 7200 256
3.5'' PMR Seagate IronWolf ST12000VN0008 12 8 7200 256
3.5'' PMR+TDMR Seagate IronWolf ST14000VN0008 14 8 7200 256
3.5'' PMR Seagate Enterprise NAS ST2000VN0001 2 2 7200 128
3.5'' PMR Seagate Enterprise NAS ST3000VN0001 3 4 7200 128
3.5'' PMR Seagate Enterprise NAS ST4000VN0001 4 4 7200 128
3.5'' PMR Seagate Enterprise NAS ST5000VN0001 5 5 7200 128
3.5'' PMR Seagate Enterprise NAS ST6000VN0001 6 6 7200 128
3.5'' PMR Seagate Enterprise NAS ST6000NE0001 6 6 7200 256
3.5'' PMR Seagate Enterprise NAS ST8000NE0001 8 6 7200 256
3.5'' PMR Seagate IronWolf Pro ST2000NE0025 2 2 7200 128
3.5'' PMR Seagate IronWolf Pro ST4000NE0025 4 4 7200 128
3.5'' PMR Seagate IronWolf Pro ST6000NE0023 6 6 7200 256
3.5'' PMR Seagate IronWolf Pro ST8000NE0004 8 7 7200 256
3.5'' PMR Seagate IronWolf Pro ST10000NE0008 10 7 7200 256
3.5'' PMR Seagate IronWolf Pro ST12000NE0008 12 8 7200 256
3.5'' PMR+TDMR Seagate IronWolf Pro ST12000NE0008 14 8 7200 256
3.5'' PMR Seagate Exos 7E8/EC3.5 v5 ST2000NM0125 2 2 7200 128
3.5'' PMR Seagate Exos 7E8/EC3.5 v5 ST4000NM0115 4 4 7200 128
3.5'' PMR Seagate Exos 7E8/EC3.5 v5 ST6000NM0115 6 5 7200 256
3.5'' PMR Seagate Exos 7E8/EC3.5 v5 ST6000NM0065 6 6 7200 256
3.5'' PMR Seagate Exos 7E8/EC3.5 v5 ST8000NM0055 8 6 7200 256
3.5'' PMR Seagate Exos 7E8/EC3.5 v5 ST2000NM0105 2 2 7200 128
3.5'' PMR Seagate Exos 7E8/EC3.5 v5 ST4000NM0085 4 4 7200 128
3.5'' PMR Seagate Exos 7E8/EC3.5 v5 ST6000NM0125 6 5 7200 256
3.5'' PMR Seagate Exos 7E8/EC3.5 v5 ST6000NM0055 6 6 7200 256
3.5'' PMR Seagate Exos 7E8/EC3.5 v5 ST8000NM0045 8 6 7200 256
3.5'' PMR Seagate Exos X10/EC3.5 v6 ST8000NM0016 8 7 7200 256
3.5'' PMR Seagate Exos X10/EC3.5 v6 ST8000NM0206 8 7 7200 256
3.5'' PMR Seagate Exos X10/EC3.5 v6 ST8000NM0006 8 7 7200 256
3.5'' PMR Seagate Exos X10/EC3.5 v6 ST8000NM0136 8 7 7200 256
3.5'' PMR Seagate Exos X10/EC3.5 v6 ST10000NM0016 10 7 7200 256
3.5'' PMR Seagate Exos X10/EC3.5 v6 ST10000NM0086 10 7 7200 256
3.5'' PMR Seagate Exos X10/EC3.5 v6 ST10000NM0006 10 7 7200 256
3.5'' PMR Seagate Exos X10/EC3.5 v6 ST10000NM0146 10 7 7200 256
3.5'' PMR Seagate Exos X12/EC3.5 v7 ST12000NM0007 12 8 7200 256
3.5'' PMR+TDMR Seagate Exos X14 ST14000NM0428 14 8 7200 256
3.5'' PMR HGST Ultrastar 7K6000 HUS726020ALE61y 2 2 7200 128
3.5'' PMR HGST Ultrastar 7K6000 HUS726040ALE61y 4 4/5 7200 128
3.5'' PMR HGST Ultrastar 7K6000 HUS726050ALE61y 5 5 7200 128
3.5'' PMR HGST Ultrastar 7K6000 HUS726060ALE61y 6 5 7200 128
3.5'' PMR HGST Ultrastar 7K6000 HUS726020ALN61y 2 2 7200 128
3.5'' PMR HGST Ultrastar 7K6000 HUS726040ALN61y 4 4/5 7200 128
3.5'' PMR HGST Ultrastar 7K6000 HUS726050ALN61y 5 5 7200 128
3.5'' PMR HGST Ultrastar 7K6000 HUS726060ALN61y 6 5 7200 128
3.5'' PMR HGST Ultrastar DC HC310/7K6 HUS726T4TALE6L4 4 3 7200 256
3.5'' PMR HGST Ultrastar DC HC310/7K6 HUS726T6TALE6L4 6 4 7200 256
3.5'' PMR HGST Ultrastar DC HC310/7K6 HUS726T4TALN6L4 4 3 7200 256
3.5'' PMR HGST Ultrastar DC HC310/7K6 HUS726T6TALN6L4 6 4 7200 256
3.5'' PMR HGST Ultrastar DC HC320/7K8 HUS728T8TALE6L4 8 5 7200 256
3.5'' PMR HGST Ultrastar DC HC320/7K8 HUS728T8TALN6L4 8 5 7200 256
3.5'' PMR HGST Ultrastar He8 HUH728060ALE60y 6 7 7200 128
3.5'' PMR HGST Ultrastar He8 HUH728080ALE60y 8 7 7200 128
3.5'' PMR HGST Ultrastar He8 HUH728060ALN60y 6 7 7200 128
3.5'' PMR HGST Ultrastar He8 HUH728080ALN60y 8 7 7200 128
3.5'' PMR HGST Ultrastar DC HC510/He10 HUH721008ALE60y 8 7 7200 256
3.5'' PMR HGST Ultrastar DC HC510/He10 HUH721010ALE60y 10 7 7200 256
3.5'' PMR HGST Ultrastar DC HC510/He10 HUH721008ALN60y 8 7 7200 256
3.5'' PMR HGST Ultrastar DC HC510/He10 HUH721010ALN60y 10 7 7200 256
3.5'' PMR HGST Ultrastar DC HC520/He12 HUH721212ALE60y 12 8 7200 256
3.5'' PMR HGST Ultrastar DC HC520/He12 HUH721212ALN60y 12 8 7200 256
3.5'' PMR+TDMR HGST Ultrastar DC HC530 WUH721414ALE6Ly 14 8 7200 512
3.5'' PMR+TDMR HGST Ultrastar DC HC530 WUH721414ALN6Ly 14 8 7200 512
3.5'' PMR WDC Blue WD10EZEX 1 1 7200 64
3.5'' PMR WDC Blue WD10EZRZ 1 1 5400 64
3.5'' PMR WDC Blue WD20EZRZ 2 2 5400 64
3.5'' PMR WDC Blue WD30EZRZ 3 3 5400 64
3.5'' PMR WDC Blue WD40EZRZ 4 4 5400 64
3.5'' PMR WDC Blue WD50EZRZ 5 5 5400 64
3.5'' PMR WDC Blue WD60EZRZ 6 5 5400 64
3.5'' PMR WDC Black WD1003FZEX 1 1 7200 64
3.5'' PMR WDC Black WD2003FZEX 2 3 7200 64
3.5'' PMR WDC Black WD3003FZEX 3 4 7200 64
3.5'' PMR WDC Black WD4004FZWX 4 5 7200 128
3.5'' PMR WDC Black WD4005FZBX 4   7200 256
3.5'' PMR WDC Black WD5001FZWX 5 5 7200 128
3.5'' PMR WDC Black WD6002FZWX 6 5 7200 128
3.5'' PMR WDC Black WD6003FZBX 6   7200 256
3.5'' PMR WDC Purple WD10PURX 1 1 5400 64
3.5'' PMR WDC Purple WD20PURX 2 2 5400 64
3.5'' PMR WDC Purple WD30PURX 3 3 5400 64
3.5'' PMR WDC Purple WD40PURX 4 4 5400 64
3.5'' PMR WDC Purple WD50PURX 5 5 5400 64
3.5'' PMR WDC Purple WD60PURX 6 5 5400 64
3.5'' PMR WDC Purple WD80PUZX 8 7 5400 128
3.5'' PMR WDC Purple WD81PUZX 8 7 5400 256
3.5'' PMR WDC Purple WD100PURZ 10 7 5400 256
3.5'' PMR WDC Purple WD101PURZ 10 7 7200 256
3.5'' PMR WDC Purple WD121PURZ 12 8 7200 256
3.5'' PMR WDC Red WD10EFRX 1 1 5400 64
3.5'' PMR WDC Red WD20EFRX 2 2/3 5400 64
3.5'' PMR WDC Red WD30EFRX 3 3 5400 64
3.5'' PMR WDC Red WD40EFRX 4 4 5400 64
3.5'' PMR WDC Red WD50EFRX 5 5 5400 64
3.5'' PMR WDC Red WD60EFRX 6 5 5400 64
3.5'' PMR WDC Red WD80EFZX 8 7 5400 128
3.5'' PMR WDC Red WD100EFAX 10 7 5400 256
3.5'' PMR WDC Red Pro WD2002FFSX 2 2/3 7200 64
3.5'' PMR WDC Red Pro WD4002FFWX 4 5 7200 128
3.5'' PMR WDC Red Pro WD4003FFBX 4   7200 256
3.5'' PMR WDC Red Pro WD6002FFWX 6 5 7200 128
3.5'' PMR WDC Red Pro WD6003FFBX 6   7200 256
3.5'' PMR WDC Red Pro WD8001FFWX 8 7 7200 128
3.5'' PMR WDC Red Pro WD8003FFBX 8 7 7200 256
3.5'' PMR WDC Red Pro WD101KFBX 10 7 7200 256
3.5'' PMR WDC Gold WD6002FRYZ 6 5 7200 128
3.5'' PMR WDC Gold WD8002FRYZ 8 7 7200 128
3.5'' PMR WDC Gold WD8003FRYZ 8 7 7200 256
3.5'' PMR WDC Gold WD101KRYZ 10 7 7200 256
3.5'' PMR WDC Gold WD121KRYZ 12 8 7200 256
3.5'' PMR Toshiba Desktop DT01ACA100 1 1 7200 32
3.5'' PMR Toshiba Desktop DT01ACA200 2 2 7200 64
3.5'' PMR Toshiba Desktop DT01ACA300 3 3 7200 64
3.5'' PMR Toshiba Generic Data Storage MD04ACA200 2   7200 128
3.5'' PMR Toshiba Generic Data Storage MD04ACA300 3   7200 128
3.5'' PMR Toshiba Generic Data Storage MD04ACA400 4 5 7200 128
3.5'' PMR Toshiba Generic Data Storage MD04ACA500/D 5 5 7200 128
3.5'' PMR Toshiba Generic Data Storage MD04ACA600 6 6 7200 128
3.5'' PMR Toshiba Video Stream DT01ABA100V 1 1 5700 32
3.5'' PMR Toshiba Video Stream DT01ABA200V 2 2 5700 32
3.5'' PMR Toshiba Video Stream DT01ABA300V 3 3 5940 32
3.5'' PMR Toshiba Surveillance MD04ABA400V 4   5400 128
3.5'' PMR Toshiba Surveillance MD04ABA500V 5   5400 128
3.5'' PMR Toshiba Surveillance MD06ACA600V 6   7200 256
3.5'' PMR Toshiba Surveillance MD06ACA800V 8   7200 256
3.5'' PMR Toshiba Surveillance MD06ACA10TV 10 7 7200 256
3.5'' PMR Toshiba NAS MN04ACA400 4 5 7200 128
3.5'' PMR Toshiba NAS MN05ACA600 6 6 7200 128
3.5'' PMR Toshiba NAS MN05ACA800 8 6 7200 128
3.5'' PMR Toshiba NAS MN06ACA10T 10 7 7200 256
3.5'' PMR Toshiba NAS MN07ACA12T 12 8 7200 256
3.5'' PMR Toshiba NAS MN07ACA14T 14 9 7200 256
3.5'' PMR Toshiba Enterprise Cloud MC04ACA200E 2 4 7200 128
3.5'' PMR Toshiba Enterprise Cloud MC04ACA300E 3 4 7200 128
3.5'' PMR Toshiba Enterprise Cloud MC04ACA400E 4 5 7200 128
3.5'' PMR Toshiba Enterprise Cloud MC04ACA500E 5 5 7200 128
3.5'' PMR Toshiba Enterprise Cloud MC04ACA600E 6 5 7200 128
3.5'' PMR Toshiba Enterprise Capacity MG04ACA200E 2 4 7200 128
3.5'' PMR Toshiba Enterprise Capacity MG04ACA300E 3 4 7200 128
3.5'' PMR Toshiba Enterprise Capacity MG04ACA400E 4 5 7200 128
3.5'' PMR Toshiba Enterprise Capacity MG04ACA500E/DE 5 5 7200 128
3.5'' PMR Toshiba Enterprise Capacity MG06ACA600E 6   7200 256
3.5'' PMR Toshiba Enterprise Capacity MG06ACA800E 8   7200 256
3.5'' PMR Toshiba Enterprise Capacity MG06ACA10TE 10 7 7200 256
3.5'' PMR Toshiba Enterprise Capacity MG07ACA12TE 12 8 7200 256
3.5'' PMR Toshiba Enterprise Capacity MG07ACA14TE 14 9 7200 256
3.5'' PMR Toshiba Enterprise Capacity MG04ACA200A 2 4 7200 128
3.5'' PMR Toshiba Enterprise Capacity MG04ACA300A 3 4 7200 128
3.5'' PMR Toshiba Enterprise Capacity MG04ACA400A 4 5 7200 128
3.5'' PMR Toshiba Enterprise Capacity MG04ACA500A/DA 5 5 7200 128
3.5'' PMR Toshiba Enterprise Capacity MG06ACA600A 6   7200 256
3.5'' PMR Toshiba Enterprise Capacity MG06ACA800A 8   7200 256
3.5'' PMR Toshiba Enterprise Capacity MG06ACA10TA 10 7 7200 256
3.5'' PMR Toshiba Enterprise Capacity MG07ACA12TA 12 8 7200 256
3.5'' PMR Toshiba Enterprise Capacity MG07ACA14TA 14 9 7200 256

下面是部分型号的西数的官网规格表,如下:

继续阅读3.5寸硬盘参数表-PMR/SMR/TDMR-2018-10-24

ImageNet(2010-2017)图像识别数据集

ImageNet 数据集是目前世界上图像识别最大的数据库,根据 WordNet 层次 结构 (目前仅限物体)组织,主要用于机器视觉领域的图像分类和目标检测。其中层次结构的每个节点由数百和数千个图像描绘,每个节点平均有超过 500 个图像,有大约 1500 万张图片,2.2 万类。 ImageNet 数据集于 2009 年由斯坦福大学的李飞飞等人在视觉科学学会(VSS)首次发布,而后自 2010 年起一年一度的 ImageNet 大规模视觉识别挑战(ILSVRC)挑战赛不断完善 ImageNet 数据集。

ImageNet.torrent  需要占用磁盘空间 860.55 GB

参考链接


如何检查macOS SSD健康状态,保持系统及文档安全

苹果为了保持自家一定领先地位,在 MAC 设备上都采用了 SSD 磁盘。为了帮助用户关注磁盘运行状况,macOS 系统中已经内置了检查内置 SSD 和其它已连接磁盘运行状态的相关工具。以便在SSD 固态磁盘挂掉之前,就让用户提前检测并知晓其工作状态。

各种存储介质,包括 SSD,其实都是消耗品。这意味着一旦磁盘挂了,不仅会影响系统正常运行,甚至存储的文件都会有损失的风险。

继续阅读如何检查macOS SSD健康状态,保持系统及文档安全

OCR-文本图像合成工具

1. Text Recognition Data Generator

Github地址: https://github.com/Belval/TextRecognitionDataGenerator

官方文档:https://textrecognitiondatagenerator.readthedocs.io/en/latest/index.html

安装:

# pip 安装,中文不建议
$ pip install trdg -i https://pypi.mirrors.ustc.edu.cn/simple/

# git clone
$ git clone https://github.com/Belval/TextRecognitionDataGenerator

以下根据个人需要:

git clone 解压后进入 /trdg/bin 安装目录:

$ mv trdg ../run.py

$ cd ..

$ vim run.py
# 删除 run.py中的 from trdg import, 全部改为 import

$ vim data_generator.py
# 同上,删除此文件首部的 from trdg import, 改为 import
  • pictures/ 文件夹内存放背景图,可以多添加一些图片用于丰富生成的合成图片;
  • fonts/ 文件夹内 cn/ en/分别存放中、英文字体文件(.ttf格式),可以自己在网上下载不同ttf文件放入文件夹内;
  • string_generator.py 定义了图片上的文本如何选取,可以自行定义(博主在Centos7服务器上中文好像一直有乱码问题,只能修改string 的编码)
  • data_generator.py 是按照给定参数生成图片,最好在里面加上 try / except,大规模合成数据万一有一个case报错就要重新生成,很麻烦,相应的在 bin/trdg 文件中修改相应的生成 labels.txt 的代码,保证一致(这里也可能涉及到保存的中文文本乱码,如果是的话也要修改string的编解码)

生成命令(示例,具体见官方文档):

$ python trdg -l cn -c 1000000 -d 1 -rs -b 3 -w 20 -bl 1 -rbl -tc '#000000,#888888' -f 64 -t 32 --output_dir 'sin-100w'
  • -l cn: language 为中文
  • -c 1000000: 生成1000000张图
  • -d 1: 文字按正弦函数曲线分布(0为不弯曲,1为sin,2为cos)
  • -rs: 图片文字随机选取;
  • -b 3: 背景图像从pictures文件夹中的图像上随机截取(0为高斯白噪声背景,1为白色背景,2为quasicrystal,3为自定义图片)
  • -bl 1 -rbl: 随机模糊,1为模糊的kernel size
  • -tc '#000000, #888888': 颜色变化区间
  • -f 64: 水平分布文字图像的高(像素64)
  • --output_dir 'sin-100w': 输出文件夹

2. Text Render

Github地址:https://github.com/Sanster/text_renderer

参见 github 的 README.md.

3. SynthText

Github地址: https://github.com/ankush-me/SynthText

参考链接